From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj2-f13.google.com (mail-pj2-f13.google.com [74.125.227.141]) (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 B9C864FE2D7 for ; Fri, 2 Oct 2026 17:10:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.141 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790961040; cv=none; b=aenwtlSBn4iiJJ0JLqREcxA21vxf1lR88MOc6mJGc1odULntQh12bQWbBd45j3tDUlH3sIKQ0vxa6EQsO7UAZ6rjdpCxHj5v/iONmEZi0EPGjJnLHwjegjrWHmQgnnMnq6/hFKFRwCHyUgOuWcXD2VJlnTTinoKW1EtOLY/tk4M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790961040; c=relaxed/simple; bh=efWEPmj0Vc93yD7ksoAs6CSfVahXXbn88QWzVR/N9r8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QzhLR2L4h/WVQnDX3vFpeVnhSNPAl6A0SgogIOxgRVyoUbdGWs2nlv7jatqN+oabnQBn1z+Ube52EOUQ2iAcrG1Fl1B41jrJMguiitqGVYIwekXE1bC7Q7ThVhL14npV8S8aValM0QPN4l4F+L3P6JejHLGImudZMmWA7ogayuM= 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=Zc9hwhi/; arc=none smtp.client-ip=74.125.227.141 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="Zc9hwhi/" Received: by mail-pj2-f13.google.com with SMTP id d9443c01a7336-2dd88a115ebso45843765ad.2 for ; Fri, 02 Oct 2026 10:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790961030; x=1791565830; 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:content-type; bh=3aHGH1btHKyA9bPipQiTAK39EsUtmJmoqAt6kx41g10=; b=Zc9hwhi/muWpKPb1YQkRv8j3Lrxz8qHYxUikCn/vBZfDAga5Wfy6Bs323IcaMvkAlS uzFxtE0O/KKs3AHvUu4F+bxkBfoN230osEkRbt8rtVZbCXMzDwXY6Y9ikeKjfoXVxSZ/ QWM1d+bYreYbQhAbZQbuOjOw/k4iEskLszWcXcoZNDs4otuZI/GjJlvECtwUvcMol3QT Tt6GBI/rYsNEChdK5Y0VTw9geNjQIr7E8W6I3XEP70hnIslyxCugqDb8LhsTS7vFwpDt Ue2cj4aiYboVa8od+cbZrNIgPWXqLQJ7JB6qreoGgRgjSCg9YurBUpC1u1d1iEzr4jpA gQWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790961030; x=1791565830; 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:content-type; bh=3aHGH1btHKyA9bPipQiTAK39EsUtmJmoqAt6kx41g10=; b=Xr6a654ykQXbmATbpE8eryFU2TY5lo8Ongamh0Ms0kFk2GGc3XAHO3FN1kSklPZQ5f FtkcA3ASGLz4tbUbzrcDNxXDZlvyp6AHJbaXXjWC5RorVbQ6XPNOZEDk5bjHrSfWH0JX /3Y7e5nOJfzBE2Rr4VguEQmk575KUt+3+4vak1cnTnAl/3gkg0lMUUU87zsvUGfIiP/B I4PIKphxze+IXW9LBsGUfPhy+DVsp3gP22niXR8VvLlkN7mXkFuWiI6tN2sS8l+l7BPb tw+QffUf6ayQUHAiyolyKyhu/ph4ULkfDw7Rf1ilwCAtwe0ivJDKp9tKgv7dTM7/bJpi xdIw== X-Forwarded-Encrypted: i=1; AKwUvByuZG9wP9giLM3EvAg/F/Iyoi2ikMQjKNyBV7toi6cjjb4D5ip7hsIxfFEg+bCYr5BScNmSDx96CMh+Dow=@vger.kernel.org X-Gm-Message-State: AFq9FYJNh+XpOno+tC11mTyE2RUD4x9ba8JDBia0GekWgJqN6aX4KWPU M6aD7KykSmFzKqhG9uJx0yDGcP0LjNwCwWPXBycR8CrAFks5DKEFkCbK X-Gm-Gg: AYBFou0uwm7YefnW5q54ohxwuMLZihv39x8yqYyZqwTB4flGd4tGUslzlYG6eu+7DSx jQXcIn6DXHNq54FwlYBD7hfqQjtYypPLGz3w6PXLLNV5us2pWgVPSoum+mba+2eX3bnlK5XptZ0 +owa/8BAa1rxmJlX3Q96DiFuOo01txc+/8+BBhQWcLnjJrhEkYsjyBupXREGol6DEliX35GFe10 0cMOz3Am0fwooVp/4sIqBdnh75rYJdCjoQih5Ca6a9wGJyg44TAnWPg9FepNlAuFdd/KW9Ai3yV ibJvM89vDmY/SkgudjTU+Xjk721NdLpxo5jc91ETlbYrc0TdXnHMje9ib2d5YgA+4u6oR3MARjZ Q23/BvO0SGAv1GWG1+i9JvhjQpKkQLFozAMAweDhzY7zrvxzfgeCDK2PuPpFDz6kPHIMIsr87jn fMtlZw6drkmUXsxfM6ComY6/xnXHW0Gzfo8J7TxKgEg5zq4PTVQOTDtGXQrNFXb5n9lXa6xgMl0 0O0slqfzbbVlckcSA== X-Received: by 2002:a17:90a:d2c8:b0:3a2:b70b:9cc3 with SMTP id 98e67ed59e1d1-3a6ce5a1ad5mr3213022a91.8.1790961029453; Fri, 02 Oct 2026 10:10:29 -0700 (PDT) Received: from kernel.tail6741c6.ts.net ([185.220.238.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a7024d0f5fsm1597719a91.0.2026.10.02.10.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2026 10:10:29 -0700 (PDT) From: Kunwu Chan To: paulmck@kernel.org, corbet@lwn.net, mingo@redhat.com, frederic@kernel.org, neeraj.upadhyay@kernel.org, josh@joshtriplett.org, urezki@gmail.com, dave@stgolabs.net, lianux.mm@gmail.com Cc: stern@rowland.harvard.edu, parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun@kernel.org, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, dlustig@nvidia.com, joelagnelf@nvidia.com, skhan@linuxfoundation.org, rdunlap@infradead.org, longman@redhat.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, qiang.zhang@linux.dev, kunwu.chan@gmail.com, brads@mainlining.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, lkmm@lists.linux.dev, linux-doc@vger.kernel.org, rcu@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH RFC v2 08/15] locking/lockdep: use hazptr to wait for dynamic key lookups Date: Sat, 3 Oct 2026 01:08:40 +0800 Message-ID: <20261002170847.3653663-9-kunwu.chan@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261002170847.3653663-1-kunwu.chan@gmail.com> References: <20261002170847.3653663-1-kunwu.chan@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit lockdep_unregister_key() waits for is_dynamic_key() callers with synchronize_rcu_expedited(), which requires system-wide coordination. Make is_dynamic_key() protect the hash bucket with a hazard pointer and use hazptr_synchronize() to wait for traversals of that bucket. The hash bucket returned by keyhashentry() has a stable address, so it can be used as the hazptr synchronization target. Keep the key hashlist lifetime RCU-based with hlist_del_rcu() and call_rcu(). Protect the traversal with the hazptr scoped_guard() added earlier in this series. This adapts the lockdep use case from Boqun Feng's shazptr series to the current hazptr API. Link: https://lore.kernel.org/lkml/20250625031101.12555-1-boqun.feng@gmail.com/ Signed-off-by: Kunwu Chan --- kernel/locking/lockdep.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index c56a7f91d72e..d1ce5ace7fbf 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -58,6 +58,7 @@ #include #include #include +#include #include @@ -1280,14 +1281,19 @@ static bool is_dynamic_key(const struct lock_class_key *key) hash_head = keyhashentry(key); - rcu_read_lock(); - hlist_for_each_entry_rcu(k, hash_head, hash_entry) { - if (k == key) { - found = true; - break; + { + struct hazptr_ctx ctx; + void *bucket = hash_head; + + scoped_guard(hazptr, &ctx, &bucket) { + hlist_for_each_entry_rcu(k, hash_head, hash_entry, 1) { + if (k == key) { + found = true; + break; + } + } } } - rcu_read_unlock(); return found; } @@ -6683,11 +6689,10 @@ void lockdep_unregister_key(struct lock_class_key *key) * * Some operations like __qdisc_destroy() will call this in a debug * kernel, and the network traffic is disabled while waiting, hence - * the delay of the wait matters in debugging cases. Currently use a - * synchronize_rcu_expedited() to speed up the wait at the cost of - * system IPIs. TODO: Replace RCU with hazptr for this. + * the delay of the wait matters in debugging cases. Replace the + * expedited RCU wait with hazptr_synchronize(). */ - synchronize_rcu_expedited(); + hazptr_synchronize(keyhashentry(key)); } EXPORT_SYMBOL_GPL(lockdep_unregister_key); -- 2.43.0