Skip to content

Commit 6bb8211

Browse files
committed
Merge tag 'powerpc-4.15-7' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux
Pull powerpc fixes from Michael Ellerman: "One fix for an oops at boot if we take a hotplug interrupt before we are ready to handle it. The bulk is patches to implement mitigation for Meltdown, see the change logs for more details. Thanks to: Nicholas Piggin, Michael Neuling, Oliver O'Halloran, Jon Masters, Jose Ricardo Ziviani, David Gibson" * tag 'powerpc-4.15-7' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: powerpc/powernv: Check device-tree for RFI flush settings powerpc/pseries: Query hypervisor for RFI flush settings powerpc/64s: Support disabling RFI flush with no_rfi_flush and nopti powerpc/64s: Add support for RFI flush of L1-D cache powerpc/64s: Convert slb_miss_common to use RFI_TO_USER/KERNEL powerpc/64: Convert fast_exception_return to use RFI_TO_USER/KERNEL powerpc/64: Convert the syscall exit path to use RFI_TO_USER/KERNEL powerpc/64s: Simple RFI macro conversions powerpc/64: Add macros for annotating the destination of rfid/hrfid powerpc/pseries: Add H_GET_CPU_CHARACTERISTICS flags & wrapper powerpc/pseries: Make RAS IRQ explicitly dependent on DLPAR WQ
2 parents 9443c16 + 6e032b3 commit 6bb8211

21 files changed

+561
-36
lines changed

arch/powerpc/include/asm/exception-64e.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,11 @@ exc_##label##_book3e:
209209
ori r3,r3,vector_offset@l; \
210210
mtspr SPRN_IVOR##vector_number,r3;
211211

212+
#define RFI_TO_KERNEL \
213+
rfi
214+
215+
#define RFI_TO_USER \
216+
rfi
217+
212218
#endif /* _ASM_POWERPC_EXCEPTION_64E_H */
213219

arch/powerpc/include/asm/exception-64s.h

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,59 @@
7474
*/
7575
#define EX_R3 EX_DAR
7676

77+
/*
78+
* Macros for annotating the expected destination of (h)rfid
79+
*
80+
* The nop instructions allow us to insert one or more instructions to flush the
81+
* L1-D cache when returning to userspace or a guest.
82+
*/
83+
#define RFI_FLUSH_SLOT \
84+
RFI_FLUSH_FIXUP_SECTION; \
85+
nop; \
86+
nop; \
87+
nop
88+
89+
#define RFI_TO_KERNEL \
90+
rfid
91+
92+
#define RFI_TO_USER \
93+
RFI_FLUSH_SLOT; \
94+
rfid; \
95+
b rfi_flush_fallback
96+
97+
#define RFI_TO_USER_OR_KERNEL \
98+
RFI_FLUSH_SLOT; \
99+
rfid; \
100+
b rfi_flush_fallback
101+
102+
#define RFI_TO_GUEST \
103+
RFI_FLUSH_SLOT; \
104+
rfid; \
105+
b rfi_flush_fallback
106+
107+
#define HRFI_TO_KERNEL \
108+
hrfid
109+
110+
#define HRFI_TO_USER \
111+
RFI_FLUSH_SLOT; \
112+
hrfid; \
113+
b hrfi_flush_fallback
114+
115+
#define HRFI_TO_USER_OR_KERNEL \
116+
RFI_FLUSH_SLOT; \
117+
hrfid; \
118+
b hrfi_flush_fallback
119+
120+
#define HRFI_TO_GUEST \
121+
RFI_FLUSH_SLOT; \
122+
hrfid; \
123+
b hrfi_flush_fallback
124+
125+
#define HRFI_TO_UNKNOWN \
126+
RFI_FLUSH_SLOT; \
127+
hrfid; \
128+
b hrfi_flush_fallback
129+
77130
#ifdef CONFIG_RELOCATABLE
78131
#define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
79132
mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
@@ -218,7 +271,7 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
218271
mtspr SPRN_##h##SRR0,r12; \
219272
mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
220273
mtspr SPRN_##h##SRR1,r10; \
221-
h##rfid; \
274+
h##RFI_TO_KERNEL; \
222275
b . /* prevent speculative execution */
223276
#define EXCEPTION_PROLOG_PSERIES_1(label, h) \
224277
__EXCEPTION_PROLOG_PSERIES_1(label, h)
@@ -232,7 +285,7 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
232285
mtspr SPRN_##h##SRR0,r12; \
233286
mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
234287
mtspr SPRN_##h##SRR1,r10; \
235-
h##rfid; \
288+
h##RFI_TO_KERNEL; \
236289
b . /* prevent speculative execution */
237290

238291
#define EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \

arch/powerpc/include/asm/feature-fixups.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,20 @@ label##3: \
187187
FTR_ENTRY_OFFSET label##1b-label##3b; \
188188
.popsection;
189189

190+
#define RFI_FLUSH_FIXUP_SECTION \
191+
951: \
192+
.pushsection __rfi_flush_fixup,"a"; \
193+
.align 2; \
194+
952: \
195+
FTR_ENTRY_OFFSET 951b-952b; \
196+
.popsection;
197+
198+
190199
#ifndef __ASSEMBLY__
200+
#include <linux/types.h>
201+
202+
extern long __start___rfi_flush_fixup, __stop___rfi_flush_fixup;
203+
191204
void apply_feature_fixups(void);
192205
void setup_feature_keys(void);
193206
#endif

arch/powerpc/include/asm/hvcall.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
#define H_GET_HCA_INFO 0x1B8
242242
#define H_GET_PERF_COUNT 0x1BC
243243
#define H_MANAGE_TRACE 0x1C0
244+
#define H_GET_CPU_CHARACTERISTICS 0x1C8
244245
#define H_FREE_LOGICAL_LAN_BUFFER 0x1D4
245246
#define H_QUERY_INT_STATE 0x1E4
246247
#define H_POLL_PENDING 0x1D8
@@ -330,6 +331,17 @@
330331
#define H_SIGNAL_SYS_RESET_ALL_OTHERS -2
331332
/* >= 0 values are CPU number */
332333

334+
/* H_GET_CPU_CHARACTERISTICS return values */
335+
#define H_CPU_CHAR_SPEC_BAR_ORI31 (1ull << 63) // IBM bit 0
336+
#define H_CPU_CHAR_BCCTRL_SERIALISED (1ull << 62) // IBM bit 1
337+
#define H_CPU_CHAR_L1D_FLUSH_ORI30 (1ull << 61) // IBM bit 2
338+
#define H_CPU_CHAR_L1D_FLUSH_TRIG2 (1ull << 60) // IBM bit 3
339+
#define H_CPU_CHAR_L1D_THREAD_PRIV (1ull << 59) // IBM bit 4
340+
341+
#define H_CPU_BEHAV_FAVOUR_SECURITY (1ull << 63) // IBM bit 0
342+
#define H_CPU_BEHAV_L1D_FLUSH_PR (1ull << 62) // IBM bit 1
343+
#define H_CPU_BEHAV_BNDS_CHK_SPEC_BAR (1ull << 61) // IBM bit 2
344+
333345
/* Flag values used in H_REGISTER_PROC_TBL hcall */
334346
#define PROC_TABLE_OP_MASK 0x18
335347
#define PROC_TABLE_DEREG 0x10
@@ -436,6 +448,11 @@ static inline unsigned int get_longbusy_msecs(int longbusy_rc)
436448
}
437449
}
438450

451+
struct h_cpu_char_result {
452+
u64 character;
453+
u64 behaviour;
454+
};
455+
439456
#endif /* __ASSEMBLY__ */
440457
#endif /* __KERNEL__ */
441458
#endif /* _ASM_POWERPC_HVCALL_H */

arch/powerpc/include/asm/paca.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ struct paca_struct {
232232
struct sibling_subcore_state *sibling_subcore_state;
233233
#endif
234234
#endif
235+
#ifdef CONFIG_PPC_BOOK3S_64
236+
/*
237+
* rfi fallback flush must be in its own cacheline to prevent
238+
* other paca data leaking into the L1d
239+
*/
240+
u64 exrfi[EX_SIZE] __aligned(0x80);
241+
void *rfi_flush_fallback_area;
242+
u64 l1d_flush_congruence;
243+
u64 l1d_flush_sets;
244+
#endif
235245
};
236246

237247
extern void copy_mm_to_paca(struct mm_struct *mm);

arch/powerpc/include/asm/plpar_wrappers.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,18 @@ static inline long plapr_signal_sys_reset(long cpu)
326326
return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu);
327327
}
328328

329+
static inline long plpar_get_cpu_characteristics(struct h_cpu_char_result *p)
330+
{
331+
unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
332+
long rc;
333+
334+
rc = plpar_hcall(H_GET_CPU_CHARACTERISTICS, retbuf);
335+
if (rc == H_SUCCESS) {
336+
p->character = retbuf[0];
337+
p->behaviour = retbuf[1];
338+
}
339+
340+
return rc;
341+
}
342+
329343
#endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */

arch/powerpc/include/asm/setup.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ static inline void pseries_big_endian_exceptions(void) {}
3939
static inline void pseries_little_endian_exceptions(void) {}
4040
#endif /* CONFIG_PPC_PSERIES */
4141

42+
void rfi_flush_enable(bool enable);
43+
44+
/* These are bit flags */
45+
enum l1d_flush_type {
46+
L1D_FLUSH_NONE = 0x1,
47+
L1D_FLUSH_FALLBACK = 0x2,
48+
L1D_FLUSH_ORI = 0x4,
49+
L1D_FLUSH_MTTRIG = 0x8,
50+
};
51+
52+
void __init setup_rfi_flush(enum l1d_flush_type, bool enable);
53+
void do_rfi_flush_fixups(enum l1d_flush_type types);
54+
4255
#endif /* !__ASSEMBLY__ */
4356

4457
#endif /* _ASM_POWERPC_SETUP_H */

arch/powerpc/kernel/asm-offsets.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ int main(void)
237237
OFFSET(PACA_NMI_EMERG_SP, paca_struct, nmi_emergency_sp);
238238
OFFSET(PACA_IN_MCE, paca_struct, in_mce);
239239
OFFSET(PACA_IN_NMI, paca_struct, in_nmi);
240+
OFFSET(PACA_RFI_FLUSH_FALLBACK_AREA, paca_struct, rfi_flush_fallback_area);
241+
OFFSET(PACA_EXRFI, paca_struct, exrfi);
242+
OFFSET(PACA_L1D_FLUSH_CONGRUENCE, paca_struct, l1d_flush_congruence);
243+
OFFSET(PACA_L1D_FLUSH_SETS, paca_struct, l1d_flush_sets);
244+
240245
#endif
241246
OFFSET(PACAHWCPUID, paca_struct, hw_cpu_id);
242247
OFFSET(PACAKEXECSTATE, paca_struct, kexec_state);

arch/powerpc/kernel/entry_64.S

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#include <asm/tm.h>
3838
#include <asm/ppc-opcode.h>
3939
#include <asm/export.h>
40+
#ifdef CONFIG_PPC_BOOK3S
41+
#include <asm/exception-64s.h>
42+
#else
43+
#include <asm/exception-64e.h>
44+
#endif
4045

4146
/*
4247
* System calls.
@@ -262,13 +267,23 @@ BEGIN_FTR_SECTION
262267
END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
263268

264269
ld r13,GPR13(r1) /* only restore r13 if returning to usermode */
270+
ld r2,GPR2(r1)
271+
ld r1,GPR1(r1)
272+
mtlr r4
273+
mtcr r5
274+
mtspr SPRN_SRR0,r7
275+
mtspr SPRN_SRR1,r8
276+
RFI_TO_USER
277+
b . /* prevent speculative execution */
278+
279+
/* exit to kernel */
265280
1: ld r2,GPR2(r1)
266281
ld r1,GPR1(r1)
267282
mtlr r4
268283
mtcr r5
269284
mtspr SPRN_SRR0,r7
270285
mtspr SPRN_SRR1,r8
271-
RFI
286+
RFI_TO_KERNEL
272287
b . /* prevent speculative execution */
273288

274289
.Lsyscall_error:
@@ -397,8 +412,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
397412
mtmsrd r10, 1
398413
mtspr SPRN_SRR0, r11
399414
mtspr SPRN_SRR1, r12
400-
401-
rfid
415+
RFI_TO_USER
402416
b . /* prevent speculative execution */
403417
#endif
404418
_ASM_NOKPROBE_SYMBOL(system_call_common);
@@ -878,7 +892,7 @@ BEGIN_FTR_SECTION
878892
END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
879893
ACCOUNT_CPU_USER_EXIT(r13, r2, r4)
880894
REST_GPR(13, r1)
881-
1:
895+
882896
mtspr SPRN_SRR1,r3
883897

884898
ld r2,_CCR(r1)
@@ -891,8 +905,22 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
891905
ld r3,GPR3(r1)
892906
ld r4,GPR4(r1)
893907
ld r1,GPR1(r1)
908+
RFI_TO_USER
909+
b . /* prevent speculative execution */
894910

895-
rfid
911+
1: mtspr SPRN_SRR1,r3
912+
913+
ld r2,_CCR(r1)
914+
mtcrf 0xFF,r2
915+
ld r2,_NIP(r1)
916+
mtspr SPRN_SRR0,r2
917+
918+
ld r0,GPR0(r1)
919+
ld r2,GPR2(r1)
920+
ld r3,GPR3(r1)
921+
ld r4,GPR4(r1)
922+
ld r1,GPR1(r1)
923+
RFI_TO_KERNEL
896924
b . /* prevent speculative execution */
897925

898926
#endif /* CONFIG_PPC_BOOK3E */
@@ -1073,7 +1101,7 @@ __enter_rtas:
10731101

10741102
mtspr SPRN_SRR0,r5
10751103
mtspr SPRN_SRR1,r6
1076-
rfid
1104+
RFI_TO_KERNEL
10771105
b . /* prevent speculative execution */
10781106

10791107
rtas_return_loc:
@@ -1098,7 +1126,7 @@ rtas_return_loc:
10981126

10991127
mtspr SPRN_SRR0,r3
11001128
mtspr SPRN_SRR1,r4
1101-
rfid
1129+
RFI_TO_KERNEL
11021130
b . /* prevent speculative execution */
11031131
_ASM_NOKPROBE_SYMBOL(__enter_rtas)
11041132
_ASM_NOKPROBE_SYMBOL(rtas_return_loc)
@@ -1171,7 +1199,7 @@ _GLOBAL(enter_prom)
11711199
LOAD_REG_IMMEDIATE(r12, MSR_SF | MSR_ISF | MSR_LE)
11721200
andc r11,r11,r12
11731201
mtsrr1 r11
1174-
rfid
1202+
RFI_TO_KERNEL
11751203
#endif /* CONFIG_PPC_BOOK3E */
11761204

11771205
1: /* Return from OF */

0 commit comments

Comments
 (0)