Add support for arm cca
This PR aims at adding support to build realm guests. First commit adds support for create_guest_memfd() and set_user_memory_region2(). To do this, the memory_init() is modified by adding a boolean parameter. This is required when building a confidential guest for arm cca and probably also required by other cases.
The second commit imports the virtee/cca crate and adds the steps to build a cca guest. The following items should be completed before merge the PR:
- [x] use populate() only for kernel and initialize() for non-kernel area
- [x] handle the case in which the guest switch from shared -> private
- [x] correctly calculation of max_ipa
This has been testing using the v7 series for Linux as a guest and v6 series for KVM on FVP model.
Feedback is welcome.
@MatiasVara is this ready for review, or should I wait?
@jakecorrenti I'm addressing the KVM guest_memfd changes (which @MatiasVara also added in this PR) to my latest SEV-SNP patches. This will probably require a rebase after that. Once that happens, it will likely be ready for a review.
@jakecorrenti I'm addressing the KVM guest_memfd changes (which @MatiasVara also added in this PR) to my latest SEV-SNP patches. This will probably require a rebase after that. Once that happens, it will likely be ready for a review.
I think the PR is ready to review. The current issue is that it does not work for the latest series for KVM (v6). I am investigating the issue.
I just updated the PR with the fix for v6 series. The fix is only to set the KVM_ARM_VCPU_REC feature during the initialization of VCPUs otherwise vcpu_finalize would fail.
@jakecorrenti @tylerfanelli @slp Feel free to give a quick look. I am pretty sure there many things to fix.
After reviewing the Jake comments I came to the conclusion that this PR should be split otherwise is hard to review:
- Add
Use create_guest_memfd() and set_user_memory_region2()only whenteeis enabled. - Add the handling of
KVM_MEMORY_FAULTonly fortee, which includes the extra thread for handling shared to private and viceverse. -
Teeshould be replaced withtee and x86-64since allteeis forx86-64. - Add CCA support. This shall be added with
cca and teeenabled. - Eventually some code will be shared for
teeinx86-64andaarch64but I can't see it yet.
@jakecorrenti @tylerfanelli @slp WDYT?
After reviewing the Jake comments I came to the conclusion that this PR should be split otherwise is hard to review:
0. Add `Use create_guest_memfd() and set_user_memory_region2()` only when `tee` is enabled. 1. Add the handling of `KVM_MEMORY_FAULT` only for `tee`, which includes the extra thread for handling shared to private and viceverse. 2. `Tee` should be replaced with `tee and x86-64` since all `tee` is for `x86-64`.
I don't know if this is idiomatic by any means, and it depends on whether you can have target arch-specific features, but could we have something like tee-x86 and tee? tee-x86 for the x86 specific functionality, and then tee for the shared bits? Would that be cleaner than just writing #[cfg(all(feature = "tee", target_arch = "x86_64"))]? Again, I don't know if that's "proper" Rust or even possible.
3. Add CCA support. This shall be added with `cca and tee` enabled. 4. Eventually some code will be shared for `tee` in `x86-64` and `aarch64` but I can't see it yet.@jakecorrenti @tylerfanelli @slp WDYT?
Other than my question above, that all sounds good to me.
After reviewing the Jake comments I came to the conclusion that this PR should be split otherwise is hard to review:
- Add
Use create_guest_memfd() and set_user_memory_region2()only whenteeis enabled.
I don't think set_user_memory_region2 should be tee only, as I believe that on newer kernels, set_user_memory_region is deprecated.
- Add the handling of
KVM_MEMORY_FAULTonly fortee, which includes the extra thread for handling shared to private and viceverse.
I'm addressing that in my SEV-SNP PR currently.
Teeshould be replaced withtee and x86-64since allteeis forx86-64.
Makes sense to me.
- Add CCA support. This shall be added with
cca and teeenabled.
Do you mean aarch64 and tee?
After reviewing the Jake comments I came to the conclusion that this PR should be split otherwise is hard to review:
0. Add `Use create_guest_memfd() and set_user_memory_region2()` only when `tee` is enabled. 1. Add the handling of `KVM_MEMORY_FAULT` only for `tee`, which includes the extra thread for handling shared to private and viceverse. 2. `Tee` should be replaced with `tee and x86-64` since all `tee` is for `x86-64`.I don't know if this is idiomatic by any means, and it depends on whether you can have target arch-specific features, but could we have something like
tee-x86andtee?tee-x86for the x86 specific functionality, and thenteefor the shared bits? Would that be cleaner than just writing#[cfg(all(feature = "tee", target_arch = "x86_64"))]? Again, I don't know if that's "proper" Rust or even possible.
I do not know either. I though that tee and x86 would have code that tdx and snv share, if that exists.
3. Add CCA support. This shall be added with `cca and tee` enabled. 4. Eventually some code will be shared for `tee` in `x86-64` and `aarch64` but I can't see it yet.@jakecorrenti @tylerfanelli @slp WDYT?
Other than my question above, that all sounds good to me.
After reviewing the Jake comments I came to the conclusion that this PR should be split otherwise is hard to review:
- Add
Use create_guest_memfd() and set_user_memory_region2()only whenteeis enabled.I don't think
set_user_memory_region2should beteeonly, as I believe that on newer kernels,set_user_memory_regionis deprecated.
That's OK. I could just leave set_user_memory_region2 for the future.
- Add the handling of
KVM_MEMORY_FAULTonly fortee, which includes the extra thread for handling shared to private and viceverse.I'm addressing that in my SEV-SNP PR currently.
The first two items in my list are for all tee but they were in my PR for almost a year already. In any case, I need to split those chunks from my PR.
Teeshould be replaced withtee and x86-64since allteeis forx86-64.Makes sense to me.
- Add CCA support. This shall be added with
cca and teeenabled.Do you mean
aarch64 and tee?
Yes for the moment.
After reviewing the Jake comments I came to the conclusion that this PR should be split otherwise is hard to review:
- Add
Use create_guest_memfd() and set_user_memory_region2()only whenteeis enabled.- Add the handling of
KVM_MEMORY_FAULTonly fortee, which includes the extra thread for handling shared to private and viceverse.Teeshould be replaced withtee and x86-64since allteeis forx86-64.- Add CCA support. This shall be added with
cca and teeenabled.- Eventually some code will be shared for
teeinx86-64andaarch64but I can't see it yet.@jakecorrenti @tylerfanelli @slp WDYT?
I just split the PR into a few commits. It is the same code though. The first three commits are independent of cca and should be shared by all tees. Also [Enable tee only in x86-64 shall for all tees since it aims at separating the code for tee and x86 and tee and aach64.
I open two PR to update kvm-bindings (see https://github.com/virtee/kvm-bindings/pull/2) and kvm-ioctls (see https://github.com/virtee/kvm-ioctls/pull/4) due to changes upstream (v8).
I've Just rebased the PR and tried it on v8 series.
I just rebased and tested on v8. Also, I am now relying on the rust-vmm/kvm repo.
I think the following issues shall be addressed before merging:
- [x] support for blk
- [x] Check the EXIT_FAULT
- [ ] Check FDT hardcoded
- [x] Try v9 series