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

Dornerworks x64 VM patch #16

Merged
merged 6 commits into from
Jun 7, 2023
Merged

Conversation

nomadeel
Copy link

This PR contains commits from Dornerworks' x64 VM patches for the VMM: https://github.com/dornerworks/camkes-vm/commits/open_source_release. Parts of Dornerworks' patches have been updated and/or changed slightly to match the newer VMM structure compared to what the patches originally targeted.

@oliver-wm
Copy link

Is this the one that was on bitbucket?

@nomadeel
Copy link
Author

nomadeel commented Apr 12, 2021

I think so, yeah.

EDIT: No, nevermind, it's not. This is new.

@oliver-wm
Copy link

I think so, yeah.

EDIT: No, nevermind, it's not. This is new.

Ok will review then

#ifdef CONFIG_ARCH_X86_64
vm_vmcs_init_64_bit_guest(vcpu);
#else
vm_vmcs_init_32_bit_guest(vcpu);
Copy link
Member

Choose a reason for hiding this comment

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

There are example apps that run a 32bit guest on a 64 bit host. Is this no longer something that we will support?

Copy link
Author

Choose a reason for hiding this comment

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

Yep, just found out as well when fixing some builds. I need to make extra changes to the various repositories to allow 32-bit guest on 64-bit host.

Copy link
Member

Choose a reason for hiding this comment

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

Have these changes been made?

@chrisguikema
Copy link
Contributor

What needs to happen to get this merged?

@@ -4,6 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

/* Under release mode, this file will get built using -O3. Howerver on gcc 8.4,
Copy link
Member

Choose a reason for hiding this comment

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

Is this a problem specific to GCC 8.4 or does it happen with newer versions and clang also? Such issues leave an odd feeling that there is an issue with the code (maybe alignment?) that I consider worth investigating. However, it should not be seen as a blocker for merging this as it temporarily fixes a problem.

I have created #75 to track this.

@axel-h
Copy link
Member

axel-h commented Sep 28, 2022

What needs to happen to get this merged?

Seems it needs a rebase now. I have a few comments on the code quality, but have to leave it to other to comment on the x64 changes.

@@ -368,15 +499,65 @@ uintptr_t vm_emulate_realmode(vm_vcpu_t *vcpu, uint8_t *instr_buf,
case 0xa1:
/* mov offset memory to eax */
instr++;
#ifdef CONFIG_ARCH_X86_64
memcpy(&mem, instr, 4);
Copy link
Member

Choose a reason for hiding this comment

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

When using sizeof(seL4_Word)/2 there is no need to duplicate the code. Might apply in other places also.

Suggested change
memcpy(&mem, instr, 4);
memcpy(&mem, instr, sizeof(seL4_Word)/2 );

@abrandnewusername
Copy link
Contributor

abrandnewusername commented May 2, 2023

Update:

  • Fixed most of the issues mentioned in previous comments
  • Changed the guard from CONFIG_ARCH_X86_64 to CONFIG_X86_64_VTX_64BIT_GUESTS due to a decision made in the related PR: Dornerworks x64 VM seL4#324 (comment)).

Future works: Current implementation for x64 support relies on the corresponding kernel implementation (see seL4/seL4#324), which does not support running both 32-bit VM guest and 64-bit VM guest on the same system. It will be ideal to implement this feature in the future.

Copy link
Member

@wom-bat wom-bat left a comment

Choose a reason for hiding this comment

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

A few minor changes can clean up some of the ifdefs. Otherwise, good to go.

Damon Lee and others added 6 commits June 6, 2023 16:58
This large commit combines a number of smaller commits in order to add
64-bit VM support to the VMM. The commits do the following:

    * Load elfs of the same architecture size
    * Support reading 64-bit vaddrs from elf files
    * Create initial address space based on guest architecture
    * Allow instruction decoding of 4-level paging scheme
    * Do not exit VMX state based on CR3 load/store in 64-bit mode
    * Use seL4_Word for vmcs and user context fields
    * Handle additional general purpose registers
    * Handle 64-bit MSRs
    * Configure 64-bit guests to boot in long mode
    * Let guest know about 64-bit hardware features in 64-bit mode
    * Add FADT and DSDT tables
    * Track guest state for additional 64-bit registers
    * Add new function to print 64-bit guest context
    * Properly emulate 64-bit trampoline code
    * Define access rights macros for vmcs initialization
    * Hardcode FADT table information
    * Set an initial stack pointer before running guest
    * Handle fetching cross-page instructions
    * Add additional x86 instruction prefixes

CCDC-GVSC DISTRIBUTION A.  Approved for public release; distribution
unlimited. OPSEC#4481.

Co-authored-by: Chris Guikema <[email protected]>
Signed-off-by: Damon Lee <[email protected]>
As the comment in the file explains, optimisation level -O3 on gcc 8.4
is too aggressive and causes issues for the guest VM. The problem isn't
limited to a single function or group of functions but rather the entire
file for some reason that requires extra investigation (but is not worth
the time to do so).

Signed-off-by: Damon Lee <[email protected]>
Previously, the physical address of the ACPI tables were being
tracked. This caused a Linux error while parsing the ACPI tables. Since
Linux does not have access to those memory regions, they would appear
empty, causing an Invalid Table Length bug print. By tracking the
virtual address that Linux expects and placing the vaddr into the ACPI
tables, Linux can parse the tables properly.

Signed-off-by: Chris Guikema <[email protected]>
switch from CONFIG_ARCH_X86_64 to CONFIG_X86_64_VTX_64BIT_GUESTS to
allow 32 bit guests on 64 bit hosts; fix print format for seL4_Word;
misc improvement.

Signed-off-by: Jingyao Zhou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants