Fix for page faults under KVM
Under KVM we were hitting what look like out-of-order and/or issues during initialization when writing to the page tables and then immediately writing to the mapped memory. Adding a memory barrier and an io_wait() in memory_bootstrap.cpp fixed it.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
#include "kutil/assert.h"
|
#include "kutil/assert.h"
|
||||||
#include "kutil/linked_list.h"
|
#include "kutil/linked_list.h"
|
||||||
#include "kutil/slab_allocator.h"
|
#include "kutil/slab_allocator.h"
|
||||||
#include "memory.h"
|
#include "io.h"
|
||||||
#include "page_manager.h"
|
#include "page_manager.h"
|
||||||
|
|
||||||
const unsigned efi_page_size = 0x1000;
|
const unsigned efi_page_size = 0x1000;
|
||||||
@@ -402,7 +402,7 @@ memory_initialize(const void *memory_map, size_t map_length, size_t desc_length)
|
|||||||
uint64_t free_next = free_region_start_virt;
|
uint64_t free_next = free_region_start_virt;
|
||||||
|
|
||||||
// We'll need to copy any existing tables (except the PML4 which the
|
// We'll need to copy any existing tables (except the PML4 which the
|
||||||
// bootloader gave us) into our 4 reserved pages so we can edit them.
|
// bootloader gave us) into our reserved pages so we can edit them.
|
||||||
page_table_indices fr_idx{free_region_start_virt};
|
page_table_indices fr_idx{free_region_start_virt};
|
||||||
|
|
||||||
copy_new_table(&tables[0], fr_idx[0], &tables[1]);
|
copy_new_table(&tables[0], fr_idx[0], &tables[1]);
|
||||||
@@ -473,6 +473,10 @@ memory_initialize(const void *memory_map, size_t map_length, size_t desc_length)
|
|||||||
|
|
||||||
page_in_ident(&tables[0], pt_start_phys, pt_start_virt, remaining_pages, tables + 4);
|
page_in_ident(&tables[0], pt_start_phys, pt_start_virt, remaining_pages, tables + 4);
|
||||||
|
|
||||||
|
// Make sure the page table is finished updating before we write to memory
|
||||||
|
__sync_synchronize();
|
||||||
|
io_wait();
|
||||||
|
|
||||||
// Finally, build an acutal set of kernel page tables that just contains
|
// Finally, build an acutal set of kernel page tables that just contains
|
||||||
// what the kernel actually has mapped, but making everything writable
|
// what the kernel actually has mapped, but making everything writable
|
||||||
// (especially the page tables themselves)
|
// (especially the page tables themselves)
|
||||||
|
|||||||
Reference in New Issue
Block a user