From 69b7cc1189f913a712f9fa2f1a908e5d6f2de39a Mon Sep 17 00:00:00 2001 From: markj Date: Fri, 10 Mar 2017 18:51:47 +0000 Subject: MFC r313841, r313850: Prevent CPU migration when checking the DTrace nofault flag on x86. --- sys/cddl/dev/dtrace/amd64/dtrace_subr.c | 11 ++++++++++- sys/cddl/dev/dtrace/i386/dtrace_subr.c | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'sys/cddl') diff --git a/sys/cddl/dev/dtrace/amd64/dtrace_subr.c b/sys/cddl/dev/dtrace/amd64/dtrace_subr.c index df39d2e..717f455 100644 --- a/sys/cddl/dev/dtrace/amd64/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/amd64/dtrace_subr.c @@ -41,7 +41,9 @@ #include #include #include +#include #include +#include #include extern void dtrace_getnanotime(struct timespec *tsp); @@ -384,6 +386,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 @@ -393,7 +397,12 @@ dtrace_trap(struct trapframe *frame, u_int type) * * 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. diff --git a/sys/cddl/dev/dtrace/i386/dtrace_subr.c b/sys/cddl/dev/dtrace/i386/dtrace_subr.c index b70eab9..3801c1b 100644 --- a/sys/cddl/dev/dtrace/i386/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/i386/dtrace_subr.c @@ -42,7 +42,9 @@ #include #include #include +#include #include +#include #include extern uintptr_t kernelbase; @@ -386,6 +388,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 @@ -395,7 +399,12 @@ dtrace_trap(struct trapframe *frame, u_int type) * * 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. -- cgit v1.1