From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58A6F3DD520 for ; Thu, 14 May 2026 13:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778763639; cv=none; b=luKc95skPWAsGQHHDxbPJ5mwFCiuHnjppv5pze6UE4TwADPboS9M3ZfTlxTmzUnzkqBT+pYjcCZZHfWpYzhjej1TE/9VZ9FqS5LyGD3fnfKv551S3e1RwKG0hXPzAQtF4tLpVNgyaThYsix9sLcirPP7JiNmSO1y2x+Xm8scEIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778763639; c=relaxed/simple; bh=y+63E2ApBElpTrupNQOJ7GnljASd3GxnwbYuEUdT9D0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Fv/QxqjDxDzRsWvvd3tiu2w2GSmBYmwi5ax+hijwVHAKy5rvnIUk/oeJyvhicmidJRwoidFChvqSP7MMeU5jOb2h0gU8fGXX9P+BCfCXSN5IiYxX0rY6Kfv+bBoheGVFP9nI/4cEEzHXOwuW3A/+aP3fRECeMhoHh8WWupGw3PI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IRqPjVXD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IRqPjVXD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C184C2BCB3; Thu, 14 May 2026 13:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778763639; bh=y+63E2ApBElpTrupNQOJ7GnljASd3GxnwbYuEUdT9D0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=IRqPjVXDYNip0scBemnQXcCSA3FB1zpPZ9wLrCssrGqzAHMZdfWtYMKfxFmQv7pjY X6lAMVPKY5OyYR98Z4+ASXv+mJo6PdM8fSu8174vpY6+H3hT4UIWrZjuRlY5wmdNS6 VQTmKmtRYox1kywc5BYZ9FHx0fzVaMFyCUk+WgW9Gto8SSYCmblMjP2OgXUNT0VY8P CpRuXQtfG4wQH8zbzSNZJhtSi8lrbRdxoKqrt2BYbBpvc+TttPqo4U0CXvQLyiQksY HQwu76lOcTvVe8wanDVficAF0Y3wb2XTMkDVPSIK7DotnISkD6W+A4//OJEqtiEh3L 24uHP7x28k7GA== Message-ID: <2e78296b-7783-4303-9a88-16f154d0bed7@kernel.org> Date: Thu, 14 May 2026 15:00:35 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] mm/slub: hold cpus_read_lock around flush_rcu_sheaves_on_cache() Content-Language: en-US To: Qing Wang , harry@kernel.org Cc: akpm@linux-foundation.org, cl@gentwo.org, hao.li@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, rientjes@google.com, roman.gushchin@linux.dev References: <20260512035035.762317-1-wangqing7171@gmail.com> From: "Vlastimil Babka (SUSE)" In-Reply-To: <20260512035035.762317-1-wangqing7171@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/12/26 05:50, Qing Wang wrote: > flush_rcu_sheaves_on_cache() calls queue_work_on() in a > for_each_online_cpu() loop, which requires the cpu to stay online. > But cpus_read_lock() is not held in kvfree_rcu_barrier_on_cache() and the > set of "online cpus" is subject to change. > > There are two paths that call flush_rcu_sheaves_on_cache(): > > // has cpus_read_lock() > flush_all_rcu_sheaves() > -> flush_rcu_sheaves_on_cache() > > // no cpus_read_lock() > kvfree_rcu_barrier_on_cache() > -> flush_rcu_sheaves_on_cache() > > Fix this by holding cpus_read_lock() in kvfree_rcu_barrier_on_cache(). > > Why not move cpus_read_lock() from flush_all_rcu_sheaves() into > flush_rcu_sheaves_on_cache()? The reason is it would introduce a new lock > order (slab_mutex -> cpu_hotplug_lock). The reverse order > (cpu_hotplug_lock -> slab_mutex) is established by > > - cpuhp_setup_state_nocalls(..., slub_cpu_setup, ...) > - kmem_cache_destroy() > > The two orders together would form an AB-BA deadlock. > > Finally, add lockdep_assert_cpus_held() in flush_rcu_sheaves_on_cache() > to catch the same problem in the future. > > Fixes: 0f35040de593 ("mm/slab: introduce kvfree_rcu_barrier_on_cache() for cache destruction") > Signed-off-by: Qing Wang Added Cc: stable as Harry suggested. Applied to slab/for-next-fixes. Thanks! > --- > Changes in v2: > - Deleted the unnecessary comment. > - Added "Fixes" field in the commit message. > Changes in v3: > - Deleted the unnecessary comment. > > mm/slab_common.c | 2 ++ > mm/slub.c | 1 + > 2 files changed, 3 insertions(+) > > diff --git a/mm/slab_common.c b/mm/slab_common.c > index d5a70a831a2a..8b661fff5eed 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -2110,7 +2110,9 @@ EXPORT_SYMBOL_GPL(kvfree_rcu_barrier); > void kvfree_rcu_barrier_on_cache(struct kmem_cache *s) > { > if (cache_has_sheaves(s)) { > + cpus_read_lock(); > flush_rcu_sheaves_on_cache(s); > + cpus_read_unlock(); > rcu_barrier(); > } > > diff --git a/mm/slub.c b/mm/slub.c > index 161079ac5ba1..2a005d1e3a74 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -4024,6 +4024,7 @@ void flush_rcu_sheaves_on_cache(struct kmem_cache *s) > struct slub_flush_work *sfw; > unsigned int cpu; > > + lockdep_assert_cpus_held(); > mutex_lock(&flush_lock); > > for_each_online_cpu(cpu) {