From 9ed616129ec6fa2a3011d324b2eb19f91cfb8547 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 16 Jan 2018 14:08:57 +0800 Subject: [PATCH] block/nvme: Implement .bdrv_(un)register_buf Forward these two calls to the IOVA manager. Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Message-Id: <20180116060901.17413-6-famz@redhat.com> Signed-off-by: Fam Zheng --- block/nvme.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/block/nvme.c b/block/nvme.c index 0bae185b88..a487b4d381 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1147,6 +1147,27 @@ static void nvme_aio_unplug(BlockDriverState *bs) } } +static void nvme_register_buf(BlockDriverState *bs, void *host, size_t size) +{ + int ret; + BDRVNVMeState *s = bs->opaque; + + ret = qemu_vfio_dma_map(s->vfio, host, size, false, NULL); + if (ret) { + /* FIXME: we may run out of IOVA addresses after repeated + * bdrv_register_buf/bdrv_unregister_buf, because nvme_vfio_dma_unmap + * doesn't reclaim addresses for fixed mappings. */ + error_report("nvme_register_buf failed: %s", strerror(-ret)); + } +} + +static void nvme_unregister_buf(BlockDriverState *bs, void *host) +{ + BDRVNVMeState *s = bs->opaque; + + qemu_vfio_dma_unmap(s->vfio, host); +} + static BlockDriver bdrv_nvme = { .format_name = "nvme", .protocol_name = "nvme", @@ -1172,6 +1193,9 @@ static BlockDriver bdrv_nvme = { .bdrv_io_plug = nvme_aio_plug, .bdrv_io_unplug = nvme_aio_unplug, + + .bdrv_register_buf = nvme_register_buf, + .bdrv_unregister_buf = nvme_unregister_buf, }; static void bdrv_nvme_init(void)