ANDROID: rust_binder: allocate pages array with kvmalloc

Avoid making order 3 allocations with kmalloc. Using kvmalloc will help
avoid OOM conditions.

Bug: 350907206
Change-Id: Ib1e8c113ac2cbe6b46938e2541ff76efc1f9d111
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
This commit is contained in:
Alice Ryhl
2025-07-23 12:43:49 +00:00
committed by Treehugger Robot
parent 3f3a5c5e78
commit 138082a939
+4 -4
View File
@@ -21,7 +21,7 @@ use core::{
};
use kernel::{
alloc::allocator::Kmalloc,
alloc::allocator::KVmalloc,
alloc::Allocator,
bindings,
error::Result,
@@ -297,7 +297,7 @@ impl ShrinkablePageRange {
let layout = Layout::array::<PageInfo>(num_pages).map_err(|_| ENOMEM)?;
// SAFETY: The layout has non-zero size.
let pages = Kmalloc::alloc(layout, GFP_KERNEL)?.cast::<PageInfo>();
let pages = KVmalloc::alloc(layout, GFP_KERNEL)?.cast::<PageInfo>();
// SAFETY: This just initializes the pages array.
unsafe {
@@ -317,7 +317,7 @@ impl ShrinkablePageRange {
pr_debug!("Failed to register with vma: already registered");
drop(inner);
// SAFETY: The `pages` array was allocated with the same layout.
unsafe { Kmalloc::free(pages.cast(), layout) };
unsafe { KVmalloc::free(pages.cast(), layout) };
return Err(EBUSY);
}
@@ -647,7 +647,7 @@ impl PinnedDrop for ShrinkablePageRange {
let layout = unsafe { Layout::array::<PageInfo>(size).unwrap_unchecked() };
// SAFETY: The `pages` array was allocated with the same layout.
unsafe { Kmalloc::free(pages.cast(), layout) };
unsafe { KVmalloc::free(pages.cast(), layout) };
}
}