Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: support memory mapped stacks #70810

Merged
merged 13 commits into from
Apr 10, 2024

Commits on Apr 1, 2024

  1. x86: gen_gdt: remove extra unnecessary parens

    Pylint complains so we fix.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    8f47e42 View commit details
    Browse the repository at this point in the history
  2. x86: do not advertise demand paging support for x86_64

    x86_64 does not currently support demand paging so don't
    advertise it.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    58fe23a View commit details
    Browse the repository at this point in the history
  3. x86: synchronize usage of CONFIG_X86_STACK_PROTECTION

    Most places use CONFIG_X86_STACK_PROTECTION, but there are some
    places using CONFIG_HW_STACK_PROTECTION. So synchronize all
    to use CONFIG_X86_STACK_PROTECTION instead.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    eb713f4 View commit details
    Browse the repository at this point in the history
  4. x86: correct size for stack bound check for privileged stack

    Previous commit changed the privileged stack size to be using
    kconfig CONFIG_PRIVILEGED_STACK_SIZE instead of simply
    CONFIG_MMU_PAGE_SIZE. However, the stack bound check function
    was still using the MMU page size, so fix that.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    3e4524b View commit details
    Browse the repository at this point in the history
  5. kernel: add options to cleanup after aborting current thread

    This adds the mechanism to do cleanup after k_thread_abort()
    is called with the current thread. This is mainly used for
    cleaning up things when the thread cannot be running, e.g.,
    cleanup the thread stack.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    5e8c5ab View commit details
    Browse the repository at this point in the history
  6. kernel: mm: introduce k_mem_phys_map()/_unmap()

    This is similar to k_mem_map()/_unmap(). But instead of using
    anonymous memory, the provided physical region is mapped
    into virtual address instead. In addition to simple mapping
    physical ro virtual addresses, the mapping also adds two
    guard pages before and after the virtual region to catch
    buffer under-/over-flow.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    00b3617 View commit details
    Browse the repository at this point in the history
  7. kernel: add the ability to memory map thread stacks

    This introduces support for memory mapped thread stacks,
    where each thread stack is mapped into virtual memory
    address space with two guard pages to catch
    under-/over-flowing the stack. This is just on the kernel
    side. Additional architecture code is required to fully
    support this feature.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    05c6583 View commit details
    Browse the repository at this point in the history
  8. tests: mem_protect/userspace: extend tests for mapped stack

    This extends the test for memory mapped stack, as the address of
    memory mapped stack object would be different than the actual
    stack object.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    9fd9271 View commit details
    Browse the repository at this point in the history
  9. tests: threads/thread_stack: extend tests for mapped stack

    This extends the test for memory mapped stack, as the address of
    memory mapped stack object would be different than the actual
    stack object.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    20b30bb View commit details
    Browse the repository at this point in the history
  10. cmsis_rtos_v1: support memory mapped stack at abort hook

    This extends the thread abort hook to support memory mapped
    stack. The calculation to find out to which instance of thread
    pools the outgoing thread belongs requires physical address.
    So find the physical address via the memory mapped stack for
    that.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    e19928d View commit details
    Browse the repository at this point in the history
  11. tests: mem_protect/stackprot: test mapped stack

    This extends the mem_protect/stackprot tests to support testing
    with memory mapped stack.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    d60e22d View commit details
    Browse the repository at this point in the history
  12. boards: qemu_x86/atom/virt: forcibly disable memory mapped stack

    The current memory mapped stack code requires actual physical
    addresses for stacks, and cannot deal with stacks already using
    virtual addresses. So disable mapped stack via defconfig.
    
    Note that this is done before enabling memory mapped stacks on
    x86 so test won't fail when the support in the architecture
    code is introduced.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    d2c3853 View commit details
    Browse the repository at this point in the history
  13. x86: add support for memory mapped stack for threads

    This adds the necessary bits to enable memory mapping thread
    stacks on both x86 and x86_64. Note that currently these do
    not support multi level mappings (e.g. demand paging and
    running in virtual address space: qemu_x86/atom/virt board)
    as the mapped stacks require actual physical addresses.
    
    Signed-off-by: Daniel Leung <daniel.leung@intel.com>
    dcpleung committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    0b1c3c9 View commit details
    Browse the repository at this point in the history