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]
Message-ID: <c321e998-6fd2-86e9-7876-7250a9b23c25@intel.com>
Date:   Wed, 2 Jun 2021 14:18:47 +0300
From:   Adrian Hunter <adrian.hunter@...el.com>
To:     Leo Yan <leo.yan@...aro.org>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...hat.com>,
        Namhyung Kim <namhyung@...nel.org>,
        Thomas Gleixner <tglx@...utronix.de>, x86@...nel.org,
        "H. Peter Anvin" <hpa@...or.com>,
        Mathieu Poirier <mathieu.poirier@...aro.org>,
        Suzuki K Poulose <suzuki.poulose@....com>,
        Mike Leach <mike.leach@...aro.org>,
        Andi Kleen <ak@...ux.intel.com>,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
        coresight@...ts.linaro.org, linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH v2 8/8] perf record: Directly bail out for compat case

On 2/06/21 1:30 pm, Leo Yan wrote:
> Since the 64-bit atomicity is not promised in 32-bit perf, directly
> report the error and bail out for this case.
> 
> Now only applies on x86_64 and Arm64 platforms.
> 
> Suggested-by: Adrian Hunter <adrian.hunter@...el.com>

Maybe we can do better for the compat case.

We can assume the upper 32-bits change very seldom,
and always increase. So for the 'read' case:

	u64 first, second, last;
	u64 mask = (u64)((u32)-1) << 32;

	do {
		first = READ_ONCE(pc->aux_head);
		rmb();
		second = READ_ONCE(pc->aux_head);
		rmb();
		last = READ_ONCE(pc->aux_head);
	} while ((first & mask) != (last & mask));
	return second;

For the write case, we can cause a fatal error only if the new
tail has non-zero upper 32-bits.  That gives up to 4GiB of data
before aborting:

	if (tail & mask)
		return -1;
	smp_mb();
	WRITE_ONCE(pc->aux_tail, tail);

> Signed-off-by: Leo Yan <leo.yan@...aro.org>
> ---
>  tools/perf/builtin-record.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 3337b5f93336..f47e298281f7 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -74,6 +74,7 @@
>  #include <linux/zalloc.h>
>  #include <linux/bitmap.h>
>  #include <sys/time.h>
> +#include <sys/utsname.h>
>  
>  struct switch_output {
>  	bool		 enabled;
> @@ -848,6 +849,22 @@ static int record__mmap_evlist(struct record *rec,
>  				  opts->auxtrace_sample_mode;
>  	char msg[512];
>  
> +#ifndef __LP64__
> +	struct utsname uts;
> +	int ret;
> +
> +	ret = uname(&uts);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (!strncmp(uts.machine, "x86_64", 6) || !strncmp(uts.machine, "aarch64", 7) ||
> +	    !strncmp(uts.machine, "arm64", 5)) {
> +		pr_err("Error, 32-bit perf cannot record from a 64-bit kernel.\n"
> +		       "Please use a 64-bit version of perf instead.\n");
> +		return -ENOTSUP;
> +	}
> +#endif
> +
>  	if (opts->affinity != PERF_AFFINITY_SYS)
>  		cpu__setup_cpunode_map();
>  
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ