From 832a58028ca08b08536bb0821bb4d72e56651fe7 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Tue, 15 Mar 2022 11:35:01 +0000 Subject: [PATCH] ANDROID: KVM: arm64: iommu: Run validate() on struct pkvm_iommu In preparation for needing to validate more aspects of a device that is about to be registered, change the callback to accept the to-be-added 'struct pkvm_iommu' rather than individual inputs. Bug: 190463801 Change-Id: I74663af26a06624a7f084b067de97f28baa6f262 Signed-off-by: David Brazdil (cherry picked from commit be84f2c770810494ef178cdb73e22b05f2dfc2b6) Signed-off-by: Mostafa Saleh Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/iommu.h | 7 ++++--- arch/arm64/kvm/hyp/nvhe/iommu.c | 12 ++++++------ arch/arm64/kvm/hyp/nvhe/iommu/s2mpu.c | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/iommu.h b/arch/arm64/kvm/hyp/include/nvhe/iommu.h index 2367fe153ad3..70d9c9e67991 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/iommu.h +++ b/arch/arm64/kvm/hyp/include/nvhe/iommu.h @@ -20,10 +20,11 @@ struct pkvm_iommu_ops { int (*init)(void *data, size_t size); /* - * Driver-specific validation of device registration inputs. - * This should be stateless. No locks are held at entry. + * Driver-specific validation of a device that is being registered. + * All fields of the device struct have been populated. + * Called with the host lock held. */ - int (*validate)(phys_addr_t base, size_t size); + int (*validate)(struct pkvm_iommu *dev); /* * Callback to apply a host stage-2 mapping change at driver level. diff --git a/arch/arm64/kvm/hyp/nvhe/iommu.c b/arch/arm64/kvm/hyp/nvhe/iommu.c index 367a8eef39bb..6b5bd157dd8d 100644 --- a/arch/arm64/kvm/hyp/nvhe/iommu.c +++ b/arch/arm64/kvm/hyp/nvhe/iommu.c @@ -306,12 +306,6 @@ int __pkvm_iommu_register(unsigned long dev_id, if (!is_mmio_range(dev_pa, dev_size)) return -EINVAL; - if (drv->ops->validate) { - ret = drv->ops->validate(dev_pa, dev_size); - if (ret) - return ret; - } - /* * Accept memory donation if the host is providing new memory. * Note: We do not return the memory even if there is an error later. @@ -350,6 +344,12 @@ int __pkvm_iommu_register(unsigned long dev_id, goto out; } + if (dev->ops->validate) { + ret = dev->ops->validate(dev); + if (ret) + goto out; + } + /* * Unmap the device's MMIO range from host stage-2. If registration * is successful, future attempts to re-map will be blocked by diff --git a/arch/arm64/kvm/hyp/nvhe/iommu/s2mpu.c b/arch/arm64/kvm/hyp/nvhe/iommu/s2mpu.c index 3fbd68c84218..dd9c81f15898 100644 --- a/arch/arm64/kvm/hyp/nvhe/iommu/s2mpu.c +++ b/arch/arm64/kvm/hyp/nvhe/iommu/s2mpu.c @@ -465,9 +465,9 @@ static int s2mpu_init(void *data, size_t size) return ret; } -static int s2mpu_validate(phys_addr_t pa, size_t size) +static int s2mpu_validate(struct pkvm_iommu *dev) { - if (size != S2MPU_MMIO_SIZE) + if (dev->size != S2MPU_MMIO_SIZE) return -EINVAL; return 0;