Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp585809ybp; Fri, 4 Oct 2019 01:31:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRFn1zuJ+VUIn1N60rNfrt6COjnnaJTCT6nRcdIpKTbEY1lIYQhz2ooMkhRUgI/5uu+GmE X-Received: by 2002:a17:906:4e57:: with SMTP id g23mr11223894ejw.264.1570177884835; Fri, 04 Oct 2019 01:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570177884; cv=none; d=google.com; s=arc-20160816; b=CVEHjaAM6UF1lxzHmbj4YePQm5253Hgz8dXOrSNqyqRLo77XhSuTU5hDje27raOc6Z ziQAG2qemybm7FQNmW87eSWrLnOZ7AFQO7Xr+P9u80jHNi0UK2xoZKlB3OvQpW5rmc3J HCVvMUwo8YjsGjSWQ9Da/D+Qc5/hV/ekUqo9Emc4wCQD3YyBKdgybeLR/oJf4Ywc5OoV rq2mMrFO4rPwbjOZ3WW06QIITixGyPE/vK4jjOPZUobGMzVDoG3dpRJXrN6/wxDupRaR MP9F1PVUrmZ1w11pc9p1tH4WKzPsUZQe5GnT7w/pOTb+iS88IIqCifpO1vdB6JkYMFjx MD9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=bmaajNEs8HF8MaJ4G246fdAIcatkKBBfU43XB8wM02w=; b=DPWxqV8VrlL8jdid4sBQ7gTPRAEx8I7BgpkrAYG7bY7FJgwfSRDOWb3lEFp6JzwUKO CcRPkL5lMFwo4L0JjKrhHkT6NihS3nLrrHULZ4fMlmZaeuLDJTcZ54fzaZ+NZ7k1uz38 z7GBXuu0dV3We1ZWtiskHClJwOJ79x2qHwW2hO1M2A1QZ8RkMKyeqtJubkDCxicje6T6 k95o0kwbp6VjezniCuDgkyHgykqB2HxwxBb2zGjyJf+jXBjkZWxiNU0dwgKJBQ/Cgc9M IKWQvQ9y2GYWpUXr/+YcWZt2m93Ijru29mOEnN+YN7zbwbLiSpIlMc654gGsFsdQwqcG IYVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si3410459edj.220.2019.10.04.01.31.00; Fri, 04 Oct 2019 01:31:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387759AbfJDIOP (ORCPT + 99 others); Fri, 4 Oct 2019 04:14:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:34936 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387631AbfJDIOP (ORCPT ); Fri, 4 Oct 2019 04:14:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6495EB16B; Fri, 4 Oct 2019 08:14:12 +0000 (UTC) Date: Fri, 4 Oct 2019 10:13:58 +0200 From: Michal Hocko To: Qian Cai Cc: akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, tj@kernel.org, vdavydov.dev@gmail.com, hannes@cmpxchg.org, guro@fb.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/slub: fix a deadlock in show_slab_objects() Message-ID: <20191004081358.GA9578@dhcp22.suse.cz> References: <1570131869-2545-1-git-send-email-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1570131869-2545-1-git-send-email-cai@lca.pw> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 03-10-19 15:44:29, Qian Cai wrote: > Long time ago, there fixed a similar deadlock in show_slab_objects() > [1]. However, it is apparently due to the commits like 01fb58bcba63 > ("slab: remove synchronous synchronize_sched() from memcg cache > deactivation path") and 03afc0e25f7f ("slab: get_online_mems for > kmem_cache_{create,destroy,shrink}"), this kind of deadlock is back by > just reading files in /sys/kernel/slab will generate a lockdep splat > below. > > Since the "mem_hotplug_lock" here is only to obtain a stable online node > mask while racing with NUMA node hotplug, it is probably fine to do > without it. "It is probably fine" is not a proper justification. Please have a look at my older email where I've exaplained why I believe it is safe. > WARNING: possible circular locking dependency detected > ------------------------------------------------------ I pressume the deadlock is real. If that is the case then Cc: stable and Fixes tag would be really appreciated. > Signed-off-by: Qian Cai Anyway, I do agree that this is the right thing to do. With the improved changelog, fixed up the comment alignment feel free to add Acked-by: Michal Hocko > --- > mm/slub.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 42c1b3af3c98..922cdcf5758a 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -4838,7 +4838,15 @@ static ssize_t show_slab_objects(struct kmem_cache *s, > } > } > > - get_online_mems(); > +/* > + * It is not possible to take "mem_hotplug_lock" here, as it has already held > + * "kernfs_mutex" which could race with the lock order: > + * > + * mem_hotplug_lock->slab_mutex->kernfs_mutex > + * > + * In the worest case, it might be mis-calculated while doing NUMA node > + * hotplug, but it shall be corrected by later reads of the same files. > + */ > #ifdef CONFIG_SLUB_DEBUG > if (flags & SO_ALL) { > struct kmem_cache_node *n; > @@ -4879,7 +4887,6 @@ static ssize_t show_slab_objects(struct kmem_cache *s, > x += sprintf(buf + x, " N%d=%lu", > node, nodes[node]); > #endif > - put_online_mems(); > kfree(nodes); > return x + sprintf(buf + x, "\n"); > } > -- > 1.8.3.1 > -- Michal Hocko SUSE Labs