IB/uverbs: Fix device cleanup
authorYishai Hadas <yishaih@mellanox.com>
Tue, 1 Aug 2017 06:41:36 +0000 (09:41 +0300)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 11 Nov 2017 13:34:29 +0000 (13:34 +0000)
commit25f8872127547bc3162ab5914f289c2675f83f0c
tree879321e201436c01d2e6dc5d1d9f713caa481005
parent68c76de3c2355927f22cd96f59a00fc7906d8777
IB/uverbs: Fix device cleanup

commit efdd6f53b10aead0f5cf19a93dd3eb268ac0d991 upstream.

Uverbs device should be cleaned up only when there is no
potential usage of.

As part of ib_uverbs_remove_one which might be triggered upon reset flow
the device reference count is decreased as expected and leave the final
cleanup to the FDs that were opened.

Current code increases reference count upon opening a new command FD and
decreases it upon closing the file. The event FD is opened internally
and rely on the command FD by taking on it a reference count.

In case that the command FD was closed and just later the event FD we
may ensure that the device resources as of srcu are still alive as they
are still in use.

Fixing the above by moving the reference count decreasing to the place
where the command FD is really freed instead of doing that when it was
just closed.

fixes: 036b10635739 ("IB/uverbs: Enable device removal when there are active user space applications")
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Reviewed-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Tested-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/infiniband/core/uverbs_main.c