Skip to content

Commit

Permalink
misc/log: change logging on unrecoverable errors
Browse files Browse the repository at this point in the history
Change log-statements from 'log_debug' to 'log_error', when they are in
relation to an unrecoverable error. As a rule of thumb, if the log is
immediately followed by 'return -1', then it's an error. If we can
continue but just log for helping, it's debug.

Signed-off-by: Mads Ynddal <[email protected]>
  • Loading branch information
Baekalfen committed May 22, 2024
1 parent fbdb45f commit 69de15a
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 90 deletions.
6 changes: 3 additions & 3 deletions src/iommu/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int _iommu_map_vaddr(struct iommu_ctx *ctx, void *vaddr, size_t len, uint64_t *i
if (flags & IOMMU_MAP_FIXED_IOVA) {
_iova = *iova;
} else if (ctx->ops.iova_reserve && ctx->ops.iova_reserve(ctx, len, &_iova, flags)) {
log_debug("failed to allocate iova\n");
log_error("failed to allocate iova\n");
return -1;
}

Expand Down Expand Up @@ -169,7 +169,7 @@ int iommu_unmap_vaddr(struct iommu_ctx *ctx, void *vaddr, size_t *len)
*len = m->len;

if (ctx->ops.dma_unmap(ctx, m)) {
log_debug("failed to unmap dma\n");
log_error("failed to unmap dma\n");
return -1;
}

Expand All @@ -196,7 +196,7 @@ int iommu_unmap_all(struct iommu_ctx *ctx)
{
if (ctx->ops.dma_unmap_all) {
if (ctx->ops.dma_unmap_all(ctx)) {
log_debug("failed to unmap dma\n");
log_error("failed to unmap dma\n");
return -1;
}

Expand Down
22 changes: 11 additions & 11 deletions src/iommu/iommufd.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static int iommu_ioas_update_iova_ranges(struct iommu_ioas *ioas)

if (ioctl(__iommufd, IOMMU_IOAS_IOVA_RANGES, &iova_ranges)) {
if (errno != EMSGSIZE) {
log_debug("could not get ioas iova ranges\n");
log_error("could not get ioas iova ranges\n");
return -1;
}

Expand All @@ -64,7 +64,7 @@ static int iommu_ioas_update_iova_ranges(struct iommu_ioas *ioas)
iova_ranges.allowed_iovas = (uintptr_t)ioas->ctx.iova_ranges;

if (ioctl(__iommufd, IOMMU_IOAS_IOVA_RANGES, &iova_ranges)) {
log_debug("could not get ioas iova ranges\n");
log_error("could not get ioas iova ranges\n");
return -1;
}
}
Expand Down Expand Up @@ -106,33 +106,33 @@ static int iommufd_get_device_fd(struct iommu_ctx *ctx, const char *bdf)

vfio_id = pci_get_device_vfio_id(bdf);
if (!vfio_id) {
log_debug("could not determine the vfio device id for %s\n", bdf);
log_error("could not determine the vfio device id for %s\n", bdf);
return -1;
}

if (asprintf(&path, "/dev/vfio/devices/%s", vfio_id) < 0) {
log_debug("asprintf failed\n");
log_error("asprintf failed\n");
return -1;
}

devfd = open(path, O_RDWR);
if (devfd < 0) {
log_debug("could not open the device cdev\n");
log_error("could not open the device cdev\n");
return -1;
}

if (ioctl(devfd, VFIO_DEVICE_BIND_IOMMUFD, &bind)) {
log_debug("could not bind device to iommufd\n");
log_error("could not bind device to iommufd\n");
goto close_dev;
}

if (ioctl(devfd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_data)) {
log_debug("could not associate device with ioas\n");
log_error("could not associate device with ioas\n");
goto close_dev;
}

if (iommu_ioas_update_iova_ranges(ioas)) {
log_debug("could not update iova ranges\n");
log_error("could not update iova ranges\n");
goto close_dev;
}

Expand Down Expand Up @@ -177,7 +177,7 @@ static int iommu_ioas_do_dma_map(struct iommu_ctx *ctx, struct iova_mapping *m)
}

if (ioctl(__iommufd, IOMMU_IOAS_MAP, &map)) {
log_debug("failed to map\n");
log_error("failed to map\n");
return -1;
}

Expand Down Expand Up @@ -211,7 +211,7 @@ static int iommu_ioas_do_dma_unmap(struct iommu_ctx *ctx, struct iova_mapping *m
}

if (ioctl(__iommufd, IOMMU_IOAS_UNMAP, &unmap)) {
log_debug("failed to unmap\n");
log_error("failed to unmap\n");
return -1;
}

Expand Down Expand Up @@ -243,7 +243,7 @@ static int iommu_ioas_init(struct iommu_ioas *ioas)
};

if (ioctl(__iommufd, IOMMU_IOAS_ALLOC, &alloc_data)) {
log_debug("could not allocate ioas\n");
log_error("could not allocate ioas\n");
return -1;
}

Expand Down
38 changes: 19 additions & 19 deletions src/iommu/vfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static int vfio_iommu_type1_iova_reserve(struct iommu_ctx *ctx, size_t len, uint
__autolock(&vfio->lock);

if (!ALIGNED(len, __VFN_PAGESIZE)) {
log_debug("len is not page aligned\n");
log_error("len is not page aligned\n");
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -233,21 +233,21 @@ static int vfio_iommu_type1_init(struct vfio_container *vfio)
return 0;

if (ioctl(vfio->fd, VFIO_SET_IOMMU, VFIO_TYPE1_IOMMU)) {
log_debug("failed to set vfio iommu type\n");
log_error("failed to set vfio iommu type\n");
return -1;
}

vfio->iommu_set = true;

#ifdef VFIO_IOMMU_INFO_CAPS
if (vfio_iommu_type1_get_capabilities(vfio)) {
log_debug("failed to get iommu capabilities\n");
log_error("failed to get iommu capabilities\n");
return -1;
}
#endif

if (vfio_iommu_type1_iova_reserve(&vfio->ctx, VFIO_IOMMU_TYPE1_IOVA_RESERVED, &iova, 0x0)) {
log_debug("could not reserve iova range\n");
log_error("could not reserve iova range\n");
return -1;
}

Expand All @@ -271,12 +271,12 @@ static int vfio_group_set_container(struct vfio_group *group, struct vfio_contai
log_info("adding group '%s' to container\n", group->path);

if (ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &vfio->fd)) {
log_debug("failed to add group to vfio container\n");
log_error("failed to add group to vfio container\n");
return -1;
}

if (vfio_iommu_type1_init(vfio)) {
log_debug("failed to configure iommu\n");
log_error("failed to configure iommu\n");

log_fatal_if(ioctl(group->fd, VFIO_GROUP_UNSET_CONTAINER), "unset container\n");

Expand All @@ -296,18 +296,18 @@ static int vfio_group_open(const char *path)

fd = open(path, O_RDWR);
if (fd < 0) {
log_debug("failed to open vfio group file: %s\n", strerror(errno));
log_error("failed to open vfio group file: %s\n", strerror(errno));
return -1;
}

if (ioctl(fd, VFIO_GROUP_GET_STATUS, &group_status)) {
log_debug("failed to get vfio group status\n");
log_error("failed to get vfio group status\n");
goto close_fd;
}

if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
errno = EINVAL;
log_debug("vfio group is not viable\n");
log_error("vfio group is not viable\n");
goto close_fd;
}

Expand Down Expand Up @@ -349,7 +349,7 @@ static int vfio_get_group_fd(struct vfio_container *vfio, const char *path)

group->fd = vfio_group_open(group->path);
if (group->fd < 0) {
log_debug("failed to open vfio group\n");
log_error("failed to open vfio group\n");
goto free_group_path;
}

Expand All @@ -375,7 +375,7 @@ static int vfio_get_device_fd(struct iommu_ctx *ctx, const char *bdf)

group = pci_get_iommu_group(bdf);
if (!group) {
log_debug("could not determine iommu group for device %s\n", bdf);
log_error("could not determine iommu group for device %s\n", bdf);
errno = EINVAL;
return -1;
}
Expand All @@ -387,7 +387,7 @@ static int vfio_get_device_fd(struct iommu_ctx *ctx, const char *bdf)

ret_fd = ioctl(gfd, VFIO_GROUP_GET_DEVICE_FD, bdf);
if (ret_fd < 0) {
log_debug("failed to get device fd\n");
log_error("failed to get device fd\n");
return -1;
}

Expand Down Expand Up @@ -417,13 +417,13 @@ static int vfio_iommu_type1_do_dma_map(struct iommu_ctx *ctx, struct iova_mappin
}

if (!ALIGNED(((uintptr_t)m->vaddr | m->len | m->iova), __VFN_PAGESIZE)) {
log_debug("vaddr, len or iova not page aligned\n");
log_error("vaddr, len or iova not page aligned\n");
errno = EINVAL;
return -1;
}

if (ioctl(vfio->fd, VFIO_IOMMU_MAP_DMA, &dma_map)) {
log_debug("could not map\n");
log_error("could not map\n");
return -1;
}

Expand All @@ -447,7 +447,7 @@ static int vfio_iommu_type1_do_dma_unmap(struct iommu_ctx *ctx, struct iova_mapp
}

if (ioctl(vfio->fd, VFIO_IOMMU_UNMAP_DMA, &dma_unmap)) {
log_debug("could not unmap\n");
log_error("could not unmap\n");
return -1;
}

Expand Down Expand Up @@ -485,7 +485,7 @@ static int vfio_iommu_type1_do_dma_unmap_all(struct iommu_ctx *ctx)
};

if (ioctl(vfio->fd, VFIO_IOMMU_UNMAP_DMA, &dma_unmap)) {
log_debug("failed to unmap dma\n");
log_error("failed to unmap dma\n");
return -1;
}

Expand All @@ -510,17 +510,17 @@ static int vfio_init_container(struct vfio_container *vfio)
{
vfio->fd = open("/dev/vfio/vfio", O_RDWR);
if (vfio->fd < 0) {
log_debug("failed to open vfio device\n");
log_error("failed to open vfio device\n");
return -1;
}

if (ioctl(vfio->fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION) {
log_debug("invalid vfio version\n");
log_error("invalid vfio version\n");
return -1;
}

if (!ioctl(vfio->fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) {
log_debug("vfio type 1 iommu not supported\n");
log_error("vfio type 1 iommu not supported\n");
return -1;
}

Expand Down
Loading

0 comments on commit 69de15a

Please sign in to comment.