From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 31E6A3B95E3 for ; Tue, 19 May 2026 19:45:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779219935; cv=none; b=osxejDx7SmCwLMAUf6Lkzrhkk0p3oDiN0h2rhE9xLl07xtOQ0dwgeeSEWhi0XkYv9R8O0AjMl1M4M64LkD31tsH6ogR5pI1A3PWioVeqHV8XeLuiJ5geWKjRleBsq7/evC7ox3QvCaqdmJ2ikEjErsV3ykISR+vlobnAVPoXLBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779219935; c=relaxed/simple; bh=RkHk7z2ygyoyi1ilNEZkRX+Ty9Jdxo0cKjCdLWv4d/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sYUdZySIyhnLJ+swBAWfKyWti9ECQWsKLJS6EPV3zrMJxHxioFLoGrdNuvgVVLyliGW6A2ui5hOXV7cInx9DHAftX2TwgSLGTYMr+cupL+Ln7wckZap1noB4yO6ly1L2x6CPhYnikwzGar+Lb7N8Td42g9elD49insnqYgSXyBg= 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=oo/cVKbO; arc=none smtp.client-ip=209.85.208.180 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="oo/cVKbO" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-392445f11c5so44288041fa.1 for ; Tue, 19 May 2026 12:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779219931; x=1779824731; 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=oo/cVKbOwuQ9VzCH0JHE1tU30g9CZHYXv/oAQzJOAFFxCanZ0Rj6BrHDbzGkGWNQtl pzqK3l1Y2WOc7adhC/LJ0xGeVUnEa/Fq4XEwS1YcnKaUIssBN8J/IVZB5vPPzHBdetbX mOrwQ7sxRinxJ4j4cm2/MmPnKDq5byeQ5k1CsyDXIzeuPiheMeQR0y71uUsQ1UYElB80 jjZESSdhZTNv6nfD9NnadsUVPdpSXbSuBKgCytmXqvLXD9h39AsEd8XkEWGNiyoGaVrB sfaS4gdpNu7iZQeDswTSXS1lu2jxHiOxwnWJ+JULpJbmtrnlsVzsO8w5oRWRZ+NDpK0W yFxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779219931; x=1779824731; 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=YMoPs2J9zb+KOG/9cyr4SS6Ew6mhwGO8TUrBkv8XcXikb2aNYWxuUTaPfw3erCv2y9 WSBirdA37Q3dynDuwDIh/yLGHV9AH4Yo7TIW3/cqZpSFXEPFzQfJcLCBPbxT0HuCGYS9 wD5vEjE3g7+vADQTjFQDJKNMFYeYgWOAo0/vXU69p+YKjWaeIOVG7BOyuMwrN2fXSrOE gdvWS19YhdgxzyPHNaz1gg2jmzkT+igI4r0uYSfkZ4A/xD/Ck5yASPSMTQ9NTaD6C0kg GoJXEmQKsB68Gv5cKHsqGqtu49IJGwuISeHzpKelfdfmLQYlBVjhN1CSfjpUv1ohk2a8 Pisg== X-Forwarded-Encrypted: i=1; AFNElJ981hVwuDbUDMw90PL2gduJsz+zYmz2znlp3BfB93jsYYjbgFGA9KauMjMtniLhIBFVyNa2htPwPbOiyPs=@vger.kernel.org X-Gm-Message-State: AOJu0YyXCp0VNr26iEnGDbj2BzaKKq581WYJLqgRgb1n/KYpZH4T/U3w RreiJEuvbvaRF8denxAzBIKilJaM0m2AMOTdoyCftcfx1JO7Fv1Ew6FX X-Gm-Gg: Acq92OHip3cwbl7YHOlInbMuyicWwTV0ME31ev4jz5w7xmYBepFUihez1Cr72sYu6y9 1yVKBCOdfFJeSxF2WCBSvyd/1p+yWpKrqUii2eYmnW6w7EZgFuC3hafyX2I6PcjGlHbfNhzDGc9 3FDN83qx+tVAbCY6vk0CPV42JEHdJW7VY6ow8ISxExfRlT6RZvf+LkdrH7P55OhfvrNxWC8yi/K k6Nu/D8cZX/x0wZn8VkxLoVYS4bnCOXjUm4k+sI1Chtn7T/KW9KZF4OV3rfAKIacA0hYdI2tN+X 3sRl8Ud+te8O0izG/JyqRKl5mAq4A8QmmHXLdiEOq2o59QEuEJwp3H+xcmttFDH+45g14M8RXZn DZ0SIcIN9nRuJtiU1u5yiO4yDf2pyno6XqIIcgmknFi/7sWwNnLrOh5E1ivam9Ktzhn1ckiYYL6 m1ejJ18higMsFuaUA= X-Received: by 2002:a2e:bccb:0:b0:393:7f7a:4047 with SMTP id 38308e7fff4ca-3945b60917amr73751851fa.16.1779219931313; Tue, 19 May 2026 12:45:31 -0700 (PDT) Received: from localhost.localdomain ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3958827ec3fsm23558761fa.9.2026.05.19.12.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 12:45:31 -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 v2 09/11] rcu: Document rcu_access_pointer() feeding into cmpxchg() Date: Tue, 19 May 2026 21:45:22 +0200 Message-ID: <20260519194524.158515-10-urezki@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260519194524.158515-1-urezki@gmail.com> References: <20260519194524.158515-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