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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 434CFCF8547 for ; Thu, 3 Oct 2024 00:25:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF80E6B041D; Wed, 2 Oct 2024 20:25:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA7646B04EA; Wed, 2 Oct 2024 20:25:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FAED6B04EB; Wed, 2 Oct 2024 20:25:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 596596B041D for ; Wed, 2 Oct 2024 20:25:43 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B4D3B1A07D9 for ; Thu, 3 Oct 2024 00:25:42 +0000 (UTC) X-FDA: 82630397724.01.2E1A9D3 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by imf23.hostedemail.com (Postfix) with ESMTP id 8C2A0140006 for ; Thu, 3 Oct 2024 00:25:39 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="fBN8DH/m"; spf=pass (imf23.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.47 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727915099; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fdmBFtAuO1xuuA1xbvQwfI32coSRJZlqI5hdaMf3qvc=; b=2zipXgTFnz4ztfNVg6+DVNPuztZEJskcnw05nNfjK2C+s3mU2w4pDaAyv0wUSG8BmmULE+ vQZOUV6kwvM0Cg0ggeAqasDN9a4MQFmAXjLIYDrj34dcTUrhFRM7aTmfw2J+Sseqi5Ky/t o/fsG98s0pAvoPAbFwFQyLXErQf545M= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="fBN8DH/m"; spf=pass (imf23.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.47 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727915099; a=rsa-sha256; cv=none; b=FsZKfOIg4091W+MgyUAVQwSEgd5OJYmf0SMQ8KPvhWCcndsKIz2TK5Qqr20YXs1FzpyXCU 7h6SOQK85ImQ1fE5nQEuCW17l1+RzSA135hb1MutGxNZnlU2/dqjOS9RkPqcbJBnm01eiq o0gGhEC4ijqQk9hMNxreKpeJEhN3eho= Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6cb2cba60e1so2606946d6.3 for ; Wed, 02 Oct 2024 17:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727915138; x=1728519938; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=fdmBFtAuO1xuuA1xbvQwfI32coSRJZlqI5hdaMf3qvc=; b=fBN8DH/mrhW84z1mQ9lwjebE6JPoC/ZSixJmQGVODEoT79efgiv2NmwuHT3YNVKnS/ UO8eM2OmuaxjwHDiuu0MLfNAMwHW6scytCsEP/cZ3Oc4FtuZT+uA+4ghWD2WjzxG/O3G aMDMbJarYQM3nfaTGxZBv5QD/NgWXLkUTPuT3dsUJCCY3cs2yDqHrh17Tb5AiftarSh+ t8GH8J4iztv3WBYARoM3E3L5+xcHmlJ9K3xb8cdPAtLhF6Is/aI+jAJ04vAYR56Mhd0W IR1RE4BHKfGmyVwVKu8yXk7IdO6o1uSaTk403CS6rdvqRNdsnKqUr7Mdx6+Cdpw9jJRD vPjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727915138; x=1728519938; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fdmBFtAuO1xuuA1xbvQwfI32coSRJZlqI5hdaMf3qvc=; b=cZaV4xvxO1dVyt7jyEDulKOl5DPGQIluPrvU1JlDPIf/oIDVZYWnIF3MbdXhQYsaH+ v4KwM81JgJQZSqPHGzLvzyy6zA84VtYtOS+099iSvF8qKD/OSwpZ7xtG28JIkkgpRIs6 ESotZIbz6prDepTobgaITtOf7OdcomxvDFzzP9BheWSr0Cu1Ng/I+ckCuhYxgccykqFO yZKT/p6Q/YZqd7MeYIGDJsy/fpCTk5hP1NH3WgCd9oxGVRZ+290pgI7Kn2XvI09qmU0k +CmJCUIBaeootd1A/VvBzF1kqJkA4hPMeuzrDfFnE43J+JsQhiJpMgxq/QsfPwd0d68F fLCQ== X-Forwarded-Encrypted: i=1; AJvYcCWzlv1oL38wB5arwrCFgAcfLd1Z5VHic0OtMcM9cc1ieif56bAODuncqDwh5GdozMg5VWwBvHdueA==@kvack.org X-Gm-Message-State: AOJu0Ywceb+P/L/ZWvWhjm6TAywl5FW07FifgLAPxa4Gu4pDWpNgEpuK f4YY5xnNdA0msEh5HjQOD912aKdsosEPE2HDuDhTApJzVsksJoYO X-Google-Smtp-Source: AGHT+IGnKF3a9DMxLqjSehWRMwSs/R7LCv/5apMPogn0UWIcgsZAqe38g270iV/q54p8i8gQNXFtXg== X-Received: by 2002:a05:6214:1932:b0:6cb:8266:bef1 with SMTP id 6a1803df08f44-6cb8266c00emr59910906d6.0.1727915138385; Wed, 02 Oct 2024 17:25:38 -0700 (PDT) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45d9299ec6bsm26281cf.53.2024.10.02.17.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 17:25:37 -0700 (PDT) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfauth.phl.internal (Postfix) with ESMTP id 061921200068; Wed, 2 Oct 2024 20:25:37 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Wed, 02 Oct 2024 20:25:37 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvtddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrd gtohhmqeenucggtffrrghtthgvrhhnpefhteffveeuhefhveefgfehvdejkeefuefgfeeg vedtheegvdelueevvdegteffueenucffohhmrghinhepkhgvrhhnvghlrdhorhhgpdhlph gtrdgvvhgvnhhtshenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeile dvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgt ohhmsehfihigmhgvrdhnrghmvgdpnhgspghrtghpthhtohepfeefpdhmohguvgepshhmth hpohhuthdprhgtphhtthhopehmrghthhhivghurdguvghsnhhohigvrhhssegvfhhfihgt ihhoshdrtghomhdprhgtphhtthhopehtohhrvhgrlhgusheslhhinhhugidqfhhouhhnug grthhiohhnrdhorhhgpdhrtghpthhtoheprghkphhmsehlihhnuhigqdhfohhunhgurght ihhonhdrohhrghdprhgtphhtthhopehpvghtvghriiesihhnfhhrrgguvggrugdrohhrgh dprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhr ghdprhgtphhtthhopehnphhighhgihhnsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmh hpvgesvghllhgvrhhmrghnrdhiugdrrghupdhrtghpthhtohepghhrvghgkhhhsehlihhn uhigfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtohepsghighgvrghshieslhhinh huthhrohhnihigrdguvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Oct 2024 20:25:36 -0400 (EDT) Date: Wed, 2 Oct 2024 17:24:31 -0700 From: Boqun Feng To: Mathieu Desnoyers Cc: Linus Torvalds , Andrew Morton , Peter Zijlstra , linux-kernel@vger.kernel.org, Nicholas Piggin , Michael Ellerman , Greg Kroah-Hartman , Sebastian Andrzej Siewior , "Paul E. McKenney" , Will Deacon , Alan Stern , John Stultz , Neeraj Upadhyay , Frederic Weisbecker , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Lai Jiangshan , Zqiang , Ingo Molnar , Waiman Long , Mark Rutland , Thomas Gleixner , Vlastimil Babka , maged.michael@gmail.com, Mateusz Guzik , Jonas Oberhauser , rcu@vger.kernel.org, linux-mm@kvack.org, lkmm@lists.linux.dev Subject: Re: [RFC PATCH 3/4] hp: Implement Hazard Pointers Message-ID: References: <20241002010205.1341915-1-mathieu.desnoyers@efficios.com> <20241002010205.1341915-4-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241002010205.1341915-4-mathieu.desnoyers@efficios.com> X-Rspam-User: X-Stat-Signature: pbofuzq8fepmt3a3unkpuaamdhy6fkkw X-Rspamd-Queue-Id: 8C2A0140006 X-Rspamd-Server: rspam11 X-HE-Tag: 1727915139-91143 X-HE-Meta: U2FsdGVkX1+IMniL/i2tzsLKQLlocJZBzSYaZqE7HrwCqH9k9ZgyML4u3NM/CIkC2yO/b/qTQ49zq3bTUpxfRn+sW03w4gMR2IBTSS/Hfd3k7766gLRdz3WaqHfWvv02EgmIU5+A1cbIJAJcWXoTg/yD84FE3Ng0XppwiIk1cUrO9oTdIgziqFLbLBk6bb+lB/CgNEBL3DdJLBaBtGKTH3BahDQFF7C1agseUPdFZ8eP27AMSDfPh2OQET6oJqxfRq06VlBhhkqd0ZfPnV54/qQD12zdNOeSjtNJFJ1ypmCD8QALDFoTMcRVzjuSif/gbKvB6QLYWGx0GCP/y9AR6DVE4eMNB4mUsp5g7fre6gIczMiX10cRM1KPZjDJa3PvMkZyAgT5AazSVekS2mgRAm/pO/nR94yyq8qeGOFVb1UkE3O9eNUO4FVSSUTM7NlwdaMlE4mvt5U7rCUT6pW3fk8kJPkg2hkvpB7hOZ79cPHql7nEzvEM7rrx3t8Gi5HR0i5j1hgKW3/yG5rW6vyupRwc+vJ6WD4kNowDYIHlH1VC0byVu3TZWua9fhltmTmYEYv1yUpsiTsZQI0BZWh6N4YaIuHS/Iv/5r/jrHBPu2aosatT/x2QW8Sjclgc40kXOzFevoUdNVpG458uZJEZIKcXR5tk4kam/R5gxpKlRLkYKwzjxz1fcvalxZ1C/p+f9QQTjMY7jLFWppIRoL6e4+xcw5Pyhn7XLe/yvQ+qSaRwhlRk6DCjqU2kvt+fyHYSh43ATjUTxBoM2Gmu2sZne7x0qGYCJ0kdTjW2wcctj0jHQIChfw4rV992D8dF0Xw8hYm4Io1PZKA6jZ2WOpOgsBptSbBCcqEviFVL63N6mwN8z7nF2pGBUBDi9wVxP8L1XKxEJFgV0+SJyH6YNMdPwWh4LhQ/Zq9NAUl8/ujZneh0BN+tNRypNDTSNsvbjfiY1KSWwEKnYwtGHIciUl7 EyeMIhWL rFHpKsYot2X7IIuZ2uJIx3tqEtFYpB4chzK/AECI2wTGEwDmp5750sBc4IyBtcM/D4yzk2HLyMTmMmEV2YA9tPloS2KHoQU3Z1oOrEdVHUU6edcM+VZhf+GRWzwHXrDlQdOZChW90cU07Gm/foAawFQsUwKBtY5e8fT2/hAewCOto5tcBUx9KlvGRtDasua3TlvEaTaE/mVyKbmVggYK+oxX7pKasjJxNSNeuGTci46fyXYxY0QkKIhdQ6Z9OjI05+oUaoduLuECZqptN0GeAHvQ8ijv8wPNtdCHh1Te4e2Uj6is8RIE/5ROfY1v9kIG+WTJm674RB+JCf+UCwF65Ok/oroYmNixIyRp4OoiOcVl3cCs8ma+S04nLtFdvKh/SgsDyzdQDHBfwLoCVnDo9AWbvmUkoxDURHWrIsM7NH+v7xsysq3XCEw5FuxNEvuUK2//LTl3+liZVqs2feST7r7ZCIlFyWWfBwDDyDT64V09Jwz9LFVdX6cQpX47DQK1fQMLAAAo071iq83pqaVt06HQnMzfrD0o5UK3DvTbQwVjBe1w1a57JRl7CS8EroyuCMsCcYD34Y3/GIMGg7/l+KFyi0PXTaYW/i0HcUtkwnpCInj7du6beSPR01FLhzGJ42be07/UqriD7oscBanl0gD1AagzWlYaF6mNstjHhqyd0Br1h/caTdeomQzjK9oLLXus3+IEhw6tAKdb67MyCj8zjFR9KDvftg8enQZQiOnjsK+e6ddaWv3srcxdWaVarkNQqaWCSosuIsN0R/2w3ydXXZo6FfFdk4JzQKnQ4glXEfqOYjUPV2m8UtkK0P1wxzjnKvMXnfWJwnp8yqgfL4Zp52+RCY53YlTxpBt8P6YNapQ/02jkg4l8KwQzwUu8eF7AeBDZWl0ApslWfS6I6z40yrs+1NcHshJwhwt2rZ4BaEIjy6aA8/59wUasScJmADZf/zIj4IiPcPXbUfT40bHEEx0Er 4FHPzXB0 R7s1d/a86Vgnsbf0vNLU6ctGF4uAINIVNPWvsj4ADB1q7OqUl12MMnfjOA6ZPWkcmdosm7A4pdQJnwQ8yWB1+FnpzapijxLd2/p8v/d70g+GTCh1IiZoziR8MOf/f9wJNrNFY6zteif+bQ3a3R9lJiD1SIXVKXE+DhObLOVojNx6mz7rMvciQn7dICetsE1OmDTWklVzlyDWqFEDEiDWxBQzDw5KvPhc 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: List-Subscribe: List-Unsubscribe: On Tue, Oct 01, 2024 at 09:02:04PM -0400, Mathieu Desnoyers wrote: > This API provides existence guarantees of objects through Hazard > Pointers (HP). > > Each HP domain defines a fixed number of hazard pointer slots (nr_cpus) > across the entire system. > > Its main benefit over RCU is that it allows fast reclaim of > HP-protected pointers without needing to wait for a grace period. > > It also allows the hazard pointer scan to call a user-defined callback > to retire a hazard pointer slot immediately if needed. This callback > may, for instance, issue an IPI to the relevant CPU. > > There are a few possible use-cases for this in the Linux kernel: > > - Improve performance of mm_count by replacing lazy active mm by HP. > - Guarantee object existence on pointer dereference to use refcount: > - replace locking used for that purpose in some drivers, > - replace RCU + inc_not_zero pattern, > - rtmutex: Improve situations where locks need to be taken in > reverse dependency chain order by guaranteeing existence of > first and second locks in traversal order, allowing them to be > locked in the correct order (which is reverse from traversal > order) rather than try-lock+retry on nested lock. > > References: > > [1]: M. M. Michael, "Hazard pointers: safe memory reclamation for > lock-free objects," in IEEE Transactions on Parallel and > Distributed Systems, vol. 15, no. 6, pp. 491-504, June 2004 > > Link: https://lore.kernel.org/lkml/j3scdl5iymjlxavomgc6u5ndg3svhab6ga23dr36o4f5mt333w@7xslvq6b6hmv/ > Link: https://lpc.events/event/18/contributions/1731/ > Signed-off-by: Mathieu Desnoyers > Cc: Nicholas Piggin > Cc: Michael Ellerman > Cc: Greg Kroah-Hartman > Cc: Sebastian Andrzej Siewior > Cc: "Paul E. McKenney" > Cc: Will Deacon > Cc: Peter Zijlstra > Cc: Boqun Feng > Cc: Alan Stern > Cc: John Stultz > Cc: Neeraj Upadhyay > Cc: Linus Torvalds > Cc: Andrew Morton > Cc: Boqun Feng > Cc: Frederic Weisbecker > Cc: Joel Fernandes > Cc: Josh Triplett > Cc: Uladzislau Rezki > Cc: Steven Rostedt > Cc: Lai Jiangshan > Cc: Zqiang > Cc: Ingo Molnar > Cc: Waiman Long > Cc: Mark Rutland > Cc: Thomas Gleixner > Cc: Vlastimil Babka > Cc: maged.michael@gmail.com > Cc: Mateusz Guzik > Cc: Jonas Oberhauser > Cc: rcu@vger.kernel.org > Cc: linux-mm@kvack.org > Cc: lkmm@lists.linux.dev > --- > include/linux/hp.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ > kernel/Makefile | 2 +- > kernel/hp.c | 46 ++++++++++++++ > 3 files changed, 201 insertions(+), 1 deletion(-) > create mode 100644 include/linux/hp.h > create mode 100644 kernel/hp.c > > diff --git a/include/linux/hp.h b/include/linux/hp.h > new file mode 100644 > index 000000000000..929e8685a0fd > --- /dev/null > +++ b/include/linux/hp.h > @@ -0,0 +1,154 @@ > +// SPDX-FileCopyrightText: 2024 Mathieu Desnoyers > +// > +// SPDX-License-Identifier: LGPL-2.1-or-later > + > +#ifndef _LINUX_HP_H > +#define _LINUX_HP_H > + > +/* > + * HP: Hazard Pointers > + * > + * This API provides existence guarantees of objects through hazard > + * pointers. > + * > + * It uses a fixed number of hazard pointer slots (nr_cpus) across the > + * entire system for each HP domain. > + * > + * Its main benefit over RCU is that it allows fast reclaim of > + * HP-protected pointers without needing to wait for a grace period. > + * > + * It also allows the hazard pointer scan to call a user-defined callback > + * to retire a hazard pointer slot immediately if needed. This callback > + * may, for instance, issue an IPI to the relevant CPU. > + * > + * References: > + * > + * [1]: M. M. Michael, "Hazard pointers: safe memory reclamation for > + * lock-free objects," in IEEE Transactions on Parallel and > + * Distributed Systems, vol. 15, no. 6, pp. 491-504, June 2004 > + */ > + > +#include > + > +/* > + * Hazard pointer slot. > + */ > +struct hp_slot { > + void *addr; > +}; > + > +/* > + * Hazard pointer context, returned by hp_use(). > + */ > +struct hp_ctx { > + struct hp_slot *slot; > + void *addr; > +}; > + > +/* > + * hp_scan: Scan hazard pointer domain for @addr. > + * > + * Scan hazard pointer domain for @addr. > + * If @retire_cb is NULL, wait to observe that each slot contains a value > + * that differs from @addr. > + * If @retire_cb is non-NULL, invoke @callback for each slot containing > + * @addr. > + */ > +void hp_scan(struct hp_slot __percpu *percpu_slots, void *addr, > + void (*retire_cb)(int cpu, struct hp_slot *slot, void *addr)); > + > +/* Get the hazard pointer context address (may be NULL). */ > +static inline > +void *hp_ctx_addr(struct hp_ctx ctx) > +{ > + return ctx.addr; > +} > + > +/* > + * hp_allocate: Allocate a hazard pointer. > + * > + * Allocate a hazard pointer slot for @addr. The object existence should > + * be guaranteed by the caller. > + * > + * Returns a hazard pointer context. > + */ > +static inline > +struct hp_ctx hp_allocate(struct hp_slot __percpu *percpu_slots, void *addr) > +{ > + struct hp_slot *slot; > + struct hp_ctx ctx; > + > + if (!addr) > + goto fail; > + slot = this_cpu_ptr(percpu_slots); Are you assuming this is called with preemption disabled? Otherwise, there could two threads picking up the same hazard pointer slot on one CPU, > + /* > + * A single hazard pointer slot per CPU is available currently. > + * Other hazard pointer domains can eventually have a different > + * configuration. > + */ > + if (READ_ONCE(slot->addr)) > + goto fail; .. and they could both read an empty slot, and both think they successfully protect the objects, which could be different objects. Or am I missing something subtle here? > + WRITE_ONCE(slot->addr, addr); /* Store B */ > + ctx.slot = slot; > + ctx.addr = addr; > + return ctx; > + > +fail: > + ctx.slot = NULL; > + ctx.addr = NULL; > + return ctx; > +} > + > +/* > + * hp_dereference_allocate: Dereference and allocate a hazard pointer. > + * > + * Returns a hazard pointer context. > + */ > +static inline > +struct hp_ctx hp_dereference_allocate(struct hp_slot __percpu *percpu_slots, void * const * addr_p) > +{ > + struct hp_slot *slot; > + void *addr, *addr2; > + struct hp_ctx ctx; > + > + addr = READ_ONCE(*addr_p); > +retry: > + ctx = hp_allocate(percpu_slots, addr); > + if (!hp_ctx_addr(ctx)) > + goto fail; > + /* Memory ordering: Store B before Load A. */ > + smp_mb(); > + /* > + * Use RCU dereference without lockdep checks, because > + * lockdep is not aware of HP guarantees. > + */ > + addr2 = rcu_access_pointer(*addr_p); /* Load A */ Why rcu_access_pointer() instead of READ_ONCE()? Because you want to mark the head of address dependency? Regards, Boqun > + /* > + * If @addr_p content has changed since the first load, > + * clear the hazard pointer and try again. > + */ > + if (!ptr_eq(addr2, addr)) { > + WRITE_ONCE(slot->addr, NULL); > + if (!addr2) > + goto fail; > + addr = addr2; > + goto retry; > + } > + ctx.slot = slot; > + ctx.addr = addr2; > + return ctx; > + > +fail: > + ctx.slot = NULL; > + ctx.addr = NULL; > + return ctx; > +} > + [...]