Re: [RFC PATCH 1/3] fork,arm,x86,fs/resctrl: Fix stale resource group assignment vs copy_process()
From: Reinette Chatre
Date: Mon Nov 23 2026 - 17:50:29 EST
Hi Chenyu,
On 11/22/26 7:48 PM, Chen Yu wrote:
> On Fri, Nov 20, 2026 at 10:39:30AM -0800, Reinette Chatre wrote:
...
>> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
>> index 57ab090072c2..ebf780fc5fe9 100644
>> --- a/fs/resctrl/rdtgroup.c
>> +++ b/fs/resctrl/rdtgroup.c
>> @@ -657,12 +657,28 @@ static int __rdtgroup_move_task(struct task_struct *tsk,
>> return -EINVAL;
>> }
>>
>> + /*
>> + * Hold tasklist_lock for read so that resctrl_copy_process(), which
>> + * holds it for write, cannot read the CLOSID and the RMID of @tsk
>> + * while only one of the two has been updated.
>> + *
>> + * Hold tasklist_lock just for the @tsk update. A CPU running @tsk
>> + * keeps using the CLOSID and RMID that resctrl_arch_sched_in()
>> + * applied when @tsk was last scheduled in, so
>> + * update_task_closid_rmid() below has to interrupt that CPU for the
>> + * new resource group to take effect. Leave that until after
>> + * tasklist_lock has been dropped: a CPU waiting for tasklist_lock
>> + * for write waits with interrupts disabled, and @tsk's CPU is the
>> + * one that may be waiting, because @tsk may be forking.
>> + */
>> + read_lock(&tasklist_lock);
>> if (rdtgrp->type == RDTMON_GROUP)
>> resctrl_arch_set_closid_rmid(tsk, rdtgrp->mon.parent->closid,
>> rdtgrp->mon.rmid);
>> else
>> resctrl_arch_set_closid_rmid(tsk, rdtgrp->closid,
>> rdtgrp->mon.rmid);
>> + read_unlock(&tasklist_lock);
>>
>
> Is it possible to combine u32 closid and u32 rmid into u64 closid_rmid?
This is something we can look into yes. The "What remains?" portion of
the cover letter highlights this but stops short of proposing the change
as you do here. Making this change will only eliminate the need for this
lock at this point though, it will not fix the bug, right?
> RDT will no longer support 32-bit kernels, so u64 is always atomic. Then
Planned, but not yet done.
> we don't need the above tasklist_lock in __rdtgroup_move_task(), and there
> is no race with resctrl_arch_sched_in() - but we do need it during fork()
> though.
Right. The primary goal with this patch is to add a resctrl hook into
kernel/fork.c:copy_process() to address the bug that results in a task
_permanently_ assigned with a wrong CLOSID/RMID. This is required whether
CLOSID/RMID are two separate values or one, as demonstrated by MPAM, which
stores the two as one value, also needing this.
In comparison, as described in the cover letter, the potential race with
x86 __resctrl_sched_in(), is not permanent since it is corrected at next context
switch. As you indicate with your proposal, addressing it needs a separate
and more invasive fix.
Reinette