From 5e8448afe05f2227d9d683f81727864dc4818972 Mon Sep 17 00:00:00 2001
From: Balbir Singh <bsingharora@gmail.com>
Date: Mon, 8 Jan 2018 15:57:12 +0530
Subject: [PATCH 03/26] UBUNTU: SAUCE: rfi-flush: Add barriers to the fallback
 L1D flushing

CVE-2017-5754

Add a hwsync after DCBT_STOP_ALL_STREAM_IDS to order loads/
stores prior to stopping prefetch with loads and stores
as a part of the flushing. A lwsync is needed to ensure
that after we don't mix the flushing of one congruence class
with another

Signed-off-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
---
 arch/powerpc/kernel/exceptions-64s.S | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 45dff63..3b73dbb 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -674,13 +674,15 @@ rfi_flush_fallback:
 	addi	r12,r12,8
 	mtctr	r11
 	DCBT_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
-	/* XXX: Should an instruction synchronizing operation be done here? */
 
+	/* order ld/st prior to dcbt stop all streams with flushing */
+	hwsync
 1:	li	r8,0
 	.rept	8 /* 8-way set associative */
 	ldx	r11,r10,r8
 	add	r8,r8,r12
 	.endr
+	lwsync	/* Ensure that we do all 8 sets before others */
 	addi	r10,r10,128 /* 128 byte cache line */
 	bdnz	1b
 
@@ -714,13 +716,15 @@ hrfi_flush_fallback:
 	addi	r12,r12,8
 	mtctr	r11
 	DCBT_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
-	/* XXX: Should an instruction synchronizing operation be done here? */
 
+	/* order ld/st prior to dcbt stop all streams with flushing */
+	hwsync
 1:	li	r8,0
 	.rept	8 /* 8-way set associative */
 	ldx	r11,r10,r8
 	add	r8,r8,r12
 	.endr
+	lwsync	/* Ensure that we do all 8 sets before others */
 	addi	r10,r10,128 /* 128 byte cache line */
 	bdnz	1b
 
-- 
2.7.4

