Skip to contentSkip to conversation

Viridian changes for Hyper-V as a guest

PATCH Superseded Ross Lagerwall 4 participants 12 messages Aug 28 – Sep 4

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Viridian changes for Hyper-V as a guest

Hi,

Here are two changes to get the existing Virdian enlightenments working when running a Windows 11 guest with Hyper-V enabled

Hyper-V also depends on some unimplemented MSRs to boot, but that will be addressed in a separate series.

Thanks,
Ross

Ross Lagerwall (2):
x86/viridian: Workaround Hyper-V GP fault writing to MSR x86/viridian: Implement synthetic timer direct mode

 xen/arch/x86/hvm/viridian/synic.c    |  3 +++
 xen/arch/x86/hvm/viridian/time.c     | 25 +++++++++++++++++++------
 xen/arch/x86/hvm/viridian/viridian.c |  3 +++
 3 files changed, 25 insertions(+), 6 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 x86/viridian: Workaround Hyper-V GP fault writing to MSR

The Viridian spec requires the vector to be >= 0x10 when writing to the SINTx MSR, otherwise it should #GP fault.
The spec-defined initial value is 0x0000000000010000, i.e. the vector is
0. On startup, for some reason Windows 11 Hyper-V tries to set the MSR to the spec-defined initial value and since the vector is 0, it GP faults. To workaround this, treat the write as a no-op if the value is unchanged.

---
 xen/arch/x86/hvm/viridian/synic.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/hvm/viridian/synic.c +3 -0
index e6cba7548f1b..37ddff201a6b 100644
@@ -157,6 +157,9 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
         if ( !(viridian_feature_mask(d) & HVMPV_synic) )
             return X86EMUL_EXCEPTION;
 
+        if ( val == vs->as_uint64 )
+            break;
+
         /* Vectors must be in the range 0x10-0xff inclusive */
         new.as_uint64 = val;
         if ( new.vector < 0x10 )
Signature · 1 line
2.53.0
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] x86/viridian: Workaround Hyper-V GP fault writing to MSR

Quoted 9 lines · Ross Lagerwall

The Viridian spec requires the vector to be >= 0x10 when writing to the SINTx MSR, otherwise it should #GP fault.
The spec-defined initial value is 0x0000000000010000, i.e. the vector is
0. On startup, for some reason Windows 11 Hyper-V tries to set the MSR to the spec-defined initial value and since the vector is 0, it GP faults. To workaround this, treat the write as a no-op if the value is unchanged.

I expect that despite the (valid) absence of a Fixes: tag this will want backporting.

Jan

#3 lore raw

Re: [PATCH v1 1/2] x86/viridian: Workaround Hyper-V GP fault writing to MSR

Quoted 9 lines · Jan Beulich
Quoted 8 lines · Ross Lagerwall

The Viridian spec requires the vector to be >= 0x10 when writing to the SINTx MSR, otherwise it should #GP fault.
The spec-defined initial value is 0x0000000000010000, i.e. the vector is
0. On startup, for some reason Windows 11 Hyper-V tries to set the MSR to the spec-defined initial value and since the vector is 0, it GP faults. To workaround this, treat the write as a no-op if the value is unchanged.

Quoted 6 lines
Quoted 1 line

I expect that despite the (valid) absence of a Fixes: tag this will want backporting.

It should be fine to backport, though in general I think backporting nested virt fixes at this point is not needed as there will be too many changes to go into the stable releases for it to reach a usable state.

Ross

#4 lore raw

Re: [PATCH v1 1/2] x86/viridian: Workaround Hyper-V GP fault writing to MSR

Quoted 12 lines · Ross Lagerwall
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Ross Lagerwall

The Viridian spec requires the vector to be >= 0x10 when writing to the SINTx MSR, otherwise it should #GP fault.
The spec-defined initial value is 0x0000000000010000, i.e. the vector is
0. On startup, for some reason Windows 11 Hyper-V tries to set the MSR to the spec-defined initial value and since the vector is 0, it GP faults. To workaround this, treat the write as a no-op if the value is unchanged.

Quoted 8 lines
Quoted 4 lines

I expect that despite the (valid) absence of a Fixes: tag this will want backporting.

It should be fine to backport, though in general I think backporting nested virt fixes at this point is not needed as there will be too many changes to go into the stable releases for it to reach a usable state.

How is this nested-virt related? It looks to affect Win11 when run on bare- metal Xen?

Jan

#5 lore raw

Re: [PATCH v1 1/2] x86/viridian: Workaround Hyper-V GP fault writing to MSR

Quoted 18 lines · Jan Beulich
Quoted 17 lines · Ross Lagerwall
Quoted 15 lines · Jan Beulich
Quoted 9 lines · Ross Lagerwall

The Viridian spec requires the vector to be >= 0x10 when writing to the SINTx MSR, otherwise it should #GP fault.
The spec-defined initial value is 0x0000000000010000, i.e. the vector is
0. On startup, for some reason Windows 11 Hyper-V tries to set the MSR to the spec-defined initial value and since the vector is 0, it GP faults. To workaround this, treat the write as a no-op if the value is unchanged.

I expect that despite the (valid) absence of a Fixes: tag this will want backporting.

Quoted 6 lines
Quoted 3 lines

It should be fine to backport, though in general I think backporting nested virt fixes at this point is not needed as there will be too many changes to go into the stable releases for it to reach a usable state.

How is this nested-virt related? It looks to affect Win11 when run on bare- metal Xen?

The regular Windows 11 kernel doesn't have this behaviour on startup, only the Windows 11 Hyper-V kernel (and possibly other Windows versions too) so you wouldn't encounter this behaviour unless using nested-virt.

Ross

#6 lore raw

Re: [PATCH v1 1/2] x86/viridian: Workaround Hyper-V GP fault writing to MSR

In reply to Ross Lagerwall
Quoted 18 lines · Ross Lagerwall

The Viridian spec requires the vector to be >= 0x10 when writing to the SINTx MSR, otherwise it should #GP fault.
The spec-defined initial value is 0x0000000000010000, i.e. the vector is
0. On startup, for some reason Windows 11 Hyper-V tries to set the MSR to the spec-defined initial value and since the vector is 0, it GP faults. To workaround this, treat the write as a no-op if the value is unchanged.

---
 xen/arch/x86/hvm/viridian/synic.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/hvm/viridian/synic.c +0 -0
index e6cba7548f1b..37ddff201a6b 100644

xen/arch/x86/hvm/viridian/synic.c int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val) · line 161

Quoted 5 lines
xen/arch/x86/hvm/viridian/synic.c +2 -0
@@ -157,6 +157,9 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
         if ( !(viridian_feature_mask(d) & HVMPV_synic) )
             return X86EMUL_EXCEPTION;
 
+        if ( val == vs->as_uint64 )
+            break;

This needs a code comment, or it's something which will be deleted in a few years time when someone wonders why it's present.

/* Windows 11 Hyper-V (Summer 2026) has been seen to write this MSR to it's default value, despite not being a spec compliant value.  Tolerate writes which have no change in value. */

~Andrew

#7 lore raw

PATCH 2/2 x86/viridian: Implement synthetic timer direct mode

In reply to Ross Lagerwall

In direct mode, the timer asserts an interrupt on expiration rather than using a SynIC message. It is useful to implement this since Windows 11's Hyper-V can only use synthetic timers in direct mode.

---

Should this use a new Viridian feature bit or is it OK to use the existing stimer bit?

 xen/arch/x86/hvm/viridian/time.c     | 25 +++++++++++++++++++------
 xen/arch/x86/hvm/viridian/viridian.c |  3 +++
 2 files changed, 22 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/viridian/time.c +19 -6
index 082528dc9416..2b0ac3eac963 100644
@@ -223,6 +223,14 @@ static void start_stimer(struct viridian_stimer *vs)
     set_timer(&vs->timer, timeout + NOW());
 }
 
+static void stimer_deliver_direct(struct vcpu *v, struct viridian_stimer *vs)
+{
+    struct vlapic *vlapic = vcpu_vlapic(v);
+
+    if ( vlapic_enabled(vlapic) )
+        vlapic_set_irq(vcpu_vlapic(v), vs->config.apic_vector, 0);
+}
+
 static void poll_stimer(struct vcpu *v, unsigned int stimerx)
 {
     struct viridian_vcpu *vv = v->arch.hvm.viridian;
@@ -242,9 +250,11 @@ static void poll_stimer(struct vcpu *v, unsigned int stimerx)
     if ( !test_bit(stimerx, &vv->stimer_pending) )
         return;
 
-    if ( !viridian_synic_deliver_timer_msg(v, vs->config.sintx,
-                                           stimerx, vs->expiration,
-                                           time_ref_count(v->domain)) )
+    if ( vs->config.direct_mode )
+        stimer_deliver_direct(v, vs);
+    else if ( !viridian_synic_deliver_timer_msg(v, vs->config.sintx,
+                                                stimerx, vs->expiration,
+                                                time_ref_count(v->domain)) )
         return;
 
     clear_bit(stimerx, &vv->stimer_pending);
@@ -372,7 +382,7 @@ int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
 
         vs->config.as_uint64 = val;
 
-        if ( !vs->config.sintx || !vs->count )
+        if ( (!vs->config.direct_mode && !vs->config.sintx) || !vs->count )
             vs->config.enable = 0;
 
         if ( vs->config.enable )
@@ -583,8 +593,11 @@ void viridian_time_load_vcpu_ctxt(
 
         vs->config.as_uint64 = ctxt->stimer_config_msr[i];
         vs->count = ctxt->stimer_count_msr[i];
-        if ( !vs->config.sintx || !vs->count )
-            /* Reject enabling with a zero sintx or count fields. */
+        if ( (!vs->config.direct_mode && !vs->config.sintx) || !vs->count )
+            /*
+             * Reject enabling with a zero sintx (if not using direct mode) or
+             * zero count field.
+             */
             vs->config.enable = 0;
     }
 }
xen/arch/x86/hvm/viridian/viridian.c +3 -0
index 90e749ceb581..99192e8d077d 100644
@@ -78,6 +78,7 @@ typedef union _HV_CRASH_CTL_REG_CONTENTS
 #define CPUID3D_CPU_DYNAMIC_PARTITIONING (1 << 3)
 #define CPUID3D_CRASH_MSRS (1 << 10)
 #define CPUID3D_SINT_POLLING (1 << 17)
+#define CPUID3D_STIMER_DIRECT_MODE (1 << 19)
 
 /* Viridian CPUID leaf 4: Implementation Recommendations. */
 #define CPUID4A_HCALL_REMOTE_TLB_FLUSH (1 << 2)
@@ -185,6 +186,8 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
             res->d |= CPUID3D_CRASH_MSRS;
         if ( viridian_feature_mask(d) & HVMPV_synic )
             res->d |= CPUID3D_SINT_POLLING;
+        if ( viridian_feature_mask(d) & HVMPV_stimer )
+            res->d |= CPUID3D_STIMER_DIRECT_MODE;
 
         break;
     }
Signature · 1 line
2.53.0
#8 lore raw

Re: [PATCH v1 2/2] x86/viridian: Implement synthetic timer direct mode

Quoted 3 lines · Ross Lagerwall

In direct mode, the timer asserts an interrupt on expiration rather than using a SynIC message. It is useful to implement this since Windows 11's Hyper-V can only use synthetic timers in direct mode.

Hello, is this new behavior compared to Server 2025? What happens if direct mode is not available, does it fall back to disabling stimer?

Quoted 81 lines

---

Should this use a new Viridian feature bit or is it OK to use the existing stimer bit?

  xen/arch/x86/hvm/viridian/time.c     | 25 +++++++++++++++++++------
  xen/arch/x86/hvm/viridian/viridian.c |  3 +++
  2 files changed, 22 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/viridian/time.c +19 -6
index 082528dc9416..2b0ac3eac963 100644
@@ -223,6 +223,14 @@ static void start_stimer(struct viridian_stimer *vs)
      set_timer(&vs->timer, timeout + NOW());
  }
 
+static void stimer_deliver_direct(struct vcpu *v, struct viridian_stimer *vs)
+{
+    struct vlapic *vlapic = vcpu_vlapic(v);
+
+    if ( vlapic_enabled(vlapic) )
+        vlapic_set_irq(vcpu_vlapic(v), vs->config.apic_vector, 0);
+}
+
  static void poll_stimer(struct vcpu *v, unsigned int stimerx)
  {
      struct viridian_vcpu *vv = v->arch.hvm.viridian;
@@ -242,9 +250,11 @@ static void poll_stimer(struct vcpu *v, unsigned int stimerx)
      if ( !test_bit(stimerx, &vv->stimer_pending) )
          return;
 
-    if ( !viridian_synic_deliver_timer_msg(v, vs->config.sintx,
-                                           stimerx, vs->expiration,
-                                           time_ref_count(v->domain)) )
+    if ( vs->config.direct_mode )
+        stimer_deliver_direct(v, vs);
+    else if ( !viridian_synic_deliver_timer_msg(v, vs->config.sintx,
+                                                stimerx, vs->expiration,
+                                                time_ref_count(v->domain)) )
          return;
 
      clear_bit(stimerx, &vv->stimer_pending);
@@ -372,7 +382,7 @@ int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
 
          vs->config.as_uint64 = val;
 
-        if ( !vs->config.sintx || !vs->count )
+        if ( (!vs->config.direct_mode && !vs->config.sintx) || !vs->count )
              vs->config.enable = 0;
 
          if ( vs->config.enable )
@@ -583,8 +593,11 @@ void viridian_time_load_vcpu_ctxt(
 
          vs->config.as_uint64 = ctxt->stimer_config_msr[i];
          vs->count = ctxt->stimer_count_msr[i];
-        if ( !vs->config.sintx || !vs->count )
-            /* Reject enabling with a zero sintx or count fields. */
+        if ( (!vs->config.direct_mode && !vs->config.sintx) || !vs->count )
+            /*
+             * Reject enabling with a zero sintx (if not using direct mode) or
+             * zero count field.
+             */
              vs->config.enable = 0;
      }
  }
xen/arch/x86/hvm/viridian/viridian.c +1 -0
index 90e749ceb581..99192e8d077d 100644
@@ -78,6 +78,7 @@ typedef union _HV_CRASH_CTL_REG_CONTENTS
  #define CPUID3D_CPU_DYNAMIC_PARTITIONING (1 << 3)
  #define CPUID3D_CRASH_MSRS (1 << 10)
  #define CPUID3D_SINT_POLLING (1 << 17)
+#define CPUID3D_STIMER_DIRECT_MODE (1 << 19)
 
  /* Viridian CPUID leaf 4: Implementation Recommendations. */
  #define CPUID4A_HCALL_REMOTE_TLB_FLUSH (1 << 2)

xen/arch/x86/hvm/viridian/viridian.c void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf, · line 193

Quoted 8 lines
xen/arch/x86/hvm/viridian/viridian.c +2 -0
@@ -185,6 +186,8 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
              res->d |= CPUID3D_CRASH_MSRS;
          if ( viridian_feature_mask(d) & HVMPV_synic )
              res->d |= CPUID3D_SINT_POLLING;
+        if ( viridian_feature_mask(d) & HVMPV_stimer )
+            res->d |= CPUID3D_STIMER_DIRECT_MODE;
 
          break;
      }

--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#9 lore raw

Re: [PATCH v1 2/2] x86/viridian: Implement synthetic timer direct mode

Quoted 7 lines · Tu Dinh
Quoted 3 lines · Ross Lagerwall

In direct mode, the timer asserts an interrupt on expiration rather than using a SynIC message. It is useful to implement this since Windows 11's Hyper-V can only use synthetic timers in direct mode.

Hello, is this new behavior compared to Server 2025? What happens if direct mode is not available, does it fall back to disabling stimer?

No, it's not new behaviour. According to Linux commit 8644f771e07c it has been this way since 2016. If direct mode is not available, the VM still works but without using synthetic timers.

Ross

#10 lore raw

Re: [PATCH v1 2/2] x86/viridian: Implement synthetic timer direct mode

In reply to Ross Lagerwall
Quoted 9 lines · Ross Lagerwall

In direct mode, the timer asserts an interrupt on expiration rather than using a SynIC message. It is useful to implement this since Windows 11's Hyper-V can only use synthetic timers in direct mode.

---

Should this use a new Viridian feature bit or is it OK to use the existing stimer bit?

Not sure there. What you need to deal with though are migration related aspects:
- A migrating-in guest should not suddenly see the CPUID bit set when it was clear before.
- As so far we don't even reject the .direct_mode bit to be set, it being set in any of the MSRs of an incoming, unaware guest needs to be taken care of (the guest must not suddenly get interrupts at the encoded .apic_vector).
Dealing with this may actually be easier with a new feature bit added.

xen/arch/x86/hvm/viridian/time.c static void start_stimer(struct viridian_stimer *vs) · line 226

Quoted 7 lines
xen/arch/x86/hvm/viridian/time.c +1 -0
@@ -223,6 +223,14 @@ static void start_stimer(struct viridian_stimer *vs)
     set_timer(&vs->timer, timeout + NOW());
 }
 
+static void stimer_deliver_direct(struct vcpu *v, struct viridian_stimer *vs)

Second parameter can be pointer-to-const.

xen/arch/x86/hvm/viridian/time.c static void start_stimer(struct viridian_stimer *vs) · line 231

Quoted 5 lines
xen/arch/x86/hvm/viridian/time.c +5 -0
+{
+    struct vlapic *vlapic = vcpu_vlapic(v);
+
+    if ( vlapic_enabled(vlapic) )
+        vlapic_set_irq(vcpu_vlapic(v), vs->config.apic_vector, 0);

Before you use the vector, you will want to check its validity (along the lines of the check that patch 1 aims to avoid in a special case). Whether that needs doing at the time the MSR is written by the guest or at the call site I don't
know: The (oldish) spec I'm looking at doesn't talk about validation of values written at all.

Also please don't re-invoke vcpu_vlapic() when you have already latched its result in a local variable.

Quoted 13 lines
xen/arch/x86/hvm/viridian/time.c +1 -1
@@ -372,7 +382,7 @@ int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
 
         vs->config.as_uint64 = val;
 
-        if ( !vs->config.sintx || !vs->count )
+        if ( (!vs->config.direct_mode && !vs->config.sintx) || !vs->count )
             vs->config.enable = 0;
 
         if ( vs->config.enable )
@@ -583,8 +593,11 @@ void viridian_time_load_vcpu_ctxt(
 
         vs->config.as_uint64 = ctxt->stimer_config_msr[i];
         vs->count = ctxt->stimer_count_msr[i];

xen/arch/x86/hvm/viridian/time.c void viridian_time_load_vcpu_ctxt( · line 603

Quoted 10 lines
xen/arch/x86/hvm/viridian/time.c +5 -2
-        if ( !vs->config.sintx || !vs->count )
-            /* Reject enabling with a zero sintx or count fields. */
+        if ( (!vs->config.direct_mode && !vs->config.sintx) || !vs->count )
+            /*
+             * Reject enabling with a zero sintx (if not using direct mode) or
+             * zero count field.
+             */
             vs->config.enable = 0;
     }
 }

Related to possible validation needs: Is it perhaps also required that .sintx be clear when .direct_mode is set?

Jan

#11 lore raw

Re: [PATCH v1 2/2] x86/viridian: Implement synthetic timer direct mode

Quoted 11 lines · Jan Beulich
Quoted 9 lines · Ross Lagerwall

In direct mode, the timer asserts an interrupt on expiration rather than using a SynIC message. It is useful to implement this since Windows 11's Hyper-V can only use synthetic timers in direct mode.

---

Should this use a new Viridian feature bit or is it OK to use the existing stimer bit?

Quoted 8 lines

Not sure there. What you need to deal with though are migration related aspects:
- A migrating-in guest should not suddenly see the CPUID bit set when it was clear before.
- As so far we don't even reject the .direct_mode bit to be set, it being set in any of the MSRs of an incoming, unaware guest needs to be taken care of (the guest must not suddenly get interrupts at the encoded .apic_vector).
Dealing with this may actually be easier with a new feature bit added.

OK, I'll add a new feature bit to handle this.

Quoted 37 lines

xen/arch/x86/hvm/viridian/time.c static void start_stimer(struct viridian_stimer *vs) · line 226

Quoted 8 lines
xen/arch/x86/hvm/viridian/time.c +1 -0
@@ -223,6 +223,14 @@ static void start_stimer(struct viridian_stimer *vs)
      set_timer(&vs->timer, timeout + NOW());
  }
 
+static void stimer_deliver_direct(struct vcpu *v, struct viridian_stimer *vs)

Second parameter can be pointer-to-const.

xen/arch/x86/hvm/viridian/time.c static void start_stimer(struct viridian_stimer *vs) · line 231

Quoted 5 lines
xen/arch/x86/hvm/viridian/time.c +5 -0
+{
+    struct vlapic *vlapic = vcpu_vlapic(v);
+
+    if ( vlapic_enabled(vlapic) )
+        vlapic_set_irq(vcpu_vlapic(v), vs->config.apic_vector, 0);

Before you use the vector, you will want to check its validity (along the lines of the check that patch 1 aims to avoid in a special case). Whether that needs doing at the time the MSR is written by the guest or at the call site I don't
know: The (oldish) spec I'm looking at doesn't talk about validation of values written at all.

Also please don't re-invoke vcpu_vlapic() when you have already latched its result in a local variable.

Quoted 11 lines
xen/arch/x86/hvm/viridian/time.c +1 -1
@@ -372,7 +382,7 @@ int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
 
          vs->config.as_uint64 = val;
 
-        if ( !vs->config.sintx || !vs->count )
+        if ( (!vs->config.direct_mode && !vs->config.sintx) || !vs->count )
              vs->config.enable = 0;
 
          if ( vs->config.enable )
@@ -583,8 +593,11 @@ void viridian_time_load_vcpu_ctxt(
 
Quoted 15 lines

xen/arch/x86/hvm/viridian/time.c void viridian_time_load_vcpu_ctxt( · line 603

Quoted 12 lines
xen/arch/x86/hvm/viridian/time.c +5 -2
          vs->config.as_uint64 = ctxt->stimer_config_msr[i];
          vs->count = ctxt->stimer_count_msr[i];
-        if ( !vs->config.sintx || !vs->count )
-            /* Reject enabling with a zero sintx or count fields. */
+        if ( (!vs->config.direct_mode && !vs->config.sintx) || !vs->count )
+            /*
+             * Reject enabling with a zero sintx (if not using direct mode) or
+             * zero count field.
+             */
              vs->config.enable = 0;
      }
  }

Related to possible validation needs: Is it perhaps also required that .sintx be clear when .direct_mode is set?

The relevant part from the most recent published version of the spec [1] says:

"""
It is not permitted to set the SINTx field to zero for an enabled timer (that is not in direct mode). If attempted, the timer will be marked disabled (that is, bit 0 cleared) immediately.
"""

It doesn't say anything about validating the APIC vector or disallowing other combinations of input. However, it seems sensible to do that so I will, with the same behaviour of disabling the timer on failure.

[1] https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/timers

Ross