rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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: Thu, 27 Nov 2025 07:14:32 +1000	[thread overview]
Message-ID: <aSdtuN-iq7L6lx8D@fedora> (raw)
In-Reply-To: <DEIOIGNYXG3C.39IML6BFML3DE@nvidia.com>

On Wed, Nov 26, 2025 at 11:00:00PM +0900, Alexandre Courbot wrote:
> On Wed Nov 26, 2025 at 10:36 PM JST, Alice Ryhl wrote:
> > On Wed, Nov 26, 2025 at 10:22:14PM +0900, Alexandre Courbot wrote:
> >> On Wed Nov 26, 2025 at 6:54 PM JST, Alice Ryhl wrote:
> >> > On Wed, Nov 26, 2025 at 09:31:46AM +0900, Alexandre Courbot wrote:
> >> >> On Tue Nov 25, 2025 at 11:59 PM JST, Alice Ryhl wrote:
> >> >> > On Tue, Nov 25, 2025 at 3:55 PM Alexandre Courbot <acourbot@nvidia.com> wrote:
> >> >> >>
> >> >> >> On Tue Nov 25, 2025 at 11:41 PM JST, Alice Ryhl wrote:
> >> >> >> > On Tue, Nov 25, 2025 at 3:29 PM Alexandre Courbot <acourbot@nvidia.com> wrote:
> >> >> >> >>
> >> >> >> >> On Fri Nov 21, 2025 at 1:04 PM JST, bshephar wrote:
> >> >> >> >> >              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`.
> >> >> >
> >> >> > Alignment stores values that are powers of two, not multiples of PAGE_SIZE.
> >> >> 
> >> >> Isn't PAGE_SIZE always a power of two though?
> >> >
> >> > Yes it is. Maybe you can elaborate on how you wanted to use Alignment?
> >> > It sounds like you have something different in mind than what I thought.
> >> 
> >> I thought we could just do something like this:
> >> 
> >>     use kernel::ptr::{Alignable, Alignment};
> >> 
> >>     let aligned_size = size
> >>         .align_up(Alignment::new::<PAGE_SIZE>())
> >>         .ok_or(EOVERFLOW)?;
> >> 
> >> (maybe we could also have that `Alignment<PAGE_SIZE>` stored as a const
> >> in `page.rs` for convenience, as it might be used often)
> >
> > If you're trying to round up a number to the next multiple of PAGE_SIZE,
> > then you should use page_align() because that's exactly what the
> > function does.
> >
> > If you think there is something wrong with the design of page_align(),
> > change it instead of reimplemtning it.
> 
> In that case I would suggest that `page_align` returns an `Option`
> instead of potentially panicking. Does that sound reasonable? I cannot
> find any user of it in the Rust code for now.
> 

This sounds reasonable, and I did wonder when I read the comment on
page_align() whether it should just implement that check within the
function rather than relying on callers. But, I think changing the
signature of that function is probably something that should be done
separately to this change. I can't see anyone using it atm either, but
there could be unmerged branches or pending reviews that are using it.
If that's the path we want to go down, and it sounds completely
reasonable, I'll send that separately before posting a v2 of this patch
to use it.

Happy to take your guidance on that to satisfy the logistics of the
kernels ML driven patch approach.

  parent reply	other threads:[~2025-11-26 21:14 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 [this message]
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=aSdtuN-iq7L6lx8D@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 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).