]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commit
vfio/spapr: Reference mm in tce_container
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Wed, 30 Nov 2016 06:52:04 +0000 (17:52 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 2 Dec 2016 03:38:33 +0000 (14:38 +1100)
commitbc82d122ae4a0e9f971f13403995898fcfa0c09e
treef95d3369a1b62cb2324e4ad6d5234c8d0b1322e3
parentd9c728949ddc9de5734bf3b12ea906ca8a77f2a0
vfio/spapr: Reference mm in tce_container

In some situations the userspace memory context may live longer than
the userspace process itself so if we need to do proper memory context
cleanup, we better have tce_container take a reference to mm_struct and
use it later when the process is gone (@current or @current->mm is NULL).

This references mm and stores the pointer in the container; this is done
in a new helper - tce_iommu_mm_set() - when one of the following happens:
- a container is enabled (IOMMU v1);
- a first attempt to pre-register memory is made (IOMMU v2);
- a DMA window is created (IOMMU v2).
The @mm stays referenced till the container is destroyed.

This replaces current->mm with container->mm everywhere except debug
prints.

This adds a check that current->mm is the same as the one stored in
the container to prevent userspace from making changes to a memory
context of other processes.

DMA map/unmap ioctls() do not check for @mm as they already check
for @enabled which is set after tce_iommu_mm_set() is called.

This does not reference a task as multiple threads within the same mm
are allowed to ioctl() to vfio and supposedly they will have same limits
and capabilities and if they do not, we'll just fail with no harm made.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Acked-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
drivers/vfio/vfio_iommu_spapr_tce.c