Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2383070pxj; Mon, 10 May 2021 01:19:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6qQbW45+dkIZb7tMgWcigsCQ+jARy962t6pWSwv76K2Ill/J9KAxeXHolIrwGEAMoDU++ X-Received: by 2002:a05:6402:3548:: with SMTP id f8mr27712059edd.251.1620634794035; Mon, 10 May 2021 01:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620634794; cv=none; d=google.com; s=arc-20160816; b=K8kxBz+RCWNeC/7YwwjwjDyBeanWjDx2Tn03MO6Iw0h9oR/GRvuBAmjZsC8P+93CGC 6J8UFqFcNfkqOU6ufhDrZWevisUGLgmVacCjnq6QjM7EZYx59AQDorKe+3EAyCxQdFCB DPrzcAFoByLa81SFGYzHfIKa7OnEziAojA9y/k/Qmmb6RRp96JYnMRo8WC9LN2RPB6cr DaRDMnc6AgKt2EbSBxF16RfykVJD7WiPMykNI6dELFBIKiQ3LN1Fp5Fe+FuOS7pPmVYn ZrBDlXVBjJLvooSEuLB/GDWYhQy8XPGMWTtw4xGUtZRz+0tMguY0TTHUqCM2NzkRnVmM MDIQ== 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=ZmZm3Jko1v3ID81xAqT2Qvsu9cHu/PNh2EFfmlDVSKU=; b=I7qe25NEbACdUjMkAexWPhojUM0jW0uvDnKJKJOJeFxqExzAlYeYG+UUD7shpWUzym NeG/2hIsf5gDhyN6o9HDCWITTn7lYVXYolLvy1nk3NdVXNySZ0mN/Gcks6RWYWF7Dp90 fDa+bablVtg2M+lhT6vN22RHBCE30i2dvljv887s452itf6yVQ8kx+JwNa15hyVxUjS5 jG52cZpOneL/tEFVoBayP0DSreBRpAiph61zPQxvJWTRK9rUB9FGFmmMKRO+0ZiR1gnI iFwI3chDA0nRWM57wzEtVUffYRjyxpj565TMwoueeDxwfpN3ywa4bfuN7L0Z2KTUU3LL toWg== 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 u1si12553471edx.492.2021.05.10.01.19.31; Mon, 10 May 2021 01:19: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 S230405AbhEJIRr (ORCPT + 99 others); Mon, 10 May 2021 04:17:47 -0400 Received: from mga12.intel.com ([192.55.52.136]:42752 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbhEJIRh (ORCPT ); Mon, 10 May 2021 04:17:37 -0400 IronPort-SDR: xamYHSpP1LJYGecblgikwpraTbNlSoaOtD96Py7PAU3NgARBAYPASUPZQ+1k/xs28PCes0DNq9 R0dxrVsfnXjw== X-IronPort-AV: E=McAfee;i="6200,9189,9979"; a="178727809" X-IronPort-AV: E=Sophos;i="5.82,287,1613462400"; d="scan'208";a="178727809" 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:33 -0700 IronPort-SDR: BtGn8W/bEKnvkM5tWe28Cx4jwUeYxjVfAoYbadjt+GQK+/njuLa56E/DTGkXzVY5VB5txs4xoT XAqksDP31spA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,287,1613462400"; d="scan'208";a="408250910" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga002.jf.intel.com with ESMTP; 10 May 2021 01:16:30 -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 07/10] KVM: x86: Refresh CPUID on writes to MSR_IA32_XSS Date: Mon, 10 May 2021 16:15:31 +0800 Message-Id: <20210510081535.94184-8-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 From: Yang Weijiang 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 55efbacfc244..cac41bae5f4e 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 e7527b6cadb4..8a1855760e43 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 5bd550eaf683..3a67ad29fa9d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3247,9 +3247,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.31.1