forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 2
Modifief kexec_load syscall to support running EFI application. #1
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
Open
oweisse
wants to merge
54
commits into
kexec_review
Choose a base branch
from
master
base: kexec_review
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Currently only supports extremely simple apps like HelloWorld.efi
* kexec.h - Added KEXEC_RUN_PE flag to be passed to kexec_load. This is the
* kexec.c
- Implemented kimage_load_pe, kimage_run_pe
- Implemented EFI hooks to generate fake EFI system table and
fake EFI boot services.
- Implemented naive EFI AllocatePool, FreePool
- Implemented EFI conout to enable OutputString
EFI Boot Services:
efi_hook_HandleProtocol:
- prints out the protocol GUID and name
- implemented gEfiLoadedImageProtocolGuid
- implemented gEfiDevicePathProtocolGuid
EFI Protocols:
gEfiLoadedImageProtocolGuid:
- Respond with a fixed EFI_LOADED_IMAGE_PROTOCOL containing a fixd boot-device and fixed LoadOptions
gEfiLoadedImageProtocolGuid:
- Acceplts only BOOT_DEVICE_HANDLE, replies with a fixed windows_boot_device_path
windows_loaded_image needs to be patched during kimage_load_pe
* efi_setup_11_mapping: creates 1:1 mapping
* efi_hook_AllocatePool: now calls efi_setup_11_mapping and returns
"physical" address, thanks to the 1:1 mapping
* efi_hook_FreePool: Removed call to kfree, which is incompatible with
our new 1:1 mapping
* efi_register_mem_allocation: register new memory allocation * efi_unregister_allocation: reclaim memory and make it EfiConventionalMemory * efi_hook_GetMemoryMap: get current memory mappings The current bookkepping is naive and incorrect. TODO: 1. When allocating memory, we should seearch if blocks of EfiConventionalMemory are available for allocation. 2. When registerring memory, we might need to split a block of EfiConventionalMemory 3. When unregistering memory, we need to potentially coalsce blocks of EfiConventionalMemory.
This os a preparation for smarter management of mem maps.
Windows loader sets up interrupts 0x3, 0x2C, 0x2D to empty interrupt handlers. A good fix in the future would be to make the page temporarily.
Also refactored CHAR16 to char conversion function
…them.
Implemented the following functions:
* efi_hook_LocateHandle: implemented only for gEfiBlockIoProtocolGuid. Returning 4
devices: raw-hard-drive and partitions 1,2,3.
* efi_handle_protocol_DevicePath: implemented for the 4 devices mentioned above
* efi_handle_protocol_BlockIO: Returns the proper EFI_BLOCK_IO_PROTOCOL, depending
on the handle provided. Implemented Read/write
callbacks whcih print log msg to screen and return
an erro code.
* efi_hook_CloseProtocol: empty implementation (log and return success)
see efi_block_io_read_blocks
This ensures Windows loader can access these addresses
hugelgupf
reviewed
Jul 19, 2019
hugelgupf
reviewed
Jul 19, 2019
hugelgupf
reviewed
Jul 19, 2019
This is crucial to support Windows loader replacing CR3 with its own page table
This is required to allow Winload.efi to access the system table. * Allocate memory in a 1:1 mapped area * Print the memory map after every memory allocation.
This is important so that the system table and other structures can be accessible when Windows loader (either bootmg or Winload.efi) try to access them via a Windows page table.
laoder: * fake_systab * fake_systab->con_out * efi_config_table * runtime_services
… memory. Also making sure the memory map is sorted
Passing the original EFI runtime services via the system table. * Areas marked "reserved" in e820 map are marked EfiRuntimeServicesCode, as they contain runtime code. * Modified InternalSerialPuts to be a MACRO * Refactored memory mapping functions
This is required when winload.efi iterates the result of GetMemoryMap, since it only considers memory descriptors with the attribute EFI_MEMORY_RUNTIME. Failing to do so will later yield a failure of the runtime call to set_virtual_address_map. See fix in efi_mem_allocation_build_chunk. Also fixed MapKey value to be a monotonically advancing value.
…ile.
* include/linux/efi.h: declaration of the list and relevant functions
* kernel/efi_protocol_guids.c: contains the list and search/comparison
functions
* kernel/Makefile: added kernel/efi_protocol_guids.c
When efi_hook_AllocatePages is called with EFI_ALLOCATE_TYPE of AllocateAddress we take a leap of faith that the requested physical address is available. We should make sure the address is actually available and return error if not.
this call can be ignored.
Right now the available devices are hard coded, based on our very-specific drive.
The hack is to remove the NX bit from P4D in the page table. This allows executing the windows loader code in a memory space which is seemingly user-space. Since IA32_EFER.NXE == 1, having P4D with the NX bit will result in a page fault, when we start fetching instructions for Windows loader.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently only supports extremely simple apps like HelloWorld.efi
- Implemented kimage_load_pe, kimage_run_pe
- Implemented EFI hooks to generate fake EFI system table and
fake EFI boot services.
- Implemented naive EFI AllocatePool, FreePool
- Implemented EFI conout to enable OutputString