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

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


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Fri, 4 Sep 2026 13:40:38 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FTyGvNtPrZrovxMyhWZqvh1nAydJSiP93/UkRdaZr4A=; b=Dnk6zXgjyHo5f+UkPJ3jWaW1JAITyd9KpsPcB9sWxWxCfvTI47ZwlWmgFBGQ0kSLScoDeUZgEIviMa0t5y6pAgMhuzYvREJZC+boLlWHpYGDPMhn1L2cd9uMCOzCbJlNRqCHtV0y592nb6/XSX1IjF6OwYQOUUbLJiG7kryPFCRH46b0a2/M0iDPcrNOp8gi91FSB4qLzx/rGibw95iSQhxKGe0YRkU38INy2T6DkCWFaCWxX+Ruz/z6UvJU73nXNyS+571ENFNwS0lDILUfHrTP7FCDOUoW2RKHaXDkhaMA0sAc62tUngnifo9KVU69igxw9D515HHfmYfvoiAWow==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L1/sHFfD0dFVDIsc/0+z5kgENWb3b43gM7hldhRgAqrUKeG2j81RW1YPx7y71MWsVwGJe7bqVRPL2CEzuURQ59/cZoQmV5xeyI7znvHm02I7NV98CfO0zGxKtCGvSACRIqK4Llnw6X55TT74Y9CrTPzv1GcnUBuREpIe62tYaUwP1zae5TFrGWdErtRCt11k2SB4UZof7c36pb7C1bQXUDekAMla/8UI4OQmd7PyNOVoIaANFNr9bpvO/qXO/DceUzlmRS1oabHgb0KFCKDx67Vge2SFMkDpVNAV5E8c/HUqaVurcZwoh+YqbmERjszqadjJrIq59R3ExR9dmSqAxQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Paul Durrant <paul@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Fri, 04 Sep 2026 12:41:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 9/3/26 12:12 PM, Jan Beulich wrote:
On 28.08.2026 15:11, Ross Lagerwall wrote:
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.

Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---

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.

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


--- a/xen/arch/x86/hvm/viridian/time.c
+++ b/xen/arch/x86/hvm/viridian/time.c
@@ -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.

+{
+    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.

@@ -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;
      }
  }
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



 


Rackspace

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