Skip to contentSkip to conversation

TDX: Fix and enhancement

PATCH Applied Xiaoyao Li 5 participants 14 messages Jun 3, 2025 – Jun 17, 2025 x86 trust domain extensions (TDX)

lore
Share & tools
lore

Xiaoyao Li

author
#0 lore raw

cover TDX: Fix and enhancement

Patch 1 and patch 3 are the left review feedback of TDX QEMU v9 series.

Patch 2 is caught during preparing patch 3.

Xiaoyao Li (3):
i386/cpu: Rename enable_cpuid_0x1f to force_cpuid_0x1f i386/tdx: Fix the typo of the comment of struct TdxGuest i386/tdx: Clarify the error message of
mrconfigid/mrowner/mrownerconfig

 target/i386/cpu.h     |  4 ++--
 target/i386/kvm/tdx.c | 14 ++++++++++----
 target/i386/kvm/tdx.h |  6 +++---
 3 files changed, 15 insertions(+), 9 deletions(-)

base-commit: 6322b753f798337835e205b6d805356bea582c86

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/3 i386/cpu: Rename enable_cpuid_0x1f to force_cpuid_0x1f

The name of "enable_cpuid_0x1f" isn't right to its behavior because the leaf 0x1f can be enabled even when "enable_cpuid_0x1f" is false.

Rename it to "force_cpuid_0x1f" to better reflect its behavior.

---
Suggested by Igor at https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/cpu.h     | 4 ++--
 target/i386/kvm/tdx.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
target/i386/cpu.h +2 -2
index 1146465c8c62..aaef6a2a6767 100644
@@ -2270,7 +2270,7 @@ struct ArchCPU {
     bool enable_cpuid_0xb;
 
     /* Force to enable cpuid 0x1f */
-    bool enable_cpuid_0x1f;
+    bool force_cpuid_0x1f;
 
     /* Enable auto level-increase for all CPUID leaves */
     bool full_cpuid_auto_level;
@@ -2540,7 +2540,7 @@ void mark_forced_on_features(X86CPU *cpu, FeatureWord w, uint64_t mask,
 
 static inline bool x86_has_cpuid_0x1f(X86CPU *cpu)
 {
-    return cpu->enable_cpuid_0x1f ||
+    return cpu->force_cpuid_0x1f ||
            x86_has_extended_topo(cpu->env.avail_cpu_topo);
 }
 
target/i386/kvm/tdx.c +1 -1
index 0a21ae555c5c..17e671f1710f 100644
@@ -746,7 +746,7 @@ static void tdx_cpu_instance_init(X86ConfidentialGuest *cg, CPUState *cpu)
     /* invtsc is fixed1 for TD guest */
     object_property_set_bool(OBJECT(cpu), "invtsc", true, &error_abort);
 
-    x86cpu->enable_cpuid_0x1f = true;
+    x86cpu->force_cpuid_0x1f = true;
 }
 
 static uint32_t tdx_adjust_cpuid_features(X86ConfidentialGuest *cg,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] i386/cpu: Rename enable_cpuid_0x1f to force_cpuid_0x1f

Quoted 5 lines · Xiaoyao Li

The name of "enable_cpuid_0x1f" isn't right to its behavior because the leaf 0x1f can be enabled even when "enable_cpuid_0x1f" is false.

Rename it to "force_cpuid_0x1f" to better reflect its behavior.

Quoted 8 lines

---
Suggested by Igor at https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/cpu.h     | 4 ++--
 target/i386/kvm/tdx.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] i386/cpu: Rename enable_cpuid_0x1f to force_cpuid_0x1f

In reply to Xiaoyao Li
Quoted 7 lines · On Tue, 3 Jun 2025 01:03:03 -0400 Xiaoyao Li <[email protected]> wrote:

The name of "enable_cpuid_0x1f" isn't right to its behavior because the leaf 0x1f can be enabled even when "enable_cpuid_0x1f" is false.

Rename it to "force_cpuid_0x1f" to better reflect its behavior.

Quoted 42 lines

---
Suggested by Igor at https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/cpu.h     | 4 ++--
 target/i386/kvm/tdx.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
target/i386/cpu.h +2 -2
index 1146465c8c62..aaef6a2a6767 100644
@@ -2270,7 +2270,7 @@ struct ArchCPU {
     bool enable_cpuid_0xb;
 
     /* Force to enable cpuid 0x1f */
-    bool enable_cpuid_0x1f;
+    bool force_cpuid_0x1f;
 
     /* Enable auto level-increase for all CPUID leaves */
     bool full_cpuid_auto_level;
@@ -2540,7 +2540,7 @@ void mark_forced_on_features(X86CPU *cpu, FeatureWord w, uint64_t mask,
 
 static inline bool x86_has_cpuid_0x1f(X86CPU *cpu)
 {
-    return cpu->enable_cpuid_0x1f ||
+    return cpu->force_cpuid_0x1f ||
            x86_has_extended_topo(cpu->env.avail_cpu_topo);
 }
 
target/i386/kvm/tdx.c +1 -1
index 0a21ae555c5c..17e671f1710f 100644
@@ -746,7 +746,7 @@ static void tdx_cpu_instance_init(X86ConfidentialGuest *cg, CPUState *cpu)
     /* invtsc is fixed1 for TD guest */
     object_property_set_bool(OBJECT(cpu), "invtsc", true, &error_abort);
 
-    x86cpu->enable_cpuid_0x1f = true;
+    x86cpu->force_cpuid_0x1f = true;
 }
 
 static uint32_t tdx_adjust_cpuid_features(X86ConfidentialGuest *cg,
Reviewed-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] i386/cpu: Rename enable_cpuid_0x1f to force_cpuid_0x1f

In reply to Xiaoyao Li
Quoted 10 lines · Xiaoyao Li

Date: Tue, 3 Jun 2025 01:03:03 -0400
From: Xiaoyao Li <[email protected]>
Subject: [PATCH 1/3] i386/cpu: Rename enable_cpuid_0x1f to force_cpuid_0x1f
X-Mailer: git-send-email 2.43.0

The name of "enable_cpuid_0x1f" isn't right to its behavior because the leaf 0x1f can be enabled even when "enable_cpuid_0x1f" is false.

Rename it to "force_cpuid_0x1f" to better reflect its behavior.

Quoted 8 lines

---
Suggested by Igor at https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/cpu.h     | 4 ++--
 target/i386/kvm/tdx.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
author
#5 lore raw

PATCH 2/3 i386/tdx: Fix the typo of the comment of struct TdxGuest

In reply to Xiaoyao Li

Change sha348 to sha384.

---
 target/i386/kvm/tdx.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/i386/kvm/tdx.h +3 -3
index 04b5afe199f9..8dd66e90149b 100644
@@ -40,9 +40,9 @@ typedef struct TdxGuest {
     bool initialized;
     uint64_t attributes;    /* TD attributes */
     uint64_t xfam;
-    char *mrconfigid;       /* base64 encoded sha348 digest */
-    char *mrowner;          /* base64 encoded sha348 digest */
-    char *mrownerconfig;    /* base64 encoded sha348 digest */
+    char *mrconfigid;       /* base64 encoded sha384 digest */
+    char *mrowner;          /* base64 encoded sha384 digest */
+    char *mrownerconfig;    /* base64 encoded sha384 digest */
 
     MemoryRegion *tdvf_mr;
     TdxFirmware tdvf;
Signature · 1 line
2.43.0
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] i386/tdx: Fix the typo of the comment of struct TdxGuest

Quoted 6 lines · Xiaoyao Li

Change sha348 to sha384.

---
 target/i386/kvm/tdx.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 2/3
#7 lore raw

Re: [PATCH 2/3] i386/tdx: Fix the typo of the comment of struct TdxGuest

In reply to Xiaoyao Li
Quoted 3 lines · On Tue, 3 Jun 2025 01:03:04 -0400 Xiaoyao Li <[email protected]> wrote:

Change sha348 to sha384.

Quoted 21 lines
---
 target/i386/kvm/tdx.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/i386/kvm/tdx.h +3 -3
index 04b5afe199f9..8dd66e90149b 100644
@@ -40,9 +40,9 @@ typedef struct TdxGuest {
     bool initialized;
     uint64_t attributes;    /* TD attributes */
     uint64_t xfam;
-    char *mrconfigid;       /* base64 encoded sha348 digest */
-    char *mrowner;          /* base64 encoded sha348 digest */
-    char *mrownerconfig;    /* base64 encoded sha348 digest */
+    char *mrconfigid;       /* base64 encoded sha384 digest */
+    char *mrowner;          /* base64 encoded sha384 digest */
+    char *mrownerconfig;    /* base64 encoded sha384 digest */
 
     MemoryRegion *tdvf_mr;
     TdxFirmware tdvf;
Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH 2/3] i386/tdx: Fix the typo of the comment of struct TdxGuest

In reply to Xiaoyao Li
Quoted 6 lines · Xiaoyao Li

Date: Tue, 3 Jun 2025 01:03:04 -0400
From: Xiaoyao Li <[email protected]>
Subject: [PATCH 2/3] i386/tdx: Fix the typo of the comment of struct
TdxGuest
X-Mailer: git-send-email 2.43.0

Quoted 6 lines

Change sha348 to sha384.

---
 target/i386/kvm/tdx.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
author
#9 lore raw

PATCH 3/3 i386/tdx: Clarify the error message of mrconfigid/mrowner/mrownerconfig

In reply to Xiaoyao Li

The error message is misleading - we successfully decoded the data, the decoded data was simply with the wrong length.

Change the error message to show it is an length check failure with both the received and expected values.

---
Suggested by Daniel at https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/kvm/tdx.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
target/i386/kvm/tdx.c +9 -3
index 17e671f1710f..4172bbd23340 100644
@@ -1026,7 +1026,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrconfigid");
+            error_setg(errp, "TDX 'mrconfigid' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrconfigid, data, data_len);
@@ -1039,7 +1041,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrowner");
+            error_setg(errp, "TDX 'mrowner' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrowner, data, data_len);
@@ -1052,7 +1056,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrownerconfig");
+            error_setg(errp, "TDX 'mrownerconfig' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrownerconfig, data, data_len);
Signature · 1 line
2.43.0
Reviewed-by on v1 3/3
#10 lore raw

Re: [PATCH 3/3] i386/tdx: Clarify the error message of mrconfigid/mrowner/mrownerconfig

Quoted 6 lines · Xiaoyao Li

The error message is misleading - we successfully decoded the data, the decoded data was simply with the wrong length.

Change the error message to show it is an length check failure with both the received and expected values.

Quoted 7 lines

---
Suggested by Daniel at https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/kvm/tdx.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 3/3
#11 lore raw

Re: [PATCH 3/3] i386/tdx: Clarify the error message of mrconfigid/mrowner/mrownerconfig

In reply to Xiaoyao Li
Quoted 8 lines · On Tue, 3 Jun 2025 01:03:05 -0400 Xiaoyao Li <[email protected]> wrote:

The error message is misleading - we successfully decoded the data, the decoded data was simply with the wrong length.

Change the error message to show it is an length check failure with both the received and expected values.

Quoted 43 lines

---
Suggested by Daniel at https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/kvm/tdx.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
target/i386/kvm/tdx.c +9 -3
index 17e671f1710f..4172bbd23340 100644
@@ -1026,7 +1026,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrconfigid");
+            error_setg(errp, "TDX 'mrconfigid' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrconfigid, data, data_len);
@@ -1039,7 +1041,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrowner");
+            error_setg(errp, "TDX 'mrowner' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrowner, data, data_len);
@@ -1052,7 +1056,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrownerconfig");
+            error_setg(errp, "TDX 'mrownerconfig' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrownerconfig, data, data_len);
Reviewed-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] i386/tdx: Clarify the error message of mrconfigid/mrowner/mrownerconfig

In reply to Xiaoyao Li
Quoted 12 lines · Xiaoyao Li

Date: Tue, 3 Jun 2025 01:03:05 -0400
From: Xiaoyao Li <[email protected]>
Subject: [PATCH 3/3] i386/tdx: Clarify the error message of
mrconfigid/mrowner/mrownerconfig
X-Mailer: git-send-email 2.43.0

The error message is misleading - we successfully decoded the data, the decoded data was simply with the wrong length.

Change the error message to show it is an length check failure with both the received and expected values.

Quoted 7 lines

---
Suggested by Daniel at https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/kvm/tdx.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)