| 66 | } |
| 67 | |
| 68 | static int |
| 69 | vduse_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm __rte_unused) |
| 70 | { |
| 71 | struct vduse_iotlb_entry entry; |
| 72 | uint64_t size, page_size; |
| 73 | struct stat stat; |
| 74 | void *mmap_addr; |
| 75 | int fd, ret; |
| 76 | |
| 77 | entry.start = iova; |
| 78 | entry.last = iova + 1; |
| 79 | |
| 80 | ret = ioctl(dev->vduse_dev_fd, VDUSE_IOTLB_GET_FD, &entry); |
| 81 | if (ret < 0) { |
| 82 | VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to get IOTLB entry for 0x%" PRIx64 "\n", |
| 83 | iova); |
| 84 | return -1; |
| 85 | } |
| 86 | |
| 87 | fd = ret; |
| 88 | |
| 89 | VHOST_LOG_CONFIG(dev->ifname, DEBUG, "New IOTLB entry:\n"); |
| 90 | VHOST_LOG_CONFIG(dev->ifname, DEBUG, "\tIOVA: %" PRIx64 " - %" PRIx64 "\n", |
| 91 | (uint64_t)entry.start, (uint64_t)entry.last); |
| 92 | VHOST_LOG_CONFIG(dev->ifname, DEBUG, "\toffset: %" PRIx64 "\n", (uint64_t)entry.offset); |
| 93 | VHOST_LOG_CONFIG(dev->ifname, DEBUG, "\tfd: %d\n", fd); |
| 94 | VHOST_LOG_CONFIG(dev->ifname, DEBUG, "\tperm: %x\n", entry.perm); |
| 95 | |
| 96 | size = entry.last - entry.start + 1; |
| 97 | mmap_addr = mmap(0, size + entry.offset, entry.perm, MAP_SHARED, fd, 0); |
| 98 | if (!mmap_addr) { |
| 99 | VHOST_LOG_CONFIG(dev->ifname, ERR, |
| 100 | "Failed to mmap IOTLB entry for 0x%" PRIx64 "\n", iova); |
| 101 | ret = -1; |
| 102 | goto close_fd; |
| 103 | } |
| 104 | |
| 105 | ret = fstat(fd, &stat); |
| 106 | if (ret < 0) { |
| 107 | VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to get page size.\n"); |
| 108 | munmap(mmap_addr, entry.offset + size); |
| 109 | goto close_fd; |
| 110 | } |
| 111 | page_size = (uint64_t)stat.st_blksize; |
| 112 | |
| 113 | vhost_user_iotlb_cache_insert(dev, entry.start, (uint64_t)(uintptr_t)mmap_addr, |
| 114 | entry.offset, size, page_size, entry.perm); |
| 115 | |
| 116 | ret = 0; |
| 117 | close_fd: |
| 118 | close(fd); |
| 119 | |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | static struct vhost_backend_ops vduse_backend_ops = { |
| 124 | .iotlb_miss = vduse_iotlb_miss, |
nothing calls this directly
no test coverage detected