Skip to contentSkip to conversation

i386/tdx: Fix the report of gpa in QAPI

PATCH Applied Zhenzhong Duan 4 participants 8 messages Jul 10, 2025 x86 trust domain extensions (TDX)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i386/tdx: Fix the report of gpa in QAPI

Gpa is defined in QAPI but never reported to monitor because has_gpa is never set to ture.

Fix it by setting has_gpa to ture when TDX_REPORT_FATAL_ERROR_GPA_VALID is set in error_code.

Fixes 6e250463b08b ("i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility")
---
 target/i386/kvm/tdx.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
target/i386/kvm/tdx.c +6 -2
index e809e4b2df..370a9b6e65 100644
@@ -1269,7 +1269,8 @@ void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run)
 }
 
 static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code,
-                                        char *message, uint64_t gpa)
+                                        char *message, bool has_gpa,
+                                        uint64_t gpa)
 {
     GuestPanicInformation *panic_info;
 
@@ -1278,6 +1279,7 @@ static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code,
     panic_info->u.tdx.error_code = (uint32_t) error_code;
     panic_info->u.tdx.message = message;
     panic_info->u.tdx.gpa = gpa;
+    panic_info->u.tdx.has_gpa = has_gpa;
 
     qemu_system_guest_panicked(panic_info);
 }
@@ -1297,6 +1299,7 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run)
     char *message = NULL;
     uint64_t *tmp;
     uint64_t gpa = -1ull;
+    bool has_gpa = false;
 
     if (error_code & 0xffff) {
         error_report("TDX: REPORT_FATAL_ERROR: invalid error code: 0x%"PRIx64,
@@ -1329,9 +1332,10 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run)
 
     if (error_code & TDX_REPORT_FATAL_ERROR_GPA_VALID) {
         gpa = run->system_event.data[R_R13];
+        has_gpa = true;
     }
 
-    tdx_panicked_on_fatal_error(cpu, error_code, message, gpa);
+    tdx_panicked_on_fatal_error(cpu, error_code, message, has_gpa, gpa);
 
     return -1;
 }
Signature · 1 line
2.47.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Zhenzhong Duan

Gpa is defined in QAPI but never reported to monitor because has_gpa is never set to ture.

Fix it by setting has_gpa to ture when TDX_REPORT_FATAL_ERROR_GPA_VALID is set in error_code.

Fixes 6e250463b08b ("i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility")
---
 target/i386/kvm/tdx.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 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 :|
#3 lore raw
In reply to Zhenzhong Duan
Quoted 5 lines · Zhenzhong Duan

Gpa is defined in QAPI but never reported to monitor because has_gpa is never set to ture.

Fix it by setting has_gpa to ture when TDX_REPORT_FATAL_ERROR_GPA_VALID is set in error_code.

Hi Zhenzhong,

I would like to understand what the problem is without panic_info->u.tdx.has_gpa being set?

Quoted 48 lines
Fixes 6e250463b08b ("i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility")
---
  target/i386/kvm/tdx.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
target/i386/kvm/tdx.c +6 -2
index e809e4b2df..370a9b6e65 100644
@@ -1269,7 +1269,8 @@ void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run)
  }
 
  static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code,
-                                        char *message, uint64_t gpa)
+                                        char *message, bool has_gpa,
+                                        uint64_t gpa)
  {
      GuestPanicInformation *panic_info;
 
@@ -1278,6 +1279,7 @@ static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code,
      panic_info->u.tdx.error_code = (uint32_t) error_code;
      panic_info->u.tdx.message = message;
      panic_info->u.tdx.gpa = gpa;
+    panic_info->u.tdx.has_gpa = has_gpa;
 
      qemu_system_guest_panicked(panic_info);
  }
@@ -1297,6 +1299,7 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run)
      char *message = NULL;
      uint64_t *tmp;
      uint64_t gpa = -1ull;
+    bool has_gpa = false;
 
      if (error_code & 0xffff) {
          error_report("TDX: REPORT_FATAL_ERROR: invalid error code: 0x%"PRIx64,
@@ -1329,9 +1332,10 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run)
 
      if (error_code & TDX_REPORT_FATAL_ERROR_GPA_VALID) {
          gpa = run->system_event.data[R_R13];
+        has_gpa = true;
      }
 
-    tdx_panicked_on_fatal_error(cpu, error_code, message, gpa);
+    tdx_panicked_on_fatal_error(cpu, error_code, message, has_gpa, gpa);
 
      return -1;
  }
#4 lore raw
Quoted 11 lines · Xiaoyao Li
Quoted 5 lines · Zhenzhong Duan

Gpa is defined in QAPI but never reported to monitor because has_gpa is never set to ture.

Fix it by setting has_gpa to ture when TDX_REPORT_FATAL_ERROR_GPA_VALID is set in error_code.

Hi Zhenzhong,

I would like to understand what the problem is without panic_info-

Quoted 1 line

u.tdx.has_gpa being set?

Never mind, I figure it out.

qapi_event_send_guest_panicked() in qemu_system_guest_panicked will send the event and data. Libvirt tries to parse the data, but find the .has_data field is not set correctly.

My original patch used (gpa == -1) as the indicator for whether gpa is valid, this needs to be cleaned up. I will send the cleanup patch.

#5 lore raw
Quoted 10 lines · Xiaoyao Li
Quoted 9 lines · Xiaoyao Li
Quoted 5 lines · Zhenzhong Duan

Gpa is defined in QAPI but never reported to monitor because has_gpa is never set to ture.

Fix it by setting has_gpa to ture when TDX_REPORT_FATAL_ERROR_GPA_VALID is set in error_code.

Hi Zhenzhong,

Quoted 8 lines
Quoted 2 lines

I would like to understand what the problem is without panic_info-

Quoted 1 line

u.tdx.has_gpa being set?

Never mind, I figure it out.

qapi_event_send_guest_panicked() in qemu_system_guest_panicked will send the event and data. Libvirt tries to parse the data, but find the .has_data field is not set correctly.

Close, but not quite.

The "has_" fields are only present in the QEMU internal data structures, never on the wire in the JSON messages that libvirt receives.

The problem is with QEMU's struct -> JSON serialization - if the 'has_gpa' field is not set to 'true', then QEMU will *never* emit the 'gpa' field in the JSON it sends to the client app.

So what libvirt receives is this:

{"timestamp": {"seconds": 1752156518, "microseconds": 809325},
"event": "GUEST_PANICKED",

  "data": {"action": "pause", "info": {
      "error-code": 0,
      "message": "TD misconfiguration: SEPT #VE has to be disabled",
      "type": "tdx"}}}

which has no 'gpa' present.

Quoted 2 lines

My original patch used (gpa == -1) as the indicator for whether gpa is valid, this needs to be cleaned up. I will send the cleanup patch.

The value you assign to 'gpa' doesn't matter when 'has_gpa' is false, as it'll never get into the JSON event, so having it be '-1' is not significantly different from leaving it on 0.

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 :|
#6 lore raw
Quoted 31 lines · Daniel P. Berrangé
Quoted 10 lines · Xiaoyao Li
Quoted 9 lines · Xiaoyao Li
Quoted 5 lines · Zhenzhong Duan

Gpa is defined in QAPI but never reported to monitor because has_gpa is never set to ture.

Fix it by setting has_gpa to ture when TDX_REPORT_FATAL_ERROR_GPA_VALID is set in error_code.

Hi Zhenzhong,

Quoted 8 lines
Quoted 2 lines

I would like to understand what the problem is without panic_info-

Quoted 1 line

u.tdx.has_gpa being set?

Never mind, I figure it out.

qapi_event_send_guest_panicked() in qemu_system_guest_panicked will send the event and data. Libvirt tries to parse the data, but find the .has_data field is not set correctly.

Close, but not quite.

The "has_" fields are only present in the QEMU internal data structures, never on the wire in the JSON messages that libvirt receives.

The problem is with QEMU's struct -> JSON serialization - if the 'has_gpa' field is not set to 'true', then QEMU will *never* emit the 'gpa' field in the JSON it sends to the client app.

So what libvirt receives is this:

Quoted 8 lines

{"timestamp": {"seconds": 1752156518, "microseconds": 809325},
"event": "GUEST_PANICKED",

   "data": {"action": "pause", "info": {
       "error-code": 0,
       "message": "TD misconfiguration: SEPT #VE has to be disabled",
       "type": "tdx"}}}

which has no 'gpa' present.

Thanks for the explanation! It's much clear to me now!

Quoted 6 lines
Quoted 2 lines

My original patch used (gpa == -1) as the indicator for whether gpa is valid, this needs to be cleaned up. I will send the cleanup patch.

The value you assign to 'gpa' doesn't matter when 'has_gpa' is false, as it'll never get into the JSON event, so having it be '-1' is not significantly different from leaving it on 0.

I meant cleanup the QEMU internal logic in qemu_system_guest_panicked()

system/runstate.c +0 -0
@@ -690,7 +690,7 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
                           " error code: 0x%" PRIx32 " error 

message:\"%s\"\n",

                           info->u.tdx.error_code, message);
             g_free(message);

- if (info->u.tdx.gpa != -1ull) {
+ if (info->u.tdx.has_gpa) {
qemu_log_mask(LOG_GUEST_ERROR, "Additional error
information "

                               "can be found at gpa page: 0x%" PRIx64 "\n",
                               info->u.tdx.gpa);
Quoted 2 lines

With regards,
Daniel

#7 lore raw
Quoted 23 lines · Xiaoyao Li
Quoted 7 lines · Daniel P. Berrangé
Quoted 2 lines · Xiaoyao Li

My original patch used (gpa == -1) as the indicator for whether gpa is valid, this needs to be cleaned up. I will send the cleanup patch.

The value you assign to 'gpa' doesn't matter when 'has_gpa' is false, as it'll never get into the JSON event, so having it be '-1' is not significantly different from leaving it on 0.

I meant cleanup the QEMU internal logic in qemu_system_guest_panicked()

system/runstate.c +1 -1
@@ -690,7 +690,7 @@ void qemu_system_guest_panicked(GuestPanicInformation
 *info)
                           " error code: 0x%" PRIx32 " error
 message:\"%s\"\n",
                           info->u.tdx.error_code, message);
             g_free(message);
-            if (info->u.tdx.gpa != -1ull) {
+            if (info->u.tdx.has_gpa) {
                 qemu_log_mask(LOG_GUEST_ERROR, "Additional error

information "

Quoted 2 lines
                               "can be found at gpa page: 0x%" PRIx64 "\n",
                               info->u.tdx.gpa);

Yes, that would be better

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 :|