From db73e999e9bcb0cd5241e8843f20bb90b6a1c510 Mon Sep 17 00:00:00 2001 From: Thanos Makatos Date: Wed, 23 Feb 2022 09:49:03 +0000 Subject: [PATCH] nvmf/vfio-user: migration: don't ignore unsupported ranges The read_data, write_data, and data_written migration callbacks assume that the migration data are accessed in one go. Until this is fixed, with this patch we ensure we don't ignore unsupported ranges. Change-Id: I640415858b8c374ffc9e487cd20f5130e0be9305 Signed-off-by: Thanos Makatos Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11717 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker --- lib/nvmf/vfio_user.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index 1754f7998..af3fd54a7 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -3802,33 +3802,42 @@ vfio_user_migration_prepare_data(vfu_ctx_t *vfu_ctx, uint64_t *offset, uint64_t } static ssize_t -vfio_user_migration_read_data(vfu_ctx_t *vfu_ctx, void *buf, uint64_t count, uint64_t offset) +vfio_user_migration_read_data(vfu_ctx_t *vfu_ctx __attribute__((unused)), + void *buf __attribute__((unused)), + uint64_t count __attribute__((unused)), + uint64_t offset __attribute__((unused))) { - struct nvmf_vfio_user_endpoint *endpoint = vfu_get_private(vfu_ctx); - struct nvmf_vfio_user_ctrlr *ctrlr = endpoint->ctrlr; - struct vfio_user_migration_region *migr_reg = &ctrlr->migr_reg; - - memcpy(buf, endpoint->migr_data, count); - migr_reg->pending_bytes = 0; - - return 0; + SPDK_DEBUGLOG(nvmf_vfio, "%s: migration read data not supported\n", + endpoint_id(vfu_get_private(vfu_ctx))); + errno = ENOTSUP; + return -1; } static ssize_t -vfio_user_migration_write_data(vfu_ctx_t *vfu_ctx, void *buf, uint64_t count, uint64_t offset) +vfio_user_migration_write_data(vfu_ctx_t *vfu_ctx __attribute__((unused)), + void *buf __attribute__((unused)), + uint64_t count __attribute__((unused)), + uint64_t offset __attribute__((unused))) { - struct nvmf_vfio_user_endpoint *endpoint = vfu_get_private(vfu_ctx); - - memcpy(endpoint->migr_data, buf, count); - - return 0; + SPDK_DEBUGLOG(nvmf_vfio, "%s: migration write data not supported\n", + endpoint_id(vfu_get_private(vfu_ctx))); + errno = ENOTSUP; + return -1; } static int -vfio_user_migration_data_written(vfu_ctx_t *vfu_ctx, uint64_t count) +vfio_user_migration_data_written(vfu_ctx_t *vfu_ctx __attribute__((unused)), + uint64_t count) { SPDK_DEBUGLOG(nvmf_vfio, "write 0x%"PRIx64"\n", (uint64_t)count); + if (count != vfio_user_migr_data_len()) { + SPDK_DEBUGLOG(nvmf_vfio, "%s bad count %#lx\n", + endpoint_id(vfu_get_private(vfu_ctx)), count); + errno = EINVAL; + return -1; + } + return 0; }