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

Implement memory range mapping/unmapping; Cleanup and standardize vmap API #308

Merged
merged 4 commits into from
Nov 23, 2023

Conversation

wipawel
Copy link
Contributor

@wipawel wipawel commented Sep 12, 2023

This resolves #253.

@wipawel wipawel added feature New feature or request improvement A small enhancement, that makes already implemented features better Priority: 2 Very important feature labels Sep 12, 2023
@wipawel wipawel requested a review from a team as a code owner September 12, 2023 07:21
arch/x86/pagetables.c Outdated Show resolved Hide resolved
arch/x86/pagetables.c Outdated Show resolved Hide resolved
arch/x86/pagetables.c Outdated Show resolved Hide resolved
arch/x86/pagetables.c Outdated Show resolved Hide resolved
arch/x86/pagetables.c Outdated Show resolved Hide resolved
arch/x86/pagetables.c Outdated Show resolved Hide resolved
arch/x86/pagetables.c Outdated Show resolved Hide resolved
common/acpi.c Outdated Show resolved Hide resolved
common/usermode.c Outdated Show resolved Hide resolved
tests/unittests.c Outdated Show resolved Hide resolved
@wipawel wipawel changed the title Implement better vunmap() and memory range mapping/unmapping Implement memory range mapping/unmapping; Cleanup and standardize vmap API Nov 21, 2023
minipli-oss
minipli-oss previously approved these changes Nov 23, 2023
Copy link
Contributor

@minipli-oss minipli-oss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, Pawel. Only a few nits and questions left, but really no more code changes required.

The comment regarding only being able to unmap single pages via SYSCALL_MUNMAP still applies. But I guess, now with v[un]map_range() available, it's easy to extend the functionality to cover multiple pages. But this can (and should!) be a follow-up change.

Thanks again for the hard work!

arch/x86/pagetables.c Outdated Show resolved Hide resolved
arch/x86/pagetables.c Show resolved Hide resolved
arch/x86/pagetables.c Show resolved Hide resolved
@wipawel
Copy link
Contributor Author

wipawel commented Nov 23, 2023

Great work, Pawel. Only a few nits and questions left, but really no more code changes required.

The comment regarding only being able to unmap single pages via SYSCALL_MUNMAP still applies. But I guess, now with v[un]map_range() available, it's easy to extend the functionality to cover multiple pages. But this can (and should!) be a follow-up change.

Thanks again for the hard work!

Thanks very much Mathias!

I created a dedicated issue for the mmap/munmap usermode extension: #332. This should also depend on another issue: #331, but in general should be much easier to implement now.

Summary of the changes:
  * Get rid of kmap() API - it was confusing and non-standard
  * Add set of generic vmap APIs and make them public
      - These functions allow to specify all parameters
          * All level PT flags
          * Address space (via CR3 pointer)
  * Add set of order-specific (4K, 2M, 1G) public vmap APIs
      - Use default PT flags for non-last level
      - Allow to propagate user bit on request
  * Add separate sets of APIs for kernel and user address spaces
  * Move all interface definitions from page.h to pagetable.h

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
This API allows to automatically map (or unmap) a range of physical
addresses specified with a start address and length.
Both vmap_range() and vunmap_range() allow to automatically map
the physical address range into multiple different memory areas
specified via vmap_flags parameter.

Support memory areas via vmap_flags:
  * VMAP_IDENT - kernel address space, identity mapping
  * VMAP_KERNEL - high kernel addresses (small area)
  * VMAP_KERNEL_MAP - low kernel addresses (large area)
  * VMAP_KERNEL_USER - kernel address space, but user memory area
  * VMAP_KERNEL_USER_ACCESS - kernel address space, but user memory
                              area with user access permission
  * VMAP_USER - user address space, user memory area
  * VMAP_USER_IDENT - user address space, identity mapping, no user
                      access
  * VMAP_USER_KERNEL - user address space, high kernel addresses, no
                       user access
  * VMAP_USER_KERNEL_MAP - user address space, low kernel addresses,
                           no user access

The vmap_range() tries to use as many huge pages as possible for the
mapping.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
Use vmap_range() to handle multiple mapping areas automatically
and consistently.

Standardize rules for virtual address returned by get_free_pages().

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
Copy link
Contributor

@minipli-oss minipli-oss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@wipawel wipawel merged commit c20748c into KernelTestFramework:mainline Nov 23, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request improvement A small enhancement, that makes already implemented features better Priority: 2 Very important feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Allow specifying size of range to address mapping APIs
3 participants