Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/amd64/pmap.c
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 437 Lines • ▼ Show 20 Lines | |||||
SYSCTL_INT(_vm_pmap, OID_AUTO, pti, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, | SYSCTL_INT(_vm_pmap, OID_AUTO, pti, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, | ||||
&pti, 0, | &pti, 0, | ||||
"Page Table Isolation enabled"); | "Page Table Isolation enabled"); | ||||
static vm_object_t pti_obj; | static vm_object_t pti_obj; | ||||
static pml4_entry_t *pti_pml4; | static pml4_entry_t *pti_pml4; | ||||
static vm_pindex_t pti_pg_idx; | static vm_pindex_t pti_pg_idx; | ||||
static bool pti_finalized; | static bool pti_finalized; | ||||
extern struct pcpu *__pcpu; | |||||
extern struct pcpu temp_bsp_pcpu; | |||||
extern pt_entry_t *pcpu_pte; | |||||
struct pmap_pkru_range { | struct pmap_pkru_range { | ||||
struct rs_el pkru_rs_el; | struct rs_el pkru_rs_el; | ||||
u_int pkru_keyidx; | u_int pkru_keyidx; | ||||
int pkru_flags; | int pkru_flags; | ||||
}; | }; | ||||
static uma_zone_t pmap_pkru_ranges_zone; | static uma_zone_t pmap_pkru_ranges_zone; | ||||
static bool pmap_pkru_same(pmap_t pmap, vm_offset_t sva, vm_offset_t eva); | static bool pmap_pkru_same(pmap_t pmap, vm_offset_t sva, vm_offset_t eva); | ||||
▲ Show 20 Lines • Show All 1,149 Lines • ▼ Show 20 Lines | |||||
* mapped with PA == VA, hence we would have to relocate every address | * mapped with PA == VA, hence we would have to relocate every address | ||||
* from the linked base (virtual) address "KERNBASE" to the actual | * from the linked base (virtual) address "KERNBASE" to the actual | ||||
* (physical) address starting relative to 0] | * (physical) address starting relative to 0] | ||||
*/ | */ | ||||
void | void | ||||
pmap_bootstrap(vm_paddr_t *firstaddr) | pmap_bootstrap(vm_paddr_t *firstaddr) | ||||
{ | { | ||||
vm_offset_t va; | vm_offset_t va; | ||||
pt_entry_t *pte; | pt_entry_t *pte, *pcpu_pte; | ||||
uint64_t cr4; | uint64_t cr4, pcpu_phys; | ||||
u_long res; | u_long res; | ||||
int i; | int i; | ||||
KERNend = *firstaddr; | KERNend = *firstaddr; | ||||
res = atop(KERNend - (vm_paddr_t)kernphys); | res = atop(KERNend - (vm_paddr_t)kernphys); | ||||
if (!pti) | if (!pti) | ||||
pg_g = X86_PG_G; | pg_g = X86_PG_G; | ||||
/* | /* | ||||
* Create an initial set of page tables to run the kernel in. | * Create an initial set of page tables to run the kernel in. | ||||
*/ | */ | ||||
create_pagetables(firstaddr); | create_pagetables(firstaddr); | ||||
pcpu_phys = allocpages(firstaddr, MAXCPU); | |||||
/* | /* | ||||
* Add a physical memory segment (vm_phys_seg) corresponding to the | * Add a physical memory segment (vm_phys_seg) corresponding to the | ||||
* preallocated kernel page table pages so that vm_page structures | * preallocated kernel page table pages so that vm_page structures | ||||
* representing these pages will be created. The vm_page structures | * representing these pages will be created. The vm_page structures | ||||
* are required for promotion of the corresponding kernel virtual | * are required for promotion of the corresponding kernel virtual | ||||
* addresses to superpage mappings. | * addresses to superpage mappings. | ||||
*/ | */ | ||||
vm_phys_add_seg(KPTphys, KPTphys + ptoa(nkpt)); | vm_phys_add_seg(KPTphys, KPTphys + ptoa(nkpt)); | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | #define SYSMAP(c, p, v, n) \ | ||||
/* | /* | ||||
* Crashdump maps. The first page is reused as CMAP1 for the | * Crashdump maps. The first page is reused as CMAP1 for the | ||||
* memory test. | * memory test. | ||||
*/ | */ | ||||
SYSMAP(caddr_t, CMAP1, crashdumpmap, MAXDUMPPGS) | SYSMAP(caddr_t, CMAP1, crashdumpmap, MAXDUMPPGS) | ||||
CADDR1 = crashdumpmap; | CADDR1 = crashdumpmap; | ||||
SYSMAP(struct pcpu *, pcpu_pte, __pcpu, MAXCPU); | |||||
virtual_avail = va; | virtual_avail = va; | ||||
for (i = 0; i < MAXCPU; i++) { | |||||
pcpu_pte[i] = (pcpu_phys + ptoa(i)) | X86_PG_V | X86_PG_RW | | |||||
pg_g | pg_nx | X86_PG_M | X86_PG_A; | |||||
markj: pg_nx? | |||||
} | |||||
STAILQ_INIT(&cpuhead); | |||||
wrmsr(MSR_GSBASE, (uint64_t)&__pcpu[0]); | |||||
pcpu_init(&__pcpu[0], 0, sizeof(struct pcpu)); | |||||
amd64_bsp_pcpu_init1(&__pcpu[0]); | |||||
amd64_bsp_ist_init(&__pcpu[0]); | |||||
Done Inline ActionsWhy don't we need to call amd64_bsp_pcpu_init2() here? I would wrap this in a amd64_bsp_pcpu_reinit() function, defined in machdep.c. markj: Why don't we need to call amd64_bsp_pcpu_init2() here?
I would wrap this in a… | |||||
Done Inline ActionsThis is pmap_bootstrap(), called from getmemsize(). There is no point in calling amd64_bp_pcpu_init2() this early. More, I suspect that some values to put into pcpu are not yet ready. That was the reason for doing init1/init2. init2 is called much later in hammer_time(). kib: This is pmap_bootstrap(), called from getmemsize(). There is no point in calling… | |||||
__pcpu[0].pc_dynamic = temp_bsp_pcpu.pc_dynamic; | |||||
__pcpu[0].pc_acpi_id = temp_bsp_pcpu.pc_acpi_id; | |||||
Done Inline ActionsExtra newline. markj: Extra newline. | |||||
/* | /* | ||||
* Initialize the PAT MSR. | * Initialize the PAT MSR. | ||||
* pmap_init_pat() clears and sets CR4_PGE, which, as a | * pmap_init_pat() clears and sets CR4_PGE, which, as a | ||||
* side-effect, invalidates stale PG_G TLB entries that might | * side-effect, invalidates stale PG_G TLB entries that might | ||||
* have been created in our pre-boot environment. | * have been created in our pre-boot environment. | ||||
*/ | */ | ||||
pmap_init_pat(); | pmap_init_pat(); | ||||
▲ Show 20 Lines • Show All 8,323 Lines • Show Last 20 Lines |
pg_nx?