All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Elena Reshetova <elena.reshetova@intel.com>
Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org,
	peterz@infradead.org, gregkh@linuxfoundation.org,
	mingo@redhat.com, alexander.shishkin@linux.intel.com,
	jolsa@kernel.org, mark.rutland@arm.com,
	akpm@linux-foundation.org, matija.glavinic-pecotic.ext@nokia.com,
	Hans Liljestrand <ishkamiel@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	David Windsor <dwindsor@gmail.com>
Subject: Re: [PATCH 2/9] tools: convert cpu_map.refcnt from atomic_t to refcount_t
Date: Wed, 22 Feb 2017 17:29:40 -0300	[thread overview]
Message-ID: <20170222202940.GD20447@kernel.org> (raw)
In-Reply-To: <1487691303-31858-3-git-send-email-elena.reshetova@intel.com>

Em Tue, Feb 21, 2017 at 05:34:56PM +0200, Elena Reshetova escreveu:
> 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.

The following patch was needed for this one to build:

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.h b/tools/perf/util/cpumap.h
index e84491636c1b..ab1aeed8cd5d 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -3,10 +3,10 @@
 
 #include <stdio.h>
 #include <stdbool.h>
-#include <linux/refcount.h>
 
 #include "perf.h"
 #include "util/debug.h"
+#include <linux/refcount.h>
 
 struct cpu_map {
 	refcount_t refcnt;
 
> Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
> Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: David Windsor <dwindsor@gmail.com>
> ---
>  tools/perf/util/cpumap.c | 16 ++++++++--------
>  tools/perf/util/cpumap.h |  4 ++--
>  2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
> index 2c0b522..0e21e28 100644
> --- a/tools/perf/util/cpumap.c
> +++ b/tools/perf/util/cpumap.c
> @@ -28,7 +28,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;
> @@ -42,7 +42,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;
> @@ -251,7 +251,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;
> @@ -268,7 +268,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;
> @@ -277,7 +277,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);
>  	}
> @@ -286,13 +286,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);
>  }
>  
> @@ -356,7 +356,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 06bd689..4f12a01 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.7.4

  reply	other threads:[~2017-02-22 20:37 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 15:34 [PATCH 0/9] tools subsystem refcounter conversions Elena Reshetova
2017-02-21 15:34 ` [PATCH 1/9] tools: convert cgroup_sel.refcnt from atomic_t to refcount_t Elena Reshetova
2017-02-21 15:43   ` Arnaldo Carvalho de Melo
2017-02-22 14:29     ` Reshetova, Elena
2017-02-22 14:29       ` Reshetova, Elena
2017-02-22 15:37       ` Arnaldo Carvalho de Melo
2017-02-22 15:37         ` Arnaldo Carvalho de Melo
2017-02-22 16:10         ` Reshetova, Elena
2017-02-22 16:10           ` Reshetova, Elena
2017-02-22 20:28           ` Arnaldo Carvalho de Melo
2017-02-22 20:28             ` Arnaldo Carvalho de Melo
2017-02-23 13:10             ` Reshetova, Elena
2017-02-23 13:10               ` Reshetova, Elena
2017-03-07  7:36   ` [tip:perf/core] perf cgroup: Convert " tip-bot for Elena Reshetova
2017-02-21 15:34 ` [PATCH 2/9] tools: convert cpu_map.refcnt " Elena Reshetova
2017-02-22 20:29   ` Arnaldo Carvalho de Melo [this message]
2017-02-21 15:34 ` [PATCH 3/9] tools: convert comm_str.refcnt " Elena Reshetova
2017-02-22 20:33   ` Arnaldo Carvalho de Melo
2017-02-22 22:20     ` Arnaldo Carvalho de Melo
2017-02-22 22:31       ` Arnaldo Carvalho de Melo
2017-02-23  9:16         ` Reshetova, Elena
2017-02-23  9:16           ` Reshetova, Elena
2017-02-23 13:02           ` Arnaldo Carvalho de Melo
2017-02-21 15:34 ` [PATCH 4/9] tools: convert dso.refcnt " Elena Reshetova
2017-02-22 20:37   ` Arnaldo Carvalho de Melo
2017-02-22 20:40     ` Arnaldo Carvalho de Melo
2017-03-07  7:45   ` [tip:perf/core] perf dso: Convert " tip-bot for Elena Reshetova
2017-02-21 15:34 ` [PATCH 5/9] tools: convert map.refcnt " Elena Reshetova
2017-03-07  7:48   ` [tip:perf/core] perf map: Convert " tip-bot for Elena Reshetova
2017-02-21 15:35 ` [PATCH 6/9] tools: convert map_groups.refcnt " Elena Reshetova
2017-02-22 20:55   ` Arnaldo Carvalho de Melo
2017-02-21 15:35 ` [PATCH 7/9] tools: convert perf_map.refcnt " Elena Reshetova
2017-02-21 15:35 ` [PATCH 8/9] tools: convert thread.refcnt " Elena Reshetova
2017-02-22 23:06   ` Arnaldo Carvalho de Melo
2017-03-07  7:56   ` [tip:perf/core] perf thread: " tip-bot for Elena Reshetova
2017-02-21 15:35 ` [PATCH 9/9] tools: convert thread_map.refcnt " Elena Reshetova
2017-02-21 15:39 ` [PATCH 0/9] tools subsystem refcounter conversions Arnaldo Carvalho de Melo
2017-02-22 23:23   ` Arnaldo Carvalho de Melo
2017-02-22 23:29     ` Arnaldo Carvalho de Melo
2017-02-23 11:39       ` Reshetova, Elena
2017-02-23 11:39         ` Reshetova, Elena
2017-02-23 12:50         ` Arnaldo Carvalho de Melo
2017-02-23 12:50           ` Arnaldo Carvalho de Melo
2017-02-23 16:23         ` Arnaldo Carvalho de Melo
2017-02-23 16:23           ` Arnaldo Carvalho de Melo
2017-02-24  7:27           ` Reshetova, Elena
2017-02-24  7:27             ` Reshetova, Elena
2017-02-24 13:32             ` Arnaldo Carvalho de Melo
2017-02-24 13:32               ` Arnaldo Carvalho de Melo
2017-03-07  8:02           ` [tip:perf/core] perf evlist: Clarify a bit the use of perf_mmap->refcnt tip-bot for Arnaldo Carvalho de Melo
2017-02-21 15:46 ` [PATCH 0/9] tools subsystem refcounter conversions Peter Zijlstra
2017-02-21 16:00   ` Reshetova, Elena
2017-02-21 16:00     ` Reshetova, Elena

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170222202940.GD20447@kernel.org \
    --to=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=dwindsor@gmail.com \
    --cc=elena.reshetova@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ishkamiel@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=matija.glavinic-pecotic.ext@nokia.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.