WSL2-Linux-Kernel/arch/s390
Niklas Schnelle 3ad81e6aff s390/pci: fix iommu bitmap allocation
commit c1ae1c59c8 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-10-25 11:59:03 +02:00
..
appldata s390/appldata: use struct_size() helper 2020-06-29 16:32:34 +02:00
boot s390/ipl: add missing intersection check to ipl_report handling 2023-03-22 13:31:32 +01:00
configs s390: update defconfigs 2021-09-15 14:29:21 +02:00
crypto s390/paes: fix PKEY_TYPE_EP11_AES handling for secure keyblobs 2023-09-19 12:22:31 +02:00
hypfs s390/hypfs: avoid error message under KVM 2022-09-05 10:30:11 +02:00
include s390/ap: fix status returned by ap_qact() 2023-03-10 09:39:16 +01:00
kernel s390/ipl: add missing secure/has_secure file to ipl type 'unknown' 2023-09-19 12:22:52 +02:00
kvm KVM: s390: fix sthyi error handling 2023-08-11 15:13:49 +02:00
lib s390/uaccess: add missing earlyclobber annotations to __clear_user() 2023-04-05 11:25:01 +02:00
mm KVM: s390: pv: fix index value of replaced ASCE 2023-08-03 10:22:26 +02:00
net bpf, s390: Fix potential memory leak about jit_data 2021-10-04 09:49:10 +02:00
pci s390/pci: fix iommu bitmap allocation 2023-10-25 11:59:03 +02:00
purgatory s390/purgatory: disable branch profiling 2023-06-28 10:29:52 +02:00
tools s390/disassembler: add instructions 2021-07-27 09:39:19 +02:00
Kbuild s390/numa: move code to arch/s390/kernel 2020-08-11 18:16:55 +02:00
Kconfig s390: remove unneeded 'select BUILD_BIN2C' 2022-07-07 17:53:27 +02:00
Kconfig.debug tracing: Refactor TRACE_IRQFLAGS_SUPPORT in Kconfig 2021-08-16 11:37:21 -04:00
Makefile s390/decompressor: fix misaligned symbol build error 2023-07-23 13:47:55 +02:00