aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mmiotrace.h
diff options
context:
space:
mode:
authorPekka Paalanen <pq@iki.fi>2008-05-12 15:20:56 -0400
committerThomas Gleixner <tglx@linutronix.de>2008-05-24 05:21:14 -0400
commit8b7d89d02ef3c6a7c73d6596f28cea7632850af4 (patch)
tree32601bf4f34dd9e3ec1e9610c555e10dc448006c /include/linux/mmiotrace.h
parent677aa9f77e8de3791b481a0cec6c8b84d1eec626 (diff)
x86: mmiotrace - trace memory mapped IO
Mmiotrace is a tool for trapping memory mapped IO (MMIO) accesses within the kernel. It is used for debugging and especially for reverse engineering evil binary drivers. Mmiotrace works by wrapping the ioremap family of kernel functions and marking the returned pages as not present. Access to the IO memory triggers a page fault, which will be handled by mmiotrace's custom page fault handler. This will single-step the faulted instruction with the MMIO page marked as present. Access logs are directed to user space via relay and debug_fs. This page fault approach is necessary, because binary drivers have readl/writel etc. calls inlined and therefore extremely difficult to trap with with e.g. kprobes. This patch depends on the custom page fault handlers patch. Signed-off-by: Pekka Paalanen <pq@iki.fi> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/linux/mmiotrace.h')
-rw-r--r--include/linux/mmiotrace.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
new file mode 100644
index 000000000000..cb247825f3ec
--- /dev/null
+++ b/include/linux/mmiotrace.h
@@ -0,0 +1,62 @@
1#ifndef MMIOTRACE_H
2#define MMIOTRACE_H
3
4#include <asm/types.h>
5
6#define MMIO_VERSION 0x04
7
8/* mm_io_header.type */
9#define MMIO_OPCODE_MASK 0xff
10#define MMIO_OPCODE_SHIFT 0
11#define MMIO_WIDTH_MASK 0xff00
12#define MMIO_WIDTH_SHIFT 8
13#define MMIO_MAGIC (0x6f000000 | (MMIO_VERSION<<16))
14#define MMIO_MAGIC_MASK 0xffff0000
15
16enum mm_io_opcode { /* payload type: */
17 MMIO_READ = 0x1, /* struct mm_io_rw */
18 MMIO_WRITE = 0x2, /* struct mm_io_rw */
19 MMIO_PROBE = 0x3, /* struct mm_io_map */
20 MMIO_UNPROBE = 0x4, /* struct mm_io_map */
21 MMIO_MARKER = 0x5, /* raw char data */
22 MMIO_UNKNOWN_OP = 0x6, /* struct mm_io_rw */
23};
24
25struct mm_io_header {
26 __u32 type;
27 __u32 sec; /* timestamp */
28 __u32 nsec;
29 __u32 pid; /* PID of the process, or 0 for kernel core */
30 __u16 data_len; /* length of the following payload */
31};
32
33struct mm_io_rw {
34 __u64 address; /* virtual address of register */
35 __u64 value;
36 __u64 pc; /* optional program counter */
37};
38
39struct mm_io_map {
40 __u64 phys; /* base address in PCI space */
41 __u64 addr; /* base virtual address */
42 __u64 len; /* mapping size */
43 __u64 pc; /* optional program counter */
44};
45
46
47/*
48 * These structures are used to allow a single relay_write()
49 * call to write a full packet.
50 */
51
52struct mm_io_header_rw {
53 struct mm_io_header header;
54 struct mm_io_rw rw;
55} __attribute__((packed));
56
57struct mm_io_header_map {
58 struct mm_io_header header;
59 struct mm_io_map map;
60} __attribute__((packed));
61
62#endif /* MMIOTRACE_H */