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

[PATCH v1 1/2] x86/nestedsvm: Handle CR8 accesses with V_INTR_MASKING=0 correctly


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Fri, 20 Nov 2026 16:35:02 +0000
  • 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=yTeqJmnCBhEKJWbkrtvtJBnxbAcpt2zFU1Mn89XlmXw=; b=YyRWlgB95358Lgci9hzrVYbOV5OB9d9MkCzGerxCrROMhdbAwMTRvz5uwW9GnuWBLUPNhyu+M4gsji/xM1NSWhwka82/Pch9/b/nWytxAHmcWghclEiK+KSGzbF+bOukpPEJzyUTfEW396O35V2ARyAKi9WVdSfLQmaC31TX2xz1JrUrJBprOmR5OgW8BJFVb17tnzw804enqckK8O8N38nWnM5Ct+RPASMlRUgyZN9iR5/pf4uF7goXWRa6PreZUpLyzBOuPNsOxFVreCwJ04kIlM/wqHSNZt8mukS6jg1cev5W82XOibwlk72ZKLW6QTWW0ktitdQfHU0CQ2da3g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XlOrN7Kcp8XU9vWbbmeavx7nIDsAMmzMevGNQk6UP5vHx8xwV5KJEoJnJRWuZ8H24tND779rDkuE3vrHySvmJ4vZn1P4HrcqghHlMhSnoHqrLf/gGZ6SvED7bOdjJS2d3Upr29MFoZI3HsIx3j3cBKi1yNAEjY6rYrX8IaAU2c8xECumfFt39h2wYgcEjAGOKKZfjD4Bw2G23eYr0UqqI9gtx0HM5W0eDqDrzwKn3ZXQ7j1d93PCocuMpYRrIT/a15LJZcnlUJcTZUOE248QvwRWiQsYag5zgzS36CwCoHRaacSWkwkzzfF6lZZmuKo7FdHAeFp3KZL+Q+1JtcMZIA==
  • 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: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Fri, 20 Nov 2026 16:36:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

When V_INTR_MASKING=0, reads return the value in the APIC TPR and writes
update the value in the APIC TPR and the V_TPR.

To implement this for Nested SVM, intercept reads and writes of CR8 when
V_INTR_MASKING=0. For reads, simply return the value in Xen's emulated
APIC. For writes, update the value in the emulated APIC as well as
VMCB(0-2)'s V_TPR.

Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---
 xen/arch/x86/hvm/emulate.c       |  1 +
 xen/arch/x86/hvm/hvm.c           |  1 +
 xen/arch/x86/hvm/svm/nestedsvm.c |  3 +++
 xen/arch/x86/hvm/svm/svm.c       | 30 ++++++++++++++++++------------
 xen/arch/x86/hvm/vmx/vmx.c       |  4 ++++
 5 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index cd2831d34b44..57e1fa7e5a2a 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -2376,6 +2376,7 @@ static int cf_check hvmemul_write_cr(
         }
 
         vlapic_set_reg(vcpu_vlapic(curr), APIC_TASKPRI, val << 4);
+        hvm_update_guest_cr(curr, 8);
         rc = X86EMUL_OKAY;
         break;
 
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 4334ff678d34..6a2a76339be1 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2205,6 +2205,7 @@ int hvm_mov_to_cr(unsigned int cr, unsigned int gpr)
 
     case 8:
         vlapic_set_reg(vcpu_vlapic(curr), APIC_TASKPRI, ((val & 0x0f) << 4));
+        hvm_update_guest_cr(curr, cr);
         rc = X86EMUL_OKAY;
         break;
 
diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 366178ff54a7..eeb9363dc061 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -394,6 +394,9 @@ static int nsvm_vmcb_prepare4vmrun(struct vcpu *v, struct 
cpu_user_regs *regs)
 
     n2vmcb->_cr_intercepts =
         n1vmcb->_cr_intercepts | ns_vmcb->_cr_intercepts;
+    if ( !svm->ns_hostflags.vintrmask )
+        n2vmcb->_cr_intercepts |=
+            CR_INTERCEPT_CR8_READ | CR_INTERCEPT_CR8_WRITE;
     n2vmcb->_dr_intercepts =
         n1vmcb->_dr_intercepts | ns_vmcb->_dr_intercepts;
     n2vmcb->_exception_intercepts =
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index bfca1eda4af5..1043f4a988a8 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -104,6 +104,15 @@ static void cf_check svm_cpu_down(void)
     write_efer(read_efer() & ~EFER_SVME);
 }
 
+static void svm_update_tpr(struct vmcb *vmcb, struct vlapic *vlapic)
+{
+    /* Reflect the vlapic's TPR in the hardware vtpr */
+    vintr_t intr = vmcb_get_vintr(vmcb);
+
+    intr.tpr = (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
+    vmcb_set_vintr(vmcb, intr);
+}
+
 static void cf_check svm_update_guest_cr(
     struct vcpu *v, unsigned int cr, unsigned int flags)
 {
@@ -170,6 +179,13 @@ static void cf_check svm_update_guest_cr(
 
         vmcb_set_cr4(vmcb, value);
         break;
+
+    case 8:
+        if ( nestedhvm_vcpu_in_guestmode(v) &&
+             !vcpu_nestedsvm(v).ns_hostflags.vintrmask )
+            svm_update_tpr(vmcb, vcpu_vlapic(v));
+        break;
+
     default:
         BUG();
     }
@@ -959,14 +975,7 @@ static void noreturn cf_check svm_do_resume(void)
     }
 
     if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) )
-    {
-        vintr_t intr;
-
-        /* Reflect the vlapic's TPR in the hardware vtpr */
-        intr = vmcb_get_vintr(vmcb);
-        intr.tpr = (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
-        vmcb_set_vintr(vmcb, intr);
-    }
+        svm_update_tpr(vmcb, vlapic);
 
     hvm_do_resume(v);
 
@@ -3069,10 +3078,7 @@ void asmlinkage svm_vmexit_handler(void)
     if ( vcpu_guestmode || vlapic_hw_disabled(vlapic) )
         return;
 
-    /* The exit may have updated the TPR: reflect this in the hardware vtpr */
-    intr = vmcb_get_vintr(vmcb);
-    intr.tpr = (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
-    vmcb_set_vintr(vmcb, intr);
+    svm_update_tpr(vmcb, vlapic);
 }
 
 /*
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 3c7374a9ff42..53d50a1bb329 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1874,6 +1874,10 @@ static void cf_check vmx_update_guest_cr(
             hvm_asid_flush_vcpu(v);
         break;
 
+    case 8:
+        /* Nothing to do */
+        break;
+
     default:
         BUG();
     }
-- 
2.56.0




 


Rackspace

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