linux-stable/arch/s390/pci
Niklas Schnelle c1ae1c59c8 s390/pci: fix iommu bitmap allocation
Since the fixed commits both zdev->iommu_bitmap and zdev->lazy_bitmap
are allocated as vzalloc(zdev->iommu_pages / 8). The problem is that
zdev->iommu_bitmap is a pointer to unsigned long but the above only
yields an allocation that is a multiple of sizeof(unsigned long) which
is 8 on s390x if the number of IOMMU pages is a multiple of 64.
This in turn is the case only if the effective IOMMU aperture is
a multiple of 64 * 4K = 256K. This is usually the case and so didn't
cause visible issues since both the virt_to_phys(high_memory) reduced
limit and hardware limits use nice numbers.

Under KVM, and in particular with QEMU limiting the IOMMU aperture to
the vfio DMA limit (default 65535), it is possible for the reported
aperture not to be a multiple of 256K however. In this case we end up
with an iommu_bitmap whose allocation is not a multiple of
8 causing bitmap operations to access it out of bounds.

Sadly we can't just fix this in the obvious way and use bitmap_zalloc()
because for large RAM systems (tested on 8 TiB) the zdev->iommu_bitmap
grows too large for kmalloc(). So add our own bitmap_vzalloc() wrapper.
This might be a candidate for common code, but this area of code will
be replaced by the upcoming conversion to use the common code DMA API on
s390 so just add a local routine.

Fixes: 2245932155 ("s390/pci: use virtual memory for iommu bitmap")
Fixes: 13954fd691 ("s390/pci_dma: improve lazy flush for unmap")
Cc: stable@vger.kernel.org
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2023-10-19 16:35:41 +02:00
..
Makefile KVM: s390: pci: Hook to access KVM lowlevel from VFIO 2022-08-29 13:29:28 +02:00
pci.c s390: mm: convert to GENERIC_IOREMAP 2023-08-18 10:12:34 -07:00
pci_bus.c Merge branch 'uaccess-inline-asm-cleanup' into features 2023-04-04 18:29:28 +02:00
pci_bus.h PCI: s390: Fix use-after-free of PCI resources with per-function hotplug 2023-03-13 09:15:11 +01:00
pci_clp.c s390/pci: use builtin_misc_device macro to simplify the code 2023-08-23 14:37:42 +02:00
pci_debug.c s390/pci: make better use of zpci_dbg() levels 2022-04-25 13:54:15 +02:00
pci_dma.c s390/pci: fix iommu bitmap allocation 2023-10-19 16:35:41 +02:00
pci_event.c s390/pci: don't log availability events as errors 2022-04-25 13:54:15 +02:00
pci_insn.c KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding 2022-07-11 09:54:32 +02:00
pci_iov.c s390/pci: add missing pci_iov.h include 2020-09-16 14:08:47 +02:00
pci_iov.h s390/pci: consolidate SR-IOV specific code 2020-09-14 11:38:34 +02:00
pci_irq.c s390: fix various typos 2023-07-03 11:19:42 +02:00
pci_kvm_hook.c KVM: s390: pci: Hook to access KVM lowlevel from VFIO 2022-08-29 13:29:28 +02:00
pci_mmio.c s390/pci: add missing EX_TABLE entries to __pcistg_mio_inuser()/__pcilg_mio_inuser() 2022-10-26 14:47:31 +02:00
pci_sysfs.c s390/pci: tolerate inconsistent handle in recover 2021-10-04 09:49:36 +02:00