From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4EE81A6838 for ; Tue, 12 May 2026 03:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.67 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778557843; cv=none; b=PPabeh0GwJ9awr5+Hzb+lMXqPjzzUg/07vtJ9Jq+nJ5623rwi/9O0InaTfQu8xhsY4+6/E7sLfgkeq9wZA1ydfFB7/bku3KDgE/7bKVCmhGfFx5GWC02waZU0F/Kn4RV3tsMqjc48K0py7E9Uxgl7qCmt/vpL+6GtMV5ZPqhmwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778557843; c=relaxed/simple; bh=yXM/Evon0krJIJnsSF+VpkVhLV6XwdhYouPQkxATc60=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PNhIDDse2+uaSm48RRG6DB2eaEgPIYHrITHKPAKSu3qkD+4CeHom2LHA+758kS+DjtDsBnJtW9EK1wuvODHYDkUWhEhOSOsxUaRUeupcC/2Y0pVgBK05w+bouZOjQ8WW82iSHil4A63I4oI/tpf72JeUFkTUq08yJRIPjPTKIyA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V2VKpP4L; arc=none smtp.client-ip=209.85.216.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V2VKpP4L" Received: by mail-pj1-f67.google.com with SMTP id 98e67ed59e1d1-3660daea6a5so2648623a91.1 for ; Mon, 11 May 2026 20:50:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778557842; x=1779162642; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v5udFJeK8iDZYzDB3JHZhpoCGdix8HdaGJ6c14ctwbU=; b=V2VKpP4LCZWCPQZy/fxJHQOPbTsjJqbj9hfHGdd9amBCOxzh3p81TuSoV5e7MPLUXM iLi16bVKPhnzJ3fcTU6gbpPOtFgY6dXef+z36DuPZVlDlny1OMhHTTh7LB7n98jIhCC7 hKcqmp2ZGfYa+R25jhvDLQSebrpyLzzTn8u9LLNAY7FYbpJBdrz35BoUfC+s7tNYhh3g q9Zl2mEFMQFSn6qy3UkrPlYhY+qxyLsUsUYLiY0j7e1JlQQt3OxCWhcf+n0xbuxmMhTM cvohXtiXFJaX2xZZKhpvBJBgcbpYcx20uWJfcyNwO1mNUzewMpOaNOq7aBrvX49Wu6JC c4DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778557842; x=1779162642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=v5udFJeK8iDZYzDB3JHZhpoCGdix8HdaGJ6c14ctwbU=; b=YI5WsfDGpOjylA6IWBoKrIeGrAh9Gc8inWiOHTnD/uitQboNq6B8XzTBtXy9coO3Sb GHvyzY9JCNz4oByHHdXHJ/3SQ8tKsRjT9uWFwdd2E9Hr7EIsOqO5mCOi8qsLPlZemYO2 rfmyOy4Vqsb7P7smNvybij7yZFnyl0h/QWW3XXVASUdFDLZYtpAVSMIXuabTyWcBHKGv afg2dgfWQU+PYSiMAd2Yi7vXez+qzBaBqF6LS0yE+rfQ74Vr33duJUU0/ZiP+7HDONDC uufU3eYJ8cmVOPs4Og/g3oG+fLI4k92vk4v8IgjmOdoJIJp1OQS1XsI+QsxNKamePCfz xoMw== X-Forwarded-Encrypted: i=1; AFNElJ/0D66jKMauT0Y1+1vKuE61mR0edW47vPfNMHsBOwpxsYcCjA5RiBfR52xwlA+zG0p2BmTBIq/se+/WQ2I=@vger.kernel.org X-Gm-Message-State: AOJu0YyCXZnVjf0Nol82ALrPPklexeDdQT+OykEOUGoLSoYUpP888qkJ JccC4vkX+UJmLGsGvxtAk6v+xo0Pu/eJfWb7K0rcb1Hqe/Z9vrlqOQA+bF8wQhNr X-Gm-Gg: Acq92OGmomLMOiULBH5ZpRQCFCf2p/pwkwA/+EEq9b2yUqdWKt8/1QIS6sxUlAUu7Ex XGB4o5P+SwZlsjLqfyeS3qztl4JkjAX9I7C3EETP8BkLNU2Mkh3rgv2f6rAaOoBoEzBW73l6moj AEp3nPQXvTYkmWkk7G0+ZFf6tZRa87cRrMd2wWG6uEvVftioyCrPMLBViRp5J1sOT0n0LnQ0tkw IePU/3nZd3+WyPaGd1Ex/zKWUNQvCyYT5Rukoaszjp5u2l64Ehs8Uz4hbFWNcXeHpB2Gn2M50EF 6r/gpm/5D5/1bWT/smn8SDHXnApGycRZ/2n1rqUVZavTrWAeMUoHNm6O8p+GmDcvQWIOPWLl/O2 XrZc87iH5ymjtbcsQAuCaz0WaUn2paLk1Af/YGVvyn0pEaSYRgdxhpgkJKOF/WeecNDnJ6Ov2ng dfIWtERD5/R1X1QFwFoDhFeWVixHs99rptw5VKRDZY3Z3UzHNGPsGrSP9O2YtD X-Received: by 2002:a17:90b:5783:b0:368:5367:d681 with SMTP id 98e67ed59e1d1-368536812a9mr7320694a91.10.1778557841889; Mon, 11 May 2026 20:50:41 -0700 (PDT) Received: from lima-ubuntu.hz.ali.com ([47.246.98.218]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-367d625cee7sm9389081a91.2.2026.05.11.20.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 20:50:41 -0700 (PDT) From: Qing Wang To: 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, vbabka@kernel.org, wangqing7171@gmail.com Subject: [PATCH v3] mm/slub: hold cpus_read_lock around flush_rcu_sheaves_on_cache() Date: Tue, 12 May 2026 11:50:35 +0800 Message-Id: <20260512035035.762317-1-wangqing7171@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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) { -- 2.34.1