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

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


  • To: Roger Pau Monné <roger@xxxxxxxxxxxxxx>
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Wed, 9 Sep 2026 11:59:28 +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=iRRatVfPlabWz6C1vuH5L6jVfQWHxAF+090Hq+u2EU0=; b=k2X49mm+KFPADahN2u9xHRIau85JKfxZ+VY60YjSn2Nl96GPYZxG0jSvJhyLD1Yo5WAw8+K8cuzd3/mcAFiOpSlIi7N8ZO2gWw1ErBswrNWDFb1zeA2jd9t1GZeRyr+b9MlCaYKZOkQfixCavEsJJJT99s27LVu0S2QBVzWUUba7tKS3APLPRSs2HvoiXfi1qXBphFmvUOD4zxaoTmw6iZKX5s0DU3D4q8165dzHYmu3PKAH3ULFlXpeYhJFxKBRb9E2xchM2h1iL6v2PDV+oYKlt3XGVIhifFtGMBhFX1/Q0V4yJofJjGVAxBu9YMzbfZUZJHFJtTebeYavkbrTyQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q87JX48OZP1hyS3ReEUuAUmZnfFZl0CxzYkcgxHaLCwZgu8A4g+WJ7wQJ5eDqv5Z+0UW4TvoTLaDSzf8J5cdMeyJOh9r1Stmbqhz+IlJTqkiKp7v09vBNBy0uChluQV/5to6VcJEgcPGmOXkp6DyJV6pNhRjDziEGND9/Sp5Lkvuifm54PJsEgZniBN1p/RRyLkhNeE3+yzi2+u2W8sVjtzHjqRllMzLf2v6Jt8oh3oPE07PHL6Wb7g5NFm7KiUHHyGjreFgrNmcelduVoxnyD3Ie90/DyYcGEULqWVRXD7NXVj9oBL574UCSEezGAtlLa6eZxywiK9H8cME2VT4/w==
  • 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: xen-devel@xxxxxxxxxxxxxxxxxxxx, Paul Durrant <paul@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Wed, 09 Sep 2026 10:59:48 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 9/4/26 4:15 PM, Roger Pau Monné wrote:
On Fri, Sep 04, 2026 at 03:15:15PM +0100, 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>
---

In v2:

* Handle migration from older Xen by introducing a new Viridian flag.
* Added more sanity checks during MSR write and vCPU context load.

  xen/arch/x86/hvm/viridian/time.c     | 46 ++++++++++++++++++++++++----
  xen/arch/x86/hvm/viridian/viridian.c |  3 ++
  xen/include/public/hvm/params.h      |  7 ++++-
  3 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/hvm/viridian/time.c b/xen/arch/x86/hvm/viridian/time.c
index 082528dc9416..4c8352612b19 100644
--- 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, const struct viridian_stimer *vs)
+{
+    struct vlapic *vlapic = vcpu_vlapic(v);
+
+    if ( vlapic_enabled(vlapic) )
+        vlapic_set_irq(vlapic, 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);
@@ -361,6 +371,7 @@ int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, 
uint64_t val)
      case HV_X64_MSR_STIMER2_CONFIG:
      case HV_X64_MSR_STIMER3_CONFIG:
      {
+        union hv_stimer_config new;
          unsigned int stimerx = (idx - HV_X64_MSR_STIMER0_CONFIG) / 2;
          struct viridian_stimer *vs =
              &array_access_nospec(vv->stimer, stimerx);
@@ -368,11 +379,18 @@ int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, 
uint64_t val)
          if ( !(viridian_feature_mask(d) & HVMPV_stimer) )
              return X86EMUL_EXCEPTION;
+ new.as_uint64 = val;
+        if ( new.direct_mode &&
+             !(viridian_feature_mask(d) & HVMPV_stimer_direct) )
+            return X86EMUL_EXCEPTION;

Do we know whether native HyperV also injects a #GP in case of setting
reserved bits on the register?

I did some investigation into Hyper-V's behaviour (W11 26H1) since the spec
doesn't say anything about it:

Reserved bits set                  => GP fault
Direct=1 SINTx=any ApicVector<16   => GP fault
Direct=1 SINTx=any ApicVector=any  => SINTx appears to be ignored
Direct=0 SINTx=any ApicVector>0    => GP fault
Direct=0 SINTx=0   ApicVector=0    => sets Enabled=0

I'll update the patch accordingly.


To keep the previous behavior, should Xen silently ignore the setting
when not supported, like it did in the past?

OK. Unless someone objects, I'll still perform the new checks for reserved bits
and the ApicVector set while Direct=0 case even if the stimer_direct flag is
not present.

Ross



 


Rackspace

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