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 <dbrazdil@google.com>
Change-Id: Ic5ca01a56344cd0253bf7b71560f057ba0e54d6b
This commit is contained in:
David Brazdil
2021-06-24 11:02:37 +00:00
parent d2efcdcb2b
commit 3cd8b5b00b
2 changed files with 10 additions and 2 deletions

View File

@@ -127,6 +127,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;

View File

@@ -301,10 +301,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)