Author: mjg
Date: Fri Apr 27 15:16:34 2018
New Revision: 333064
URL: https://svnweb.freebsd.org/changeset/base/333064

Log:
  systrace: track it like sdt probes
  
  While here predict false.
  
  Note the code is wrong (regardless of this change). Dereference of the
  pointer can race with module unload. A fix would set the probe to a
  nop stub instead of NULL.

Modified:
  head/sys/cddl/dev/systrace/systrace.c
  head/sys/kern/kern_dtrace.c
  head/sys/kern/subr_syscall.c
  head/sys/sys/sysent.h

Modified: head/sys/cddl/dev/systrace/systrace.c
==============================================================================
--- head/sys/cddl/dev/systrace/systrace.c       Fri Apr 27 13:59:24 2018        
(r333063)
+++ head/sys/cddl/dev/systrace/systrace.c       Fri Apr 27 15:16:34 2018        
(r333064)
@@ -135,6 +135,8 @@ extern const char *freebsd32_syscallnames[];
 #error 1 << SYSTRACE_SHIFT must exceed number of system calls
 #endif
 
+static int systrace_enabled_count;
+
 static void    systrace_load(void *);
 static void    systrace_unload(void *);
 
@@ -315,6 +317,9 @@ systrace_enable(void *arg, dtrace_id_t id, void *parg)
                SYSENT[sysnum].sy_entry = id;
        else
                SYSENT[sysnum].sy_return = id;
+       systrace_enabled_count++;
+       if (systrace_enabled_count == 1)
+               systrace_enabled = true;
 }
 
 static void
@@ -324,6 +329,9 @@ systrace_disable(void *arg, dtrace_id_t id, void *parg
 
        SYSENT[sysnum].sy_entry = 0;
        SYSENT[sysnum].sy_return = 0;
+       systrace_enabled_count--;
+       if (systrace_enabled_count == 0)
+               systrace_enabled = false;
 }
 
 static void

Modified: head/sys/kern/kern_dtrace.c
==============================================================================
--- head/sys/kern/kern_dtrace.c Fri Apr 27 13:59:24 2018        (r333063)
+++ head/sys/kern/kern_dtrace.c Fri Apr 27 15:16:34 2018        (r333064)
@@ -56,7 +56,8 @@ dtrace_doubletrap_func_t      dtrace_doubletrap_func;
 dtrace_pid_probe_ptr_t         dtrace_pid_probe_ptr;
 dtrace_return_probe_ptr_t      dtrace_return_probe_ptr;
 
-systrace_probe_func_t __read_frequently        systrace_probe_func;
+bool __read_frequently         systrace_enabled;
+systrace_probe_func_t          systrace_probe_func;
 
 /* Return the DTrace process data size compiled in the kernel hooks. */
 size_t

Modified: head/sys/kern/subr_syscall.c
==============================================================================
--- head/sys/kern/subr_syscall.c        Fri Apr 27 13:59:24 2018        
(r333063)
+++ head/sys/kern/subr_syscall.c        Fri Apr 27 15:16:34 2018        
(r333064)
@@ -126,7 +126,8 @@ syscallenter(struct thread *td)
 
 #ifdef KDTRACE_HOOKS
                /* Give the syscall:::entry DTrace probe a chance to fire. */
-               if (systrace_probe_func != NULL && sa->callp->sy_entry != 0)
+               if (__predict_false(systrace_enabled &&
+                   sa->callp->sy_entry != 0))
                        (*systrace_probe_func)(sa, SYSTRACE_ENTRY, 0);
 #endif
 
@@ -140,7 +141,8 @@ syscallenter(struct thread *td)
 
 #ifdef KDTRACE_HOOKS
                /* Give the syscall:::return DTrace probe a chance to fire. */
-               if (systrace_probe_func != NULL && sa->callp->sy_return != 0)
+               if (__predict_false(systrace_enabled &&
+                   sa->callp->sy_return != 0))
                        (*systrace_probe_func)(sa, SYSTRACE_RETURN,
                            error ? -1 : td->td_retval[0]);
 #endif

Modified: head/sys/sys/sysent.h
==============================================================================
--- head/sys/sys/sysent.h       Fri Apr 27 13:59:24 2018        (r333063)
+++ head/sys/sys/sysent.h       Fri Apr 27 15:16:34 2018        (r333064)
@@ -53,6 +53,7 @@ typedef       void    (*systrace_probe_func_t)(struct 
syscall_a
                    enum systrace_probe_t, int);
 typedef        void    (*systrace_args_func_t)(int, void *, uint64_t *, int *);
 
+extern bool                    systrace_enabled;
 extern systrace_probe_func_t   systrace_probe_func;
 
 struct sysent {                        /* system call table */
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to