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] [thread-next>] [day] [month] [year] [list]
Message-ID: <cb83246f93281138f0e970bfccea4b13f2a64046.camel@intel.com>
Date:   Fri, 25 Nov 2022 00:59:25 +0000
From:   "Huang, Kai" <kai.huang@...el.com>
To:     "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
        "Hansen, Dave" <dave.hansen@...el.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC:     "Luck, Tony" <tony.luck@...el.com>,
        "bagasdotme@...il.com" <bagasdotme@...il.com>,
        "ak@...ux.intel.com" <ak@...ux.intel.com>,
        "Wysocki, Rafael J" <rafael.j.wysocki@...el.com>,
        "kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>,
        "Christopherson,, Sean" <seanjc@...gle.com>,
        "Chatre, Reinette" <reinette.chatre@...el.com>,
        "pbonzini@...hat.com" <pbonzini@...hat.com>,
        "linux-mm@...ck.org" <linux-mm@...ck.org>,
        "Yamahata, Isaku" <isaku.yamahata@...el.com>,
        "peterz@...radead.org" <peterz@...radead.org>,
        "Shahar, Sagi" <sagis@...gle.com>,
        "imammedo@...hat.com" <imammedo@...hat.com>,
        "Gao, Chao" <chao.gao@...el.com>,
        "Brown, Len" <len.brown@...el.com>,
        "sathyanarayanan.kuppuswamy@...ux.intel.com" 
        <sathyanarayanan.kuppuswamy@...ux.intel.com>,
        "Huang, Ying" <ying.huang@...el.com>,
        "Williams, Dan J" <dan.j.williams@...el.com>
Subject: Re: [PATCH v7 16/20] x86/virt/tdx: Configure TDX module with TDMRs
 and global KeyID

On Wed, 2022-11-23 at 15:56 -0800, Dave Hansen wrote:
> On 11/20/22 16:26, Kai Huang wrote:
> > After the TDX-usable memory regions are constructed in an array of TDMRs
> > and the global KeyID is reserved, configure them to the TDX module using
> > TDH.SYS.CONFIG SEAMCALL.  TDH.SYS.CONFIG can only be called once and can
> > be done on any logical cpu.
> > 
> > Reviewed-by: Isaku Yamahata <isaku.yamahata@...el.com>
> > Signed-off-by: Kai Huang <kai.huang@...el.com>
> > ---
> >  arch/x86/virt/vmx/tdx/tdx.c | 37 +++++++++++++++++++++++++++++++++++++
> >  arch/x86/virt/vmx/tdx/tdx.h |  2 ++
> >  2 files changed, 39 insertions(+)
> > 
> > diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
> > index e2cbeeb7f0dc..3a032930e58a 100644
> > --- a/arch/x86/virt/vmx/tdx/tdx.c
> > +++ b/arch/x86/virt/vmx/tdx/tdx.c
> > @@ -979,6 +979,37 @@ static int construct_tdmrs(struct tdmr_info *tdmr_array, int *tdmr_num)
> >  	return ret;
> >  }
> >  
> > +static int config_tdx_module(struct tdmr_info *tdmr_array, int tdmr_num,
> > +			     u64 global_keyid)
> > +{
> > +	u64 *tdmr_pa_array;
> > +	int i, array_sz;
> > +	u64 ret;
> > +
> > +	/*
> > +	 * TDMR_INFO entries are configured to the TDX module via an
> > +	 * array of the physical address of each TDMR_INFO.  TDX module
> > +	 * requires the array itself to be 512-byte aligned.  Round up
> > +	 * the array size to 512-byte aligned so the buffer allocated
> > +	 * by kzalloc() will meet the alignment requirement.
> > +	 */
> 
> Aagh.  Return of (a different) 512-byte aligned structure.
> 
> > +	array_sz = ALIGN(tdmr_num * sizeof(u64), TDMR_INFO_PA_ARRAY_ALIGNMENT);
> > +	tdmr_pa_array = kzalloc(array_sz, GFP_KERNEL);
> 
> Just to be clear, all that chatter about alignment is because the
> *START* of the array has to be aligned.  Right?  
> 

Correct.

> I see alignment for
> 'array_sz', but that's not the start of the array.
> 
> tdmr_pa_array is the start of the array.  Where is *THAT* aligned?

The alignment is assumed to be guaranteed based on the Documentation you quoted
below.

> 
> How does rounding up the size make kzalloc() magically know how to align
> the *START* of the allocation?
> 
> Because I'm actually questioning my own sanity at this point, I went and
> double-checked the docs (Documentation/core-api/memory-allocation.rst):
> 
> > The address of a chunk allocated with `kmalloc` is aligned to at least
> > ARCH_KMALLOC_MINALIGN bytes.  For sizes which are a power of two, the
> > alignment is also guaranteed to be at least the respective size.
> 
> Hint #1: ARCH_KMALLOC_MINALIGN is way less than 512.
> Hint #2: tdmr_num is not guaranteed to be a power of two.

	tdmr_num * sizeof(u64) is not guaranteed.

> Hint #3: Comments don't actually affect the allocation

Sorry I don't understand the Hint #3.

Perhaps I should just allocate one page so it must be 512-byte aligned?

	/*
	 * TDMR_INFO entries are configured to the TDX module  via an array
	 * of physical address of each TDMR_INFO.  The TDX module requires
	 * the array itself to be 512-byte aligned.  Just allocate a page
	 * to use it as the array so the alignment can be guaranteed.  The
	 * page will be freed after TDH.SYS.CONFIG anyway.
	 */
	

Powered by blists - more mailing lists