[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YwT0+DO4AuO1xL82@google.com>
Date: Tue, 23 Aug 2022 15:40:40 +0000
From: Sean Christopherson <seanjc@...gle.com>
To: Binbin Wu <binbin.wu@...ux.intel.com>
Cc: isaku.yamahata@...el.com, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, isaku.yamahata@...il.com,
Paolo Bonzini <pbonzini@...hat.com>, erdemaktas@...gle.com,
Sagi Shahar <sagis@...gle.com>
Subject: Re: [PATCH v8 018/103] KVM: TDX: Stub in tdx.h with structs,
accessors, and VMCS helpers
On Tue, Aug 23, 2022, Binbin Wu wrote:
>
> On 2022/8/8 6:01, isaku.yamahata@...el.com wrote:
> > +static __always_inline void tdvps_vmcs_check(u32 field, u8 bits)
> > +{
> > + BUILD_BUG_ON_MSG(__builtin_constant_p(field) && (field) & 0x1,
> > + "Read/Write to TD VMCS *_HIGH fields not supported");
> > +
> > + BUILD_BUG_ON(bits != 16 && bits != 32 && bits != 64);
> > +
> > + BUILD_BUG_ON_MSG(bits != 64 && __builtin_constant_p(field) &&
> > + (((field) & 0x6000) == 0x2000 ||
> > + ((field) & 0x6000) == 0x6000),
> > + "Invalid TD VMCS access for 64-bit field");
>
> if bits is 64 here, "bits != 64" is false, how could this check for "Invalid
> TD VMCS access for 64-bit field"?
Bits 14:13 of the encoding, which is extracted by "(field) & 0x6000", encodes the
width of the VMCS field. Bit 0 of the encoding, "(field) & 0x1" above, is a modifier
that is only relevant when operating in 32-bit mode, and is disallowed because TDX is
64-bit only.
This yields four possibilities for TDX:
(field) & 0x6000) == 0x0000 : 16-bit field
(field) & 0x6000) == 0x2000 : 64-bit field
(field) & 0x6000) == 0x4000 : 32-bit field
(field) & 0x6000) == 0x6000 : 64-bit field (technically "natural width", but
effectively 64-bit because TDX is
64-bit only)
The assertion is that if the encoding indicates a 64-bit field (0x2000 or 0x6000),
then the number of bits KVM is accessing must be '64'. The below assertions do
the same thing for 32-bit and 16-bit fields.
> > + BUILD_BUG_ON_MSG(bits != 32 && __builtin_constant_p(field) &&
> > + ((field) & 0x6000) == 0x4000,
> > + "Invalid TD VMCS access for 32-bit field");
>
> ditto
>
>
> > + BUILD_BUG_ON_MSG(bits != 16 && __builtin_constant_p(field) &&
> > + ((field) & 0x6000) == 0x0000,
> > + "Invalid TD VMCS access for 16-bit field");
>
> ditto
Powered by blists - more mailing lists