]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
habanalabs: all FD must be closed before removing device
authorOded Gabbay <oded.gabbay@gmail.com>
Sat, 6 Apr 2019 10:23:54 +0000 (13:23 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 31 May 2019 13:43:37 +0000 (06:43 -0700)
commitf1d84fe4bdd8871c77a8f009480ebde21e54b02f
treefcf6a468329c2a80c0dc77c96979941fa8ad513f
parent7de03fc00debb96c758817781d867de60656c96f
habanalabs: all FD must be closed before removing device

[ Upstream commit caa3c8e52582fc4d2ed82afd5e7ea164c18ef4fe ]

This patch fixes a bug in the implementation of the function that removes
the device.

The bug can happen when the device is removed but not the driver itself
(e.g. remove by the OS due to PCI freeze in Power architecture).

In that case, there maybe open users that are calling IOCTLs while the
device is removed. This is a possible race condition that the driver must
handle. Otherwise, a kernel panic may occur.

This race is prevented in the hard-reset flow, because the driver makes
sure the users are closed before continuing with the hard-reset. This
race can not occur when the driver itself is removed because the OS makes
sure all the file descriptors are closed.

The fix is to make sure the open users close their file descriptors and if
they don't (after a certain amount of time), the driver sends them a
SIGKILL, because the remove of the device can't be stopped.

The patch re-uses the same code that is called from the hard-reset flow.

Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/misc/habanalabs/device.c