Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1999684imm; Thu, 14 Jun 2018 07:15:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIRFvi62dVP6YDjmr273rdSV0VGBJ+vhSA/20mZifGAdHiZEasMNM70QwZGDmmt2AVqcNjJ X-Received: by 2002:aa7:8589:: with SMTP id w9-v6mr9764440pfn.119.1528985733478; Thu, 14 Jun 2018 07:15:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528985733; cv=none; d=google.com; s=arc-20160816; b=WB5wTFWQxnT+ex40Lrji1AQdkr3mgjAcjSdLsgbVJu8OE3wWEQPHx1dnRB286WlFau Van3XsQF3zV1/O53dkUBwZsaGSpnQbx5JeCEEArtiL6LX+/67KqxAjRYCwQEH44x/T8G pT8ORKcOyV0MV8wGCCVF5/ZaowbA9jqQWjYkZZ2/IOvNLpyU2n7BmF/KnJCxo7jQawzG x6VIXDhA8RPc7Vuo/Xp8KKAyJDesOQzfoyxr/RUBYd6Dlh8MyK/OUTvRRV+tK4t2Wzpj KVvqgJmVNidcbYXR9YE5HczRLN6Z+y8a7HlIhy3YyG4Q4JJxtogL6AyjKSMh/pQCP29O X38Q== 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=QSRwY0nKtgFyP9A0ZJN7uT2MJVdQ2Hk4d1LoK/z9zVs=; b=OKO/aLIqkRYBrdFLmBf1O6z/rT+9moOX25qy32zeOJquc6IQBXnzJzGCkA4Asep7zQ SN1489yEbQkBrYsYkcQXSpeNKhyyP1p648Q67vDqQtXVZBcTY9XcUA/5LmQqj8E3WmYh bRyncN6Y0Wuyo9Sd2ZwwAgpWmxulun8vBwDTnHsi4zpBcuVpXrWjIqdDDnUWKYjFDsIM tHDHauRAkM56AIGAMYSWOKnIq12Ia91wSUHRoNq2XyQzL2HfIBX2X3zLbvBydIArCL3W Qy7pRpfC6nTc8FIwShUZeWoJTlbpf+0Zim2UhfAdurZLfGufu4/AgEGfcDc5oE1wG3Wb uPGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rYLGHh7w; 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 bc4-v6si5200886plb.254.2018.06.14.07.15.19; Thu, 14 Jun 2018 07:15:33 -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=rYLGHh7w; 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 S966359AbeFNOOP (ORCPT + 99 others); Thu, 14 Jun 2018 10:14:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:55680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966343AbeFNOOC (ORCPT ); Thu, 14 Jun 2018 10:14:02 -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 2AA4D208E5; Thu, 14 Jun 2018 14:14:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528985641; bh=3MHN5oDqdvsmB4O+vp5oHRFmu2PyT2ElPDEJ1Z9Q6ww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rYLGHh7wgRn2BPG2ouLqnuRK9YlEiCGCALkE7KuyMajcZVVvKrYx/70bsCnCxkVBj JvUql8CeuXO833rky2xFyjbuqboMg7ktN857txIKFXfXO9U0b6VBR9g4IAB3sjyEB4 pPOjK7+TNkEA1qSAtsAaaberqCn8Nw+aFAB64iKQ= 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 04/24] x86/fpu: Disable MPX when eagerfpu is off Date: Thu, 14 Jun 2018 16:04:59 +0200 Message-Id: <20180614132724.657637907@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 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: yu-cheng yu commit a5fe93a549c54838063d2952dd9643b0b18aa67f upstream. This issue is a fallout from the command-line parsing move. When "eagerfpu=off" is given as a command-line input, the kernel should disable MPX support. The decision for turning off MPX was made in fpu__init_system_ctx_switch(), which is after the selection of the XSAVE format. This patch fixes it by getting that decision done earlier in fpu__init_system_xstate(). 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-4-git-send-email-yu-cheng.yu@intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/fpu/internal.h | 1 arch/x86/kernel/fpu/init.c | 56 ++++++++++++++++++++++++++++-------- arch/x86/kernel/fpu/xstate.c | 3 - 3 files changed, 46 insertions(+), 14 deletions(-) --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -42,6 +42,7 @@ extern void fpu__init_cpu_xstate(void); extern void fpu__init_system(struct cpuinfo_x86 *c); extern void fpu__init_check_bugs(void); extern void fpu__resume_cpu(void); +extern u64 fpu__get_supported_xfeatures_mask(void); /* * Debugging facility: --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -266,7 +266,45 @@ static void __init fpu__init_system_xsta static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO; /* + * Find supported xfeatures based on cpu features and command-line input. + * This must be called after fpu__init_parse_early_param() is called and + * xfeatures_mask is enumerated. + */ +u64 __init fpu__get_supported_xfeatures_mask(void) +{ + /* Support all xfeatures known to us */ + if (eagerfpu != DISABLE) + return XCNTXT_MASK; + + /* Warning of xfeatures being disabled for no eagerfpu mode */ + if (xfeatures_mask & XFEATURE_MASK_EAGER) { + pr_err("x86/fpu: eagerfpu switching disabled, disabling the following xstate features: 0x%llx.\n", + xfeatures_mask & XFEATURE_MASK_EAGER); + } + + /* Return a mask that masks out all features requiring eagerfpu mode */ + return ~XFEATURE_MASK_EAGER; +} + +/* + * Disable features dependent on eagerfpu. + */ +static void __init fpu__clear_eager_fpu_features(void) +{ + setup_clear_cpu_cap(X86_FEATURE_MPX); +} + +/* * Pick the FPU context switching strategy: + * + * When eagerfpu is AUTO or ENABLE, we ensure it is ENABLE if either of + * the following is true: + * + * (1) the cpu has xsaveopt, as it has the optimization and doing eager + * FPU switching has a relatively low cost compared to a plain xsave; + * (2) the cpu has xsave features (e.g. MPX) that depend on eager FPU + * switching. Should the kernel boot with noxsaveopt, we support MPX + * with eager FPU switching at a higher cost. */ static void __init fpu__init_system_ctx_switch(void) { @@ -278,19 +316,11 @@ static void __init fpu__init_system_ctx_ WARN_ON_FPU(current->thread.fpu.fpstate_active); current_thread_info()->status = 0; - /* Auto enable eagerfpu for xsaveopt */ if (boot_cpu_has(X86_FEATURE_XSAVEOPT) && eagerfpu != DISABLE) eagerfpu = ENABLE; - if (xfeatures_mask & XFEATURE_MASK_EAGER) { - if (eagerfpu == DISABLE) { - pr_err("x86/fpu: eagerfpu switching disabled, disabling the following xstate features: 0x%llx.\n", - xfeatures_mask & XFEATURE_MASK_EAGER); - xfeatures_mask &= ~XFEATURE_MASK_EAGER; - } else { - eagerfpu = ENABLE; - } - } + if (xfeatures_mask & XFEATURE_MASK_EAGER) + eagerfpu = ENABLE; if (eagerfpu == ENABLE) setup_force_cpu_cap(X86_FEATURE_EAGER_FPU); @@ -308,10 +338,12 @@ static void __init fpu__init_parse_early * No need to check "eagerfpu=auto" again, since it is the * initial default. */ - if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off")) + if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off")) { eagerfpu = DISABLE; - else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on")) + fpu__clear_eager_fpu_features(); + } 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); --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -632,8 +632,7 @@ void __init fpu__init_system_xstate(void BUG(); } - /* Support only the state known to the OS: */ - xfeatures_mask = xfeatures_mask & XCNTXT_MASK; + xfeatures_mask &= fpu__get_supported_xfeatures_mask(); /* Enable xstate instructions to be able to continue with initialization: */ fpu__init_cpu_xstate();