In preparation for allowing for additional table levels, add the necessary information to the zdev and s390 domain to track table type. For now, these values will always be set to signify a region third table which is what s390-iommu always uses today. Signed-off-by: Matthew Rosato <mjrosato@xxxxxxxxxxxxx> --- arch/s390/include/asm/pci.h | 2 ++ drivers/iommu/s390-iommu.c | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h index 474e1f8d1d3c..8f8ebaeec60a 100644 --- a/arch/s390/include/asm/pci.h +++ b/arch/s390/include/asm/pci.h @@ -189,6 +189,8 @@ struct zpci_dev { struct kvm_zdev *kzdev; struct mutex kzdev_lock; spinlock_t dom_lock; /* protect s390_domain change */ + u64 max_table_size; + u8 origin_type; }; static inline bool zdev_enabled(struct zpci_dev *zdev) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index fbdeded3d48b..f6c27b6ab4c6 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -31,6 +31,7 @@ struct s390_domain { unsigned long *dma_table; spinlock_t list_lock; struct rcu_head rcu; + u8 origin_type; }; static struct iommu_domain blocking_domain; @@ -331,6 +332,7 @@ static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap) static struct iommu_domain *s390_domain_alloc_paging(struct device *dev) { + struct zpci_dev *zdev = to_zpci_dev(dev); struct s390_domain *s390_domain; s390_domain = kzalloc(sizeof(*s390_domain), GFP_KERNEL); @@ -344,7 +346,8 @@ static struct iommu_domain *s390_domain_alloc_paging(struct device *dev) } s390_domain->domain.geometry.force_aperture = true; s390_domain->domain.geometry.aperture_start = 0; - s390_domain->domain.geometry.aperture_end = ZPCI_TABLE_SIZE_RT - 1; + s390_domain->domain.geometry.aperture_end = zdev->max_table_size; + s390_domain->origin_type = zdev->origin_type; spin_lock_init(&s390_domain->list_lock); INIT_LIST_HEAD_RCU(&s390_domain->devices); @@ -450,9 +453,9 @@ static void s390_iommu_get_resv_regions(struct device *dev, list_add_tail(®ion->list, list); } - if (zdev->end_dma < ZPCI_TABLE_SIZE_RT - 1) { + if (zdev->end_dma < zdev->max_table_size) { region = iommu_alloc_resv_region(zdev->end_dma + 1, - ZPCI_TABLE_SIZE_RT - zdev->end_dma - 1, + zdev->max_table_size - zdev->end_dma, 0, IOMMU_RESV_RESERVED, GFP_KERNEL); if (!region) return; @@ -470,11 +473,11 @@ static struct iommu_device *s390_iommu_probe_device(struct device *dev) zdev = to_zpci_dev(dev); if (zdev->start_dma > zdev->end_dma || - zdev->start_dma > ZPCI_TABLE_SIZE_RT - 1) + zdev->start_dma > zdev->max_table_size) return ERR_PTR(-EINVAL); - if (zdev->end_dma > ZPCI_TABLE_SIZE_RT - 1) - zdev->end_dma = ZPCI_TABLE_SIZE_RT - 1; + if (zdev->end_dma > zdev->max_table_size) + zdev->end_dma = zdev->max_table_size; if (zdev->tlb_refresh) dev->iommu->shadow_on_flush = 1; @@ -732,6 +735,8 @@ int zpci_init_iommu(struct zpci_dev *zdev) ZPCI_TABLE_SIZE_RT - zdev->start_dma, zdev->end_dma - zdev->start_dma + 1); zdev->end_dma = zdev->start_dma + aperture_size - 1; + zdev->origin_type = ZPCI_TABLE_TYPE_RTX; + zdev->max_table_size = ZPCI_TABLE_SIZE_RT - 1; return 0; -- 2.47.0