rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drm: nova: Align GEM memory allocation to system page size
@ 2025-12-08  6:44 Brendan Shephard
  2025-12-13 18:41 ` Joel Fernandes
  0 siblings, 1 reply; 2+ messages in thread
From: Brendan Shephard @ 2025-12-08  6:44 UTC (permalink / raw)
  To: aliceryhl, joelagnelf, acourbot, airlied
  Cc: rust-for-linux, nouveau, Brendan Shephard

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.

This change uses the updated page_align() function from commit:
"rust: Return Option from page_align and ensure no usize overflow"
Which returns an Option<usize> for overflow safety.

Signed-off-by: Brendan Shephard <bshephar@bne-home.net>
---
Changes in v2:
- Updated to use the new page_align() Option<usize> return value from:
  Commit: "rust: Return Option from page_align and ensure no usize overflow"
  https://lore.kernel.org/rust-for-linux/20251204224006.353646-2-bshephar@bne-home.net/T/#u

 drivers/gpu/drm/nova/gem.rs | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/nova/gem.rs b/drivers/gpu/drm/nova/gem.rs
index 2760ba4f3450..41439f3b9361 100644
--- a/drivers/gpu/drm/nova/gem.rs
+++ b/drivers/gpu/drm/nova/gem.rs
@@ -3,6 +3,7 @@
 use kernel::{
     drm,
     drm::{gem, gem::BaseObject},
+    page::page_align,
     prelude::*,
     sync::aref::ARef,
 };
@@ -27,11 +28,7 @@ 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 {
-            return Err(EINVAL);
-        }
+        let aligned_size = page_align(size).ok_or(EINVAL)?
 
         gem::Object::new(dev, aligned_size)
     }

base-commit: 37bb2e7217b01404e2abf9d90d8e5705a5603b52
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] drm: nova: Align GEM memory allocation to system page size
  2025-12-08  6:44 [PATCH v2] drm: nova: Align GEM memory allocation to system page size Brendan Shephard
@ 2025-12-13 18:41 ` Joel Fernandes
  0 siblings, 0 replies; 2+ messages in thread
From: Joel Fernandes @ 2025-12-13 18:41 UTC (permalink / raw)
  To: Brendan Shephard; +Cc: aliceryhl, acourbot, airlied, rust-for-linux, nouveau

On Mon, Dec 08, 2025 at 04:44:05PM +1000, Brendan Shephard 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.
> 
> This change uses the updated page_align() function from commit:
> "rust: Return Option from page_align and ensure no usize overflow"
> Which returns an Option<usize> for overflow safety.
> 
> Signed-off-by: Brendan Shephard <bshephar@bne-home.net>
> ---
> Changes in v2:
> - Updated to use the new page_align() Option<usize> return value from:
>   Commit: "rust: Return Option from page_align and ensure no usize overflow"
>   https://lore.kernel.org/rust-for-linux/20251204224006.353646-2-bshephar@bne-home.net/T/#u
> 
>  drivers/gpu/drm/nova/gem.rs | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nova/gem.rs b/drivers/gpu/drm/nova/gem.rs
> index 2760ba4f3450..41439f3b9361 100644
> --- a/drivers/gpu/drm/nova/gem.rs
> +++ b/drivers/gpu/drm/nova/gem.rs
> @@ -3,6 +3,7 @@
>  use kernel::{
>      drm,
>      drm::{gem, gem::BaseObject},
> +    page::page_align,
>      prelude::*,
>      sync::aref::ARef,
>  };
> @@ -27,11 +28,7 @@ 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 {
> -            return Err(EINVAL);
> -        }
> +        let aligned_size = page_align(size).ok_or(EINVAL)?

Don't you lose the size == 0 check here? If intentional, please update the
changelog mentioning it.

thanks,

 - Joel




>  
>          gem::Object::new(dev, aligned_size)
>      }
> 
> base-commit: 37bb2e7217b01404e2abf9d90d8e5705a5603b52
> -- 
> 2.52.0
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-13 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-08  6:44 [PATCH v2] drm: nova: Align GEM memory allocation to system page size Brendan Shephard
2025-12-13 18:41 ` Joel Fernandes

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).