linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	Artem Savkov <asavkov@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-mm@kvack.org
Subject: Re: possible circular locking dependency mmap_sem/cpu_hotplug_lock.rw_sem
Date: Tue, 5 Sep 2017 12:23:36 +0200	[thread overview]
Message-ID: <20170905102336.bqxb7tltnt3lphkq@dhcp22.suse.cz> (raw)
In-Reply-To: <alpine.DEB.2.20.1709051013380.1900@nanos>

On Tue 05-09-17 10:19:13, Thomas Gleixner wrote:
> On Mon, 4 Sep 2017, Michal Hocko wrote:
> 
> > Thomas, Johannes,
> > could you double check my thinking here? I will repost the patch to
> > Andrew if you are OK with this.
> > > +	/*
> > > +	 * The only protection from memory hotplug vs. drain_stock races is
> > > +	 * that we always operate on local CPU stock here with IRQ disabled
> > > +	 */
> > >  	local_irq_save(flags);
> > >  
> > >  	stock = this_cpu_ptr(&memcg_stock);
> > > @@ -1807,26 +1811,27 @@ static void drain_all_stock(struct mem_cgroup *root_memcg)
> > >  	if (!mutex_trylock(&percpu_charge_mutex))
> > >  		return;
> > >  	/* Notify other cpus that system-wide "drain" is running */
> > > -	get_online_cpus();
> > >  	curcpu = get_cpu();
> 
> The problem here is that this does only protect you against a CPU being
> unplugged, but not against a CPU coming online concurrently.

Yes but same as the drain_all_pages we do not have any cpu up specific
intialization so there is no specific action to race against AFAICS.

> I have no idea
> whether that might be a problem, but at least you should put a comment in
> which explains why it is not.

What about this?
---
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5c70f47abb3d..ff9b0979ccc3 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1810,7 +1810,12 @@ static void drain_all_stock(struct mem_cgroup *root_memcg)
 	/* If someone's already draining, avoid adding running more workers. */
 	if (!mutex_trylock(&percpu_charge_mutex))
 		return;
-	/* Notify other cpus that system-wide "drain" is running */
+	/*
+	 * Notify other cpus that system-wide "drain" is running
+	 * We do not care about races with the cpu hotplug because cpu down
+	 * as well as workers from this path always operate on the local
+	 * per-cpu data. CPU up doesn't touch memcg_stock at all.
+	 */
 	curcpu = get_cpu();
 	for_each_online_cpu(cpu) {
 		struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu);

-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2017-09-05 10:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-07 14:09 possible circular locking dependency mmap_sem/cpu_hotplug_lock.rw_sem Artem Savkov
2017-08-15 19:01 ` Paul E. McKenney
2017-08-16 13:39   ` Laurent Dufour
2017-08-16 15:36     ` Artem Savkov
2017-08-16 15:40       ` Laurent Dufour
2017-08-16 14:07 ` Thomas Gleixner
2017-08-30 14:15   ` Michal Hocko
2017-08-30 15:43     ` Michal Hocko
2017-08-31 11:10       ` Artem Savkov
2017-08-31 12:09         ` Michal Hocko
2017-08-31 12:19           ` Artem Savkov
2017-09-04 14:03       ` Michal Hocko
2017-09-05  8:19         ` Thomas Gleixner
2017-09-05 10:23           ` Michal Hocko [this message]
2017-09-05 11:04             ` Thomas Gleixner

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=20170905102336.bqxb7tltnt3lphkq@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=asavkov@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).