4 * Copyright(c) 2017-2018 Intel Corporation.
5 * Copyright(c) 2020 Red Hat, Inc.
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.
12 #include "qemu/osdep.h"
14 #include "hw/virtio/virtio-net.h"
15 #include "net/vhost_net.h"
16 #include "net/vhost-vdpa.h"
17 #include "hw/virtio/vhost-vdpa.h"
18 #include "qemu/config-file.h"
19 #include "qemu/error-report.h"
21 #include "qemu/memalign.h"
22 #include "qemu/option.h"
23 #include "qapi/error.h"
24 #include <linux/vhost.h>
25 #include <sys/ioctl.h>
27 #include "standard-headers/linux/virtio_net.h"
28 #include "monitor/monitor.h"
29 #include "hw/virtio/vhost.h"
31 /* Todo:need to add the multiqueue support here */
32 typedef struct VhostVDPAState
{
34 struct vhost_vdpa vhost_vdpa
;
35 VHostNetState
*vhost_net
;
37 /* Control commands shadow buffers */
38 void *cvq_cmd_out_buffer
;
39 virtio_net_ctrl_ack
*status
;
44 const int vdpa_feature_bits
[] = {
45 VIRTIO_F_NOTIFY_ON_EMPTY
,
46 VIRTIO_RING_F_INDIRECT_DESC
,
47 VIRTIO_RING_F_EVENT_IDX
,
51 VIRTIO_NET_F_GUEST_CSUM
,
53 VIRTIO_NET_F_GUEST_TSO4
,
54 VIRTIO_NET_F_GUEST_TSO6
,
55 VIRTIO_NET_F_GUEST_ECN
,
56 VIRTIO_NET_F_GUEST_UFO
,
57 VIRTIO_NET_F_HOST_TSO4
,
58 VIRTIO_NET_F_HOST_TSO6
,
59 VIRTIO_NET_F_HOST_ECN
,
60 VIRTIO_NET_F_HOST_UFO
,
61 VIRTIO_NET_F_MRG_RXBUF
,
64 VIRTIO_NET_F_CTRL_RX_EXTRA
,
65 VIRTIO_NET_F_CTRL_VLAN
,
66 VIRTIO_NET_F_GUEST_ANNOUNCE
,
67 VIRTIO_NET_F_CTRL_MAC_ADDR
,
71 VIRTIO_F_IOMMU_PLATFORM
,
74 VIRTIO_NET_F_HASH_REPORT
,
75 VIRTIO_NET_F_GUEST_ANNOUNCE
,
77 VHOST_INVALID_FEATURE_BIT
80 /** Supported device specific feature bits with SVQ */
81 static const uint64_t vdpa_svq_device_features
=
82 BIT_ULL(VIRTIO_NET_F_CSUM
) |
83 BIT_ULL(VIRTIO_NET_F_GUEST_CSUM
) |
84 BIT_ULL(VIRTIO_NET_F_MTU
) |
85 BIT_ULL(VIRTIO_NET_F_MAC
) |
86 BIT_ULL(VIRTIO_NET_F_GUEST_TSO4
) |
87 BIT_ULL(VIRTIO_NET_F_GUEST_TSO6
) |
88 BIT_ULL(VIRTIO_NET_F_GUEST_ECN
) |
89 BIT_ULL(VIRTIO_NET_F_GUEST_UFO
) |
90 BIT_ULL(VIRTIO_NET_F_HOST_TSO4
) |
91 BIT_ULL(VIRTIO_NET_F_HOST_TSO6
) |
92 BIT_ULL(VIRTIO_NET_F_HOST_ECN
) |
93 BIT_ULL(VIRTIO_NET_F_HOST_UFO
) |
94 BIT_ULL(VIRTIO_NET_F_MRG_RXBUF
) |
95 BIT_ULL(VIRTIO_NET_F_STATUS
) |
96 BIT_ULL(VIRTIO_NET_F_CTRL_VQ
) |
97 BIT_ULL(VIRTIO_NET_F_MQ
) |
98 BIT_ULL(VIRTIO_F_ANY_LAYOUT
) |
99 BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR
) |
100 BIT_ULL(VIRTIO_NET_F_RSC_EXT
) |
101 BIT_ULL(VIRTIO_NET_F_STANDBY
);
103 VHostNetState
*vhost_vdpa_get_vhost_net(NetClientState
*nc
)
105 VhostVDPAState
*s
= DO_UPCAST(VhostVDPAState
, nc
, nc
);
106 assert(nc
->info
->type
== NET_CLIENT_DRIVER_VHOST_VDPA
);
110 static int vhost_vdpa_net_check_device_id(struct vhost_net
*net
)
114 struct vhost_dev
*hdev
;
116 hdev
= (struct vhost_dev
*)&net
->dev
;
117 ret
= hdev
->vhost_ops
->vhost_get_device_id(hdev
, &device_id
);
118 if (device_id
!= VIRTIO_ID_NET
) {
124 static int vhost_vdpa_add(NetClientState
*ncs
, void *be
,
125 int queue_pair_index
, int nvqs
)
127 VhostNetOptions options
;
128 struct vhost_net
*net
= NULL
;
132 options
.backend_type
= VHOST_BACKEND_TYPE_VDPA
;
133 assert(ncs
->info
->type
== NET_CLIENT_DRIVER_VHOST_VDPA
);
134 s
= DO_UPCAST(VhostVDPAState
, nc
, ncs
);
135 options
.net_backend
= ncs
;
137 options
.busyloop_timeout
= 0;
140 net
= vhost_net_init(&options
);
142 error_report("failed to init vhost_net for queue");
146 ret
= vhost_vdpa_net_check_device_id(net
);
152 vhost_net_cleanup(net
);
158 static void vhost_vdpa_cleanup(NetClientState
*nc
)
160 VhostVDPAState
*s
= DO_UPCAST(VhostVDPAState
, nc
, nc
);
161 struct vhost_dev
*dev
= &s
->vhost_net
->dev
;
163 qemu_vfree(s
->cvq_cmd_out_buffer
);
164 qemu_vfree(s
->status
);
165 if (dev
->vq_index
+ dev
->nvqs
== dev
->vq_index_end
) {
166 g_clear_pointer(&s
->vhost_vdpa
.iova_tree
, vhost_iova_tree_delete
);
169 vhost_net_cleanup(s
->vhost_net
);
170 g_free(s
->vhost_net
);
173 if (s
->vhost_vdpa
.device_fd
>= 0) {
174 qemu_close(s
->vhost_vdpa
.device_fd
);
175 s
->vhost_vdpa
.device_fd
= -1;
179 static bool vhost_vdpa_has_vnet_hdr(NetClientState
*nc
)
181 assert(nc
->info
->type
== NET_CLIENT_DRIVER_VHOST_VDPA
);
186 static bool vhost_vdpa_has_ufo(NetClientState
*nc
)
188 assert(nc
->info
->type
== NET_CLIENT_DRIVER_VHOST_VDPA
);
189 VhostVDPAState
*s
= DO_UPCAST(VhostVDPAState
, nc
, nc
);
190 uint64_t features
= 0;
191 features
|= (1ULL << VIRTIO_NET_F_HOST_UFO
);
192 features
= vhost_net_get_features(s
->vhost_net
, features
);
193 return !!(features
& (1ULL << VIRTIO_NET_F_HOST_UFO
));
197 static bool vhost_vdpa_check_peer_type(NetClientState
*nc
, ObjectClass
*oc
,
200 const char *driver
= object_class_get_name(oc
);
202 if (!g_str_has_prefix(driver
, "virtio-net-")) {
203 error_setg(errp
, "vhost-vdpa requires frontend driver virtio-net-*");
210 /** Dummy receive in case qemu falls back to userland tap networking */
211 static ssize_t
vhost_vdpa_receive(NetClientState
*nc
, const uint8_t *buf
,
217 static NetClientInfo net_vhost_vdpa_info
= {
218 .type
= NET_CLIENT_DRIVER_VHOST_VDPA
,
219 .size
= sizeof(VhostVDPAState
),
220 .receive
= vhost_vdpa_receive
,
221 .cleanup
= vhost_vdpa_cleanup
,
222 .has_vnet_hdr
= vhost_vdpa_has_vnet_hdr
,
223 .has_ufo
= vhost_vdpa_has_ufo
,
224 .check_peer_type
= vhost_vdpa_check_peer_type
,
227 static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa
*v
, void *addr
)
229 VhostIOVATree
*tree
= v
->iova_tree
;
232 * No need to specify size or to look for more translations since
233 * this contiguous chunk was allocated by us.
235 .translated_addr
= (hwaddr
)(uintptr_t)addr
,
237 const DMAMap
*map
= vhost_iova_tree_find_iova(tree
, &needle
);
240 if (unlikely(!map
)) {
241 error_report("Cannot locate expected map");
245 r
= vhost_vdpa_dma_unmap(v
, map
->iova
, map
->size
+ 1);
246 if (unlikely(r
!= 0)) {
247 error_report("Device cannot unmap: %s(%d)", g_strerror(r
), r
);
250 vhost_iova_tree_remove(tree
, *map
);
253 static size_t vhost_vdpa_net_cvq_cmd_len(void)
256 * MAC_TABLE_SET is the ctrl command that produces the longer out buffer.
257 * In buffer is always 1 byte, so it should fit here
259 return sizeof(struct virtio_net_ctrl_hdr
) +
260 2 * sizeof(struct virtio_net_ctrl_mac
) +
261 MAC_TABLE_ENTRIES
* ETH_ALEN
;
264 static size_t vhost_vdpa_net_cvq_cmd_page_len(void)
266 return ROUND_UP(vhost_vdpa_net_cvq_cmd_len(), qemu_real_host_page_size());
269 /** Map CVQ buffer. */
270 static int vhost_vdpa_cvq_map_buf(struct vhost_vdpa
*v
, void *buf
, size_t size
,
276 map
.translated_addr
= (hwaddr
)(uintptr_t)buf
;
278 map
.perm
= write
? IOMMU_RW
: IOMMU_RO
,
279 r
= vhost_iova_tree_map_alloc(v
->iova_tree
, &map
);
280 if (unlikely(r
!= IOVA_OK
)) {
281 error_report("Cannot map injected element");
285 r
= vhost_vdpa_dma_map(v
, map
.iova
, vhost_vdpa_net_cvq_cmd_page_len(), buf
,
287 if (unlikely(r
< 0)) {
294 vhost_iova_tree_remove(v
->iova_tree
, map
);
298 static int vhost_vdpa_net_cvq_start(NetClientState
*nc
)
303 assert(nc
->info
->type
== NET_CLIENT_DRIVER_VHOST_VDPA
);
305 s
= DO_UPCAST(VhostVDPAState
, nc
, nc
);
306 if (!s
->vhost_vdpa
.shadow_vqs_enabled
) {
310 r
= vhost_vdpa_cvq_map_buf(&s
->vhost_vdpa
, s
->cvq_cmd_out_buffer
,
311 vhost_vdpa_net_cvq_cmd_page_len(), false);
312 if (unlikely(r
< 0)) {
316 r
= vhost_vdpa_cvq_map_buf(&s
->vhost_vdpa
, s
->status
,
317 vhost_vdpa_net_cvq_cmd_page_len(), true);
318 if (unlikely(r
< 0)) {
319 vhost_vdpa_cvq_unmap_buf(&s
->vhost_vdpa
, s
->cvq_cmd_out_buffer
);
325 static void vhost_vdpa_net_cvq_stop(NetClientState
*nc
)
327 VhostVDPAState
*s
= DO_UPCAST(VhostVDPAState
, nc
, nc
);
329 assert(nc
->info
->type
== NET_CLIENT_DRIVER_VHOST_VDPA
);
331 if (s
->vhost_vdpa
.shadow_vqs_enabled
) {
332 vhost_vdpa_cvq_unmap_buf(&s
->vhost_vdpa
, s
->cvq_cmd_out_buffer
);
333 vhost_vdpa_cvq_unmap_buf(&s
->vhost_vdpa
, s
->status
);
337 static ssize_t
vhost_vdpa_net_cvq_add(VhostVDPAState
*s
, size_t out_len
,
340 /* Buffers for the device */
341 const struct iovec out
= {
342 .iov_base
= s
->cvq_cmd_out_buffer
,
345 const struct iovec in
= {
346 .iov_base
= s
->status
,
347 .iov_len
= sizeof(virtio_net_ctrl_ack
),
349 VhostShadowVirtqueue
*svq
= g_ptr_array_index(s
->vhost_vdpa
.shadow_vqs
, 0);
352 r
= vhost_svq_add(svq
, &out
, 1, &in
, 1, NULL
);
353 if (unlikely(r
!= 0)) {
354 if (unlikely(r
== -ENOSPC
)) {
355 qemu_log_mask(LOG_GUEST_ERROR
, "%s: No space on device queue\n",
362 * We can poll here since we've had BQL from the time we sent the
363 * descriptor. Also, we need to take the answer before SVQ pulls by itself,
364 * when BQL is released
366 return vhost_svq_poll(svq
);
369 static ssize_t
vhost_vdpa_net_load_cmd(VhostVDPAState
*s
, uint8_t class,
370 uint8_t cmd
, const void *data
,
373 const struct virtio_net_ctrl_hdr ctrl
= {
378 assert(data_size
< vhost_vdpa_net_cvq_cmd_page_len() - sizeof(ctrl
));
380 memcpy(s
->cvq_cmd_out_buffer
, &ctrl
, sizeof(ctrl
));
381 memcpy(s
->cvq_cmd_out_buffer
+ sizeof(ctrl
), data
, data_size
);
383 return vhost_vdpa_net_cvq_add(s
, sizeof(ctrl
) + data_size
,
384 sizeof(virtio_net_ctrl_ack
));
387 static int vhost_vdpa_net_load_mac(VhostVDPAState
*s
, const VirtIONet
*n
)
389 uint64_t features
= n
->parent_obj
.guest_features
;
390 if (features
& BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR
)) {
391 ssize_t dev_written
= vhost_vdpa_net_load_cmd(s
, VIRTIO_NET_CTRL_MAC
,
392 VIRTIO_NET_CTRL_MAC_ADDR_SET
,
393 n
->mac
, sizeof(n
->mac
));
394 if (unlikely(dev_written
< 0)) {
398 return *s
->status
!= VIRTIO_NET_OK
;
404 static int vhost_vdpa_net_load_mq(VhostVDPAState
*s
,
407 struct virtio_net_ctrl_mq mq
;
408 uint64_t features
= n
->parent_obj
.guest_features
;
411 if (!(features
& BIT_ULL(VIRTIO_NET_F_MQ
))) {
415 mq
.virtqueue_pairs
= cpu_to_le16(n
->curr_queue_pairs
);
416 dev_written
= vhost_vdpa_net_load_cmd(s
, VIRTIO_NET_CTRL_MQ
,
417 VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
, &mq
,
419 if (unlikely(dev_written
< 0)) {
423 return *s
->status
!= VIRTIO_NET_OK
;
426 static int vhost_vdpa_net_load(NetClientState
*nc
)
428 VhostVDPAState
*s
= DO_UPCAST(VhostVDPAState
, nc
, nc
);
429 struct vhost_vdpa
*v
= &s
->vhost_vdpa
;
433 assert(nc
->info
->type
== NET_CLIENT_DRIVER_VHOST_VDPA
);
435 if (!v
->shadow_vqs_enabled
) {
439 n
= VIRTIO_NET(v
->dev
->vdev
);
440 r
= vhost_vdpa_net_load_mac(s
, n
);
441 if (unlikely(r
< 0)) {
444 r
= vhost_vdpa_net_load_mq(s
, n
);
452 static NetClientInfo net_vhost_vdpa_cvq_info
= {
453 .type
= NET_CLIENT_DRIVER_VHOST_VDPA
,
454 .size
= sizeof(VhostVDPAState
),
455 .receive
= vhost_vdpa_receive
,
456 .start
= vhost_vdpa_net_cvq_start
,
457 .load
= vhost_vdpa_net_load
,
458 .stop
= vhost_vdpa_net_cvq_stop
,
459 .cleanup
= vhost_vdpa_cleanup
,
460 .has_vnet_hdr
= vhost_vdpa_has_vnet_hdr
,
461 .has_ufo
= vhost_vdpa_has_ufo
,
462 .check_peer_type
= vhost_vdpa_check_peer_type
,
466 * Do not forward commands not supported by SVQ. Otherwise, the device could
467 * accept it and qemu would not know how to update the device model.
469 static bool vhost_vdpa_net_cvq_validate_cmd(const void *out_buf
, size_t len
)
471 struct virtio_net_ctrl_hdr ctrl
;
473 if (unlikely(len
< sizeof(ctrl
))) {
474 qemu_log_mask(LOG_GUEST_ERROR
,
475 "%s: invalid legnth of out buffer %zu\n", __func__
, len
);
479 memcpy(&ctrl
, out_buf
, sizeof(ctrl
));
480 switch (ctrl
.class) {
481 case VIRTIO_NET_CTRL_MAC
:
483 case VIRTIO_NET_CTRL_MAC_ADDR_SET
:
486 qemu_log_mask(LOG_GUEST_ERROR
, "%s: invalid mac cmd %u\n",
490 case VIRTIO_NET_CTRL_MQ
:
492 case VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
:
495 qemu_log_mask(LOG_GUEST_ERROR
, "%s: invalid mq cmd %u\n",
500 qemu_log_mask(LOG_GUEST_ERROR
, "%s: invalid control class %u\n",
501 __func__
, ctrl
.class);
508 * Validate and copy control virtqueue commands.
510 * Following QEMU guidelines, we offer a copy of the buffers to the device to
511 * prevent TOCTOU bugs.
513 static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue
*svq
,
514 VirtQueueElement
*elem
,
517 VhostVDPAState
*s
= opaque
;
519 virtio_net_ctrl_ack status
= VIRTIO_NET_ERR
;
520 /* Out buffer sent to both the vdpa device and the device model */
522 .iov_base
= s
->cvq_cmd_out_buffer
,
524 /* in buffer used for device model */
525 const struct iovec in
= {
527 .iov_len
= sizeof(status
),
529 ssize_t dev_written
= -EINVAL
;
532 out
.iov_len
= iov_to_buf(elem
->out_sg
, elem
->out_num
, 0,
533 s
->cvq_cmd_out_buffer
,
534 vhost_vdpa_net_cvq_cmd_len());
535 ok
= vhost_vdpa_net_cvq_validate_cmd(s
->cvq_cmd_out_buffer
, out
.iov_len
);
540 dev_written
= vhost_vdpa_net_cvq_add(s
, out
.iov_len
, sizeof(status
));
541 if (unlikely(dev_written
< 0)) {
545 if (unlikely(dev_written
< sizeof(status
))) {
546 error_report("Insufficient written data (%zu)", dev_written
);
550 if (*s
->status
!= VIRTIO_NET_OK
) {
551 return VIRTIO_NET_ERR
;
554 status
= VIRTIO_NET_ERR
;
555 virtio_net_handle_ctrl_iov(svq
->vdev
, &in
, 1, &out
, 1);
556 if (status
!= VIRTIO_NET_OK
) {
557 error_report("Bad CVQ processing in model");
561 in_len
= iov_from_buf(elem
->in_sg
, elem
->in_num
, 0, &status
,
563 if (unlikely(in_len
< sizeof(status
))) {
564 error_report("Bad device CVQ written length");
566 vhost_svq_push_elem(svq
, elem
, MIN(in_len
, sizeof(status
)));
568 return dev_written
< 0 ? dev_written
: 0;
571 static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops
= {
572 .avail_handler
= vhost_vdpa_net_handle_ctrl_avail
,
575 static NetClientState
*net_vhost_vdpa_init(NetClientState
*peer
,
579 int queue_pair_index
,
583 VhostIOVATree
*iova_tree
)
585 NetClientState
*nc
= NULL
;
590 nc
= qemu_new_net_client(&net_vhost_vdpa_info
, peer
, device
,
593 nc
= qemu_new_net_control_client(&net_vhost_vdpa_cvq_info
, peer
,
596 snprintf(nc
->info_str
, sizeof(nc
->info_str
), TYPE_VHOST_VDPA
);
597 s
= DO_UPCAST(VhostVDPAState
, nc
, nc
);
599 s
->vhost_vdpa
.device_fd
= vdpa_device_fd
;
600 s
->vhost_vdpa
.index
= queue_pair_index
;
601 s
->vhost_vdpa
.shadow_vqs_enabled
= svq
;
602 s
->vhost_vdpa
.iova_tree
= iova_tree
;
604 s
->cvq_cmd_out_buffer
= qemu_memalign(qemu_real_host_page_size(),
605 vhost_vdpa_net_cvq_cmd_page_len());
606 memset(s
->cvq_cmd_out_buffer
, 0, vhost_vdpa_net_cvq_cmd_page_len());
607 s
->status
= qemu_memalign(qemu_real_host_page_size(),
608 vhost_vdpa_net_cvq_cmd_page_len());
609 memset(s
->status
, 0, vhost_vdpa_net_cvq_cmd_page_len());
611 s
->vhost_vdpa
.shadow_vq_ops
= &vhost_vdpa_net_svq_ops
;
612 s
->vhost_vdpa
.shadow_vq_ops_opaque
= s
;
614 ret
= vhost_vdpa_add(nc
, (void *)&s
->vhost_vdpa
, queue_pair_index
, nvqs
);
616 qemu_del_net_client(nc
);
622 static int vhost_vdpa_get_iova_range(int fd
,
623 struct vhost_vdpa_iova_range
*iova_range
)
625 int ret
= ioctl(fd
, VHOST_VDPA_GET_IOVA_RANGE
, iova_range
);
627 return ret
< 0 ? -errno
: 0;
630 static int vhost_vdpa_get_features(int fd
, uint64_t *features
, Error
**errp
)
632 int ret
= ioctl(fd
, VHOST_GET_FEATURES
, features
);
633 if (unlikely(ret
< 0)) {
634 error_setg_errno(errp
, errno
,
635 "Fail to query features from vhost-vDPA device");
640 static int vhost_vdpa_get_max_queue_pairs(int fd
, uint64_t features
,
641 int *has_cvq
, Error
**errp
)
643 unsigned long config_size
= offsetof(struct vhost_vdpa_config
, buf
);
644 g_autofree
struct vhost_vdpa_config
*config
= NULL
;
645 __virtio16
*max_queue_pairs
;
648 if (features
& (1 << VIRTIO_NET_F_CTRL_VQ
)) {
654 if (features
& (1 << VIRTIO_NET_F_MQ
)) {
655 config
= g_malloc0(config_size
+ sizeof(*max_queue_pairs
));
656 config
->off
= offsetof(struct virtio_net_config
, max_virtqueue_pairs
);
657 config
->len
= sizeof(*max_queue_pairs
);
659 ret
= ioctl(fd
, VHOST_VDPA_GET_CONFIG
, config
);
661 error_setg(errp
, "Fail to get config from vhost-vDPA device");
665 max_queue_pairs
= (__virtio16
*)&config
->buf
;
667 return lduw_le_p(max_queue_pairs
);
673 int net_init_vhost_vdpa(const Netdev
*netdev
, const char *name
,
674 NetClientState
*peer
, Error
**errp
)
676 const NetdevVhostVDPAOptions
*opts
;
679 g_autofree NetClientState
**ncs
= NULL
;
680 g_autoptr(VhostIOVATree
) iova_tree
= NULL
;
682 int queue_pairs
, r
, i
= 0, has_cvq
= 0;
684 assert(netdev
->type
== NET_CLIENT_DRIVER_VHOST_VDPA
);
685 opts
= &netdev
->u
.vhost_vdpa
;
686 if (!opts
->vhostdev
) {
687 error_setg(errp
, "vdpa character device not specified with vhostdev");
691 vdpa_device_fd
= qemu_open(opts
->vhostdev
, O_RDWR
, errp
);
692 if (vdpa_device_fd
== -1) {
696 r
= vhost_vdpa_get_features(vdpa_device_fd
, &features
, errp
);
697 if (unlikely(r
< 0)) {
701 queue_pairs
= vhost_vdpa_get_max_queue_pairs(vdpa_device_fd
, features
,
703 if (queue_pairs
< 0) {
704 qemu_close(vdpa_device_fd
);
709 struct vhost_vdpa_iova_range iova_range
;
711 uint64_t invalid_dev_features
=
712 features
& ~vdpa_svq_device_features
&
713 /* Transport are all accepted at this point */
714 ~MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START
,
715 VIRTIO_TRANSPORT_F_END
- VIRTIO_TRANSPORT_F_START
);
717 if (invalid_dev_features
) {
718 error_setg(errp
, "vdpa svq does not work with features 0x%" PRIx64
,
719 invalid_dev_features
);
723 vhost_vdpa_get_iova_range(vdpa_device_fd
, &iova_range
);
724 iova_tree
= vhost_iova_tree_new(iova_range
.first
, iova_range
.last
);
727 ncs
= g_malloc0(sizeof(*ncs
) * queue_pairs
);
729 for (i
= 0; i
< queue_pairs
; i
++) {
730 ncs
[i
] = net_vhost_vdpa_init(peer
, TYPE_VHOST_VDPA
, name
,
731 vdpa_device_fd
, i
, 2, true, opts
->x_svq
,
738 nc
= net_vhost_vdpa_init(peer
, TYPE_VHOST_VDPA
, name
,
739 vdpa_device_fd
, i
, 1, false,
740 opts
->x_svq
, iova_tree
);
745 /* iova_tree ownership belongs to last NetClientState */
746 g_steal_pointer(&iova_tree
);
751 for (i
--; i
>= 0; i
--) {
752 qemu_del_net_client(ncs
[i
]);
757 qemu_close(vdpa_device_fd
);