-
Notifications
You must be signed in to change notification settings - Fork 35
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
cpu/vc: implement RDTSC
and RDSTCP
#VC handlers
#327
Merged
Merged
Conversation
This file contains 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
p4zuu
reviewed
Apr 24, 2024
When accessing GHCB fields that were written to by the host, we must check that they are set as valid in the valid bitmap. Conversely, when setting fields of the GHCB to communicate with the host, we must set them as valid in the valid bitmap. To do so, we must get the offset of such field in the GHCB and translate it into an index into the valid bitmap. Instead of hardcoding GHCB field offsets, implement getters and setters for each field, which will automatically get or set the appropriate value from the valid bitmap based on that field's offset. This was not done before because there was no way of getting a field's offset at compile time before Rust 1.77, which introduced the core::mem::offset_of!() macro. Signed-off-by: Carlos López <carlos.lopez@suse.com>
When performing a VMGEXIT to request a RDMSR we expect the instruction results to be placed in RDX and RAX. However, we must check that the hypervisor set those registers as valid before reading them. To do so, use the recently introduced getters. Signed-off-by: Carlos López <carlos.lopez@suse.com>
Implement a the #VC handler for the SVM_RDTSC exit reason. This also requires decoding the RDTSC instruction. The handler simply forwards the call into the GHCB and copies out the relevant registers to the guest state. While we are at it, enable the relevant RDTSC #VC test. Signed-off-by: Carlos López <carlos.lopez@suse.com>
Due to a typo, this function was issuing a RDTSC instruction instead of RDTSCP. Signed-off-by: Carlos López <carlos.lopez@suse.com>
Implement a the #VC handler for the SVM_RDTSCP exit reason. This also requires decoding the RDTSCP instruction. The handler simply forwards the call into the GHCB and copies out the relevant registers to the guest state. While we are at it, enable the relevant RDTSCP #VC test. Signed-off-by: Carlos López <carlos.lopez@suse.com>
Add a test to verify that the GHCB layout is as expected, as per the GHCB specification: https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/specifications/56421.pdf Signed-off-by: Carlos López <carlos.lopez@suse.com>
p4zuu
reviewed
Apr 24, 2024
p4zuu
approved these changes
Apr 24, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Well done! I especially like the new macros for GHCB getters/setters and the test-case checking the GHCB offsets. |
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.
offset_of!()
macro).GHCB::rdmsr_regs()
.RDTSC
#VC handler and enable relevant in-SVSM test.rdtscp()
.RDTSCP
#VC handler and enable relevant in-SVSM test.This works towards a more complete implementation of #14 .