Skip to contentSkip to conversation

viridian updates

PATCH Superseded Paul Durrant 3 participants 16 messages Mar 21, 2017 – Mar 22, 2017

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover viridian updates

Paul Durrant (6):
x86/viridian: fix xen-hvmcrash when vp_assist page is present x86/viridian: don't put Xen version information in CPUID leaf 2 x86/viridian: get rid of the magic numbers in CPUID leaves 1 and 2 x86/viridian: add warnings for unimplemented hypercalls and MSRs 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         | 264 ++++++++++++++++++++++++++++++++----
 xen/include/asm-x86/hvm/viridian.h  |   1 +
 xen/include/public/hvm/params.h     |   7 +-
 8 files changed, 276 insertions(+), 33 deletions(-)
Signature · 7 lines
2.1.4


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

PATCH v3 1/6 x86/viridian: fix xen-hvmcrash when vp_assist page is present

Currently use of xen-hvmcrash will cause an immediate domain_crash() in initialize_vp_assist() because it is called from viridian_load_vcpu_ctxt() without having first cleared any previous mapping.

This patch addes a check into viridian_load_vcpu_ctxt() to avoid re- initialization and turned the domain_crash() in initialize_vp_assist() into an ASSERT() since neither codepath into that function should allow it to be hit.

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

v3:
- Slightly too much simplification in v2... missing hunk re-instated

v2:
- Patch significantly simplified

---
 xen/arch/x86/hvm/viridian.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
xen/arch/x86/hvm/viridian.c +4 -9
index f2c9613..a71f928 100644
@@ -283,6 +283,8 @@ static void initialize_vp_assist(struct vcpu *v)
     struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
     void *va;
 
+    ASSERT(!v->arch.hvm_vcpu.viridian.vp_assist.va);
+
     /*
      * See section 7.8.7 of the specification for details of this
      * enlightenment.
@@ -306,14 +308,6 @@ static void initialize_vp_assist(struct vcpu *v)
 
     clear_page(va);
 
-    /*
-     * If we overwrite an existing address here then something has
-     * gone wrong and a domain page will leak. Instead crash the
-     * domain to make the problem obvious.
-     */
-    if ( v->arch.hvm_vcpu.viridian.vp_assist.va )
-        domain_crash(d);
-
     v->arch.hvm_vcpu.viridian.vp_assist.va = va;
     return;
 
@@ -904,7 +898,8 @@ static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         return -EINVAL;
 
     v->arch.hvm_vcpu.viridian.vp_assist.msr.raw = ctxt.vp_assist_msr;
-    if ( v->arch.hvm_vcpu.viridian.vp_assist.msr.fields.enabled )
+    if ( v->arch.hvm_vcpu.viridian.vp_assist.msr.fields.enabled &&
+         !v->arch.hvm_vcpu.viridian.vp_assist.va )
         initialize_vp_assist(v);
 
     v->arch.hvm_vcpu.viridian.vp_assist.vector = ctxt.vp_assist_vector;
Signature · 7 lines
2.1.4


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

PATCH v3 2/6 x86/viridian: don't put Xen version information in CPUID leaf 2

In reply to Paul Durrant

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

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         | 50 +++++++++++++++++++++++++++++++++++--
 2 files changed, 56 insertions(+), 2 deletions(-)
docs/misc/xen-command-line.markdown +8 -0
index bad20db..f029e66 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,1772`
+
+<major>, <minor> and <build> must be integers specified in hexadecimal. The values will be
+encoded in guest CPUID 0x40000002 if viridian enlightenments are enabled.
+
 ### vpid (Intel)
 > `= <boolean>`
 
xen/arch/x86/hvm/viridian.c +48 -2

68 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
#7 lore raw

PATCH v3 3/6 x86/viridian: get rid of the magic numbers in CPUID leaves 1 and 2

In reply to Paul Durrant

The numbers correspond to ASCII characters so just use appropriate character strings directly.

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

v2:
- Use memcpy() rather than cast-and-assign

---
 xen/arch/x86/hvm/viridian.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/viridian.c +6 -4
index 8a5c831..41f550c 100644
@@ -132,14 +132,16 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
     switch ( leaf )
     {
     case 0:
+        /* See section 2.4.1 of the specification */
         res->a = 0x40000006; /* Maximum leaf */
-        res->b = 0x7263694d; /* Magic numbers  */
-        res->c = 0x666F736F;
-        res->d = 0x76482074;
+        memcpy(&res->b, "Micr", 4);
+        memcpy(&res->c, "osof", 4);
+        memcpy(&res->d, "t Hv", 4);
         break;
 
     case 1:
-        res->a = 0x31237648; /* Version number */
+        /* See section 2.4.2 of the specification */
+        memcpy(&res->a, "Hv#1", 4);
         break;
 
     case 2:
Signature · 7 lines
2.1.4


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

PATCH v3 5/6 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 f029e66..d42298c 100644
@@ -1624,6 +1624,14 @@ relinquish control to dom0.
 <major>, <minor> and <build> must be integers specified in hexadecimal. 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 d6381c0..9d1272a 100644
@@ -177,6 +177,14 @@ static uint16_t viridian_major = 6;
 static uint16_t viridian_minor = 0;
 static uint32_t 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)
 {
@@ -254,7 +262,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
#8 lore raw

PATCH v3 4/6 x86/viridian: add warnings for unimplemented hypercalls and MSRs

In reply to Paul Durrant

These warnings can be useful when Microsoft updates Windows.

In the past there have been several cases when Windows erroneously uses hypercalls and MSRs that should be gated on CPUID flags than Xen does not set. The usual symptom is a guest crash with little or no information in the hypervisor log. Adding these warnings at least gives a clue as to what might be happening in such cases.

Some versions of Windows do currently issue hypercalls that they should not, so this patch whitelists those to avoid the warnings as the lack of implementation is clearly proved not to be a problem to the guest.

The warnings are rate limited so a malicious guest cannot use them to as a DoS.

NOTE: Because the MSR warnings need to be gated on range checking the
MSR address this patch imports the up-to-date definitions of all the viridian MSRs from the specification.

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

v3:
- Slight tweak to string literals

v2:
- Use gprintk() rather than gdprintk()
- Further changes requested by Jan

---
 xen/arch/x86/hvm/viridian.c | 106 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 92 insertions(+), 14 deletions(-)
xen/arch/x86/hvm/viridian.c +92 -14
index 41f550c..d6381c0 100644
@@ -23,17 +23,73 @@
 #include <public/hvm/hvm_op.h>
 
 /* Viridian MSR numbers. */
-#define HV_X64_MSR_GUEST_OS_ID                  0x40000000
-#define HV_X64_MSR_HYPERCALL                    0x40000001
-#define HV_X64_MSR_VP_INDEX                     0x40000002
-#define HV_X64_MSR_TIME_REF_COUNT               0x40000020
-#define HV_X64_MSR_REFERENCE_TSC                0x40000021
-#define HV_X64_MSR_TSC_FREQUENCY                0x40000022
-#define HV_X64_MSR_APIC_FREQUENCY               0x40000023
-#define HV_X64_MSR_EOI                          0x40000070
-#define HV_X64_MSR_ICR                          0x40000071
-#define HV_X64_MSR_TPR                          0x40000072
-#define HV_X64_MSR_VP_ASSIST_PAGE               0x40000073
+#define HV_X64_MSR_GUEST_OS_ID                   0x40000000
+#define HV_X64_MSR_HYPERCALL                     0x40000001
+#define HV_X64_MSR_VP_INDEX                      0x40000002
+#define HV_X64_MSR_RESET                         0x40000003
+#define HV_X64_MSR_VP_RUNTIME                    0x40000010
+#define HV_X64_MSR_TIME_REF_COUNT                0x40000020
+#define HV_X64_MSR_REFERENCE_TSC                 0x40000021
+#define HV_X64_MSR_TSC_FREQUENCY                 0x40000022
+#define HV_X64_MSR_APIC_FREQUENCY                0x40000023
+#define HV_X64_MSR_EOI                           0x40000070
+#define HV_X64_MSR_ICR                           0x40000071
+#define HV_X64_MSR_TPR                           0x40000072
+#define HV_X64_MSR_VP_ASSIST_PAGE                0x40000073
+#define HV_X64_MSR_SCONTROL                      0x40000080
+#define HV_X64_MSR_SVERSION                      0x40000081
+#define HV_X64_MSR_SIEFP                         0x40000082
+#define HV_X64_MSR_SIMP                          0x40000083
+#define HV_X64_MSR_EOM                           0x40000084
+#define HV_X64_MSR_SINT0                         0x40000090
+#define HV_X64_MSR_SINT1                         0x40000091
+#define HV_X64_MSR_SINT2                         0x40000092
+#define HV_X64_MSR_SINT3                         0x40000093
+#define HV_X64_MSR_SINT4                         0x40000094
+#define HV_X64_MSR_SINT5                         0x40000095
+#define HV_X64_MSR_SINT6                         0x40000096
+#define HV_X64_MSR_SINT7                         0x40000097
+#define HV_X64_MSR_SINT8                         0x40000098
+#define HV_X64_MSR_SINT9                         0x40000099
+#define HV_X64_MSR_SINT10                        0x4000009A
+#define HV_X64_MSR_SINT11                        0x4000009B
+#define HV_X64_MSR_SINT12                        0x4000009C
+#define HV_X64_MSR_SINT13                        0x4000009D
+#define HV_X64_MSR_SINT14                        0x4000009E
+#define HV_X64_MSR_SINT15                        0x4000009F
+#define HV_X64_MSR_STIMER0_CONFIG                0x400000B0
+#define HV_X64_MSR_STIMER0_COUNT                 0x400000B1
+#define HV_X64_MSR_STIMER1_CONFIG                0x400000B2
+#define HV_X64_MSR_STIMER1_COUNT                 0x400000B3
+#define HV_X64_MSR_STIMER2_CONFIG                0x400000B4
+#define HV_X64_MSR_STIMER2_COUNT                 0x400000B5
+#define HV_X64_MSR_STIMER3_CONFIG                0x400000B6
+#define HV_X64_MSR_STIMER3_COUNT                 0x400000B7
+#define HV_X64_MSR_POWER_STATE_TRIGGER_C1        0x400000C1
+#define HV_X64_MSR_POWER_STATE_TRIGGER_C2        0x400000C2
+#define HV_X64_MSR_POWER_STATE_TRIGGER_C3        0x400000C3
+#define HV_X64_MSR_POWER_STATE_CONFIG_C1         0x400000D1
+#define HV_X64_MSR_POWER_STATE_CONFIG_C2         0x400000D2
+#define HV_X64_MSR_POWER_STATE_CONFIG_C3         0x400000D3
+#define HV_X64_MSR_STATS_PARTITION_RETAIL_PAGE   0x400000E0
+#define HV_X64_MSR_STATS_PARTITION_INTERNAL_PAGE 0x400000E1
+#define HV_X64_MSR_STATS_VP_RETAIL_PAGE          0x400000E2
+#define HV_X64_MSR_STATS_VP_INTERNAL_PAGE        0x400000E3
+#define HV_X64_MSR_GUEST_IDLE                    0x400000F0
+#define HV_X64_MSR_SYNTH_DEBUG_CONTROL           0x400000F1
+#define HV_X64_MSR_SYNTH_DEBUG_STATUS            0x400000F2
+#define HV_X64_MSR_SYNTH_DEBUG_SEND_BUFFER       0x400000F3
+#define HV_X64_MSR_SYNTH_DEBUG_RECEIVE_BUFFER    0x400000F4
+#define HV_X64_MSR_SYNTH_DEBUG_PENDING_BUFFER    0x400000F5
+#define HV_X64_MSR_CRASH_P0                      0x40000100
+#define HV_X64_MSR_CRASH_P1                      0x40000101
+#define HV_X64_MSR_CRASH_P2                      0x40000102
+#define HV_X64_MSR_CRASH_P3                      0x40000103
+#define HV_X64_MSR_CRASH_P4                      0x40000104
+#define HV_X64_MSR_CRASH_CTL                     0x40000105
+
+#define VIRIDIAN_MSR_MIN HV_X64_MSR_GUEST_OS_ID
+#define VIRIDIAN_MSR_MAX HV_X64_MSR_CRASH_CTL
 
 /* Viridian Hypercall Status Codes. */
 #define HV_STATUS_SUCCESS                       0x0000
@@ -41,9 +97,11 @@
 #define HV_STATUS_INVALID_PARAMETER             0x0005
 
 /* Viridian Hypercall Codes. */
-#define HvFlushVirtualAddressSpace 2
-#define HvFlushVirtualAddressList  3
-#define HvNotifyLongSpinWait       8
+#define HvFlushVirtualAddressSpace 0x0002
+#define HvFlushVirtualAddressList  0x0003
+#define HvNotifyLongSpinWait       0x0008
+#define HvGetPartitionId           0x0046
+#define HvExtCallQueryCapabilities 0x8001
 
 /* Viridian Hypercall Flags. */
 #define HV_FLUSH_ALL_PROCESSORS 1
@@ -541,6 +599,10 @@ int wrmsr_viridian_regs(uint32_t idx, uint64_t val)
         break;
 
     default:
+        if ( idx >= VIRIDIAN_MSR_MIN && idx <= VIRIDIAN_MSR_MAX )
+            gprintk(XENLOG_WARNING, "write to unimplemented MSR %#x\n",
+                    idx);
+
         return 0;
     }
 
@@ -664,6 +726,10 @@ int rdmsr_viridian_regs(uint32_t idx, uint64_t *val)
     }
 
     default:
+        if ( idx >= VIRIDIAN_MSR_MIN && idx <= VIRIDIAN_MSR_MAX )
+            gprintk(XENLOG_WARNING, "read from unimplemented MSR %#x\n",
+                    idx);
+
         return 0;
     }
 
@@ -817,6 +883,18 @@ int viridian_hypercall(struct cpu_user_regs *regs)
     }
 
     default:
+        gprintk(XENLOG_WARNING, "unimplemented hypercall %04x\n",
+                input.call_code);
+
+    case HvGetPartitionId:
+    case HvExtCallQueryCapabilities:
+        /*
+         * These hypercalls seem to be erroneously issued by Windows
+         * despite neither AccessPartitionId nor EnableExtendedHypercalls
+         * being set in CPUID leaf 2.
+         * Given that return a status of 'invalid code' has not so far
+         * caused any problems it's not worth logging.
+         */
         status = HV_STATUS_INVALID_HYPERCALL_CODE;
         break;
     }
Signature · 7 lines
2.1.4


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

PATCH v3 6/6 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]>

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..af45582 100644
@@ -288,6 +288,12 @@
 #define LIBXL_HAVE_SCHED_CREDIT2_PARAMS 1
 
 /*
+ * LIBXL_HAVE_CRASH_CTL indicates that the 'crash_ctl' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_CRASH_CTL 1
+
+/*
  * libxl ABI compatibility
  *
  * The only guarantee which libxl makes regarding ABI compatibility
tools/libxl/libxl_dom.c +4 -0
index e133962..c25cf48 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
Reviewed-by on v3 1/6
#2 lore raw

Re: [PATCH v3 1/6] x86/viridian: fix xen-hvmcrash when vp_assist page is present

In reply to Paul Durrant
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:

Currently use of xen-hvmcrash will cause an immediate domain_crash() in initialize_vp_assist() because it is called from viridian_load_vcpu_ctxt() without having first cleared any previous mapping.

This patch addes a check into viridian_load_vcpu_ctxt() to avoid re- initialization and turned the domain_crash() in initialize_vp_assist() into an ASSERT() since neither codepath into that function should allow it to be hit.

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

#4 lore raw

Re: [PATCH v3 2/6] x86/viridian: don't put Xen version information in CPUID leaf 2

In reply to Paul Durrant

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to continue using the vga · line 1620

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:
docs/misc/xen-command-line.markdown +2 -0
@@ -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>`

In my proposal I had intentionally enclosed each number in square brackets, indicating that each one is optional. I don't see the point of having to specify all numbers all the time (and your earlier split option model didn't make this a requirement either).

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to continue using the vga · line 1625

Quoted 4 lines
docs/misc/xen-command-line.markdown +4 -0
+> Default: `6,0,1772`
+
+<major>, <minor> and <build> must be integers specified in hexadecimal. The values will be
+encoded in guest CPUID 0x40000002 if viridian enlightenments are enabled.

Please wrap at column 80 the latest. And why do the numbers need to be in hex?

xen/arch/x86/hvm/viridian.c typedef struct { · line 115

Quoted 13 lines
xen/arch/x86/hvm/viridian.c +7 -0
@@ -106,6 +106,19 @@ typedef struct {
 #define CPUID6A_MSR_BITMAPS     (1 << 1)
 #define CPUID6A_NESTED_PAGING   (1 << 3)
 
+/*
+ * Version and build number reported by CPUID leaf 2
+ *
+ * These numbers are chosen to match the version numbers reported by
+ * Windows Server 2008.
+ */
+static char __initdata viridian_version[sizeof("0xVVVV,0xVVVV,0xVVVVVVVV")] = "";

Pointless in initializer.

xen/arch/x86/hvm/viridian.c typedef struct { · line 116

Quoted 1 line
xen/arch/x86/hvm/viridian.c +1 -0
+string_param("viridian-version", viridian_version);

Why not custom_param()?

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 928

Quoted 7 lines
xen/arch/x86/hvm/viridian.c +3 -0
@@ -910,6 +923,39 @@ static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)
 HVM_REGISTER_SAVE_RESTORE(VIRIDIAN_VCPU, viridian_save_vcpu_ctxt,
                           viridian_load_vcpu_ctxt, 1, HVMSR_PER_VCPU);
 
+static int __init viridian_init(void)
+{
+    char *t, *v = viridian_version;

With e being pointer to const, I think t should be, too.

Quoted 7 lines
xen/arch/x86/hvm/viridian.c +7 -0
+    unsigned int n[3], i = 0;
+
+    if ( *v == '\0' )
+        return 0;
+
+    while ( (t = strsep(&v, ",")) != NULL )
+    {

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 945

Quoted 10 lines
xen/arch/x86/hvm/viridian.c +10 -0
+        const char *e;
+
+        n[i++] = simple_strtoul(t, &e, 16);
+        if ( *e != '\0' )
+            goto fail;
+    }
+    if ( i != 3 )
+        goto fail;
+
+    if (n[0] > 0xffff || n[1] > 0xffff)

Missing blanks.

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 953

Quoted 8 lines
xen/arch/x86/hvm/viridian.c +8 -0
+        goto fail;
+
+    viridian_major = n[0];
+    viridian_minor = n[1];
+    viridian_build = n[2];
+    return 0;
+
+fail:

Indentation.

Jan

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

#5 lore raw

Re: [PATCH v3 2/6] x86/viridian: don't put Xen version information in CPUID leaf 2

Quoted 17 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 March 2017 10:10
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 2/6] x86/viridian: don't put Xen version information in CPUID leaf 2

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:
docs/misc/xen-command-line.markdown +0 -0
@@ -1616,6 +1616,14 @@ The optional `keep` parameter causes Xen to

continue using the vga

Quoted 3 lines
docs/misc/xen-command-line.markdown +0 -0
 console even after dom0 has been started.  The default behaviour is to
 relinquish control to dom0.
 
Quoted 8 lines

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to continue using the vga · line 1620

Quoted 2 lines
docs/misc/xen-command-line.markdown +2 -0
+### viridian-version
+> `= <major>,<minor>,<build>`

In my proposal I had intentionally enclosed each number in square brackets, indicating that each one is optional. I don't see the point of having to specify all numbers all the time (and your earlier split option model didn't make this a requirement either).

So you'd like something like:

viridian-version=,,0xabcd

so that just the build number can be overridden to 0xabcd?

Quoted 9 lines

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to continue using the vga

Quoted 3 lines
docs/misc/xen-command-line.markdown +3 -0
+> Default: `6,0,1772`
+
+<major>, <minor> and <build> must be integers specified in hexadecimal.

The values will be

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to · line 1624

Quoted 1 line
docs/misc/xen-command-line.markdown +1 -0
+encoded in guest CPUID 0x40000002 if viridian enlightenments are

enabled.

Please wrap at column 80 the latest. And why do the numbers need to be in hex?

I can relax that restriction if you'd prefer.

Quoted 16 lines
Quoted 4 lines

xen/arch/x86/hvm/viridian.c typedef struct { · line 115

Quoted 10 lines
xen/arch/x86/hvm/viridian.c +7 -0
@@ -106,6 +106,19 @@ typedef struct {
 #define CPUID6A_MSR_BITMAPS     (1 << 1)
 #define CPUID6A_NESTED_PAGING   (1 << 3)
 
+/*
+ * Version and build number reported by CPUID leaf 2
+ *
+ * These numbers are chosen to match the version numbers reported by
+ * Windows Server 2008.
+ */
+static char __initdata

viridian_version[sizeof("0xVVVV,0xVVVV,0xVVVVVVVV")] = "";

Quoted 2 lines

Pointless in initializer.

Seemed to be common practice elsewhere in the code.

Quoted 4 lines

xen/arch/x86/hvm/viridian.c typedef struct { · line 116

Quoted 1 line
xen/arch/x86/hvm/viridian.c +1 -0
+string_param("viridian-version", viridian_version);

Why not custom_param()?

Not come across custom_param(). I'll look it up.

Quoted 12 lines

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain

Quoted 1 line
xen/arch/x86/hvm/viridian.c +0 -0
@@ -910,6 +923,39 @@ static int viridian_load_vcpu_ctxt(struct domain

*d, hvm_domain_context_t *h)

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain · line 923

Quoted 1 line
xen/arch/x86/hvm/viridian.c +0 -0
 HVM_REGISTER_SAVE_RESTORE(VIRIDIAN_VCPU,

viridian_save_vcpu_ctxt,

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 928

Quoted 5 lines
xen/arch/x86/hvm/viridian.c +3 -0
                           viridian_load_vcpu_ctxt, 1, HVMSR_PER_VCPU);
 
+static int __init viridian_init(void)
+{
+    char *t, *v = viridian_version;

With e being pointer to const, I think t should be, too.

Ok.

Quoted 11 lines
Quoted 11 lines
xen/arch/x86/hvm/viridian.c +11 -0
+    unsigned int n[3], i = 0;
+
+    if ( *v == '\0' )
+        return 0;
+
+    while ( (t = strsep(&v, ",")) != NULL )
+    {
+        const char *e;
+
+        n[i++] = simple_strtoul(t, &e, 16);
+        if ( *e != '\0' )
Quoted 9 lines

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 945

Quoted 6 lines
xen/arch/x86/hvm/viridian.c +6 -0
+            goto fail;
+    }
+    if ( i != 3 )
+        goto fail;
+
+    if (n[0] > 0xffff || n[1] > 0xffff)

Missing blanks.

Oops.

Quoted 11 lines

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 953

Quoted 8 lines
xen/arch/x86/hvm/viridian.c +8 -0
+        goto fail;
+
+    viridian_major = n[0];
+    viridian_minor = n[1];
+    viridian_build = n[2];
+    return 0;
+
+fail:

Indentation.

Yes, sorry I forgot about that xen style quirk.

Paul

Quoted 1 line

Jan

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

#6 lore raw

Re: [PATCH v3 2/6] x86/viridian: don't put Xen version information in CPUID leaf 2

Quoted 20 lines
Quoted 11 lines
Quoted 1 line · On 22.03.17 at 11:20, <[email protected]> wrote:

From: Jan Beulich [mailto:[email protected]]
Sent: 22 March 2017 10:10

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:
docs/misc/xen-command-line.markdown +0 -0
@@ -1616,6 +1616,14 @@ The optional `keep` parameter causes Xen to

continue using the vga

Quoted 3 lines
docs/misc/xen-command-line.markdown +0 -0
 console even after dom0 has been started.  The default behaviour is to
 relinquish control to dom0.
 
Quoted 8 lines

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to continue using the vga · line 1620

Quoted 2 lines
docs/misc/xen-command-line.markdown +2 -0
+### viridian-version
+> `= <major>,<minor>,<build>`

In my proposal I had intentionally enclosed each number in square brackets, indicating that each one is optional. I don't see the point of having to specify all numbers all the time (and your earlier split option model didn't make this a requirement either).

Quoted 5 lines

So you'd like something like:

viridian-version=,,0xabcd

so that just the build number can be overridden to 0xabcd?

Yes.

Quoted 11 lines
Quoted 9 lines

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to continue using the vga

Quoted 3 lines
docs/misc/xen-command-line.markdown +3 -0
+> Default: `6,0,1772`
+
+<major>, <minor> and <build> must be integers specified in hexadecimal.

The values will be

docs/misc/xen-command-line.markdown The optional `keep` parameter causes Xen to · line 1624

Quoted 1 line
docs/misc/xen-command-line.markdown +1 -0
+encoded in guest CPUID 0x40000002 if viridian enlightenments are

enabled.

Please wrap at column 80 the latest. And why do the numbers need to be in hex?

I can relax that restriction if you'd prefer.

Yes please. I don't think version numbers are commonly expressed in hex.

Quoted 15 lines
Quoted 15 lines

xen/arch/x86/hvm/viridian.c typedef struct { · line 115

Quoted 13 lines
xen/arch/x86/hvm/viridian.c +7 -0
@@ -106,6 +106,19 @@ typedef struct {
 #define CPUID6A_MSR_BITMAPS     (1 << 1)
 #define CPUID6A_NESTED_PAGING   (1 << 3)
 
+/*
+ * Version and build number reported by CPUID leaf 2
+ *
+ * These numbers are chosen to match the version numbers reported by
+ * Windows Server 2008.
+ */
+static char __initdata

viridian_version[sizeof("0xVVVV,0xVVVV,0xVVVVVVVV")] = "";

Quoted 3 lines
Quoted 1 line

Pointless in initializer.

Seemed to be common practice elsewhere in the code.

Odd.

Quoted 11 lines
Quoted 10 lines

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 953

Quoted 8 lines
xen/arch/x86/hvm/viridian.c +8 -0
+        goto fail;
+
+    viridian_major = n[0];
+    viridian_minor = n[1];
+    viridian_build = n[2];
+    return 0;
+
+fail:

Indentation.

Quoted 1 line

Yes, sorry I forgot about that xen style quirk.

Is this a quirk? It's desirable to not misguide diff's -p handling (as we want it to produce the function, not some random label, where the same name can occur more than once in a source file).

Jan

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

#11 lore raw

Re: [PATCH v3 6/6] x86/viridian: implement the crash MSRs

In reply to Paul Durrant

tools/libxl/libxl.h line 294

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:
tools/libxl/libxl.h +4 -0
@@ -288,6 +288,12 @@
 #define LIBXL_HAVE_SCHED_CREDIT2_PARAMS 1
 
 /*
+ * LIBXL_HAVE_CRASH_CTL indicates that the 'crash_ctl' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_CRASH_CTL 1

I was about to commit this together with 1, 3, and 4, when this define caught my eye: Isn't the name a little too generic? I.e. LIBXL_HAVE_VIRIDIAN_CRASH_CTL perhaps?

Jan

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

#12 lore raw

Re: [PATCH v3 6/6] x86/viridian: implement the crash MSRs

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:
tools/libxl/libxl.h +0 -0
@@ -288,6 +288,12 @@
 #define LIBXL_HAVE_SCHED_CREDIT2_PARAMS 1
 
Quoted 10 lines

tools/libxl/libxl.h line 294

Quoted 5 lines
tools/libxl/libxl.h +4 -0
 /*
+ * LIBXL_HAVE_CRASH_CTL indicates that the 'crash_ctl' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_CRASH_CTL 1

I was about to commit this together with 1, 3, and 4, when this define caught my eye: Isn't the name a little too generic? I.e. LIBXL_HAVE_VIRIDIAN_CRASH_CTL perhaps?

That's fine by me.

Quoted 2 lines

Jan

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

#13 lore raw

Re: [PATCH v3 6/6] x86/viridian: implement the crash MSRs

Quoted 28 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 22 March 2017 11:10
To: Jan Beulich <[email protected]>
Cc: Paul Durrant <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [PATCH v3 6/6] x86/viridian: implement the crash MSRs

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:
tools/libxl/libxl.h +0 -0
@@ -288,6 +288,12 @@
 #define LIBXL_HAVE_SCHED_CREDIT2_PARAMS 1
 
Quoted 10 lines

tools/libxl/libxl.h line 294

Quoted 5 lines
tools/libxl/libxl.h +4 -0
 /*
+ * LIBXL_HAVE_CRASH_CTL indicates that the 'crash_ctl' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_CRASH_CTL 1

I was about to commit this together with 1, 3, and 4, when this define caught my eye: Isn't the name a little too generic? I.e. LIBXL_HAVE_VIRIDIAN_CRASH_CTL perhaps?

Quoted 2 lines

That's fine by me.

Ok with me too.

Paul

Quoted 2 lines
Quoted 2 lines

Jan

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

#14 lore raw

Re: [PATCH v3 6/6] x86/viridian: implement the crash MSRs

In reply to Paul Durrant

xen/arch/x86/hvm/viridian.c int rdmsr_viridian_regs(uint32_t idx, uint64_t *val) · line 805

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:
xen/arch/x86/hvm/viridian.c +5 -0
+    case HV_X64_MSR_CRASH_CTL:
+    {
+        HV_CRASH_CTL_REG_CONTENTS ctl = {
+            .CrashNotify = 1,
+        };

This initializer failed my pre-push build test: Some gcc versions we still support don't allow fields of unnamed union members to be initialized this way. As there are at least two ways to deal with this, and as this is code maintained by you, I didn't want to pick either, as I don't know your preference.

Jan

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

#15 lore raw

Re: [PATCH v3 6/6] x86/viridian: implement the crash MSRs

Quoted 16 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 22 March 2017 11:38
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [PATCH v3 6/6] x86/viridian: implement the crash MSRs

xen/arch/x86/hvm/viridian.c int rdmsr_viridian_regs(uint32_t idx, uint64_t *val) · line 805

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 19:17, <[email protected]> wrote:
xen/arch/x86/hvm/viridian.c +5 -0
+    case HV_X64_MSR_CRASH_CTL:
+    {
+        HV_CRASH_CTL_REG_CONTENTS ctl = {
+            .CrashNotify = 1,
+        };
Quoted 6 lines

This initializer failed my pre-push build test: Some gcc versions we still support don't allow fields of unnamed union members to be initialized this way. As there are at least two ways to deal with this, and as this is code maintained by you, I didn't want to pick either, as I don't know your preference.

Ok, I guess I'll go for naming the union member. Do you want me to resubmit?

Paul

Quoted 1 line

Jan

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