1108a6481SCindy Lu /* 2108a6481SCindy Lu * vhost-vdpa 3108a6481SCindy Lu * 4108a6481SCindy Lu * Copyright(c) 2017-2018 Intel Corporation. 5108a6481SCindy Lu * Copyright(c) 2020 Red Hat, Inc. 6108a6481SCindy Lu * 7108a6481SCindy Lu * This work is licensed under the terms of the GNU GPL, version 2 or later. 8108a6481SCindy Lu * See the COPYING file in the top-level directory. 9108a6481SCindy Lu * 10108a6481SCindy Lu */ 11108a6481SCindy Lu 12108a6481SCindy Lu #include "qemu/osdep.h" 13108a6481SCindy Lu #include <linux/vhost.h> 14108a6481SCindy Lu #include <linux/vfio.h> 15108a6481SCindy Lu #include <sys/eventfd.h> 16108a6481SCindy Lu #include <sys/ioctl.h> 17108a6481SCindy Lu #include "hw/virtio/vhost.h" 18108a6481SCindy Lu #include "hw/virtio/vhost-backend.h" 19108a6481SCindy Lu #include "hw/virtio/virtio-net.h" 20108a6481SCindy Lu #include "hw/virtio/vhost-vdpa.h" 21df77d45aSXie Yongji #include "exec/address-spaces.h" 22108a6481SCindy Lu #include "qemu/main-loop.h" 234dc5acc0SCindy Lu #include "cpu.h" 24778e67deSLaurent Vivier #include "trace.h" 25778e67deSLaurent Vivier #include "qemu-common.h" 26108a6481SCindy Lu 27032e4d68SEugenio Pérez /* 28032e4d68SEugenio Pérez * Return one past the end of the end of section. Be careful with uint64_t 29032e4d68SEugenio Pérez * conversions! 30032e4d68SEugenio Pérez */ 31032e4d68SEugenio Pérez static Int128 vhost_vdpa_section_end(const MemoryRegionSection *section) 32032e4d68SEugenio Pérez { 33032e4d68SEugenio Pérez Int128 llend = int128_make64(section->offset_within_address_space); 34032e4d68SEugenio Pérez llend = int128_add(llend, section->size); 35032e4d68SEugenio Pérez llend = int128_and(llend, int128_exts64(TARGET_PAGE_MASK)); 36032e4d68SEugenio Pérez 37032e4d68SEugenio Pérez return llend; 38032e4d68SEugenio Pérez } 39032e4d68SEugenio Pérez 40013108b6SEugenio Pérez static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section, 41013108b6SEugenio Pérez uint64_t iova_min, 42013108b6SEugenio Pérez uint64_t iova_max) 43108a6481SCindy Lu { 44013108b6SEugenio Pérez Int128 llend; 45013108b6SEugenio Pérez 46013108b6SEugenio Pérez if ((!memory_region_is_ram(section->mr) && 47108a6481SCindy Lu !memory_region_is_iommu(section->mr)) || 48c64038c9SEugenio Pérez memory_region_is_protected(section->mr) || 49d60c75d2SJason Wang /* vhost-vDPA doesn't allow MMIO to be mapped */ 50013108b6SEugenio Pérez memory_region_is_ram_device(section->mr)) { 51013108b6SEugenio Pérez return true; 52013108b6SEugenio Pérez } 53013108b6SEugenio Pérez 54013108b6SEugenio Pérez if (section->offset_within_address_space < iova_min) { 55013108b6SEugenio Pérez error_report("RAM section out of device range (min=0x%" PRIx64 56013108b6SEugenio Pérez ", addr=0x%" HWADDR_PRIx ")", 57013108b6SEugenio Pérez iova_min, section->offset_within_address_space); 58013108b6SEugenio Pérez return true; 59013108b6SEugenio Pérez } 60013108b6SEugenio Pérez 61013108b6SEugenio Pérez llend = vhost_vdpa_section_end(section); 62013108b6SEugenio Pérez if (int128_gt(llend, int128_make64(iova_max))) { 63013108b6SEugenio Pérez error_report("RAM section out of device range (max=0x%" PRIx64 64013108b6SEugenio Pérez ", end addr=0x%" PRIx64 ")", 65013108b6SEugenio Pérez iova_max, int128_get64(llend)); 66013108b6SEugenio Pérez return true; 67013108b6SEugenio Pérez } 68013108b6SEugenio Pérez 69013108b6SEugenio Pérez return false; 70108a6481SCindy Lu } 71108a6481SCindy Lu 72108a6481SCindy Lu static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, 73108a6481SCindy Lu void *vaddr, bool readonly) 74108a6481SCindy Lu { 75386494f2SCindy Lu struct vhost_msg_v2 msg = {}; 76108a6481SCindy Lu int fd = v->device_fd; 77108a6481SCindy Lu int ret = 0; 78108a6481SCindy Lu 79108a6481SCindy Lu msg.type = v->msg_type; 80108a6481SCindy Lu msg.iotlb.iova = iova; 81108a6481SCindy Lu msg.iotlb.size = size; 82108a6481SCindy Lu msg.iotlb.uaddr = (uint64_t)(uintptr_t)vaddr; 83108a6481SCindy Lu msg.iotlb.perm = readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW; 84108a6481SCindy Lu msg.iotlb.type = VHOST_IOTLB_UPDATE; 85108a6481SCindy Lu 86778e67deSLaurent Vivier trace_vhost_vdpa_dma_map(v, fd, msg.type, msg.iotlb.iova, msg.iotlb.size, 87778e67deSLaurent Vivier msg.iotlb.uaddr, msg.iotlb.perm, msg.iotlb.type); 88778e67deSLaurent Vivier 89108a6481SCindy Lu if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { 90108a6481SCindy Lu error_report("failed to write, fd=%d, errno=%d (%s)", 91108a6481SCindy Lu fd, errno, strerror(errno)); 92108a6481SCindy Lu return -EIO ; 93108a6481SCindy Lu } 94108a6481SCindy Lu 95108a6481SCindy Lu return ret; 96108a6481SCindy Lu } 97108a6481SCindy Lu 98108a6481SCindy Lu static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, 99108a6481SCindy Lu hwaddr size) 100108a6481SCindy Lu { 101386494f2SCindy Lu struct vhost_msg_v2 msg = {}; 102108a6481SCindy Lu int fd = v->device_fd; 103108a6481SCindy Lu int ret = 0; 104108a6481SCindy Lu 105108a6481SCindy Lu msg.type = v->msg_type; 106108a6481SCindy Lu msg.iotlb.iova = iova; 107108a6481SCindy Lu msg.iotlb.size = size; 108108a6481SCindy Lu msg.iotlb.type = VHOST_IOTLB_INVALIDATE; 109108a6481SCindy Lu 110778e67deSLaurent Vivier trace_vhost_vdpa_dma_unmap(v, fd, msg.type, msg.iotlb.iova, 111778e67deSLaurent Vivier msg.iotlb.size, msg.iotlb.type); 112778e67deSLaurent Vivier 113108a6481SCindy Lu if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { 114108a6481SCindy Lu error_report("failed to write, fd=%d, errno=%d (%s)", 115108a6481SCindy Lu fd, errno, strerror(errno)); 116108a6481SCindy Lu return -EIO ; 117108a6481SCindy Lu } 118108a6481SCindy Lu 119108a6481SCindy Lu return ret; 120108a6481SCindy Lu } 121108a6481SCindy Lu 122e6db5df7SEugenio Pérez static void vhost_vdpa_listener_begin_batch(struct vhost_vdpa *v) 123a5bd0580SJason Wang { 124a5bd0580SJason Wang int fd = v->device_fd; 125e6db5df7SEugenio Pérez struct vhost_msg_v2 msg = { 126e6db5df7SEugenio Pérez .type = v->msg_type, 127e6db5df7SEugenio Pérez .iotlb.type = VHOST_IOTLB_BATCH_BEGIN, 128e6db5df7SEugenio Pérez }; 129a5bd0580SJason Wang 130a5bd0580SJason Wang if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { 131a5bd0580SJason Wang error_report("failed to write, fd=%d, errno=%d (%s)", 132a5bd0580SJason Wang fd, errno, strerror(errno)); 133a5bd0580SJason Wang } 134a5bd0580SJason Wang } 135a5bd0580SJason Wang 136e6db5df7SEugenio Pérez static void vhost_vdpa_iotlb_batch_begin_once(struct vhost_vdpa *v) 137e6db5df7SEugenio Pérez { 138e6db5df7SEugenio Pérez if (v->dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) && 139e6db5df7SEugenio Pérez !v->iotlb_batch_begin_sent) { 140e6db5df7SEugenio Pérez vhost_vdpa_listener_begin_batch(v); 141e6db5df7SEugenio Pérez } 142e6db5df7SEugenio Pérez 143e6db5df7SEugenio Pérez v->iotlb_batch_begin_sent = true; 144e6db5df7SEugenio Pérez } 145e6db5df7SEugenio Pérez 146a5bd0580SJason Wang static void vhost_vdpa_listener_commit(MemoryListener *listener) 147a5bd0580SJason Wang { 148a5bd0580SJason Wang struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); 149a5bd0580SJason Wang struct vhost_dev *dev = v->dev; 1508acb3218SPhilippe Mathieu-Daudé struct vhost_msg_v2 msg = {}; 151a5bd0580SJason Wang int fd = v->device_fd; 152a5bd0580SJason Wang 153a5bd0580SJason Wang if (!(dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) { 154a5bd0580SJason Wang return; 155a5bd0580SJason Wang } 156a5bd0580SJason Wang 157e6db5df7SEugenio Pérez if (!v->iotlb_batch_begin_sent) { 158e6db5df7SEugenio Pérez return; 159e6db5df7SEugenio Pérez } 160e6db5df7SEugenio Pérez 161a5bd0580SJason Wang msg.type = v->msg_type; 162a5bd0580SJason Wang msg.iotlb.type = VHOST_IOTLB_BATCH_END; 163a5bd0580SJason Wang 164a5bd0580SJason Wang if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { 165a5bd0580SJason Wang error_report("failed to write, fd=%d, errno=%d (%s)", 166a5bd0580SJason Wang fd, errno, strerror(errno)); 167a5bd0580SJason Wang } 168e6db5df7SEugenio Pérez 169e6db5df7SEugenio Pérez v->iotlb_batch_begin_sent = false; 170a5bd0580SJason Wang } 171a5bd0580SJason Wang 172108a6481SCindy Lu static void vhost_vdpa_listener_region_add(MemoryListener *listener, 173108a6481SCindy Lu MemoryRegionSection *section) 174108a6481SCindy Lu { 175108a6481SCindy Lu struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); 176108a6481SCindy Lu hwaddr iova; 177108a6481SCindy Lu Int128 llend, llsize; 178108a6481SCindy Lu void *vaddr; 179108a6481SCindy Lu int ret; 180108a6481SCindy Lu 181013108b6SEugenio Pérez if (vhost_vdpa_listener_skipped_section(section, v->iova_range.first, 182013108b6SEugenio Pérez v->iova_range.last)) { 183108a6481SCindy Lu return; 184108a6481SCindy Lu } 185108a6481SCindy Lu 186108a6481SCindy Lu if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK) != 187108a6481SCindy Lu (section->offset_within_region & ~TARGET_PAGE_MASK))) { 188108a6481SCindy Lu error_report("%s received unaligned region", __func__); 189108a6481SCindy Lu return; 190108a6481SCindy Lu } 191108a6481SCindy Lu 192108a6481SCindy Lu iova = TARGET_PAGE_ALIGN(section->offset_within_address_space); 193032e4d68SEugenio Pérez llend = vhost_vdpa_section_end(section); 194108a6481SCindy Lu if (int128_ge(int128_make64(iova), llend)) { 195108a6481SCindy Lu return; 196108a6481SCindy Lu } 197108a6481SCindy Lu 198108a6481SCindy Lu memory_region_ref(section->mr); 199108a6481SCindy Lu 200108a6481SCindy Lu /* Here we assume that memory_region_is_ram(section->mr)==true */ 201108a6481SCindy Lu 202108a6481SCindy Lu vaddr = memory_region_get_ram_ptr(section->mr) + 203108a6481SCindy Lu section->offset_within_region + 204108a6481SCindy Lu (iova - section->offset_within_address_space); 205108a6481SCindy Lu 206778e67deSLaurent Vivier trace_vhost_vdpa_listener_region_add(v, iova, int128_get64(llend), 207778e67deSLaurent Vivier vaddr, section->readonly); 208778e67deSLaurent Vivier 209108a6481SCindy Lu llsize = int128_sub(llend, int128_make64(iova)); 210108a6481SCindy Lu 211e6db5df7SEugenio Pérez vhost_vdpa_iotlb_batch_begin_once(v); 212108a6481SCindy Lu ret = vhost_vdpa_dma_map(v, iova, int128_get64(llsize), 213108a6481SCindy Lu vaddr, section->readonly); 214108a6481SCindy Lu if (ret) { 215108a6481SCindy Lu error_report("vhost vdpa map fail!"); 216108a6481SCindy Lu goto fail; 217108a6481SCindy Lu } 218108a6481SCindy Lu 219108a6481SCindy Lu return; 220108a6481SCindy Lu 221108a6481SCindy Lu fail: 222108a6481SCindy Lu /* 223108a6481SCindy Lu * On the initfn path, store the first error in the container so we 224108a6481SCindy Lu * can gracefully fail. Runtime, there's not much we can do other 225108a6481SCindy Lu * than throw a hardware error. 226108a6481SCindy Lu */ 227108a6481SCindy Lu error_report("vhost-vdpa: DMA mapping failed, unable to continue"); 228108a6481SCindy Lu return; 229108a6481SCindy Lu 230108a6481SCindy Lu } 231108a6481SCindy Lu 232108a6481SCindy Lu static void vhost_vdpa_listener_region_del(MemoryListener *listener, 233108a6481SCindy Lu MemoryRegionSection *section) 234108a6481SCindy Lu { 235108a6481SCindy Lu struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener); 236108a6481SCindy Lu hwaddr iova; 237108a6481SCindy Lu Int128 llend, llsize; 238108a6481SCindy Lu int ret; 239108a6481SCindy Lu 240013108b6SEugenio Pérez if (vhost_vdpa_listener_skipped_section(section, v->iova_range.first, 241013108b6SEugenio Pérez v->iova_range.last)) { 242108a6481SCindy Lu return; 243108a6481SCindy Lu } 244108a6481SCindy Lu 245108a6481SCindy Lu if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK) != 246108a6481SCindy Lu (section->offset_within_region & ~TARGET_PAGE_MASK))) { 247108a6481SCindy Lu error_report("%s received unaligned region", __func__); 248108a6481SCindy Lu return; 249108a6481SCindy Lu } 250108a6481SCindy Lu 251108a6481SCindy Lu iova = TARGET_PAGE_ALIGN(section->offset_within_address_space); 252032e4d68SEugenio Pérez llend = vhost_vdpa_section_end(section); 253108a6481SCindy Lu 254778e67deSLaurent Vivier trace_vhost_vdpa_listener_region_del(v, iova, int128_get64(llend)); 255778e67deSLaurent Vivier 256108a6481SCindy Lu if (int128_ge(int128_make64(iova), llend)) { 257108a6481SCindy Lu return; 258108a6481SCindy Lu } 259108a6481SCindy Lu 260108a6481SCindy Lu llsize = int128_sub(llend, int128_make64(iova)); 261108a6481SCindy Lu 262e6db5df7SEugenio Pérez vhost_vdpa_iotlb_batch_begin_once(v); 263108a6481SCindy Lu ret = vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize)); 264108a6481SCindy Lu if (ret) { 265108a6481SCindy Lu error_report("vhost_vdpa dma unmap error!"); 266108a6481SCindy Lu } 267108a6481SCindy Lu 268108a6481SCindy Lu memory_region_unref(section->mr); 269108a6481SCindy Lu } 270108a6481SCindy Lu /* 271108a6481SCindy Lu * IOTLB API is used by vhost-vpda which requires incremental updating 272108a6481SCindy Lu * of the mapping. So we can not use generic vhost memory listener which 273108a6481SCindy Lu * depends on the addnop(). 274108a6481SCindy Lu */ 275108a6481SCindy Lu static const MemoryListener vhost_vdpa_memory_listener = { 276142518bdSPeter Xu .name = "vhost-vdpa", 277a5bd0580SJason Wang .commit = vhost_vdpa_listener_commit, 278108a6481SCindy Lu .region_add = vhost_vdpa_listener_region_add, 279108a6481SCindy Lu .region_del = vhost_vdpa_listener_region_del, 280108a6481SCindy Lu }; 281108a6481SCindy Lu 282108a6481SCindy Lu static int vhost_vdpa_call(struct vhost_dev *dev, unsigned long int request, 283108a6481SCindy Lu void *arg) 284108a6481SCindy Lu { 285108a6481SCindy Lu struct vhost_vdpa *v = dev->opaque; 286108a6481SCindy Lu int fd = v->device_fd; 287f2a6e6c4SKevin Wolf int ret; 288108a6481SCindy Lu 289108a6481SCindy Lu assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); 290108a6481SCindy Lu 291f2a6e6c4SKevin Wolf ret = ioctl(fd, request, arg); 292f2a6e6c4SKevin Wolf return ret < 0 ? -errno : ret; 293108a6481SCindy Lu } 294108a6481SCindy Lu 295*3631151bSRoman Kagan static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) 296108a6481SCindy Lu { 297108a6481SCindy Lu uint8_t s; 298*3631151bSRoman Kagan int ret; 299108a6481SCindy Lu 300778e67deSLaurent Vivier trace_vhost_vdpa_add_status(dev, status); 301*3631151bSRoman Kagan ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s); 302*3631151bSRoman Kagan if (ret < 0) { 303*3631151bSRoman Kagan return ret; 304108a6481SCindy Lu } 305108a6481SCindy Lu 306108a6481SCindy Lu s |= status; 307108a6481SCindy Lu 308*3631151bSRoman Kagan ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s); 309*3631151bSRoman Kagan if (ret < 0) { 310*3631151bSRoman Kagan return ret; 311*3631151bSRoman Kagan } 312*3631151bSRoman Kagan 313*3631151bSRoman Kagan ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s); 314*3631151bSRoman Kagan if (ret < 0) { 315*3631151bSRoman Kagan return ret; 316*3631151bSRoman Kagan } 317*3631151bSRoman Kagan 318*3631151bSRoman Kagan if (!(s & status)) { 319*3631151bSRoman Kagan return -EIO; 320*3631151bSRoman Kagan } 321*3631151bSRoman Kagan 322*3631151bSRoman Kagan return 0; 323108a6481SCindy Lu } 324108a6481SCindy Lu 325013108b6SEugenio Pérez static void vhost_vdpa_get_iova_range(struct vhost_vdpa *v) 326013108b6SEugenio Pérez { 327013108b6SEugenio Pérez int ret = vhost_vdpa_call(v->dev, VHOST_VDPA_GET_IOVA_RANGE, 328013108b6SEugenio Pérez &v->iova_range); 329013108b6SEugenio Pérez if (ret != 0) { 330013108b6SEugenio Pérez v->iova_range.first = 0; 331013108b6SEugenio Pérez v->iova_range.last = UINT64_MAX; 332013108b6SEugenio Pérez } 333013108b6SEugenio Pérez 334013108b6SEugenio Pérez trace_vhost_vdpa_get_iova_range(v->dev, v->iova_range.first, 335013108b6SEugenio Pérez v->iova_range.last); 336013108b6SEugenio Pérez } 337013108b6SEugenio Pérez 3384d191cfdSJason Wang static bool vhost_vdpa_one_time_request(struct vhost_dev *dev) 3394d191cfdSJason Wang { 3404d191cfdSJason Wang struct vhost_vdpa *v = dev->opaque; 3414d191cfdSJason Wang 3424d191cfdSJason Wang return v->index != 0; 3434d191cfdSJason Wang } 3444d191cfdSJason Wang 34528770ff9SKevin Wolf static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) 346108a6481SCindy Lu { 347108a6481SCindy Lu struct vhost_vdpa *v; 348108a6481SCindy Lu assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); 349778e67deSLaurent Vivier trace_vhost_vdpa_init(dev, opaque); 350e1c1915bSDavid Hildenbrand int ret; 351e1c1915bSDavid Hildenbrand 352e1c1915bSDavid Hildenbrand /* 353e1c1915bSDavid Hildenbrand * Similar to VFIO, we end up pinning all guest memory and have to 354e1c1915bSDavid Hildenbrand * disable discarding of RAM. 355e1c1915bSDavid Hildenbrand */ 356e1c1915bSDavid Hildenbrand ret = ram_block_discard_disable(true); 357e1c1915bSDavid Hildenbrand if (ret) { 358e1c1915bSDavid Hildenbrand error_report("Cannot set discarding of RAM broken"); 359e1c1915bSDavid Hildenbrand return ret; 360e1c1915bSDavid Hildenbrand } 361108a6481SCindy Lu 362108a6481SCindy Lu v = opaque; 363a5bd0580SJason Wang v->dev = dev; 364108a6481SCindy Lu dev->opaque = opaque ; 365108a6481SCindy Lu v->listener = vhost_vdpa_memory_listener; 366108a6481SCindy Lu v->msg_type = VHOST_IOTLB_MSG_V2; 367108a6481SCindy Lu 368013108b6SEugenio Pérez vhost_vdpa_get_iova_range(v); 3694d191cfdSJason Wang 3704d191cfdSJason Wang if (vhost_vdpa_one_time_request(dev)) { 3714d191cfdSJason Wang return 0; 3724d191cfdSJason Wang } 3734d191cfdSJason Wang 374108a6481SCindy Lu vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | 375108a6481SCindy Lu VIRTIO_CONFIG_S_DRIVER); 376108a6481SCindy Lu 377108a6481SCindy Lu return 0; 378108a6481SCindy Lu } 379108a6481SCindy Lu 380d0416d48SJason Wang static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev, 381d0416d48SJason Wang int queue_index) 382d0416d48SJason Wang { 383d0416d48SJason Wang size_t page_size = qemu_real_host_page_size; 384d0416d48SJason Wang struct vhost_vdpa *v = dev->opaque; 385d0416d48SJason Wang VirtIODevice *vdev = dev->vdev; 386d0416d48SJason Wang VhostVDPAHostNotifier *n; 387d0416d48SJason Wang 388d0416d48SJason Wang n = &v->notifier[queue_index]; 389d0416d48SJason Wang 390d0416d48SJason Wang if (n->addr) { 391d0416d48SJason Wang virtio_queue_set_host_notifier_mr(vdev, queue_index, &n->mr, false); 392d0416d48SJason Wang object_unparent(OBJECT(&n->mr)); 393d0416d48SJason Wang munmap(n->addr, page_size); 394d0416d48SJason Wang n->addr = NULL; 395d0416d48SJason Wang } 396d0416d48SJason Wang } 397d0416d48SJason Wang 398d0416d48SJason Wang static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n) 399d0416d48SJason Wang { 400d0416d48SJason Wang int i; 401d0416d48SJason Wang 402d0416d48SJason Wang for (i = 0; i < n; i++) { 403d0416d48SJason Wang vhost_vdpa_host_notifier_uninit(dev, i); 404d0416d48SJason Wang } 405d0416d48SJason Wang } 406d0416d48SJason Wang 407d0416d48SJason Wang static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index) 408d0416d48SJason Wang { 409d0416d48SJason Wang size_t page_size = qemu_real_host_page_size; 410d0416d48SJason Wang struct vhost_vdpa *v = dev->opaque; 411d0416d48SJason Wang VirtIODevice *vdev = dev->vdev; 412d0416d48SJason Wang VhostVDPAHostNotifier *n; 413d0416d48SJason Wang int fd = v->device_fd; 414d0416d48SJason Wang void *addr; 415d0416d48SJason Wang char *name; 416d0416d48SJason Wang 417d0416d48SJason Wang vhost_vdpa_host_notifier_uninit(dev, queue_index); 418d0416d48SJason Wang 419d0416d48SJason Wang n = &v->notifier[queue_index]; 420d0416d48SJason Wang 421d0416d48SJason Wang addr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, fd, 422d0416d48SJason Wang queue_index * page_size); 423d0416d48SJason Wang if (addr == MAP_FAILED) { 424d0416d48SJason Wang goto err; 425d0416d48SJason Wang } 426d0416d48SJason Wang 427d0416d48SJason Wang name = g_strdup_printf("vhost-vdpa/host-notifier@%p mmaps[%d]", 428d0416d48SJason Wang v, queue_index); 429d0416d48SJason Wang memory_region_init_ram_device_ptr(&n->mr, OBJECT(vdev), name, 430d0416d48SJason Wang page_size, addr); 431d0416d48SJason Wang g_free(name); 432d0416d48SJason Wang 433d0416d48SJason Wang if (virtio_queue_set_host_notifier_mr(vdev, queue_index, &n->mr, true)) { 434d0416d48SJason Wang munmap(addr, page_size); 435d0416d48SJason Wang goto err; 436d0416d48SJason Wang } 437d0416d48SJason Wang n->addr = addr; 438d0416d48SJason Wang 439d0416d48SJason Wang return 0; 440d0416d48SJason Wang 441d0416d48SJason Wang err: 442d0416d48SJason Wang return -1; 443d0416d48SJason Wang } 444d0416d48SJason Wang 445d0416d48SJason Wang static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev) 446d0416d48SJason Wang { 447d0416d48SJason Wang int i; 448d0416d48SJason Wang 449d0416d48SJason Wang for (i = dev->vq_index; i < dev->vq_index + dev->nvqs; i++) { 450d0416d48SJason Wang if (vhost_vdpa_host_notifier_init(dev, i)) { 451d0416d48SJason Wang goto err; 452d0416d48SJason Wang } 453d0416d48SJason Wang } 454d0416d48SJason Wang 455d0416d48SJason Wang return; 456d0416d48SJason Wang 457d0416d48SJason Wang err: 458d0416d48SJason Wang vhost_vdpa_host_notifiers_uninit(dev, i); 459d0416d48SJason Wang return; 460d0416d48SJason Wang } 461d0416d48SJason Wang 462108a6481SCindy Lu static int vhost_vdpa_cleanup(struct vhost_dev *dev) 463108a6481SCindy Lu { 464108a6481SCindy Lu struct vhost_vdpa *v; 465108a6481SCindy Lu assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); 466108a6481SCindy Lu v = dev->opaque; 467778e67deSLaurent Vivier trace_vhost_vdpa_cleanup(dev, v); 468d0416d48SJason Wang vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); 469108a6481SCindy Lu memory_listener_unregister(&v->listener); 470108a6481SCindy Lu 471108a6481SCindy Lu dev->opaque = NULL; 472e1c1915bSDavid Hildenbrand ram_block_discard_disable(false); 473e1c1915bSDavid Hildenbrand 474108a6481SCindy Lu return 0; 475108a6481SCindy Lu } 476108a6481SCindy Lu 477108a6481SCindy Lu static int vhost_vdpa_memslots_limit(struct vhost_dev *dev) 478108a6481SCindy Lu { 479778e67deSLaurent Vivier trace_vhost_vdpa_memslots_limit(dev, INT_MAX); 480108a6481SCindy Lu return INT_MAX; 481108a6481SCindy Lu } 482108a6481SCindy Lu 483108a6481SCindy Lu static int vhost_vdpa_set_mem_table(struct vhost_dev *dev, 484108a6481SCindy Lu struct vhost_memory *mem) 485108a6481SCindy Lu { 4864d191cfdSJason Wang if (vhost_vdpa_one_time_request(dev)) { 4874d191cfdSJason Wang return 0; 4884d191cfdSJason Wang } 4894d191cfdSJason Wang 490778e67deSLaurent Vivier trace_vhost_vdpa_set_mem_table(dev, mem->nregions, mem->padding); 491778e67deSLaurent Vivier if (trace_event_get_state_backends(TRACE_VHOST_VDPA_SET_MEM_TABLE) && 492778e67deSLaurent Vivier trace_event_get_state_backends(TRACE_VHOST_VDPA_DUMP_REGIONS)) { 493778e67deSLaurent Vivier int i; 494778e67deSLaurent Vivier for (i = 0; i < mem->nregions; i++) { 495778e67deSLaurent Vivier trace_vhost_vdpa_dump_regions(dev, i, 496778e67deSLaurent Vivier mem->regions[i].guest_phys_addr, 497778e67deSLaurent Vivier mem->regions[i].memory_size, 498778e67deSLaurent Vivier mem->regions[i].userspace_addr, 499778e67deSLaurent Vivier mem->regions[i].flags_padding); 500778e67deSLaurent Vivier } 501778e67deSLaurent Vivier } 502108a6481SCindy Lu if (mem->padding) { 503*3631151bSRoman Kagan return -EINVAL; 504108a6481SCindy Lu } 505108a6481SCindy Lu 506108a6481SCindy Lu return 0; 507108a6481SCindy Lu } 508108a6481SCindy Lu 509108a6481SCindy Lu static int vhost_vdpa_set_features(struct vhost_dev *dev, 510108a6481SCindy Lu uint64_t features) 511108a6481SCindy Lu { 512108a6481SCindy Lu int ret; 5134d191cfdSJason Wang 5144d191cfdSJason Wang if (vhost_vdpa_one_time_request(dev)) { 5154d191cfdSJason Wang return 0; 5164d191cfdSJason Wang } 5174d191cfdSJason Wang 518778e67deSLaurent Vivier trace_vhost_vdpa_set_features(dev, features); 519108a6481SCindy Lu ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); 520108a6481SCindy Lu if (ret) { 521108a6481SCindy Lu return ret; 522108a6481SCindy Lu } 523108a6481SCindy Lu 524*3631151bSRoman Kagan return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); 525108a6481SCindy Lu } 526108a6481SCindy Lu 527a5bd0580SJason Wang static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) 528a5bd0580SJason Wang { 529a5bd0580SJason Wang uint64_t features; 530a5bd0580SJason Wang uint64_t f = 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 | 531a5bd0580SJason Wang 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH; 532a5bd0580SJason Wang int r; 533a5bd0580SJason Wang 534a5bd0580SJason Wang if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) { 5352a83e97eSJason Wang return -EFAULT; 536a5bd0580SJason Wang } 537a5bd0580SJason Wang 538a5bd0580SJason Wang features &= f; 5394d191cfdSJason Wang 5404d191cfdSJason Wang if (vhost_vdpa_one_time_request(dev)) { 541a5bd0580SJason Wang r = vhost_vdpa_call(dev, VHOST_SET_BACKEND_FEATURES, &features); 542a5bd0580SJason Wang if (r) { 5432a83e97eSJason Wang return -EFAULT; 544a5bd0580SJason Wang } 5454d191cfdSJason Wang } 546a5bd0580SJason Wang 547a5bd0580SJason Wang dev->backend_cap = features; 548a5bd0580SJason Wang 549a5bd0580SJason Wang return 0; 550a5bd0580SJason Wang } 551a5bd0580SJason Wang 552c232b8f4SZenghui Yu static int vhost_vdpa_get_device_id(struct vhost_dev *dev, 553108a6481SCindy Lu uint32_t *device_id) 554108a6481SCindy Lu { 555778e67deSLaurent Vivier int ret; 556778e67deSLaurent Vivier ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_DEVICE_ID, device_id); 557778e67deSLaurent Vivier trace_vhost_vdpa_get_device_id(dev, *device_id); 558778e67deSLaurent Vivier return ret; 559108a6481SCindy Lu } 560108a6481SCindy Lu 561108a6481SCindy Lu static int vhost_vdpa_reset_device(struct vhost_dev *dev) 562108a6481SCindy Lu { 563778e67deSLaurent Vivier int ret; 564108a6481SCindy Lu uint8_t status = 0; 565108a6481SCindy Lu 566778e67deSLaurent Vivier ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); 567778e67deSLaurent Vivier trace_vhost_vdpa_reset_device(dev, status); 568778e67deSLaurent Vivier return ret; 569108a6481SCindy Lu } 570108a6481SCindy Lu 571108a6481SCindy Lu static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) 572108a6481SCindy Lu { 573108a6481SCindy Lu assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs); 574108a6481SCindy Lu 575353244d8SJason Wang trace_vhost_vdpa_get_vq_index(dev, idx, idx); 576353244d8SJason Wang return idx; 577108a6481SCindy Lu } 578108a6481SCindy Lu 579108a6481SCindy Lu static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev) 580108a6481SCindy Lu { 581108a6481SCindy Lu int i; 582778e67deSLaurent Vivier trace_vhost_vdpa_set_vring_ready(dev); 583108a6481SCindy Lu for (i = 0; i < dev->nvqs; ++i) { 584108a6481SCindy Lu struct vhost_vring_state state = { 585108a6481SCindy Lu .index = dev->vq_index + i, 586108a6481SCindy Lu .num = 1, 587108a6481SCindy Lu }; 588108a6481SCindy Lu vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state); 589108a6481SCindy Lu } 590108a6481SCindy Lu return 0; 591108a6481SCindy Lu } 592108a6481SCindy Lu 593778e67deSLaurent Vivier static void vhost_vdpa_dump_config(struct vhost_dev *dev, const uint8_t *config, 594778e67deSLaurent Vivier uint32_t config_len) 595778e67deSLaurent Vivier { 596778e67deSLaurent Vivier int b, len; 597778e67deSLaurent Vivier char line[QEMU_HEXDUMP_LINE_LEN]; 598778e67deSLaurent Vivier 599778e67deSLaurent Vivier for (b = 0; b < config_len; b += 16) { 600778e67deSLaurent Vivier len = config_len - b; 601778e67deSLaurent Vivier qemu_hexdump_line(line, b, config, len, false); 602778e67deSLaurent Vivier trace_vhost_vdpa_dump_config(dev, line); 603778e67deSLaurent Vivier } 604778e67deSLaurent Vivier } 605778e67deSLaurent Vivier 606108a6481SCindy Lu static int vhost_vdpa_set_config(struct vhost_dev *dev, const uint8_t *data, 607108a6481SCindy Lu uint32_t offset, uint32_t size, 608108a6481SCindy Lu uint32_t flags) 609108a6481SCindy Lu { 610108a6481SCindy Lu struct vhost_vdpa_config *config; 611108a6481SCindy Lu int ret; 612108a6481SCindy Lu unsigned long config_size = offsetof(struct vhost_vdpa_config, buf); 613986d4f78SLi Qiang 614778e67deSLaurent Vivier trace_vhost_vdpa_set_config(dev, offset, size, flags); 615108a6481SCindy Lu config = g_malloc(size + config_size); 616108a6481SCindy Lu config->off = offset; 617108a6481SCindy Lu config->len = size; 618108a6481SCindy Lu memcpy(config->buf, data, size); 619778e67deSLaurent Vivier if (trace_event_get_state_backends(TRACE_VHOST_VDPA_SET_CONFIG) && 620778e67deSLaurent Vivier trace_event_get_state_backends(TRACE_VHOST_VDPA_DUMP_CONFIG)) { 621778e67deSLaurent Vivier vhost_vdpa_dump_config(dev, data, size); 622778e67deSLaurent Vivier } 623108a6481SCindy Lu ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG, config); 624108a6481SCindy Lu g_free(config); 625108a6481SCindy Lu return ret; 626108a6481SCindy Lu } 627108a6481SCindy Lu 628108a6481SCindy Lu static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, 62950de5138SKevin Wolf uint32_t config_len, Error **errp) 630108a6481SCindy Lu { 631108a6481SCindy Lu struct vhost_vdpa_config *v_config; 632108a6481SCindy Lu unsigned long config_size = offsetof(struct vhost_vdpa_config, buf); 633108a6481SCindy Lu int ret; 634108a6481SCindy Lu 635778e67deSLaurent Vivier trace_vhost_vdpa_get_config(dev, config, config_len); 636108a6481SCindy Lu v_config = g_malloc(config_len + config_size); 637108a6481SCindy Lu v_config->len = config_len; 638108a6481SCindy Lu v_config->off = 0; 639108a6481SCindy Lu ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_CONFIG, v_config); 640108a6481SCindy Lu memcpy(config, v_config->buf, config_len); 641108a6481SCindy Lu g_free(v_config); 642778e67deSLaurent Vivier if (trace_event_get_state_backends(TRACE_VHOST_VDPA_GET_CONFIG) && 643778e67deSLaurent Vivier trace_event_get_state_backends(TRACE_VHOST_VDPA_DUMP_CONFIG)) { 644778e67deSLaurent Vivier vhost_vdpa_dump_config(dev, config, config_len); 645778e67deSLaurent Vivier } 646108a6481SCindy Lu return ret; 647108a6481SCindy Lu } 648108a6481SCindy Lu 649108a6481SCindy Lu static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) 650108a6481SCindy Lu { 651108a6481SCindy Lu struct vhost_vdpa *v = dev->opaque; 652778e67deSLaurent Vivier trace_vhost_vdpa_dev_start(dev, started); 6534d191cfdSJason Wang 6544d191cfdSJason Wang if (started) { 6554d191cfdSJason Wang vhost_vdpa_host_notifiers_init(dev); 6564d191cfdSJason Wang vhost_vdpa_set_vring_ready(dev); 6574d191cfdSJason Wang } else { 6584d191cfdSJason Wang vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); 6594d191cfdSJason Wang } 6604d191cfdSJason Wang 661245cf2c2SEugenio Pérez if (dev->vq_index + dev->nvqs != dev->vq_index_end) { 6624d191cfdSJason Wang return 0; 6634d191cfdSJason Wang } 6644d191cfdSJason Wang 665108a6481SCindy Lu if (started) { 666108a6481SCindy Lu memory_listener_register(&v->listener, &address_space_memory); 667*3631151bSRoman Kagan return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); 668108a6481SCindy Lu } else { 669108a6481SCindy Lu vhost_vdpa_reset_device(dev); 670108a6481SCindy Lu vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | 671108a6481SCindy Lu VIRTIO_CONFIG_S_DRIVER); 672108a6481SCindy Lu memory_listener_unregister(&v->listener); 673108a6481SCindy Lu 674108a6481SCindy Lu return 0; 675108a6481SCindy Lu } 676108a6481SCindy Lu } 677108a6481SCindy Lu 678108a6481SCindy Lu static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, 679108a6481SCindy Lu struct vhost_log *log) 680108a6481SCindy Lu { 6814d191cfdSJason Wang if (vhost_vdpa_one_time_request(dev)) { 6824d191cfdSJason Wang return 0; 6834d191cfdSJason Wang } 6844d191cfdSJason Wang 685778e67deSLaurent Vivier trace_vhost_vdpa_set_log_base(dev, base, log->size, log->refcnt, log->fd, 686778e67deSLaurent Vivier log->log); 687108a6481SCindy Lu return vhost_vdpa_call(dev, VHOST_SET_LOG_BASE, &base); 688108a6481SCindy Lu } 689108a6481SCindy Lu 690108a6481SCindy Lu static int vhost_vdpa_set_vring_addr(struct vhost_dev *dev, 691108a6481SCindy Lu struct vhost_vring_addr *addr) 692108a6481SCindy Lu { 693778e67deSLaurent Vivier trace_vhost_vdpa_set_vring_addr(dev, addr->index, addr->flags, 694778e67deSLaurent Vivier addr->desc_user_addr, addr->used_user_addr, 695778e67deSLaurent Vivier addr->avail_user_addr, 696778e67deSLaurent Vivier addr->log_guest_addr); 697108a6481SCindy Lu return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); 698108a6481SCindy Lu } 699108a6481SCindy Lu 700108a6481SCindy Lu static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, 701108a6481SCindy Lu struct vhost_vring_state *ring) 702108a6481SCindy Lu { 703778e67deSLaurent Vivier trace_vhost_vdpa_set_vring_num(dev, ring->index, ring->num); 704108a6481SCindy Lu return vhost_vdpa_call(dev, VHOST_SET_VRING_NUM, ring); 705108a6481SCindy Lu } 706108a6481SCindy Lu 707108a6481SCindy Lu static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, 708108a6481SCindy Lu struct vhost_vring_state *ring) 709108a6481SCindy Lu { 710778e67deSLaurent Vivier trace_vhost_vdpa_set_vring_base(dev, ring->index, ring->num); 711108a6481SCindy Lu return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); 712108a6481SCindy Lu } 713108a6481SCindy Lu 714108a6481SCindy Lu static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, 715108a6481SCindy Lu struct vhost_vring_state *ring) 716108a6481SCindy Lu { 717778e67deSLaurent Vivier int ret; 718778e67deSLaurent Vivier 719778e67deSLaurent Vivier ret = vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); 720778e67deSLaurent Vivier trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num); 721778e67deSLaurent Vivier return ret; 722108a6481SCindy Lu } 723108a6481SCindy Lu 724108a6481SCindy Lu static int vhost_vdpa_set_vring_kick(struct vhost_dev *dev, 725108a6481SCindy Lu struct vhost_vring_file *file) 726108a6481SCindy Lu { 727778e67deSLaurent Vivier trace_vhost_vdpa_set_vring_kick(dev, file->index, file->fd); 728108a6481SCindy Lu return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); 729108a6481SCindy Lu } 730108a6481SCindy Lu 731108a6481SCindy Lu static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, 732108a6481SCindy Lu struct vhost_vring_file *file) 733108a6481SCindy Lu { 734778e67deSLaurent Vivier trace_vhost_vdpa_set_vring_call(dev, file->index, file->fd); 735108a6481SCindy Lu return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); 736108a6481SCindy Lu } 737634f7c89SCindy Lu static int vhost_vdpa_set_config_call(struct vhost_dev *dev, 738634f7c89SCindy Lu int fd) 739634f7c89SCindy Lu { 740634f7c89SCindy Lu trace_vhost_vdpa_set_config_call(dev, fd); 741634f7c89SCindy Lu return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, &fd); 742634f7c89SCindy Lu } 743108a6481SCindy Lu 744108a6481SCindy Lu static int vhost_vdpa_get_features(struct vhost_dev *dev, 745108a6481SCindy Lu uint64_t *features) 746108a6481SCindy Lu { 747778e67deSLaurent Vivier int ret; 748778e67deSLaurent Vivier 749778e67deSLaurent Vivier ret = vhost_vdpa_call(dev, VHOST_GET_FEATURES, features); 750778e67deSLaurent Vivier trace_vhost_vdpa_get_features(dev, *features); 751778e67deSLaurent Vivier return ret; 752108a6481SCindy Lu } 753108a6481SCindy Lu 754108a6481SCindy Lu static int vhost_vdpa_set_owner(struct vhost_dev *dev) 755108a6481SCindy Lu { 7564d191cfdSJason Wang if (vhost_vdpa_one_time_request(dev)) { 7574d191cfdSJason Wang return 0; 7584d191cfdSJason Wang } 7594d191cfdSJason Wang 760778e67deSLaurent Vivier trace_vhost_vdpa_set_owner(dev); 761108a6481SCindy Lu return vhost_vdpa_call(dev, VHOST_SET_OWNER, NULL); 762108a6481SCindy Lu } 763108a6481SCindy Lu 764108a6481SCindy Lu static int vhost_vdpa_vq_get_addr(struct vhost_dev *dev, 765108a6481SCindy Lu struct vhost_vring_addr *addr, struct vhost_virtqueue *vq) 766108a6481SCindy Lu { 767108a6481SCindy Lu assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); 768108a6481SCindy Lu addr->desc_user_addr = (uint64_t)(unsigned long)vq->desc_phys; 769108a6481SCindy Lu addr->avail_user_addr = (uint64_t)(unsigned long)vq->avail_phys; 770108a6481SCindy Lu addr->used_user_addr = (uint64_t)(unsigned long)vq->used_phys; 771778e67deSLaurent Vivier trace_vhost_vdpa_vq_get_addr(dev, vq, addr->desc_user_addr, 772778e67deSLaurent Vivier addr->avail_user_addr, addr->used_user_addr); 773108a6481SCindy Lu return 0; 774108a6481SCindy Lu } 775108a6481SCindy Lu 776108a6481SCindy Lu static bool vhost_vdpa_force_iommu(struct vhost_dev *dev) 777108a6481SCindy Lu { 778108a6481SCindy Lu return true; 779108a6481SCindy Lu } 780108a6481SCindy Lu 781108a6481SCindy Lu const VhostOps vdpa_ops = { 782108a6481SCindy Lu .backend_type = VHOST_BACKEND_TYPE_VDPA, 783108a6481SCindy Lu .vhost_backend_init = vhost_vdpa_init, 784108a6481SCindy Lu .vhost_backend_cleanup = vhost_vdpa_cleanup, 785108a6481SCindy Lu .vhost_set_log_base = vhost_vdpa_set_log_base, 786108a6481SCindy Lu .vhost_set_vring_addr = vhost_vdpa_set_vring_addr, 787108a6481SCindy Lu .vhost_set_vring_num = vhost_vdpa_set_vring_num, 788108a6481SCindy Lu .vhost_set_vring_base = vhost_vdpa_set_vring_base, 789108a6481SCindy Lu .vhost_get_vring_base = vhost_vdpa_get_vring_base, 790108a6481SCindy Lu .vhost_set_vring_kick = vhost_vdpa_set_vring_kick, 791108a6481SCindy Lu .vhost_set_vring_call = vhost_vdpa_set_vring_call, 792108a6481SCindy Lu .vhost_get_features = vhost_vdpa_get_features, 793a5bd0580SJason Wang .vhost_set_backend_cap = vhost_vdpa_set_backend_cap, 794108a6481SCindy Lu .vhost_set_owner = vhost_vdpa_set_owner, 795108a6481SCindy Lu .vhost_set_vring_endian = NULL, 796108a6481SCindy Lu .vhost_backend_memslots_limit = vhost_vdpa_memslots_limit, 797108a6481SCindy Lu .vhost_set_mem_table = vhost_vdpa_set_mem_table, 798108a6481SCindy Lu .vhost_set_features = vhost_vdpa_set_features, 799108a6481SCindy Lu .vhost_reset_device = vhost_vdpa_reset_device, 800108a6481SCindy Lu .vhost_get_vq_index = vhost_vdpa_get_vq_index, 801108a6481SCindy Lu .vhost_get_config = vhost_vdpa_get_config, 802108a6481SCindy Lu .vhost_set_config = vhost_vdpa_set_config, 803108a6481SCindy Lu .vhost_requires_shm_log = NULL, 804108a6481SCindy Lu .vhost_migration_done = NULL, 805108a6481SCindy Lu .vhost_backend_can_merge = NULL, 806108a6481SCindy Lu .vhost_net_set_mtu = NULL, 807108a6481SCindy Lu .vhost_set_iotlb_callback = NULL, 808108a6481SCindy Lu .vhost_send_device_iotlb_msg = NULL, 809108a6481SCindy Lu .vhost_dev_start = vhost_vdpa_dev_start, 810108a6481SCindy Lu .vhost_get_device_id = vhost_vdpa_get_device_id, 811108a6481SCindy Lu .vhost_vq_get_addr = vhost_vdpa_vq_get_addr, 812108a6481SCindy Lu .vhost_force_iommu = vhost_vdpa_force_iommu, 813634f7c89SCindy Lu .vhost_set_config_call = vhost_vdpa_set_config_call, 814108a6481SCindy Lu }; 815