LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Nicholas Piggin" <npiggin@gmail.com>
To: "Rohan McLure" <rmclure@linux.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v4 19/20] powerpc/64s: Clear gprs on interrupt routine entry in Book3S
Date: Fri, 16 Sep 2022 10:43:27 +1000	[thread overview]
Message-ID: <CMXEQTG6VVGD.14Q5OOB0LQ168@bobo> (raw)
In-Reply-To: <5359A37E-5094-4EBC-999A-C5CD5110D1F5@linux.ibm.com>

On Thu Sep 15, 2022 at 4:55 PM AEST, Rohan McLure wrote:
>
>
> > On 12 Sep 2022, at 10:15 pm, Nicholas Piggin <npiggin@gmail.com> wrote:
> > 
> > On Wed Aug 24, 2022 at 12:05 PM AEST, Rohan McLure wrote:
> >> Zero GPRS r0, r2-r11, r14-r31, on entry into the kernel for all
> >> other interrupt sources to limit influence of user-space values
> >> in potential speculation gadgets. The remaining gprs are overwritten by
> >> entry macros to interrupt handlers, irrespective of whether or not a
> >> given handler consumes these register values.
> >> 
> >> Prior to this commit, r14-r31 are restored on a per-interrupt basis at
> >> exit, but now they are always restored. Remove explicit REST_NVGPRS
> >> invocations as non-volatiles must now always be restored. 32-bit systems
> >> do not clear user registers on interrupt, and continue to depend on the
> >> return value of interrupt_exit_user_prepare to determine whether or not
> >> to restore non-volatiles.
> >> 
> >> The mmap_bench benchmark in selftests should rapidly invoke pagefaults.
> >> See ~0.8% performance regression with this mitigation, but this
> >> indicates the worst-case performance due to heavier-weight interrupt
> >> handlers.
> > 
> > Ow, my heart :(
> > 
> > Are we not keeping a CONFIG option to rid ourselves of this vile
> > performance robbing thing? Are we getting rid of the whole
> > _TIF_RESTOREALL thing too, or does PPC32 want to keep it?
>
> I see no reason not to include a CONFIG option for this 
> mitigation here other than simplicity. Any suggestions for a name?
> I’m thinking PPC64_SANITIZE_INTERRUPTS. Defaults on Book3E_64, optional
> on Book3S_64.

INTERRUPT_SANITIZE_REGISTERS perhaps?

>
> >> 
> >> Signed-off-by: Rohan McLure <rmclure@linux.ibm.com>
> >> ---
> >> V1 -> V2: Add benchmark data
> >> V2 -> V3: Use ZEROIZE_GPR{,S} macro renames, clarify
> >> interrupt_exit_user_prepare changes in summary.
> >> ---
> >> arch/powerpc/kernel/exceptions-64s.S | 21 ++++++++-------------
> >> arch/powerpc/kernel/interrupt_64.S   |  9 ++-------
> >> 2 files changed, 10 insertions(+), 20 deletions(-)
> >> 
> >> diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
> >> index a3b51441b039..038e42fb2182 100644
> >> --- a/arch/powerpc/kernel/exceptions-64s.S
> >> +++ b/arch/powerpc/kernel/exceptions-64s.S
> >> @@ -502,6 +502,7 @@ DEFINE_FIXED_SYMBOL(\name\()_common_real, text)
> >> 	std	r10,0(r1)		/* make stack chain pointer	*/
> >> 	std	r0,GPR0(r1)		/* save r0 in stackframe	*/
> >> 	std	r10,GPR1(r1)		/* save r1 in stackframe	*/
> >> +	ZEROIZE_GPR(0)
> >> 
> >> 	/* Mark our [H]SRRs valid for return */
> >> 	li	r10,1
> >> @@ -538,14 +539,18 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
> >> 	ld	r10,IAREA+EX_R10(r13)
> >> 	std	r9,GPR9(r1)
> >> 	std	r10,GPR10(r1)
> >> +	ZEROIZE_GPRS(9, 10)
> > 
> > You use 9/10 right afterwards, this'd have to move down to where
> > you zero r11 at least.
> > 
> >> 	ld	r9,IAREA+EX_R11(r13)	/* move r11 - r13 to stackframe	*/
> >> 	ld	r10,IAREA+EX_R12(r13)
> >> 	ld	r11,IAREA+EX_R13(r13)
> >> 	std	r9,GPR11(r1)
> >> 	std	r10,GPR12(r1)
> >> 	std	r11,GPR13(r1)
> >> +	/* keep r12 ([H]SRR1/MSR), r13 (PACA) for interrupt routine */
> >> +	ZEROIZE_GPR(11)
> > 
> > Kernel always has to keep r13 so no need to comment that. Keeping r11,
> > is that for those annoying fp_unavailable etc handlers?
> > 
> > There's probably not much a user can do with this, given they're set
> > from the MSR. Use can influence some bits of its MSR though. So long
> > as we're being paranoid, you could add an IOPTION to retain r11 only for
> > the handlers that need it, or have them load it from MSR and zero it
> > here.
>
> Good suggestion. Presume you’re referring to r12 here. I might go the
> IOPTION route.

Yeah r12, I think you need it because some of those assembly handlers
expect it there to check SRR1 bits. Having an IOPTION is probably good
and it documents that quirk of those handlers. That's bitten me before.

Thanks,
Nick

  reply	other threads:[~2022-09-16  0:44 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24  2:05 [PATCH v4 00/20] powerpc: Syscall wrapper and register clearing Rohan McLure
2022-08-24  2:05 ` [PATCH v4 01/20] powerpc: Remove asmlinkage from syscall handler definitions Rohan McLure
2022-08-25  7:04   ` Andrew Donnellan
2022-09-12  8:20   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 02/20] powerpc: Use generic fallocate compatibility syscall Rohan McLure
2022-09-12  8:38   ` Nicholas Piggin
2022-09-12  9:57     ` Arnd Bergmann
2022-09-12 11:00       ` Christophe Leroy
2022-09-12 11:07         ` Arnd Bergmann
2022-08-24  2:05 ` [PATCH v4 03/20] powerpc/32: Remove powerpc select specialisation Rohan McLure
2022-09-12  9:03   ` Nicholas Piggin
2022-09-15  4:36     ` Rohan McLure
2022-08-24  2:05 ` [PATCH v4 04/20] powerpc: Provide do_ppc64_personality helper Rohan McLure
2022-09-12  9:26   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 05/20] powerpc: Remove direct call to personality syscall handler Rohan McLure
2022-09-12  9:42   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 06/20] powerpc: Remove direct call to mmap2 syscall handlers Rohan McLure
2022-09-12  9:47   ` Nicholas Piggin
2022-09-15  5:06     ` Rohan McLure
2022-08-24  2:05 ` [PATCH v4 07/20] powerpc: Adopt SYSCALL_DEFINE for arch-specific " Rohan McLure
2022-09-12 10:04   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 08/20] powerpc: Include all arch-specific syscall prototypes Rohan McLure
2022-09-12 10:33   ` Nicholas Piggin
2022-09-13  7:09     ` Rohan McLure
2022-08-24  2:05 ` [PATCH v4 09/20] powerpc: Enable compile-time check for syscall handlers Rohan McLure
2022-09-12 10:42   ` Nicholas Piggin
2022-09-13  2:29     ` Michael Ellerman
2022-08-24  2:05 ` [PATCH v4 10/20] powerpc: Use common syscall handler type Rohan McLure
2022-09-12 10:56   ` Nicholas Piggin
2022-09-15  5:45     ` Rohan McLure
2022-09-16  1:02       ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 11/20] powerpc: Add ZEROIZE_GPRS macros for register clears Rohan McLure
2022-09-12 11:09   ` Nicholas Piggin
2022-09-15  5:47     ` Rohan McLure
2022-08-24  2:05 ` [PATCH v4 12/20] Revert "powerpc/syscall: Save r3 in regs->orig_r3" Rohan McLure
2022-09-12 11:14   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 13/20] powerpc: Provide syscall wrapper Rohan McLure
2022-09-12 11:26   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 14/20] powerpc/64s: Clear/restore caller gprs in syscall interrupt/return Rohan McLure
2022-09-12 11:47   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 15/20] powerpc/64s: Use {ZEROIZE,SAVE,REST}_GPRS macros in sc, scv 0 handlers Rohan McLure
2022-09-12 11:49   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 16/20] powerpc/32: Clarify interrupt restores with REST_GPR macro in entry_32.S Rohan McLure
2022-08-24  2:05 ` [PATCH v4 17/20] powerpc/64e: Clarify register saves and clears with {SAVE,ZEROIZE}_GPRS Rohan McLure
2022-09-12 12:17   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 18/20] powerpc/64s: Fix comment on interrupt handler prologue Rohan McLure
2022-09-12 11:51   ` Nicholas Piggin
2022-08-24  2:05 ` [PATCH v4 19/20] powerpc/64s: Clear gprs on interrupt routine entry in Book3S Rohan McLure
2022-09-12 12:15   ` Nicholas Piggin
2022-09-15  6:55     ` Rohan McLure
2022-09-16  0:43       ` Nicholas Piggin [this message]
2022-08-24  2:05 ` [PATCH v4 20/20] powerpc/64e: Clear gprs on interrupt routine entry Rohan McLure
2022-09-12  0:55 ` [PATCH v4 00/20] powerpc: Syscall wrapper and register clearing Rohan McLure

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=CMXEQTG6VVGD.14Q5OOB0LQ168@bobo \
    --to=npiggin@gmail.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=rmclure@linux.ibm.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