1 /* 2 * vhost shadow virtqueue 3 * 4 * SPDX-FileCopyrightText: Red Hat, Inc. 2021 5 * SPDX-FileContributor: Author: Eugenio Pérez <eperezma@redhat.com> 6 * 7 * SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 10 #include "qemu/osdep.h" 11 #include "hw/virtio/vhost-shadow-virtqueue.h" 12 13 #include "qemu/error-report.h" 14 #include "qapi/error.h" 15 #include "qemu/main-loop.h" 16 #include "qemu/log.h" 17 #include "qemu/memalign.h" 18 #include "linux-headers/linux/vhost.h" 19 20 /** 21 * Validate the transport device features that both guests can use with the SVQ 22 * and SVQs can use with the device. 23 * 24 * @dev_features: The features 25 * @errp: Error pointer 26 */ 27 bool vhost_svq_valid_features(uint64_t features, Error **errp) 28 { 29 bool ok = true; 30 uint64_t svq_features = features; 31 32 for (uint64_t b = VIRTIO_TRANSPORT_F_START; b <= VIRTIO_TRANSPORT_F_END; 33 ++b) { 34 switch (b) { 35 case VIRTIO_F_ANY_LAYOUT: 36 continue; 37 38 case VIRTIO_F_ACCESS_PLATFORM: 39 /* SVQ trust in the host's IOMMU to translate addresses */ 40 case VIRTIO_F_VERSION_1: 41 /* SVQ trust that the guest vring is little endian */ 42 if (!(svq_features & BIT_ULL(b))) { 43 svq_features |= BIT_ULL(b); 44 ok = false; 45 } 46 continue; 47 48 default: 49 if (svq_features & BIT_ULL(b)) { 50 svq_features &= ~BIT_ULL(b); 51 ok = false; 52 } 53 } 54 } 55 56 if (!ok) { 57 error_setg(errp, "SVQ Invalid device feature flags, offer: 0x%"PRIx64 58 ", ok: 0x%"PRIx64, features, svq_features); 59 } 60 return ok; 61 } 62 63 /** 64 * Number of descriptors that the SVQ can make available from the guest. 65 * 66 * @svq: The svq 67 */ 68 static uint16_t vhost_svq_available_slots(const VhostShadowVirtqueue *svq) 69 { 70 return svq->vring.num - (svq->shadow_avail_idx - svq->shadow_used_idx); 71 } 72 73 /** 74 * Translate addresses between the qemu's virtual address and the SVQ IOVA 75 * 76 * @svq: Shadow VirtQueue 77 * @vaddr: Translated IOVA addresses 78 * @iovec: Source qemu's VA addresses 79 * @num: Length of iovec and minimum length of vaddr 80 */ 81 static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq, 82 hwaddr *addrs, const struct iovec *iovec, 83 size_t num) 84 { 85 if (num == 0) { 86 return true; 87 } 88 89 for (size_t i = 0; i < num; ++i) { 90 DMAMap needle = { 91 .translated_addr = (hwaddr)(uintptr_t)iovec[i].iov_base, 92 .size = iovec[i].iov_len, 93 }; 94 Int128 needle_last, map_last; 95 size_t off; 96 97 const DMAMap *map = vhost_iova_tree_find_iova(svq->iova_tree, &needle); 98 /* 99 * Map cannot be NULL since iova map contains all guest space and 100 * qemu already has a physical address mapped 101 */ 102 if (unlikely(!map)) { 103 qemu_log_mask(LOG_GUEST_ERROR, 104 "Invalid address 0x%"HWADDR_PRIx" given by guest", 105 needle.translated_addr); 106 return false; 107 } 108 109 off = needle.translated_addr - map->translated_addr; 110 addrs[i] = map->iova + off; 111 112 needle_last = int128_add(int128_make64(needle.translated_addr), 113 int128_make64(iovec[i].iov_len)); 114 map_last = int128_make64(map->translated_addr + map->size); 115 if (unlikely(int128_gt(needle_last, map_last))) { 116 qemu_log_mask(LOG_GUEST_ERROR, 117 "Guest buffer expands over iova range"); 118 return false; 119 } 120 } 121 122 return true; 123 } 124 125 /** 126 * Write descriptors to SVQ vring 127 * 128 * @svq: The shadow virtqueue 129 * @sg: Cache for hwaddr 130 * @iovec: The iovec from the guest 131 * @num: iovec length 132 * @more_descs: True if more descriptors come in the chain 133 * @write: True if they are writeable descriptors 134 * 135 * Return true if success, false otherwise and print error. 136 */ 137 static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, 138 const struct iovec *iovec, size_t num, 139 bool more_descs, bool write) 140 { 141 uint16_t i = svq->free_head, last = svq->free_head; 142 unsigned n; 143 uint16_t flags = write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; 144 vring_desc_t *descs = svq->vring.desc; 145 bool ok; 146 147 if (num == 0) { 148 return true; 149 } 150 151 ok = vhost_svq_translate_addr(svq, sg, iovec, num); 152 if (unlikely(!ok)) { 153 return false; 154 } 155 156 for (n = 0; n < num; n++) { 157 if (more_descs || (n + 1 < num)) { 158 descs[i].flags = flags | cpu_to_le16(VRING_DESC_F_NEXT); 159 descs[i].next = cpu_to_le16(svq->desc_next[i]); 160 } else { 161 descs[i].flags = flags; 162 } 163 descs[i].addr = cpu_to_le64(sg[n]); 164 descs[i].len = cpu_to_le32(iovec[n].iov_len); 165 166 last = i; 167 i = cpu_to_le16(svq->desc_next[i]); 168 } 169 170 svq->free_head = le16_to_cpu(svq->desc_next[last]); 171 return true; 172 } 173 174 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, 175 const struct iovec *out_sg, size_t out_num, 176 const struct iovec *in_sg, size_t in_num, 177 unsigned *head) 178 { 179 unsigned avail_idx; 180 vring_avail_t *avail = svq->vring.avail; 181 bool ok; 182 g_autofree hwaddr *sgs = g_new(hwaddr, MAX(out_num, in_num)); 183 184 *head = svq->free_head; 185 186 /* We need some descriptors here */ 187 if (unlikely(!out_num && !in_num)) { 188 qemu_log_mask(LOG_GUEST_ERROR, 189 "Guest provided element with no descriptors"); 190 return false; 191 } 192 193 ok = vhost_svq_vring_write_descs(svq, sgs, out_sg, out_num, in_num > 0, 194 false); 195 if (unlikely(!ok)) { 196 return false; 197 } 198 199 ok = vhost_svq_vring_write_descs(svq, sgs, in_sg, in_num, false, true); 200 if (unlikely(!ok)) { 201 return false; 202 } 203 204 /* 205 * Put the entry in the available array (but don't update avail->idx until 206 * they do sync). 207 */ 208 avail_idx = svq->shadow_avail_idx & (svq->vring.num - 1); 209 avail->ring[avail_idx] = cpu_to_le16(*head); 210 svq->shadow_avail_idx++; 211 212 /* Update the avail index after write the descriptor */ 213 smp_wmb(); 214 avail->idx = cpu_to_le16(svq->shadow_avail_idx); 215 216 return true; 217 } 218 219 static void vhost_svq_kick(VhostShadowVirtqueue *svq) 220 { 221 /* 222 * We need to expose the available array entries before checking the used 223 * flags 224 */ 225 smp_mb(); 226 if (svq->vring.used->flags & VRING_USED_F_NO_NOTIFY) { 227 return; 228 } 229 230 event_notifier_set(&svq->hdev_kick); 231 } 232 233 /** 234 * Add an element to a SVQ. 235 * 236 * The caller must check that there is enough slots for the new element. It 237 * takes ownership of the element: In case of failure not ENOSPC, it is free. 238 * 239 * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full 240 */ 241 int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, 242 size_t out_num, const struct iovec *in_sg, size_t in_num, 243 VirtQueueElement *elem) 244 { 245 unsigned qemu_head; 246 unsigned ndescs = in_num + out_num; 247 bool ok; 248 249 if (unlikely(ndescs > vhost_svq_available_slots(svq))) { 250 return -ENOSPC; 251 } 252 253 ok = vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_head); 254 if (unlikely(!ok)) { 255 g_free(elem); 256 return -EINVAL; 257 } 258 259 svq->desc_state[qemu_head].elem = elem; 260 svq->desc_state[qemu_head].ndescs = ndescs; 261 vhost_svq_kick(svq); 262 return 0; 263 } 264 265 /* Convenience wrapper to add a guest's element to SVQ */ 266 static int vhost_svq_add_element(VhostShadowVirtqueue *svq, 267 VirtQueueElement *elem) 268 { 269 return vhost_svq_add(svq, elem->out_sg, elem->out_num, elem->in_sg, 270 elem->in_num, elem); 271 } 272 273 /** 274 * Forward available buffers. 275 * 276 * @svq: Shadow VirtQueue 277 * 278 * Note that this function does not guarantee that all guest's available 279 * buffers are available to the device in SVQ avail ring. The guest may have 280 * exposed a GPA / GIOVA contiguous buffer, but it may not be contiguous in 281 * qemu vaddr. 282 * 283 * If that happens, guest's kick notifications will be disabled until the 284 * device uses some buffers. 285 */ 286 static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq) 287 { 288 /* Clear event notifier */ 289 event_notifier_test_and_clear(&svq->svq_kick); 290 291 /* Forward to the device as many available buffers as possible */ 292 do { 293 virtio_queue_set_notification(svq->vq, false); 294 295 while (true) { 296 VirtQueueElement *elem; 297 int r; 298 299 if (svq->next_guest_avail_elem) { 300 elem = g_steal_pointer(&svq->next_guest_avail_elem); 301 } else { 302 elem = virtqueue_pop(svq->vq, sizeof(*elem)); 303 } 304 305 if (!elem) { 306 break; 307 } 308 309 r = vhost_svq_add_element(svq, elem); 310 if (unlikely(r != 0)) { 311 if (r == -ENOSPC) { 312 /* 313 * This condition is possible since a contiguous buffer in 314 * GPA does not imply a contiguous buffer in qemu's VA 315 * scatter-gather segments. If that happens, the buffer 316 * exposed to the device needs to be a chain of descriptors 317 * at this moment. 318 * 319 * SVQ cannot hold more available buffers if we are here: 320 * queue the current guest descriptor and ignore kicks 321 * until some elements are used. 322 */ 323 svq->next_guest_avail_elem = elem; 324 } 325 326 /* VQ is full or broken, just return and ignore kicks */ 327 return; 328 } 329 } 330 331 virtio_queue_set_notification(svq->vq, true); 332 } while (!virtio_queue_empty(svq->vq)); 333 } 334 335 /** 336 * Handle guest's kick. 337 * 338 * @n: guest kick event notifier, the one that guest set to notify svq. 339 */ 340 static void vhost_handle_guest_kick_notifier(EventNotifier *n) 341 { 342 VhostShadowVirtqueue *svq = container_of(n, VhostShadowVirtqueue, svq_kick); 343 event_notifier_test_and_clear(n); 344 vhost_handle_guest_kick(svq); 345 } 346 347 static bool vhost_svq_more_used(VhostShadowVirtqueue *svq) 348 { 349 uint16_t *used_idx = &svq->vring.used->idx; 350 if (svq->last_used_idx != svq->shadow_used_idx) { 351 return true; 352 } 353 354 svq->shadow_used_idx = cpu_to_le16(*(volatile uint16_t *)used_idx); 355 356 return svq->last_used_idx != svq->shadow_used_idx; 357 } 358 359 /** 360 * Enable vhost device calls after disable them. 361 * 362 * @svq: The svq 363 * 364 * It returns false if there are pending used buffers from the vhost device, 365 * avoiding the possible races between SVQ checking for more work and enabling 366 * callbacks. True if SVQ used vring has no more pending buffers. 367 */ 368 static bool vhost_svq_enable_notification(VhostShadowVirtqueue *svq) 369 { 370 svq->vring.avail->flags &= ~cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); 371 /* Make sure the flag is written before the read of used_idx */ 372 smp_mb(); 373 return !vhost_svq_more_used(svq); 374 } 375 376 static void vhost_svq_disable_notification(VhostShadowVirtqueue *svq) 377 { 378 svq->vring.avail->flags |= cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); 379 } 380 381 static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *svq, 382 uint16_t num, uint16_t i) 383 { 384 for (uint16_t j = 0; j < (num - 1); ++j) { 385 i = le16_to_cpu(svq->desc_next[i]); 386 } 387 388 return i; 389 } 390 391 static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, 392 uint32_t *len) 393 { 394 const vring_used_t *used = svq->vring.used; 395 vring_used_elem_t used_elem; 396 uint16_t last_used, last_used_chain, num; 397 398 if (!vhost_svq_more_used(svq)) { 399 return NULL; 400 } 401 402 /* Only get used array entries after they have been exposed by dev */ 403 smp_rmb(); 404 last_used = svq->last_used_idx & (svq->vring.num - 1); 405 used_elem.id = le32_to_cpu(used->ring[last_used].id); 406 used_elem.len = le32_to_cpu(used->ring[last_used].len); 407 408 svq->last_used_idx++; 409 if (unlikely(used_elem.id >= svq->vring.num)) { 410 qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used", 411 svq->vdev->name, used_elem.id); 412 return NULL; 413 } 414 415 if (unlikely(!svq->desc_state[used_elem.id].elem)) { 416 qemu_log_mask(LOG_GUEST_ERROR, 417 "Device %s says index %u is used, but it was not available", 418 svq->vdev->name, used_elem.id); 419 return NULL; 420 } 421 422 num = svq->desc_state[used_elem.id].ndescs; 423 last_used_chain = vhost_svq_last_desc_of_chain(svq, num, used_elem.id); 424 svq->desc_next[last_used_chain] = svq->free_head; 425 svq->free_head = used_elem.id; 426 427 *len = used_elem.len; 428 return g_steal_pointer(&svq->desc_state[used_elem.id].elem); 429 } 430 431 /** 432 * Push an element to SVQ, returning it to the guest. 433 */ 434 void vhost_svq_push_elem(VhostShadowVirtqueue *svq, 435 const VirtQueueElement *elem, uint32_t len) 436 { 437 virtqueue_push(svq->vq, elem, len); 438 if (svq->next_guest_avail_elem) { 439 /* 440 * Avail ring was full when vhost_svq_flush was called, so it's a 441 * good moment to make more descriptors available if possible. 442 */ 443 vhost_handle_guest_kick(svq); 444 } 445 } 446 447 static void vhost_svq_flush(VhostShadowVirtqueue *svq, 448 bool check_for_avail_queue) 449 { 450 VirtQueue *vq = svq->vq; 451 452 /* Forward as many used buffers as possible. */ 453 do { 454 unsigned i = 0; 455 456 vhost_svq_disable_notification(svq); 457 while (true) { 458 uint32_t len; 459 g_autofree VirtQueueElement *elem = vhost_svq_get_buf(svq, &len); 460 if (!elem) { 461 break; 462 } 463 464 if (unlikely(i >= svq->vring.num)) { 465 qemu_log_mask(LOG_GUEST_ERROR, 466 "More than %u used buffers obtained in a %u size SVQ", 467 i, svq->vring.num); 468 virtqueue_fill(vq, elem, len, i); 469 virtqueue_flush(vq, i); 470 return; 471 } 472 virtqueue_fill(vq, elem, len, i++); 473 } 474 475 virtqueue_flush(vq, i); 476 event_notifier_set(&svq->svq_call); 477 478 if (check_for_avail_queue && svq->next_guest_avail_elem) { 479 /* 480 * Avail ring was full when vhost_svq_flush was called, so it's a 481 * good moment to make more descriptors available if possible. 482 */ 483 vhost_handle_guest_kick(svq); 484 } 485 } while (!vhost_svq_enable_notification(svq)); 486 } 487 488 /** 489 * Forward used buffers. 490 * 491 * @n: hdev call event notifier, the one that device set to notify svq. 492 * 493 * Note that we are not making any buffers available in the loop, there is no 494 * way that it runs more than virtqueue size times. 495 */ 496 static void vhost_svq_handle_call(EventNotifier *n) 497 { 498 VhostShadowVirtqueue *svq = container_of(n, VhostShadowVirtqueue, 499 hdev_call); 500 event_notifier_test_and_clear(n); 501 vhost_svq_flush(svq, true); 502 } 503 504 /** 505 * Set the call notifier for the SVQ to call the guest 506 * 507 * @svq: Shadow virtqueue 508 * @call_fd: call notifier 509 * 510 * Called on BQL context. 511 */ 512 void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd) 513 { 514 if (call_fd == VHOST_FILE_UNBIND) { 515 /* 516 * Fail event_notifier_set if called handling device call. 517 * 518 * SVQ still needs device notifications, since it needs to keep 519 * forwarding used buffers even with the unbind. 520 */ 521 memset(&svq->svq_call, 0, sizeof(svq->svq_call)); 522 } else { 523 event_notifier_init_fd(&svq->svq_call, call_fd); 524 } 525 } 526 527 /** 528 * Get the shadow vq vring address. 529 * @svq: Shadow virtqueue 530 * @addr: Destination to store address 531 */ 532 void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, 533 struct vhost_vring_addr *addr) 534 { 535 addr->desc_user_addr = (uint64_t)(uintptr_t)svq->vring.desc; 536 addr->avail_user_addr = (uint64_t)(uintptr_t)svq->vring.avail; 537 addr->used_user_addr = (uint64_t)(uintptr_t)svq->vring.used; 538 } 539 540 size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq) 541 { 542 size_t desc_size = sizeof(vring_desc_t) * svq->vring.num; 543 size_t avail_size = offsetof(vring_avail_t, ring) + 544 sizeof(uint16_t) * svq->vring.num; 545 546 return ROUND_UP(desc_size + avail_size, qemu_real_host_page_size()); 547 } 548 549 size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq) 550 { 551 size_t used_size = offsetof(vring_used_t, ring) + 552 sizeof(vring_used_elem_t) * svq->vring.num; 553 return ROUND_UP(used_size, qemu_real_host_page_size()); 554 } 555 556 /** 557 * Set a new file descriptor for the guest to kick the SVQ and notify for avail 558 * 559 * @svq: The svq 560 * @svq_kick_fd: The svq kick fd 561 * 562 * Note that the SVQ will never close the old file descriptor. 563 */ 564 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd) 565 { 566 EventNotifier *svq_kick = &svq->svq_kick; 567 bool poll_stop = VHOST_FILE_UNBIND != event_notifier_get_fd(svq_kick); 568 bool poll_start = svq_kick_fd != VHOST_FILE_UNBIND; 569 570 if (poll_stop) { 571 event_notifier_set_handler(svq_kick, NULL); 572 } 573 574 /* 575 * event_notifier_set_handler already checks for guest's notifications if 576 * they arrive at the new file descriptor in the switch, so there is no 577 * need to explicitly check for them. 578 */ 579 if (poll_start) { 580 event_notifier_init_fd(svq_kick, svq_kick_fd); 581 event_notifier_set(svq_kick); 582 event_notifier_set_handler(svq_kick, vhost_handle_guest_kick_notifier); 583 } 584 } 585 586 /** 587 * Start the shadow virtqueue operation. 588 * 589 * @svq: Shadow Virtqueue 590 * @vdev: VirtIO device 591 * @vq: Virtqueue to shadow 592 */ 593 void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, 594 VirtQueue *vq) 595 { 596 size_t desc_size, driver_size, device_size; 597 598 svq->next_guest_avail_elem = NULL; 599 svq->shadow_avail_idx = 0; 600 svq->shadow_used_idx = 0; 601 svq->last_used_idx = 0; 602 svq->vdev = vdev; 603 svq->vq = vq; 604 605 svq->vring.num = virtio_queue_get_num(vdev, virtio_get_queue_index(vq)); 606 driver_size = vhost_svq_driver_area_size(svq); 607 device_size = vhost_svq_device_area_size(svq); 608 svq->vring.desc = qemu_memalign(qemu_real_host_page_size(), driver_size); 609 desc_size = sizeof(vring_desc_t) * svq->vring.num; 610 svq->vring.avail = (void *)((char *)svq->vring.desc + desc_size); 611 memset(svq->vring.desc, 0, driver_size); 612 svq->vring.used = qemu_memalign(qemu_real_host_page_size(), device_size); 613 memset(svq->vring.used, 0, device_size); 614 svq->desc_state = g_new0(SVQDescState, svq->vring.num); 615 svq->desc_next = g_new0(uint16_t, svq->vring.num); 616 for (unsigned i = 0; i < svq->vring.num - 1; i++) { 617 svq->desc_next[i] = cpu_to_le16(i + 1); 618 } 619 } 620 621 /** 622 * Stop the shadow virtqueue operation. 623 * @svq: Shadow Virtqueue 624 */ 625 void vhost_svq_stop(VhostShadowVirtqueue *svq) 626 { 627 event_notifier_set_handler(&svq->svq_kick, NULL); 628 g_autofree VirtQueueElement *next_avail_elem = NULL; 629 630 if (!svq->vq) { 631 return; 632 } 633 634 /* Send all pending used descriptors to guest */ 635 vhost_svq_flush(svq, false); 636 637 for (unsigned i = 0; i < svq->vring.num; ++i) { 638 g_autofree VirtQueueElement *elem = NULL; 639 elem = g_steal_pointer(&svq->desc_state[i].elem); 640 if (elem) { 641 virtqueue_detach_element(svq->vq, elem, 0); 642 } 643 } 644 645 next_avail_elem = g_steal_pointer(&svq->next_guest_avail_elem); 646 if (next_avail_elem) { 647 virtqueue_detach_element(svq->vq, next_avail_elem, 0); 648 } 649 svq->vq = NULL; 650 g_free(svq->desc_next); 651 g_free(svq->desc_state); 652 qemu_vfree(svq->vring.desc); 653 qemu_vfree(svq->vring.used); 654 } 655 656 /** 657 * Creates vhost shadow virtqueue, and instructs the vhost device to use the 658 * shadow methods and file descriptors. 659 * 660 * @iova_tree: Tree to perform descriptors translations 661 * 662 * Returns the new virtqueue or NULL. 663 * 664 * In case of error, reason is reported through error_report. 665 */ 666 VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree) 667 { 668 g_autofree VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1); 669 int r; 670 671 r = event_notifier_init(&svq->hdev_kick, 0); 672 if (r != 0) { 673 error_report("Couldn't create kick event notifier: %s (%d)", 674 g_strerror(errno), errno); 675 goto err_init_hdev_kick; 676 } 677 678 r = event_notifier_init(&svq->hdev_call, 0); 679 if (r != 0) { 680 error_report("Couldn't create call event notifier: %s (%d)", 681 g_strerror(errno), errno); 682 goto err_init_hdev_call; 683 } 684 685 event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); 686 event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); 687 svq->iova_tree = iova_tree; 688 return g_steal_pointer(&svq); 689 690 err_init_hdev_call: 691 event_notifier_cleanup(&svq->hdev_kick); 692 693 err_init_hdev_kick: 694 return NULL; 695 } 696 697 /** 698 * Free the resources of the shadow virtqueue. 699 * 700 * @pvq: gpointer to SVQ so it can be used by autofree functions. 701 */ 702 void vhost_svq_free(gpointer pvq) 703 { 704 VhostShadowVirtqueue *vq = pvq; 705 vhost_svq_stop(vq); 706 event_notifier_cleanup(&vq->hdev_kick); 707 event_notifier_set_handler(&vq->hdev_call, NULL); 708 event_notifier_cleanup(&vq->hdev_call); 709 g_free(vq); 710 } 711