From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57CBAECE58C for ; Mon, 7 Oct 2019 21:59:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0491021479 for ; Mon, 7 Oct 2019 21:59:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="DN+h02cp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0491021479 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9B4A18E0006; Mon, 7 Oct 2019 17:59:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9653B8E0003; Mon, 7 Oct 2019 17:59:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 855238E0006; Mon, 7 Oct 2019 17:59:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id 644998E0003 for ; Mon, 7 Oct 2019 17:59:05 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 07026611D for ; Mon, 7 Oct 2019 21:59:05 +0000 (UTC) X-FDA: 76018354650.04.slope75_4f3ebccf0c125 X-HE-Tag: slope75_4f3ebccf0c125 X-Filterd-Recvd-Size: 3788 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Mon, 7 Oct 2019 21:59:04 +0000 (UTC) Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 16ED6206C0; Mon, 7 Oct 2019 21:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570485543; bh=vccaCfLekIcqrg8RQFT5wkIkeO9fGglQMnl9ddohi3I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DN+h02cpgv8d+Ejd5EN5YVKMhepec70IQOiCXb9JSCch6mASL0uEQB7yMuQHMEBvT l7Jbk1GmZ8HyfHw2sXhUVm7teniTYmTFqrgq/Qtt1gY5Hz1ruYREBCug0GS+PgJIoq CICr5sHeej3dbaCyraAh0n/gN7lxLsld/R41sB+k= Date: Mon, 7 Oct 2019 14:59:02 -0700 From: Andrew Morton To: Michal Hocko Cc: Qian Cai , tj@kernel.org, vdavydov.dev@gmail.com, hannes@cmpxchg.org, guro@fb.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] mm/slub: fix a deadlock in show_slab_objects() Message-Id: <20191007145902.a1ae6aac11c29d466a445a94@linux-foundation.org> In-Reply-To: <20191007081621.GE2381@dhcp22.suse.cz> References: <1570192309-10132-1-git-send-email-cai@lca.pw> <20191004125701.GJ9578@dhcp22.suse.cz> <20191007081621.GE2381@dhcp22.suse.cz> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, 7 Oct 2019 10:16:21 +0200 Michal Hocko wrote: > On Fri 04-10-19 14:57:01, Michal Hocko wrote: > > On Fri 04-10-19 08:31:49, 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 which 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, in the worst case, the results > > > may me miscalculated while doing NUMA node hotplug, but they shall be > > > corrected by later reads of the same files. > > > > I think it is important to mention that this doesn't expose the > > show_slab_objects to use-after-free. There is only a single path that > > might really race here and that is the slab hotplug notifier callback > > __kmem_cache_shrink (via slab_mem_going_offline_callback) but that path > > doesn't really destroy kmem_cache_node data structures. Yes, I noted this during review. It's a bit subtle and is worthy of more than a changelog note, I think. How about this? --- a/mm/slub.c~mm-slub-fix-a-deadlock-in-show_slab_objects-fix +++ a/mm/slub.c @@ -4851,6 +4851,10 @@ static ssize_t show_slab_objects(struct * already held which will conflict with an existing lock order: * * mem_hotplug_lock->slab_mutex->kernfs_mutex + * + * We don't really need mem_hotplug_lock (to hold off + * slab_mem_going_offline_callback()) here because slab's memory hot + * unplug code doesn't destroy the kmem_cache->node[] data. */ #ifdef CONFIG_SLUB_DEBUG _ > Andrew, please add this to the changelog so that we do not have to > scratch heads again when looking into that code. I did that as well.