ANDROID: KVM: arm64: Add 'host_stage2_adjust_mmio_range' to kvm_iommu_ops

Add a new kvm_iommu_ops hook to the lower-EL instruction/data abort
handler, which allows the IOMMU driver to restrict the region of device
memory that is about to be mapped in the host stage-2.

This can be used by the IOMMU driver to restrict access to the MMIO
registers of the IOMMU itself.

Test: builds, boots
Bug: 190463801
Change-Id: I51cf3cfd84c889627e290d74579657447964ca16
Signed-off-by: David Brazdil <dbrazdil@google.com>
(cherry picked from commit cc1ad46fb2)
Signed-off-by: Mostafa Saleh <smostafa@google.com>
Signed-off-by: Quentin Perret <qperret@google.com>
This commit is contained in:
David Brazdil
2021-10-28 14:23:05 +01:00
committed by Quentin Perret
parent 59d406c88d
commit 2bc6495fed
2 changed files with 13 additions and 0 deletions

View File

@@ -138,6 +138,8 @@ struct kvm_iommu_ops {
phys_addr_t fault_pa, unsigned int len,
bool is_write, int rd);
void (*host_stage2_set_owner)(phys_addr_t addr, size_t size, u32 owner_id);
int (*host_stage2_adjust_mmio_range)(phys_addr_t addr, phys_addr_t *start,
phys_addr_t *end);
};
extern struct kvm_iommu_ops kvm_iommu_ops;

View File

@@ -624,6 +624,17 @@ static int host_stage2_idmap(u64 addr)
prot = is_memory ? PKVM_HOST_MEM_PROT : PKVM_HOST_MMIO_PROT;
/**
* Let device drivers adjust the permitted range first.
* host_stage2_adjust_range() should be last to also properly align it.
*/
if (!is_memory && kvm_iommu_ops.host_stage2_adjust_mmio_range) {
ret = kvm_iommu_ops.host_stage2_adjust_mmio_range(addr, &range.start,
&range.end);
if (ret)
return ret;
}
host_lock_component();
ret = host_stage2_adjust_range(addr, &range);
if (ret)