'tdx-guest' object supports a "quote-generation-socket" property for
attestation purpose. When "quote-generation-socket" is configured in
guest xml, libvirt generates unix socket format cmdline for QEMU.

'Path' element can be omitted, default path "/var/run/tdx-qgs/qgs.socket"
is used in this case.

QEMU command line example:
  qemu-system-x86_64 \
    -object 
'{"qom-type":"tdx-guest","id":"lsec0","mrconfigid":"xxx","mrowner":"xxx","mrownerconfig":"xxx","quote-generation-socket":{"type":"unix","path":"/var/run/tdx-qgs/qgs.socket"},"attributes":268435457}'
 \
    -machine pc-q35-6.0,confidential-guest-support=lsec0

Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com>
---
 src/conf/domain_conf.h  |  3 +++
 src/qemu/qemu_command.c | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index cf5437f642..b89162df42 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2999,6 +2999,9 @@ struct _virDomainSEVSNPDef {
 };
 
 
+/* Copied from QGS source code */
+#define QGS_UNIX_SOCKET_FILE   "/var/run/tdx-qgs/qgs.socket"
+
 struct _virDomainTDXDef {
     bool havePolicy;
     unsigned long long policy;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3081636c24..dc1b9c0029 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9948,15 +9948,29 @@ qemuBuildPVCommandLine(virCommand *cmd)
 static int
 qemuBuildTDXCommandLine(virCommand *cmd, virDomainTDXDef *tdx)
 {
+    g_autoptr(virJSONValue) addr = NULL;
     g_autoptr(virJSONValue) props = NULL;
+    const char *path = QGS_UNIX_SOCKET_FILE;
 
     if (tdx->havePolicy)
         VIR_DEBUG("policy=0x%llx", tdx->policy);
 
+    if (tdx->haveQGS) {
+        if (tdx->qgs_unix_path)
+            path = tdx->qgs_unix_path;
+
+        if (virJSONValueObjectAdd(&addr,
+                                  "s:type", "unix",
+                                  "s:path", path,
+                                  NULL) < 0)
+            return -1;
+    }
+
     if (qemuMonitorCreateObjectProps(&props, "tdx-guest", "lsec0",
                                      "S:mrconfigid", tdx->mrconfigid,
                                      "S:mrowner", tdx->mrowner,
                                      "S:mrownerconfig", tdx->mrownerconfig,
+                                     "A:quote-generation-socket", &addr,
                                      NULL) < 0)
         return -1;
 
-- 
2.34.1

Reply via email to