From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Will Deacon" <will@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Lyude Paul" <lyude@redhat.com>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH v5 2/4] rust: sync: atomic: add atomic_per_byte_memcpy
Date: Wed, 11 Nov 2026 14:46:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-209187@kernel.org> (raw)
In-Reply-To: <20261110-page-volatile-io-v5-2-a91ef252c24b@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] rust: sync: atomic: missing #[inline] attribute on
atomic_per_byte_memcpy()
- [Low] rust: sync: atomic: wrong core::ptr::copy() doc on
atomic_per_byte_memcpy()
--
commit cade864abc69fc627ff4e6283efdc3170c94fccf
Author: Andreas Hindborg <a.hindborg@kernel.org>
rust: sync: atomic: add atomic_per_byte_memcpy
This commit adds atomic_per_byte_memcpy() in kernel::sync::atomic, wrapping
the kernel's memcpy() to perform byte-wise atomic memory copies.
> diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs
> index 6d27898add42c..cbcb081d8674e 100644
> --- a/rust/kernel/sync/atomic.rs
> +++ b/rust/kernel/sync/atomic.rs
> @@ -848,3 +848,38 @@ pub unsafe fn cmpxchg<T: AtomicType, Ordering: ordering::Ordering>(
> // per LKMM.
> unsafe { Atomic::from_ptr(ptr) }.cmpxchg(old, new, o)
> }
> +
> +/// Copy `len` bytes from `src` to `dst` using byte-wise atomic operations.
> +///
> +/// This is the concurrent-safe counterpart of `core::ptr::copy()` (the equivalent of standard
> +/// C's `memcpy()`). Because of the atomicity at byte level, when racing with another concurrent
[Severity: Low]
Should this documentation (and the commit message) refer to
core::ptr::copy_nonoverlapping() instead of core::ptr::copy()?
core::ptr::copy() is the equivalent of C's memmove() and permits overlapping
regions, whereas core::ptr::copy_nonoverlapping() corresponds to C's
memcpy() and matches the safety requirement below that src and dst do not
overlap.
> +/// atomic access (or when a normal read races with an atomic read), or with an external access
> +/// (from DMA or userspace), the behavior of this function is defined: the memory is copied at
> +/// (at least) byte granularity.
> +///
> +/// Implementation note: this is currently implemented by the kernel's `memcpy()`, which is
> +/// implemented in a way such that byte-wise atomic memory load/store instructions are used.
> +///
> +/// # Safety
> +///
> +/// Callers must ensure that:
> +///
> +/// - `src` is valid for atomic reads for `len` bytes for the duration of the call.
> +/// - `dst` is valid for atomic writes for `len` bytes for the duration of the call.
> +/// - The memory regions `src .. src + len` and `dst .. dst + len` do not overlap.
> +pub unsafe fn atomic_per_byte_memcpy(src: *const u8, dst: *mut u8, len: usize) {
> + // SAFETY: By the safety requirements of this function, the following operation will not:
> + // - Trap.
> + // - Invalidate any reference invariants.
> + // - Race with any operation by the Rust AM, as `bindings::memcpy` is a byte-wise atomic
> + // operation and all operations by the Rust AM to the involved memory areas use byte-wise
> + // atomic semantics.
> + // - Copy between overlapping regions, which `memcpy()` does not support.
> + unsafe {
> + bindings::memcpy(
> + dst.cast::<kernel::ffi::c_void>(),
> + src.cast::<kernel::ffi::c_void>(),
> + len,
> + )
> + };
> +}
[Severity: Low]
Should atomic_per_byte_memcpy() be marked #[inline]? It is a non-generic
function in the kernel crate that forwards directly to bindings::memcpy(),
so without #[inline] callers in other crates cannot inline the wrapper
unless LTO is enabled.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261110-page-volatile-io-v5-0-a91ef252c24b@kernel.org?part=2
next prev parent reply other threads:[~2026-11-11 14:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 14:44 [PATCH v5 0/4] rust: byte-wise atomic copies between `Page` and shared memory Andreas Hindborg
2026-11-10 14:44 ` [PATCH v5 1/4] rust: io: require freedom from plain accesses for `SysMem` Andreas Hindborg
2026-11-11 14:46 ` sashiko-bot
2026-11-11 19:40 ` Andreas Hindborg
2026-11-10 14:44 ` [PATCH v5 2/4] rust: sync: atomic: add atomic_per_byte_memcpy Andreas Hindborg
2026-11-11 14:46 ` sashiko-bot [this message]
2026-11-11 19:43 ` Andreas Hindborg
2026-11-10 14:44 ` [PATCH v5 3/4] rust: io: copy `SysMem` with `atomic_per_byte_memcpy` Andreas Hindborg
2026-11-10 14:44 ` [PATCH v5 4/4] rust: page: add byte-wise atomic copy methods for `SysMem` Andreas Hindborg
2026-11-11 9:30 ` [PATCH v5 0/4] rust: byte-wise atomic copies between `Page` and shared memory Peter Zijlstra
2026-11-11 13:26 ` Andreas Hindborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-209187@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=mark.rutland@arm.com \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=will@kernel.org \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.