From: Diana Craciun <diana.craciun@nxp.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Diana Craciun <diana.craciun@nxp.com>
Subject: [PATCH 07/11 v2] powerpc/fsl: Flush the branch predictor at each kernel entry (32 bit)
Date: Fri, 21 Dec 2018 19:30:33 +0200 [thread overview]
Message-ID: <1545413437-5538-8-git-send-email-diana.craciun@nxp.com> (raw)
In-Reply-To: <1545413437-5538-1-git-send-email-diana.craciun@nxp.com>
In order to protect against speculation attacks on
indirect branches, the branch predictor is flushed at
kernel entry to protect for the following situations:
- userspace process attacking another userspace process
- userspace process attacking the kernel
Basically when the privillege level change (i.e.the kernel
is entered), the branch predictor state is flushed.
Signed-off-by: Diana Craciun <diana.craciun@nxp.com>
---
v1-->v2
- fixed warnings reported by the automated build system
arch/powerpc/kernel/head_booke.h | 11 +++++++++++
arch/powerpc/kernel/head_fsl_booke.S | 15 +++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index d0862a1..27f5249 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -32,6 +32,15 @@
*/
#define THREAD_NORMSAVE(offset) (THREAD_NORMSAVES + (offset * 4))
+#ifdef CONFIG_PPC_FSL_BOOK3E
+#define BOOKE_CLEAR_BTB(reg) \
+START_BTB_FLUSH_SECTION \
+ BTB_FLUSH(reg) \
+END_BTB_FLUSH_SECTION
+#else
+#define BOOKE_CLEAR_BTB(reg)
+#endif
+
#define NORMAL_EXCEPTION_PROLOG(intno) \
mtspr SPRN_SPRG_WSCRATCH0, r10; /* save one register */ \
mfspr r10, SPRN_SPRG_THREAD; \
@@ -43,6 +52,7 @@
andi. r11, r11, MSR_PR; /* check whether user or kernel */\
mr r11, r1; \
beq 1f; \
+ BOOKE_CLEAR_BTB(r11) \
/* if from user, start at top of this thread's kernel stack */ \
lwz r11, THREAD_INFO-THREAD(r10); \
ALLOC_STACK_FRAME(r11, THREAD_SIZE); \
@@ -128,6 +138,7 @@
stw r9,_CCR(r8); /* save CR on stack */\
mfspr r11,exc_level_srr1; /* check whether user or kernel */\
DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \
+ BOOKE_CLEAR_BTB(r10) \
andi. r11,r11,MSR_PR; \
mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\
lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S
index e2750b8..2386ce2 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -453,6 +453,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
mfcr r13
stw r13, THREAD_NORMSAVE(3)(r10)
DO_KVM BOOKE_INTERRUPT_DTLB_MISS SPRN_SRR1
+START_BTB_FLUSH_SECTION
+ mfspr r11, SPRN_SRR1
+ andi. r10,r11,MSR_PR
+ beq 1f
+ BTB_FLUSH(r10)
+1:
+END_BTB_FLUSH_SECTION
mfspr r10, SPRN_DEAR /* Get faulting address */
/* If we are faulting a kernel address, we have to use the
@@ -547,6 +554,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
mfcr r13
stw r13, THREAD_NORMSAVE(3)(r10)
DO_KVM BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR1
+START_BTB_FLUSH_SECTION
+ mfspr r11, SPRN_SRR1
+ andi. r10,r11,MSR_PR
+ beq 1f
+ BTB_FLUSH(r10)
+1:
+END_BTB_FLUSH_SECTION
+
mfspr r10, SPRN_SRR0 /* Get faulting address */
/* If we are faulting a kernel address, we have to use the
--
2.5.5
next prev parent reply other threads:[~2018-12-21 17:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-21 17:30 [PATCH 00/11 v2] powerpc/fsl: NXP PowerPC Spectre variant 2 workarounds Diana Craciun
2018-12-21 17:30 ` [PATCH 01/11 v2] powerpc/fsl: Add infrastructure to fixup branch predictor flush Diana Craciun
2018-12-21 17:30 ` [PATCH 02/11 v2] powerpc/fsl: Add macro to flush the branch predictor Diana Craciun
2018-12-21 17:30 ` [PATCH 03/11 v2] powerpc/fsl: Fix spectre_v2 mitigations reporting Diana Craciun
2018-12-21 17:30 ` [PATCH 04/11 v2] powerpc/fsl: Emulate SPRN_BUCSR register Diana Craciun
2018-12-21 17:30 ` [PATCH 05/11 v2] powerpc/fsl: Add nospectre_v2 command line argument Diana Craciun
2018-12-21 17:30 ` [PATCH 06/11 v2] powerpc/fsl: Flush the branch predictor at each kernel entry (64bit) Diana Craciun
2018-12-21 17:30 ` Diana Craciun [this message]
2018-12-21 17:30 ` [PATCH 08/11 v2] powerpc/fsl: Flush branch predictor when entering KVM Diana Craciun
2018-12-21 17:30 ` [PATCH 09/11 v2] powerpc/fsl: Enable runtime patching if nospectre_v2 boot arg is used Diana Craciun
2018-12-21 17:30 ` [PATCH 10/11 v2] powerpc/fsl: Update Spectre v2 reporting Diana Craciun
2018-12-21 17:30 ` [PATCH 11/11 v2] powerpc/fsl: Add FSL_PPC_BOOK3E as supported arch for nospectre_v2 boot arg Diana Craciun
2018-12-22 10:07 ` [PATCH 00/11 v2] powerpc/fsl: NXP PowerPC Spectre variant 2 workarounds Michael Ellerman
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=1545413437-5538-8-git-send-email-diana.craciun@nxp.com \
--to=diana.craciun@nxp.com \
--cc=linuxppc-dev@lists.ozlabs.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).