2 * Copyright (C) 1995 Linus Torvalds
3 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs.
6 #include <linux/signal.h>
7 #include <linux/sched.h>
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/string.h>
11 #include <linux/types.h>
12 #include <linux/ptrace.h>
13 #include <linux/mman.h>
15 #include <linux/smp.h>
16 #include <linux/interrupt.h>
17 #include <linux/init.h>
18 #include <linux/tty.h>
19 #include <linux/vt_kern.h> /* For unblank_screen() */
20 #include <linux/compiler.h>
21 #include <linux/highmem.h>
22 #include <linux/bootmem.h> /* for max_low_pfn */
23 #include <linux/vmalloc.h>
24 #include <linux/module.h>
25 #include <linux/kprobes.h>
26 #include <linux/uaccess.h>
27 #include <linux/kdebug.h>
29 #include <asm/system.h>
31 #include <asm/segment.h>
32 #include <asm/pgalloc.h>
34 #include <asm/tlbflush.h>
35 #include <asm/proto.h>
36 #include <asm-generic/sections.h>
39 * Page fault error code bits
40 * bit 0 == 0 means no page found, 1 means protection fault
41 * bit 1 == 0 means read, 1 means write
42 * bit 2 == 0 means kernel, 1 means user-mode
43 * bit 3 == 1 means use of reserved bit detected
44 * bit 4 == 1 means fault was an instruction fetch
46 #define PF_PROT (1<<0)
47 #define PF_WRITE (1<<1)
48 #define PF_USER (1<<2)
49 #define PF_RSVD (1<<3)
50 #define PF_INSTR (1<<4)
52 #ifdef CONFIG_PAGE_FAULT_HANDLERS
53 static HLIST_HEAD(pf_handlers); /* protected by RCU */
54 static DEFINE_SPINLOCK(pf_handlers_writer);
56 void register_page_fault_handler(struct pf_handler *new_pfh)
59 spin_lock_irqsave(&pf_handlers_writer, flags);
60 hlist_add_head_rcu(&new_pfh->hlist, &pf_handlers);
61 spin_unlock_irqrestore(&pf_handlers_writer, flags);
63 EXPORT_SYMBOL_GPL(register_page_fault_handler);
66 * unregister_page_fault_handler:
67 * The caller must ensure @old_pfh is not in use anymore before freeing it.
68 * This function does not guarantee it. The list of handlers is protected by
69 * RCU, so you can do this by e.g. calling synchronize_rcu().
71 void unregister_page_fault_handler(struct pf_handler *old_pfh)
74 spin_lock_irqsave(&pf_handlers_writer, flags);
75 hlist_del_rcu(&old_pfh->hlist);
76 spin_unlock_irqrestore(&pf_handlers_writer, flags);
78 EXPORT_SYMBOL_GPL(unregister_page_fault_handler);
81 /* returns non-zero if do_page_fault() should return */
82 static int handle_custom_pf(struct pt_regs *regs, unsigned long error_code,
83 unsigned long address)
85 #ifdef CONFIG_PAGE_FAULT_HANDLERS
87 struct pf_handler *cur;
88 struct hlist_node *ncur;
90 if (hlist_empty(&pf_handlers))
94 hlist_for_each_entry_rcu(cur, ncur, &pf_handlers, hlist) {
95 ret = cur->handler(regs, error_code, address);
106 static inline int notify_page_fault(struct pt_regs *regs)
108 #ifdef CONFIG_KPROBES
111 /* kprobe_running() needs smp_processor_id() */
113 if (!user_mode_vm(regs)) {
115 if (!user_mode(regs)) {
118 if (kprobe_running() && kprobe_fault_handler(regs, 14))
131 * Sometimes AMD Athlon/Opteron CPUs report invalid exceptions on prefetch.
132 * Check that here and ignore it.
135 * Sometimes the CPU reports invalid exceptions on prefetch.
136 * Check that here and ignore it.
138 * Opcode checker based on code by Richard Brunner
140 static int is_prefetch(struct pt_regs *regs, unsigned long addr,
141 unsigned long error_code)
143 unsigned char *instr;
146 unsigned char *max_instr;
149 * If it was a exec (instruction fetch) fault on NX page, then
150 * do not ignore the fault:
152 if (error_code & PF_INSTR)
155 instr = (unsigned char *)convert_ip_to_linear(current, regs);
156 max_instr = instr + 15;
158 if (user_mode(regs) && instr >= (unsigned char *)TASK_SIZE)
161 while (scan_more && instr < max_instr) {
162 unsigned char opcode;
163 unsigned char instr_hi;
164 unsigned char instr_lo;
166 if (probe_kernel_address(instr, opcode))
169 instr_hi = opcode & 0xf0;
170 instr_lo = opcode & 0x0f;
177 * Values 0x26,0x2E,0x36,0x3E are valid x86 prefixes.
178 * In X86_64 long mode, the CPU will signal invalid
179 * opcode if some of these prefixes are present so
180 * X86_64 will never get here anyway
182 scan_more = ((instr_lo & 7) == 0x6);
187 * In AMD64 long mode 0x40..0x4F are valid REX prefixes
188 * Need to figure out under what instruction mode the
189 * instruction was issued. Could check the LDT for lm,
190 * but for now it's good enough to assume that long
191 * mode only uses well known segments or kernel.
193 scan_more = (!user_mode(regs)) || (regs->cs == __USER_CS);
197 /* 0x64 thru 0x67 are valid prefixes in all modes. */
198 scan_more = (instr_lo & 0xC) == 0x4;
201 /* 0xF0, 0xF2, 0xF3 are valid prefixes in all modes. */
202 scan_more = !instr_lo || (instr_lo>>1) == 1;
205 /* Prefetch instruction is 0x0F0D or 0x0F18 */
208 if (probe_kernel_address(instr, opcode))
210 prefetch = (instr_lo == 0xF) &&
211 (opcode == 0x0D || opcode == 0x18);
221 static void force_sig_info_fault(int si_signo, int si_code,
222 unsigned long address, struct task_struct *tsk)
226 info.si_signo = si_signo;
228 info.si_code = si_code;
229 info.si_addr = (void __user *)address;
230 force_sig_info(si_signo, &info, tsk);
234 static int bad_address(void *p)
237 return probe_kernel_address((unsigned long *)p, dummy);
241 static void dump_pagetable(unsigned long address)
244 __typeof__(pte_val(__pte(0))) page;
247 page = ((__typeof__(page) *) __va(page))[address >> PGDIR_SHIFT];
248 #ifdef CONFIG_X86_PAE
249 printk("*pdpt = %016Lx ", page);
250 if ((page >> PAGE_SHIFT) < max_low_pfn
251 && page & _PAGE_PRESENT) {
253 page = ((__typeof__(page) *) __va(page))[(address >> PMD_SHIFT)
254 & (PTRS_PER_PMD - 1)];
255 printk(KERN_CONT "*pde = %016Lx ", page);
259 printk("*pde = %08lx ", page);
263 * We must not directly access the pte in the highpte
264 * case if the page table is located in highmem.
265 * And let's rather not kmap-atomic the pte, just in case
266 * it's allocated already.
268 if ((page >> PAGE_SHIFT) < max_low_pfn
269 && (page & _PAGE_PRESENT)
270 && !(page & _PAGE_PSE)) {
272 page = ((__typeof__(page) *) __va(page))[(address >> PAGE_SHIFT)
273 & (PTRS_PER_PTE - 1)];
274 printk("*pte = %0*Lx ", sizeof(page)*2, (u64)page);
278 #else /* CONFIG_X86_64 */
284 pgd = (pgd_t *)read_cr3();
286 pgd = __va((unsigned long)pgd & PHYSICAL_PAGE_MASK);
287 pgd += pgd_index(address);
288 if (bad_address(pgd)) goto bad;
289 printk("PGD %lx ", pgd_val(*pgd));
290 if (!pgd_present(*pgd)) goto ret;
292 pud = pud_offset(pgd, address);
293 if (bad_address(pud)) goto bad;
294 printk("PUD %lx ", pud_val(*pud));
295 if (!pud_present(*pud) || pud_large(*pud))
298 pmd = pmd_offset(pud, address);
299 if (bad_address(pmd)) goto bad;
300 printk("PMD %lx ", pmd_val(*pmd));
301 if (!pmd_present(*pmd) || pmd_large(*pmd)) goto ret;
303 pte = pte_offset_kernel(pmd, address);
304 if (bad_address(pte)) goto bad;
305 printk("PTE %lx", pte_val(*pte));
315 static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
317 unsigned index = pgd_index(address);
323 pgd_k = init_mm.pgd + index;
325 if (!pgd_present(*pgd_k))
329 * set_pgd(pgd, *pgd_k); here would be useless on PAE
330 * and redundant with the set_pmd() on non-PAE. As would
334 pud = pud_offset(pgd, address);
335 pud_k = pud_offset(pgd_k, address);
336 if (!pud_present(*pud_k))
339 pmd = pmd_offset(pud, address);
340 pmd_k = pmd_offset(pud_k, address);
341 if (!pmd_present(*pmd_k))
343 if (!pmd_present(*pmd)) {
344 set_pmd(pmd, *pmd_k);
345 arch_flush_lazy_mmu_mode();
347 BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k));
353 static const char errata93_warning[] =
354 KERN_ERR "******* Your BIOS seems to not contain a fix for K8 errata #93\n"
355 KERN_ERR "******* Working around it, but it may cause SEGVs or burn power.\n"
356 KERN_ERR "******* Please consider a BIOS update.\n"
357 KERN_ERR "******* Disabling USB legacy in the BIOS may also help.\n";
360 /* Workaround for K8 erratum #93 & buggy BIOS.
361 BIOS SMM functions are required to use a specific workaround
362 to avoid corruption of the 64bit RIP register on C stepping K8.
363 A lot of BIOS that didn't get tested properly miss this.
364 The OS sees this as a page fault with the upper 32bits of RIP cleared.
365 Try to work around it here.
366 Note we only handle faults in kernel here.
367 Does nothing for X86_32
369 static int is_errata93(struct pt_regs *regs, unsigned long address)
373 if (address != regs->ip)
375 if ((address >> 32) != 0)
377 address |= 0xffffffffUL << 32;
378 if ((address >= (u64)_stext && address <= (u64)_etext) ||
379 (address >= MODULES_VADDR && address <= MODULES_END)) {
381 printk(errata93_warning);
392 * Work around K8 erratum #100 K8 in compat mode occasionally jumps to illegal
393 * addresses >4GB. We catch this in the page fault handler because these
394 * addresses are not reachable. Just detect this case and return. Any code
395 * segment in LDT is compatibility mode.
397 static int is_errata100(struct pt_regs *regs, unsigned long address)
400 if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) &&
407 void do_invalid_op(struct pt_regs *, unsigned long);
409 static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
411 #ifdef CONFIG_X86_F00F_BUG
414 * Pentium F0 0F C7 C8 bug workaround.
416 if (boot_cpu_data.f00f_bug) {
417 nr = (address - idt_descr.address) >> 3;
420 do_invalid_op(regs, 0);
428 static void show_fault_oops(struct pt_regs *regs, unsigned long error_code,
429 unsigned long address)
432 if (!oops_may_print())
436 #ifdef CONFIG_X86_PAE
437 if (error_code & PF_INSTR) {
439 pte_t *pte = lookup_address(address, &level);
441 if (pte && pte_present(*pte) && !pte_exec(*pte))
442 printk(KERN_CRIT "kernel tried to execute "
443 "NX-protected page - exploit attempt? "
444 "(uid: %d)\n", current->uid);
448 printk(KERN_ALERT "BUG: unable to handle kernel ");
449 if (address < PAGE_SIZE)
450 printk(KERN_CONT "NULL pointer dereference");
452 printk(KERN_CONT "paging request");
454 printk(KERN_CONT " at %08lx\n", address);
456 printk(KERN_CONT " at %016lx\n", address);
458 printk(KERN_ALERT "IP:");
459 printk_address(regs->ip, 1);
460 dump_pagetable(address);
464 static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs,
465 unsigned long error_code)
467 unsigned long flags = oops_begin();
468 struct task_struct *tsk;
470 printk(KERN_ALERT "%s: Corrupted page table at address %lx\n",
471 current->comm, address);
472 dump_pagetable(address);
474 tsk->thread.cr2 = address;
475 tsk->thread.trap_no = 14;
476 tsk->thread.error_code = error_code;
477 if (__die("Bad pagetable", regs, error_code))
479 oops_end(flags, regs, SIGKILL);
483 static int spurious_fault_check(unsigned long error_code, pte_t *pte)
485 if ((error_code & PF_WRITE) && !pte_write(*pte))
487 if ((error_code & PF_INSTR) && !pte_exec(*pte))
494 * Handle a spurious fault caused by a stale TLB entry. This allows
495 * us to lazily refresh the TLB when increasing the permissions of a
496 * kernel page (RO -> RW or NX -> X). Doing it eagerly is very
497 * expensive since that implies doing a full cross-processor TLB
498 * flush, even if no stale TLB entries exist on other processors.
499 * There are no security implications to leaving a stale TLB when
500 * increasing the permissions on a page.
502 static int spurious_fault(unsigned long address,
503 unsigned long error_code)
510 /* Reserved-bit violation or user access to kernel space? */
511 if (error_code & (PF_USER | PF_RSVD))
514 pgd = init_mm.pgd + pgd_index(address);
515 if (!pgd_present(*pgd))
518 pud = pud_offset(pgd, address);
519 if (!pud_present(*pud))
523 return spurious_fault_check(error_code, (pte_t *) pud);
525 pmd = pmd_offset(pud, address);
526 if (!pmd_present(*pmd))
530 return spurious_fault_check(error_code, (pte_t *) pmd);
532 pte = pte_offset_kernel(pmd, address);
533 if (!pte_present(*pte))
536 return spurious_fault_check(error_code, pte);
541 * Handle a fault on the vmalloc or module mapping area
544 * Handle a fault on the vmalloc area
546 * This assumes no large pages in there.
548 static int vmalloc_fault(unsigned long address)
551 unsigned long pgd_paddr;
555 /* Make sure we are in vmalloc area */
556 if (!(address >= VMALLOC_START && address < VMALLOC_END))
560 * Synchronize this task's top level page-table
561 * with the 'reference' page table.
563 * Do _not_ use "current" here. We might be inside
564 * an interrupt in the middle of a task switch..
566 pgd_paddr = read_cr3();
567 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
570 pte_k = pte_offset_kernel(pmd_k, address);
571 if (!pte_present(*pte_k))
575 pgd_t *pgd, *pgd_ref;
576 pud_t *pud, *pud_ref;
577 pmd_t *pmd, *pmd_ref;
578 pte_t *pte, *pte_ref;
580 /* Make sure we are in vmalloc area */
581 if (!(address >= VMALLOC_START && address < VMALLOC_END))
584 /* Copy kernel mappings over when needed. This can also
585 happen within a race in page table update. In the later
588 pgd = pgd_offset(current->mm ?: &init_mm, address);
589 pgd_ref = pgd_offset_k(address);
590 if (pgd_none(*pgd_ref))
593 set_pgd(pgd, *pgd_ref);
595 BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
597 /* Below here mismatches are bugs because these lower tables
600 pud = pud_offset(pgd, address);
601 pud_ref = pud_offset(pgd_ref, address);
602 if (pud_none(*pud_ref))
604 if (pud_none(*pud) || pud_page_vaddr(*pud) != pud_page_vaddr(*pud_ref))
606 pmd = pmd_offset(pud, address);
607 pmd_ref = pmd_offset(pud_ref, address);
608 if (pmd_none(*pmd_ref))
610 if (pmd_none(*pmd) || pmd_page(*pmd) != pmd_page(*pmd_ref))
612 pte_ref = pte_offset_kernel(pmd_ref, address);
613 if (!pte_present(*pte_ref))
615 pte = pte_offset_kernel(pmd, address);
616 /* Don't use pte_page here, because the mappings can point
617 outside mem_map, and the NUMA hash lookup cannot handle
619 if (!pte_present(*pte) || pte_pfn(*pte) != pte_pfn(*pte_ref))
625 int show_unhandled_signals = 1;
628 * This routine handles page faults. It determines the address,
629 * and the problem, and then passes it off to one of the appropriate
635 void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
637 struct task_struct *tsk;
638 struct mm_struct *mm;
639 struct vm_area_struct *vma;
640 unsigned long address;
648 * We can fault from pretty much anywhere, with unknown IRQ state.
650 trace_hardirqs_fixup();
654 prefetchw(&mm->mmap_sem);
656 /* get the address */
657 address = read_cr2();
659 si_code = SEGV_MAPERR;
661 if (notify_page_fault(regs))
663 if (handle_custom_pf(regs, error_code, address))
667 * We fault-in kernel-space virtual memory on-demand. The
668 * 'reference' page table is init_mm.pgd.
670 * NOTE! We MUST NOT take any locks for this case. We may
671 * be in an interrupt or a critical region, and should
672 * only copy the information from the master page table,
675 * This verifies that the fault happens in kernel space
676 * (error_code & 4) == 0, and that the fault was not a
677 * protection error (error_code & 9) == 0.
680 if (unlikely(address >= TASK_SIZE)) {
682 if (unlikely(address >= TASK_SIZE64)) {
684 if (!(error_code & (PF_RSVD|PF_USER|PF_PROT)) &&
685 vmalloc_fault(address) >= 0)
688 /* Can handle a stale RO->RW TLB */
689 if (spurious_fault(address, error_code))
693 * Don't take the mm semaphore here. If we fixup a prefetch
694 * fault we could otherwise deadlock.
696 goto bad_area_nosemaphore;
701 /* It's safe to allow irq's after cr2 has been saved and the vmalloc
702 fault has been handled. */
703 if (regs->flags & (X86_EFLAGS_IF | X86_VM_MASK))
707 * If we're in an interrupt, have no user context or are running in an
708 * atomic region then we must not take the fault.
710 if (in_atomic() || !mm)
711 goto bad_area_nosemaphore;
712 #else /* CONFIG_X86_64 */
713 if (likely(regs->flags & X86_EFLAGS_IF))
716 if (unlikely(error_code & PF_RSVD))
717 pgtable_bad(address, regs, error_code);
720 * If we're in an interrupt, have no user context or are running in an
721 * atomic region then we must not take the fault.
723 if (unlikely(in_atomic() || !mm))
724 goto bad_area_nosemaphore;
727 * User-mode registers count as a user access even for any
728 * potential system fault or CPU buglet.
730 if (user_mode_vm(regs))
731 error_code |= PF_USER;
734 /* When running in the kernel we expect faults to occur only to
735 * addresses in user space. All other faults represent errors in the
736 * kernel and should generate an OOPS. Unfortunately, in the case of an
737 * erroneous fault occurring in a code path which already holds mmap_sem
738 * we will deadlock attempting to validate the fault against the
739 * address space. Luckily the kernel only validly references user
740 * space from well defined areas of code, which are listed in the
743 * As the vast majority of faults will be valid we will only perform
744 * the source reference check when there is a possibility of a deadlock.
745 * Attempt to lock the address space, if we cannot we then validate the
746 * source. If this is invalid we can skip the address space check,
747 * thus avoiding the deadlock.
749 if (!down_read_trylock(&mm->mmap_sem)) {
750 if ((error_code & PF_USER) == 0 &&
751 !search_exception_tables(regs->ip))
752 goto bad_area_nosemaphore;
753 down_read(&mm->mmap_sem);
756 vma = find_vma(mm, address);
759 if (vma->vm_start <= address)
761 if (!(vma->vm_flags & VM_GROWSDOWN))
763 if (error_code & PF_USER) {
765 * Accessing the stack below %sp is always a bug.
766 * The large cushion allows instructions like enter
767 * and pusha to work. ("enter $65535,$31" pushes
768 * 32 pointers and then decrements %sp by 65535.)
770 if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
773 if (expand_stack(vma, address))
776 * Ok, we have a good vm_area for this memory access, so
780 si_code = SEGV_ACCERR;
782 switch (error_code & (PF_PROT|PF_WRITE)) {
783 default: /* 3: write, present */
785 case PF_WRITE: /* write, not present */
786 if (!(vma->vm_flags & VM_WRITE))
790 case PF_PROT: /* read, present */
792 case 0: /* read, not present */
793 if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
801 * If for any reason at all we couldn't handle the fault,
802 * make sure we exit gracefully rather than endlessly redo
805 fault = handle_mm_fault(mm, vma, address, write);
806 if (unlikely(fault & VM_FAULT_ERROR)) {
807 if (fault & VM_FAULT_OOM)
809 else if (fault & VM_FAULT_SIGBUS)
813 if (fault & VM_FAULT_MAJOR)
820 * Did it hit the DOS screen memory VA from vm86 mode?
822 if (v8086_mode(regs)) {
823 unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT;
825 tsk->thread.screen_bitmap |= 1 << bit;
828 up_read(&mm->mmap_sem);
832 * Something tried to access memory that isn't in our memory map..
833 * Fix it, but check if it's kernel or user first..
836 up_read(&mm->mmap_sem);
838 bad_area_nosemaphore:
839 /* User mode accesses just cause a SIGSEGV */
840 if (error_code & PF_USER) {
842 * It's possible to have interrupts off here.
847 * Valid to do another page fault here because this one came
850 if (is_prefetch(regs, address, error_code))
853 if (is_errata100(regs, address))
856 if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
857 printk_ratelimit()) {
860 "%s%s[%d]: segfault at %lx ip %08lx sp %08lx error %lx",
862 "%s%s[%d]: segfault at %lx ip %lx sp %lx error %lx",
864 task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
865 tsk->comm, task_pid_nr(tsk), address, regs->ip,
866 regs->sp, error_code);
867 print_vma_addr(" in ", regs->ip);
871 tsk->thread.cr2 = address;
872 /* Kernel addresses are always protection faults */
873 tsk->thread.error_code = error_code | (address >= TASK_SIZE);
874 tsk->thread.trap_no = 14;
875 force_sig_info_fault(SIGSEGV, si_code, address, tsk);
879 if (is_f00f_bug(regs, address))
883 /* Are we prepared to handle this kernel fault? */
884 if (fixup_exception(regs))
889 * Valid to do another page fault here, because if this fault
890 * had been triggered by is_prefetch fixup_exception would have
894 * Hall of shame of CPU/BIOS bugs.
896 if (is_prefetch(regs, address, error_code))
899 if (is_errata93(regs, address))
903 * Oops. The kernel tried to access some bad page. We'll have to
904 * terminate things with extreme prejudice.
909 flags = oops_begin();
912 show_fault_oops(regs, error_code, address);
914 tsk->thread.cr2 = address;
915 tsk->thread.trap_no = 14;
916 tsk->thread.error_code = error_code;
919 die("Oops", regs, error_code);
923 if (__die("Oops", regs, error_code))
925 /* Executive summary in case the body of the oops scrolled away */
926 printk(KERN_EMERG "CR2: %016lx\n", address);
927 oops_end(flags, regs, SIGKILL);
931 * We ran out of memory, or some other thing happened to us that made
932 * us unable to handle the page fault gracefully.
935 up_read(&mm->mmap_sem);
936 if (is_global_init(tsk)) {
939 down_read(&mm->mmap_sem);
946 printk("VM: killing process %s\n", tsk->comm);
947 if (error_code & PF_USER)
948 do_group_exit(SIGKILL);
952 up_read(&mm->mmap_sem);
954 /* Kernel mode? Handle exceptions or die */
955 if (!(error_code & PF_USER))
958 /* User space => ok to do another page fault */
959 if (is_prefetch(regs, address, error_code))
962 tsk->thread.cr2 = address;
963 tsk->thread.error_code = error_code;
964 tsk->thread.trap_no = 14;
965 force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk);
968 DEFINE_SPINLOCK(pgd_lock);
971 void vmalloc_sync_all(void)
975 * Note that races in the updates of insync and start aren't
976 * problematic: insync can only get set bits added, and updates to
977 * start are only improving performance (without affecting correctness
980 static DECLARE_BITMAP(insync, PTRS_PER_PGD);
981 static unsigned long start = TASK_SIZE;
982 unsigned long address;
984 if (SHARED_KERNEL_PMD)
987 BUILD_BUG_ON(TASK_SIZE & ~PGDIR_MASK);
988 for (address = start; address >= TASK_SIZE; address += PGDIR_SIZE) {
989 if (!test_bit(pgd_index(address), insync)) {
993 spin_lock_irqsave(&pgd_lock, flags);
994 list_for_each_entry(page, &pgd_list, lru) {
995 if (!vmalloc_sync_one(page_address(page),
999 spin_unlock_irqrestore(&pgd_lock, flags);
1001 set_bit(pgd_index(address), insync);
1003 if (address == start && test_bit(pgd_index(address), insync))
1004 start = address + PGDIR_SIZE;
1006 #else /* CONFIG_X86_64 */
1008 * Note that races in the updates of insync and start aren't
1009 * problematic: insync can only get set bits added, and updates to
1010 * start are only improving performance (without affecting correctness
1013 static DECLARE_BITMAP(insync, PTRS_PER_PGD);
1014 static unsigned long start = VMALLOC_START & PGDIR_MASK;
1015 unsigned long address;
1017 for (address = start; address <= VMALLOC_END; address += PGDIR_SIZE) {
1018 if (!test_bit(pgd_index(address), insync)) {
1019 const pgd_t *pgd_ref = pgd_offset_k(address);
1020 unsigned long flags;
1023 if (pgd_none(*pgd_ref))
1025 spin_lock_irqsave(&pgd_lock, flags);
1026 list_for_each_entry(page, &pgd_list, lru) {
1028 pgd = (pgd_t *)page_address(page) + pgd_index(address);
1030 set_pgd(pgd, *pgd_ref);
1032 BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
1034 spin_unlock_irqrestore(&pgd_lock, flags);
1035 set_bit(pgd_index(address), insync);
1037 if (address == start)
1038 start = address + PGDIR_SIZE;