linux-stable/drivers/vfio
Steve Sistare 98bd3240f1 vfio/type1: restore locked_vm
commit 90fdd158a6 upstream.

When a vfio container is preserved across exec or fork-exec, the new
task's mm has a locked_vm count of 0.  After a dma vaddr is updated using
VFIO_DMA_MAP_FLAG_VADDR, locked_vm remains 0, and the pinned memory does
not count against the task's RLIMIT_MEMLOCK.

To restore the correct locked_vm count, when VFIO_DMA_MAP_FLAG_VADDR is
used and the dma's mm has changed, add the dma's locked_vm count to
the new mm->locked_vm, subject to the rlimit, and subtract it from the
old mm->locked_vm.

Fixes: c3cbab24db ("vfio/type1: implement interfaces to update vaddr")
Cc: stable@vger.kernel.org
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/1675184289-267876-5-git-send-email-steven.sistare@oracle.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-10 09:29:56 +01:00
..
fsl-mc VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
mdev vfio/mdev: add mdev available instance checking to the core 2022-10-04 12:06:58 -06:00
pci VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
platform VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
Kconfig VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
Makefile VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
container.c vfio: Refactor dma APIs for emulated devices 2022-12-05 08:56:01 -04:00
group.c vfio: Fix NULL pointer dereference caused by uninitialized group->iommufd 2023-03-10 09:29:49 +01:00
iommufd.c vfio-iommufd: Support iommufd for emulated VFIO devices 2022-12-02 11:52:03 -04:00
iova_bitmap.c vfio/iova_bitmap: refactor iova_bitmap_set() to better handle page boundaries 2022-12-02 10:09:25 -07:00
vfio.h VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
vfio_iommu_spapr_tce.c vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c 2022-12-05 12:04:32 -07:00
vfio_iommu_type1.c vfio/type1: restore locked_vm 2023-03-10 09:29:56 +01:00
vfio_main.c VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
virqfd.c vfio: Fold vfio_virqfd.ko into vfio.ko 2022-12-05 12:04:32 -07:00