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

[RFC] Add support for KVM_GET_XSAVE2 ioctls #261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

roypat
Copy link
Collaborator

@roypat roypat commented Apr 24, 2024

Since Linux 5.17, the kvm_xsave struct has a flexible array member (FAM) at the end, which can be retrieved using the KVM_GET_XSAVE2 ioctl [1]. What makes this FAM special is that the length is not stored in the header, but has to be retrieved via
KVM_CHECK_CAPABILITY(KVM_CAP_XSAVE2), which returns the total size of the kvm_xsave struct (e.g. the traditional 4096 byte header + the size of the FAM). Thus, to support KVM_GET_XSAVE2, we first need to check the capability on the VM fd, construct a FamStructWrapper of the correct size, and then call KVM_GET_XSAVE2.

I'm marking this as "RFC" because I'm not quite sure how to best deal the combination of "check capability on VM FD" and "do ioctl on vcpu FD". In this patch, I simply add a VmFd parameter to Vcpu::get_xsave2, but that's kinda ugly. Alternatively, we could store a reference to the VM file descriptor inside each Vcpu structure, but that'd be a larger change. What do people think about this?

(also, this PR needs rust-vmm/kvm-bindings#104, because Rust apparently only type checks type aliases at use-sites instead of definition-site, meaning I did not notice that I forgot to implement Default for kvm_xsave2 when working on the new kvm-bindings release. That's why the CI is failing here for now)

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

Since Linux 5.17, the `kvm_xsave` struct has a flexible array member
(FAM) at the end, which can be retrieved using the `KVM_GET_XSAVE2`
ioctl [1]. What makes this FAM special is that the length is not stored
in the header, but has to be retrieved via
`KVM_CHECK_CAPABILITY(KVM_CAP_XSAVE2)`, which returns the total size of
the `kvm_xsave` struct (e.g. the traditional 4096 byte header + the size
of the FAM). Thus, to support `KVM_GET_XSAVE2`, we first need to check
the capability on the VM fd, construct a FamStructWrapper of the correct
size, and then call `KVM_GET_XSAVE2`.

[1]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-get-xsave2

Signed-off-by: Patrick Roy <[email protected]>
@roypat
Copy link
Collaborator Author

roypat commented Apr 24, 2024

cc @likebreath since iirc you were looking into a post-5.17 solution for kvm_xsave, too

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.

1 participant