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

cpu/vc: implement RDTSC and RDSTCP #VC handlers #327

Merged
merged 6 commits into from
Apr 26, 2024

Conversation

00xc
Copy link
Member

@00xc 00xc commented Apr 23, 2024

  • Add GHCB getters and setters that check or set the valid bitmap (now that there's a stable offset_of!() macro).
  • Fix potential problem with GHCB::rdmsr_regs().
  • Implement RDTSC #VC handler and enable relevant in-SVSM test.
  • Fix rdtscp().
  • Implement RDTSCP #VC handler and enable relevant in-SVSM test.
  • Add a test for the GHCB layout.

This works towards a more complete implementation of #14 .

kernel/src/sev/ghcb.rs Show resolved Hide resolved
kernel/src/sev/ghcb.rs Outdated Show resolved Hide resolved
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>
Copy link
Collaborator

@p4zuu p4zuu left a 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

@joergroedel
Copy link
Member

Well done! I especially like the new macros for GHCB getters/setters and the test-case checking the GHCB offsets.

@joergroedel joergroedel merged commit 95e2039 into coconut-svsm:main Apr 26, 2024
3 checks passed
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.

None yet

3 participants