From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752692AbcAPT6X (ORCPT ); Sat, 16 Jan 2016 14:58:23 -0500 Received: from mail-ob0-f173.google.com ([209.85.214.173]:33775 "EHLO mail-ob0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752530AbcAPT6W (ORCPT ); Sat, 16 Jan 2016 14:58:22 -0500 MIME-Version: 1.0 In-Reply-To: <20160116193658.GC32085@pd.tnic> References: <1452972124-7380-1-git-send-email-brgerst@gmail.com> <20160116193658.GC32085@pd.tnic> Date: Sat, 16 Jan 2016 14:58:21 -0500 Message-ID: Subject: Re: [PATCH] x86: static_cpu_has_safe: discard dynamic check after init From: Brian Gerst To: Borislav Petkov Cc: "the arch/x86 maintainers" , Linux Kernel Mailing List , Ingo Molnar , "H. Peter Anvin" , Denys Vlasenko , Andy Lutomirski , Linus Torvalds Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 16, 2016 at 2:36 PM, Borislav Petkov 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