Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

memblock: Move late alloc warning down to phys alloc

If a driver/subsystem tries to do an allocation after the memblock
allocations have been freed and the memory handed to the buddy
allocator, it will not actually be legal to use that allocation: the
buddy allocator owns the memory. Currently this mis-use is handled by
the memblock function which does allocations and returns virtual
addresses by printing a warning and doing a kmalloc instead. However
the physical allocation function does not to do this check - callers of
the physical alloc function are unprotected against mis-use.

Improve the error catching here by moving the check into the physical
allocation function which is used by the virtual addr allocation
function.

Signed-off-by: James Gowans <jgowans@amazon.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alex Graf <graf@amazon.de>
Link: https://lore.kernel.org/r/20240619095555.85980-1-jgowans@amazon.com
Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>

authored by

James Gowans and committed by
Mike Rapoport (IBM)
94ff46de d9d814ee

+11 -7
+11 -7
mm/memblock.c
··· 1449 1449 if (WARN_ONCE(nid == MAX_NUMNODES, "Usage of MAX_NUMNODES is deprecated. Use NUMA_NO_NODE instead\n")) 1450 1450 nid = NUMA_NO_NODE; 1451 1451 1452 + /* 1453 + * Detect any accidental use of these APIs after slab is ready, as at 1454 + * this moment memblock may be deinitialized already and its 1455 + * internal data may be destroyed (after execution of memblock_free_all) 1456 + */ 1457 + if (WARN_ON_ONCE(slab_is_available())) { 1458 + void *vaddr = kzalloc_node(size, GFP_NOWAIT, nid); 1459 + 1460 + return vaddr ? virt_to_phys(vaddr) : 0; 1461 + } 1462 + 1452 1463 if (!align) { 1453 1464 /* Can't use WARNs this early in boot on powerpc */ 1454 1465 dump_stack(); ··· 1585 1574 { 1586 1575 phys_addr_t alloc; 1587 1576 1588 - /* 1589 - * Detect any accidental use of these APIs after slab is ready, as at 1590 - * this moment memblock may be deinitialized already and its 1591 - * internal data may be destroyed (after execution of memblock_free_all) 1592 - */ 1593 - if (WARN_ON_ONCE(slab_is_available())) 1594 - return kzalloc_node(size, GFP_NOWAIT, nid); 1595 1577 1596 1578 if (max_addr > memblock.current_limit) 1597 1579 max_addr = memblock.current_limit;