Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1108843pxv; Fri, 16 Jul 2021 01:38:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBsJWCS9vBhfqJsG43fvnXWj7xx54dc6yJa4io+eVxQLvtgOE90BRVrxMiQYP8rI+kKrLl X-Received: by 2002:a17:906:6814:: with SMTP id k20mr10551628ejr.381.1626424734225; Fri, 16 Jul 2021 01:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424734; cv=none; d=google.com; s=arc-20160816; b=fPUbOgOAaUbEr+duDA8/KzvHP6An/ViB8GrnqYhipYSKSetfzQkjPaoXm3sirSSl35 CgCWrCqr/9k+L5w+C/aVeVSR/h/Y53t2PfhzdIaowB84bLItfA7IfjKP8uGPwpoCPRQA /OtngCUjPI2Vlu6Mg1yulRD4luV+7vB/A0DSi/aFNxOiuqVoUO7n2eLY+dUAUZoyiMqm vGEe0WGXBrmVUVs/ytuG9WH3V94LkvozC2cmteZnDMb2yJuRdziNbex+9W4iw9tPtuzb jy90fKdVXpZIcM5Vk2+g0UmWgQnUen4NSh9t/WfTwyR0sWgQkiKTuPwIShoEJ4zmHvMW 8RXQ== 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; bh=x+0caHybOBqAZzu/GxvANIo+64Qb13S+R5G02gTkOWc=; b=FGKRiPJ6GPM5+GjysNmaxEl2Ywk18jxpyC5C/SlNUShJ6YY+y9UvIBWT8rY8VT2JUz OCcyx17P7rjgtfuWBPXDR2QPrUE/vcaHpW6xosez+8IZXyRQ5u4dKGb5eZfqB7+Js7im SeMCd7imOYuSpPvzFrkWXXunYhr+85s1wWmvXK0hQrL4C4Nd/n+VmD1w6ZpPHiaV+6Zt TUZwsmiqubPx3IQ0qDrW9D9G95HVdr0I32EK14ai17I1KQ3HCY4IW8iiUjT0yNaqDx8Z GuWQZ+bIY6xo6q7eLNOhq35jic56URAVnY84hOyMQyLLqBAt7ERLPxbgznSp/E2h/WIi Q2lQ== 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 a18si10770695ejv.28.2021.07.16.01.38.31; Fri, 16 Jul 2021 01:38:54 -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 S237208AbhGPIjh (ORCPT + 99 others); Fri, 16 Jul 2021 04:39:37 -0400 Received: from mga09.intel.com ([134.134.136.24]:15663 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238503AbhGPIj2 (ORCPT ); Fri, 16 Jul 2021 04:39:28 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10046"; a="210687305" X-IronPort-AV: E=Sophos;i="5.84,244,1620716400"; d="scan'208";a="210687305" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jul 2021 01:36:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,244,1620716400"; d="scan'208";a="460679821" Received: from michael-optiplex-9020.sh.intel.com ([10.239.159.182]) by orsmga008.jf.intel.com with ESMTP; 16 Jul 2021 01:36:31 -0700 From: Yang Weijiang To: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com, vkuznets@redhat.com, wei.w.wang@intel.com, like.xu.linux@gmail.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yang Weijiang Subject: [PATCH v6 07/12] KVM: x86: Refresh CPUID on writes to MSR_IA32_XSS Date: Fri, 16 Jul 2021 16:50:01 +0800 Message-Id: <1626425406-18582-8-git-send-email-weijiang.yang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1626425406-18582-1-git-send-email-weijiang.yang@intel.com> References: <1626425406-18582-1-git-send-email-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 Message-Id: <20210203113421.5759-3-weijiang.yang@intel.com> Signed-off-by: Paolo Bonzini --- 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 9c7ced0e3171..a98b15cefc6b 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -651,6 +651,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 b4da665bb892..d6e343809b25 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -131,9 +131,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 b586a45fce2b..5f2e13c9f507 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3265,9 +3265,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.21.1