From: Brendan Shephard <bshephar@bne-home.net>
To: Alexandre Courbot <acourbot@nvidia.com>
Cc: Alice Ryhl <aliceryhl@google.com>,
dakr@kernel.org, joelagnelf@nvidia.com, jhubbard@nvidia.com,
airlied@gmail.com, rust-for-linux@vger.kernel.org,
nouveau@lists.freedesktop.org, brendan.shephard@gmail.com,
Nouveau <nouveau-bounces@lists.freedesktop.org>
Subject: Re: [PATCH 1/1] drm: nova: Align GEM memory allocation to system page size
Date: Wed, 26 Nov 2025 16:05:47 +1000 [thread overview]
Message-ID: <aSaYu8GCrU4XRRNF@fedora> (raw)
In-Reply-To: <DEHV24KY55H3.16CA6ALYGJ68A@nvidia.com>
On Tue, Nov 25, 2025 at 11:55:08PM +0900, Alexandre Courbot wrote:
> On Tue Nov 25, 2025 at 11:41 PM JST, Alice Ryhl wrote:
> >> > @@ -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 {
> >>
> >> `PAGE_SIZE` here is no more correct than the hardcoded `1 << 12` - well,
> >> I'll admit it looks better as a placeholder. :) But the actual alignment
> >> will eventually be provided elsewhere.
> >
> > What about kernels with 16k pages?
>
> The actual alignment should IIUC be a mix of the GPU and kernel's
> requirements (GPU can also use a different page size). So no matter what
> we pick right now, it won't be great but you are right that PAGE_SIZE
> will at least accomodate the kernel.
>
So, maybe what we realistically should be doing is aligning to the
larger page size when comparing system and GPU page sizes?
> >
> >> > return Err(EINVAL);
> >> > }
> >> >
> >> > + let aligned_size = page_align(size);
> >>
> >> `page_align` won't panic on overflow, but it will still return an
> >> invalid size. This is a job for `kernel::ptr::Alignment`, which let's
> >> you return an error when an overflow occurs.
> >
> > The Rust implementation of page_align() is implemented as (addr +
> > (PAGE_SIZE - 1)) & PAGE_MASK, which definitely will panic on overflow
> > if the appropriate config options are enabled.
>
> That's right, I skimmed its code too fast. ^_^; All the more reason to
> use `Alignment`.
We would still need to ensure the value is a multiple of PAGE_SIZE
though right? Like if the user requests a size that is _not_ a multiple
of 2, then we would want to align the value to a PAGE_SIZE. Which is
what the existing logic does, it's just always rounding to the next
multiple of 4096. Maybe I'm missing something about Alignment and I need
to spend some more time looking at it as an alternative here.
prev parent reply other threads:[~2025-12-13 12:17 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
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 [this message]
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=aSaYu8GCrU4XRRNF@fedora \
--to=bshephar@bne-home.net \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=brendan.shephard@gmail.com \
--cc=dakr@kernel.org \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=nouveau-bounces@lists.freedesktop.org \
--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 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.