nvme-fc: fix double-free scenarios on hw queues
authorJames Smart <jsmart2021@gmail.com>
Thu, 21 Nov 2019 17:59:37 +0000 (09:59 -0800)
committerKeith Busch <kbusch@kernel.org>
Tue, 26 Nov 2019 18:00:13 +0000 (03:00 +0900)
commitc869e494ef8b5846d9ba91f1e922c23cd444f0c1
treeaedd613bf8f6a1cfecd3ecb4185bf2ef2324c7b7
parentc80b36cd9576efa861a080b05382856173a02ae9
nvme-fc: fix double-free scenarios on hw queues

If an error occurs on one of the ios used for creating an
association, the creating routine has error paths that are
invoked by the command failure and the error paths will free
up the controller resources created to that point.

But... the io was ultimately determined by an asynchronous
completion routine that detected the error and which
unconditionally invokes the error_recovery path which calls
delete_association. Delete association deletes all outstanding
io then tears down the controller resources. So the
create_association thread can be running in parallel with
the error_recovery thread. What was seen was the LLDD received
a call to delete a queue, causing the LLDD to do a free of a
resource, then the transport called the delete queue again
causing the driver to repeat the free call. The second free
routine corrupted the allocator. The transport shouldn't be
making the duplicate call, and the delete queue is just one
of the resources being freed.

To fix, it is realized that the create_association path is
completely serialized with one command at a time. So the
failed io completion will always be seen by the create_association
path and as of the failure, there are no ios to terminate and there
is no reason to be manipulating queue freeze states, etc.
The serialized condition stays true until the controller is
transitioned to the LIVE state. Thus the fix is to change the
error recovery path to check the controller state and only
invoke the teardown path if not already in the CONNECTING state.

Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Ewan D. Milne <emilne@redhat.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/host/fc.c