Skip to content

Commit a5f1005

Browse files
Sebastian OttMartin Schwidefsky
authored andcommitted
s390/pci: handle insufficient resources during dma tlb flush
In a virtualized setup lazy flushing can lead to the hypervisor running out of resources when lots of guest pages need to be pinned. In this situation simply trigger a global flush to give the hypervisor a chance to free some of these resources. Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com> Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> Reviewed-by: Pierre Morel <pmorel@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent d39a01e commit a5f1005

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎arch/s390/pci/pci_dma.c‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ static int __dma_update_trans(struct zpci_dev *zdev, unsigned long pa,
181181
static int __dma_purge_tlb(struct zpci_dev *zdev, dma_addr_t dma_addr,
182182
size_t size, int flags)
183183
{
184+
unsigned long irqflags;
185+
int ret;
186+
184187
/*
185188
* With zdev->tlb_refresh == 0, rpcit is not required to establish new
186189
* translations when previously invalid translation-table entries are
@@ -196,8 +199,22 @@ static int __dma_purge_tlb(struct zpci_dev *zdev, dma_addr_t dma_addr,
196199
return 0;
197200
}
198201

199-
return zpci_refresh_trans((u64) zdev->fh << 32, dma_addr,
200-
PAGE_ALIGN(size));
202+
ret = zpci_refresh_trans((u64) zdev->fh << 32, dma_addr,
203+
PAGE_ALIGN(size));
204+
if (ret == -ENOMEM && !s390_iommu_strict) {
205+
/* enable the hypervisor to free some resources */
206+
if (zpci_refresh_global(zdev))
207+
goto out;
208+
209+
spin_lock_irqsave(&zdev->iommu_bitmap_lock, irqflags);
210+
bitmap_andnot(zdev->iommu_bitmap, zdev->iommu_bitmap,
211+
zdev->lazy_bitmap, zdev->iommu_pages);
212+
bitmap_zero(zdev->lazy_bitmap, zdev->iommu_pages);
213+
spin_unlock_irqrestore(&zdev->iommu_bitmap_lock, irqflags);
214+
ret = 0;
215+
}
216+
out:
217+
return ret;
201218
}
202219

203220
static int dma_update_trans(struct zpci_dev *zdev, unsigned long pa,

‎arch/s390/pci/pci_insn.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
8989
if (cc)
9090
zpci_err_insn(cc, status, addr, range);
9191

92+
if (cc == 1 && (status == 4 || status == 16))
93+
return -ENOMEM;
94+
9295
return (cc) ? -EIO : 0;
9396
}
9497

0 commit comments

Comments
 (0)