@@ -70,6 +70,7 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
+KBUILD_CFLAGS += -DDISABLE_TRACEPOINTS
GCOV_PROFILE := n
UBSAN_SANITIZE := n
@@ -51,6 +51,7 @@ KBUILD_CFLAGS += -D__DISABLE_EXPORTS
# Disable relocation relaxation in case the link is not PIE.
KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
+KBUILD_CFLAGS += -DDISABLE_TRACEPOINTS
# sev.c indirectly inludes inat-table.h which is generated during
# compilation and stored in $(objtree). Add the directory to the includes so
@@ -37,13 +37,16 @@ static inline void set_64bit(volatile u64 *ptr, u64 value)
#ifdef CONFIG_X86_CMPXCHG64
#define arch_cmpxchg64(ptr, o, n) \
- ((__typeof__(*(ptr)))__cmpxchg64((ptr), (unsigned long long)(o), \
+ ((__typeof__(*(ptr)))__cmpxchg64((unsigned long long *)(ptr), \
+ (unsigned long long)(o), \
(unsigned long long)(n)))
-#define arch_cmpxchg64_local(ptr, o, n) \
- ((__typeof__(*(ptr)))__cmpxchg64_local((ptr), (unsigned long long)(o), \
+#define arch_cmpxchg64_local(ptr, o, n) \
+ ((__typeof__(*(ptr)))__cmpxchg64_local((unsigned long long *)(ptr), \
+ (unsigned long long)(o), \
(unsigned long long)(n)))
-#define arch_try_cmpxchg64(ptr, po, n) \
- __try_cmpxchg64((ptr), (unsigned long long *)(po), \
+#define arch_try_cmpxchg64(ptr, po, n) \
+ __try_cmpxchg64((unsigned long long *)(ptr), \
+ (unsigned long long *)(po), \
(unsigned long long)(n))
#endif
@@ -2,13 +2,20 @@
#ifndef _ASM_X86_SHARED_IO_H
#define _ASM_X86_SHARED_IO_H
+#include <linux/tracepoint-defs.h>
+#include <linux/trace_portio.h>
#include <linux/types.h>
+DECLARE_TRACEPOINT(portio_write);
+DECLARE_TRACEPOINT(portio_read);
+
#define BUILDIO(bwl, bw, type) \
static inline void __out##bwl(type value, u16 port) \
{ \
asm volatile("out" #bwl " %" #bw "0, %w1" \
: : "a"(value), "Nd"(port)); \
+ if (tracepoint_enabled(portio_write)) \
+ do_trace_portio_write(value, port, #bwl[0]); \
} \
\
static inline type __in##bwl(u16 port) \
@@ -16,6 +23,8 @@ static inline type __in##bwl(u16 port) \
type value; \
asm volatile("in" #bwl " %w1, %" #bw "0" \
: "=a"(value) : "Nd"(port)); \
+ if (tracepoint_enabled(portio_read)) \
+ do_trace_portio_read(value, port, #bwl[0]); \
return value; \
}
@@ -40,6 +40,7 @@ $(obj)/inat.o: $(obj)/inat-tables.c
clean-files := inat-tables.c
obj-$(CONFIG_SMP) += msr-smp.o cache-smp.o
+obj-$(CONFIG_TRACEPOINTS) += trace_portio.o
lib-y := delay.o misc.o cmdline.o cpu.o
lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o
new file mode 100644
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/instruction_pointer.h>
+#include <linux/trace_portio.h>
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/portio.h>
+
+void do_trace_portio_read(u32 value, u16 port, char width)
+{
+ trace_portio_read(value, port, width, (void *)_RET_IP_);
+}
+EXPORT_SYMBOL_GPL(do_trace_portio_read);
+EXPORT_TRACEPOINT_SYMBOL_GPL(portio_read);
+
+void do_trace_portio_write(u32 value, u16 port, char width)
+{
+ trace_portio_write(value, port, width, (void *)_RET_IP_);
+}
+EXPORT_SYMBOL_GPL(do_trace_portio_write);
+EXPORT_TRACEPOINT_SYMBOL_GPL(portio_write);
new file mode 100644
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/types.h>
+
+extern void do_trace_portio_read(u32 value, u16 port, char width);
+extern void do_trace_portio_write(u32 value, u16 port, char width);
@@ -80,7 +80,7 @@ struct bpf_raw_event_map {
#define DECLARE_TRACEPOINT(tp) \
extern struct tracepoint __tracepoint_##tp
-#ifdef CONFIG_TRACEPOINTS
+#if defined(CONFIG_TRACEPOINTS) && !defined(DISABLE_TRACEPOINTS)
# define tracepoint_enabled(tp) \
static_key_false(&(__tracepoint_##tp).key)
#else
new file mode 100644
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM portio
+
+#if !defined(_TRACE_PORTIO_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_PORTIO_H
+
+#include <linux/tracepoint.h>
+
+DECLARE_EVENT_CLASS(portio_class,
+ TP_PROTO(u32 value, u16 port, char width, void *ip_addr),
+
+ TP_ARGS(value, port, width, ip_addr),
+
+ TP_STRUCT__entry(
+ __field(u32, value)
+ __field(u16, port)
+ __field(char, width)
+ __field(void *, ip_addr)
+ ),
+
+ TP_fast_assign(
+ __entry->value = value;
+ __entry->port = port;
+ __entry->width = width;
+ __entry->ip_addr = ip_addr;
+ ),
+
+ TP_printk("port=0x%04x value=0x%0*x %pS",
+ __entry->port,
+ __entry->width == 'b' ? 2 :
+ __entry->width == 'w' ? 4 : 8,
+ __entry->value, __entry->ip_addr)
+);
+
+DEFINE_EVENT(portio_class, portio_read,
+ TP_PROTO(u32 value, u16 port, char width, void *ip_addr),
+ TP_ARGS(value, port, width, ip_addr)
+);
+
+DEFINE_EVENT(portio_class, portio_write,
+ TP_PROTO(u32 value, u16 port, char width, void *ip_addr),
+ TP_ARGS(value, port, width, ip_addr)
+);
+
+#endif /* _TRACE_PORTIO_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Add support for port I/O tracing on x86. Memory mapped I/O tracing is available on x86 via CONFIG_MMIOTRACE but that relies on page faults so it doesn't work with port I/O. This feature uses tracepoints in a similar manner as CONFIG_TRACE_MMIO_ACCESS. Signed-off-by: Dan Raymond <raymod2@gmail.com> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> --- V1 -> V2: - create header file for prototypes to silence new compiler warning - reduce CPU overhead to 2 instructions (no branching) when tracing disabled - fix imprecise IP logging by retrieving the IP off the stack instead of using compile time labels V2 -> V3: - restore missing semicolon V3 -> V4: - make GPL licenses consistent - change pointer arguments from (long) to (void *) - eliminate include guard checks and use -DDISABLE_TRACEPOINTS instead to disable tracepoints in arch/x86/boot/* - fix compiler warnings due to signed/unsigned mismatch in arch_cmpxchg64() arch/x86/boot/Makefile | 1 + arch/x86/boot/compressed/Makefile | 1 + arch/x86/include/asm/cmpxchg_32.h | 13 ++++---- arch/x86/include/asm/shared/io.h | 9 ++++++ arch/x86/lib/Makefile | 1 + arch/x86/lib/trace_portio.c | 21 +++++++++++++ include/linux/trace_portio.h | 6 ++++ include/linux/tracepoint-defs.h | 2 +- include/trace/events/portio.h | 49 +++++++++++++++++++++++++++++++ 9 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 arch/x86/lib/trace_portio.c create mode 100644 include/linux/trace_portio.h create mode 100644 include/trace/events/portio.h base-commit: be8b93b5cc7d533eb8c9b0590cdac055ecafe13a