Currently, when we map the MC portal object, the device fd we get from
VFIO device setup is also recorded in the device list of its group. Once
the region is mapped we no longer need the fd, so we close it directly,
but its entry stays in the list. Since group teardown now closes every
device fd it tracks, the stale entry causes the same fd number to be
closed a second time.
Fix it by removing the device from the group instead of closing the fd
directly, which both closes the fd and drops the tracking entry.
Fixes: ba19fbe3894e ("bus/fslmc: fix some VFIO device FD and memory leaks")
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Anatoly Burakov <[email protected]>
---
drivers/bus/fslmc/fslmc_vfio.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index e8c6948bebb..5d20b92af15 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -1317,6 +1317,7 @@ static intptr_t vfio_map_mcp_obj(const char *mcp_obj)
{
intptr_t v_addr = (intptr_t)MAP_FAILED;
int32_t ret, mc_fd;
+ int vfio_group_fd;
struct vfio_group_status status = { .argsz = sizeof(status) };
struct vfio_device_info d_info = { .argsz = sizeof(d_info) };
@@ -1338,7 +1339,10 @@ static intptr_t vfio_map_mcp_obj(const char *mcp_obj)
mc_fd, reg_info.offset);
MC_FAILURE:
- close(mc_fd);
+ /* the group tracks this fd, removing the device also closes it */
+ vfio_group_fd =
fslmc_vfio_group_fd_by_name(fslmc_vfio_get_group_name());
+ if (fslmc_vfio_group_remove_dev(vfio_group_fd, mcp_obj) != 0)
+ DPAA2_BUS_ERR("Failed to remove %s from vfio", mcp_obj);
return v_addr;
}
--
2.52.0