From: Deborah Brouwer <deborah.brouwer@collabora.com>
To: "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>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org,
Deborah Brouwer <deborah.brouwer@collabora.com>
Subject: [PATCH v4 2/3] rust: uaccess: add method to get UserPtr from u64
Date: Tue, 20 Oct 2026 17:06:46 -0700 [thread overview]
Message-ID: <20261020-b4-dev_query_fixes-v4-2-df66b4c98bc6@collabora.com> (raw)
In-Reply-To: <20261020-b4-dev_query_fixes-v4-0-df66b4c98bc6@collabora.com>
Currently a UserPtr can be created from a usize integer representing a
userspace address. To create a UserPtr from a u64 integer, the u64 must
be cast to usize. On 32-bit systems, this cast will discard the upper 32
bits of the address.
Provide a new method to create a UserPtr from a u64 integer. This avoids
the caller having to cast before creating a UserPtr and also clarifies
that the truncation is intended. This is equivalent to the C-side
macro u64_to_user_ptr() that provides typechecking and casting to a __user
pointer.
Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
rust/kernel/uaccess.rs | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
index 8e18285ec44b..a6fd1af155b3 100644
--- a/rust/kernel/uaccess.rs
+++ b/rust/kernel/uaccess.rs
@@ -31,6 +31,15 @@ pub fn from_addr(addr: usize) -> Self {
Self(addr as *mut c_void)
}
+ /// Create a `UserPtr` from a u64 userspace address.
+ ///
+ /// Deliberately truncate upper bits for 32-bit systems.
+ #[doc(alias = "u64_to_user_ptr")]
+ #[inline]
+ pub fn from_u64(addr: u64) -> Self {
+ Self::from_addr(addr as usize)
+ }
+
/// Create a `UserPtr` from a pointer representing the userspace address.
#[inline]
pub fn from_ptr(addr: *mut c_void) -> Self {
--
2.56.0
next prev parent reply other threads:[~2026-10-21 0:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 0:06 [PATCH v4 0/3] drm/tyr: allow mismatched buffers for dev_query Deborah Brouwer
2026-10-21 0:06 ` [PATCH v4 1/3] rust: uaccess: add UserSliceWriter::clear() Deborah Brouwer
2026-10-21 0:06 ` Deborah Brouwer [this message]
2026-10-21 0:06 ` [PATCH v4 3/3] drm/tyr: allow userspace buffers to be mismatched Deborah Brouwer
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=20261020-b4-dev_query_fixes-v4-2-df66b4c98bc6@collabora.com \
--to=deborah.brouwer@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®