diff --git a/arch/x86/apic.c b/arch/x86/apic.c index 8bd9e8f9..17fa946b 100644 --- a/arch/x86/apic.c +++ b/arch/x86/apic.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -160,7 +161,7 @@ void init_apic(unsigned int cpu_id, apic_mode_t mode) { * X2APIC uses MSRs for accesses, so no mapping needed. */ if (apic_mode == APIC_MODE_XAPIC) - vmap_4k(apic_get_base(apic_base), apic_base.base, L1_PROT_NOCACHE); + vmap_kern_4k(apic_get_base(apic_base), apic_base.base, L1_PROT_NOCACHE); spiv.reg = apic_read(APIC_SPIV); spiv.vector = APIC_SPI_VECTOR; diff --git a/arch/x86/boot/multiboot.c b/arch/x86/boot/multiboot.c index 2a727d78..4a7e4426 100644 --- a/arch/x86/boot/multiboot.c +++ b/arch/x86/boot/multiboot.c @@ -29,6 +29,7 @@ #include #include #include +#include #define TAG_ADDR(tag) \ ((multiboot2_tag_t *) ((multiboot2_uint8_t *) (tag) + (((tag)->size + 7) & ~7))) @@ -186,8 +187,8 @@ void map_multiboot_areas(void) { paddr_t mbi_stop = mbi_start + multiboot2_hdr_size; for (mfn_t mfn = paddr_to_mfn(mbi_start); mfn <= paddr_to_mfn(mbi_stop); mfn++) { - vmap_4k(mfn_to_virt(mfn), mfn, L1_PROT_RO); - kmap_4k(mfn, L1_PROT_RO); + vmap_kern_4k(mfn_to_virt(mfn), mfn, L1_PROT_RO); + vmap_kern_4k(mfn_to_virt_kern(mfn), mfn, L1_PROT_RO); } } diff --git a/arch/x86/ioapic.c b/arch/x86/ioapic.c index 85d3cb18..2cff3bbd 100644 --- a/arch/x86/ioapic.c +++ b/arch/x86/ioapic.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #define IOAPIC_SYSTEM_ISA_BUS_NAME "ISA" @@ -217,8 +218,9 @@ ioapic_t *add_ioapic(uint8_t id, uint8_t version, bool enabled, uint64_t base_ad ioapic->base_address = base_address; ioapic->gsi_base = gsi_base; - ioapic->virt_address = vmap_4k(paddr_to_virt(ioapic->base_address), - paddr_to_mfn(ioapic->base_address), L1_PROT_NOCACHE); + ioapic->virt_address = + vmap_kern_4k(paddr_to_virt(ioapic->base_address), + paddr_to_mfn(ioapic->base_address), L1_PROT_NOCACHE); BUG_ON(!ioapic->virt_address); return ioapic; diff --git a/arch/x86/pagetables.c b/arch/x86/pagetables.c index 755b0b82..1fe57971 100644 --- a/arch/x86/pagetables.c +++ b/arch/x86/pagetables.c @@ -308,31 +308,112 @@ static void *_vmap(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned int order, return va; } -void *vmap_kern(void *va, mfn_t mfn, unsigned int order, +static inline void *__vmap_1g(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l4_flags, + unsigned long l3_flags) { + return _vmap(cr3_ptr, va, mfn, PAGE_ORDER_1G, l4_flags, l3_flags | _PAGE_PSE, + PT_NO_FLAGS, PT_NO_FLAGS); +} + +static inline void *__vmap_2m(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l4_flags, + unsigned long l3_flags, unsigned long l2_flags) { + return _vmap(cr3_ptr, va, mfn, PAGE_ORDER_2M, l4_flags, l3_flags, + l2_flags | _PAGE_PSE, PT_NO_FLAGS); +} + +static inline void *__vmap_4k(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l4_flags, + unsigned long l3_flags, unsigned long l2_flags, + unsigned long l1_flags) { + return _vmap(cr3_ptr, va, mfn, PAGE_ORDER_4K, l4_flags, l3_flags, l2_flags, l1_flags); +} + +static inline void *_vmap_1g(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l3_flags, + bool propagate_user) { + unsigned long l4_flags = L4_PROT; + + if (propagate_user) + l4_flags |= l3_flags & _PAGE_USER; + return __vmap_1g(cr3_ptr, va, mfn, l4_flags, l3_flags); +} + +static inline void *_vmap_2m(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l2_flags, + bool propagate_user) { + unsigned long l4_flags = L4_PROT; + unsigned long l3_flags = L3_PROT; + + if (propagate_user) { + unsigned long user_bit = l2_flags & _PAGE_USER; + l4_flags |= user_bit; + l3_flags |= user_bit; + } + return __vmap_2m(cr3_ptr, va, mfn, l4_flags, l3_flags, l2_flags); +} + +static inline void *_vmap_4k(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l1_flags, + bool propagate_user) { + unsigned long l4_flags = L4_PROT; + unsigned long l3_flags = L3_PROT; + unsigned long l2_flags = L2_PROT; + + if (propagate_user) { + unsigned long user_bit = l1_flags & _PAGE_USER; + l4_flags |= user_bit; + l3_flags |= user_bit; + l2_flags |= user_bit; + } + + return __vmap_4k(cr3_ptr, va, mfn, l4_flags, l3_flags, l2_flags, l1_flags); +} + +void *vmap(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned int order, #if defined(__x86_64__) - unsigned long l4_flags, + unsigned long l4_flags, #endif - unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags) { - unsigned long _va = _ul(va) & PAGE_ORDER_TO_MASK(order); - + unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags) { dprintk("%s: va: 0x%p mfn: 0x%lx (order: %u)\n", __func__, va, mfn, order); + + spin_lock(&vmap_lock); + va = _vmap(cr3_ptr, va, mfn, order, l4_flags, l3_flags, l2_flags, l1_flags); + spin_unlock(&vmap_lock); + + return va; +} + +void *vmap_1g(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l3_flags, + bool propagate_user) { + unsigned long _va = _ul(va) & PAGE_ORDER_TO_MASK(PAGE_ORDER_1G); + + dprintk("%s: va: 0x%p mfn: 0x%lx\n", __func__, va, mfn); + spin_lock(&vmap_lock); - va = _vmap(&cr3, _ptr(_va), mfn, order, l4_flags, l3_flags, l2_flags, l1_flags); + va = _vmap_1g(cr3_ptr, _ptr(_va), mfn, l3_flags, propagate_user); spin_unlock(&vmap_lock); + return va; } -void *vmap_user(void *va, mfn_t mfn, unsigned int order, -#if defined(__x86_64__) - unsigned long l4_flags, -#endif - unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags) { - unsigned long _va = _ul(va) & PAGE_ORDER_TO_MASK(order); +void *vmap_2m(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l2_flags, + bool propagate_user) { + unsigned long _va = _ul(va) & PAGE_ORDER_TO_MASK(PAGE_ORDER_2M); + + dprintk("%s: va: 0x%p mfn: 0x%lx\n", __func__, va, mfn); + + spin_lock(&vmap_lock); + va = _vmap_2m(cr3_ptr, _ptr(_va), mfn, l2_flags, propagate_user); + spin_unlock(&vmap_lock); + + return va; +} + +void *vmap_4k(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l1_flags, + bool propagate_user) { + unsigned long _va = _ul(va) & PAGE_ORDER_TO_MASK(PAGE_ORDER_4K); + + dprintk("%s: va: 0x%p mfn: 0x%lx\n", __func__, va, mfn); - dprintk("%s: va: 0x%p mfn: 0x%lx (order: %u)\n", __func__, va, mfn, order); spin_lock(&vmap_lock); - va = _vmap(&user_cr3, _ptr(_va), mfn, order, l4_flags, l3_flags, l2_flags, l1_flags); + va = _vmap_4k(cr3_ptr, _ptr(_va), mfn, l1_flags, propagate_user); spin_unlock(&vmap_lock); + return va; } @@ -349,7 +430,7 @@ static void map_tmp_mapping_entry(void) { pte_t *entry = l1_table_entry(mfn_to_virt(l1e->mfn), _tmp_mapping); /* Map _tmp_mapping_entry PTE of new page tables */ - kmap_4k(l1e->mfn, L1_PROT); + vmap_kern_4k(mfn_to_virt_kern(l1e->mfn), l1e->mfn, L1_PROT); /* Point _tmp_mapping_entry at new page tables location */ _tmp_mapping_entry = paddr_to_virt_kern(_paddr(entry)); @@ -789,17 +870,17 @@ void init_pagetables(void) { switch (r->base) { case VIRT_IDENT_BASE: for (mfn_t mfn = virt_to_mfn(r->start); mfn < virt_to_mfn(r->end); mfn++) - vmap_4k(mfn_to_virt(mfn), mfn, r->flags); + vmap_kern_4k(mfn_to_virt(mfn), mfn, r->flags); break; case VIRT_KERNEL_BASE: for (mfn_t mfn = virt_to_mfn(r->start); mfn < virt_to_mfn(r->end); mfn++) - kmap_4k(mfn, r->flags); + vmap_kern_4k(mfn_to_virt_kern(mfn), mfn, r->flags); break; case VIRT_USER_BASE: for (mfn_t mfn = virt_to_mfn(r->start); mfn < virt_to_mfn(r->end); mfn++) { void *va = mfn_to_virt_user(mfn); - vmap_4k(va, mfn, r->flags); + vmap_kern_4k(va, mfn, r->flags); vmap_user_4k(va, mfn, r->flags); } break; diff --git a/common/setup.c b/common/setup.c index 7f8d2341..9bddd000 100644 --- a/common/setup.c +++ b/common/setup.c @@ -136,16 +136,17 @@ void zap_boot_mappings(void) { } static void __text_init map_bios_area(void) { - vmap_4k(paddr_to_virt(BDA_ADDR_START), paddr_to_mfn(BDA_ADDR_START), L1_PROT_RO); - kmap_4k(paddr_to_mfn(BDA_ADDR_START), L1_PROT_RO); + vmap_kern_4k(paddr_to_virt(BDA_ADDR_START), paddr_to_mfn(BDA_ADDR_START), L1_PROT_RO); + vmap_kern_4k(paddr_to_virt_kern(BDA_ADDR_START), paddr_to_mfn(BDA_ADDR_START), + L1_PROT_RO); uint32_t ebda_addr = get_bios_ebda_addr(); - vmap_4k(paddr_to_virt(ebda_addr), paddr_to_mfn(ebda_addr), L1_PROT_RO); - kmap_4k(paddr_to_mfn(ebda_addr), L1_PROT_RO); + vmap_kern_4k(paddr_to_virt(ebda_addr), paddr_to_mfn(ebda_addr), L1_PROT_RO); + vmap_kern_4k(paddr_to_virt_kern(ebda_addr), paddr_to_mfn(ebda_addr), L1_PROT_RO); for (mfn_t bios_mfn = paddr_to_mfn(BIOS_ACPI_ROM_START); bios_mfn < paddr_to_mfn(BIOS_ACPI_ROM_STOP); bios_mfn++) - kmap_4k(bios_mfn, L1_PROT_RO); + vmap_kern_4k(mfn_to_virt_kern(bios_mfn), bios_mfn, L1_PROT_RO); } static void display_cpu_info(void) { diff --git a/drivers/acpi/acpica/osl.c b/drivers/acpi/acpica/osl.c index d4fbd46d..e1862cf7 100644 --- a/drivers/acpi/acpica/osl.c +++ b/drivers/acpi/acpica/osl.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -306,7 +307,7 @@ void *AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length) { void *_va; if (!frame) { - _va = vmap_4k(mfn_to_virt_map(mfn), mfn, L1_PROT); + _va = vmap_kern_4k(mfn_to_virt_map(mfn), mfn, L1_PROT); if (!_va) { spin_unlock(&map_lock); return NULL; diff --git a/drivers/fb/fb.c b/drivers/fb/fb.c index 8912adb3..c2e8c58d 100644 --- a/drivers/fb/fb.c +++ b/drivers/fb/fb.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include extern uint64_t fonts[]; @@ -56,8 +56,8 @@ static void (*put_pixel)(uint32_t x, uint32_t y, uint32_t color); static void map_fb_area(paddr_t start, size_t size) { for (mfn_t video_mfn = paddr_to_mfn(start); video_mfn < paddr_to_mfn(start + size); video_mfn++) { - vmap_4k(mfn_to_virt(video_mfn), video_mfn, L1_PROT_NOCACHE); - kmap_4k(video_mfn, L1_PROT_NOCACHE); + vmap_kern_4k(mfn_to_virt(video_mfn), video_mfn, L1_PROT_NOCACHE); + vmap_kern_4k(mfn_to_virt_kern(video_mfn), video_mfn, L1_PROT_NOCACHE); } } diff --git a/drivers/hpet.c b/drivers/hpet.c index 6333d15a..448358b9 100644 --- a/drivers/hpet.c +++ b/drivers/hpet.c @@ -26,6 +26,7 @@ #include #include #include +#include bool init_hpet(const cpu_t *cpu) { #ifndef KTF_ACPICA @@ -59,7 +60,7 @@ bool init_hpet(const cpu_t *cpu) { #endif hpet_base_mfn = paddr_to_mfn(address); - vmap_4k(_ptr(address), hpet_base_mfn, L1_PROT_NOCACHE); + vmap_kern_4k(_ptr(address), hpet_base_mfn, L1_PROT_NOCACHE); config = (acpi_hpet_timer_t *) (address + HPET_OFFSET_TIMER_0_CONFIG_CAP_REG); general = (acpi_hpet_general_t *) (address + HPET_OFFSET_GENERAL_CAP_REG); main_counter = (uint64_t *) (address + HPET_OFFSET_GENERAL_MAIN_COUNTER_REG); diff --git a/drivers/vga.c b/drivers/vga.c index 12c54092..d679bf73 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -24,7 +24,7 @@ */ #include #include -#include +#include #include #define MAX_ROWS VGA_ROWS @@ -83,7 +83,7 @@ void vga_write(void *vga_memory, const char *buf, size_t len, vga_color_t color) void map_vga_area(void) { for (mfn_t vga_mfn = paddr_to_mfn(VGA_START_ADDR); vga_mfn < paddr_to_mfn(VGA_END_ADDR); vga_mfn++) { - vmap_4k(mfn_to_virt(vga_mfn), vga_mfn, L1_PROT_NOCACHE); - kmap_4k(vga_mfn, L1_PROT_NOCACHE); + vmap_kern_4k(mfn_to_virt(vga_mfn), vga_mfn, L1_PROT_NOCACHE); + vmap_kern_4k(mfn_to_virt_kern(vga_mfn), vga_mfn, L1_PROT_NOCACHE); } } diff --git a/include/arch/x86/page.h b/include/arch/x86/page.h index 7b3b8f30..13194646 100644 --- a/include/arch/x86/page.h +++ b/include/arch/x86/page.h @@ -175,22 +175,6 @@ typedef unsigned long mfn_t; /* External declarations */ -extern void *vmap_kern(void *va, mfn_t mfn, unsigned int order, -#if defined(__x86_64__) - unsigned long l4_flags, -#endif - unsigned long l3_flags, unsigned long l2_flags, - unsigned long l1_flags); - -extern void *vmap_user(void *va, mfn_t mfn, unsigned int order, -#if defined(__x86_64__) - unsigned long l4_flags, -#endif - unsigned long l3_flags, unsigned long l2_flags, - unsigned long l1_flags); - -extern int vunmap_kern(void *va, mfn_t *mfn, unsigned int *order); -extern int vunmap_user(void *va, mfn_t *mfn, unsigned int *order); extern void pat_set_type(pat_field_t field, pat_memory_type_t type); extern pat_memory_type_t pat_get_type(pat_field_t field); @@ -257,67 +241,6 @@ static inline mfn_t virt_to_mfn(const void *va) { return paddr_to_mfn(virt_to_paddr(va)); } -static inline void *kmap(mfn_t mfn, unsigned int order, -#if defined(__x86_64__) - unsigned long l4_flags, -#endif - unsigned long l3_flags, unsigned long l2_flags, - unsigned long l1_flags) { - return vmap_kern(mfn_to_virt_kern(mfn), mfn, order, -#if defined(__x86_64__) - l4_flags, -#endif - l3_flags, l2_flags, l1_flags); -} - -static inline void *vmap_1g(void *va, mfn_t mfn, unsigned long l3_flags) { - return vmap_kern(va, mfn, PAGE_ORDER_1G, L4_PROT, l3_flags | _PAGE_PSE, PT_NO_FLAGS, - PT_NO_FLAGS); -} - -static inline void *vmap_2m(void *va, mfn_t mfn, unsigned long l2_flags) { - return vmap_kern(va, mfn, PAGE_ORDER_2M, L4_PROT, L3_PROT, l2_flags | _PAGE_PSE, - PT_NO_FLAGS); -} - -static inline void *vmap_4k(void *va, mfn_t mfn, unsigned long l1_flags) { - return vmap_kern(va, mfn, PAGE_ORDER_4K, L4_PROT, L3_PROT, L2_PROT, l1_flags); -} - -static inline void *kmap_1g(mfn_t mfn, unsigned long l3_flags) { - return kmap(mfn, PAGE_ORDER_1G, L4_PROT, l3_flags | _PAGE_PSE, PT_NO_FLAGS, - PT_NO_FLAGS); -} - -static inline void *kmap_2m(mfn_t mfn, unsigned long l2_flags) { - return kmap(mfn, PAGE_ORDER_2M, L4_PROT, L3_PROT, l2_flags | _PAGE_PSE, PT_NO_FLAGS); -} - -static inline void *kmap_4k(mfn_t mfn, unsigned long l1_flags) { - return kmap(mfn, PAGE_ORDER_4K, L4_PROT, L3_PROT, L2_PROT, l1_flags); -} - -static inline void *vmap_user_1g(void *va, mfn_t mfn, unsigned long l3_flags) { - unsigned long user = l3_flags & _PAGE_USER; - - return vmap_user(va, mfn, PAGE_ORDER_1G, L4_PROT | user, - l3_flags | (user | _PAGE_PSE), PT_NO_FLAGS, PT_NO_FLAGS); -} - -static inline void *vmap_user_2m(void *va, mfn_t mfn, unsigned long l2_flags) { - unsigned long user = l2_flags & _PAGE_USER; - - return vmap_user(va, mfn, PAGE_ORDER_2M, L4_PROT | user, L3_PROT | user, - l2_flags | (user | _PAGE_PSE), PT_NO_FLAGS); -} - -static inline void *vmap_user_4k(void *va, mfn_t mfn, unsigned long l1_flags) { - unsigned long user = l1_flags & _PAGE_USER; - - return vmap_user(va, mfn, PAGE_ORDER_4K, L4_PROT | user, L3_PROT | user, - L2_PROT | user, l1_flags); -} - #endif /* __ASSEMBLY__ */ #endif /* KTF_PAGE_H */ diff --git a/include/arch/x86/pagetable.h b/include/arch/x86/pagetable.h index a0405b5e..a404000f 100644 --- a/include/arch/x86/pagetable.h +++ b/include/arch/x86/pagetable.h @@ -167,6 +167,21 @@ extern void unmap_pagetables(cr3_t *from_cr3, cr3_t *of_cr3); extern int map_pagetables_va(cr3_t *cr3_ptr, void *va); extern int unmap_pagetables_va(cr3_t *cr3_ptr, void *va); +extern void *vmap(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned int order, +#if defined(__x86_64__) + unsigned long l4_flags, +#endif + unsigned long l3_flags, unsigned long l2_flags, unsigned long l1_flags); +extern void *vmap_1g(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l3_flags, + bool propagate_user); +extern void *vmap_2m(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l2_flags, + bool propagate_user); +extern void *vmap_4k(cr3_t *cr3_ptr, void *va, mfn_t mfn, unsigned long l1_flags, + bool propagate_user); + +extern int vunmap_kern(void *va, mfn_t *mfn, unsigned int *order); +extern int vunmap_user(void *va, mfn_t *mfn, unsigned int *order); + /* Static declarations */ static inline pt_index_t l1_table_index(const void *va) { @@ -320,6 +335,48 @@ static inline bool is_pgentry_present(pgentry_t e) { return !!(e & _PAGE_PRESENT); } +static inline void *vmap_kern(void *va, mfn_t mfn, unsigned int order, +#if defined(__x86_64__) + unsigned long l4_flags, +#endif + unsigned long l3_flags, unsigned long l2_flags, + unsigned long l1_flags) { + return vmap(&cr3, va, mfn, order, l4_flags, l3_flags, l2_flags, l1_flags); +} + +static inline void *vmap_kern_1g(void *va, mfn_t mfn, unsigned long l3_flags) { + return vmap_1g(&cr3, va, mfn, l3_flags, false); +} + +static inline void *vmap_kern_2m(void *va, mfn_t mfn, unsigned long l2_flags) { + return vmap_2m(&cr3, va, mfn, l2_flags, false); +} + +static inline void *vmap_kern_4k(void *va, mfn_t mfn, unsigned long l1_flags) { + return vmap_4k(&cr3, va, mfn, l1_flags, false); +} + +static inline void *vmap_user(void *va, mfn_t mfn, unsigned int order, +#if defined(__x86_64__) + unsigned long l4_flags, +#endif + unsigned long l3_flags, unsigned long l2_flags, + unsigned long l1_flags) { + return vmap(&user_cr3, va, mfn, order, l4_flags, l3_flags, l2_flags, l1_flags); +} + +static inline void *vmap_user_1g(void *va, mfn_t mfn, unsigned long l3_flags) { + return vmap_1g(&user_cr3, va, mfn, l3_flags, true); +} + +static inline void *vmap_user_2m(void *va, mfn_t mfn, unsigned long l2_flags) { + return vmap_2m(&user_cr3, va, mfn, l2_flags, true); +} + +static inline void *vmap_user_4k(void *va, mfn_t mfn, unsigned long l1_flags) { + return vmap_4k(&user_cr3, va, mfn, l1_flags, true); +} + #endif /* __ASSEMBLY__ */ #endif /* KTF_PAGETABLE_H */ diff --git a/mm/pmm.c b/mm/pmm.c index 6622f805..089d9101 100644 --- a/mm/pmm.c +++ b/mm/pmm.c @@ -23,12 +23,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include -#include - #include #include #include +#include +#include +#include size_t total_phys_memory; @@ -641,5 +641,9 @@ void put_free_frames(mfn_t mfn, unsigned int order) { void map_frames_array(void) { frames_array_t *array; - list_for_each_entry (array, &frames, list) { kmap_4k(virt_to_mfn(array), L1_PROT); } + list_for_each_entry (array, &frames, list) { + mfn_t mfn = virt_to_mfn(array); + + BUG_ON(!vmap_kern_4k(mfn_to_virt_kern(mfn), mfn, L1_PROT)); + } } diff --git a/mm/vmm.c b/mm/vmm.c index ba7bc65b..193f63b1 100644 --- a/mm/vmm.c +++ b/mm/vmm.c @@ -24,7 +24,7 @@ */ #include #include -#include +#include #include #include @@ -61,7 +61,8 @@ void *get_free_pages(unsigned int order, gfp_flags_t flags) { } if (flags & GFP_KERNEL) { - va = kmap(mfn, order, L4_PROT, L3_PROT, L2_PROT, L1_PROT); + va = vmap_kern(mfn_to_virt_kern(mfn), mfn, order, L4_PROT, L3_PROT, L2_PROT, + L1_PROT); if (flags & GFP_USER) vmap_user(mfn_to_virt_kern(mfn), mfn, order, L4_PROT, L3_PROT, L2_PROT, L1_PROT); diff --git a/smp/mptables.c b/smp/mptables.c index e3c8baf3..fe5f6f26 100644 --- a/smp/mptables.c +++ b/smp/mptables.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -88,7 +88,8 @@ static mpf_t *get_mpf_addr(void) { if (get_memory_range(KB(512), &range) < 0) return NULL; - sysm_addr = kmap_4k(paddr_to_mfn(_paddr(range.end) - KB(1)), L1_PROT_RO); + mfn_t mfn = paddr_to_mfn(_paddr(range.end) - KB(1)); + sysm_addr = vmap_kern_4k(mfn_to_virt_kern(mfn), mfn, L1_PROT_RO); if (sysm_addr) { ptr = find_mpf(sysm_addr, sysm_addr + KB(1)); if (ptr) diff --git a/tests/test_cond_branch_mispredictions.c b/tests/test_cond_branch_mispredictions.c index c9b9c15b..7543187d 100644 --- a/tests/test_cond_branch_mispredictions.c +++ b/tests/test_cond_branch_mispredictions.c @@ -26,6 +26,7 @@ */ #include #include +#include #include #include @@ -204,7 +205,7 @@ void __aligned(PAGE_SIZE) test_cond_forward_branch_cl1(unsigned iterations) { int __aligned(PAGE_SIZE) test_cond_branch_mispredictions(void *unused) { frame_t *frame = get_free_frame(); - channel = vmap_4k(_ptr(CHANNEL_ADDR), frame->mfn, L1_PROT); + channel = vmap_kern_4k(_ptr(CHANNEL_ADDR), frame->mfn, L1_PROT); cl0 = &channel->lines[CACHE_LINE1]; /* CACHE_LINE_0_ADDR */ cl1 = &channel->lines[CACHE_LINE2]; /* CACHE_LINE_1_ADDR */ diff --git a/tests/test_uncond_branch_mispredictions.c b/tests/test_uncond_branch_mispredictions.c index 6be92edf..d8afd39f 100644 --- a/tests/test_uncond_branch_mispredictions.c +++ b/tests/test_uncond_branch_mispredictions.c @@ -26,6 +26,7 @@ */ #include #include +#include #include #include @@ -220,7 +221,7 @@ void __aligned(PAGE_SIZE) test_uncond_forward_branch_cl1(unsigned iterations) { int __aligned(PAGE_SIZE) test_uncond_branch_mispredictions(void *unused) { frame_t *frame = get_free_frame(); - channel = vmap_4k(_ptr(CHANNEL_ADDR), frame->mfn, L1_PROT); + channel = vmap_kern_4k(_ptr(CHANNEL_ADDR), frame->mfn, L1_PROT); cl0 = &channel->lines[CACHE_LINE1]; /* CACHE_LINE_0_ADDR */ cl1 = &channel->lines[CACHE_LINE2]; /* CACHE_LINE_1_ADDR */ diff --git a/tests/unittests.c b/tests/unittests.c index f0b321fb..04837823 100644 --- a/tests/unittests.c +++ b/tests/unittests.c @@ -26,17 +26,16 @@ #include #include #include +#include #include #include #include +#include #include #include #include #include -#include -#include - static char opt_string[4]; string_cmd("string", opt_string); @@ -217,7 +216,7 @@ int unit_tests(void *_unused) { task_user4 = new_user_task("test4 user", test_user_task_func4, NULL); frame_t *frame = get_free_frame(); - vmap_4k(HIGH_USER_PTR + 0x1000, frame->mfn, L1_PROT); + vmap_kern_4k(HIGH_USER_PTR + 0x1000, frame->mfn, L1_PROT); memset(HIGH_USER_PTR + 0x1000, 0, 0x1000); vmap_user_4k(HIGH_USER_PTR, frame->mfn, L1_PROT_USER);