Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1998618imm; Thu, 14 Jun 2018 07:14:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLBUKQDKjk4GdlUBBvRKXhWyqsO+otzn/rR7hG1aAnnfJWP7zjPDll7RBim7u28j8r3xZ8z X-Received: by 2002:a65:4607:: with SMTP id v7-v6mr2454823pgq.31.1528985677006; Thu, 14 Jun 2018 07:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528985676; cv=none; d=google.com; s=arc-20160816; b=zkx2lRbTW6/S0JjigY3sOUYX0AvA7UdXzYCIYPmuG5/FMy8S7U+iBZ/wydLhSSmp4x QHeGNSpMa+dEZP/JGST9eUx335yBGSeQlT1jHWEjnBqpsldOEG1YjRYbWwYJWpxogZ2Q mGjUCIxDRxU5VeuoCBTqNGOMH4we0dIedi2lDoJcGrVMjBuaTN6cMDGyvHO90ySZvPYU l3nYlOXHppvPEtySDy7ElCS4SaAFR8N8RBosX+Gnq1xQE3HO/WmySGDosjUHXkPv8/Bh 1GCJPSoNynT593mTfWyLmg2qU73oyp0LyiKwmOSmSdMZvL4aZxsyVhkpDRreVc0EYE20 uV2A== 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:dkim-signature :arc-authentication-results; bh=rQKBN86w7u49lMe/ytbYaCMTueHVSVWrUjsHonqfje0=; b=TQEaYW4rQ1xYn63Xwq0LQ7EkUMK8qRAljLC2MxjvX04Hjg50yegqOV0946yEf/pE71 Lrm4N3jIpv7GyUpWw60+/kV2K3ZuTIrAafQPH334zbQU/BtYZ05Fg8oHVE56H2vuueF7 2w6I0rkQR88vssvJIAGANmkrpvIewzmYuGHA1UC30ZPT7WJ6gHYFIV5z3rtTzjrbUMB/ CDL97xu0UHsrBplJ4CuPvOxrxoy+H/2r/KWF53OTUDDLf0iVaQjWJ6VJPva0TiWKLsaI xGnyGLCYTK10ISkqSjbq6SJOGIAoQoNwWqRILDdtF4ndqNiXdfDLOHXSx8S9gyqf6tMq TQHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="kiu8n/PS"; 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 q72-v6si5340197pfi.183.2018.06.14.07.14.22; Thu, 14 Jun 2018 07:14:36 -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; dkim=pass header.i=@kernel.org header.s=default header.b="kiu8n/PS"; 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 S966169AbeFNONF (ORCPT + 99 others); Thu, 14 Jun 2018 10:13:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:54292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966150AbeFNOM4 (ORCPT ); Thu, 14 Jun 2018 10:12:56 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9954B208DB; Thu, 14 Jun 2018 14:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528985576; bh=onS7lc/CPsi3TFRUgMWJBfWgWRU2x+B+yJ0/90shOzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kiu8n/PS5P+WKioYTJ71E7DOcIrdR8HFVtdfJiLnp7TuJbxtitOHDi4p7KMZzbS2Y SOldroNKlolX3f6v2hNooVQBP/UYh3tHZYZe5OK0meBrpURZme7isAAkH5QXpVrIrL DqfpLuSx4/DfHqjNii4O4MIZXTi2SpllG/hryht0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu-cheng Yu , Andy Lutomirski , Borislav Petkov , Borislav Petkov , Dave Hansen , Fenghua Yu , "H. Peter Anvin" , Linus Torvalds , Oleg Nesterov , Peter Zijlstra , Quentin Casasnovas , "Ravi V. Shankar" , Sai Praneeth Prakhya , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.4 01/24] x86/fpu: Fix early FPU command-line parsing Date: Thu, 14 Jun 2018 16:04:56 +0200 Message-Id: <20180614132724.543910879@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180614132724.483802160@linuxfoundation.org> References: <20180614132724.483802160@linuxfoundation.org> User-Agent: quilt/0.65 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: yu-cheng yu commit 4f81cbafcce2c603db7865e9d0e461f7947d77d4 upstream. The function fpu__init_system() is executed before parse_early_param(). This causes wrong FPU configuration. This patch fixes this issue by parsing boot_command_line in the beginning of fpu__init_system(). With all four patches in this series, each parameter disables features as the following: eagerfpu=off: eagerfpu, avx, avx2, avx512, mpx no387: fpu nofxsr: fxsr, fxsropt, xmm noxsave: xsave, xsaveopt, xsaves, xsavec, avx, avx2, avx512, mpx, xgetbv1 noxsaveopt: xsaveopt noxsaves: xsaves Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Borislav Petkov Cc: Dave Hansen Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Quentin Casasnovas Cc: Ravi V. Shankar Cc: Sai Praneeth Prakhya Cc: Thomas Gleixner Cc: yu-cheng yu Link: http://lkml.kernel.org/r/1452119094-7252-2-git-send-email-yu-cheng.yu@intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/fpu/init.c | 109 +++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 71 deletions(-) --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -3,8 +3,11 @@ */ #include #include +#include +#include #include +#include /* * Initialize the TS bit in CR0 according to the style of context-switches @@ -262,18 +265,6 @@ static void __init fpu__init_system_xsta */ static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO; -static int __init eager_fpu_setup(char *s) -{ - if (!strcmp(s, "on")) - eagerfpu = ENABLE; - else if (!strcmp(s, "off")) - eagerfpu = DISABLE; - else if (!strcmp(s, "auto")) - eagerfpu = AUTO; - return 1; -} -__setup("eagerfpu=", eager_fpu_setup); - /* * Pick the FPU context switching strategy: */ @@ -308,11 +299,46 @@ static void __init fpu__init_system_ctx_ } /* + * We parse fpu parameters early because fpu__init_system() is executed + * before parse_early_param(). + */ +static void __init fpu__init_parse_early_param(void) +{ + /* + * No need to check "eagerfpu=auto" again, since it is the + * initial default. + */ + if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off")) + eagerfpu = DISABLE; + else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on")) + eagerfpu = ENABLE; + + if (cmdline_find_option_bool(boot_command_line, "no387")) + setup_clear_cpu_cap(X86_FEATURE_FPU); + + if (cmdline_find_option_bool(boot_command_line, "nofxsr")) { + setup_clear_cpu_cap(X86_FEATURE_FXSR); + setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT); + setup_clear_cpu_cap(X86_FEATURE_XMM); + } + + if (cmdline_find_option_bool(boot_command_line, "noxsave")) + fpu__xstate_clear_all_cpu_caps(); + + if (cmdline_find_option_bool(boot_command_line, "noxsaveopt")) + setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); + + if (cmdline_find_option_bool(boot_command_line, "noxsaves")) + setup_clear_cpu_cap(X86_FEATURE_XSAVES); +} + +/* * Called on the boot CPU once per system bootup, to set up the initial * FPU state that is later cloned into all processes: */ void __init fpu__init_system(struct cpuinfo_x86 *c) { + fpu__init_parse_early_param(); fpu__init_system_early_generic(c); /* @@ -336,62 +362,3 @@ void __init fpu__init_system(struct cpui fpu__init_system_ctx_switch(); } - -/* - * Boot parameter to turn off FPU support and fall back to math-emu: - */ -static int __init no_387(char *s) -{ - setup_clear_cpu_cap(X86_FEATURE_FPU); - return 1; -} -__setup("no387", no_387); - -/* - * Disable all xstate CPU features: - */ -static int __init x86_noxsave_setup(char *s) -{ - if (strlen(s)) - return 0; - - fpu__xstate_clear_all_cpu_caps(); - - return 1; -} -__setup("noxsave", x86_noxsave_setup); - -/* - * Disable the XSAVEOPT instruction specifically: - */ -static int __init x86_noxsaveopt_setup(char *s) -{ - setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); - - return 1; -} -__setup("noxsaveopt", x86_noxsaveopt_setup); - -/* - * Disable the XSAVES instruction: - */ -static int __init x86_noxsaves_setup(char *s) -{ - setup_clear_cpu_cap(X86_FEATURE_XSAVES); - - return 1; -} -__setup("noxsaves", x86_noxsaves_setup); - -/* - * Disable FX save/restore and SSE support: - */ -static int __init x86_nofxsr_setup(char *s) -{ - setup_clear_cpu_cap(X86_FEATURE_FXSR); - setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT); - setup_clear_cpu_cap(X86_FEATURE_XMM); - - return 1; -} -__setup("nofxsr", x86_nofxsr_setup);