Re: [PATCH 3/3 v5] s390/pai: Support CPU hotplug for PMU PAI

[email protected]
Newsgroups org.kernel.vger.linux-s390
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Calling `cpus_read_lock()` inside CPU hotplug callbacks causes a guaranteed self-deadlock.
--

--- Patch [3]: [PATCH 3/3 v5] s390/pai: Support CPU hotplug for PMU PAI ---
commit c7c540e2c7341f700711120ef64b2203ca9970ed
Author: Thomas Richter <[email protected]>
s390/pai: Support CPU hotplug for PMU PAI

This patch adds CPU hotplug support for the PAI PMU driver. It allocates and
frees per-CPU data structures during CPU online and offline operations to
prevent a kernel panic when PMU callbacks run on newly onlined CPUs.

> diff --git a/arch/s390/kernel/perf_pai.c b/arch/s390/kernel/perf_pai.c
> --- a/arch/s390/kernel/perf_pai.c
> +++ b/arch/s390/kernel/perf_pai.c

[ ... ]

> @@ -1216,8 +1256,38 @@ static int __init paipmu_setup(void)
>  	return install_ok;
>  }
>  
> +static int pai_online_cpu(unsigned int cpu)
> +{
> +	int rc;
> +
> +	cpus_read_lock();

[Severity: High]
Will this cause a self-deadlock? The CPU hotplug core already holds the
cpu_hotplug_lock for writing when it invokes the hotplug callbacks.
Attempting to acquire it for reading via cpus_read_lock() here seems like
it would cause a deadlock, as percpu_rwsem does not support recursive
read-after-write locking.

> +	mutex_lock(&pai_reserve_mutex);
> +	rc = pai_alloc_cpu(PAI_PMU_CRYPTO, cpu, true);
> +	if (!rc) {
> +		rc = pai_alloc_cpu(PAI_PMU_EXT, cpu, true);
> +		if (rc)
> +			pai_event_destroy_cpu(PAI_PMU_CRYPTO, cpu, true);
> +	}
> +	mutex_unlock(&pai_reserve_mutex);
> +	cpus_read_unlock();
> +	return rc;
> +}
> +
> +static int pai_offline_cpu(unsigned int cpu)
> +{
> +	cpus_read_lock();

[Severity: High]
Similarly, does calling cpus_read_lock() here in the offline callback cause
a self-deadlock for the same reason?

> +	mutex_lock(&pai_reserve_mutex);
> +	pai_event_destroy_cpu(PAI_PMU_CRYPTO, cpu, true);
> +	pai_event_destroy_cpu(PAI_PMU_EXT, cpu, true);
> +	mutex_unlock(&pai_reserve_mutex);
> +	cpus_read_unlock();
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.