From nobody Fri Dec 19 20:42:29 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9A48C433F5 for ; Wed, 16 Feb 2022 10:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbiBPK2O (ORCPT ); Wed, 16 Feb 2022 05:28:14 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232879AbiBPK1H (ORCPT ); Wed, 16 Feb 2022 05:27:07 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF13D212897; Wed, 16 Feb 2022 02:26:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645007215; x=1676543215; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ie0tCkuCmIT++Q1x3wLM6OpLH0d8phwb7tCfdjlxfP0=; b=CrmxyiSuzJ6bU/HTKQcGqjp8PSIFRWgxNyi+JEN5cO4YQxKuNBKLRaUP vrDDr36cCTGdv8eQzEhTW1H5fOX1AxbJILMXxv5PBvq137iDmvfdtj7zV H5jnRE40SavUlGwmcVzIYXw5uezitHVQcKWbdahjhue/9jEG9byQJ9WTJ 6OKm+AvhwDAl3zm/iAJ6rwlHXADecW/rkj36LdnFNvjrcNVzgawl2NZ1x FZ+QgBaKL/MqIUNVTDw9hwnHMkvjCMGoh91tHOIyuDMcGDBL9BMMp2rIG PzB2A41woFn0PmDCU47xUMLboyZnpEgJYHYf38eiaYn3+0/mTLDh4srP8 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="250312477" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="250312477" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 02:26:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="498708603" Received: from embargo.jf.intel.com ([10.165.9.183]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 02:26:50 -0800 From: Yang Weijiang To: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com, like.xu.linux@gmail.com, vkuznets@redhat.com, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Like Xu , Yang Weijiang Subject: [PATCH v9 10/17] KVM: x86: Refine the matching and clearing logic for supported_xss Date: Tue, 15 Feb 2022 16:25:37 -0500 Message-Id: <20220215212544.51666-11-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220215212544.51666-1-weijiang.yang@intel.com> References: <20220215212544.51666-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Like Xu Refine the code path of the existing clearing of supported_xss in this way: initialize the supported_xss with the filter of KVM_SUPPORTED_XSS mask and update its value in a bit clear manner (rather than bit setting). Suggested-by: Sean Christopherson Signed-off-by: Like Xu Signed-off-by: Yang Weijiang --- arch/x86/kvm/vmx/vmx.c | 5 +++-- arch/x86/kvm/x86.c | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 62188f2ab2d4..da2a16c0b8d1 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7434,9 +7434,10 @@ static __init void vmx_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_UMIP); =20 /* CPUID 0xD.1 */ - supported_xss =3D 0; - if (!cpu_has_vmx_xsaves()) + if (!cpu_has_vmx_xsaves()) { kvm_cpu_cap_clear(X86_FEATURE_XSAVES); + supported_xss =3D 0; + } =20 /* CPUID 0x80000001 and 0x7 (RDPID) */ if (!cpu_has_vmx_rdtscp()) { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5d8a0364a3cc..fb1a62eedd86 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -223,6 +223,8 @@ static struct kvm_user_return_msrs __percpu *user_retur= n_msrs; | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ | XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE) =20 +#define KVM_SUPPORTED_XSS 0 + u64 __read_mostly host_efer; EXPORT_SYMBOL_GPL(host_efer); =20 @@ -11522,8 +11524,10 @@ int kvm_arch_hardware_setup(void *opaque) =20 rdmsrl_safe(MSR_EFER, &host_efer); =20 - if (boot_cpu_has(X86_FEATURE_XSAVES)) + if (boot_cpu_has(X86_FEATURE_XSAVES)) { rdmsrl(MSR_IA32_XSS, host_xss); + supported_xss =3D host_xss & KVM_SUPPORTED_XSS; + } =20 r =3D ops->hardware_setup(); if (r !=3D 0) --=20 2.27.0