Re: [PATCH v2 16/25] KVM: TDX: Get system-wide info about TDX module on initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/31/2024 5:09 PM, Binbin Wu wrote:



On 10/31/2024 3:00 AM, Rick Edgecombe wrote:
[...]
+static u32 tdx_set_guest_phys_addr_bits(const u32 eax, int addr_bits)
+{
+    return (eax & ~GENMASK(23, 16)) | (addr_bits & 0xff) << 16;
+}
+
+#define KVM_TDX_CPUID_NO_SUBLEAF    ((__u32)-1)
+
+static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char idx)
+{
+    const struct tdx_sys_info_td_conf *td_conf = &tdx_sysinfo->td_conf;
+
+    entry->function = (u32)td_conf->cpuid_config_leaves[idx];
+    entry->index = td_conf->cpuid_config_leaves[idx] >> 32;
+    entry->eax = (u32)td_conf->cpuid_config_values[idx][0];
+    entry->ebx = td_conf->cpuid_config_values[idx][0] >> 32;
+    entry->ecx = (u32)td_conf->cpuid_config_values[idx][1];
+    entry->edx = td_conf->cpuid_config_values[idx][1] >> 32;
+
+    if (entry->index == KVM_TDX_CPUID_NO_SUBLEAF)
+        entry->index = 0;
+
+    /* Work around missing support on old TDX modules */
+    if (entry->function == 0x80000008)
+        entry->eax = tdx_set_guest_phys_addr_bits(entry->eax, 0xff);
Is it necessary to set bit 16~23 to 0xff?
It seems that when userspace wants to retrieve the value, the GPAW will
be set in tdx_read_cpuid() anyway.

here it is to initialize the configurable CPUID bits that get reported to userspace. Though TDX module doesn't allow them to be set in TD_PARAM for KVM_TDX_INIT_VM, they get set to 0xff because KVM reuse these bits EBX[23:16] as the interface for userspace to configure GPAW of TD guest (implemented in setup_tdparams_eptp_controls() in patch 19). That's why they need to be set as all-1 to allow userspace to configure.

And the comment above it is wrong and vague. we need to change it to something like

	/*
         * Though TDX module doesn't allow the configuration of guest
         * phys addr bits (EBX[23:16]), KVM uses it as the interface for
         * userspace to configure the GPAW. So need to report these bits
         * as configurable to userspace.
         */
+}
+

[...]





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux