From e2851b0ad93f7d95c0654ccfb7910ba368662c8c Mon Sep 17 00:00:00 2001 From: Kris Van Hees Date: Sat, 17 Dec 2016 18:08:44 -0500 Subject: [PATCH] dtrace: SDT cleanup and bring in line with kernel This commit performs some cleanup on the SDT provider, removing some housekeeping tasks that are no longer needed (such as the need for an arch-specific sdt_provide_module_arch() function). This commit also contains a fix for the loop used in enabling and disabling probes. It was failing to ensure that the enable/disable function was being called with the correct SDT probe. Signed-off-by: Kris Van Hees --- dtrace/include/sparc64/dtrace/sdt_arch.h | 1 - dtrace/include/x86_64/dtrace/sdt_arch.h | 1 - dtrace/sdt_dev.c | 27 ++++++++++-------------- dtrace/sdt_sparc64.c | 16 ++++++-------- dtrace/sdt_x86_64.c | 14 ++---------- 5 files changed, 19 insertions(+), 40 deletions(-) diff --git a/dtrace/include/sparc64/dtrace/sdt_arch.h b/dtrace/include/sparc64/dtrace/sdt_arch.h index c21ef6126fe9..096b9ae944b7 100644 --- a/dtrace/include/sparc64/dtrace/sdt_arch.h +++ b/dtrace/include/sparc64/dtrace/sdt_arch.h @@ -32,7 +32,6 @@ * Use is subject to license terms. */ - #define SDT_AFRAMES 1 #endif /* _SPARC64_SDT_ARCH_H */ diff --git a/dtrace/include/x86_64/dtrace/sdt_arch.h b/dtrace/include/x86_64/dtrace/sdt_arch.h index 0179400a2e3b..a24ec3c7e3e5 100644 --- a/dtrace/include/x86_64/dtrace/sdt_arch.h +++ b/dtrace/include/x86_64/dtrace/sdt_arch.h @@ -32,7 +32,6 @@ * Use is subject to license terms. */ - #define SDT_AFRAMES 4 #endif /* _X86_64_SDT_ARCH_H */ diff --git a/dtrace/sdt_dev.c b/dtrace/sdt_dev.c index 4b29b66d2ed1..a672fb57561a 100644 --- a/dtrace/sdt_dev.c +++ b/dtrace/sdt_dev.c @@ -288,9 +288,6 @@ void sdt_provide_module(void *arg, struct module *mp) return; } - if (!sdt_provide_module_arch(arg, mp)) - return; - for (idx = 0, sdpd = mp->sdt_probes; idx < mp->sdt_probec; idx++, sdpd++) { char *name = sdpd->sdpd_name, *nname; @@ -379,6 +376,7 @@ void sdt_provide_module(void *arg, struct module *mp) int _sdt_enable(void *arg, dtrace_id_t id, void *parg) { sdt_probe_t *sdp = parg; + sdt_probe_t *curr; /* * Ensure that we have a reference to the module. @@ -391,14 +389,12 @@ int _sdt_enable(void *arg, dtrace_id_t id, void *parg) * reference we took above, because we only need one to prevent the * module from being unloaded. */ - PDATA(sdp->sdp_module)->sdt_enabled++; - if (PDATA(sdp->sdp_module)->sdt_enabled > 1) + PDATA(sdp->sdp_module)->enabled_cnt++; + if (PDATA(sdp->sdp_module)->enabled_cnt > 1) module_put(sdp->sdp_module); - while (sdp != NULL) { - sdt_enable_arch(sdp, id, arg); - sdp = sdp->sdp_next; - } + for (curr = sdp; curr != NULL; curr = curr->sdp_next) + sdt_enable_arch(curr, id, arg); return 0; } @@ -406,6 +402,10 @@ int _sdt_enable(void *arg, dtrace_id_t id, void *parg) void _sdt_disable(void *arg, dtrace_id_t id, void *parg) { sdt_probe_t *sdp = parg; + sdt_probe_t *curr; + + for (curr = sdp; curr != NULL; curr = curr->sdp_next) + sdt_disable_arch(curr, id, arg); /* * If we are disabling a probe, we know it was enabled, and therefore @@ -413,14 +413,9 @@ void _sdt_disable(void *arg, dtrace_id_t id, void *parg) * being unloaded. If we disable the last probe on the module, we can * drop the reference. */ - PDATA(sdp->sdp_module)->sdt_enabled--; - if (PDATA(sdp->sdp_module)->sdt_enabled == 0) + PDATA(sdp->sdp_module)->enabled_cnt--; + if (PDATA(sdp->sdp_module)->enabled_cnt == 0) module_put(sdp->sdp_module); - - while (sdp != NULL) { - sdt_disable_arch(sdp, id, arg); - sdp = sdp->sdp_next; - } } void sdt_getargdesc(void *arg, dtrace_id_t id, void *parg, diff --git a/dtrace/sdt_sparc64.c b/dtrace/sdt_sparc64.c index 65bc8d07ca41..1c744ba11bdc 100644 --- a/dtrace/sdt_sparc64.c +++ b/dtrace/sdt_sparc64.c @@ -44,7 +44,7 @@ * mov %i1, %o2 * mov %i2, %o3 * mov %i3, %o4 - * call 0xfff> + * call dtrace_probe * mov %i4, %o5 * ret * restore @@ -56,7 +56,7 @@ * mov %i1, %o2 * mov %i2, %o3 * mov %i3, %o4 - * call + * call dtrace_probe * mov %i4, %o5 * ret * restore @@ -64,8 +64,10 @@ * For is-enabled probes, we just drop an "or %g0, 1, %o0" * directly into the delay slot. */ -#if SDT_TRAMP_SIZE < 11 -# error SDT_TRAMP_SIZE is less than the required 11 instructions. +#ifndef SDT_TRAMP_SIZE +# error The kernel must define SDT_TRAMP_SIZE! +#elif SDT_TRAMP_SIZE < 11 +# error SDT_TRAMP_SIZE must be at least 11 instructions! #endif #define SA(x) ((long)ALIGN((x), 4)) @@ -194,12 +196,6 @@ void sdt_disable_arch(sdt_probe_t *sdp, dtrace_id_t id, void *arg) int sdt_dev_init_arch(void) { - /* - * Sanity check to ensure that the memory allocated by the kernel is - * sufficient for what PDATA needs. - */ - ASSERT(sizeof(dtrace_module_t) < DTRACE_PDATA_SIZE); - return 0; } diff --git a/dtrace/sdt_x86_64.c b/dtrace/sdt_x86_64.c index 69440d2ce2e8..b8f1ef440f2b 100644 --- a/dtrace/sdt_x86_64.c +++ b/dtrace/sdt_x86_64.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "dtrace.h" #include "dtrace_dev.h" @@ -53,7 +54,7 @@ static uint8_t sdt_invop(struct pt_regs *regs) this_cpu_core->cpu_dtrace_regs = NULL; } - return ASM_CALL_SIZE; + return DTRACE_INVOP_NOPS; } } @@ -66,11 +67,6 @@ void sdt_provide_probe_arch(sdt_probe_t *sdp, struct module *mp, int idx) sdp->sdp_savedval = *sdp->sdp_patchpoint; } -int sdt_provide_module_arch(void *arg, struct module *mp) -{ - return 1; -} - void sdt_enable_arch(sdt_probe_t *sdp, dtrace_id_t id, void *arg) { dtrace_invop_enable((uint8_t *)sdp->sdp_patchpoint); @@ -120,12 +116,6 @@ uint64_t sdt_getarg(void *arg, dtrace_id_t id, void *parg, int argno, int sdt_dev_init_arch(void) { - /* - * Sanity check to ensure that the memory allocated by the kernel is - * sufficient for what PDATA needs. - */ - ASSERT(sizeof(dtrace_module_t) < DTRACE_PDATA_SIZE); - return dtrace_invop_add(sdt_invop); } -- 2.50.1