KernelTestFramework / ktf

Kernel Test Framework
BSD 2-Clause "Simplified" License
140 stars 18 forks source link

Add basic support for user land address space #269

Closed wipawel closed 2 years ago

wipawel commented 2 years ago

It is implementing part of the Issue #55.

Consists of the following commits:

    arch, pagetables: fix IS_ADDR_SPACE_VA() macro

    The IS_ADDR_SPACE_VA() macro was using incorrect comparison for an
    address belonging to an address space. Masking (&) could return
    incorrect result for a shifted user address space mappings.
    arch, pagetables: fix vmap()'s initial va alignment check

    It should check VA alignment based on requested order, not just
    PAGE_MASK (4K pages order).
    arch, pagetables: prepare vmap() to handle separate address spaces

    Make _vmap() accept CR3 as parameter, indicating which address space
    is being mapped into. And turn vmap() and vunmap() into helper functions
    with default address space of the kernel (vmap_kern(), vunmap_kern()).

    Remove mmap_*() helper functions as they are confusing and not used.
    mm/vmm: add put_page_top() helper function for stack pages
    arch, pagetables: add user address space

    Add separate CR3 variable holding top of the user space page tables.
    Add vmap_user*() helper functions, capable of mapping both kernel
    mappings (kernel privilege, for necessary kernel mappings in user
    address space) and user mappings (userland data and code).

    Map userland data and code to both kernel and user address spaces.

    Map IDT and TSS's RSP0 stack to user address space as kernel mappings.
    arch: add SET_CR3 assembly macro

    The macro preserves RAX register via stack, but does not clean the stack.