Re: [PATCH 21/25] KVM: x86: Introduce KVM_TDX_GET_CPUID

From: Paolo Bonzini
Date: Tue Sep 10 2024 - 13:37:45 EST


On 9/3/24 08:21, Tony Lindgren wrote:
On Mon, Aug 19, 2024 at 10:59:49AM +0800, Tao Su wrote:
On Mon, Aug 12, 2024 at 03:48:16PM -0700, Rick Edgecombe wrote:
From: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
+ /*
+ * Work around missing support on old TDX modules, fetch
+ * guest maxpa from gfn_direct_bits.
+ */
+ if (output_e->function == 0x80000008) {
+ gpa_t gpa_bits = gfn_to_gpa(kvm_gfn_direct_bits(vcpu->kvm));
+ unsigned int g_maxpa = __ffs(gpa_bits) + 1;
+
+ output_e->eax &= ~0x00ff0000;
+ output_e->eax |= g_maxpa << 16;
+ }

I suggest putting all guest_phys_bits related WA in a WA-only patch, which will
be clearer.

The 80000008 workaround needs to be tidied up for sure, it's hard to follow.

I think it's okay if you just add a separate tdx_get_guest_phys_addr_bits(struct kvm *kvm).

--- a/arch/x86/kvm/vmx/tdx.h
+++ b/arch/x86/kvm/vmx/tdx.h
@@ -25,6 +25,11 @@ struct kvm_tdx {
bool finalized;
u64 tsc_offset;
+
+ /* For KVM_MAP_MEMORY and KVM_TDX_INIT_MEM_REGION. */
+ atomic64_t nr_premapped;

I don't see it is used in this patch set.

Yes that should have been in a later patch.

Yes, it's used in the MMU prep part 2 series.

Paolo