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: <0a454227-ab99-4eb9-a736-1c826cfeb97d@arm.com>
Date: Wed, 15 May 2024 13:12:02 +0100
From: Robin Murphy <robin.murphy@....com>
To: Namhyung Kim <namhyung@...nel.org>, Will Deacon <will@...nel.org>,
 Mark Rutland <mark.rutland@....com>
Cc: Ingo Molnar <mingo@...nel.org>, Peter Zijlstra <peterz@...radead.org>,
 LKML <linux-kernel@...r.kernel.org>, linux-arm-kernel@...ts.infradead.org,
 Greg Thelen <gthelen@...gle.com>, Tuan Phan <tuanphan@...amperecomputing.com>
Subject: Re: [PATCH] perf/arm-dmc620: Fix lockdep assert in ->event_init()

On 2024-05-14 7:00 pm, Namhyung Kim wrote:
> for_each_sibling_event() checks leader's ctx but it doesn't have the ctx
> yet if it's the leader.  Like in perf_event_validate_size(), we should
> skip checking siblings in that case.

Ugh, looking around for_each_sibling_event() sites, it looks like there 
are a fair few other drivers using this pattern as well :(

I'd love for groups to be less horribly complicated, but I think I can 
follow the underlying reasoning here. I suppose one could argue that the 
assertion could take into account that there's nothing to protect in the 
case where event->ctx is still NULL, since nobody else should be able to 
touch the event's own empty sibling list at this point before 
perf_event_open() has even returned. However by the same token there's 
also no real reason for drivers *not* to return early when they equally 
can tell that the sibling list must be empty, and indeed that seems to 
be a fairly common pattern too, so I see no issue with fixing up all the 
offending drivers for consistency either.

Reviewed-by: Robin Murphy <robin.murphy@....com>

> Fixes: f3c0eba287049 ("perf: Add a few assertions")
> Reported-by: Greg Thelen <gthelen@...gle.com>
> Cc: Robin Murphy <robin.murphy@....com>
> Cc: Tuan Phan <tuanphan@...amperecomputing.com>
> Signed-off-by: Namhyung Kim <namhyung@...nel.org>
> ---
>   drivers/perf/arm_dmc620_pmu.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c
> index 8a81be2dd5ec..88c17c1d6d49 100644
> --- a/drivers/perf/arm_dmc620_pmu.c
> +++ b/drivers/perf/arm_dmc620_pmu.c
> @@ -542,12 +542,16 @@ static int dmc620_pmu_event_init(struct perf_event *event)
>   	if (event->cpu < 0)
>   		return -EINVAL;
>   
> +	hwc->idx = -1;
> +
> +	if (event->group_leader == event)
> +		return 0;
> +
>   	/*
>   	 * We can't atomically disable all HW counters so only one event allowed,
>   	 * although software events are acceptable.
>   	 */
> -	if (event->group_leader != event &&
> -			!is_software_event(event->group_leader))
> +	if (!is_software_event(event->group_leader))
>   		return -EINVAL;
>   
>   	for_each_sibling_event(sibling, event->group_leader) {
> @@ -556,7 +560,6 @@ static int dmc620_pmu_event_init(struct perf_event *event)
>   			return -EINVAL;
>   	}
>   
> -	hwc->idx = -1;
>   	return 0;
>   }
>   

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ