Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 May 2021 00:39:05 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: b847aca56c2b - stable/12 - x86: add x86_clear_dbregs() helper
Message-ID:  <202105010039.1410d5X6048144@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=b847aca56c2b252bd68f63d142473bbdf1f71429

commit b847aca56c2b252bd68f63d142473bbdf1f71429
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-04-09 23:19:23 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-05-01 00:38:29 +0000

    x86: add x86_clear_dbregs() helper
    
    (cherry picked from commit a8b75a57c9b2cb3388746f097a55086a0f8c5d38)
---
 sys/amd64/amd64/machdep.c | 50 +++++++++++++++++++++++++++--------------------
 sys/i386/i386/machdep.c   | 50 +++++++++++++++++++++++++++--------------------
 sys/x86/include/x86_var.h |  1 +
 3 files changed, 59 insertions(+), 42 deletions(-)

diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 2400d130ac0c..1e663382f140 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -588,6 +588,34 @@ freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
 }
 #endif
 
+/*
+ * Reset the hardware debug registers if they were in use.
+ * They won't have any meaning for the newly exec'd process.
+ */
+void
+x86_clear_dbregs(struct pcb *pcb)
+{
+	if ((pcb->pcb_flags & PCB_DBREGS) == 0)
+		return;
+
+	pcb->pcb_dr0 = 0;
+	pcb->pcb_dr1 = 0;
+	pcb->pcb_dr2 = 0;
+	pcb->pcb_dr3 = 0;
+	pcb->pcb_dr6 = 0;
+	pcb->pcb_dr7 = 0;
+
+	if (pcb == curpcb) {
+		/*
+		 * Clear the debug registers on the running CPU,
+		 * otherwise they will end up affecting the next
+		 * process we switch to.
+		 */
+		reset_dbregs();
+	}
+	clear_pcb_flags(pcb, PCB_DBREGS);
+}
+
 /*
  * Reset registers to default values on exec.
  */
@@ -624,27 +652,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 	regs->tf_gs = _ugssel;
 	regs->tf_flags = TF_HASSEGS;
 
-	/*
-	 * Reset the hardware debug registers if they were in use.
-	 * They won't have any meaning for the newly exec'd process.
-	 */
-	if (pcb->pcb_flags & PCB_DBREGS) {
-		pcb->pcb_dr0 = 0;
-		pcb->pcb_dr1 = 0;
-		pcb->pcb_dr2 = 0;
-		pcb->pcb_dr3 = 0;
-		pcb->pcb_dr6 = 0;
-		pcb->pcb_dr7 = 0;
-		if (pcb == curpcb) {
-			/*
-			 * Clear the debug registers on the running
-			 * CPU, otherwise they will end up affecting
-			 * the next process we switch to.
-			 */
-			reset_dbregs();
-		}
-		clear_pcb_flags(pcb, PCB_DBREGS);
-	}
+	x86_clear_dbregs(pcb);
 
 	/*
 	 * Drop the FP state if we hold it, so that the process gets a
diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c
index 885087f7a479..4ef37861b151 100644
--- a/sys/i386/i386/machdep.c
+++ b/sys/i386/i386/machdep.c
@@ -1134,6 +1134,34 @@ setup_priv_lcall_gate(struct proc *p)
 }
 #endif
 
+/*
+ * Reset the hardware debug registers if they were in use.
+ * They won't have any meaning for the newly exec'd process.
+ */
+void
+x86_clear_dbregs(struct pcb *pcb)
+{
+        if ((pcb->pcb_flags & PCB_DBREGS) == 0)
+		return;
+
+	pcb->pcb_dr0 = 0;
+	pcb->pcb_dr1 = 0;
+	pcb->pcb_dr2 = 0;
+	pcb->pcb_dr3 = 0;
+	pcb->pcb_dr6 = 0;
+	pcb->pcb_dr7 = 0;
+
+	if (pcb == curpcb) {
+		/*
+		 * Clear the debug registers on the running CPU,
+		 * otherwise they will end up affecting the next
+		 * process we switch to.
+		 */
+		reset_dbregs();
+	}
+	pcb->pcb_flags &= ~PCB_DBREGS;
+}
+
 /*
  * Reset registers to default values on exec.
  */
@@ -1187,27 +1215,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 	/* PS_STRINGS value for BSD/OS binaries.  It is 0 for non-BSD/OS. */
 	regs->tf_ebx = imgp->ps_strings;
 
-        /*
-         * Reset the hardware debug registers if they were in use.
-         * They won't have any meaning for the newly exec'd process.  
-         */
-        if (pcb->pcb_flags & PCB_DBREGS) {
-                pcb->pcb_dr0 = 0;
-                pcb->pcb_dr1 = 0;
-                pcb->pcb_dr2 = 0;
-                pcb->pcb_dr3 = 0;
-                pcb->pcb_dr6 = 0;
-                pcb->pcb_dr7 = 0;
-                if (pcb == curpcb) {
-		        /*
-			 * Clear the debug registers on the running
-			 * CPU, otherwise they will end up affecting
-			 * the next process we switch to.
-			 */
-		        reset_dbregs();
-                }
-		pcb->pcb_flags &= ~PCB_DBREGS;
-        }
+	x86_clear_dbregs(pcb);
 
 	pcb->pcb_initial_npxcw = __INITIAL_NPXCW__;
 
diff --git a/sys/x86/include/x86_var.h b/sys/x86/include/x86_var.h
index 44d2853377b3..3e146b44338f 100644
--- a/sys/x86/include/x86_var.h
+++ b/sys/x86/include/x86_var.h
@@ -127,6 +127,7 @@ u_int	cpu_auxmsr(void);
 bool	cpu_mwait_usable(void);
 void	cpu_probe_amdc1e(void);
 void	cpu_setregs(void);
+void	x86_clear_dbregs(struct pcb *pcb);
 bool	disable_wp(void);
 void	restore_wp(bool old_wp);
 void	dump_add_page(vm_paddr_t);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105010039.1410d5X6048144>