Skip to content

Commit c228f5a

Browse files
niklas88joergroedel
authored andcommitted
iommu/s390: Add I/O TLB ops
Currently s390-iommu does an I/O TLB flush (RPCIT) for every update of the I/O translation table explicitly. For one this is wasteful since RPCIT can be skipped after a mapping operation if zdev->tlb_refresh is unset. Moreover we can do a single RPCIT for a range of pages including whne doing lazy unmapping. Thankfully both of these optimizations can be achieved by implementing the IOMMU operations common code provides for the different types of I/O tlb flushes: * flush_iotlb_all: Flushes the I/O TLB for the entire IOVA space * iotlb_sync: Flushes the I/O TLB for a range of pages that can be gathered up, for example to implement lazy unmapping. * iotlb_sync_map: Flushes the I/O TLB after a mapping operation Signed-off-by: Niklas Schnelle <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 59bbf59 commit c228f5a

File tree

1 file changed

+56
-11
lines changed

1 file changed

+56
-11
lines changed

drivers/iommu/s390-iommu.c

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,63 @@ static void s390_iommu_release_device(struct device *dev)
199199
__s390_iommu_detach_device(zdev);
200200
}
201201

202+
static void s390_iommu_flush_iotlb_all(struct iommu_domain *domain)
203+
{
204+
struct s390_domain *s390_domain = to_s390_domain(domain);
205+
struct zpci_dev *zdev;
206+
unsigned long flags;
207+
208+
spin_lock_irqsave(&s390_domain->list_lock, flags);
209+
list_for_each_entry(zdev, &s390_domain->devices, iommu_list) {
210+
zpci_refresh_trans((u64)zdev->fh << 32, zdev->start_dma,
211+
zdev->end_dma - zdev->start_dma + 1);
212+
}
213+
spin_unlock_irqrestore(&s390_domain->list_lock, flags);
214+
}
215+
216+
static void s390_iommu_iotlb_sync(struct iommu_domain *domain,
217+
struct iommu_iotlb_gather *gather)
218+
{
219+
struct s390_domain *s390_domain = to_s390_domain(domain);
220+
size_t size = gather->end - gather->start + 1;
221+
struct zpci_dev *zdev;
222+
unsigned long flags;
223+
224+
/* If gather was never added to there is nothing to flush */
225+
if (!gather->end)
226+
return;
227+
228+
spin_lock_irqsave(&s390_domain->list_lock, flags);
229+
list_for_each_entry(zdev, &s390_domain->devices, iommu_list) {
230+
zpci_refresh_trans((u64)zdev->fh << 32, gather->start,
231+
size);
232+
}
233+
spin_unlock_irqrestore(&s390_domain->list_lock, flags);
234+
}
235+
236+
static void s390_iommu_iotlb_sync_map(struct iommu_domain *domain,
237+
unsigned long iova, size_t size)
238+
{
239+
struct s390_domain *s390_domain = to_s390_domain(domain);
240+
struct zpci_dev *zdev;
241+
unsigned long flags;
242+
243+
spin_lock_irqsave(&s390_domain->list_lock, flags);
244+
list_for_each_entry(zdev, &s390_domain->devices, iommu_list) {
245+
if (!zdev->tlb_refresh)
246+
continue;
247+
zpci_refresh_trans((u64)zdev->fh << 32,
248+
iova, size);
249+
}
250+
spin_unlock_irqrestore(&s390_domain->list_lock, flags);
251+
}
252+
202253
static int s390_iommu_update_trans(struct s390_domain *s390_domain,
203254
phys_addr_t pa, dma_addr_t dma_addr,
204255
unsigned long nr_pages, int flags)
205256
{
206257
phys_addr_t page_addr = pa & PAGE_MASK;
207-
dma_addr_t start_dma_addr = dma_addr;
208258
unsigned long irq_flags, i;
209-
struct zpci_dev *zdev;
210259
unsigned long *entry;
211260
int rc = 0;
212261

@@ -225,15 +274,6 @@ static int s390_iommu_update_trans(struct s390_domain *s390_domain,
225274
dma_addr += PAGE_SIZE;
226275
}
227276

228-
spin_lock(&s390_domain->list_lock);
229-
list_for_each_entry(zdev, &s390_domain->devices, iommu_list) {
230-
rc = zpci_refresh_trans((u64)zdev->fh << 32,
231-
start_dma_addr, nr_pages * PAGE_SIZE);
232-
if (rc)
233-
break;
234-
}
235-
spin_unlock(&s390_domain->list_lock);
236-
237277
undo_cpu_trans:
238278
if (rc && ((flags & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_VALID)) {
239279
flags = ZPCI_PTE_INVALID;
@@ -340,6 +380,8 @@ static size_t s390_iommu_unmap_pages(struct iommu_domain *domain,
340380
if (rc)
341381
return 0;
342382

383+
iommu_iotlb_gather_add_range(gather, iova, size);
384+
343385
return size;
344386
}
345387

@@ -384,6 +426,9 @@ static const struct iommu_ops s390_iommu_ops = {
384426
.detach_dev = s390_iommu_detach_device,
385427
.map_pages = s390_iommu_map_pages,
386428
.unmap_pages = s390_iommu_unmap_pages,
429+
.flush_iotlb_all = s390_iommu_flush_iotlb_all,
430+
.iotlb_sync = s390_iommu_iotlb_sync,
431+
.iotlb_sync_map = s390_iommu_iotlb_sync_map,
387432
.iova_to_phys = s390_iommu_iova_to_phys,
388433
.free = s390_domain_free,
389434
}

0 commit comments

Comments
 (0)