Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp200285pxb; Wed, 3 Feb 2021 03:26:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxABXDPtvT7H289+j1yHTccJbKPaPP+HYQRpcbuJXsmiMnP1yW9vNGTEWOyFak2UgRXRjQ5 X-Received: by 2002:a17:906:87c3:: with SMTP id zb3mr2744167ejb.244.1612351587163; Wed, 03 Feb 2021 03:26:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612351587; cv=none; d=google.com; s=arc-20160816; b=gMwawmapjTd6u0NhYIFbCoyIcQADvlz37GVurvtO+onLb1SLwOieAexHXGv0fCdtcz YABM9CEP77JarlXiACZmIKLhB1jgGCKLkYq6xnzW7WWekofB5eDCDAOcQjKb4aWzrM94 lsIbl3itd5Y6Lxj6MlhSUUVovV1vdcZhjLzDZMENCk0HtTvKNv5SAL0pBBNdtUpvLfmQ WbyDeGqU/CdcHZJ48wOoezSvgC9lkUZj6iX5P48r5O8NnEkfjEPOi39qJ4kB/3Hp+lKM EpL0KqbFi6N0LgDqxi6lN+Ea1K8xWl4fBh6uM7T6VGQj7rzLl32nmV0+bz30oRPPN4pi qKsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=68NUTV4FORjGNb4CoX+GB8Cvd0INh4lD+U/clk8rz7o=; b=dfWXOJ3BHa39hDtldjBPDYymd8vRHmHIhfEu/u3ZrgURVxA959EfoA44/WTlkVNFtH 2kYxqNEcOg/jizv6tIdbbUI+r5IPuhCyHISTPlpCSndmKnZVOyVbVAXlikvNhTN8Z2t3 079H8nl4W3+TTjE92xdeLDs3TPjdJCNW4mGpB1pVyKKgqdKlethaXhpOXdrFZbsAmLLd nO9uS1ux/ruLR9+S/LV1mmveIJAAn8MBm4Z/L6SRO9sPEMhB3PorK7eftJO0Hf43MRiT w21hnnUus+HJ1CyuVnys1YlP30CSpMsF79vjJZ1qmvuBijKhIdUQFj8nmM3kSNAR4haU M7jw== 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 f7si1160283edd.574.2021.02.03.03.26.02; Wed, 03 Feb 2021 03:26:27 -0800 (PST) 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 S234180AbhBCLW5 (ORCPT + 99 others); Wed, 3 Feb 2021 06:22:57 -0500 Received: from mga01.intel.com ([192.55.52.88]:28346 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233970AbhBCLWv (ORCPT ); Wed, 3 Feb 2021 06:22:51 -0500 IronPort-SDR: 8XHOv15Wmcl9JvrQszIxUX+Iyqyp5Ehkg8JWrYFR406KDQfNbnlRMQ48fgH1y+U38wadHwYMx0 x6CkJP2E70NA== X-IronPort-AV: E=McAfee;i="6000,8403,9883"; a="199981252" X-IronPort-AV: E=Sophos;i="5.79,398,1602572400"; d="scan'208";a="199981252" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 03:22:10 -0800 IronPort-SDR: ripUjQo/ALViGKnbPULZnRlXedGAddQynxji8jEWod4h7ZwLYd1oP83ffyyC90NTmjktNXP3/U kltFP04/y+AA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,398,1602572400"; d="scan'208";a="480311096" Received: from unknown (HELO local-michael-cet-test.sh.intel.com) ([10.239.159.166]) by fmsmga001.fm.intel.com with ESMTP; 03 Feb 2021 03:22:08 -0800 From: Yang Weijiang To: pbonzini@redhat.com, seanjc@google.com, jmattson@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yu.c.zhang@linux.intel.com, Yang Weijiang Subject: [PATCH v15 02/14] KVM: x86: Refresh CPUID on writes to MSR_IA32_XSS Date: Wed, 3 Feb 2021 19:34:09 +0800 Message-Id: <20210203113421.5759-3-weijiang.yang@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20210203113421.5759-1-weijiang.yang@intel.com> References: <20210203113421.5759-1-weijiang.yang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Updated CPUID.0xD.0x1, which reports the current required storage size of all features enabled via XCR0 | XSS, when the guest's XSS is modified. Note, KVM does not yet support any XSS based features, i.e. supported_xss is guaranteed to be zero at this time. Co-developed-by: Zhang Yi Z Signed-off-by: Zhang Yi Z Signed-off-by: Yang Weijiang --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 21 ++++++++++++++++++--- arch/x86/kvm/x86.c | 7 +++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 3d6616f6f6ef..1734f872712d 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -611,6 +611,7 @@ struct kvm_vcpu_arch { u64 xcr0; u64 guest_supported_xcr0; + u64 guest_supported_xss; struct kvm_pio_request pio; void *pio_data; diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 13036cf0b912..6d7d9d59fd5b 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -129,9 +129,24 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu) best->ebx = xstate_required_size(vcpu->arch.xcr0, false); best = kvm_find_cpuid_entry(vcpu, 0xD, 1); - if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) || - cpuid_entry_has(best, X86_FEATURE_XSAVEC))) - best->ebx = xstate_required_size(vcpu->arch.xcr0, true); + if (best) { + if (cpuid_entry_has(best, X86_FEATURE_XSAVES) || + cpuid_entry_has(best, X86_FEATURE_XSAVEC)) { + u64 xstate = vcpu->arch.xcr0 | vcpu->arch.ia32_xss; + + best->ebx = xstate_required_size(xstate, true); + } + + if (!cpuid_entry_has(best, X86_FEATURE_XSAVES)) { + best->ecx = 0; + best->edx = 0; + } + vcpu->arch.guest_supported_xss = + (((u64)best->edx << 32) | best->ecx) & supported_xss; + + } else { + vcpu->arch.guest_supported_xss = 0; + } best = kvm_find_cpuid_entry(vcpu, KVM_CPUID_FEATURES, 0); if (kvm_hlt_in_guest(vcpu->kvm) && best && diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a657706358e8..30a07caf077c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3133,9 +3133,12 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) * IA32_XSS[bit 8]. Guests have to use RDMSR/WRMSR rather than * XSAVES/XRSTORS to save/restore PT MSRs. */ - if (data & ~supported_xss) + if (data & ~vcpu->arch.guest_supported_xss) return 1; - vcpu->arch.ia32_xss = data; + if (vcpu->arch.ia32_xss != data) { + vcpu->arch.ia32_xss = data; + kvm_update_cpuid_runtime(vcpu); + } break; case MSR_SMI_COUNT: if (!msr_info->host_initiated) -- 2.26.2