All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm: Simplify RESERVE_BRK()
@ 2022-04-28 20:04 Josh Poimboeuf
  2022-04-29 10:10 ` Peter Zijlstra
  2022-05-04 10:03 ` Borislav Petkov
  0 siblings, 2 replies; 3+ messages in thread
From: Josh Poimboeuf @ 2022-04-28 20:04 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, Peter Zijlstra

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: Josh Poimboeuf <jpoimboe@redhat.com>
---
 arch/x86/include/asm/setup.h | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index a1b107f2a12a..7590ac2570b9 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -108,27 +108,19 @@ extern unsigned long _brk_end;
 void *extend_brk(size_t size, size_t align);
 
 /*
- * Reserve space in the brk section.  The name must be unique within
- * the file, and somewhat descriptive.  The size is in bytes.  Must be
- * used at file scope.
+ * Reserve space in the brk section.  The name must be unique within the file,
+ * and somewhat descriptive.  The size is in bytes.
  *
- * (This uses a temp function to wrap the asm so we can pass it the
- * size parameter; otherwise we wouldn't be able to.  We can't use a
- * "section" attribute on a normal variable because it always ends up
- * being @progbits, which ends up allocating space in the vmlinux
- * executable.)
+ * The allocation is done using inline asm (rather than using a section
+ * attribute on a normal variable) in order to allow the use of @nobits, so
+ * that it doesn't take up any space in the vmlinux file.
  */
-#define RESERVE_BRK(name,sz)						\
-	static void __section(".discard.text") __noendbr __used notrace	\
-	__brk_reservation_fn_##name##__(void) {				\
-		asm volatile (						\
-			".pushsection .brk_reservation,\"aw\",@nobits;" \
-			".brk." #name ":"				\
-			" 1:.skip %c0;"					\
-			" .size .brk." #name ", . - 1b;"		\
-			" .popsection"					\
-			: : "i" (sz));					\
-	}
+#define RESERVE_BRK(name, size)						\
+	asm(".pushsection .brk_reservation,\"aw\",@nobits\n\t"		\
+	    ".brk." #name ":\n\t"					\
+	    ".skip " __stringify(size) "\n\t"				\
+	    ".size .brk." #name ", " __stringify(size) "\n\t"		\
+	    ".popsection\n\t")
 
 extern void probe_roms(void);
 #ifdef __i386__
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/mm: Simplify RESERVE_BRK()
  2022-04-28 20:04 [PATCH] x86/mm: Simplify RESERVE_BRK() Josh Poimboeuf
@ 2022-04-29 10:10 ` Peter Zijlstra
  2022-05-04 10:03 ` Borislav Petkov
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2022-04-29 10:10 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: x86, linux-kernel

On Thu, Apr 28, 2022 at 01:04:25PM -0700, Josh Poimboeuf wrote:
> 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: Josh Poimboeuf <jpoimboe@redhat.com>

Tested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/mm: Simplify RESERVE_BRK()
  2022-04-28 20:04 [PATCH] x86/mm: Simplify RESERVE_BRK() Josh Poimboeuf
  2022-04-29 10:10 ` Peter Zijlstra
@ 2022-05-04 10:03 ` Borislav Petkov
  1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2022-05-04 10:03 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: x86, linux-kernel, Peter Zijlstra

On Thu, Apr 28, 2022 at 01:04:25PM -0700, Josh Poimboeuf wrote:
> 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: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  arch/x86/include/asm/setup.h | 30 +++++++++++-------------------
>  1 file changed, 11 insertions(+), 19 deletions(-)

Nice.

Reviewed-by: Borislav Petkov <bp@suse.de>

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-04 10:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 20:04 [PATCH] x86/mm: Simplify RESERVE_BRK() Josh Poimboeuf
2022-04-29 10:10 ` Peter Zijlstra
2022-05-04 10:03 ` Borislav Petkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.