'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 | 25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 93f8d0f960..86b7da6f45 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2991,6 +2991,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 7d75a53345..92e6779f18 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9789,18 +9789,43 @@ qemuBuildPVCommandLine(virCommand *cmd)
 }
 
 
+static virJSONValue *
+qemuBuildTDXQGSCommandLine(virDomainTDXDef *tdx)
+{
+    g_autoptr(virJSONValue) addr = NULL;
+    const char *path;
+
+    if (!tdx->haveQGS)
+        return NULL;
+
+    path = tdx->qgs_unix_path ? : QGS_UNIX_SOCKET_FILE;
+
+    if (virJSONValueObjectAdd(&addr,
+                              "s:type", "unix",
+                              "s:path", path,
+                              NULL) < 0)
+        return NULL;
+
+    return g_steal_pointer(&addr);
+}
+
+
 static int
 qemuBuildTDXCommandLine(virCommand *cmd, virDomainTDXDef *tdx)
 {
+    g_autoptr(virJSONValue) addr = NULL;
     g_autoptr(virJSONValue) props = NULL;
 
     if (tdx->havePolicy)
         VIR_DEBUG("policy=0x%llx", tdx->policy);
 
+    addr = qemuBuildTDXQGSCommandLine(tdx);
+
     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