Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp30713imm; Fri, 21 Sep 2018 17:27:20 -0700 (PDT) X-Google-Smtp-Source: ACcGV61dValgv+2pWf2NnW2Oe9N6DFuyEiGayTfAj5lmGiaUNkZFUMKw+yti656SYhzn/SkTicSe X-Received: by 2002:a17:902:4a0c:: with SMTP id w12-v6mr101350pld.289.1537576040035; Fri, 21 Sep 2018 17:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537576040; cv=none; d=google.com; s=arc-20160816; b=DSQyM/xRrSQO9TJnIbUxX+nMRpEXsLXBBFA4EK+Es53PYR3m9c82oUu6EZa0u/glLK pBhgsaKYdEHD479W7vg8e0xlC0+Pc6yiasEWOjJUVFDisZZ7hlNflkIT1jWmuj7e+nHB Z6nYR7qAI0oW3RJuYl1GcS1VFwwcJwFerZvvhxKizWGKgdPgxBqdaQvQZXl003QRSzoC 3/LfZohGkFXe1a9EXexkcXV6/Y96EJh3bAboBdhuGjUHR61wQdIe9MNe7eLFmyZM//Kd k3qf9n9RF1eKxfuiA0+4/2f7KjDi8bkAJ72XIwXFVbbP2WnaN1VIJGqikgoWF43Ap2i2 uOCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=CYIiRr0yQJr1XXmHO57No460SIBvTDPFZNxfzSA7fIE=; b=IBSkUstyPy3jGjr4Egz4PQDWwgXkBJNrIo+wtA9pQ2I993wvOcHfy/vfVPnLj252XF WE1+L7EJjn5yTI8ii6rGwE5eWIn+oPZy0g/dXZSEkka3dzlURLX9YOUSnn8mMXqZlXw0 nuKeB7dQMZRp/gzB5MvRul9VUwSy2awPi63Bcd7Eafl6zuW12ANb0ep0xiQl82sPIMLC wfKH/m7VOIdggqV0xpfAOGapwf87+0IQYHN4NpflF1vgu0P+q7XfLXcoukHYmiGXTnqf J7o9jDdMiUwSxBhRDuQUCTICmRPWSlkQwc0kY8Q5TpDevpVAuxyGV2Z8ntGKK01vEdaq j6pw== 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 o5-v6si9856616pgm.222.2018.09.21.17.27.03; Fri, 21 Sep 2018 17:27:20 -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 S2391876AbeIVGKn (ORCPT + 99 others); Sat, 22 Sep 2018 02:10:43 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44071 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391841AbeIVGKm (ORCPT ); Sat, 22 Sep 2018 02:10:42 -0400 Received: from [2a02:8011:400e:2:cbab:f00:c93f:614] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1g3Vds-0008BM-9h; Sat, 22 Sep 2018 01:19:24 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1g3Vdn-0000pn-4h; Sat, 22 Sep 2018 01:19:19 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, x86@kernel.org, "Andy Lutomirski" Date: Sat, 22 Sep 2018 01:15:42 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 02/63] x86/fpu: Default eagerfpu if FPU and FXSR are enabled In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:cbab:f00:c93f:614 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.58-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Ben Hutchings This is a limited version of commit 58122bf1d856 "x86/fpu: Default eagerfpu=on on all CPUs". That commit revealed bugs in the use of eagerfpu together with math emulation or without the FXSR feature. Although those bugs have been fixed upstream, the fixes do not seem to be practical to backport to 3.16. The security issue that motivates using eagerfpu (CVE-2018-3665) is an information leak through speculative execution, and most CPUs lacking the FXSR feature also don't implement speculative execution. The exceptions I am aware of are the Intel Pentium Pro and AMD K6 family, which will remain vulnerable to this issue. Move the eagerfpu variable and associated initialisation into fpu_init(), since xstate_enable_boot_cpu() won't be called at all if XSAVE is disabled. Signed-off-by: Ben Hutchings Cc: Andy Lutomirski Cc: x86@kernel.org --- --- a/arch/x86/kernel/xsave.c +++ b/arch/x86/kernel/xsave.c @@ -509,19 +509,6 @@ static void __init setup_init_fpu_buf(vo xsave_state(init_xstate_buf, -1); } -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); - /* * Enable and initialize the xsave feature. */ @@ -560,17 +547,11 @@ static void __init xstate_enable_boot_cp prepare_fx_sw_frame(); setup_init_fpu_buf(); - /* Auto enable eagerfpu for xsaveopt */ - if (cpu_has_xsaveopt && eagerfpu != DISABLE) - eagerfpu = ENABLE; - if (pcntxt_mask & XSTATE_EAGER) { - if (eagerfpu == DISABLE) { + if (!boot_cpu_has(X86_FEATURE_EAGER_FPU)) { pr_err("eagerfpu not present, disabling some xstate features: 0x%llx\n", pcntxt_mask & XSTATE_EAGER); pcntxt_mask &= ~XSTATE_EAGER; - } else { - eagerfpu = ENABLE; } } @@ -613,9 +594,6 @@ void eager_fpu_init(void) clear_used_math(); current_thread_info()->status = 0; - if (eagerfpu == ENABLE) - setup_force_cpu_cap(X86_FEATURE_EAGER_FPU); - if (!cpu_has_eager_fpu) { stts(); return; --- a/arch/x86/kernel/i387.c +++ b/arch/x86/kernel/i387.c @@ -159,6 +159,19 @@ static void init_thread_xstate(void) xstate_size = sizeof(struct i387_fsave_struct); } +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); + /* * Called at bootup to set up the initial FPU state that is later cloned * into all processes. @@ -197,6 +210,17 @@ void fpu_init(void) if (xstate_size == 0) init_thread_xstate(); + /* + * We should always enable eagerfpu, but it doesn't work properly + * here without fpu and fxsr. + */ + if (eagerfpu == AUTO) + eagerfpu = (boot_cpu_has(X86_FEATURE_FPU) && + boot_cpu_has(X86_FEATURE_FXSR)) ? + ENABLE : DISABLE; + if (eagerfpu == ENABLE) + setup_force_cpu_cap(X86_FEATURE_EAGER_FPU); + mxcsr_feature_mask_init(); xsave_init(); eager_fpu_init();