From: Rohan McLure <rmclure@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Rohan McLure <rmclure@linux.ibm.com>, npiggin@gmail.com
Subject: [PATCH 3/6] powerpc: Make syscalls save and restore gprs
Date: Wed, 1 Jun 2022 15:48:47 +1000 [thread overview]
Message-ID: <20220601054850.250287-3-rmclure@linux.ibm.com> (raw)
In-Reply-To: <20220601054850.250287-1-rmclure@linux.ibm.com>
Clears user state in gprs to reduce the influence of user registers on
speculation within kernel syscall handlers.
Remove conditional branches on result of `syscall_exit_prepare` to
restore non-volatile gprs, as these registers are always cleared and
hence always must be restored.
Signed-off-by: Rohan McLure <rmclure@linux.ibm.com>
---
arch/powerpc/kernel/interrupt_64.S | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/kernel/interrupt_64.S b/arch/powerpc/kernel/interrupt_64.S
index b11c2bd84827..e601ed999798 100644
--- a/arch/powerpc/kernel/interrupt_64.S
+++ b/arch/powerpc/kernel/interrupt_64.S
@@ -108,6 +108,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
* but this is the best we can do.
*/
+ ZERO_GPRS(5, 12)
+ ZERO_NVGPRS()
+
/* Calling convention has r3 = orig r0, r4 = regs */
mr r3,r0
bl system_call_exception
@@ -138,6 +141,7 @@ BEGIN_FTR_SECTION
HMT_MEDIUM_LOW
END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
+ REST_NVGPRS(r1)
cmpdi r3,0
bne .Lsyscall_vectored_\name\()_restore_regs
@@ -180,7 +184,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
ld r4,_LINK(r1)
ld r5,_XER(r1)
- REST_NVGPRS(r1)
ld r0,GPR0(r1)
mtcr r2
mtctr r3
@@ -308,6 +311,9 @@ END_BTB_FLUSH_SECTION
wrteei 1
#endif
+ ZERO_GPRS(5, 12)
+ ZERO_NVGPRS()
+
/* Calling convention has r3 = orig r0, r4 = regs */
mr r3,r0
bl system_call_exception
@@ -350,6 +356,7 @@ BEGIN_FTR_SECTION
stdcx. r0,0,r1 /* to clear the reservation */
END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
+ REST_NVGPRS(r1)
cmpdi r3,0
bne .Lsyscall_restore_regs
/* Zero volatile regs that may contain sensitive kernel data */
@@ -377,7 +384,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
.Lsyscall_restore_regs:
ld r3,_CTR(r1)
ld r4,_XER(r1)
- REST_NVGPRS(r1)
mtctr r3
mtspr SPRN_XER,r4
REST_GPR(0, r1)
@@ -445,7 +451,7 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_user)
bl interrupt_exit_user_prepare
cmpdi r3,0
bne- .Lrestore_nvgprs_\srr
-.Lrestore_nvgprs_\srr\()_cont:
+ .Lrestore_nvgprs_\srr\()_cont:
std r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */
#ifdef CONFIG_PPC_BOOK3S
.Linterrupt_return_\srr\()_user_rst_start:
--
2.34.1
next prev parent reply other threads:[~2022-06-01 5:51 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-01 5:48 [PATCH 1/6] powerpc: Add ZERO_GPRS macros for register clears Rohan McLure
2022-06-01 5:48 ` [PATCH 2/6] powerpc: Provide syscall wrapper Rohan McLure
2022-06-01 8:29 ` Christophe Leroy
2022-06-09 13:06 ` Christophe Leroy
2022-06-16 5:42 ` Rohan McLure
2022-06-16 7:20 ` Arnd Bergmann
2022-06-01 8:59 ` kernel test robot
2022-06-01 9:35 ` kernel test robot
2022-06-01 12:23 ` kernel test robot
2022-06-01 14:33 ` Christophe Leroy
2022-06-03 3:24 ` Rohan McLure
2022-06-03 7:09 ` Andrew Donnellan
2022-06-03 8:39 ` Christophe Leroy
2022-06-14 13:57 ` Andrew Donnellan
2022-06-03 9:04 ` Arnd Bergmann
2022-06-15 1:47 ` Rohan McLure
2022-06-15 10:13 ` Arnd Bergmann
2022-06-01 5:48 ` Rohan McLure [this message]
2022-06-01 8:33 ` [PATCH 3/6] powerpc: Make syscalls save and restore gprs Christophe Leroy
2022-06-01 5:48 ` [PATCH 4/6] powerpc: Fix comment, use clear and restore macros Rohan McLure
2022-06-01 5:48 ` [PATCH 5/6] powerpc: Move syscall handler prototypes to header Rohan McLure
2022-06-01 5:48 ` [PATCH 6/6] powerpc/64s: Clear gprs on interrupt routine entry Rohan McLure
2022-06-01 8:37 ` Christophe Leroy
2022-06-01 7:45 ` [PATCH 1/6] powerpc: Add ZERO_GPRS macros for register clears Christophe Leroy
2022-06-01 16:00 ` Segher Boessenkool
2022-06-10 3:32 ` Rohan McLure
2022-06-10 14:05 ` Segher Boessenkool
2022-06-11 8:42 ` Christophe Leroy
2022-06-13 18:48 ` Segher Boessenkool
2022-06-14 4:31 ` Michael Ellerman
2022-06-14 11:43 ` Segher Boessenkool
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=20220601054850.250287-3-rmclure@linux.ibm.com \
--to=rmclure@linux.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.com \
/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).