Page MenuHomeFreeBSD

linuxkpi: Add Linux 6.12 variant of `kvrealloc()`
ClosedPublic

Authored by dumbbell on Apr 16 2026, 9:17 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, May 18, 6:30 AM
Unknown Object (File)
Mon, May 18, 6:24 AM
Unknown Object (File)
Sun, May 17, 10:12 PM
Unknown Object (File)
Sun, May 17, 10:05 PM
Unknown Object (File)
Mon, May 11, 10:39 PM
Unknown Object (File)
Sun, May 10, 2:37 AM
Unknown Object (File)
Sun, May 10, 2:29 AM
Unknown Object (File)
Sat, May 9, 10:07 PM
Subscribers

Details

Summary

In Linux 6.12, the API changed to be closer to krealloc():

  • The function does not take the old size anymore
  • The function becomes a wrapper around krealloc() with a fallback mechanism.

This is part of the update of DRM drivers to Linux 6.12.

Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bz requested changes to this revision.Apr 20 2026, 11:15 PM
bz added a subscriber: bz.
bz added inline comments.
sys/compat/linuxkpi/common/include/linux/slab.h
274

Again, I believe this should be the new default and the old version should require LINUXKPI_VERSION.

292

So if ptr is NULL we are in bad shape anyway also in the old version.

I believe what we could do to simplify this is:

size_t oldsize = ksize(ptr);

_lkpi_kvrealloc( ... ) which is the old versions and then the old version is a plain wrapper around the __lkpi_kvrealloc() one used by both. That way it is a lot less code duplication. And is we want we can add the ptr != NULL check there too if really needed.

This revision now requires changes to proceed.Apr 20 2026, 11:15 PM

Trying to address comments from @bz

sys/compat/linuxkpi/common/include/linux/slab.h
292

I’m not sure I fully understood your suggestion. So I moved the new implementation to its own function, __lkpi_kvrealloc(), which takes the oldsize argument. Then I modified the old and new APIs to call this internal function. Does this corresponds to what you had in mind?

Perhaps the __lkpi_kvrealloc() internal function should be moved to src/linux_slab.c, what do you think?

For the case where ptr is NULL, why do you think we are in a bad situation? According to the docs of krealloc() and kvrealloc(), passing a NULL pointer to them is the same as calling their k*malloc() equivalents. This is what we do in lkpi_realloc().

bz requested changes to this revision.Wed, Apr 22, 1:55 PM
bz added inline comments.
sys/compat/linuxkpi/common/include/linux/slab.h
292

Yes, the part below is exactly what I thought. The above logic I am not sure now after your explanation.

Do we need to do the same as lkpi_realloc then? Also krealloc looks wrong now that I think of it as it will enforce physically contiguous memory which we do not need in this case.

Yes it would likely make sense then to move __lkpi_kvrealloc as lkpi_kvrealloc into linux_slab.c and follow the logic of lkpi_krealloc() just without the if (size <= PAGE_SIZE) part and using kvmalloc/kvfree instead of kmalloc/kfree.

This revision now requires changes to proceed.Wed, Apr 22, 1:55 PM
  • Move lkpi_kvrealloc() to src/linux_slab.c
  • Replicate the behaviour of lkpi_krealloc() in lkpi_kvrealloc() instead of calling it to not request contiguous memory in case of a new allocation.
dumbbell added inline comments.
sys/compat/linuxkpi/common/include/linux/slab.h
292

I followed your suggestion and replicated the logic of krealloc() instead of calling it, to avoid a request of contiguous memory.

bz added inline comments.
sys/compat/linuxkpi/common/include/linux/slab.h
289

ksize calling malloc_usable_size() and malloc_usable_size() returns 0 if it's a NULL pointer; I had no idea about ZERO_SIZED_PTRS == 16. Nice catch.

This revision is now accepted and ready to land.Wed, Apr 22, 7:24 PM
This revision was automatically updated to reflect the committed changes.
dumbbell marked an inline comment as done.