Some(ptr) => {
Hi all,
Today's linux-next merge of the mm-unstable tree got a conflict in:
rust/kernel/alloc/allocator.rs
between commit:
fde578c86281 ("rust: alloc: replace aligned_size() with Kmalloc::aligned_layout()")
from the drm-misc-fixes tree and commit:
cda097b07bce ("rust: support large alignments in allocations")
from the mm-unstable tree.
I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging. You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.
--
Cheers,
Stephen Rothwell
diff --cc rust/kernel/alloc/allocator.rs
index 2692cf90c948,63f271624428..000000000000
--- a/rust/kernel/alloc/allocator.rs
+++ b/rust/kernel/alloc/allocator.rs
@@@ -43,11 -42,28 +42,17 @@@ pub struct Vmalloc
/// For more details see [self].
pub struct KVmalloc;
-/// Returns a proper size to alloc a new object aligned to `new_layout`'s alignment.
-fn aligned_size(new_layout: Layout) -> usize {
- // Customized layouts from `Layout::from_size_align()` can have size < align, so pad first.
- let layout = new_layout.pad_to_align();
-
- // Note that `layout.size()` (after padding) is guaranteed to be a multiple of `layout.align()`
- // which together with the slab guarantees means the `krealloc` will return a properly aligned
- // object (see comments in `kmalloc()` for more information).
- layout.size()
-}
-
/// # Invariants
///
- /// One of the following: `krealloc`, `vrealloc`, `kvrealloc`.
+ /// One of the following: `krealloc_node_align`, `vrealloc_node_align`, `kvrealloc_node_align`.
struct ReallocFunc(
- unsafe extern "C" fn(*const crate::ffi::c_void, usize, u32) -> *mut crate::ffi::c_void,
+ unsafe extern "C" fn(
+ *const crate::ffi::c_void,
+ usize,
+ crate::ffi::c_ulong,
+ u32,
+ crate::ffi::c_int,
+ ) -> *mut crate::ffi::c_void,
);
impl ReallocFunc {
@@@ -76,8 -92,9 +81,9 @@@
layout: Layout,
old_layout: Layout,
flags: Flags,
+ nid: NumaNode,
) -> Result<NonNull<[u8]>, AllocError> {
- let size = aligned_size(layout);
+ let size = layout.size();
let ptr = match ptr {
Some(ptr) => {
if old_layout.size() == 0 {
@@@ -134,11 -140,10 +140,12 @@@ unsafe impl Allocator for Kmalloc
layout: Layout,
old_layout: Layout,
flags: Flags,
+ nid: NumaNode,
) -> Result<NonNull<[u8]>, AllocError> {
+ let layout = Kmalloc::aligned_layout(layout);
+
// SAFETY: `ReallocFunc::call` has the same safety requirements as `Allocator::realloc`.
- unsafe { ReallocFunc::KREALLOC.call(ptr, layout, old_layout, flags) }
+ unsafe { ReallocFunc::KREALLOC.call(ptr, layout, old_layout, flags, nid) }
}
}
@@@ -177,19 -177,10 +179,14 @@@ unsafe impl Allocator for KVmalloc
layout: Layout,
old_layout: Layout,
flags: Flags,
+ nid: NumaNode,
) -> Result<NonNull<[u8]>, AllocError> {
+ // `KVmalloc` may use the `Kmalloc` backend, hence we have to enforce a `Kmalloc`
+ // compatible layout.
+ let layout = Kmalloc::aligned_layout(layout);
+
- // TODO: Support alignments larger than PAGE_SIZE.
- if layout.align() > bindings::PAGE_SIZE {
- pr_warn!("KVmalloc does not support alignments larger than PAGE_SIZE yet.\n");
- return Err(AllocError);
- }
-
// SAFETY: If not `None`, `ptr` is guaranteed to point to valid memory, which was previously
// allocated with this `Allocator`.
- unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flags) }
+ unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flags, nid) }
}
}
On Wed Aug 13, 2025 at 3:11 AM CEST, Stephen Rothwell wrote: > Hi all, > > Today's linux-next merge of the mm-unstable tree got a conflict in: > > rust/kernel/alloc/allocator.rs > > between commit: > > fde578c86281 ("rust: alloc: replace aligned_size() with Kmalloc::aligned_layout()") > > from the drm-misc-fixes tree and commit: > > cda097b07bce ("rust: support large alignments in allocations") > > from the mm-unstable tree. > > I fixed it up (see below) and can carry the fix as necessary. This > is now fixed as far as linux-next is concerned, but any non trivial > conflicts should be mentioned to your upstream maintainer when your tree > is submitted for merging. You may also want to consider cooperating > with the maintainer of the conflicting tree to minimise any particularly > complex conflicts. Thanks, the resolution looks good!
On Wed, 13 Aug 2025 11:11:51 +1000 Stephen Rothwell <sfr@canb.auug.org.au> wrote: > Hi all, > > Today's linux-next merge of the mm-unstable tree got a conflict in: > > rust/kernel/alloc/allocator.rs > > between commit: > > fde578c86281 ("rust: alloc: replace aligned_size() with Kmalloc::aligned_layout()") > > from the drm-misc-fixes tree and commit: > > cda097b07bce ("rust: support large alignments in allocations") > > from the mm-unstable tree. > > I fixed it up (see below) and can carry the fix as necessary. This > is now fixed as far as linux-next is concerned, but any non trivial > conflicts should be mentioned to your upstream maintainer when your tree > is submitted for merging. You may also want to consider cooperating > with the maintainer of the conflicting tree to minimise any particularly > complex conflicts. > Thanks. Well that's messy. Is it intended that the containing series ("Alloc and drm::Device fixes") be merged into 6.17-rcX?
On Wed Aug 13, 2025 at 5:59 AM CEST, Andrew Morton wrote: > Thanks. > > Well that's messy. I think it's not too bad, the changes are just too close to each other -- no semantic conflict. As a general heads-up, Rust code is a bit more prone to conflicts. On one hand this is due to the more powerful type system and components of different subsystems being a bit closer connected to each other to provide additional safety guarantees. On the other hand, there's simply a lot of foundational work going on in parallel. For the Rust parts that are maintained under your mm tree, I think it should generally stay well within limits though. > Is it intended that the containing series ("Alloc and drm::Device > fixes") be merged into 6.17-rcX? Yes, not sure if it will be in -rc2 already, but should be in -rc3. So, the conflict in -next should vanish in case you backmerge the corresponding -rc.
© 2016 - 2025 Red Hat, Inc.