Module Name: src Committed By: maxv Date: Fri Jan 5 08:04:21 UTC 2018
Modified Files: src/sys/arch/amd64/amd64: gdt.c machdep.c src/sys/arch/amd64/include: types.h src/sys/arch/x86/include: cpu.h pmap.h src/sys/arch/x86/x86: cpu.c pmap.c Log Message: Add a __HAVE_PCPU_AREA option, enabled by default on native amd64 but not Xen. With this option, the CPU structures that must always be present in the CPU's page tables are moved on L4 slot 384, which means address 0xffffc00000000000. A new pcpu_area structure is defined. It contains shared structures (IDT, LDT), and then an array of pcpu_entry structures, indexed by cpu_index(ci). Theoretically the LDT should be in the array, but this will be done later. During the boot procedure, cpu0 calls pmap_init_pcpu, which creates a page tree that is able to map the pcpu_area structure entirely. cpu0 then immediately maps the shared structures. Later, every CPU goes through cpu_pcpuarea_init, which allocates physical pages and kenters the relevant pcpu_entry to them. Finally, each pointer is replaced to point to pcpuarea. The point of this change is to make sure that the structures that must always be present in the page tables have their own L4 slot. Until now their L4 slot was that of pmap_kernel, and making a distinction between what must be mapped and what does not need to be was complicated. Even in the non-speculative-bug case this change makes some sense: there are several x86 instructions that leak the addresses of the CPU structures, and putting these structures inside pmap_kernel actually offered a way to compute the address of the kernel heap - which would have made ASLR on it plainly useless, had we implemented that. Note that, for now, pcpuarea does not contain rsp0. Unfortunately this change adds many #ifdefs, and makes the code harder to understand. There is also some duplication, but that will be solved later. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/sys/arch/amd64/amd64/gdt.c cvs rdiff -u -r1.283 -r1.284 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.52 -r1.53 src/sys/arch/amd64/include/types.h cvs rdiff -u -r1.86 -r1.87 src/sys/arch/x86/include/cpu.h cvs rdiff -u -r1.72 -r1.73 src/sys/arch/x86/include/pmap.h cvs rdiff -u -r1.141 -r1.142 src/sys/arch/x86/x86/cpu.c cvs rdiff -u -r1.275 -r1.276 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.