Skip to content

Commit

Permalink
iommufd: remove put_device_fd logic
Browse files Browse the repository at this point in the history
An IOAS may have several devices attached, so devfd does not belong as a
member within struct iommu_ioas. Remove it.

This member was used in put_device_fd, but the iommufd backend does not
need such cleanup. It is enough to close the device file descriptor
(which we do in vfio_pci_close).

Signed-off-by: Klaus Jensen <[email protected]>
  • Loading branch information
birkelund committed Aug 23, 2024
1 parent 3fb1ff2 commit c5e1dc4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
16 changes: 0 additions & 16 deletions src/iommu/iommufd.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct iommu_ioas {

char *name;
uint32_t id;
int devfd;
};

static struct iommu_ioas iommufd_default_ioas = {
Expand Down Expand Up @@ -149,7 +148,6 @@ static int iommufd_get_device_fd(struct iommu_ctx *ctx, const char *bdf)
goto close_dev;
}

ioas->devfd = devfd;
return devfd;

close_dev:
Expand All @@ -159,19 +157,6 @@ static int iommufd_get_device_fd(struct iommu_ctx *ctx, const char *bdf)
return -1;
}

static int iommufd_put_device_fd(struct iommu_ctx *ctx, const char *bdf UNUSED)
{
struct iommu_ioas *ioas = container_of_var(ctx, ioas, ctx);

if (ioas->devfd) {
close(ioas->devfd);
return 0;
}

errno = ENODEV;
return -1;
}

static int iommu_ioas_do_dma_map(struct iommu_ctx *ctx, void *vaddr, size_t len, uint64_t *iova,
unsigned long flags)
{
Expand Down Expand Up @@ -250,7 +235,6 @@ static int iommu_ioas_do_dma_unmap_all(struct iommu_ctx *ctx)

static const struct iommu_ctx_ops iommufd_ops = {
.get_device_fd = iommufd_get_device_fd,
.put_device_fd = iommufd_put_device_fd,

.dma_map = iommu_ioas_do_dma_map,
.dma_unmap = iommu_ioas_do_dma_unmap,
Expand Down
5 changes: 4 additions & 1 deletion src/vfio/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,8 @@ int vfio_pci_close(struct vfio_pci_device *pci)

close(pci->dev.fd);

return ctx->ops.put_device_fd(ctx, pci->bdf);
if (ctx->ops.put_device_fd)
return ctx->ops.put_device_fd(ctx, pci->bdf);

return 0;
}

0 comments on commit c5e1dc4

Please sign in to comment.