diff mbox series

firmware/psci: Don't register with debugfs if PSCI isn't available

Message ID 20230105090834.630238-1-maz@kernel.org (mailing list archive)
State New, archived
Headers show
Series firmware/psci: Don't register with debugfs if PSCI isn't available | expand

Commit Message

Marc Zyngier Jan. 5, 2023, 9:08 a.m. UTC
Contrary to popular belief, PSCI is not a universal property of an
ARM/arm64 system. There is a garden variety of systems out there
that don't (or even cannot) implement it.

I'm the first one deplore such a situation, but hey...

On such systems, a "cat /sys/kernel/debug/psci" results in
fireworks, as no invocation callback is registered.

Check for the invoke_psci_fn and psci_ops.get_version pointers
before registering with the debugfs subsystem, avoiding the
issue altogether.

Fixes: 3137f2e60098 ("firmware/psci: Add debugfs support to ease debugging")
Reported-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>
---
 drivers/firmware/psci/psci.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Mark Rutland Jan. 5, 2023, 1:08 p.m. UTC | #1
On Thu, Jan 05, 2023 at 09:08:34AM +0000, Marc Zyngier wrote:
> Contrary to popular belief, PSCI is not a universal property of an
> ARM/arm64 system. There is a garden variety of systems out there
> that don't (or even cannot) implement it.
> 
> I'm the first one deplore such a situation, but hey...
> 
> On such systems, a "cat /sys/kernel/debug/psci" results in
> fireworks, as no invocation callback is registered.
> 
> Check for the invoke_psci_fn and psci_ops.get_version pointers
> before registering with the debugfs subsystem, avoiding the
> issue altogether.
> 
> Fixes: 3137f2e60098 ("firmware/psci: Add debugfs support to ease debugging")
> Reported-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  drivers/firmware/psci/psci.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
> index e7bcfca4159f..447ee4ea5c90 100644
> --- a/drivers/firmware/psci/psci.c
> +++ b/drivers/firmware/psci/psci.c
> @@ -440,6 +440,9 @@ static const struct file_operations psci_debugfs_ops = {
>  
>  static int __init psci_debugfs_init(void)
>  {
> +	if (!invoke_psci_fn || !psci_ops.get_version)
> +		return 0;
> +
>  	return PTR_ERR_OR_ZERO(debugfs_create_file("psci", 0444, NULL, NULL,
>  						   &psci_debugfs_ops));
>  }
> -- 
> 2.34.1
>
Dmitry Baryshkov Jan. 5, 2023, 1:13 p.m. UTC | #2
On 05/01/2023 11:08, Marc Zyngier wrote:
> Contrary to popular belief, PSCI is not a universal property of an
> ARM/arm64 system. There is a garden variety of systems out there
> that don't (or even cannot) implement it.
> 
> I'm the first one deplore such a situation, but hey...
> 
> On such systems, a "cat /sys/kernel/debug/psci" results in
> fireworks, as no invocation callback is registered.
> 
> Check for the invoke_psci_fn and psci_ops.get_version pointers
> before registering with the debugfs subsystem, avoiding the
> issue altogether.
> 
> Fixes: 3137f2e60098 ("firmware/psci: Add debugfs support to ease debugging")
> Reported-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>

Acked-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Hector Martin Jan. 5, 2023, 10:56 p.m. UTC | #3
On 05/01/2023 18.08, Marc Zyngier wrote:
> Contrary to popular belief, PSCI is not a universal property of an
> ARM/arm64 system. There is a garden variety of systems out there
> that don't (or even cannot) implement it.
> 
> I'm the first one deplore such a situation, but hey...
> 
> On such systems, a "cat /sys/kernel/debug/psci" results in
> fireworks, as no invocation callback is registered.
> 
> Check for the invoke_psci_fn and psci_ops.get_version pointers
> before registering with the debugfs subsystem, avoiding the
> issue altogether.
> 
> Fixes: 3137f2e60098 ("firmware/psci: Add debugfs support to ease debugging")
> Reported-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>
> ---
>  drivers/firmware/psci/psci.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
> index e7bcfca4159f..447ee4ea5c90 100644
> --- a/drivers/firmware/psci/psci.c
> +++ b/drivers/firmware/psci/psci.c
> @@ -440,6 +440,9 @@ static const struct file_operations psci_debugfs_ops = {
>  
>  static int __init psci_debugfs_init(void)
>  {
> +	if (!invoke_psci_fn || !psci_ops.get_version)
> +		return 0;
> +
>  	return PTR_ERR_OR_ZERO(debugfs_create_file("psci", 0444, NULL, NULL,
>  						   &psci_debugfs_ops));
>  }

Reviewed-by: Hector Martin <marcan@marcan.st>

- Hector
Will Deacon Jan. 6, 2023, 5:50 p.m. UTC | #4
On Thu, 5 Jan 2023 09:08:34 +0000, Marc Zyngier wrote:
> Contrary to popular belief, PSCI is not a universal property of an
> ARM/arm64 system. There is a garden variety of systems out there
> that don't (or even cannot) implement it.
> 
> I'm the first one deplore such a situation, but hey...
> 
> On such systems, a "cat /sys/kernel/debug/psci" results in
> fireworks, as no invocation callback is registered.
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] firmware/psci: Don't register with debugfs if PSCI isn't available
      https://git.kernel.org/arm64/c/cef139299fd8

Cheers,
diff mbox series

Patch

diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
index e7bcfca4159f..447ee4ea5c90 100644
--- a/drivers/firmware/psci/psci.c
+++ b/drivers/firmware/psci/psci.c
@@ -440,6 +440,9 @@  static const struct file_operations psci_debugfs_ops = {
 
 static int __init psci_debugfs_init(void)
 {
+	if (!invoke_psci_fn || !psci_ops.get_version)
+		return 0;
+
 	return PTR_ERR_OR_ZERO(debugfs_create_file("psci", 0444, NULL, NULL,
 						   &psci_debugfs_ops));
 }