From f51f6b5d266d4f54363dcfe408784640efdacc54 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Thu, 24 Jun 2021 11:02:37 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Add 'host_stage2_set_owner' to kvm_iommu_ops Add a new hook to kvm_iommu_ops that is invoked whenever a range of pages changes their owner in the host stage2. This is currently limited to finalize_host_mappings, which changes the owner of EL2-mapped pages from host to hyp. The driver is expected to apply corresponding changes in the IOMMU it controls, so that only the new owner can access the page range. Test: builds, boots Bug: 190463801 Signed-off-by: David Brazdil Change-Id: Ic5ca01a56344cd0253bf7b71560f057ba0e54d6b --- arch/arm64/include/asm/kvm_hyp.h | 1 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 902fefe9b38f..0451ec0f4263 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -126,6 +126,7 @@ extern u64 kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val); struct kvm_iommu_ops { int (*init)(void); bool (*host_smc_handler)(struct kvm_cpu_context *host_ctxt); + void (*host_stage2_set_owner)(phys_addr_t addr, size_t size, u8 owner_id); }; extern struct kvm_iommu_ops kvm_iommu_ops; diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 674f10564373..3bda371ba83b 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -322,10 +322,17 @@ int host_stage2_idmap_locked(phys_addr_t addr, u64 size, int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id) { + int ret; + hyp_assert_lock_held(&host_kvm.lock); - return host_stage2_try(kvm_pgtable_stage2_set_owner, &host_kvm.pgt, - addr, size, &host_s2_pool, owner_id); + ret = host_stage2_try(kvm_pgtable_stage2_set_owner, &host_kvm.pgt, + addr, size, &host_s2_pool, owner_id); + + if (!ret && kvm_iommu_ops.host_stage2_set_owner) + kvm_iommu_ops.host_stage2_set_owner(addr, size, owner_id); + + return ret; } static bool host_stage2_force_pte_cb(u64 addr, u64 end, enum kvm_pgtable_prot prot)