[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <301184ce-05e5-871c-7a6c-4298a0cbd1ae@intel.com>
Date: Wed, 23 Nov 2022 15:56:54 -0800
From: Dave Hansen <dave.hansen@...el.com>
To: Kai Huang <kai.huang@...el.com>, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org
Cc: linux-mm@...ck.org, seanjc@...gle.com, pbonzini@...hat.com,
dan.j.williams@...el.com, rafael.j.wysocki@...el.com,
kirill.shutemov@...ux.intel.com, ying.huang@...el.com,
reinette.chatre@...el.com, len.brown@...el.com,
tony.luck@...el.com, peterz@...radead.org, ak@...ux.intel.com,
isaku.yamahata@...el.com, chao.gao@...el.com,
sathyanarayanan.kuppuswamy@...ux.intel.com, bagasdotme@...il.com,
sagis@...gle.com, imammedo@...hat.com
Subject: Re: [PATCH v7 16/20] x86/virt/tdx: Configure TDX module with TDMRs
and global KeyID
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? 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?
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.
Hint #3: Comments don't actually affect the allocation
<snip>
Powered by blists - more mailing lists