From: Cyril Bur <cyrilbur@gmail.com>
To: mikey@neuling.org, benh@kernel.crashing.org,
linuxppc-dev@lists.ozlabs.org
Subject: [RFC PATCH 09/12] [WIP] powerpc/tm: Tweak signal code to handle new reclaim/recheckpoint times
Date: Tue, 20 Feb 2018 11:22:38 +1100 [thread overview]
Message-ID: <20180220002241.29648-10-cyrilbur@gmail.com> (raw)
In-Reply-To: <20180220002241.29648-1-cyrilbur@gmail.com>
---
arch/powerpc/kernel/process.c | 13 ++++++++++++-
arch/powerpc/kernel/signal.c | 11 ++++++-----
arch/powerpc/kernel/signal_32.c | 16 ++--------------
arch/powerpc/kernel/signal_64.c | 41 +++++++++++++++++++++++++++++------------
4 files changed, 49 insertions(+), 32 deletions(-)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 8a32fd062a2b..cd3ae80a6878 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1070,9 +1070,20 @@ void restore_tm_state(struct pt_regs *regs)
* again, anything else could lead to an incorrect ckpt_msr being
* saved and therefore incorrect signal contexts.
*/
- clear_thread_flag(TIF_RESTORE_TM);
+
+ /*
+ * So, on signals we're going to have cleared the TM bits from
+ * the MSR, meaning that heading to userspace signal handler
+ * this will be true.
+ * I'm not convinced clearing the TIF_RESTORE_TM flag is a
+ * good idea however, we should do it only if we actually
+ * recheckpoint, which we'll need to do once the signal
+ * hanlder is done and we're returning to the main thread of
+ * execution.
+ */
if (!MSR_TM_ACTIVE(regs->msr))
return;
+ clear_thread_flag(TIF_RESTORE_TM);
msr_diff = current->thread.ckpt_regs.msr & ~regs->msr;
msr_diff &= MSR_FP | MSR_VEC | MSR_VSX;
diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
index 61db86ecd318..4f0398c6ce03 100644
--- a/arch/powerpc/kernel/signal.c
+++ b/arch/powerpc/kernel/signal.c
@@ -191,16 +191,17 @@ unsigned long get_tm_stackpointer(struct task_struct *tsk)
*
* For signals taken in non-TM or suspended mode, we use the
* normal/non-checkpointed stack pointer.
+ *
+ * We now do reclaims on kernel entry, we should absolutely
+ * never need to reclaim here.
+ * TODO Update the comment above if needed.
*/
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
BUG_ON(tsk != current);
- if (MSR_TM_ACTIVE(tsk->thread.regs->msr)) {
- tm_reclaim_current(TM_CAUSE_SIGNAL);
- if (MSR_TM_TRANSACTIONAL(tsk->thread.regs->msr))
- return tsk->thread.ckpt_regs.gpr[1];
- }
+ if (MSR_TM_TRANSACTIONAL(tsk->thread.regs->msr))
+ return tsk->thread.ckpt_regs.gpr[1];
#endif
return tsk->thread.regs->gpr[1];
}
diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index a46de0035214..a87a7c8b5d9e 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -860,21 +860,9 @@ static long restore_tm_user_regs(struct pt_regs *regs,
tm_enable();
/* Make sure the transaction is marked as failed */
current->thread.tm_texasr |= TEXASR_FS;
- /* This loads the checkpointed FP/VEC state, if used */
- tm_recheckpoint(¤t->thread);
- /* This loads the speculative FP/VEC state, if used */
- msr_check_and_set(msr & (MSR_FP | MSR_VEC));
- if (msr & MSR_FP) {
- load_fp_state(¤t->thread.fp_state);
- regs->msr |= (MSR_FP | current->thread.fpexc_mode);
- }
-#ifdef CONFIG_ALTIVEC
- if (msr & MSR_VEC) {
- load_vr_state(¤t->thread.vr_state);
- regs->msr |= MSR_VEC;
- }
-#endif
+ /* See comment in signal_64.c */
+ set_thread_flag(TIF_RESTORE_TM);
return 0;
}
diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index 720117690822..a7751d1fcac6 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -568,21 +568,20 @@ static long restore_tm_sigcontexts(struct task_struct *tsk,
}
}
#endif
- tm_enable();
/* Make sure the transaction is marked as failed */
tsk->thread.tm_texasr |= TEXASR_FS;
- /* This loads the checkpointed FP/VEC state, if used */
- tm_recheckpoint(&tsk->thread);
- msr_check_and_set(msr & (MSR_FP | MSR_VEC));
- if (msr & MSR_FP) {
- load_fp_state(&tsk->thread.fp_state);
- regs->msr |= (MSR_FP | tsk->thread.fpexc_mode);
- }
- if (msr & MSR_VEC) {
- load_vr_state(&tsk->thread.vr_state);
- regs->msr |= MSR_VEC;
- }
+ /*
+ * I believe this is only nessesary if the
+ * clear_thread_flag(TIF_RESTORE_TM); in restore_tm_state()
+ * stays before the if (!MSR_TM_ACTIVE(regs->msr).
+ *
+ * Actually no, we should follow the comment in
+ * restore_tm_state() but this should ALSO be here if
+ * if the signal handler does something crazy like 'generate'
+ * a transaction.
+ */
+ set_thread_flag(TIF_RESTORE_TM);
return err;
}
@@ -734,6 +733,22 @@ int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
if (MSR_TM_SUSPENDED(mfmsr()))
tm_reclaim_current(0);
+ /*
+ * There is a universe where the signal handler did something
+ * crazy like drop the transaction entirely. That is, the main
+ * thread was in transactional or suspended mode and the
+ * signal handler has put them in non transactional mode.
+ * In that case we'll need to clear the TIF_RESTORE_TM flag.
+ * I'll need to ponder it exactly but for now thats all I
+ * think that needs to be done. At the moment it all works
+ * because no signal hanlder is nuts enough to do it.
+ *
+ * Add... somewhere... I guess in the else block, in the
+ * after the #endif
+ *
+ * clear_thread_flag(TIF_RESTORE_TM);
+ */
+
if (__get_user(msr, &uc->uc_mcontext.gp_regs[PT_MSR]))
goto badframe;
if (MSR_TM_ACTIVE(msr)) {
@@ -748,6 +763,8 @@ int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
else
/* Fall through, for non-TM restore */
#endif
+ clear_thread_flag(TIF_RESTORE_TM);
+
if (restore_sigcontext(current, NULL, 1, &uc->uc_mcontext))
goto badframe;
--
2.16.2
next prev parent reply other threads:[~2018-02-20 0:23 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-20 0:22 [RFC PATCH 00/12] Deal with TM on kernel entry and exit Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 01/12] powerpc/tm: Remove struct thread_info param from tm_reclaim_thread() Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 02/12] selftests/powerpc: Fix tm.h helpers Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 03/12] selftests/powerpc: Add tm-signal-drop-transaction TM test Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 04/12] selftests/powerpc: Use less common thread names Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 05/12] [WIP] powerpc/tm: Reclaim/recheckpoint on entry/exit Cyril Bur
2018-02-20 2:50 ` Michael Neuling
2018-02-20 3:54 ` Cyril Bur
2018-02-20 5:25 ` Michael Neuling
2018-02-20 6:32 ` Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 06/12] [WIP] powerpc/tm: Remove dead code from __switch_to_tm() Cyril Bur
2018-02-20 2:52 ` Michael Neuling
2018-02-20 3:43 ` Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 07/12] [WIP] powerpc/tm: Add TM_KERNEL_ENTRY in more delicate exception pathes Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 08/12] [WIP] powerpc/tm: Fix *unavailable_tm exceptions Cyril Bur
2018-02-20 0:22 ` Cyril Bur [this message]
2018-02-20 0:22 ` [RFC PATCH 10/12] [WIP] powerpc/tm: Correctly save/restore checkpointed sprs Cyril Bur
2018-02-20 3:00 ` Michael Neuling
2018-02-20 3:59 ` Cyril Bur
2018-02-20 5:27 ` Michael Neuling
2018-02-20 0:22 ` [RFC PATCH 11/12] [WIP] powerpc/tm: Afterthoughts Cyril Bur
2018-02-20 0:22 ` [RFC PATCH 12/12] [WIP] selftests/powerpc: Remove incorrect tm-syscall selftest Cyril Bur
2018-02-20 3:04 ` Michael Neuling
2018-02-20 3:42 ` Cyril Bur
2018-06-13 22:38 ` [RFC,00/12] Deal with TM on kernel entry and exit Breno Leitao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180220002241.29648-10-cyrilbur@gmail.com \
--to=cyrilbur@gmail.com \
--cc=benh@kernel.crashing.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mikey@neuling.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).