[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 2/3] amd/msr: allow passthrough of VIRT_SPEC_CTRL for HVM guests


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Mon, 9 May 2022 12:23:40 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GjRohO2w6zWAWxxxxyMvxjPFxMF3NNR0gFdp/U8yXKU=; b=fsmTmaeSp+wS2Vj484hPBklIZ4yU6DYW/yVF4cT3f5kwM+ZBaUYdoGuObyTIr26oGnvGU4otkxmC95cERBKoS7dY7dxFtCdd+5HwKuoDx+VXQBR9s3ZgOqbjrm4txNrM+VNuVBoWnNmBw+67+ZKRKc18YsYS/vx0F4Ea9Om6WNgGh/QYI45SdfhkM4uqd6guuc8VRfv2R+0cvXazAg0KQ9le08P++GjAjqm0XsP+9lHuVGXuEqq+JhVwOhfiizJBrH+qTMxJ1CsmGu0JF6qLMk/cD6Du3AXI+UXndjyK3FgK2Qy54vSUWzwn77C6zoyZSVCXHGX973jNiR8QH+9QUw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BPK91CIX8qTdGBp8JLz4yktWNkianaoUaIMt8/HdLxCmfqmXJsxVsU+P3jrV7eMY1/0XT3IaelcD13XeAsvYvn0+J0EPq6omXRzosoxveTvzf8PWAcpr0y3cyAH6S2WZmvkvj1RXJZpOwXcrGrfBpr45hzd4dSI3AWsJp1iWLfm+oDQEH8rxLDiydguritS4djkT4u2eiki9qVwWlRsNOn4MqRXApejzYv3cV09BqtrVQ/Ql7sgffboH3lXrCkkdvCik5rhltYyYoS1ZUMX/Nrs93ztH8ss1bT1H3bm+aG72v6SCXveqgDovo083T0HzzYuxkZxnSNYlERku3mCaAw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 09 May 2022 10:24:13 +0000
  • Ironport-data: A9a23:gsvRAaLlLhfkTjC7FE+RpZQlxSXFcZb7ZxGr2PjKsXjdYENS1GcAm zdNDWvQbvzYNmv9ett3OYqy8EoHvpHWm4JlSAJlqX01Q3x08seUXt7xwmUcns+xwm8vaGo9s q3yv/GZdJhcokf0/0vrav67xZVF/fngqoDUUYYoAQgsA149IMsdoUg7wbRh39Y52YHR7z6l4 rseneWOYDdJ5BYsWo4kw/rrRMRH5amaVJsw5zTSVNgT1LPsvyB94KE3fMldG0DQUIhMdtNWc s6YpF2PEsE1yD92Yj+tuu6TnkTn2dc+NyDW4pZdc/DKbhSvOkXee0v0XRYRQR4/ttmHozx+4 NFQ7reTEQkRBbLnqrQsfgNVNnFdYpQTrdcrIVDn2SCS52vvViK2htlLUgQxN4Be/ftrC2ZT8 /BeMCoKch2Im+OxxvS8V/VogcMgasLsOevzuFk5lW2fUalgHMGFGvqSjTNb9G5YasRmB/HRa tBfcTNyRB/BfwdOKhEcD5dWcOKA2SKkLmII9AL9Sawfv1bU8Cpj0unWG8fUV/iSfZpHh3y0n zeTl4j+KlRAXDCF8hKH+H+xgu7EnQvgRZkfUra/85ZCn1m71mEVThoMWjOTsfS/z0KzRd9bA 0gV4TY167g/8lSxSdvwVAH+p2SL1iPwQPJVGuw+rQ2IlKzd5l/DAnBeF2EZLts7qMUxWDomk EeTmM/kDiBut7vTTm+B8rCTrnW5Pi19wXI+WBLohDAtu7HLyLzfRDqfJjq/OMZZVuHIJAw=
  • Ironport-hdrordr: A9a23:aMdE4KOz04jkDMBcT13155DYdb4zR+YMi2TDiHoddfUFSKalfp 6V98jztSWatN/eYgBEpTmlAtj5fZq8z+8N3WB1B9uftWbd2FdAQLsSjrcKhgeQYBEWldQtqZ uIEZIOb+EYZGIS5aia3OD7KadH/DDuytHUuQ609QYIcegFUdAD0+8vYTzraHGeCTM2c6YRJd 653I5qtjCgcXMYYoCSAWQEZfHKo5numIj9aRALKhY74E3W5AnYoILSIly95FMzQjlPybAt/S zslBH43Lyqt7WexgXH32HewpxKkJ/Ky8dFBuaLls8JQw+cwzqAVcBEYfmvrTo1qOag5BIDl8 TNmQ4pO4BJ53bYbgiO0G7Q8jil9Axrx27pyFeej3emi9f+XigGB81Igp8cWgfF6mI71esMnJ 5j7ia8jd56HBnAlCPy65zjTBdxjHe5pnIkjKo6k2Ffa40Dc7VcxLZvsX+9KK1wUh4S1bpXUd WHVKrnlbZrmBKhHjrkV1BUsZORti9ZJGbEfqAA0vbloQS+0koJjXfw//Zv4EvoxKhNNKWs2N 60Q5iAtIs+OvP+PpgNc9vof6OMexzwaCOJFl6uCnLaM4xCE07xivfMkcYIDaeRCdc18Kc=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, May 06, 2022 at 02:15:47PM +0200, Jan Beulich wrote:
> On 03.05.2022 10:26, Roger Pau Monne wrote:
> > --- a/xen/arch/x86/cpuid.c
> > +++ b/xen/arch/x86/cpuid.c
> > @@ -541,6 +541,9 @@ static void __init calculate_hvm_max_policy(void)
> >           raw_cpuid_policy.basic.sep )
> >          __set_bit(X86_FEATURE_SEP, hvm_featureset);
> >  
> > +    if ( boot_cpu_has(X86_FEATURE_VIRT_SC_MSR_HVM) )
> > +        __set_bit(X86_FEATURE_VIRT_SSBD, hvm_featureset);
> > +
> >      /*
> >       * If Xen isn't virtualising MSR_SPEC_CTRL for HVM guests (functional
> >       * availability, or admin choice), hide the feature.
> 
> Especially with the setting of VIRT_SSBD below here (from patch 1) I
> don't think this can go without comment. The more that the other
> instance ...
> 
> > @@ -597,6 +600,13 @@ static void __init calculate_hvm_def_policy(void)
> >      guest_common_feature_adjustments(hvm_featureset);
> >      guest_common_default_feature_adjustments(hvm_featureset);
> >  
> > +    /*
> > +     * Only expose VIRT_SSBD if AMD_SSBD is not available, and thus
> > +     * VIRT_SC_MSR_HVM is set.
> > +     */
> > +    if ( boot_cpu_has(X86_FEATURE_VIRT_SC_MSR_HVM) )
> > +        __set_bit(X86_FEATURE_VIRT_SSBD, hvm_featureset);
> > +
> >      sanitise_featureset(hvm_featureset);
> >      cpuid_featureset_to_policy(hvm_featureset, p);
> >      recalculate_xstate(p);
> 
> ... here is about default exposure, so cannot really be extended to
> the condition under which this is put in "max" (except that of course
> "max" needs to include everything "def" has).

Would you be OK with adding:

    /*
     * VIRT_SC_MSR_HVM ensures the selection of SSBD is context
     * switched between the hypervisor and guest selected values for
     * HVM when the platform doesn't expose AMD_SSBD support.
     */

> > @@ -3105,6 +3116,30 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
> >      vmcb_set_vintr(vmcb, intr);
> >  }
> >  
> > +/* Called with GIF=0. */
> > +void vmexit_virt_spec_ctrl(void)
> > +{
> > +    unsigned int val = opt_ssbd ? SPEC_CTRL_SSBD : 0;
> > +
> > +    if ( val == current->arch.msrs->virt_spec_ctrl.raw )
> > +        return;
> > +
> > +    if ( cpu_has_virt_ssbd )
> > +        wrmsr(MSR_VIRT_SPEC_CTRL, val, 0);
> > +}
> > +
> > +/* Called with GIF=0. */
> > +void vmentry_virt_spec_ctrl(void)
> > +{
> > +    unsigned int val = opt_ssbd ? SPEC_CTRL_SSBD : 0;
> > +
> > +    if ( val == current->arch.msrs->virt_spec_ctrl.raw )
> > +        return;
> > +
> > +    if ( cpu_has_virt_ssbd )
> > +        wrmsr(MSR_VIRT_SPEC_CTRL, current->arch.msrs->virt_spec_ctrl.raw, 
> > 0);
> > +}
> 
> I guess the double use of current makes it difficult for the compiler
> to CSE both uses. Furthermore for symmetry with the other function
> how about
> 
> void vmentry_virt_spec_ctrl(void)
> {
>     unsigned int val = current->arch.msrs->virt_spec_ctrl.raw;
> 
>     if ( val == (opt_ssbd ? SPEC_CTRL_SSBD : 0) )
>         return;
> 
>     if ( cpu_has_virt_ssbd )
>         wrmsr(MSR_VIRT_SPEC_CTRL, val, 0);
> }
> 
> i.e. "val" always representing the value we want to write?

Yes, that's fine.  I've adjusted the function.

> With at least a comment added above, and preferably with the change
> to the function (unless that gets in the way of the 3rd patch)
> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Thanks, will wait for confirmation that the proposed comment is fine.

Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.