mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chen Yu <yu.c.chen@intel.com>
To: Reinette Chatre <reinette.chatre@intel.com>
Cc: <kees@kernel.org>, <mingo@redhat.com>, <peterz@infradead.org>,
	<juri.lelli@redhat.com>, <vincent.guittot@linaro.org>,
	<dietmar.eggemann@arm.com>, <rostedt@goodmis.org>,
	<bsegall@google.com>, <mgorman@suse.de>, <vschneid@redhat.com>,
	<kprateek.nayak@amd.com>, <david@kernel.org>, <ljs@kernel.org>,
	<liam@infradead.org>, <vbabka@kernel.org>, <rppt@kernel.org>,
	<surenb@google.com>, <mhocko@suse.com>, <bp@alien8.de>,
	<tglx@linutronix.de>, <dave.hansen@linux.intel.com>,
	<tony.luck@intel.com>, <ben.horgan@arm.com>,
	<Dave.Martin@arm.com>, <james.morse@arm.com>,
	<babu.moger@amd.com>, <fustini@kernel.org>,
	<jedrzej.wasiukiewicz@intel.com>, <fenghuay@nvidia.com>,
	<peternewman@google.com>, <x86@kernel.org>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <patches@lists.linux.dev>
Subject: Re: [RFC PATCH 1/3] fork,arm,x86,fs/resctrl: Fix stale resource group assignment vs copy_process()
Date: Fri, 27 Nov 2026 00:10:01 +0800	[thread overview]
Message-ID: <awhZ2UGIpFDNgcCs@chenyu-dev> (raw)
In-Reply-To: <22918abf-7487-4662-a87b-34c579783e51@intel.com>

Hi Reinette,

On Mon, Nov 23, 2026 at 02:50:14PM -0800, Reinette Chatre wrote:
> 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?
>

Right, current patch can fix the race between fork() and rmdir/task movement.
 
> > 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. 
>

OK, I think the current version is ok to fix the race, and we can deal with
__resctrl_sched_in() later.

I fed AI with the patch 3/3 to generate a simplified test script, and try
to reproduce:
1. The frequent forked task f joins the task list with group m's RMID, which
is freed by rmdir.
2. A later mkdir N reuses the freed RMID, and task f shows up in the new group N.

Tested on a 160-CPU Intel server with the script, C does not show up in
the new groups. 50 cycles passed.

Tested-by: Chen Yu <yu.c.chen@intel.com>

thanks,
Chenyu

  reply	other threads:[~2026-11-26 16:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 18:39 [RFC PATCH 0/3] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork Reinette Chatre
2026-11-20 18:39 ` [RFC PATCH 1/3] fork,arm,x86,fs/resctrl: Fix stale resource group assignment vs copy_process() Reinette Chatre
2026-11-23  3:48   ` Chen Yu
2026-11-23 22:50     ` Reinette Chatre
2026-11-26 16:10       ` Chen Yu [this message]
2026-11-23 14:14   ` Ben Horgan
2026-11-24  0:43     ` Reinette Chatre
2026-11-24 10:08       ` Ben Horgan
2026-11-20 18:39 ` [RFC PATCH 2/3] arm,x86/resctrl: Assert tasklist_lock is held when setting CLOSID and RMID Reinette Chatre
2026-11-20 18:39 ` [RFC PATCH 3/3] NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer Reinette Chatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awhZ2UGIpFDNgcCs@chenyu-dev \
    --to=yu.c.chen@intel.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=bp@alien8.de \
    --cc=bsegall@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=fenghuay@nvidia.com \
    --cc=fustini@kernel.org \
    --cc=james.morse@arm.com \
    --cc=jedrzej.wasiukiewicz@intel.com \
    --cc=juri.lelli@redhat.com \
    --cc=kees@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=patches@lists.linux.dev \
    --cc=peternewman@google.com \
    --cc=peterz@infradead.org \
    --cc=reinette.chatre@intel.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=vbabka@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®