lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 7 Jul 2021 14:43:07 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Jiri Olsa <jolsa@...hat.com>
Cc:     lkml <linux-kernel@...r.kernel.org>,
        Peter Zijlstra <a.p.zijlstra@...llo.nl>,
        Ingo Molnar <mingo@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Namhyung Kim <namhyung@...nel.org>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Michael Petlan <mpetlan@...hat.com>,
        Ian Rogers <irogers@...gle.com>, nakamura.shun@...itsu.com,
        linux-perf-users@...r.kernel.org
Subject: Re: [PATCH 6/7] libperF: Add group support to perf_evsel__open

Em Tue, Jul 06, 2021 at 05:17:03PM +0200, Jiri Olsa escreveu:
> Adding support to set group_fd in perf_evsel__open
> call and make it to follow the group setup.
> 
> Signed-off-by: Jiri Olsa <jolsa@...nel.org>
> ---
>  tools/lib/perf/evsel.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
> index 3e6638d27c45..9ebf7122d476 100644
> --- a/tools/lib/perf/evsel.c
> +++ b/tools/lib/perf/evsel.c
> @@ -17,6 +17,7 @@
>  #include <linux/string.h>
>  #include <sys/ioctl.h>
>  #include <sys/mman.h>
> +#include <asm/bug.h>
>  
>  void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
>  		      int idx)
> @@ -76,6 +77,25 @@ sys_perf_event_open(struct perf_event_attr *attr,
>  	return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
>  }
>  
> +static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
> +{
> +	struct perf_evsel *leader = evsel->leader;
> +	int fd;
> +
> +	if (evsel == leader)
> +		return -1;
> +
> +	/*
> +	 * Leader must be already processed/open,
> +	 * if not it's a bug.
> +	 */
> +	BUG_ON(!leader->fd);

Humm, having panics in library code looks ugly, why can't we just return
some errno and let the whatever is using the library to fail gracefully?

I applied the patches so far, will make them available at tmp.perf/core
now.

- Arnaldo

> +	fd = FD(leader, cpu, thread);
> +	BUG_ON(fd == -1);
> +	return fd;
> +}
> +
>  int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
>  		     struct perf_thread_map *threads)
>  {
> @@ -111,11 +131,13 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
>  
>  	for (cpu = 0; cpu < cpus->nr; cpu++) {
>  		for (thread = 0; thread < threads->nr; thread++) {
> -			int fd;
> +			int fd, group_fd;
> +
> +			group_fd = get_group_fd(evsel, cpu, thread);
>  
>  			fd = sys_perf_event_open(&evsel->attr,
>  						 threads->map[thread].pid,
> -						 cpus->map[cpu], -1, 0);
> +						 cpus->map[cpu], group_fd, 0);
>  
>  			if (fd < 0)
>  				return -errno;
> -- 
> 2.31.1
> 

-- 

- Arnaldo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ