[PATCH 03/11] rust: io: add `SysMem::fill_zero`

From: Andreas Hindborg

Date: Fri Nov 20 2026 - 05:28:22 EST


Add a method for zeroing the memory of a `SysMem` byte view. The method
uses `atomic::memset()`, so the memory can be subject to concurrent
accesses.

This is used to zero the data of a page that is mapped to user space or
shared with a device.

Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/kernel/io.rs | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
index 76904c63eb0a..33cb5a9fb3a8 100644
--- a/rust/kernel/io.rs
+++ b/rust/kernel/io.rs
@@ -1586,6 +1586,17 @@ unsafe impl<T: ?Sized + Sync> Send for SysMem<'_, T> {}
// SAFETY: `SysMem<'_, T>` is conceptually `&T`.
unsafe impl<T: ?Sized + Sync> Sync for SysMem<'_, T> {}

+impl SysMem<'_, [u8]> {
+ /// Writes zeroes to all bytes of the view using byte-wise atomic operations.
+ #[inline]
+ pub fn fill_zero(self) {
+ // SAFETY: Per type invariant, `self.ptr` is a valid kernel accessible memory region of
+ // `self.ptr.len()` bytes, and no plain access races with this write, so it is valid for
+ // atomic writes.
+ unsafe { atomic::memset(self.ptr.cast(), 0, self.ptr.len()) };
+ }
+}
+
impl<'a, T: ?Sized> SysMem<'a, T> {
/// Create a `SysMem` from a raw pointer.
///

--
2.54.0