Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2382672pxj; Mon, 10 May 2021 01:19:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ1360kDHUtK88oA+/qsfoIj1xkYHwJdHbpthqErvcj934W+4qYWACD9maU//f5gARe/3l X-Received: by 2002:a17:906:8a59:: with SMTP id gx25mr24768063ejc.63.1620634745537; Mon, 10 May 2021 01:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620634745; cv=none; d=google.com; s=arc-20160816; b=A5pyw1PpXCzpnMQAKLbLlSdl4AZQdV2Bf0Odi713lguxUmj7CmwzFt2yuEBJu16wS8 b2oOgIfx3tc3SIFvIflsfbJ/BsltOHDHTfWRbE8fW8f6x2LZOxaaXMCxzN5qh6uIaPxk 0tilJBLmpjP1T1+Nf+m6lKAsb6IyyQAkLn4T/nivbB5dAZcGZyvPgGXL5nC4dAdmPnt/ KTybyz+HSvXqv8kuA+OrGDCoW0yRyZ71WRykNMkByMU1c2qALK6kaESuJyeiR5X2SdxR zhwBWraIxiGi0sIoH2kshp0TBmkpyppXhPZ98eiqVKzRvnA4y/Iw9cdDGgi+S4i9Zwxh 6xYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=jzgJxTyRtV3L73ga5h3ojfDIsncUajwmiJo+i36sWjY=; b=yIkkrP2ypu1e7DrOPpuRU2i9vb4QYD0T0JyMCG+Xm72DULSFV836uFiEUedIW3VpvX 7uxEWpMd+7L20PkHPu4+dK2mxUmTxghPiNYpdqL0Pxh2Ew1zeYff6roT23O9/0fQkeO6 i0LGC+Md9OfPtXxHMifXLgTLo/psk4l7XHGb0EWBmdci1yHwdo7qxg+9dfmYfuHOklTy EatAm8i1LQnfcKq1v0PaCqi/CiY7FdtQD3RAu5KNZLsAUK0FmLeAK31Gbk6zQwmfN9cz LdnDcxj0AbEUNph3Xy3SowtJcIuofJuj+4UW4SgnON91Rhnv2kf40v8EoiCYHlNhdegY HPrA== 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 c70si8875566edf.310.2021.05.10.01.18.42; Mon, 10 May 2021 01:19:05 -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 S230427AbhEJISJ (ORCPT + 99 others); Mon, 10 May 2021 04:18:09 -0400 Received: from mga12.intel.com ([192.55.52.136]:42745 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbhEJISD (ORCPT ); Mon, 10 May 2021 04:18:03 -0400 IronPort-SDR: nIYrj6Th6YIWXU8kccrnw6P7SimQpSxdlUAPaITU2Eoiybvfy1p74qsQTD2d4vtTOI5V2D68fm Vt+vr9gSRNug== X-IronPort-AV: E=McAfee;i="6200,9189,9979"; a="178727863" X-IronPort-AV: E=Sophos;i="5.82,287,1613462400"; d="scan'208";a="178727863" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2021 01:16:38 -0700 IronPort-SDR: kDaLMmQ7qIEtzBGjdyaCKBJ5lu1ay316rk7uTBooip+k8P1ETMHdLWCMWq13U0UAVeXUCqveNM +DMNnUZ1i5Zg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,287,1613462400"; d="scan'208";a="408250952" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga002.jf.intel.com with ESMTP; 10 May 2021 01:16:36 -0700 From: Like Xu To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , weijiang.yang@intel.com, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH v4 09/10] KVM: x86: Refine the matching and clearing logic for supported_xss Date: Mon, 10 May 2021 16:15:33 +0800 Message-Id: <20210510081535.94184-10-like.xu@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510081535.94184-1-like.xu@linux.intel.com> References: <20210510081535.94184-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 f88c6e8f7a3a..d080bf163565 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7384,9 +7384,10 @@ static __init void vmx_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_UMIP); /* CPUID 0xD.1 */ - supported_xss = 0; - if (!cpu_has_vmx_xsaves()) + if (!cpu_has_vmx_xsaves()) { kvm_cpu_cap_clear(X86_FEATURE_XSAVES); + supported_xss = 0; + } /* 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 b699f7a37b1a..3a32bea2277e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -203,6 +203,8 @@ static struct kvm_user_return_msrs __percpu *user_return_msrs; | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ | XFEATURE_MASK_PKRU) +#define KVM_SUPPORTED_XSS 0 + u64 __read_mostly host_efer; EXPORT_SYMBOL_GPL(host_efer); @@ -10619,8 +10621,10 @@ int kvm_arch_hardware_setup(void *opaque) rdmsrl_safe(MSR_EFER, &host_efer); - if (boot_cpu_has(X86_FEATURE_XSAVES)) + if (boot_cpu_has(X86_FEATURE_XSAVES)) { rdmsrl(MSR_IA32_XSS, host_xss); + supported_xss = host_xss & KVM_SUPPORTED_XSS; + } r = ops->hardware_setup(); if (r != 0) -- 2.31.1