From mboxrd@z Thu Jan 1 00:00:00 1970 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 735E7C3526D for ; Wed, 26 Jan 2022 16:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243174AbiAZQhn (ORCPT ); Wed, 26 Jan 2022 11:37:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243175AbiAZQhk (ORCPT ); Wed, 26 Jan 2022 11:37:40 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFFA9C06161C for ; Wed, 26 Jan 2022 08:37:39 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id h14so90747plf.1 for ; Wed, 26 Jan 2022 08:37:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0lkZXVf0iO42qTs6hmWV+2+LZ5uEDOqbitDpMYhaXGE=; b=U35s0iOlg1H127K2jntAKAz9pNUTT4BjIPRQR3LmfMrto8XQT9oVEI8fImw584Xrhg Kb2Fkwx7b2BPIGTNgkGxnyoHslX+Kgt4S4aBPkqamXByT+Nimjw7/9f7Y1oY6XAbtKLW vEd7QNcl9vw82H+7wrUcszlx0+Al5md/yU0u38N5lyfA3rjNhSIIHTbBpW+1td5S3s5a S4gseYjxmHJoRJ2D5Mo32mSoAJqh9ponRVGa+mNPArgvcdBRyHY+KK5UGNNdfyRZGEzm sKzQFDZNBrrTi8PBzUwDu7B/j8Kg1imcXCuG5jyRFpJP93CFbp+YsiNX3X4QxH72ZZIj ecdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0lkZXVf0iO42qTs6hmWV+2+LZ5uEDOqbitDpMYhaXGE=; b=5dweCtmOwQ+fh0HhcXu1zvk4O33zsBRDjLjpCG9k5Ggg0FI+GLFy17tAihV18OYhkV Hs+Lnz+CfNVcZaKAdi9SMcN/chab/MFC4L9LNsMPdF+HJfu7MnTJrwtJaYjjuujehj9D TRaFqI8b+MW54OtDRoZnPUnVx3E1V66qnlBdlaX48gGQTFrlZSyzwpPY098gxBXqZsRy yoWgWaUV5xpp3YHru+CqyMPgb2DBTCrTTwI45RpqquL+w4WnxSMvfRSbI8ytDWCDMf1I Fj9k7SumwPYiDFKoKYrV24y8EkJzCcYboRoRypv6I2BOxg+hqJhvQfF13aEmVDx25y3z wtdg== X-Gm-Message-State: AOAM532YBIxix0GPmbjGCApxZdafjXy8we0StmsfcJvz9YDfgINaZdGI SleUN3ijTOMFyg9+g1IxZRmOjA== X-Google-Smtp-Source: ABdhPJx3wnTz6Lmd7CP8lDGl/you1LvrfJY9yqRtpA+GKDRZbVlp9xUtDYLSM7/YLkgGC6ty9Ba5jg== X-Received: by 2002:a17:902:b718:b0:14a:c2ac:6ae2 with SMTP id d24-20020a170902b71800b0014ac2ac6ae2mr23555204pls.125.1643215059266; Wed, 26 Jan 2022 08:37:39 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id ha11sm5027116pjb.3.2022.01.26.08.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 08:37:38 -0800 (PST) Date: Wed, 26 Jan 2022 16:37:35 +0000 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , Wanpeng Li , Jim Mattson , Vitaly Kuznetsov , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time Message-ID: References: <20220117082631.86143-1-likexu@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 23, 2022, Like Xu wrote: > From: Like Xu > > XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by > both RESET and INIT. The kvm_set_msr_common()'s handling of MSR_IA32_XSS > also needs to update kvm_update_cpuid_runtime(). In the above cases, the > size in bytes of the XSAVE area containing all states enabled by XCR0 or > (XCRO | IA32_XSS) needs to be updated. > > For simplicity and consistency, existing helpers are used to write values > and call kvm_update_cpuid_runtime(), and it's not exactly a fast path. > > Fixes: a554d207dc46 ("KVM: X86: Processor States following Reset or INIT") > Signed-off-by: Like Xu > --- > v2 -> v3 Changelog: > - Apply s/legacy/existing in the commit message; (Sean) > - Invoke kvm_update_cpuid_runtime() for MSR_IA32_XSS; (Sean) > > arch/x86/kvm/x86.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 55518b7d3b96..4b509b26d9ab 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -3535,6 +3535,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct > msr_data *msr_info) > if (data & ~supported_xss) > return 1; > vcpu->arch.ia32_xss = data; > + kvm_update_cpuid_runtime(vcpu); > break; > case MSR_SMI_COUNT: > if (!msr_info->host_initiated) > @@ -11256,7 +11257,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > > vcpu->arch.msr_misc_features_enables = 0; > > - vcpu->arch.xcr0 = XFEATURE_MASK_FP; > + __kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP); > } > > /* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */ > @@ -11273,7 +11274,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > cpuid_0x1 = kvm_find_cpuid_entry(vcpu, 1, 0); > kvm_rdx_write(vcpu, cpuid_0x1 ? cpuid_0x1->eax : 0x600); > > - vcpu->arch.ia32_xss = 0; > + __kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true); Heh, this now conflicts with a patch Xiaoyao just posted, turns out the SDM was wrong. I think there's also some whitespace change or something that prevents this from applying cleanly. For convenience, I'll post a miniseries with this and Xiaoyao's patch. [*] https://lore.kernel.org/all/20220126034750.2495371-1-xiaoyao.li@intel.com > > static_call(kvm_x86_vcpu_reset)(vcpu, init_event); > > -- > 2.33.1 > >