1 /* 2 * vhost-vdpa 3 * 4 * Copyright(c) 2017-2018 Intel Corporation. 5 * Copyright(c) 2020 Red Hat, Inc. 6 * 7 * This work is licensed under the terms of the GNU GPL, version 2 or later. 8 * See the COPYING file in the top-level directory. 9 * 10 */ 11 12 #include "qemu/osdep.h" 13 #include <linux/vhost.h> 14 #include <linux/vfio.h> 15 #include <sys/eventfd.h> 16 #include <sys/ioctl.h> 17 #include "hw/virtio/vhost.h" 18 #include "hw/virtio/vhost-backend.h" 19 #include "hw/virtio/virtio-net.h" 20 #include "hw/virtio/vhost-shadow-virtqueue.h" 21 #include "hw/virtio/vhost-vdpa.h" 22 #include "exec/address-spaces.h" 23 #include "migration/blocker.h" 24 #include "qemu/cutils.h" 25 #include "qemu/main-loop.h" 26 #include "cpu.h" 27 #include "trace.h" 28 #include "qapi/error.h" 29 30 /* 31 * Return one past the end of the end of section. Be careful with uint64_t 32 * conversions! 33 */ 34 static Int128 vhost_vdpa_section_end(const MemoryRegionSection *section) 35 { 36 Int128 llend = int128_make64(section->offset_within_address_space); 37 llend = int128_add(llend, section->size); 38 llend = int128_and(llend, int128_exts64(TARGET_PAGE_MASK)); 39 40 return llend; 41 } 42 43 static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section, 44 uint64_t iova_min, 45 uint64_t iova_max) 46 { 47 Int128 llend; 48 49 if ((!memory_region_is_ram(section->mr) && 50 !memory_region_is_iommu(section->mr)) || 51 memory_region_is_protected(section->mr) || 52 /* vhost-vDPA doesn't allow MMIO to be mapped */ 53 memory_region_is_ram_device(section->mr)) { 54 return true; 55 } 56 57 if (section->offset_within_address_space < iova_min) { 58 error_report("RAM section out of device range (min=0x%" PRIx64 59 ", addr=0x%" HWADDR_PRIx ")", 60 iova_min, section->offset_within_address_space); 61 return true; 62 } 63 64 llend = vhost_vdpa_section_end(section); 65 if (int128_gt(llend, int128_make64(iova_max))) { 66 error_report("RAM section out of device range (max=0x%" PRIx64 67 ", end addr=0x%" PRIx64 ")", 68 iova_max, int128_get64(llend)); 69 return true; 70 } 71 72 return false; 73 } 74 75 /* 76 * The caller must set asid = 0 if the device does not support asid. 77 * This is not an ABI break since it is set to 0 by the initializer anyway. 78 */ 79 int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, 80 hwaddr size, void *vaddr, bool readonly) 81 { 82 struct vhost_msg_v2 msg = {}; 83 int fd = v->device_fd; 84 int ret = 0; 85 86 msg.type = v->msg_type; 87 msg.asid = asid; 88 msg.iotlb.iova = iova; 89 msg.iotlb.size = size; 90 msg.iotlb.uaddr = (uint64_t)(uintptr_t)vaddr; 91 msg.iotlb.perm = readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW; 92 msg.iotlb.type = VHOST_IOTLB_UPDATE; 93 94 trace_vhost_vdpa_dma_map(v, fd, msg.type, msg.asid, msg.iotlb.iova, 95 msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.perm, 96 msg.iotlb.type); 97 98 if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { 99 error_report("failed to write, fd=%d, errno=%d (%s)", 100 fd, errno, strerror(errno)); 101 return -EIO ; 102 } 103 104 return ret; 105 } 106 107 /* 108 * The caller must set asid = 0 if the device does not support asid. 109 * This is not an ABI break since it is set to 0 by the initializer anyway. 110 */ 111 int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, 112 hwaddr size) 113 { 114 struct vhost_msg_v2 msg = {}; 115 int fd = v->device_fd; 116 int ret = 0; 117 118 msg.type = v->msg_type; 119 msg.asid = asid; 120 msg.iotlb.iova = iova; 121 msg.iotlb.size = size; 122 msg.iotlb.type = VHOST_IOTLB_INVALIDATE; 123 124 trace_vhost_vdpa_dma_unmap(v, fd, msg.type, msg.asid, msg.iotlb.iova, 125 msg.iotlb.size, msg.iotlb.type); 126 127 if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { 128 error_report("failed to write, fd=%d, errno=%d (%s)", 129 fd, errno, strerror(errno)); 130 return -EIO ; 131 } 132 133 return ret; 134 } 135 136 static void vhost_vdpa_listener_begin_batch(struct vhost_vdpa *v) 137 { 138 int fd = v->device_fd; 139 struct vhost_msg_v2 msg = { 140 .type = v->msg_type, 141 .iotlb.type = VHOST_IOTLB_BATCH_BEGIN, 142 }; 143 144 trace_vhost_vdpa_listener_begin_batch(v, fd, msg.type, msg.iotlb.type); 145 if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { 146 error_report("failed to write, fd=%d, errno=%d (%s)", 147 fd, errno, strerror(errno)); 148 } 149 } 150 151 static void vhost_vdpa_iotlb_batch_begin_once(struct vhost_vdpa *v) 152 { 153 if (v->dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) && 154 !v->iotlb_batch_begin_sent) { 155 vhost_vdpa_listener_begin_batch(v); 156 } 157 158 v->iotlb_batch_begin_sent = true; 159 } 160 161 static void vhost_vdpa_listener_commit(MemoryListener *listener) 162 { 163 struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); 164 struct vhost_dev *dev = v->dev; 165 struct vhost_msg_v2 msg = {}; 166 int fd = v->device_fd; 167 168 if (!(dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) { 169 return; 170 } 171 172 if (!v->iotlb_batch_begin_sent) { 173 return; 174 } 175 176 msg.type = v->msg_type; 177 msg.iotlb.type = VHOST_IOTLB_BATCH_END; 178 179 trace_vhost_vdpa_listener_commit(v, fd, msg.type, msg.iotlb.type); 180 if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { 181 error_report("failed to write, fd=%d, errno=%d (%s)", 182 fd, errno, strerror(errno)); 183 } 184 185 v->iotlb_batch_begin_sent = false; 186 } 187 188 static void vhost_vdpa_listener_region_add(MemoryListener *listener, 189 MemoryRegionSection *section) 190 { 191 DMAMap mem_region = {}; 192 struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); 193 hwaddr iova; 194 Int128 llend, llsize; 195 void *vaddr; 196 int ret; 197 198 if (vhost_vdpa_listener_skipped_section(section, v->iova_range.first, 199 v->iova_range.last)) { 200 return; 201 } 202 203 if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK) != 204 (section->offset_within_region & ~TARGET_PAGE_MASK))) { 205 error_report("%s received unaligned region", __func__); 206 return; 207 } 208 209 iova = TARGET_PAGE_ALIGN(section->offset_within_address_space); 210 llend = vhost_vdpa_section_end(section); 211 if (int128_ge(int128_make64(iova), llend)) { 212 return; 213 } 214 215 memory_region_ref(section->mr); 216 217 /* Here we assume that memory_region_is_ram(section->mr)==true */ 218 219 vaddr = memory_region_get_ram_ptr(section->mr) + 220 section->offset_within_region + 221 (iova - section->offset_within_address_space); 222 223 trace_vhost_vdpa_listener_region_add(v, iova, int128_get64(llend), 224 vaddr, section->readonly); 225 226 llsize = int128_sub(llend, int128_make64(iova)); 227 if (v->shadow_data) { 228 int r; 229 230 mem_region.translated_addr = (hwaddr)(uintptr_t)vaddr, 231 mem_region.size = int128_get64(llsize) - 1, 232 mem_region.perm = IOMMU_ACCESS_FLAG(true, section->readonly), 233 234 r = vhost_iova_tree_map_alloc(v->iova_tree, &mem_region); 235 if (unlikely(r != IOVA_OK)) { 236 error_report("Can't allocate a mapping (%d)", r); 237 goto fail; 238 } 239 240 iova = mem_region.iova; 241 } 242 243 vhost_vdpa_iotlb_batch_begin_once(v); 244 ret = vhost_vdpa_dma_map(v, VHOST_VDPA_GUEST_PA_ASID, iova, 245 int128_get64(llsize), vaddr, section->readonly); 246 if (ret) { 247 error_report("vhost vdpa map fail!"); 248 goto fail_map; 249 } 250 251 return; 252 253 fail_map: 254 if (v->shadow_data) { 255 vhost_iova_tree_remove(v->iova_tree, mem_region); 256 } 257 258 fail: 259 /* 260 * On the initfn path, store the first error in the container so we 261 * can gracefully fail. Runtime, there's not much we can do other 262 * than throw a hardware error. 263 */ 264 error_report("vhost-vdpa: DMA mapping failed, unable to continue"); 265 return; 266 267 } 268 269 static void vhost_vdpa_listener_region_del(MemoryListener *listener, 270 MemoryRegionSection *section) 271 { 272 struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); 273 hwaddr iova; 274 Int128 llend, llsize; 275 int ret; 276 277 if (vhost_vdpa_listener_skipped_section(section, v->iova_range.first, 278 v->iova_range.last)) { 279 return; 280 } 281 282 if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK) != 283 (section->offset_within_region & ~TARGET_PAGE_MASK))) { 284 error_report("%s received unaligned region", __func__); 285 return; 286 } 287 288 iova = TARGET_PAGE_ALIGN(section->offset_within_address_space); 289 llend = vhost_vdpa_section_end(section); 290 291 trace_vhost_vdpa_listener_region_del(v, iova, int128_get64(llend)); 292 293 if (int128_ge(int128_make64(iova), llend)) { 294 return; 295 } 296 297 llsize = int128_sub(llend, int128_make64(iova)); 298 299 if (v->shadow_data) { 300 const DMAMap *result; 301 const void *vaddr = memory_region_get_ram_ptr(section->mr) + 302 section->offset_within_region + 303 (iova - section->offset_within_address_space); 304 DMAMap mem_region = { 305 .translated_addr = (hwaddr)(uintptr_t)vaddr, 306 .size = int128_get64(llsize) - 1, 307 }; 308 309 result = vhost_iova_tree_find_iova(v->iova_tree, &mem_region); 310 if (!result) { 311 /* The memory listener map wasn't mapped */ 312 return; 313 } 314 iova = result->iova; 315 vhost_iova_tree_remove(v->iova_tree, *result); 316 } 317 vhost_vdpa_iotlb_batch_begin_once(v); 318 ret = vhost_vdpa_dma_unmap(v, VHOST_VDPA_GUEST_PA_ASID, iova, 319 int128_get64(llsize)); 320 if (ret) { 321 error_report("vhost_vdpa dma unmap error!"); 322 } 323 324 memory_region_unref(section->mr); 325 } 326 /* 327 * IOTLB API is used by vhost-vdpa which requires incremental updating 328 * of the mapping. So we can not use generic vhost memory listener which 329 * depends on the addnop(). 330 */ 331 static const MemoryListener vhost_vdpa_memory_listener = { 332 .name = "vhost-vdpa", 333 .commit = vhost_vdpa_listener_commit, 334 .region_add = vhost_vdpa_listener_region_add, 335 .region_del = vhost_vdpa_listener_region_del, 336 }; 337 338 static int vhost_vdpa_call(struct vhost_dev *dev, unsigned long int request, 339 void *arg) 340 { 341 struct vhost_vdpa *v = dev->opaque; 342 int fd = v->device_fd; 343 int ret; 344 345 assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); 346 347 ret = ioctl(fd, request, arg); 348 return ret < 0 ? -errno : ret; 349 } 350 351 static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) 352 { 353 uint8_t s; 354 int ret; 355 356 trace_vhost_vdpa_add_status(dev, status); 357 ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s); 358 if (ret < 0) { 359 return ret; 360 } 361 362 s |= status; 363 364 ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s); 365 if (ret < 0) { 366 return ret; 367 } 368 369 ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s); 370 if (ret < 0) { 371 return ret; 372 } 373 374 if (!(s & status)) { 375 return -EIO; 376 } 377 378 return 0; 379 } 380 381 int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range) 382 { 383 int ret = ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); 384 385 return ret < 0 ? -errno : 0; 386 } 387 388 /* 389 * The use of this function is for requests that only need to be 390 * applied once. Typically such request occurs at the beginning 391 * of operation, and before setting up queues. It should not be 392 * used for request that performs operation until all queues are 393 * set, which would need to check dev->vq_index_end instead. 394 */ 395 static bool vhost_vdpa_first_dev(struct vhost_dev *dev) 396 { 397 struct vhost_vdpa *v = dev->opaque; 398 399 return v->index == 0; 400 } 401 402 static int vhost_vdpa_get_dev_features(struct vhost_dev *dev, 403 uint64_t *features) 404 { 405 int ret; 406 407 ret = vhost_vdpa_call(dev, VHOST_GET_FEATURES, features); 408 trace_vhost_vdpa_get_features(dev, *features); 409 return ret; 410 } 411 412 static void vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v) 413 { 414 g_autoptr(GPtrArray) shadow_vqs = NULL; 415 416 shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); 417 for (unsigned n = 0; n < hdev->nvqs; ++n) { 418 VhostShadowVirtqueue *svq; 419 420 svq = vhost_svq_new(v->shadow_vq_ops, v->shadow_vq_ops_opaque); 421 g_ptr_array_add(shadow_vqs, svq); 422 } 423 424 v->shadow_vqs = g_steal_pointer(&shadow_vqs); 425 } 426 427 static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) 428 { 429 struct vhost_vdpa *v; 430 assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); 431 trace_vhost_vdpa_init(dev, opaque); 432 int ret; 433 434 v = opaque; 435 v->dev = dev; 436 dev->opaque = opaque ; 437 v->listener = vhost_vdpa_memory_listener; 438 v->msg_type = VHOST_IOTLB_MSG_V2; 439 vhost_vdpa_init_svq(dev, v); 440 441 if (!vhost_vdpa_first_dev(dev)) { 442 return 0; 443 } 444 445 /* 446 * Similar to VFIO, we end up pinning all guest memory and have to 447 * disable discarding of RAM. 448 */ 449 ret = ram_block_discard_disable(true); 450 if (ret) { 451 error_report("Cannot set discarding of RAM broken"); 452 return ret; 453 } 454 455 vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | 456 VIRTIO_CONFIG_S_DRIVER); 457 458 return 0; 459 } 460 461 static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev, 462 int queue_index) 463 { 464 size_t page_size = qemu_real_host_page_size(); 465 struct vhost_vdpa *v = dev->opaque; 466 VirtIODevice *vdev = dev->vdev; 467 VhostVDPAHostNotifier *n; 468 469 n = &v->notifier[queue_index]; 470 471 if (n->addr) { 472 virtio_queue_set_host_notifier_mr(vdev, queue_index, &n->mr, false); 473 object_unparent(OBJECT(&n->mr)); 474 munmap(n->addr, page_size); 475 n->addr = NULL; 476 } 477 } 478 479 static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index) 480 { 481 size_t page_size = qemu_real_host_page_size(); 482 struct vhost_vdpa *v = dev->opaque; 483 VirtIODevice *vdev = dev->vdev; 484 VhostVDPAHostNotifier *n; 485 int fd = v->device_fd; 486 void *addr; 487 char *name; 488 489 vhost_vdpa_host_notifier_uninit(dev, queue_index); 490 491 n = &v->notifier[queue_index]; 492 493 addr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, fd, 494 queue_index * page_size); 495 if (addr == MAP_FAILED) { 496 goto err; 497 } 498 499 name = g_strdup_printf("vhost-vdpa/host-notifier@%p mmaps[%d]", 500 v, queue_index); 501 memory_region_init_ram_device_ptr(&n->mr, OBJECT(vdev), name, 502 page_size, addr); 503 g_free(name); 504 505 if (virtio_queue_set_host_notifier_mr(vdev, queue_index, &n->mr, true)) { 506 object_unparent(OBJECT(&n->mr)); 507 munmap(addr, page_size); 508 goto err; 509 } 510 n->addr = addr; 511 512 return 0; 513 514 err: 515 return -1; 516 } 517 518 static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n) 519 { 520 int i; 521 522 /* 523 * Pack all the changes to the memory regions in a single 524 * transaction to avoid a few updating of the address space 525 * topology. 526 */ 527 memory_region_transaction_begin(); 528 529 for (i = dev->vq_index; i < dev->vq_index + n; i++) { 530 vhost_vdpa_host_notifier_uninit(dev, i); 531 } 532 533 memory_region_transaction_commit(); 534 } 535 536 static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev) 537 { 538 struct vhost_vdpa *v = dev->opaque; 539 int i; 540 541 if (v->shadow_vqs_enabled) { 542 /* FIXME SVQ is not compatible with host notifiers mr */ 543 return; 544 } 545 546 /* 547 * Pack all the changes to the memory regions in a single 548 * transaction to avoid a few updating of the address space 549 * topology. 550 */ 551 memory_region_transaction_begin(); 552 553 for (i = dev->vq_index; i < dev->vq_index + dev->nvqs; i++) { 554 if (vhost_vdpa_host_notifier_init(dev, i)) { 555 vhost_vdpa_host_notifiers_uninit(dev, i - dev->vq_index); 556 break; 557 } 558 } 559 560 memory_region_transaction_commit(); 561 } 562 563 static void vhost_vdpa_svq_cleanup(struct vhost_dev *dev) 564 { 565 struct vhost_vdpa *v = dev->opaque; 566 size_t idx; 567 568 for (idx = 0; idx < v->shadow_vqs->len; ++idx) { 569 vhost_svq_stop(g_ptr_array_index(v->shadow_vqs, idx)); 570 } 571 g_ptr_array_free(v->shadow_vqs, true); 572 } 573 574 static int vhost_vdpa_cleanup(struct vhost_dev *dev) 575 { 576 struct vhost_vdpa *v; 577 assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); 578 v = dev->opaque; 579 trace_vhost_vdpa_cleanup(dev, v); 580 if (vhost_vdpa_first_dev(dev)) { 581 ram_block_discard_disable(false); 582 } 583 584 vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); 585 memory_listener_unregister(&v->listener); 586 vhost_vdpa_svq_cleanup(dev); 587 588 dev->opaque = NULL; 589 590 return 0; 591 } 592 593 static int vhost_vdpa_memslots_limit(struct vhost_dev *dev) 594 { 595 trace_vhost_vdpa_memslots_limit(dev, INT_MAX); 596 return INT_MAX; 597 } 598 599 static int vhost_vdpa_set_mem_table(struct vhost_dev *dev, 600 struct vhost_memory *mem) 601 { 602 if (!vhost_vdpa_first_dev(dev)) { 603 return 0; 604 } 605 606 trace_vhost_vdpa_set_mem_table(dev, mem->nregions, mem->padding); 607 if (trace_event_get_state_backends(TRACE_VHOST_VDPA_SET_MEM_TABLE) && 608 trace_event_get_state_backends(TRACE_VHOST_VDPA_DUMP_REGIONS)) { 609 int i; 610 for (i = 0; i < mem->nregions; i++) { 611 trace_vhost_vdpa_dump_regions(dev, i, 612 mem->regions[i].guest_phys_addr, 613 mem->regions[i].memory_size, 614 mem->regions[i].userspace_addr, 615 mem->regions[i].flags_padding); 616 } 617 } 618 if (mem->padding) { 619 return -EINVAL; 620 } 621 622 return 0; 623 } 624 625 static int vhost_vdpa_set_features(struct vhost_dev *dev, 626 uint64_t features) 627 { 628 struct vhost_vdpa *v = dev->opaque; 629 int ret; 630 631 if (!vhost_vdpa_first_dev(dev)) { 632 return 0; 633 } 634 635 if (v->shadow_vqs_enabled) { 636 if ((v->acked_features ^ features) == BIT_ULL(VHOST_F_LOG_ALL)) { 637 /* 638 * QEMU is just trying to enable or disable logging. SVQ handles 639 * this sepparately, so no need to forward this. 640 */ 641 v->acked_features = features; 642 return 0; 643 } 644 645 v->acked_features = features; 646 647 /* We must not ack _F_LOG if SVQ is enabled */ 648 features &= ~BIT_ULL(VHOST_F_LOG_ALL); 649 } 650 651 trace_vhost_vdpa_set_features(dev, features); 652 ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); 653 if (ret) { 654 return ret; 655 } 656 657 return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); 658 } 659 660 static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) 661 { 662 uint64_t features; 663 uint64_t f = 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 | 664 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH | 665 0x1ULL << VHOST_BACKEND_F_IOTLB_ASID | 666 0x1ULL << VHOST_BACKEND_F_SUSPEND; 667 int r; 668 669 if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) { 670 return -EFAULT; 671 } 672 673 features &= f; 674 675 if (vhost_vdpa_first_dev(dev)) { 676 r = vhost_vdpa_call(dev, VHOST_SET_BACKEND_FEATURES, &features); 677 if (r) { 678 return -EFAULT; 679 } 680 } 681 682 dev->backend_cap = features; 683 684 return 0; 685 } 686 687 static int vhost_vdpa_get_device_id(struct vhost_dev *dev, 688 uint32_t *device_id) 689 { 690 int ret; 691 ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_DEVICE_ID, device_id); 692 trace_vhost_vdpa_get_device_id(dev, *device_id); 693 return ret; 694 } 695 696 static int vhost_vdpa_reset_device(struct vhost_dev *dev) 697 { 698 struct vhost_vdpa *v = dev->opaque; 699 int ret; 700 uint8_t status = 0; 701 702 ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); 703 trace_vhost_vdpa_reset_device(dev, status); 704 v->suspended = false; 705 return ret; 706 } 707 708 static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) 709 { 710 assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs); 711 712 trace_vhost_vdpa_get_vq_index(dev, idx, idx); 713 return idx; 714 } 715 716 static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev) 717 { 718 int i; 719 trace_vhost_vdpa_set_vring_ready(dev); 720 for (i = 0; i < dev->nvqs; ++i) { 721 struct vhost_vring_state state = { 722 .index = dev->vq_index + i, 723 .num = 1, 724 }; 725 vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state); 726 } 727 return 0; 728 } 729 730 static int vhost_vdpa_set_config_call(struct vhost_dev *dev, 731 int fd) 732 { 733 trace_vhost_vdpa_set_config_call(dev, fd); 734 return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, &fd); 735 } 736 737 static void vhost_vdpa_dump_config(struct vhost_dev *dev, const uint8_t *config, 738 uint32_t config_len) 739 { 740 int b, len; 741 char line[QEMU_HEXDUMP_LINE_LEN]; 742 743 for (b = 0; b < config_len; b += 16) { 744 len = config_len - b; 745 qemu_hexdump_line(line, b, config, len, false); 746 trace_vhost_vdpa_dump_config(dev, line); 747 } 748 } 749 750 static int vhost_vdpa_set_config(struct vhost_dev *dev, const uint8_t *data, 751 uint32_t offset, uint32_t size, 752 uint32_t flags) 753 { 754 struct vhost_vdpa_config *config; 755 int ret; 756 unsigned long config_size = offsetof(struct vhost_vdpa_config, buf); 757 758 trace_vhost_vdpa_set_config(dev, offset, size, flags); 759 config = g_malloc(size + config_size); 760 config->off = offset; 761 config->len = size; 762 memcpy(config->buf, data, size); 763 if (trace_event_get_state_backends(TRACE_VHOST_VDPA_SET_CONFIG) && 764 trace_event_get_state_backends(TRACE_VHOST_VDPA_DUMP_CONFIG)) { 765 vhost_vdpa_dump_config(dev, data, size); 766 } 767 ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG, config); 768 g_free(config); 769 return ret; 770 } 771 772 static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, 773 uint32_t config_len, Error **errp) 774 { 775 struct vhost_vdpa_config *v_config; 776 unsigned long config_size = offsetof(struct vhost_vdpa_config, buf); 777 int ret; 778 779 trace_vhost_vdpa_get_config(dev, config, config_len); 780 v_config = g_malloc(config_len + config_size); 781 v_config->len = config_len; 782 v_config->off = 0; 783 ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_CONFIG, v_config); 784 memcpy(config, v_config->buf, config_len); 785 g_free(v_config); 786 if (trace_event_get_state_backends(TRACE_VHOST_VDPA_GET_CONFIG) && 787 trace_event_get_state_backends(TRACE_VHOST_VDPA_DUMP_CONFIG)) { 788 vhost_vdpa_dump_config(dev, config, config_len); 789 } 790 return ret; 791 } 792 793 static int vhost_vdpa_set_dev_vring_base(struct vhost_dev *dev, 794 struct vhost_vring_state *ring) 795 { 796 trace_vhost_vdpa_set_vring_base(dev, ring->index, ring->num); 797 return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); 798 } 799 800 static int vhost_vdpa_set_vring_dev_kick(struct vhost_dev *dev, 801 struct vhost_vring_file *file) 802 { 803 trace_vhost_vdpa_set_vring_kick(dev, file->index, file->fd); 804 return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); 805 } 806 807 static int vhost_vdpa_set_vring_dev_call(struct vhost_dev *dev, 808 struct vhost_vring_file *file) 809 { 810 trace_vhost_vdpa_set_vring_call(dev, file->index, file->fd); 811 return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); 812 } 813 814 static int vhost_vdpa_set_vring_dev_addr(struct vhost_dev *dev, 815 struct vhost_vring_addr *addr) 816 { 817 trace_vhost_vdpa_set_vring_addr(dev, addr->index, addr->flags, 818 addr->desc_user_addr, addr->used_user_addr, 819 addr->avail_user_addr, 820 addr->log_guest_addr); 821 822 return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); 823 824 } 825 826 /** 827 * Set the shadow virtqueue descriptors to the device 828 * 829 * @dev: The vhost device model 830 * @svq: The shadow virtqueue 831 * @idx: The index of the virtqueue in the vhost device 832 * @errp: Error 833 * 834 * Note that this function does not rewind kick file descriptor if cannot set 835 * call one. 836 */ 837 static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev, 838 VhostShadowVirtqueue *svq, unsigned idx, 839 Error **errp) 840 { 841 struct vhost_vring_file file = { 842 .index = dev->vq_index + idx, 843 }; 844 const EventNotifier *event_notifier = &svq->hdev_kick; 845 int r; 846 847 r = event_notifier_init(&svq->hdev_kick, 0); 848 if (r != 0) { 849 error_setg_errno(errp, -r, "Couldn't create kick event notifier"); 850 goto err_init_hdev_kick; 851 } 852 853 r = event_notifier_init(&svq->hdev_call, 0); 854 if (r != 0) { 855 error_setg_errno(errp, -r, "Couldn't create call event notifier"); 856 goto err_init_hdev_call; 857 } 858 859 file.fd = event_notifier_get_fd(event_notifier); 860 r = vhost_vdpa_set_vring_dev_kick(dev, &file); 861 if (unlikely(r != 0)) { 862 error_setg_errno(errp, -r, "Can't set device kick fd"); 863 goto err_init_set_dev_fd; 864 } 865 866 event_notifier = &svq->hdev_call; 867 file.fd = event_notifier_get_fd(event_notifier); 868 r = vhost_vdpa_set_vring_dev_call(dev, &file); 869 if (unlikely(r != 0)) { 870 error_setg_errno(errp, -r, "Can't set device call fd"); 871 goto err_init_set_dev_fd; 872 } 873 874 return 0; 875 876 err_init_set_dev_fd: 877 event_notifier_set_handler(&svq->hdev_call, NULL); 878 879 err_init_hdev_call: 880 event_notifier_cleanup(&svq->hdev_kick); 881 882 err_init_hdev_kick: 883 return r; 884 } 885 886 /** 887 * Unmap a SVQ area in the device 888 */ 889 static void vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr addr) 890 { 891 const DMAMap needle = { 892 .translated_addr = addr, 893 }; 894 const DMAMap *result = vhost_iova_tree_find_iova(v->iova_tree, &needle); 895 hwaddr size; 896 int r; 897 898 if (unlikely(!result)) { 899 error_report("Unable to find SVQ address to unmap"); 900 return; 901 } 902 903 size = ROUND_UP(result->size, qemu_real_host_page_size()); 904 r = vhost_vdpa_dma_unmap(v, v->address_space_id, result->iova, size); 905 if (unlikely(r < 0)) { 906 error_report("Unable to unmap SVQ vring: %s (%d)", g_strerror(-r), -r); 907 return; 908 } 909 910 vhost_iova_tree_remove(v->iova_tree, *result); 911 } 912 913 static void vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, 914 const VhostShadowVirtqueue *svq) 915 { 916 struct vhost_vdpa *v = dev->opaque; 917 struct vhost_vring_addr svq_addr; 918 919 vhost_svq_get_vring_addr(svq, &svq_addr); 920 921 vhost_vdpa_svq_unmap_ring(v, svq_addr.desc_user_addr); 922 923 vhost_vdpa_svq_unmap_ring(v, svq_addr.used_user_addr); 924 } 925 926 /** 927 * Map the SVQ area in the device 928 * 929 * @v: Vhost-vdpa device 930 * @needle: The area to search iova 931 * @errorp: Error pointer 932 */ 933 static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, DMAMap *needle, 934 Error **errp) 935 { 936 int r; 937 938 r = vhost_iova_tree_map_alloc(v->iova_tree, needle); 939 if (unlikely(r != IOVA_OK)) { 940 error_setg(errp, "Cannot allocate iova (%d)", r); 941 return false; 942 } 943 944 r = vhost_vdpa_dma_map(v, v->address_space_id, needle->iova, 945 needle->size + 1, 946 (void *)(uintptr_t)needle->translated_addr, 947 needle->perm == IOMMU_RO); 948 if (unlikely(r != 0)) { 949 error_setg_errno(errp, -r, "Cannot map region to device"); 950 vhost_iova_tree_remove(v->iova_tree, *needle); 951 } 952 953 return r == 0; 954 } 955 956 /** 957 * Map the shadow virtqueue rings in the device 958 * 959 * @dev: The vhost device 960 * @svq: The shadow virtqueue 961 * @addr: Assigned IOVA addresses 962 * @errp: Error pointer 963 */ 964 static bool vhost_vdpa_svq_map_rings(struct vhost_dev *dev, 965 const VhostShadowVirtqueue *svq, 966 struct vhost_vring_addr *addr, 967 Error **errp) 968 { 969 ERRP_GUARD(); 970 DMAMap device_region, driver_region; 971 struct vhost_vring_addr svq_addr; 972 struct vhost_vdpa *v = dev->opaque; 973 size_t device_size = vhost_svq_device_area_size(svq); 974 size_t driver_size = vhost_svq_driver_area_size(svq); 975 size_t avail_offset; 976 bool ok; 977 978 vhost_svq_get_vring_addr(svq, &svq_addr); 979 980 driver_region = (DMAMap) { 981 .translated_addr = svq_addr.desc_user_addr, 982 .size = driver_size - 1, 983 .perm = IOMMU_RO, 984 }; 985 ok = vhost_vdpa_svq_map_ring(v, &driver_region, errp); 986 if (unlikely(!ok)) { 987 error_prepend(errp, "Cannot create vq driver region: "); 988 return false; 989 } 990 addr->desc_user_addr = driver_region.iova; 991 avail_offset = svq_addr.avail_user_addr - svq_addr.desc_user_addr; 992 addr->avail_user_addr = driver_region.iova + avail_offset; 993 994 device_region = (DMAMap) { 995 .translated_addr = svq_addr.used_user_addr, 996 .size = device_size - 1, 997 .perm = IOMMU_RW, 998 }; 999 ok = vhost_vdpa_svq_map_ring(v, &device_region, errp); 1000 if (unlikely(!ok)) { 1001 error_prepend(errp, "Cannot create vq device region: "); 1002 vhost_vdpa_svq_unmap_ring(v, driver_region.translated_addr); 1003 } 1004 addr->used_user_addr = device_region.iova; 1005 1006 return ok; 1007 } 1008 1009 static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, 1010 VhostShadowVirtqueue *svq, unsigned idx, 1011 Error **errp) 1012 { 1013 uint16_t vq_index = dev->vq_index + idx; 1014 struct vhost_vring_state s = { 1015 .index = vq_index, 1016 }; 1017 int r; 1018 1019 r = vhost_vdpa_set_dev_vring_base(dev, &s); 1020 if (unlikely(r)) { 1021 error_setg_errno(errp, -r, "Cannot set vring base"); 1022 return false; 1023 } 1024 1025 r = vhost_vdpa_svq_set_fds(dev, svq, idx, errp); 1026 return r == 0; 1027 } 1028 1029 static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) 1030 { 1031 struct vhost_vdpa *v = dev->opaque; 1032 Error *err = NULL; 1033 unsigned i; 1034 1035 if (!v->shadow_vqs_enabled) { 1036 return true; 1037 } 1038 1039 for (i = 0; i < v->shadow_vqs->len; ++i) { 1040 VirtQueue *vq = virtio_get_queue(dev->vdev, dev->vq_index + i); 1041 VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); 1042 struct vhost_vring_addr addr = { 1043 .index = dev->vq_index + i, 1044 }; 1045 int r; 1046 bool ok = vhost_vdpa_svq_setup(dev, svq, i, &err); 1047 if (unlikely(!ok)) { 1048 goto err; 1049 } 1050 1051 vhost_svq_start(svq, dev->vdev, vq, v->iova_tree); 1052 ok = vhost_vdpa_svq_map_rings(dev, svq, &addr, &err); 1053 if (unlikely(!ok)) { 1054 goto err_map; 1055 } 1056 1057 /* Override vring GPA set by vhost subsystem */ 1058 r = vhost_vdpa_set_vring_dev_addr(dev, &addr); 1059 if (unlikely(r != 0)) { 1060 error_setg_errno(&err, -r, "Cannot set device address"); 1061 goto err_set_addr; 1062 } 1063 } 1064 1065 return true; 1066 1067 err_set_addr: 1068 vhost_vdpa_svq_unmap_rings(dev, g_ptr_array_index(v->shadow_vqs, i)); 1069 1070 err_map: 1071 vhost_svq_stop(g_ptr_array_index(v->shadow_vqs, i)); 1072 1073 err: 1074 error_reportf_err(err, "Cannot setup SVQ %u: ", i); 1075 for (unsigned j = 0; j < i; ++j) { 1076 VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, j); 1077 vhost_vdpa_svq_unmap_rings(dev, svq); 1078 vhost_svq_stop(svq); 1079 } 1080 1081 return false; 1082 } 1083 1084 static void vhost_vdpa_svqs_stop(struct vhost_dev *dev) 1085 { 1086 struct vhost_vdpa *v = dev->opaque; 1087 1088 if (!v->shadow_vqs_enabled) { 1089 return; 1090 } 1091 1092 for (unsigned i = 0; i < v->shadow_vqs->len; ++i) { 1093 VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); 1094 1095 vhost_svq_stop(svq); 1096 vhost_vdpa_svq_unmap_rings(dev, svq); 1097 1098 event_notifier_cleanup(&svq->hdev_kick); 1099 event_notifier_cleanup(&svq->hdev_call); 1100 } 1101 } 1102 1103 static void vhost_vdpa_suspend(struct vhost_dev *dev) 1104 { 1105 struct vhost_vdpa *v = dev->opaque; 1106 int r; 1107 1108 if (!vhost_vdpa_first_dev(dev)) { 1109 return; 1110 } 1111 1112 if (dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) { 1113 trace_vhost_vdpa_suspend(dev); 1114 r = ioctl(v->device_fd, VHOST_VDPA_SUSPEND); 1115 if (unlikely(r)) { 1116 error_report("Cannot suspend: %s(%d)", g_strerror(errno), errno); 1117 } else { 1118 v->suspended = true; 1119 return; 1120 } 1121 } 1122 1123 vhost_vdpa_reset_device(dev); 1124 } 1125 1126 static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) 1127 { 1128 struct vhost_vdpa *v = dev->opaque; 1129 bool ok; 1130 trace_vhost_vdpa_dev_start(dev, started); 1131 1132 if (started) { 1133 vhost_vdpa_host_notifiers_init(dev); 1134 ok = vhost_vdpa_svqs_start(dev); 1135 if (unlikely(!ok)) { 1136 return -1; 1137 } 1138 vhost_vdpa_set_vring_ready(dev); 1139 } else { 1140 vhost_vdpa_suspend(dev); 1141 vhost_vdpa_svqs_stop(dev); 1142 vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); 1143 } 1144 1145 if (dev->vq_index + dev->nvqs != dev->vq_index_end) { 1146 return 0; 1147 } 1148 1149 if (started) { 1150 memory_listener_register(&v->listener, &address_space_memory); 1151 return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); 1152 } 1153 1154 return 0; 1155 } 1156 1157 static void vhost_vdpa_reset_status(struct vhost_dev *dev) 1158 { 1159 struct vhost_vdpa *v = dev->opaque; 1160 1161 if (dev->vq_index + dev->nvqs != dev->vq_index_end) { 1162 return; 1163 } 1164 1165 vhost_vdpa_reset_device(dev); 1166 vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | 1167 VIRTIO_CONFIG_S_DRIVER); 1168 memory_listener_unregister(&v->listener); 1169 } 1170 1171 static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, 1172 struct vhost_log *log) 1173 { 1174 struct vhost_vdpa *v = dev->opaque; 1175 if (v->shadow_vqs_enabled || !vhost_vdpa_first_dev(dev)) { 1176 return 0; 1177 } 1178 1179 trace_vhost_vdpa_set_log_base(dev, base, log->size, log->refcnt, log->fd, 1180 log->log); 1181 return vhost_vdpa_call(dev, VHOST_SET_LOG_BASE, &base); 1182 } 1183 1184 static int vhost_vdpa_set_vring_addr(struct vhost_dev *dev, 1185 struct vhost_vring_addr *addr) 1186 { 1187 struct vhost_vdpa *v = dev->opaque; 1188 1189 if (v->shadow_vqs_enabled) { 1190 /* 1191 * Device vring addr was set at device start. SVQ base is handled by 1192 * VirtQueue code. 1193 */ 1194 return 0; 1195 } 1196 1197 return vhost_vdpa_set_vring_dev_addr(dev, addr); 1198 } 1199 1200 static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, 1201 struct vhost_vring_state *ring) 1202 { 1203 trace_vhost_vdpa_set_vring_num(dev, ring->index, ring->num); 1204 return vhost_vdpa_call(dev, VHOST_SET_VRING_NUM, ring); 1205 } 1206 1207 static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, 1208 struct vhost_vring_state *ring) 1209 { 1210 struct vhost_vdpa *v = dev->opaque; 1211 1212 if (v->shadow_vqs_enabled) { 1213 /* 1214 * Device vring base was set at device start. SVQ base is handled by 1215 * VirtQueue code. 1216 */ 1217 return 0; 1218 } 1219 1220 return vhost_vdpa_set_dev_vring_base(dev, ring); 1221 } 1222 1223 static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, 1224 struct vhost_vring_state *ring) 1225 { 1226 struct vhost_vdpa *v = dev->opaque; 1227 int ret; 1228 1229 if (v->shadow_vqs_enabled) { 1230 ring->num = virtio_queue_get_last_avail_idx(dev->vdev, ring->index); 1231 return 0; 1232 } 1233 1234 if (!v->suspended) { 1235 /* 1236 * Cannot trust in value returned by device, let vhost recover used 1237 * idx from guest. 1238 */ 1239 return -1; 1240 } 1241 1242 ret = vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); 1243 trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num); 1244 return ret; 1245 } 1246 1247 static int vhost_vdpa_set_vring_kick(struct vhost_dev *dev, 1248 struct vhost_vring_file *file) 1249 { 1250 struct vhost_vdpa *v = dev->opaque; 1251 int vdpa_idx = file->index - dev->vq_index; 1252 1253 if (v->shadow_vqs_enabled) { 1254 VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, vdpa_idx); 1255 vhost_svq_set_svq_kick_fd(svq, file->fd); 1256 return 0; 1257 } else { 1258 return vhost_vdpa_set_vring_dev_kick(dev, file); 1259 } 1260 } 1261 1262 static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, 1263 struct vhost_vring_file *file) 1264 { 1265 struct vhost_vdpa *v = dev->opaque; 1266 int vdpa_idx = file->index - dev->vq_index; 1267 VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, vdpa_idx); 1268 1269 /* Remember last call fd because we can switch to SVQ anytime. */ 1270 vhost_svq_set_svq_call_fd(svq, file->fd); 1271 if (v->shadow_vqs_enabled) { 1272 return 0; 1273 } 1274 1275 return vhost_vdpa_set_vring_dev_call(dev, file); 1276 } 1277 1278 static int vhost_vdpa_get_features(struct vhost_dev *dev, 1279 uint64_t *features) 1280 { 1281 struct vhost_vdpa *v = dev->opaque; 1282 int ret = vhost_vdpa_get_dev_features(dev, features); 1283 1284 if (ret == 0 && v->shadow_vqs_enabled) { 1285 /* Add SVQ logging capabilities */ 1286 *features |= BIT_ULL(VHOST_F_LOG_ALL); 1287 } 1288 1289 return ret; 1290 } 1291 1292 static int vhost_vdpa_set_owner(struct vhost_dev *dev) 1293 { 1294 if (!vhost_vdpa_first_dev(dev)) { 1295 return 0; 1296 } 1297 1298 trace_vhost_vdpa_set_owner(dev); 1299 return vhost_vdpa_call(dev, VHOST_SET_OWNER, NULL); 1300 } 1301 1302 static int vhost_vdpa_vq_get_addr(struct vhost_dev *dev, 1303 struct vhost_vring_addr *addr, struct vhost_virtqueue *vq) 1304 { 1305 assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); 1306 addr->desc_user_addr = (uint64_t)(unsigned long)vq->desc_phys; 1307 addr->avail_user_addr = (uint64_t)(unsigned long)vq->avail_phys; 1308 addr->used_user_addr = (uint64_t)(unsigned long)vq->used_phys; 1309 trace_vhost_vdpa_vq_get_addr(dev, vq, addr->desc_user_addr, 1310 addr->avail_user_addr, addr->used_user_addr); 1311 return 0; 1312 } 1313 1314 static bool vhost_vdpa_force_iommu(struct vhost_dev *dev) 1315 { 1316 return true; 1317 } 1318 1319 const VhostOps vdpa_ops = { 1320 .backend_type = VHOST_BACKEND_TYPE_VDPA, 1321 .vhost_backend_init = vhost_vdpa_init, 1322 .vhost_backend_cleanup = vhost_vdpa_cleanup, 1323 .vhost_set_log_base = vhost_vdpa_set_log_base, 1324 .vhost_set_vring_addr = vhost_vdpa_set_vring_addr, 1325 .vhost_set_vring_num = vhost_vdpa_set_vring_num, 1326 .vhost_set_vring_base = vhost_vdpa_set_vring_base, 1327 .vhost_get_vring_base = vhost_vdpa_get_vring_base, 1328 .vhost_set_vring_kick = vhost_vdpa_set_vring_kick, 1329 .vhost_set_vring_call = vhost_vdpa_set_vring_call, 1330 .vhost_get_features = vhost_vdpa_get_features, 1331 .vhost_set_backend_cap = vhost_vdpa_set_backend_cap, 1332 .vhost_set_owner = vhost_vdpa_set_owner, 1333 .vhost_set_vring_endian = NULL, 1334 .vhost_backend_memslots_limit = vhost_vdpa_memslots_limit, 1335 .vhost_set_mem_table = vhost_vdpa_set_mem_table, 1336 .vhost_set_features = vhost_vdpa_set_features, 1337 .vhost_reset_device = vhost_vdpa_reset_device, 1338 .vhost_get_vq_index = vhost_vdpa_get_vq_index, 1339 .vhost_get_config = vhost_vdpa_get_config, 1340 .vhost_set_config = vhost_vdpa_set_config, 1341 .vhost_requires_shm_log = NULL, 1342 .vhost_migration_done = NULL, 1343 .vhost_backend_can_merge = NULL, 1344 .vhost_net_set_mtu = NULL, 1345 .vhost_set_iotlb_callback = NULL, 1346 .vhost_send_device_iotlb_msg = NULL, 1347 .vhost_dev_start = vhost_vdpa_dev_start, 1348 .vhost_get_device_id = vhost_vdpa_get_device_id, 1349 .vhost_vq_get_addr = vhost_vdpa_vq_get_addr, 1350 .vhost_force_iommu = vhost_vdpa_force_iommu, 1351 .vhost_set_config_call = vhost_vdpa_set_config_call, 1352 .vhost_reset_status = vhost_vdpa_reset_status, 1353 }; 1354