Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1593664
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 11/35] perf cpumap: Convert cpu_map.refcnt from atomic_t to refcount_t |
| Date | 2017-03-06 20:50 +0100 |
| Message-ID | <ti6NR-4s3-65@gated-at.bofh.it> (permalink) |
| References | <ti6E9-4o1-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Elena Reshetova <elena.reshetova@intel.com>
The refcount_t type and corresponding API should be used instead of atomic_t
when the variable is used as a reference counter.
This allows to avoid accidental refcounter overflows that might lead to
use-after-free situations.
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: David Windsor <dwindsor@gmail.com>
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Kees Kook <keescook@chromium.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Windsor <dwindsor@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hans Liljestrand <ishkamiel@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: alsa-devel@alsa-project.org
Link: http://lkml.kernel.org/r/1487691303-31858-3-git-send-email-elena.reshetova@intel.com
[ fixed mixed conversion to refcount in tests/cpumap.c ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/cpumap.c | 2 +-
tools/perf/util/cpumap.c | 16 ++++++++--------
tools/perf/util/cpumap.h | 4 ++--
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c
index f168a85992d0..4478773cdb97 100644
--- a/tools/perf/tests/cpumap.c
+++ b/tools/perf/tests/cpumap.c
@@ -66,7 +66,7 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused,
TEST_ASSERT_VAL("wrong nr", map->nr == 2);
TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1);
TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256);
- TEST_ASSERT_VAL("wrong refcnt", atomic_read(&map->refcnt) == 1);
+ TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1);
cpu_map__put(map);
return 0;
}
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 8c7504939113..39ad2caccf56 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -29,7 +29,7 @@ static struct cpu_map *cpu_map__default_new(void)
cpus->map[i] = i;
cpus->nr = nr_cpus;
- atomic_set(&cpus->refcnt, 1);
+ refcount_set(&cpus->refcnt, 1);
}
return cpus;
@@ -43,7 +43,7 @@ static struct cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus)
if (cpus != NULL) {
cpus->nr = nr_cpus;
memcpy(cpus->map, tmp_cpus, payload_size);
- atomic_set(&cpus->refcnt, 1);
+ refcount_set(&cpus->refcnt, 1);
}
return cpus;
@@ -252,7 +252,7 @@ struct cpu_map *cpu_map__dummy_new(void)
if (cpus != NULL) {
cpus->nr = 1;
cpus->map[0] = -1;
- atomic_set(&cpus->refcnt, 1);
+ refcount_set(&cpus->refcnt, 1);
}
return cpus;
@@ -269,7 +269,7 @@ struct cpu_map *cpu_map__empty_new(int nr)
for (i = 0; i < nr; i++)
cpus->map[i] = -1;
- atomic_set(&cpus->refcnt, 1);
+ refcount_set(&cpus->refcnt, 1);
}
return cpus;
@@ -278,7 +278,7 @@ struct cpu_map *cpu_map__empty_new(int nr)
static void cpu_map__delete(struct cpu_map *map)
{
if (map) {
- WARN_ONCE(atomic_read(&map->refcnt) != 0,
+ WARN_ONCE(refcount_read(&map->refcnt) != 0,
"cpu_map refcnt unbalanced\n");
free(map);
}
@@ -287,13 +287,13 @@ static void cpu_map__delete(struct cpu_map *map)
struct cpu_map *cpu_map__get(struct cpu_map *map)
{
if (map)
- atomic_inc(&map->refcnt);
+ refcount_inc(&map->refcnt);
return map;
}
void cpu_map__put(struct cpu_map *map)
{
- if (map && atomic_dec_and_test(&map->refcnt))
+ if (map && refcount_dec_and_test(&map->refcnt))
cpu_map__delete(map);
}
@@ -357,7 +357,7 @@ int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
/* ensure we process id in increasing order */
qsort(c->map, c->nr, sizeof(int), cmp_ids);
- atomic_set(&c->refcnt, 1);
+ refcount_set(&c->refcnt, 1);
*res = c;
return 0;
}
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 1a0549af8f5c..e84491636c1b 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -3,13 +3,13 @@
#include <stdio.h>
#include <stdbool.h>
-#include <linux/atomic.h>
+#include <linux/refcount.h>
#include "perf.h"
#include "util/debug.h"
struct cpu_map {
- atomic_t refcnt;
+ refcount_t refcnt;
int nr;
int map[];
};
--
2.9.3
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 22/35] perf cpumap: Introduce cpu_map__snprint_mask() Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 12/35] perf comm: Convert comm_str.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 30/35] perf tools: Force uncore events to system wide monitoring Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 27/35] perf probe: Generalize probe event file open routine Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 17/35] perf thread: convert thread.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 25/35] kretprobes: Ensure probe location is at function entry Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 13/35] perf dso: Convert dso.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 21/35] perf ftrace: Add support for --pid option Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 19/35] perf evlist: Clarify a bit the use of perf_mmap->refcnt Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 23/35] perf ftrace: Add support for -a and -C option Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 10/35] perf cgroup: Convert cgroup_sel.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 07/35] tools include: Provide gcc based cmpxchg fallback for !x86 Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 20/35] perf tools: Allow sorting by symbol size Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 28/35] perf intel-PT/BTS: Add missing initialization Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 33/35] perf bench futex: Fix build on musl + clang Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 05/35] tools arch x86: Introduce atomic_cmpxchg() Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 14/35] perf map: Convert map.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 16/35] perf evlist: Convert perf_map.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 06/35] tools include: Introduce atomic_cmpxchg_{relaxed,release}() Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 24/35] perf ftrace: Use pager for displaying result Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 35/35] perf bench numa: Add more comment for -c option Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 11/35] perf cpumap: Convert cpu_map.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 02/35] perf stat: Issue a HW watchdog disable hint Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 26/35] trace/kprobes: Allow return probes with offsets and absolute addresses Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 15/35] perf map: Convert map_groups.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 01/35] perf vendor events: Add mapping for KnightsMill PMU events Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 32/35] perf bench futex: Use __maybe_unused Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 29/35] trace/kprobes: Add back warning about offset in return probes Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 31/35] tools build: Add test for sched_getcpu() Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 09/35] tools include: Adopt kernel's refcount.h Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 18/35] perf thread_map: Convert thread_map.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
[PATCH 34/35] tools build: Use the same CC for feature detection and actual build Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-03-06 20:50 +0100
Re: [GIT PULL 00/35] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2017-03-07 08:20 +0100
csiph-web