Re: [PATCH v2 10/25] x86/virt/tdx: Add SEAMCALL wrappers for TDX flush operations
From: Edgecombe, Rick P
Date: Wed Nov 13 2024 - 16:48:42 EST
On Wed, 2024-11-13 at 13:41 -0800, Dave Hansen wrote:
> 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.
That is a really good point.
> 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?
Haha, we have already had bugs around these names actually. If we we end up with
the current arch/x86 based approach we can see if we can fit it in.