Bug 251389 - linuxkpi malloc is not strictly compatible with Linux
Summary: linuxkpi malloc is not strictly compatible with Linux
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-emulation (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-26 01:32 UTC by Justin Hibbits
Modified: 2020-11-27 00:29 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Hibbits freebsd_committer freebsd_triage 2020-11-26 01:32:09 UTC
Linux's kmalloc seems to provide the following guarantees:

* GPF_KERNEL returns memory in the lower 4GB physical space
* Allocations are physically contiguous

malloc(9) does not make either of these guarantees.  This ends up breaking DRM modules on powerpc64 platforms, where even if memory happens to be contiguous it may not be in the bottom 4GB physical address space, and it may even be in a different NUMA domain, where NUMA domains are physically indexed at 1<<45, such that the bottom 4GB of the second NUMA domain doesn't fit into the 40-bit PA range accessible to Radeon GPUs.

Contiguity can be emulated with contigmalloc(9), but that's not a viable solution for replacing all calls, as it's very possible for the size to not be known and traceable through the lifetime of a pointer.
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2020-11-26 16:22:23 UTC
(In reply to Justin Hibbits from comment #0)
Is this a cross-platform guarantee, or only valid and assumed for PPC ?
Comment 2 Justin Hibbits freebsd_committer freebsd_triage 2020-11-27 00:29:32 UTC
(In reply to Konstantin Belousov from comment #1)
It appears to be a general guarantee, from reading the linux source.

GFP_KERNEL implies ZONE_NORMAL, which is guaranteed to be below 4GB.  The contiguity guarantee looks to be a property of the Linux slab allocator.