From mboxrd@z Thu Jan 1 00:00:00 1970 From: cl@linux.com (Christoph Lameter) Date: Thu, 11 Sep 2014 09:19:52 -0500 (CDT) Subject: Page fault in kernel code In-Reply-To: References: <4E5779AD88B2F040B8A7E83ECF544D1A55B65C@SJCPEX01CL02.citrite.net> <35026.1410353642@turing-police.cc.vt.edu> Message-ID: To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Thu, 11 Sep 2014, Leon Romanovsky wrote: > > Linux kernel memory is not page-able, but memory allocated through vmalloc > > can still cause page fault. How device drivers using vmalloc handle this? > Pages allocated via vmalloc call won't generate page-faults. Kernel faults are used on some platforms in a very limited way but not for swapping in or "paging in from disk". Have a look at linux/arch/x86/mm/fault.c: /* * We fault-in kernel-space virtual memory on-demand. The * 'reference' page table is init_mm.pgd. * * NOTE! We MUST NOT take any locks for this case. We may * be in an interrupt or a critical region, and should * only copy the information from the master page table, * nothing more. * * This verifies that the fault happens in kernel space * (error_code & 4) == 0, and that the fault was not a * protection error (error_code & 9) == 0. */ if (unlikely(fault_in_kernel_space(address))) { if (!(error_code & (PF_RSVD | PF_USER | PF_PROT))) { if (vmalloc_fault(address) >= 0) return; if (kmemcheck_fault(regs, address, error_code)) return; } /* Can handle a stale RO->RW TLB: */ if (spurious_fault(error_code, address)) return; /* kprobes don't want to hook the spurious faults: */ if (kprobes_fault(regs)) return; /* * Don't take the mm semaphore here. If we fixup a prefetch * fault we could otherwise deadlock: */ bad_area_nosemaphore(regs, error_code, address); return; }