diff mbox series

x86/debug: Move activate_debugregs() into debug.c

Message ID 20250314180750.73925-1-andrew.cooper3@citrix.com (mailing list archive)
State New
Headers show
Series x86/debug: Move activate_debugregs() into debug.c | expand

Commit Message

Andrew Cooper March 14, 2025, 6:07 p.m. UTC
We have since gained a better location for it to live.

Fix up the includes while doing so.  I don't recall why we had kernel.h but
it's definitely stale now.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/debug.c | 35 ++++++++++++++++++++++++++++++++++-
 xen/arch/x86/traps.c | 32 --------------------------------
 2 files changed, 34 insertions(+), 33 deletions(-)
diff mbox series

Patch

diff --git a/xen/arch/x86/debug.c b/xen/arch/x86/debug.c
index e99e663ba5b9..71755dea6ff2 100644
--- a/xen/arch/x86/debug.c
+++ b/xen/arch/x86/debug.c
@@ -3,10 +3,11 @@ 
  * Copyright (C) 2023 XenServer.
  */
 #include <xen/bug.h>
-#include <xen/kernel.h>
+#include <xen/sched.h>
 
 #include <xen/lib/x86/cpu-policy.h>
 
+#include <asm/current.h>
 #include <asm/debugreg.h>
 
 /*
@@ -84,3 +85,35 @@  unsigned int x86_adj_dr7_rsvd(const struct cpu_policy *p, unsigned int dr7)
 
     return dr7;
 }
+
+void activate_debugregs(const struct vcpu *curr)
+{
+    ASSERT(curr == current);
+
+    write_debugreg(0, curr->arch.dr[0]);
+    write_debugreg(1, curr->arch.dr[1]);
+    write_debugreg(2, curr->arch.dr[2]);
+    write_debugreg(3, curr->arch.dr[3]);
+    write_debugreg(6, curr->arch.dr6);
+
+    /*
+     * Avoid writing the subsequently getting replaced value when getting
+     * called from set_debugreg() below. Eventual future callers will need
+     * to take this into account.
+     */
+    if ( curr->arch.dr7 & DR7_ACTIVE_MASK )
+        write_debugreg(7, curr->arch.dr7);
+
+    /*
+     * Both the PV and HVM paths leave stale DR_MASK values in hardware on
+     * context-switch-out.  If we're activating %dr7 for the guest, we must
+     * sync the DR_MASKs too, whether or not the guest can see them.
+     */
+    if ( boot_cpu_has(X86_FEATURE_DBEXT) )
+    {
+        wrmsrl(MSR_AMD64_DR0_ADDRESS_MASK, curr->arch.msrs->dr_mask[0]);
+        wrmsrl(MSR_AMD64_DR1_ADDRESS_MASK, curr->arch.msrs->dr_mask[1]);
+        wrmsrl(MSR_AMD64_DR2_ADDRESS_MASK, curr->arch.msrs->dr_mask[2]);
+        wrmsrl(MSR_AMD64_DR3_ADDRESS_MASK, curr->arch.msrs->dr_mask[3]);
+    }
+}
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 5addb1f903d3..df1155bfb673 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -1942,38 +1942,6 @@  void __init trap_init(void)
     cpu_init();
 }
 
-void activate_debugregs(const struct vcpu *curr)
-{
-    ASSERT(curr == current);
-
-    write_debugreg(0, curr->arch.dr[0]);
-    write_debugreg(1, curr->arch.dr[1]);
-    write_debugreg(2, curr->arch.dr[2]);
-    write_debugreg(3, curr->arch.dr[3]);
-    write_debugreg(6, curr->arch.dr6);
-
-    /*
-     * Avoid writing the subsequently getting replaced value when getting
-     * called from set_debugreg() below. Eventual future callers will need
-     * to take this into account.
-     */
-    if ( curr->arch.dr7 & DR7_ACTIVE_MASK )
-        write_debugreg(7, curr->arch.dr7);
-
-    /*
-     * Both the PV and HVM paths leave stale DR_MASK values in hardware on
-     * context-switch-out.  If we're activating %dr7 for the guest, we must
-     * sync the DR_MASKs too, whether or not the guest can see them.
-     */
-    if ( boot_cpu_has(X86_FEATURE_DBEXT) )
-    {
-        wrmsrl(MSR_AMD64_DR0_ADDRESS_MASK, curr->arch.msrs->dr_mask[0]);
-        wrmsrl(MSR_AMD64_DR1_ADDRESS_MASK, curr->arch.msrs->dr_mask[1]);
-        wrmsrl(MSR_AMD64_DR2_ADDRESS_MASK, curr->arch.msrs->dr_mask[2]);
-        wrmsrl(MSR_AMD64_DR3_ADDRESS_MASK, curr->arch.msrs->dr_mask[3]);
-    }
-}
-
 void asm_domain_crash_synchronous(unsigned long addr)
 {
     /*