2022-12-30 04:38:58

by Russell Currey

[permalink] [raw]
Subject: [PATCH v2 2/7] powerpc/secvar: WARN_ON_ONCE() if multiple secvar ops are set

The secvar code only supports one consumer at a time.

Multiple consumers aren't possible at this point in time, but we'd want
it to be obvious if it ever could happen.

Signed-off-by: Russell Currey <[email protected]>
---
arch/powerpc/kernel/secvar-ops.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/secvar-ops.c b/arch/powerpc/kernel/secvar-ops.c
index 6a29777d6a2d..aa1b2adc2710 100644
--- a/arch/powerpc/kernel/secvar-ops.c
+++ b/arch/powerpc/kernel/secvar-ops.c
@@ -8,10 +8,12 @@

#include <linux/cache.h>
#include <asm/secvar.h>
+#include <asm/bug.h>

-const struct secvar_operations *secvar_ops __ro_after_init;
+const struct secvar_operations *secvar_ops __ro_after_init = NULL;

void set_secvar_ops(const struct secvar_operations *ops)
{
+ WARN_ON_ONCE(secvar_ops);
secvar_ops = ops;
}
--
2.38.1


2023-01-04 07:26:39

by Andrew Donnellan

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] powerpc/secvar: WARN_ON_ONCE() if multiple secvar ops are set

On Fri, 2022-12-30 at 15:20 +1100, Russell Currey wrote:
> The secvar code only supports one consumer at a time.
>
> Multiple consumers aren't possible at this point in time, but we'd
> want
> it to be obvious if it ever could happen.
>
> Signed-off-by: Russell Currey <[email protected]>

This seems sensible - there aren't any cases where set_secvar_ops()
should be called twice.

> ---
>  arch/powerpc/kernel/secvar-ops.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kernel/secvar-ops.c
> b/arch/powerpc/kernel/secvar-ops.c
> index 6a29777d6a2d..aa1b2adc2710 100644
> --- a/arch/powerpc/kernel/secvar-ops.c
> +++ b/arch/powerpc/kernel/secvar-ops.c
> @@ -8,10 +8,12 @@
>  
>  #include <linux/cache.h>
>  #include <asm/secvar.h>
> +#include <asm/bug.h>
>  
> -const struct secvar_operations *secvar_ops __ro_after_init;
> +const struct secvar_operations *secvar_ops __ro_after_init = NULL;

I think this is implicitly NULL, but it's fine to make it explicit.

Reviewed-by: Andrew Donnellan <[email protected]>

>  
>  void set_secvar_ops(const struct secvar_operations *ops)
>  {
> +       WARN_ON_ONCE(secvar_ops);
>         secvar_ops = ops;
>  }

--
Andrew Donnellan OzLabs, ADL Canberra
[email protected] IBM Australia Limited