Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libperf: Add perf_cpu_map__refcnt() interanl accessor to use in the maps test

To remove one more direct access to 'struct perf_cpu_map' so that we can
intercept accesses to its instantiations and refcount check it to catch
use after free, etc.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Link: https://lore.kernel.org/lkml/ZD1qdYjG+DL6KOfP@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+9 -5
+3 -3
tools/lib/perf/cpumap.c
··· 40 40 static void cpu_map__delete(struct perf_cpu_map *map) 41 41 { 42 42 if (map) { 43 - WARN_ONCE(refcount_read(&map->refcnt) != 0, 43 + WARN_ONCE(refcount_read(perf_cpu_map__refcnt(map)) != 0, 44 44 "cpu_map refcnt unbalanced\n"); 45 45 free(map); 46 46 } ··· 49 49 struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map) 50 50 { 51 51 if (map) 52 - refcount_inc(&map->refcnt); 52 + refcount_inc(perf_cpu_map__refcnt(map)); 53 53 return map; 54 54 } 55 55 56 56 void perf_cpu_map__put(struct perf_cpu_map *map) 57 57 { 58 - if (map && refcount_dec_and_test(&map->refcnt)) 58 + if (map && refcount_dec_and_test(perf_cpu_map__refcnt(map))) 59 59 cpu_map__delete(map); 60 60 } 61 61
+4
tools/lib/perf/include/internal/cpumap.h
··· 30 30 31 31 void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus); 32 32 33 + static inline refcount_t *perf_cpu_map__refcnt(struct perf_cpu_map *map) 34 + { 35 + return &map->refcnt; 36 + } 33 37 #endif /* __LIBPERF_INTERNAL_CPUMAP_H */
+2 -2
tools/perf/tests/cpumap.c
··· 68 68 TEST_ASSERT_VAL("wrong nr", perf_cpu_map__nr(map) == 2); 69 69 TEST_ASSERT_VAL("wrong cpu", perf_cpu_map__cpu(map, 0).cpu == 1); 70 70 TEST_ASSERT_VAL("wrong cpu", perf_cpu_map__cpu(map, 1).cpu == 256); 71 - TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1); 71 + TEST_ASSERT_VAL("wrong refcnt", refcount_read(perf_cpu_map__refcnt(map)) == 1); 72 72 perf_cpu_map__put(map); 73 73 return 0; 74 74 } ··· 94 94 TEST_ASSERT_VAL("wrong nr", perf_cpu_map__nr(map) == 256); 95 95 TEST_ASSERT_VAL("wrong cpu", perf_cpu_map__cpu(map, 0).cpu == 1); 96 96 TEST_ASSERT_VAL("wrong cpu", perf_cpu_map__max(map).cpu == 256); 97 - TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1); 97 + TEST_ASSERT_VAL("wrong refcnt", refcount_read(perf_cpu_map__refcnt(map)) == 1); 98 98 perf_cpu_map__put(map); 99 99 return 0; 100 100 }