s390x/pci: Honor DMA limits set by vfio

When an s390 guest is using lazy unmapping, it can result in a very
large number of oustanding DMA requests, far beyond the default
limit configured for vfio.  Let's track DMA usage similar to vfio
in the host, and trigger the guest to flush their DMA mappings
before vfio runs out.

Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
[aw: non-Linux build fixes]
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
Matthew Rosato 2020-10-26 11:34:35 -04:00 committed by Alex Williamson
parent cd7498d07f
commit 37fa32de70
6 changed files with 117 additions and 12 deletions

View file

@ -12,7 +12,9 @@
#include <sys/ioctl.h>
#include "qemu/osdep.h"
#include "hw/s390x/s390-pci-bus.h"
#include "hw/s390x/s390-pci-vfio.h"
#include "hw/vfio/pci.h"
#include "hw/vfio/vfio-common.h"
/*
@ -52,3 +54,43 @@ retry:
return vfio_get_info_dma_avail(info, avail);
}
S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
S390PCIBusDevice *pbdev)
{
S390PCIDMACount *cnt;
uint32_t avail;
VFIOPCIDevice *vpdev = container_of(pbdev->pdev, VFIOPCIDevice, pdev);
int id;
assert(vpdev);
id = vpdev->vbasedev.group->container->fd;
if (!s390_pci_update_dma_avail(id, &avail)) {
return NULL;
}
QTAILQ_FOREACH(cnt, &s->zpci_dma_limit, link) {
if (cnt->id == id) {
cnt->users++;
return cnt;
}
}
cnt = g_new0(S390PCIDMACount, 1);
cnt->id = id;
cnt->users = 1;
cnt->avail = avail;
QTAILQ_INSERT_TAIL(&s->zpci_dma_limit, cnt, link);
return cnt;
}
void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt)
{
assert(cnt);
cnt->users--;
if (cnt->users == 0) {
QTAILQ_REMOVE(&s->zpci_dma_limit, cnt, link);
}
}