1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PowerPC64 SLB support.
5 * Copyright (C) 2004 David Gibson <dwg@au.ibm.com>, IBM
6 * Based on earlier code written by:
7 * Dave Engebretsen and Mike Corrigan {engebret|mikejc}@us.ibm.com
8 * Copyright (c) 2001 Dave Engebretsen
9 * Copyright (C) 2002 Anton Blanchard <anton@au.ibm.com>, IBM
12 #include <asm/asm-prototypes.h>
14 #include <asm/mmu_context.h>
16 #include <asm/ppc-opcode.h>
17 #include <asm/cputable.h>
18 #include <asm/cacheflush.h>
20 #include <linux/compiler.h>
21 #include <linux/context_tracking.h>
22 #include <linux/mm_types.h>
23 #include <linux/pgtable.h>
26 #include <asm/code-patching.h>
32 LINEAR_INDEX = 0, /* Kernel linear map (0xc000000000000000) */
33 KSTACK_INDEX = 1, /* Kernel stack map */
36 static long slb_allocate_user(struct mm_struct *mm, unsigned long ea);
38 #define slb_esid_mask(ssize) \
39 (((ssize) == MMU_SEGSIZE_256M)? ESID_MASK: ESID_MASK_1T)
41 static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
44 return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | index;
47 static inline unsigned long __mk_vsid_data(unsigned long vsid, int ssize,
50 return (vsid << slb_vsid_shift(ssize)) | flags |
51 ((unsigned long) ssize << SLB_VSID_SSIZE_SHIFT);
54 static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
57 return __mk_vsid_data(get_kernel_vsid(ea, ssize), ssize, flags);
60 bool stress_slb_enabled __initdata;
62 static int __init parse_stress_slb(char *p)
64 stress_slb_enabled = true;
67 early_param("stress_slb", parse_stress_slb);
69 __ro_after_init DEFINE_STATIC_KEY_FALSE(stress_slb_key);
71 static void assert_slb_presence(bool present, unsigned long ea)
73 #ifdef CONFIG_DEBUG_VM
76 WARN_ON_ONCE(mfmsr() & MSR_EE);
78 if (!cpu_has_feature(CPU_FTR_ARCH_206))
82 * slbfee. requires bit 24 (PPC bit 39) be clear in RB. Hardware
83 * ignores all other bits from 0-27, so just clear them all.
85 ea &= ~((1UL << SID_SHIFT) - 1);
86 asm volatile(__PPC_SLBFEE_DOT(%0, %1) : "=r"(tmp) : "r"(ea) : "cr0");
88 WARN_ON(present == (tmp == 0));
92 static inline void slb_shadow_update(unsigned long ea, int ssize,
96 struct slb_shadow *p = get_slb_shadow();
99 * Clear the ESID first so the entry is not valid while we are
100 * updating it. No write barriers are needed here, provided
101 * we only update the current CPU's SLB shadow buffer.
103 WRITE_ONCE(p->save_area[index].esid, 0);
104 WRITE_ONCE(p->save_area[index].vsid, cpu_to_be64(mk_vsid_data(ea, ssize, flags)));
105 WRITE_ONCE(p->save_area[index].esid, cpu_to_be64(mk_esid_data(ea, ssize, index)));
108 static inline void slb_shadow_clear(enum slb_index index)
110 WRITE_ONCE(get_slb_shadow()->save_area[index].esid, cpu_to_be64(index));
113 static inline void create_shadowed_slbe(unsigned long ea, int ssize,
115 enum slb_index index)
118 * Updating the shadow buffer before writing the SLB ensures
119 * we don't get a stale entry here if we get preempted by PHYP
120 * between these two statements.
122 slb_shadow_update(ea, ssize, flags, index);
124 assert_slb_presence(false, ea);
125 asm volatile("slbmte %0,%1" :
126 : "r" (mk_vsid_data(ea, ssize, flags)),
127 "r" (mk_esid_data(ea, ssize, index))
132 * Insert bolted entries into SLB (which may not be empty, so don't clear
135 void __slb_restore_bolted_realmode(void)
137 struct slb_shadow *p = get_slb_shadow();
138 enum slb_index index;
140 /* No isync needed because realmode. */
141 for (index = 0; index < SLB_NUM_BOLTED; index++) {
142 asm volatile("slbmte %0,%1" :
143 : "r" (be64_to_cpu(p->save_area[index].vsid)),
144 "r" (be64_to_cpu(p->save_area[index].esid)));
147 assert_slb_presence(true, local_paca->kstack);
151 * Insert the bolted entries into an empty SLB.
153 void slb_restore_bolted_realmode(void)
155 __slb_restore_bolted_realmode();
156 get_paca()->slb_cache_ptr = 0;
158 get_paca()->slb_kern_bitmap = (1U << SLB_NUM_BOLTED) - 1;
159 get_paca()->slb_used_bitmap = get_paca()->slb_kern_bitmap;
163 * This flushes all SLB entries including 0, so it must be realmode.
165 void slb_flush_all_realmode(void)
167 asm volatile("slbmte %0,%0; slbia" : : "r" (0));
170 static __always_inline void __slb_flush_and_restore_bolted(bool preserve_kernel_lookaside)
172 struct slb_shadow *p = get_slb_shadow();
173 unsigned long ksp_esid_data, ksp_vsid_data;
177 * SLBIA IH=1 on ISA v2.05 and newer processors may preserve lookaside
178 * information created with Class=0 entries, which we use for kernel
179 * SLB entries (the SLB entries themselves are still invalidated).
181 * Older processors will ignore this optimisation. Over-invalidation
182 * is fine because we never rely on lookaside information existing.
184 if (preserve_kernel_lookaside)
189 ksp_esid_data = be64_to_cpu(p->save_area[KSTACK_INDEX].esid);
190 ksp_vsid_data = be64_to_cpu(p->save_area[KSTACK_INDEX].vsid);
192 asm volatile(PPC_SLBIA(%0)" \n"
201 * This flushes non-bolted entries, it can be run in virtual mode. Must
202 * be called with interrupts disabled.
204 void slb_flush_and_restore_bolted(void)
206 BUILD_BUG_ON(SLB_NUM_BOLTED != 2);
208 WARN_ON(!irqs_disabled());
211 * We can't take a PMU exception in the following code, so hard
212 * disable interrupts.
217 __slb_flush_and_restore_bolted(false);
220 assert_slb_presence(true, get_paca()->kstack);
222 get_paca()->slb_cache_ptr = 0;
224 get_paca()->slb_kern_bitmap = (1U << SLB_NUM_BOLTED) - 1;
225 get_paca()->slb_used_bitmap = get_paca()->slb_kern_bitmap;
228 void slb_save_contents(struct slb_entry *slb_ptr)
233 /* Save slb_cache_ptr value. */
234 get_paca()->slb_save_cache_ptr = get_paca()->slb_cache_ptr;
239 for (i = 0; i < mmu_slb_size; i++) {
240 asm volatile("slbmfee %0,%1" : "=r" (e) : "r" (i));
241 asm volatile("slbmfev %0,%1" : "=r" (v) : "r" (i));
248 void slb_dump_contents(struct slb_entry *slb_ptr)
257 pr_err("SLB contents of cpu 0x%x\n", smp_processor_id());
258 pr_err("Last SLB entry inserted at slot %d\n", get_paca()->stab_rr);
260 for (i = 0; i < mmu_slb_size; i++) {
268 pr_err("%02d %016lx %016lx\n", i, e, v);
270 if (!(e & SLB_ESID_V)) {
274 llp = v & SLB_VSID_LLP;
275 if (v & SLB_VSID_B_1T) {
276 pr_err(" 1T ESID=%9lx VSID=%13lx LLP:%3lx\n",
278 (v & ~SLB_VSID_B) >> SLB_VSID_SHIFT_1T, llp);
280 pr_err(" 256M ESID=%9lx VSID=%13lx LLP:%3lx\n",
282 (v & ~SLB_VSID_B) >> SLB_VSID_SHIFT, llp);
285 pr_err("----------------------------------\n");
287 /* Dump slb cache entires as well. */
288 pr_err("SLB cache ptr value = %d\n", get_paca()->slb_save_cache_ptr);
289 pr_err("Valid SLB cache entries:\n");
290 n = min_t(int, get_paca()->slb_save_cache_ptr, SLB_CACHE_ENTRIES);
291 for (i = 0; i < n; i++)
292 pr_err("%02d EA[0-35]=%9x\n", i, get_paca()->slb_cache[i]);
293 pr_err("Rest of SLB cache entries:\n");
294 for (i = n; i < SLB_CACHE_ENTRIES; i++)
295 pr_err("%02d EA[0-35]=%9x\n", i, get_paca()->slb_cache[i]);
298 void slb_vmalloc_update(void)
301 * vmalloc is not bolted, so just have to flush non-bolted.
303 slb_flush_and_restore_bolted();
306 static bool preload_hit(struct thread_info *ti, unsigned long esid)
310 for (i = 0; i < ti->slb_preload_nr; i++) {
313 idx = (ti->slb_preload_tail + i) % SLB_PRELOAD_NR;
314 if (esid == ti->slb_preload_esid[idx])
320 static bool preload_add(struct thread_info *ti, unsigned long ea)
325 if (mmu_has_feature(MMU_FTR_1T_SEGMENT)) {
326 /* EAs are stored >> 28 so 256MB segments don't need clearing */
327 if (ea & ESID_MASK_1T)
331 esid = ea >> SID_SHIFT;
333 if (preload_hit(ti, esid))
336 idx = (ti->slb_preload_tail + ti->slb_preload_nr) % SLB_PRELOAD_NR;
337 ti->slb_preload_esid[idx] = esid;
338 if (ti->slb_preload_nr == SLB_PRELOAD_NR)
339 ti->slb_preload_tail = (ti->slb_preload_tail + 1) % SLB_PRELOAD_NR;
341 ti->slb_preload_nr++;
346 static void preload_age(struct thread_info *ti)
348 if (!ti->slb_preload_nr)
350 ti->slb_preload_nr--;
351 ti->slb_preload_tail = (ti->slb_preload_tail + 1) % SLB_PRELOAD_NR;
354 void slb_setup_new_exec(void)
356 struct thread_info *ti = current_thread_info();
357 struct mm_struct *mm = current->mm;
358 unsigned long exec = 0x10000000;
360 WARN_ON(irqs_disabled());
363 * preload cache can only be used to determine whether a SLB
364 * entry exists if it does not start to overflow.
366 if (ti->slb_preload_nr + 2 > SLB_PRELOAD_NR)
372 * We have no good place to clear the slb preload cache on exec,
373 * flush_thread is about the earliest arch hook but that happens
374 * after we switch to the mm and have aleady preloaded the SLBEs.
376 * For the most part that's probably okay to use entries from the
377 * previous exec, they will age out if unused. It may turn out to
378 * be an advantage to clear the cache before switching to it,
383 * preload some userspace segments into the SLB.
384 * Almost all 32 and 64bit PowerPC executables are linked at
385 * 0x10000000 so it makes sense to preload this segment.
387 if (!is_kernel_addr(exec)) {
388 if (preload_add(ti, exec))
389 slb_allocate_user(mm, exec);
392 /* Libraries and mmaps. */
393 if (!is_kernel_addr(mm->mmap_base)) {
394 if (preload_add(ti, mm->mmap_base))
395 slb_allocate_user(mm, mm->mmap_base);
399 asm volatile("isync" : : : "memory");
404 void preload_new_slb_context(unsigned long start, unsigned long sp)
406 struct thread_info *ti = current_thread_info();
407 struct mm_struct *mm = current->mm;
408 unsigned long heap = mm->start_brk;
410 WARN_ON(irqs_disabled());
413 if (ti->slb_preload_nr + 3 > SLB_PRELOAD_NR)
418 /* Userspace entry address. */
419 if (!is_kernel_addr(start)) {
420 if (preload_add(ti, start))
421 slb_allocate_user(mm, start);
424 /* Top of stack, grows down. */
425 if (!is_kernel_addr(sp)) {
426 if (preload_add(ti, sp))
427 slb_allocate_user(mm, sp);
430 /* Bottom of heap, grows up. */
431 if (heap && !is_kernel_addr(heap)) {
432 if (preload_add(ti, heap))
433 slb_allocate_user(mm, heap);
437 asm volatile("isync" : : : "memory");
442 static void slb_cache_slbie_kernel(unsigned int index)
444 unsigned long slbie_data = get_paca()->slb_cache[index];
445 unsigned long ksp = get_paca()->kstack;
447 slbie_data <<= SID_SHIFT;
448 slbie_data |= 0xc000000000000000ULL;
449 if ((ksp & slb_esid_mask(mmu_kernel_ssize)) == slbie_data)
451 slbie_data |= mmu_kernel_ssize << SLBIE_SSIZE_SHIFT;
453 asm volatile("slbie %0" : : "r" (slbie_data));
456 static void slb_cache_slbie_user(unsigned int index)
458 unsigned long slbie_data = get_paca()->slb_cache[index];
460 slbie_data <<= SID_SHIFT;
461 slbie_data |= user_segment_size(slbie_data) << SLBIE_SSIZE_SHIFT;
462 slbie_data |= SLBIE_C; /* user slbs have C=1 */
464 asm volatile("slbie %0" : : "r" (slbie_data));
467 /* Flush all user entries from the segment table of the current processor. */
468 void switch_slb(struct task_struct *tsk, struct mm_struct *mm)
470 struct thread_info *ti = task_thread_info(tsk);
474 * We need interrupts hard-disabled here, not just soft-disabled,
475 * so that a PMU interrupt can't occur, which might try to access
476 * user memory (to get a stack trace) and possible cause an SLB miss
477 * which would update the slb_cache/slb_cache_ptr fields in the PACA.
482 __slb_flush_and_restore_bolted(false);
484 get_paca()->slb_cache_ptr = 0;
485 get_paca()->slb_kern_bitmap = (1U << SLB_NUM_BOLTED) - 1;
487 } else if (cpu_has_feature(CPU_FTR_ARCH_300)) {
489 * SLBIA IH=3 invalidates all Class=1 SLBEs and their
490 * associated lookaside structures, which matches what
491 * switch_slb wants. So ARCH_300 does not use the slb
494 asm volatile(PPC_SLBIA(3));
497 unsigned long offset = get_paca()->slb_cache_ptr;
499 if (!mmu_has_feature(MMU_FTR_NO_SLBIE_B) &&
500 offset <= SLB_CACHE_ENTRIES) {
502 * Could assert_slb_presence(true) here, but
503 * hypervisor or machine check could have come
504 * in and removed the entry at this point.
507 for (i = 0; i < offset; i++)
508 slb_cache_slbie_user(i);
510 /* Workaround POWER5 < DD2.1 issue */
511 if (!cpu_has_feature(CPU_FTR_ARCH_207S) && offset == 1)
512 slb_cache_slbie_user(0);
515 /* Flush but retain kernel lookaside information */
516 __slb_flush_and_restore_bolted(true);
519 get_paca()->slb_kern_bitmap = (1U << SLB_NUM_BOLTED) - 1;
522 get_paca()->slb_cache_ptr = 0;
524 get_paca()->slb_used_bitmap = get_paca()->slb_kern_bitmap;
529 * We gradually age out SLBs after a number of context switches to
530 * reduce reload overhead of unused entries (like we do with FP/VEC
531 * reload). Each time we wrap 256 switches, take an entry out of the
534 tsk->thread.load_slb++;
535 if (!tsk->thread.load_slb) {
536 unsigned long pc = KSTK_EIP(tsk);
542 for (i = 0; i < ti->slb_preload_nr; i++) {
546 idx = (ti->slb_preload_tail + i) % SLB_PRELOAD_NR;
547 ea = (unsigned long)ti->slb_preload_esid[idx] << SID_SHIFT;
549 slb_allocate_user(mm, ea);
553 * Synchronize slbmte preloads with possible subsequent user memory
554 * address accesses by the kernel (user mode won't happen until
555 * rfid, which is safe).
560 void slb_set_size(u16 size)
565 void slb_initialize(void)
567 unsigned long linear_llp, vmalloc_llp, io_llp;
568 unsigned long lflags;
569 static int slb_encoding_inited;
570 #ifdef CONFIG_SPARSEMEM_VMEMMAP
571 unsigned long vmemmap_llp;
574 /* Prepare our SLB miss handler based on our page size */
575 linear_llp = mmu_psize_defs[mmu_linear_psize].sllp;
576 io_llp = mmu_psize_defs[mmu_io_psize].sllp;
577 vmalloc_llp = mmu_psize_defs[mmu_vmalloc_psize].sllp;
578 get_paca()->vmalloc_sllp = SLB_VSID_KERNEL | vmalloc_llp;
579 #ifdef CONFIG_SPARSEMEM_VMEMMAP
580 vmemmap_llp = mmu_psize_defs[mmu_vmemmap_psize].sllp;
582 if (!slb_encoding_inited) {
583 slb_encoding_inited = 1;
584 pr_devel("SLB: linear LLP = %04lx\n", linear_llp);
585 pr_devel("SLB: io LLP = %04lx\n", io_llp);
586 #ifdef CONFIG_SPARSEMEM_VMEMMAP
587 pr_devel("SLB: vmemmap LLP = %04lx\n", vmemmap_llp);
591 get_paca()->stab_rr = SLB_NUM_BOLTED - 1;
592 get_paca()->slb_kern_bitmap = (1U << SLB_NUM_BOLTED) - 1;
593 get_paca()->slb_used_bitmap = get_paca()->slb_kern_bitmap;
595 lflags = SLB_VSID_KERNEL | linear_llp;
597 /* Invalidate the entire SLB (even entry 0) & all the ERATS */
598 asm volatile("isync":::"memory");
599 asm volatile("slbmte %0,%0"::"r" (0) : "memory");
600 asm volatile("isync; slbia; isync":::"memory");
601 create_shadowed_slbe(PAGE_OFFSET, mmu_kernel_ssize, lflags, LINEAR_INDEX);
604 * For the boot cpu, we're running on the stack in init_thread_union,
605 * which is in the first segment of the linear mapping, and also
606 * get_paca()->kstack hasn't been initialized yet.
607 * For secondary cpus, we need to bolt the kernel stack entry now.
609 slb_shadow_clear(KSTACK_INDEX);
610 if (raw_smp_processor_id() != boot_cpuid &&
611 (get_paca()->kstack & slb_esid_mask(mmu_kernel_ssize)) > PAGE_OFFSET)
612 create_shadowed_slbe(get_paca()->kstack,
613 mmu_kernel_ssize, lflags, KSTACK_INDEX);
615 asm volatile("isync":::"memory");
618 static void slb_cache_update(unsigned long esid_data)
622 if (cpu_has_feature(CPU_FTR_ARCH_300))
623 return; /* ISAv3.0B and later does not use slb_cache */
629 * Now update slb cache entries
631 slb_cache_index = local_paca->slb_cache_ptr;
632 if (slb_cache_index < SLB_CACHE_ENTRIES) {
634 * We have space in slb cache for optimized switch_slb().
635 * Top 36 bits from esid_data as per ISA
637 local_paca->slb_cache[slb_cache_index++] = esid_data >> SID_SHIFT;
638 local_paca->slb_cache_ptr++;
641 * Our cache is full and the current cache content strictly
642 * doesn't indicate the active SLB conents. Bump the ptr
643 * so that switch_slb() will ignore the cache.
645 local_paca->slb_cache_ptr = SLB_CACHE_ENTRIES + 1;
649 static enum slb_index alloc_slb_index(bool kernel)
651 enum slb_index index;
654 * The allocation bitmaps can become out of synch with the SLB
655 * when the _switch code does slbie when bolting a new stack
656 * segment and it must not be anywhere else in the SLB. This leaves
657 * a kernel allocated entry that is unused in the SLB. With very
658 * large systems or small segment sizes, the bitmaps could slowly
659 * fill with these entries. They will eventually be cleared out
660 * by the round robin allocator in that case, so it's probably not
661 * worth accounting for.
665 * SLBs beyond 32 entries are allocated with stab_rr only
666 * POWER7/8/9 have 32 SLB entries, this could be expanded if a
667 * future CPU has more.
669 if (local_paca->slb_used_bitmap != U32_MAX) {
670 index = ffz(local_paca->slb_used_bitmap);
671 local_paca->slb_used_bitmap |= 1U << index;
673 local_paca->slb_kern_bitmap |= 1U << index;
675 /* round-robin replacement of slb starting at SLB_NUM_BOLTED. */
676 index = local_paca->stab_rr;
677 if (index < (mmu_slb_size - 1))
680 index = SLB_NUM_BOLTED;
681 local_paca->stab_rr = index;
684 local_paca->slb_kern_bitmap |= 1U << index;
686 local_paca->slb_kern_bitmap &= ~(1U << index);
689 BUG_ON(index < SLB_NUM_BOLTED);
694 static long slb_insert_entry(unsigned long ea, unsigned long context,
695 unsigned long flags, int ssize, bool kernel)
698 unsigned long vsid_data, esid_data;
699 enum slb_index index;
701 vsid = get_vsid(context, ea, ssize);
706 * There must not be a kernel SLB fault in alloc_slb_index or before
707 * slbmte here or the allocation bitmaps could get out of whack with
710 * User SLB faults or preloads take this path which might get inlined
711 * into the caller, so add compiler barriers here to ensure unsafe
712 * memory accesses do not come between.
716 index = alloc_slb_index(kernel);
718 vsid_data = __mk_vsid_data(vsid, ssize, flags);
719 esid_data = mk_esid_data(ea, ssize, index);
722 * No need for an isync before or after this slbmte. The exception
723 * we enter with and the rfid we exit with are context synchronizing.
724 * User preloads should add isync afterwards in case the kernel
725 * accesses user memory before it returns to userspace with rfid.
727 assert_slb_presence(false, ea);
729 int slb_cache_index = local_paca->slb_cache_ptr;
732 * stress_slb() does not use slb cache, repurpose as a
733 * cache of inserted (non-bolted) kernel SLB entries. All
734 * non-bolted kernel entries are flushed on any user fault,
735 * or if there are already 3 non-boled kernel entries.
737 BUILD_BUG_ON(SLB_CACHE_ENTRIES < 3);
738 if (!kernel || slb_cache_index == 3) {
741 for (i = 0; i < slb_cache_index; i++)
742 slb_cache_slbie_kernel(i);
747 local_paca->slb_cache[slb_cache_index++] = esid_data >> SID_SHIFT;
748 local_paca->slb_cache_ptr = slb_cache_index;
750 asm volatile("slbmte %0, %1" : : "r" (vsid_data), "r" (esid_data));
755 slb_cache_update(esid_data);
760 static long slb_allocate_kernel(unsigned long ea, unsigned long id)
762 unsigned long context;
766 if (id == LINEAR_MAP_REGION_ID) {
768 /* We only support upto MAX_PHYSMEM_BITS */
769 if ((ea & EA_MASK) > (1UL << MAX_PHYSMEM_BITS))
772 flags = SLB_VSID_KERNEL | mmu_psize_defs[mmu_linear_psize].sllp;
774 #ifdef CONFIG_SPARSEMEM_VMEMMAP
775 } else if (id == VMEMMAP_REGION_ID) {
777 if (ea >= H_VMEMMAP_END)
780 flags = SLB_VSID_KERNEL | mmu_psize_defs[mmu_vmemmap_psize].sllp;
782 } else if (id == VMALLOC_REGION_ID) {
784 if (ea >= H_VMALLOC_END)
787 flags = local_paca->vmalloc_sllp;
789 } else if (id == IO_REGION_ID) {
791 if (ea >= H_KERN_IO_END)
794 flags = SLB_VSID_KERNEL | mmu_psize_defs[mmu_io_psize].sllp;
800 ssize = MMU_SEGSIZE_1T;
801 if (!mmu_has_feature(MMU_FTR_1T_SEGMENT))
802 ssize = MMU_SEGSIZE_256M;
804 context = get_kernel_context(ea);
806 return slb_insert_entry(ea, context, flags, ssize, true);
809 static long slb_allocate_user(struct mm_struct *mm, unsigned long ea)
811 unsigned long context;
817 * consider this as bad access if we take a SLB miss
818 * on an address above addr limit.
820 if (ea >= mm_ctx_slb_addr_limit(&mm->context))
823 context = get_user_context(&mm->context, ea);
827 if (unlikely(ea >= H_PGTABLE_RANGE)) {
832 ssize = user_segment_size(ea);
834 bpsize = get_slice_psize(mm, ea);
835 flags = SLB_VSID_USER | mmu_psize_defs[bpsize].sllp;
837 return slb_insert_entry(ea, context, flags, ssize, false);
840 long do_slb_fault(struct pt_regs *regs, unsigned long ea)
842 unsigned long id = get_region_id(ea);
844 /* IRQs are not reconciled here, so can't check irqs_disabled */
845 VM_WARN_ON(mfmsr() & MSR_EE);
847 if (unlikely(!(regs->msr & MSR_RI)))
851 * SLB kernel faults must be very careful not to touch anything
852 * that is not bolted. E.g., PACA and global variables are okay,
853 * mm->context stuff is not.
855 * SLB user faults can access all of kernel memory, but must be
856 * careful not to touch things like IRQ state because it is not
857 * "reconciled" here. The difficulty is that we must use
858 * fast_exception_return to return from kernel SLB faults without
859 * looking at possible non-bolted memory. We could test user vs
860 * kernel faults in the interrupt handler asm and do a full fault,
861 * reconcile, ret_from_except for user faults which would make them
862 * first class kernel code. But for performance it's probably nicer
863 * if they go via fast_exception_return too.
865 if (id >= LINEAR_MAP_REGION_ID) {
867 #ifdef CONFIG_DEBUG_VM
868 /* Catch recursive kernel SLB faults. */
869 BUG_ON(local_paca->in_kernel_slb_handler);
870 local_paca->in_kernel_slb_handler = 1;
872 err = slb_allocate_kernel(ea, id);
873 #ifdef CONFIG_DEBUG_VM
874 local_paca->in_kernel_slb_handler = 0;
878 struct mm_struct *mm = current->mm;
884 err = slb_allocate_user(mm, ea);
886 preload_add(current_thread_info(), ea);
892 void do_bad_slb_fault(struct pt_regs *regs, unsigned long ea, long err)
894 if (err == -EFAULT) {
896 _exception(SIGSEGV, regs, SEGV_BNDERR, ea);
898 bad_page_fault(regs, ea, SIGSEGV);
899 } else if (err == -EINVAL) {
900 unrecoverable_exception(regs);