Skip to contentSkip to conversation

viridian updates

PATCH In review Paul Durrant 2 participants 5 messages Mar 22, 2017

lore
Share & tools
lore
#0 lore raw

v5 cover viridian updates

Paul Durrant (3):
x86/viridian: don't put Xen version information in CPUID leaf 2 x86/viridian: make the threshold for HvNotifyLongSpinWait tunable x86/viridian: implement the crash MSRs

 docs/man/xl.cfg.pod.5.in            |  10 ++-
 docs/misc/xen-command-line.markdown |  16 ++++
 tools/libxl/libxl.h                 |   6 ++
 tools/libxl/libxl_dom.c             |   4 +
 tools/libxl/libxl_types.idl         |   1 +
 xen/arch/x86/hvm/viridian.c         | 141 +++++++++++++++++++++++++++++++++++-
 xen/include/asm-x86/hvm/viridian.h  |   1 +
 xen/include/public/hvm/params.h     |   7 +-
 8 files changed, 180 insertions(+), 6 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v5 1/3 x86/viridian: don't put Xen version information in CPUID leaf 2

The Hypervisor Top Level Functional Specification v5.0a states in section 2.5:

"The hypervisor version information is encoded in leaf 0x40000002. Two version numbers are provided: the main version and the service version. The main version includes a major and minor version number and a build number. These correspond to Microsoft Windows release numbers."

It also goes on to advise clients (i.e. guest versions of Windows) to use the following algorithm to determine compatibility with the hypervisor enlightenments:

if <your-main-version> greater than <hypervisor-main-version>
{
your version is compatible
}
else if <your-main-version> equal to <hypervisor-main-version> and
<your-service-version> greater than or equal to <hypervisor-service-version>
{
your version is compatible
}
else
{
your version is NOT compatible
}

So, clearly putting Xen hypervisor version information in that leaf is spurious, but we probably get away with it because Xen's major version is lower than the major version of Windows in which Hyper-V first appeared (Server 2008).

This patch changes the leaf to use the kernel major and minor versions, and build number from Windows Server 2008 (64-bit) by default. These default values can be overriden from the Xen command line using new 'viridian-version' parameter.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

v5:
- Re-work code as per Jan's suggestion
- Fix label indentation

v4:
- Make elements of viridian-version parameter optional
- Use custom_param()
- Constify a pointer

v3:
- Use a combined version parameter

v2:
- Use full version information (including build number) from Windows Server 2008
- Add command line parameters to allow version information to be overridden

---
 docs/misc/xen-command-line.markdown |  8 ++++++
 xen/arch/x86/hvm/viridian.c         | 56 +++++++++++++++++++++++++++++++++++--
 2 files changed, 62 insertions(+), 2 deletions(-)
docs/misc/xen-command-line.markdown +8 -0
index bad20db..c81d693 100644
@@ -1616,6 +1616,14 @@ The optional `keep` parameter causes Xen to continue using the vga
 console even after dom0 has been started.  The default behaviour is to
 relinquish control to dom0.
 
+### viridian-version
+> `= [<major>],[<minor>],[<build>]`
+
+> Default: `6,0,0x1772`
+
+<major>, <minor> and <build> must be integers. The values will be
+encoded in guest CPUID 0x40000002 if viridian enlightenments are enabled.
+
 ### vpid (Intel)
 > `= <boolean>`
 
xen/arch/x86/hvm/viridian.c +54 -2

74 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v5 1/3
#2 lore raw

Re: [PATCH v5 1/3] x86/viridian: don't put Xen version information in CPUID leaf 2

Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 22.03.17 at 16:28, <[email protected]> wrote:

The Hypervisor Top Level Functional Specification v5.0a states in section 2.5:

"The hypervisor version information is encoded in leaf 0x40000002. Two version numbers are provided: the main version and the service version. The main version includes a major and minor version number and a build number. These correspond to Microsoft Windows release numbers."

It also goes on to advise clients (i.e. guest versions of Windows) to use the following algorithm to determine compatibility with the hypervisor enlightenments:

if <your-main-version> greater than <hypervisor-main-version>
{
your version is compatible
}
else if <your-main-version> equal to <hypervisor-main-version> and
<your-service-version> greater than or equal to <hypervisor-service-version>
{
your version is compatible
}
else
{
your version is NOT compatible
}

So, clearly putting Xen hypervisor version information in that leaf is spurious, but we probably get away with it because Xen's major version is lower than the major version of Windows in which Hyper-V first appeared (Server 2008).

Quoted 6 lines

This patch changes the leaf to use the kernel major and minor versions, and build number from Windows Server 2008 (64-bit) by default. These default values can be overriden from the Xen command line using new 'viridian-version' parameter.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

PATCH v5 2/3 x86/viridian: make the threshold for HvNotifyLongSpinWait tunable

In reply to Paul Durrant

The current threshold before the guest issues the hypercall is, and always has been, hard-coded to 2047. It is not clear where this number came from so, to at least allow for ease of experimentation, this patch makes the threshold tunable via the Xen command line.

---
Cc: Andrew Cooper <[email protected]>

v3:
- Use '-' in parameter name rather than '_'

v2:
- Significantly simplify patch by directly initializing the parameter

---
 docs/misc/xen-command-line.markdown |  8 ++++++++
 xen/arch/x86/hvm/viridian.c         | 16 +++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
docs/misc/xen-command-line.markdown +8 -0
index c81d693..bdbdb8a 100644
@@ -1624,6 +1624,14 @@ relinquish control to dom0.
 <major>, <minor> and <build> must be integers. The values will be
 encoded in guest CPUID 0x40000002 if viridian enlightenments are enabled.
 
+### viridian-spinlock-retry-count
+> `= <integer>`
+
+> Default: `2047`
+
+Specify the maximum number of retries before an enlightened Windows
+guest will notify Xen that it has failed to acquire a spinlock.
+
 ### vpid (Intel)
 > `= <boolean>`
 
xen/arch/x86/hvm/viridian.c +15 -1
index d59294f..4c65ddc 100644
@@ -174,6 +174,14 @@ static uint16_t __read_mostly viridian_major = 6;
 static uint16_t __read_mostly viridian_minor = 0;
 static uint32_t __read_mostly viridian_build = 0x1772;
 
+/*
+ * Maximum number of retries before the guest will notify of failure
+ * to acquire a spinlock.
+ */
+static uint32_t __read_mostly viridian_spinlock_retry_count = 2047;
+integer_param("viridian-spinlock-retry-count",
+              viridian_spinlock_retry_count);
+
 void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
                            uint32_t subleaf, struct cpuid_leaf *res)
 {
@@ -251,7 +259,13 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
             res->a |= CPUID4A_HCALL_REMOTE_TLB_FLUSH;
         if ( !cpu_has_vmx_apic_reg_virt )
             res->a |= CPUID4A_MSR_BASED_APIC;
-        res->b = 2047; /* long spin count */
+
+        /*
+         * This value is the recommended number of attempts to try to
+         * acquire a spinlock before notifying the hypervisor via the
+         * HvNotifyLongSpinWait hypercall.
+         */
+        res->b = viridian_spinlock_retry_count;
         break;
 
     case 6:
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw

PATCH v5 3/3 x86/viridian: implement the crash MSRs

In reply to Paul Durrant

Section 2.4.4 of the Hypervisor Top Level Functional Specification states that enabling bit 10 in EDX of CPUID leaf 3 advertises to Windows a set of MSRs into which it can write crash information.

This patch advertises that bit and implements the MSRs such that Xen can log the information if a Windows guest crashes.

---
Cc: Ian Jackson <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>

v5:
- Fix LIBXL_HAVE_... name

v4:
- Name the union in HV_CRASH_CTL_REG_CONTENTS to keep older gcc happy

v3:
- Use WARNING level message rather than INFO

v2:
- Make MSRs per-vcpu rather than per-domain
- Fix hypervisor stack leak
- Replicate BUILD_BOG_ON()
- Use gprintk() rather than printk()

---
 docs/man/xl.cfg.pod.5.in           | 10 ++++--
 tools/libxl/libxl.h                |  6 ++++
 tools/libxl/libxl_dom.c            |  4 +++
 tools/libxl/libxl_types.idl        |  1 +
 xen/arch/x86/hvm/viridian.c        | 69 ++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/hvm/viridian.h |  1 +
 xen/include/public/hvm/params.h    |  7 +++-
 7 files changed, 95 insertions(+), 3 deletions(-)
docs/man/xl.cfg.pod.5.in +8 -2
index 52802d5..991960b 100644
@@ -1601,11 +1601,17 @@ per-vcpu event channel upcall vectors.
 Note that this enlightenment will have no effect if the guest is
 using APICv posted interrupts.
 
+=item B<crash_ctl>
+
+This group incorporates the crash control MSRs. These enlightenments
+allow Windows to write crash information such that it can be logged
+by Xen.
+
 =item B<defaults>
 
 This is a special value that enables the default set of groups, which
-is currently the B<base>, B<freq>, B<time_ref_count> and B<apic_assist>
-groups.
+is currently the B<base>, B<freq>, B<time_ref_count>, B<apic_assist>
+and B<crash_ctl> groups.
 
 =item B<all>
 
tools/libxl/libxl.h +6 -0
index 72ec39d..833f866 100644
@@ -288,6 +288,12 @@
 #define LIBXL_HAVE_SCHED_CREDIT2_PARAMS 1
 
 /*
+ * LIBXL_HAVE_VIRIDIAN_CRASH_CTL indicates that the 'crash_ctl' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_VIRIDIAN_CRASH_CTL 1
+
+/*
  * libxl ABI compatibility
  *
  * The only guarantee which libxl makes regarding ABI compatibility
tools/libxl/libxl_dom.c +4 -0
index c88b904..cf03ded 100644
@@ -214,6 +214,7 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
         libxl_bitmap_set(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_FREQ);
         libxl_bitmap_set(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_TIME_REF_COUNT);
         libxl_bitmap_set(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_APIC_ASSIST);
+        libxl_bitmap_set(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_CRASH_CTL);
     }
 
     libxl_for_each_set_bit(v, info->u.hvm.viridian_enable) {
@@ -259,6 +260,9 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
     if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_APIC_ASSIST))
         mask |= HVMPV_apic_assist;
 
+    if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_CRASH_CTL))
+        mask |= HVMPV_crash_ctl;
+
     if (mask != 0 &&
         xc_hvm_param_set(CTX->xch,
                          domid,
tools/libxl/libxl_types.idl +1 -0
index 2475a4d..69e789a 100644
@@ -224,6 +224,7 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [
     (3, "reference_tsc"),
     (4, "hcall_remote_tlb_flush"),
     (5, "apic_assist"),
+    (6, "crash_ctl"),
     ])
 
 libxl_hdtype = Enumeration("hdtype", [
xen/arch/x86/hvm/viridian.c +69 -0

93 lines not on this page · raw message

xen/include/asm-x86/hvm/viridian.h +1 -0
index 271c36d..30259e9 100644
@@ -26,6 +26,7 @@ struct viridian_vcpu
         void *va;
         int vector;
     } vp_assist;
+    uint64_t crash_param[5];
 };
 
 union viridian_guest_os_id
xen/include/public/hvm/params.h +6 -1
index 58c8478..19c9eb8 100644
@@ -135,13 +135,18 @@
 #define _HVMPV_apic_assist 5
 #define HVMPV_apic_assist (1 << _HVMPV_apic_assist)
 
+/* Enable crash MSRs */
+#define _HVMPV_crash_ctl 6
+#define HVMPV_crash_ctl (1 << _HVMPV_crash_ctl)
+
 #define HVMPV_feature_mask \
         (HVMPV_base_freq | \
          HVMPV_no_freq | \
          HVMPV_time_ref_count | \
          HVMPV_reference_tsc | \
          HVMPV_hcall_remote_tlb_flush | \
-         HVMPV_apic_assist)
+         HVMPV_apic_assist | \
+         HVMPV_crash_ctl)
 
 #endif
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel