Skip to content

Commit

Permalink
fix: migration quiesce and short write
Browse files Browse the repository at this point in the history
Signed-off-by: William Henderson <william.henderson@nutanix.com>
  • Loading branch information
w-henderson authored and jlevon committed Sep 15, 2023
1 parent 4b42857 commit 5562eb7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
17 changes: 16 additions & 1 deletion lib/libvfio-user.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,7 @@ static bool
command_needs_quiesce(vfu_ctx_t *vfu_ctx, const vfu_msg_t *msg)
{
struct vfio_user_region_access *reg;
struct vfio_user_device_feature *feature;

if (vfu_ctx->quiesce == NULL) {
return false;
Expand All @@ -1540,7 +1541,6 @@ command_needs_quiesce(vfu_ctx_t *vfu_ctx, const vfu_msg_t *msg)
/*
* bad request, it will be eventually failed by
* handle_region_access
*
*/
return false;
}
Expand All @@ -1549,8 +1549,23 @@ command_needs_quiesce(vfu_ctx_t *vfu_ctx, const vfu_msg_t *msg)
return true;
}
break;

case VFIO_USER_DEVICE_FEATURE:
if (msg->in.iov.iov_len < sizeof(*feature)) {
/*
* bad request, it will be eventually failed by
* handle_region_access
*/
return false;
}
feature = msg->in.iov.iov_base;
if (migration_feature_needs_quiesce(feature)) {
return true;
}
break;
}


return false;
}

Expand Down
14 changes: 14 additions & 0 deletions lib/migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ handle_mig_data_write(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg)
return ERROR_INT(EINVAL);
}

if (msg->in.iov.iov_len < sizeof(struct vfio_user_mig_data) + req->size) {
vfu_log(vfu_ctx, LOG_ERR, "short write (%d < %ld)",
req->argsz, sizeof(struct vfio_user_mig_data) + req->size);
return ERROR_INT(EINVAL);
}

ssize_t ret = migr->callbacks.write_data(vfu_ctx, &req->data, req->size);

if (ret < 0) {
Expand Down Expand Up @@ -434,4 +440,12 @@ migration_set_pgsize(struct migration *migr, size_t pgsize)
return 0;
}

bool
migration_feature_needs_quiesce(struct vfio_user_device_feature *feature)
{
return ((feature->flags &
(VFIO_DEVICE_FEATURE_SET | VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE)) != 0)
&& !(feature->flags & VFIO_DEVICE_FEATURE_PROBE);
}

/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
3 changes: 1 addition & 2 deletions lib/migration.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ MOCK_DECLARE(ssize_t, handle_device_state, vfu_ctx_t *vfu_ctx,
struct migration *migr, uint32_t device_state, bool notify);

bool
access_migration_needs_quiesce(const vfu_ctx_t *vfu_ctx, size_t region_index,
uint64_t offset);
migration_feature_needs_quiesce(struct vfio_user_device_feature *feature);

#endif /* LIB_VFIO_USER_MIGRATION_H */

Expand Down

0 comments on commit 5562eb7

Please sign in to comment.