]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
vfio/type1: restore locked_vm
authorSteve Sistare <steven.sistare@oracle.com>
Tue, 31 Jan 2023 16:58:06 +0000 (08:58 -0800)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 9 Feb 2023 18:39:14 +0000 (11:39 -0700)
commit90fdd158a695d70403163f9a0e4efc5b20f3fd3e
treecfe5b2d217348c33f9d12502cb3dba052c00839c
parent18e292705ba21cc9b3227b9ad5b1c28973605ee5
vfio/type1: restore locked_vm

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: c3cbab24db38 ("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>
drivers/vfio/vfio_iommu_type1.c