| 1160 | #endif |
| 1161 | |
| 1162 | static int |
| 1163 | vhost_user_postcopy_register(struct virtio_net *dev, int main_fd, |
| 1164 | struct vhu_msg_context *ctx) |
| 1165 | { |
| 1166 | struct VhostUserMemory *memory; |
| 1167 | struct rte_vhost_mem_region *reg; |
| 1168 | struct vhu_msg_context ack_ctx; |
| 1169 | uint32_t i; |
| 1170 | |
| 1171 | if (!dev->postcopy_listening) |
| 1172 | return 0; |
| 1173 | |
| 1174 | /* |
| 1175 | * We haven't a better way right now than sharing |
| 1176 | * DPDK's virtual address with Qemu, so that Qemu can |
| 1177 | * retrieve the region offset when handling userfaults. |
| 1178 | */ |
| 1179 | memory = &ctx->msg.payload.memory; |
| 1180 | for (i = 0; i < memory->nregions; i++) { |
| 1181 | reg = &dev->mem->regions[i]; |
| 1182 | memory->regions[i].userspace_addr = reg->host_user_addr; |
| 1183 | } |
| 1184 | |
| 1185 | /* Send the addresses back to qemu */ |
| 1186 | ctx->fd_num = 0; |
| 1187 | send_vhost_reply(dev, main_fd, ctx); |
| 1188 | |
| 1189 | /* Wait for qemu to acknowledge it got the addresses |
| 1190 | * we've got to wait before we're allowed to generate faults. |
| 1191 | */ |
| 1192 | if (read_vhost_message(dev, main_fd, &ack_ctx) <= 0) { |
| 1193 | VHOST_LOG_CONFIG(dev->ifname, ERR, |
| 1194 | "failed to read qemu ack on postcopy set-mem-table\n"); |
| 1195 | return -1; |
| 1196 | } |
| 1197 | |
| 1198 | if (validate_msg_fds(dev, &ack_ctx, 0) != 0) |
| 1199 | return -1; |
| 1200 | |
| 1201 | if (ack_ctx.msg.request.frontend != VHOST_USER_SET_MEM_TABLE) { |
| 1202 | VHOST_LOG_CONFIG(dev->ifname, ERR, |
| 1203 | "bad qemu ack on postcopy set-mem-table (%d)\n", |
| 1204 | ack_ctx.msg.request.frontend); |
| 1205 | return -1; |
| 1206 | } |
| 1207 | |
| 1208 | /* Now userfault register and we can use the memory */ |
| 1209 | for (i = 0; i < memory->nregions; i++) { |
| 1210 | reg = &dev->mem->regions[i]; |
| 1211 | if (vhost_user_postcopy_region_register(dev, reg) < 0) |
| 1212 | return -1; |
| 1213 | } |
| 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | static int |
| 1219 | vhost_user_mmap_region(struct virtio_net *dev, |
no test coverage detected