]> git.baikalelectronics.ru Git - kernel.git/commit
memblock: introduce saner 'memblock_free_ptr()' interface
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 Sep 2021 20:23:22 +0000 (13:23 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 Sep 2021 20:23:22 +0000 (13:23 -0700)
commit14cda2ccc54b3b907a6ec28d76b1a3c77517a167
tree96d0a1d317e28e7b22165ca419c99f7313e64ea3
parent9a3ae1064c0d08fe62c0324b0bc595c106a6d31c
memblock: introduce saner 'memblock_free_ptr()' interface

The boot-time allocation interface for memblock is a mess, with
'memblock_alloc()' returning a virtual pointer, but then you are
supposed to free it with 'memblock_free()' that takes a _physical_
address.

Not only is that all kinds of strange and illogical, but it actually
causes bugs, when people then use it like a normal allocation function,
and it fails spectacularly on a NULL pointer:

   https://lore.kernel.org/all/20210912140820.GD25450@xsang-OptiPlex-9020/

or just random memory corruption if the debug checks don't catch it:

   https://lore.kernel.org/all/61ab2d0c-3313-aaab-514c-e15b7aa054a0@suse.cz/

I really don't want to apply patches that treat the symptoms, when the
fundamental cause is this horribly confusing interface.

I started out looking at just automating a sane replacement sequence,
but because of this mix or virtual and physical addresses, and because
people have used the "__pa()" macro that can take either a regular
kernel pointer, or just the raw "unsigned long" address, it's all quite
messy.

So this just introduces a new saner interface for freeing a virtual
address that was allocated using 'memblock_alloc()', and that was kept
as a regular kernel pointer.  And then it converts a couple of users
that are obvious and easy to test, including the 'xbc_nodes' case in
lib/bootconfig.c that caused problems.

Reported-by: kernel test robot <oliver.sang@intel.com>
Fixes: 25da0f4f4b8c ("init: bootconfig: Remove all bootconfig data when the init memory is removed")
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/x86/kernel/setup_percpu.c
arch/x86/mm/kasan_init_64.c
arch/x86/mm/numa.c
arch/x86/mm/numa_emulation.c
drivers/base/arch_numa.c
drivers/macintosh/smu.c
include/linux/memblock.h
init/main.c
kernel/printk/printk.c
lib/bootconfig.c
mm/memblock.c