From eca09c3a1a4581c98736e347aeff9ff4f282220a Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Fri, 12 Aug 2016 18:51:34 +0100 Subject: [PATCH] dtrace: split arch-dependent parts out of fasttrap This is much the same as what SDT is already doing. No SPARC parts yet. Signed-off-by: Nick Alcock Acked-by: Kris Van Hees Orabug: 24455245 --- dtrace/Kbuild | 2 +- dtrace/fasttrap_dev.c | 94 +------------- dtrace/fasttrap_impl.h | 8 +- dtrace/fasttrap_x86_64.c | 127 +++++++++++++++++++ dtrace/include/x86_64/dtrace/fasttrap_arch.h | 37 ++++++ 5 files changed, 178 insertions(+), 90 deletions(-) create mode 100644 dtrace/fasttrap_x86_64.c create mode 100644 dtrace/include/x86_64/dtrace/fasttrap_arch.h diff --git a/dtrace/Kbuild b/dtrace/Kbuild index ae8f15b81d9f..32a0ecf64a10 100644 --- a/dtrace/Kbuild +++ b/dtrace/Kbuild @@ -46,7 +46,7 @@ dtrace-y := dtrace_mod.o dtrace_dev.o \ dtrace_probe.o dtrace_probe_ctx.o \ dtrace_ptofapi.o dtrace_predicate.o \ dtrace_spec.o dtrace_state.o dtrace_util.o -fasttrap-y := fasttrap_mod.o fasttrap_dev.o +fasttrap-y := fasttrap_mod.o fasttrap_dev.o fasttrap_$(UTS_MACHINE).o profile-y := profile_mod.o profile_dev.o sdt-y := sdt_mod.o sdt_dev.o sdt_$(UTS_MACHINE).o systrace-y := systrace_mod.o systrace_dev.o diff --git a/dtrace/fasttrap_dev.c b/dtrace/fasttrap_dev.c index c46ee71e1c72..28b75ac1fd51 100644 --- a/dtrace/fasttrap_dev.c +++ b/dtrace/fasttrap_dev.c @@ -21,7 +21,7 @@ * * CDDL HEADER END * - * Copyright 2010, 2011, 2012, 2013 Oracle, Inc. All rights reserved. + * Copyright 2010 -- 2016 Oracle, Inc. All rights reserved. * Use is subject to license terms. */ @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "dtrace.h" @@ -78,44 +79,6 @@ static volatile uint64_t fasttrap_mod_gen; static void fasttrap_pid_cleanup(void); -static void fasttrap_usdt_args64(fasttrap_probe_t *probe, struct pt_regs *regs, - int argc, uintptr_t *argv) { - int i, x, cap = min(argc, (int)probe->ftp_nargs); - uintptr_t *st = (uintptr_t *)regs->sp; - - for (i = 0; i < cap; i++) { - switch (x = probe->ftp_argmap[i]) { - case 0: - argv[i] = regs->di; - break; - case 1: - argv[i] = regs->si; - break; - case 2: - argv[i] = regs->dx; - break; - case 3: - argv[i] = regs->cx; - break; - case 4: - argv[i] = regs->r8; - break; - case 5: - argv[i] = regs->r9; - break; - default: - ASSERT(x > 5); - - __copy_from_user_inatomic_nocache(&argv[i], - (void *)&st[x - 6], - sizeof(st[0])); - } - } - - while (i < argc) - argv[i++] = 0; -} - static int fasttrap_pid_probe(fasttrap_machtp_t *mtp, struct pt_regs *regs) { fasttrap_tracepoint_t *tp = container_of(mtp, fasttrap_tracepoint_t, ftt_mtp); @@ -143,25 +106,16 @@ static int fasttrap_pid_probe(fasttrap_machtp_t *mtp, struct pt_regs *regs) { for (id = tp->ftt_ids; id != NULL; id = id->fti_next) { fasttrap_probe_t *ftp = id->fti_probe; - if (id->fti_ptype == DTFTP_IS_ENABLED) { + if (id->fti_ptype == DTFTP_IS_ENABLED) is_enabled = 1; - } else if (ftp->ftp_argmap == NULL) { - dtrace_probe(ftp->ftp_id, regs->di, regs->si, regs->dx, - regs->cx, regs->r8); - } else { - uintptr_t t[5]; - - fasttrap_usdt_args64(ftp, regs, - sizeof(t) / sizeof(t[0]), t); - dtrace_probe(ftp->ftp_id, t[0], t[1], t[2], t[3], - t[4]); - } + else + fasttrap_pid_probe_arch(ftp, regs); } this_cpu_core->cpu_dtrace_regs = NULL; if (is_enabled) - regs->ax = 1; + fasttrap_set_enabled(regs); return 0; } @@ -722,42 +676,6 @@ static void fasttrap_pid_getargdesc(void *arg, dtrace_id_t id, void *parg, strcpy(desc->dtargd_xlate, str); } -static uint64_t fasttrap_usdt_getarg(void *arg, dtrace_id_t id, void *parg, - int argno, int aframes) -{ - struct pt_regs *regs = this_cpu_core->cpu_dtrace_regs; - uint64_t *st; - uint64_t val; - - if (regs == NULL) - return 0; - - switch (argno) { - case 0: - return regs->di; - case 1: - return regs->si; - case 2: - return regs->dx; - case 3: - return regs->cx; - case 4: - return regs->r8; - case 5: - return regs->r9; - } - - ASSERT(argno > 5); - - st = (uint64_t *)regs->sp; - DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); - __copy_from_user_inatomic_nocache(&val, (void *)&st[argno - 6], - sizeof(st[0])); - DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); - - return val; -} - static void fasttrap_pid_destroy(void *arg, dtrace_id_t id, void *parg) { fasttrap_probe_t *probe = parg; diff --git a/dtrace/fasttrap_impl.h b/dtrace/fasttrap_impl.h index d34aabf2a8ec..d2992fa1f71e 100644 --- a/dtrace/fasttrap_impl.h +++ b/dtrace/fasttrap_impl.h @@ -2,6 +2,7 @@ #define _FASTTRAP_IMPL_H_ #include +#include /* * Fasttrap Providers, Probes and Tracepoints @@ -120,7 +121,12 @@ extern fasttrap_hash_t fasttrap_tpoints; (((pc) / sizeof (fasttrap_instr_t) + (pid)) & \ fasttrap_tpoints.fth_mask) -#define FASTTRAP_OFFSET_AFRAMES 3 +extern void fasttrap_usdt_args64_arch(fasttrap_probe_t *probe, struct pt_regs *regs, + int argc, uintptr_t *argv); +extern uint64_t fasttrap_usdt_getarg(void *arg, dtrace_id_t id, void *parg, + int argno, int aframes); +extern void fasttrap_pid_probe_arch(fasttrap_probe_t *ftp, struct pt_regs *regs); +extern void fasttrap_set_enabled(struct pt_regs *regs); extern void fasttrap_meta_create_probe(void *, void *, dtrace_helper_probedesc_t *); diff --git a/dtrace/fasttrap_x86_64.c b/dtrace/fasttrap_x86_64.c new file mode 100644 index 000000000000..d48cf42a1172 --- /dev/null +++ b/dtrace/fasttrap_x86_64.c @@ -0,0 +1,127 @@ +/* + * FILE: fasttrap_x86_64.c + * DESCRIPTION: Fasttrap Tracing: arch support (x86_64) + * + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 2010, 2011, 2012, 2013, 2016 Oracle, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include + +#include "dtrace.h" +#include "dtrace_dev.h" +#include "fasttrap_impl.h" + +uint64_t fasttrap_usdt_getarg(void *arg, dtrace_id_t id, void *parg, + int argno, int aframes) +{ + struct pt_regs *regs = this_cpu_core->cpu_dtrace_regs; + uint64_t *st; + uint64_t val; + + if (regs == NULL) + return 0; + + switch (argno) { + case 0: + return regs->di; + case 1: + return regs->si; + case 2: + return regs->dx; + case 3: + return regs->cx; + case 4: + return regs->r8; + case 5: + return regs->r9; + } + + ASSERT(argno > 5); + + st = (uint64_t *)regs->sp; + DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); + __copy_from_user_inatomic_nocache(&val, (void *)&st[argno - 6], + sizeof(st[0])); + DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); + + return val; +} + +static void fasttrap_map_args(fasttrap_probe_t *probe, struct pt_regs *regs, + int argc, uintptr_t *argv) +{ + int i, x, cap = min(argc, (int)probe->ftp_nargs); + uintptr_t *st = (uintptr_t *)regs->sp; + + for (i = 0; i < cap; i++) { + switch (x = probe->ftp_argmap[i]) { + case 0: + argv[i] = regs->di; + break; + case 1: + argv[i] = regs->si; + break; + case 2: + argv[i] = regs->dx; + break; + case 3: + argv[i] = regs->cx; + break; + case 4: + argv[i] = regs->r8; + break; + case 5: + argv[i] = regs->r9; + break; + default: + ASSERT(x > 5); + + __copy_from_user_inatomic_nocache(&argv[i], + (void *)&st[x - 6], + sizeof(st[0])); + } + } + + while (i < argc) + argv[i++] = 0; +} + +void fasttrap_pid_probe_arch(fasttrap_probe_t *ftp, struct pt_regs *regs) +{ + if (ftp->ftp_argmap == NULL) + dtrace_probe(ftp->ftp_id, regs->di, regs->si, regs->dx, + regs->cx, regs->r8); + else { + uintptr_t t[5]; + + fasttrap_map_args(ftp, regs, sizeof(t) / sizeof(t[0]), t); + dtrace_probe(ftp->ftp_id, t[0], t[1], t[2], t[3], + t[4]); + } +} + +void fasttrap_set_enabled(struct pt_regs *regs) +{ + regs->ax = 1; +} + diff --git a/dtrace/include/x86_64/dtrace/fasttrap_arch.h b/dtrace/include/x86_64/dtrace/fasttrap_arch.h new file mode 100644 index 000000000000..a839c9e860b7 --- /dev/null +++ b/dtrace/include/x86_64/dtrace/fasttrap_arch.h @@ -0,0 +1,37 @@ +#ifndef _X86_64_FASTTRAP_ARCH_H +#define _X86_64_FASTTRAP_ARCH_H + +/* + * Fasttrap Tracing Implementation defines + * + * Note: The contents of this file are private to the implementation of the + * DTrace subsystem and are subject to change at any time without notice. + */ + +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 2016 Oracle, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#define FASTTRAP_OFFSET_AFRAMES 3 + +#endif /* _X86_64_FASTTRAP_ARCH_H */ -- 2.50.1