Re: [PATCH v2 10/25] x86/virt/tdx: Add SEAMCALL wrappers for TDX flush operations
From: Dave Hansen
Date: Wed Nov 13 2024 - 16:42:04 EST
On 11/13/24 13:18, Edgecombe, Rick P wrote:
> -u64 tdh_vp_flush(u64 tdvpr)
> +u64 tdh_vp_flush(void *tdvpr)
> {
> struct tdx_module_args args = {
> - .rcx = tdvpr,
> + .rcx = __pa(tdvpr),
> };
>
> return seamcall(TDH_VP_FLUSH, &args);
I'd much rather these be:
tdx->tdvpr_page = alloc_page(GFP_KERNEL_ACCOUNT);
and then you pass around the struct page and do:
.rcx = page_to_phys(tdvpr)
Because it's honestly _not_ an address. It really and truly is a page
and you never need to dereference it, only pass it around as a handle.
You could get fancy and make a typedef for it or something, or even
struct tdvpr_struct {
struct page *page;
}
But that's probably overkill. It would help to, for instance, avoid
mixing up these two pages:
+u64 tdh_vp_create(u64 tdr, u64 tdvpr);
But it wouldn't help as much for these:
+u64 tdh_vp_addcx(u64 tdvpr, u64 tdcx);
+u64 tdh_vp_init(u64 tdvpr, u64 initial_rcx);
+u64 tdh_vp_init_apicid(u64 tdvpr, u64 initial_rcx, u32 x2apicid);
+u64 tdh_vp_flush(u64 tdvpr);
+u64 tdh_vp_rd(u64 tdvpr, u64 field, u64 *data);
+u64 tdh_vp_wr(u64 tdvpr, u64 field, u64 data, u64 mask);
Except for (for instance) 'tdr' vs. 'tdvpr' confusion. Spot the bug:
tdh_vp_flush(kvm_tdx(foo)->tdr_pa);
tdh_vp_flush(kvm_tdx(foo)->tdrvp_pa);
Do you want the compiler's help for those?