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

Re: [PATCH v4 26/30] x86/svm: clear the VMCB clean bits in svm_ctxt_switch_from()


  • To: George Dunlap <gwd@xxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Wed, 21 Oct 2026 10:21: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=ecPqRTo6wtPnw6acd6o+so58GA5o9FPZgWSVeoey6Lk=; b=dpYRF4RtJw9C2jEHW3FY+ri6Z8IgKl9mnHYyOSAxqtMTlVLwYLAegUYe966WQ1a+Q0oYbDpcoInBmAKmIrbJ7BkSBcUQLXhlqtyKFGtjvTGneW4/cvy69wZNdV6q06BGv2l0DA96wA2oEdwx7cAK2KJYY7fB7Sar89DnGO4dAKYWoMHt/lKwaYKBFandCqHdcQVQEWxWXpUk1P8kwOCg8fcBNUMSW9VWqRLzo+L5U257Wlf8BbL4qoiLepRhSdAMjRA6FlpD4WhzGV5i0KMMRHpnI2XFKSM0ImPwvlnkNwOlMCzvvhDrtTT5KdJByBzivMhjXT1RW/KJh9M2tUqhbA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iVKTI+8SpbFrwmss/cDlULIjId7C1sUAcae4ZueQHn/QGn9aXgGNGoP9zeqTXUqJHC8RS6f7z4bZ3UdRHeUIDktNWEHQ/0fPNTGQNlvT1WSSvfrUqs/AS3SMxAyEj9nSHNQuek51Tmb0NNRM1wW+VgsZ00iAQikfLuW+r+CuC6x13cdEm8rp3b/FjSHRQZM3R7l/2OZIftd11vPFQbp28DQZUVmyTCdj53Vx6NrYhTtCw441occNrTpL4e5bLTaaTA+qw/BymZwWGrnqXrep43dq2pz6E+aKX26O9icOcHagc2cX/qkC8wKVFx4LS/xn/YJeoPScpp5ja6SMnhTzjw==
  • 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: mx.microsoft.com 1; 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>, Jason Andryuk <jason.andryuk@xxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Wed, 21 Oct 2026 09:22:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 10/19/26 8:42 PM, George Dunlap wrote:
A VMCB's clean bits must all be clear when its vCPU next runs after a
deschedule, as other VMCBs run on the pCPU in the meantime.
svm_ctxt_switch_to() clears them as the vCPU is scheduled in; clear them
in svm_ctxt_switch_from() instead, as it is scheduled out.

This is equivalent.  While the vCPU is descheduled, accessors reaching
its VMCB only ever clear clean bits: svm_vmexit_handler(), which sets
them all, runs only in the vCPU's own context.  So do the nested-SVM
paths that change the active VMCB, nsvm_vcpu_hostrestore() and
nsvm_vcpu_vmentry(), and they clear the incoming VMCB's clean bits
themselves.

This prepares for moving VMCBs off always-mapped memory:
svm_ctxt_switch_to() runs before write_ptbase(), where the incoming
vCPU's VMCB will not be mapped.

Assisted-by: Claude Code:claude-fable-5, Claude Code:claude-opus-5-5
Signed-off-by: George Dunlap <gwd@xxxxxxxxxxxxxx>
---
Changes in v4:
- New in this version.
---
  xen/arch/x86/hvm/svm/svm.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 241843d8c0..4e19df9865 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -919,6 +919,8 @@ static void cf_check svm_ctxt_switch_from(struct vcpu *v)
      svm_save_dr(v);
      svm_tsc_ratio_save(v);
+ v->arch.hvm.svm.vmcb->cleanbits.raw = 0;
+
      svm_sync_vmcb(v, vmcb_needs_vmload);
      svm_vmload_pa(per_cpu(host_vmcb, cpu));
@@ -938,7 +940,6 @@ static void cf_check svm_ctxt_switch_from(struct vcpu *v) static void cf_check svm_ctxt_switch_to(struct vcpu *v)
  {
-    struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;
      int cpu = smp_processor_id();
/*
@@ -956,7 +957,6 @@ static void cf_check svm_ctxt_switch_to(struct vcpu *v)
svm_restore_dr(v); - vmcb->cleanbits.raw = 0;
      svm_tsc_ratio_load(v);
if ( cpu_has_msr_tsc_aux )

FYI I posted "x86/svm: Don't clear clean bits on every context switch" a few
weeks ago which moves it into svm_do_resume(). I think that is preferable for
the reasons mentioned in the patch and IIUC would still be after the vCPU's
VMCB is mapped.

Ross



 


Rackspace

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