xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen-detect: make CPUID fallback CPUID-faulting aware
@ 2020-10-14 15:23 Jan Beulich
  2020-10-14 15:46 ` Wei Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2020-10-14 15:23 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Andrew Cooper, Wei Liu, Roger Pau Monné

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@suse.com>

--- 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] )
     {


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] xen-detect: make CPUID fallback CPUID-faulting aware
  2020-10-14 15:23 [PATCH] xen-detect: make CPUID fallback CPUID-faulting aware Jan Beulich
@ 2020-10-14 15:46 ` Wei Liu
  0 siblings, 0 replies; 2+ messages in thread
From: Wei Liu @ 2020-10-14 15:46 UTC (permalink / raw)
  To: Jan Beulich
  Cc: xen-devel, Ian Jackson, Andrew Cooper, Wei Liu, Roger Pau Monné

On Wed, Oct 14, 2020 at 05:23:23PM +0200, Jan Beulich wrote:
> 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@suse.com>

Acked-by: Wei Liu <wl@xen.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-14 15:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 15:23 [PATCH] xen-detect: make CPUID fallback CPUID-faulting aware Jan Beulich
2020-10-14 15:46 ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).