Skip to content
Snippets Groups Projects
Commit 3051025a authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Frieder Schrempf
Browse files

x86/mm: Simplify RESERVE_BRK()


commit a1e2c031 upstream.

RESERVE_BRK() reserves data in the .brk_reservation section.  The data
is initialized to zero, like BSS, so the macro specifies 'nobits' to
prevent the data from taking up space in the vmlinux binary.  The only
way to get the compiler to do that (without putting the variable in .bss
proper) is to use inline asm.

The macro also has a hack which encloses the inline asm in a discarded
function, which allows the size to be passed (global inline asm doesn't
allow inputs).

Remove the need for the discarded function hack by just stringifying the
size rather than supplying it as an input to the inline asm.

Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20220506121631.133110232@infradead.org


[nathan: Fix conflict due to lack of 2b6ff7de and 33def849]
Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2d7c4a39
No related branches found
No related tags found
Loading
...@@ -94,27 +94,19 @@ extern unsigned long _brk_end; ...@@ -94,27 +94,19 @@ extern unsigned long _brk_end;
void *extend_brk(size_t size, size_t align); void *extend_brk(size_t size, size_t align);
/* /*
* Reserve space in the brk section. The name must be unique within * Reserve space in the brk section. The name must be unique within the file,
* the file, and somewhat descriptive. The size is in bytes. Must be * and somewhat descriptive. The size is in bytes.
* used at file scope.
* *
* (This uses a temp function to wrap the asm so we can pass it the * The allocation is done using inline asm (rather than using a section
* size parameter; otherwise we wouldn't be able to. We can't use a * attribute on a normal variable) in order to allow the use of @nobits, so
* "section" attribute on a normal variable because it always ends up * that it doesn't take up any space in the vmlinux file.
* being @progbits, which ends up allocating space in the vmlinux
* executable.)
*/ */
#define RESERVE_BRK(name,sz) \ #define RESERVE_BRK(name, size) \
static void __section(.discard.text) __used notrace \ asm(".pushsection .brk_reservation,\"aw\",@nobits\n\t" \
__brk_reservation_fn_##name##__(void) { \ ".brk." #name ":\n\t" \
asm volatile ( \ ".skip " __stringify(size) "\n\t" \
".pushsection .brk_reservation,\"aw\",@nobits;" \ ".size .brk." #name ", " __stringify(size) "\n\t" \
".brk." #name ":" \ ".popsection\n\t")
" 1:.skip %c0;" \
" .size .brk." #name ", . - 1b;" \
" .popsection" \
: : "i" (sz)); \
}
/* Helper for reserving space for arrays of things */ /* Helper for reserving space for arrays of things */
#define RESERVE_BRK_ARRAY(type, name, entries) \ #define RESERVE_BRK_ARRAY(type, name, entries) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment