From: Alice Ryhl <aliceryhl@google.com>
To: bshephar@bne-home.net
Cc: dakr@kernel.org, acourbot@nvidia.com, joelagnelf@nvidia.com,
jhubbard@nvidia.com, airlied@gmail.com,
rust-for-linux@vger.kernel.org, nouveau@lists.freedesktop.org,
brendan.shephard@gmail.com
Subject: Re: [PATCH 1/1] drm: nova: Align GEM memory allocation to system page size
Date: Tue, 25 Nov 2025 09:23:59 +0000 [thread overview]
Message-ID: <aSV1rxXq4KuInexy@google.com> (raw)
In-Reply-To: <98227EBD-92F7-40FC-A5A4-3FF3780FB2CB@bne-home.net>
On Fri, Nov 21, 2025 at 02:04:28PM +1000, bshephar@bne-home.net wrote:
> Use page::page_align for GEM object memory allocation to ensure the
> allocation is page aligned. This ensures that the allocation is page
> aligned with the system in cases where 4096 is not the default.
> For example on 16k or 64k aarch64 systems this allocation should be
> aligned accordingly.
>
> Signed-off-by: Brendan Shephard <bshephar@bne-home.net>
> ---
> drivers/gpu/drm/nova/gem.rs | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/nova/gem.rs b/drivers/gpu/drm/nova/gem.rs
> index 2760ba4f3450..a07e922e25ef 100644
> --- a/drivers/gpu/drm/nova/gem.rs
> +++ b/drivers/gpu/drm/nova/gem.rs
> @@ -3,6 +3,10 @@
> use kernel::{
> drm,
> drm::{gem, gem::BaseObject},
> + page::{
> + page_align,
> + PAGE_SIZE, //
> + },
> prelude::*,
> sync::aref::ARef,
> };
> @@ -27,12 +31,13 @@ fn new(_dev: &NovaDevice, _size: usize) -> impl PinInit<Self, Error> {
> impl NovaObject {
> /// Create a new DRM GEM object.
> pub(crate) fn new(dev: &NovaDevice, size: usize) -> Result<ARef<gem::Object<Self>>> {
> - let aligned_size = size.next_multiple_of(1 << 12);
> -
> - if size == 0 || size > aligned_size {
> + // Check for 0 size or potential usize overflow before calling page_align
> + if size == 0 || size > usize::MAX - PAGE_SIZE + 1 {
Maybe this should use isize::MAX as the maximum size instead? That's a
pretty common maximum size for allocations in Rust and big enough for
everyone.
Alice
> return Err(EINVAL);
> }
>
> + let aligned_size = page_align(size);
> +
> gem::Object::new(dev, aligned_size)
> }
>
> --
next prev parent reply other threads:[~2025-11-25 9:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 4:04 [PATCH 1/1] drm: nova: Align GEM memory allocation to system page size bshephar
2025-11-25 7:41 ` bshephar
2025-11-25 9:23 ` Alice Ryhl [this message]
2025-11-26 5:49 ` Brendan Shephard
2025-11-26 9:53 ` Alice Ryhl
2025-11-25 14:28 ` Alexandre Courbot
2025-11-25 14:41 ` Alice Ryhl
2025-11-25 14:55 ` Alexandre Courbot
2025-11-25 14:59 ` Alice Ryhl
2025-11-26 0:31 ` Alexandre Courbot
2025-11-26 9:54 ` Alice Ryhl
2025-11-26 13:22 ` Alexandre Courbot
2025-11-26 13:36 ` Alice Ryhl
2025-11-26 14:00 ` Alexandre Courbot
2025-11-26 16:24 ` Alice Ryhl
2025-11-26 21:14 ` Brendan Shephard
2025-11-26 6:05 ` Brendan Shephard
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=aSV1rxXq4KuInexy@google.com \
--to=aliceryhl@google.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=brendan.shephard@gmail.com \
--cc=bshephar@bne-home.net \
--cc=dakr@kernel.org \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=nouveau@lists.freedesktop.org \
--cc=rust-for-linux@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).