Subject: Re: [bug] KVM: Unrecoverable TM Unavailable Exception f60

From: Benjamin Herrenschmidt <[email-masked]>
Date: Fri, 14 Jul 2017 06:59:36 +1000

On Thu, 2017-07-13 at 11:46 -0300, Gustavo Romero wrote:
> Hi Jan
> Looks like that TM unavailable exception will only able to recover
> properly if it comes from problem state and since the trigger comes
> from kernel space (kvm module) it does not match
> "if (user_mode(regs))" in tm_unavailable().
> 
> I'm able to avoid this problem using the following patch:

I think the KVM exit path should be enabling TM if necessary rather
than taking the fault.

> diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
> index d4e545d27ef9..1091dc4f4274 100644
> --- a/arch/powerpc/kernel/traps.c
> +++ b/arch/powerpc/kernel/traps.c
> @@ -1433,13 +1433,11 @@ void vsx_unavailable_exception(struct pt_regs *regs)
>  static void tm_unavailable(struct pt_regs *regs)
>  {
>  #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
> -       if (user_mode(regs)) {
> -               current->thread.load_tm++;
> -               regs->msr |= MSR_TM;
> -               tm_enable();
> -               tm_restore_sprs(&current->thread);
> -               return;
> -       }
> +       current->thread.load_tm++;
> +       regs->msr |= MSR_TM;
> +       tm_enable();
> +       tm_restore_sprs(&current->thread);
> +       return;
>  #endif
>         pr_emerg("Unrecoverable TM Unavailable Exception "
>                         "%lx at %lx\n", regs->trap, regs->nip);
> 
> Regards,
> Gustavo