public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Juri Lelli <juri.lelli@redhat.com>
To: Waiman Long <longman@redhat.com>
Cc: Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>, Qais Yousef <qyousef@layalina.io>,
	Hao Luo <haoluo@google.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Xia Fukun <xiafukun@huawei.com>
Subject: Re: [PATCH] cgroup/cpuset: Change nr_deadline_tasks to an atomic_t value
Date: Wed, 11 Oct 2023 10:14:52 +0200	[thread overview]
Message-ID: <ZSZZfImXuCG4Xvaz@localhost.localdomain> (raw)
In-Reply-To: <31e06652-1dbd-e32f-3123-d17e178c5c27@redhat.com>

On 10/10/23 16:03, Waiman Long wrote:
> 
> On 10/10/23 15:44, Waiman Long wrote:
> > 
> > On 10/10/23 01:34, Juri Lelli wrote:
> > > Hi,
> > > 
> > > On 09/10/23 15:15, Waiman Long wrote:
> > > > The nr_deadline_tasks field in cpuset structure was introduced by
> > > > commit 6c24849f5515 ("sched/cpuset: Keep track of SCHED_DEADLINE task
> > > > in cpusets"). Unlike nr_migrate_dl_tasks which is only modified under
> > > > cpuset_mutex, nr_deadline_tasks can be updated in various contexts
> > > > under different locks. As a result, data races may happen that cause
> > > > incorrect value to be stored in nr_deadline_tasks leading to incorrect
> > > Could you please make an example of such data races?
> > 
> > Since update to cs->nr_deadline_tasks is not protected by a single lock,
> > it is possible that multiple CPUs may try to modify it at the same
> > time.  It is possible that nr_deadline_tasks++ and nr_deadline_tasks--
> > can be done in a single instruction like in x86 and hence atomic.
> > However, operation like "cs->nr_deadline_tasks +=
> > cs->nr_migrate_dl_tasks" is likely a RMW operation and so is subjected
> > to racing. It is mostly theoretical, but probably not impossible.
> 
> Sorry, even increment and decrement operators are not atomic.
> 
> inc_dl_tasks_cs() is only called from switched_to_dl() in deadline.c which
> is protected by the rq_lock, but there are multiple rq's. dec_dl_tasks_cs()
> is called from switched_from_dl() in deadline.c and cgroup_exit() in
> cgroup.c. The later one is protected by css_set_lock. The other place where
> nr_deadline_tasks can be changed is in cpuset_attach() protected by
> cpuset_mutex.

So, let's see. :)

switched_to_dl(), switched_from_dl() and cpuset_attach() should all be
protected (for DEADLINE tasks) by cpuset_mutex, see [1] for the former
two.

What leaves me perplexed is indeed cgroup_exit(), which seems to operate
under css_set_lock as you say. I however wonder why is that not racy
already wrt, say, cpuset_attach() which AFAIU uses css information w/o
holding css_set_lock?

Thanks,
Juri

1 - https://elixir.bootlin.com/linux/latest/source/kernel/sched/core.c#L7688


  reply	other threads:[~2023-10-11  8:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09 19:15 [PATCH] cgroup/cpuset: Change nr_deadline_tasks to an atomic_t value Waiman Long
2023-10-10  5:34 ` Juri Lelli
2023-10-10 19:44   ` Waiman Long
2023-10-10 20:03     ` Waiman Long
2023-10-11  8:14       ` Juri Lelli [this message]
2023-10-11 12:54         ` Waiman Long
2023-10-12 16:35           ` Waiman Long
2023-10-13  6:09             ` Juri Lelli

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=ZSZZfImXuCG4Xvaz@localhost.localdomain \
    --to=juri.lelli@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=haoluo@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=longman@redhat.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=tj@kernel.org \
    --cc=xiafukun@huawei.com \
    /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