Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp774485ybb; Sat, 28 Mar 2020 09:45:30 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt5UY11W+n/qoEP98xiMn+VP2c/Dk32+4eV6rvHM1Ckjfz8xbyi7jB83rdKOqNNut3jAgr4 X-Received: by 2002:a05:6820:346:: with SMTP id m6mr3964681ooe.22.1585413930728; Sat, 28 Mar 2020 09:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585413930; cv=none; d=google.com; s=arc-20160816; b=QThovztI+qzwUoTsu1/5aYOsLmcm22cGELxEUmxKCU/I5KPiA4DFYk4GYANLq8jt7U 15B1oB+QDWDGi5QSNJPzeq+eeDe4wcWZQsrU10eH+haLHM/ZgtHyfeILotXd1YE3kK/y Q3GJK7HqsBX2m+/MbvYJXBwYB+UIvoxpaeblvOC895sVSmVyrZKGUNeEW9uxaDSXGqoH Cq7saF9cGXtm29oBVWT3UID+xSxU8auHNAkbRBC6ITvnpB+M6nguSz/5EUD2FB5dj+PM f23WFM7QYwuAnfWYxdtYV7qfytH3MrKC1MnE5byGG6AwHLXlpw9QTZ4HjtTFfOFBmULq xejg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=StZmdguoRmQ8D1XY5GPdTyHUGpzBwmFncPa4Yp2H2Ao=; b=jngI98HOv3rSDVpvFwlyH2pcVs63SWfDpV43kuZ2Sja1m+JcQh25bhLV0kqep4YQ7S n/pQG8j1h4Q4eDv2j6pGOhIA0F7KzftOcWoBrTiS+KjTUhxCQeGnZM7FdLQ5CUbxlWdU R1kY5vsxkn9LbEsVMKjsK35+92WjiO5ObH+bQVM99cpIt6KjLtNeFURyFdOxd5TBsvXP q/R74p64VWvDWm4TP/h6eTqbWO6xBi0IeLC7rnyLVzujpsg2SK7MXPGtzznYTiX7aa/h zE3IHQ4zf+ds6kd/B0vusBY+Ko8zbdVBLnY9XeSfZzFNP/bqseveNLs/okPObjJ6hMKv eTrQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si4180956oth.163.2020.03.28.09.45.17; Sat, 28 Mar 2020 09:45:30 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726282AbgC1Qoh (ORCPT + 99 others); Sat, 28 Mar 2020 12:44:37 -0400 Received: from mga14.intel.com ([192.55.52.115]:39979 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727937AbgC1QoA (ORCPT ); Sat, 28 Mar 2020 12:44:00 -0400 IronPort-SDR: FsD+txz2SteLYzD+pmAZNwc582ib23SZt81ArhHZAVDM5GqQTKFzu7mIyHb2xtr7R0grJqBnP1 6oZj2frjUzmQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2020 09:43:58 -0700 IronPort-SDR: Lxh/r4VGlkKzmRM3Sz0bU7WPvYBsUu+99IK3/YDpOOFZ3i8UXsR5O2Y9HTlrjzsKAi1hOFgdCo L97pnJga7NAg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,317,1580803200"; d="scan'208";a="447771167" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga005.fm.intel.com with ESMTP; 28 Mar 2020 09:43:58 -0700 From: Yu-cheng Yu To: linux-kernel@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Dave Hansen , Tony Luck , Andy Lutomirski , Borislav Petkov , Rik van Riel , "Ravi V. Shankar" , Sebastian Andrzej Siewior , Fenghua Yu , Peter Zijlstra Cc: Yu-cheng Yu Subject: [PATCH v3 04/10] x86/fpu/xstate: Introduce XSAVES supervisor states Date: Sat, 28 Mar 2020 09:43:01 -0700 Message-Id: <20200328164307.17497-5-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200328164307.17497-1-yu-cheng.yu@intel.com> References: <20200328164307.17497-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable XSAVES supervisor states by setting MSR_IA32_XSS bits according to CPUID enumeration results. Also revise comments at various places. v2: - Remove printing of supervisor xstates from fpu__init_system_xstate(). Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Yu-cheng Yu Reviewed-by: Dave Hansen Reviewed-by: Tony Luck --- arch/x86/kernel/fpu/xstate.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index bb8b53223925..28e8229b23a7 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -228,13 +228,14 @@ void fpu__init_cpu_xstate(void) * states can be set here. */ xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures_mask_user()); + + /* + * MSR_IA32_XSS sets supervisor states managed by XSAVES. + */ + if (boot_cpu_has(X86_FEATURE_XSAVES)) + wrmsrl(MSR_IA32_XSS, xfeatures_mask_supervisor()); } -/* - * Note that in the future we will likely need a pair of - * functions here: one for user xstates and the other for - * system xstates. For now, they are the same. - */ static bool xfeature_enabled(enum xfeature xfeature) { return xfeatures_mask_all & BIT_ULL(xfeature); @@ -625,9 +626,6 @@ static void do_extra_xstate_size_checks(void) * the size of the *user* states. If we use it to size a buffer * that we use 'XSAVES' on, we could potentially overflow the * buffer because 'XSAVES' saves system states too. - * - * Note that we do not currently set any bits on IA32_XSS so - * 'XCR0 | IA32_XSS == XCR0' for now. */ static unsigned int __init get_xsaves_size(void) { @@ -750,7 +748,12 @@ void __init fpu__init_system_xstate(void) cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx); xfeatures_mask_all = eax + ((u64)edx << 32); - /* Place supervisor features in xfeatures_mask_all here */ + /* + * Find supervisor xstates supported by the processor. + */ + cpuid_count(XSTATE_CPUID, 1, &eax, &ebx, &ecx, &edx); + xfeatures_mask_all |= ecx + ((u64)edx << 32); + if ((xfeatures_mask_user() & XFEATURE_MASK_FPSSE) != XFEATURE_MASK_FPSSE) { /* * This indicates that something really unexpected happened @@ -810,6 +813,13 @@ void fpu__resume_cpu(void) */ if (boot_cpu_has(X86_FEATURE_XSAVE)) xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures_mask_user()); + + /* + * Restore IA32_XSS. The same CPUID bit enumerates support + * of XSAVES and MSR_IA32_XSS. + */ + if (boot_cpu_has(X86_FEATURE_XSAVES)) + wrmsrl(MSR_IA32_XSS, xfeatures_mask_supervisor()); } /* -- 2.21.0