]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: Secure guest check for Intel in virt-host-validate
authorZhenzhong Duan <zhenzhong.duan@intel.com>
Thu, 10 Jul 2025 07:21:03 +0000 (03:21 -0400)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 25 Jul 2025 10:27:43 +0000 (11:27 +0100)
Add check in virt-host-validate for secure guest support
on x86 for Intel Trust Domain Extentions.

Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
tools/virt-host-validate-common.c
tools/virt-host-validate-common.h

index 63cc3dbe7b3bef96927b3d088fdabe82a31cac98..59f6ac3319481a5d18372a77d2bde86d63096da4 100644 (file)
@@ -44,7 +44,8 @@ VIR_ENUM_IMPL(virHostValidateCPUFlag,
               "svm",
               "sie",
               "158",
-              "sev");
+              "sev",
+              "tdx_host_platform");
 
 
 int virHostValidateDeviceExists(const char *hvname,
@@ -434,12 +435,36 @@ virHostValidateAMDSev(const char *hvname,
 }
 
 
+static int virHostValidateIntelTDX(virValidateLevel level)
+{
+    g_autofree char *mod_value = NULL;
+
+    if (virFileReadValueString(&mod_value, "/sys/module/kvm_intel/parameters/tdx") < 0) {
+        virValidateFail(level, "Intel Trust Domain Extentions not "
+                               "supported by the currently used kernel");
+        return VIR_VALIDATE_FAILURE(level);
+    }
+
+    if (mod_value[0] != 'Y') {
+        virValidateFail(level,
+                        "Intel Trust Domain Extentions appears to be "
+                        "disabled in kernel. Add kvm_intel.tdx=Y "
+                        "to the kernel cmdline arguments");
+        return VIR_VALIDATE_FAILURE(level);
+    }
+
+    virValidatePass();
+    return 1;
+}
+
+
 int virHostValidateSecureGuests(const char *hvname,
                                 virValidateLevel level)
 {
     g_autoptr(virBitmap) flags = NULL;
     bool hasFac158 = false;
     bool hasAMDSev = false;
+    bool hasIntelTDX = false;
     virArch arch = virArchFromHost();
     g_autofree char *cmdline = NULL;
     static const char *kIBMValues[] = {"y", "Y", "on", "ON", "oN", "On", "1"};
@@ -450,6 +475,8 @@ int virHostValidateSecureGuests(const char *hvname,
         hasFac158 = true;
     else if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SEV))
         hasAMDSev = true;
+    else if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_TDX))
+        hasIntelTDX = true;
 
     virValidateCheck(hvname, "%s", _("Checking for secure guest support"));
     if (ARCH_IS_S390(arch)) {
@@ -485,6 +512,8 @@ int virHostValidateSecureGuests(const char *hvname,
         }
     } else if (hasAMDSev) {
         return virHostValidateAMDSev(hvname, level);
+    } else if (hasIntelTDX) {
+        return virHostValidateIntelTDX(level);
     }
 
     virValidateFail(level,
index 7fb3545fe3b4734d18a7727439834330cf4bf003..c81d203933ee71fa634e96497ed94c1b20715aaa 100644 (file)
@@ -32,6 +32,7 @@ typedef enum {
     VIR_HOST_VALIDATE_CPU_FLAG_SIE,
     VIR_HOST_VALIDATE_CPU_FLAG_FACILITY_158,
     VIR_HOST_VALIDATE_CPU_FLAG_SEV,
+    VIR_HOST_VALIDATE_CPU_FLAG_TDX,
 
     VIR_HOST_VALIDATE_CPU_FLAG_LAST,
 } virHostValidateCPUFlag;