x86/acrn: Introduce acrn_cpuid_base() and hypervisor feature bits
authorYin Fengwei <fengwei.yin@intel.com>
Sun, 7 Feb 2021 03:10:25 +0000 (11:10 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 9 Feb 2021 09:58:18 +0000 (10:58 +0100)
ACRN Hypervisor reports hypervisor features via CPUID leaf 0x40000001
which is similar to KVM. A VM can check if it's the privileged VM using
the feature bits. The Service VM is the only privileged VM by design.

Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Fengwei Yin <fengwei.yin@intel.com>
Cc: Zhi Wang <zhi.a.wang@intel.com>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Yu Wang <yu1.wang@intel.com>
Cc: Reinette Chatre <reinette.chatre@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Acked-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Signed-off-by: Shuo Liu <shuo.a.liu@intel.com>
Link: https://lore.kernel.org/r/20210207031040.49576-4-shuo.a.liu@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/include/asm/acrn.h
arch/x86/kernel/cpu/acrn.c

index ff259b69cde79266bf614951bcdbb670f650e8ee..127f20672c5d36e5e411c1cf700c690aa15ec527 100644 (file)
@@ -2,7 +2,23 @@
 #ifndef _ASM_X86_ACRN_H
 #define _ASM_X86_ACRN_H
 
+/*
+ * This CPUID returns feature bitmaps in EAX.
+ * Guest VM uses this to detect the appropriate feature bit.
+ */
+#define        ACRN_CPUID_FEATURES             0x40000001
+/* Bit 0 indicates whether guest VM is privileged */
+#define        ACRN_FEATURE_PRIVILEGED_VM      BIT(0)
+
 void acrn_setup_intr_handler(void (*handler)(void));
 void acrn_remove_intr_handler(void);
 
+static inline u32 acrn_cpuid_base(void)
+{
+       if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
+               return hypervisor_cpuid_base("ACRNACRNACRN", 0);
+
+       return 0;
+}
+
 #endif /* _ASM_X86_ACRN_H */
index e0c1817819057d17e65aa4932e0b4a02f9fc6a76..23f5f27b5a024865054b19b43c766c3f6afa8bfa 100644 (file)
@@ -21,7 +21,7 @@
 
 static u32 __init acrn_detect(void)
 {
-       return hypervisor_cpuid_base("ACRNACRNACRN", 0);
+       return acrn_cpuid_base();
 }
 
 static void __init acrn_init_platform(void)