Re: [PATCH v3 3/3] x86/resctrl: Implement rename op for mon groups
From: Reinette Chatre
Date: Fri Mar 03 2023 - 14:06:14 EST
Hi Peter,
On 3/3/2023 7:10 AM, Peter Newman wrote:
> On Thu, Mar 2, 2023 at 11:27 PM Reinette Chatre
> <reinette.chatre@xxxxxxxxx> wrote:
>> On 3/2/2023 6:26 AM, Peter Newman wrote:
>>> On Sat, Feb 11, 2023 at 12:21 AM Reinette Chatre
>>> <reinette.chatre@xxxxxxxxx> wrote:
>>>
>>>> On 1/25/2023 2:13 AM, Peter Newman wrote:
>>>>> + for_each_process_thread(p, t) {
>>>>> + if (is_closid_match(t, prdtgrp) && is_rmid_match(t, rdtgrp))
>>>>> + rdt_move_one_task(t, new_prdtgrp->closid, t->rmid,
>>>>> + cpus);
>>>>> + }
>>>>> + read_unlock(&tasklist_lock);
>>>>
>>>> Can rdt_move_group_tasks() be used here?
>>>
>>> As it is today, rdt_move_group_tasks() would move too many tasks.
>>> mongrp_move() needs both the CLOSID and RMID to match, while
>>> rdt_move_group_tasks() only needs 0-1 of the two to match.
>>>
>>> I tried adding more parameters to rdt_move_group_tasks() to change the
>>> move condition, but I couldn't make the resulting code not look gross
>>> and after factoring the tricky stuff into rdt_move_one_task(),
>>> rdt_move_group_tasks() didn't look interesting enough to reuse.
>>
>> Could it be made readable by adding a compare function as parameter to
>> rdt_move_group_tasks() that is used to determine if a task should be moved?
>
> Yes, I think that would be ok in this case. That shouldn't have any
> cost if these are all static functions.
>
> As long as we have an rdt_move_group_tasks() function, it's a liability
> to have a separate task-moving loop for someone to miss in the future.
Agreed.
> Should I still bother with factoring out rdt_move_one_task() in the
> parent patch? It was motivated by my creating a new task-moving loop
> in this patch.
I do not think that refactoring is necessary if you go this route.
>>>>> +
>>>>> + rdtgrp = kernfs_to_rdtgroup(kn);
>>>>> + new_prdtgrp = kernfs_to_rdtgroup(new_parent);
>>>>> + if (!rdtgrp || !new_prdtgrp) {
>>>>> + free_cpumask_var(tmpmask);
>>>>> + return -EPERM;
>>>>> + }
>>>>> +
>>>>
>>>> How robust is this against user space attempting to move files?
>>>
>>> I'm not sure I understand the question. Can you be more specific?
>>
>> This commit adds support for rename to resctrl. I thus expect this
>> function to be called when user space attempts to move _any_ of
>> the files and/or directories within resctrl. This could be out of
>> curiosity, buggy, or maliciousness. I would like to understand how
>> robust this code would be against such attempts because I do not see
>> much checking before the preparation to do the move is started.
>
> Now I see, thanks.
>
> kernfs_to_rdtgroup() will return the parent rdtgroup when
> kn or new_parent is a file, which will lead to kernfs_rename() moving
> a file out of a group or clobbering another file node. I'll need to
> enforce that kn and new_parent are rdtgroup directories and not file
> nodes.
Perhaps additionally that the source directories have mon_groups as parent,
similar to the destination check you already have.
Reinette