public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: tell the world boot_params is 16-byte aligned
@ 2015-05-08 13:42 Rasmus Villemoes
  2015-05-08 14:24 ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus Villemoes @ 2015-05-08 13:42 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86
  Cc: Rasmus Villemoes, linux-kernel

It doesn't matter much, but this disassembly makes me cry a little bit:

ffffffff81f21223 <copy_bootdata>:
ffffffff81f21223:       55                      push   %rbp
ffffffff81f21224:       48 c7 c0 40 c2 02 82    mov    $0xffffffff8202c240,%rax
ffffffff81f2122b:       48 89 fe                mov    %rdi,%rsi
ffffffff81f2122e:       a8 01                   test   $0x1,%al

The reason is that boot_params is defined with
__attribute__((aligned(16))) in boot/main.c, but other translation
units only see the packed attribute on the definition of struct
boot_params, so assume the worst. Making the de facto alignment public
has this effect:

$ scripts/bloat-o-meter /tmp/vmlinux.{defconfig,align}
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-230 (-230)
function                                     old     new   delta
copy_bootdata                                444     214    -230

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 arch/x86/include/asm/setup.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index f69e06b283fb..dcd6d5fc2f12 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -64,7 +64,7 @@ static inline void x86_ce4100_early_setup(void) { }
 /*
  * This is set up by the setup-routine at boot-time
  */
-extern struct boot_params boot_params;
+extern struct boot_params boot_params __attribute__((aligned(16)));
 
 static inline bool kaslr_enabled(void)
 {
-- 
2.1.3


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

* Re: [PATCH] x86: tell the world boot_params is 16-byte aligned
  2015-05-08 13:42 [PATCH] x86: tell the world boot_params is 16-byte aligned Rasmus Villemoes
@ 2015-05-08 14:24 ` Borislav Petkov
  2015-05-08 16:23   ` Rasmus Villemoes
  0 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2015-05-08 14:24 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, linux-kernel

On Fri, May 08, 2015 at 03:42:33PM +0200, Rasmus Villemoes wrote:
> It doesn't matter much, but this disassembly makes me cry a little bit:
> 
> ffffffff81f21223 <copy_bootdata>:
> ffffffff81f21223:       55                      push   %rbp
> ffffffff81f21224:       48 c7 c0 40 c2 02 82    mov    $0xffffffff8202c240,%rax
> ffffffff81f2122b:       48 89 fe                mov    %rdi,%rsi
> ffffffff81f2122e:       a8 01                   test   $0x1,%al
> 
> The reason is that boot_params is defined with
> __attribute__((aligned(16))) in boot/main.c, but other translation
> units only see the packed attribute on the definition of struct
> boot_params, so assume the worst. Making the de facto alignment public

Wouldn't it be better if we put both attributes together, i.e.:

diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index ab456dc233b5..d26953d896d2 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -155,7 +155,7 @@ struct boot_params {
        __u8  _pad8[48];                                /* 0xcd0 */
        struct edd_info eddbuf[EDDMAXNR];               /* 0xd00 */
        __u8  _pad9[276];                               /* 0xeec */
-} __attribute__((packed));
+} __attribute__((packed, aligned(16)));
 
 enum {
        X86_SUBARCH_PC = 0,
---

so that they're concentrated in one place?

gcc seems to swallow it, I haven't checked the bloat decrease though,
when one would declare boot_params this way.

Thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

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

* Re: [PATCH] x86: tell the world boot_params is 16-byte aligned
  2015-05-08 14:24 ` Borislav Petkov
@ 2015-05-08 16:23   ` Rasmus Villemoes
  2015-05-08 16:26     ` H. Peter Anvin
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus Villemoes @ 2015-05-08 16:23 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, linux-kernel

On Fri, May 08 2015, Borislav Petkov <bp@alien8.de> wrote:

> On Fri, May 08, 2015 at 03:42:33PM +0200, Rasmus Villemoes wrote:
>> It doesn't matter much, but this disassembly makes me cry a little bit:
>> 
>> ffffffff81f21223 <copy_bootdata>:
>> ffffffff81f21223:       55                      push   %rbp
>> ffffffff81f21224:       48 c7 c0 40 c2 02 82    mov    $0xffffffff8202c240,%rax
>> ffffffff81f2122b:       48 89 fe                mov    %rdi,%rsi
>> ffffffff81f2122e:       a8 01                   test   $0x1,%al
>> 
>> The reason is that boot_params is defined with
>> __attribute__((aligned(16))) in boot/main.c, but other translation
>> units only see the packed attribute on the definition of struct
>> boot_params, so assume the worst. Making the de facto alignment public
>
> Wouldn't it be better if we put both attributes together, i.e.:

Sure, putting it on the type works as well. Either way is fine with me.

Rasmus

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

* Re: [PATCH] x86: tell the world boot_params is 16-byte aligned
  2015-05-08 16:23   ` Rasmus Villemoes
@ 2015-05-08 16:26     ` H. Peter Anvin
  2015-05-08 17:40       ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: H. Peter Anvin @ 2015-05-08 16:26 UTC (permalink / raw)
  To: Rasmus Villemoes, Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, x86, linux-kernel

NAK.  This could break in the case of careless bootloaders...

On May 8, 2015 9:23:52 AM PDT, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
>On Fri, May 08 2015, Borislav Petkov <bp@alien8.de> wrote:
>
>> On Fri, May 08, 2015 at 03:42:33PM +0200, Rasmus Villemoes wrote:
>>> It doesn't matter much, but this disassembly makes me cry a little
>bit:
>>> 
>>> ffffffff81f21223 <copy_bootdata>:
>>> ffffffff81f21223:       55                      push   %rbp
>>> ffffffff81f21224:       48 c7 c0 40 c2 02 82    mov   
>$0xffffffff8202c240,%rax
>>> ffffffff81f2122b:       48 89 fe                mov    %rdi,%rsi
>>> ffffffff81f2122e:       a8 01                   test   $0x1,%al
>>> 
>>> The reason is that boot_params is defined with
>>> __attribute__((aligned(16))) in boot/main.c, but other translation
>>> units only see the packed attribute on the definition of struct
>>> boot_params, so assume the worst. Making the de facto alignment
>public
>>
>> Wouldn't it be better if we put both attributes together, i.e.:
>
>Sure, putting it on the type works as well. Either way is fine with me.
>
>Rasmus

-- 
Sent from my mobile phone.  Please pardon brevity and lack of formatting.

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

* Re: [PATCH] x86: tell the world boot_params is 16-byte aligned
  2015-05-08 16:26     ` H. Peter Anvin
@ 2015-05-08 17:40       ` Borislav Petkov
  2015-05-08 18:36         ` H. Peter Anvin
  0 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2015-05-08 17:40 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Rasmus Villemoes, Thomas Gleixner, Ingo Molnar, x86, linux-kernel

On Fri, May 08, 2015 at 09:26:49AM -0700, H. Peter Anvin wrote:
> NAK.  This could break in the case of careless bootloaders...

Please elaborate. You mean, they'll go with the max alignment too and
search boot_params there?

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

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

* Re: [PATCH] x86: tell the world boot_params is 16-byte aligned
  2015-05-08 17:40       ` Borislav Petkov
@ 2015-05-08 18:36         ` H. Peter Anvin
  0 siblings, 0 replies; 6+ messages in thread
From: H. Peter Anvin @ 2015-05-08 18:36 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Rasmus Villemoes, Thomas Gleixner, Ingo Molnar, x86, linux-kernel

On 05/08/2015 10:40 AM, Borislav Petkov wrote:
> On Fri, May 08, 2015 at 09:26:49AM -0700, H. Peter Anvin wrote:
>> NAK.  This could break in the case of careless bootloaders...
> 
> Please elaborate. You mean, they'll go with the max alignment too and
> search boot_params there?
> 

A careless bootloader may not align this data structure to any
particular alignment.

Of course, for x86 it doesn't matter too much, as it just hurts performance.

	-hpa


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

end of thread, other threads:[~2015-05-08 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-08 13:42 [PATCH] x86: tell the world boot_params is 16-byte aligned Rasmus Villemoes
2015-05-08 14:24 ` Borislav Petkov
2015-05-08 16:23   ` Rasmus Villemoes
2015-05-08 16:26     ` H. Peter Anvin
2015-05-08 17:40       ` Borislav Petkov
2015-05-08 18:36         ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox