Re: [PATCH] x86: static_cpu_has_safe: discard dynamic check after init
From: Brian Gerst
Date: Sat Jan 16 2016 - 14:58:55 EST
On Sat, Jan 16, 2016 at 2:36 PM, Borislav Petkov <bp@xxxxxxx> wrote:
> On Sat, Jan 16, 2016 at 02:22:04PM -0500, Brian Gerst wrote:
>> Move the code to do the dynamic check to the init text section so that it
>> is discarded after alternatives have run and a static branch has been
>> chosen.
>>
>> A new section is defined to avoid warnings with modpost due to references
>> to init text from main text, which in this case is legitimate. All such
>> references are patched out before init mem is discarded.
>
> And we're doing this because...? Space savings? How much are we talkin'?
It saves space. The only thing left in main text is one jump
instruction (5 bytes).
The old t_dynamic branch looked something like this (26 bytes in
.text, not discarded):
553: bf 7d 00 00 00 mov $0x7d,%edi
558: 48 89 4d c8 mov %rcx,-0x38(%rbp)
55c: e8 00 00 00 00 callq 561 <__switch_to+0xf1>
55d: R_X86_64_PC32 __static_cpu_has_safe-0x4
561: 84 c0 test %al,%al
563: 48 8b 4d c8 mov -0x38(%rbp),%rcx
567: 0f 85 77 01 00 00 jne 6e4 <__switch_to+0x274>
New (21 bytes, discarded after init):
0: f7 05 00 00 00 00 00 testl $0x20000000,0x0(%rip) #
a <.static_cpu_has+0xa>
7: 00 00 20
2: R_X86_64_PC32 boot_cpu_data+0x18
a: 0f 85 00 00 00 00 jne 10 <.static_cpu_has+0x10>
c: R_X86_64_PC32 .text+0x4b9
10: e9 00 00 00 00 jmpq 15 <.static_cpu_has+0x15>
11: R_X86_64_PC32 .text+0x529
--
Brian Gerst