perf target: Remove uid from target
authorIan Rogers <irogers@google.com>
Wed, 4 Jun 2025 17:45:43 +0000 (10:45 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Mon, 9 Jun 2025 18:18:18 +0000 (11:18 -0700)
Gathering threads with a uid by scanning /proc is inherently racy
leading to perf_event_open failures that quit perf. All users of the
functionality now use BPF filters, so remove uid and uid_str from
target.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250604174545.2853620-10-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
13 files changed:
tools/perf/builtin-ftrace.c
tools/perf/builtin-kvm.c
tools/perf/builtin-stat.c
tools/perf/builtin-trace.c
tools/perf/tests/backward-ring-buffer.c
tools/perf/tests/event-times.c
tools/perf/tests/openat-syscall-tp-fields.c
tools/perf/tests/perf-record.c
tools/perf/tests/task-exit.c
tools/perf/util/bpf-filter.c
tools/perf/util/evlist.c
tools/perf/util/target.c
tools/perf/util/target.h

index bba36ebc2aa7f2908ebd18885f0b0cbf66ec1142..3a253a1b9f4526b9bcca0f9f4e39fc7933e716a8 100644 (file)
@@ -1663,7 +1663,6 @@ int cmd_ftrace(int argc, const char **argv)
        int (*cmd_func)(struct perf_ftrace *) = NULL;
        struct perf_ftrace ftrace = {
                .tracer = DEFAULT_TRACER,
-               .target = { .uid = UINT_MAX, },
        };
        const struct option common_options[] = {
        OPT_STRING('p', "pid", &ftrace.target.pid, "pid",
index 67fd2b006b0b6f85c839014dcd3d0f98567feba6..d75bd368498045160eae975d7ba941108ab9e0f9 100644 (file)
@@ -1871,8 +1871,6 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
        kvm->opts.user_interval = 1;
        kvm->opts.mmap_pages = 512;
        kvm->opts.target.uses_mmap = false;
-       kvm->opts.target.uid_str = NULL;
-       kvm->opts.target.uid = UINT_MAX;
 
        symbol__init(NULL);
        disable_buildid_cache();
index bf0e5e12d992f0a56a85fe0031f0a1f6cf09acb6..50fc53adb7e458e694d0ffd9bf8f0d03b31af032 100644 (file)
@@ -108,9 +108,7 @@ static struct parse_events_option_args parse_events_option_args = {
 
 static bool all_counters_use_bpf = true;
 
-static struct target target = {
-       .uid    = UINT_MAX,
-};
+static struct target target;
 
 static volatile sig_atomic_t   child_pid                       = -1;
 static int                     detailed_run                    =  0;
index 4bb062b96f5138477c9c73170146ef4a1aa841ef..bf9b5d0630d3ddacbda102e02a18478609d69f5b 100644 (file)
@@ -5399,7 +5399,6 @@ int cmd_trace(int argc, const char **argv)
        struct trace trace = {
                .opts = {
                        .target = {
-                               .uid       = UINT_MAX,
                                .uses_mmap = true,
                        },
                        .user_freq     = UINT_MAX,
index 79a980b1e7869305d52d7ced03afdf39538916f4..c5e7999f281775a02165d0c4eea564592f5ee096 100644 (file)
@@ -91,7 +91,6 @@ static int test__backward_ring_buffer(struct test_suite *test __maybe_unused, in
        struct parse_events_error parse_error;
        struct record_opts opts = {
                .target = {
-                       .uid = UINT_MAX,
                        .uses_mmap = true,
                },
                .freq         = 0,
index deefe5003bfc293037162926261099fc46c73117..2148024b4f4af96aa39fed2cdaa04a4c5cdd401d 100644 (file)
@@ -17,9 +17,7 @@
 static int attach__enable_on_exec(struct evlist *evlist)
 {
        struct evsel *evsel = evlist__last(evlist);
-       struct target target = {
-               .uid = UINT_MAX,
-       };
+       struct target target = {};
        const char *argv[] = { "true", NULL, };
        char sbuf[STRERR_BUFSIZE];
        int err;
index 0ef4ba7c1571db7dd2120942af3bfce6e1332005..2a139d2781a87574a4cdd8dbf3f915e4526c379f 100644 (file)
@@ -28,7 +28,6 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 {
        struct record_opts opts = {
                .target = {
-                       .uid = UINT_MAX,
                        .uses_mmap = true,
                },
                .no_buffering = true,
index 0958c7c8995f427982919bfb0dcc36c5ad63d982..0b3c37e668717c68f184406128334eae54ed8249 100644 (file)
@@ -45,7 +45,6 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest
 {
        struct record_opts opts = {
                .target = {
-                       .uid = UINT_MAX,
                        .uses_mmap = true,
                },
                .no_buffering = true,
index 8e328bbd509dc66ef3c6322e5d19aed20932d5fa..4053ff2813bb79cb8e7d1b1a3a1f0ba18c9aebe4 100644 (file)
@@ -46,7 +46,6 @@ static int test__task_exit(struct test_suite *test __maybe_unused, int subtest _
        struct evsel *evsel;
        struct evlist *evlist;
        struct target target = {
-               .uid            = UINT_MAX,
                .uses_mmap      = true,
        };
        const char *argv[] = { "true", NULL };
index 92e2f054b45e91ddb7e7c86098f8657734188385..d0e013eeb0f75324f64b5adf05b6037cb1b01710 100644 (file)
@@ -450,7 +450,7 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
        struct bpf_program *prog;
        struct bpf_link *link;
        struct perf_bpf_filter_entry *entry;
-       bool needs_idx_hash = !target__has_cpu(target) && !target->uid_str;
+       bool needs_idx_hash = !target__has_cpu(target);
 
        entry = calloc(MAX_FILTERS, sizeof(*entry));
        if (entry == NULL)
index dcd1130502dfc24ad49a3132de37fe460f46f307..bed91bc88510340183500f1bc5e392bed33f40ad 100644 (file)
@@ -1006,8 +1006,7 @@ int evlist__create_maps(struct evlist *evlist, struct target *target)
         * per-thread data. thread_map__new_str will call
         * thread_map__new_all_cpus to enumerate all threads.
         */
-       threads = thread_map__new_str(target->pid, target->tid, target->uid,
-                                     all_threads);
+       threads = thread_map__new_str(target->pid, target->tid, UINT_MAX, all_threads);
 
        if (!threads)
                return -1;
index f3ad59ccfa998cb21133297e79c505ab982f9de3..8cf71bea295a22308d8597bfb4195fe1c0cc14e2 100644 (file)
@@ -28,20 +28,6 @@ enum target_errno target__validate(struct target *target)
                        ret = TARGET_ERRNO__PID_OVERRIDE_CPU;
        }
 
-       /* UID and PID are mutually exclusive */
-       if (target->tid && target->uid_str) {
-               target->uid_str = NULL;
-               if (ret == TARGET_ERRNO__SUCCESS)
-                       ret = TARGET_ERRNO__PID_OVERRIDE_UID;
-       }
-
-       /* UID and CPU are mutually exclusive */
-       if (target->uid_str && target->cpu_list) {
-               target->cpu_list = NULL;
-               if (ret == TARGET_ERRNO__SUCCESS)
-                       ret = TARGET_ERRNO__UID_OVERRIDE_CPU;
-       }
-
        /* PID and SYSTEM are mutually exclusive */
        if (target->tid && target->system_wide) {
                target->system_wide = false;
@@ -49,13 +35,6 @@ enum target_errno target__validate(struct target *target)
                        ret = TARGET_ERRNO__PID_OVERRIDE_SYSTEM;
        }
 
-       /* UID and SYSTEM are mutually exclusive */
-       if (target->uid_str && target->system_wide) {
-               target->system_wide = false;
-               if (ret == TARGET_ERRNO__SUCCESS)
-                       ret = TARGET_ERRNO__UID_OVERRIDE_SYSTEM;
-       }
-
        /* BPF and CPU are mutually exclusive */
        if (target->bpf_str && target->cpu_list) {
                target->cpu_list = NULL;
@@ -70,13 +49,6 @@ enum target_errno target__validate(struct target *target)
                        ret = TARGET_ERRNO__BPF_OVERRIDE_PID;
        }
 
-       /* BPF and UID are mutually exclusive */
-       if (target->bpf_str && target->uid_str) {
-               target->uid_str = NULL;
-               if (ret == TARGET_ERRNO__SUCCESS)
-                       ret = TARGET_ERRNO__BPF_OVERRIDE_UID;
-       }
-
        /* BPF and THREADS are mutually exclusive */
        if (target->bpf_str && target->per_thread) {
                target->per_thread = false;
@@ -124,31 +96,19 @@ uid_t parse_uid(const char *str)
        return result->pw_uid;
 }
 
-enum target_errno target__parse_uid(struct target *target)
-{
-       target->uid = parse_uid(target->uid_str);
-
-       return target->uid != UINT_MAX ? TARGET_ERRNO__SUCCESS : TARGET_ERRNO__INVALID_UID;
-}
-
 /*
  * This must have a same ordering as the enum target_errno.
  */
 static const char *target__error_str[] = {
        "PID/TID switch overriding CPU",
-       "PID/TID switch overriding UID",
-       "UID switch overriding CPU",
        "PID/TID switch overriding SYSTEM",
-       "UID switch overriding SYSTEM",
        "SYSTEM/CPU switch overriding PER-THREAD",
        "BPF switch overriding CPU",
        "BPF switch overriding PID/TID",
-       "BPF switch overriding UID",
        "BPF switch overriding THREAD",
-       "Invalid User: %s",
 };
 
-int target__strerror(struct target *target, int errnum,
+int target__strerror(struct target *target __maybe_unused, int errnum,
                          char *buf, size_t buflen)
 {
        int idx;
@@ -173,10 +133,6 @@ int target__strerror(struct target *target, int errnum,
                snprintf(buf, buflen, "%s", msg);
                break;
 
-       case TARGET_ERRNO__INVALID_UID:
-               snprintf(buf, buflen, msg, target->uid_str);
-               break;
-
        default:
                /* cannot reach here */
                break;
index e082bda990fbc4fbcf5ae6536a8a3eb11e633a22..84ebb9c940c6c6cfaa1734d02a90b2768f904482 100644 (file)
@@ -9,9 +9,7 @@ struct target {
        const char   *pid;
        const char   *tid;
        const char   *cpu_list;
-       const char   *uid_str;
        const char   *bpf_str;
-       uid_t        uid;
        bool         system_wide;
        bool         uses_mmap;
        bool         default_per_cpu;
@@ -36,32 +34,24 @@ enum target_errno {
 
        /* for target__validate() */
        TARGET_ERRNO__PID_OVERRIDE_CPU  = __TARGET_ERRNO__START,
-       TARGET_ERRNO__PID_OVERRIDE_UID,
-       TARGET_ERRNO__UID_OVERRIDE_CPU,
        TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
-       TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
        TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
        TARGET_ERRNO__BPF_OVERRIDE_CPU,
        TARGET_ERRNO__BPF_OVERRIDE_PID,
-       TARGET_ERRNO__BPF_OVERRIDE_UID,
        TARGET_ERRNO__BPF_OVERRIDE_THREAD,
 
-       /* for target__parse_uid() */
-       TARGET_ERRNO__INVALID_UID,
-
        __TARGET_ERRNO__END,
 };
 
 enum target_errno target__validate(struct target *target);
 
 uid_t parse_uid(const char *str);
-enum target_errno target__parse_uid(struct target *target);
 
 int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
 
 static inline bool target__has_task(struct target *target)
 {
-       return target->tid || target->pid || target->uid_str;
+       return target->tid || target->pid;
 }
 
 static inline bool target__has_cpu(struct target *target)