Re: [PATCH v3 13/18] powerpc: Add support for setting SPRN_TIDR

From: Michael Ellerman
Date: Thu Nov 09 2017 - 06:53:11 EST


Sukadev Bhattiprolu <sukadev@xxxxxxxxxxxxxxxxxx> writes:

> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index 37ed60b..d861fcd 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -1120,6 +1120,13 @@ static inline void restore_sprs(struct thread_struct *old_thread,
> mtspr(SPRN_TAR, new_thread->tar);
> }
> #endif
> +#ifdef CONFIG_PPC64
> + if (old_thread->tidr != new_thread->tidr) {
> + /* TIDR should be non-zero only with ISA3.0. */
> + WARN_ON_ONCE(!cpu_has_feature(CPU_FTR_ARCH_300));

This is silly, just make the whole block depend on CPU_FTR_ARCH_300.

I've fixed it up.

> @@ -1466,6 +1581,10 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
>
> clear_task_ebb(dst);
>
> +#ifdef CONFIG_PPC64
> + dst->thread.tidr = 0;
> +#endif
> +
> return 0;
> }

This is called from clone().


> @@ -1576,6 +1695,9 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
> #endif
>
> setup_ksp_vsid(p, sp);
> +#ifdef CONFIG_PPC64
> + p->thread.tidr = 0;
> +#endif

And so is this.

So I think you only need the latter.

That does mean you're clearing the TIDR on fork(), but not exec().

Typically you'd do the reverse, ie. clear it on exec() but leave it the
same on fork().

Because this is a "thread id" I think it does make sense to clear it on
fork(), otherwise you potentially have two processes with the same id
and only one of them will be woken up by the AS_notify.

So I'll drop the clear from arch_dup_task_struct().

cheers