Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


*/
goto bad_area_nosemaphore;
}
...

Avmallocfault is indicated if the address is outside useraddress space. The page tables of the process
must therefore be synchronized with the information in the kernel’s master page table. Naturally, this is
only permitted if access took place in kernel mode and the fault was not triggered by a protection error;
in other words, neither bit 2 nor bits 3 and 0 of the error code may be set.^19


The kernel uses the auxiliary functionvmalloc_faultto synchronize the page tables. I won’t show the
code in detail because all it does is copy the relevant entry from the page table ofinit—thisisthe
kernel master table on IA-32 systems — into the current page table. If no matching entry is found there,
the kernel invokesfixup_exceptionin a final attempt to recover the fault; I discuss this shortly.


The kernel jumps to thebad_area_nosemaphorelabel if the fault was triggered during an interrupt (see
Chapter 14) or in a kernel thread (see Chapter 14) that does not have its own context and therefore no
separate instance ofmm_struct.


arch/i386/mm/fault.c
mm = tsk->mm;

/*
* If we’re in an interrupt, have no user context or are running in an
* atomic region then we must not take the fault..
*/
if (in_atomic() || !mm)
goto bad_area_nosemaphore;
...
bad_area_nosemaphore:
/* User mode accesses just cause a SIGSEGV */
if (error_code & 4) {
...
force_sig_info_fault(SIGSEGV, si_code, address, tsk);
return;
}

no_context:
/* Are we prepared to handle this kernel fault? */
if (fixup_exception(regs))
return;

A segmentation fault is output if the fault originates from userspace (indicated by the fact that bit 4 is
set inerror_code).If,however,thefaultoriginatesfromkernelspace,fixup_exceptionis invoked. I
describe this function below.


If the fault does not occur in an interrupt or without a context, the kernel checks whether the address
space of the process contains a region in which the fault address lies. It invokes thefind_vmafunction,
which we know from Section 4.5.1 to do this.


(^19) This is checked by!(error_code & 0x0000000d).Because 20 + 22 + 23 = 13 =0xd, neither bit 2norbits 3 and 0 may be set.

Free download pdf