[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] xen-detect: make CPUID fallback CPUID-faulting aware



commit 7b36d16d21ae70a1eaabe577b7e4b42ed0f1a7d1
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Oct 20 08:53:53 2020 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Oct 20 08:53:53 2020 +0200

    xen-detect: make CPUID fallback CPUID-faulting aware
    
    Relying on presence / absence of hypervisor leaves in raw / escaped
    CPUID output cannot be used to tell apart PV and HVM on CPUID faulting
    capable hardware. Utilize a PV-only feature flag to avoid false positive
    HVM detection.
    
    While at it also short circuit the main detection loop: For PV, only
    the base group of leaves can possibly hold hypervisor information.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Wei Liu <wl@xxxxxxx>
---
 tools/misc/xen-detect.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tools/misc/xen-detect.c b/tools/misc/xen-detect.c
index fd187a4be6..eac9e46a35 100644
--- a/tools/misc/xen-detect.c
+++ b/tools/misc/xen-detect.c
@@ -83,11 +83,31 @@ static int check_for_xen(int pv_context)
 
         if ( !strcmp("XenVMMXenVMM", signature) && (regs[0] >= (base + 2)) )
             goto found;
+
+        /* Higher base addresses are possible only with HVM. */
+        if ( pv_context )
+            break;
     }
 
     return 0;
 
  found:
+    /*
+     * On CPUID faulting capable hardware even un-escaped CPUID will return
+     * the hypervisor leaves. Need to further distinguish modes.
+     */
+    if ( !pv_context )
+    {
+        /*
+         * XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD is a PV-only feature
+         * pre-dating CPUID faulting support in Xen. Hence we can use it to
+         * tell whether we shouldn't report "success" to our caller here.
+         */
+        cpuid(base + 2, regs, 0);
+        if ( regs[2] & (1u << 0) )
+            return 0;
+    }
+
     cpuid(base + 1, regs, pv_context);
     if ( regs[0] )
     {
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.