Author: markj
Date: Fri Mar 10 18:52:37 2017
New Revision: 315012
URL: https://svnweb.freebsd.org/changeset/base/315012

Log:
  MFC r313841, r313850:
  Prevent CPU migration when checking the DTrace nofault flag on x86.

Modified:
  stable/10/sys/cddl/dev/dtrace/amd64/dtrace_subr.c
  stable/10/sys/cddl/dev/dtrace/i386/dtrace_subr.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cddl/dev/dtrace/amd64/dtrace_subr.c
==============================================================================
--- stable/10/sys/cddl/dev/dtrace/amd64/dtrace_subr.c   Fri Mar 10 18:51:47 
2017        (r315011)
+++ stable/10/sys/cddl/dev/dtrace/amd64/dtrace_subr.c   Fri Mar 10 18:52:37 
2017        (r315012)
@@ -41,7 +41,9 @@
 #include <sys/dtrace_impl.h>
 #include <sys/dtrace_bsd.h>
 #include <machine/clock.h>
+#include <machine/cpufunc.h>
 #include <machine/frame.h>
+#include <machine/psl.h>
 #include <vm/pmap.h>
 
 extern uintptr_t       dtrace_in_probe_addr;
@@ -466,6 +468,8 @@ dtrace_gethrestime(void)
 int
 dtrace_trap(struct trapframe *frame, u_int type)
 {
+       uint16_t nofault;
+
        /*
         * A trap can occur while DTrace executes a probe. Before
         * executing the probe, DTrace blocks re-scheduling and sets
@@ -476,7 +480,12 @@ dtrace_trap(struct trapframe *frame, u_i
         * Check if DTrace has enabled 'no-fault' mode:
         *
         */
-       if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) {
+       sched_pin();
+       nofault = cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT;
+       sched_unpin();
+       if (nofault) {
+               KASSERT((read_rflags() & PSL_I) == 0, ("interrupts enabled"));
+
                /*
                 * There are only a couple of trap types that are expected.
                 * All the rest will be handled in the usual way.

Modified: stable/10/sys/cddl/dev/dtrace/i386/dtrace_subr.c
==============================================================================
--- stable/10/sys/cddl/dev/dtrace/i386/dtrace_subr.c    Fri Mar 10 18:51:47 
2017        (r315011)
+++ stable/10/sys/cddl/dev/dtrace/i386/dtrace_subr.c    Fri Mar 10 18:52:37 
2017        (r315012)
@@ -42,7 +42,9 @@
 #include <sys/dtrace_impl.h>
 #include <sys/dtrace_bsd.h>
 #include <machine/clock.h>
+#include <machine/cpufunc.h>
 #include <machine/frame.h>
+#include <machine/psl.h>
 #include <vm/pmap.h>
 
 extern uintptr_t       kernelbase;
@@ -475,6 +477,8 @@ dtrace_gethrestime(void)
 int
 dtrace_trap(struct trapframe *frame, u_int type)
 {
+       uint16_t nofault;
+
        /*
         * A trap can occur while DTrace executes a probe. Before
         * executing the probe, DTrace blocks re-scheduling and sets
@@ -485,7 +489,12 @@ dtrace_trap(struct trapframe *frame, u_i
         * Check if DTrace has enabled 'no-fault' mode:
         *
         */
-       if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) {
+       sched_pin();
+       nofault = cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT;
+       sched_unpin();
+       if (nofault) {
+               KASSERT((read_eflags() & PSL_I) == 0, ("interrupts enabled"));
+
                /*
                 * There are only a couple of trap types that are expected.
                 * All the rest will be handled in the usual way.
_______________________________________________
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

Reply via email to