From: Alice Ryhl <aliceryhl@google.com>
To: Brendan Shephard <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: Wed, 26 Nov 2025 09:53:06 +0000 [thread overview]
Message-ID: <aSbOAsOJbhtkJACJ@google.com> (raw)
In-Reply-To: <aSaU5lSmtD17U0kT@fedora>
On Wed, Nov 26, 2025 at 03:49:26PM +1000, Brendan Shephard wrote:
> On Tue, Nov 25, 2025 at 09:23:59AM +0000, Alice Ryhl wrote:
> > On Fri, Nov 21, 2025 at 02:04:28PM +1000, bshephar@bne-home.net wrote:
> > > 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
>
> Thanks for the review Alice. I used usize here because the page_align()
> function specifically mentions that the provided value should not
> overflow a ['usize'].
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/rust/kernel/page.rs#n30
>
> I don't think that alone needs to be the deciding factor, but it's worth
> expressing why I made that decision to begin with. Happy to hear your
> thoughts, and if you still feel isize::MAX is more appropriate given
> this information.
I know that you picked this particular limit to avoid integer overflow.
I think picking a lower limit makes sense because isize::MAX is a
relatively standard choice for maximum allocation sizes. I think it is a
nice choice because it means you can always compute 2*x for any index or
size x without risk of overflow.
But it's up to the nova folks, not me.
Alice
next prev parent reply other threads:[~2025-11-26 9:53 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 [this message]
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=aSbOAsOJbhtkJACJ@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).