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

[PATCH v1 11/28] x86/hvm: introduce vcpu_is_vlapic_tpr_emulated()


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: dmukhin@xxxxxxxx
  • Date: Wed, 4 Nov 2026 17:33:28 -0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 205.220.161.53) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=ford.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ford.com; dkim=pass (signature was verified) header.d=saarlouis.ford.com; dkim=pass (signature was verified) header.d=ford.com; arc=none (0)
  • 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=epfnUdbtf7rNlmst+lBbQXBN+HCXSuGOjupcOfOOzY4=; b=iehks+zFxJF8zdie0EFxDD+xkTmI3/WfryQlTP0pgf9L3zR2yegmjPgXz8MagV6GmMb1lPfgYT0M0XCkepUjyGQfD0/vDqbqzu+O/yngXlJ8nNmyvkWtUIRAHdg80+qvzRwr+QHWOrnfexPTBt11oi0CQlVeCzgqtvHwg0F6jEaY/NmQHnjENKURWN6FrM60mHPu777l3RE4ZdEOkiJNmg1+OfjfZUaLG/naY/r0ps3WwLVpoMoSEezYWImzOdWHD/1nO0MfXD/bzsSjZSfOTeoDZVpkrEITLgYA53o4GuH+PVZPHkBt3g2NCd1pZfMmy7+674xmOk+4+N1Jyily+w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ldgb/Fn1VnCien9g6i4NduTptysqtsvs0FxdX/Ek8a3LHzdwetIO5kc098beW3SWF37Vu9w8ZBPFR5j3nW1Jh88c1DWTTUgRRENiy1YwpO9RJB1V27xSd5GBJAmiZ+Mtux3j6uz1Z6O8VgNMaLMwuJiENmtRq7DCHftHjY8mE4ViV4PHAFrWCmPGH+2mX8sHkV4XnQiWMdVclr3r7sEKJdLcdxrTatMyIL6P02In2mn3ccmBiIlHSHwNKHw8Ouq+Vh86lANaNRSvVWxnF3l+JGylt5hrUitfsD46OSDNym5GATjdpDZrsCV7+qx+8duW7Hmi83LKq2wqC40lNTklBg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=ppford header.d=ford.com header.i="@ford.com" header.h="Cc:Content-Transfer-Encoding:Content-Type:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"; dkim=pass header.s=selector2-azureford-onmicrosoft-com header.d=azureford.onmicrosoft.com header.i="@azureford.onmicrosoft.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=ppserprodsaar header.d=saarlouis.ford.com header.i="@saarlouis.ford.com" header.h="Cc:Content-Transfer-Encoding:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"; dkim=pass header.s=ppfserpocford header.d=ford.com header.i="@ford.com" header.h="Cc:Content-Transfer-Encoding:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"
  • Cc: andrew.cooper3@xxxxxxxxxx, jason.andryuk@xxxxxxx, jbeulich@xxxxxxxx, roger@xxxxxxxxxxxxxx, teddy.astie@xxxxxxxxxx, dmukhin@xxxxxxx, Denis Mukhin <dmukhin@xxxxxxxx>
  • Delivery-date: Thu, 05 Nov 2026 01:34:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Pser-m365-app: SER-APP

From: Denis Mukhin <dmukhin@xxxxxxxx>

Introduce vcpu_is_vlapic_tpr_emulated() in genetic SVM code to account
for the case when platform provides accelerated access to vLAPIC's TPR.

Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
 xen/arch/x86/hvm/svm/svm.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 673c818a0039..14a86ca4ff8f 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -925,6 +925,19 @@ static void cf_check svm_ctxt_switch_to(struct vcpu *v)
     }
 }
 
+static bool vcpu_is_vlapic_tpr_emulated(const struct vcpu *v, bool 
force_noaccel)
+{
+    const struct vlapic *vlapic = vcpu_vlapic(v);
+
+    if ( force_noaccel )
+        return false;
+
+    if ( vlapic_hw_disabled(vlapic) )
+        return false;
+
+    return true;
+}
+
 static void noreturn cf_check svm_do_resume(void)
 {
     struct vcpu *v = current;
@@ -933,7 +946,6 @@ static void noreturn cf_check svm_do_resume(void)
                         v->domain->arch.monitor.software_breakpoint_enabled ||
                         v->domain->arch.monitor.debug_exception_enabled);
     bool vcpu_guestmode = false;
-    struct vlapic *vlapic = vcpu_vlapic(v);
 
     if ( nestedhvm_enabled(v->domain) && nestedhvm_vcpu_in_guestmode(v) )
         vcpu_guestmode = 1;
@@ -959,8 +971,9 @@ static void noreturn cf_check svm_do_resume(void)
         vmcb->cleanbits.raw = 0;
     }
 
-    if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) )
+    if ( vcpu_is_vlapic_tpr_emulated(v, vcpu_guestmode) )
     {
+        struct vlapic *vlapic = vcpu_vlapic(v);
         vintr_t intr;
 
         /* Reflect the vlapic's TPR in the hardware vtpr */
@@ -2538,7 +2551,6 @@ void asmlinkage svm_vmexit_handler(void)
     int insn_len;
     vintr_t intr;
     bool vcpu_guestmode = false;
-    struct vlapic *vlapic = vcpu_vlapic(v);
 
     regs->rax = vmcb->rax;
     regs->rip = vmcb->rip;
@@ -2565,8 +2577,10 @@ void asmlinkage svm_vmexit_handler(void)
      * NB. We need to preserve the low bits of the TPR to make checked builds
      * of Windows work, even though they don't actually do anything.
      */
-    if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) )
+    if ( vcpu_is_vlapic_tpr_emulated(v, vcpu_guestmode) )
     {
+        struct vlapic *vlapic = vcpu_vlapic(v);
+
         intr = vmcb_get_vintr(vmcb);
         vlapic_set_reg(vlapic, APIC_TASKPRI,
                    ((intr.fields.tpr & 0x0F) << 4) |
@@ -3097,14 +3111,16 @@ void asmlinkage svm_vmexit_handler(void)
     }
 
   out:
-    if ( vcpu_guestmode || vlapic_hw_disabled(vlapic) )
-        return;
+    if ( vcpu_is_vlapic_tpr_emulated(v, vcpu_guestmode ) )
+    {
+        struct vlapic *vlapic = vcpu_vlapic(v);
 
-    /* The exit may have updated the TPR: reflect this in the hardware vtpr */
-    intr = vmcb_get_vintr(vmcb);
-    intr.fields.tpr =
-        (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
-    vmcb_set_vintr(vmcb, intr);
+        /* The exit may have updated the TPR: reflect this in the hardware 
vtpr */
+        intr = vmcb_get_vintr(vmcb);
+        intr.fields.tpr =
+            (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
+        vmcb_set_vintr(vmcb, intr);
+    }
 }
 
 /*
-- 
2.55.0




 


Rackspace

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