diff mbox series

arm64/sme: Always initialise TPIDR2 storage

Message ID 20220701113409.1765924-1-broonie@kernel.org (mailing list archive)
State New, archived
Headers show
Series arm64/sme: Always initialise TPIDR2 storage | expand

Commit Message

Mark Brown July 1, 2022, 11:34 a.m. UTC
Ensure that the value stored for TPIDR2 is always initialised, even if we
don't support it, in order to defend against the possibility that we might
look at the value and do something with it.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Will Deacon July 1, 2022, 2:40 p.m. UTC | #1
On Fri, Jul 01, 2022 at 12:34:09PM +0100, Mark Brown wrote:
> Ensure that the value stored for TPIDR2 is always initialised, even if we
> don't support it, in order to defend against the possibility that we might
> look at the value and do something with it.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
>  arch/arm64/kernel/process.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 944d782d581b..da1c65a7092c 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -376,6 +376,8 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
>  		*task_user_tls(p) = read_sysreg(tpidr_el0);
>  		if (system_supports_tpidr2())
>  			p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0);
> +		else
> +			p->thread.tpidr2_el0 = 0;

Why is this needed? If !system_supports_tpidr2(), then we'll just copy the
tpidr2_el0 field from the parent. Given that INIT_THREAD defines this to be
zero, then it looks like it should all work out.

What am I missing?

Will
Mark Brown July 1, 2022, 2:45 p.m. UTC | #2
On Fri, Jul 01, 2022 at 03:40:43PM +0100, Will Deacon wrote:
> On Fri, Jul 01, 2022 at 12:34:09PM +0100, Mark Brown wrote:

> > +		else
> > +			p->thread.tpidr2_el0 = 0;

> Why is this needed? If !system_supports_tpidr2(), then we'll just copy the
> tpidr2_el0 field from the parent. Given that INIT_THREAD defines this to be
> zero, then it looks like it should all work out.

> What am I missing?

It should be redundant, I just had to check harder than I liked
that there wasn't a path where we could get it wrong.
diff mbox series

Patch

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 944d782d581b..da1c65a7092c 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -376,6 +376,8 @@  int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
 		*task_user_tls(p) = read_sysreg(tpidr_el0);
 		if (system_supports_tpidr2())
 			p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0);
+		else
+			p->thread.tpidr2_el0 = 0;
 
 		if (stack_start) {
 			if (is_compat_thread(task_thread_info(p)))