Revert "ANDROID: KVM: arm64: iommu: Create private mapping last"

This reverts commit c690c2e305.

Bug: 233587962
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: If921b6b032233bc649b076fa3f4de37600c71dc3
This commit is contained in:
Will Deacon
2022-07-07 15:48:55 +01:00
parent 59fe12e0c0
commit 59eea64c9a

View File

@@ -293,7 +293,7 @@ int __pkvm_iommu_register(unsigned long dev_id,
{
struct pkvm_iommu *dev = NULL;
struct pkvm_iommu_driver *drv;
void *mem_va = NULL;
void *dev_va, *mem_va = NULL;
int ret = 0;
drv = get_driver(drv_id);
@@ -337,11 +337,20 @@ int __pkvm_iommu_register(unsigned long dev_id,
goto out;
}
/* Create EL2 mapping for the device. */
dev_va = (void *)__pkvm_create_private_mapping(dev_pa, dev_size,
PAGE_HYP_DEVICE);
if (IS_ERR(dev_va)) {
ret = PTR_ERR(dev_va);
goto out;
}
/* Populate the new device entry. */
*dev = (struct pkvm_iommu){
.id = dev_id,
.ops = drv->ops,
.pa = dev_pa,
.va = dev_va,
.size = dev_size,
};
@@ -351,22 +360,13 @@ int __pkvm_iommu_register(unsigned long dev_id,
}
/*
* Unmap the device's MMIO range from host stage-2. If registration
* is successful, future attempts to re-map will be blocked by
* pkvm_iommu_host_stage2_adjust_range.
* Unmap the device's MMIO range from host stage-2. Future attempts to
* map will be blocked by pkvm_iommu_host_stage2_adjust_range.
*/
ret = host_stage2_unmap_dev_locked(dev_pa, dev_size);
if (ret)
goto out;
/* Create EL2 mapping for the device. Do it last as it is irreversible. */
dev->va = (void *)__pkvm_create_private_mapping(dev_pa, dev_size,
PAGE_HYP_DEVICE);
if (IS_ERR(dev->va)) {
ret = PTR_ERR(dev->va);
goto out;
}
/* Register device and prevent host from mapping the MMIO range. */
list_add_tail(&dev->list, &iommu_list);