Skip to content

Commit d3cbff1

Browse files
ozbenhmpe
authored andcommitted
powerpc: Put exception configuration in a common place
The various calls to establish exception endianness and AIL are now done from a single point using already established CPU and FW feature bits to decide what to do. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 3808a88 commit d3cbff1

8 files changed

Lines changed: 108 additions & 103 deletions

File tree

‎arch/powerpc/include/asm/hvcall.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,6 @@ static inline unsigned long cmo_get_page_size(void)
431431
{
432432
return CMO_PageSize;
433433
}
434-
435-
extern long pSeries_enable_reloc_on_exc(void);
436-
extern long pSeries_disable_reloc_on_exc(void);
437-
438-
extern long pseries_big_endian_exceptions(void);
439-
440-
#else
441-
442-
#define pSeries_enable_reloc_on_exc() do {} while (0)
443-
#define pSeries_disable_reloc_on_exc() do {} while (0)
444-
445434
#endif /* CONFIG_PPC_PSERIES */
446435

447436
#endif /* __ASSEMBLY__ */

‎arch/powerpc/include/asm/opal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
234234
int depth, void *data);
235235
extern int early_init_dt_scan_recoverable_ranges(unsigned long node,
236236
const char *uname, int depth, void *data);
237+
extern void opal_configure_cores(void);
237238

238239
extern int opal_get_chars(uint32_t vtermno, char *buf, int count);
239240
extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);

‎arch/powerpc/include/asm/setup.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ void initmem_init(void);
2626
void setup_panic(void);
2727
#define ARCH_PANIC_TIMEOUT 180
2828

29+
#ifdef CONFIG_PPC_PSERIES
30+
extern void pseries_enable_reloc_on_exc(void);
31+
extern void pseries_disable_reloc_on_exc(void);
32+
extern void pseries_big_endian_exceptions(void);
33+
extern void pseries_little_endian_exceptions(void);
34+
#else
35+
static inline void pseries_enable_reloc_on_exc(void) {}
36+
static inline void pseries_disable_reloc_on_exc(void) {}
37+
static inline void pseries_big_endian_exceptions(void) {}
38+
static inline void pseries_little_endian_exceptions(void) {}
39+
#endif /* CONFIG_PPC_PSERIES */
40+
2941
#endif /* !__ASSEMBLY__ */
3042

3143
#endif /* _ASM_POWERPC_SETUP_H */

‎arch/powerpc/kernel/setup_64.c‎

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include <asm/kvm_ppc.h>
7070
#include <asm/hugetlb.h>
7171
#include <asm/livepatch.h>
72+
#include <asm/opal.h>
7273

7374
#ifdef DEBUG
7475
#define DBG(fmt...) udbg_printf(fmt)
@@ -205,23 +206,50 @@ static void fixup_boot_paca(void)
205206
get_paca()->data_offset = 0;
206207
}
207208

208-
static void cpu_ready_for_interrupts(void)
209+
static void configure_exceptions(void)
209210
{
210-
/* Set IR and DR in PACA MSR */
211-
get_paca()->kernel_msr = MSR_KERNEL;
212-
213211
/*
214-
* Enable AIL if supported, and we are in hypervisor mode. If we are
215-
* not in hypervisor mode, we enable relocation-on interrupts later
216-
* in pSeries_setup_arch() using the H_SET_MODE hcall.
212+
* Setup the trampolines from the lowmem exception vectors
213+
* to the kdump kernel when not using a relocatable kernel.
217214
*/
218-
if (cpu_has_feature(CPU_FTR_HVMODE) &&
219-
cpu_has_feature(CPU_FTR_ARCH_207S)) {
220-
unsigned long lpcr = mfspr(SPRN_LPCR);
221-
mtspr(SPRN_LPCR, lpcr | LPCR_AIL_3);
215+
setup_kdump_trampoline();
216+
217+
/* Under a PAPR hypervisor, we need hypercalls */
218+
if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
219+
/* Enable AIL if possible */
220+
pseries_enable_reloc_on_exc();
221+
222+
/*
223+
* Tell the hypervisor that we want our exceptions to
224+
* be taken in little endian mode.
225+
*
226+
* We don't call this for big endian as our calling convention
227+
* makes us always enter in BE, and the call may fail under
228+
* some circumstances with kdump.
229+
*/
230+
#ifdef __LITTLE_ENDIAN__
231+
pseries_little_endian_exceptions();
232+
#endif
233+
} else {
234+
/* Set endian mode using OPAL */
235+
if (firmware_has_feature(FW_FEATURE_OPAL))
236+
opal_configure_cores();
237+
238+
/* Enable AIL if supported, and we are in hypervisor mode */
239+
if (cpu_has_feature(CPU_FTR_HVMODE) &&
240+
cpu_has_feature(CPU_FTR_ARCH_207S)) {
241+
unsigned long lpcr = mfspr(SPRN_LPCR);
242+
mtspr(SPRN_LPCR, lpcr | LPCR_AIL_3);
243+
}
222244
}
223245
}
224246

247+
static void cpu_ready_for_interrupts(void)
248+
{
249+
/* Set IR and DR in PACA MSR */
250+
get_paca()->kernel_msr = MSR_KERNEL;
251+
}
252+
225253
/*
226254
* Early initialization entry point. This is called by head.S
227255
* with MMU translation disabled. We rely on the "feature" of
@@ -277,10 +305,10 @@ void __init early_setup(unsigned long dt_ptr)
277305
probe_machine();
278306

279307
/*
280-
* Setup the trampolines from the lowmem exception vectors
281-
* to the kdump kernel when not using a relocatable kernel.
308+
* Configure exception handlers. This include setting up trampolines
309+
* if needed, setting exception endian mode, etc...
282310
*/
283-
setup_kdump_trampoline();
311+
configure_exceptions();
284312

285313
/* Initialize the hash table or TLB handling */
286314
early_init_mmu();

‎arch/powerpc/kvm/book3s_pr.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <asm/mmu_context.h>
3636
#include <asm/switch_to.h>
3737
#include <asm/firmware.h>
38-
#include <asm/hvcall.h>
38+
#include <asm/setup.h>
3939
#include <linux/gfp.h>
4040
#include <linux/sched.h>
4141
#include <linux/vmalloc.h>
@@ -1690,7 +1690,7 @@ static int kvmppc_core_init_vm_pr(struct kvm *kvm)
16901690
if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
16911691
spin_lock(&kvm_global_user_count_lock);
16921692
if (++kvm_global_user_count == 1)
1693-
pSeries_disable_reloc_on_exc();
1693+
pseries_disable_reloc_on_exc();
16941694
spin_unlock(&kvm_global_user_count_lock);
16951695
}
16961696
return 0;
@@ -1706,7 +1706,7 @@ static void kvmppc_core_destroy_vm_pr(struct kvm *kvm)
17061706
spin_lock(&kvm_global_user_count_lock);
17071707
BUG_ON(kvm_global_user_count == 0);
17081708
if (--kvm_global_user_count == 0)
1709-
pSeries_enable_reloc_on_exc();
1709+
pseries_enable_reloc_on_exc();
17101710
spin_unlock(&kvm_global_user_count_lock);
17111711
}
17121712
}

‎arch/powerpc/platforms/powernv/opal.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static struct atomic_notifier_head opal_msg_notifier_head[OPAL_MSG_TYPE_MAX];
5757
static uint32_t opal_heartbeat;
5858
static struct task_struct *kopald_tsk;
5959

60-
static void opal_reinit_cores(void)
60+
void opal_configure_cores(void)
6161
{
6262
/* Do the actual re-init, This will clobber all FPRs, VRs, etc...
6363
*
@@ -70,6 +70,10 @@ static void opal_reinit_cores(void)
7070
#else
7171
opal_reinit_cpus(OPAL_REINIT_CPUS_HILE_LE);
7272
#endif
73+
74+
/* Restore some bits */
75+
if (cur_cpu_spec->cpu_restore)
76+
cur_cpu_spec->cpu_restore();
7377
}
7478

7579
int __init early_init_dt_scan_opal(unsigned long node,
@@ -106,13 +110,6 @@ int __init early_init_dt_scan_opal(unsigned long node,
106110
panic("OPAL != V3 detected, no longer supported.\n");
107111
}
108112

109-
/* Reinit all cores with the right endian */
110-
opal_reinit_cores();
111-
112-
/* Restore some bits */
113-
if (cur_cpu_spec->cpu_restore)
114-
cur_cpu_spec->cpu_restore();
115-
116113
return 1;
117114
}
118115

‎arch/powerpc/platforms/pseries/lpar.c‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -261,24 +261,8 @@ static void pSeries_lpar_hptab_clear(void)
261261
* This is also called on boot when a fadump happens. In that case we
262262
* must not change the exception endian mode.
263263
*/
264-
if (firmware_has_feature(FW_FEATURE_SET_MODE) && !is_fadump_active()) {
265-
long rc;
266-
267-
rc = pseries_big_endian_exceptions();
268-
/*
269-
* At this point it is unlikely panic() will get anything
270-
* out to the user, but at least this will stop us from
271-
* continuing on further and creating an even more
272-
* difficult to debug situation.
273-
*
274-
* There is a known problem when kdump'ing, if cpus are offline
275-
* the above call will fail. Rather than panicking again, keep
276-
* going and hope the kdump kernel is also little endian, which
277-
* it usually is.
278-
*/
279-
if (rc && !kdump_in_progress())
280-
panic("Could not enable big endian exceptions");
281-
}
264+
if (firmware_has_feature(FW_FEATURE_SET_MODE) && !is_fadump_active())
265+
pseries_big_endian_exceptions();
282266
#endif
283267
}
284268

‎arch/powerpc/platforms/pseries/setup.c‎

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -319,82 +319,105 @@ static void pseries_lpar_idle(void)
319319
* to ever be a problem in practice we can move this into a kernel thread to
320320
* finish off the process later in boot.
321321
*/
322-
long pSeries_enable_reloc_on_exc(void)
322+
void pseries_enable_reloc_on_exc(void)
323323
{
324324
long rc;
325325
unsigned int delay, total_delay = 0;
326326

327327
while (1) {
328328
rc = enable_reloc_on_exceptions();
329-
if (!H_IS_LONG_BUSY(rc))
330-
return rc;
329+
if (!H_IS_LONG_BUSY(rc)) {
330+
if (rc == H_P2) {
331+
pr_info("Relocation on exceptions not"
332+
" supported\n");
333+
} else if (rc != H_SUCCESS) {
334+
pr_warn("Unable to enable relocation"
335+
" on exceptions: %ld\n", rc);
336+
}
337+
break;
338+
}
331339

332340
delay = get_longbusy_msecs(rc);
333341
total_delay += delay;
334342
if (total_delay > 1000) {
335343
pr_warn("Warning: Giving up waiting to enable "
336344
"relocation on exceptions (%u msec)!\n",
337345
total_delay);
338-
return rc;
346+
return;
339347
}
340348

341349
mdelay(delay);
342350
}
343351
}
344-
EXPORT_SYMBOL(pSeries_enable_reloc_on_exc);
352+
EXPORT_SYMBOL(pseries_enable_reloc_on_exc);
345353

346-
long pSeries_disable_reloc_on_exc(void)
354+
void pseries_disable_reloc_on_exc(void)
347355
{
348356
long rc;
349357

350358
while (1) {
351359
rc = disable_reloc_on_exceptions();
352360
if (!H_IS_LONG_BUSY(rc))
353-
return rc;
361+
break;
354362
mdelay(get_longbusy_msecs(rc));
355363
}
364+
if (rc != H_SUCCESS)
365+
pr_warning("Warning: Failed to disable relocation on "
366+
"exceptions: %ld\n", rc);
356367
}
357-
EXPORT_SYMBOL(pSeries_disable_reloc_on_exc);
368+
EXPORT_SYMBOL(pseries_disable_reloc_on_exc);
358369

359370
#ifdef CONFIG_KEXEC
360371
static void pSeries_machine_kexec(struct kimage *image)
361372
{
362-
long rc;
363-
364-
if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
365-
rc = pSeries_disable_reloc_on_exc();
366-
if (rc != H_SUCCESS)
367-
pr_warning("Warning: Failed to disable relocation on "
368-
"exceptions: %ld\n", rc);
369-
}
373+
if (firmware_has_feature(FW_FEATURE_SET_MODE))
374+
pseries_disable_reloc_on_exc();
370375

371376
default_machine_kexec(image);
372377
}
373378
#endif
374379

375380
#ifdef __LITTLE_ENDIAN__
376-
long pseries_big_endian_exceptions(void)
381+
void pseries_big_endian_exceptions(void)
377382
{
378383
long rc;
379384

380385
while (1) {
381386
rc = enable_big_endian_exceptions();
382387
if (!H_IS_LONG_BUSY(rc))
383-
return rc;
388+
break;
384389
mdelay(get_longbusy_msecs(rc));
385390
}
391+
392+
/*
393+
* At this point it is unlikely panic() will get anything
394+
* out to the user, since this is called very late in kexec
395+
* but at least this will stop us from continuing on further
396+
* and creating an even more difficult to debug situation.
397+
*
398+
* There is a known problem when kdump'ing, if cpus are offline
399+
* the above call will fail. Rather than panicking again, keep
400+
* going and hope the kdump kernel is also little endian, which
401+
* it usually is.
402+
*/
403+
if (rc && !kdump_in_progress())
404+
panic("Could not enable big endian exceptions");
386405
}
387406

388-
static long pseries_little_endian_exceptions(void)
407+
void pseries_little_endian_exceptions(void)
389408
{
390409
long rc;
391410

392411
while (1) {
393412
rc = enable_little_endian_exceptions();
394413
if (!H_IS_LONG_BUSY(rc))
395-
return rc;
414+
break;
396415
mdelay(get_longbusy_msecs(rc));
397416
}
417+
if (rc) {
418+
ppc_md.progress("H_SET_MODE LE exception fail", 0);
419+
panic("Could not enable little endian exceptions");
420+
}
398421
}
399422
#endif
400423

@@ -464,18 +487,6 @@ static void __init pSeries_setup_arch(void)
464487
}
465488

466489
ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
467-
468-
if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
469-
long rc;
470-
471-
rc = pSeries_enable_reloc_on_exc();
472-
if (rc == H_P2) {
473-
pr_info("Relocation on exceptions not supported\n");
474-
} else if (rc != H_SUCCESS) {
475-
pr_warn("Unable to enable relocation on exceptions: "
476-
"%ld\n", rc);
477-
}
478-
}
479490
}
480491

481492
static int __init pSeries_init_panel(void)
@@ -678,23 +689,6 @@ static int __init pSeries_probe(void)
678689

679690
pr_debug("pSeries detected, looking for LPAR capability...\n");
680691

681-
682-
#ifdef __LITTLE_ENDIAN__
683-
if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
684-
long rc;
685-
/*
686-
* Tell the hypervisor that we want our exceptions to
687-
* be taken in little endian mode. If this fails we don't
688-
* want to use BUG() because it will trigger an exception.
689-
*/
690-
rc = pseries_little_endian_exceptions();
691-
if (rc) {
692-
ppc_md.progress("H_SET_MODE LE exception fail", 0);
693-
panic("Could not enable little endian exceptions");
694-
}
695-
}
696-
#endif
697-
698692
if (firmware_has_feature(FW_FEATURE_LPAR))
699693
hpte_init_lpar();
700694
else

0 commit comments

Comments
 (0)