[PATCH v2 01/59] x86/paravirt: Ensure proper alignment

Peter Zijlstra posted 59 patches 3 years, 7 months ago
There is a newer version of this series
[PATCH v2 01/59] x86/paravirt: Ensure proper alignment
Posted by Peter Zijlstra 3 years, 7 months ago
From: Thomas Gleixner <tglx@linutronix.de>

The entries in the .parainstr sections are 8 byte aligned and the
corresponding C struct makes the array offset 16 bytes.

Though the pushed entries are only using 12 bytes. .parainstr_end is
therefore 4 bytes short.

That works by chance because it's only used in a loop:

     for (p = start; p < end; p++)

But this falls flat when calculating the number of elements:

    n = end - start

That's obviously off by one.

Ensure that the gap is filled and the last entry is occupying 16 bytes.

Cc: Juergen Gross <jgross@suse.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/include/asm/paravirt.h       |    1 +
 arch/x86/include/asm/paravirt_types.h |    1 +
 2 files changed, 2 insertions(+)

--- a/arch/x86/include/asm/paravirt.h
+++ b/arch/x86/include/asm/paravirt.h
@@ -743,6 +743,7 @@ extern void default_banner(void);
 	 word 771b;				\
 	 .byte ptype;				\
 	 .byte 772b-771b;			\
+	 _ASM_ALIGN;				\
 	.popsection
 
 
--- a/arch/x86/include/asm/paravirt_types.h
+++ b/arch/x86/include/asm/paravirt_types.h
@@ -294,6 +294,7 @@ extern struct paravirt_patch_template pv
 	"  .byte " type "\n"				\
 	"  .byte 772b-771b\n"				\
 	"  .short " clobber "\n"			\
+	_ASM_ALIGN "\n"					\
 	".popsection\n"
 
 /* Generate patchable code, with the default asm parameters. */
Re: [PATCH v2 01/59] x86/paravirt: Ensure proper alignment
Posted by Juergen Gross 3 years, 7 months ago
On 02.09.22 15:06, Peter Zijlstra wrote:
> From: Thomas Gleixner <tglx@linutronix.de>
> 
> The entries in the .parainstr sections are 8 byte aligned and the
> corresponding C struct makes the array offset 16 bytes.
> 
> Though the pushed entries are only using 12 bytes. .parainstr_end is
> therefore 4 bytes short.
> 
> That works by chance because it's only used in a loop:
> 
>       for (p = start; p < end; p++)
> 
> But this falls flat when calculating the number of elements:
> 
>      n = end - start
> 
> That's obviously off by one.
> 
> Ensure that the gap is filled and the last entry is occupying 16 bytes.
> 
> Cc: Juergen Gross <jgross@suse.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen