Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2778548ybk; Tue, 12 May 2020 07:58:54 -0700 (PDT) X-Google-Smtp-Source: APiQypJF62p0BmNjqDOu2CWXoXLaAtiFh+JlzYZWj5PvfIP9zHeY/H4BdmIj147e6gqi/wfsBr66 X-Received: by 2002:a17:906:33c9:: with SMTP id w9mr11237691eja.284.1589295533859; Tue, 12 May 2020 07:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589295533; cv=none; d=google.com; s=arc-20160816; b=FBS1c269ywkAmamcgnN/OyeJL1bsjksy2fKxNepEPIz5RSOPr7g/20zI1x1QUiPpwY g7jysdCTKq5I9DecjdqBjSyQW+5NGRUrZwayKAJJLElXLu7G6JmLaJ1ELTmkSSChBmS4 YDSD2JxefmXPCj0+P8HkG4S+SrM4h9ul4yGzTKBbUiod0x1gayNJZ6AD76pAAuHITezB Rlcm319A0Y2mlsWuxf1UtMo947PZUJFZ2AeBL0mpIs9FX+4udbxQ3qDOIrKjtzYfKYjZ MQiMeLxPqSmpunKqnD/fpB+7tqj6sWtVtdBhWI2h2Y52pCFZPIf5sOeRUxY+qd9YePKJ xa2A== 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=Df+Rck3W9pQak4GyzphyKSCh++2IIq3cnPW0OBFEIis=; b=zAsgLw7mhvX1qGwAnqOd7Pt0Zfx5tdhpBcPEBKgqocxyeC+S8Jbe20QdkWLiPB0Gwl FSYBHPeT3My3qO8INRzl+RRe2Pu4p6F4vGxwfgHfVuPjGTJz2LBLE9VQS5XIwURnIC9f tAyr+MdB3dJrTLjnarLJTzfBfa951WBdKlwvpxzIcQBzrVDj57+0PPi3C+ZXlnLITohj u+Xqzk1dRC/iQi30kLfsXpil9T1p8lpkFdoaMilcw04DNwMg+b9iGGpk94N0+OaPvBlf tuCjcdlPQuc4aqqBXocPfj6ScZ1b7TvlTpyAla9gLVK449QBrCRVxd0Loji1yZH6a3Eh tvsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id oa21si4549708ejb.375.2020.05.12.07.58.30; Tue, 12 May 2020 07:58:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730509AbgELOzg (ORCPT + 99 others); Tue, 12 May 2020 10:55:36 -0400 Received: from mga05.intel.com ([192.55.52.43]:29542 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730382AbgELOzL (ORCPT ); Tue, 12 May 2020 10:55:11 -0400 IronPort-SDR: KxMJMbIabyE6yDBT5BN3vL/bSjW7lWFaLF82e1KxesbqygEYIR5DYAw+Q54ohtRjq+F18n5MHp LKfpATp2UlLg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2020 07:55:08 -0700 IronPort-SDR: ycXa9Zx+oa3bMYzeNsXVx6WidMeyg+KjvHrd4q3baB8WKcIF9fxtE728pgCvjYxrc1zo1dvV9c vJ2VSjIqwsTA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,384,1583222400"; d="scan'208";a="371587810" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga001.fm.intel.com with ESMTP; 12 May 2020 07:55:08 -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 v4 04/10] x86/fpu/xstate: Introduce XSAVES supervisor states Date: Tue, 12 May 2020 07:54:38 -0700 Message-Id: <20200512145444.15483-5-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200512145444.15483-1-yu-cheng.yu@intel.com> References: <20200512145444.15483-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. Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Yu-cheng Yu Reviewed-by: Dave Hansen Reviewed-by: Tony Luck --- v2: - Remove printing of supervisor xstates from fpu__init_system_xstate(). 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 fa71af643025..a68213ed5be6 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