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

plat/kvm: Use AllocatePages() to allocate memory regions in UEFI #1061

Merged

Conversation

mogasergiu
Copy link
Member

@mogasergiu mogasergiu commented Aug 21, 2023

According to the UEFI specifications, AllocatePool() is the safest allocation method, however there are two pitfalls:

  • we don't know the BIOS's memory allocator or the system's memory map, so the resulted allocation start address may be out of the range that would be compatible with a Unikraft configuration that does not have CONFIG_HAVE_PAGING
  • it does not guarantee page-aligned allocations and, even though we may be able to align the length or the end address, the allocation's start address may therefore not be page-aligned

Thus, replace such calls to AllocatePool() with calls to AllocatePages() to ensure page-aligned start addresses. Furthermore, preserve backwards compatibility with Unikraft configurations that do not have CONFIG_HAVE_PAGING by limiting the allocation's start address to be below the highest address of the static boot page tables through the help of bpt_unmap_mrd.

Prerequisite checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Base target

  • Architecture(s): [all]
  • Platform(s): [kvm]
  • Application(s): [all]

Additional configuration

Description of changes

@mogasergiu mogasergiu requested a review from a team as a code owner August 21, 2023 07:56
@unikraft-bot
Copy link
Member

Checkpatch passed

Beep boop! I ran Unikraft's checkpatch.pl support script on your pull request and it all looks good!

SHA commit checkpatch
5f75401 plat/kvm: Use `AllocatePages()` to allocate memory regions in `UEFI`

@unikraft-bot unikraft-bot added area/plat Unikraft Patform lang/c Issues or PRs to do with C/C++ plat/kvm Unikraft for KVM labels Aug 21, 2023
@razvand razvand requested review from mschlumpp and eduardvintila and removed request for a team and craciunoiuc September 8, 2023 21:20
@razvand razvand added this to the v0.15.0 (Pandora) milestone Sep 8, 2023
plat/kvm/efi.c Outdated Show resolved Hide resolved
@mogasergiu mogasergiu force-pushed the smoga/s/allocate_pool/allocate_pages branch 2 times, most recently from d088656 to 32411b4 Compare October 6, 2023 15:31
Copy link
Member

@mschlumpp mschlumpp left a comment

Choose a reason for hiding this comment

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

I have no idea about UEFI, and wasn't able to get QEMU working with it. I assume that somebody else will test it.
Okay seems to work, but we should really increase the default memory region count. With the default memory region count the image does not boot on QEMU+OVMF.

Reviewed-by: Marco Schlumpp marco@unikraft.io

According to the `UEFI` specifications, `AllocatePool()` is the safest
allocation method, however there are two pitfalls:
- we don't know the BIOS's memory allocator or the system's memory map,
so the resulted allocation start address may be out of the range that
would be compatible with a Unikraft configuration that does not have
`CONFIG_HAVE_PAGING`
- it does not guarantee page-aligned allocations and, even though we
may be able to align the length or the end address, the allocation's
start address may therefore not be page-aligned

Thus, replace such calls to `AllocatePool()` with calls to
`AllocatePages()` to ensure page-aligned start addresses. Furthermore,
preserve backwards compatibility with Unikraft configurations that do
not have `CONFIG_HAVE_PAGING` by limiting the allocation's start address
to be below the highest address of the static boot page tables through
the help of `bpt_unmap_mrd`.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
@mogasergiu mogasergiu force-pushed the smoga/s/allocate_pool/allocate_pages branch from 32411b4 to 6b81bd5 Compare October 9, 2023 07:17
Copy link
Member

@eduardvintila eduardvintila left a comment

Choose a reason for hiding this comment

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

Looks very good to me. Thanks, @mogasergiu!

Reviewed-by: Eduard Vintilă eduard.vintila47@gmail.com

Copy link
Member

@michpappas michpappas left a comment

Choose a reason for hiding this comment

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

Approved-by: Michalis Pappas michalis@unikraft.io

@razvand razvand merged commit afbd076 into unikraft:staging Oct 14, 2023
9 checks passed
razvand pushed a commit that referenced this pull request Oct 14, 2023
According to the `UEFI` specifications, `AllocatePool()` is the safest
allocation method, however there are two pitfalls:
- we don't know the BIOS's memory allocator or the system's memory map,
so the resulted allocation start address may be out of the range that
would be compatible with a Unikraft configuration that does not have
`CONFIG_HAVE_PAGING`
- it does not guarantee page-aligned allocations and, even though we
may be able to align the length or the end address, the allocation's
start address may therefore not be page-aligned

Thus, replace such calls to `AllocatePool()` with calls to
`AllocatePages()` to ensure page-aligned start addresses. Furthermore,
preserve backwards compatibility with Unikraft configurations that do
not have `CONFIG_HAVE_PAGING` by limiting the allocation's start address
to be below the highest address of the static boot page tables through
the help of `bpt_unmap_mrd`.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1061
razvand pushed a commit that referenced this pull request Oct 20, 2023
According to the `UEFI` specifications, `AllocatePool()` is the safest
allocation method, however there are two pitfalls:
- we don't know the BIOS's memory allocator or the system's memory map,
so the resulted allocation start address may be out of the range that
would be compatible with a Unikraft configuration that does not have
`CONFIG_HAVE_PAGING`
- it does not guarantee page-aligned allocations and, even though we
may be able to align the length or the end address, the allocation's
start address may therefore not be page-aligned

Thus, replace such calls to `AllocatePool()` with calls to
`AllocatePages()` to ensure page-aligned start addresses. Furthermore,
preserve backwards compatibility with Unikraft configurations that do
not have `CONFIG_HAVE_PAGING` by limiting the allocation's start address
to be below the highest address of the static boot page tables through
the help of `bpt_unmap_mrd`.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1061
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/plat Unikraft Patform lang/c Issues or PRs to do with C/C++ plat/kvm Unikraft for KVM
Projects
Status: Done!
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants