Add support for KVM_GET_XSAVE2 #310
Merged
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.
Summary of the PR
Since Linux 5.17, the
kvm_xsave
struct has a flexiblre 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 itself, but has to be retrieved via
KVM_CHECK_CAPABILITY(KVM_CAP_XSAVE2)
which returns the total size ofthe
kvm_xsave
struct (e.g. the traditional 4096 byte region + extraregion with the size of the FAM). To support it in rust-vmm,
Xsave
hasbeen introduced as its
FamStructWrapper
.The size required to hold the whole
kvm_xsave
structure can varydepending on features that have been dynamically enabled by
arch_prctl()
[2]. Any features must not be enabled after the size hasbeen confirmed; otherwise,
KVM_GET_XSAVE2
writes beyond the allocatedarea for
Xsave
, potentially causing undefined behavior. It is unableto put
KVM_CHECK_CAPABILITY
call for the size check andKVM_GET_XSAVE2
call together intoget_xsave2()
, because there is achance of race condition where another thread enables additional
features between them. That's why
get_xsave2()
is markedunsafe
.Although
KVM_SET_XSAVE
was extended andKVM_SET_XSAVE2
was not addedto support the
kvm_xsave
with FAM,set_xsave2()
is also implementedto enable users to pass
Xsave
to it for convenience. That is alsomarked
unsafe
for the same reason.In addition to that, after Linux 5.17, the existing
set_xsave2()
may copy databeyond the traditional 4096 bytes if XSTATE features are dynamically enabled.
So it is also marked
unsafe
.Requirements
Before submitting your PR, please make sure you addressed the following
requirements:
git commit -s
), and the commit message has max 60 characters for thesummary and max 75 characters for each description line.
test.
Release" section of CHANGELOG.md (if no such section exists, please create one).
unsafe
code is properly documented.