android_kernel_xiaomi_sm8350/arch/s390
Niklas Schnelle 664aad86e5 s390/pci: fix iommu bitmap allocation
commit c1ae1c59c8c6e0b66a718308c623e0cb394dab6b 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:53:24 +02:00
..
appldata
boot s390/ipl: add missing intersection check to ipl_report handling 2023-03-22 13:28:09 +01:00
configs
crypto
hypfs
include s390/debug: add _ASM_S390_ prefix to header guard 2023-02-06 07:52:41 +01:00
kernel s390/ipl: add missing secure/has_secure file to ipl type 'unknown' 2023-09-23 10:59:56 +02:00
kvm KVM: s390: fix sthyi error handling 2023-08-11 11:53:55 +02:00
lib s390/uaccess: add missing earlyclobber annotations to __clear_user() 2023-04-05 11:16:46 +02:00
mm
net
numa
oprofile
pci s390/pci: fix iommu bitmap allocation 2023-10-25 11:53:24 +02:00
purgatory
scripts
tools
Kbuild
Kconfig
Kconfig.debug
Makefile