From e6caf76ddcbeeb405084e53866ef64c2554abf46 Mon Sep 17 00:00:00 2001 From: Sven Schnelle Date: Thu, 9 Mar 2023 13:52:54 +0100 Subject: Add config3 field to struct perf_event_attr Linux kernel commit 09519ec3b19 ("perf: Add perf_event_attr::config3") aka v6.3-rc1~29^2~13 added a new config3 field to struct perf_event_attr. Add this field and implement its decoding in strace, which also fixes compilation of tests because of an array out-of-bounds warning in tests/perf_event.c. Signed-off-by: Sven Schnelle * bundled/linux/include/uapi/linux/perf_event.h: Update to headers_install'ed Linux kernel v6.3-rc1. * src/perf_event_struct.h (struct perf_event_attr): Add config3 field. * src/perf.c (print_perf_event_attr): Print config3 field. * tests/perf_event_open.c (print_event_attr): Check it. --- bundled/linux/include/uapi/linux/perf_event.h | 5 +++++ src/perf.c | 4 ++++ src/perf_event_struct.h | 2 ++ tests/perf_event_open.c | 10 +++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bundled/linux/include/uapi/linux/perf_event.h b/bundled/linux/include/uapi/linux/perf_event.h index 8da6e2592..93d5c3f59 100644 --- a/bundled/linux/include/uapi/linux/perf_event.h +++ b/bundled/linux/include/uapi/linux/perf_event.h @@ -374,6 +374,7 @@ enum perf_event_read_format { #define PERF_ATTR_SIZE_VER5 112 /* add: aux_watermark */ #define PERF_ATTR_SIZE_VER6 120 /* add: aux_sample_size */ #define PERF_ATTR_SIZE_VER7 128 /* add: sig_data */ +#define PERF_ATTR_SIZE_VER8 136 /* add: config3 */ /* * Hardware event_id to monitor via a performance monitoring event: @@ -511,8 +512,12 @@ struct perf_event_attr { /* * User provided data if sigtrap=1, passed back to user via * siginfo_t::si_perf_data, e.g. to permit user to identify the event. + * Note, siginfo_t::si_perf_data is long-sized, and sig_data will be + * truncated accordingly on 32 bit architectures. */ __u64 sig_data; + + __u64 config3; /* extension of config2 */ }; /* diff --git a/src/perf.c b/src/perf.c index 76c4fab08..78681ecee 100644 --- a/src/perf.c +++ b/src/perf.c @@ -434,6 +434,10 @@ print_perf_event_attr(struct tcb *const tcp, const kernel_ulong_t addr) tprint_struct_next(); PRINT_FIELD_X(*attr, sig_data); + STRACE_PERF_CHECK_FIELD(config3); + tprint_struct_next(); + PRINT_FIELD_X(*attr, config3); + print_perf_event_attr_out: if ((attr->size && (attr->size > size)) || (!attr->size && (size < PERF_ATTR_SIZE_VER0))) { diff --git a/src/perf_event_struct.h b/src/perf_event_struct.h index d9020f6e9..21113b376 100644 --- a/src/perf_event_struct.h +++ b/src/perf_event_struct.h @@ -94,6 +94,8 @@ struct perf_event_attr { /* End of ver 6 - 120 bytes */ uint64_t sig_data; /* End of ver 7 - 128 bytes */ + uint64_t config3; + /* End of ver 8 - 136 bytes */ }; struct perf_event_query_bpf { diff --git a/tests/perf_event_open.c b/tests/perf_event_open.c index 139d16ce5..6a01c8186 100644 --- a/tests/perf_event_open.c +++ b/tests/perf_event_open.c @@ -139,7 +139,7 @@ print_event_attr(struct perf_event_attr *attr_ptr, size_t size, enum { STRACE_PEA_ABBREV_SIZE = offsetof(struct perf_event_attr, wakeup_events), - STRACE_PEA_SIZE = 128, + STRACE_PEA_SIZE = 136, }; uint32_t read_size; @@ -385,6 +385,14 @@ print_event_attr(struct perf_event_attr *attr_ptr, size_t size, val = attr->sig_data; printf(", sig_data=%#" PRIx64, (uint64_t) val); + if (size <= 128) { + cutoff = 128; + goto end; + } + + val = attr->config3; + printf(", config3=%#" PRIx64, (uint64_t) val); + cutoff = STRACE_PEA_SIZE; end: -- cgit v1.2.1