vfio: do not needlessly setup device in secondary process
authorDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Wed, 21 Nov 2018 18:41:32 +0000 (19:41 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Sun, 25 Nov 2018 12:09:05 +0000 (13:09 +0100)
commit047e3f9f2a4a4b73da86b707af8a32039ba1cad7
treea0e519670fad7ceb9c2e8a3dad2aa2507a6e99ec
parentd3110b124af64199b0901223c7e0117f7480480f
vfio: do not needlessly setup device in secondary process

Setting up a device that wasn't setup in the primary
process will possibly break the primary process. That's
because the IPC message to retrieve the group fd in the
primary will also *open* that group if it wasn't opened
before. Even though the secondary process closes that fd
soon after as a part of its error handling path, the
primary process leaks it.

What's worse, opening that fd on the primary will
increment the process-local counter of opened groups.
If it was 0 before, then the group will never be added
to the vfio container, nor dpdk memory will be ever
mapped.

This patch moves the proper error checks earlier in the
code to fully prevent setting up devices in secondary
processes that weren't setup in the primary process.

Fixes: 2f4adfad0a69 ("vfio: add multiprocess support")

Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
drivers/bus/pci/linux/pci_vfio.c