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

Re: [RFC PATCH v2 3/5] x86: Track vcpu context switches and introduce needs_tlb_flush field


  • To: Teddy Astie <teddy.astie@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Fri, 18 Sep 2026 14:48:35 +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=iSvoD2QhDS7LRDfKxNZb6FGqDEVd/0RqYV2zQj9z1YU=; b=l3DKRq2D34QFWU5SzXTzr18IrCHUZbW3/dfGn8AcRfFMREjUYxI7Ca/M3fcDNoL2SPQpU/jv1ddgIeBoJagfteL3TfwnbBFASmcjxrgJITmcQYxLt/i1R2dXdpKaiHpnRxEStGmqi16+eJzXeWFoJACLfAz7giywR9IObGBiP0KUk29yjGkNYSIib0GbvWNArmxwVjZG3DzdpogkcJmOX2kxFnYZdCx8gSK59d2q5ZOtoBWXw7MjdXMM+8Hyn8WERYdaYVZuWUbr3OFKeBMaWBIUmxAE+v2Vd7mXgi69dXy6uU+NdJ3fu6reOOGh1m2SzZ/Ztot3VQB/xoWEv5+T3A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fYi63ZaEttOFVb2RmS1acD1WLf9u2N2dGQ5EWgQJzHdgXSAzRPq8Owpm3YTSbLXKfkbhioap5D11FyjX+B93EI3EzmJMIjj1PzTLo+a3xaXWbOYEKYgEU/ZLxn0Axr9POM6OtLweq9yAHcy71euQ4ENVqRMejwbyHyUyXBvypDKeGQKWAnNAVRr5djqr6AAdPA9sAzPu9LbTQSLq0hfl293cfjmysSZD9PXHKPiyp3tzyOf8CJPa8LuRF1+4MSOikKvntV06k9AXdBsKSqIJiR7rjsUii1XIXIWNAln31KzKpCFf+FgjbSxSNWhZsCzaEvzTM/1wiJx2vqRWT4POGQ==
  • 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: Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>
  • Delivery-date: Fri, 18 Sep 2026 13:48:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 7/31/26 3:46 PM, Teddy Astie wrote:
Introduce needs_tlb_flush that indicate that the vCPU related TLB
needs to be flushed before entering this domain. This is intended
to be used later for using the same ASID for all vCPU of a domain.

Also track vCPU context switch to determine :
  - per vcpu "latest_cpu" that tracks which pCPU last ran this vCPU,
    this is used to know whether our current TLB (of our pCPU) state
    is stale.
    Schedule a TLB flush if the vCPU ran on another pCPU previously.
  - per pCPU "latest_vcpu" (per domain) that tracks which vCPU the
    TLB+ASID/VPID is holding onto.
    Schedule a TLB flush if this pCPU hasn't ran this vCPU previously
    (which can happen if we context-switch multiples vCPUs of a same
    domain on a same pCPU).

If ASID use is disabled, unconditionnaly perform a TLB flush.

Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
v2: Merge several patches into one, move logic to context_switch(),
     move fields to arch_vcpu/arch_domain, consider !asid_enabled case.
---
  xen/arch/x86/domain.c             | 26 ++++++++++++++++++++++++++
  xen/arch/x86/include/asm/domain.h |  6 ++++++
  2 files changed, 32 insertions(+)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 996b50af7a..27155546ca 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -38,6 +38,7 @@
  #include <xen/smp.h>
  #include <xen/softirq.h>
  #include <xen/wait.h>
+#include <xen/xvmalloc.h>
#include <asm/amd.h>
  #include <asm/cpu-policy.h>
@@ -874,6 +875,13 @@ int arch_domain_create(struct domain *d,
spec_ctrl_init_domain(d); + rc = -ENOMEM;
+    d->arch.latest_vcpu = xvmalloc_array(int, nr_cpu_ids);

Does this work with pCPU hotplug or do you need to use NR_CPUS?

+    if ( !d->arch.latest_vcpu )
+        goto fail;
+    for (unsigned int i = 0; i < nr_cpu_ids; i++)
+        d->arch.latest_vcpu[i] = -1;
+

The other arches define INVALID_VCPU_ID to be MAX_VIRT_CPUS. Not sure if it is
worth doing the same for x86?

Ross



 


Rackspace

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