From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 A942D47B437 for ; Mon, 11 May 2026 17:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778522101; cv=none; b=NnHnw55w2w23lXJlxsgoe68kqWIPROPK+oMcdovgfuPRCFso317D88becLS37bOH5o+hNSkZd7VXQNJt15Zkwg19uW6gx2odj2qesnny6279CItZ9ArGih8+REgoxI8Wl21XJiT5mXBTMG4sGzM2//AMLF0q/1m1qS/cto9yHKI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778522101; c=relaxed/simple; bh=RkHk7z2ygyoyi1ilNEZkRX+Ty9Jdxo0cKjCdLWv4d/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CfzlYswD4b8S+1CBA/m9mlJzRbUMatpqi9L7iOym+EEJt9QImASHzvnVvHKfr5micd3nJEFoaW9Wh60nGiGYOoKUGP37s+/tPY73VOjTY9IL3l+n3hjxOVhpDzpYrPHDMuHbiAXr1kuIZcrzrlTEUfCVJQP9Lhfc6zhhzrcMO6g= 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=O3sOBPcL; arc=none smtp.client-ip=209.85.167.42 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="O3sOBPcL" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5a884815606so4553741e87.0 for ; Mon, 11 May 2026 10:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778522098; x=1779126898; 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=HfDpEv+39iIZARqiCjGlpklYp+nlJJtKSY6Ud1S1ntc=; b=O3sOBPcL/gSNMfdxnbbG3+8C99s8vlSyT01BeGyCPngE8ZiWrf/zESoxVXGcBHzWRW 2ZrJDCKZ5ZWQI9U2cWGeS1UCzPuh45Pr/2E0Sf1qbjp0/FrwM9K7gGngwZ+97QghSdYy XIWBcphllWB22ih/ql64HtFJpP/pI9mVLHJmp2zCEJJFkwj/tzpI7gGH6GiYQwkB4+oW plFPAX9cd8l/DveEM3J0NfK4phHRUSTclZPF3wCIhxtcH62SeO6KJIZKdxBZmqyoiddQ Dud2BjkfsG6a24pZzFFKRbOvIZqbNfUv7nT3lyLAdJdCNvpCm6ryyjGN0CvBfJU1flv0 xYIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778522098; x=1779126898; 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=HfDpEv+39iIZARqiCjGlpklYp+nlJJtKSY6Ud1S1ntc=; b=Wn1awhJarcIUqn+0UJrtBxw0dfUKOZ/LKbjNZuxRr70QqF0kixxLjjcppbxZFOKDPb UMLH73tPe/NWz9WDRpOMncuj1eFRUEH+x987VCN3M67zctzPYFbt0lbEu2YOFm4QL+cn VLsRGAMduboJ8cv7t/EkYhD/3SEElpe4VYjgkRXO/ZBLkbDraFirULAIddNlcxPrueYb Qq/+J3lgdsiP3dcF3KX7aNUQeYbp+5KVY6BE3xpcAk8zOcJC6hi0eZpsvA/yy9vZZRoI 74BkkAmPMxrkaQLxIkotUBaOo2NTUfzReI383QdiOXpvuoJyWKfrwB2L5sDCPowiVfSl oZBA== X-Forwarded-Encrypted: i=1; AFNElJ/2/C7dokEfM9gVOMWO3fmLt1oOCGKwp0v0Wep1QMDTP4M7MZqQ4u4STZPai8tc2fFxYn9vViXUDGl2DEQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwoUcvBazhycpJ0TK6iygJh05NpMx1n3cV/FFm7EkKfSpTksdtK 0dabLfIfvtHjbzFphhKRcVxjS2yOu/AZKUsc67EoDyiJSxlQJz7oqipmQwRdYg== X-Gm-Gg: Acq92OEimp6xL7qW3QkXdxvWHAQoD//06Jp1zO8hYSrtLpChfuaDxaoMiHQSIvXjFFO KTG3Ktws0k/QOR4TSz1HR2sMsm2Fu+CVTw3hjG+Hs4+m0fn3y5v1unJWy09FF+DzvFpOyaZj82y JhHMHiEqxqfMwplr6c6M+kBAL0xuXMmmXdc+5pox6/TZBOTD+gvmLHpFhsPHXi1XI2H4tYTq5Zv +QjCqlEZ4ZgmJEhRZnUPyHfaqqadX3lvdkIcHfN2m7sFOEojvEooKApDF+e0FG5SrSTQXWTFYi2 ucNlNcadS+erBeJ2htnELEm/5geZFGcj+fKetGHYW2GZ2PPovZL4rHi6ZMBg6aZRHaciUYD+wJL LOX+XKFtpHAIn7ZNCKwMeP+9SEGtDzKvnucOuEpkfJPPs7Vl1GLvAUdO2TcxafsUZxhuYV1iEJx qJ5GNYILDW92mC7xEnEfaQ2u8hnA== X-Received: by 2002:a05:6512:401f:b0:5a2:843f:5800 with SMTP id 2adb3069b0e04-5a887cde847mr8139783e87.23.1778522097566; Mon, 11 May 2026 10:54:57 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-393f614a5f4sm28968891fa.33.2026.05.11.10.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 10:54:57 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: "Paul E . McKenney" , Joel Fernandes , Frederic Weisbecker , Boqun Feng Cc: RCU , LKML , Uladzislau Rezki , Maxim Mikityanskiy Subject: [PATCH -next v1 10/12] rcu: Document rcu_access_pointer() feeding into cmpxchg() Date: Mon, 11 May 2026 19:54:46 +0200 Message-ID: <20260511175448.153326-11-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260511175448.153326-1-urezki@gmail.com> References: <20260511175448.153326-1-urezki@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 From: "Paul E. McKenney" This commit documents the rcu_access_pointer() use case for fetching the old value of an RCU-protected pointer within a lockless updater for use by an atomic cmpxchg() operation. Reported-by: Maxim Mikityanskiy Signed-off-by: Paul E. McKenney Signed-off-by: Uladzislau Rezki (Sony) --- include/linux/rcupdate.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index bfa765132de8..5e95acc33989 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -592,11 +592,13 @@ context_unsafe( \ * lockdep checks for being in an RCU read-side critical section. This is * useful when the value of this pointer is accessed, but the pointer is * not dereferenced, for example, when testing an RCU-protected pointer - * against NULL. Although rcu_access_pointer() may also be used in cases - * where update-side locks prevent the value of the pointer from changing, - * you should instead use rcu_dereference_protected() for this use case. - * Within an RCU read-side critical section, there is little reason to - * use rcu_access_pointer(). + * against NULL. Within an RCU read-side critical section, there is little + * reason to use rcu_access_pointer(). Although rcu_access_pointer() may + * also be used in cases where update-side locks prevent the value of the + * pointer from changing, you should instead use rcu_dereference_protected() + * for this use case. It is also permissible to use rcu_access_pointer() + * within lockless updaters to obtain the old value for an atomic operation, + * for example, for cmpxchg(). * * It is usually best to test the rcu_access_pointer() return value * directly in order to avoid accidental dereferences being introduced -- 2.47.3