Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2044253imm; Mon, 16 Jul 2018 00:47:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdv1g3bKo29ZmnKNGdT6UZu7APFY82JGU5OI5LrUOjRATk6VmFYUzJVLPwgkqVS3iRZXSot X-Received: by 2002:a62:700a:: with SMTP id l10-v6mr16711883pfc.71.1531727252348; Mon, 16 Jul 2018 00:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531727252; cv=none; d=google.com; s=arc-20160816; b=vrO6Fvku4ekHkdlcSfBBE069ssWd1aePfxGDNf8bl7uqkIAKAEnKX6jIRiJSCv4dsb 2+AKWKupNQQuy7oGAny3GeIAu48o8LoiF6z1oS5FF//hQN3sjh4wUYw7na0lopFLbgap fkfWdPLWhHeNuLbA0k64flbCgd/mjMqVTHWLFAIJNRSZh7rtzQhGUtBz0DJF4zG+Covm 4DVaI2fGm3i9hZg+zFfDBSqzOxnxgiTA43OqUlGovDtUnb3HyXrEHMbuEA58l837gymi tAdErDFSRVdAGOBLOok3t4v5b49eB9YfiZARO8fG8SJr8ky16u8EiKcgJ5Vbfil4jktK yqAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qEob1gs8kKbDxCmryFAg/UONqigeDQBTVMOFUtk2w6A=; b=gc/BY+tDjIH9qckWmZti+9hs9Q+p0UEEA5DeHV3Qk6K3V7Gg/ZPlugkrPwKHwarD9A 2mlOyxHa8ws86S+VQZOIvcbxp1ZhZfQ0H/irlt1RXOBZ8HsdpRVVkPFEyHwUFhG9DTx/ WPp/1w3ScIRfQcmNIYZiV6JXCFHbveX5ltcPW7QY3URqQcLxKmdNoOUbtXGdnPSpVrYG mxMqLY+eegIUuMBjf+nYWCbalA1G3C2+4W2D+2slkUpLysDtKPPLFWEqMi9Rlm0farvE gPSZhhxnlsE1toqn3p5ORwTksTIqoGrKj8Uz/YIR5nYCrbCAf6MMSWi9211t7YICBJOt 9hjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l190-v6si27947771pgl.198.2018.07.16.00.47.17; Mon, 16 Jul 2018 00:47:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389726AbeGPIMT (ORCPT + 99 others); Mon, 16 Jul 2018 04:12:19 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51110 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728470AbeGPIMT (ORCPT ); Mon, 16 Jul 2018 04:12:19 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9CCD3CEC; Mon, 16 Jul 2018 07:45:49 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Gerst , Borislav Petkov , Andrew Morton , Andy Lutomirski , Andy Lutomirski , Boris Ostrovsky , Borislav Petkov , Dave Young , Denys Vlasenko , "H. Peter Anvin" , Kristen Carlson Accardi , Laura Abbott , Linus Torvalds , "Peter Zijlstra (Intel)" , Prarit Bhargava , Ross Zwisler , Thomas Gleixner , Ingo Molnar , "Srivatsa S. Bhat" , "Matt Helsley (VMware)" , Alexey Makhalov , Bo Gan Subject: [PATCH 4.4 26/43] x86/alternatives: Discard dynamic check after init Date: Mon, 16 Jul 2018 09:36:31 +0200 Message-Id: <20180716073514.746599398@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073511.796555857@linuxfoundation.org> References: <20180716073511.796555857@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Brian Gerst commit 2476f2fa20568bd5d9e09cd35bcd73e99a6f4cc6 upstream Move the code to do the dynamic check to the altinstr_aux section so that it is discarded after alternatives have run and a static branch has been chosen. This way we're changing the dynamic branch from C code to assembly, which makes it *substantially* smaller while avoiding a completely unnecessary call to an out of line function. Signed-off-by: Brian Gerst [ Changed it to do TESTB, as hpa suggested. ] Signed-off-by: Borislav Petkov Cc: Andrew Morton Cc: Andy Lutomirski Cc: Andy Lutomirski Cc: Boris Ostrovsky Cc: Borislav Petkov Cc: Dave Young Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Kristen Carlson Accardi Cc: Laura Abbott Cc: Linus Torvalds Cc: Peter Zijlstra (Intel) Cc: Peter Zijlstra Cc: Prarit Bhargava Cc: Ross Zwisler Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1452972124-7380-1-git-send-email-brgerst@gmail.com Link: http://lkml.kernel.org/r/20160127084525.GC30712@pd.tnic Signed-off-by: Ingo Molnar Signed-off-by: Srivatsa S. Bhat Reviewed-by: Matt Helsley (VMware) Reviewed-by: Alexey Makhalov Reviewed-by: Bo Gan Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/cpufeature.h | 19 ++++++++++++------- arch/x86/kernel/cpu/common.c | 6 ------ 2 files changed, 12 insertions(+), 13 deletions(-) --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -132,8 +132,6 @@ extern const char * const x86_bug_flags[ */ #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_X86_FAST_FEATURE_TESTS) -extern bool __static_cpu_has(u16 bit); - /* * Static testing of CPU features. Used the same as boot_cpu_has(). * These will statically patch the target code for additional @@ -141,7 +139,7 @@ extern bool __static_cpu_has(u16 bit); */ static __always_inline __pure bool _static_cpu_has(u16 bit) { - asm_volatile_goto("1: jmp %l[t_dynamic]\n" + asm_volatile_goto("1: jmp 6f\n" "2:\n" ".skip -(((5f-4f) - (2b-1b)) > 0) * " "((5f-4f) - (2b-1b)),0x90\n" @@ -166,13 +164,20 @@ static __always_inline __pure bool _stat " .byte 0\n" /* repl len */ " .byte 0\n" /* pad len */ ".previous\n" - : : "i" (bit), "i" (X86_FEATURE_ALWAYS) - : : t_dynamic, t_no); + ".section .altinstr_aux,\"ax\"\n" + "6:\n" + " testb %[bitnum],%[cap_byte]\n" + " jnz %l[t_yes]\n" + " jmp %l[t_no]\n" + ".previous\n" + : : "i" (bit), "i" (X86_FEATURE_ALWAYS), + [bitnum] "i" (1 << (bit & 7)), + [cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3]) + : : t_yes, t_no); + t_yes: return true; t_no: return false; - t_dynamic: - return __static_cpu_has(bit); } #define static_cpu_has(bit) \ --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1576,12 +1576,6 @@ void cpu_init(void) } #endif -inline bool __static_cpu_has(u16 bit) -{ - return boot_cpu_has(bit); -} -EXPORT_SYMBOL_GPL(__static_cpu_has); - static void bsp_resume(void) { if (this_cpu->c_bsp_resume)