Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
dtrace: sdt provider core components
This implements the core (linked-in) machinery needed for SDT tracepoints: - generate empty stub function calls __dtrace_probe_* for each probe point and perf-event probe point, and record their section-relative offset in tables in special symbols in the output; calls to is-enabling probes (conditionals of the form if (DTRACE_FOO_ENABLED(probe-name))) are translated as well - similarly record the names and types of arguments to probes in special sections - parse both of these at load time, and substitute in nops over the top of the stub functions, remembering their locations: is-enabled probes get 0-returns patched over the top - on probe enabling, patch invalid-operation traps over the top of those stub functions; handle these by calling the probe, then return as if the trap had never happened The provider module itself is added in the next commit. Signed-off-by: Nick Alcock <nick.alcock@oracle.com> Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com> Signed-off-by: Tomas Jedlicka <tomas.jedlicka@oracle.com> Signed-off-by: Eugene Loh <eugene.loh@oracle.com> Signed-off-by: David Mc Lean <david.mclean@oracle.com> Signed-off-by: Vincent Lim <vincent.lim@oracle.com>
- Loading branch information
1 parent
2f31b95
commit 9bb7076b2261cf2470e94df26762679a950a0b1e
Showing
30 changed files
with
2,500 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -165,3 +165,9 @@ x509.genkey | ||
|
|
||
| # Documentation toolchain | ||
| sphinx_*/ | ||
| # | ||
| # Generated DTrace SDT files | ||
| # | ||
| *.sdtinfo.c | ||
| *.sdtinfo.h | ||
| *.sdtstub.S | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0 */ | ||
| /* | ||
| * Dynamic Tracing for Linux - SDT Implementation defines | ||
| * | ||
| * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 2 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| */ | ||
|
|
||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| #ifndef _X86_64_SDT_ARCH_H | ||
| #define _X86_64_SDT_ARCH_H | ||
|
|
||
| #define SDT_AFRAMES 4 | ||
|
|
||
| #endif /* _X86_64_SDT_ARCH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0 */ | ||
|
|
||
| /* Copyright (C) 2016 Oracle, Inc. */ | ||
|
|
||
| #ifndef _X86_DTRACE_SDT_ARCH_H | ||
| #define _X86_DTRACE_SDT_ARCH_H | ||
|
|
||
| #define __DTRACE_SDT_ISENABLED_PROTO void | ||
| #define __DTRACE_SDT_ISENABLED_ARGS | ||
|
|
||
| #endif /* _X86_DTRACE_SDT_ARCH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0 */ | ||
| /* | ||
| * FILE: dtrace_sdt.c | ||
| * DESCRIPTION: Dynamic Tracing: SDT registration code (arch-specific) | ||
| * | ||
| * Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. | ||
| */ | ||
|
|
||
| #include <linux/kernel.h> | ||
| #include <linux/memory.h> | ||
| #include <linux/module.h> | ||
| #include <linux/dtrace_os.h> | ||
| #include <linux/sdt.h> | ||
| #include <linux/slab.h> | ||
| #include <linux/sync_core.h> | ||
| #include <linux/vmalloc.h> | ||
| #include <asm/nmi.h> | ||
| #include <asm/nops.h> | ||
| #include <asm/dtrace_arch.h> | ||
| #include <asm/text-patching.h> | ||
|
|
||
| static uint8_t nops[ASM_CALL_SIZE]; | ||
| static uint8_t movs[ASM_CALL_SIZE]; | ||
|
|
||
| #define DT_OP_REX_RAX 0x48 | ||
| #define DT_OP_XOR_EAX_0 0x33 | ||
| #define DT_OP_XOR_EAX_1 0xc0 | ||
|
|
||
| /* This code is based on apply_alternatives and text_poke_early. It needs to | ||
| * run before SMP is initialized in order to avoid SMP problems with patching | ||
| * code that might be accessed on another CPU. | ||
| */ | ||
| void __init_or_module dtrace_sdt_nop_multi(asm_instr_t **addrs, | ||
| int *is_enabled, int cnt) | ||
| { | ||
| int i; | ||
| asm_instr_t *addr; | ||
| unsigned long flags; | ||
|
|
||
| stop_nmi(); | ||
| local_irq_save(flags); | ||
|
|
||
| for (i = 0; i < cnt; i++) { | ||
| addr = addrs[i]; | ||
| if (likely(!is_enabled[i])) | ||
| memcpy(addr, nops, sizeof(nops)); | ||
| else | ||
| memcpy(addr, movs, sizeof(movs)); | ||
| } | ||
|
|
||
| sync_core(); | ||
| local_irq_restore(flags); | ||
| restart_nmi(); | ||
| } | ||
|
|
||
| void __init dtrace_sdt_init_arch(void) | ||
| { | ||
| /* | ||
| * A little unusual, but potentially necessary. While we could use a | ||
| * single NOP sequence of length ASM_CALL_SIZE, we need to consider the | ||
| * fact that when a SDT probe point is enabled, a single invalid opcode | ||
| * is written on the first byte of this NOP sequence. By using a | ||
| * sequence of a 1-byte NOP, followed by a (ASM_CALL_SIZE - 1) byte NOP | ||
| * sequence, we play it pretty safe. | ||
| */ | ||
| add_nops(nops, 1); | ||
| add_nops(nops + 1, ASM_CALL_SIZE - 1); | ||
|
|
||
| /* | ||
| * Is-enabled probe points contain an "xor %rax, %rax" when disabled. | ||
| */ | ||
| movs[0] = DT_OP_REX_RAX; | ||
| movs[1] = DT_OP_XOR_EAX_0; | ||
| movs[2] = DT_OP_XOR_EAX_1; | ||
| add_nops(movs + 3, ASM_CALL_SIZE - 3); | ||
| } |
Oops, something went wrong.