powerpc/powernv/npu: Add lock to prevent race in concurrent context init/destroy
authorAlistair Popple <alistair@popple.id.au>
Wed, 11 Apr 2018 06:38:54 +0000 (16:38 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 23 Apr 2018 23:46:56 +0000 (09:46 +1000)
commit28a5933e8d362766462ea9e5f135e19f41e658ba
tree60f2fc855fef3941a2ca52dd5968d971fd4ada80
parent7fd6641de28fe9b5bce0c38d2adee0a72a72619e
powerpc/powernv/npu: Add lock to prevent race in concurrent context init/destroy

The pnv_npu2_init_context() and pnv_npu2_destroy_context() functions
are used to allocate/free contexts to allow address translation and
shootdown by the NPU on a particular GPU. Context initialisation is
implicitly safe as it is protected by the requirement mmap_sem be held
in write mode, however pnv_npu2_destroy_context() does not require
mmap_sem to be held and it is not safe to call with a concurrent
initialisation for a different GPU.

It was assumed the driver would ensure destruction was not called
concurrently with initialisation. However the driver may be simplified
by allowing concurrent initialisation and destruction for different
GPUs. As npu context creation/destruction is not a performance
critical path and the critical section is not large a single spinlock
is used for simplicity.

Fixes: 1ab66d1fbada ("powerpc/powernv: Introduce address translation services for Nvlink2")
Cc: stable@vger.kernel.org # v4.12+
Signed-off-by: Alistair Popple <alistair@popple.id.au>
Reviewed-by: Mark Hairgrove <mhairgrove@nvidia.com>
Tested-by: Mark Hairgrove <mhairgrove@nvidia.com>
Reviewed-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/platforms/powernv/npu-dma.c