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

On Wed 16-08-17 16:07:21, Thomas Gleixner wrote:
> On Mon, 7 Aug 2017, Artem Savkov wrote:
> 
> +Cc mm folks ...

Ups, this has fallen through cracks

> > Hello,
> > 
> > After commit fc8dffd "cpu/hotplug: Convert hotplug locking to percpu rwsem"
> > the following lockdep splat started showing up on some systems while running
> > ltp's madvise06 test (right after first dirty_pages call [1]).
> >
> > [1] https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/madvise/madvise06.c#L136
> > 
> > [21002.630252] ======================================================
> > [21002.637148] WARNING: possible circular locking dependency detected
> > [21002.644045] 4.13.0-rc3-next-20170807 #12 Not tainted
> > [21002.649583] ------------------------------------------------------
> > [21002.656492] a.out/4771 is trying to acquire lock:
> > [21002.661742]  (cpu_hotplug_lock.rw_sem){++++++}, at: [<ffffffff812b4668>] drain_all_stock.part.35+0x18/0x140
> > [21002.672629] 
> > [21002.672629] but task is already holding lock:
> > [21002.679137]  (&mm->mmap_sem){++++++}, at: [<ffffffff8106eb35>] __do_page_fault+0x175/0x530
[...]
> > [21002.993812] other info that might help us debug this:
> > [21002.993812] 
> > [21003.002744] Chain exists of:
> > [21003.002744]   cpu_hotplug_lock.rw_sem --> &type->i_mutex_dir_key#3 --> &mm->mmap_sem
> > [21003.002744] 
> > [21003.016238]  Possible unsafe locking scenario:
> > [21003.016238] 
> > [21003.022843]        CPU0                    CPU1
> > [21003.027896]        ----                    ----
> > [21003.032948]   lock(&mm->mmap_sem);
> > [21003.036741]                                lock(&type->i_mutex_dir_key#3);
> > [21003.044419]                                lock(&mm->mmap_sem);
> > [21003.051025]   lock(cpu_hotplug_lock.rw_sem);

OK, this smells like the same thing we had to address for
drain_all_pages by a459eeb7b852 ("mm, page_alloc: do not depend on cpu
hotplug locks inside the allocator"). try_charge might be deep in the
call path so taking cpu_hotplug_lock just calls for troubles.

I have of course forgot all the subtle details about drain_all_pages but
re-reading the changelog it seems that we can get along with droping
{get,put}_online_cpus in because drain_local_stock (which is called from
the WQ context as well) is disabling irqs and _always_ operates on the
local cpu stock. So we cannot possibly race with the memory hotplug
AFAICS.

So what do you think about the following patch?
---

  reply	other threads:[~2017-08-30 14:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20170807140947.nhfz2gel6wytl6ia@shodan.usersys.redhat.com>
2017-08-16 14:07 ` Thomas Gleixner
2017-08-30 14:15   ` Michal Hocko [this message]
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
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=20170830141543.qhipikpog6mkqe5b@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