lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <26afec9c667327191850b17c511901623e91976e.camel@intel.com>
Date: Thu, 25 Apr 2024 21:44:46 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "seanjc@...gle.com" <seanjc@...gle.com>
CC: "Li, Xin3" <xin3.li@...el.com>, "luto@...nel.org" <luto@...nel.org>,
	"x86@...nel.org" <x86@...nel.org>, "Liu, Zhao1" <zhao1.liu@...el.com>,
	"peterz@...radead.org" <peterz@...radead.org>, "Li, Xiaoyao"
	<xiaoyao.li@...el.com>, "mingo@...hat.com" <mingo@...hat.com>,
	"tglx@...utronix.de" <tglx@...utronix.de>, "dave.hansen@...ux.intel.com"
	<dave.hansen@...ux.intel.com>, "pbonzini@...hat.com" <pbonzini@...hat.com>,
	"kvm@...r.kernel.org" <kvm@...r.kernel.org>, "Kang, Shan"
	<shan.kang@...el.com>, "bp@...en8.de" <bp@...en8.de>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v6 8/9] KVM: VMX: Open code VMX preemption timer rate mask
 in its accessor

On Thu, 2024-04-25 at 07:42 -0700, Sean Christopherson wrote:
> On Thu, Apr 25, 2024, Kai Huang wrote:
> > On Wed, 2024-04-24 at 13:06 -0700, Sean Christopherson wrote:
> > > > > static inline u32 vmx_basic_vmcs_mem_type(u64 vmx_basic)
> > > > > {
> > > > > 	return (vmx_basic & GENMASK_ULL(53, 50)) >>
> > > > > 		VMX_BASIC_MEM_TYPE_SHIFT;
> > > > > }
> > > > > 
> > > > > looks not intuitive than original patch.
> > > > 
> > > > Yeah, agreed, that's taking the worst of both worlds.  I'll update patch 5 to drop
> > > > VMX_BASIC_MEM_TYPE_SHIFT when effectively "moving" it into vmx_basic_vmcs_mem_type().
> > > 
> > > Drat.  Finally getting back to this, dropping VMX_BASIC_MEM_TYPE_SHIFT doesn't
> > > work because it's used by nested_vmx_setup_basic(), as is VMX_BASIC_VMCS_SIZE_SHIFT,
> > > which is presumably why past me kept them around.
> > > 
> > > I'm leaning towards keeping things as proposed in this series.  I don't see us
> > > gaining a third copy, or even a third user, i.e. I don't think we are creating a
> > > future problem by open coding the shift in vmx_basic_vmcs_mem_type().  And IMO
> > > code like this
> > > 
> > > 	return (vmx_basic & VMX_BASIC_MEM_TYPE_MASK) >>
> > > 	       VMX_BASIC_MEM_TYPE_SHIFT;
> > > 
> > > is an unnecessary obfuscation when there is literally one user (the accessor).
> > > 
> > > Another idea would be to delete VMX_BASIC_MEM_TYPE_SHIFT and VMX_BASIC_VMCS_SIZE_SHIFT,
> > > and either open code the values or use local const variables, but that also seems
> > > like a net negative, e.g. splits the effective definitions over too many locations.
> > 
> > Alternatively, we can add macros like below to <asm/vmx.h> close to
> > vmx_basic_vmcs_size() etc, so it's straightforward to see.
> > 
> > +#define VMX_BSAIC_VMCS12_SIZE	((u64)VMCS12_SIZE << 32)
> > +#define VMX_BASIC_MEM_TYPE_WB	(MEM_TYPE_WB << 50)
> 
> Hmm, it's a bit hard to see it's specifically VMCS12 size, and given that prior
> to this series, VMX_BASIC_MEM_TYPE_WB = 6, I'm hesitant to re-introduce/redefine
> that macro with a different value.
> 
> What if we add a helper in vmx.h to encode the VMCS info?  Then the #defines for
> the shifts can go away because the open coded shifts are colocated and more
> obviously related.  E.g.
> 
>   static inline u64 vmx_basic_encode_vmcs_info(u32 revision, u16 size, u8 memtype)
>   {
> 	return revision | ((u64)size << 32) | ((u64)memtype << 50);
>   }
> 
> 
> and
> 
>   static void nested_vmx_setup_basic(struct nested_vmx_msrs *msrs)
>   {
> 	/*
> 	 * This MSR reports some information about VMX support. We
> 	 * should return information about the VMX we emulate for the
> 	 * guest, and the VMCS structure we give it - not about the
> 	 * VMX support of the underlying hardware.
> 	 */
> 	msrs->basic = vmx_basic_encode_vmcs_info(VMCS12_REVISION, VMCS12_SIZE,
> 						 X86_MEMTYPE_WB);
> 
> 	msrs->basic |= VMX_BASIC_TRUE_CTLS
> 	if (cpu_has_vmx_basic_inout())
> 		msrs->basic |= VMX_BASIC_INOUT;
>   }

Yeah this is better.  Thanks.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ