Support for Arm CCA VMs on Linux
Subsystems (13)
Re: [RFC PATCH 17/28] arm64: RME: Runtime faulting of memory
In reply to Steven PriceQuoted 24 lines · On Fri, 27 Jan 2023 11:29:21 +0000 Steven Price <[email protected]> wrote:
At runtime if the realm guest accesses memory which hasn't yet been mapped then KVM needs to either populate the region or fault the guest.
For memory in the lower (protected) region of IPA a fresh page is provided to the RMM which will zero the contents. For memory in the upper (shared) region of IPA, the memory from the memslot is mapped into the realm VM non secure.
Signed-off-by Steven Price <[email protected]>--- arch/arm64/include/asm/kvm_emulate.h | 10 +++++ arch/arm64/include/asm/kvm_rme.h | 12 ++++++ arch/arm64/kvm/mmu.c | 64 +++++++++++++++++++++++++--- arch/arm64/kvm/rme.c | 48 +++++++++++++++++++++ 4 files changed, 128 insertions(+), 6 deletions(-)arch/arm64/include/asm/kvm_emulate.h +0
-0@@ -502,6 +502,16 @@ static inline enum realm_state kvm_realm_state(struct kvm *kvm)return READ_ONCE (kvm->arch.realm.state); }
arch/arm64/include/asm/kvm_emulate.h static inline enum realm_state kvm_realm_state(struct kvm *kvm) · line 514
Quoted 10 lines
arch/arm64/include/asm/kvm_emulate.h +10
-0+static inline gpa_t kvm_gpa_stolen_bits (struct kvm *kvm) +{ +if (kvm_is_realm (kvm)) { +struct realm *realm = &kvm->arch.realm; + +return BIT (realm->ia_bits -1 ); + } +return 0 ; +} +
"stolen" seems a little bit vague. Maybe "shared" bit would be better as SEV-SNP has C bit and TDX has shared bit. It would be nice to align with the common knowledge.
Also, it would be nice to change the name of gpa_stolen_mask accordingly.
Quoted 104 lines
arch/arm64/include/asm/kvm_emulate.h +0
-0static inline bool vcpu_is_rec (struct kvm_vcpu *vcpu) {if (static_branch_unlikely (&kvm_rme_is_available))arch/arm64/include/asm/kvm_rme.h +12
-0@@ -50,6 +50,18 @@ void kvm_destroy_rec(struct kvm_vcpu *vcpu);int kvm_rec_enter (struct kvm_vcpu *vcpu);int handle_rme_exit (struct kvm_vcpu *vcpu,int rec_run_status); +void kvm_realm_unmap_range (struct kvm *kvm,unsigned long ipa,u64 size); +int realm_map_protected (struct realm *realm, +unsigned long hva, +unsigned long base_ipa, +struct page *dst_page, +unsigned long map_size, +struct kvm_mmu_memory_cache *memcache); +int realm_map_non_secure (struct realm *realm, +unsigned long ipa, +struct page *page, +unsigned long map_size, +struct kvm_mmu_memory_cache *memcache);int realm_set_ipa_state (struct kvm_vcpu *vcpu,unsigned long addr,unsigned long end,unsigned long ripas);arch/arm64/kvm/mmu.c +35
-3@@ -235,8 +235,13 @@ static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64lockdep_assert_held_write (&kvm->mmu_lock);WARN_ON (size & ~PAGE_MASK ); -WARN_ON (stage2_apply_range (kvm, start, end, kvm_pgtable_stage2_unmap, - may_block)); + +if (kvm_is_realm (kvm)) +kvm_realm_unmap_range (kvm, start, size); +else +WARN_ON (stage2_apply_range (kvm, start, end, + kvm_pgtable_stage2_unmap, + may_block)); }static void unmap_stage2_range (struct kvm_s2_mmu *mmu,phys_addr_t start,u64 size)@@ -250,7 +255,11 @@ static void stage2_flush_memslot(struct kvm *kvm,phys_addr_t addr = memslot->base_gfn <<PAGE_SHIFT ;phys_addr_t end = addr +PAGE_SIZE * memslot->npages; -stage2_apply_range_resched (kvm, addr, end, kvm_pgtable_stage2_flush); +if (kvm_is_realm (kvm)) +kvm_realm_unmap_range (kvm, addr, end - addr); +else +stage2_apply_range_resched (kvm, addr, end, + kvm_pgtable_stage2_flush); }/** @@ -818,6 +827,10 @@ void stage2_unmap_vm(struct kvm *kvm)struct kvm_memory_slot *memslot;int idx, bkt; +/* For realms this is handled by the RMM so nothing to do here */ +if (kvm_is_realm (kvm)) +return ; + idx =srcu_read_lock (&kvm->srcu);mmap_read_lock (current->mm);write_lock (&kvm->mmu_lock);@@ -840,6 +853,7 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu) pgt = mmu->pgt;if (kvm_is_realm (kvm) &&kvm_realm_state (kvm) !=REALM_STATE_DYING ) { +unmap_stage2_range (mmu,0 , (~0ULL ) &PAGE_MASK );write_unlock (&kvm->mmu_lock);kvm_realm_destroy_rtts (&kvm->arch.realm, pgt->ia_bits, pgt->start_level);@@ -1190,6 +1204,24 @@ static bool kvm_vma_mte_allowed(struct vm_area_struct *vma)return vma->vm_flags &VM_MTE_ALLOWED ; } +static int realm_map_ipa (struct kvm *kvm,phys_addr_t ipa,unsigned long hva, +kvm_pfn_t pfn,unsigned long map_size, +enum kvm_pgtable_prot prot, +struct kvm_mmu_memory_cache *memcache) +{ +struct realm *realm = &kvm->arch.realm; +struct page *page =pfn_to_page (pfn); + +if (WARN_ON (!(prot &KVM_PGTABLE_PROT_W ))) +return -EFAULT ; + +if (!realm_is_addr_protected (realm, ipa)) +return realm_map_non_secure (realm, ipa, page, map_size, + memcache); + +return realm_map_protected (realm, hva, ipa, page, map_size, memcache); +} +static int user_mem_abort (struct kvm_vcpu *vcpu,phys_addr_t fault_ipa,struct kvm_memory_slot *memslot,unsigned long hva,unsigned long fault_status)
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1250
Quoted 9 lines
arch/arm64/kvm/mmu.c +3
-0@@ -1210,9 +1242,15 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,unsigned long vma_pagesize, fault_granule;enum kvm_pgtable_prot prot =KVM_PGTABLE_PROT_R ;struct kvm_pgtable *pgt; +gpa_t gpa_stolen_mask =kvm_gpa_stolen_bits (vcpu->kvm); fault_granule =1UL <<ARM64_HW_PGTABLE_LEVEL_SHIFT (fault_level); write_fault =kvm_is_write_fault (vcpu); + +/* Realms cannot map read-only */
Out of curiosity, why? It would be nice to have more explanation in the comment.
Quoted 16 lines
arch/arm64/kvm/mmu.c +4
-1+if (vcpu_is_rec (vcpu)) + write_fault = true; + exec_fault =kvm_vcpu_trap_is_exec_fault (vcpu);VM_BUG_ON (write_fault && exec_fault);@@ -1272,7 +1310,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (vma_pagesize ==PMD_SIZE || vma_pagesize ==PUD_SIZE ) fault_ipa &= ~(vma_pagesize -1 ); - gfn = fault_ipa >>PAGE_SHIFT ; + gfn = (fault_ipa & ~gpa_stolen_mask) >>PAGE_SHIFT ;mmap_read_unlock (current->mm);/*
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1387
Quoted 6 lines
arch/arm64/kvm/mmu.c +2
-1@@ -1345,7 +1383,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,* If we are not forced to use page mapping, check if we are * backed by a THP and thus use block mapping if possible. */ -if (vma_pagesize ==PAGE_SIZE && !(force_pte || device)) { +/* FIXME: We shouldn't need to disable this for realms */ +if (vma_pagesize ==PAGE_SIZE && !(force_pte || device ||kvm_is_realm (kvm))) {
Why do we have to disable this temporarily?
Quoted 39 lines
arch/arm64/kvm/mmu.c +6
-1if (fault_status ==FSC_PERM && fault_granule >PAGE_SIZE ) vma_pagesize = fault_granule;else @@ -1382,6 +1421,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,*/ if (fault_status ==FSC_PERM && vma_pagesize == fault_granule) ret =kvm_pgtable_stage2_relax_perms (pgt, fault_ipa, prot); +else if (kvm_is_realm (kvm)) + ret =realm_map_ipa (kvm, fault_ipa, hva, pfn, vma_pagesize, + prot, memcache);else ret = kvm_pgtable_stage2_map(pgt, fault_ipa, vma_pagesize, __pfn_to_phys(pfn), prot,@@ -1437,6 +1479,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)struct kvm_memory_slot *memslot;unsigned long hva;bool is_iabt, write_fault, writable; +gpa_t gpa_stolen_mask =kvm_gpa_stolen_bits (vcpu->kvm);gfn_t gfn;int ret, idx;@@ -1491,7 +1534,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) idx =srcu_read_lock (&vcpu->kvm->srcu); - gfn = fault_ipa >>PAGE_SHIFT ; + gfn = (fault_ipa & ~gpa_stolen_mask) >>PAGE_SHIFT ; memslot =gfn_to_memslot (vcpu->kvm, gfn); hva =gfn_to_hva_memslot_prot (memslot, gfn, &writable); write_fault =kvm_is_write_fault (vcpu);@@ -1536,6 +1579,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)* of the page size. */ fault_ipa |=kvm_vcpu_get_hfar (vcpu) & ((1 <<12 ) -1 ); + fault_ipa &= ~gpa_stolen_mask; ret =io_mem_abort (vcpu, fault_ipa); goto out_unlock; }
arch/arm64/kvm/mmu.c bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) · line 1663
Quoted 3 lines
arch/arm64/kvm/mmu.c +0
-0@@ -1617,6 +1661,10 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)if (!kvm->arch.mmu.pgt)return false;
Does the unprotected (shared) region of a realm support aging?
Quoted 28 lines
arch/arm64/kvm/mmu.c +8
-0+/* We don't support aging for Realms */ +if (kvm_is_realm (kvm)) +return true; +WARN_ON (size !=PAGE_SIZE && size !=PMD_SIZE && size !=PUD_SIZE ); kpte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt,@@ -1630,6 +1678,10 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)if (!kvm->arch.mmu.pgt)return false; +/* We don't support aging for Realms */ +if (kvm_is_realm (kvm)) +return true; +return kvm_pgtable_stage2_is_young (kvm->arch.mmu.pgt, range->start <<PAGE_SHIFT ); }arch/arm64/kvm/rme.c +2
-0@@ -608,6 +608,54 @@ int realm_map_protected(struct realm *realm,return -ENXIO ; } +int realm_map_non_secure(struct realm *realm, + unsigned long ipa,
arch/arm64/kvm/rme.c int realm_map_protected(struct realm *realm, · line 622
Quoted 10 lines
arch/arm64/kvm/rme.c +10
-0+struct page *page, + unsigned long map_size, + struct kvm_mmu_memory_cache *memcache) +{ + phys_addr_t rd = virt_to_phys(realm->rd); +int map_level; +int ret =0 ; +unsigned long desc =page_to_phys (page) | + PTE_S2_MEMATTR(MT_S2_FWB_NORMAL) | +/* FIXME: Read+Write permissions for now */
Why can't we handle the prot from the realm_map_ipa()? Working in progress? :)
Quoted 39 lines
arch/arm64/kvm/rme.c +36
-0+ (3 <<6 ) | +PTE_SHARED ; + +if (WARN_ON (!IS_ALIGNED (ipa, map_size))) +return -EINVAL ; + +switch (map_size) { +case PAGE_SIZE : + map_level =3 ; +break ; +case RME_L2_BLOCK_SIZE : + map_level =2 ; +break ; +default : +return -EINVAL ; + } + + ret =rmi_rtt_map_unprotected (rd, ipa, map_level, desc); + +if (RMI_RETURN_STATUS (ret) ==RMI_ERROR_RTT ) { +/* Create missing RTTs and retry */ +int level =RMI_RETURN_INDEX (ret); + + ret =realm_create_rtt_levels (realm, ipa, level, map_level, + memcache); +if (WARN_ON (ret)) +return -ENXIO ; + + ret =rmi_rtt_map_unprotected (rd, ipa, map_level, desc); + } +if (WARN_ON (ret)) +return -ENXIO ; + +return 0 ; +} +static int populate_par_region (struct kvm *kvm,phys_addr_t ipa_base,phys_addr_t ipa_end)
Re: [RFC PATCH 17/28] arm64: RME: Runtime faulting of memory
Quoted 27 lines · Zhi Wang
Quoted 24 lines · On Fri, 27 Jan 2023 11:29:21 +0000 Steven Price <[email protected]> wrote:
At runtime if the realm guest accesses memory which hasn't yet been mapped then KVM needs to either populate the region or fault the guest.
For memory in the lower (protected) region of IPA a fresh page is provided to the RMM which will zero the contents. For memory in the upper (shared) region of IPA, the memory from the memslot is mapped into the realm VM non secure.
Signed-off-by Steven Price <[email protected]>--- arch/arm64/include/asm/kvm_emulate.h | 10 +++++ arch/arm64/include/asm/kvm_rme.h | 12 ++++++ arch/arm64/kvm/mmu.c | 64 +++++++++++++++++++++++++--- arch/arm64/kvm/rme.c | 48 +++++++++++++++++++++ 4 files changed, 128 insertions(+), 6 deletions(-)arch/arm64/include/asm/kvm_emulate.h +0
-0@@ -502,6 +502,16 @@ static inline enum realm_state kvm_realm_state(struct kvm *kvm)return READ_ONCE (kvm->arch.realm.state); }
Quoted 14 lines
arch/arm64/include/asm/kvm_emulate.h static inline enum realm_state kvm_realm_state(struct kvm *kvm) · line 514
Quoted 10 lines
arch/arm64/include/asm/kvm_emulate.h +10
-0+static inline gpa_t kvm_gpa_stolen_bits (struct kvm *kvm) +{ +if (kvm_is_realm (kvm)) { +struct realm *realm = &kvm->arch.realm; + +return BIT (realm->ia_bits -1 ); + } +return 0 ; +} +"stolen" seems a little bit vague. Maybe "shared" bit would be better as SEV-SNP has C bit and TDX has shared bit. It would be nice to align with the common knowledge.
The Arm CCA term is the "protected" bit[1] - although the bit is backwards as it's cleared to indicate protected... so not ideal naming! ;)
But it's termed 'stolen' here as it's effectively removed from the set of value address bits. And this function is returning a mask of the bits that are not available as address bits. The naming was meant to be generic that this could encompass other features that need to reserve IPA bits.
But it's possible this is too generic and perhaps we should just deal with a single bit rather than potential masks. Alternatively we could invert this and return a set of valid bits:
static inline gpa_t kvm_gpa_valid_bits(struct kvm *kvm)
{
if (kvm_is_realm(kvm)) {
struct realm *realm = &kvm->arch.realm;
return ~BIT(realm->ia_bits - 1);
}
return ~(gpa_t)0;
}That would at least match the current usage where the inverse is what we need.
So SEV-SNP or TDX have a concept of a mask to apply to addresses from the guest? Can we steal any existing terms?
[1] Technically the spec only states: "Software in a Realm should treat the most significant bit of an IPA as a protection attribute." I don't think the bit is directly referred to in the spec as anything other than "the most significant bit". Although that in itself is confusing as it is the most significant *active* bit (i.e the configured IPA size changes which bit is used).
Quoted 111 lines
Also, it would be nice to change the name of
gpa_stolen_maskaccordingly.Quoted 109 lines
arch/arm64/include/asm/kvm_emulate.h +0
-0static inline bool vcpu_is_rec (struct kvm_vcpu *vcpu) {if (static_branch_unlikely (&kvm_rme_is_available))arch/arm64/include/asm/kvm_rme.h +12
-0@@ -50,6 +50,18 @@ void kvm_destroy_rec(struct kvm_vcpu *vcpu);int kvm_rec_enter (struct kvm_vcpu *vcpu);int handle_rme_exit (struct kvm_vcpu *vcpu,int rec_run_status); +void kvm_realm_unmap_range (struct kvm *kvm,unsigned long ipa,u64 size); +int realm_map_protected (struct realm *realm, +unsigned long hva, +unsigned long base_ipa, +struct page *dst_page, +unsigned long map_size, +struct kvm_mmu_memory_cache *memcache); +int realm_map_non_secure (struct realm *realm, +unsigned long ipa, +struct page *page, +unsigned long map_size, +struct kvm_mmu_memory_cache *memcache);int realm_set_ipa_state (struct kvm_vcpu *vcpu,unsigned long addr,unsigned long end,unsigned long ripas);arch/arm64/kvm/mmu.c +36
-3@@ -235,8 +235,13 @@ static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64lockdep_assert_held_write (&kvm->mmu_lock);WARN_ON (size & ~PAGE_MASK ); -WARN_ON (stage2_apply_range (kvm, start, end, kvm_pgtable_stage2_unmap, - may_block)); + +if (kvm_is_realm (kvm)) +kvm_realm_unmap_range (kvm, start, size); +else +WARN_ON (stage2_apply_range (kvm, start, end, + kvm_pgtable_stage2_unmap, + may_block)); }static void unmap_stage2_range (struct kvm_s2_mmu *mmu,phys_addr_t start,u64 size)@@ -250,7 +255,11 @@ static void stage2_flush_memslot(struct kvm *kvm,phys_addr_t addr = memslot->base_gfn <<PAGE_SHIFT ;phys_addr_t end = addr +PAGE_SIZE * memslot->npages; -stage2_apply_range_resched (kvm, addr, end, kvm_pgtable_stage2_flush); +if (kvm_is_realm (kvm)) +kvm_realm_unmap_range (kvm, addr, end - addr); +else +stage2_apply_range_resched (kvm, addr, end, + kvm_pgtable_stage2_flush); }/** @@ -818,6 +827,10 @@ void stage2_unmap_vm(struct kvm *kvm)struct kvm_memory_slot *memslot;int idx, bkt; +/* For realms this is handled by the RMM so nothing to do here */ +if (kvm_is_realm (kvm)) +return ; + idx =srcu_read_lock (&kvm->srcu);mmap_read_lock (current->mm);write_lock (&kvm->mmu_lock);@@ -840,6 +853,7 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu) pgt = mmu->pgt;if (kvm_is_realm (kvm) &&kvm_realm_state (kvm) !=REALM_STATE_DYING ) { +unmap_stage2_range (mmu,0 , (~0ULL ) &PAGE_MASK );write_unlock (&kvm->mmu_lock);kvm_realm_destroy_rtts (&kvm->arch.realm, pgt->ia_bits, pgt->start_level);@@ -1190,6 +1204,24 @@ static bool kvm_vma_mte_allowed(struct vm_area_struct *vma)return vma->vm_flags &VM_MTE_ALLOWED ; } +static int realm_map_ipa (struct kvm *kvm,phys_addr_t ipa,unsigned long hva, +kvm_pfn_t pfn,unsigned long map_size, +enum kvm_pgtable_prot prot, +struct kvm_mmu_memory_cache *memcache) +{ +struct realm *realm = &kvm->arch.realm; +struct page *page =pfn_to_page (pfn); + +if (WARN_ON (!(prot &KVM_PGTABLE_PROT_W ))) +return -EFAULT ; + +if (!realm_is_addr_protected (realm, ipa)) +return realm_map_non_secure (realm, ipa, page, map_size, + memcache); + +return realm_map_protected (realm, hva, ipa, page, map_size, memcache); +} +static int user_mem_abort (struct kvm_vcpu *vcpu,phys_addr_t fault_ipa,struct kvm_memory_slot *memslot,unsigned long hva,unsigned long fault_status)@@ -1210,9 +1242,15 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,unsigned long vma_pagesize, fault_granule;enum kvm_pgtable_prot prot =KVM_PGTABLE_PROT_R ;struct kvm_pgtable *pgt; +gpa_t gpa_stolen_mask =kvm_gpa_stolen_bits (vcpu->kvm);
Quoted 7 lines
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1250
Quoted 4 lines
arch/arm64/kvm/mmu.c +2
-0fault_granule =1UL <<ARM64_HW_PGTABLE_LEVEL_SHIFT (fault_level); write_fault =kvm_is_write_fault (vcpu); + +/* Realms cannot map read-only */ Out of curiosity, why? It would be nice to have more explanation in the comment.
The RMM specification doesn't support mapping protected memory read only. I don't believe there is any reason why it couldn't, but equally I don't think there any use cases for a guest needing read-only pages so this just isn't supported by the RMM. Since the page is necessarily taken away from the host it's fairly irrelevant (from the host's perspective) whether it is actually read only or not.
However, this is technically wrong for the case of unprotected (shared) pages - it should be possible to map those read only. But I need to have a think about how to fix that up.
Quoted 14 lines
Quoted 14 lines
arch/arm64/kvm/mmu.c +4
-1+if (vcpu_is_rec (vcpu)) + write_fault = true; + exec_fault =kvm_vcpu_trap_is_exec_fault (vcpu);VM_BUG_ON (write_fault && exec_fault);@@ -1272,7 +1310,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (vma_pagesize ==PMD_SIZE || vma_pagesize ==PUD_SIZE ) fault_ipa &= ~(vma_pagesize -1 ); - gfn = fault_ipa >>PAGE_SHIFT ; + gfn = (fault_ipa & ~gpa_stolen_mask) >>PAGE_SHIFT ;mmap_read_unlock (current->mm);
Quoted 10 lines
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1387
Quoted 8 lines
arch/arm64/kvm/mmu.c +2
-1/* @@ -1345,7 +1383,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,* If we are not forced to use page mapping, check if we are * backed by a THP and thus use block mapping if possible. */ -if (vma_pagesize ==PAGE_SIZE && !(force_pte || device)) { +/* FIXME: We shouldn't need to disable this for realms */ +if (vma_pagesize ==PAGE_SIZE && !(force_pte || device ||kvm_is_realm (kvm))) {Why do we have to disable this temporarily?
The current uABI (not using memfd) has some serious issues regarding huge page support. KVM normally follows the user space mappings of the memslot - so if user space has a huge page (transparent or hugetlbs) then stage 2 for the guest also gets one.
However realms sometimes require that the stage 2 differs. The main examples are:
* RIPAS - if part of a huge page is RIPAS_RAM and part RIPAS_EMPTY then
the huge page would have to be split.
* Initially populated memory: basically the same as above - if the
populated memory doesn't perfectly align with huge pages, then the head/tail pages would need to be broken up.
Removing this hack allows the huge pages to be created in stage 2, but then causes overmapping of the initial contents, then later on when the VMM (or guest) attempts to change the properties of the misaligned tail it gets an error because the pages are already present in stage 2.
The planned solution to all this is to stop following the user space page tables and create huge pages opportunistically from the memfd that backs the protected range. For now this hack exists to avoid things "randomly" failing when e.g. the initial kernel image isn't huge page aligned. In theory it should be possible to make this work with the current uABI, but it's not worth it when we know we're replacing it.
Quoted 36 lines
Quoted 36 lines
arch/arm64/kvm/mmu.c +6
-1if (fault_status ==FSC_PERM && fault_granule >PAGE_SIZE ) vma_pagesize = fault_granule;else @@ -1382,6 +1421,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,*/ if (fault_status ==FSC_PERM && vma_pagesize == fault_granule) ret =kvm_pgtable_stage2_relax_perms (pgt, fault_ipa, prot); +else if (kvm_is_realm (kvm)) + ret =realm_map_ipa (kvm, fault_ipa, hva, pfn, vma_pagesize, + prot, memcache);else ret = kvm_pgtable_stage2_map(pgt, fault_ipa, vma_pagesize, __pfn_to_phys(pfn), prot,@@ -1437,6 +1479,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)struct kvm_memory_slot *memslot;unsigned long hva;bool is_iabt, write_fault, writable; +gpa_t gpa_stolen_mask =kvm_gpa_stolen_bits (vcpu->kvm);gfn_t gfn;int ret, idx;@@ -1491,7 +1534,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) idx =srcu_read_lock (&vcpu->kvm->srcu); - gfn = fault_ipa >>PAGE_SHIFT ; + gfn = (fault_ipa & ~gpa_stolen_mask) >>PAGE_SHIFT ; memslot =gfn_to_memslot (vcpu->kvm, gfn); hva =gfn_to_hva_memslot_prot (memslot, gfn, &writable); write_fault =kvm_is_write_fault (vcpu);@@ -1536,6 +1579,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)* of the page size. */ fault_ipa |=kvm_vcpu_get_hfar (vcpu) & ((1 <<12 ) -1 ); + fault_ipa &= ~gpa_stolen_mask; ret =io_mem_abort (vcpu, fault_ipa);
Quoted 8 lines
arch/arm64/kvm/mmu.c bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) · line 1663
Quoted 6 lines
arch/arm64/kvm/mmu.c +0
-0goto out_unlock; }@@ -1617,6 +1661,10 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)if (!kvm->arch.mmu.pgt)return false;Does the unprotected (shared) region of a realm support aging?
In theory this should be possible to support by unmapping the NS entry and handling the fault. But the hardware access flag optimisation isn't available with the RMM, and the overhead of RMI calls to unmap/map could be significant.
For now this isn't something we've looked at, but I guess it might be worth trying out when we have some real hardware to benchmark on.
Quoted 26 lines
Quoted 26 lines
arch/arm64/kvm/mmu.c +8
-0+/* We don't support aging for Realms */ +if (kvm_is_realm (kvm)) +return true; +WARN_ON (size !=PAGE_SIZE && size !=PMD_SIZE && size !=PUD_SIZE ); kpte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt,@@ -1630,6 +1678,10 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)if (!kvm->arch.mmu.pgt)return false; +/* We don't support aging for Realms */ +if (kvm_is_realm (kvm)) +return true; +return kvm_pgtable_stage2_is_young (kvm->arch.mmu.pgt, range->start <<PAGE_SHIFT ); }arch/arm64/kvm/rme.c +0
-0@@ -608,6 +608,54 @@ int realm_map_protected(struct realm *realm,return -ENXIO ; }
Quoted 13 lines
arch/arm64/kvm/rme.c int realm_map_protected(struct realm *realm, · line 622
Quoted 12 lines
arch/arm64/kvm/rme.c +12
-0+int realm_map_non_secure (struct realm *realm, +unsigned long ipa, +struct page *page, +unsigned long map_size, +struct kvm_mmu_memory_cache *memcache) +{ +phys_addr_t rd =virt_to_phys (realm->rd); +int map_level; +int ret =0 ; +unsigned long desc =page_to_phys (page) | + PTE_S2_MEMATTR(MT_S2_FWB_NORMAL) | +/* FIXME: Read+Write permissions for now */ Why can't we handle the prot from the
realm_map_ipa()? Working in progress? :)
Yes, work in progress - this comes from the "Realms cannot map read-only" in user_mem_abort() above. Since all faults are treated as write faults we need to upgrade to read/write here too.
The prot in realm_map_ipa isn't actually useful currently because we simply WARN_ON and return if it doesn't have PROT_W. Again this needs to be fixed! It's on my todo list ;)
Steve
Quoted 40 lines
Quoted 39 lines
arch/arm64/kvm/rme.c +36
-0+ (3 <<6 ) | +PTE_SHARED ; + +if (WARN_ON (!IS_ALIGNED (ipa, map_size))) +return -EINVAL ; + +switch (map_size) { +case PAGE_SIZE : + map_level =3 ; +break ; +case RME_L2_BLOCK_SIZE : + map_level =2 ; +break ; +default : +return -EINVAL ; + } + + ret =rmi_rtt_map_unprotected (rd, ipa, map_level, desc); + +if (RMI_RETURN_STATUS (ret) ==RMI_ERROR_RTT ) { +/* Create missing RTTs and retry */ +int level =RMI_RETURN_INDEX (ret); + + ret =realm_create_rtt_levels (realm, ipa, level, map_level, + memcache); +if (WARN_ON (ret)) +return -ENXIO ; + + ret =rmi_rtt_map_unprotected (rd, ipa, map_level, desc); + } +if (WARN_ON (ret)) +return -ENXIO ; + +return 0 ; +} +static int populate_par_region (struct kvm *kvm,phys_addr_t ipa_base,phys_addr_t ipa_end)
Re: [RFC PATCH 17/28] arm64: RME: Runtime faulting of memory
Quoted 66 lines · On Fri, 10 Mar 2023 15:47:19 +0000 Steven Price <[email protected]> wrote:
Quoted 27 lines · Zhi Wang
Quoted 24 lines · On Fri, 27 Jan 2023 11:29:21 +0000 Steven Price <[email protected]> wrote:
At runtime if the realm guest accesses memory which hasn't yet been mapped then KVM needs to either populate the region or fault the guest.
For memory in the lower (protected) region of IPA a fresh page is provided to the RMM which will zero the contents. For memory in the upper (shared) region of IPA, the memory from the memslot is mapped into the realm VM non secure.
Signed-off-by Steven Price <[email protected]>--- arch/arm64/include/asm/kvm_emulate.h | 10 +++++ arch/arm64/include/asm/kvm_rme.h | 12 ++++++ arch/arm64/kvm/mmu.c | 64 +++++++++++++++++++++++++--- arch/arm64/kvm/rme.c | 48 +++++++++++++++++++++ 4 files changed, 128 insertions(+), 6 deletions(-)arch/arm64/include/asm/kvm_emulate.h +0
-0@@ -502,6 +502,16 @@ static inline enum realm_state kvm_realm_state(struct kvm *kvm)return READ_ONCE (kvm->arch.realm.state); }Quoted 14 lines
arch/arm64/include/asm/kvm_emulate.h static inline enum realm_state kvm_realm_state(struct kvm *kvm) · line 514
Quoted 10 lines
arch/arm64/include/asm/kvm_emulate.h +10
-0+static inline gpa_t kvm_gpa_stolen_bits (struct kvm *kvm) +{ +if (kvm_is_realm (kvm)) { +struct realm *realm = &kvm->arch.realm; + +return BIT (realm->ia_bits -1 ); + } +return 0 ; +} +"stolen" seems a little bit vague. Maybe "shared" bit would be better as SEV-SNP has C bit and TDX has shared bit. It would be nice to align with the common knowledge.
The Arm CCA term is the "protected" bit[1] - although the bit is backwards as it's cleared to indicate protected... so not ideal naming! ;)
But it's termed 'stolen' here as it's effectively removed from the set of value address bits. And this function is returning a mask of the bits that are not available as address bits. The naming was meant to be generic that this could encompass other features that need to reserve IPA bits.
But it's possible this is too generic and perhaps we should just deal with a single bit rather than potential masks. Alternatively we could invert this and return a set of valid bits:
static inline
gpa_tkvm_gpa_valid_bits(struct kvm *kvm){ if (kvm_is_realm(kvm)) { struct realm *realm = &kvm->arch.realm; return ~BIT(realm->ia_bits - 1); } return ~(gpa_t)0; }
Quoted 6 lines
That would at least match the current usage where the inverse is what we need.
So SEV-SNP or TDX have a concept of a mask to apply to addresses from the guest? Can we steal any existing terms?
In a general level, they are using "shared"/"private". TDX is using a function kvm_gfn_shared_mask() to get the mask and three other marcos to apply the mask on GPA (IPA)[1]. SEV-SNP is re-using SME macros e.g. __sme_clr() to apply the mask[2].
Guess we can take them as an reference: using an inline function to get the protected_bit_mask, like kvm_ipa_protected_mask() with the spec text you pasted in the comment of the function. The name echoes the spec description.
Then another necessary functions like kvm_gpa_{is, to}_{shared, private} , which applies the mask to a GPA(IPA), to echo the terms in the generic KVM knowledge. (Guess we can refine that with realm_is_addr_protected()).
[1] https://www.spinics.net/lists/kernel/msg4718104.html
[2] https://lore.kernel.org/lkml/[email protected]/
Quoted 134 lines
[1] Technically the spec only states: "Software in a Realm should treat the most significant bit of an IPA as a protection attribute." I don't think the bit is directly referred to in the spec as anything other than "the most significant bit". Although that in itself is confusing as it is the most significant *active* bit (i.e the configured IPA size changes which bit is used).
Quoted 111 lines
Also, it would be nice to change the name of
gpa_stolen_maskaccordingly.Quoted 109 lines
arch/arm64/include/asm/kvm_emulate.h +0
-0static inline bool vcpu_is_rec (struct kvm_vcpu *vcpu) {if (static_branch_unlikely (&kvm_rme_is_available))arch/arm64/include/asm/kvm_rme.h +12
-0@@ -50,6 +50,18 @@ void kvm_destroy_rec(struct kvm_vcpu *vcpu);int kvm_rec_enter (struct kvm_vcpu *vcpu);int handle_rme_exit (struct kvm_vcpu *vcpu,int rec_run_status); +void kvm_realm_unmap_range (struct kvm *kvm,unsigned long ipa,u64 size); +int realm_map_protected (struct realm *realm, +unsigned long hva, +unsigned long base_ipa, +struct page *dst_page, +unsigned long map_size, +struct kvm_mmu_memory_cache *memcache); +int realm_map_non_secure (struct realm *realm, +unsigned long ipa, +struct page *page, +unsigned long map_size, +struct kvm_mmu_memory_cache *memcache);int realm_set_ipa_state (struct kvm_vcpu *vcpu,unsigned long addr,unsigned long end,unsigned long ripas);arch/arm64/kvm/mmu.c +36
-3@@ -235,8 +235,13 @@ static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64lockdep_assert_held_write (&kvm->mmu_lock);WARN_ON (size & ~PAGE_MASK ); -WARN_ON (stage2_apply_range (kvm, start, end, kvm_pgtable_stage2_unmap, - may_block)); + +if (kvm_is_realm (kvm)) +kvm_realm_unmap_range (kvm, start, size); +else +WARN_ON (stage2_apply_range (kvm, start, end, + kvm_pgtable_stage2_unmap, + may_block)); }static void unmap_stage2_range (struct kvm_s2_mmu *mmu,phys_addr_t start,u64 size)@@ -250,7 +255,11 @@ static void stage2_flush_memslot(struct kvm *kvm,phys_addr_t addr = memslot->base_gfn <<PAGE_SHIFT ;phys_addr_t end = addr +PAGE_SIZE * memslot->npages; -stage2_apply_range_resched (kvm, addr, end, kvm_pgtable_stage2_flush); +if (kvm_is_realm (kvm)) +kvm_realm_unmap_range (kvm, addr, end - addr); +else +stage2_apply_range_resched (kvm, addr, end, + kvm_pgtable_stage2_flush); }/** @@ -818,6 +827,10 @@ void stage2_unmap_vm(struct kvm *kvm)struct kvm_memory_slot *memslot;int idx, bkt; +/* For realms this is handled by the RMM so nothing to do here */ +if (kvm_is_realm (kvm)) +return ; + idx =srcu_read_lock (&kvm->srcu);mmap_read_lock (current->mm);write_lock (&kvm->mmu_lock);@@ -840,6 +853,7 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu) pgt = mmu->pgt;if (kvm_is_realm (kvm) &&kvm_realm_state (kvm) !=REALM_STATE_DYING ) { +unmap_stage2_range (mmu,0 , (~0ULL ) &PAGE_MASK );write_unlock (&kvm->mmu_lock);kvm_realm_destroy_rtts (&kvm->arch.realm, pgt->ia_bits, pgt->start_level);@@ -1190,6 +1204,24 @@ static bool kvm_vma_mte_allowed(struct vm_area_struct *vma)return vma->vm_flags &VM_MTE_ALLOWED ; } +static int realm_map_ipa (struct kvm *kvm,phys_addr_t ipa,unsigned long hva, +kvm_pfn_t pfn,unsigned long map_size, +enum kvm_pgtable_prot prot, +struct kvm_mmu_memory_cache *memcache) +{ +struct realm *realm = &kvm->arch.realm; +struct page *page =pfn_to_page (pfn); + +if (WARN_ON (!(prot &KVM_PGTABLE_PROT_W ))) +return -EFAULT ; + +if (!realm_is_addr_protected (realm, ipa)) +return realm_map_non_secure (realm, ipa, page, map_size, + memcache); + +return realm_map_protected (realm, hva, ipa, page, map_size, memcache); +} +static int user_mem_abort (struct kvm_vcpu *vcpu,phys_addr_t fault_ipa,struct kvm_memory_slot *memslot,unsigned long hva,unsigned long fault_status)@@ -1210,9 +1242,15 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,unsigned long vma_pagesize, fault_granule;enum kvm_pgtable_prot prot =KVM_PGTABLE_PROT_R ;struct kvm_pgtable *pgt; +gpa_t gpa_stolen_mask =kvm_gpa_stolen_bits (vcpu->kvm);Quoted 7 lines
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1250
Quoted 4 lines
arch/arm64/kvm/mmu.c +2
-0fault_granule =1UL <<ARM64_HW_PGTABLE_LEVEL_SHIFT (fault_level); write_fault =kvm_is_write_fault (vcpu); + +/* Realms cannot map read-only */ Out of curiosity, why? It would be nice to have more explanation in the comment.
The RMM specification doesn't support mapping protected memory read only. I don't believe there is any reason why it couldn't, but equally I don't think there any use cases for a guest needing read-only pages so this just isn't supported by the RMM. Since the page is necessarily taken away from the host it's fairly irrelevant (from the host's perspective) whether it is actually read only or not.
Quoted 3 lines
However, this is technically wrong for the case of unprotected (shared) pages - it should be possible to map those read only. But I need to have a think about how to fix that up.
If the fault IPA carries the protected bit, can't we do like:
if (vcpu_is_rec(vcpu) && fault_ipa_is_protected)
write_fault = true
Are there still other gaps?
Quoted 46 lines
Quoted 15 lines
Quoted 15 lines
arch/arm64/kvm/mmu.c +4
-1+if (vcpu_is_rec (vcpu)) + write_fault = true; + exec_fault =kvm_vcpu_trap_is_exec_fault (vcpu);VM_BUG_ON (write_fault && exec_fault);@@ -1272,7 +1310,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (vma_pagesize ==PMD_SIZE || vma_pagesize ==PUD_SIZE ) fault_ipa &= ~(vma_pagesize -1 ); - gfn = fault_ipa >>PAGE_SHIFT ; + gfn = (fault_ipa & ~gpa_stolen_mask) >>PAGE_SHIFT ;mmap_read_unlock (current->mm);Quoted 10 lines
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1387
Quoted 8 lines
arch/arm64/kvm/mmu.c +2
-1/* @@ -1345,7 +1383,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,* If we are not forced to use page mapping, check if we are * backed by a THP and thus use block mapping if possible. */ -if (vma_pagesize ==PAGE_SIZE && !(force_pte || device)) { +/* FIXME: We shouldn't need to disable this for realms */ +if (vma_pagesize ==PAGE_SIZE && !(force_pte || device ||kvm_is_realm (kvm))) {Why do we have to disable this temporarily?
The current uABI (not using memfd) has some serious issues regarding huge page support. KVM normally follows the user space mappings of the memslot - so if user space has a huge page (transparent or hugetlbs) then stage 2 for the guest also gets one.
However realms sometimes require that the stage 2 differs. The main examples are:
* RIPAS - if part of a huge page is
RIPAS_RAMand partRIPAS_EMPTYthen
the huge page would have to be split.* Initially populated memory: basically the same as above - if the
populated memory doesn't perfectly align with huge pages, then the head/tail pages would need to be broken up.Removing this hack allows the huge pages to be created in stage 2, but then causes overmapping of the initial contents, then later on when the VMM (or guest) attempts to change the properties of the misaligned tail it gets an error because the pages are already present in stage 2.
Quoted 6 lines
The planned solution to all this is to stop following the user space page tables and create huge pages opportunistically from the memfd that backs the protected range. For now this hack exists to avoid things "randomly" failing when e.g. the initial kernel image isn't huge page aligned. In theory it should be possible to make this work with the current uABI, but it's not worth it when we know we're replacing it.
I see. Will dig it and see if there is any idea come to my mind.
Quoted 145 lines
Quoted 37 lines
Quoted 37 lines
arch/arm64/kvm/mmu.c +6
-1if (fault_status ==FSC_PERM && fault_granule >PAGE_SIZE ) vma_pagesize = fault_granule;else @@ -1382,6 +1421,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,*/ if (fault_status ==FSC_PERM && vma_pagesize == fault_granule) ret =kvm_pgtable_stage2_relax_perms (pgt, fault_ipa, prot); +else if (kvm_is_realm (kvm)) + ret =realm_map_ipa (kvm, fault_ipa, hva, pfn, vma_pagesize, + prot, memcache);else ret = kvm_pgtable_stage2_map(pgt, fault_ipa, vma_pagesize, __pfn_to_phys(pfn), prot,@@ -1437,6 +1479,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)struct kvm_memory_slot *memslot;unsigned long hva;bool is_iabt, write_fault, writable; +gpa_t gpa_stolen_mask =kvm_gpa_stolen_bits (vcpu->kvm);gfn_t gfn;int ret, idx;@@ -1491,7 +1534,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) idx =srcu_read_lock (&vcpu->kvm->srcu); - gfn = fault_ipa >>PAGE_SHIFT ; + gfn = (fault_ipa & ~gpa_stolen_mask) >>PAGE_SHIFT ; memslot =gfn_to_memslot (vcpu->kvm, gfn); hva =gfn_to_hva_memslot_prot (memslot, gfn, &writable); write_fault =kvm_is_write_fault (vcpu);@@ -1536,6 +1579,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)* of the page size. */ fault_ipa |=kvm_vcpu_get_hfar (vcpu) & ((1 <<12 ) -1 ); + fault_ipa &= ~gpa_stolen_mask; ret =io_mem_abort (vcpu, fault_ipa);Quoted 8 lines
arch/arm64/kvm/mmu.c bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) · line 1663
Quoted 6 lines
arch/arm64/kvm/mmu.c +0
-0goto out_unlock; }@@ -1617,6 +1661,10 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)if (!kvm->arch.mmu.pgt)return false;Does the unprotected (shared) region of a realm support aging?
In theory this should be possible to support by unmapping the NS entry and handling the fault. But the hardware access flag optimisation isn't available with the RMM, and the overhead of RMI calls to unmap/map could be significant.
For now this isn't something we've looked at, but I guess it might be worth trying out when we have some real hardware to benchmark on.
Quoted 26 lines
Quoted 26 lines
arch/arm64/kvm/mmu.c +8
-0+/* We don't support aging for Realms */ +if (kvm_is_realm (kvm)) +return true; +WARN_ON (size !=PAGE_SIZE && size !=PMD_SIZE && size !=PUD_SIZE ); kpte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt,@@ -1630,6 +1678,10 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)if (!kvm->arch.mmu.pgt)return false; +/* We don't support aging for Realms */ +if (kvm_is_realm (kvm)) +return true; +return kvm_pgtable_stage2_is_young (kvm->arch.mmu.pgt, range->start <<PAGE_SHIFT ); }arch/arm64/kvm/rme.c +0
-0@@ -608,6 +608,54 @@ int realm_map_protected(struct realm *realm,return -ENXIO ; }Quoted 13 lines
arch/arm64/kvm/rme.c int realm_map_protected(struct realm *realm, · line 622
Quoted 12 lines
arch/arm64/kvm/rme.c +12
-0+int realm_map_non_secure (struct realm *realm, +unsigned long ipa, +struct page *page, +unsigned long map_size, +struct kvm_mmu_memory_cache *memcache) +{ +phys_addr_t rd =virt_to_phys (realm->rd); +int map_level; +int ret =0 ; +unsigned long desc =page_to_phys (page) | + PTE_S2_MEMATTR(MT_S2_FWB_NORMAL) | +/* FIXME: Read+Write permissions for now */ Why can't we handle the prot from the
realm_map_ipa()? Working in progress? :)Yes, work in progress - this comes from the "Realms cannot map read-only" in
user_mem_abort()above. Since all faults are treated as write faults we need to upgrade to read/write here too.The prot in
realm_map_ipaisn't actually useful currently because we simplyWARN_ONand return if it doesn't havePROT_W. Again this needs to be fixed! It's on my todo list ;)Steve
Quoted 40 lines
Quoted 39 lines
arch/arm64/kvm/rme.c +36
-0+ (3 <<6 ) | +PTE_SHARED ; + +if (WARN_ON (!IS_ALIGNED (ipa, map_size))) +return -EINVAL ; + +switch (map_size) { +case PAGE_SIZE : + map_level =3 ; +break ; +case RME_L2_BLOCK_SIZE : + map_level =2 ; +break ; +default : +return -EINVAL ; + } + + ret =rmi_rtt_map_unprotected (rd, ipa, map_level, desc); + +if (RMI_RETURN_STATUS (ret) ==RMI_ERROR_RTT ) { +/* Create missing RTTs and retry */ +int level =RMI_RETURN_INDEX (ret); + + ret =realm_create_rtt_levels (realm, ipa, level, map_level, + memcache); +if (WARN_ON (ret)) +return -ENXIO ; + + ret =rmi_rtt_map_unprotected (rd, ipa, map_level, desc); + } +if (WARN_ON (ret)) +return -ENXIO ; + +return 0 ; +} +static int populate_par_region (struct kvm *kvm,phys_addr_t ipa_base,phys_addr_t ipa_end)
RFC PATCH 18/28 KVM: arm64: Handle realm VCPU load
In reply to Steven PriceWhen loading a realm VCPU much of the work is handled by the RMM so only some of the actions are required. Rearrange kvm_arch_vcpu_load() slightly so we can bail out early for a realm guest.
--- arch/arm64/kvm/arm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
arch/arm64/kvm/arm.c +13 -7
@@ -451,19 +451,25 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) vcpu->cpu = cpu; +if (single_task_running ()) +vcpu_clear_wfx_traps (vcpu); +else +vcpu_set_wfx_traps (vcpu); +kvm_vgic_load (vcpu);kvm_timer_vcpu_load (vcpu); + +if (kvm_arm_is_pvtime_enabled (&vcpu->arch)) +kvm_make_request (KVM_REQ_RECORD_STEAL , vcpu); + +/* No additional state needs to be loaded on Realmed VMs */ +if (vcpu_is_rec (vcpu)) +return ; +if (has_vhe ())kvm_vcpu_load_sysregs_vhe (vcpu);kvm_arch_vcpu_load_fp (vcpu);kvm_vcpu_pmu_restore_guest (vcpu); -if (kvm_arm_is_pvtime_enabled (&vcpu->arch)) -kvm_make_request (KVM_REQ_RECORD_STEAL , vcpu); - -if (single_task_running ()) -vcpu_clear_wfx_traps (vcpu); -else -vcpu_set_wfx_traps (vcpu);if (vcpu_has_ptrauth (vcpu))vcpu_ptrauth_disable (vcpu);
Signature · 1 line
2.34.1
RFC PATCH 19/28 KVM: arm64: Validate register access for a Realm VM
In reply to Steven PriceThe RMM only allows setting the lower GPRS (x0-x7) and PC for a realm guest. Check this in kvm_arm_set_reg() so that the VMM can receive a suitable error return if other registers are accessed.
--- arch/arm64/kvm/guest.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
arch/arm64/kvm/guest.c +26 -0
@@ -768,12 +768,38 @@ int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)return kvm_arm_sys_reg_get_reg (vcpu, reg); } +/* +* The RMI ABI only enables setting the lower GPRs (x0-x7) and PC. +* All other registers are reset to architectural or otherwise defined reset +* values by the RMM +*/ +static bool validate_realm_set_reg (struct kvm_vcpu *vcpu, +const struct kvm_one_reg *reg) +{ +u64 off =core_reg_offset_from_id (reg->id); + +if ((reg->id &KVM_REG_ARM_COPROC_MASK ) !=KVM_REG_ARM_CORE ) +return false; + +switch (off) { + case KVM_REG_ARM_CORE_REG(regs.regs[0]) ... +KVM_REG_ARM_CORE_REG (regs.regs[7 ]): +case KVM_REG_ARM_CORE_REG (regs.pc): +return true; + } + +return false; +} +int kvm_arm_set_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg) {/* We currently use nothing arch-specific in upper 32 bits */ if ((reg->id & ~KVM_REG_SIZE_MASK ) >>32 !=KVM_REG_ARM64 >>32 )return -EINVAL ; +if (kvm_is_realm (vcpu->kvm) && !validate_realm_set_reg (vcpu, reg)) +return -EINVAL ; +switch (reg->id &KVM_REG_ARM_COPROC_MASK ) {case KVM_REG_ARM_CORE :return set_core_reg (vcpu, reg);case KVM_REG_ARM_FW :
Signature · 1 line
2.34.1
RFC PATCH 20/28 KVM: arm64: Handle Realm PSCI requests
In reply to Steven PriceThe RMM needs to be informed of the target REC when a PSCI call is made with an MPIDR argument.
--- arch/arm64/include/asm/kvm_rme.h | 1 + arch/arm64/kvm/psci.c | 23 +++++++++++++++++++++++ arch/arm64/kvm/rme.c | 13 +++++++++++++ 3 files changed, 37 insertions(+)
arch/arm64/include/asm/kvm_rme.h +1 -0
@@ -65,6 +65,7 @@ int realm_map_non_secure(struct realm *realm,int realm_set_ipa_state (struct kvm_vcpu *vcpu,unsigned long addr,unsigned long end,unsigned long ripas); +int realm_psci_complete (struct kvm_vcpu *calling,struct kvm_vcpu *target);#define RME_RTT_BLOCK_LEVEL 2#define RME_RTT_MAX_LEVEL 3
arch/arm64/kvm/psci.c +23 -0
@@ -76,6 +76,10 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)*/ if (!vcpu)return PSCI_RET_INVALID_PARAMS ; + +if (vcpu_is_rec (vcpu)) +realm_psci_complete (source_vcpu, vcpu); +if (!kvm_arm_vcpu_stopped (vcpu)) {if (kvm_psci_version (source_vcpu) !=KVM_ARM_PSCI_0_1 )return PSCI_RET_ALREADY_ON ;
@@ -135,6 +139,25 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)/* Ignore other bits of target affinity */ target_affinity &= target_affinity_mask; +if (vcpu_is_rec (vcpu)) { +struct kvm_vcpu *target_vcpu; + +/* RMM supports only zero affinity level */ +if (lowest_affinity_level !=0 ) +return PSCI_RET_INVALID_PARAMS ; + + target_vcpu =kvm_mpidr_to_vcpu (kvm, target_affinity); +if (!target_vcpu) +return PSCI_RET_INVALID_PARAMS ; + +/* +* Provide the references of running and target RECs to the RMM +* so that the RMM can complete the PSCI request. +*/ +realm_psci_complete (vcpu, target_vcpu); +return PSCI_RET_SUCCESS ; + } +/* * If one or more VCPU matching target affinity are running * then ON else OFF
arch/arm64/kvm/rme.c +13 -0
@@ -126,6 +126,19 @@ static void free_delegated_page(struct realm *realm, phys_addr_t phys)free_page ((unsigned long )phys_to_virt (phys)); } +int realm_psci_complete (struct kvm_vcpu *calling,struct kvm_vcpu *target) +{ +int ret; + + ret =rmi_psci_complete (virt_to_phys (calling->arch.rec.rec_page), +virt_to_phys (target->arch.rec.rec_page)); + +if (ret) +return -EINVAL ; + +return 0 ; +} + static void realm_destroy_undelegate_range(struct realm *realm, unsigned long ipa, unsigned long addr,
Signature · 1 line
2.34.1
RFC PATCH 21/28 KVM: arm64: WARN on injected undef exceptions
In reply to Steven PriceThe RMM doesn't allow injection of a undefined exception into a realm guest. Add a WARN to catch if this ever happens.
--- arch/arm64/kvm/inject_fault.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/kvm/inject_fault.c +2 -0
@@ -175,6 +175,8 @@ void kvm_inject_size_fault(struct kvm_vcpu *vcpu)*/ void kvm_inject_undefined (struct kvm_vcpu *vcpu) { +if (vcpu_is_rec (vcpu)) +WARN (1 ,"Cannot inject undefined exception into REC. Continuing with unknown behaviour" );if (vcpu_el1_is_32bit (vcpu))inject_undef32 (vcpu);else
Signature · 1 line
2.34.1
RFC PATCH 22/28 arm64: Don't expose stolen time for realm guests
In reply to Steven PriceIt doesn't make much sense and with the ABI as it is it's a footgun for the VMM which makes fatal granule protection faults easy to trigger.
--- arch/arm64/kvm/arm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/kvm/arm.c +4 -1
@@ -302,7 +302,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r =system_supports_mte ();break ;case KVM_CAP_STEAL_TIME : - r =kvm_arm_pvtime_supported (); +if (kvm &&kvm_is_realm (kvm)) + r =0 ; +else + r =kvm_arm_pvtime_supported ();break ;case KVM_CAP_ARM_EL1_32BIT : r =cpus_have_const_cap (ARM64_HAS_32BIT_EL1 );
Signature · 1 line
2.34.1
RFC PATCH 23/28 KVM: arm64: Allow activating realms
In reply to Steven PriceAdd the ioctl to activate a realm and set the static branch to enable access to the realm functionality if the RMM is detected.
--- arch/arm64/kvm/rme.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
arch/arm64/kvm/rme.c +18 -1
@@ -1000,6 +1000,20 @@ static int kvm_init_ipa_range_realm(struct kvm *kvm,return ret; } +static int kvm_activate_realm (struct kvm *kvm) +{ +struct realm *realm = &kvm->arch.realm; + +if (kvm_realm_state (kvm) !=REALM_STATE_NEW ) +return -EBUSY ; + +if (rmi_realm_activate (virt_to_phys (realm->rd))) +return -ENXIO ; + +WRITE_ONCE (realm->state,REALM_STATE_ACTIVE ); +return 0 ; +} +/* Protects access to rme_vmid_bitmap */ static DEFINE_SPINLOCK (rme_vmid_lock);static unsigned long *rme_vmid_bitmap;
@@ -1175,6 +1189,9 @@ int kvm_realm_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) r =kvm_populate_realm (kvm, &args);break ; } +case KVM_CAP_ARM_RME_ACTIVATE_REALM : + r =kvm_activate_realm (kvm); +break ;default : r = -EINVAL ;break ;
@@ -1415,7 +1432,7 @@ int kvm_init_rme(void)WARN_ON (rmi_features (0 , &rmm_feat_reg0)); -/* Future patch will enable static branch kvm_rme_is_available */ +static_branch_enable (&kvm_rme_is_available);return 0 ; }
Signature · 1 line
2.34.1
RFC PATCH 24/28 arm64: rme: allow userspace to inject aborts
In reply to Steven PriceFrom: Joey Gouly <[email protected]>
Extend KVM_SET_VCPU_EVENTS to support realms, where KVM cannot set the system registers, and the RMM must perform it on next REC entry.
--- Documentation/virt/kvm/api.rst | 2 ++ arch/arm64/kvm/guest.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+)
Documentation/virt/kvm/api.rst +2 -0
@@ -1238,6 +1238,8 @@ User space may need to inject several types of events to the guest. Set the pending SError exception state for this VCPU. It is not possible to 'cancel' an Serror that has been made pending. +User space cannot inject SErrors into Realms. + If the guest performed an access to I/O memory which could not be handled by userspace, for example because of missing instruction syndrome decode information or because there is no device mapped at the accessed IPA, then
arch/arm64/kvm/guest.c +24 -0
@@ -851,6 +851,30 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,bool has_esr = events->exception.serror_has_esr;bool ext_dabt_pending = events->exception.ext_dabt_pending; +if (vcpu_is_rec (vcpu)) { +/* Cannot inject SError into a Realm. */ +if (serror_pending) +return -EINVAL ; + +/* +* If a data abort is pending, set the flag and let the RMM +* inject an SEA when the REC is scheduled to be run. +*/ +if (ext_dabt_pending) { +/* +* Can only inject SEA into a Realm if the previous exit +* was due to a data abort of an Unprotected IPA. +*/ +if (!(vcpu->arch.rec.run->entry.flags &RMI_EMULATED_MMIO )) +return -EINVAL ; + + vcpu->arch.rec.run->entry.flags &= ~RMI_EMULATED_MMIO ; + vcpu->arch.rec.run->entry.flags |=RMI_INJECT_SEA ; + } + +return 0 ; + } +if (serror_pending && has_esr) {if (!cpus_have_const_cap (ARM64_HAS_RAS_EXTN ))return -EINVAL ;
Signature · 1 line
2.34.1
RFC PATCH 25/28 arm64: rme: support RSI_HOST_CALL
In reply to Steven PriceFrom: Joey Gouly <[email protected]>
Forward RSI_HOST_CALLS to KVM's HVC handler.
--- arch/arm64/kvm/rme-exit.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
arch/arm64/kvm/rme-exit.c +26 -0
@@ -4,6 +4,7 @@*/ #include <linux/kvm_host.h> +#include <kvm/arm_hypercalls.h> #include <kvm/arm_psci.h> #include <asm/rmi_smc.h>
@@ -98,6 +99,29 @@ static int rec_exit_ripas_change(struct kvm_vcpu *vcpu)return 1 ; } +static int rec_exit_host_call (struct kvm_vcpu *vcpu) +{ +int ret, i; +struct rec *rec = &vcpu->arch.rec; + + vcpu->stat.hvc_exit_stat++; + +for (i =0 ; i <REC_RUN_GPRS ; i++) +vcpu_set_reg (vcpu, i, rec->run->exit.gprs[i]); + + ret =kvm_hvc_call_handler (vcpu); + +if (ret <0 ) { +vcpu_set_reg (vcpu,0 , ~0UL ); + ret =1 ; + } + +for (i =0 ; i <REC_RUN_GPRS ; i++) + rec->run->entry.gprs[i] =vcpu_get_reg (vcpu, i); + +return ret; +} +static void update_arch_timer_irq_lines (struct kvm_vcpu *vcpu) {struct rec *rec = &vcpu->arch.rec;
@@ -159,6 +183,8 @@ int handle_rme_exit(struct kvm_vcpu *vcpu, int rec_run_ret)return rec_exit_psci (vcpu);case RMI_EXIT_RIPAS_CHANGE :return rec_exit_ripas_change (vcpu); +case RMI_EXIT_HOST_CALL : +return rec_exit_host_call (vcpu); } kvm_pr_unimpl("Unsupported exit reason: %u\n",
Signature · 1 line
2.34.1
RFC PATCH 26/28 arm64: rme: Allow checking SVE on VM instance
In reply to Steven PriceFrom: Suzuki K Poulose <[email protected]>
Given we have different types of VMs supported, check the support for SVE for the given instance of the VM to accurately report the status.
--- arch/arm64/include/asm/kvm_rme.h | 2 ++ arch/arm64/kvm/arm.c | 5 ++++- arch/arm64/kvm/rme.c | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-)
arch/arm64/include/asm/kvm_rme.h +2 -0
@@ -40,6 +40,8 @@ struct rec {int kvm_init_rme (void );u32 kvm_realm_ipa_limit (void ); +bool kvm_rme_supports_sve (void ); +int kvm_realm_enable_cap (struct kvm *kvm,struct kvm_enable_cap *cap);int kvm_init_realm_vm (struct kvm *kvm);void kvm_destroy_realm (struct kvm *kvm);
arch/arm64/kvm/arm.c +4 -1
@@ -326,7 +326,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r =get_kvm_ipa_limit ();break ;case KVM_CAP_ARM_SVE : - r =system_supports_sve (); +if (kvm &&kvm_is_realm (kvm)) + r =kvm_rme_supports_sve (); +else + r =system_supports_sve ();break ;case KVM_CAP_ARM_PTRAUTH_ADDRESS :case KVM_CAP_ARM_PTRAUTH_GENERIC :
arch/arm64/kvm/rme.c +6 -1
@@ -49,6 +49,11 @@ static bool rme_supports(unsigned long feature)return !!u64_get_bits (rmm_feat_reg0, feature); } +bool kvm_rme_supports_sve (void ) +{ +return rme_supports (RMI_FEATURE_REGISTER_0_SVE_EN ); +} +static int rmi_check_version (void ) {struct arm_smccc_res res;
@@ -1104,7 +1109,7 @@ static int config_realm_sve(struct realm *realm,int max_sve_vq =u64_get_bits (rmm_feat_reg0,RMI_FEATURE_REGISTER_0_SVE_VL ); -if (!rme_supports (RMI_FEATURE_REGISTER_0_SVE_EN )) +if (!kvm_rme_supports_sve ())return -EINVAL ;if (cfg->sve_vq > max_sve_vq)
Signature · 1 line
2.34.1
RFC PATCH 27/28 arm64: RME: Always use 4k pages for realms
In reply to Steven PriceAlways split up huge pages to avoid problems managing huge pages. There are two issues currently:
1. The uABI for the VMM allows populating memory on 4k boundaries even if the underlying allocator (e.g. hugetlbfs) is using a larger page size. Using a memfd for private allocations will push this issue onto the VMM as it will need to respect the granularity of the allocator.
2. The guest is able to request arbitrary ranges to be remapped as shared. Again with a memfd approach it will be up to the VMM to deal with the complexity and either overmap (need the huge mapping and add an additional 'overlapping' shared mapping) or reject the request as invalid due to the use of a huge page allocator.
For now just break everything down to 4k pages in the RMM controlled stage 2.
--- arch/arm64/kvm/mmu.c | 4 ++++ arch/arm64/kvm/rme.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)
arch/arm64/kvm/mmu.c +4 -0
@@ -1278,6 +1278,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (logging_active) { force_pte = true; vma_shift =PAGE_SHIFT ; + }else if (kvm_is_realm (kvm)) { +// Force PTE level mappings for realms + force_pte = true; + vma_shift =PAGE_SHIFT ; }else { vma_shift =get_vma_page_shift (vma, hva); }
arch/arm64/kvm/rme.c +3 -1
@@ -730,7 +730,9 @@ static int populate_par_region(struct kvm *kvm,break ; } -if (is_vm_hugetlb_page (vma)) +// FIXME: To avoid the overmapping issue (see below comment) +// force the use of 4k pages +if (is_vm_hugetlb_page (vma) &&0 ) vma_shift =huge_page_shift (hstate_vma (vma));else vma_shift =PAGE_SHIFT ;
Signature · 1 line
2.34.1
RFC PATCH 28/28 HACK: Accept prototype RMI versions
In reply to Steven PriceThe upstream RMM currently advertises the major version of an internal prototype (v56.0) rather than the expected version from the RMM architecture specification (v1.0).
Add a config option to enable support for the prototype RMI v56.0.
--- arch/arm64/include/asm/rmi_smc.h | 7 +++++++ arch/arm64/kvm/Kconfig | 8 ++++++++ arch/arm64/kvm/rme.c | 8 ++++++++ 3 files changed, 23 insertions(+)
arch/arm64/include/asm/rmi_smc.h +7 -0
@@ -6,6 +6,13 @@#ifndef __ASM_RME_SMC_H#define __ASM_RME_SMC_H +#ifdef CONFIG_RME_USE_PROTOTYPE_HACKS + +// Allow the prototype RMI version +#define PROTOTYPE_RMI_ABI_MAJOR_VERSION 56 + +#endif /* CONFIG_RME_USE_PROTOTYPE_HACKS */ +#include <linux/arm-smccc.h> #define SMC_RxI_CALL (func) \
arch/arm64/kvm/Kconfig +8 -0
@@ -58,6 +58,14 @@ config NVHE_EL2_DEBUG If unsure, say N. +config RME_USE_PROTOTYPE_HACKS + bool "Allow RMM prototype version numbers" + default y + help + For compatibility with the the current RMM code allow versions + numbers from a prototype implementation as well as the expected + version number from the RMM specification. + config PROTECTED_NVHE_STACKTRACE bool "Protected KVM hypervisor stacktraces" depends on NVHE_EL2_DEBUG
arch/arm64/kvm/rme.c +8 -0
@@ -67,6 +67,14 @@ static int rmi_check_version(void) version_major =RMI_ABI_VERSION_GET_MAJOR (res.a0); version_minor =RMI_ABI_VERSION_GET_MINOR (res.a0); +#ifdef PROTOTYPE_RMI_ABI_MAJOR_VERSION +// Support the prototype +if (version_major ==PROTOTYPE_RMI_ABI_MAJOR_VERSION ) { +kvm_err ("Using prototype RMM support (version %d.%d)\n" , + version_major, version_minor); +return 0 ; + } +#endif if (version_major !=RMI_ABI_MAJOR_VERSION ) { kvm_err("Unsupported RMI ABI (version %d.%d) we support %d\n", version_major, version_minor,
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewercover arm64: Support for Arm Confidential Compute Architecture
In reply to Suzuki K PouloseThis series is an initial version of the support for running VMs under the Arm Confidential Compute Architecture. The purpose of the series is to gather feedback on the proposed UABI changes for running Confidential VMs with KVM. More information on the Arm CCA and instructions for how to get, build and run the entire software stack is available here [0].
A new option, --realm is added to the the run command to mark the VM as a confidential compute VM. This version doesn't use the Guest private memory [1] support yet, instead uses normal anonymous/hugetlbfs backed memory. Our aim is to switch to the guest private memory for the Realm.
The host including the kernel and kvmtool, must not access any memory allocated to the protected IPA of the Realm.
The series adds the support for managing the lifecycle of the Realm, which includes:
* Configuration
* Creation of Realm (RD)
* Load initial memory images
* Creation of Realm Execution Contexts (RECs aka VCPUs)a
* Activation of the Realm.
Patches are split as follows :
Patches 1 and 2 are fixes to existing code.
Patch 3 adds a new option --nocompat to disable compat warnings Patches 4 - 6 are some preparations for Realm specific changes.
The remaining patches adds Realm support and using the --realm option is enabled in patch 30.
The v1.0 of the Realm Management Monitor (RMM) specification doesn't support paging protected memory of a Realm. Thus all of the memory backing the RAM is locked by the VMM.
Since the IPA space of a Realm is split into Protected and Unprotected, with one alias of the other, the VMM doubles the IPA Size for a Realm VM.
The KVM support for Arm CCA is advertised with a new cap KVM_CAP_ARM_RME. A new "VM type" field is defined in the vm_type for CREATE_VM ioctl to indicate that a VM is "Realm". Once the VM is created, the life cycle of the Realm is managed via KVM_ENABLE_CAP of KVM_CAP_ARM_RME.
Command line options are also added to configure the Realm parameters. These include :
- Hash algorithm for measurements
- Realm personalisation value
- SVE vector Length (Optional feature in v1.0 RMM spec. Not yet supported by the TF-RMM. coming soon).
Support for PMU and self-hosted debug (number of watchpoint/breakpoit registers) are not supported yet in the KVM/RMM implementation. This will be added soon.
The UABI doesn't support discovering the "supported" configuration values. In real world, the Realm configuration 'affects' the initial measurement of the Realms and which may be verified by a remote entity. Thus, the VMM is not at liberty to make choices for configurations based on the "host" capabilities. Instead, VMM should launch a Realm with the user requested parameters. If this cannot be satisfied, there is no point in running the Realm. We are happy to change this if there is interest.
Special actions are required to load the initial memory images (e.g, kernel, firmware, DTB, initrd) in to the Realm memory.
For VCPUs, we add a new feature KVM_ARM_VCPU_REC, which will be used to control the creation of the REC object (via KVM_ARM_VCPU_FINALIZE). This must be done after the initial register state of the VCPUs are set.
RMM imposes an order in which the RECs are created. i.e., they must be created in the ascending order of the MPIDR. This is for now a responsibility of the VMM.
Once the Realm images are loaded, VCPUs created, Realm is activated before the first vCPU is run.
virtio for the Realms enforces VIRTIO_F_ACCESS_PLATFORM flag.
Also, added support for injecting SEA into the VM for unhandled MMIO.
A tree with the patches are also available here :
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1
Running the Realm
------------------
A realm VM can be launched using :
$ lkvm run \ --realm \ --disable-sve \ [ --measurement-algo="sha256","sha512" ] \ [ --realm-pv="<realm-pv>" ] \ <normal-VM options>
[0] https://lkml.kernel.org/r/[email protected]
[1] https://lkml.kernel.org/r/[email protected]
To: [email protected]
To: [email protected]
Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Alexandru Elisei (11):
Add --nocompat option to disable compat warnings
arm64: Add --realm command line option
arm64: Lock realm RAM in memory
arm64: Create Realm Descriptor
arm: Add kernel size to VM context
arm64: Populate initial realm contents
arm64: Finalize realm VCPU after reset
init: Add last_{init, exit} list macros
arm64: Activate realm before the first VCPU is run
arm64: Don't try to debug a realm
arm64: Allow the user to create a realm
Christoffer Dall (4):
arm64: Create a realm virtual machine
arm64: Add --measurement-algo command line option for a realm
arm64: Don't try to set PSTATE for VCPUs belonging to a realm
arm64: Specify SMC as the PSCI conduits for realms
Joey Gouly (2):
mmio: add arch hook for an unhandled MMIO access
arm64: realm: inject an abort on an unhandled MMIO access
Suzuki K Poulose (14):
arm64: Disable MTE when CFI flash is emulated
script: update_headers: Ignore missing architectures
hw: cfi flash: Handle errors in memory transitions
arm64: Check pvtime support against the KVM instance
arm64: Check SVE capability on the VM instance
arm64: Add option to disable SVE
linux: Update kernel headers for RME support
arm64: Add configuration step for Realms
arm64: Add support for Realm Personalisation Value
arm64: Add support for specifying the SVE vector length for Realm
arm64: realm: Double the IPA space
virtio: Add a wrapper for get_host_features
virtio: Add arch specific hook for virtio host flags
arm64: realm: Enforce virtio F_ACCESS_PLATFORM flag
Makefile | 1 + arm/aarch32/include/asm/realm.h | 13 ++ arm/aarch32/kvm.c | 5 + arm/aarch64/include/asm/kvm.h | 64 ++++++ arm/aarch64/include/asm/realm.h | 13 ++ arm/aarch64/include/kvm/kvm-config-arch.h | 16 +- arm/aarch64/kvm-cpu.c | 41 +++- arm/aarch64/kvm.c | 95 ++++++++- arm/aarch64/pvtime.c | 4 +- arm/aarch64/realm.c | 229 ++++++++++++++++++++++ arm/fdt.c | 15 +- arm/include/arm-common/kvm-arch.h | 4 + arm/include/arm-common/kvm-config-arch.h | 5 + arm/kvm-cpu.c | 13 ++ arm/kvm.c | 75 ++++++- builtin-run.c | 5 +- guest_compat.c | 1 + hw/cfi_flash.c | 4 + include/kvm/kvm-config.h | 1 + include/kvm/kvm-cpu.h | 2 + include/kvm/kvm.h | 2 + include/kvm/util-init.h | 6 +- include/kvm/virtio.h | 2 + include/linux/kernel.h | 1 + include/linux/kvm.h | 22 ++- include/linux/virtio_blk.h | 19 -- include/linux/virtio_net.h | 14 +- include/linux/virtio_ring.h | 16 +- mips/kvm-cpu.c | 4 + mips/kvm.c | 5 + mmio.c | 3 + powerpc/kvm-cpu.c | 4 + powerpc/kvm.c | 5 + riscv/kvm-cpu.c | 4 + riscv/kvm.c | 5 + util/update_headers.sh | 1 + virtio/core.c | 8 + virtio/mmio-legacy.c | 2 +- virtio/mmio-modern.c | 2 +- virtio/pci-legacy.c | 2 +- virtio/pci-modern.c | 2 +- x86/kvm-cpu.c | 4 + x86/kvm.c | 5 + 43 files changed, 667 insertions(+), 77 deletions(-) create mode 100644 arm/aarch32/include/asm/realm.h create mode 100644 arm/aarch64/include/asm/realm.h create mode 100644 arm/aarch64/realm.c
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 1/31 arm64: Disable MTE when CFI flash is emulated
CFI Flash file image cannot be mapped into the memory of the guest if MTE is enabled. Thus disable MTE if flash emulation is requested.
--- arm/aarch64/kvm.c | 6 ++++++ 1 file changed, 6 insertions(+)
arm/aarch64/kvm.c +6 -0
@@ -145,6 +145,12 @@ void kvm__arch_enable_mte(struct kvm *kvm)return ; } +if (kvm->cfg.flash_filename) { + kvm->cfg.arch.mte_disabled = true; +pr_info ("MTE is incompatible with CFI flash support, disabling" ); +return ; + } +if (kvm->cfg.arch.mte_disabled) {pr_debug ("MTE disabled by user" );return ;
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 2/31 script: update_headers: Ignore missing architectures
In reply to Suzuki K PouloseIgnore missing architectures for header updates, for use with older kernels.
--- util/update_headers.sh | 1 + 1 file changed, 1 insertion(+)
util/update_headers.sh +1 -0
@@ -48,6 +48,7 @@ copy_optional_arch () { for arch in arm64 mips powerpc riscv x86 do + [ -f $LINUX_ROOT/arch/${arch} ] || continue; case "$arch" in arm64) KVMTOOL_PATH=arm/aarch64 copy_optional_arch asm/sve_context.h ;;
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 3/31 hw: cfi flash: Handle errors in memory transitions
In reply to Suzuki K PouloseHandle failures in creating the memory maps and back in transitioning the CFI flash. e.g., with MTE enabled, CFI flash emulation breaks with the map operation, silently. And we later hit unhandled aborts in the guest.
To avoid such issues, let us make sure we catch the error and handle it right at source.
--- hw/cfi_flash.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/cfi_flash.c +4 -0
@@ -455,6 +455,8 @@ static int map_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev) KVM_MEM_TYPE_RAM | KVM_MEM_TYPE_READONLY);if (!ret) sfdev->is_mapped = true; +else +die ("CFI Flash: ERROR: Unable to map memory: %d\n" , ret);return ret; }
@@ -472,6 +474,8 @@ static int unmap_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev)if (!ret) sfdev->is_mapped = false; +else +die ("CFI Flash: Failed to unmap Flash %d" , ret);return ret; }
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 4/31 Add --nocompat option to disable compat warnings
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
Commit e66942073035 ("kvm tools: Guest kernel compatability") added the functionality that enables devices to print a warning message if the device hasn't been initialized by the time the VM is destroyed. The purpose of these messages is to let the user know if the kernel hasn't been built with the correct Kconfig options to take advantage of the said devices (all using virtio).
Since then, kvmtool has evolved and now supports loading different payloads (like firmware images), and having those warnings even when it is entirely intentional for the payload not to touch the devices can be confusing for the user and makes the output unnecessarily verbose in those cases.
Add the --nocompat option to disable the warnings; the warnings are still enabled by default.
--- builtin-run.c | 5 ++++- guest_compat.c | 1 + include/kvm/kvm-config.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-)
builtin-run.c +4 -1
@@ -183,6 +183,8 @@ static int mem_parser(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('\0' ,"nodefaults" , &(cfg)->nodefaults,"Disable" \" implicit configuration that cannot be" \" disabled otherwise" ), \ +OPT_BOOLEAN ('\0' ,"nocompat" , &(cfg)->nocompat,"Disable" \ +" compat warnings" ), \OPT_CALLBACK ('\0' ,"9p" ,NULL ,"dir_to_share,tag_name" , \"Enable virtio 9p to share files between host and" \ " guest", virtio_9p_rootdir_parser, kvm), \
@@ -797,7 +799,8 @@ static int kvm_cmd_run_work(struct kvm *kvm)static void kvm_cmd_run_exit (struct kvm *kvm,int guest_ret) { -compat__print_all_messages (); +if (!kvm->cfg.nocompat) +compat__print_all_messages ();init_list__exit (kvm);
guest_compat.c +1 -0
@@ -88,6 +88,7 @@ int compat__print_all_messages(void)printf ("\n # KVM compatibility warning.\n\t%s\n\t%s\n" , msg->title, msg->desc); +printf ("\tTo stop seeing this warning, use the --nocompat option.\n" );list_del (&msg->list);compat__free (msg);
include/kvm/kvm-config.h +1 -0
@@ -30,6 +30,7 @@ struct kvm_config {u64 vsock_cid;bool virtio_rng;bool nodefaults; +bool nocompat;int active_console;int debug_iodelay;int nrcpus;
Signature · 1 line
2.34.1
Re: [RFC kvmtool 04/31] Add --nocompat option to disable compat warnings
Hi,
Quoted 9 lines · Suzuki K Poulose
From: Alexandru Elisei <[email protected]>
Commit
e66942073035("kvm tools: Guest kernel compatability") added the functionality that enables devices to print a warning message if the device hasn't been initialized by the time the VM is destroyed. The purpose of these messages is to let the user know if the kernel hasn't been built with the correctKconfigoptions to take advantage of the said devices (all using virtio).
Quoted 7 lines
Since then, kvmtool has evolved and now supports loading different payloads (like firmware images), and having those warnings even when it is entirely intentional for the payload not to touch the devices can be confusing for the user and makes the output unnecessarily verbose in those cases.
Add the --nocompat option to disable the warnings; the warnings are still enabled by default.
I had a conversation with Will regarding this some time ago, we settled on a different approach, by using --loglevel=<level>, similar to what Linux does. I'll put that on my TODO list and try to send patches soon-ish.
Thanks,
Alex
Quoted 60 lines
Reported-by Christoffer Dall <[email protected]>Signed-off-by Alexandru Elisei <[email protected]>Signed-off-by Suzuki K Poulose <[email protected]>--- builtin-run.c | 5 ++++- guest_compat.c | 1 + include/kvm/kvm-config.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-)builtin-run.c +4
-1@@ -183,6 +183,8 @@ static int mem_parser(const struct option *opt, const char *arg, int unset)OPT_BOOLEAN ('\0' ,"nodefaults" , &(cfg)->nodefaults,"Disable" \" implicit configuration that cannot be" \" disabled otherwise" ), \ +OPT_BOOLEAN ('\0' ,"nocompat" , &(cfg)->nocompat,"Disable" \ +" compat warnings" ), \OPT_CALLBACK ('\0' ,"9p" ,NULL ,"dir_to_share,tag_name" , \"Enable virtio 9p to share files between host and" \ " guest", virtio_9p_rootdir_parser, kvm), \@@ -797,7 +799,8 @@ static int kvm_cmd_run_work(struct kvm *kvm)static void kvm_cmd_run_exit (struct kvm *kvm,int guest_ret) { -compat__print_all_messages (); +if (!kvm->cfg.nocompat) +compat__print_all_messages ();init_list__exit (kvm);guest_compat.c +1
-0@@ -88,6 +88,7 @@ int compat__print_all_messages(void)printf ("\n # KVM compatibility warning.\n\t%s\n\t%s\n" , msg->title, msg->desc); +printf ("\tTo stop seeing this warning, use the --nocompat option.\n" );list_del (&msg->list);compat__free (msg);include/kvm/kvm-config.h +1
-0@@ -30,6 +30,7 @@ struct kvm_config {u64 vsock_cid;bool virtio_rng;bool nodefaults; +bool nocompat;int active_console;int debug_iodelay;int nrcpus;Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 5/31 arm64: Check pvtime support against the KVM instance
In reply to Suzuki K PouloseKVM_CAP_STEAL_TIME can be checked against a VM instance. To allow controlling the feature depending on the VM type, use the cap against the VM.
--- arm/aarch64/pvtime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arm/aarch64/pvtime.c +2 -2
@@ -58,8 +58,8 @@ int kvm_cpu__setup_pvtime(struct kvm_cpu *vcpu)if (kvm_cfg->no_pvtime)return 0 ; - has_stolen_time =kvm__supports_extension (vcpu->kvm, -KVM_CAP_STEAL_TIME ); + has_stolen_time =kvm__supports_vm_extension (vcpu->kvm, +KVM_CAP_STEAL_TIME );if (!has_stolen_time) { kvm_cfg->no_pvtime = true;return 0 ;
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 6/31 arm64: Check SVE capability on the VM instance
In reply to Suzuki K PouloseSimilar to PVtime, check the SVE capability on the VM instance to account for the different VM types and the corresponding support.
--- arm/aarch64/kvm-cpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arm/aarch64/kvm-cpu.c +4 -2
@@ -150,13 +150,15 @@ void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) }/* Enable SVE if available */ -if (kvm__supports_extension (kvm,KVM_CAP_ARM_SVE )) +if (kvm__supports_vm_extension (kvm,KVM_CAP_ARM_SVE )) init->features[0 ] |=1UL <<KVM_ARM_VCPU_SVE ; }int kvm_cpu__configure_features (struct kvm_cpu *vcpu) { -if (kvm__supports_extension (vcpu->kvm,KVM_CAP_ARM_SVE )) { +struct kvm *kvm = vcpu->kvm; + +if (kvm__supports_vm_extension (kvm,KVM_CAP_ARM_SVE )) {int feature =KVM_ARM_VCPU_SVE ;if (ioctl (vcpu->vcpu_fd,KVM_ARM_VCPU_FINALIZE , &feature)) {
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 7/31 arm64: Add option to disable SVE
In reply to Suzuki K Poulosekvmtool enables SVE whenever it is supported by the KVM. However, Realm VMs may want controlled features, which gets measured during the creation. Thus, provide an option to disable the SVE, to preserve the current behavior of SVE on by default.
--- arm/aarch64/include/kvm/kvm-config-arch.h | 4 +++- arm/aarch64/kvm-cpu.c | 8 +++++--- arm/include/arm-common/kvm-config-arch.h | 1 + 3 files changed, 9 insertions(+), 4 deletions(-)
arm/aarch64/include/kvm/kvm-config-arch.h +3 -1
@@ -19,7 +19,9 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset);"Specify random seed for Kernel Address Space " \ "Layout Randomization (KASLR)"), \OPT_BOOLEAN ('\0' ,"no-pvtime" , &(cfg)->no_pvtime,"Disable" \ -" stolen time" ), +" stolen time" ), \ +OPT_BOOLEAN ('\0' ,"disable-sve" , &(cfg)->disable_sve, \ +"Disable SVE" ), #include "arm-common/kvm-config-arch.h"#endif /* KVM__KVM_CONFIG_ARCH_H */
arm/aarch64/kvm-cpu.c +5 -3
@@ -149,8 +149,9 @@ void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) init->features[0 ] |=1UL <<KVM_ARM_VCPU_PTRAUTH_GENERIC ; } -/* Enable SVE if available */ -if (kvm__supports_vm_extension (kvm,KVM_CAP_ARM_SVE )) +/* If SVE is not disabled explicitly, enable if available */ +if (!kvm->cfg.arch.disable_sve && +kvm__supports_vm_extension (kvm,KVM_CAP_ARM_SVE )) init->features[0 ] |=1UL <<KVM_ARM_VCPU_SVE ; }
@@ -158,7 +159,8 @@ int kvm_cpu__configure_features(struct kvm_cpu *vcpu) {struct kvm *kvm = vcpu->kvm; -if (kvm__supports_vm_extension (kvm,KVM_CAP_ARM_SVE )) { +if (!kvm->cfg.arch.disable_sve && +kvm__supports_vm_extension (kvm,KVM_CAP_ARM_SVE )) {int feature =KVM_ARM_VCPU_SVE ;if (ioctl (vcpu->vcpu_fd,KVM_ARM_VCPU_FINALIZE , &feature)) {
arm/include/arm-common/kvm-config-arch.h +1 -0
@@ -15,6 +15,7 @@ struct kvm_config_arch {enum irqchip_type irqchip;u64 fw_addr;bool no_pvtime; +bool disable_sve; };int irqchip_parser (const struct option *opt,const char *arg,int unset);
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 8/31 linux: Update kernel headers for RME support
In reply to Suzuki K PouloseUpdate the RME specific ABI bits from the kernel headers.
--- arm/aarch64/include/asm/kvm.h | 64 +++++++++++++++++++++++++++++++++++ include/linux/kvm.h | 22 +++++++++--- include/linux/virtio_blk.h | 19 ----------- include/linux/virtio_net.h | 14 ++++---- include/linux/virtio_ring.h | 16 +++------ 5 files changed, 93 insertions(+), 42 deletions(-)
arm/aarch64/include/asm/kvm.h +64 -0
@@ -108,6 +108,7 @@ struct kvm_regs {#define KVM_ARM_VCPU_SVE 4/* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5/* VCPU uses address authentication */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6/* VCPU uses generic authentication */ +#define KVM_ARM_VCPU_REC 7/* VCPU REC state as part of Realm */ struct kvm_vcpu_init {__u32 target;
@@ -400,6 +401,69 @@ enum {#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3#define KVM_DEV_ARM_ITS_CTRL_RESET 4 +/* KVM_CAP_ARM_RME kvm_enable_cap->args[0] points to this */ +#define KVM_CAP_ARM_RME_CONFIG_REALM 0 +#define KVM_CAP_ARM_RME_CREATE_RD 1 +#define KVM_CAP_ARM_RME_INIT_IPA_REALM 2 +#define KVM_CAP_ARM_RME_POPULATE_REALM 3 +#define KVM_CAP_ARM_RME_ACTIVATE_REALM 4 + +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_ZERO (0x01ULL << 7) +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256 0 +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA512 1 + +#define KVM_CAP_ARM_RME_RPV_SIZE 64 + +/* List of configuration items accepted for KVM_CAP_ARM_RME_CONFIG_REALM */ +#define KVM_CAP_ARM_RME_CFG_RPV 0 +#define KVM_CAP_ARM_RME_CFG_HASH_ALGO 1 +#define KVM_CAP_ARM_RME_CFG_SVE 2 +#define KVM_CAP_ARM_RME_CFG_DBG 3 +#define KVM_CAP_ARM_RME_CFG_PMU 4 + +struct kvm_cap_arm_rme_config_item { +__u32 cfg; +union { +/* cfg == KVM_CAP_ARM_RME_CFG_RPV */ +struct { +__u8 rpv[KVM_CAP_ARM_RME_RPV_SIZE ]; + }; + +/* cfg == KVM_CAP_ARM_RME_CFG_HASH_ALGO */ +struct { +__u32 hash_algo; + }; + +/* cfg == KVM_CAP_ARM_RME_CFG_SVE */ +struct { +__u32 sve_vq; + }; + +/* cfg == KVM_CAP_ARM_RME_CFG_DBG */ +struct { +__u32 num_brps; +__u32 num_wrps; + }; + +/* cfg == KVM_CAP_ARM_RME_CFG_PMU */ +struct { +__u32 num_pmu_cntrs; + }; +/* Fix the size of the union */ +__u8 reserved[256 ]; + }; +}; + +struct kvm_cap_arm_rme_populate_realm_args { +__u64 populate_ipa_base; +__u64 populate_ipa_size; +}; + +struct kvm_cap_arm_rme_init_ipa_args { +__u64 init_ipa_base; +__u64 init_ipa_size; +}; +/* Device Control API on vcpu fd */ #define KVM_ARM_VCPU_PMU_V3_CTRL 0#define KVM_ARM_VCPU_PMU_V3_IRQ 0
include/linux/kvm.h +17 -5
@@ -903,14 +903,25 @@ struct kvm_ppc_resize_hpt {#define KVM_S390_SIE_PAGE_OFFSET 1/* -* On arm64, machine type can be used to request the physical -* address size for the VM. Bits[7-0] are reserved for the guest -* PA size shift (i.e, log2(PA_Size)). For backward compatibility, -* value 0 implies the default IPA size, 40bits. +* On arm64, machine type can be used to request both the machine type and +* the physical address size for the VM. +* +* Bits[11-8] are reserved for the ARM specific machine type. +* +* Bits[7-0] are reserved for the guest PA size shift (i.e, log2(PA_Size)). +* For backward compatibility, value 0 implies the default IPA size, 40bits. */ +#define KVM_VM_TYPE_ARM_SHIFT 8 +#define KVM_VM_TYPE_ARM_MASK (0xfULL << KVM_VM_TYPE_ARM_SHIFT) +#define KVM_VM_TYPE_ARM (_type) \ + (((_type) << KVM_VM_TYPE_ARM_SHIFT) & KVM_VM_TYPE_ARM_MASK) +#define KVM_VM_TYPE_ARM_NORMAL KVM_VM_TYPE_ARM(0) +#define KVM_VM_TYPE_ARM_REALM KVM_VM_TYPE_ARM(1) +#define KVM_VM_TYPE_ARM_IPA_SIZE_MASK 0xffULL#define KVM_VM_TYPE_ARM_IPA_SIZE (x) \ ((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK) +/* * ioctls for /dev/kvm fds: */
@@ -1177,7 +1188,8 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220#define KVM_CAP_S390_ZPCI_OP 221#define KVM_CAP_S390_CPU_TOPOLOGY 222 -#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 + +#define KVM_CAP_ARM_RME 300 // FIXME: Large number to prevent conflicts#ifdef KVM_CAP_IRQ_ROUTING
include/linux/virtio_blk.h +0 -19
@@ -40,7 +40,6 @@#define VIRTIO_BLK_F_MQ 12/* support more than one vq */ #define VIRTIO_BLK_F_DISCARD 13/* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14/* WRITE ZEROES is supported */ -#define VIRTIO_BLK_F_SECURE_ERASE 16/* Secure Erase is supported */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY
@@ -122,21 +121,6 @@ struct virtio_blk_config {__u8 write_zeroes_may_unmap;__u8 unused1[3 ]; - -/* the next 3 entries are guarded by VIRTIO_BLK_F_SECURE_ERASE */ -/* -* The maximum secure erase sectors (in 512-byte sectors) for -* one segment. -*/ -__virtio32 max_secure_erase_sectors; -/* -* The maximum number of secure erase segments in a -* secure erase command. -*/ -__virtio32 max_secure_erase_seg; -/* Secure erase commands must be aligned to this number of sectors. */ -__virtio32 secure_erase_sector_alignment; - } __attribute__((packed));/*
@@ -171,9 +155,6 @@ struct virtio_blk_config {/* Write zeroes command */ #define VIRTIO_BLK_T_WRITE_ZEROES 13 -/* Secure erase command */ -#define VIRTIO_BLK_T_SECURE_ERASE 14 -#ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000
include/linux/virtio_net.h +7 -7
@@ -56,7 +56,7 @@#define VIRTIO_NET_F_MQ 22/* Device supports Receive Flow * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23/* Set MAC address */ -#define VIRTIO_NET_F_NOTF_COAL 53/* Device supports notifications coalescing */ +#define VIRTIO_NET_F_NOTF_COAL 53/* Guest can handle notifications coalescing */ #define VIRTIO_NET_F_HASH_REPORT 57/* Supports hash report */ #define VIRTIO_NET_F_RSS 60/* Supports RSS RX steering */ #define VIRTIO_NET_F_RSC_EXT 61/* extended coalescing info */
@@ -364,24 +364,24 @@ struct virtio_net_hash_config {*/ #define VIRTIO_NET_CTRL_NOTF_COAL 6/* -* Set the tx-usecs/tx-max-packets parameters. +* Set the tx-usecs/tx-max-packets patameters. +* tx-usecs - Maximum number of usecs to delay a TX notification. +* tx-max-packets - Maximum number of packets to send before a TX notification. */ struct virtio_net_ctrl_coal_tx { -/* Maximum number of packets to send before a TX notification */ __le32 tx_max_packets; -/* Maximum number of usecs to delay a TX notification */ __le32 tx_usecs; };#define VIRTIO_NET_CTRL_NOTF_COAL_TX_SET 0/* -* Set the rx-usecs/rx-max-packets parameters. +* Set the rx-usecs/rx-max-packets patameters. +* rx-usecs - Maximum number of usecs to delay a RX notification. +* rx-max-frames - Maximum number of packets to receive before a RX notification. */ struct virtio_net_ctrl_coal_rx { -/* Maximum number of packets to receive before a RX notification */ __le32 rx_max_packets; -/* Maximum number of usecs to delay a RX notification */ __le32 rx_usecs; };
include/linux/virtio_ring.h +5 -11
@@ -93,21 +93,15 @@#define VRING_USED_ALIGN_SIZE 4#define VRING_DESC_ALIGN_SIZE 16 -/** -* struct vring_desc - Virtio ring descriptors, -* 16 bytes long. These can chain together via @next. -* -* @addr: buffer address (guest-physical) -* @len: buffer length -* @flags: descriptor flags -* @next: index of the next descriptor in the chain, -* if the VRING_DESC_F_NEXT flag is set. We chain unused -* descriptors via this, too. -*/ +/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ struct vring_desc { +/* Address (guest-physical). */ __virtio64 addr; +/* Length. */ __virtio32 len; +/* The flags as indicated above. */ __virtio16 flags; +/* We chain unused descriptors via this, too */ __virtio16 next; };
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 9/31 arm64: Add --realm command line option
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
Add the --realm command line option which causes kvmtool to exit with an error if specified, but which will be enabled once realms are fully supported by kvmtool.
--- arm/aarch64/include/kvm/kvm-config-arch.h | 5 ++++- arm/aarch64/kvm.c | 20 ++++++++++++++++++-- arm/include/arm-common/kvm-config-arch.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-)
arm/aarch64/include/kvm/kvm-config-arch.h +4 -1
@@ -21,7 +21,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset);OPT_BOOLEAN ('\0' ,"no-pvtime" , &(cfg)->no_pvtime,"Disable" \" stolen time" ), \OPT_BOOLEAN ('\0' ,"disable-sve" , &(cfg)->disable_sve, \ -"Disable SVE" ), +"Disable SVE" ), \ +OPT_BOOLEAN ('\0' ,"realm" , &(cfg)->is_realm, \ +"Create VM running in a realm using Arm RME" ), + #include "arm-common/kvm-config-arch.h"#endif /* KVM__KVM_CONFIG_ARCH_H */
arm/aarch64/kvm.c +18 -2
@@ -38,9 +38,8 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset)return 0 ; } -void kvm__arch_validate_cfg (struct kvm *kvm) +static void validate_mem_cfg (struct kvm *kvm) { -if (kvm->cfg.ram_addr <ARM_MEMORY_AREA ) {die ("RAM address is below the I/O region ending at %luGB" ,ARM_MEMORY_AREA >>30 );
@@ -52,6 +51,23 @@ void kvm__arch_validate_cfg(struct kvm *kvm) } } +static void validate_realm_cfg (struct kvm *kvm) +{ +if (!kvm->cfg.arch.is_realm) +return ; + +if (kvm->cfg.arch.aarch32_guest) +die ("Realms supported only for 64bit guests" ); + +die ("Realms not supported" ); +} + +void kvm__arch_validate_cfg (struct kvm *kvm) +{ +validate_mem_cfg (kvm); +validate_realm_cfg (kvm); +} +u64 kvm__arch_default_ram_address (void ) {return ARM_MEMORY_AREA ;
arm/include/arm-common/kvm-config-arch.h +1 -0
@@ -11,6 +11,7 @@ struct kvm_config_arch {bool aarch32_guest;bool has_pmuv3;bool mte_disabled; +bool is_realm;u64 kaslr_seed;enum irqchip_type irqchip;u64 fw_addr;
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 10/31 arm64: Create a realm virtual machine
In reply to Suzuki K PouloseFrom: Christoffer Dall <[email protected]>
Set the machine type to realm when creating a VM via the KVM_CREATE_VM ioctl.
[ Alex E: Reworked patch, split the command line option into a different
patch ]
--- arm/aarch64/kvm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arm/aarch64/kvm.c +8 -4
@@ -131,12 +131,15 @@ int kvm__arch_get_ipa_limit(struct kvm *kvm)int kvm__get_vm_type (struct kvm *kvm) {unsigned int ipa_bits, max_ipa_bits; -unsigned long max_ipa; +unsigned long max_ipa, vm_type; -/* If we're running on an old kernel, use 0 as the VM type */ + vm_type = kvm->cfg.arch.is_realm ? \ +KVM_VM_TYPE_ARM_REALM :KVM_VM_TYPE_ARM_NORMAL ; + +/* If we're running on an old kernel, use 0 as the IPA bits */ max_ipa_bits =kvm__arch_get_ipa_limit (kvm);if (!max_ipa_bits) -return 0 ; +return vm_type;/* Otherwise, compute the minimal required IPA size */ max_ipa = kvm->cfg.ram_addr + kvm->cfg.ram_size -1 ;
@@ -147,7 +150,8 @@ int kvm__get_vm_type(struct kvm *kvm)if (ipa_bits > max_ipa_bits)die ("Memory too large for this system (needs %d bits, %d available)" , ipa_bits, max_ipa_bits); -return KVM_VM_TYPE_ARM_IPA_SIZE (ipa_bits); + vm_type |=KVM_VM_TYPE_ARM_IPA_SIZE (ipa_bits); +return vm_type; }void kvm__arch_enable_mte (struct kvm *kvm)
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 11/31 arm64: Lock realm RAM in memory
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
RMM doesn't yet support paging protected memory pages. Thus the VMM must pin the entire VM memory.
Use mlock2 to keep the realm pages pinned in memory once they are faulted in. Use the MLOCK_ONFAULT flag to prevent pre-mapping the pages and maintain some semblance of on demand-paging for a realm VM.
--- arm/kvm.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-)
arm/kvm.c +42 -2
@@ -7,6 +7,8 @@#include "arm-common/gic.h" +#include <sys/resource.h> +#include <linux/kernel.h> #include <linux/kvm.h> #include <linux/sizes.h>
@@ -24,6 +26,25 @@ bool kvm__arch_cpu_supports_vm(void)return true; } +static void try_increase_mlock_limit (struct kvm *kvm) +{ +u64 size = kvm->arch.ram_alloc_size; +struct rlimit mlock_limit, new_limit; + +if (getrlimit (RLIMIT_MEMLOCK , &mlock_limit)) { +perror ("getrlimit(RLIMIT_MEMLOCK)" ); +return ; + } + +if (mlock_limit.rlim_cur > size) +return ; + + new_limit.rlim_cur = size; + new_limit.rlim_max =max ((rlim_t )size, mlock_limit.rlim_max); +/* Requires CAP_SYS_RESOURCE capability. */ +setrlimit (RLIMIT_MEMLOCK , &new_limit); +} +void kvm__init_ram (struct kvm *kvm) {u64 phys_start, phys_size;
@@ -49,8 +70,27 @@ void kvm__init_ram(struct kvm *kvm) kvm->ram_start = (void *)ALIGN ((unsigned long )kvm->arch.ram_alloc_start,SZ_2M ); -madvise (kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, -MADV_MERGEABLE ); +/* +* Do not merge pages if this is a Realm. +* a) We cannot replace a page in realm stage2 without export/import +* +* Pin the realm memory until we have export/import, due to the same +* reason as above. +* +* Use mlock2(,,MLOCK_ONFAULT) to allow faulting in pages and thus +* allowing to lazily populate the PAR. +*/ +if (kvm->cfg.arch.is_realm) { +int ret; + +try_increase_mlock_limit (kvm); + ret =mlock2 (kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, +MLOCK_ONFAULT ); +if (ret) +die_perror ("mlock2" ); + }else { +madvise (kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,MADV_MERGEABLE ); + }madvise (kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,MADV_HUGEPAGE );
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 12/31 arm64: Create Realm Descriptor
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
Create the Realm Descriptor using the measurement algorithm set with --measurement-algo.
--- Makefile | 1 + arm/aarch32/include/asm/realm.h | 10 ++++++++++ arm/aarch64/include/asm/realm.h | 10 ++++++++++ arm/aarch64/realm.c | 14 ++++++++++++++ arm/kvm.c | 3 +++ 5 files changed, 38 insertions(+) create mode 100644 arm/aarch32/include/asm/realm.h create mode 100644 arm/aarch64/include/asm/realm.h create mode 100644 arm/aarch64/realm.c
Makefile +1 -0
@@ -192,6 +192,7 @@ ifeq ($(ARCH), arm64) OBJS += arm/aarch64/kvm.o OBJS += arm/aarch64/pvtime.o OBJS += arm/aarch64/pmu.o + OBJS += arm/aarch64/realm.o ARCH_INCLUDE := $(HDRS_ARM_COMMON) ARCH_INCLUDE += -Iarm/aarch64/include
arm/aarch32/include/asm/realm.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_REALM_H +#define __ASM_REALM_H + +#include "kvm/kvm.h" + +static inline void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm) {} + +#endif /* ! __ASM_REALM_H */
arm/aarch64/include/asm/realm.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_REALM_H +#define __ASM_REALM_H + +#include "kvm/kvm.h" + +void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm); + +#endif /* ! __ASM_REALM_H */
arm/aarch64/realm.c new file +14 -0
@@ -0,0 +1,14 @@ +#include "kvm/kvm.h" + +#include <asm/realm.h> + +void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm) +{ +struct kvm_enable_cap rme_create_rd = { + .cap =KVM_CAP_ARM_RME , + .args[0 ] =KVM_CAP_ARM_RME_CREATE_RD , + }; + +if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &rme_create_rd) <0 ) +die_perror ("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)" ); +}
arm/kvm.c +3 -0
@@ -127,6 +127,9 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)void kvm__arch_init (struct kvm *kvm) { +if (kvm->cfg.arch.is_realm) +kvm_arm_realm_create_realm_descriptor (kvm); +/* Create the virtual GIC. */ if (gic__create (kvm, kvm->cfg.arch.irqchip))die ("Failed to create virtual GIC" );
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 13/31 arm64: Add --measurement-algo command line option for a realm
In reply to Suzuki K PouloseFrom: Christoffer Dall <[email protected]>
Add the command line option to specify the algorithm that will be used to create the cryptographic measurement of the realm. Valid options are "sha256" and "sha512". The final measurement will be a hash using the selected algorithm
--- arm/aarch64/include/kvm/kvm-config-arch.h | 5 ++++- arm/aarch64/kvm.c | 17 ++++++++++++++++- arm/include/arm-common/kvm-arch.h | 1 + arm/include/arm-common/kvm-config-arch.h | 1 + 4 files changed, 22 insertions(+), 2 deletions(-)
arm/aarch64/include/kvm/kvm-config-arch.h +4 -1
@@ -23,7 +23,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset);OPT_BOOLEAN ('\0' ,"disable-sve" , &(cfg)->disable_sve, \"Disable SVE" ), \OPT_BOOLEAN ('\0' ,"realm" , &(cfg)->is_realm, \ -"Create VM running in a realm using Arm RME" ), +"Create VM running in a realm using Arm RME" ), \ +OPT_STRING ('\0' ,"measurement-algo" , &(cfg)->measurement_algo, \ +"sha256, sha512" , \ +"Realm Measurement algorithm, default: sha256" ), #include "arm-common/kvm-config-arch.h"
arm/aarch64/kvm.c +16 -1
@@ -53,12 +53,27 @@ static void validate_mem_cfg(struct kvm *kvm)static void validate_realm_cfg (struct kvm *kvm) { -if (!kvm->cfg.arch.is_realm) +if (!kvm->cfg.arch.is_realm) { +if (kvm->cfg.arch.measurement_algo) +die ("--measurement-algo valid only with --realm" );return ; + }if (kvm->cfg.arch.aarch32_guest)die ("Realms supported only for 64bit guests" ); +if (kvm->cfg.arch.measurement_algo) { +if (strcmp (kvm->cfg.arch.measurement_algo,"sha256" ) ==0 ) + kvm->arch.measurement_algo =KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256 ; +else if (strcmp (kvm->cfg.arch.measurement_algo,"sha512" ) ==0 ) + kvm->arch.measurement_algo =KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA512 ; +else +die ("unknown realm measurement algorithm" ); + }else { +pr_debug ("Realm Hash algorithm: Using default SHA256\n" ); + kvm->arch.measurement_algo =KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256 ; + } +die ("Realms not supported" ); }
arm/include/arm-common/kvm-arch.h +1 -0
@@ -113,6 +113,7 @@ struct kvm_arch {u64 dtb_guest_start;cpu_set_t *vcpu_affinity_cpuset; + u64 measurement_algo; };#endif /* ARM_COMMON__KVM_ARCH_H */
arm/include/arm-common/kvm-config-arch.h +1 -0
@@ -6,6 +6,7 @@struct kvm_config_arch {const char *dump_dtb_filename;const char *vcpu_affinity; +const char *measurement_algo;unsigned int force_cntfrq;bool virtio_trans_pci;bool aarch32_guest;
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 14/31 arm64: Add configuration step for Realms
In reply to Suzuki K PouloseRealm must be configured before it is created. Add the step to specify the parameters for the Realm.
--- arm/aarch64/realm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
arm/aarch64/realm.c +24 -0
@@ -2,6 +2,29 @@#include <asm/realm.h> + +static void realm_configure_hash_algo (struct kvm *kvm) +{ +struct kvm_cap_arm_rme_config_item hash_algo_cfg = { + .cfg =KVM_CAP_ARM_RME_CFG_HASH_ALGO , + .hash_algo = kvm->arch.measurement_algo, + }; + +struct kvm_enable_cap rme_config = { + .cap =KVM_CAP_ARM_RME , + .args[0 ] =KVM_CAP_ARM_RME_CONFIG_REALM , + .args[1 ] = (u64)&hash_algo_cfg, + }; + +if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &rme_config) <0 ) +die_perror ("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) hash_algo" ); +} + +static void realm_configure_parameters (struct kvm *kvm) +{ +realm_configure_hash_algo (kvm); +} +void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm) {struct kvm_enable_cap rme_create_rd = {
@@ -9,6 +32,7 @@ void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) .args[0] = KVM_CAP_ARM_RME_CREATE_RD, }; +realm_configure_parameters (kvm);if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &rme_create_rd) <0 )die_perror ("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)" ); }
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 15/31 arm64: Add support for Realm Personalisation Value
In reply to Suzuki K PouloseAdd option to specify Realm personalisation value
--- arm/aarch64/include/kvm/kvm-config-arch.h | 6 +++++- arm/aarch64/kvm.c | 7 +++++++ arm/aarch64/realm.c | 23 +++++++++++++++++++++++ arm/include/arm-common/kvm-config-arch.h | 1 + 4 files changed, 36 insertions(+), 1 deletion(-)
arm/aarch64/include/kvm/kvm-config-arch.h +5 -1
@@ -26,7 +26,11 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Create VM running in a realm using Arm RME"), \OPT_STRING ('\0' ,"measurement-algo" , &(cfg)->measurement_algo, \"sha256, sha512" , \ -"Realm Measurement algorithm, default: sha256" ), +"Realm Measurement algorithm, default: sha256" ),\ +OPT_STRING ('\0' ,"realm-pv" , &(cfg)->realm_pv, \ +"personalisation value" , \ +"Personalisation Value (only) for Realm VMs" ), + #include "arm-common/kvm-config-arch.h"
arm/aarch64/kvm.c +7 -0
@@ -56,6 +56,8 @@ static void validate_realm_cfg(struct kvm *kvm)if (!kvm->cfg.arch.is_realm) {if (kvm->cfg.arch.measurement_algo)die ("--measurement-algo valid only with --realm" ); +if (kvm->cfg.arch.realm_pv) +die ("--realm-pv valid only with --realm" );return ; }
@@ -74,6 +76,11 @@ static void validate_realm_cfg(struct kvm *kvm) kvm->arch.measurement_algo =KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256 ; } +if (kvm->cfg.arch.realm_pv) { +if (strlen (kvm->cfg.arch.realm_pv) >KVM_CAP_ARM_RME_RPV_SIZE ) +die ("Invalid size for Realm Personalization Value\n" ); + } +die ("Realms not supported" ); }
arm/aarch64/realm.c +23 -0
@@ -20,9 +20,32 @@ static void realm_configure_hash_algo(struct kvm *kvm)die_perror ("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) hash_algo" ); } +static void realm_configure_rpv (struct kvm *kvm) +{ +struct kvm_cap_arm_rme_config_item rpv_cfg = { + .cfg =KVM_CAP_ARM_RME_CFG_RPV , + }; + +struct kvm_enable_cap rme_config = { + .cap =KVM_CAP_ARM_RME , + .args[0 ] =KVM_CAP_ARM_RME_CONFIG_REALM , + .args[1 ] = (u64)&rpv_cfg, + }; + +if (!kvm->cfg.arch.realm_pv) +return ; + +memset (&rpv_cfg.rpv,0 ,sizeof (rpv_cfg.rpv)); +memcpy (&rpv_cfg.rpv, kvm->cfg.arch.realm_pv,strlen (kvm->cfg.arch.realm_pv)); + +if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &rme_config) <0 ) +die_perror ("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) RPV" ); +} +static void realm_configure_parameters (struct kvm *kvm) {realm_configure_hash_algo (kvm); +realm_configure_rpv (kvm); }void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm)
arm/include/arm-common/kvm-config-arch.h +1 -0
@@ -7,6 +7,7 @@ struct kvm_config_arch {const char *dump_dtb_filename;const char *vcpu_affinity;const char *measurement_algo; +const char *realm_pv;unsigned int force_cntfrq;bool virtio_trans_pci;bool aarch32_guest;
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 16/31 arm64: Add support for specifying the SVE vector length for Realm
In reply to Suzuki K PouloseAdd option to specify SVE vector length for realms.
--- arm/aarch64/include/kvm/kvm-config-arch.h | 6 ++++-- arm/aarch64/kvm.c | 23 +++++++++++++++++++++++ arm/aarch64/realm.c | 21 +++++++++++++++++++++ arm/include/arm-common/kvm-arch.h | 1 + arm/include/arm-common/kvm-config-arch.h | 1 + 5 files changed, 50 insertions(+), 2 deletions(-)
arm/aarch64/include/kvm/kvm-config-arch.h +4 -2
@@ -29,8 +29,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Realm Measurement algorithm, default: sha256"),\OPT_STRING ('\0' ,"realm-pv" , &(cfg)->realm_pv, \"personalisation value" , \ -"Personalisation Value (only) for Realm VMs" ), - +"Personalisation Value (only) for Realm VMs" ), \ +OPT_U64 ('\0' ,"sve-vl" , &(cfg)->sve_vl, \ +"SVE Vector Length the VM" \ +"(only supported for Realms)" ), #include "arm-common/kvm-config-arch.h"
arm/aarch64/kvm.c +23 -0
@@ -51,13 +51,19 @@ static void validate_mem_cfg(struct kvm *kvm) } } +#define SVE_VL_ALIGN 128 +static void validate_realm_cfg (struct kvm *kvm) { +u32 sve_vl; +if (!kvm->cfg.arch.is_realm) {if (kvm->cfg.arch.measurement_algo)die ("--measurement-algo valid only with --realm" );if (kvm->cfg.arch.realm_pv)die ("--realm-pv valid only with --realm" ); +if (kvm->cfg.arch.sve_vl) +die ("--sve-vl valid only with --realm" );return ; }
@@ -76,6 +82,23 @@ static void validate_realm_cfg(struct kvm *kvm) kvm->arch.measurement_algo =KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256 ; } + sve_vl = kvm->cfg.arch.sve_vl; +if (sve_vl) { +if (kvm->cfg.arch.disable_sve) +die ("SVE VL requested when SVE is disabled" ); +if (!IS_ALIGNED (sve_vl,SVE_VL_ALIGN )) +die ("SVE VL is not aligned to %dbit\n" ,SVE_VL_ALIGN ); + kvm->arch.sve_vq = (sve_vl /SVE_VL_ALIGN ) -1 ; + }else { +/* +* Disable SVE for Realms, if a VL is not requested. +* The SVE VL will be measured as part of the parameter +* and we do not want to add an unknown entity to the +* measurement. +*/ + kvm->cfg.arch.disable_sve = true; + } +if (kvm->cfg.arch.realm_pv) {if (strlen (kvm->cfg.arch.realm_pv) >KVM_CAP_ARM_RME_RPV_SIZE )die ("Invalid size for Realm Personalization Value\n" );
arm/aarch64/realm.c +21 -0
@@ -42,10 +42,31 @@ static void realm_configure_rpv(struct kvm *kvm)die_perror ("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) RPV" ); } +static void realm_configure_sve (struct kvm *kvm) +{ +struct kvm_cap_arm_rme_config_item sve_cfg = { + .cfg =KVM_CAP_ARM_RME_CFG_SVE , + .sve_vq = kvm->arch.sve_vq, + }; + +struct kvm_enable_cap rme_config = { + .cap =KVM_CAP_ARM_RME , + .args[0 ] =KVM_CAP_ARM_RME_CONFIG_REALM , + .args[1 ] = (u64)&sve_cfg, + }; + +if (kvm->cfg.arch.disable_sve) +return ; + +if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &rme_config) <0 ) +die_perror ("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) SVE" ); +} +static void realm_configure_parameters (struct kvm *kvm) {realm_configure_hash_algo (kvm);realm_configure_rpv (kvm); +realm_configure_sve (kvm); }void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm)
arm/include/arm-common/kvm-arch.h +1 -0
@@ -114,6 +114,7 @@ struct kvm_arch {cpu_set_t *vcpu_affinity_cpuset;u64 measurement_algo; + u64 sve_vq; };#endif /* ARM_COMMON__KVM_ARCH_H */
arm/include/arm-common/kvm-config-arch.h +1 -0
@@ -19,6 +19,7 @@ struct kvm_config_arch {u64 fw_addr;bool no_pvtime;bool disable_sve; +u64 sve_vl; };int irqchip_parser (const struct option *opt,const char *arg,int unset);
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 17/31 arm: Add kernel size to VM context
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
Add the kernel image size to the VM context, as we are going to use it later. This matches what we already do with the initrd.
--- arm/include/arm-common/kvm-arch.h | 1 + arm/kvm.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-)
arm/include/arm-common/kvm-arch.h +1 -0
@@ -108,6 +108,7 @@ struct kvm_arch {*/ u64 memory_guest_start;u64 kern_guest_start; +u64 kern_size;u64 initrd_guest_start;u64 initrd_size;u64 dtb_guest_start;
arm/kvm.c +5 -3
@@ -153,7 +153,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, limit = kvm->ram_start +min (kvm->ram_size, (u64 )SZ_256M ) -1 ; pos = kvm->ram_start +kvm__arch_get_kern_offset (kvm, fd_kernel); - kvm->arch.kern_guest_start =host_to_guest_flat (kvm, pos); file_size =read_file (fd_kernel, pos, limit - pos);if (file_size <0 ) {if (errno ==ENOMEM )
@@ -161,9 +160,12 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,die_perror ("kernel read" ); } + + kvm->arch.kern_guest_start =host_to_guest_flat (kvm, pos); + kvm->arch.kern_size = file_size; kernel_end = pos + file_size; -pr_debug ("Loaded kernel to 0x%llx (%zd bytes)" , - kvm->arch.kern_guest_start, file_size); +pr_debug ("Loaded kernel to 0x%llx (%llu bytes)" , + kvm->arch.kern_guest_start, kvm->arch.kern_size);/* * Now load backwards from the end of memory so the kernel
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 18/31 arm64: Populate initial realm contents
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
Populate the realm memory with the initial contents, which include the device tree blob, the kernel image, and initrd, if specified, or the firmware image.
Populating an image in the realm involves two steps:
a) Mark the IPA area as RAM - INIT_IPA_REALM
b) Load the contents into the IPA - POPULATE_REALM
Wherever we know the actual size of an image in memory, we make sure the "memory area" is initialised to RAM.
e.g., Linux kernel image size from the header which includes the bss etc. The "file size" on disk for the Linux image is much smaller. We mark the region of size Image.header.size as RAM (a), from the kernel load address. And load the Image file into the memory (b) above. At the moment we only detect the Arm64 Linux Image header format.
Since we're already touching the code that copies the initrd in guest memory, let's do a bit of cleaning and remove a useless local variable.
--- arm/aarch32/include/asm/realm.h | 3 + arm/aarch64/include/asm/realm.h | 3 + arm/aarch64/realm.c | 112 ++++++++++++++++++++++++++++++++ arm/fdt.c | 6 ++ arm/kvm.c | 20 ++++-- include/linux/kernel.h | 1 + 6 files changed, 140 insertions(+), 5 deletions(-)
arm/aarch32/include/asm/realm.h +3 -0
@@ -6,5 +6,8 @@#include "kvm/kvm.h" static inline void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_kernel (struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_initrd (struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_dtb (struct kvm *kvm) {}#endif /* ! __ASM_REALM_H */
arm/aarch64/include/asm/realm.h +3 -0
@@ -6,5 +6,8 @@#include "kvm/kvm.h" void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm); +void kvm_arm_realm_populate_kernel (struct kvm *kvm); +void kvm_arm_realm_populate_initrd (struct kvm *kvm); +void kvm_arm_realm_populate_dtb (struct kvm *kvm);#endif /* ! __ASM_REALM_H */
arm/aarch64/realm.c +112 -0
120 lines not on this page · raw message
arm/fdt.c +6 -0
@@ -7,6 +7,8 @@#include "arm-common/gic.h" #include "arm-common/pci.h" +#include <asm/realm.h> +#include <stdbool.h> #include <linux/byteorder.h>
@@ -231,6 +233,10 @@ static int setup_fdt(struct kvm *kvm)if (kvm->cfg.arch.dump_dtb_filename)dump_fdt (kvm->cfg.arch.dump_dtb_filename, fdt_dest); + +if (kvm->cfg.arch.is_realm) +kvm_arm_realm_populate_dtb (kvm); +return 0 ; }late_init (setup_fdt);
arm/kvm.c +15 -5
@@ -6,6 +6,7 @@#include "kvm/fdt.h" #include "arm-common/gic.h" +#include <asm/realm.h> #include <sys/resource.h>
@@ -167,6 +168,9 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,pr_debug ("Loaded kernel to 0x%llx (%llu bytes)" , kvm->arch.kern_guest_start, kvm->arch.kern_size); +if (kvm->cfg.arch.is_realm) +kvm_arm_realm_populate_kernel (kvm); +/* * Now load backwards from the end of memory so the kernel * decompressor has plenty of space to work with. First up is
@@ -188,7 +192,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,/* ... and finally the initrd, if we have one. */ if (fd_initrd !=-1 ) {struct stat sb; -unsigned long initrd_start;if (fstat (fd_initrd, &sb))die_perror ("fstat" );
@@ -199,7 +202,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,if (pos < kernel_end)die ("initrd overlaps with kernel image." ); - initrd_start = guest_addr; file_size =read_file (fd_initrd, pos, limit - pos);if (file_size ==-1 ) {if (errno ==ENOMEM )
@@ -208,11 +210,13 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,die_perror ("initrd read" ); } - kvm->arch.initrd_guest_start = initrd_start; + kvm->arch.initrd_guest_start = guest_addr; kvm->arch.initrd_size = file_size;pr_debug ("Loaded initrd to 0x%llx (%llu bytes)" , - kvm->arch.initrd_guest_start, - kvm->arch.initrd_size); + kvm->arch.initrd_guest_start, kvm->arch.initrd_size); + +if (kvm->cfg.arch.is_realm) +kvm_arm_realm_populate_initrd (kvm); }else { kvm->arch.initrd_size =0 ; }
@@ -269,6 +273,8 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename)/* Kernel isn't loaded by kvm, point start address to firmware */ kvm->arch.kern_guest_start = fw_addr; + kvm->arch.kern_size = fw_sz; +pr_debug ("Loaded firmware to 0x%llx (%zd bytes)" , kvm->arch.kern_guest_start, fw_sz);
@@ -283,6 +289,10 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) kvm->arch.dtb_guest_start, kvm->arch.dtb_guest_start + FDT_MAX_SIZE); +if (kvm->cfg.arch.is_realm) +/* We hijack the kernel fields to describe the firmware. */ +kvm_arm_realm_populate_kernel (kvm); +return true; }
include/linux/kernel.h +1 -0
@@ -9,6 +9,7 @@#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d)) +#define ALIGN_DOWN (x,a) __ALIGN_MASK(x - (typeof(x))((a) - 1),(typeof(x))(a)-1)#define ALIGN (x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)#define __ALIGN_MASK (x,mask) (((x)+(mask))&~(mask))#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
Signature · 1 line
2.34.1
Re: [RFC kvmtool 18/31] arm64: Populate initial realm contents
Hi,
Quoted 223 lines
From: Alexandru Elisei <[email protected]>
Populate the realm memory with the initial contents, which include the device tree blob, the kernel image, and initrd, if specified, or the firmware image.
Populating an image in the realm involves two steps:
a) Mark the IPA area as RAM -INIT_IPA_REALM
b) Load the contents into the IPA -POPULATE_REALMWherever we know the actual size of an image in memory, we make sure the "memory area" is initialised to RAM.
e.g., Linux kernel image size from the header which includes the bss etc. The "file size" on disk for the Linux image is much smaller. We mark the region of size Image.header.size as RAM (a), from the kernel load address. And load the Image file into the memory (b) above. At the moment we only detect the Arm64 Linux Image header format.Since we're already touching the code that copies the initrd in guest memory, let's do a bit of cleaning and remove a useless local variable.
Signed-off-by Alexandru Elisei <[email protected]>[ Make sure the Linux kernel image area is marked as RAM ]Signed-off-by Suzuki K Poulose <[email protected]>--- arm/aarch32/include/asm/realm.h | 3 + arm/aarch64/include/asm/realm.h | 3 + arm/aarch64/realm.c | 112 ++++++++++++++++++++++++++++++++ arm/fdt.c | 6 ++ arm/kvm.c | 20 ++++-- include/linux/kernel.h | 1 + 6 files changed, 140 insertions(+), 5 deletions(-)arm/aarch32/include/asm/realm.h +3
-0@@ -6,5 +6,8 @@#include "kvm/kvm.h" static inline void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_kernel (struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_initrd (struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_dtb (struct kvm *kvm) {}#endif /* ! __ASM_REALM_H */ arm/aarch64/include/asm/realm.h +3
-0@@ -6,5 +6,8 @@#include "kvm/kvm.h" void kvm_arm_realm_create_realm_descriptor (struct kvm *kvm); +void kvm_arm_realm_populate_kernel (struct kvm *kvm); +void kvm_arm_realm_populate_initrd (struct kvm *kvm); +void kvm_arm_realm_populate_dtb (struct kvm *kvm);#endif /* ! __ASM_REALM_H */ arm/aarch64/realm.c +112
-0@@ -1,5 +1,7 @@#include "kvm/kvm.h" +#include <linux/byteorder.h> +#include <asm/image.h> #include <asm/realm.h> @@ -80,3 +82,113 @@ void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm)if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &rme_create_rd) <0 )die_perror ("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)" ); } + +static void realm_init_ipa_range (struct kvm *kvm,u64 start,u64 size) +{ +struct kvm_cap_arm_rme_init_ipa_args init_ipa_args = { + .init_ipa_base = start, + .init_ipa_size = size + }; +struct kvm_enable_cap rme_init_ipa_realm = { + .cap =KVM_CAP_ARM_RME , + .args[0 ] =KVM_CAP_ARM_RME_INIT_IPA_REALM , + .args[1 ] = (u64)&init_ipa_args + }; + +if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &rme_init_ipa_realm) <0 ) +die ("unable to intialise IPA range for Realm %llx - %llx (size %llu)" , + start, start + size, size); + +} + +static void __realm_populate (struct kvm *kvm,u64 start,u64 size) +{ +struct kvm_cap_arm_rme_populate_realm_args populate_args = { + .populate_ipa_base = start, + .populate_ipa_size = size + }; +struct kvm_enable_cap rme_populate_realm = { + .cap =KVM_CAP_ARM_RME , + .args[0 ] =KVM_CAP_ARM_RME_POPULATE_REALM , + .args[1 ] = (u64)&populate_args + }; + +if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &rme_populate_realm) <0 ) +die ("unable to populate Realm memory %llx - %llx (size %llu)" , + start, start + size, size); +} + +static void realm_populate (struct kvm *kvm,u64 start,u64 size) +{ +realm_init_ipa_range (kvm, start, size); +__realm_populate (kvm, start, size); +} + +static bool is_arm64_linux_kernel_image (void *header) +{ +struct arm64_image_header *hdr = header; + +return memcmp (&hdr->magic,ARM64_IMAGE_MAGIC ,sizeof (hdr->magic)) ==0 ; +} + +static ssize_t arm64_linux_kernel_image_size (void *header) +{ +struct arm64_image_header *hdr = header; + +if (is_arm64_linux_kernel_image (header)) +return le64_to_cpu (hdr->image_size); +die ("Not arm64 Linux kernel Image" ); +} + +void kvm_arm_realm_populate_kernel (struct kvm *kvm) +{ +u64 start, end, mem_size; +void *header =guest_flat_to_host (kvm, kvm->arch.kern_guest_start); + + start =ALIGN_DOWN (kvm->arch.kern_guest_start,SZ_4K ); + end =ALIGN (kvm->arch.kern_guest_start + kvm->arch.kern_size,SZ_4K ); + +if (is_arm64_linux_kernel_image (header)) + mem_size =arm64_linux_kernel_image_size (header); +else + mem_size = end - start; + +realm_init_ipa_range (kvm, start, mem_size); +__realm_populate (kvm, start, end - start); +} + +void kvm_arm_realm_populate_initrd (struct kvm *kvm) +{ +u64 kernel_end, start, end; + + kernel_end =ALIGN (kvm->arch.kern_guest_start + kvm->arch.kern_size,SZ_4K ); + start =ALIGN_DOWN (kvm->arch.initrd_guest_start,SZ_4K ); +/* +* Because we align the initrd to 4 bytes, it is theoretically possible +* for the start of the initrd to overlap with the same page where the +* kernel ends. +*/ +if (start < kernel_end) + start = kernel_end; + end =ALIGN (kvm->arch.initrd_guest_start + kvm->arch.initrd_size,SZ_4K ); +if (end > start) +realm_populate (kvm, start, end - start); +} + +void kvm_arm_realm_populate_dtb (struct kvm *kvm) +{ +u64 initrd_end, start, end; + + initrd_end =ALIGN (kvm->arch.initrd_guest_start + kvm->arch.initrd_size,SZ_4K ); + start =ALIGN_DOWN (kvm->arch.dtb_guest_start,SZ_4K ); +/* +* Same situation as with the initrd, but now it is the DTB which is +* overlapping with the last page of the initrd, because the initrd is +* populated first. +*/ +if (start < initrd_end) + start = initrd_end; + end =ALIGN (kvm->arch.dtb_guest_start +FDT_MAX_SIZE ,SZ_4K ); +if (end > start) +realm_populate (kvm, start, end - start); +}arm/fdt.c +6
-0@@ -7,6 +7,8 @@#include "arm-common/gic.h" #include "arm-common/pci.h" +#include <asm/realm.h> +#include <stdbool.h> #include <linux/byteorder.h> @@ -231,6 +233,10 @@ static int setup_fdt(struct kvm *kvm)if (kvm->cfg.arch.dump_dtb_filename)dump_fdt (kvm->cfg.arch.dump_dtb_filename, fdt_dest); + +if (kvm->cfg.arch.is_realm) +kvm_arm_realm_populate_dtb (kvm); +return 0 ; }late_init (setup_fdt);arm/kvm.c +1
-0@@ -6,6 +6,7 @@#include "kvm/fdt.h" #include "arm-common/gic.h" +#include <asm/realm.h> #include <sys/resource.h>
arm/kvm.c bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, · line 169
Quoted 2 lines
arm/kvm.c +0
-0@@ -167,6 +168,9 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,pr_debug ("Loaded kernel to 0x%llx (%llu bytes)" , kvm->arch.kern_guest_start, kvm->arch.kern_size);
I've noticed that multiple calling of the measurement test from the kvm-unit-tests suite results in different Realm Initial Measurements, although the kernel image is always the same.
After short investigation, I've found that the RIM starts being different while populating the last 4kB chunk of the kernel image. The issue occurs when the image size is not aligned to the page size (4kB).
After zeroing the unused area of the last chunk, the measurements become repeatable.
Quoted 64 lines
arm/kvm.c +14
-5+if (kvm->cfg.arch.is_realm) +kvm_arm_realm_populate_kernel (kvm); +/* * Now load backwards from the end of memory so the kernel * decompressor has plenty of space to work with. First up is @@ -188,7 +192,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,/* ... and finally the initrd, if we have one. */ if (fd_initrd !=-1 ) {struct stat sb; -unsigned long initrd_start;if (fstat (fd_initrd, &sb))die_perror ("fstat" );@@ -199,7 +202,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,if (pos < kernel_end)die ("initrd overlaps with kernel image." ); - initrd_start = guest_addr; file_size =read_file (fd_initrd, pos, limit - pos);if (file_size ==-1 ) {if (errno ==ENOMEM )@@ -208,11 +210,13 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,die_perror ("initrd read" ); } - kvm->arch.initrd_guest_start = initrd_start; + kvm->arch.initrd_guest_start = guest_addr; kvm->arch.initrd_size = file_size;pr_debug ("Loaded initrd to 0x%llx (%llu bytes)" , - kvm->arch.initrd_guest_start, - kvm->arch.initrd_size); + kvm->arch.initrd_guest_start, kvm->arch.initrd_size); + +if (kvm->cfg.arch.is_realm) +kvm_arm_realm_populate_initrd (kvm); }else { kvm->arch.initrd_size =0 ; }@@ -269,6 +273,8 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename)/* Kernel isn't loaded by kvm, point start address to firmware */ kvm->arch.kern_guest_start = fw_addr; + kvm->arch.kern_size = fw_sz; +pr_debug ("Loaded firmware to 0x%llx (%zd bytes)" , kvm->arch.kern_guest_start, fw_sz);@@ -283,6 +289,10 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) kvm->arch.dtb_guest_start, kvm->arch.dtb_guest_start + FDT_MAX_SIZE); +if (kvm->cfg.arch.is_realm) +/* We hijack the kernel fields to describe the firmware. */ +kvm_arm_realm_populate_kernel (kvm); +return true; }include/linux/kernel.h +0
-0
include/linux/kernel.h line 15
Quoted 7 lines
include/linux/kernel.h +1
-0@@ -9,6 +9,7 @@#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d)) +#define ALIGN_DOWN (x,a) __ALIGN_MASK(x - (typeof(x))((a) - 1),(typeof(x))(a)-1)#define ALIGN (x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)#define __ALIGN_MASK (x,mask) (((x)+(mask))&~(mask))#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
Kind regards,
Piotr Sawicki
Suzuki K Poulose
reviewerRe: [RFC kvmtool 18/31] arm64: Populate initial realm contents
Hi Piotr
Quoted 46 lines · Piotr Sawicki
Hi,
Quoted 37 lines
From: Alexandru Elisei <[email protected]>
Populate the realm memory with the initial contents, which include the device tree blob, the kernel image, and initrd, if specified, or the firmware image.
Populating an image in the realm involves two steps:
a) Mark the IPA area as RAM -INIT_IPA_REALM
b) Load the contents into the IPA -POPULATE_REALMWherever we know the actual size of an image in memory, we make sure the "memory area" is initialised to RAM.
e.g., Linux kernel image size from the header which includes the bss etc. The "file size" on disk for the Linux image is much smaller. We mark the region of size Image.header.size as RAM (a), from the kernel load address. And load the Image file into the memory (b) above. At the moment we only detect the Arm64 Linux Image header format.Since we're already touching the code that copies the initrd in guest memory, let's do a bit of cleaning and remove a useless local variable.
Signed-off-by Alexandru Elisei <[email protected]>[ Make sure the Linux kernel image area is marked as RAM ]Signed-off-by Suzuki K Poulose <[email protected]>arm/kvm.c +1
-0@@ -6,6 +6,7 @@ #include "kvm/fdt.h" #include "arm-common/gic.h" +#include <asm/realm.h> #include <sys/resource.h>arm/kvm.c bool kvm__arch_load_kernel_image(struct kvm *kvm, · line 170
Quoted 3 lines
arm/kvm.c +0
-0@@ -167,6 +168,9 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, pr_debug("Loaded kernel to 0x%llx (%llu bytes)", kvm->arch.kern_guest_start, kvm->arch.kern_size);I've noticed that multiple calling of the measurement test from the kvm-unit-tests suite results in different Realm Initial Measurements, although the kernel image is always the same.
Quoted 5 lines
After short investigation, I've found that the RIM starts being different while populating the last 4kB chunk of the kernel image. The issue occurs when the image size is not aligned to the page size (4kB).
After zeroing the unused area of the last chunk, the measurements become repeatable.
That is a good point. We could memset() the remaining bits of the 4K page to 0. I will make this change.
Suzuki
Re: [RFC kvmtool 18/31] arm64: Populate initial realm contents
Hi Suzuki
Quoted 49 lines
Hi Piotr
Quoted 46 lines · Piotr Sawicki
Hi,
Quoted 37 lines
From: Alexandru Elisei <[email protected]>
Populate the realm memory with the initial contents, which include the device tree blob, the kernel image, and initrd, if specified, or the firmware image.
Populating an image in the realm involves two steps:
a) Mark the IPA area as RAM -INIT_IPA_REALM
b) Load the contents into the IPA -POPULATE_REALMWherever we know the actual size of an image in memory, we make sure the "memory area" is initialised to RAM.
e.g., Linux kernel image size from the header which includes the bss etc. The "file size" on disk for the Linux image is much smaller. We mark the region of size Image.header.size as RAM (a), from the kernel load address. And load the Image file into the memory (b) above. At the moment we only detect the Arm64 Linux Image header format.Since we're already touching the code that copies the initrd in guest memory, let's do a bit of cleaning and remove a useless local variable.
Signed-off-by Alexandru Elisei <[email protected]>[ Make sure the Linux kernel image area is marked as RAM ]Signed-off-by Suzuki K Poulose <[email protected]>arm/kvm.c +1
-0@@ -6,6 +6,7 @@ #include "kvm/fdt.h" #include "arm-common/gic.h" +#include <asm/realm.h> #include <sys/resource.h>arm/kvm.c bool kvm__arch_load_kernel_image(struct kvm *kvm, · line 170
Quoted 3 lines
arm/kvm.c +0
-0@@ -167,6 +168,9 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, pr_debug("Loaded kernel to 0x%llx (%llu bytes)", kvm->arch.kern_guest_start, kvm->arch.kern_size);I've noticed that multiple calling of the measurement test from the kvm-unit-tests suite results in different Realm Initial Measurements, although the kernel image is always the same.
Quoted 7 lines
Quoted 5 lines
After short investigation, I've found that the RIM starts being different while populating the last 4kB chunk of the kernel image. The issue occurs when the image size is not aligned to the page size (4kB).
After zeroing the unused area of the last chunk, the measurements become repeatable.
That is a good point. We could
memset()the remaining bits of the 4K page to 0. I will make this change.
It looks that this is somewhat related to the implementation of the 9p filesystem (Linux host and/or the FVP emulator).
I'm getting this issue only when the initrd and the guest kernel images are located in the shared folder that uses the 9p filesystem. Moving those files to the ramdisk (e.g. to the /root folder) and running lkvm tool on them resolves the issue.
Kind regards,
Piotr Sawicki
Suzuki K Poulose
reviewerRFC 19/31 arm64: Don't try to set PSTATE for VCPUs belonging to a realm
In reply to Suzuki K PouloseFrom: Christoffer Dall <[email protected]>
RME doesn't allow setting the PSTATE but resets it to an architectural value, and KVM also does not allow setting this register from user space, so stop trying to do that.
--- arm/aarch64/kvm-cpu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
arm/aarch64/kvm-cpu.c +7 -5
@@ -92,11 +92,13 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu) reg.addr = (u64)&data; -/* pstate = all interrupts masked */ - data =PSR_D_BIT |PSR_A_BIT |PSR_I_BIT |PSR_F_BIT | PSR_MODE_EL1h; - reg.id =ARM64_CORE_REG (regs.pstate); -if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 ) -die_perror ("KVM_SET_ONE_REG failed (spsr[EL1])" ); +if (!kvm->cfg.arch.is_realm) { +/* pstate = all interrupts masked */ + data =PSR_D_BIT |PSR_A_BIT |PSR_I_BIT |PSR_F_BIT | PSR_MODE_EL1h; + reg.id =ARM64_CORE_REG (regs.pstate); +if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 ) +die_perror ("KVM_SET_ONE_REG failed (PSTATE)" ); + }/* x1...x3 = 0 */ data =0 ;
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 20/31 arm64: Finalize realm VCPU after reset
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
In order to run a VCPU belonging to a realm, that VCPU must be in the finalized state. Finalize the CPU after reset, since kvmtool won't be touching the VCPU state afterwards.
--- arm/aarch64/kvm-cpu.c | 7 +++++++ 1 file changed, 7 insertions(+)
arm/aarch64/kvm-cpu.c +7 -0
@@ -128,6 +128,13 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu)if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 )die_perror ("KVM_SET_ONE_REG failed (pc)" ); } + +if (kvm->cfg.arch.is_realm) { +int feature =KVM_ARM_VCPU_REC ; + +if (ioctl (vcpu->vcpu_fd,KVM_ARM_VCPU_FINALIZE , &feature) <0 ) +die_perror ("KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_REC)" ); + } }void kvm_cpu__select_features (struct kvm *kvm,struct kvm_vcpu_init *init)
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 21/31 init: Add last_{init, exit} list macros
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
Add a last_init macro for constructor functions that will be executed last in the initialization process. Add a symmetrical macro, last_exit, for destructor functions that will be the last to be executed when kvmtool exits.
The list priority for the late_{init, exit} macros has been bumped down a spot, but their relative priority remains unchanged, to keep the same size for the init_lists and exit_lists.
--- include/kvm/util-init.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/kvm/util-init.h +4 -2
@@ -39,7 +39,8 @@ static void __attribute__ ((constructor)) __init__##cb(void) \#define dev_init (cb) __init_list_add(cb, 5)#define virtio_dev_init (cb) __init_list_add(cb, 6)#define firmware_init (cb) __init_list_add(cb, 7) -#define late_init (cb) __init_list_add(cb, 9) +#define late_init (cb) __init_list_add(cb, 8) +#define last_init (cb) __init_list_add(cb, 9)#define core_exit (cb) __exit_list_add(cb, 0)#define base_exit (cb) __exit_list_add(cb, 2)
@@ -47,5 +48,6 @@ static void __attribute__ ((constructor)) __init__##cb(void) \#define dev_exit (cb) __exit_list_add(cb, 5)#define virtio_dev_exit (cb) __exit_list_add(cb, 6)#define firmware_exit (cb) __exit_list_add(cb, 7) -#define late_exit (cb) __exit_list_add(cb, 9) +#define late_exit (cb) __exit_list_add(cb, 8) +#define last_exit (cb) __exit_list_add(cb, 9)#endif
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 22/31 arm64: Activate realm before the first VCPU is run
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
Before KVM can run a VCPU belong to a realm, the realm be activated. Activating a realm prevents the adding of new object and seals the cryptographic measurement of that realm. The VCPU state is part of the measurement, which means that realm activation must be performed after all VCPUs have been reset.
Current RMM implementation can only create RECs in the order of their MPIDRs. VCPUs get assigned MPIDRs by KVM based on their VCPU id. Reset the VCPUs in the order they were created from the main thread instead of doing it from their own thread, which doesn't guarantee any ordering.
--- arm/aarch64/kvm-cpu.c | 4 ++++ arm/aarch64/realm.c | 35 +++++++++++++++++++++++++++++++ arm/include/arm-common/kvm-arch.h | 1 + 3 files changed, 40 insertions(+)
arm/aarch64/kvm-cpu.c +4 -0
@@ -187,6 +187,10 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu)cpu_set_t *affinity;int ret; +/* VCPU reset is done before activating the realm. */ +if (kvm->arch.realm_is_active) +return ; + affinity = kvm->arch.vcpu_affinity_cpuset;if (affinity) { ret =sched_setaffinity (0 ,sizeof (cpu_set_t), affinity);
arm/aarch64/realm.c +35 -0
@@ -1,4 +1,5 @@#include "kvm/kvm.h" +#include "kvm/kvm-cpu.h" #include <linux/byteorder.h> #include <asm/image.h>
@@ -192,3 +193,37 @@ void kvm_arm_realm_populate_dtb(struct kvm *kvm)if (end > start)realm_populate (kvm, start, end - start); } + +static void kvm_arm_realm_activate_realm (struct kvm *kvm) +{ +struct kvm_enable_cap activate_realm = { + .cap =KVM_CAP_ARM_RME , + .args[0 ] =KVM_CAP_ARM_RME_ACTIVATE_REALM , + }; + +if (ioctl (kvm->vm_fd,KVM_ENABLE_CAP , &activate_realm) <0 ) +die_perror ("KVM_CAP_ARM_RME(KVM_CAP_ARM_RME_ACTIVATE_REALM)" ); + + kvm->arch.realm_is_active = true; +} + +static int kvm_arm_realm_finalize (struct kvm *kvm) +{ +int i; + +if (!kvm->cfg.arch.is_realm) +return 0 ; + +/* +* VCPU reset must happen before the realm is activated, because their +* state is part of the cryptographic measurement for the realm. +*/ +for (i =0 ; i < kvm->nrcpus; i++) +kvm_cpu__reset_vcpu (kvm->cpus[i]); + +/* Activate and seal the measurement for the realm. */ +kvm_arm_realm_activate_realm (kvm); + +return 0 ; +} +last_init (kvm_arm_realm_finalize)
arm/include/arm-common/kvm-arch.h +1 -0
@@ -116,6 +116,7 @@ struct kvm_arch {cpu_set_t *vcpu_affinity_cpuset;u64 measurement_algo;u64 sve_vq; + bool realm_is_active; };#endif /* ARM_COMMON__KVM_ARCH_H */
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 23/31 arm64: Specify SMC as the PSCI conduits for realms
In reply to Suzuki K PouloseFrom: Christoffer Dall <[email protected]>
This lets the VM use the RMM implementation for PSCI.
--- arm/fdt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arm/fdt.c +8 -1
@@ -208,7 +208,14 @@ static int setup_fdt(struct kvm *kvm)_FDT (fdt_property_string (fdt,"compatible" ,"arm,psci" )); fns = &psci_0_1_fns; } -_FDT (fdt_property_string (fdt,"method" ,"hvc" )); + + +if (kvm->cfg.arch.is_realm) { +_FDT (fdt_property_string (fdt,"method" ,"smc" )); + }else { +_FDT (fdt_property_string (fdt,"method" ,"hvc" )); + } +_FDT (fdt_property_cell (fdt,"cpu_suspend" , fns->cpu_suspend));_FDT (fdt_property_cell (fdt,"cpu_off" , fns->cpu_off));_FDT (fdt_property_cell (fdt,"cpu_on" , fns->cpu_on));
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 24/31 arm64: Don't try to debug a realm
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
Don't read the register values for a running realm, because they don't reflect the actual hardware state of a realm. And don't try to read realm memory, because that will promptly lead to kvmtool being killed.
--- arm/aarch64/kvm-cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arm/aarch64/kvm-cpu.c +8 -0
@@ -250,6 +250,9 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu) reg.addr = (u64)&data; +if (vcpu->kvm->cfg.arch.is_realm) +return ; +dprintf (debug_fd,"\n*pc:\n" ); reg.id =ARM64_CORE_REG (regs.pc);if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 )
@@ -274,6 +277,11 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu) reg.addr = (u64)&data;dprintf (debug_fd,"\n Registers:\n" ); +if (vcpu->kvm->cfg.arch.is_realm) { +dprintf (debug_fd," UNACCESSIBLE\n" ); +return ; + } + reg.id =ARM64_CORE_REG (regs.pc);if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 )die ("KVM_GET_ONE_REG failed (pc)" );
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 25/31 arm64: realm: Double the IPA space
In reply to Suzuki K PouloseThe Realm's IPA space is divided into 2 halves. Protected (lower half) and Unprotected (upper half). KVM implements aliasing of the IPA, where the unprotected IPA is alias of the corresponding protected ipa. Thus we must double the IPA space required for a given VM.
--- arm/aarch64/kvm.c | 3 +++ 1 file changed, 3 insertions(+)
arm/aarch64/kvm.c +3 -0
@@ -189,6 +189,9 @@ int kvm__get_vm_type(struct kvm *kvm)/* Otherwise, compute the minimal required IPA size */ max_ipa = kvm->cfg.ram_addr + kvm->cfg.ram_size -1 ; ipa_bits =max (32 ,fls_long (max_ipa)); +/* Realm needs double the IPA space */ +if (kvm->cfg.arch.is_realm) + ipa_bits++;pr_debug ("max_ipa %lx ipa_bits %d max_ipa_bits %d" , max_ipa, ipa_bits, max_ipa_bits);
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 26/31 virtio: Add a wrapper for get_host_features
In reply to Suzuki K PouloseAdd a wrapper to the vdev->ops->get_host_features() to allow setting platform specific flags outside the device
--- include/kvm/virtio.h | 2 ++ virtio/core.c | 5 +++++ virtio/mmio-legacy.c | 2 +- virtio/mmio-modern.c | 2 +- virtio/pci-legacy.c | 2 +- virtio/pci-modern.c | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-)
include/kvm/virtio.h +2 -0
@@ -248,4 +248,6 @@ void virtio_set_guest_features(struct kvm *kvm, struct virtio_device *vdev,void virtio_notify_status (struct kvm *kvm,struct virtio_device *vdev,void *dev,u8 status); +u64 virtio_dev_get_host_features (struct virtio_device *vdev,struct kvm *kvm,void *dev); +#endif /* KVM__VIRTIO_H */
virtio/core.c +5 -0
@@ -283,6 +283,11 @@ void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev, vdev->ops->notify_status (kvm, dev, ext_status); } +u64 virtio_dev_get_host_features (struct virtio_device *vdev,struct kvm *kvm,void *dev) +{ +return vdev->ops->get_host_features (kvm, dev); +} +bool virtio_access_config (struct kvm *kvm,struct virtio_device *vdev,void *dev,unsigned long offset,void *data,size_t size,bool is_write)
virtio/mmio-legacy.c +1 -1
@@ -26,7 +26,7 @@ static void virtio_mmio_config_in(struct kvm_cpu *vcpu,break ;case VIRTIO_MMIO_DEVICE_FEATURES :if (vmmio->hdr.host_features_sel ==0 ) - val = vdev->ops->get_host_features (vmmio->kvm, + val =virtio_dev_get_host_features (vdev, vmmio->kvm, vmmio->dev);ioport__write32 (data, val);break ;
virtio/mmio-modern.c +1 -1
@@ -26,7 +26,7 @@ static void virtio_mmio_config_in(struct kvm_cpu *vcpu,case VIRTIO_MMIO_DEVICE_FEATURES :if (vmmio->hdr.host_features_sel >1 )break ; - features |= vdev->ops->get_host_features (vmmio->kvm, vmmio->dev); + features |=virtio_dev_get_host_features (vdev, vmmio->kvm, vmmio->dev); val = features >> (32 * vmmio->hdr.host_features_sel);break ;case VIRTIO_MMIO_QUEUE_NUM_MAX :
virtio/pci-legacy.c +1 -1
@@ -44,7 +44,7 @@ static bool virtio_pci__data_in(struct kvm_cpu *vcpu, struct virtio_device *vdevswitch (offset) {case VIRTIO_PCI_HOST_FEATURES : - val = vdev->ops->get_host_features (kvm, vpci->dev); + val =virtio_dev_get_host_features (vdev, kvm, vpci->dev);ioport__write32 (data, val);break ;case VIRTIO_PCI_QUEUE_PFN :
virtio/pci-modern.c +1 -1
@@ -158,7 +158,7 @@ static bool virtio_pci__common_read(struct virtio_device *vdev,case VIRTIO_PCI_COMMON_DF :if (vpci->device_features_sel >1 )break ; - features |= vdev->ops->get_host_features (vpci->kvm, vpci->dev); + features |=virtio_dev_get_host_features (vdev, vpci->kvm, vpci->dev); val = features >> (32 * vpci->device_features_sel);ioport__write32 (data, val);break ;
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 27/31 virtio: Add arch specific hook for virtio host flags
In reply to Suzuki K PouloseAdd callbacks for archs to provide virtio host flags.
--- arm/aarch32/kvm.c | 5 +++++ arm/aarch64/kvm.c | 5 +++++ include/kvm/kvm.h | 2 ++ mips/kvm.c | 5 +++++ powerpc/kvm.c | 5 +++++ riscv/kvm.c | 5 +++++ virtio/core.c | 5 ++++- x86/kvm.c | 5 +++++ 8 files changed, 36 insertions(+), 1 deletion(-)
arm/aarch32/kvm.c +5 -0
@@ -12,3 +12,8 @@ u64 kvm__arch_default_ram_address(void) {return ARM_MEMORY_AREA ; } + +u64 kvm__arch_get_virtio_host_features (struct kvm *kvm) +{ +return 0 ; +}
arm/aarch64/kvm.c +5 -0
@@ -234,3 +234,8 @@ void kvm__arch_enable_mte(struct kvm *kvm)pr_debug ("MTE capability enabled" ); } + +u64 kvm__arch_get_virtio_host_features (struct kvm *kvm) +{ +return 0 ; +}
include/kvm/kvm.h +2 -0
@@ -203,6 +203,8 @@ int kvm__arch_free_firmware(struct kvm *kvm);bool kvm__arch_cpu_supports_vm (void );void kvm__arch_read_term (struct kvm *kvm); +u64 kvm__arch_get_virtio_host_features (struct kvm *kvm); +#ifdef ARCH_HAS_CFG_RAM_ADDRESS static inline bool kvm__arch_has_cfg_ram_address (void ) {
mips/kvm.c +5 -0
@@ -374,3 +374,8 @@ void ioport__map_irq(u8 *irq)void serial8250__inject_sysrq (struct kvm *kvm,char sysrq) { } + +u64 kvm__arch_get_virtio_host_features (struct kvm *kvm) +{ +return 0 ; +}
powerpc/kvm.c +5 -0
@@ -529,3 +529,8 @@ int kvm__arch_free_firmware(struct kvm *kvm) {return 0 ; } + +u64 kvm__arch_get_virtio_host_features (struct kvm *kvm) +{ +return 0 ; +}
riscv/kvm.c +5 -0
@@ -182,3 +182,8 @@ int kvm__arch_setup_firmware(struct kvm *kvm) {return 0 ; } + +u64 kvm__arch_get_virtio_host_features (struct kvm *kvm) +{ +return 0 ; +}
virtio/core.c +4 -1
@@ -285,7 +285,10 @@ void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev,u64 virtio_dev_get_host_features (struct virtio_device *vdev,struct kvm *kvm,void *dev) { -return vdev->ops->get_host_features (kvm, dev); +u64 features =kvm__arch_get_virtio_host_features (kvm); + + features |= vdev->ops->get_host_features (kvm, dev); +return features; } bool virtio_access_config(struct kvm *kvm, struct virtio_device *vdev,
x86/kvm.c +5 -0
@@ -387,3 +387,8 @@ void kvm__arch_read_term(struct kvm *kvm)serial8250__update_consoles (kvm);virtio_console__inject_interrupt (kvm); } + +u64 kvm__arch_get_virtio_host_features (struct kvm *kvm) +{ +return 0 ; +}
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 28/31 arm64: realm: Enforce virtio F_ACCESS_PLATFORM flag
In reply to Suzuki K PouloseFor realms, force the F_ACCESS_PLATFORM flag to ensure DMA-APIs are triggered for virtio in Linux
--- arm/aarch64/kvm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arm/aarch64/kvm.c +7 -1
@@ -5,6 +5,7 @@#include <linux/byteorder.h> #include <linux/cpumask.h> #include <linux/sizes.h> +#include <linux/virtio_config.h> #include <kvm/util.h>
@@ -237,5 +238,10 @@ void kvm__arch_enable_mte(struct kvm *kvm)u64 kvm__arch_get_virtio_host_features (struct kvm *kvm) { -return 0 ; +u64 features =0 ; + +/* Enforce F_ACCESS_PLATFORM for Realms */ +if (kvm->cfg.arch.is_realm) + features |= (1ULL <<VIRTIO_F_ACCESS_PLATFORM ); +return features; }
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 29/31 mmio: add arch hook for an unhandled MMIO access
In reply to Suzuki K PouloseFrom: Joey Gouly <[email protected]>
Add a hook that allows an architecture to run some code on an unhandled MMIO access.
--- arm/kvm-cpu.c | 4 ++++ include/kvm/kvm-cpu.h | 2 ++ mips/kvm-cpu.c | 4 ++++ mmio.c | 3 +++ powerpc/kvm-cpu.c | 4 ++++ riscv/kvm-cpu.c | 4 ++++ x86/kvm-cpu.c | 4 ++++ 7 files changed, 25 insertions(+)
arm/kvm-cpu.c +4 -0
@@ -152,3 +152,7 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)void kvm_cpu__show_page_tables (struct kvm_cpu *vcpu) { } + +void kvm_cpu__arch_unhandled_mmio (struct kvm_cpu *vcpu) +{ +}
include/kvm/kvm-cpu.h +2 -0
@@ -29,4 +29,6 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu);void kvm_cpu__arch_nmi (struct kvm_cpu *cpu);void kvm_cpu__run_on_all_cpus (struct kvm *kvm,struct kvm_cpu_task *task); +void kvm_cpu__arch_unhandled_mmio (struct kvm_cpu *cpu); +#endif /* KVM__KVM_CPU_H */
mips/kvm-cpu.c +4 -0
@@ -217,3 +217,7 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu)void kvm_cpu__show_page_tables (struct kvm_cpu *vcpu) { } + +void kvm_cpu__arch_unhandled_mmio (struct kvm_cpu *cpu) +{ +}
mmio.c +3 -0
@@ -206,6 +206,9 @@ bool kvm__emulate_mmio(struct kvm_cpu *vcpu, u64 phys_addr, u8 *data,fprintf (stderr,"Warning: Ignoring MMIO %s at %016llx (length %u)\n" ,to_direction (is_write), (unsigned long long )phys_addr, len); + +kvm_cpu__arch_unhandled_mmio (vcpu); + goto out; }
powerpc/kvm-cpu.c +4 -0
@@ -288,3 +288,7 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) {/* Does nothing yet */ } + +void kvm_cpu__arch_unhandled_mmio (struct kvm_cpu *cpu) +{ +}
riscv/kvm-cpu.c +4 -0
@@ -461,3 +461,7 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu)kvm_cpu__show_csrs (vcpu); } + +void kvm_cpu__arch_unhandled_mmio (struct kvm_cpu *cpu) +{ +}
x86/kvm-cpu.c +4 -0
@@ -444,3 +444,7 @@ void kvm_cpu__arch_nmi(struct kvm_cpu *cpu)ioctl (cpu->vcpu_fd,KVM_NMI ); } + +void kvm_cpu__arch_unhandled_mmio (struct kvm_cpu *cpu) +{ +}
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 30/31 arm64: realm: inject an abort on an unhandled MMIO access
In reply to Suzuki K PouloseFrom: Joey Gouly <[email protected]>
For Realms, inject a synchronous external abort, instead of ignoring unknown MMIO accesses.
--- arm/kvm-cpu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arm/kvm-cpu.c +9 -0
@@ -155,4 +155,13 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu)void kvm_cpu__arch_unhandled_mmio (struct kvm_cpu *vcpu) { +struct kvm_vcpu_events events = { }; + +if (!vcpu->kvm->cfg.arch.is_realm) +return ; + + events.exception.ext_dabt_pending =1 ; + +if (ioctl (vcpu->vcpu_fd,KVM_SET_VCPU_EVENTS , &events) <0 ) +die_perror ("KVM_SET_VCPU_EVENTS failed" ); }
Signature · 1 line
2.34.1
Suzuki K Poulose
reviewerRFC 31/31 arm64: Allow the user to create a realm
In reply to Suzuki K PouloseFrom: Alexandru Elisei <[email protected]>
We have everything in place to create a realm, allow the user to do so.
--- arm/aarch64/kvm.c | 2 -- 1 file changed, 2 deletions(-)
arm/aarch64/kvm.c +0 -2
@@ -104,8 +104,6 @@ static void validate_realm_cfg(struct kvm *kvm)if (strlen (kvm->cfg.arch.realm_pv) >KVM_CAP_ARM_RME_RPV_SIZE )die ("Invalid size for Realm Personalization Value\n" ); } - -die ("Realms not supported" ); }void kvm__arch_validate_cfg (struct kvm *kvm)
Signature · 1 line
2.34.1
Re: [RFC kvmtool 00/31] arm64: Support for Arm Confidential Compute Architecture
In reply to Suzuki K PouloseHi Suzuki
Quoted 70 lines
This series is an initial version of the support for running VMs under the Arm Confidential Compute Architecture. The purpose of the series is to gather feedback on the proposed UABI changes for running Confidential VMs with KVM. More information on the Arm CCA and instructions for how to get, build and run the entire software stack is available here [0].
A new option,
--realmis added to the theruncommand to mark the VM as a confidential compute VM. This version doesn't use the Guest private memory [1] support yet, instead uses normal anonymous/hugetlbfs backed memory. Our aim is to switch to the guest private memory for the Realm.The host including the kernel and kvmtool, must not access any memory allocated to the protected IPA of the Realm.
The series adds the support for managing the lifecycle of the Realm, which includes:
* Configuration
* Creation of Realm (RD)
* Load initial memory images
* Creation of Realm Execution Contexts (RECs aka VCPUs)a
* Activation of the Realm.Patches are split as follows :
Patches 1 and 2 are fixes to existing code.
Patch 3 adds a new option --nocompat to disable compat warnings Patches 4 - 6 are some preparations for Realm specific changes.The remaining patches adds Realm support and using the --realm option is enabled in patch 30.
The v1.0 of the Realm Management Monitor (RMM) specification doesn't support paging protected memory of a Realm. Thus all of the memory backing the RAM is locked by the VMM.
Since the IPA space of a Realm is split into Protected and Unprotected, with one alias of the other, the VMM doubles the IPA Size for a Realm VM.
The KVM support for Arm CCA is advertised with a new cap
KVM_CAP_ARM_RME. A new "VM type" field is defined in thevm_typeforCREATE_VMioctl to indicate that a VM is "Realm". Once the VM is created, the life cycle of the Realm is managed viaKVM_ENABLE_CAPofKVM_CAP_ARM_RME.Command line options are also added to configure the Realm parameters. These include :
- Hash algorithm for measurements
- Realm personalisation value
- SVE vector Length (Optional feature in v1.0 RMM spec. Not yet supported by the TF-RMM. coming soon).Support for PMU and self-hosted debug (number of watchpoint/breakpoit registers) are not supported yet in the KVM/RMM implementation. This will be added soon.
The UABI doesn't support discovering the "supported" configuration values. In real world, the Realm configuration 'affects' the initial measurement of the Realms and which may be verified by a remote entity. Thus, the VMM is not at liberty to make choices for configurations based on the "host" capabilities. Instead, VMM should launch a Realm with the user requested parameters. If this cannot be satisfied, there is no point in running the Realm. We are happy to change this if there is interest.
Special actions are required to load the initial memory images (e.g, kernel, firmware, DTB, initrd) in to the Realm memory.
For VCPUs, we add a new feature
KVM_ARM_VCPU_REC, which will be used to control the creation of the REC object (viaKVM_ARM_VCPU_FINALIZE). This must be done after the initial register state of the VCPUs are set.
RMM imposes an order in which the RECs are created. i.e., they must be created in the ascending order of the MPIDR. This is for now a responsibility of the VMM.
Quoted 7 lines
Once the Realm images are loaded, VCPUs created, Realm is activated before the first vCPU is run.
virtio for the Realms enforces
VIRTIO_F_ACCESS_PLATFORMflag.Also, added support for injecting SEA into the VM for unhandled MMIO.
I wonder if there is a plan to develop a dedicated (stand-alone) tool that allows a realm developer to calculate Realm Initial Measurements for realms. I mean a tool that can be compiled and run on a Linux PC machine.
As you know, the remote attestation mechanism requires a verifier to be provisioned with reference values. In this case, a realm verifier should have access to the initial reference measurement (RIM) of a realm that is intended to be run on a remote Arm CCA platform.
The algorithm that measures the initial state of realms (RIM) is highly sensitive to the content of a realm memory and the order of RMI operations. This means that not only the content of populated realm memory matters but also the implementation of the host components (e.g. kvm, kvmtool/qemu).In the of kvmtool-cca, the layout of memory and the content of DTB highly depend on the provided options (DTB is generated in run-time). Unfortunately, the content of DTB also depends on the linking order of object files (the order of DTB generation is imposed by __attribute__((constructor)) that is used to register devices). This complicates development of a separate tool for calculating RIM, as the tool would have to emulate all quirks of the kvmtool.
One of the solution of retrieving Realm Initial Measurements seems to be running the whole firmware/software (e.g. kvmtool/Linux host/TF-RMM) stack on the FVP emulator and gathering the RIM directly from the TF-RMM. This would require a realm developer to have access to the whole firmware/software stack and the emulator of the CCA platform.
The other solution would require the implementation of a dedicated tool. For instance, a sensible approach could be to extend the functionality of kvmtool.
Is Arm going to develop a dedicated, stand-alone tool for calculating RIMs?
What is the recommended way of retrieving/calculating RIMs for realms?
Kind regards,
Piotr Sawicki
Joey Gouly
reviewercover Support for Arm Confidential Compute Architecture
In reply to Suzuki K PouloseThis series adds support for running the kvm-unit-tests in the Arm CCA reference software architecture. See more details on Arm CCA and how to build/run the entire stack here [0].
This involves enlightening the boot/setup code with the Realm Service Interface (RSI). The series also includes new test cases that exercise the RSI calls.
Currently we only support "kvmtool" as the VMM for running Realms. There was an attempt to add support for running the test scripts using with kvmtool here [1], which hasn't progressed. It would be good to have that resolved, so that we can run all the tests without manually specifying the commandlines for each run. For the purposes of running the Realm specific tests, we have added a "temporary" script "run-realm-tests" until the kvmtool support is added. We do not expect this to be merged.
Base Realm Support
-------------------
Realm IPA Space
---------------
When running on in Realm world, the (Guest) Physical Address - aka Intermediate Physical Address (IPA) in Arm terminology - space of the VM is split into two halves, protected (lower half) and un-protected (upper half). A protected IPA will always map pages in the "realm world" and the contents are not accessible to the host. An unprotected IPA on the other hand can be mapped to page in the "normal world" and thus shared with the host. All host emulated MMIO ranges must be in unprotected IPA space.
Realm can query the Realm Management Monitor for the configuration via RSI call (RSI_REALM_CONFIG) and identify the "boundary" of the "IPA" split.
As far as the hyp/VMM is concerned, there is only one "IPA space" (the lower half) of memory map. The "upper half" is "unprotected alias" of the memory map.
In the guest, this is achieved by "treating the MSB (1 << (IPA_WIDTH - 1))" as a protection attribute (PTE_NS_SHARED), where the Realm applies this to any address, it thinks is acccessed/managed by host (e.g., MMIO, shared pages). Given that this is runtime variable (but fixed for a given Realm), uses a variable to track the value.
All I/O regions are marked as "shared". Care is taken to ensure I/O access (uart) with MMU off uses the "Unprotected Physical address".
Realm IPA State
---------------
Additionally, each page (4K) in the protected IPA space has a state associated (Realm IPA State - RIPAS) with it. It is either of :
RIPAS_EMPTY
RIPAS_RAM
Any IPA backed by RAM, must be marked as RIPAS_RAM before an access is made to it. The hypervisor/VMM does this for the initial image loaded into the Realm memory before the Realm starts execution. Given the kvm-unit-test flat files do not contain a metadata header (e.g., like the arm64 Linux kernel Image), indicating the "actual image size in memory", the VMM cannot transition the area towards the end of the image (e.g., bss, stack) which are accessed very early during boot. Thus the early boot assembly code will mark the area upto the stack as RAM.
Once we land in the C code, we mark target relocation area for FDT and initrd as RIPAS_RAM. At this point, we can scan the FDT and mark all RAM memory blocks as RIPAS_RAM.
TODO: It would be good to add an image header to the flat files indicating the size, which can take the burden off doing the early assembly boot code RSI calls.
Shared Memory support
---------------------
Given the "default" memory of a VM is not accessible to host, we add new page alloc/free routines for "memory shared" with the host. e.g., GICv3-ITS must use shared pages for ITS emulation.
RSI Test suites
--------------
There are new testcases added to exercise the RSI interfaces and the RMM flows.
Attestation and measurement services related RSI tests require parsing tokens and claims returned by the RMM. This is achieved with the help of QCBOR library [2], which is added as a submodule to the project. We have also added a wrapper library - libtokenverifier - around the QCBOR to parse the tokens according to the RMM specifications.
The patches are also available here:
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1
[0] https://lore.kernel.org/all/[email protected]/
[1] https://lkml.kernel.org/r/[email protected]
[2] https://github.com/laurencelundblade/QCBOR
Thanks,
Joey
Alexandru Elisei (3):
arm: Expand SMCCC arguments and return values
arm: selftest: realm: skip pabt test when running in a realm
NOT-FOR-MERGING: add run-realm-tests
Djordje Kovacevic (1):
arm: realm: Add tests for in realm SEA
Gareth Stockwell (1):
arm: realm: add hvc and RSI_HOST_CALL tests
Jean-Philippe Brucker (1):
arm: Move io_init after vm initialization
Joey Gouly (9):
lib/string: include stddef.h for size_t
arm: realm: Add RSI interface header
arm: Make physical address mask dynamic
arm: Introduce NS_SHARED PTE attribute
arm: realm: Make uart available before MMU is enabled
arm: realm: Realm initialisation
arm: realm: Add support for changing the state of memory
arm: realm: Add RSI version test lib/alloc_page: Add shared page allocation support
Mate Toth-Pal (2):
arm: Add a library to verify tokens using the QCBOR library
arm: realm: Add Realm attestation tests
Subhasish Ghosh (1):
arm: realm: Add test for FPU/SIMD context save/restore
Suzuki K Poulose (9):
arm: realm: Set RIPAS state for RAM
arm: realm: Early memory setup
arm: gic-v3-its: Use shared pages wherever needed
arm: realm: Enable memory encryption
qcbor: Add QCBOR as a submodule
arm: Add build steps for QCBOR library
arm: realm: add RSI interface for attestation measurements
arm: realm: Add helpers to decode RSI return codes
arm: realm: Add a test for shared memory
.gitmodules | 3 + arm/Makefile.arm64 | 17 +- arm/Makefile.common | 1 + arm/cstart.S | 49 +- arm/cstart64.S | 123 ++- arm/realm-attest.c | 1125 +++++++++++++++++++++++++++ arm/realm-fpu.c | 242 ++++++ arm/realm-ns-memory.c | 86 ++ arm/realm-rsi.c | 157 ++++ arm/realm-sea.c | 143 ++++ arm/run-realm-tests | 56 ++ arm/selftest.c | 9 +- arm/unittests.cfg | 94 +++ lib/alloc_page.c | 34 +- lib/alloc_page.h | 24 + lib/arm/asm/arm-smccc.h | 44 ++ lib/arm/asm/psci.h | 13 +- lib/arm/asm/rsi.h | 16 + lib/arm/gic-v3.c | 6 +- lib/arm/io.c | 24 +- lib/arm/mmu.c | 73 +- lib/arm/psci.c | 19 +- lib/arm/setup.c | 17 +- lib/arm64/asm/arm-smccc.h | 6 + lib/arm64/asm/io.h | 6 + lib/arm64/asm/pgtable-hwdef.h | 6 - lib/arm64/asm/pgtable.h | 20 + lib/arm64/asm/processor.h | 8 + lib/arm64/asm/rsi.h | 84 ++ lib/arm64/asm/smc-rsi.h | 139 ++++ lib/arm64/gic-v3-its.c | 6 +- lib/arm64/rsi.c | 143 ++++ lib/libcflat.h | 1 + lib/qcbor | 1 + lib/string.h | 2 + lib/token_verifier/attest_defines.h | 50 ++ lib/token_verifier/token_dumper.c | 158 ++++ lib/token_verifier/token_dumper.h | 15 + lib/token_verifier/token_verifier.c | 591 ++++++++++++++ lib/token_verifier/token_verifier.h | 77 ++ 40 files changed, 3640 insertions(+), 48 deletions(-) create mode 100644 .gitmodules create mode 100644 arm/realm-attest.c create mode 100644 arm/realm-fpu.c create mode 100644 arm/realm-ns-memory.c create mode 100644 arm/realm-rsi.c create mode 100644 arm/realm-sea.c create mode 100755 arm/run-realm-tests create mode 100644 lib/arm/asm/arm-smccc.h create mode 100644 lib/arm/asm/rsi.h create mode 100644 lib/arm64/asm/arm-smccc.h create mode 100644 lib/arm64/asm/rsi.h create mode 100644 lib/arm64/asm/smc-rsi.h create mode 100644 lib/arm64/rsi.c create mode 160000 lib/qcbor create mode 100644 lib/token_verifier/attest_defines.h create mode 100644 lib/token_verifier/token_dumper.c create mode 100644 lib/token_verifier/token_dumper.h create mode 100644 lib/token_verifier/token_verifier.c create mode 100644 lib/token_verifier/token_verifier.h
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 1/27 lib/string: include stddef.h for size_t
Don't implicitly rely on this header being included.
--- lib/string.h | 2 ++ 1 file changed, 2 insertions(+)
lib/string.h +2 -0
@@ -7,6 +7,8 @@#ifndef _STRING_H_#define _STRING_H_ +#include <stddef.h> /* For size_t */ +extern size_t strlen (const char *buf);extern size_t strnlen (const char *buf,size_t maxlen);extern char *strcat (char *dest,const char *src);
Signature · 1 line
2.17.1
Re: [RFC kvm-unit-tests 01/27] lib/string: include stddef.h for size_t
Quoted 12 lines · Joey Gouly
Don't implicitly rely on this header being included.
Signed-off-by Joey Gouly <[email protected]>--- lib/string.h | 2 ++ 1 file changed, 2 insertions(+)lib/string.h +0
-0
lib/string.h line 14
Quoted 8 lines
lib/string.h +2
-0@@ -7,6 +7,8 @@#ifndef _STRING_H_#define _STRING_H_ +#include <stddef.h> /* For size_t */ +extern size_t strlen (const char *buf);extern size_t strnlen (const char *buf,size_t maxlen);extern char *strcat (char *dest,const char *src);
Joey Gouly
reviewerRFC 2/27 arm: Expand SMCCC arguments and return values
In reply to Joey GoulyFrom: Alexandru Elisei <[email protected]>
PSCI uses the SMC Calling Convention (SMCCC) to communicate with the higher level software. PSCI uses at most 4 arguments and expend only one return value. However, SMCCC has provisions for more arguments (upto 17 depending on the SMCCC version) and upto 10 distinct return values.
We are going to be adding tests that make use of it, so add support for the extended number of arguments and return values.
Also rename the SMCCC functions to generic, non-PSCI names, so they can be used for Realm services.
--- arm/cstart.S | 49 ++++++++++++++++++++++++++++------ arm/cstart64.S | 55 +++++++++++++++++++++++++++++++++------ arm/selftest.c | 2 +- lib/arm/asm/arm-smccc.h | 44 +++++++++++++++++++++++++++++++ lib/arm/asm/psci.h | 13 +++++---- lib/arm/psci.c | 19 +++++++++++--- lib/arm64/asm/arm-smccc.h | 6 +++++ 7 files changed, 160 insertions(+), 28 deletions(-) create mode 100644 lib/arm/asm/arm-smccc.h create mode 100644 lib/arm64/asm/arm-smccc.h
arm/cstart.S +41 -8
@@ -96,26 +96,59 @@ start: .text /* - * psci_invoke_hvc / psci_invoke_smc + * arm_smccc_hvc / arm_smccc_smc * * Inputs: * r0 -- function_id * r1 -- arg0 * r2 -- arg1 * r3 -- arg2 + * [sp] - arg3 + * [sp + #4] - arg4 + * [sp + #8] - arg5 + * [sp + #12] - arg6 + * [sp + #16] - arg7 + * [sp + #20] - arg8 + * [sp + #24] - arg9 + * [sp + #28] - arg10 + * [sp + #32] - result (as a pointer to a struct smccc_result) * * Outputs: * r0 -- return code + * + * If result pointer is not NULL: + * result.r0 -- return code + * result.r1 -- r1 + * result.r2 -- r2 + * result.r3 -- r3 + * result.r4 -- r4 + * result.r5 -- r5 + * result.r6 -- r6 + * result.r7 -- r7 + * result.r8 -- r8 + * result.r9 -- r9 */ -.globl psci_invoke_hvc -psci_invoke_hvc: - hvc #0 +.macro do_smccc_call instr + mov r12, sp + push {r4-r11} + ldm r12, {r4-r11} + \instr #0 + ldr r10, [sp, #64] + cmp r10, #0 + beq 1f + stm r10, {r0-r9} +1: + pop {r4-r11} mov pc, lr +.endm -.globl psci_invoke_smc -psci_invoke_smc: - smc #0 - mov pc, lr +.globl arm_smccc_hvc +arm_smccc_hvc: + do_smccc_call hvc + +.globl arm_smccc_smc +arm_smccc_smc: + do_smccc_call smc enable_vfp: /* Enable full access to CP10 and CP11: */
arm/cstart64.S +47 -8
73 lines not on this page · raw message
arm/selftest.c +1 -1
@@ -405,7 +405,7 @@ static void psci_print(void)int ver =psci_invoke (PSCI_0_2_FN_PSCI_VERSION ,0 ,0 ,0 );report_info ("PSCI version: %d.%d" ,PSCI_VERSION_MAJOR (ver),PSCI_VERSION_MINOR (ver)); -report_info ("PSCI method: %s" , psci_invoke == psci_invoke_hvc ? +report_info ("PSCI method: %s" , psci_invoke_fn == arm_smccc_hvc ?"hvc" :"smc" ); }
lib/arm/asm/arm-smccc.h new file +44 -0
44 lines not on this page · raw message
lib/arm/asm/psci.h +6 -7
@@ -3,13 +3,12 @@#include <libcflat.h> #include <linux/psci.h> -typedef int (*psci_invoke_fn )(unsigned int function_id,unsigned long arg0, -unsigned long arg1,unsigned long arg2); -extern psci_invoke_fn psci_invoke; -extern int psci_invoke_hvc (unsigned int function_id,unsigned long arg0, -unsigned long arg1,unsigned long arg2); -extern int psci_invoke_smc (unsigned int function_id,unsigned long arg0, -unsigned long arg1,unsigned long arg2); +#include <asm/arm-smccc.h> + +extern smccc_invoke_fn psci_invoke_fn; + +extern int psci_invoke (unsigned int function_id,unsigned long arg0, +unsigned long arg1,unsigned long arg2);extern void psci_set_conduit (void );extern int psci_cpu_on (unsigned long cpuid,unsigned long entry_point);extern void psci_system_reset (void );
lib/arm/psci.c +15 -4
@@ -13,13 +13,24 @@#include <asm/smp.h> static int psci_invoke_none (unsigned int function_id,unsigned long arg0, -unsigned long arg1,unsigned long arg2) +unsigned long arg1,unsigned long arg2, +unsigned long arg3,unsigned long arg4, +unsigned long arg5,unsigned long arg6, +unsigned long arg7,unsigned long arg8, +unsigned long arg9,unsigned long arg10, +struct smccc_result *result) {printf ("No PSCI method configured! Can't invoke...\n" );return PSCI_RET_NOT_PRESENT ; } -psci_invoke_fn psci_invoke = psci_invoke_none; +smccc_invoke_fn psci_invoke_fn = psci_invoke_none; + +int psci_invoke (unsigned int function_id,unsigned long arg0, +unsigned long arg1,unsigned long arg2) +{ +return psci_invoke_fn (function_id, arg0, arg1, arg2,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,NULL ); +}int psci_cpu_on (unsigned long cpuid,unsigned long entry_point) {
@@ -69,9 +80,9 @@ void psci_set_conduit(void)assert (method !=NULL && len ==4 );if (strcmp (method->data,"hvc" ) ==0 ) - psci_invoke = psci_invoke_hvc; + psci_invoke_fn = arm_smccc_hvc;else if (strcmp (method->data,"smc" ) ==0 ) - psci_invoke = psci_invoke_smc; + psci_invoke_fn = arm_smccc_smc;else assert_msg (false,"Unknown PSCI conduit: %s" , method->data); }
lib/arm64/asm/arm-smccc.h new file +6 -0
@@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 Arm Limited. +* All rights reserved. +*/ +#include "../../arm/asm/arm-smccc.h"
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 3/27 arm: realm: Add RSI interface header
In reply to Joey GoulyAdd the defintions for the Realm Service Interface (RSI). RSI calls are a way for the Realm to communicate with the RMM and request information/services.
--- lib/arm64/asm/smc-rsi.h | 139 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 lib/arm64/asm/smc-rsi.h
lib/arm64/asm/smc-rsi.h new file +139 -0
@@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 Arm Limited. +* All rights reserved. +*/ +#ifndef __SMC_RSI_H_ +#define __SMC_RSI_H_ + +/* +* This file describes the Realm Services Interface (RSI) Application Binary +* Interface (ABI) for SMC calls made from within the Realm to the RMM and +* serviced by the RMM. +*/ + +#define SMC_RSI_CALL_BASE 0xC4000000 + +/* +* The major version number of the RSI implementation. Increase this whenever +* the binary format or semantics of the SMC calls change. +*/ +#define RSI_ABI_VERSION_MAJOR 12 + +/* +* The minor version number of the RSI implementation. Increase this when +* a bug is fixed, or a feature is added without breaking binary compatibility. +*/ +#define RSI_ABI_VERSION_MINOR 0 + +#define RSI_ABI_VERSION ((RSI_ABI_VERSION_MAJOR << 16) | \ + RSI_ABI_VERSION_MINOR) + +#define RSI_ABI_VERSION_GET_MAJOR (_version) ((_version) >> 16) +#define RSI_ABI_VERSION_GET_MINOR (_version) ((_version) & 0xFFFF) + +#define RSI_SUCCESS 0 +#define RSI_ERROR_INPUT 1 +#define RSI_ERROR_STATE 2 +#define RSI_INCOMPLETE 3 +#define RSI_ERROR_MEMORY 4 + +#define SMC_RSI_FID (_x) (SMC_RSI_CALL_BASE + (_x)) + +#define SMC_RSI_ABI_VERSION SMC_RSI_FID(0x190) + +/* +* arg1 == The IPA of token buffer +* arg2 == Challenge value, bytes: 0 - 7 +* arg3 == Challenge value, bytes: 7 - 15 +* arg4 == Challenge value, bytes: 16 - 23 +* arg5 == Challenge value, bytes: 24 - 31 +* arg6 == Challenge value, bytes: 32 - 39 +* arg7 == Challenge value, bytes: 40 - 47 +* arg8 == Challenge value, bytes: 48 - 55 +* arg9 == Challenge value, bytes: 56 - 63 +* ret0 == Status / error +*/ +#define SMC_RSI_ATTEST_TOKEN_INIT SMC_RSI_FID(0x194) + +/* +* arg1 == The IPA of token buffer +* ret0 == Status / error +* ret1 == Size of completed token in bytes +*/ +#define SMC_RSI_ATTEST_TOKEN_CONTINUE SMC_RSI_FID(0x195) + +/* +* arg1 == Index (1..4), which measurement (REM) to extend +* arg2 == Size of realm measurement in bytes, max 64 bytes +* arg3 == Measurement value, bytes: 0 - 7 +* arg4 == Measurement value, bytes: 7 - 15 +* arg5 == Measurement value, bytes: 16 - 23 +* arg6 == Measurement value, bytes: 24 - 31 +* arg7 == Measurement value, bytes: 32 - 39 +* arg8 == Measurement value, bytes: 40 - 47 +* arg9 == Measurement value, bytes: 48 - 55 +* arg10 == Measurement value, bytes: 56 - 63 +* ret0 == Status / error +*/ +#define SMC_RSI_MEASUREMENT_EXTEND SMC_RSI_FID(0x193) + +/* +* arg1 == Index (0..4), which measurement (RIM or REM) to read +* ret0 == Status / error +* ret1 == Measurement value, bytes: 0 - 7 +* ret2 == Measurement value, bytes: 7 - 15 +* ret3 == Measurement value, bytes: 16 - 23 +* ret4 == Measurement value, bytes: 24 - 31 +* ret5 == Measurement value, bytes: 32 - 39 +* ret6 == Measurement value, bytes: 40 - 47 +* ret7 == Measurement value, bytes: 48 - 55 +* ret8 == Measurement value, bytes: 56 - 63 +*/ +#define SMC_RSI_MEASUREMENT_READ SMC_RSI_FID(0x192) + +#ifndef __ASSEMBLY__ + +struct rsi_realm_config { +union { +struct { +unsigned long ipa_width;/* Width of IPA in bits */ + }; +unsigned char __reserved0[0x1000 ]; + }; +/* Offset 0x1000 */ +}; + +#endif /* __ASSEMBLY__ */ + +/* +* arg0 == struct rsi_realm_config addr +*/ +#define SMC_RSI_REALM_CONFIG SMC_RSI_FID(0x196) + +/* +* arg0 == IPA address of target region +* arg1 == size of target region in bytes +* arg2 == RIPAS value +* ret0 == Status / error +* ret1 == Top of modified IPA range +*/ +#define SMC_RSI_IPA_STATE_SET SMC_RSI_FID(0x197) + +#define RSI_HOST_CALL_NR_GPRS 31 + +#ifndef __ASSEMBLY__ + +struct rsi_host_call { +unsigned int imm; +unsigned long gprs[RSI_HOST_CALL_NR_GPRS ]; +}; + +#endif /* __ASSEMBLY__ */ + +/* +* arg0 == struct rsi_host_call addr +*/ +#define SMC_RSI_HOST_CALL SMC_RSI_FID(0x199) + +#endif /* __SMC_RSI_H_ */
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 4/27 arm: Make physical address mask dynamic
In reply to Joey GoulyWe are about to add Realm support where the physical address width may be known via RSI. Make the Physical Address mask dynamic, so that it can be adjusted to the limit for the realm. This will be required for making pages shared, as we introduce the "sharing" attribute as the top bit of the IPA.
--- lib/arm/mmu.c | 2 ++ lib/arm/setup.c | 1 + lib/arm64/asm/pgtable-hwdef.h | 6 ------ lib/arm64/asm/pgtable.h | 9 +++++++++ 4 files changed, 12 insertions(+), 6 deletions(-)
lib/arm/mmu.c +2 -0
@@ -22,6 +22,8 @@pgd_t *mmu_idmap; +unsigned long phys_mask_shift =48 ; +/* CPU 0 starts with disabled MMU */ static cpumask_t mmu_enabled_cpumask;
lib/arm/setup.c +1 -0
@@ -22,6 +22,7 @@#include <asm/thread_info.h> #include <asm/setup.h> #include <asm/page.h> +#include <asm/pgtable.h> #include <asm/processor.h> #include <asm/smp.h> #include <asm/timer.h>
lib/arm64/asm/pgtable-hwdef.h +0 -6
@@ -115,12 +115,6 @@#define PTE_ATTRINDX (t) (_AT(pteval_t, (t)) << 2)#define PTE_ATTRINDX_MASK (_AT(pteval_t, 7) << 2) -/* -* Highest possible physical address supported. -*/ -#define PHYS_MASK_SHIFT (48) -#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) -/* * TCR flags. */
lib/arm64/asm/pgtable.h +9 -0
@@ -21,6 +21,15 @@#include <linux/compiler.h> +extern unsigned long prot_ns_shared; +/* +* Highest possible physical address supported. +*/ +extern unsigned long phys_mask_shift; +#define PHYS_MASK_SHIFT (phys_mask_shift) +#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) + +/* * We can convert va <=> pa page table addresses with simple casts * because we always allocate their pages with alloc_page(), and
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 5/27 arm: Introduce NS_SHARED PTE attribute
In reply to Joey GoulyIntroduce a new attribute to indicate the mapping is "Shared" with the host. This will be used by the Realms to share pages with the Host. For normal VMs, this is always 0.
For realms, this is dynamic, depending on the IPA width. The top bit of the IPA is "treated" as the "NS_SHARED" attribute, making the VM access the unprotected alias of the IPA.
By default, apply the NS_SHARED attribute for all I/O.
--- lib/arm/mmu.c | 5 ++++- lib/arm64/asm/pgtable.h | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
lib/arm/mmu.c +4 -1
@@ -22,6 +22,8 @@pgd_t *mmu_idmap; +/* Used by Realms, depends on IPA size */ +unsigned long prot_ns_shared =0 ;unsigned long phys_mask_shift =48 ;/* CPU 0 starts with disabled MMU */
@@ -194,7 +196,8 @@ void __iomem *__ioremap(phys_addr_t phys_addr, size_t size) {phys_addr_t paddr_aligned = phys_addr &PAGE_MASK ;phys_addr_t paddr_end =PAGE_ALIGN (phys_addr + size); -pgprot_t prot =__pgprot (PTE_UNCACHED |PTE_USER |PTE_UXN |PTE_PXN ); +pgprot_t prot =__pgprot (PTE_UNCACHED |PTE_USER |PTE_UXN | +PTE_PXN |PTE_NS_SHARED );pgd_t *pgtable;assert (sizeof (long ) ==8 || !(phys_addr >>32 ));
lib/arm64/asm/pgtable.h +6 -0
@@ -22,6 +22,12 @@#include <linux/compiler.h> extern unsigned long prot_ns_shared; +/* +* The Non-secure shared bit for Realms is actually part of the output +* address, however it is modeled as a PTE attribute. +*/ +#define PTE_NS_SHARED (prot_ns_shared) +/* * Highest possible physical address supported. */
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 6/27 arm: Move io_init after vm initialization
In reply to Joey GoulyFrom: Jean-Philippe Brucker <[email protected]>
To create shared pages, the NS_SHARED bit must be written into the idmap. Before VM initializations, idmap hasn't necessarily been created. To write shared pages, access must be done on a IPA with the NS_SHARED bit. When the stage-1 MMU is enabled, that bit is set in the PTE. But when the stage-1 MMU is disabled, then the realm must write to the IPA with NS_SHARED directly.
To avoid changing the whole virtio infrastructure to support pre-MMU in a realm, move the IO initialization after MMU enablement.
--- lib/arm/setup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/arm/setup.c +3 -3
@@ -274,9 +274,6 @@ void setup(const void *fdt, phys_addr_t freemem_start)/* cpu_init must be called before thread_info_init */ thread_info_init (current_thread_info (),0 ); -/* mem_init must be called before io_init */ -io_init (); -timer_save_state (); ret =dt_get_bootargs (&bootargs);
@@ -292,4 +289,7 @@ void setup(const void *fdt, phys_addr_t freemem_start)if (!(auxinfo.flags &AUXINFO_MMU_OFF ))setup_vm (); + +/* mem_init and setup_vm must be called before io_init */ +io_init (); }
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 7/27 arm: realm: Make uart available before MMU is enabled
In reply to Joey GoulyA Realm must access any emulated I/O mappings with the PTE_NS_SHARED bit set. This is modelled as a PTE attribute, but is actually part of the address.
So, when MMU is disabled, the "physical address" must reflect this bit set. We access the UART early before the MMU is enabled. So, make sure the UART is accessed always with the bit set.
--- lib/arm/io.c | 24 +++++++++++++++++++++++- lib/arm64/asm/pgtable.h | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-)
lib/arm/io.c +23 -1
@@ -15,6 +15,8 @@#include <asm/psci.h> #include <asm/spinlock.h> #include <asm/io.h> +#include <asm/mmu-api.h> +#include <asm/pgtable.h> #include "io.h"
@@ -29,6 +31,24 @@ static struct spinlock uart_lock;#define UART_EARLY_BASE (u8 *)(unsigned long)CONFIG_UART_EARLY_BASEstatic volatile u8 *uart0_base =UART_EARLY_BASE ; +static inline volatile u8 *get_uart_base (void ) +{ +/* +* The address of the UART base may be different +* based on whether we are running with/without +* MMU enabled. +* +* For realms, we must force to use the shared physical +* alias with MMU disabled, to make sure the I/O can +* be emulated. +* When the MMU is turned ON, the mappings are created +* appropriately. +*/ +if (mmu_enabled ()) +return uart0_base; +return (u8 *)arm_shared_phys_alias ((void *)uart0_base); +} +static void uart0_init (void ) {/*
@@ -81,9 +101,11 @@ void io_init(void)void puts (const char *s) { +volatile u8 *uart_base =get_uart_base (); +spin_lock (&uart_lock);while (*s) -writeb (*s++, uart0_base); +writeb (*s++, uart_base);spin_unlock (&uart_lock); }
lib/arm64/asm/pgtable.h +5 -0
@@ -28,6 +28,11 @@ extern unsigned long prot_ns_shared;*/ #define PTE_NS_SHARED (prot_ns_shared) +static inline unsigned long arm_shared_phys_alias (void *addr) +{ +return ((unsigned long )addr |PTE_NS_SHARED ); +} +/* * Highest possible physical address supported. */
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 8/27 arm: realm: Realm initialisation
In reply to Joey GoulyDuring the boot, run a check for the presence of RMM. If we are Realm, detect the Realm configuration using RSI and initialise the key parameters.
Also expose a helper to indicate if this is running inside a Realm
--- arm/Makefile.arm64 | 1 + lib/arm/asm/rsi.h | 16 ++++++++++ lib/arm/setup.c | 3 ++ lib/arm64/asm/processor.h | 8 +++++ lib/arm64/asm/rsi.h | 36 +++++++++++++++++++++ lib/arm64/rsi.c | 67 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 131 insertions(+) create mode 100644 lib/arm/asm/rsi.h create mode 100644 lib/arm64/asm/rsi.h create mode 100644 lib/arm64/rsi.c
arm/Makefile.arm64 +1 -0
@@ -24,6 +24,7 @@ cstart.o = $(TEST_DIR)/cstart64.o cflatobjs += lib/arm64/processor.o cflatobjs += lib/arm64/spinlock.o cflatobjs += lib/arm64/gic-v3-its.o lib/arm64/gic-v3-its-cmd.o +cflatobjs += lib/arm64/rsi.o OBJDIRS += lib/arm64
lib/arm/asm/rsi.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 Arm Limited. +* All rights reserved. +*/ +#ifndef __ASMARM_RSI_H_ +#define __ASMARM_RSI_H_ + +#include <stdbool.h> + +static inline bool is_realm (void ) +{ +return false; +} + +#endif /* __ASMARM_RSI_H_ */
lib/arm/setup.c +3 -0
@@ -24,6 +24,7 @@#include <asm/page.h> #include <asm/pgtable.h> #include <asm/processor.h> +#include <asm/rsi.h> #include <asm/smp.h> #include <asm/timer.h> #include <asm/psci.h>
@@ -244,6 +245,8 @@ void setup(const void *fdt, phys_addr_t freemem_start)u32 fdt_size;int ret; +arm_rsi_init (); +assert (sizeof (long ) ==8 || freemem_start < (3ul <<30 )); freemem = (void *)(unsigned long )freemem_start;
lib/arm64/asm/processor.h +8 -0
@@ -114,6 +114,14 @@ static inline unsigned long get_id_aa64mmfr0_el1(void)#define ID_AA64MMFR0_TGRAN64_SUPPORTED 0x0#define ID_AA64MMFR0_TGRAN16_SUPPORTED 0x1 +static inline unsigned long get_id_aa64pfr0_el1 (void ) +{ +return read_sysreg (id_aa64pfr0_el1); +} + +#define ID_AA64PFR0_EL1_EL3 (0xf << 12) +#define ID_AA64PFR0_EL1_EL3_NI (0x0 << 12) +static inline bool system_supports_granule (size_t granule) {u32 shift;
lib/arm64/asm/rsi.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 Arm Limited. +* All rights reserved. +*/ +#ifndef __ASMARM64_RSI_H_ +#define __ASMARM64_RSI_H_ + +#include <stdbool.h> + +#include <asm/arm-smccc.h> +#include <asm/io.h> +#include <asm/smc-rsi.h> + +#define RSI_GRANULE_SIZE SZ_4K + +extern bool rsi_present; + +void arm_rsi_init (void ); + +int rsi_invoke (unsigned int function_id,unsigned long arg0, +unsigned long arg1,unsigned long arg2, +unsigned long arg3,unsigned long arg4, +unsigned long arg5,unsigned long arg6, +unsigned long arg7,unsigned long arg8, +unsigned long arg9,unsigned long arg10, +struct smccc_result *result); + +int rsi_get_version (void ); + +static inline bool is_realm (void ) +{ +return rsi_present; +} + +#endif /* __ASMARM64_RSI_H_ */
lib/arm64/rsi.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 9/27 arm: realm: Add support for changing the state of memory
In reply to Joey GoulyFor a Realm, the guest physical address (in reality the IPA/GPA of the VM) has an associated state (Realm IPA State, RIPAS) which is either of :
RIPAS_RAM
RIPAS_EMPTY
The state of the physical address decides certain behaviors. e.g., any access to a RIPAS_EMPTY PA will generate a Synchronous External Abort back to the Realm, from the RMM.
All "PA" that represents RAM for the Realm, must be set to RIPAS_RAM before an access is made. When the initial image (e.g., test, DTB) of a Realm is loaded, the hypervisor/VMM can transition the state of the loaded "area" to RIPAS_RAM. The rest of the "RAM" must be transitioned by the test payload before any access is made.
Similarly, a Realm could set an "IPA" to RIPAS_EMPTY, when it is about to use the "unprotected" alias of the IPA. This is a hint for the host to reclaim the page from the protected "IPA.
This patchs adds supporting helpers for setting the IPA state from Realm. These will be used later for the Realm.
--- lib/arm/mmu.c | 1 + lib/arm64/asm/rsi.h | 8 ++++++++ lib/arm64/rsi.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+)
lib/arm/mmu.c +1 -0
@@ -12,6 +12,7 @@#include <asm/setup.h> #include <asm/page.h> #include <asm/io.h> +#include <asm/rsi.h> #include "alloc_page.h" #include "vmalloc.h"
lib/arm64/asm/rsi.h +8 -0
@@ -33,4 +33,12 @@ static inline bool is_realm(void) return rsi_present; } +enum ripas_t { +RIPAS_EMPTY , +RIPAS_RAM , +}; + +void arm_set_memory_protected (unsigned long va,size_t size); +void arm_set_memory_shared (unsigned long va,size_t size); +#endif /* __ASMARM64_RSI_H_ */
lib/arm64/rsi.c +44 -0
47 lines not on this page · raw message
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 10/27 arm: realm: Set RIPAS state for RAM
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
A Realm must ensure that the "RAM" region is set to RIPAS_RAM, before any access is made. This patch makes sure that all memory blocks are marked as RIPAS_RAM. Also, before we relocate the "FDT" and "initrd", make sure the target location is marked too. This happens before we parse the memory blocks.
It is OK to do this operation on a given IPA multiple times. So, we don't exclude the inital image areas from the "target" list.
Also, this operation doesn't require the host to commit physical memory to back the IPAs yet. It can be done on demand via fault handling.
--- lib/arm/setup.c | 7 +++++++ 1 file changed, 7 insertions(+)
lib/arm/setup.c +7 -0
@@ -181,6 +181,7 @@ static void mem_init(phys_addr_t freemem_start)while (r && r->end != mem.end) r =mem_region_find (r->end);assert (r); +arm_set_memory_protected (r->start, r->end - r->start);/* Ensure our selected freemem range is somewhere in our full range */ assert (freemem_start >= mem.start && freemem->end <= mem.end);
@@ -252,6 +253,11 @@ void setup(const void *fdt, phys_addr_t freemem_start)/* Move the FDT to the base of free memory */ fdt_size =fdt_totalsize (fdt); +/* +* Before we touch the memory @freemem, make sure it +* is set to protected for Realms. +*/ +arm_set_memory_protected ((unsigned long )freemem, fdt_size); ret =fdt_move (fdt, freemem, fdt_size);assert (ret ==0 ); ret =dt_init (freemem);
@@ -263,6 +269,7 @@ void setup(const void *fdt, phys_addr_t freemem_start)assert (ret ==0 || ret == -FDT_ERR_NOTFOUND );if (ret ==0 ) { initrd = freemem; +arm_set_memory_protected ((unsigned long )initrd, initrd_size);memmove (initrd, tmp, initrd_size); freemem += initrd_size; }
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 11/27 arm: realm: Early memory setup
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
A Realm must mark areas of memory as RIPAS_RAM before an access is made.
The binary image is loaded by the VMM and thus the area is converted. However, the file image may not cover tail portion of the "memory" image (e.g, BSS, stack etc.). Convert the area touched by the early boot code to RAM before the access is made in early assembly code.
Once, we land in the C code, we take care of converting the entire RAM region to RIPAS_RAM.
Please note that this operation doesn't require the host to commit memory to the Realm.
--- arm/cstart64.S | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+)
arm/cstart64.S +72 -0
@@ -14,6 +14,7 @@ #include <asm/pgtable-hwdef.h> #include <asm/thread_info.h> #include <asm/sysreg.h> +#include <asm/smc-rsi.h> .macro zero_range, tmp1, tmp2 9998: cmp \tmp1, \tmp2
@@ -61,6 +62,7 @@ start: b 1b 1: + bl __early_mem_setup /* zero BSS */ adrp x4, bss add x4, x4, :lo12:bss
@@ -170,6 +172,76 @@ arm_smccc_hvc: arm_smccc_smc: do_smccc_call smc +__early_mem_setup: + /* Preserve x0 - x3 */ + mov x5, x0 + mov x6, x1 + mov x7, x2 + mov x8, x3 + + /* + * Check for EL3, otherwise an SMC instruction + * will cause an UNDEFINED exception. + */ + mrs x9, ID_AA64PFR0_EL1 + lsr x9, x9, #12 + and x9, x9, 0b11 + cbnz x9, 1f + ret + +1: + /* + * Are we a realm? Request the RSI ABI version. + * If KVM is catching SMCs, it returns an error in x0 (~0UL) + */ + ldr x0, =SMC_RSI_ABI_VERSION + smc #0 + + ldr x1, =RSI_ABI_VERSION + cmp x0, x1 + bne 3f + + /* + * For realms, we must mark area from bss + * to the end of stack as memory before it is + * accessed, as they are not populated as part + * of the initial image. As such we can run + * this unconditionally irrespective of whether + * we are a normal VM or Realm. + * + * x1 = bss_start. + */ + adrp x1, bss + + /* x9 = (end of stack - bss_start) */ + adrp x9, (stacktop + PAGE_SIZE) +2: + /* calculate the size as (end - start) */ + sub x2, x9, x1 + + /* x3 = RIPAS_RAM */ + mov x3, #1 + + /* x0 = SMC_RSI_IPA_STATE_SET */ + movz x0, :abs_g2_s:SMC_RSI_IPA_STATE_SET + movk x0, :abs_g1_nc:SMC_RSI_IPA_STATE_SET + movk x0, :abs_g0_nc:SMC_RSI_IPA_STATE_SET + + /* Run the RSI request */ + smc #0 + + /* halt if there is an error */ + cbnz x0, halt + + cmp x1, x9 + bne 2b +3: + mov x3, x8 + mov x2, x7 + mov x1, x6 + mov x0, x5 + ret + get_mmu_off: adrp x0, auxinfo ldr x0, [x0, :lo12:auxinfo + 8]
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 12/27 arm: realm: Add RSI version test
In reply to Joey GoulyAdd basic test for checking the RSI version command.
--- arm/Makefile.arm64 | 1 + arm/realm-rsi.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 7 +++++++ 3 files changed, 57 insertions(+) create mode 100644 arm/realm-rsi.c
arm/Makefile.arm64 +1 -0
@@ -33,6 +33,7 @@ tests = $(TEST_DIR)/timer.flat tests += $(TEST_DIR)/micro-bench.flat tests += $(TEST_DIR)/cache.flat tests += $(TEST_DIR)/debug.flat +tests += $(TEST_DIR)/realm-rsi.flat include $(SRCDIR)/$(TEST_DIR)/Makefile.common
arm/realm-rsi.c new file +49 -0
49 lines not on this page · raw message
arm/unittests.cfg +7 -0
@@ -275,3 +275,10 @@ file = debug.flat arch = arm64 extra_params = -append 'ss-migration' groups = debug migration + +# Realm RSI ABI test +[realm-rsi] +file = realm-rsi.flat +groups = nodefault realms +accel = kvm +arch = arm64
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 13/27 arm: selftest: realm: skip pabt test when running in a realm
In reply to Joey GoulyFrom: Alexandru Elisei <[email protected]>
The realm manager treats instruction aborts as fatal errors, skip this test.
--- arm/selftest.c | 7 +++++++ 1 file changed, 7 insertions(+)
arm/selftest.c +7 -0
@@ -18,6 +18,7 @@#include <asm/smp.h> #include <asm/mmu.h> #include <asm/barrier.h> +#include <asm/rsi.h> static cpumask_t ready, valid;
@@ -392,11 +393,17 @@ static void check_vectors(void *arg __unused) user_psci_system_off);#endif }else { +if (is_realm ()) { +report_skip ("pabt test not supported in a realm" ); + goto out; + } +if (!check_pabt_init ())report_skip ("Couldn't guess an invalid physical address" );else report (check_pabt (),"pabt" ); } +out:exit (report_summary ()); }
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 14/27 arm: realm: add hvc and RSI_HOST_CALL tests
In reply to Joey GoulyFrom: Gareth Stockwell <[email protected]>
Test that a HVC instruction in a Realm is turned into an undefined exception.
Test that RSI_HOST_CALL passes through to the Hypervisor.
--- arm/realm-rsi.c | 110 +++++++++++++++++++++++++++++++++++++++++++++- arm/unittests.cfg | 15 +++++++ 2 files changed, 124 insertions(+), 1 deletion(-)
arm/realm-rsi.c +109 -1
@@ -14,6 +14,96 @@#include <asm/pgtable.h> #include <asm/processor.h> +#define FID_SMCCC_VERSION 0x80000000 +#define FID_INVALID 0xc5000041 + +#define SMCCC_VERSION_1_1 0x10001 +#define SMCCC_SUCCESS 0 +#define SMCCC_NOT_SUPPORTED -1 + +static bool unknown_taken; + +static void unknown_handler (struct pt_regs *regs,unsigned int esr) +{ +report_info ("unknown_handler: esr=0x%x" , esr); + unknown_taken = true; +} + +static void hvc_call (unsigned int fid) +{ +struct smccc_result res; + + unknown_taken = false; +arm_smccc_hvc (fid,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , &res); + +if (unknown_taken) { +report (true,"FID=0x%x caused Unknown exception" , fid); + }else { +report (false,"FID=0x%x did not cause Unknown exception" , fid); +report_info ("x0: 0x%lx" , res.r0); +report_info ("x1: 0x%lx" , res.r1); +report_info ("x2: 0x%lx" , res.r2); +report_info ("x3: 0x%lx" , res.r3); +report_info ("x4: 0x%lx" , res.r4); +report_info ("x5: 0x%lx" , res.r5); +report_info ("x6: 0x%lx" , res.r6); +report_info ("x7: 0x%lx" , res.r7); + } +} + +static void rsi_test_hvc (void ) +{ +report_prefix_push ("hvc" ); + +/* Test that HVC causes Undefined exception, regardless of FID */ +install_exception_handler (EL1H_SYNC ,ESR_EL1_EC_UNKNOWN , unknown_handler); +hvc_call (FID_SMCCC_VERSION ); +hvc_call (FID_INVALID ); +install_exception_handler (EL1H_SYNC ,ESR_EL1_EC_UNKNOWN ,NULL ); + +report_prefix_pop (); +} + +static void host_call (unsigned int fid,unsigned long expected_x0) +{ +struct smccc_result res; +struct rsi_host_call __attribute__((aligned (256 ))) host_call_data = {0 }; + + host_call_data.gprs[0 ] = fid; + +arm_smccc_smc (SMC_RSI_HOST_CALL ,virt_to_phys (&host_call_data), +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , &res); + +if (res.r0) { +report (false,"RSI_HOST_CALL returned 0x%lx" , res.r0); + }else { +if (host_call_data.gprs[0 ] == expected_x0) { +report (true,"FID=0x%x x0=0x%lx" , + fid, host_call_data.gprs[0 ]); + }else { +report (false,"FID=0x%x x0=0x%lx expected=0x%lx" , + fid, host_call_data.gprs[0 ], expected_x0); +report_info ("x1: 0x%lx" , host_call_data.gprs[1 ]); +report_info ("x2: 0x%lx" , host_call_data.gprs[2 ]); +report_info ("x3: 0x%lx" , host_call_data.gprs[3 ]); +report_info ("x4: 0x%lx" , host_call_data.gprs[4 ]); +report_info ("x5: 0x%lx" , host_call_data.gprs[5 ]); +report_info ("x6: 0x%lx" , host_call_data.gprs[6 ]); + } + } +} + +static void rsi_test_host_call (void ) +{ +report_prefix_push ("host_call" ); + +/* Test that host calls return expected values */ +host_call (FID_SMCCC_VERSION ,SMCCC_VERSION_1_1 ); +host_call (FID_INVALID ,SMCCC_NOT_SUPPORTED ); + +report_prefix_pop (); +} +static void rsi_test_version (void ) {int version;
@@ -36,6 +126,8 @@ static void rsi_test_version(void)int main (int argc,char **argv) { +int i; +report_prefix_push ("rsi" );if (!is_realm ()) {
@@ -43,7 +135,23 @@ int main(int argc, char **argv) goto exit; } -rsi_test_version (); +if (argc <2 ) { +rsi_test_version (); +rsi_test_host_call (); +rsi_test_hvc (); + }else { +for (i =1 ; i < argc; i++) { +if (strcmp (argv[i],"version" ) ==0 ) { +rsi_test_version (); + }else if (strcmp (argv[i],"hvc" ) ==0 ) { +rsi_test_hvc (); + }else if (strcmp (argv[i],"host_call" ) ==0 ) { +rsi_test_host_call (); + }else { +report_abort ("Unknown subtest '%s'" , argv[1 ]); + } + } + } exit:return report_summary (); }
arm/unittests.cfg +15 -0
@@ -280,5 +280,20 @@ groups = debug migration [realm-rsi] file = realm-rsi.flat groups = nodefault realms +extra_params = -append 'version' +accel = kvm +arch = arm64 + +[realm-host-call] +file = realm-rsi.flat +groups = nodefault realms +extra_params = -append 'host_call' +accel = kvm +arch = arm64 + +[realm-hvc] +file = realm-rsi.flat +groups = nodefault realms +extra_params = -append 'hvc' accel = kvm arch = arm64
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 15/27 arm: realm: Add test for FPU/SIMD context save/restore
In reply to Joey GoulyFrom: Subhasish Ghosh <[email protected]>
Test that the FPU/SIMD registers are saved and restored correctly when context switching VCPUs.
In order to test fpu/simd functionality, we need to make sure that kvm-unit-tests doesn't generate code that uses the fpu registers, as that might interfere with the test results. Thus make sure we compile the tests with -mgeneral-regs-only.
--- arm/Makefile.arm64 | 1 + arm/Makefile.common | 1 + arm/realm-fpu.c | 242 ++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 8 ++ 4 files changed, 252 insertions(+) create mode 100644 arm/realm-fpu.c
arm/Makefile.arm64 +1 -0
@@ -34,6 +34,7 @@ tests += $(TEST_DIR)/micro-bench.flat tests += $(TEST_DIR)/cache.flat tests += $(TEST_DIR)/debug.flat tests += $(TEST_DIR)/realm-rsi.flat +tests += $(TEST_DIR)/realm-fpu.flat include $(SRCDIR)/$(TEST_DIR)/Makefile.common
arm/Makefile.common +1 -0
@@ -25,6 +25,7 @@ CFLAGS += -std=gnu99 CFLAGS += -ffreestanding CFLAGS += -O2 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib +CFLAGS += -mgeneral-regs-only # We want to keep intermediate files .PRECIOUS: %.elf %.o
arm/realm-fpu.c new file +242 -0
242 lines not on this page · raw message
arm/unittests.cfg +8 -0
@@ -297,3 +297,11 @@ groups = nodefault realms extra_params = -append 'hvc' accel = kvm arch = arm64 + +# Realm FPU/SIMD test +[realm-fpu-context] +file = realm-fpu.flat +smp = 2 +groups = nodefault realms +accel = kvm +arch = arm64
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 16/27 arm: realm: Add tests for in realm SEA
In reply to Joey GoulyFrom: Djordje Kovacevic <[email protected]>
The RMM/Host could inject Synchronous External Aborts in to the Realm for various reasons.
RMM injects the SEA for :
* Instruction/Data fetch from an IPA that is in RIPAS_EMPTY state
* Instruction fetch from an Unprotected IPA.
Trigger these conditions from within the Realm and verify that the SEAs are received.
--- arm/Makefile.arm64 | 1 + arm/realm-sea.c | 143 +++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++ 3 files changed, 150 insertions(+) create mode 100644 arm/realm-sea.c
arm/Makefile.arm64 +1 -0
@@ -35,6 +35,7 @@ tests += $(TEST_DIR)/cache.flat tests += $(TEST_DIR)/debug.flat tests += $(TEST_DIR)/realm-rsi.flat tests += $(TEST_DIR)/realm-fpu.flat +tests += $(TEST_DIR)/realm-sea.flat include $(SRCDIR)/$(TEST_DIR)/Makefile.common
arm/realm-sea.c new file +143 -0
143 lines not on this page · raw message
arm/unittests.cfg +6 -0
@@ -305,3 +305,9 @@ smp = 2 groups = nodefault realms accel = kvm arch = arm64 + +[realm-sea] +file = realm-sea.flat +groups = nodefault realms +accel = kvm +arch = arm64
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 17/27 lib/alloc_page: Add shared page allocation support
In reply to Joey GoulyAdd support for allocating "pages" that can be shared with the host. Or in other words, decrypted pages. This is achieved by adding hooks for setting a memory region as "encrypted" or "decrypted", which can be overridden by the architecture specific backends.
Also add a new flag - FLAG_SHARED - for allocating shared pages.
The page allocation/free routines get a "_shared_" variant too. These will be later used for Realm support and tests.
--- lib/alloc_page.c | 34 +++++++++++++++++++++++++++++++--- lib/alloc_page.h | 24 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-)
lib/alloc_page.c +31 -3
@@ -53,6 +53,20 @@ static struct mem_area areas[MAX_AREAS];/* Mask of initialized areas */ static unsigned int areas_mask;/* Protects areas and areas mask */ + +#ifndef set_memory_encrypted +static inline void set_memory_encrypted (unsigned long mem,unsigned long size) +{ +} +#endif + +#ifndef set_memory_decrypted +static inline void set_memory_decrypted (unsigned long mem,unsigned long size) +{ +} +#endif + +static struct spinlock lock;bool page_alloc_initialized (void )
@@ -263,7 +277,7 @@ static bool coalesce(struct mem_area *a, u8 order, pfn_t pfn, pfn_t pfn2)* - no pages in the memory block were already free * - no pages in the memory block are special */ -static void _free_pages (void *mem) +static void _free_pages (void *mem,u32 flags) {pfn_t pfn2, pfn =virt_to_pfn (mem);struct mem_area *a =NULL ;
@@ -281,6 +295,9 @@ static void _free_pages(void *mem) p = pfn - a->base; order = a->page_states[p] &ORDER_MASK ; +if (flags &FLAG_SHARED ) +set_memory_encrypted ((unsigned long )mem,BIT (order) *PAGE_SIZE ); +/* ensure that the first page is allocated and not special */ assert (IS_ALLOCATED (a->page_states[p]));/* ensure that the order has a sane value */
@@ -320,7 +337,14 @@ static void _free_pages(void *mem)void free_pages (void *mem) {spin_lock (&lock); -_free_pages (mem); +_free_pages (mem,0 ); +spin_unlock (&lock); +} + +void free_pages_shared (void *mem) +{ +spin_lock (&lock); +_free_pages (mem,FLAG_SHARED );spin_unlock (&lock); }
@@ -353,7 +377,7 @@ static void _unreserve_one_page(pfn_t pfn) i = pfn - a->base;assert (a->page_states[i] ==STATUS_SPECIAL ); a->page_states[i] =STATUS_ALLOCATED ; -_free_pages (pfn_to_virt (pfn)); +_free_pages (pfn_to_virt (pfn),0 ); }int reserve_pages (phys_addr_t addr,size_t n)
@@ -401,6 +425,10 @@ static void *page_memalign_order_flags(u8 al, u8 ord, u32 flags)if (area &BIT (i)) res =page_memalign_order (areas + i, al, ord, fresh);spin_unlock (&lock); + +if (res && (flags &FLAG_SHARED )) +set_memory_decrypted ((unsigned long )res,BIT (ord) *PAGE_SIZE ); +if (res && !(flags &FLAG_DONTZERO ))memset (res,0 ,BIT (ord) *PAGE_SIZE );return res;
lib/alloc_page.h +24 -0
@@ -21,6 +21,7 @@#define FLAG_DONTZERO 0x10000#define FLAG_FRESH 0x20000 +#define FLAG_SHARED 0x40000/* Returns true if the page allocator has been initialized */ bool page_alloc_initialized (void );
@@ -121,4 +122,27 @@ int reserve_pages(phys_addr_t addr, size_t npages);*/ void unreserve_pages (phys_addr_t addr,size_t npages); +/* Shared page operations */ +static inline void *alloc_pages_shared (unsigned long order) +{ +return alloc_pages_flags (order,FLAG_SHARED ); +} + +static inline void *alloc_page_shared (void ) +{ +return alloc_pages_shared (0 ); +} + +void free_pages_shared (void *mem); + +static inline void free_page_shared (void *page) +{ +free_pages_shared (page); +} + +static inline void free_pages_shared_by_order (void *mem,unsigned long order) +{ +free_pages_shared (mem); +} +#endif
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 18/27 arm: gic-v3-its: Use shared pages wherever needed
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
GICv3-ITS is emulated by the host and thus we should allocate shared pages for access by the host. Make sure the allocations are shared.
--- lib/arm/gic-v3.c | 6 ++++-- lib/arm64/gic-v3-its.c | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-)
lib/arm/gic-v3.c +4 -2
@@ -171,7 +171,9 @@ void gicv3_lpi_alloc_tables(void)u64 prop_val;int cpu; - gicv3_data.lpi_prop =alloc_pages (order); +assert (gicv3_redist_base ()); + + gicv3_data.lpi_prop =alloc_pages_shared (order);/* ID bits = 13, ie. up to 14b LPI INTID */ prop_val = (u64)(virt_to_phys (gicv3_data.lpi_prop)) |13 ;
@@ -186,7 +188,7 @@ void gicv3_lpi_alloc_tables(void)writeq (prop_val, ptr +GICR_PROPBASER ); - gicv3_data.lpi_pend[cpu] =alloc_pages (order); + gicv3_data.lpi_pend[cpu] =alloc_pages_shared (order); pend_val = (u64)(virt_to_phys (gicv3_data.lpi_pend[cpu]));writeq (pend_val, ptr +GICR_PENDBASER ); }
lib/arm64/gic-v3-its.c +3 -3
@@ -54,7 +54,7 @@ static void its_baser_alloc_table(struct its_baser *baser, size_t size)void *reg_addr =gicv3_its_base () +GITS_BASER + baser->index *8 ;u64 val =readq (reg_addr); - baser->table_addr =alloc_pages (order); + baser->table_addr =alloc_pages_shared (order); val |=virt_to_phys (baser->table_addr) |GITS_BASER_VALID ;
@@ -70,7 +70,7 @@ static void its_cmd_queue_init(void)unsigned long order =get_order (SZ_64K >>PAGE_SHIFT );u64 cbaser; - its_data.cmd_base =alloc_pages (order); + its_data.cmd_base =alloc_pages_shared (order); cbaser =virt_to_phys (its_data.cmd_base) | (SZ_64K /SZ_4K -1 ) |GITS_CBASER_VALID ;
@@ -123,7 +123,7 @@ struct its_device *its_create_device(u32 device_id, int nr_ites) new->nr_ites = nr_ites; n = (its_data.typer.ite_size * nr_ites) >>PAGE_SHIFT ; - new->itt =alloc_pages (get_order (n)); + new->itt =alloc_pages_shared (get_order (n)); its_data.nr_devices++;return new;
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 19/27 arm: realm: Enable memory encryption
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
Enable memory encryption support for Realms.
When a page is "decrypted", we set the RIPAS to EMPTY, hinting to the hypervisor that it could reclaim the page backing the IPA. Also the pagetable is updated with the PTE_NS_SHARED attrbiute, whic in effect turns the "ipa" to the unprotected alias.
Similarly for "encryption" we mark the IPA back to RIPAS_RAM and clear the PTE_NS_SHARED attribute.
--- lib/arm/mmu.c | 65 ++++++++++++++++++++++++++++++++++++++++++++-- lib/arm64/asm/io.h | 6 +++++ 2 files changed, 69 insertions(+), 2 deletions(-)
lib/arm/mmu.c +63 -2
@@ -22,6 +22,7 @@#include <linux/compiler.h> pgd_t *mmu_idmap; +unsigned long idmap_end;/* Used by Realms, depends on IPA size */ unsigned long prot_ns_shared =0 ;
@@ -30,6 +31,11 @@ unsigned long phys_mask_shift = 48;/* CPU 0 starts with disabled MMU */ static cpumask_t mmu_enabled_cpumask; +static bool is_idmap_address (phys_addr_t pa) +{ +return pa < idmap_end; +} +bool mmu_enabled (void ) {/*
@@ -92,12 +98,17 @@ static pteval_t *get_pte(pgd_t *pgtable, uintptr_t vaddr)return &pte_val (*pte); } +static void set_pte (uintptr_t vaddr,pteval_t *p_pte,pteval_t pte) +{ +WRITE_ONCE (*p_pte, pte); +flush_tlb_page (vaddr); +} +static pteval_t *install_pte (pgd_t *pgtable,uintptr_t vaddr,pteval_t pte) {pteval_t *p_pte =get_pte (pgtable, vaddr); -WRITE_ONCE (*p_pte, pte); -flush_tlb_page (vaddr); +set_pte (vaddr, p_pte, pte);return p_pte; }
@@ -122,6 +133,39 @@ phys_addr_t virt_to_pte_phys(pgd_t *pgtable, void *mem) + ((ulong )mem & (PAGE_SIZE -1 )); } +/* +* __idmap_set_range_prot - Apply permissions to the given idmap range. +*/ +static void __idmap_set_range_prot (unsigned long virt_offset,size_t size,pgprot_t prot) +{ +pteval_t *ptep; +pteval_t default_prot =PTE_TYPE_PAGE |PTE_AF |PTE_SHARED ; + +while (size >0 ) { +pteval_t pte = virt_offset | default_prot |pgprot_val (prot); + +if (!is_idmap_address (virt_offset)) +break ; +/* Break before make : Clear the PTE entry first */ + ptep =install_pte (mmu_idmap, (uintptr_t )virt_offset,0 ); +/* Now apply the changes */ +set_pte ((uintptr_t )virt_offset, ptep, pte); + + size -=PAGE_SIZE ; + virt_offset +=PAGE_SIZE ; + } +} + +static void idmap_set_range_shared (unsigned long virt_offset,size_t size) +{ +return __idmap_set_range_prot (virt_offset, size,__pgprot (PTE_WBWA |PTE_USER |PTE_NS_SHARED )); +} + +static void idmap_set_range_protected (unsigned long virt_offset,size_t size) +{ +__idmap_set_range_prot (virt_offset, size,__pgprot (PTE_WBWA |PTE_USER )); +} +void mmu_set_range_ptes (pgd_t *pgtable,uintptr_t virt_offset,phys_addr_t phys_start,phys_addr_t phys_end,pgprot_t prot)
@@ -190,6 +234,7 @@ void *setup_mmu(phys_addr_t phys_end, void *unused) }mmu_enable (mmu_idmap); + idmap_end = phys_end;return mmu_idmap; }
@@ -278,3 +323,19 @@ void mmu_clear_user(pgd_t *pgtable, unsigned long vaddr)flush_tlb_page (vaddr); } } + +void set_memory_encrypted (unsigned long va,size_t size) +{ +if (is_realm ()) { +arm_set_memory_protected (__virt_to_phys (va), size); +idmap_set_range_protected (va, size); + } +} + +void set_memory_decrypted (unsigned long va,size_t size) +{ +if (is_realm ()) { +arm_set_memory_shared (__virt_to_phys (va), size); +idmap_set_range_shared (va, size); + } +}
lib/arm64/asm/io.h +6 -0
@@ -89,6 +89,12 @@ static inline void *phys_to_virt(phys_addr_t x) return (void *)__phys_to_virt(x); } +extern void set_memory_decrypted (unsigned long va,size_t size); +#define set_memory_decrypted set_memory_decrypted + +extern void set_memory_encrypted (unsigned long va,size_t size); +#define set_memory_encrypted set_memory_encrypted +#include <asm-generic/io.h> #endif /* _ASMARM64_IO_H_ */
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 20/27 qcbor: Add QCBOR as a submodule
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
Adds the library QCBOR as submodule. This will be later used for arm64 realm attestation token parsing. The repository is available at:
https://github.com/laurencelundblade/QCBOR tag v1.0
--- .gitmodules | 3 +++ lib/qcbor | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 lib/qcbor
.gitmodules new file +3 -0
@@ -0,0 +1,3 @@ +[submodule "lib/qcbor"] + path = lib/qcbor + url = https://github.com/laurencelundblade/QCBOR.git
lib/qcbor new file +1 -0
@@ -0,0 +1 @@ +Subproject commit 56b17bf9f74096774944bcac0829adcd887d391e
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 21/27 arm: Add build steps for QCBOR library
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
The QCBOR library will be used for Realm attestation.
--- arm/Makefile.arm64 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arm/Makefile.arm64 +5 -1
@@ -9,6 +9,8 @@ ldarch = elf64-littleaarch64 arch_LDFLAGS = -pie -n arch_LDFLAGS += -z notext CFLAGS += -mstrict-align +CFLAGS += -I $(SRCDIR)/lib/qcbor/inc +CFLAGS += -DQCBOR_DISABLE_FLOAT_HW_USE -DQCBOR_DISABLE_PREFERRED_FLOAT -DUSEFULBUF_DISABLE_ALL_FLOAT mno_outline_atomics := $(call cc-option, -mno-outline-atomics, "") CFLAGS += $(mno_outline_atomics)
@@ -25,6 +27,7 @@ cflatobjs += lib/arm64/processor.o cflatobjs += lib/arm64/spinlock.o cflatobjs += lib/arm64/gic-v3-its.o lib/arm64/gic-v3-its-cmd.o cflatobjs += lib/arm64/rsi.o +cflatobjs += lib/qcbor/src/qcbor_decode.o lib/qcbor/src/UsefulBuf.o OBJDIRS += lib/arm64
@@ -40,4 +43,5 @@ tests += $(TEST_DIR)/realm-sea.flat include $(SRCDIR)/$(TEST_DIR)/Makefile.common arch_clean: arm_clean - $(RM) lib/arm64/.*.d + $(RM) lib/arm64/.*.d \ + lib/qcbor/src/.*.d
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 22/27 arm: Add a library to verify tokens using the QCBOR library
In reply to Joey GoulyFrom: Mate Toth-Pal <[email protected]>
Add a library wrapper around the QCBOR for parsing the Arm CCA attestation tokens.
--- arm/Makefile.arm64 | 7 +- lib/token_verifier/attest_defines.h | 50 +++ lib/token_verifier/token_dumper.c | 158 ++++++++ lib/token_verifier/token_dumper.h | 15 + lib/token_verifier/token_verifier.c | 591 ++++++++++++++++++++++++++++ lib/token_verifier/token_verifier.h | 77 ++++ 6 files changed, 897 insertions(+), 1 deletion(-) create mode 100644 lib/token_verifier/attest_defines.h create mode 100644 lib/token_verifier/token_dumper.c create mode 100644 lib/token_verifier/token_dumper.h create mode 100644 lib/token_verifier/token_verifier.c create mode 100644 lib/token_verifier/token_verifier.h
arm/Makefile.arm64 +6 -1
@@ -11,6 +11,7 @@ arch_LDFLAGS += -z notext CFLAGS += -mstrict-align CFLAGS += -I $(SRCDIR)/lib/qcbor/inc CFLAGS += -DQCBOR_DISABLE_FLOAT_HW_USE -DQCBOR_DISABLE_PREFERRED_FLOAT -DUSEFULBUF_DISABLE_ALL_FLOAT +CFLAGS += -I $(SRCDIR)/lib/token_verifier mno_outline_atomics := $(call cc-option, -mno-outline-atomics, "") CFLAGS += $(mno_outline_atomics)
@@ -28,6 +29,9 @@ cflatobjs += lib/arm64/spinlock.o cflatobjs += lib/arm64/gic-v3-its.o lib/arm64/gic-v3-its-cmd.o cflatobjs += lib/arm64/rsi.o cflatobjs += lib/qcbor/src/qcbor_decode.o lib/qcbor/src/UsefulBuf.o +cflatobjs += lib/token_verifier/token_verifier.o +cflatobjs += lib/token_verifier/token_dumper.o + OBJDIRS += lib/arm64
@@ -44,4 +48,5 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile.common arch_clean: arm_clean $(RM) lib/arm64/.*.d \ - lib/qcbor/src/.*.d + lib/qcbor/src/.*.d \ + lib/token_verifier/.*.d
lib/token_verifier/attest_defines.h new file +50 -0
50 lines not on this page · raw message
lib/token_verifier/token_dumper.c new file +158 -0
158 lines not on this page · raw message
lib/token_verifier/token_dumper.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 Arm Limited. +* All rights reserved. +*/ + +#ifndef __TOKEN_DUMPER_H__ +#define __TOKEN_DUMPER_H__ + +#include "token_verifier.h" + +void print_raw_token (const char *token,size_t size); +void print_token (struct attestation_claims *claims); + +#endif /* __TOKEN_DUMPER_H__ */
lib/token_verifier/token_verifier.c new file +591 -0
591 lines not on this page · raw message
lib/token_verifier/token_verifier.h new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 23/27 arm: realm: add RSI interface for attestation measurements
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
Add wrappers for the Attestation and measurement related RSI calls. These will be later used in the test cases
--- lib/arm64/asm/rsi.h | 7 +++++++ lib/arm64/rsi.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
lib/arm64/asm/rsi.h +7 -0
@@ -27,6 +27,13 @@ int rsi_invoke(unsigned int function_id, unsigned long arg0, struct smccc_result *result);int rsi_get_version (void ); +void rsi_attest_token_init (phys_addr_t addr,unsigned long *challenge, +struct smccc_result *res); +void rsi_attest_token_continue (phys_addr_t addr,struct smccc_result *res); +void rsi_extend_measurement (unsigned int index,unsigned long size, +unsigned long *measurement, +struct smccc_result *res); +void rsi_read_measurement (unsigned int index,struct smccc_result *res);static inline bool is_realm (void ) {
lib/arm64/rsi.c +32 -0
@@ -66,6 +66,38 @@ void arm_rsi_init(void) prot_ns_shared = (1UL << phys_mask_shift); } +void rsi_attest_token_init (phys_addr_t addr,unsigned long *challenge, +struct smccc_result *res) +{ +rsi_invoke (SMC_RSI_ATTEST_TOKEN_INIT , addr, + challenge[0 ], challenge[1 ], challenge[2 ], + challenge[3 ], challenge[4 ], challenge[5 ], + challenge[6 ], challenge[7 ],0 ,0 , res); +} + +void rsi_attest_token_continue (phys_addr_t addr,struct smccc_result *res) +{ +rsi_invoke (SMC_RSI_ATTEST_TOKEN_CONTINUE , addr, +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , res); +} + +void rsi_extend_measurement (unsigned int index,unsigned long size, +unsigned long *measurement,struct smccc_result *res) +{ +rsi_invoke (SMC_RSI_MEASUREMENT_EXTEND , index, size, + measurement[0 ], measurement[1 ], + measurement[2 ], measurement[3 ], + measurement[4 ], measurement[5 ], + measurement[6 ], measurement[7 ], +0 , res); +} + +void rsi_read_measurement (unsigned int index,struct smccc_result *res) +{ +rsi_invoke (SMC_RSI_MEASUREMENT_READ , index,0 , +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , res); +} +static unsigned rsi_set_addr_range_state (unsigned long start,unsigned long size,enum ripas_t state,unsigned long *top) {
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 24/27 arm: realm: Add helpers to decode RSI return codes
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
RMM encodes error code and index in the result of an operation. Add helpers to decode this information for use with the attestation tests.
--- lib/arm64/asm/rsi.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
lib/arm64/asm/rsi.h +33 -0
@@ -16,6 +16,39 @@extern bool rsi_present; +/* +* Logical representation of return code returned by RMM commands. +* Each failure mode of a given command should return a unique return code, so +* that the caller can use it to unambiguously identify the failure mode. To +* avoid having a very large list of enumerated values, the return code is +* composed of a status which identifies the category of the error (for example, +* an address was misaligned), and an index which disambiguates between multiple +* similar failure modes (for example, a command may take multiple addresses as +* its input; the index identifies _which_ of them was misaligned.) +*/ +typedef unsigned int status_t ; +typedef struct { +status_t status; +unsigned int index; +}return_code_t ; + +/* +* Convenience function for creating a return_code_t. +*/ +static inline return_code_t make_return_code (unsigned int status, +unsigned int index) +{ +return (return_code_t ) {status, index}; +} + +/* +* Unpacks a return code. +*/ +static inline return_code_t unpack_return_code (unsigned long error_code) +{ +return make_return_code (error_code &0xff , error_code >>8 ); +} +void arm_rsi_init (void ); int rsi_invoke(unsigned int function_id, unsigned long arg0,
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 25/27 arm: realm: Add Realm attestation tests
In reply to Joey GoulyFrom: Mate Toth-Pal <[email protected]>
Add tests for Attestation and measurement related RSI calls.
--- arm/Makefile.arm64 | 1 + arm/realm-attest.c | 1125 ++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 50 ++ lib/libcflat.h | 1 + 4 files changed, 1177 insertions(+) create mode 100644 arm/realm-attest.c
arm/Makefile.arm64 +1 -0
@@ -41,6 +41,7 @@ tests += $(TEST_DIR)/micro-bench.flat tests += $(TEST_DIR)/cache.flat tests += $(TEST_DIR)/debug.flat tests += $(TEST_DIR)/realm-rsi.flat +tests += $(TEST_DIR)/realm-attest.flat tests += $(TEST_DIR)/realm-fpu.flat tests += $(TEST_DIR)/realm-sea.flat
arm/realm-attest.c new file +1125 -0
1,125 lines not on this page · raw message
arm/unittests.cfg +50 -0
53 lines not on this page · raw message
lib/libcflat.h +1 -0
@@ -163,6 +163,7 @@ extern void setup_vm(void);#define SZ_64K (1 << 16)#define SZ_1M (1 << 20)#define SZ_2M (1 << 21) +#define SZ_512M (1 << 29)#define SZ_1G (1 << 30)#define SZ_2G (1ul << 31)
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 26/27 arm: realm: Add a test for shared memory
In reply to Joey GoulyFrom: Suzuki K Poulose <[email protected]>
Do some basic tests that trigger marking a memory region as RIPAS_EMPTY and accessing the shared memory. Also, convert it back to RAM and make sure the contents are scrubbed.
--- arm/Makefile.arm64 | 1 + arm/realm-ns-memory.c | 86 +++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 8 ++++ 3 files changed, 95 insertions(+) create mode 100644 arm/realm-ns-memory.c
arm/Makefile.arm64 +1 -0
@@ -44,6 +44,7 @@ tests += $(TEST_DIR)/realm-rsi.flat tests += $(TEST_DIR)/realm-attest.flat tests += $(TEST_DIR)/realm-fpu.flat tests += $(TEST_DIR)/realm-sea.flat +tests += $(TEST_DIR)/realm-ns-memory.flat include $(SRCDIR)/$(TEST_DIR)/Makefile.common
arm/realm-ns-memory.c new file +86 -0
86 lines not on this page · raw message
arm/unittests.cfg +8 -0
@@ -361,3 +361,11 @@ smp = 1 extra_params = -m 32 -append 'measurement' accel = kvm arch = arm64 + +[realm-ns-memory] +file=realm-ns-memory.flat +groups = nodefault realms +smp = 1 +extra_params = -m 32 +accel = kvm +arch = arm64
Signature · 1 line
2.17.1
Joey Gouly
reviewerRFC 27/27 NOT-FOR-MERGING: add run-realm-tests
In reply to Joey GoulyFrom: Alexandru Elisei <[email protected]>
Until we add support for KVMTOOL to run the tests using the scripts, provide a temporary script to run all the Realm tests.
--- arm/run-realm-tests | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 arm/run-realm-tests
arm/run-realm-tests new file +56 -0
@@ -0,0 +1,56 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2023, Arm Ltd +# All rights reserved +# + +TASKSET=${TASKSET:-taskset} +LKVM=${LKVM:-lkvm} +ARGS="--realm --irqchip=gicv3 --console=serial --network mode=none --nodefaults" + +TESTDIR="." +while getopts "d:" option; do + case "${option}" in + d) TESTDIR=${OPTARG};; + ?) + exit 1 + ;; + esac +done +if [[ ! -d ${TESTDIR} ]]; then + echo "Invalid directory: ${TESTDIR}" + exit 1 +fi + +function run_tests { + DIR="$1" + + $LKVM run $ARGS -c 2 -m 16 -k $DIR/selftest.flat -p "setup smp=2 mem=16" + $LKVM run $ARGS -c 1 -m 16 -k $DIR/selftest.flat -p "vectors-kernel" + $LKVM run $ARGS -c 1 -m 16 -k $DIR/selftest.flat -p "vectors-user" + $LKVM run $ARGS -c 4 -m 32 -k $DIR/selftest.flat -p "smp" + + $LKVM run $ARGS -c 1 -m 32 -k $DIR/realm-ns-memory.flat + + $LKVM run $ARGS -c 4 -m 32 -k $DIR/psci.flat + + $LKVM run $ARGS -c 4 -m 32 -k $DIR/gic.flat -p "ipi" + $LKVM run $ARGS -c 4 -m 32 -k $DIR/gic.flat -p "active" + + $LKVM run $ARGS -c 1 -m 16 -k $DIR/timer.flat + + $LKVM run $ARGS -c 1 -m 16 -k $DIR/realm-rsi.flat -p "version" + $LKVM run $ARGS -c 1 -m 16 -k $DIR/realm-rsi.flat -p "host_call hvc" + $LKVM run $ARGS -c 1 -m 16 -k $DIR/realm-sea.flat + + $LKVM run $ARGS -c 1 -m 24 -k $DIR/realm-attest.flat -p "attest" + $LKVM run $ARGS -c 2 -m 24 -k $DIR/realm-attest.flat -p "attest_smp" + $LKVM run $ARGS -c 1 -m 24 -k $DIR/realm-attest.flat -p "extend" + $LKVM run $ARGS -c 2 -m 24 -k $DIR/realm-attest.flat -p "extend_smp" + $LKVM run $ARGS -c 1 -m 24 -k $DIR/realm-attest.flat -p "extend_and_attest" + $LKVM run $ARGS -c 1 -m 24 -k $DIR/realm-attest.flat -p "measurement" + + $TASKSET -c 0 $LKVM run $ARGS -c 4 -m 32 -k $DIR/realm-fpu.flat +} + +run_tests "${TESTDIR}"
Signature · 1 line
2.17.1
Quoted 6 lines · Suzuki K Poulose
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
A prototype for launching Realm VMs with QEMU is available at:
https://lore.kernel.org/qemu-devel/[email protected]/
Thanks,
Jean
Quoted 9 lines · Jean-Philippe Brucker
Quoted 6 lines · Suzuki K Poulose
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Quoted 5 lines
A prototype for launching Realm VMs with QEMU is available at:
https://lore.kernel.org/qemu-devel/[email protected]/Thanks,
Jean
Hi Jean,
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
I configure it with the aarch64-softmmu target only and built, any other steps I should worry?
Itaru.
Quoted 6 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Itaru,
Quoted 3 lines · Itaru Kitayama
Hi Jean,
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
Do you know which call returns this error? Normally the RMEGuest support should print more detailed errors. Are you able to launch normal guests (without the rme-guest object and confidential-guest-support machine parameter)? Could you give the complete QEMU command-line?
Quoted 2 lines
I configure it with the aarch64-softmmu target only and built, any other steps I should worry?
No, that should be enough
Thanks,
Jean
Quoted 4 lines · Jean-Philippe Brucker
Hi Itaru,
On Wed, Mar 01, 2023 at 08:35:05AM +0900, Itaru Kitayama wrote:
Quoted 8 lines
Quoted 3 lines
Hi Jean,
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.Do you know which call returns this error? Normally the RMEGuest support should print more detailed errors. Are you able to launch normal guests (without the rme-guest object and confidential-guest-support machine parameter)? Could you give the complete QEMU command-line?
No, I cant say which. Yes, the CCA-capable QEMU boots if I don't set RME-related options.
Here's mine (based upon your command-line):
qemu-system-aarch64 -cpu host -accel kvm -machine virt,gic-version=3,confidential-guest-support=rme0 -smp 2 -m 256M -nographic -object rme-guest,id=rme0,measurement-algo=sha512 -kernel Image -initrd rootfs.ext2 -append 'console=ttyAMA0 earlycon' -overcommit mem-lock=on
Itaru.
Quoted 8 lines
Quoted 3 lines
I configure it with the aarch64-softmmu target only and built, any other steps I should worry?
No, that should be enough
Thanks,
Jean
Quoted 18 lines · Itaru Kitayama
Quoted 4 lines · Jean-Philippe Brucker
Hi Itaru,
On Wed, Mar 01, 2023 at 08:35:05AM +0900, Itaru Kitayama wrote:
Quoted 8 lines
Quoted 3 lines
Hi Jean,
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.Do you know which call returns this error? Normally the RMEGuest support should print more detailed errors. Are you able to launch normal guests (without the rme-guest object and confidential-guest-support machine parameter)? Could you give the complete QEMU command-line?
No, I cant say which. Yes, the CCA-capable QEMU boots if I don't set RME-related options.
Quoted 6 lines
Here's mine (based upon your command-line):
qemu-system-aarch64 -cpu host -accel kvm -machine virt,gic-version=3,confidential-guest-support=rme0 -smp 2 -m 256M -nographic -object rme-guest,id=rme0,measurement-algo=sha512 -kernel Image -initrd rootfs.ext2 -append 'console=ttyAMA0 earlycon' -overcommit mem-lock=on
Thank you, this works on my setup so I'm not sure what's wrong. Check that KVM initialized successfully, with this in the host kernel log:
"[ 0.267019] kvm [1]: Using prototype RMM support (version 56.0)"
Next step would be to find out where the EINVAL comes from, with printfs or GDB. This seems rather specific so I'll email you directly to avoid filling up everyone's inbox.
Thanks,
Jean
Quoted 2 lines · Itaru Kitayama
Quoted 2 lines
Quoted 2 lines
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
This was the KVM_SET_ONE_REG for the SVE vector size. During my tests I didn't enable SVE in the host but shrinkwrap enables more options.
Until we figure out support for SVE, disable it on the QEMU command-line (similarly to '--disable-sve' needed for kvmtool boot):
-cpu host,sve=off
Thanks,
Jean
Suzuki K Poulose
reviewerQuoted 6 lines · Jean-Philippe Brucker
Quoted 2 lines · Itaru Kitayama
Quoted 2 lines
Quoted 2 lines
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
This was the
KVM_SET_ONE_REGfor the SVE vector size. During my tests I didn't enable SVE in the host but shrinkwrap enables more options.
Does the Qemu check for SVE capability on /dev/kvm ? For kvmtool, we changed to using the VM instance and that would prevent using SVE, until the RMM supports it.
Suzuki
Quoted 8 lines
Until we figure out support for SVE, disable it on the QEMU command-line (similarly to '--disable-sve' needed for kvmtool boot):
-cpu host,sve=off
Thanks,
Jean
Quoted 11 lines · Suzuki K Poulose
Quoted 6 lines · Jean-Philippe Brucker
Quoted 2 lines · Itaru Kitayama
Quoted 2 lines
Quoted 2 lines
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
This was the
KVM_SET_ONE_REGfor the SVE vector size. During my tests I didn't enable SVE in the host but shrinkwrap enables more options.Does the Qemu check for SVE capability on
/dev/kvm? For kvmtool, we changed to using the VM instance and that would prevent using SVE, until the RMM supports it.
Yes, QEMU does check the SVE cap on /dev/kvm. I can propose changing it or complementing it with a VM check in my next version, it seems to work (though I need to double-check the VM fd lifetime). Same goes for KVM_CAP_STEAL_TIME, which I need to disable explicitly at the moment.
Thanks,
Jean
Quoted 13 lines
Suzuki
Quoted 8 lines
Until we figure out support for SVE, disable it on the QEMU command-line (similarly to '--disable-sve' needed for kvmtool boot):
-cpu host,sve=off
Thanks,
Jean
Quoted 9 lines · Jean-Philippe Brucker
Quoted 8 lines · Suzuki K Poulose
Quoted 6 lines · Jean-Philippe Brucker
Quoted 2 lines · Itaru Kitayama
Quoted 2 lines
Quoted 2 lines
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
This was the
KVM_SET_ONE_REGfor the SVE vector size. During my tests I didn't enable SVE in the host but shrinkwrap enables more options.
Quoted 8 lines
Quoted 3 lines
Does the Qemu check for SVE capability on
/dev/kvm? For kvmtool, we changed to using the VM instance and that would prevent using SVE, until the RMM supports it.Yes, QEMU does check the SVE cap on
/dev/kvm. I can propose changing it or complementing it with a VM check in my next version, it seems to work (though I need to double-check the VM fd lifetime). Same goes forKVM_CAP_STEAL_TIME, which I need to disable explicitly at the moment.
I'm probably missing something since I haven't looked at this, but I'm wondering what the "VM instance" check is and why it should be necessary. Shouldn't KVM only expose capabilities which it can provide? I.e. the "VM instance" check should be done by KVM and, when it fails, the SVE and steal-time capabilities should return 0.
Thanks,
drew
Suzuki K Poulose
reviewerQuoted 14 lines · Andrew Jones
Quoted 13 lines · Jean-Philippe Brucker
Quoted 11 lines · Suzuki K Poulose
Quoted 6 lines · Jean-Philippe Brucker
Quoted 2 lines · Itaru Kitayama
Quoted 2 lines
Quoted 2 lines
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
This was the
KVM_SET_ONE_REGfor the SVE vector size. During my tests I didn't enable SVE in the host but shrinkwrap enables more options.Does the Qemu check for SVE capability on
/dev/kvm? For kvmtool, we changed to using the VM instance and that would prevent using SVE, until the RMM supports it.
Quoted 7 lines
Quoted 4 lines
Yes, QEMU does check the SVE cap on
/dev/kvm. I can propose changing it or complementing it with a VM check in my next version, it seems to work (though I need to double-check the VM fd lifetime). Same goes forKVM_CAP_STEAL_TIME, which I need to disable explicitly at the moment.I'm probably missing something since I haven't looked at this, but I'm wondering what the "VM instance" check is and why it should be necessary.
Userspace can check for a KVM_CAP_ on KVM fd (/dev/kvm) or a VM fd (returned via KVM_CREATE_VM).
Quoted 1 line
Shouldn't KVM only expose capabilities which it can provide? I.e. the
Correct, given now that we have different "types" of VMs possible on Arm64, (Normal vs Realm vs pVM), the capabilities of each of these could be different and thus we should use the KVM_CAP_ on the VM fd ( referred to VM instance above) and not the generic KVM fd.
Quoted 3 lines
"VM instance" check should be done by KVM and, when it fails, the SVE and steal-time capabilities should return 0.
Correct.
Suzuki
Quoted 2 lines
Thanks,
drew
Quoted 26 lines · Suzuki K Poulose
Quoted 14 lines · Andrew Jones
Quoted 13 lines · Jean-Philippe Brucker
Quoted 11 lines · Suzuki K Poulose
Quoted 6 lines · Jean-Philippe Brucker
Quoted 2 lines · Itaru Kitayama
Quoted 2 lines
Quoted 2 lines
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
This was the
KVM_SET_ONE_REGfor the SVE vector size. During my tests I didn't enable SVE in the host but shrinkwrap enables more options.Does the Qemu check for SVE capability on
/dev/kvm? For kvmtool, we changed to using the VM instance and that would prevent using SVE, until the RMM supports it.Quoted 7 lines
Quoted 4 lines
Yes, QEMU does check the SVE cap on
/dev/kvm. I can propose changing it or complementing it with a VM check in my next version, it seems to work (though I need to double-check the VM fd lifetime). Same goes forKVM_CAP_STEAL_TIME, which I need to disable explicitly at the moment.I'm probably missing something since I haven't looked at this, but I'm wondering what the "VM instance" check is and why it should be necessary.
Userspace can check for a
KVM_CAP_on KVM fd (/dev/kvm) or a VM fd (returned viaKVM_CREATE_VM).
Quoted 6 lines
Quoted 1 line
Shouldn't KVM only expose capabilities which it can provide? I.e. the
Correct, given now that we have different "types" of VMs possible on Arm64, (Normal vs Realm vs pVM), the capabilities of each of these could be different and thus we should use the
KVM_CAP_on the VM fd ( referred to VM instance above) and not the generic KVM fd.
Using the vm ioctl is even encouraged in the doc for KVM_CHECK_EXTENSION:
"Based on their initialization different VMs may have different capabilities. It is thus encouraged to use the vm ioctl to query for capabilities"
It would probably make sense to convert QEMU to use the vm ioctl everywhere (the wrapper falls back to the global version on failure anyway.)
Quoted 11 lines
Quoted 4 lines
"VM instance" check should be done by KVM and, when it fails, the SVE and steal-time capabilities should return 0.
Correct.
Suzuki
Quoted 2 lines
Thanks,
drew
Quoted 38 lines · Cornelia Huck
Quoted 26 lines · Suzuki K Poulose
Quoted 14 lines · Andrew Jones
Quoted 13 lines · Jean-Philippe Brucker
Quoted 11 lines · Suzuki K Poulose
Quoted 6 lines · Jean-Philippe Brucker
Quoted 2 lines · Itaru Kitayama
Quoted 2 lines
Quoted 2 lines
I've tried your series in Real on CCA Host, but the KVM arch init emits an Invalid argument error and terminates.
This was the
KVM_SET_ONE_REGfor the SVE vector size. During my tests I didn't enable SVE in the host but shrinkwrap enables more options.Does the Qemu check for SVE capability on
/dev/kvm? For kvmtool, we changed to using the VM instance and that would prevent using SVE, until the RMM supports it.Quoted 7 lines
Quoted 4 lines
Yes, QEMU does check the SVE cap on
/dev/kvm. I can propose changing it or complementing it with a VM check in my next version, it seems to work (though I need to double-check the VM fd lifetime). Same goes forKVM_CAP_STEAL_TIME, which I need to disable explicitly at the moment.I'm probably missing something since I haven't looked at this, but I'm wondering what the "VM instance" check is and why it should be necessary.
Userspace can check for a
KVM_CAP_on KVM fd (/dev/kvm) or a VM fd (returned viaKVM_CREATE_VM).Quoted 6 lines
Quoted 1 line
Shouldn't KVM only expose capabilities which it can provide? I.e. the
Correct, given now that we have different "types" of VMs possible on Arm64, (Normal vs Realm vs pVM), the capabilities of each of these could be different and thus we should use the
KVM_CAP_on the VM fd ( referred to VM instance above) and not the generic KVM fd.Using the vm ioctl is even encouraged in the doc for
KVM_CHECK_EXTENSION:
Quoted 6 lines
"Based on their initialization different VMs may have different capabilities. It is thus encouraged to use the vm ioctl to query for capabilities"
It would probably make sense to convert QEMU to use the vm ioctl everywhere (the wrapper falls back to the global version on failure anyway.)
Indeed, I'll see if I can come up with something generic, thanks for the pointer
Thanks,
Jean
Quoted 30 lines · Suzuki K Poulose
[...]
Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sve
Quoted 2 lines
You may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Building all of these components and configuring the FVP correctly can be quite tricky, so I thought I would plug a tool we have called Shrinkwrap, which can simplify all of this.
The tool accepts a yaml input configuration that describes how a set of components should be built and packaged, and how the FVP should be configured and booted. And by default, it uses a Docker container on its backend, which contains all the required tools, including the FVP. You can optionally use Podman or have it run on your native system if you prefer. It supports both x86_64 and aarch64. And you can even run it in --dry-run mode to see the set of shell commands that would have been executed.
It comes with two CCA configs out-of-the-box; cca-3world.yaml builds TF-A, RMM, Linux (for both host and guest), kvmtool and kvm-unit-tests. cca-4world.yaml adds Hafnium and some demo SPs for the secure world (although since Hafnium requires x86_64 to build, cca-4world.yaml doesn't currently work on an aarch64 build host).
See the documentation [1] and repository [2] for more info.
Brief instructions to get you up and running:
# Install shrinkwrap. (I assume you have Docker installed):
sudo pip3 install pyyaml termcolor tuxmake
git clone https://git.gitlab.arm.com/tooling/shrinkwrap.git
export PATH=$PWD/shrinkwrap/shrinkwrap:$PATH
# If running Python < 3.9:
sudo pip3 install graphlib-backport
# Build all the CCA components:
shrinkwrap build cca-3world.yaml [--dry-run]
# Run the stack in the FVP:
shrinkwrap run cca-3world.yaml -r ROOTFS=<my_rootfs.ext4> [--dry-run]
By default, building is done at ~/.shrinkwrap/build/cca-3world and the package is created at ~/.shrinkwrap/package/cca-3world (this can be changed with envvars).
The 'run' command will boot TF-A, RMM and host Linux kernel in the FVP, and mount the provided rootfs. You will likely want to have copied the userspace pieces into the rootfs before running, so you can create realms:
- ~/.shrinkwrap/package/cca-3world/Image (kernel with RMI and RSI support)
- ~/.shrinkwrap/package/cca-3world/lkvm (kvmtool able to launch realms)
- ~/.shrinkwrap/package/cca-3world/kvm-unit-tests.tgz (built kvm-unit-tests)
Once the FVP is booted to a shell, you can do something like this to launch a Linux guest in a realm:
lkvm run --realm --disable-sve -c 1 -m 256 -k Image
[1] https://shrinkwrap.docs.arm.com
[2] https://gitlab.arm.com/tooling/shrinkwrap
Quoted 62 lines · Ryan Roberts
Quoted 30 lines · Suzuki K Poulose
[...]
Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveQuoted 2 lines
You may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Building all of these components and configuring the FVP correctly can be quite tricky, so I thought I would plug a tool we have called Shrinkwrap, which can simplify all of this.
The tool accepts a yaml input configuration that describes how a set of components should be built and packaged, and how the FVP should be configured and booted. And by default, it uses a Docker container on its backend, which contains all the required tools, including the FVP. You can optionally use Podman or have it run on your native system if you prefer. It supports both
x86_64and aarch64. And you can even run it in --dry-run mode to see the set of shell commands that would have been executed.It comes with two CCA configs out-of-the-box;
cca-3world.yamlbuilds TF-A, RMM, Linux (for both host and guest), kvmtool and kvm-unit-tests.cca-4world.yamladds Hafnium and some demo SPs for the secure world (although since Hafnium requiresx86_64to build,cca-4world.yamldoesn't currently work on an aarch64 build host).See the documentation [1] and repository [2] for more info.
Brief instructions to get you up and running:
# Install shrinkwrap. (I assume you have Docker installed):
sudo pip3 install pyyaml termcolor tuxmake
git clone https://git.gitlab.arm.com/tooling/shrinkwrap.git
export PATH=$PWD/shrinkwrap/shrinkwrap:$PATH
Quoted 5 lines
# If running Python < 3.9:
sudo pip3 install graphlib-backport# Build all the CCA components:
shrinkwrap buildcca-3world.yaml[--dry-run]
This has been working on my Multipass instance on M1, thanks for the tool.
Thanks,
Itaru.
Quoted 29 lines
# Run the stack in the FVP:
shrinkwrap runcca-3world.yaml-r ROOTFS=<my_rootfs.ext4> [--dry-run]By default, building is done at ~/.shrinkwrap/build/cca-3world and the package is created at ~/.shrinkwrap/package/cca-3world (this can be changed with envvars).
The 'run' command will boot TF-A, RMM and host Linux kernel in the FVP, and mount the provided rootfs. You will likely want to have copied the userspace pieces into the rootfs before running, so you can create realms:
- ~/.shrinkwrap/package/cca-3world/Image (kernel with RMI and RSI support)
- ~/.shrinkwrap/package/cca-3world/lkvm (kvmtool able to launch realms)
- ~/.shrinkwrap/package/cca-3world/kvm-unit-tests.tgz (built kvm-unit-tests)Once the FVP is booted to a shell, you can do something like this to launch a Linux guest in a realm:
lkvm run --realm --disable-sve -c 1 -m 256 -k Image[1] https://shrinkwrap.docs.arm.com
[2] https://gitlab.arm.com/tooling/shrinkwrap_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 67 lines · Itaru Kitayama
Quoted 65 lines · Ryan Roberts
Quoted 30 lines · Suzuki K Poulose
[...]
Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveQuoted 2 lines
You may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Building all of these components and configuring the FVP correctly can be quite tricky, so I thought I would plug a tool we have called Shrinkwrap, which can simplify all of this.
The tool accepts a yaml input configuration that describes how a set of components should be built and packaged, and how the FVP should be configured and booted. And by default, it uses a Docker container on its backend, which contains all the required tools, including the FVP. You can optionally use Podman or have it run on your native system if you prefer. It supports both
x86_64and aarch64. And you can even run it in --dry-run mode to see the set of shell commands that would have been executed.It comes with two CCA configs out-of-the-box;
cca-3world.yamlbuilds TF-A, RMM, Linux (for both host and guest), kvmtool and kvm-unit-tests.cca-4world.yamladds Hafnium and some demo SPs for the secure world (although since Hafnium requiresx86_64to build,cca-4world.yamldoesn't currently work on an aarch64 build host).See the documentation [1] and repository [2] for more info.
Brief instructions to get you up and running:
# Install shrinkwrap. (I assume you have Docker installed):
sudo pip3 install pyyaml termcolor tuxmake
git clone https://git.gitlab.arm.com/tooling/shrinkwrap.git
export PATH=$PWD/shrinkwrap/shrinkwrap:$PATH# If running Python < 3.9:
sudo pip3 install graphlib-backport
Quoted 7 lines
Quoted 2 lines
# Build all the CCA components:
shrinkwrap buildcca-3world.yaml[--dry-run]This has been working on my Multipass instance on M1, thanks for the tool.
Thanks,
Itaru.
It took a while though I've just booted an Ubuntu 22.10 disk image with the cca-3world.yaml config on M1.
Thanks,
Itaru.
Quoted 30 lines
Quoted 30 lines
# Run the stack in the FVP:
shrinkwrap runcca-3world.yaml-r ROOTFS=<my_rootfs.ext4> [--dry-run]By default, building is done at ~/.shrinkwrap/build/cca-3world and the package is created at ~/.shrinkwrap/package/cca-3world (this can be changed with envvars).
The 'run' command will boot TF-A, RMM and host Linux kernel in the FVP, and mount the provided rootfs. You will likely want to have copied the userspace pieces into the rootfs before running, so you can create realms:
- ~/.shrinkwrap/package/cca-3world/Image (kernel with RMI and RSI support)
- ~/.shrinkwrap/package/cca-3world/lkvm (kvmtool able to launch realms)
- ~/.shrinkwrap/package/cca-3world/kvm-unit-tests.tgz (built kvm-unit-tests)Once the FVP is booted to a shell, you can do something like this to launch a Linux guest in a realm:
lkvm run --realm --disable-sve -c 1 -m 256 -k Image[1] https://shrinkwrap.docs.arm.com
[2] https://gitlab.arm.com/tooling/shrinkwrap_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 71 lines · Itaru Kitayama
Quoted 70 lines · Itaru Kitayama
Quoted 67 lines · Ryan Roberts
Quoted 30 lines · Suzuki K Poulose
[...]
Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveQuoted 2 lines
You may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Building all of these components and configuring the FVP correctly can be quite tricky, so I thought I would plug a tool we have called Shrinkwrap, which can simplify all of this.
The tool accepts a yaml input configuration that describes how a set of components should be built and packaged, and how the FVP should be configured and booted. And by default, it uses a Docker container on its backend, which contains all the required tools, including the FVP. You can optionally use Podman or have it run on your native system if you prefer. It supports both
x86_64and aarch64. And you can even run it in --dry-run mode to see the set of shell commands that would have been executed.It comes with two CCA configs out-of-the-box;
cca-3world.yamlbuilds TF-A, RMM, Linux (for both host and guest), kvmtool and kvm-unit-tests.cca-4world.yamladds Hafnium and some demo SPs for the secure world (although since Hafnium requiresx86_64to build,cca-4world.yamldoesn't currently work on an aarch64 build host).See the documentation [1] and repository [2] for more info.
Brief instructions to get you up and running:
# Install shrinkwrap. (I assume you have Docker installed):
sudo pip3 install pyyaml termcolor tuxmake
git clone https://git.gitlab.arm.com/tooling/shrinkwrap.git
export PATH=$PWD/shrinkwrap/shrinkwrap:$PATH# If running Python < 3.9:
sudo pip3 install graphlib-backport# Build all the CCA components:
shrinkwrap buildcca-3world.yaml[--dry-run]
Quoted 7 lines
Quoted 4 lines
This has been working on my Multipass instance on M1, thanks for the tool.
Thanks,
Itaru.It took a while though I've just booted an Ubuntu 22.10 disk image with the
cca-3world.yamlconfig on M1.
That's good to hear - If you have any feedback (or patches ;-)) for Shrinkwrap that would improve the experience, do let me know!
Quoted 34 lines
Thanks,
Itaru.Quoted 30 lines
Quoted 30 lines
# Run the stack in the FVP:
shrinkwrap runcca-3world.yaml-r ROOTFS=<my_rootfs.ext4> [--dry-run]By default, building is done at ~/.shrinkwrap/build/cca-3world and the package is created at ~/.shrinkwrap/package/cca-3world (this can be changed with envvars).
The 'run' command will boot TF-A, RMM and host Linux kernel in the FVP, and mount the provided rootfs. You will likely want to have copied the userspace pieces into the rootfs before running, so you can create realms:
- ~/.shrinkwrap/package/cca-3world/Image (kernel with RMI and RSI support)
- ~/.shrinkwrap/package/cca-3world/lkvm (kvmtool able to launch realms)
- ~/.shrinkwrap/package/cca-3world/kvm-unit-tests.tgz (built kvm-unit-tests)Once the FVP is booted to a shell, you can do something like this to launch a Linux guest in a realm:
lkvm run --realm --disable-sve -c 1 -m 256 -k Image[1] https://shrinkwrap.docs.arm.com
[2] https://gitlab.arm.com/tooling/shrinkwrap_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 43 lines · * Suzuki K Poulose ([email protected]) wrote:
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsArm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------x
Quoted 8 lines
EL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor Call
Hi,
It's nice to see this full stack posted - thanks!
Are there any pointers to information on attestation and similar measurement things? In particular, are there any plans for a vTPM for Realms - if there were, it would make life easy for us, since we can share some user space stuff with other CoCo systems.
Dave
Quoted 176 lines
RME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1
Guest Support branch: cca-guest/rfc-v1[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Suzuki K Poulose
reviewerHi Dave
Thanks for your response, and apologies for the delay. Response, in line.
Quoted 53 lines · Dr. David Alan Gilbert
Quoted 43 lines · * Suzuki K Poulose ([email protected]) wrote:
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsArm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xQuoted 8 lines
EL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor Call
Quoted 5 lines
Hi,
It's nice to see this full stack posted - thanks!Are there any pointers to information on attestation and similar measurement things? In particular, are there any plans for a vTPM
The RMM v1.0 provides attestation and measurement services to the Realm, via Realm Service Interface (RSI) calls. However, there is no support for partitioning the Realm VM with v1.0. This is currently under development and should be available in the near future.
With that in place, a vTPM could reside in a partition of the Realm VM along side the OS in another. Does that answer your question ?
Kind regards
Suzuki
Quoted 181 lines
for Realms - if there were, it would make life easy for us, since we can share some user space stuff with other CoCo systems.
Dave
Quoted 176 lines
RME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1
Guest Support branch: cca-guest/rfc-v1[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
Quoted 58 lines · * Suzuki K Poulose ([email protected]) wrote:
Hi Dave
Thanks for your response, and apologies for the delay. Response, in line.
Quoted 53 lines · Dr. David Alan Gilbert
Quoted 51 lines · * Suzuki K Poulose ([email protected]) wrote:
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsArm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xEL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor Call
Quoted 8 lines
Quoted 5 lines
Hi,
It's nice to see this full stack posted - thanks!Are there any pointers to information on attestation and similar measurement things? In particular, are there any plans for a vTPM
The RMM v1.0 provides attestation and measurement services to the Realm, via Realm Service Interface (RSI) calls.
Can you point me at some docs for that?
Quoted 6 lines
However, there is no support
for partitioning the Realm VM with v1.0. This is currently under development and should be available in the near future.With that in place, a vTPM could reside in a partition of the Realm VM along side the OS in another. Does that answer your question ?
Possibly; it would be great to be able to use a standard vTPM interface here rather than have to do anything special. People already have this working on AMD SEV-SNP.
Dave
Quoted 184 lines
Kind regards
SuzukiQuoted 179 lines
for Realms - if there were, it would make life easy for us, since we can share some user space stuff with other CoCo systems.
Dave
Quoted 174 lines
RME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1
Guest Support branch: cca-guest/rfc-v1[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Suzuki K Poulose
reviewerQuoted 62 lines · Dr. David Alan Gilbert
Quoted 61 lines · * Suzuki K Poulose ([email protected]) wrote:
Hi Dave
Thanks for your response, and apologies for the delay. Response, in line.
Quoted 56 lines · Dr. David Alan Gilbert
Quoted 43 lines · * Suzuki K Poulose ([email protected]) wrote:
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux
stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsArm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xQuoted 8 lines
EL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor CallHi,
It's nice to see this full stack posted - thanks!
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Are there any pointers to information on attestation and similar measurement things? In particular, are there any plans for a vTPM
The RMM v1.0 provides attestation and measurement services to the Realm, via Realm Service Interface (RSI) calls.
Can you point me at some docs for that?
It is part of the RMM specification [1], linked below. Please see "Chapter A7. Realm Measurement and Attestation"
[1] https://developer.arm.com/documentation/den0137/latest
Quoted 10 lines
Quoted 6 lines
However, there is no support
for partitioning the Realm VM with v1.0. This is currently under development and should be available in the near future.With that in place, a vTPM could reside in a partition of the Realm VM along side the OS in another. Does that answer your question ?
Possibly; it would be great to be able to use a standard vTPM interface here rather than have to do anything special. People already have this working on AMD SEV-SNP.
Ok.
Quoted 2 lines
Dave
...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest
Suzuki
Quoted 59 lines
Quoted 59 lines
Quoted 58 lines
Quoted 58 lines
[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1
Guest Support branch: cca-guest/rfc-v1[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
On Fri, 27 Jan 2023 11:22:48 +0000
Suzuki K Poulose <[email protected]> wrote:
Hi Suzuki,
Looking at this has been on the backlog for a while from our side and we are finally getting to it. So before we dive in and given it's been 6 months, I wanted to check if you expect to post a new version shortly or if there is a rebased tree available?
Jonathan
Quoted 232 lines
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsArm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xEL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor CallRME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1
Guest Support branch: cca-guest/rfc-v1[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Suzuki K Poulose
reviewerHi Jonathan
Quoted 9 lines · Jonathan Cameron
On Fri, 27 Jan 2023 11:22:48 +0000
Suzuki K Poulose <[email protected]> wrote:Hi Suzuki,
Looking at this has been on the backlog for a while from our side and we are finally getting to it. So before we dive in and given it's been 6 months, I wanted to check if you expect to post a new version shortly or if there is a rebased tree available?
Thanks for your interest. We have been updating our trees to the latest RMM specification (v1.0-eac2 now) and also rebasing Linux/KVM on top of v6.5-rc1. We will post this as soon as we have all the components ready (and the TF-RMM). At the earliest, this would be around early September.
That said, the revised version will have the following changes :
- Changes to the Stage2 management
- Changes to RMM memory management for Realm
- PMU/SVE support
Otherwise, most of the changes remain the same (e.g., UABI). Happy to hear feedback on those areas.
Kind regards
Suzuki
Quoted 236 lines
Jonathan
Quoted 232 lines
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsArm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xEL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor CallRME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1
Guest Support branch: cca-guest/rfc-v1[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 18 lines · On Fri, 14 Jul 2023 16:03:37 +0100 Suzuki K Poulose <[email protected]>…
Hi Jonathan
Quoted 9 lines · Jonathan Cameron
On Fri, 27 Jan 2023 11:22:48 +0000
Suzuki K Poulose <[email protected]> wrote:Hi Suzuki,
Looking at this has been on the backlog for a while from our side and we are finally getting to it. So before we dive in and given it's been 6 months, I wanted to check if you expect to post a new version shortly or if there is a rebased tree available?
Thanks for your interest. We have been updating our trees to the latest RMM specification (v1.0-eac2 now) and also rebasing Linux/KVM on top of v6.5-rc1. We will post this as soon as we have all the components ready (and the TF-RMM). At the earliest, this would be around early September.
Quoted 7 lines
That said, the revised version will have the following changes :
- Changes to the Stage2 management
- Changes to RMM memory management for Realm
- PMU/SVE supportOtherwise, most of the changes remain the same (e.g., UABI). Happy to hear feedback on those areas.
Hi Suzuki,
Thanks for the update. If there is any chance of visibility of changes via a git tree etc that would be great in the meantime. If not, such is life and I'll try to wait patiently :) + we'll review the existing code.
Jonathan
Quoted 243 lines
Kind regards
SuzukiQuoted 236 lines
Jonathan
Quoted 232 lines
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsArm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xEL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor CallRME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \ <normal-vm-options>Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1
Guest Support branch: cca-guest/rfc-v1[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Suzuki K Poulose
reviewerQuoted 26 lines · Jonathan Cameron
Quoted 23 lines · On Fri, 14 Jul 2023 16:03:37 +0100 Suzuki K Poulose <[email protected]>…
Hi Jonathan
Quoted 9 lines · Jonathan Cameron
On Fri, 27 Jan 2023 11:22:48 +0000
Suzuki K Poulose <[email protected]> wrote:Hi Suzuki,
Looking at this has been on the backlog for a while from our side and we are finally getting to it. So before we dive in and given it's been 6 months, I wanted to check if you expect to post a new version shortly or if there is a rebased tree available?
Thanks for your interest. We have been updating our trees to the latest RMM specification (v1.0-eac2 now) and also rebasing Linux/KVM on top of v6.5-rc1. We will post this as soon as we have all the components ready (and the TF-RMM). At the earliest, this would be around early September.
That said, the revised version will have the following changes :
- Changes to the Stage2 management
- Changes to RMM memory management for Realm
- PMU/SVE support
Quoted 8 lines
Quoted 2 lines
Otherwise, most of the changes remain the same (e.g., UABI). Happy to hear feedback on those areas.
Hi Suzuki,
Thanks for the update. If there is any chance of visibility of changes via a git tree etc that would be great in the meantime. If not, such is life and I'll try to wait patiently :) + we'll review the existing code.
I am afraid not yet. Thanks for reviewing the changes :-)
Suzuki
Suzuki K Poulose
reviewerHi,
Quoted 10 lines
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for Realms
We have updated the stack for Arm CCA Linux support to RMM-v1.0-EAC2 (See links) We are not posting the patches for review yet, as we plan to update our stack to support the latest RMM-v1.0 specification, which includes some functional changes to support PSCI monitoring by the VMM along with other minor changes. All relevant components are updated on a new branch "rmm-v1.0-eac2" Guest-mem support is not included, but is in progress.
Change log :
- KVM RMI support updated to v1.0-eac2, with optimisations to stage2 tear down
- Guest (Linux and kvm-unit-test) support for RSI compliant to v1.0-eac2
- SVE, PMU support for Realms
kvmtool :
- Dropped no-compat and switched to --loglevel (merged upstream)
- Support for SVE, --sve-vl for vector length
Quoted 132 lines
Arm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xEL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor CallRME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]
Quoted 7 lines
Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \
As noted above, this is no longer required.
Quoted 16 lines
<normal-vm-options>
Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============
Quoted 8 lines
[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/
EAC2 spec: https://developer.arm.com/documentation/den0137/1-0eac2/
Quoted 8 lines
[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms
Quoted 6 lines
[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1
Update branch : cca-host/rmm-v1.0-eac2
Quoted 1 line
Guest Support branch: cca-guest/rfc-v1
Update branch : cca-guest/rmm-v1.0-eac2
Combined tree for host and guest is also available at: "cca-full/rmm-v1.0-eac2"
Quoted 3 lines
[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1
Update branch : cca/rmm-v1.0-eac2
Quoted 4 lines
[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1
Update branch : cca/rmm-v1.0-eac2
Suzuki
Quoted 6 lines
[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]
Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
Quoted 265 lines · Suzuki K Poulose
Hi,
Quoted 10 lines
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsWe have updated the stack for Arm CCA Linux support to RMM-v1.0-EAC2 (See links) We are not posting the patches for review yet, as we plan to update our stack to support the latest RMM-v1.0 specification, which includes some functional changes to support PSCI monitoring by the VMM along with other minor changes. All relevant components are updated on a new branch "rmm-v1.0-eac2" Guest-mem support is not included, but is in progress.
Change log :
- KVM RMI support updated to v1.0-eac2, with optimisations to stage2 tear down
- Guest (Linux and kvm-unit-test) support for RSI compliant to v1.0-eac2
- SVE, PMU support for Realmskvmtool :
- Dropped no-compat and switched to --loglevel (merged upstream)
- Support for SVE, --sve-vl for vector lengthQuoted 132 lines
Arm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xEL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor CallRME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Quoted 7 lines
Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \As noted above, this is no longer required.
Quoted 16 lines
<normal-vm-options>
Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============Quoted 8 lines
[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/EAC2 spec: https://developer.arm.com/documentation/den0137/1-0eac2/
Quoted 8 lines
[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20PlatformsQuoted 6 lines
[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1Update branch : cca-host/rmm-v1.0-eac2
Quoted 1 line
Guest Support branch: cca-guest/rfc-v1
Update branch : cca-guest/rmm-v1.0-eac2
Combined tree for host and guest is also available at: "cca-full/rmm-v1.0-eac2"
Quoted 3 lines
[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1Update branch : cca/rmm-v1.0-eac2
Quoted 4 lines
[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1Update branch : cca/rmm-v1.0-eac2
Suzuki
Quoted 6 lines
[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>
Quoted 8 lines
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
Suzuki,
Any update to the Arm CCA series (v3?) since last October?
Thanks,
Itaru.
Suzuki K Poulose
reviewerHi Itaru,
Quoted 274 lines · Itaru Kitayama
Quoted 264 lines · Suzuki K Poulose
Hi,
Quoted 10 lines
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsWe have updated the stack for Arm CCA Linux support to RMM-v1.0-EAC2 (See links) We are not posting the patches for review yet, as we plan to update our stack to support the latest RMM-v1.0 specification, which includes some functional changes to support PSCI monitoring by the VMM along with other minor changes. All relevant components are updated on a new branch "rmm-v1.0-eac2" Guest-mem support is not included, but is in progress.
Change log :
- KVM RMI support updated to v1.0-eac2, with optimisations to stage2 tear down
- Guest (Linux and kvm-unit-test) support for RSI compliant to v1.0-eac2
- SVE, PMU support for Realmskvmtool :
- Dropped no-compat and switched to --loglevel (merged upstream)
- Support for SVE, --sve-vl for vector lengthQuoted 132 lines
Arm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xEL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor CallRME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Quoted 7 lines
Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \As noted above, this is no longer required.
Quoted 16 lines
<normal-vm-options>
Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============Quoted 8 lines
[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/EAC2 spec: https://developer.arm.com/documentation/den0137/1-0eac2/
Quoted 5 lines
[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.gitQuoted 8 lines
[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/ >>>
[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1Update branch : cca-host/rmm-v1.0-eac2
Quoted 1 line
Guest Support branch: cca-guest/rfc-v1
Update branch : cca-guest/rmm-v1.0-eac2
Combined tree for host and guest is also available at: "cca-full/rmm-v1.0-eac2"
Quoted 3 lines
[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1Update branch : cca/rmm-v1.0-eac2
Quoted 4 lines
[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1Update branch : cca/rmm-v1.0-eac2
Suzuki
Quoted 6 lines
[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>Quoted 8 lines
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
Quoted 2 lines
Suzuki,
Any update to the Arm CCA series (v3?) since last October?
Yes, we now have a version that supports the final RMM-v1.0 specification (RMM-v1.0-EAC5). We also have the UEFI EDK2 firmware support for Guests in Realm world.
We are planning to post the changes for review in the v6.8-rc cycle. We are trying to integrate the guest_mem support (available in v6.8-rc1) as well as reusing some of the arm64 kvm generic interface for configuring the Realm parameters (e.g., PMU, SVE_VL etc).
Here is a version that is missing the items mentioned above, based on v6.7-rc4, if anyone would like to try.
Also, the easiest way to get the components built and model kick started is using the shrinkwrap [6] tool, using the cca-3world configuration. The tool pulls all the required software components, builds (including the buildroot for rootfs) and can run a model using these built components.
[0] Linux Repo:
Where: [email protected]:linux-arm/linux-cca.git KVM Support branch: cca-host/rmm-v1.0-eac5 Linux Guest branch: cca-guest/rmm-v1.0-eac5 Full stack branch: cca-full/rmm-v1.0-eac5
[1] kvmtool Repo:
Where: [email protected]:linux-arm/kvmtool-cca.git Branch: cca/rmm-v1.0-eac5
[2] kvm-unit-tests Repo:
Where: [email protected]:linux-arm/kvm-unit-tests-cca.git Branch: cca/rmm-v1.0-eac5
[3] UEFI Guest firmware:
edk2: https://git.gitlab.arm.com/linux-arm/edk2-cca.git revision: 2802_arm_cca_rmm-v1.0-eac5 edk2-platforms: https://git.gitlab.arm.com/linux-arm/edk2-platforms-cca.git revision: 2802_arm_cca_rmm-v1.0-eac5
[4] RMM Repo:
Where: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git tag : tf-rmm-v0.4.0
[5] TF-A repo:
Where: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git Tag: v2.10
[6] https://shrinkwrap.docs.arm.com/en/latest/
config: cca-3world.yaml
Kind regards
Suzuki
Suzuki K Poulose
reviewerQuoted 7 lines · Suzuki K Poulose
Hi Itaru,
Quoted 4 lines · Itaru Kitayama
Quoted 3 lines · Suzuki K Poulose
Hi,
...
Quoted 13 lines
Quoted 3 lines
Suzuki,
Any update to the Arm CCA series (v3?) since last October?Yes, we now have a version that supports the final RMM-v1.0 specification (RMM-v1.0-EAC5). We also have the UEFI EDK2 firmware support for Guests in Realm world.
We are planning to post the changes for review in the v6.8-rc cycle. We are trying to integrate the
guest_memsupport (available in v6.8-rc1) as well as reusing some of the arm64 kvm generic interface for configuring the Realm parameters (e.g., PMU,SVE_VLetc).
Quoted 8 lines
Here is a version that is missing the items mentioned above, based on v6.7-rc4, if anyone would like to try.
Also, the easiest way to get the components built and model kick started is using the shrinkwrap [6] tool, using the cca-3world configuration. The tool pulls all the required software components, builds (including the buildroot for rootfs) and can run a model using these built components.
Also, please see 'arm/run-realm-tests.sh' in the kvm-unit-tests-cca repository for sample command lines to invoke kvmtool to create Realm VMs.
Quoted 30 lines
[0] Linux Repo:
Where: [email protected]:linux-arm/linux-cca.git KVM Support branch: cca-host/rmm-v1.0-eac5 Linux Guest branch: cca-guest/rmm-v1.0-eac5 Full stack branch: cca-full/rmm-v1.0-eac5[1] kvmtool Repo:
Where: [email protected]:linux-arm/kvmtool-cca.git
Branch: cca/rmm-v1.0-eac5[2] kvm-unit-tests Repo:
Where: [email protected]:linux-arm/kvm-unit-tests-cca.git
Branch: cca/rmm-v1.0-eac5[3] UEFI Guest firmware:
edk2: https://git.gitlab.arm.com/linux-arm/edk2-cca.git
revision: 2802_arm_cca_rmm-v1.0-eac5edk2-platforms:
https://git.gitlab.arm.com/linux-arm/edk2-platforms-cca.git
revision: 2802_arm_cca_rmm-v1.0-eac5[4] RMM Repo:
Where: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git
tag : tf-rmm-v0.4.0
Quoted 8 lines
[5] TF-A repo:
Where: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git
Tag: v2.10[6] https://shrinkwrap.docs.arm.com/en/latest/
config:cca-3world.yaml
Suzuki
Quoted 33 lines · Suzuki K Poulose
Quoted 7 lines · Suzuki K Poulose
Hi Itaru,
Quoted 4 lines · Itaru Kitayama
Quoted 3 lines · Suzuki K Poulose
Hi,
...
Quoted 13 lines
Quoted 3 lines
Suzuki,
Any update to the Arm CCA series (v3?) since last October?Yes, we now have a version that supports the final RMM-v1.0 specification (RMM-v1.0-EAC5). We also have the UEFI EDK2 firmware support for Guests in Realm world.
We are planning to post the changes for review in the v6.8-rc cycle. We are trying to integrate the
guest_memsupport (available in v6.8-rc1) as well as reusing some of the arm64 kvm generic interface for configuring the Realm parameters (e.g., PMU,SVE_VLetc).Quoted 8 lines
Here is a version that is missing the items mentioned above, based on v6.7-rc4, if anyone would like to try.
Also, the easiest way to get the components built and model kick started is using the shrinkwrap [6] tool, using the cca-3world configuration. The tool pulls all the required software components, builds (including the buildroot for rootfs) and can run a model using these built components.
Quoted 3 lines
Also, please see '
arm/run-realm-tests.sh' in the kvm-unit-tests-cca repository for sample command lines to invoke kvmtool to create Realm VMs.
Thank you, Suzuki. I have just run the script above, again in the framework of shrinkwrap on the RevC FVP and the jobs ran fine. I need to go look at the lots of logs.
Itaru.
Quoted 43 lines
Quoted 32 lines
[0] Linux Repo:
Where: [email protected]:linux-arm/linux-cca.git KVM Support branch: cca-host/rmm-v1.0-eac5 Linux Guest branch: cca-guest/rmm-v1.0-eac5 Full stack branch: cca-full/rmm-v1.0-eac5[1] kvmtool Repo:
Where: [email protected]:linux-arm/kvmtool-cca.git
Branch: cca/rmm-v1.0-eac5[2] kvm-unit-tests Repo:
Where: [email protected]:linux-arm/kvm-unit-tests-cca.git
Branch: cca/rmm-v1.0-eac5[3] UEFI Guest firmware:
edk2: https://git.gitlab.arm.com/linux-arm/edk2-cca.git
revision: 2802_arm_cca_rmm-v1.0-eac5edk2-platforms:
https://git.gitlab.arm.com/linux-arm/edk2-platforms-cca.git
revision: 2802_arm_cca_rmm-v1.0-eac5[4] RMM Repo:
Where: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git
tag : tf-rmm-v0.4.0Quoted 8 lines
[5] TF-A repo:
Where: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git
Tag: v2.10[6] https://shrinkwrap.docs.arm.com/en/latest/
config:cca-3world.yamlSuzuki
Quoted 287 lines · Suzuki K Poulose
Hi Itaru,
Quoted 272 lines · Itaru Kitayama
Quoted 262 lines · Suzuki K Poulose
Hi,
Quoted 10 lines
We are happy to announce the early RFC version of the Arm Confidential Compute Architecture (CCA) support for the Linux stack. The intention is to seek early feedback in the following areas:
* KVM integration of the Arm CCA
* KVM UABI for managing the Realms, seeking to generalise the operations wherever possible with other Confidential Compute solutions.
Note: This version doesn't support Guest Private memory, which will be added later (see below).
* Linux Guest support for RealmsWe have updated the stack for Arm CCA Linux support to RMM-v1.0-EAC2 (See links) We are not posting the patches for review yet, as we plan to update our stack to support the latest RMM-v1.0 specification, which includes some functional changes to support PSCI monitoring by the VMM along with other minor changes. All relevant components are updated on a new branch "rmm-v1.0-eac2" Guest-mem support is not included, but is in progress.
Change log :
- KVM RMI support updated to v1.0-eac2, with optimisations to stage2 tear down
- Guest (Linux and kvm-unit-test) support for RSI compliant to v1.0-eac2
- SVE, PMU support for Realmskvmtool :
- Dropped no-compat and switched to --loglevel (merged upstream)
- Support for SVE, --sve-vl for vector lengthQuoted 130 lines
Arm CCA Introduction
=====================The Arm CCA is a reference software architecture and implementation that builds on the Realm Management Extension (RME), enabling the execution of Virtual machines, while preventing access by more privileged software, such as hypervisor. The Arm CCA allows the hypervisor to control the VM, but removes the right for access to the code, register state or data that is used by VM.
More information on the architecture is available here[0].Arm CCA Reference Software Architecture Realm World || Normal World || Secure World || || | || || EL0 x-------x || x----x | x------x || || | Realm | || | | | | | || || | | || | VM | | | | || || ----| VM* |---------||-| |---| |-||----------------|| | | || | | | | H | || || EL1 x-------x || x----x | | | || || ^ || | | o | || || | || | | | || || ------- R*------------------------| s -|--------------------- S || | | || || I || | t | || || | || | | || || v || x------x || || EL2 RMM* || ^ || || ^ || | || || ========|=============================|======================== | | SMC x--------- *RMI* -------------xEL3 Root World
EL3 Firmware
===============================================================
Where :
RMM - Realm Management Monitor
RMI - Realm Management Interface
RSI - Realm Service Interface
SMC - Secure Monitor CallRME introduces a new security state "Realm world", in addition to the traditional Secure and Non-Secure states. The Arm CCA defines a new component, Realm Management Monitor (RMM) that runs at R-EL2. This is a standard piece of firmware, verified, installed and loaded by the EL3 firmware (e.g, TF-A), at system boot.
The RMM provides standard interfaces - Realm Management Interface (RMI) - to the Normal world hypervisor to manage the VMs running in the Realm world (also called Realms in short). These are exposed via SMC and are routed through the EL3 firmwre.
The RMI interface includes:
- Move a physical page from the Normal world to the Realm world
- Creating a Realm with requested parameters, tracked via Realm Descriptor (RD)
- Creating VCPUs aka Realm Execution Context (REC), with initial register state.
- Create stage2 translation table at any level.
- Load initial images into Realm Memory from normal world memory
- Schedule RECs (vCPUs) and handle exits
- Inject virtual interrupts into the Realm
- Service stage2 runtime faults with pages (provided by host, scrubbed by RMM).
- Create "shared" mappings that can be accessed by VMM/Hyp.
- Reclaim the memory allocated for the RAM and RTTs (Realm Translation Tables)However v1.0 of RMM specifications doesn't support:
- Paging protected memory of a Realm VM. Thus the pages backing the protected memory region must be pinned.
- Live migration of Realms.
- Trusted Device assignment.
- Physical interrupt backed Virtual interrupts for RealmsRMM also provides certain services to the Realms via SMC, called Realm Service Interface (RSI). These include:
- Realm Guest Configuration.
- Attestation & Measurement services
- Managing the state of an Intermediate Physical Address (IPA aka GPA) page.
- Host Call service (Communication with the Normal world Hypervisor)The specifications for the RMM software is currently at *v1.0-Beta2* and the latest version is available here [1].
The Trusted Firmware foundation has an implementation of the RMM - TF-RMM - available here [3].
Implementation
=================This version of the stack is based on the RMM specification v1.0-Beta0[2], with following exceptions :
- TF-RMM/KVM currently doesn't support the optional features of PMU, SVE and Self-hosted debug (coming soon).
- TheRSI_HOST_CALLstructure alignment requirement is reduced to matchRMM v1.0 Beta1- RMI/RSI version numbers do not match the RMM spec. This will be resolved once the spec/implementation is complete, across TF-RMM+Linux stack.
We plan to update the stack to support the latest version of the RMMv1.0 spec in the coming revisions.
This release includes the following components :
a) Linux Kernel
i) Host / KVM support - Support for driving the Realms via RMI. This is dependent on running in the Kernel at EL2 (aka VHE mode). Also provides UABI for VMMs to manage the Realm VMs. The support is restricted to 4K page size, matching the Stage2 granule supported by RMM. The VMM is responsible for making sure the guest memory is locked.TODO: Guest Private memory[10] integration - We have been following the series and support will be added once it is merged upstream.
ii) Guest support - Support for a Linux Kernel to run in the Realm VM at Realm-EL1, using RSI services. This includes virtio support (virtio-v1.0 only). All I/O are treated as non-secure/shared.
c) kvmtool - VMM changes required to manage Realm VMs. No guest private memory as mentioned above.
d) kvm-unit-tests - Support for running in Realms along with additional tests for RSI ABI.Running the stack
====================To run/test the stack, you would need the following components :
1) FVP Base AEM RevC model with
FEAT_RMEsupport [4]
2) TF-A firmware for EL3 [5]
3) TF-A RMM for R-EL2 [3]
4) Linux Kernel [6]
5) kvmtool [7]
6) kvm-unit-tests [8]Quoted 7 lines
Instructions for building the firmware components and running the model are available here [9]. Once, the host kernel is booted, a Realm can be launched by invoking the
lkvmcommad as follows:$ lkvm run --realm \ --measurement-algo=["sha256", "sha512"] \ --disable-sve \As noted above, this is no longer required.
Quoted 16 lines
<normal-vm-options>
Where:
* --measurement-algo (Optional) specifies the algorithm selected for creating the initial measurements by the RMM for this Realm (defaults to sha256).
* GICv3 is mandatory for the Realms.
* SVE is not yet supported in the TF-RMM, and thus must be disabled using --disable-sveYou may also run the kvm-unit-tests inside the Realm world, using the similar options as above.
Links
============Quoted 8 lines
[0] Arm CCA Landing page (See Key Resources section for various documentations)
https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture[1] RMM Specification Latest
https://developer.arm.com/documentation/den0137/latest[2] RMM v1.0-Beta0 specification
https://developer.arm.com/documentation/den0137/1-0bet0/EAC2 spec: https://developer.arm.com/documentation/den0137/1-0eac2/
Quoted 5 lines
[3] Trusted Firmware RMM - TF-RMM
https://www.trustedfirmware.org/projects/tf-rmm/
GIT: https://git.trustedfirmware.org/TF-RMM/tf-rmm.gitQuoted 8 lines
[4] FVP Base RevC AEM Model (available on
x86_64/ Arm64 Linux)
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms[5] Trusted Firmware for A class
https://www.trustedfirmware.org/projects/tf-a/ >>>
[6] Linux kernel support for Arm-CCA
https://gitlab.arm.com/linux-arm/linux-cca
Host Support branch: cca-host/rfc-v1Update branch : cca-host/rmm-v1.0-eac2
Quoted 1 line
Guest Support branch: cca-guest/rfc-v1
Update branch : cca-guest/rmm-v1.0-eac2
Combined tree for host and guest is also available at: "cca-full/rmm-v1.0-eac2"
Quoted 3 lines
[7] kvmtool support for Arm CCA
https://gitlab.arm.com/linux-arm/kvmtool-cca cca/rfc-v1Update branch : cca/rmm-v1.0-eac2
Quoted 4 lines
[8] kvm-unit-tests support for Arm CCA
https://gitlab.arm.com/linux-arm/kvm-unit-tests-cca cca/rfc-v1Update branch : cca/rmm-v1.0-eac2
Suzuki
Quoted 6 lines
[9] Instructions for Building Firmware components and running the model, see section 4.19.2 "Building and running TF-A with RME"
https://trustedfirmware-a.readthedocs.io/en/latest/components/realm-management-extension.html#building-and-running-tf-a-with-rme[10] fd based Guest Private memory for KVM
https://lkml.kernel.org/r/[email protected]Cc: Alexandru Elisei <[email protected]>
Cc: Andrew Jones <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chao Peng <[email protected]>
Cc: Christoffer Dall <[email protected]>
Cc: Fuad Tabba <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: James Morse <[email protected]>
Cc: Jean-Philippe Brucker <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Quentin Perret <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Steven Price <[email protected]>Quoted 8 lines
Cc: Thomas Huth <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Zenghui Yu <[email protected]>
To: [email protected]
To: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]Quoted 2 lines
Suzuki,
Any update to the Arm CCA series (v3?) since last October?Yes, we now have a version that supports the final RMM-v1.0 specification (RMM-v1.0-EAC5). We also have the UEFI EDK2 firmware support for Guests in Realm world.
We are planning to post the changes for review in the v6.8-rc cycle. We are trying to integrate the
guest_memsupport (available in v6.8-rc1) as well as reusing some of the arm64 kvm generic interface for configuring the Realm parameters (e.g., PMU,SVE_VLetc).
Quoted 8 lines
Here is a version that is missing the items mentioned above, based on v6.7-rc4, if anyone would like to try.
Also, the easiest way to get the components built and model kick started is using the shrinkwrap [6] tool, using the cca-3world configuration. The tool pulls all the required software components, builds (including the buildroot for rootfs) and can run a model using these built components.
Hi Suzuki,
This is great news! I've just booted you guys WIP Linux kernel through shrinkwrap (cca-3world.yaml) without an issue.
Many thanks to Ryan who delivered an extremely handy tool to us.
Thanks,
Itaru.
Quoted 42 lines
[0] Linux Repo:
Where: [email protected]:linux-arm/linux-cca.git KVM Support branch: cca-host/rmm-v1.0-eac5 Linux Guest branch: cca-guest/rmm-v1.0-eac5 Full stack branch: cca-full/rmm-v1.0-eac5[1] kvmtool Repo:
Where: [email protected]:linux-arm/kvmtool-cca.git Branch: cca/rmm-v1.0-eac5[2] kvm-unit-tests Repo:
Where: [email protected]:linux-arm/kvm-unit-tests-cca.git Branch: cca/rmm-v1.0-eac5[3] UEFI Guest firmware:
edk2: https://git.gitlab.arm.com/linux-arm/edk2-cca.git revision: 2802_arm_cca_rmm-v1.0-eac5 edk2-platforms: https://git.gitlab.arm.com/linux-arm/edk2-platforms-cca.git revision: 2802_arm_cca_rmm-v1.0-eac5[4] RMM Repo:
Where: https://git.trustedfirmware.org/TF-RMM/tf-rmm.git tag : tf-rmm-v0.4.0[5] TF-A repo:
Where: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git Tag: v2.10[6] https://shrinkwrap.docs.arm.com/en/latest/
config:cca-3world.yamlKind regards
Suzuki