From nobody Sun Feb 8 06:04:45 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 8417E321421 for ; Wed, 31 Dec 2025 12:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183761; cv=none; b=BxGIb+sS2Vv3rh8ETXt7cXqudZR9qjg0p2MXF2YEV2te0kPeOlQDBG27LeMaIwwuiwmNdVJqX5nHmpVsiLtLXSrI3NgRF3I5D69Hd0eN0JHAkIZ/ZHoBjgY1DYrP3fUxFCz+9PXaAlaZga6+mwlgrdEG4r7oIIv+wjhRCItdoic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183761; c=relaxed/simple; bh=ho7sEa3sHiw4JAsNigwc6kC7aT+CIvKjmsF0WqyxYeE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aAfQ3lQYJhTL7qT+/4Tuph1o5z2f+NHBe5/2G0B539zFgGIWq02/Kwt5lx5CBByNGF4P/5Yjkoyxy9o4g0/0I47Q6qgi8Mr1otqM5Gz4b0+8mwVKF9Pn+5K8+zWrEAPGklJpUNqglaYewjZqXQXug+aTnvElppBE7TvqmfqRBV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2Ap73j1g; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2Ap73j1g" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-47d5bd981c8so14239755e9.0 for ; Wed, 31 Dec 2025 04:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767183758; x=1767788558; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=REYT8YJ/dkSr2Ie21SxZFTWd8sKfplhaWYQ+TaqETKQ=; b=2Ap73j1gygHyUQFpr4eUUI36IwMsSDE9zD6EK+Ycrd8gnoiHVXSbKHSZIdn12ZAQsD B2ac01AkES2Ca0hIGBmdrvosX+t9SFzEeov/7lBFbGdX0xijRnWKUZq/4gekbe6FWkAR Knf7ZbS/hwJxjsCsCYheXLOS/iFkMayeDx+0e4uSlkdCV7IRAEBymrAtX2qr1EUwEpBP Llvwb5i49ZxRHXkjwxFQ7OdSqI2V45Fld2uK8tXKCkyMkGWXWwD1skDNZvula8/Eu7jF 2CWlvw5V7Y3oU301orMZ9ba7DMx2zBw66OyLNMv1LUD/Mj6j7MCCAKx2aQeXa3ECom66 jGBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767183758; x=1767788558; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=REYT8YJ/dkSr2Ie21SxZFTWd8sKfplhaWYQ+TaqETKQ=; b=Tw+aMPs8uAYNln72GIg05+KSDBTQI7g27WGEyZzpJDQT5C5A9JMCYsoZziSeMxpk61 O6w+ZaT7bmfpvKH27EB/pjVQnM6zP2kYkuG7uYv95WGQ9KvUFK4KaN3l1m5H9eU9kjH8 Zm+Jwwqhqfn6mHF9vygf0JifPEWyB+AI0LqkiVZB0D1Jq3oLZrVHQYwmMthr/L6KB1EK Gq+gknrFYMOGZ5UcQojTojDVVqtQ5tQLxk0o3H1raSMTYBdwOg1HKl/au4GeDHiaZJtA xg+0laoJx1p++0fC9qKnPmFG/mXS13s3DAS9QZOUwtNkWhSoMDFAPSTnKmmk3WHxjEjm tg/g== X-Forwarded-Encrypted: i=1; AJvYcCWKDcyZfQpz+keEs7FqqUUGPEm+gzaYy7jpAf6r2IUY6mhnCbBkPgvewYxliGgxwDSj3LOV1bIY6zCeNr0=@vger.kernel.org X-Gm-Message-State: AOJu0YwoG0f0rKRjmPEpRjfnqO1NPtQ9WMNKIiUgAKqjBCXed6RE2Bqt YXjWhhBXPfBg+Y8yMqUgeSP2WcH4Zppe5xErGu1r2axStbyMBSjahVJrBz1qIVDmB2pGDKYfm1q WEXH4YsM1nMCe0TE85Q== X-Google-Smtp-Source: AGHT+IG+d3dn97mR05G1vfxtVGQCjvCQzYBGJ5XjDQkL2U/PB1Ft8yM2WWn+7k6yvU3vRGKPA72nmhH58SjTDVY= X-Received: from wmsm38.prod.google.com ([2002:a05:600c:3b26:b0:477:a1f9:138c]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:818f:b0:477:7b16:5f77 with SMTP id 5b1f17b1804b1-47d19538725mr450831265e9.3.1767183757851; Wed, 31 Dec 2025 04:22:37 -0800 (PST) Date: Wed, 31 Dec 2025 12:22:25 +0000 In-Reply-To: <20251231-rwonce-v1-0-702a10b85278@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251231-rwonce-v1-0-702a10b85278@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=3744; i=aliceryhl@google.com; h=from:subject:message-id; bh=ho7sEa3sHiw4JAsNigwc6kC7aT+CIvKjmsF0WqyxYeE=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBpVRWLKHPgRt7fOS19l2MagjlWg0LGc+wVA9YRb 5uR2DA3RfaJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaVUViwAKCRAEWL7uWMY5 RhplD/91zkdMMSGPLFlUxmye1zAnivnHlCVwGrBjDg+IhGKnsT9ZSGq9/ZSv+0HBjouSoFXO/gS C7rCtFQgHg1EQ2RCW6jzt70ph9bv8lh3ob+cOuLf167GMhNEpDTTtbgSkqUQiidmnH4arv17iLr C9n72wGxhQbLJgGSouTCXPyCjUTg9Z5YSY+tT++gPbdLApvL10aoophFoOf7gEZyHnIOLPBUqxh QbxWhIubQMig97irk7zNGgUMvWSn0oU2+4zFhNe7MVOgQL/M3oNZ8FRqsOiRTZY/SCEGf5i2GLN pJTK/AarnDFWPuJsZ6UYhZeN9ZQSDkoWeZdLWOVtKrEvU11Nx5M7Ss7989CfRAeoLAUw0MrWvMQ zoOrU5wALF/6YNktCRdDFmpXg6nPzG1q5B1CRlzlc8sxxcjwRD/lgoLMSu6guiI5ls/AButpJiu sMZFGqgCtR3p4FmX2ch0ecWN/kK4lFRU/oiTY6fUwAo2EdtdN1HO8dss7HPbpSoUqCwl085YgWR TMq88vxxwiddr7umQrgL8YQIOeGPUkHEJCIcUZ8RZJP8cCXWi3wiTufRFv3nU8joLUfvQBXts3E dVkAqZ0IPWv/nX4/sjoXpJ//15qdnZOrGa/yh79ghXgdg3FNlmtFDgE0FujYtkUWSJBf17JcRYo e6fQY6LvRgmu/Aw== X-Mailer: b4 0.14.2 Message-ID: <20251231-rwonce-v1-1-702a10b85278@google.com> Subject: [PATCH 1/5] arch: add CONFIG_ARCH_USE_CUSTOM_READ_ONCE for arm64/alpha From: Alice Ryhl To: Boqun Feng , Will Deacon , Peter Zijlstra Cc: Richard Henderson , Matt Turner , Magnus Lindholm , Catalin Marinas , Miguel Ojeda , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Mark Rutland , FUJITA Tomonori , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , John Stultz , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable By exposing this variable as a config option, conditional compilation in Rust code may rely on it to determine whether it should use a volatile read or call a C helper function to perform a READ_ONCE operation. This config option is also added on alpha for consistency, even if Rust does not support alpha right now. Signed-off-by: Alice Ryhl --- arch/Kconfig | 11 +++++++++++ arch/alpha/Kconfig | 1 + arch/alpha/include/asm/rwonce.h | 4 ++-- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/rwonce.h | 4 ++-- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 31220f512b16d5cfbc259935c2d3675b60c1e25c..683176bb09e50e31f398bb92678= 283e5de66b282 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -229,6 +229,17 @@ config HAVE_EFFICIENT_UNALIGNED_ACCESS See Documentation/core-api/unaligned-memory-access.rst for more information on the topic of unaligned memory accesses. =20 +config ARCH_USE_CUSTOM_READ_ONCE + bool + help + Some architectures reorder address-dependent volatile loads, + which means that the default implementation of READ_ONCE that + relies on a volatile load is not appropriate. + + This symbol should be selected by an architecture if it + redefines READ_ONCE to use a different implementation than a + volatile load. + config ARCH_USE_BUILTIN_BSWAP bool help diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig index 80367f2cf821ceb4fc29485b7b21b37d5c310765..1d5d48153ba0087554221e9412a= 6af0c672d3f5c 100644 --- a/arch/alpha/Kconfig +++ b/arch/alpha/Kconfig @@ -11,6 +11,7 @@ config ALPHA select ARCH_NO_PREEMPT select ARCH_NO_SG_CHAIN select ARCH_USE_CMPXCHG_LOCKREF + select ARCH_USE_CUSTOM_READ_ONCE if SMP select FORCE_PCI select PCI_DOMAINS if PCI select PCI_SYSCALL if PCI diff --git a/arch/alpha/include/asm/rwonce.h b/arch/alpha/include/asm/rwonc= e.h index 35542bcf92b3a883df353784bcb2d243475ccd91..c9f21aa0764625b24e895792392= 6d09a2eb97e7c 100644 --- a/arch/alpha/include/asm/rwonce.h +++ b/arch/alpha/include/asm/rwonce.h @@ -5,7 +5,7 @@ #ifndef __ASM_RWONCE_H #define __ASM_RWONCE_H =20 -#ifdef CONFIG_SMP +#ifdef CONFIG_ARCH_USE_CUSTOM_READ_ONCE =20 #include =20 @@ -28,7 +28,7 @@ (typeof(x))__x; \ }) =20 -#endif /* CONFIG_SMP */ +#endif /* CONFIG_ARCH_USE_CUSTOM_READ_ONCE */ =20 #include =20 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 93173f0a09c7deb07b46ab4f16a1a0e4320dfbf1..cd16053c8302479458a05c23ba9= cfb73ee50232c 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -89,6 +89,7 @@ config ARM64 select ARCH_KEEP_MEMBLOCK select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE select ARCH_USE_CMPXCHG_LOCKREF + select ARCH_USE_CUSTOM_READ_ONCE if LTO select ARCH_USE_GNU_PROPERTY select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS diff --git a/arch/arm64/include/asm/rwonce.h b/arch/arm64/include/asm/rwonc= e.h index 78beceec10cda47b319db29d9f79d2a5df35e92d..5da6b2d6a12399a520f7a331001= 4de723baa278a 100644 --- a/arch/arm64/include/asm/rwonce.h +++ b/arch/arm64/include/asm/rwonce.h @@ -5,7 +5,7 @@ #ifndef __ASM_RWONCE_H #define __ASM_RWONCE_H =20 -#if defined(CONFIG_LTO) && !defined(__ASSEMBLER__) +#if defined(CONFIG_ARCH_USE_CUSTOM_READ_ONCE) && !defined(__ASSEMBLER__) =20 #include #include @@ -62,7 +62,7 @@ }) =20 #endif /* !BUILD_VDSO */ -#endif /* CONFIG_LTO && !__ASSEMBLER__ */ +#endif /* CONFIG_ARCH_USE_CUSTOM_READ_ONCE && !__ASSEMBLER__ */ =20 #include =20 --=20 2.52.0.351.gbe84eed79e-goog From nobody Sun Feb 8 06:04:45 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 08E9B31ED76 for ; Wed, 31 Dec 2025 12:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183764; cv=none; b=igO/fBR3oJhGap7mTmpWMrATh/ynm9SA4UqnPMVxI9pTIZS/s9uiZ78UuVJ0GDkiFhFJoMnsGUsdNePkjBcSiRbLjHO39c/IuliAV/Mgos0Z3nYz+DRJ7Rm+3NFpYIxAIAviHCDmakXg+AguLV1DAntJpH426Myi1PRGC4Yp6u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183764; c=relaxed/simple; bh=xEInC3fu2akfjyTzgU6ASYK4Ti9C0Fwxb+5tsaoSXWY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZpPgLIe0K3COjS7R5l9r8+msTooVJiwZkJQdzLKq3doX57NxtxHkL5WyXWlu1MMdxeCXClZxZBVWkAF1+nHfXtKf16LAQ0F+iILUo/FS3AySf0k7N8Z0J1k/8bd5yEvX53xDGgnPRa2b3iGqS63ZJqtHGLBoREYM1P0JNuO2kXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=STagWI6n; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="STagWI6n" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-43102ac1da8so7722199f8f.2 for ; Wed, 31 Dec 2025 04:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767183759; x=1767788559; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wY+MioUEzLGTu451Qf335kX3GDWJpHFtljbNWqzcaPs=; b=STagWI6nlkE1Fe1kiEkmTx4MFJJa88tmaE3Ce2E6MWedolcOH0TmpGnS1sC31YOfVo L27CTh+4mOiAoS/TktjWTHIzQZnkLChgWXJrrkgsyKXSN52YW8OAQ4YMjOKk/D39URNl KCD6g7INvr+fwY9JoZwXE6bQkPM0oO75gRt3P/L/3KfhF1LMPYYMSug9nhp8HQ1L1ZC0 cOCEOpxN2368VuRrqg68g2E6vmPksPr4ae/XmgQFpoTgunDo/7PiW7cHOhR+bYx3mB+f upTamGGgp2rt3VfIpEOjG2L69JhuuWHSYTJTV8JnXHxoipSjxmbr2NBT5DRUiIWSJyLA 5sbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767183759; x=1767788559; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wY+MioUEzLGTu451Qf335kX3GDWJpHFtljbNWqzcaPs=; b=da+KSN/FiTy/LLH4Lu5nTu3GfDJODLnNc5+t9AJxtSfTNYZub44s2CsHN1NxE7R/a7 EkfGzg90Gk/WVeI+bmI1uBHw8oP9aXYdhd+jOE00oumQvAvu3T6vpWZgNCKihFUvVuj1 1MtOL0uPfKN4ZAnuQrbZbcypdj0B4Mjbqpq0dZS2fZOV3ra33x89weqNkTT7n+0/HU3K FQujds1k8fg/kvUcjKoE4ckZa88qrrM5p8om8KN4V90l5NGZCSrSRX+74cj3fj2oKGmc Zs/JAc5cw2rALtIIbWI5mrrjXbEYO2pbhz9jzp9jq3gSFWpnt6/4GX4nClJzRIlcJS3o +wPQ== X-Forwarded-Encrypted: i=1; AJvYcCVMwZQbTOSN7iBrURFHuVSQthm3w8+BBxP8DGXTSsv+6Fr08V4nJ9l0RrxCa1JRN7s7lkT5JHP74X+K1e8=@vger.kernel.org X-Gm-Message-State: AOJu0YzJYJXaVddjxxaEcDYoR+VJJWuv5d+WV/QlnHyV/nSo60KzeVAF ay8sveOA28HAGdbGLBnJS1LTRq2wBS/S5mUDp+pYvsBxZWFphBtF4+Usm5MpMysxD9gcYh8JwIt oL2diwYZySnueX3/GPg== X-Google-Smtp-Source: AGHT+IEitYbwlxMWnTamAVtk40AR4WQ2RNUYZFRzIPAOaqn/Hd7ztALmxDa49nVO+fS0C8mDnzEVsTtIzFsZHnI= X-Received: from wrbez4.prod.google.com ([2002:a05:6000:2504:b0:430:2785:456]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:178c:b0:431:104:6daf with SMTP id ffacd0b85a97d-4324e709ab3mr53524517f8f.54.1767183759209; Wed, 31 Dec 2025 04:22:39 -0800 (PST) Date: Wed, 31 Dec 2025 12:22:26 +0000 In-Reply-To: <20251231-rwonce-v1-0-702a10b85278@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251231-rwonce-v1-0-702a10b85278@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=10427; i=aliceryhl@google.com; h=from:subject:message-id; bh=xEInC3fu2akfjyTzgU6ASYK4Ti9C0Fwxb+5tsaoSXWY=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBpVRWL8JXFNz2YiOAabCoqI+IEhQm+4iN4Cw2GP 8bBpof1XGuJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaVUViwAKCRAEWL7uWMY5 Rp/5EAC37oMUwkvFIuBMb1J8TrahAvBfS7wmSDGExhSeTS/0tTlOAmgS6ra79WgITGRX0Z73b37 VO2XL36+LYeSzqZTthJ22W0gB0MXJn4KoMYL6mm25GNEUrDj8DvsczCDT3tlvxmfQjkQWbFXh35 IfM2dzl5IImt4EdlyZWMwjc7CxqCcfnzUk/fkfSJdU9z6wFdNCVwkuxQoPYP3oM/V+QdWhXrtFV z+pMFdXoRaY3ptvtVPH4yEDd2GcgpTSd+e77NhR7xeeZo2qIKh3f47WGJHbGMblg9YIqkMt7GdA 0isxcCJxtTG5l4KWZdXOZ8plZiHVSAKrLCqasMPXvy3bhHxmtQum+kluiC8TDROyN351r6GHyaZ mCVDGtbeoCrgHumlhCy8HcNkcE2W1QFAM1Z84rTVhp3G5x6O3ah+W8nKlZRF1YwX8D6rX0rkNMi +G2vN9bYtKEFLG7JeA/9lV5ysIWX2N+dM5ZyauD5lzCXVJgsReYKyvNyYD2UgXqBpq8X2X6805X 7REv3jxoGcSlaMd5ANOKwFWO+Cj5Ef2y6ZxmUWJs6BinfW0ndgLlFI+Y0bmA9wAzyAEFyGOWm2q 6x4WLaSet0wlWDMy+P1vDdIRjA6DIbGPmrorx3yrAFojNztMSvFoTrQXuXbX68QTFJv1cL7R+Ex wRxItByaQGdKzfg== X-Mailer: b4 0.14.2 Message-ID: <20251231-rwonce-v1-2-702a10b85278@google.com> Subject: [PATCH 2/5] rust: sync: add READ_ONCE and WRITE_ONCE From: Alice Ryhl To: Boqun Feng , Will Deacon , Peter Zijlstra Cc: Richard Henderson , Matt Turner , Magnus Lindholm , Catalin Marinas , Miguel Ojeda , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Mark Rutland , FUJITA Tomonori , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , John Stultz , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable There are currently a few places in the kernel where we use volatile reads when we really should be using `READ_ONCE`. To make it possible to replace these with proper `READ_ONCE` calls, introduce a Rust version of `READ_ONCE`. I've written the code to use Rust's volatile ops directly when possible. This results in a small amount of code duplication, but I think it makes sense for READ_ONCE and WRITE_ONCE to be implemented in pure Rust when possible. Otherwise they would unconditionally be a function call unless you have a system where you can perform cross-language inlining. I considered these functions in the bindings crate instead of kernel crate. I actually think it would make a lot of sense. But it implies some annoying complications on old compilers since the #![feature()] invocations in kernel/lib.rs do not apply in the bindings crate. For now, we do not support using READ_ONCE on compound types even if they have the right size. This can be added later. This fails checkpatch due to a misordered MAINTAINERS entry, but this is a pre-existing problem. Signed-off-by: Alice Ryhl --- MAINTAINERS | 2 + rust/helpers/helpers.c | 1 + rust/helpers/rwonce.c | 34 ++++++++ rust/kernel/sync.rs | 2 + rust/kernel/sync/rwonce.rs | 188 +++++++++++++++++++++++++++++++++++++++++= ++++ 5 files changed, 227 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 12f49de7fe036c2439c00f9f4c67b2219d72a4c3..1d0cae158fe2cc7d99b6a64c111= 76b635e2d14e4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4117,9 +4117,11 @@ F: arch/*/include/asm/atomic*.h F: include/*/atomic*.h F: include/linux/refcount.h F: scripts/atomic/ +F: rust/helpers/rwonce.c F: rust/kernel/sync/atomic.rs F: rust/kernel/sync/atomic/ F: rust/kernel/sync/refcount.rs +F: rust/kernel/sync/rwonce.rs =20 ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER M: Bradley Grove diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index 79c72762ad9c4b473971e6210c9577860d2e2b08..28b79ca7844fb744e5ad1282388= 24921c055ec82 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -48,6 +48,7 @@ #include "rcu.c" #include "refcount.c" #include "regulator.c" +#include "rwonce.c" #include "scatterlist.c" #include "security.c" #include "signal.c" diff --git a/rust/helpers/rwonce.c b/rust/helpers/rwonce.c new file mode 100644 index 0000000000000000000000000000000000000000..55c621678cd632e728cb925b6a4= a2e34e2fc4884 --- /dev/null +++ b/rust/helpers/rwonce.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (C) 2025 Google LLC. + */ + +#ifdef CONFIG_ARCH_USE_CUSTOM_READ_ONCE + +__rust_helper u8 rust_helper_read_once_1(const u8 *ptr) +{ + return READ_ONCE(*ptr); +} + +__rust_helper u16 rust_helper_read_once_2(const u16 *ptr) +{ + return READ_ONCE(*ptr); +} + +__rust_helper u32 rust_helper_read_once_4(const u32 *ptr) +{ + return READ_ONCE(*ptr); +} + +__rust_helper u64 rust_helper_read_once_8(const u64 *ptr) +{ + return READ_ONCE(*ptr); +} + +__rust_helper void *rust_helper_read_once_ptr(void * const *ptr) +{ + return READ_ONCE(*ptr); +} + +#endif diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs index 5df87e2bd212e192b8a67644bd99f05b9d4afd75..a5bf7bdc3fa8a044786eafae39f= e8844aeeef057 100644 --- a/rust/kernel/sync.rs +++ b/rust/kernel/sync.rs @@ -20,6 +20,7 @@ pub mod poll; pub mod rcu; mod refcount; +pub mod rwonce; mod set_once; =20 pub use arc::{Arc, ArcBorrow, UniqueArc}; @@ -30,6 +31,7 @@ pub use lock::spinlock::{new_spinlock, SpinLock, SpinLockGuard}; pub use locked_by::LockedBy; pub use refcount::Refcount; +pub use rwonce::{READ_ONCE, WRITE_ONCE}; pub use set_once::SetOnce; =20 /// Represents a lockdep class. It's a wrapper around C's `lock_class_key`. diff --git a/rust/kernel/sync/rwonce.rs b/rust/kernel/sync/rwonce.rs new file mode 100644 index 0000000000000000000000000000000000000000..a1660e43c9ef94011812d181671= 3cf031a73de1d --- /dev/null +++ b/rust/kernel/sync/rwonce.rs @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Copyright (C) 2025 Google LLC. + +//! Rust version of the raw `READ_ONCE`/`WRITE_ONCE` functions. +//! +//! C header: [`include/asm-generic/rwonce.h`](srctree/include/asm-generic= /rwonce.h) + +/// Read the pointer once. +/// +/// # Safety +/// +/// It must be safe to `READ_ONCE` the `ptr` with this type. +#[inline(always)] +#[must_use] +#[track_caller] +#[expect(non_snake_case)] +pub unsafe fn READ_ONCE(ptr: *const T) -> T { + // SAFETY: It's safe to read `ptr` once with this type. + unsafe { T::read_once(ptr) } +} + +/// Write the pointer once. +/// +/// # Safety +/// +/// It must be safe to `WRITE_ONCE` the `ptr` with this type. +#[inline(always)] +#[track_caller] +#[expect(non_snake_case)] +pub unsafe fn WRITE_ONCE(ptr: *mut T, val: T) { + // SAFETY: It's safe to write `ptr` once with this type. + unsafe { T::write_once(ptr, val) }; +} + +/// This module contains the generic implementations. +#[expect(clippy::undocumented_unsafe_blocks)] +#[expect(clippy::missing_safety_doc)] +mod rwonce_generic_impl { + use core::ffi::c_void; + #[allow(unused_imports)] + use core::ptr::{read_volatile, write_volatile}; + + #[inline(always)] + #[track_caller] + #[cfg(not(CONFIG_ARCH_USE_CUSTOM_READ_ONCE))] + pub(super) unsafe fn read_once_1(ptr: *const u8) -> u8 { + unsafe { read_volatile::(ptr) } + } + + #[inline(always)] + #[track_caller] + #[cfg(not(CONFIG_ARCH_USE_CUSTOM_READ_ONCE))] + pub(super) unsafe fn read_once_2(ptr: *const u16) -> u16 { + unsafe { read_volatile::(ptr) } + } + + #[inline(always)] + #[track_caller] + #[cfg(not(CONFIG_ARCH_USE_CUSTOM_READ_ONCE))] + pub(super) unsafe fn read_once_4(ptr: *const u32) -> u32 { + unsafe { read_volatile::(ptr) } + } + + #[inline(always)] + #[track_caller] + #[cfg(not(CONFIG_ARCH_USE_CUSTOM_READ_ONCE))] + pub(super) unsafe fn read_once_8(ptr: *const u64) -> u64 { + unsafe { read_volatile::(ptr) } + } + + #[inline(always)] + #[track_caller] + #[cfg(not(CONFIG_ARCH_USE_CUSTOM_READ_ONCE))] + pub(super) unsafe fn read_once_ptr(ptr: *const *mut c_void) -> *mut c_= void { + unsafe { read_volatile::<*mut c_void>(ptr) } + } + + #[inline(always)] + #[track_caller] + pub(super) unsafe fn write_once_1(ptr: *mut u8, val: u8) { + unsafe { write_volatile::(ptr, val) } + } + + #[inline(always)] + #[track_caller] + pub(super) unsafe fn write_once_2(ptr: *mut u16, val: u16) { + unsafe { write_volatile::(ptr, val) } + } + + #[inline(always)] + #[track_caller] + pub(super) unsafe fn write_once_4(ptr: *mut u32, val: u32) { + unsafe { write_volatile::(ptr, val) } + } + + #[inline(always)] + #[track_caller] + pub(super) unsafe fn write_once_8(ptr: *mut u64, val: u64) { + unsafe { write_volatile::(ptr, val) } + } + + #[inline(always)] + #[track_caller] + pub(super) unsafe fn write_once_ptr(ptr: *mut *mut c_void, val: *mut c= _void) { + unsafe { write_volatile::<*mut c_void>(ptr, val) } + } +} +use rwonce_generic_impl::*; + +#[cfg(CONFIG_ARCH_USE_CUSTOM_READ_ONCE)] +use bindings::{read_once_1, read_once_2, read_once_4, read_once_8, read_on= ce_ptr}; + +/// Rust trait for types that may be used with `READ_ONCE`/`WRITE_ONCE`. +/// +/// This serves a similar purpose to the `compiletime_assert_rwonce_type` = macro in the C header. +pub trait RwOnceType { + /// The `READ_ONCE` for this type. + /// + /// # Safety + /// + /// It must be safe to `READ_ONCE` the `ptr` with this type. + unsafe fn read_once(ptr: *const Self) -> Self; + + /// The `WRITE_ONCE` for this type. + /// + /// # Safety + /// + /// It must be safe to `WRITE_ONCE` the `ptr` with this type. + unsafe fn write_once(ptr: *mut Self, val: Self); +} + +macro_rules! impl_rw_once_type { + ($($t:ty, $read:ident, $write:ident $(, <$u:ident>)?;)*) =3D> {$( + #[allow(unknown_lints, reason =3D "unnecessary_transmutes is unkno= wn prior to MSRV 1.88.0")] + #[allow(unnecessary_transmutes)] + #[allow(clippy::missing_transmute_annotations)] + #[allow(clippy::useless_transmute)] + impl$(<$u>)? RwOnceType for $t { + #[inline(always)] + #[track_caller] + unsafe fn read_once(ptr: *const Self) -> Self { + // SAFETY: The caller ensures we can `READ_ONCE`. + // + // Note that `transmute` fails to compile if the two types= are of different sizes. + unsafe { core::mem::transmute($read(ptr.cast())) } + } + + #[inline(always)] + #[track_caller] + unsafe fn write_once(ptr: *mut Self, val: Self) { + // SAFETY: The caller ensures we can `WRITE_ONCE`. + unsafe { $write(ptr.cast(), core::mem::transmute(val)) }; + } + } + )*} +} + +// These macros determine which types may be used with rwonce, and which h= elper function should be +// used if so. +// +// Note that `core::mem::transmute` fails the build if the source and targ= et type have different +// sizes, so picking the wrong helper should lead to a build error. + +impl_rw_once_type! { + u8, read_once_1, write_once_1; + i8, read_once_1, write_once_1; + u16, read_once_2, write_once_2; + i16, read_once_2, write_once_2; + u32, read_once_4, write_once_4; + i32, read_once_4, write_once_4; + u64, read_once_8, write_once_8; + i64, read_once_8, write_once_8; + *mut T, read_once_ptr, write_once_ptr, ; + *const T, read_once_ptr, write_once_ptr, ; +} + +#[cfg(target_pointer_width =3D "32")] +impl_rw_once_type! { + usize, read_once_4, write_once_4; + isize, read_once_4, write_once_4; +} + +#[cfg(target_pointer_width =3D "64")] +impl_rw_once_type! { + usize, read_once_8, write_once_8; + isize, read_once_8, write_once_8; +} --=20 2.52.0.351.gbe84eed79e-goog From nobody Sun Feb 8 06:04:45 2026 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 083CD322DD0 for ; Wed, 31 Dec 2025 12:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183764; cv=none; b=rTsHhFhuMN4Omv1Br1pNAdgvrCYiybPw33SMNs9LvwduQJscSK3dnnlwSYoZIRaa43yHfuimvphm0C3VbllArmgSRM9ddEWSnUsLc4pQg5yWzJqUr0vTilO61bh1UsBC5O5391x1GH1ltExvk/RzC/UGnPF2B/KKR5xsFbPahQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183764; c=relaxed/simple; bh=f+ElsItk3DSISt1bsxPjTx60qDfLwGd+MdLyPyzjyQI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KUhYlY1V5cZzpY/BgawbdC3Xc9xlOntbtfLu1iYUzAkDq+u9ZR2RRzylOWcHD/kaljYD48IEbUP8bW2Jo9V8enQ79OqNb/gtYterflO8a5qJK111q8IHxxiIE5pPuih5nkwL/hS3xFPAhpMKfCQ918fA/ziGYowq2SHpwgT8eJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BU9WJOai; arc=none smtp.client-ip=209.85.218.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BU9WJOai" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-b79fcc35ab2so867050966b.2 for ; Wed, 31 Dec 2025 04:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767183760; x=1767788560; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=m0aSDGMKyT+fMQNL6kGw597IXO3k2kPPSUGq+qvudkw=; b=BU9WJOaitrVt6PfvkjkWkxeV1Lf+qreGMVZh3tOZ2Nd+mvgYwxGYyJIf+TLnmMn6n2 XtzQFi26YaG5INjCjj5ODjFcSHzIbYfoPFFiHJqXqV1S2vtvENmKEioHO9R9AtJAnzBt yeid0ul802VnCPE+G/JB/9ufpPI0tl3gEhV2KAU4nh6YEXKbf+0kXXAm74vyIZdBgvn7 0CYWDQCdh4DM1zEAQbQKY/mbrBWr7HGnwOpN4nLWMggkll1pPl4rVYV4FADDqzkK32ru wOTicV7IPGTmZyJt8pNOY+z53eeN6LbwGB0WjXzH3DklXBDQC2xgnmLNRpVJX+lxlWRb 9tJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767183760; x=1767788560; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=m0aSDGMKyT+fMQNL6kGw597IXO3k2kPPSUGq+qvudkw=; b=THGGL/KlnJC7VDQcPhBbpfoPsH3YOJhuMZ78WyUrxHNdn3ZRE9S9rAF/OVbv72ZZfA MGvB+jy3sU/DnZdVYvBFzWWvzXetDPNHqzGDXhgqvmFn2fFDmMldBE4/JMOo5P/1mOwc JdiF8unjGVxAtdCZkGsArCm229Sr1ru7Q3YFh1wnZRIGMJAveYIP0Vk1QnnqdVtJvl8C y2kTpWZcK1r0G94u/2c0P0VAdyEqDhF2Sk/CHjcJMouxbyPxGMYGBw1N/Gn3hFsSmmOk o9/MD4PaoYNHaQdNksgGOklU1mnHv/09P38dK3nQHj3O7jpr2RbSOd7D3h8Tq5vis51J mplQ== X-Forwarded-Encrypted: i=1; AJvYcCXaGc2bi505jKYviEAkZuHsiuRy60jZ7bJPAFsIKfCvV7SqIy6v+tsaDWf5/hf2pastX4F4LSyOFTBzFvA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2CknJi2U+kE8rN0VJBkL6jmg35Q38cOiuHLf1YLDLXUVJcr+D dHA2CSoLdN7BxVynP57h8yL9XqMFrIpc1J2r288j2TsbDQg7nF76aMo729X1yfcPE8H4aqtHsbv xz58qHUBqX5F4Mkum5w== X-Google-Smtp-Source: AGHT+IF6QCK61/Taq0LVCEy6u2Lh/f9qkwECTfyeXwyFZObuLicNLjWSsvwiJ+SkeSLRWE4V1R+yhLQS/6l+gLk= X-Received: from ejbva10.prod.google.com ([2002:a17:907:11ca:b0:b73:7b14:6671]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:c10a:b0:b83:972c:7862 with SMTP id a640c23a62f3a-b83972c7a78mr466276466b.45.1767183760503; Wed, 31 Dec 2025 04:22:40 -0800 (PST) Date: Wed, 31 Dec 2025 12:22:27 +0000 In-Reply-To: <20251231-rwonce-v1-0-702a10b85278@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251231-rwonce-v1-0-702a10b85278@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2011; i=aliceryhl@google.com; h=from:subject:message-id; bh=f+ElsItk3DSISt1bsxPjTx60qDfLwGd+MdLyPyzjyQI=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBpVRWL4oDnxIVIQOubpJwcZRLcyzDfMlz7wIFAM FONlx/oCYKJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaVUViwAKCRAEWL7uWMY5 RmH6D/46KKFKWvICb3h6YXEsXSSffucVzMDtCNxV/nON8HqUTVC9QRwy+QA5BR0hrfvViIl1dKx QFW5mE6zsjqHKs9m3qdyng4MUI8hLxBMk3ZddZ5++5KMoowDj7M9YW79F70Q5JL8cPNiGTxEn8T VOpmnKD0W0uqGzPVPn23nyrMXrCuGOSOlv1Gd7VlP14rVqitTFZNDbO/h3Jxy6lNTukLQ+koVaY IfTia3CyF5IhIS2g511uFdNOICKH6TDOYX8thm7ndly6HHx+6ARDy7WILR47BIDGvXOQdbt1kLi V6/5WiEP3hVfSFSXEsvYYHcIWFmsvvPJOUUlHKqLTHmMiG5YzhOcIMdWR2xCLaCeAb147Thitc8 +Ze9StLM0Z7stUstGbYjIUZFQ+V4Rndjy2ocRJH5Ed52rnZN9G1Iy0NTMogqlQ8hkUiNoISzYer 7JORef2rWkONYm1I2EyDd+XsVaBfYDD7SBf7gj1LjEzjn/cJZqNNetKASeZnYDGe8oD8X/hfN41 /K11v2L2aZsQ/aZx/TvPkBaD5UlBxpRXYfQLDLE0Xgz2TNev4vNJ6gzjLvwaHsk+5wi29msQ69Q ZqqGYocGcZHMGcf7aalYz96ESMDQx6plGafNctmZtxnbAR6RDeb4Gt0M3Bf/FonllPV4dkLOmiO +fYoPkvnNt3oL+w== X-Mailer: b4 0.14.2 Message-ID: <20251231-rwonce-v1-3-702a10b85278@google.com> Subject: [PATCH 3/5] rust: sync: support using bool with READ_ONCE From: Alice Ryhl To: Boqun Feng , Will Deacon , Peter Zijlstra Cc: Richard Henderson , Matt Turner , Magnus Lindholm , Catalin Marinas , Miguel Ojeda , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Mark Rutland , FUJITA Tomonori , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , John Stultz , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Normally it is undefined behavior for a bool to take any value other than 0 or 1. However, in the case of READ_ONCE(some_bool) is used, this UB seems dangerous and unnecessary. I can easily imagine some Rust code that looks like this: if READ_ONCE(&raw const (*my_c_struct).my_bool_field) { ... } And by making an analogy to what the equivalent C code is, anyone writing this probably just meant to treat any non-zero value as true. For WRITE_ONCE no special logic is required. Signed-off-by: Alice Ryhl --- rust/kernel/sync/rwonce.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rust/kernel/sync/rwonce.rs b/rust/kernel/sync/rwonce.rs index a1660e43c9ef94011812d1816713cf031a73de1d..73477f53131926996614df573b2= d50fff98e624f 100644 --- a/rust/kernel/sync/rwonce.rs +++ b/rust/kernel/sync/rwonce.rs @@ -163,6 +163,7 @@ unsafe fn write_once(ptr: *mut Self, val: Self) { // sizes, so picking the wrong helper should lead to a build error. =20 impl_rw_once_type! { + bool, read_once_bool, write_once_1; u8, read_once_1, write_once_1; i8, read_once_1, write_once_1; u16, read_once_2, write_once_2; @@ -186,3 +187,21 @@ unsafe fn write_once(ptr: *mut Self, val: Self) { usize, read_once_8, write_once_8; isize, read_once_8, write_once_8; } + +/// Read an integer as a boolean once. +/// +/// Returns `true` if the value behind the pointer is non-zero. Otherwise = returns `false`. +/// +/// # Safety +/// +/// It must be safe to `READ_ONCE` the `ptr` with type `u8`. +#[inline(always)] +#[track_caller] +unsafe fn read_once_bool(ptr: *const bool) -> bool { + // Implement `read_once_bool` in terms of `read_once_1`. The arch-spec= ific logic is inside + // of `read_once_1`. + // + // SAFETY: It is safe to `READ_ONCE` the `ptr` with type `u8`. + let byte =3D unsafe { read_once_1(ptr.cast::()) }; + byte !=3D 0u8 +} --=20 2.52.0.351.gbe84eed79e-goog From nobody Sun Feb 8 06:04:45 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 ACE043246F8 for ; Wed, 31 Dec 2025 12:22:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183765; cv=none; b=aBrr0DAeHASLwxnUeeg+fMCs1ylXU+wTCYHsLxfnc/tlw1ocYz8uQ+B9JOnurZ5o8miqSvPy7swvR3j/8t3WdE88rpRp1bVPc/geHvj8in4C5avWXJBs24FKPTfZOxioLFVJ4Bfwa7sg+cF7g4+zvVR6fcOr14OO4YLDzz8EdvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183765; c=relaxed/simple; bh=dWGhxjFk0H0ccZ8Z0LvyX4T5xP2vhqe9w9Pjy9Iy9EA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UDtLnrnfOKSm6WuMBP9aywqi4Fu/O1F0tDpfX0vKIc6+qtlrfXLO2pc0pZDGxhUSIwjFNRPYupEif2avW8rHI19FlvtYujc6u9n6S1mlemFLBHyF3uCc9pCehgZfpzay7kWaiAp0eafxHi6xUmtLB5g3yjeyKtPzGcRsc3Xl2P8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nQCx8LIw; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nQCx8LIw" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-47d3ba3a49cso57200095e9.2 for ; Wed, 31 Dec 2025 04:22:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767183762; x=1767788562; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IML1ayTIBjLRiL1IISCGMNFG24NcobrFATGIP2DkaPQ=; b=nQCx8LIw+IgysOK/5LWZzN/DCseniEUCOx83/YJLJoYGeRXt2B9W0ViIzG/PLVxErJ aPTCWHKdShoMzrvJLx7VlCbIKxZLE5/lAGpmOemIut2kSAYo5coyRJj2Z1fF/5d3jNKJ b1n7Uu64DCLHSIuSspS9y/ror7OQA/AKG/D2Cwa6CtBd0/elfRROWUYvDZXYfu2LKxuq U3hIl0Ftp6SOzCwb1M4m45VgGeeHVnNZV6iSLdXIt+/Bl3Tlrb9Nv62ydTN4tpcGaPpi VhMZeJLZ5CbMQoIK0g0PgDmWA86RLK3OLOtd4YRc0326TR9OGav+5mpSKb8Hxh0nico3 rLqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767183762; x=1767788562; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IML1ayTIBjLRiL1IISCGMNFG24NcobrFATGIP2DkaPQ=; b=FyExlMLvB/79Xd/Z+b6sK8xjWidHHSLSClx+lmYI0yuVc3LEERBO21RTVdEOYA1uKt sLtBruy7kO8LD6XEJYHpKCmjKEfinQ5Jdwlle7KCmTyU39JX/0Lu2FENbogG0VxPA9A1 gyTnqQdyJ5dmqeERvROa737+zOxBVVh2CqVXjPV2EWLK+wS0FWMqyW3FzIdDzhUkY8WF MKp79UvbUot7tUGGhmWao/aNwFNHIie9lkS6mn84DX+f/BkLI6kFDQ7akAKPv9juVhye 0JAvF8Uv83YalD1M0mFUIWgbcOIL1OCwyAvTUUR2WS/ouzIncwr52gG8bD/wVeP0zSy1 zJzA== X-Forwarded-Encrypted: i=1; AJvYcCURV42m1DRe2uCNb++OHJDjkGZDADBJp1axk/o5RLHkCNHCNqz+8oIdclfVex3gSg3+NSQRB8RRsuH/WWc=@vger.kernel.org X-Gm-Message-State: AOJu0YzjPj0wS2X6M9FOLcKQ06RlpReKGDuekgQIB94MwJWYjFksDpFL dwlWAypwl13TLvnz8IQwx/0W1M4QdG97QReuqyjcoblwPG1c2cLjTS6Ug6KjzUzEF4Uf0GbiJR+ BJIdwMgXZ4FpCDugNlg== X-Google-Smtp-Source: AGHT+IEJ0sOB06BtEpr8ZstmrMz9PeNhPmO2C6GqJfhTbjec6TNWZvpmubPfbs7AHp85adb5H0AyCveolppYmsI= X-Received: from wmco11.prod.google.com ([2002:a05:600c:a30b:b0:47d:47dc:d5d4]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600d:115:b0:46e:37fe:f0e6 with SMTP id 5b1f17b1804b1-47d1997e733mr293114935e9.30.1767183761820; Wed, 31 Dec 2025 04:22:41 -0800 (PST) Date: Wed, 31 Dec 2025 12:22:28 +0000 In-Reply-To: <20251231-rwonce-v1-0-702a10b85278@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251231-rwonce-v1-0-702a10b85278@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1228; i=aliceryhl@google.com; h=from:subject:message-id; bh=dWGhxjFk0H0ccZ8Z0LvyX4T5xP2vhqe9w9Pjy9Iy9EA=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBpVRWLGkM6ekaGvNs/GppoXyA8q6kxlkpqLewuW 7WNKhbTKjqJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaVUViwAKCRAEWL7uWMY5 RtLUEACKkaSaNK/TcJXYBxaQi+3v3CPDHRjWTgRzkBlZ2cipngBrd+Bwm5aNQr6HLLA2wljr5zB sd8yJUc9TZdLiWbispUZaLCxJC+XAMVad9CXiS98PYq5H0Hv98uxbgcFI4T3nuHqM/xrG4OBMqR d9jwZii4XhRij0gUrPqQYAqX3+sb174Ah2h6tS1WLllr/7oegCZFedCpoObQ7JF9OwSXtT5VevH R2ZDKva3GoKaG0vo428LZXH/UDDFPKUn6o0Y1whhaRXdzIG5we6N/H53PjF2Q+OC2kHDHtqgKea xjKnfDl8tJ5TAjd69k/mBPk3xHvVo/vIbXfL35oFTix2yk1n8kcuv1Zx0+Qbv6gF1FSr5sn9Yot z3DlseF+Q4w5zWKbGVngm4+kn9Lo6gew72+hoQ8C2n7b9mGKUkCIqmNHamdglZznxgfrHGI8imv Lkz8hP73DNqX6vhQblP3+Fxt/SN84uREUef+vAAyVKFAIp7SprtvVzputk+BQAw+YVR+0f8QLLn eErdIcXGjyGhtXHOc3Gp79iwy56k9avNJ3qKMHDpuuC1LPYW4FH+9lKwRwkh6qmqJXW5Wd6RnE0 rUhuFmIzHmZwLTF8u3QbBC9TYTfct5eLCQac3dju/Lnq2VWuei0fDBQanQibHCkKnD/nVST47AS Hq8sRXqSOcbvtBQ== X-Mailer: b4 0.14.2 Message-ID: <20251231-rwonce-v1-4-702a10b85278@google.com> Subject: [PATCH 4/5] rust: hrtimer: use READ_ONCE instead of read_volatile From: Alice Ryhl To: Boqun Feng , Will Deacon , Peter Zijlstra Cc: Richard Henderson , Matt Turner , Magnus Lindholm , Catalin Marinas , Miguel Ojeda , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Mark Rutland , FUJITA Tomonori , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , John Stultz , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Using `READ_ONCE` is the correct way to read the `node.expires` field. Signed-off-by: Alice Ryhl --- rust/kernel/time/hrtimer.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 856d2d929a00892dc8eaec63cebdf547817953d3..e2b7a26f8aade972356c3eb5f64= 89bcda3e2e849 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -239,11 +239,9 @@ pub fn expires(&self) -> HrTimerInstant // - Timers cannot have negative ktime_t values as their expiratio= n time. // - There's no actual locking here, a racy read is fine and expec= ted unsafe { - Instant::from_ktime( - // This `read_volatile` is intended to correspond to a REA= D_ONCE call. - // FIXME(read_once): Replace with `read_once` when availab= le on the Rust side. - core::ptr::read_volatile(&raw const ((*c_timer_ptr).node.e= xpires)), - ) + Instant::from_ktime(kernel::sync::READ_ONCE( + &raw const (*c_timer_ptr).node.expires, + )) } } } --=20 2.52.0.351.gbe84eed79e-goog From nobody Sun Feb 8 06:04:45 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 8BB7032471E for ; Wed, 31 Dec 2025 12:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183766; cv=none; b=VdhQk+DKqEmYVx1KiaOyQ4BwgoZxSjC1WH2DVsSpZsnpbSazK+UT6zREFuKA9+/03l386WTwiX71R3bwihfG4NrWvVCPlFU4u2onLRLwhz1Ad4p2RyeVXFQ6QDYM8PQuNpJ5kbwSNPvQJiSnUGdZcMfK6Bmdt50iHUkck04dXuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183766; c=relaxed/simple; bh=x48g//vEaovaCGc/+3V+kdS96OVZQrdlR7cVmTcJM3Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q+DMuqrZBPMIdutCjASF7BTqK3EHpzsLAjT9NXvoq5itkFT96ektazwBzVsPMDSXLRU/8a6ip94tj5vXjKqEcv32tfaLYLyi4XYDrrOllx/UsjBsH8wqcpftVRWC0wXs1+kJ3KQBonvuOLFSfXpBWiRcbmyqeCeN3T11q9FKDq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rXg+fj/D; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rXg+fj/D" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-43102ac1da8so7722218f8f.2 for ; Wed, 31 Dec 2025 04:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767183763; x=1767788563; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EnX+YiWBwSFj03NZe+M6b1I0lykasXzPK5veF6o26Xk=; b=rXg+fj/DzoTvLQUq1C+NqmI1l/Dv9/E+2MpEhMt9Bn2phj0jP+SEVHcy6DFdj25ZWT cUZnz/qO1Qjs6y8pbxud7nGfmNScImOxjXZtq0ysNMkYcUmVxJTMi9HqajRH89WZDJPp D4n08kz2zhlNVxK5fLBL2MbnBu36uVh8B50QgJUpIjy2Ln2ixFUb9wkTubZUR2z5s0tU l6+mFPAmw4nGWooXRhLE3pmb7yHtaNG5Ilo6WykD0NpSojQ5s/1wggb/ZB/NfVTawK/x 5DG/FXxuiw4SnZ0HBZkOh4NSj4bScSQfDWK4NLUnyqqdHvOXZ0FrIU8hGYtakERRt/Gv 0l1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767183763; x=1767788563; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EnX+YiWBwSFj03NZe+M6b1I0lykasXzPK5veF6o26Xk=; b=KKdzMopagE/dQ/W3D1nQzWvcJtFUGdwQ9FQzwL8zSLPx0Q6CF/+k2PU79CzjZhCImO aKwG8msbpbY1+kFOT8KnQz7y/wzimiCkpvSh2RDGGf0Mz7xRIaAL8YB1dZ3k/piYp3Mt oJeE5okgkXcl++ysepK7AnR3z/fN3b4YcX/4Z78lOrkPmAjuJnRXuPwluiIUU2gGlfh6 O6XwEqIaOq1TWGXB9KKR4Y5G54cQ7VDExjDQ+xRH8XkhXkd41B6yzzLdMBMta+5c14gm WnrcOj1f37PyaFt4+ES6BFzvr/QSpDwdLc3oLptqCILU8N/DvTOBn1EzjdwoiBmATncQ C0Jg== X-Forwarded-Encrypted: i=1; AJvYcCVP1XbP0regoluS6TWi446fgsM8q5yFXhp46rD51JoeISe0kP9aVflrVelsgrHQ0ACT5mT2b+jvHKzJRcs=@vger.kernel.org X-Gm-Message-State: AOJu0YyqmA5FWsTzZ5GbWNxhvKXAw4KQu5N5ohPw1by/T4wgwPb/i9vc k2do7y5sal7apAsRZ+a3cq4E9UvLj4ywIKL3t5pkNAMa/T9UZ0Cp6edD+XpUlBpMkfJrCWENiid DbMBiG9btcxGPxNBvSg== X-Google-Smtp-Source: AGHT+IEVvKcXr6CgV/sO/SopdsqbSp5OU9ou7XeJWfmPxsy3aUaKE2cdpBZhPeJYGAC28ivLbvgGuv+puag4k9w= X-Received: from wro8.prod.google.com ([2002:a05:6000:41c8:b0:432:5cc6:c7ec]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:40db:b0:42c:b8fd:21b3 with SMTP id ffacd0b85a97d-4324e70b2c0mr47793415f8f.57.1767183762838; Wed, 31 Dec 2025 04:22:42 -0800 (PST) Date: Wed, 31 Dec 2025 12:22:29 +0000 In-Reply-To: <20251231-rwonce-v1-0-702a10b85278@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251231-rwonce-v1-0-702a10b85278@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1210; i=aliceryhl@google.com; h=from:subject:message-id; bh=x48g//vEaovaCGc/+3V+kdS96OVZQrdlR7cVmTcJM3Y=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBpVRWLpYz+qsgfDBCA957maLrU5abZ/AV0KNPf2 x2dVJo4CRyJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaVUViwAKCRAEWL7uWMY5 RpbRD/0SaSpBYAhj01HuT6p1Sh0F3HjDBRU4CbZou0WZNZ4WriLhGAdf+MIIjlEt+5DLcmae+YX 27BXKetHb+p7wJar0/d6qrTf/TQHUwmCyaL950x8UvyGKZjIVa/TCNx64b/oJobA7VmOtuNtFHr krbCJy/HsPCYdyTfYX7LhHPaeMGMOZDlhS5MWUgWYmbEo0Jx4LgSaNXEzhQpnmDg88F1vPMjjhW no8A0idLJ5umHWtXn0h1OKB0XvRpQTVwo+JZsNk8M/8cFdcvbJQxHrbwuTEGFaIkb01dRY1Ntdf 01rcHfSx1yu4iyuNDwnwXWxKy6Gk0DisKWSz0r+uqQjJIH5yLwLiZ+oKtGUU50CoT+p7D3XX7ee NQYmTAfFErPyMycWpb0rdPLebSye3a2RtXxOO0cCLsGAzKsadQYt9Qyiz/SRaSuGAxprP+2SaA1 tYW2y41LKbfKByd3v4AXtcjuXykAoAaaZnFcRcSSFxaaLuuAzS1kB42Gdu92hVpMPWBZ16h/RLM lf/wjXI1jEitSsib4IBK188r4m5IDfIk6q5hlJM5cvNgfzDpsOBNpz0qvCLfTiIP01+JvimWH6n S+0cvXpMJQIc85ahkyeZd7IPV6qu+FHl1qL2ZnTHNJ0ktF6I2ONB+Fvhbz5Z7ky5OYO5MmZfBJO 4eEFKw4YUaLnpqg== X-Mailer: b4 0.14.2 Message-ID: <20251231-rwonce-v1-5-702a10b85278@google.com> Subject: [PATCH 5/5] rust: fs: use READ_ONCE instead of read_volatile From: Alice Ryhl To: Boqun Feng , Will Deacon , Peter Zijlstra Cc: Richard Henderson , Matt Turner , Magnus Lindholm , Catalin Marinas , Miguel Ojeda , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Mark Rutland , FUJITA Tomonori , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , John Stultz , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Using `READ_ONCE` is the correct way to read the `f_flags` field. Signed-off-by: Alice Ryhl --- rust/kernel/fs/file.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs index 23ee689bd2400565223181645157d832a836589f..6b07f08e7012f512e5374326609= 6ce0076d29e1c 100644 --- a/rust/kernel/fs/file.rs +++ b/rust/kernel/fs/file.rs @@ -335,12 +335,8 @@ pub fn cred(&self) -> &Credential { /// The flags are a combination of the constants in [`flags`]. #[inline] pub fn flags(&self) -> u32 { - // This `read_volatile` is intended to correspond to a READ_ONCE c= all. - // - // SAFETY: The file is valid because the shared reference guarante= es a nonzero refcount. - // - // FIXME(read_once): Replace with `read_once` when available on th= e Rust side. - unsafe { core::ptr::addr_of!((*self.as_ptr()).f_flags).read_volati= le() } + // SAFETY: The `f_flags` field of `struct file` is readable with `= READ_ONCE`. + unsafe { kernel::sync::READ_ONCE(&raw const (*self.as_ptr()).f_fla= gs) } } } =20 --=20 2.52.0.351.gbe84eed79e-goog