1 From feca8e36e9f135abdeab5c69bb3a20824d17ec22 Mon Sep 17 00:00:00 2001
2 From: Breno Leitao <leitao@debian.org>
3 Date: Mon, 8 Apr 2019 16:32:38 +1000
4 Subject: powerpc/tm: Limit TM code inside PPC_TRANSACTIONAL_MEM
6 commit 897bc3df8c5aebb54c32d831f917592e873d0559 upstream.
8 Commit e1c3743e1a20 ("powerpc/tm: Set MSR[TS] just prior to recheckpoint")
9 moved a code block around and this block uses a 'msr' variable outside of
10 the CONFIG_PPC_TRANSACTIONAL_MEM, however the 'msr' variable is declared
11 inside a CONFIG_PPC_TRANSACTIONAL_MEM block, causing a possible error when
12 CONFIG_PPC_TRANSACTION_MEM is not defined.
14 error: 'msr' undeclared (first use in this function)
16 This is not causing a compilation error in the mainline kernel, because
17 'msr' is being used as an argument of MSR_TM_ACTIVE(), which is defined as
18 the following when CONFIG_PPC_TRANSACTIONAL_MEM is *not* set:
20 #define MSR_TM_ACTIVE(x) 0
22 This patch just fixes this issue avoiding the 'msr' variable usage outside
23 the CONFIG_PPC_TRANSACTIONAL_MEM block, avoiding trusting in the
24 MSR_TM_ACTIVE() definition.
26 Cc: stable@vger.kernel.org
27 Reported-by: Christoph Biedl <linux-kernel.bfrz@manchmal.in-ulm.de>
28 Fixes: e1c3743e1a20 ("powerpc/tm: Set MSR[TS] just prior to recheckpoint")
29 Signed-off-by: Breno Leitao <leitao@debian.org>
30 Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
31 Signed-off-by: Michael Neuling <mikey@neuling.org>
32 Signed-off-by: Sasha Levin <sashal@kernel.org>
34 arch/powerpc/kernel/signal_64.c | 23 ++++++++++++++++++-----
35 1 file changed, 18 insertions(+), 5 deletions(-)
37 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
38 index bbd1c73243d7..14b0f5b6a373 100644
39 --- a/arch/powerpc/kernel/signal_64.c
40 +++ b/arch/powerpc/kernel/signal_64.c
41 @@ -755,12 +755,25 @@ SYSCALL_DEFINE0(rt_sigreturn)
42 if (restore_tm_sigcontexts(current, &uc->uc_mcontext,
43 &uc_transact->uc_mcontext))
47 - /* Fall through, for non-TM restore */
50 - if (restore_sigcontext(current, NULL, 1, &uc->uc_mcontext))
54 + * Fall through, for non-TM restore
56 + * Unset MSR[TS] on the thread regs since MSR from user
57 + * context does not have MSR active, and recheckpoint was
58 + * not called since restore_tm_sigcontexts() was not called
61 + * If not unsetting it, the code can RFID to userspace with
62 + * MSR[TS] set, but without CPU in the proper state,
63 + * causing a TM bad thing.
65 + current->thread.regs->msr &= ~MSR_TS_MASK;
66 + if (restore_sigcontext(current, NULL, 1, &uc->uc_mcontext))
70 if (restore_altstack(&uc->uc_stack))