1 | The following changes since commit d0d3dd401b70168a353450e031727affee828527: | 1 | The following changes since commit 352998df1c53b366413690d95b35f76d0721ebed: |
---|---|---|---|
2 | 2 | ||
3 | Update version for v6.0.0-rc2 release (2021-04-06 18:34:34 +0100) | 3 | Merge tag 'i2c-20220314' of https://github.com/philmd/qemu into staging (2022-03-14 14:39:33 +0000) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the git repository at: |
6 | 6 | ||
7 | https://github.com/jasowang/qemu.git tags/net-pull-request | 7 | https://github.com/jasowang/qemu.git tags/net-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 21df394d9e2ffce9fa308f496d1ae228cf6cdb57: | 9 | for you to fetch changes up to 12a195fa343aae2ead1301ce04727bd0ae25eb15: |
10 | 10 | ||
11 | tap-win32: correctly recycle buffers (2021-04-08 17:33:59 +0800) | 11 | vdpa: Expose VHOST_F_LOG_ALL on SVQ (2022-03-15 13:57:44 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | 14 | ||
15 | Fixes for rc3: | 15 | Changes since V2: |
16 | 16 | - fix 32bit build errros | |
17 | - query-netdev is reverted (that's why the changeset is huge) | ||
18 | - fix a regression caused by padding for in TAP for win32 | ||
19 | |||
20 | 17 | ||
21 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
22 | Jason Wang (6): | 19 | Eugenio Pérez (14): |
23 | Revert "net: Do not fill legacy info_str for backends" | 20 | vhost: Add VhostShadowVirtqueue |
24 | Revert "hmp: Use QAPI NetdevInfo in hmp_info_network" | 21 | vhost: Add Shadow VirtQueue kick forwarding capabilities |
25 | Revert "net: Move NetClientState.info_str to dynamic allocations" | 22 | vhost: Add Shadow VirtQueue call forwarding capabilities |
26 | Revert "tests: Add tests for query-netdev command" | 23 | vhost: Add vhost_svq_valid_features to shadow vq |
27 | Revert "qapi: net: Add query-netdev command" | 24 | virtio: Add vhost_svq_get_vring_addr |
28 | tap-win32: correctly recycle buffers | 25 | vdpa: adapt vhost_ops callbacks to svq |
26 | vhost: Shadow virtqueue buffers forwarding | ||
27 | util: Add iova_tree_alloc_map | ||
28 | util: add iova_tree_find_iova | ||
29 | vhost: Add VhostIOVATree | ||
30 | vdpa: Add custom IOTLB translations to SVQ | ||
31 | vdpa: Adapt vhost_vdpa_get_vring_base to SVQ | ||
32 | vdpa: Never set log_base addr if SVQ is enabled | ||
33 | vdpa: Expose VHOST_F_LOG_ALL on SVQ | ||
29 | 34 | ||
30 | hw/net/xen_nic.c | 5 +- | 35 | Jason Wang (1): |
31 | include/net/net.h | 5 +- | 36 | virtio-net: fix map leaking on error during receive |
32 | include/qapi/hmp-output-visitor.h | 30 ------ | 37 | |
33 | net/l2tpv3.c | 8 +- | 38 | hw/net/virtio-net.c | 1 + |
34 | net/net.c | 73 ++------------ | 39 | hw/virtio/meson.build | 2 +- |
35 | net/netmap.c | 7 -- | 40 | hw/virtio/vhost-iova-tree.c | 110 +++++++ |
36 | net/slirp.c | 124 +----------------------- | 41 | hw/virtio/vhost-iova-tree.h | 27 ++ |
37 | net/socket.c | 92 +++++------------- | 42 | hw/virtio/vhost-shadow-virtqueue.c | 636 +++++++++++++++++++++++++++++++++++++ |
38 | net/tap-win32.c | 16 ++-- | 43 | hw/virtio/vhost-shadow-virtqueue.h | 87 +++++ |
39 | net/tap.c | 107 +++------------------ | 44 | hw/virtio/vhost-vdpa.c | 522 +++++++++++++++++++++++++++++- |
40 | net/vde.c | 25 +---- | 45 | include/hw/virtio/vhost-vdpa.h | 8 + |
41 | net/vhost-user.c | 20 +--- | 46 | include/qemu/iova-tree.h | 38 ++- |
42 | net/vhost-vdpa.c | 15 +-- | 47 | util/iova-tree.c | 170 ++++++++++ |
43 | qapi/hmp-output-visitor.c | 193 -------------------------------------- | 48 | 10 files changed, 1584 insertions(+), 17 deletions(-) |
44 | qapi/meson.build | 1 - | 49 | create mode 100644 hw/virtio/vhost-iova-tree.c |
45 | qapi/net.json | 80 ---------------- | 50 | create mode 100644 hw/virtio/vhost-iova-tree.h |
46 | tests/qtest/meson.build | 3 - | 51 | create mode 100644 hw/virtio/vhost-shadow-virtqueue.c |
47 | tests/qtest/test-query-netdev.c | 120 ------------------------ | 52 | create mode 100644 hw/virtio/vhost-shadow-virtqueue.h |
48 | 18 files changed, 66 insertions(+), 858 deletions(-) | ||
49 | delete mode 100644 include/qapi/hmp-output-visitor.h | ||
50 | delete mode 100644 qapi/hmp-output-visitor.c | ||
51 | delete mode 100644 tests/qtest/test-query-netdev.c | ||
52 | 53 | ||
53 | 54 | ||
54 | 55 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Commit bedd7e93d0196 ("virtio-net: fix use after unmap/free for sg") | ||
2 | tries to fix the use after free of the sg by caching the virtqueue | ||
3 | elements in an array and unmap them at once after receiving the | ||
4 | packets, But it forgot to unmap the cached elements on error which | ||
5 | will lead to leaking of mapping and other unexpected results. | ||
1 | 6 | ||
7 | Fixing this by detaching the cached elements on error. This addresses | ||
8 | CVE-2022-26353. | ||
9 | |||
10 | Reported-by: Victor Tom <vv474172261@gmail.com> | ||
11 | Cc: qemu-stable@nongnu.org | ||
12 | Fixes: CVE-2022-26353 | ||
13 | Fixes: bedd7e93d0196 ("virtio-net: fix use after unmap/free for sg") | ||
14 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | ||
15 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
16 | --- | ||
17 | hw/net/virtio-net.c | 1 + | ||
18 | 1 file changed, 1 insertion(+) | ||
19 | |||
20 | diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/net/virtio-net.c | ||
23 | +++ b/hw/net/virtio-net.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, | ||
25 | |||
26 | err: | ||
27 | for (j = 0; j < i; j++) { | ||
28 | + virtqueue_detach_element(q->rx_vq, elems[j], lens[j]); | ||
29 | g_free(elems[j]); | ||
30 | } | ||
31 | |||
32 | -- | ||
33 | 2.7.4 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Eugenio Pérez <eperezma@redhat.com> | ||
1 | 2 | ||
3 | Vhost shadow virtqueue (SVQ) is an intermediate jump for virtqueue | ||
4 | notifications and buffers, allowing qemu to track them. While qemu is | ||
5 | forwarding the buffers and virtqueue changes, it is able to commit the | ||
6 | memory it's being dirtied, the same way regular qemu's VirtIO devices | ||
7 | do. | ||
8 | |||
9 | This commit only exposes basic SVQ allocation and free. Next patches of | ||
10 | the series add functionality like notifications and buffers forwarding. | ||
11 | |||
12 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
13 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
14 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
15 | --- | ||
16 | hw/virtio/meson.build | 2 +- | ||
17 | hw/virtio/vhost-shadow-virtqueue.c | 62 ++++++++++++++++++++++++++++++++++++++ | ||
18 | hw/virtio/vhost-shadow-virtqueue.h | 28 +++++++++++++++++ | ||
19 | 3 files changed, 91 insertions(+), 1 deletion(-) | ||
20 | create mode 100644 hw/virtio/vhost-shadow-virtqueue.c | ||
21 | create mode 100644 hw/virtio/vhost-shadow-virtqueue.h | ||
22 | |||
23 | diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/hw/virtio/meson.build | ||
26 | +++ b/hw/virtio/meson.build | ||
27 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) | ||
28 | |||
29 | virtio_ss = ss.source_set() | ||
30 | virtio_ss.add(files('virtio.c')) | ||
31 | -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c')) | ||
32 | +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c')) | ||
33 | virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) | ||
34 | virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) | ||
35 | virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c')) | ||
36 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c | ||
37 | new file mode 100644 | ||
38 | index XXXXXXX..XXXXXXX | ||
39 | --- /dev/null | ||
40 | +++ b/hw/virtio/vhost-shadow-virtqueue.c | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | +/* | ||
43 | + * vhost shadow virtqueue | ||
44 | + * | ||
45 | + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 | ||
46 | + * SPDX-FileContributor: Author: Eugenio Pérez <eperezma@redhat.com> | ||
47 | + * | ||
48 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
49 | + */ | ||
50 | + | ||
51 | +#include "qemu/osdep.h" | ||
52 | +#include "hw/virtio/vhost-shadow-virtqueue.h" | ||
53 | + | ||
54 | +#include "qemu/error-report.h" | ||
55 | + | ||
56 | +/** | ||
57 | + * Creates vhost shadow virtqueue, and instructs the vhost device to use the | ||
58 | + * shadow methods and file descriptors. | ||
59 | + * | ||
60 | + * Returns the new virtqueue or NULL. | ||
61 | + * | ||
62 | + * In case of error, reason is reported through error_report. | ||
63 | + */ | ||
64 | +VhostShadowVirtqueue *vhost_svq_new(void) | ||
65 | +{ | ||
66 | + g_autofree VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1); | ||
67 | + int r; | ||
68 | + | ||
69 | + r = event_notifier_init(&svq->hdev_kick, 0); | ||
70 | + if (r != 0) { | ||
71 | + error_report("Couldn't create kick event notifier: %s (%d)", | ||
72 | + g_strerror(errno), errno); | ||
73 | + goto err_init_hdev_kick; | ||
74 | + } | ||
75 | + | ||
76 | + r = event_notifier_init(&svq->hdev_call, 0); | ||
77 | + if (r != 0) { | ||
78 | + error_report("Couldn't create call event notifier: %s (%d)", | ||
79 | + g_strerror(errno), errno); | ||
80 | + goto err_init_hdev_call; | ||
81 | + } | ||
82 | + | ||
83 | + return g_steal_pointer(&svq); | ||
84 | + | ||
85 | +err_init_hdev_call: | ||
86 | + event_notifier_cleanup(&svq->hdev_kick); | ||
87 | + | ||
88 | +err_init_hdev_kick: | ||
89 | + return NULL; | ||
90 | +} | ||
91 | + | ||
92 | +/** | ||
93 | + * Free the resources of the shadow virtqueue. | ||
94 | + * | ||
95 | + * @pvq: gpointer to SVQ so it can be used by autofree functions. | ||
96 | + */ | ||
97 | +void vhost_svq_free(gpointer pvq) | ||
98 | +{ | ||
99 | + VhostShadowVirtqueue *vq = pvq; | ||
100 | + event_notifier_cleanup(&vq->hdev_kick); | ||
101 | + event_notifier_cleanup(&vq->hdev_call); | ||
102 | + g_free(vq); | ||
103 | +} | ||
104 | diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h | ||
105 | new file mode 100644 | ||
106 | index XXXXXXX..XXXXXXX | ||
107 | --- /dev/null | ||
108 | +++ b/hw/virtio/vhost-shadow-virtqueue.h | ||
109 | @@ -XXX,XX +XXX,XX @@ | ||
110 | +/* | ||
111 | + * vhost shadow virtqueue | ||
112 | + * | ||
113 | + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 | ||
114 | + * SPDX-FileContributor: Author: Eugenio Pérez <eperezma@redhat.com> | ||
115 | + * | ||
116 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
117 | + */ | ||
118 | + | ||
119 | +#ifndef VHOST_SHADOW_VIRTQUEUE_H | ||
120 | +#define VHOST_SHADOW_VIRTQUEUE_H | ||
121 | + | ||
122 | +#include "qemu/event_notifier.h" | ||
123 | + | ||
124 | +/* Shadow virtqueue to relay notifications */ | ||
125 | +typedef struct VhostShadowVirtqueue { | ||
126 | + /* Shadow kick notifier, sent to vhost */ | ||
127 | + EventNotifier hdev_kick; | ||
128 | + /* Shadow call notifier, sent to vhost */ | ||
129 | + EventNotifier hdev_call; | ||
130 | +} VhostShadowVirtqueue; | ||
131 | + | ||
132 | +VhostShadowVirtqueue *vhost_svq_new(void); | ||
133 | + | ||
134 | +void vhost_svq_free(gpointer vq); | ||
135 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free); | ||
136 | + | ||
137 | +#endif | ||
138 | -- | ||
139 | 2.7.4 | ||
140 | |||
141 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Eugenio Pérez <eperezma@redhat.com> | |
2 | |||
3 | At this mode no buffer forwarding will be performed in SVQ mode: Qemu | ||
4 | will just forward the guest's kicks to the device. | ||
5 | |||
6 | Host memory notifiers regions are left out for simplicity, and they will | ||
7 | not be addressed in this series. | ||
8 | |||
9 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
10 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
12 | --- | ||
13 | hw/virtio/vhost-shadow-virtqueue.c | 55 ++++++++++++++ | ||
14 | hw/virtio/vhost-shadow-virtqueue.h | 14 ++++ | ||
15 | hw/virtio/vhost-vdpa.c | 144 ++++++++++++++++++++++++++++++++++++- | ||
16 | include/hw/virtio/vhost-vdpa.h | 4 ++ | ||
17 | 4 files changed, 215 insertions(+), 2 deletions(-) | ||
18 | |||
19 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/hw/virtio/vhost-shadow-virtqueue.c | ||
22 | +++ b/hw/virtio/vhost-shadow-virtqueue.c | ||
23 | @@ -XXX,XX +XXX,XX @@ | ||
24 | #include "hw/virtio/vhost-shadow-virtqueue.h" | ||
25 | |||
26 | #include "qemu/error-report.h" | ||
27 | +#include "qemu/main-loop.h" | ||
28 | +#include "linux-headers/linux/vhost.h" | ||
29 | + | ||
30 | +/** | ||
31 | + * Forward guest notifications. | ||
32 | + * | ||
33 | + * @n: guest kick event notifier, the one that guest set to notify svq. | ||
34 | + */ | ||
35 | +static void vhost_handle_guest_kick(EventNotifier *n) | ||
36 | +{ | ||
37 | + VhostShadowVirtqueue *svq = container_of(n, VhostShadowVirtqueue, svq_kick); | ||
38 | + event_notifier_test_and_clear(n); | ||
39 | + event_notifier_set(&svq->hdev_kick); | ||
40 | +} | ||
41 | + | ||
42 | +/** | ||
43 | + * Set a new file descriptor for the guest to kick the SVQ and notify for avail | ||
44 | + * | ||
45 | + * @svq: The svq | ||
46 | + * @svq_kick_fd: The svq kick fd | ||
47 | + * | ||
48 | + * Note that the SVQ will never close the old file descriptor. | ||
49 | + */ | ||
50 | +void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd) | ||
51 | +{ | ||
52 | + EventNotifier *svq_kick = &svq->svq_kick; | ||
53 | + bool poll_stop = VHOST_FILE_UNBIND != event_notifier_get_fd(svq_kick); | ||
54 | + bool poll_start = svq_kick_fd != VHOST_FILE_UNBIND; | ||
55 | + | ||
56 | + if (poll_stop) { | ||
57 | + event_notifier_set_handler(svq_kick, NULL); | ||
58 | + } | ||
59 | + | ||
60 | + /* | ||
61 | + * event_notifier_set_handler already checks for guest's notifications if | ||
62 | + * they arrive at the new file descriptor in the switch, so there is no | ||
63 | + * need to explicitly check for them. | ||
64 | + */ | ||
65 | + if (poll_start) { | ||
66 | + event_notifier_init_fd(svq_kick, svq_kick_fd); | ||
67 | + event_notifier_set(svq_kick); | ||
68 | + event_notifier_set_handler(svq_kick, vhost_handle_guest_kick); | ||
69 | + } | ||
70 | +} | ||
71 | + | ||
72 | +/** | ||
73 | + * Stop the shadow virtqueue operation. | ||
74 | + * @svq: Shadow Virtqueue | ||
75 | + */ | ||
76 | +void vhost_svq_stop(VhostShadowVirtqueue *svq) | ||
77 | +{ | ||
78 | + event_notifier_set_handler(&svq->svq_kick, NULL); | ||
79 | +} | ||
80 | |||
81 | /** | ||
82 | * Creates vhost shadow virtqueue, and instructs the vhost device to use the | ||
83 | @@ -XXX,XX +XXX,XX @@ VhostShadowVirtqueue *vhost_svq_new(void) | ||
84 | goto err_init_hdev_call; | ||
85 | } | ||
86 | |||
87 | + event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); | ||
88 | return g_steal_pointer(&svq); | ||
89 | |||
90 | err_init_hdev_call: | ||
91 | @@ -XXX,XX +XXX,XX @@ err_init_hdev_kick: | ||
92 | void vhost_svq_free(gpointer pvq) | ||
93 | { | ||
94 | VhostShadowVirtqueue *vq = pvq; | ||
95 | + vhost_svq_stop(vq); | ||
96 | event_notifier_cleanup(&vq->hdev_kick); | ||
97 | event_notifier_cleanup(&vq->hdev_call); | ||
98 | g_free(vq); | ||
99 | diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/hw/virtio/vhost-shadow-virtqueue.h | ||
102 | +++ b/hw/virtio/vhost-shadow-virtqueue.h | ||
103 | @@ -XXX,XX +XXX,XX @@ typedef struct VhostShadowVirtqueue { | ||
104 | EventNotifier hdev_kick; | ||
105 | /* Shadow call notifier, sent to vhost */ | ||
106 | EventNotifier hdev_call; | ||
107 | + | ||
108 | + /* | ||
109 | + * Borrowed virtqueue's guest to host notifier. To borrow it in this event | ||
110 | + * notifier allows to recover the VhostShadowVirtqueue from the event loop | ||
111 | + * easily. If we use the VirtQueue's one, we don't have an easy way to | ||
112 | + * retrieve VhostShadowVirtqueue. | ||
113 | + * | ||
114 | + * So shadow virtqueue must not clean it, or we would lose VirtQueue one. | ||
115 | + */ | ||
116 | + EventNotifier svq_kick; | ||
117 | } VhostShadowVirtqueue; | ||
118 | |||
119 | +void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); | ||
120 | + | ||
121 | +void vhost_svq_stop(VhostShadowVirtqueue *svq); | ||
122 | + | ||
123 | VhostShadowVirtqueue *vhost_svq_new(void); | ||
124 | |||
125 | void vhost_svq_free(gpointer vq); | ||
126 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c | ||
127 | index XXXXXXX..XXXXXXX 100644 | ||
128 | --- a/hw/virtio/vhost-vdpa.c | ||
129 | +++ b/hw/virtio/vhost-vdpa.c | ||
130 | @@ -XXX,XX +XXX,XX @@ | ||
131 | #include "hw/virtio/vhost.h" | ||
132 | #include "hw/virtio/vhost-backend.h" | ||
133 | #include "hw/virtio/virtio-net.h" | ||
134 | +#include "hw/virtio/vhost-shadow-virtqueue.h" | ||
135 | #include "hw/virtio/vhost-vdpa.h" | ||
136 | #include "exec/address-spaces.h" | ||
137 | #include "qemu/main-loop.h" | ||
138 | #include "cpu.h" | ||
139 | #include "trace.h" | ||
140 | #include "qemu-common.h" | ||
141 | +#include "qapi/error.h" | ||
142 | |||
143 | /* | ||
144 | * Return one past the end of the end of section. Be careful with uint64_t | ||
145 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_one_time_request(struct vhost_dev *dev) | ||
146 | return v->index != 0; | ||
147 | } | ||
148 | |||
149 | +static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, | ||
150 | + Error **errp) | ||
151 | +{ | ||
152 | + g_autoptr(GPtrArray) shadow_vqs = NULL; | ||
153 | + | ||
154 | + if (!v->shadow_vqs_enabled) { | ||
155 | + return 0; | ||
156 | + } | ||
157 | + | ||
158 | + shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); | ||
159 | + for (unsigned n = 0; n < hdev->nvqs; ++n) { | ||
160 | + g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(); | ||
161 | + | ||
162 | + if (unlikely(!svq)) { | ||
163 | + error_setg(errp, "Cannot create svq %u", n); | ||
164 | + return -1; | ||
165 | + } | ||
166 | + g_ptr_array_add(shadow_vqs, g_steal_pointer(&svq)); | ||
167 | + } | ||
168 | + | ||
169 | + v->shadow_vqs = g_steal_pointer(&shadow_vqs); | ||
170 | + return 0; | ||
171 | +} | ||
172 | + | ||
173 | static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) | ||
174 | { | ||
175 | struct vhost_vdpa *v; | ||
176 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) | ||
177 | dev->opaque = opaque ; | ||
178 | v->listener = vhost_vdpa_memory_listener; | ||
179 | v->msg_type = VHOST_IOTLB_MSG_V2; | ||
180 | + ret = vhost_vdpa_init_svq(dev, v, errp); | ||
181 | + if (ret) { | ||
182 | + goto err; | ||
183 | + } | ||
184 | |||
185 | vhost_vdpa_get_iova_range(v); | ||
186 | |||
187 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) | ||
188 | VIRTIO_CONFIG_S_DRIVER); | ||
189 | |||
190 | return 0; | ||
191 | + | ||
192 | +err: | ||
193 | + ram_block_discard_disable(false); | ||
194 | + return ret; | ||
195 | } | ||
196 | |||
197 | static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev, | ||
198 | @@ -XXX,XX +XXX,XX @@ static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n) | ||
199 | |||
200 | static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev) | ||
201 | { | ||
202 | + struct vhost_vdpa *v = dev->opaque; | ||
203 | int i; | ||
204 | |||
205 | + if (v->shadow_vqs_enabled) { | ||
206 | + /* FIXME SVQ is not compatible with host notifiers mr */ | ||
207 | + return; | ||
208 | + } | ||
209 | + | ||
210 | for (i = dev->vq_index; i < dev->vq_index + dev->nvqs; i++) { | ||
211 | if (vhost_vdpa_host_notifier_init(dev, i)) { | ||
212 | goto err; | ||
213 | @@ -XXX,XX +XXX,XX @@ err: | ||
214 | return; | ||
215 | } | ||
216 | |||
217 | +static void vhost_vdpa_svq_cleanup(struct vhost_dev *dev) | ||
218 | +{ | ||
219 | + struct vhost_vdpa *v = dev->opaque; | ||
220 | + size_t idx; | ||
221 | + | ||
222 | + if (!v->shadow_vqs) { | ||
223 | + return; | ||
224 | + } | ||
225 | + | ||
226 | + for (idx = 0; idx < v->shadow_vqs->len; ++idx) { | ||
227 | + vhost_svq_stop(g_ptr_array_index(v->shadow_vqs, idx)); | ||
228 | + } | ||
229 | + g_ptr_array_free(v->shadow_vqs, true); | ||
230 | +} | ||
231 | + | ||
232 | static int vhost_vdpa_cleanup(struct vhost_dev *dev) | ||
233 | { | ||
234 | struct vhost_vdpa *v; | ||
235 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_cleanup(struct vhost_dev *dev) | ||
236 | trace_vhost_vdpa_cleanup(dev, v); | ||
237 | vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); | ||
238 | memory_listener_unregister(&v->listener); | ||
239 | + vhost_vdpa_svq_cleanup(dev); | ||
240 | |||
241 | dev->opaque = NULL; | ||
242 | ram_block_discard_disable(false); | ||
243 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev, | ||
244 | return ret; | ||
245 | } | ||
246 | |||
247 | +static void vhost_vdpa_reset_svq(struct vhost_vdpa *v) | ||
248 | +{ | ||
249 | + if (!v->shadow_vqs_enabled) { | ||
250 | + return; | ||
251 | + } | ||
252 | + | ||
253 | + for (unsigned i = 0; i < v->shadow_vqs->len; ++i) { | ||
254 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); | ||
255 | + vhost_svq_stop(svq); | ||
256 | + } | ||
257 | +} | ||
258 | + | ||
259 | static int vhost_vdpa_reset_device(struct vhost_dev *dev) | ||
260 | { | ||
261 | + struct vhost_vdpa *v = dev->opaque; | ||
262 | int ret; | ||
263 | uint8_t status = 0; | ||
264 | |||
265 | + vhost_vdpa_reset_svq(v); | ||
266 | + | ||
267 | ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); | ||
268 | trace_vhost_vdpa_reset_device(dev, status); | ||
269 | return ret; | ||
270 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, | ||
271 | return ret; | ||
272 | } | ||
273 | |||
274 | +static int vhost_vdpa_set_vring_dev_kick(struct vhost_dev *dev, | ||
275 | + struct vhost_vring_file *file) | ||
276 | +{ | ||
277 | + trace_vhost_vdpa_set_vring_kick(dev, file->index, file->fd); | ||
278 | + return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); | ||
279 | +} | ||
280 | + | ||
281 | +/** | ||
282 | + * Set the shadow virtqueue descriptors to the device | ||
283 | + * | ||
284 | + * @dev: The vhost device model | ||
285 | + * @svq: The shadow virtqueue | ||
286 | + * @idx: The index of the virtqueue in the vhost device | ||
287 | + * @errp: Error | ||
288 | + */ | ||
289 | +static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, | ||
290 | + VhostShadowVirtqueue *svq, unsigned idx, | ||
291 | + Error **errp) | ||
292 | +{ | ||
293 | + struct vhost_vring_file file = { | ||
294 | + .index = dev->vq_index + idx, | ||
295 | + }; | ||
296 | + const EventNotifier *event_notifier = &svq->hdev_kick; | ||
297 | + int r; | ||
298 | + | ||
299 | + file.fd = event_notifier_get_fd(event_notifier); | ||
300 | + r = vhost_vdpa_set_vring_dev_kick(dev, &file); | ||
301 | + if (unlikely(r != 0)) { | ||
302 | + error_setg_errno(errp, -r, "Can't set device kick fd"); | ||
303 | + } | ||
304 | + | ||
305 | + return r == 0; | ||
306 | +} | ||
307 | + | ||
308 | +static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) | ||
309 | +{ | ||
310 | + struct vhost_vdpa *v = dev->opaque; | ||
311 | + Error *err = NULL; | ||
312 | + unsigned i; | ||
313 | + | ||
314 | + if (!v->shadow_vqs) { | ||
315 | + return true; | ||
316 | + } | ||
317 | + | ||
318 | + for (i = 0; i < v->shadow_vqs->len; ++i) { | ||
319 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); | ||
320 | + bool ok = vhost_vdpa_svq_setup(dev, svq, i, &err); | ||
321 | + if (unlikely(!ok)) { | ||
322 | + error_reportf_err(err, "Cannot setup SVQ %u: ", i); | ||
323 | + return false; | ||
324 | + } | ||
325 | + } | ||
326 | + | ||
327 | + return true; | ||
328 | +} | ||
329 | + | ||
330 | static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) | ||
331 | { | ||
332 | struct vhost_vdpa *v = dev->opaque; | ||
333 | + bool ok; | ||
334 | trace_vhost_vdpa_dev_start(dev, started); | ||
335 | |||
336 | if (started) { | ||
337 | vhost_vdpa_host_notifiers_init(dev); | ||
338 | + ok = vhost_vdpa_svqs_start(dev); | ||
339 | + if (unlikely(!ok)) { | ||
340 | + return -1; | ||
341 | + } | ||
342 | vhost_vdpa_set_vring_ready(dev); | ||
343 | } else { | ||
344 | vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); | ||
345 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, | ||
346 | static int vhost_vdpa_set_vring_kick(struct vhost_dev *dev, | ||
347 | struct vhost_vring_file *file) | ||
348 | { | ||
349 | - trace_vhost_vdpa_set_vring_kick(dev, file->index, file->fd); | ||
350 | - return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); | ||
351 | + struct vhost_vdpa *v = dev->opaque; | ||
352 | + int vdpa_idx = file->index - dev->vq_index; | ||
353 | + | ||
354 | + if (v->shadow_vqs_enabled) { | ||
355 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, vdpa_idx); | ||
356 | + vhost_svq_set_svq_kick_fd(svq, file->fd); | ||
357 | + return 0; | ||
358 | + } else { | ||
359 | + return vhost_vdpa_set_vring_dev_kick(dev, file); | ||
360 | + } | ||
361 | } | ||
362 | |||
363 | static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, | ||
364 | diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h | ||
365 | index XXXXXXX..XXXXXXX 100644 | ||
366 | --- a/include/hw/virtio/vhost-vdpa.h | ||
367 | +++ b/include/hw/virtio/vhost-vdpa.h | ||
368 | @@ -XXX,XX +XXX,XX @@ | ||
369 | #ifndef HW_VIRTIO_VHOST_VDPA_H | ||
370 | #define HW_VIRTIO_VHOST_VDPA_H | ||
371 | |||
372 | +#include <gmodule.h> | ||
373 | + | ||
374 | #include "hw/virtio/virtio.h" | ||
375 | #include "standard-headers/linux/vhost_types.h" | ||
376 | |||
377 | @@ -XXX,XX +XXX,XX @@ typedef struct vhost_vdpa { | ||
378 | bool iotlb_batch_begin_sent; | ||
379 | MemoryListener listener; | ||
380 | struct vhost_vdpa_iova_range iova_range; | ||
381 | + bool shadow_vqs_enabled; | ||
382 | + GPtrArray *shadow_vqs; | ||
383 | struct vhost_dev *dev; | ||
384 | VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; | ||
385 | } VhostVDPA; | ||
386 | -- | ||
387 | 2.7.4 | ||
388 | |||
389 | diff view generated by jsdifflib |
1 | Several issues has been reported for query-netdev info | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | series. Consider it's late in the rc, this reverts commit | ||
3 | f2e8319d456724c3d8514d943dc4607e2f08e88a. | ||
4 | 2 | ||
3 | This will make qemu aware of the device used buffers, allowing it to | ||
4 | write the guest memory with its contents if needed. | ||
5 | |||
6 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
7 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
5 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 8 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
6 | --- | 9 | --- |
7 | net/l2tpv3.c | 2 ++ | 10 | hw/virtio/vhost-shadow-virtqueue.c | 38 ++++++++++++++++++++++++++++++++++++++ |
8 | net/slirp.c | 3 +++ | 11 | hw/virtio/vhost-shadow-virtqueue.h | 4 ++++ |
9 | net/socket.c | 28 ++++++++++++++++++++++++++++ | 12 | hw/virtio/vhost-vdpa.c | 31 +++++++++++++++++++++++++++++-- |
10 | net/tap-win32.c | 2 ++ | 13 | 3 files changed, 71 insertions(+), 2 deletions(-) |
11 | net/tap.c | 9 +++++++++ | ||
12 | net/vde.c | 2 ++ | ||
13 | net/vhost-user.c | 1 + | ||
14 | net/vhost-vdpa.c | 1 + | ||
15 | 8 files changed, 48 insertions(+) | ||
16 | 14 | ||
17 | diff --git a/net/l2tpv3.c b/net/l2tpv3.c | 15 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c |
18 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/net/l2tpv3.c | 17 | --- a/hw/virtio/vhost-shadow-virtqueue.c |
20 | +++ b/net/l2tpv3.c | 18 | +++ b/hw/virtio/vhost-shadow-virtqueue.c |
21 | @@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev, | 19 | @@ -XXX,XX +XXX,XX @@ static void vhost_handle_guest_kick(EventNotifier *n) |
22 | 20 | } | |
23 | QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, | 21 | |
24 | &nc->stored_config->u.l2tpv3, l2tpv3); | 22 | /** |
23 | + * Forward vhost notifications | ||
24 | + * | ||
25 | + * @n: hdev call event notifier, the one that device set to notify svq. | ||
26 | + */ | ||
27 | +static void vhost_svq_handle_call(EventNotifier *n) | ||
28 | +{ | ||
29 | + VhostShadowVirtqueue *svq = container_of(n, VhostShadowVirtqueue, | ||
30 | + hdev_call); | ||
31 | + event_notifier_test_and_clear(n); | ||
32 | + event_notifier_set(&svq->svq_call); | ||
33 | +} | ||
25 | + | 34 | + |
26 | + s->nc.info_str = g_strdup_printf("l2tpv3: connected"); | 35 | +/** |
27 | return 0; | 36 | + * Set the call notifier for the SVQ to call the guest |
28 | outerr: | 37 | + * |
29 | qemu_del_net_client(nc); | 38 | + * @svq: Shadow virtqueue |
30 | diff --git a/net/slirp.c b/net/slirp.c | 39 | + * @call_fd: call notifier |
40 | + * | ||
41 | + * Called on BQL context. | ||
42 | + */ | ||
43 | +void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd) | ||
44 | +{ | ||
45 | + if (call_fd == VHOST_FILE_UNBIND) { | ||
46 | + /* | ||
47 | + * Fail event_notifier_set if called handling device call. | ||
48 | + * | ||
49 | + * SVQ still needs device notifications, since it needs to keep | ||
50 | + * forwarding used buffers even with the unbind. | ||
51 | + */ | ||
52 | + memset(&svq->svq_call, 0, sizeof(svq->svq_call)); | ||
53 | + } else { | ||
54 | + event_notifier_init_fd(&svq->svq_call, call_fd); | ||
55 | + } | ||
56 | +} | ||
57 | + | ||
58 | +/** | ||
59 | * Set a new file descriptor for the guest to kick the SVQ and notify for avail | ||
60 | * | ||
61 | * @svq: The svq | ||
62 | @@ -XXX,XX +XXX,XX @@ VhostShadowVirtqueue *vhost_svq_new(void) | ||
63 | } | ||
64 | |||
65 | event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); | ||
66 | + event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); | ||
67 | return g_steal_pointer(&svq); | ||
68 | |||
69 | err_init_hdev_call: | ||
70 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_free(gpointer pvq) | ||
71 | VhostShadowVirtqueue *vq = pvq; | ||
72 | vhost_svq_stop(vq); | ||
73 | event_notifier_cleanup(&vq->hdev_kick); | ||
74 | + event_notifier_set_handler(&vq->hdev_call, NULL); | ||
75 | event_notifier_cleanup(&vq->hdev_call); | ||
76 | g_free(vq); | ||
77 | } | ||
78 | diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | 79 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/net/slirp.c | 80 | --- a/hw/virtio/vhost-shadow-virtqueue.h |
33 | +++ b/net/slirp.c | 81 | +++ b/hw/virtio/vhost-shadow-virtqueue.h |
34 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | 82 | @@ -XXX,XX +XXX,XX @@ typedef struct VhostShadowVirtqueue { |
35 | stored->tftp_server_name = g_strdup(tftp_server_name); | 83 | * So shadow virtqueue must not clean it, or we would lose VirtQueue one. |
84 | */ | ||
85 | EventNotifier svq_kick; | ||
86 | + | ||
87 | + /* Guest's call notifier, where the SVQ calls guest. */ | ||
88 | + EventNotifier svq_call; | ||
89 | } VhostShadowVirtqueue; | ||
90 | |||
91 | void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); | ||
92 | +void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); | ||
93 | |||
94 | void vhost_svq_stop(VhostShadowVirtqueue *svq); | ||
95 | |||
96 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/hw/virtio/vhost-vdpa.c | ||
99 | +++ b/hw/virtio/vhost-vdpa.c | ||
100 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_dev_kick(struct vhost_dev *dev, | ||
101 | return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); | ||
102 | } | ||
103 | |||
104 | +static int vhost_vdpa_set_vring_dev_call(struct vhost_dev *dev, | ||
105 | + struct vhost_vring_file *file) | ||
106 | +{ | ||
107 | + trace_vhost_vdpa_set_vring_call(dev, file->index, file->fd); | ||
108 | + return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); | ||
109 | +} | ||
110 | + | ||
111 | /** | ||
112 | * Set the shadow virtqueue descriptors to the device | ||
113 | * | ||
114 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_dev_kick(struct vhost_dev *dev, | ||
115 | * @svq: The shadow virtqueue | ||
116 | * @idx: The index of the virtqueue in the vhost device | ||
117 | * @errp: Error | ||
118 | + * | ||
119 | + * Note that this function does not rewind kick file descriptor if cannot set | ||
120 | + * call one. | ||
121 | */ | ||
122 | static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, | ||
123 | VhostShadowVirtqueue *svq, unsigned idx, | ||
124 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, | ||
125 | r = vhost_vdpa_set_vring_dev_kick(dev, &file); | ||
126 | if (unlikely(r != 0)) { | ||
127 | error_setg_errno(errp, -r, "Can't set device kick fd"); | ||
128 | + return false; | ||
129 | + } | ||
130 | + | ||
131 | + event_notifier = &svq->hdev_call; | ||
132 | + file.fd = event_notifier_get_fd(event_notifier); | ||
133 | + r = vhost_vdpa_set_vring_dev_call(dev, &file); | ||
134 | + if (unlikely(r != 0)) { | ||
135 | + error_setg_errno(errp, -r, "Can't set device call fd"); | ||
36 | } | 136 | } |
37 | 137 | ||
38 | + nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net), | 138 | return r == 0; |
39 | + restricted ? "on" : "off"); | 139 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_kick(struct vhost_dev *dev, |
140 | static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, | ||
141 | struct vhost_vring_file *file) | ||
142 | { | ||
143 | - trace_vhost_vdpa_set_vring_call(dev, file->index, file->fd); | ||
144 | - return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); | ||
145 | + struct vhost_vdpa *v = dev->opaque; | ||
40 | + | 146 | + |
41 | s = DO_UPCAST(SlirpState, nc, nc); | 147 | + if (v->shadow_vqs_enabled) { |
42 | 148 | + int vdpa_idx = file->index - dev->vq_index; | |
43 | s->slirp = slirp_init(restricted, ipv4, net, mask, host, | 149 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, vdpa_idx); |
44 | diff --git a/net/socket.c b/net/socket.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/net/socket.c | ||
47 | +++ b/net/socket.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque) | ||
49 | s->fd = -1; | ||
50 | net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | ||
51 | s->nc.link_down = true; | ||
52 | + g_free(s->nc.info_str); | ||
53 | + s->nc.info_str = g_new0(char, 1); | ||
54 | |||
55 | return; | ||
56 | } | ||
57 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, | ||
58 | stored->mcast = g_strdup(mcast); | ||
59 | |||
60 | s->dgram_dst = saddr; | ||
61 | + nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)", | ||
62 | + fd, inet_ntoa(saddr.sin_addr), | ||
63 | + ntohs(saddr.sin_port)); | ||
64 | } else { | ||
65 | if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) { | ||
66 | s->dgram_dst.sin_family = AF_UNIX; | ||
67 | } | ||
68 | + | 150 | + |
69 | + nc->info_str = g_strdup_printf("socket: fd=%d %s", | 151 | + vhost_svq_set_svq_call_fd(svq, file->fd); |
70 | + fd, SocketAddressType_str(sa_type)); | 152 | + return 0; |
71 | } | 153 | + } else { |
72 | 154 | + return vhost_vdpa_set_vring_dev_call(dev, file); | |
73 | return s; | 155 | + } |
74 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, | ||
75 | |||
76 | nc = qemu_new_net_client(&net_socket_info, peer, model, name); | ||
77 | |||
78 | + nc->info_str = g_strdup_printf("socket: fd=%d", fd); | ||
79 | + | ||
80 | s = DO_UPCAST(NetSocketState, nc, nc); | ||
81 | |||
82 | s->fd = fd; | ||
83 | @@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque) | ||
84 | |||
85 | stored->has_fd = true; | ||
86 | stored->fd = g_strdup_printf("%d", fd); | ||
87 | + | ||
88 | + g_free(s->nc.info_str); | ||
89 | + s->nc.info_str = g_strdup_printf("socket: connection from %s:%d", | ||
90 | + inet_ntoa(saddr.sin_addr), | ||
91 | + ntohs(saddr.sin_port)); | ||
92 | } | 156 | } |
93 | 157 | ||
94 | static int net_socket_listen_init(NetClientState *peer, | 158 | static int vhost_vdpa_get_features(struct vhost_dev *dev, |
95 | @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, | ||
96 | stored->has_connect = true; | ||
97 | stored->connect = g_strdup(host_str); | ||
98 | |||
99 | + g_free(s->nc.info_str); | ||
100 | + s->nc.info_str = g_strdup_printf("socket: connect to %s:%d", | ||
101 | + inet_ntoa(saddr.sin_addr), | ||
102 | + ntohs(saddr.sin_port)); | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer, | ||
107 | stored->localaddr = g_strdup(localaddr_str); | ||
108 | } | ||
109 | |||
110 | + g_free(s->nc.info_str); | ||
111 | + s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d", | ||
112 | + inet_ntoa(saddr.sin_addr), | ||
113 | + ntohs(saddr.sin_port)); | ||
114 | return 0; | ||
115 | + | ||
116 | } | ||
117 | |||
118 | static int net_socket_udp_init(NetClientState *peer, | ||
119 | @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, | ||
120 | stored->has_udp = true; | ||
121 | stored->udp = g_strdup(rhost); | ||
122 | |||
123 | + g_free(s->nc.info_str); | ||
124 | + s->nc.info_str = g_strdup_printf("socket: udp=%s:%d", | ||
125 | + inet_ntoa(raddr.sin_addr), | ||
126 | + ntohs(raddr.sin_port)); | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | diff --git a/net/tap-win32.c b/net/tap-win32.c | ||
131 | index XXXXXXX..XXXXXXX 100644 | ||
132 | --- a/net/tap-win32.c | ||
133 | +++ b/net/tap-win32.c | ||
134 | @@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model, | ||
135 | stored->has_ifname = true; | ||
136 | stored->ifname = g_strdup(ifname); | ||
137 | |||
138 | + s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname); | ||
139 | + | ||
140 | s->handle = handle; | ||
141 | |||
142 | qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s); | ||
143 | diff --git a/net/tap.c b/net/tap.c | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/net/tap.c | ||
146 | +++ b/net/tap.c | ||
147 | @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, | ||
148 | stored->helper = g_strdup(helper); | ||
149 | } | ||
150 | |||
151 | + s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br); | ||
152 | + | ||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
157 | stored->fds = g_strdup_printf("%s:%d", stored->fds, fd); | ||
158 | g_free(tmp_s); | ||
159 | } | ||
160 | + | ||
161 | + s->nc.info_str = g_strdup_printf("fd=%d", fd); | ||
162 | } else if (tap->has_helper) { | ||
163 | if (!stored->has_helper) { | ||
164 | stored->has_helper = true; | ||
165 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
166 | stored->br = tap->has_br ? g_strdup(tap->br) : | ||
167 | g_strdup(DEFAULT_BRIDGE_INTERFACE); | ||
168 | } | ||
169 | + | ||
170 | + s->nc.info_str = g_strdup_printf("helper=%s", tap->helper); | ||
171 | } else { | ||
172 | if (ifname && !stored->has_ifname) { | ||
173 | stored->has_ifname = true; | ||
174 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
175 | stored->downscript = g_strdup(downscript); | ||
176 | } | ||
177 | |||
178 | + s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s", | ||
179 | + ifname, script, downscript); | ||
180 | + | ||
181 | if (strcmp(downscript, "no") != 0) { | ||
182 | snprintf(s->down_script, sizeof(s->down_script), "%s", downscript); | ||
183 | snprintf(s->down_script_arg, sizeof(s->down_script_arg), | ||
184 | diff --git a/net/vde.c b/net/vde.c | ||
185 | index XXXXXXX..XXXXXXX 100644 | ||
186 | --- a/net/vde.c | ||
187 | +++ b/net/vde.c | ||
188 | @@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model, | ||
189 | |||
190 | nc = qemu_new_net_client(&net_vde_info, peer, model, name); | ||
191 | |||
192 | + nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde)); | ||
193 | + | ||
194 | s = DO_UPCAST(VDEState, nc, nc); | ||
195 | |||
196 | s->vde = vde; | ||
197 | diff --git a/net/vhost-user.c b/net/vhost-user.c | ||
198 | index XXXXXXX..XXXXXXX 100644 | ||
199 | --- a/net/vhost-user.c | ||
200 | +++ b/net/vhost-user.c | ||
201 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device, | ||
202 | user = g_new0(struct VhostUserState, 1); | ||
203 | for (i = 0; i < queues; i++) { | ||
204 | nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name); | ||
205 | + nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label); | ||
206 | nc->queue_index = i; | ||
207 | if (!nc0) { | ||
208 | nc0 = nc; | ||
209 | diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c | ||
210 | index XXXXXXX..XXXXXXX 100644 | ||
211 | --- a/net/vhost-vdpa.c | ||
212 | +++ b/net/vhost-vdpa.c | ||
213 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, | ||
214 | stored->has_queues = true; | ||
215 | stored->queues = 1; /* TODO: change when support multiqueue */ | ||
216 | |||
217 | + nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA); | ||
218 | nc->queue_index = 0; | ||
219 | s = DO_UPCAST(VhostVDPAState, nc, nc); | ||
220 | vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR); | ||
221 | -- | 159 | -- |
222 | 2.7.4 | 160 | 2.7.4 |
223 | 161 | ||
224 | 162 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Eugenio Pérez <eperezma@redhat.com> | ||
1 | 2 | ||
3 | This allows SVQ to negotiate features with the guest and the device. For | ||
4 | the device, SVQ is a driver. While this function bypasses all | ||
5 | non-transport features, it needs to disable the features that SVQ does | ||
6 | not support when forwarding buffers. This includes packed vq layout, | ||
7 | indirect descriptors or event idx. | ||
8 | |||
9 | Future changes can add support to offer more features to the guest, | ||
10 | since the use of VirtQueue gives this for free. This is left out at the | ||
11 | moment for simplicity. | ||
12 | |||
13 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
14 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
15 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
16 | --- | ||
17 | hw/virtio/vhost-shadow-virtqueue.c | 44 ++++++++++++++++++++++++++++++++++++++ | ||
18 | hw/virtio/vhost-shadow-virtqueue.h | 2 ++ | ||
19 | hw/virtio/vhost-vdpa.c | 15 +++++++++++++ | ||
20 | 3 files changed, 61 insertions(+) | ||
21 | |||
22 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/hw/virtio/vhost-shadow-virtqueue.c | ||
25 | +++ b/hw/virtio/vhost-shadow-virtqueue.c | ||
26 | @@ -XXX,XX +XXX,XX @@ | ||
27 | #include "hw/virtio/vhost-shadow-virtqueue.h" | ||
28 | |||
29 | #include "qemu/error-report.h" | ||
30 | +#include "qapi/error.h" | ||
31 | #include "qemu/main-loop.h" | ||
32 | #include "linux-headers/linux/vhost.h" | ||
33 | |||
34 | /** | ||
35 | + * Validate the transport device features that both guests can use with the SVQ | ||
36 | + * and SVQs can use with the device. | ||
37 | + * | ||
38 | + * @dev_features: The features | ||
39 | + * @errp: Error pointer | ||
40 | + */ | ||
41 | +bool vhost_svq_valid_features(uint64_t features, Error **errp) | ||
42 | +{ | ||
43 | + bool ok = true; | ||
44 | + uint64_t svq_features = features; | ||
45 | + | ||
46 | + for (uint64_t b = VIRTIO_TRANSPORT_F_START; b <= VIRTIO_TRANSPORT_F_END; | ||
47 | + ++b) { | ||
48 | + switch (b) { | ||
49 | + case VIRTIO_F_ANY_LAYOUT: | ||
50 | + continue; | ||
51 | + | ||
52 | + case VIRTIO_F_ACCESS_PLATFORM: | ||
53 | + /* SVQ trust in the host's IOMMU to translate addresses */ | ||
54 | + case VIRTIO_F_VERSION_1: | ||
55 | + /* SVQ trust that the guest vring is little endian */ | ||
56 | + if (!(svq_features & BIT_ULL(b))) { | ||
57 | + svq_features |= BIT_ULL(b); | ||
58 | + ok = false; | ||
59 | + } | ||
60 | + continue; | ||
61 | + | ||
62 | + default: | ||
63 | + if (svq_features & BIT_ULL(b)) { | ||
64 | + svq_features &= ~BIT_ULL(b); | ||
65 | + ok = false; | ||
66 | + } | ||
67 | + } | ||
68 | + } | ||
69 | + | ||
70 | + if (!ok) { | ||
71 | + error_setg(errp, "SVQ Invalid device feature flags, offer: 0x%"PRIx64 | ||
72 | + ", ok: 0x%"PRIx64, features, svq_features); | ||
73 | + } | ||
74 | + return ok; | ||
75 | +} | ||
76 | + | ||
77 | +/** | ||
78 | * Forward guest notifications. | ||
79 | * | ||
80 | * @n: guest kick event notifier, the one that guest set to notify svq. | ||
81 | diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/hw/virtio/vhost-shadow-virtqueue.h | ||
84 | +++ b/hw/virtio/vhost-shadow-virtqueue.h | ||
85 | @@ -XXX,XX +XXX,XX @@ typedef struct VhostShadowVirtqueue { | ||
86 | EventNotifier svq_call; | ||
87 | } VhostShadowVirtqueue; | ||
88 | |||
89 | +bool vhost_svq_valid_features(uint64_t features, Error **errp); | ||
90 | + | ||
91 | void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); | ||
92 | void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); | ||
93 | |||
94 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c | ||
95 | index XXXXXXX..XXXXXXX 100644 | ||
96 | --- a/hw/virtio/vhost-vdpa.c | ||
97 | +++ b/hw/virtio/vhost-vdpa.c | ||
98 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, | ||
99 | Error **errp) | ||
100 | { | ||
101 | g_autoptr(GPtrArray) shadow_vqs = NULL; | ||
102 | + uint64_t dev_features, svq_features; | ||
103 | + int r; | ||
104 | + bool ok; | ||
105 | |||
106 | if (!v->shadow_vqs_enabled) { | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | + r = hdev->vhost_ops->vhost_get_features(hdev, &dev_features); | ||
111 | + if (r != 0) { | ||
112 | + error_setg_errno(errp, -r, "Can't get vdpa device features"); | ||
113 | + return r; | ||
114 | + } | ||
115 | + | ||
116 | + svq_features = dev_features; | ||
117 | + ok = vhost_svq_valid_features(svq_features, errp); | ||
118 | + if (unlikely(!ok)) { | ||
119 | + return -1; | ||
120 | + } | ||
121 | + | ||
122 | shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); | ||
123 | for (unsigned n = 0; n < hdev->nvqs; ++n) { | ||
124 | g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(); | ||
125 | -- | ||
126 | 2.7.4 | ||
127 | |||
128 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Eugenio Pérez <eperezma@redhat.com> | ||
1 | 2 | ||
3 | It reports the shadow virtqueue address from qemu virtual address space. | ||
4 | |||
5 | Since this will be different from the guest's vaddr, but the device can | ||
6 | access it, SVQ takes special care about its alignment & lack of garbage | ||
7 | data. It assumes that IOMMU will work in host_page_size ranges for that. | ||
8 | |||
9 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
10 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
12 | --- | ||
13 | hw/virtio/vhost-shadow-virtqueue.c | 29 +++++++++++++++++++++++++++++ | ||
14 | hw/virtio/vhost-shadow-virtqueue.h | 9 +++++++++ | ||
15 | 2 files changed, 38 insertions(+) | ||
16 | |||
17 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/virtio/vhost-shadow-virtqueue.c | ||
20 | +++ b/hw/virtio/vhost-shadow-virtqueue.c | ||
21 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd) | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | + * Get the shadow vq vring address. | ||
26 | + * @svq: Shadow virtqueue | ||
27 | + * @addr: Destination to store address | ||
28 | + */ | ||
29 | +void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, | ||
30 | + struct vhost_vring_addr *addr) | ||
31 | +{ | ||
32 | + addr->desc_user_addr = (uint64_t)(intptr_t)svq->vring.desc; | ||
33 | + addr->avail_user_addr = (uint64_t)(intptr_t)svq->vring.avail; | ||
34 | + addr->used_user_addr = (uint64_t)(intptr_t)svq->vring.used; | ||
35 | +} | ||
36 | + | ||
37 | +size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq) | ||
38 | +{ | ||
39 | + size_t desc_size = sizeof(vring_desc_t) * svq->vring.num; | ||
40 | + size_t avail_size = offsetof(vring_avail_t, ring) + | ||
41 | + sizeof(uint16_t) * svq->vring.num; | ||
42 | + | ||
43 | + return ROUND_UP(desc_size + avail_size, qemu_real_host_page_size); | ||
44 | +} | ||
45 | + | ||
46 | +size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq) | ||
47 | +{ | ||
48 | + size_t used_size = offsetof(vring_used_t, ring) + | ||
49 | + sizeof(vring_used_elem_t) * svq->vring.num; | ||
50 | + return ROUND_UP(used_size, qemu_real_host_page_size); | ||
51 | +} | ||
52 | + | ||
53 | +/** | ||
54 | * Set a new file descriptor for the guest to kick the SVQ and notify for avail | ||
55 | * | ||
56 | * @svq: The svq | ||
57 | diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/hw/virtio/vhost-shadow-virtqueue.h | ||
60 | +++ b/hw/virtio/vhost-shadow-virtqueue.h | ||
61 | @@ -XXX,XX +XXX,XX @@ | ||
62 | #define VHOST_SHADOW_VIRTQUEUE_H | ||
63 | |||
64 | #include "qemu/event_notifier.h" | ||
65 | +#include "hw/virtio/virtio.h" | ||
66 | +#include "standard-headers/linux/vhost_types.h" | ||
67 | |||
68 | /* Shadow virtqueue to relay notifications */ | ||
69 | typedef struct VhostShadowVirtqueue { | ||
70 | + /* Shadow vring */ | ||
71 | + struct vring vring; | ||
72 | + | ||
73 | /* Shadow kick notifier, sent to vhost */ | ||
74 | EventNotifier hdev_kick; | ||
75 | /* Shadow call notifier, sent to vhost */ | ||
76 | @@ -XXX,XX +XXX,XX @@ bool vhost_svq_valid_features(uint64_t features, Error **errp); | ||
77 | |||
78 | void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); | ||
79 | void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); | ||
80 | +void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, | ||
81 | + struct vhost_vring_addr *addr); | ||
82 | +size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq); | ||
83 | +size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq); | ||
84 | |||
85 | void vhost_svq_stop(VhostShadowVirtqueue *svq); | ||
86 | |||
87 | -- | ||
88 | 2.7.4 | ||
89 | |||
90 | diff view generated by jsdifflib |
1 | Several issues has been reported for query-netdev series. Consider | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | it's late in the rc, this reverts commit | ||
3 | d32ad10a14d46dfe9304e3ed5858a11dcd5c71a0. | ||
4 | 2 | ||
3 | First half of the buffers forwarding part, preparing vhost-vdpa | ||
4 | callbacks to SVQ to offer it. QEMU cannot enable it at this moment, so | ||
5 | this is effectively dead code at the moment, but it helps to reduce | ||
6 | patch size. | ||
7 | |||
8 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
9 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
5 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 10 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
6 | --- | 11 | --- |
7 | include/net/net.h | 3 -- | 12 | hw/virtio/vhost-vdpa.c | 48 +++++++++++++++++++++++++++++++++++++++++------- |
8 | net/l2tpv3.c | 7 ---- | 13 | 1 file changed, 41 insertions(+), 7 deletions(-) |
9 | net/net.c | 30 +------------- | ||
10 | net/netmap.c | 7 ---- | ||
11 | net/slirp.c | 122 ------------------------------------------------------ | ||
12 | net/socket.c | 71 ------------------------------- | ||
13 | net/tap-win32.c | 9 ---- | ||
14 | net/tap.c | 103 +++------------------------------------------ | ||
15 | net/vde.c | 22 ---------- | ||
16 | net/vhost-user.c | 18 ++------ | ||
17 | net/vhost-vdpa.c | 14 ------- | ||
18 | qapi/net.json | 80 ----------------------------------- | ||
19 | 12 files changed, 9 insertions(+), 477 deletions(-) | ||
20 | 14 | ||
21 | diff --git a/include/net/net.h b/include/net/net.h | 15 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c |
22 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/include/net/net.h | 17 | --- a/hw/virtio/vhost-vdpa.c |
24 | +++ b/include/net/net.h | 18 | +++ b/hw/virtio/vhost-vdpa.c |
25 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, |
26 | #include "qapi/qapi-types-net.h" | 20 | return ret; |
27 | #include "net/queue.h" | 21 | } |
28 | #include "hw/qdev-properties-system.h" | 22 | |
29 | -#include "qapi/clone-visitor.h" | 23 | +static int vhost_vdpa_set_dev_vring_base(struct vhost_dev *dev, |
30 | -#include "qapi/qapi-visit-net.h" | 24 | + struct vhost_vring_state *ring) |
31 | 25 | +{ | |
32 | #define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X" | 26 | + trace_vhost_vdpa_set_vring_base(dev, ring->index, ring->num); |
33 | #define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \ | 27 | + return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); |
34 | @@ -XXX,XX +XXX,XX @@ struct NetClientState { | 28 | +} |
35 | char *model; | 29 | + |
36 | char *name; | 30 | static int vhost_vdpa_set_vring_dev_kick(struct vhost_dev *dev, |
37 | char info_str[256]; | 31 | struct vhost_vring_file *file) |
38 | - NetdevInfo *stored_config; | 32 | { |
39 | unsigned receive_disabled : 1; | 33 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_dev_call(struct vhost_dev *dev, |
40 | NetClientDestructor *destructor; | 34 | return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); |
41 | unsigned int queue_index; | ||
42 | diff --git a/net/l2tpv3.c b/net/l2tpv3.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/net/l2tpv3.c | ||
45 | +++ b/net/l2tpv3.c | ||
46 | @@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev, | ||
47 | |||
48 | l2tpv3_read_poll(s, true); | ||
49 | |||
50 | - /* Store startup parameters */ | ||
51 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
52 | - nc->stored_config->type = NET_BACKEND_L2TPV3; | ||
53 | - | ||
54 | - QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, | ||
55 | - &nc->stored_config->u.l2tpv3, l2tpv3); | ||
56 | - | ||
57 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
58 | "l2tpv3: connected"); | ||
59 | return 0; | ||
60 | diff --git a/net/net.c b/net/net.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/net/net.c | ||
63 | +++ b/net/net.c | ||
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | #include "monitor/monitor.h" | ||
66 | #include "qemu/help_option.h" | ||
67 | #include "qapi/qapi-commands-net.h" | ||
68 | +#include "qapi/qapi-visit-net.h" | ||
69 | #include "qapi/qmp/qdict.h" | ||
70 | #include "qapi/qmp/qerror.h" | ||
71 | #include "qemu/error-report.h" | ||
72 | @@ -XXX,XX +XXX,XX @@ static void qemu_free_net_client(NetClientState *nc) | ||
73 | } | ||
74 | g_free(nc->name); | ||
75 | g_free(nc->model); | ||
76 | - qapi_free_NetdevInfo(nc->stored_config); | ||
77 | if (nc->destructor) { | ||
78 | nc->destructor(nc); | ||
79 | } | ||
80 | @@ -XXX,XX +XXX,XX @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name, | ||
81 | return filter_list; | ||
82 | } | 35 | } |
83 | 36 | ||
84 | -NetdevInfoList *qmp_query_netdev(Error **errp) | 37 | +static int vhost_vdpa_set_vring_dev_addr(struct vhost_dev *dev, |
85 | -{ | 38 | + struct vhost_vring_addr *addr) |
86 | - NetdevInfoList *list = NULL; | 39 | +{ |
87 | - NetClientState *nc; | 40 | + trace_vhost_vdpa_set_vring_addr(dev, addr->index, addr->flags, |
88 | - | 41 | + addr->desc_user_addr, addr->used_user_addr, |
89 | - QTAILQ_FOREACH(nc, &net_clients, next) { | 42 | + addr->avail_user_addr, |
90 | - /* | 43 | + addr->log_guest_addr); |
91 | - * Only look at netdevs (backend network devices), not for each queue | 44 | + |
92 | - * or NIC / hubport | 45 | + return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); |
93 | - */ | 46 | + |
94 | - if (nc->stored_config) { | 47 | +} |
95 | - NetdevInfo *element = QAPI_CLONE(NetdevInfo, nc->stored_config); | 48 | + |
96 | - | 49 | /** |
97 | - g_free(element->id); /* Need to dealloc empty id after clone */ | 50 | * Set the shadow virtqueue descriptors to the device |
98 | - element->id = g_strdup(nc->name); | 51 | * |
99 | - | 52 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, |
100 | - element->has_peer_id = nc->peer != NULL; | 53 | static int vhost_vdpa_set_vring_addr(struct vhost_dev *dev, |
101 | - if (element->has_peer_id) { | 54 | struct vhost_vring_addr *addr) |
102 | - element->peer_id = g_strdup(nc->peer->name); | ||
103 | - } | ||
104 | - | ||
105 | - QAPI_LIST_PREPEND(list, element); | ||
106 | - } | ||
107 | - } | ||
108 | - | ||
109 | - return list; | ||
110 | -} | ||
111 | - | ||
112 | void hmp_info_network(Monitor *mon, const QDict *qdict) | ||
113 | { | 55 | { |
114 | NetClientState *nc, *peer; | 56 | - trace_vhost_vdpa_set_vring_addr(dev, addr->index, addr->flags, |
115 | diff --git a/net/netmap.c b/net/netmap.c | 57 | - addr->desc_user_addr, addr->used_user_addr, |
116 | index XXXXXXX..XXXXXXX 100644 | 58 | - addr->avail_user_addr, |
117 | --- a/net/netmap.c | 59 | - addr->log_guest_addr); |
118 | +++ b/net/netmap.c | 60 | - return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); |
119 | @@ -XXX,XX +XXX,XX @@ int net_init_netmap(const Netdev *netdev, | 61 | + struct vhost_vdpa *v = dev->opaque; |
120 | pstrcpy(s->ifname, sizeof(s->ifname), netmap_opts->ifname); | 62 | + |
121 | netmap_read_poll(s, true); /* Initially only poll for reads. */ | 63 | + if (v->shadow_vqs_enabled) { |
122 | 64 | + /* | |
123 | - /* Store startup parameters */ | 65 | + * Device vring addr was set at device start. SVQ base is handled by |
124 | - nc->stored_config = g_new0(NetdevInfo, 1); | 66 | + * VirtQueue code. |
125 | - nc->stored_config->type = NET_BACKEND_NETMAP; | 67 | + */ |
126 | - | 68 | + return 0; |
127 | - QAPI_CLONE_MEMBERS(NetdevNetmapOptions, | 69 | + } |
128 | - &nc->stored_config->u.netmap, netmap_opts); | 70 | + |
129 | - | 71 | + return vhost_vdpa_set_vring_dev_addr(dev, addr); |
130 | return 0; | ||
131 | } | 72 | } |
132 | 73 | ||
133 | diff --git a/net/slirp.c b/net/slirp.c | 74 | static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, |
134 | index XXXXXXX..XXXXXXX 100644 | 75 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, |
135 | --- a/net/slirp.c | 76 | static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, |
136 | +++ b/net/slirp.c | 77 | struct vhost_vring_state *ring) |
137 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | ||
138 | int shift; | ||
139 | char *end; | ||
140 | struct slirp_config_str *config; | ||
141 | - NetdevUserOptions *stored; | ||
142 | - StringList **stored_hostfwd; | ||
143 | - StringList **stored_guestfwd; | ||
144 | |||
145 | if (!ipv4 && (vnetwork || vhost || vnameserver)) { | ||
146 | error_setg(errp, "IPv4 disabled but netmask/host/dns provided"); | ||
147 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | ||
148 | |||
149 | nc = qemu_new_net_client(&net_slirp_info, peer, model, name); | ||
150 | |||
151 | - /* Store startup parameters */ | ||
152 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
153 | - nc->stored_config->type = NET_BACKEND_USER; | ||
154 | - stored = &nc->stored_config->u.user; | ||
155 | - | ||
156 | - if (vhostname) { | ||
157 | - stored->has_hostname = true; | ||
158 | - stored->hostname = g_strdup(vhostname); | ||
159 | - } | ||
160 | - | ||
161 | - stored->has_q_restrict = true; | ||
162 | - stored->q_restrict = restricted; | ||
163 | - | ||
164 | - stored->has_ipv4 = true; | ||
165 | - stored->ipv4 = ipv4; | ||
166 | - | ||
167 | - stored->has_ipv6 = true; | ||
168 | - stored->ipv6 = ipv6; | ||
169 | - | ||
170 | - if (ipv4) { | ||
171 | - uint8_t *net_bytes = (uint8_t *)&net; | ||
172 | - uint8_t *mask_bytes = (uint8_t *)&mask; | ||
173 | - | ||
174 | - stored->has_net = true; | ||
175 | - stored->net = g_strdup_printf("%d.%d.%d.%d/%d.%d.%d.%d", | ||
176 | - net_bytes[0], net_bytes[1], | ||
177 | - net_bytes[2], net_bytes[3], | ||
178 | - mask_bytes[0], mask_bytes[1], | ||
179 | - mask_bytes[2], mask_bytes[3]); | ||
180 | - | ||
181 | - stored->has_host = true; | ||
182 | - stored->host = g_strdup(inet_ntoa(host)); | ||
183 | - } | ||
184 | - | ||
185 | - if (tftp_export) { | ||
186 | - stored->has_tftp = true; | ||
187 | - stored->tftp = g_strdup(tftp_export); | ||
188 | - } | ||
189 | - | ||
190 | - if (bootfile) { | ||
191 | - stored->has_bootfile = true; | ||
192 | - stored->bootfile = g_strdup(bootfile); | ||
193 | - } | ||
194 | - | ||
195 | - if (vdhcp_start) { | ||
196 | - stored->has_dhcpstart = true; | ||
197 | - stored->dhcpstart = g_strdup(vdhcp_start); | ||
198 | - } | ||
199 | - | ||
200 | - if (ipv4) { | ||
201 | - stored->has_dns = true; | ||
202 | - stored->dns = g_strdup(inet_ntoa(dns)); | ||
203 | - } | ||
204 | - | ||
205 | - if (dnssearch) { | ||
206 | - stored->has_dnssearch = true; | ||
207 | - StringList **stored_list = &stored->dnssearch; | ||
208 | - | ||
209 | - for (int i = 0; dnssearch[i]; i++) { | ||
210 | - String *element = g_new0(String, 1); | ||
211 | - | ||
212 | - element->str = g_strdup(dnssearch[i]); | ||
213 | - QAPI_LIST_APPEND(stored_list, element); | ||
214 | - } | ||
215 | - } | ||
216 | - | ||
217 | - if (vdomainname) { | ||
218 | - stored->has_domainname = true; | ||
219 | - stored->domainname = g_strdup(vdomainname); | ||
220 | - } | ||
221 | - | ||
222 | - if (ipv6) { | ||
223 | - char addrstr[INET6_ADDRSTRLEN]; | ||
224 | - const char *res; | ||
225 | - | ||
226 | - stored->has_ipv6_prefix = true; | ||
227 | - stored->ipv6_prefix = g_strdup(vprefix6); | ||
228 | - | ||
229 | - stored->has_ipv6_prefixlen = true; | ||
230 | - stored->ipv6_prefixlen = vprefix6_len; | ||
231 | - | ||
232 | - res = inet_ntop(AF_INET6, &ip6_host, | ||
233 | - addrstr, sizeof(addrstr)); | ||
234 | - | ||
235 | - stored->has_ipv6_host = true; | ||
236 | - stored->ipv6_host = g_strdup(res); | ||
237 | - | ||
238 | - res = inet_ntop(AF_INET6, &ip6_dns, | ||
239 | - addrstr, sizeof(addrstr)); | ||
240 | - | ||
241 | - stored->has_ipv6_dns = true; | ||
242 | - stored->ipv6_dns = g_strdup(res); | ||
243 | - } | ||
244 | - | ||
245 | - if (smb_export) { | ||
246 | - stored->has_smb = true; | ||
247 | - stored->smb = g_strdup(smb_export); | ||
248 | - } | ||
249 | - | ||
250 | - if (vsmbserver) { | ||
251 | - stored->has_smbserver = true; | ||
252 | - stored->smbserver = g_strdup(vsmbserver); | ||
253 | - } | ||
254 | - | ||
255 | - if (tftp_server_name) { | ||
256 | - stored->has_tftp_server_name = true; | ||
257 | - stored->tftp_server_name = g_strdup(tftp_server_name); | ||
258 | - } | ||
259 | - | ||
260 | snprintf(nc->info_str, sizeof(nc->info_str), | ||
261 | "net=%s,restrict=%s", inet_ntoa(net), | ||
262 | restricted ? "on" : "off"); | ||
263 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | ||
264 | s->poll_notifier.notify = net_slirp_poll_notify; | ||
265 | main_loop_poll_add_notifier(&s->poll_notifier); | ||
266 | |||
267 | - stored_hostfwd = &stored->hostfwd; | ||
268 | - stored_guestfwd = &stored->guestfwd; | ||
269 | - | ||
270 | for (config = slirp_configs; config; config = config->next) { | ||
271 | - String *element = g_new0(String, 1); | ||
272 | - | ||
273 | - element->str = g_strdup(config->str); | ||
274 | if (config->flags & SLIRP_CFG_HOSTFWD) { | ||
275 | if (slirp_hostfwd(s, config->str, errp) < 0) { | ||
276 | goto error; | ||
277 | } | ||
278 | - stored->has_hostfwd = true; | ||
279 | - QAPI_LIST_APPEND(stored_hostfwd, element); | ||
280 | } else { | ||
281 | if (slirp_guestfwd(s, config->str, errp) < 0) { | ||
282 | goto error; | ||
283 | } | ||
284 | - stored->has_guestfwd = true; | ||
285 | - QAPI_LIST_APPEND(stored_guestfwd, element); | ||
286 | } | ||
287 | } | ||
288 | #ifndef _WIN32 | ||
289 | diff --git a/net/socket.c b/net/socket.c | ||
290 | index XXXXXXX..XXXXXXX 100644 | ||
291 | --- a/net/socket.c | ||
292 | +++ b/net/socket.c | ||
293 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, | ||
294 | NetSocketState *s; | ||
295 | SocketAddress *sa; | ||
296 | SocketAddressType sa_type; | ||
297 | - NetdevSocketOptions *stored; | ||
298 | |||
299 | sa = socket_local_address(fd, errp); | ||
300 | if (!sa) { | ||
301 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, | ||
302 | net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | ||
303 | net_socket_read_poll(s, true); | ||
304 | |||
305 | - /* Store startup parameters */ | ||
306 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
307 | - nc->stored_config->type = NET_BACKEND_SOCKET; | ||
308 | - stored = &nc->stored_config->u.socket; | ||
309 | - | ||
310 | - stored->has_fd = true; | ||
311 | - stored->fd = g_strdup_printf("%d", fd); | ||
312 | - | ||
313 | /* mcast: save bound address as dst */ | ||
314 | if (is_connected && mcast != NULL) { | ||
315 | - stored->has_mcast = true; | ||
316 | - stored->mcast = g_strdup(mcast); | ||
317 | - | ||
318 | s->dgram_dst = saddr; | ||
319 | snprintf(nc->info_str, sizeof(nc->info_str), | ||
320 | "socket: fd=%d (cloned mcast=%s:%d)", | ||
321 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, | ||
322 | { | 78 | { |
323 | NetClientState *nc; | 79 | - trace_vhost_vdpa_set_vring_base(dev, ring->index, ring->num); |
324 | NetSocketState *s; | 80 | - return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); |
325 | - NetdevSocketOptions *stored; | 81 | + struct vhost_vdpa *v = dev->opaque; |
326 | 82 | + | |
327 | nc = qemu_new_net_client(&net_socket_info, peer, model, name); | 83 | + if (v->shadow_vqs_enabled) { |
328 | 84 | + /* | |
329 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, | 85 | + * Device vring base was set at device start. SVQ base is handled by |
330 | } else { | 86 | + * VirtQueue code. |
331 | qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s); | 87 | + */ |
332 | } | 88 | + return 0; |
333 | - | 89 | + } |
334 | - /* Store startup parameters */ | 90 | + |
335 | - nc->stored_config = g_new0(NetdevInfo, 1); | 91 | + return vhost_vdpa_set_dev_vring_base(dev, ring); |
336 | - nc->stored_config->type = NET_BACKEND_SOCKET; | ||
337 | - stored = &nc->stored_config->u.socket; | ||
338 | - | ||
339 | - stored->has_fd = true; | ||
340 | - stored->fd = g_strdup_printf("%d", fd); | ||
341 | - | ||
342 | return s; | ||
343 | } | 92 | } |
344 | 93 | ||
345 | @@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque) | 94 | static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, |
346 | struct sockaddr_in saddr; | ||
347 | socklen_t len; | ||
348 | int fd; | ||
349 | - NetdevSocketOptions *stored; | ||
350 | |||
351 | for(;;) { | ||
352 | len = sizeof(saddr); | ||
353 | @@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque) | ||
354 | s->fd = fd; | ||
355 | s->nc.link_down = false; | ||
356 | net_socket_connect(s); | ||
357 | - | ||
358 | - /* Store additional startup parameters (extend net_socket_listen_init) */ | ||
359 | - stored = &s->nc.stored_config->u.socket; | ||
360 | - | ||
361 | - stored->has_fd = true; | ||
362 | - stored->fd = g_strdup_printf("%d", fd); | ||
363 | - | ||
364 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
365 | "socket: connection from %s:%d", | ||
366 | inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
367 | @@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer, | ||
368 | NetSocketState *s; | ||
369 | struct sockaddr_in saddr; | ||
370 | int fd, ret; | ||
371 | - NetdevSocketOptions *stored; | ||
372 | |||
373 | if (parse_host_port(&saddr, host_str, errp) < 0) { | ||
374 | return -1; | ||
375 | @@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer, | ||
376 | net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | ||
377 | |||
378 | qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); | ||
379 | - | ||
380 | - /* Store startup parameters */ | ||
381 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
382 | - nc->stored_config->type = NET_BACKEND_SOCKET; | ||
383 | - stored = &nc->stored_config->u.socket; | ||
384 | - | ||
385 | - stored->has_listen = true; | ||
386 | - stored->listen = g_strdup(host_str); | ||
387 | - | ||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, | ||
392 | NetSocketState *s; | ||
393 | int fd, connected, ret; | ||
394 | struct sockaddr_in saddr; | ||
395 | - NetdevSocketOptions *stored; | ||
396 | |||
397 | if (parse_host_port(&saddr, host_str, errp) < 0) { | ||
398 | return -1; | ||
399 | @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, | ||
400 | return -1; | ||
401 | } | ||
402 | |||
403 | - /* Store additional startup parameters (extend net_socket_fd_init) */ | ||
404 | - stored = &s->nc.stored_config->u.socket; | ||
405 | - | ||
406 | - stored->has_connect = true; | ||
407 | - stored->connect = g_strdup(host_str); | ||
408 | - | ||
409 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
410 | "socket: connect to %s:%d", | ||
411 | inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
412 | @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer, | ||
413 | int fd; | ||
414 | struct sockaddr_in saddr; | ||
415 | struct in_addr localaddr, *param_localaddr; | ||
416 | - NetdevSocketOptions *stored; | ||
417 | |||
418 | if (parse_host_port(&saddr, host_str, errp) < 0) { | ||
419 | return -1; | ||
420 | @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer, | ||
421 | |||
422 | s->dgram_dst = saddr; | ||
423 | |||
424 | - /* Store additional startup parameters (extend net_socket_fd_init) */ | ||
425 | - stored = &s->nc.stored_config->u.socket; | ||
426 | - | ||
427 | - if (!stored->has_mcast) { | ||
428 | - stored->has_mcast = true; | ||
429 | - stored->mcast = g_strdup(host_str); | ||
430 | - } | ||
431 | - | ||
432 | - if (localaddr_str) { | ||
433 | - stored->has_localaddr = true; | ||
434 | - stored->localaddr = g_strdup(localaddr_str); | ||
435 | - } | ||
436 | - | ||
437 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
438 | "socket: mcast=%s:%d", | ||
439 | inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
440 | @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, | ||
441 | NetSocketState *s; | ||
442 | int fd, ret; | ||
443 | struct sockaddr_in laddr, raddr; | ||
444 | - NetdevSocketOptions *stored; | ||
445 | |||
446 | if (parse_host_port(&laddr, lhost, errp) < 0) { | ||
447 | return -1; | ||
448 | @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, | ||
449 | |||
450 | s->dgram_dst = raddr; | ||
451 | |||
452 | - /* Store additional startup parameters (extend net_socket_fd_init) */ | ||
453 | - stored = &s->nc.stored_config->u.socket; | ||
454 | - | ||
455 | - stored->has_localaddr = true; | ||
456 | - stored->localaddr = g_strdup(lhost); | ||
457 | - | ||
458 | - stored->has_udp = true; | ||
459 | - stored->udp = g_strdup(rhost); | ||
460 | - | ||
461 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
462 | "socket: udp=%s:%d", | ||
463 | inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); | ||
464 | diff --git a/net/tap-win32.c b/net/tap-win32.c | ||
465 | index XXXXXXX..XXXXXXX 100644 | ||
466 | --- a/net/tap-win32.c | ||
467 | +++ b/net/tap-win32.c | ||
468 | @@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model, | ||
469 | NetClientState *nc; | ||
470 | TAPState *s; | ||
471 | tap_win32_overlapped_t *handle; | ||
472 | - NetdevTapOptions *stored; | ||
473 | |||
474 | if (tap_win32_open(&handle, ifname) < 0) { | ||
475 | printf("tap: Could not open '%s'\n", ifname); | ||
476 | @@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model, | ||
477 | |||
478 | s = DO_UPCAST(TAPState, nc, nc); | ||
479 | |||
480 | - /* Store startup parameters */ | ||
481 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
482 | - nc->stored_config->type = NET_BACKEND_TAP; | ||
483 | - stored = &nc->stored_config->u.tap; | ||
484 | - | ||
485 | - stored->has_ifname = true; | ||
486 | - stored->ifname = g_strdup(ifname); | ||
487 | - | ||
488 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
489 | "tap: ifname=%s", ifname); | ||
490 | |||
491 | diff --git a/net/tap.c b/net/tap.c | ||
492 | index XXXXXXX..XXXXXXX 100644 | ||
493 | --- a/net/tap.c | ||
494 | +++ b/net/tap.c | ||
495 | @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, | ||
496 | const char *helper, *br; | ||
497 | TAPState *s; | ||
498 | int fd, vnet_hdr; | ||
499 | - NetdevBridgeOptions *stored; | ||
500 | |||
501 | assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE); | ||
502 | bridge = &netdev->u.bridge; | ||
503 | @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, | ||
504 | } | ||
505 | s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); | ||
506 | |||
507 | - /* Store startup parameters */ | ||
508 | - s->nc.stored_config = g_new0(NetdevInfo, 1); | ||
509 | - s->nc.stored_config->type = NET_BACKEND_BRIDGE; | ||
510 | - stored = &s->nc.stored_config->u.bridge; | ||
511 | - | ||
512 | - if (br) { | ||
513 | - stored->has_br = true; | ||
514 | - stored->br = g_strdup(br); | ||
515 | - } | ||
516 | - | ||
517 | - if (helper) { | ||
518 | - stored->has_helper = true; | ||
519 | - stored->helper = g_strdup(helper); | ||
520 | - } | ||
521 | - | ||
522 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper, | ||
523 | br); | ||
524 | |||
525 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
526 | const char *model, const char *name, | ||
527 | const char *ifname, const char *script, | ||
528 | const char *downscript, const char *vhostfdname, | ||
529 | - int vnet_hdr, int fd, NetdevInfo **common_stored, | ||
530 | - Error **errp) | ||
531 | + int vnet_hdr, int fd, Error **errp) | ||
532 | { | ||
533 | Error *err = NULL; | ||
534 | TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr); | ||
535 | int vhostfd; | ||
536 | - NetdevTapOptions *stored; | ||
537 | |||
538 | tap_set_sndbuf(s->fd, tap, &err); | ||
539 | if (err) { | ||
540 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
541 | return; | ||
542 | } | ||
543 | |||
544 | - /* Store startup parameters */ | ||
545 | - if (!*common_stored) { | ||
546 | - *common_stored = g_new0(NetdevInfo, 1); | ||
547 | - (*common_stored)->type = NET_BACKEND_TAP; | ||
548 | - s->nc.stored_config = *common_stored; | ||
549 | - } | ||
550 | - stored = &(*common_stored)->u.tap; | ||
551 | - | ||
552 | - if (tap->has_sndbuf && !stored->has_sndbuf) { | ||
553 | - stored->has_sndbuf = true; | ||
554 | - stored->sndbuf = tap->sndbuf; | ||
555 | - } | ||
556 | - | ||
557 | - if (vnet_hdr && !stored->has_vnet_hdr) { | ||
558 | - stored->has_vnet_hdr = true; | ||
559 | - stored->vnet_hdr = true; | ||
560 | - } | ||
561 | - | ||
562 | if (tap->has_fd || tap->has_fds) { | ||
563 | - if (!stored->has_fds) { | ||
564 | - stored->has_fds = true; | ||
565 | - stored->fds = g_strdup_printf("%d", fd); | ||
566 | - } else { | ||
567 | - char *tmp_s = stored->fds; | ||
568 | - stored->fds = g_strdup_printf("%s:%d", stored->fds, fd); | ||
569 | - g_free(tmp_s); | ||
570 | - } | ||
571 | - | ||
572 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd); | ||
573 | } else if (tap->has_helper) { | ||
574 | - if (!stored->has_helper) { | ||
575 | - stored->has_helper = true; | ||
576 | - stored->helper = g_strdup(tap->helper); | ||
577 | - } | ||
578 | - | ||
579 | - if (!stored->has_br) { | ||
580 | - stored->has_br = true; | ||
581 | - stored->br = tap->has_br ? g_strdup(tap->br) : | ||
582 | - g_strdup(DEFAULT_BRIDGE_INTERFACE); | ||
583 | - } | ||
584 | - | ||
585 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s", | ||
586 | tap->helper); | ||
587 | } else { | ||
588 | - if (ifname && !stored->has_ifname) { | ||
589 | - stored->has_ifname = true; | ||
590 | - stored->ifname = g_strdup(ifname); | ||
591 | - } | ||
592 | - | ||
593 | - if (script && !stored->has_script) { | ||
594 | - stored->has_script = true; | ||
595 | - stored->script = g_strdup(script); | ||
596 | - } | ||
597 | - | ||
598 | - if (downscript && !stored->has_downscript) { | ||
599 | - stored->has_downscript = true; | ||
600 | - stored->downscript = g_strdup(downscript); | ||
601 | - } | ||
602 | - | ||
603 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
604 | "ifname=%s,script=%s,downscript=%s", ifname, script, | ||
605 | downscript); | ||
606 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
607 | vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { | ||
608 | VhostNetOptions options; | ||
609 | |||
610 | - stored->has_vhost = true; | ||
611 | - stored->vhost = true; | ||
612 | - | ||
613 | - if (tap->has_vhostforce && tap->vhostforce) { | ||
614 | - stored->has_vhostforce = true; | ||
615 | - stored->vhostforce = true; | ||
616 | - } | ||
617 | - | ||
618 | options.backend_type = VHOST_BACKEND_TYPE_KERNEL; | ||
619 | options.net_backend = &s->nc; | ||
620 | if (tap->has_poll_us) { | ||
621 | - stored->has_poll_us = true; | ||
622 | - stored->poll_us = tap->poll_us; | ||
623 | - | ||
624 | options.busyloop_timeout = tap->poll_us; | ||
625 | } else { | ||
626 | options.busyloop_timeout = 0; | ||
627 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
628 | } | ||
629 | options.opaque = (void *)(uintptr_t)vhostfd; | ||
630 | |||
631 | - if (!stored->has_vhostfds) { | ||
632 | - stored->has_vhostfds = true; | ||
633 | - stored->vhostfds = g_strdup_printf("%d", vhostfd); | ||
634 | - } else { | ||
635 | - char *tmp_s = stored->vhostfds; | ||
636 | - stored->vhostfds = g_strdup_printf("%s:%d", stored->fds, vhostfd); | ||
637 | - g_free(tmp_s); | ||
638 | - } | ||
639 | - | ||
640 | s->vhost_net = vhost_net_init(&options); | ||
641 | if (!s->vhost_net) { | ||
642 | if (tap->has_vhostforce && tap->vhostforce) { | ||
643 | @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, | ||
644 | const char *vhostfdname; | ||
645 | char ifname[128]; | ||
646 | int ret = 0; | ||
647 | - NetdevInfo *common_stored = NULL; /* will store configuration */ | ||
648 | |||
649 | assert(netdev->type == NET_CLIENT_DRIVER_TAP); | ||
650 | tap = &netdev->u.tap; | ||
651 | @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, | ||
652 | |||
653 | net_init_tap_one(tap, peer, "tap", name, NULL, | ||
654 | script, downscript, | ||
655 | - vhostfdname, vnet_hdr, fd, &common_stored, &err); | ||
656 | + vhostfdname, vnet_hdr, fd, &err); | ||
657 | if (err) { | ||
658 | error_propagate(errp, err); | ||
659 | close(fd); | ||
660 | @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, | ||
661 | net_init_tap_one(tap, peer, "tap", name, ifname, | ||
662 | script, downscript, | ||
663 | tap->has_vhostfds ? vhost_fds[i] : NULL, | ||
664 | - vnet_hdr, fd, &common_stored, &err); | ||
665 | + vnet_hdr, fd, &err); | ||
666 | if (err) { | ||
667 | error_propagate(errp, err); | ||
668 | ret = -1; | ||
669 | @@ -XXX,XX +XXX,XX @@ free_fail: | ||
670 | |||
671 | net_init_tap_one(tap, peer, "bridge", name, ifname, | ||
672 | script, downscript, vhostfdname, | ||
673 | - vnet_hdr, fd, &common_stored, &err); | ||
674 | + vnet_hdr, fd, &err); | ||
675 | if (err) { | ||
676 | error_propagate(errp, err); | ||
677 | close(fd); | ||
678 | @@ -XXX,XX +XXX,XX @@ free_fail: | ||
679 | net_init_tap_one(tap, peer, "tap", name, ifname, | ||
680 | i >= 1 ? "no" : script, | ||
681 | i >= 1 ? "no" : downscript, | ||
682 | - vhostfdname, vnet_hdr, fd, | ||
683 | - &common_stored, &err); | ||
684 | + vhostfdname, vnet_hdr, fd, &err); | ||
685 | if (err) { | ||
686 | error_propagate(errp, err); | ||
687 | close(fd); | ||
688 | diff --git a/net/vde.c b/net/vde.c | ||
689 | index XXXXXXX..XXXXXXX 100644 | ||
690 | --- a/net/vde.c | ||
691 | +++ b/net/vde.c | ||
692 | @@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model, | ||
693 | VDECONN *vde; | ||
694 | char *init_group = (char *)group; | ||
695 | char *init_sock = (char *)sock; | ||
696 | - NetdevVdeOptions *stored; | ||
697 | |||
698 | struct vde_open_args args = { | ||
699 | .port = port, | ||
700 | @@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model, | ||
701 | |||
702 | qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); | ||
703 | |||
704 | - /* Store startup parameters */ | ||
705 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
706 | - nc->stored_config->type = NET_BACKEND_VDE; | ||
707 | - stored = &nc->stored_config->u.vde; | ||
708 | - | ||
709 | - if (sock) { | ||
710 | - stored->has_sock = true; | ||
711 | - stored->sock = g_strdup(sock); | ||
712 | - } | ||
713 | - | ||
714 | - stored->has_port = true; | ||
715 | - stored->port = port; | ||
716 | - | ||
717 | - if (group) { | ||
718 | - stored->has_group = true; | ||
719 | - stored->group = g_strdup(group); | ||
720 | - } | ||
721 | - | ||
722 | - stored->has_mode = true; | ||
723 | - stored->mode = mode; | ||
724 | - | ||
725 | return 0; | ||
726 | } | ||
727 | |||
728 | diff --git a/net/vhost-user.c b/net/vhost-user.c | ||
729 | index XXXXXXX..XXXXXXX 100644 | ||
730 | --- a/net/vhost-user.c | ||
731 | +++ b/net/vhost-user.c | ||
732 | @@ -XXX,XX +XXX,XX @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event) | ||
733 | } | ||
734 | |||
735 | static int net_vhost_user_init(NetClientState *peer, const char *device, | ||
736 | - const char *name, const char *chardev, | ||
737 | - Chardev *chr, int queues) | ||
738 | + const char *name, Chardev *chr, | ||
739 | + int queues) | ||
740 | { | ||
741 | Error *err = NULL; | ||
742 | NetClientState *nc, *nc0 = NULL; | ||
743 | NetVhostUserState *s = NULL; | ||
744 | VhostUserState *user; | ||
745 | int i; | ||
746 | - NetdevVhostUserOptions *stored; | ||
747 | |||
748 | assert(name); | ||
749 | assert(queues > 0); | ||
750 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device, | ||
751 | |||
752 | assert(s->vhost_net); | ||
753 | |||
754 | - /* Store startup parameters */ | ||
755 | - nc0->stored_config = g_new0(NetdevInfo, 1); | ||
756 | - nc0->stored_config->type = NET_BACKEND_VHOST_USER; | ||
757 | - stored = &nc0->stored_config->u.vhost_user; | ||
758 | - | ||
759 | - stored->chardev = g_strdup(chardev); | ||
760 | - | ||
761 | - stored->has_queues = true; | ||
762 | - stored->queues = queues; | ||
763 | - | ||
764 | return 0; | ||
765 | |||
766 | err: | ||
767 | @@ -XXX,XX +XXX,XX @@ int net_init_vhost_user(const Netdev *netdev, const char *name, | ||
768 | return -1; | ||
769 | } | ||
770 | |||
771 | - return net_vhost_user_init(peer, "vhost_user", name, | ||
772 | - vhost_user_opts->chardev, chr, queues); | ||
773 | + return net_vhost_user_init(peer, "vhost_user", name, chr, queues); | ||
774 | } | ||
775 | diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c | ||
776 | index XXXXXXX..XXXXXXX 100644 | ||
777 | --- a/net/vhost-vdpa.c | ||
778 | +++ b/net/vhost-vdpa.c | ||
779 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, | ||
780 | VhostVDPAState *s; | ||
781 | int vdpa_device_fd = -1; | ||
782 | int ret = 0; | ||
783 | - NetdevVhostVDPAOptions *stored; | ||
784 | - | ||
785 | assert(name); | ||
786 | nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); | ||
787 | - | ||
788 | - /* Store startup parameters */ | ||
789 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
790 | - nc->stored_config->type = NET_BACKEND_VHOST_VDPA; | ||
791 | - stored = &nc->stored_config->u.vhost_vdpa; | ||
792 | - | ||
793 | - stored->has_vhostdev = true; | ||
794 | - stored->vhostdev = g_strdup(vhostdev); | ||
795 | - | ||
796 | - stored->has_queues = true; | ||
797 | - stored->queues = 1; /* TODO: change when support multiqueue */ | ||
798 | - | ||
799 | snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); | ||
800 | nc->queue_index = 0; | ||
801 | s = DO_UPCAST(VhostVDPAState, nc, nc); | ||
802 | diff --git a/qapi/net.json b/qapi/net.json | ||
803 | index XXXXXXX..XXXXXXX 100644 | ||
804 | --- a/qapi/net.json | ||
805 | +++ b/qapi/net.json | ||
806 | @@ -XXX,XX +XXX,XX @@ | ||
807 | ## | ||
808 | { 'event': 'FAILOVER_NEGOTIATED', | ||
809 | 'data': {'device-id': 'str'} } | ||
810 | - | ||
811 | -## | ||
812 | -# @NetBackend: | ||
813 | -# | ||
814 | -# Available netdev backend drivers. | ||
815 | -# | ||
816 | -# Since: 6.0 | ||
817 | -## | ||
818 | -{ 'enum': 'NetBackend', | ||
819 | - 'data': [ 'bridge', 'l2tpv3', 'netmap', 'socket', 'tap', 'user', 'vde', | ||
820 | - 'vhost-user', 'vhost-vdpa' ] } | ||
821 | - | ||
822 | -## | ||
823 | -# @NetdevInfo: | ||
824 | -# | ||
825 | -# Configuration of a network backend device (netdev). | ||
826 | -# | ||
827 | -# @id: Device identifier. | ||
828 | -# | ||
829 | -# @type: Specify the driver used for interpreting remaining arguments. | ||
830 | -# | ||
831 | -# @peer-id: The connected frontend network device name (absent if no frontend | ||
832 | -# is connected). | ||
833 | -# | ||
834 | -# Since: 6.0 | ||
835 | -## | ||
836 | -{ 'union': 'NetdevInfo', | ||
837 | - 'base': { 'id': 'str', | ||
838 | - 'type': 'NetBackend', | ||
839 | - '*peer-id': 'str' }, | ||
840 | - 'discriminator': 'type', | ||
841 | - 'data': { | ||
842 | - 'bridge': 'NetdevBridgeOptions', | ||
843 | - 'l2tpv3': 'NetdevL2TPv3Options', | ||
844 | - 'netmap': 'NetdevNetmapOptions', | ||
845 | - 'socket': 'NetdevSocketOptions', | ||
846 | - 'tap': 'NetdevTapOptions', | ||
847 | - 'user': 'NetdevUserOptions', | ||
848 | - 'vde': 'NetdevVdeOptions', | ||
849 | - 'vhost-user': 'NetdevVhostUserOptions', | ||
850 | - 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } | ||
851 | - | ||
852 | -## | ||
853 | -# @query-netdev: | ||
854 | -# | ||
855 | -# Get a list of @NetdevInfo for all virtual network backend devices (netdevs). | ||
856 | -# | ||
857 | -# Returns: a list of @NetdevInfo describing each netdev. | ||
858 | -# | ||
859 | -# Since: 6.0 | ||
860 | -# | ||
861 | -# Example: | ||
862 | -# | ||
863 | -# -> { "execute": "query-netdev" } | ||
864 | -# <- { "return": [ | ||
865 | -# { | ||
866 | -# "ipv6": true, | ||
867 | -# "ipv4": true, | ||
868 | -# "host": "10.0.2.2", | ||
869 | -# "ipv6-dns": "fec0::3", | ||
870 | -# "ipv6-prefix": "fec0::", | ||
871 | -# "net": "10.0.2.0/255.255.255.0", | ||
872 | -# "ipv6-host": "fec0::2", | ||
873 | -# "type": "user", | ||
874 | -# "peer-id": "net0", | ||
875 | -# "dns": "10.0.2.3", | ||
876 | -# "hostfwd": [ | ||
877 | -# { | ||
878 | -# "str": "tcp::20004-:22" | ||
879 | -# } | ||
880 | -# ], | ||
881 | -# "ipv6-prefixlen": 64, | ||
882 | -# "id": "netdev0", | ||
883 | -# "restrict": false | ||
884 | -# } | ||
885 | -# ] | ||
886 | -# } | ||
887 | -# | ||
888 | -## | ||
889 | -{ 'command': 'query-netdev', 'returns': ['NetdevInfo'] } | ||
890 | -- | 95 | -- |
891 | 2.7.4 | 96 | 2.7.4 |
892 | 97 | ||
893 | 98 | diff view generated by jsdifflib |
1 | Several issues has been reported for query-netdev info | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | series. Consider it's late in the rc, this reverts commit | 2 | |
3 | commit 59b5437eb732d6b103a9bc279c3482c834d1eff9. | 3 | Initial version of shadow virtqueue that actually forward buffers. There |
4 | 4 | is no iommu support at the moment, and that will be addressed in future | |
5 | patches of this series. Since all vhost-vdpa devices use forced IOMMU, | ||
6 | this means that SVQ is not usable at this point of the series on any | ||
7 | device. | ||
8 | |||
9 | For simplicity it only supports modern devices, that expects vring | ||
10 | in little endian, with split ring and no event idx or indirect | ||
11 | descriptors. Support for them will not be added in this series. | ||
12 | |||
13 | It reuses the VirtQueue code for the device part. The driver part is | ||
14 | based on Linux's virtio_ring driver, but with stripped functionality | ||
15 | and optimizations so it's easier to review. | ||
16 | |||
17 | However, forwarding buffers have some particular pieces: One of the most | ||
18 | unexpected ones is that a guest's buffer can expand through more than | ||
19 | one descriptor in SVQ. While this is handled gracefully by qemu's | ||
20 | emulated virtio devices, it may cause unexpected SVQ queue full. This | ||
21 | patch also solves it by checking for this condition at both guest's | ||
22 | kicks and device's calls. The code may be more elegant in the future if | ||
23 | SVQ code runs in its own iocontext. | ||
24 | |||
25 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
26 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
5 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 27 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
6 | --- | 28 | --- |
7 | hw/net/xen_nic.c | 5 +++-- | 29 | hw/virtio/vhost-shadow-virtqueue.c | 352 ++++++++++++++++++++++++++++++++++++- |
8 | include/net/net.h | 2 +- | 30 | hw/virtio/vhost-shadow-virtqueue.h | 26 +++ |
9 | net/l2tpv3.c | 3 ++- | 31 | hw/virtio/vhost-vdpa.c | 155 +++++++++++++++- |
10 | net/net.c | 14 ++++++-------- | 32 | 3 files changed, 522 insertions(+), 11 deletions(-) |
11 | net/slirp.c | 5 +++-- | 33 | |
12 | net/socket.c | 43 +++++++++++++++++++------------------------ | 34 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c |
13 | net/tap-win32.c | 3 ++- | ||
14 | net/tap.c | 13 ++++++++----- | ||
15 | net/vde.c | 3 ++- | ||
16 | net/vhost-user.c | 3 ++- | ||
17 | net/vhost-vdpa.c | 2 +- | ||
18 | 11 files changed, 49 insertions(+), 47 deletions(-) | ||
19 | |||
20 | diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/hw/net/xen_nic.c | 36 | --- a/hw/virtio/vhost-shadow-virtqueue.c |
23 | +++ b/hw/net/xen_nic.c | 37 | +++ b/hw/virtio/vhost-shadow-virtqueue.c |
24 | @@ -XXX,XX +XXX,XX @@ static int net_init(struct XenLegacyDevice *xendev) | 38 | @@ -XXX,XX +XXX,XX @@ |
25 | netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf, | 39 | #include "qemu/error-report.h" |
26 | "xen", NULL, netdev); | 40 | #include "qapi/error.h" |
27 | 41 | #include "qemu/main-loop.h" | |
28 | - qemu_get_queue(netdev->nic)->info_str = g_strdup_printf( | 42 | +#include "qemu/log.h" |
29 | - "nic: xenbus vif macaddr=%s", netdev->mac); | 43 | +#include "qemu/memalign.h" |
30 | + snprintf(qemu_get_queue(netdev->nic)->info_str, | 44 | #include "linux-headers/linux/vhost.h" |
31 | + sizeof(qemu_get_queue(netdev->nic)->info_str), | 45 | |
32 | + "nic: xenbus vif macaddr=%s", netdev->mac); | 46 | /** |
33 | 47 | @@ -XXX,XX +XXX,XX @@ bool vhost_svq_valid_features(uint64_t features, Error **errp) | |
34 | /* fill info */ | 48 | } |
35 | xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1); | 49 | |
36 | diff --git a/include/net/net.h b/include/net/net.h | 50 | /** |
51 | - * Forward guest notifications. | ||
52 | + * Number of descriptors that the SVQ can make available from the guest. | ||
53 | + * | ||
54 | + * @svq: The svq | ||
55 | + */ | ||
56 | +static uint16_t vhost_svq_available_slots(const VhostShadowVirtqueue *svq) | ||
57 | +{ | ||
58 | + return svq->vring.num - (svq->shadow_avail_idx - svq->shadow_used_idx); | ||
59 | +} | ||
60 | + | ||
61 | +static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, | ||
62 | + const struct iovec *iovec, size_t num, | ||
63 | + bool more_descs, bool write) | ||
64 | +{ | ||
65 | + uint16_t i = svq->free_head, last = svq->free_head; | ||
66 | + unsigned n; | ||
67 | + uint16_t flags = write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; | ||
68 | + vring_desc_t *descs = svq->vring.desc; | ||
69 | + | ||
70 | + if (num == 0) { | ||
71 | + return; | ||
72 | + } | ||
73 | + | ||
74 | + for (n = 0; n < num; n++) { | ||
75 | + if (more_descs || (n + 1 < num)) { | ||
76 | + descs[i].flags = flags | cpu_to_le16(VRING_DESC_F_NEXT); | ||
77 | + } else { | ||
78 | + descs[i].flags = flags; | ||
79 | + } | ||
80 | + descs[i].addr = cpu_to_le64((hwaddr)(intptr_t)iovec[n].iov_base); | ||
81 | + descs[i].len = cpu_to_le32(iovec[n].iov_len); | ||
82 | + | ||
83 | + last = i; | ||
84 | + i = cpu_to_le16(descs[i].next); | ||
85 | + } | ||
86 | + | ||
87 | + svq->free_head = le16_to_cpu(descs[last].next); | ||
88 | +} | ||
89 | + | ||
90 | +static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, | ||
91 | + VirtQueueElement *elem, unsigned *head) | ||
92 | +{ | ||
93 | + unsigned avail_idx; | ||
94 | + vring_avail_t *avail = svq->vring.avail; | ||
95 | + | ||
96 | + *head = svq->free_head; | ||
97 | + | ||
98 | + /* We need some descriptors here */ | ||
99 | + if (unlikely(!elem->out_num && !elem->in_num)) { | ||
100 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
101 | + "Guest provided element with no descriptors"); | ||
102 | + return false; | ||
103 | + } | ||
104 | + | ||
105 | + vhost_vring_write_descs(svq, elem->out_sg, elem->out_num, elem->in_num > 0, | ||
106 | + false); | ||
107 | + vhost_vring_write_descs(svq, elem->in_sg, elem->in_num, false, true); | ||
108 | + | ||
109 | + /* | ||
110 | + * Put the entry in the available array (but don't update avail->idx until | ||
111 | + * they do sync). | ||
112 | + */ | ||
113 | + avail_idx = svq->shadow_avail_idx & (svq->vring.num - 1); | ||
114 | + avail->ring[avail_idx] = cpu_to_le16(*head); | ||
115 | + svq->shadow_avail_idx++; | ||
116 | + | ||
117 | + /* Update the avail index after write the descriptor */ | ||
118 | + smp_wmb(); | ||
119 | + avail->idx = cpu_to_le16(svq->shadow_avail_idx); | ||
120 | + | ||
121 | + return true; | ||
122 | +} | ||
123 | + | ||
124 | +static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem) | ||
125 | +{ | ||
126 | + unsigned qemu_head; | ||
127 | + bool ok = vhost_svq_add_split(svq, elem, &qemu_head); | ||
128 | + if (unlikely(!ok)) { | ||
129 | + return false; | ||
130 | + } | ||
131 | + | ||
132 | + svq->ring_id_maps[qemu_head] = elem; | ||
133 | + return true; | ||
134 | +} | ||
135 | + | ||
136 | +static void vhost_svq_kick(VhostShadowVirtqueue *svq) | ||
137 | +{ | ||
138 | + /* | ||
139 | + * We need to expose the available array entries before checking the used | ||
140 | + * flags | ||
141 | + */ | ||
142 | + smp_mb(); | ||
143 | + if (svq->vring.used->flags & VRING_USED_F_NO_NOTIFY) { | ||
144 | + return; | ||
145 | + } | ||
146 | + | ||
147 | + event_notifier_set(&svq->hdev_kick); | ||
148 | +} | ||
149 | + | ||
150 | +/** | ||
151 | + * Forward available buffers. | ||
152 | + * | ||
153 | + * @svq: Shadow VirtQueue | ||
154 | + * | ||
155 | + * Note that this function does not guarantee that all guest's available | ||
156 | + * buffers are available to the device in SVQ avail ring. The guest may have | ||
157 | + * exposed a GPA / GIOVA contiguous buffer, but it may not be contiguous in | ||
158 | + * qemu vaddr. | ||
159 | + * | ||
160 | + * If that happens, guest's kick notifications will be disabled until the | ||
161 | + * device uses some buffers. | ||
162 | + */ | ||
163 | +static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq) | ||
164 | +{ | ||
165 | + /* Clear event notifier */ | ||
166 | + event_notifier_test_and_clear(&svq->svq_kick); | ||
167 | + | ||
168 | + /* Forward to the device as many available buffers as possible */ | ||
169 | + do { | ||
170 | + virtio_queue_set_notification(svq->vq, false); | ||
171 | + | ||
172 | + while (true) { | ||
173 | + VirtQueueElement *elem; | ||
174 | + bool ok; | ||
175 | + | ||
176 | + if (svq->next_guest_avail_elem) { | ||
177 | + elem = g_steal_pointer(&svq->next_guest_avail_elem); | ||
178 | + } else { | ||
179 | + elem = virtqueue_pop(svq->vq, sizeof(*elem)); | ||
180 | + } | ||
181 | + | ||
182 | + if (!elem) { | ||
183 | + break; | ||
184 | + } | ||
185 | + | ||
186 | + if (elem->out_num + elem->in_num > vhost_svq_available_slots(svq)) { | ||
187 | + /* | ||
188 | + * This condition is possible since a contiguous buffer in GPA | ||
189 | + * does not imply a contiguous buffer in qemu's VA | ||
190 | + * scatter-gather segments. If that happens, the buffer exposed | ||
191 | + * to the device needs to be a chain of descriptors at this | ||
192 | + * moment. | ||
193 | + * | ||
194 | + * SVQ cannot hold more available buffers if we are here: | ||
195 | + * queue the current guest descriptor and ignore further kicks | ||
196 | + * until some elements are used. | ||
197 | + */ | ||
198 | + svq->next_guest_avail_elem = elem; | ||
199 | + return; | ||
200 | + } | ||
201 | + | ||
202 | + ok = vhost_svq_add(svq, elem); | ||
203 | + if (unlikely(!ok)) { | ||
204 | + /* VQ is broken, just return and ignore any other kicks */ | ||
205 | + return; | ||
206 | + } | ||
207 | + vhost_svq_kick(svq); | ||
208 | + } | ||
209 | + | ||
210 | + virtio_queue_set_notification(svq->vq, true); | ||
211 | + } while (!virtio_queue_empty(svq->vq)); | ||
212 | +} | ||
213 | + | ||
214 | +/** | ||
215 | + * Handle guest's kick. | ||
216 | * | ||
217 | * @n: guest kick event notifier, the one that guest set to notify svq. | ||
218 | */ | ||
219 | -static void vhost_handle_guest_kick(EventNotifier *n) | ||
220 | +static void vhost_handle_guest_kick_notifier(EventNotifier *n) | ||
221 | { | ||
222 | VhostShadowVirtqueue *svq = container_of(n, VhostShadowVirtqueue, svq_kick); | ||
223 | event_notifier_test_and_clear(n); | ||
224 | - event_notifier_set(&svq->hdev_kick); | ||
225 | + vhost_handle_guest_kick(svq); | ||
226 | +} | ||
227 | + | ||
228 | +static bool vhost_svq_more_used(VhostShadowVirtqueue *svq) | ||
229 | +{ | ||
230 | + if (svq->last_used_idx != svq->shadow_used_idx) { | ||
231 | + return true; | ||
232 | + } | ||
233 | + | ||
234 | + svq->shadow_used_idx = cpu_to_le16(svq->vring.used->idx); | ||
235 | + | ||
236 | + return svq->last_used_idx != svq->shadow_used_idx; | ||
237 | } | ||
238 | |||
239 | /** | ||
240 | - * Forward vhost notifications | ||
241 | + * Enable vhost device calls after disable them. | ||
242 | + * | ||
243 | + * @svq: The svq | ||
244 | + * | ||
245 | + * It returns false if there are pending used buffers from the vhost device, | ||
246 | + * avoiding the possible races between SVQ checking for more work and enabling | ||
247 | + * callbacks. True if SVQ used vring has no more pending buffers. | ||
248 | + */ | ||
249 | +static bool vhost_svq_enable_notification(VhostShadowVirtqueue *svq) | ||
250 | +{ | ||
251 | + svq->vring.avail->flags &= ~cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); | ||
252 | + /* Make sure the flag is written before the read of used_idx */ | ||
253 | + smp_mb(); | ||
254 | + return !vhost_svq_more_used(svq); | ||
255 | +} | ||
256 | + | ||
257 | +static void vhost_svq_disable_notification(VhostShadowVirtqueue *svq) | ||
258 | +{ | ||
259 | + svq->vring.avail->flags |= cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); | ||
260 | +} | ||
261 | + | ||
262 | +static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, | ||
263 | + uint32_t *len) | ||
264 | +{ | ||
265 | + vring_desc_t *descs = svq->vring.desc; | ||
266 | + const vring_used_t *used = svq->vring.used; | ||
267 | + vring_used_elem_t used_elem; | ||
268 | + uint16_t last_used; | ||
269 | + | ||
270 | + if (!vhost_svq_more_used(svq)) { | ||
271 | + return NULL; | ||
272 | + } | ||
273 | + | ||
274 | + /* Only get used array entries after they have been exposed by dev */ | ||
275 | + smp_rmb(); | ||
276 | + last_used = svq->last_used_idx & (svq->vring.num - 1); | ||
277 | + used_elem.id = le32_to_cpu(used->ring[last_used].id); | ||
278 | + used_elem.len = le32_to_cpu(used->ring[last_used].len); | ||
279 | + | ||
280 | + svq->last_used_idx++; | ||
281 | + if (unlikely(used_elem.id >= svq->vring.num)) { | ||
282 | + qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used", | ||
283 | + svq->vdev->name, used_elem.id); | ||
284 | + return NULL; | ||
285 | + } | ||
286 | + | ||
287 | + if (unlikely(!svq->ring_id_maps[used_elem.id])) { | ||
288 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
289 | + "Device %s says index %u is used, but it was not available", | ||
290 | + svq->vdev->name, used_elem.id); | ||
291 | + return NULL; | ||
292 | + } | ||
293 | + | ||
294 | + descs[used_elem.id].next = svq->free_head; | ||
295 | + svq->free_head = used_elem.id; | ||
296 | + | ||
297 | + *len = used_elem.len; | ||
298 | + return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); | ||
299 | +} | ||
300 | + | ||
301 | +static void vhost_svq_flush(VhostShadowVirtqueue *svq, | ||
302 | + bool check_for_avail_queue) | ||
303 | +{ | ||
304 | + VirtQueue *vq = svq->vq; | ||
305 | + | ||
306 | + /* Forward as many used buffers as possible. */ | ||
307 | + do { | ||
308 | + unsigned i = 0; | ||
309 | + | ||
310 | + vhost_svq_disable_notification(svq); | ||
311 | + while (true) { | ||
312 | + uint32_t len; | ||
313 | + g_autofree VirtQueueElement *elem = vhost_svq_get_buf(svq, &len); | ||
314 | + if (!elem) { | ||
315 | + break; | ||
316 | + } | ||
317 | + | ||
318 | + if (unlikely(i >= svq->vring.num)) { | ||
319 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
320 | + "More than %u used buffers obtained in a %u size SVQ", | ||
321 | + i, svq->vring.num); | ||
322 | + virtqueue_fill(vq, elem, len, i); | ||
323 | + virtqueue_flush(vq, i); | ||
324 | + return; | ||
325 | + } | ||
326 | + virtqueue_fill(vq, elem, len, i++); | ||
327 | + } | ||
328 | + | ||
329 | + virtqueue_flush(vq, i); | ||
330 | + event_notifier_set(&svq->svq_call); | ||
331 | + | ||
332 | + if (check_for_avail_queue && svq->next_guest_avail_elem) { | ||
333 | + /* | ||
334 | + * Avail ring was full when vhost_svq_flush was called, so it's a | ||
335 | + * good moment to make more descriptors available if possible. | ||
336 | + */ | ||
337 | + vhost_handle_guest_kick(svq); | ||
338 | + } | ||
339 | + } while (!vhost_svq_enable_notification(svq)); | ||
340 | +} | ||
341 | + | ||
342 | +/** | ||
343 | + * Forward used buffers. | ||
344 | * | ||
345 | * @n: hdev call event notifier, the one that device set to notify svq. | ||
346 | + * | ||
347 | + * Note that we are not making any buffers available in the loop, there is no | ||
348 | + * way that it runs more than virtqueue size times. | ||
349 | */ | ||
350 | static void vhost_svq_handle_call(EventNotifier *n) | ||
351 | { | ||
352 | VhostShadowVirtqueue *svq = container_of(n, VhostShadowVirtqueue, | ||
353 | hdev_call); | ||
354 | event_notifier_test_and_clear(n); | ||
355 | - event_notifier_set(&svq->svq_call); | ||
356 | + vhost_svq_flush(svq, true); | ||
357 | } | ||
358 | |||
359 | /** | ||
360 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd) | ||
361 | if (poll_start) { | ||
362 | event_notifier_init_fd(svq_kick, svq_kick_fd); | ||
363 | event_notifier_set(svq_kick); | ||
364 | - event_notifier_set_handler(svq_kick, vhost_handle_guest_kick); | ||
365 | + event_notifier_set_handler(svq_kick, vhost_handle_guest_kick_notifier); | ||
366 | + } | ||
367 | +} | ||
368 | + | ||
369 | +/** | ||
370 | + * Start the shadow virtqueue operation. | ||
371 | + * | ||
372 | + * @svq: Shadow Virtqueue | ||
373 | + * @vdev: VirtIO device | ||
374 | + * @vq: Virtqueue to shadow | ||
375 | + */ | ||
376 | +void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, | ||
377 | + VirtQueue *vq) | ||
378 | +{ | ||
379 | + size_t desc_size, driver_size, device_size; | ||
380 | + | ||
381 | + svq->next_guest_avail_elem = NULL; | ||
382 | + svq->shadow_avail_idx = 0; | ||
383 | + svq->shadow_used_idx = 0; | ||
384 | + svq->last_used_idx = 0; | ||
385 | + svq->vdev = vdev; | ||
386 | + svq->vq = vq; | ||
387 | + | ||
388 | + svq->vring.num = virtio_queue_get_num(vdev, virtio_get_queue_index(vq)); | ||
389 | + driver_size = vhost_svq_driver_area_size(svq); | ||
390 | + device_size = vhost_svq_device_area_size(svq); | ||
391 | + svq->vring.desc = qemu_memalign(qemu_real_host_page_size, driver_size); | ||
392 | + desc_size = sizeof(vring_desc_t) * svq->vring.num; | ||
393 | + svq->vring.avail = (void *)((char *)svq->vring.desc + desc_size); | ||
394 | + memset(svq->vring.desc, 0, driver_size); | ||
395 | + svq->vring.used = qemu_memalign(qemu_real_host_page_size, device_size); | ||
396 | + memset(svq->vring.used, 0, device_size); | ||
397 | + svq->ring_id_maps = g_new0(VirtQueueElement *, svq->vring.num); | ||
398 | + for (unsigned i = 0; i < svq->vring.num - 1; i++) { | ||
399 | + svq->vring.desc[i].next = cpu_to_le16(i + 1); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd) | ||
404 | void vhost_svq_stop(VhostShadowVirtqueue *svq) | ||
405 | { | ||
406 | event_notifier_set_handler(&svq->svq_kick, NULL); | ||
407 | + g_autofree VirtQueueElement *next_avail_elem = NULL; | ||
408 | + | ||
409 | + if (!svq->vq) { | ||
410 | + return; | ||
411 | + } | ||
412 | + | ||
413 | + /* Send all pending used descriptors to guest */ | ||
414 | + vhost_svq_flush(svq, false); | ||
415 | + | ||
416 | + for (unsigned i = 0; i < svq->vring.num; ++i) { | ||
417 | + g_autofree VirtQueueElement *elem = NULL; | ||
418 | + elem = g_steal_pointer(&svq->ring_id_maps[i]); | ||
419 | + if (elem) { | ||
420 | + virtqueue_detach_element(svq->vq, elem, 0); | ||
421 | + } | ||
422 | + } | ||
423 | + | ||
424 | + next_avail_elem = g_steal_pointer(&svq->next_guest_avail_elem); | ||
425 | + if (next_avail_elem) { | ||
426 | + virtqueue_detach_element(svq->vq, next_avail_elem, 0); | ||
427 | + } | ||
428 | + svq->vq = NULL; | ||
429 | + g_free(svq->ring_id_maps); | ||
430 | + qemu_vfree(svq->vring.desc); | ||
431 | + qemu_vfree(svq->vring.used); | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h | ||
37 | index XXXXXXX..XXXXXXX 100644 | 436 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/include/net/net.h | 437 | --- a/hw/virtio/vhost-shadow-virtqueue.h |
39 | +++ b/include/net/net.h | 438 | +++ b/hw/virtio/vhost-shadow-virtqueue.h |
40 | @@ -XXX,XX +XXX,XX @@ struct NetClientState { | 439 | @@ -XXX,XX +XXX,XX @@ typedef struct VhostShadowVirtqueue { |
41 | NetQueue *incoming_queue; | 440 | |
42 | char *model; | 441 | /* Guest's call notifier, where the SVQ calls guest. */ |
43 | char *name; | 442 | EventNotifier svq_call; |
44 | - char *info_str; | 443 | + |
45 | + char info_str[256]; | 444 | + /* Virtio queue shadowing */ |
46 | NetdevInfo *stored_config; | 445 | + VirtQueue *vq; |
47 | unsigned receive_disabled : 1; | 446 | + |
48 | NetClientDestructor *destructor; | 447 | + /* Virtio device */ |
49 | diff --git a/net/l2tpv3.c b/net/l2tpv3.c | 448 | + VirtIODevice *vdev; |
449 | + | ||
450 | + /* Map for use the guest's descriptors */ | ||
451 | + VirtQueueElement **ring_id_maps; | ||
452 | + | ||
453 | + /* Next VirtQueue element that guest made available */ | ||
454 | + VirtQueueElement *next_guest_avail_elem; | ||
455 | + | ||
456 | + /* Next head to expose to the device */ | ||
457 | + uint16_t shadow_avail_idx; | ||
458 | + | ||
459 | + /* Next free descriptor */ | ||
460 | + uint16_t free_head; | ||
461 | + | ||
462 | + /* Last seen used idx */ | ||
463 | + uint16_t shadow_used_idx; | ||
464 | + | ||
465 | + /* Next head to consume from the device */ | ||
466 | + uint16_t last_used_idx; | ||
467 | } VhostShadowVirtqueue; | ||
468 | |||
469 | bool vhost_svq_valid_features(uint64_t features, Error **errp); | ||
470 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, | ||
471 | size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq); | ||
472 | size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq); | ||
473 | |||
474 | +void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, | ||
475 | + VirtQueue *vq); | ||
476 | void vhost_svq_stop(VhostShadowVirtqueue *svq); | ||
477 | |||
478 | VhostShadowVirtqueue *vhost_svq_new(void); | ||
479 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | 480 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/net/l2tpv3.c | 481 | --- a/hw/virtio/vhost-vdpa.c |
52 | +++ b/net/l2tpv3.c | 482 | +++ b/hw/virtio/vhost-vdpa.c |
53 | @@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev, | 483 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_dev_addr(struct vhost_dev *dev, |
54 | QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, | 484 | * Note that this function does not rewind kick file descriptor if cannot set |
55 | &nc->stored_config->u.l2tpv3, l2tpv3); | 485 | * call one. |
56 | 486 | */ | |
57 | - s->nc.info_str = g_strdup_printf("l2tpv3: connected"); | 487 | -static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, |
58 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | 488 | - VhostShadowVirtqueue *svq, unsigned idx, |
59 | + "l2tpv3: connected"); | 489 | - Error **errp) |
60 | return 0; | 490 | +static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev, |
61 | outerr: | 491 | + VhostShadowVirtqueue *svq, unsigned idx, |
62 | qemu_del_net_client(nc); | 492 | + Error **errp) |
63 | diff --git a/net/net.c b/net/net.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/net/net.c | ||
66 | +++ b/net/net.c | ||
67 | @@ -XXX,XX +XXX,XX @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr) | ||
68 | |||
69 | void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]) | ||
70 | { | 493 | { |
71 | - g_free(nc->info_str); | 494 | struct vhost_vring_file file = { |
72 | - nc->info_str = g_strdup_printf( | 495 | .index = dev->vq_index + idx, |
73 | - "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x", | 496 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, |
74 | - nc->model, | 497 | r = vhost_vdpa_set_vring_dev_kick(dev, &file); |
75 | - macaddr[0], macaddr[1], macaddr[2], | 498 | if (unlikely(r != 0)) { |
76 | - macaddr[3], macaddr[4], macaddr[5]); | 499 | error_setg_errno(errp, -r, "Can't set device kick fd"); |
77 | + snprintf(nc->info_str, sizeof(nc->info_str), | 500 | - return false; |
78 | + "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x", | 501 | + return r; |
79 | + nc->model, | 502 | } |
80 | + macaddr[0], macaddr[1], macaddr[2], | 503 | |
81 | + macaddr[3], macaddr[4], macaddr[5]); | 504 | event_notifier = &svq->hdev_call; |
505 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, | ||
506 | error_setg_errno(errp, -r, "Can't set device call fd"); | ||
507 | } | ||
508 | |||
509 | + return r; | ||
510 | +} | ||
511 | + | ||
512 | +/** | ||
513 | + * Unmap a SVQ area in the device | ||
514 | + */ | ||
515 | +static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr iova, | ||
516 | + hwaddr size) | ||
517 | +{ | ||
518 | + int r; | ||
519 | + | ||
520 | + size = ROUND_UP(size, qemu_real_host_page_size); | ||
521 | + r = vhost_vdpa_dma_unmap(v, iova, size); | ||
522 | + return r == 0; | ||
523 | +} | ||
524 | + | ||
525 | +static bool vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, | ||
526 | + const VhostShadowVirtqueue *svq) | ||
527 | +{ | ||
528 | + struct vhost_vdpa *v = dev->opaque; | ||
529 | + struct vhost_vring_addr svq_addr; | ||
530 | + size_t device_size = vhost_svq_device_area_size(svq); | ||
531 | + size_t driver_size = vhost_svq_driver_area_size(svq); | ||
532 | + bool ok; | ||
533 | + | ||
534 | + vhost_svq_get_vring_addr(svq, &svq_addr); | ||
535 | + | ||
536 | + ok = vhost_vdpa_svq_unmap_ring(v, svq_addr.desc_user_addr, driver_size); | ||
537 | + if (unlikely(!ok)) { | ||
538 | + return false; | ||
539 | + } | ||
540 | + | ||
541 | + return vhost_vdpa_svq_unmap_ring(v, svq_addr.used_user_addr, device_size); | ||
542 | +} | ||
543 | + | ||
544 | +/** | ||
545 | + * Map the shadow virtqueue rings in the device | ||
546 | + * | ||
547 | + * @dev: The vhost device | ||
548 | + * @svq: The shadow virtqueue | ||
549 | + * @addr: Assigned IOVA addresses | ||
550 | + * @errp: Error pointer | ||
551 | + */ | ||
552 | +static bool vhost_vdpa_svq_map_rings(struct vhost_dev *dev, | ||
553 | + const VhostShadowVirtqueue *svq, | ||
554 | + struct vhost_vring_addr *addr, | ||
555 | + Error **errp) | ||
556 | +{ | ||
557 | + struct vhost_vdpa *v = dev->opaque; | ||
558 | + size_t device_size = vhost_svq_device_area_size(svq); | ||
559 | + size_t driver_size = vhost_svq_driver_area_size(svq); | ||
560 | + int r; | ||
561 | + | ||
562 | + ERRP_GUARD(); | ||
563 | + vhost_svq_get_vring_addr(svq, addr); | ||
564 | + | ||
565 | + r = vhost_vdpa_dma_map(v, addr->desc_user_addr, driver_size, | ||
566 | + (void *)(uintptr_t)addr->desc_user_addr, true); | ||
567 | + if (unlikely(r != 0)) { | ||
568 | + error_setg_errno(errp, -r, "Cannot create vq driver region: "); | ||
569 | + return false; | ||
570 | + } | ||
571 | + | ||
572 | + r = vhost_vdpa_dma_map(v, addr->used_user_addr, device_size, | ||
573 | + (void *)(intptr_t)addr->used_user_addr, false); | ||
574 | + if (unlikely(r != 0)) { | ||
575 | + error_setg_errno(errp, -r, "Cannot create vq device region: "); | ||
576 | + } | ||
577 | + | ||
578 | + return r == 0; | ||
579 | +} | ||
580 | + | ||
581 | +static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, | ||
582 | + VhostShadowVirtqueue *svq, unsigned idx, | ||
583 | + Error **errp) | ||
584 | +{ | ||
585 | + uint16_t vq_index = dev->vq_index + idx; | ||
586 | + struct vhost_vring_state s = { | ||
587 | + .index = vq_index, | ||
588 | + }; | ||
589 | + int r; | ||
590 | + | ||
591 | + r = vhost_vdpa_set_dev_vring_base(dev, &s); | ||
592 | + if (unlikely(r)) { | ||
593 | + error_setg_errno(errp, -r, "Cannot set vring base"); | ||
594 | + return false; | ||
595 | + } | ||
596 | + | ||
597 | + r = vhost_vdpa_svq_set_fds(dev, svq, idx, errp); | ||
598 | return r == 0; | ||
82 | } | 599 | } |
83 | 600 | ||
84 | static int mac_table[256] = {0}; | 601 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) |
85 | @@ -XXX,XX +XXX,XX @@ static void qemu_free_net_client(NetClientState *nc) | ||
86 | } | 602 | } |
87 | g_free(nc->name); | 603 | |
88 | g_free(nc->model); | 604 | for (i = 0; i < v->shadow_vqs->len; ++i) { |
89 | - g_free(nc->info_str); | 605 | + VirtQueue *vq = virtio_get_queue(dev->vdev, dev->vq_index + i); |
90 | qapi_free_NetdevInfo(nc->stored_config); | 606 | VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); |
91 | if (nc->destructor) { | 607 | + struct vhost_vring_addr addr = { |
92 | nc->destructor(nc); | 608 | + .index = i, |
93 | @@ -XXX,XX +XXX,XX @@ void print_net_client(Monitor *mon, NetClientState *nc) | 609 | + }; |
94 | monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name, | 610 | + int r; |
95 | nc->queue_index, | 611 | bool ok = vhost_vdpa_svq_setup(dev, svq, i, &err); |
96 | NetClientDriver_str(nc->info->type), | 612 | if (unlikely(!ok)) { |
97 | - nc->info_str ? nc->info_str : ""); | 613 | - error_reportf_err(err, "Cannot setup SVQ %u: ", i); |
98 | + nc->info_str); | 614 | + goto err; |
99 | if (!QTAILQ_EMPTY(&nc->filters)) { | 615 | + } |
100 | monitor_printf(mon, "filters:\n"); | 616 | + |
617 | + vhost_svq_start(svq, dev->vdev, vq); | ||
618 | + ok = vhost_vdpa_svq_map_rings(dev, svq, &addr, &err); | ||
619 | + if (unlikely(!ok)) { | ||
620 | + goto err_map; | ||
621 | + } | ||
622 | + | ||
623 | + /* Override vring GPA set by vhost subsystem */ | ||
624 | + r = vhost_vdpa_set_vring_dev_addr(dev, &addr); | ||
625 | + if (unlikely(r != 0)) { | ||
626 | + error_setg_errno(&err, -r, "Cannot set device address"); | ||
627 | + goto err_set_addr; | ||
628 | + } | ||
629 | + } | ||
630 | + | ||
631 | + return true; | ||
632 | + | ||
633 | +err_set_addr: | ||
634 | + vhost_vdpa_svq_unmap_rings(dev, g_ptr_array_index(v->shadow_vqs, i)); | ||
635 | + | ||
636 | +err_map: | ||
637 | + vhost_svq_stop(g_ptr_array_index(v->shadow_vqs, i)); | ||
638 | + | ||
639 | +err: | ||
640 | + error_reportf_err(err, "Cannot setup SVQ %u: ", i); | ||
641 | + for (unsigned j = 0; j < i; ++j) { | ||
642 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, j); | ||
643 | + vhost_vdpa_svq_unmap_rings(dev, svq); | ||
644 | + vhost_svq_stop(svq); | ||
645 | + } | ||
646 | + | ||
647 | + return false; | ||
648 | +} | ||
649 | + | ||
650 | +static bool vhost_vdpa_svqs_stop(struct vhost_dev *dev) | ||
651 | +{ | ||
652 | + struct vhost_vdpa *v = dev->opaque; | ||
653 | + | ||
654 | + if (!v->shadow_vqs) { | ||
655 | + return true; | ||
656 | + } | ||
657 | + | ||
658 | + for (unsigned i = 0; i < v->shadow_vqs->len; ++i) { | ||
659 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); | ||
660 | + bool ok = vhost_vdpa_svq_unmap_rings(dev, svq); | ||
661 | + if (unlikely(!ok)) { | ||
662 | return false; | ||
663 | } | ||
101 | } | 664 | } |
102 | diff --git a/net/slirp.c b/net/slirp.c | 665 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) |
103 | index XXXXXXX..XXXXXXX 100644 | 666 | } |
104 | --- a/net/slirp.c | 667 | vhost_vdpa_set_vring_ready(dev); |
105 | +++ b/net/slirp.c | 668 | } else { |
106 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | 669 | + ok = vhost_vdpa_svqs_stop(dev); |
107 | stored->tftp_server_name = g_strdup(tftp_server_name); | 670 | + if (unlikely(!ok)) { |
671 | + return -1; | ||
672 | + } | ||
673 | vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); | ||
108 | } | 674 | } |
109 | 675 | ||
110 | - nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net), | ||
111 | - restricted ? "on" : "off"); | ||
112 | + snprintf(nc->info_str, sizeof(nc->info_str), | ||
113 | + "net=%s,restrict=%s", inet_ntoa(net), | ||
114 | + restricted ? "on" : "off"); | ||
115 | |||
116 | s = DO_UPCAST(SlirpState, nc, nc); | ||
117 | |||
118 | diff --git a/net/socket.c b/net/socket.c | ||
119 | index XXXXXXX..XXXXXXX 100644 | ||
120 | --- a/net/socket.c | ||
121 | +++ b/net/socket.c | ||
122 | @@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque) | ||
123 | s->fd = -1; | ||
124 | net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | ||
125 | s->nc.link_down = true; | ||
126 | - g_free(s->nc.info_str); | ||
127 | - s->nc.info_str = g_new0(char, 1); | ||
128 | + memset(s->nc.info_str, 0, sizeof(s->nc.info_str)); | ||
129 | |||
130 | return; | ||
131 | } | ||
132 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, | ||
133 | stored->mcast = g_strdup(mcast); | ||
134 | |||
135 | s->dgram_dst = saddr; | ||
136 | - nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)", | ||
137 | - fd, inet_ntoa(saddr.sin_addr), | ||
138 | - ntohs(saddr.sin_port)); | ||
139 | + snprintf(nc->info_str, sizeof(nc->info_str), | ||
140 | + "socket: fd=%d (cloned mcast=%s:%d)", | ||
141 | + fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
142 | } else { | ||
143 | if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) { | ||
144 | s->dgram_dst.sin_family = AF_UNIX; | ||
145 | } | ||
146 | |||
147 | - nc->info_str = g_strdup_printf("socket: fd=%d %s", | ||
148 | - fd, SocketAddressType_str(sa_type)); | ||
149 | + snprintf(nc->info_str, sizeof(nc->info_str), | ||
150 | + "socket: fd=%d %s", fd, SocketAddressType_str(sa_type)); | ||
151 | } | ||
152 | |||
153 | return s; | ||
154 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, | ||
155 | |||
156 | nc = qemu_new_net_client(&net_socket_info, peer, model, name); | ||
157 | |||
158 | - nc->info_str = g_strdup_printf("socket: fd=%d", fd); | ||
159 | + snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd); | ||
160 | |||
161 | s = DO_UPCAST(NetSocketState, nc, nc); | ||
162 | |||
163 | @@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque) | ||
164 | stored->has_fd = true; | ||
165 | stored->fd = g_strdup_printf("%d", fd); | ||
166 | |||
167 | - g_free(s->nc.info_str); | ||
168 | - s->nc.info_str = g_strdup_printf("socket: connection from %s:%d", | ||
169 | - inet_ntoa(saddr.sin_addr), | ||
170 | - ntohs(saddr.sin_port)); | ||
171 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
172 | + "socket: connection from %s:%d", | ||
173 | + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
174 | } | ||
175 | |||
176 | static int net_socket_listen_init(NetClientState *peer, | ||
177 | @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, | ||
178 | stored->has_connect = true; | ||
179 | stored->connect = g_strdup(host_str); | ||
180 | |||
181 | - g_free(s->nc.info_str); | ||
182 | - s->nc.info_str = g_strdup_printf("socket: connect to %s:%d", | ||
183 | - inet_ntoa(saddr.sin_addr), | ||
184 | - ntohs(saddr.sin_port)); | ||
185 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
186 | + "socket: connect to %s:%d", | ||
187 | + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer, | ||
192 | stored->localaddr = g_strdup(localaddr_str); | ||
193 | } | ||
194 | |||
195 | - g_free(s->nc.info_str); | ||
196 | - s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d", | ||
197 | - inet_ntoa(saddr.sin_addr), | ||
198 | - ntohs(saddr.sin_port)); | ||
199 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
200 | + "socket: mcast=%s:%d", | ||
201 | + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
202 | return 0; | ||
203 | |||
204 | } | ||
205 | @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, | ||
206 | stored->has_udp = true; | ||
207 | stored->udp = g_strdup(rhost); | ||
208 | |||
209 | - g_free(s->nc.info_str); | ||
210 | - s->nc.info_str = g_strdup_printf("socket: udp=%s:%d", | ||
211 | - inet_ntoa(raddr.sin_addr), | ||
212 | - ntohs(raddr.sin_port)); | ||
213 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
214 | + "socket: udp=%s:%d", | ||
215 | + inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | diff --git a/net/tap-win32.c b/net/tap-win32.c | ||
220 | index XXXXXXX..XXXXXXX 100644 | ||
221 | --- a/net/tap-win32.c | ||
222 | +++ b/net/tap-win32.c | ||
223 | @@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model, | ||
224 | stored->has_ifname = true; | ||
225 | stored->ifname = g_strdup(ifname); | ||
226 | |||
227 | - s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname); | ||
228 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
229 | + "tap: ifname=%s", ifname); | ||
230 | |||
231 | s->handle = handle; | ||
232 | |||
233 | diff --git a/net/tap.c b/net/tap.c | ||
234 | index XXXXXXX..XXXXXXX 100644 | ||
235 | --- a/net/tap.c | ||
236 | +++ b/net/tap.c | ||
237 | @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, | ||
238 | stored->helper = g_strdup(helper); | ||
239 | } | ||
240 | |||
241 | - s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br); | ||
242 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper, | ||
243 | + br); | ||
244 | |||
245 | return 0; | ||
246 | } | ||
247 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
248 | g_free(tmp_s); | ||
249 | } | ||
250 | |||
251 | - s->nc.info_str = g_strdup_printf("fd=%d", fd); | ||
252 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd); | ||
253 | } else if (tap->has_helper) { | ||
254 | if (!stored->has_helper) { | ||
255 | stored->has_helper = true; | ||
256 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
257 | g_strdup(DEFAULT_BRIDGE_INTERFACE); | ||
258 | } | ||
259 | |||
260 | - s->nc.info_str = g_strdup_printf("helper=%s", tap->helper); | ||
261 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s", | ||
262 | + tap->helper); | ||
263 | } else { | ||
264 | if (ifname && !stored->has_ifname) { | ||
265 | stored->has_ifname = true; | ||
266 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
267 | stored->downscript = g_strdup(downscript); | ||
268 | } | ||
269 | |||
270 | - s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s", | ||
271 | - ifname, script, downscript); | ||
272 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
273 | + "ifname=%s,script=%s,downscript=%s", ifname, script, | ||
274 | + downscript); | ||
275 | |||
276 | if (strcmp(downscript, "no") != 0) { | ||
277 | snprintf(s->down_script, sizeof(s->down_script), "%s", downscript); | ||
278 | diff --git a/net/vde.c b/net/vde.c | ||
279 | index XXXXXXX..XXXXXXX 100644 | ||
280 | --- a/net/vde.c | ||
281 | +++ b/net/vde.c | ||
282 | @@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model, | ||
283 | |||
284 | nc = qemu_new_net_client(&net_vde_info, peer, model, name); | ||
285 | |||
286 | - nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde)); | ||
287 | + snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d", | ||
288 | + sock, vde_datafd(vde)); | ||
289 | |||
290 | s = DO_UPCAST(VDEState, nc, nc); | ||
291 | |||
292 | diff --git a/net/vhost-user.c b/net/vhost-user.c | ||
293 | index XXXXXXX..XXXXXXX 100644 | ||
294 | --- a/net/vhost-user.c | ||
295 | +++ b/net/vhost-user.c | ||
296 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device, | ||
297 | user = g_new0(struct VhostUserState, 1); | ||
298 | for (i = 0; i < queues; i++) { | ||
299 | nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name); | ||
300 | - nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label); | ||
301 | + snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s", | ||
302 | + i, chr->label); | ||
303 | nc->queue_index = i; | ||
304 | if (!nc0) { | ||
305 | nc0 = nc; | ||
306 | diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c | ||
307 | index XXXXXXX..XXXXXXX 100644 | ||
308 | --- a/net/vhost-vdpa.c | ||
309 | +++ b/net/vhost-vdpa.c | ||
310 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, | ||
311 | stored->has_queues = true; | ||
312 | stored->queues = 1; /* TODO: change when support multiqueue */ | ||
313 | |||
314 | - nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA); | ||
315 | + snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); | ||
316 | nc->queue_index = 0; | ||
317 | s = DO_UPCAST(VhostVDPAState, nc, nc); | ||
318 | vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR); | ||
319 | -- | 676 | -- |
320 | 2.7.4 | 677 | 2.7.4 |
321 | 678 | ||
322 | 679 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Eugenio Pérez <eperezma@redhat.com> | |
2 | |||
3 | This iova tree function allows it to look for a hole in allocated | ||
4 | regions and return a totally new translation for a given translated | ||
5 | address. | ||
6 | |||
7 | It's usage is mainly to allow devices to access qemu address space, | ||
8 | remapping guest's one into a new iova space where qemu can add chunks of | ||
9 | addresses. | ||
10 | |||
11 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
12 | Reviewed-by: Peter Xu <peterx@redhat.com> | ||
13 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
14 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
15 | --- | ||
16 | include/qemu/iova-tree.h | 18 +++++++ | ||
17 | util/iova-tree.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++ | ||
18 | 2 files changed, 154 insertions(+) | ||
19 | |||
20 | diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/qemu/iova-tree.h | ||
23 | +++ b/include/qemu/iova-tree.h | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | #define IOVA_OK (0) | ||
26 | #define IOVA_ERR_INVALID (-1) /* Invalid parameters */ | ||
27 | #define IOVA_ERR_OVERLAP (-2) /* IOVA range overlapped */ | ||
28 | +#define IOVA_ERR_NOMEM (-3) /* Cannot allocate */ | ||
29 | |||
30 | typedef struct IOVATree IOVATree; | ||
31 | typedef struct DMAMap { | ||
32 | @@ -XXX,XX +XXX,XX @@ const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova); | ||
33 | void iova_tree_foreach(IOVATree *tree, iova_tree_iterator iterator); | ||
34 | |||
35 | /** | ||
36 | + * iova_tree_alloc_map: | ||
37 | + * | ||
38 | + * @tree: the iova tree to allocate from | ||
39 | + * @map: the new map (as translated addr & size) to allocate in the iova region | ||
40 | + * @iova_begin: the minimum address of the allocation | ||
41 | + * @iova_end: the maximum addressable direction of the allocation | ||
42 | + * | ||
43 | + * Allocates a new region of a given size, between iova_min and iova_max. | ||
44 | + * | ||
45 | + * Return: Same as iova_tree_insert, but cannot overlap and can return error if | ||
46 | + * iova tree is out of free contiguous range. The caller gets the assigned iova | ||
47 | + * in map->iova. | ||
48 | + */ | ||
49 | +int iova_tree_alloc_map(IOVATree *tree, DMAMap *map, hwaddr iova_begin, | ||
50 | + hwaddr iova_end); | ||
51 | + | ||
52 | +/** | ||
53 | * iova_tree_destroy: | ||
54 | * | ||
55 | * @tree: the iova tree to destroy | ||
56 | diff --git a/util/iova-tree.c b/util/iova-tree.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/util/iova-tree.c | ||
59 | +++ b/util/iova-tree.c | ||
60 | @@ -XXX,XX +XXX,XX @@ struct IOVATree { | ||
61 | GTree *tree; | ||
62 | }; | ||
63 | |||
64 | +/* Args to pass to iova_tree_alloc foreach function. */ | ||
65 | +struct IOVATreeAllocArgs { | ||
66 | + /* Size of the desired allocation */ | ||
67 | + size_t new_size; | ||
68 | + | ||
69 | + /* The minimum address allowed in the allocation */ | ||
70 | + hwaddr iova_begin; | ||
71 | + | ||
72 | + /* Map at the left of the hole, can be NULL if "this" is first one */ | ||
73 | + const DMAMap *prev; | ||
74 | + | ||
75 | + /* Map at the right of the hole, can be NULL if "prev" is the last one */ | ||
76 | + const DMAMap *this; | ||
77 | + | ||
78 | + /* If found, we fill in the IOVA here */ | ||
79 | + hwaddr iova_result; | ||
80 | + | ||
81 | + /* Whether have we found a valid IOVA */ | ||
82 | + bool iova_found; | ||
83 | +}; | ||
84 | + | ||
85 | +/** | ||
86 | + * Iterate args to the next hole | ||
87 | + * | ||
88 | + * @args: The alloc arguments | ||
89 | + * @next: The next mapping in the tree. Can be NULL to signal the last one | ||
90 | + */ | ||
91 | +static void iova_tree_alloc_args_iterate(struct IOVATreeAllocArgs *args, | ||
92 | + const DMAMap *next) | ||
93 | +{ | ||
94 | + args->prev = args->this; | ||
95 | + args->this = next; | ||
96 | +} | ||
97 | + | ||
98 | static int iova_tree_compare(gconstpointer a, gconstpointer b, gpointer data) | ||
99 | { | ||
100 | const DMAMap *m1 = a, *m2 = b; | ||
101 | @@ -XXX,XX +XXX,XX @@ int iova_tree_remove(IOVATree *tree, const DMAMap *map) | ||
102 | return IOVA_OK; | ||
103 | } | ||
104 | |||
105 | +/** | ||
106 | + * Try to find an unallocated IOVA range between prev and this elements. | ||
107 | + * | ||
108 | + * @args: Arguments to allocation | ||
109 | + * | ||
110 | + * Cases: | ||
111 | + * | ||
112 | + * (1) !prev, !this: No entries allocated, always succeed | ||
113 | + * | ||
114 | + * (2) !prev, this: We're iterating at the 1st element. | ||
115 | + * | ||
116 | + * (3) prev, !this: We're iterating at the last element. | ||
117 | + * | ||
118 | + * (4) prev, this: this is the most common case, we'll try to find a hole | ||
119 | + * between "prev" and "this" mapping. | ||
120 | + * | ||
121 | + * Note that this function assumes the last valid iova is HWADDR_MAX, but it | ||
122 | + * searches linearly so it's easy to discard the result if it's not the case. | ||
123 | + */ | ||
124 | +static void iova_tree_alloc_map_in_hole(struct IOVATreeAllocArgs *args) | ||
125 | +{ | ||
126 | + const DMAMap *prev = args->prev, *this = args->this; | ||
127 | + uint64_t hole_start, hole_last; | ||
128 | + | ||
129 | + if (this && this->iova + this->size < args->iova_begin) { | ||
130 | + return; | ||
131 | + } | ||
132 | + | ||
133 | + hole_start = MAX(prev ? prev->iova + prev->size + 1 : 0, args->iova_begin); | ||
134 | + hole_last = this ? this->iova : HWADDR_MAX; | ||
135 | + | ||
136 | + if (hole_last - hole_start > args->new_size) { | ||
137 | + args->iova_result = hole_start; | ||
138 | + args->iova_found = true; | ||
139 | + } | ||
140 | +} | ||
141 | + | ||
142 | +/** | ||
143 | + * Foreach dma node in the tree, compare if there is a hole with its previous | ||
144 | + * node (or minimum iova address allowed) and the node. | ||
145 | + * | ||
146 | + * @key: Node iterating | ||
147 | + * @value: Node iterating | ||
148 | + * @pargs: Struct to communicate with the outside world | ||
149 | + * | ||
150 | + * Return: false to keep iterating, true if needs break. | ||
151 | + */ | ||
152 | +static gboolean iova_tree_alloc_traverse(gpointer key, gpointer value, | ||
153 | + gpointer pargs) | ||
154 | +{ | ||
155 | + struct IOVATreeAllocArgs *args = pargs; | ||
156 | + DMAMap *node = value; | ||
157 | + | ||
158 | + assert(key == value); | ||
159 | + | ||
160 | + iova_tree_alloc_args_iterate(args, node); | ||
161 | + iova_tree_alloc_map_in_hole(args); | ||
162 | + return args->iova_found; | ||
163 | +} | ||
164 | + | ||
165 | +int iova_tree_alloc_map(IOVATree *tree, DMAMap *map, hwaddr iova_begin, | ||
166 | + hwaddr iova_last) | ||
167 | +{ | ||
168 | + struct IOVATreeAllocArgs args = { | ||
169 | + .new_size = map->size, | ||
170 | + .iova_begin = iova_begin, | ||
171 | + }; | ||
172 | + | ||
173 | + if (unlikely(iova_last < iova_begin)) { | ||
174 | + return IOVA_ERR_INVALID; | ||
175 | + } | ||
176 | + | ||
177 | + /* | ||
178 | + * Find a valid hole for the mapping | ||
179 | + * | ||
180 | + * Assuming low iova_begin, so no need to do a binary search to | ||
181 | + * locate the first node. | ||
182 | + * | ||
183 | + * TODO: Replace all this with g_tree_node_first/next/last when available | ||
184 | + * (from glib since 2.68). To do it with g_tree_foreach complicates the | ||
185 | + * code a lot. | ||
186 | + * | ||
187 | + */ | ||
188 | + g_tree_foreach(tree->tree, iova_tree_alloc_traverse, &args); | ||
189 | + if (!args.iova_found) { | ||
190 | + /* | ||
191 | + * Either tree is empty or the last hole is still not checked. | ||
192 | + * g_tree_foreach does not compare (last, iova_last] range, so we check | ||
193 | + * it here. | ||
194 | + */ | ||
195 | + iova_tree_alloc_args_iterate(&args, NULL); | ||
196 | + iova_tree_alloc_map_in_hole(&args); | ||
197 | + } | ||
198 | + | ||
199 | + if (!args.iova_found || args.iova_result + map->size > iova_last) { | ||
200 | + return IOVA_ERR_NOMEM; | ||
201 | + } | ||
202 | + | ||
203 | + map->iova = args.iova_result; | ||
204 | + return iova_tree_insert(tree, map); | ||
205 | +} | ||
206 | + | ||
207 | void iova_tree_destroy(IOVATree *tree) | ||
208 | { | ||
209 | g_tree_destroy(tree->tree); | ||
210 | -- | ||
211 | 2.7.4 | ||
212 | |||
213 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Eugenio Pérez <eperezma@redhat.com> | ||
1 | 2 | ||
3 | This function does the reverse operation of iova_tree_find: To look for | ||
4 | a mapping that match a translated address so we can do the reverse. | ||
5 | |||
6 | This have linear complexity instead of logarithmic, but it supports | ||
7 | overlapping HVA. Future developments could reduce it. | ||
8 | |||
9 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
10 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
12 | --- | ||
13 | include/qemu/iova-tree.h | 20 +++++++++++++++++++- | ||
14 | util/iova-tree.c | 34 ++++++++++++++++++++++++++++++++++ | ||
15 | 2 files changed, 53 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/qemu/iova-tree.h | ||
20 | +++ b/include/qemu/iova-tree.h | ||
21 | @@ -XXX,XX +XXX,XX @@ int iova_tree_remove(IOVATree *tree, const DMAMap *map); | ||
22 | * @tree: the iova tree to search from | ||
23 | * @map: the mapping to search | ||
24 | * | ||
25 | - * Search for a mapping in the iova tree that overlaps with the | ||
26 | + * Search for a mapping in the iova tree that iova overlaps with the | ||
27 | * mapping range specified. Only the first found mapping will be | ||
28 | * returned. | ||
29 | * | ||
30 | @@ -XXX,XX +XXX,XX @@ int iova_tree_remove(IOVATree *tree, const DMAMap *map); | ||
31 | const DMAMap *iova_tree_find(const IOVATree *tree, const DMAMap *map); | ||
32 | |||
33 | /** | ||
34 | + * iova_tree_find_iova: | ||
35 | + * | ||
36 | + * @tree: the iova tree to search from | ||
37 | + * @map: the mapping to search | ||
38 | + * | ||
39 | + * Search for a mapping in the iova tree that translated_addr overlaps with the | ||
40 | + * mapping range specified. Only the first found mapping will be | ||
41 | + * returned. | ||
42 | + * | ||
43 | + * Return: DMAMap pointer if found, or NULL if not found. Note that | ||
44 | + * the returned DMAMap pointer is maintained internally. User should | ||
45 | + * only read the content but never modify or free the content. Also, | ||
46 | + * user is responsible to make sure the pointer is valid (say, no | ||
47 | + * concurrent deletion in progress). | ||
48 | + */ | ||
49 | +const DMAMap *iova_tree_find_iova(const IOVATree *tree, const DMAMap *map); | ||
50 | + | ||
51 | +/** | ||
52 | * iova_tree_find_address: | ||
53 | * | ||
54 | * @tree: the iova tree to search from | ||
55 | diff --git a/util/iova-tree.c b/util/iova-tree.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/util/iova-tree.c | ||
58 | +++ b/util/iova-tree.c | ||
59 | @@ -XXX,XX +XXX,XX @@ struct IOVATreeAllocArgs { | ||
60 | bool iova_found; | ||
61 | }; | ||
62 | |||
63 | +typedef struct IOVATreeFindIOVAArgs { | ||
64 | + const DMAMap *needle; | ||
65 | + const DMAMap *result; | ||
66 | +} IOVATreeFindIOVAArgs; | ||
67 | + | ||
68 | /** | ||
69 | * Iterate args to the next hole | ||
70 | * | ||
71 | @@ -XXX,XX +XXX,XX @@ const DMAMap *iova_tree_find(const IOVATree *tree, const DMAMap *map) | ||
72 | return g_tree_lookup(tree->tree, map); | ||
73 | } | ||
74 | |||
75 | +static gboolean iova_tree_find_address_iterator(gpointer key, gpointer value, | ||
76 | + gpointer data) | ||
77 | +{ | ||
78 | + const DMAMap *map = key; | ||
79 | + IOVATreeFindIOVAArgs *args = data; | ||
80 | + const DMAMap *needle; | ||
81 | + | ||
82 | + g_assert(key == value); | ||
83 | + | ||
84 | + needle = args->needle; | ||
85 | + if (map->translated_addr + map->size < needle->translated_addr || | ||
86 | + needle->translated_addr + needle->size < map->translated_addr) { | ||
87 | + return false; | ||
88 | + } | ||
89 | + | ||
90 | + args->result = map; | ||
91 | + return true; | ||
92 | +} | ||
93 | + | ||
94 | +const DMAMap *iova_tree_find_iova(const IOVATree *tree, const DMAMap *map) | ||
95 | +{ | ||
96 | + IOVATreeFindIOVAArgs args = { | ||
97 | + .needle = map, | ||
98 | + }; | ||
99 | + | ||
100 | + g_tree_foreach(tree->tree, iova_tree_find_address_iterator, &args); | ||
101 | + return args.result; | ||
102 | +} | ||
103 | + | ||
104 | const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova) | ||
105 | { | ||
106 | const DMAMap map = { .iova = iova, .size = 0 }; | ||
107 | -- | ||
108 | 2.7.4 | ||
109 | |||
110 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Eugenio Pérez <eperezma@redhat.com> | ||
1 | 2 | ||
3 | This tree is able to look for a translated address from an IOVA address. | ||
4 | |||
5 | At first glance it is similar to util/iova-tree. However, SVQ working on | ||
6 | devices with limited IOVA space need more capabilities, like allocating | ||
7 | IOVA chunks or performing reverse translations (qemu addresses to iova). | ||
8 | |||
9 | The allocation capability, as "assign a free IOVA address to this chunk | ||
10 | of memory in qemu's address space" allows shadow virtqueue to create a | ||
11 | new address space that is not restricted by guest's addressable one, so | ||
12 | we can allocate shadow vqs vrings outside of it. | ||
13 | |||
14 | It duplicates the tree so it can search efficiently in both directions, | ||
15 | and it will signal overlap if iova or the translated address is present | ||
16 | in any tree. | ||
17 | |||
18 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
19 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
20 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
21 | --- | ||
22 | hw/virtio/meson.build | 2 +- | ||
23 | hw/virtio/vhost-iova-tree.c | 110 ++++++++++++++++++++++++++++++++++++++++++++ | ||
24 | hw/virtio/vhost-iova-tree.h | 27 +++++++++++ | ||
25 | 3 files changed, 138 insertions(+), 1 deletion(-) | ||
26 | create mode 100644 hw/virtio/vhost-iova-tree.c | ||
27 | create mode 100644 hw/virtio/vhost-iova-tree.h | ||
28 | |||
29 | diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/virtio/meson.build | ||
32 | +++ b/hw/virtio/meson.build | ||
33 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) | ||
34 | |||
35 | virtio_ss = ss.source_set() | ||
36 | virtio_ss.add(files('virtio.c')) | ||
37 | -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c')) | ||
38 | +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c', 'vhost-iova-tree.c')) | ||
39 | virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) | ||
40 | virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) | ||
41 | virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c')) | ||
42 | diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c | ||
43 | new file mode 100644 | ||
44 | index XXXXXXX..XXXXXXX | ||
45 | --- /dev/null | ||
46 | +++ b/hw/virtio/vhost-iova-tree.c | ||
47 | @@ -XXX,XX +XXX,XX @@ | ||
48 | +/* | ||
49 | + * vhost software live migration iova tree | ||
50 | + * | ||
51 | + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 | ||
52 | + * SPDX-FileContributor: Author: Eugenio Pérez <eperezma@redhat.com> | ||
53 | + * | ||
54 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
55 | + */ | ||
56 | + | ||
57 | +#include "qemu/osdep.h" | ||
58 | +#include "qemu/iova-tree.h" | ||
59 | +#include "vhost-iova-tree.h" | ||
60 | + | ||
61 | +#define iova_min_addr qemu_real_host_page_size | ||
62 | + | ||
63 | +/** | ||
64 | + * VhostIOVATree, able to: | ||
65 | + * - Translate iova address | ||
66 | + * - Reverse translate iova address (from translated to iova) | ||
67 | + * - Allocate IOVA regions for translated range (linear operation) | ||
68 | + */ | ||
69 | +struct VhostIOVATree { | ||
70 | + /* First addressable iova address in the device */ | ||
71 | + uint64_t iova_first; | ||
72 | + | ||
73 | + /* Last addressable iova address in the device */ | ||
74 | + uint64_t iova_last; | ||
75 | + | ||
76 | + /* IOVA address to qemu memory maps. */ | ||
77 | + IOVATree *iova_taddr_map; | ||
78 | +}; | ||
79 | + | ||
80 | +/** | ||
81 | + * Create a new IOVA tree | ||
82 | + * | ||
83 | + * Returns the new IOVA tree | ||
84 | + */ | ||
85 | +VhostIOVATree *vhost_iova_tree_new(hwaddr iova_first, hwaddr iova_last) | ||
86 | +{ | ||
87 | + VhostIOVATree *tree = g_new(VhostIOVATree, 1); | ||
88 | + | ||
89 | + /* Some devices do not like 0 addresses */ | ||
90 | + tree->iova_first = MAX(iova_first, iova_min_addr); | ||
91 | + tree->iova_last = iova_last; | ||
92 | + | ||
93 | + tree->iova_taddr_map = iova_tree_new(); | ||
94 | + return tree; | ||
95 | +} | ||
96 | + | ||
97 | +/** | ||
98 | + * Delete an iova tree | ||
99 | + */ | ||
100 | +void vhost_iova_tree_delete(VhostIOVATree *iova_tree) | ||
101 | +{ | ||
102 | + iova_tree_destroy(iova_tree->iova_taddr_map); | ||
103 | + g_free(iova_tree); | ||
104 | +} | ||
105 | + | ||
106 | +/** | ||
107 | + * Find the IOVA address stored from a memory address | ||
108 | + * | ||
109 | + * @tree: The iova tree | ||
110 | + * @map: The map with the memory address | ||
111 | + * | ||
112 | + * Return the stored mapping, or NULL if not found. | ||
113 | + */ | ||
114 | +const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *tree, | ||
115 | + const DMAMap *map) | ||
116 | +{ | ||
117 | + return iova_tree_find_iova(tree->iova_taddr_map, map); | ||
118 | +} | ||
119 | + | ||
120 | +/** | ||
121 | + * Allocate a new mapping | ||
122 | + * | ||
123 | + * @tree: The iova tree | ||
124 | + * @map: The iova map | ||
125 | + * | ||
126 | + * Returns: | ||
127 | + * - IOVA_OK if the map fits in the container | ||
128 | + * - IOVA_ERR_INVALID if the map does not make sense (like size overflow) | ||
129 | + * - IOVA_ERR_NOMEM if tree cannot allocate more space. | ||
130 | + * | ||
131 | + * It returns assignated iova in map->iova if return value is VHOST_DMA_MAP_OK. | ||
132 | + */ | ||
133 | +int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAMap *map) | ||
134 | +{ | ||
135 | + /* Some vhost devices do not like addr 0. Skip first page */ | ||
136 | + hwaddr iova_first = tree->iova_first ?: qemu_real_host_page_size; | ||
137 | + | ||
138 | + if (map->translated_addr + map->size < map->translated_addr || | ||
139 | + map->perm == IOMMU_NONE) { | ||
140 | + return IOVA_ERR_INVALID; | ||
141 | + } | ||
142 | + | ||
143 | + /* Allocate a node in IOVA address */ | ||
144 | + return iova_tree_alloc_map(tree->iova_taddr_map, map, iova_first, | ||
145 | + tree->iova_last); | ||
146 | +} | ||
147 | + | ||
148 | +/** | ||
149 | + * Remove existing mappings from iova tree | ||
150 | + * | ||
151 | + * @iova_tree: The vhost iova tree | ||
152 | + * @map: The map to remove | ||
153 | + */ | ||
154 | +void vhost_iova_tree_remove(VhostIOVATree *iova_tree, const DMAMap *map) | ||
155 | +{ | ||
156 | + iova_tree_remove(iova_tree->iova_taddr_map, map); | ||
157 | +} | ||
158 | diff --git a/hw/virtio/vhost-iova-tree.h b/hw/virtio/vhost-iova-tree.h | ||
159 | new file mode 100644 | ||
160 | index XXXXXXX..XXXXXXX | ||
161 | --- /dev/null | ||
162 | +++ b/hw/virtio/vhost-iova-tree.h | ||
163 | @@ -XXX,XX +XXX,XX @@ | ||
164 | +/* | ||
165 | + * vhost software live migration iova tree | ||
166 | + * | ||
167 | + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 | ||
168 | + * SPDX-FileContributor: Author: Eugenio Pérez <eperezma@redhat.com> | ||
169 | + * | ||
170 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
171 | + */ | ||
172 | + | ||
173 | +#ifndef HW_VIRTIO_VHOST_IOVA_TREE_H | ||
174 | +#define HW_VIRTIO_VHOST_IOVA_TREE_H | ||
175 | + | ||
176 | +#include "qemu/iova-tree.h" | ||
177 | +#include "exec/memory.h" | ||
178 | + | ||
179 | +typedef struct VhostIOVATree VhostIOVATree; | ||
180 | + | ||
181 | +VhostIOVATree *vhost_iova_tree_new(uint64_t iova_first, uint64_t iova_last); | ||
182 | +void vhost_iova_tree_delete(VhostIOVATree *iova_tree); | ||
183 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostIOVATree, vhost_iova_tree_delete); | ||
184 | + | ||
185 | +const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *iova_tree, | ||
186 | + const DMAMap *map); | ||
187 | +int vhost_iova_tree_map_alloc(VhostIOVATree *iova_tree, DMAMap *map); | ||
188 | +void vhost_iova_tree_remove(VhostIOVATree *iova_tree, const DMAMap *map); | ||
189 | + | ||
190 | +#endif | ||
191 | -- | ||
192 | 2.7.4 | ||
193 | |||
194 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Eugenio Pérez <eperezma@redhat.com> | |
2 | |||
3 | Use translations added in VhostIOVATree in SVQ. | ||
4 | |||
5 | Only introduce usage here, not allocation and deallocation. As with | ||
6 | previous patches, we use the dead code paths of shadow_vqs_enabled to | ||
7 | avoid commiting too many changes at once. These are impossible to take | ||
8 | at the moment. | ||
9 | |||
10 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
11 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
12 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
13 | --- | ||
14 | hw/virtio/vhost-shadow-virtqueue.c | 86 +++++++++++++++++++++++--- | ||
15 | hw/virtio/vhost-shadow-virtqueue.h | 6 +- | ||
16 | hw/virtio/vhost-vdpa.c | 122 +++++++++++++++++++++++++++++++------ | ||
17 | include/hw/virtio/vhost-vdpa.h | 3 + | ||
18 | 4 files changed, 187 insertions(+), 30 deletions(-) | ||
19 | |||
20 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/virtio/vhost-shadow-virtqueue.c | ||
23 | +++ b/hw/virtio/vhost-shadow-virtqueue.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static uint16_t vhost_svq_available_slots(const VhostShadowVirtqueue *svq) | ||
25 | return svq->vring.num - (svq->shadow_avail_idx - svq->shadow_used_idx); | ||
26 | } | ||
27 | |||
28 | -static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, | ||
29 | +/** | ||
30 | + * Translate addresses between the qemu's virtual address and the SVQ IOVA | ||
31 | + * | ||
32 | + * @svq: Shadow VirtQueue | ||
33 | + * @vaddr: Translated IOVA addresses | ||
34 | + * @iovec: Source qemu's VA addresses | ||
35 | + * @num: Length of iovec and minimum length of vaddr | ||
36 | + */ | ||
37 | +static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq, | ||
38 | + hwaddr *addrs, const struct iovec *iovec, | ||
39 | + size_t num) | ||
40 | +{ | ||
41 | + if (num == 0) { | ||
42 | + return true; | ||
43 | + } | ||
44 | + | ||
45 | + for (size_t i = 0; i < num; ++i) { | ||
46 | + DMAMap needle = { | ||
47 | + .translated_addr = (hwaddr)(uintptr_t)iovec[i].iov_base, | ||
48 | + .size = iovec[i].iov_len, | ||
49 | + }; | ||
50 | + Int128 needle_last, map_last; | ||
51 | + size_t off; | ||
52 | + | ||
53 | + const DMAMap *map = vhost_iova_tree_find_iova(svq->iova_tree, &needle); | ||
54 | + /* | ||
55 | + * Map cannot be NULL since iova map contains all guest space and | ||
56 | + * qemu already has a physical address mapped | ||
57 | + */ | ||
58 | + if (unlikely(!map)) { | ||
59 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
60 | + "Invalid address 0x%"HWADDR_PRIx" given by guest", | ||
61 | + needle.translated_addr); | ||
62 | + return false; | ||
63 | + } | ||
64 | + | ||
65 | + off = needle.translated_addr - map->translated_addr; | ||
66 | + addrs[i] = map->iova + off; | ||
67 | + | ||
68 | + needle_last = int128_add(int128_make64(needle.translated_addr), | ||
69 | + int128_make64(iovec[i].iov_len)); | ||
70 | + map_last = int128_make64(map->translated_addr + map->size); | ||
71 | + if (unlikely(int128_gt(needle_last, map_last))) { | ||
72 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
73 | + "Guest buffer expands over iova range"); | ||
74 | + return false; | ||
75 | + } | ||
76 | + } | ||
77 | + | ||
78 | + return true; | ||
79 | +} | ||
80 | + | ||
81 | +static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, | ||
82 | const struct iovec *iovec, size_t num, | ||
83 | bool more_descs, bool write) | ||
84 | { | ||
85 | @@ -XXX,XX +XXX,XX @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, | ||
86 | } else { | ||
87 | descs[i].flags = flags; | ||
88 | } | ||
89 | - descs[i].addr = cpu_to_le64((hwaddr)(intptr_t)iovec[n].iov_base); | ||
90 | + descs[i].addr = cpu_to_le64(sg[n]); | ||
91 | descs[i].len = cpu_to_le32(iovec[n].iov_len); | ||
92 | |||
93 | last = i; | ||
94 | @@ -XXX,XX +XXX,XX @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, | ||
95 | { | ||
96 | unsigned avail_idx; | ||
97 | vring_avail_t *avail = svq->vring.avail; | ||
98 | + bool ok; | ||
99 | + g_autofree hwaddr *sgs = g_new(hwaddr, MAX(elem->out_num, elem->in_num)); | ||
100 | |||
101 | *head = svq->free_head; | ||
102 | |||
103 | @@ -XXX,XX +XXX,XX @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, | ||
104 | return false; | ||
105 | } | ||
106 | |||
107 | - vhost_vring_write_descs(svq, elem->out_sg, elem->out_num, elem->in_num > 0, | ||
108 | - false); | ||
109 | - vhost_vring_write_descs(svq, elem->in_sg, elem->in_num, false, true); | ||
110 | + ok = vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num); | ||
111 | + if (unlikely(!ok)) { | ||
112 | + return false; | ||
113 | + } | ||
114 | + vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, | ||
115 | + elem->in_num > 0, false); | ||
116 | + | ||
117 | + | ||
118 | + ok = vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num); | ||
119 | + if (unlikely(!ok)) { | ||
120 | + return false; | ||
121 | + } | ||
122 | + | ||
123 | + vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, true); | ||
124 | |||
125 | /* | ||
126 | * Put the entry in the available array (but don't update avail->idx until | ||
127 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd) | ||
128 | void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, | ||
129 | struct vhost_vring_addr *addr) | ||
130 | { | ||
131 | - addr->desc_user_addr = (uint64_t)(intptr_t)svq->vring.desc; | ||
132 | - addr->avail_user_addr = (uint64_t)(intptr_t)svq->vring.avail; | ||
133 | - addr->used_user_addr = (uint64_t)(intptr_t)svq->vring.used; | ||
134 | + addr->desc_user_addr = (uint64_t)(uintptr_t)svq->vring.desc; | ||
135 | + addr->avail_user_addr = (uint64_t)(uintptr_t)svq->vring.avail; | ||
136 | + addr->used_user_addr = (uint64_t)(uintptr_t)svq->vring.used; | ||
137 | } | ||
138 | |||
139 | size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq) | ||
140 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) | ||
141 | * Creates vhost shadow virtqueue, and instructs the vhost device to use the | ||
142 | * shadow methods and file descriptors. | ||
143 | * | ||
144 | + * @iova_tree: Tree to perform descriptors translations | ||
145 | + * | ||
146 | * Returns the new virtqueue or NULL. | ||
147 | * | ||
148 | * In case of error, reason is reported through error_report. | ||
149 | */ | ||
150 | -VhostShadowVirtqueue *vhost_svq_new(void) | ||
151 | +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree) | ||
152 | { | ||
153 | g_autofree VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1); | ||
154 | int r; | ||
155 | @@ -XXX,XX +XXX,XX @@ VhostShadowVirtqueue *vhost_svq_new(void) | ||
156 | |||
157 | event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); | ||
158 | event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); | ||
159 | + svq->iova_tree = iova_tree; | ||
160 | return g_steal_pointer(&svq); | ||
161 | |||
162 | err_init_hdev_call: | ||
163 | diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h | ||
164 | index XXXXXXX..XXXXXXX 100644 | ||
165 | --- a/hw/virtio/vhost-shadow-virtqueue.h | ||
166 | +++ b/hw/virtio/vhost-shadow-virtqueue.h | ||
167 | @@ -XXX,XX +XXX,XX @@ | ||
168 | #include "qemu/event_notifier.h" | ||
169 | #include "hw/virtio/virtio.h" | ||
170 | #include "standard-headers/linux/vhost_types.h" | ||
171 | +#include "hw/virtio/vhost-iova-tree.h" | ||
172 | |||
173 | /* Shadow virtqueue to relay notifications */ | ||
174 | typedef struct VhostShadowVirtqueue { | ||
175 | @@ -XXX,XX +XXX,XX @@ typedef struct VhostShadowVirtqueue { | ||
176 | /* Virtio device */ | ||
177 | VirtIODevice *vdev; | ||
178 | |||
179 | + /* IOVA mapping */ | ||
180 | + VhostIOVATree *iova_tree; | ||
181 | + | ||
182 | /* Map for use the guest's descriptors */ | ||
183 | VirtQueueElement **ring_id_maps; | ||
184 | |||
185 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, | ||
186 | VirtQueue *vq); | ||
187 | void vhost_svq_stop(VhostShadowVirtqueue *svq); | ||
188 | |||
189 | -VhostShadowVirtqueue *vhost_svq_new(void); | ||
190 | +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree); | ||
191 | |||
192 | void vhost_svq_free(gpointer vq); | ||
193 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free); | ||
194 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c | ||
195 | index XXXXXXX..XXXXXXX 100644 | ||
196 | --- a/hw/virtio/vhost-vdpa.c | ||
197 | +++ b/hw/virtio/vhost-vdpa.c | ||
198 | @@ -XXX,XX +XXX,XX @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, | ||
199 | vaddr, section->readonly); | ||
200 | |||
201 | llsize = int128_sub(llend, int128_make64(iova)); | ||
202 | + if (v->shadow_vqs_enabled) { | ||
203 | + DMAMap mem_region = { | ||
204 | + .translated_addr = (hwaddr)(uintptr_t)vaddr, | ||
205 | + .size = int128_get64(llsize) - 1, | ||
206 | + .perm = IOMMU_ACCESS_FLAG(true, section->readonly), | ||
207 | + }; | ||
208 | + | ||
209 | + int r = vhost_iova_tree_map_alloc(v->iova_tree, &mem_region); | ||
210 | + if (unlikely(r != IOVA_OK)) { | ||
211 | + error_report("Can't allocate a mapping (%d)", r); | ||
212 | + goto fail; | ||
213 | + } | ||
214 | + | ||
215 | + iova = mem_region.iova; | ||
216 | + } | ||
217 | |||
218 | vhost_vdpa_iotlb_batch_begin_once(v); | ||
219 | ret = vhost_vdpa_dma_map(v, iova, int128_get64(llsize), | ||
220 | @@ -XXX,XX +XXX,XX @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, | ||
221 | |||
222 | llsize = int128_sub(llend, int128_make64(iova)); | ||
223 | |||
224 | + if (v->shadow_vqs_enabled) { | ||
225 | + const DMAMap *result; | ||
226 | + const void *vaddr = memory_region_get_ram_ptr(section->mr) + | ||
227 | + section->offset_within_region + | ||
228 | + (iova - section->offset_within_address_space); | ||
229 | + DMAMap mem_region = { | ||
230 | + .translated_addr = (hwaddr)(uintptr_t)vaddr, | ||
231 | + .size = int128_get64(llsize) - 1, | ||
232 | + }; | ||
233 | + | ||
234 | + result = vhost_iova_tree_find_iova(v->iova_tree, &mem_region); | ||
235 | + iova = result->iova; | ||
236 | + vhost_iova_tree_remove(v->iova_tree, &mem_region); | ||
237 | + } | ||
238 | vhost_vdpa_iotlb_batch_begin_once(v); | ||
239 | ret = vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize)); | ||
240 | if (ret) { | ||
241 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, | ||
242 | |||
243 | shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); | ||
244 | for (unsigned n = 0; n < hdev->nvqs; ++n) { | ||
245 | - g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(); | ||
246 | + g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(v->iova_tree); | ||
247 | |||
248 | if (unlikely(!svq)) { | ||
249 | error_setg(errp, "Cannot create svq %u", n); | ||
250 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev, | ||
251 | /** | ||
252 | * Unmap a SVQ area in the device | ||
253 | */ | ||
254 | -static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr iova, | ||
255 | - hwaddr size) | ||
256 | +static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, | ||
257 | + const DMAMap *needle) | ||
258 | { | ||
259 | + const DMAMap *result = vhost_iova_tree_find_iova(v->iova_tree, needle); | ||
260 | + hwaddr size; | ||
261 | int r; | ||
262 | |||
263 | - size = ROUND_UP(size, qemu_real_host_page_size); | ||
264 | - r = vhost_vdpa_dma_unmap(v, iova, size); | ||
265 | + if (unlikely(!result)) { | ||
266 | + error_report("Unable to find SVQ address to unmap"); | ||
267 | + return false; | ||
268 | + } | ||
269 | + | ||
270 | + size = ROUND_UP(result->size, qemu_real_host_page_size); | ||
271 | + r = vhost_vdpa_dma_unmap(v, result->iova, size); | ||
272 | return r == 0; | ||
273 | } | ||
274 | |||
275 | static bool vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, | ||
276 | const VhostShadowVirtqueue *svq) | ||
277 | { | ||
278 | + DMAMap needle = {}; | ||
279 | struct vhost_vdpa *v = dev->opaque; | ||
280 | struct vhost_vring_addr svq_addr; | ||
281 | - size_t device_size = vhost_svq_device_area_size(svq); | ||
282 | - size_t driver_size = vhost_svq_driver_area_size(svq); | ||
283 | bool ok; | ||
284 | |||
285 | vhost_svq_get_vring_addr(svq, &svq_addr); | ||
286 | |||
287 | - ok = vhost_vdpa_svq_unmap_ring(v, svq_addr.desc_user_addr, driver_size); | ||
288 | + needle.translated_addr = svq_addr.desc_user_addr; | ||
289 | + ok = vhost_vdpa_svq_unmap_ring(v, &needle); | ||
290 | if (unlikely(!ok)) { | ||
291 | return false; | ||
292 | } | ||
293 | |||
294 | - return vhost_vdpa_svq_unmap_ring(v, svq_addr.used_user_addr, device_size); | ||
295 | + needle.translated_addr = svq_addr.used_user_addr; | ||
296 | + return vhost_vdpa_svq_unmap_ring(v, &needle); | ||
297 | +} | ||
298 | + | ||
299 | +/** | ||
300 | + * Map the SVQ area in the device | ||
301 | + * | ||
302 | + * @v: Vhost-vdpa device | ||
303 | + * @needle: The area to search iova | ||
304 | + * @errorp: Error pointer | ||
305 | + */ | ||
306 | +static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, DMAMap *needle, | ||
307 | + Error **errp) | ||
308 | +{ | ||
309 | + int r; | ||
310 | + | ||
311 | + r = vhost_iova_tree_map_alloc(v->iova_tree, needle); | ||
312 | + if (unlikely(r != IOVA_OK)) { | ||
313 | + error_setg(errp, "Cannot allocate iova (%d)", r); | ||
314 | + return false; | ||
315 | + } | ||
316 | + | ||
317 | + r = vhost_vdpa_dma_map(v, needle->iova, needle->size + 1, | ||
318 | + (void *)(uintptr_t)needle->translated_addr, | ||
319 | + needle->perm == IOMMU_RO); | ||
320 | + if (unlikely(r != 0)) { | ||
321 | + error_setg_errno(errp, -r, "Cannot map region to device"); | ||
322 | + vhost_iova_tree_remove(v->iova_tree, needle); | ||
323 | + } | ||
324 | + | ||
325 | + return r == 0; | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_svq_map_rings(struct vhost_dev *dev, | ||
330 | struct vhost_vring_addr *addr, | ||
331 | Error **errp) | ||
332 | { | ||
333 | + DMAMap device_region, driver_region; | ||
334 | + struct vhost_vring_addr svq_addr; | ||
335 | struct vhost_vdpa *v = dev->opaque; | ||
336 | size_t device_size = vhost_svq_device_area_size(svq); | ||
337 | size_t driver_size = vhost_svq_driver_area_size(svq); | ||
338 | - int r; | ||
339 | + size_t avail_offset; | ||
340 | + bool ok; | ||
341 | |||
342 | ERRP_GUARD(); | ||
343 | - vhost_svq_get_vring_addr(svq, addr); | ||
344 | + vhost_svq_get_vring_addr(svq, &svq_addr); | ||
345 | |||
346 | - r = vhost_vdpa_dma_map(v, addr->desc_user_addr, driver_size, | ||
347 | - (void *)(uintptr_t)addr->desc_user_addr, true); | ||
348 | - if (unlikely(r != 0)) { | ||
349 | - error_setg_errno(errp, -r, "Cannot create vq driver region: "); | ||
350 | + driver_region = (DMAMap) { | ||
351 | + .translated_addr = svq_addr.desc_user_addr, | ||
352 | + .size = driver_size - 1, | ||
353 | + .perm = IOMMU_RO, | ||
354 | + }; | ||
355 | + ok = vhost_vdpa_svq_map_ring(v, &driver_region, errp); | ||
356 | + if (unlikely(!ok)) { | ||
357 | + error_prepend(errp, "Cannot create vq driver region: "); | ||
358 | return false; | ||
359 | } | ||
360 | + addr->desc_user_addr = driver_region.iova; | ||
361 | + avail_offset = svq_addr.avail_user_addr - svq_addr.desc_user_addr; | ||
362 | + addr->avail_user_addr = driver_region.iova + avail_offset; | ||
363 | |||
364 | - r = vhost_vdpa_dma_map(v, addr->used_user_addr, device_size, | ||
365 | - (void *)(intptr_t)addr->used_user_addr, false); | ||
366 | - if (unlikely(r != 0)) { | ||
367 | - error_setg_errno(errp, -r, "Cannot create vq device region: "); | ||
368 | + device_region = (DMAMap) { | ||
369 | + .translated_addr = svq_addr.used_user_addr, | ||
370 | + .size = device_size - 1, | ||
371 | + .perm = IOMMU_RW, | ||
372 | + }; | ||
373 | + ok = vhost_vdpa_svq_map_ring(v, &device_region, errp); | ||
374 | + if (unlikely(!ok)) { | ||
375 | + error_prepend(errp, "Cannot create vq device region: "); | ||
376 | + vhost_vdpa_svq_unmap_ring(v, &driver_region); | ||
377 | } | ||
378 | + addr->used_user_addr = device_region.iova; | ||
379 | |||
380 | - return r == 0; | ||
381 | + return ok; | ||
382 | } | ||
383 | |||
384 | static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, | ||
385 | diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h | ||
386 | index XXXXXXX..XXXXXXX 100644 | ||
387 | --- a/include/hw/virtio/vhost-vdpa.h | ||
388 | +++ b/include/hw/virtio/vhost-vdpa.h | ||
389 | @@ -XXX,XX +XXX,XX @@ | ||
390 | |||
391 | #include <gmodule.h> | ||
392 | |||
393 | +#include "hw/virtio/vhost-iova-tree.h" | ||
394 | #include "hw/virtio/virtio.h" | ||
395 | #include "standard-headers/linux/vhost_types.h" | ||
396 | |||
397 | @@ -XXX,XX +XXX,XX @@ typedef struct vhost_vdpa { | ||
398 | MemoryListener listener; | ||
399 | struct vhost_vdpa_iova_range iova_range; | ||
400 | bool shadow_vqs_enabled; | ||
401 | + /* IOVA mapping used by the Shadow Virtqueue */ | ||
402 | + VhostIOVATree *iova_tree; | ||
403 | GPtrArray *shadow_vqs; | ||
404 | struct vhost_dev *dev; | ||
405 | VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; | ||
406 | -- | ||
407 | 2.7.4 | ||
408 | |||
409 | diff view generated by jsdifflib |
1 | Several issues has been reported for query-netdev series. Consider | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | it's late in the rc, this reverts commit | ||
3 | 3c3b656885473ef0d699290ba966177f17839aa5. | ||
4 | 2 | ||
3 | This is needed to achieve migration, so the destination can restore its | ||
4 | index. | ||
5 | |||
6 | Setting base as last used idx, so destination will see as available all | ||
7 | the entries that the device did not use, including the in-flight | ||
8 | processing ones. | ||
9 | |||
10 | This is ok for networking, but other kinds of devices might have | ||
11 | problems with these retransmissions. | ||
12 | |||
13 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
14 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
5 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 15 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
6 | --- | 16 | --- |
7 | tests/qtest/meson.build | 3 - | 17 | hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ |
8 | tests/qtest/test-query-netdev.c | 120 ---------------------------------------- | 18 | 1 file changed, 17 insertions(+) |
9 | 2 files changed, 123 deletions(-) | ||
10 | delete mode 100644 tests/qtest/test-query-netdev.c | ||
11 | 19 | ||
12 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 20 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c |
13 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tests/qtest/meson.build | 22 | --- a/hw/virtio/vhost-vdpa.c |
15 | +++ b/tests/qtest/meson.build | 23 | +++ b/hw/virtio/vhost-vdpa.c |
16 | @@ -XXX,XX +XXX,XX @@ qtests_generic = \ | 24 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, |
17 | if config_host.has_key('CONFIG_MODULES') | 25 | static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, |
18 | qtests_generic += [ 'modules-test' ] | 26 | struct vhost_vring_state *ring) |
19 | endif | 27 | { |
20 | -if slirp.found() | 28 | + struct vhost_vdpa *v = dev->opaque; |
21 | - qtests_generic += [ 'test-query-netdev' ] | 29 | int ret; |
22 | -endif | 30 | |
23 | 31 | + if (v->shadow_vqs_enabled) { | |
24 | qtests_pci = \ | 32 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, |
25 | (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : []) + \ | 33 | + ring->index); |
26 | diff --git a/tests/qtest/test-query-netdev.c b/tests/qtest/test-query-netdev.c | 34 | + |
27 | deleted file mode 100644 | 35 | + /* |
28 | index XXXXXXX..XXXXXXX | 36 | + * Setting base as last used idx, so destination will see as available |
29 | --- a/tests/qtest/test-query-netdev.c | 37 | + * all the entries that the device did not use, including the in-flight |
30 | +++ /dev/null | 38 | + * processing ones. |
31 | @@ -XXX,XX +XXX,XX @@ | 39 | + * |
32 | -/* | 40 | + * TODO: This is ok for networking, but other kinds of devices might |
33 | - * QTest testcase for the query-netdev | 41 | + * have problems with these retransmissions. |
34 | - * | 42 | + */ |
35 | - * Copyright Yandex N.V., 2019 | 43 | + ring->num = svq->last_used_idx; |
36 | - * | 44 | + return 0; |
37 | - * This work is licensed under the terms of the GNU GPL, version 2 or later. | 45 | + } |
38 | - * See the COPYING file in the top-level directory. | 46 | + |
39 | - * | 47 | ret = vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); |
40 | - */ | 48 | trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num); |
41 | - | 49 | return ret; |
42 | -#include "qemu/osdep.h" | ||
43 | - | ||
44 | -#include "libqos/libqtest.h" | ||
45 | -#include "qapi/qmp/qdict.h" | ||
46 | -#include "qapi/qmp/qlist.h" | ||
47 | - | ||
48 | -/* | ||
49 | - * Events can get in the way of responses we are actually waiting for. | ||
50 | - */ | ||
51 | -GCC_FMT_ATTR(2, 3) | ||
52 | -static QObject *wait_command(QTestState *who, const char *command, ...) | ||
53 | -{ | ||
54 | - va_list ap; | ||
55 | - QDict *response; | ||
56 | - QObject *result; | ||
57 | - | ||
58 | - va_start(ap, command); | ||
59 | - qtest_qmp_vsend(who, command, ap); | ||
60 | - va_end(ap); | ||
61 | - | ||
62 | - response = qtest_qmp_receive(who); | ||
63 | - | ||
64 | - result = qdict_get(response, "return"); | ||
65 | - g_assert(result); | ||
66 | - qobject_ref(result); | ||
67 | - qobject_unref(response); | ||
68 | - | ||
69 | - return result; | ||
70 | -} | ||
71 | - | ||
72 | -static void qmp_query_netdev_no_error(QTestState *qts, size_t netdevs_count) | ||
73 | -{ | ||
74 | - QObject *resp; | ||
75 | - QList *netdevs; | ||
76 | - | ||
77 | - resp = wait_command(qts, "{'execute': 'query-netdev'}"); | ||
78 | - | ||
79 | - netdevs = qobject_to(QList, resp); | ||
80 | - g_assert(netdevs); | ||
81 | - g_assert(qlist_size(netdevs) == netdevs_count); | ||
82 | - | ||
83 | - qobject_unref(resp); | ||
84 | -} | ||
85 | - | ||
86 | -static void test_query_netdev(void) | ||
87 | -{ | ||
88 | - const char *arch = qtest_get_arch(); | ||
89 | - QObject *resp; | ||
90 | - QTestState *state; | ||
91 | - | ||
92 | - /* Choosing machine for platforms without default one */ | ||
93 | - if (g_str_equal(arch, "arm") || | ||
94 | - g_str_equal(arch, "aarch64")) { | ||
95 | - state = qtest_init( | ||
96 | - "-nodefaults " | ||
97 | - "-M virt " | ||
98 | - "-netdev user,id=slirp0"); | ||
99 | - } else if (g_str_equal(arch, "tricore")) { | ||
100 | - state = qtest_init( | ||
101 | - "-nodefaults " | ||
102 | - "-M tricore_testboard " | ||
103 | - "-netdev user,id=slirp0"); | ||
104 | - } else if (g_str_equal(arch, "avr")) { | ||
105 | - state = qtest_init( | ||
106 | - "-nodefaults " | ||
107 | - "-M mega2560 " | ||
108 | - "-netdev user,id=slirp0"); | ||
109 | - } else if (g_str_equal(arch, "rx")) { | ||
110 | - state = qtest_init( | ||
111 | - "-nodefaults " | ||
112 | - "-M gdbsim-r5f562n8 " | ||
113 | - "-netdev user,id=slirp0"); | ||
114 | - } else { | ||
115 | - state = qtest_init( | ||
116 | - "-nodefaults " | ||
117 | - "-netdev user,id=slirp0"); | ||
118 | - } | ||
119 | - g_assert(state); | ||
120 | - | ||
121 | - qmp_query_netdev_no_error(state, 1); | ||
122 | - | ||
123 | - resp = wait_command(state, | ||
124 | - "{'execute': 'netdev_add', 'arguments': {" | ||
125 | - " 'id': 'slirp1'," | ||
126 | - " 'type': 'user'}}"); | ||
127 | - qobject_unref(resp); | ||
128 | - | ||
129 | - qmp_query_netdev_no_error(state, 2); | ||
130 | - | ||
131 | - resp = wait_command(state, | ||
132 | - "{'execute': 'netdev_del', 'arguments': {" | ||
133 | - " 'id': 'slirp1'}}"); | ||
134 | - qobject_unref(resp); | ||
135 | - | ||
136 | - qmp_query_netdev_no_error(state, 1); | ||
137 | - | ||
138 | - qtest_quit(state); | ||
139 | -} | ||
140 | - | ||
141 | -int main(int argc, char **argv) | ||
142 | -{ | ||
143 | - int ret = 0; | ||
144 | - g_test_init(&argc, &argv, NULL); | ||
145 | - | ||
146 | - qtest_add_func("/net/qapi/query_netdev", test_query_netdev); | ||
147 | - | ||
148 | - ret = g_test_run(); | ||
149 | - | ||
150 | - return ret; | ||
151 | -} | ||
152 | -- | 50 | -- |
153 | 2.7.4 | 51 | 2.7.4 |
154 | 52 | ||
155 | 53 | diff view generated by jsdifflib |
1 | Commit 969e50b61a28 ("net: Pad short frames to minimum size before | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | sending from SLiRP/TAP") tries to pad frames but try to recyle the | ||
3 | local array that is used for padding to tap thread. This patch fixes | ||
4 | this by recyling the original buffer. | ||
5 | 2 | ||
6 | Fixes: 969e50b61a28 ("net: Pad short frames to minimum size before sending from SLiRP/TAP") | 3 | Setting the log address would make the device start reporting invalid |
7 | Tested-by: Howard Spoelstra <hsp.cat7@gmail.com> | 4 | dirty memory because the SVQ vrings are located in qemu's memory. |
8 | Tested-by: Bin Meng <bmeng.cn@gmail.com> | 5 | |
9 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 6 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> |
7 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
10 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 8 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
11 | --- | 9 | --- |
12 | net/tap-win32.c | 6 ++++-- | 10 | hw/virtio/vhost-vdpa.c | 3 ++- |
13 | 1 file changed, 4 insertions(+), 2 deletions(-) | 11 | 1 file changed, 2 insertions(+), 1 deletion(-) |
14 | 12 | ||
15 | diff --git a/net/tap-win32.c b/net/tap-win32.c | 13 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c |
16 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/net/tap-win32.c | 15 | --- a/hw/virtio/vhost-vdpa.c |
18 | +++ b/net/tap-win32.c | 16 | +++ b/hw/virtio/vhost-vdpa.c |
19 | @@ -XXX,XX +XXX,XX @@ static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size) | 17 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) |
20 | static void tap_win32_send(void *opaque) | 18 | static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, |
19 | struct vhost_log *log) | ||
21 | { | 20 | { |
22 | TAPState *s = opaque; | 21 | - if (vhost_vdpa_one_time_request(dev)) { |
23 | - uint8_t *buf; | 22 | + struct vhost_vdpa *v = dev->opaque; |
24 | + uint8_t *buf, *orig_buf; | 23 | + if (v->shadow_vqs_enabled || vhost_vdpa_one_time_request(dev)) { |
25 | int max_size = 4096; | 24 | return 0; |
26 | int size; | ||
27 | uint8_t min_pkt[ETH_ZLEN]; | ||
28 | @@ -XXX,XX +XXX,XX @@ static void tap_win32_send(void *opaque) | ||
29 | |||
30 | size = tap_win32_read(s->handle, &buf, max_size); | ||
31 | if (size > 0) { | ||
32 | + orig_buf = buf; | ||
33 | + | ||
34 | if (!s->nc.peer->do_not_pad) { | ||
35 | if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) { | ||
36 | buf = min_pkt; | ||
37 | @@ -XXX,XX +XXX,XX @@ static void tap_win32_send(void *opaque) | ||
38 | } | ||
39 | |||
40 | qemu_send_packet(&s->nc, buf, size); | ||
41 | - tap_win32_free_buffer(s->handle, buf); | ||
42 | + tap_win32_free_buffer(s->handle, orig_buf); | ||
43 | } | 25 | } |
44 | } | ||
45 | 26 | ||
46 | -- | 27 | -- |
47 | 2.7.4 | 28 | 2.7.4 |
48 | 29 | ||
49 | 30 | diff view generated by jsdifflib |
1 | Several issues has been reported for query-netdev info | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | series. Consider it's late in the rc, this reverts commit | ||
3 | a0724776c5a98a08fc946bb5a4ad16410ca64c0e. | ||
4 | 2 | ||
3 | SVQ is able to log the dirty bits by itself, so let's use it to not | ||
4 | block migration. | ||
5 | |||
6 | Also, ignore set and clear of VHOST_F_LOG_ALL on set_features if SVQ is | ||
7 | enabled. Even if the device supports it, the reports would be nonsense | ||
8 | because SVQ memory is in the qemu region. | ||
9 | |||
10 | The log region is still allocated. Future changes might skip that, but | ||
11 | this series is already long enough. | ||
12 | |||
13 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
14 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
5 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 15 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
6 | --- | 16 | --- |
7 | include/qapi/hmp-output-visitor.h | 30 ------ | 17 | hw/virtio/vhost-vdpa.c | 39 +++++++++++++++++++++++++++++++++++---- |
8 | net/net.c | 31 +----- | 18 | include/hw/virtio/vhost-vdpa.h | 1 + |
9 | qapi/hmp-output-visitor.c | 193 -------------------------------------- | 19 | 2 files changed, 36 insertions(+), 4 deletions(-) |
10 | qapi/meson.build | 1 - | ||
11 | 4 files changed, 1 insertion(+), 254 deletions(-) | ||
12 | delete mode 100644 include/qapi/hmp-output-visitor.h | ||
13 | delete mode 100644 qapi/hmp-output-visitor.c | ||
14 | 20 | ||
15 | diff --git a/include/qapi/hmp-output-visitor.h b/include/qapi/hmp-output-visitor.h | 21 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c |
16 | deleted file mode 100644 | ||
17 | index XXXXXXX..XXXXXXX | ||
18 | --- a/include/qapi/hmp-output-visitor.h | ||
19 | +++ /dev/null | ||
20 | @@ -XXX,XX +XXX,XX @@ | ||
21 | -/* | ||
22 | - * HMP string output Visitor | ||
23 | - * | ||
24 | - * Copyright Yandex N.V., 2021 | ||
25 | - * | ||
26 | - * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
27 | - * See the COPYING file in the top-level directory. | ||
28 | - * | ||
29 | - */ | ||
30 | - | ||
31 | -#ifndef HMP_OUTPUT_VISITOR_H | ||
32 | -#define HMP_OUTPUT_VISITOR_H | ||
33 | - | ||
34 | -#include "qapi/visitor.h" | ||
35 | - | ||
36 | -typedef struct HMPOutputVisitor HMPOutputVisitor; | ||
37 | - | ||
38 | -/** | ||
39 | - * Create a HMP string output visitor for @obj | ||
40 | - * | ||
41 | - * Flattens dicts/structures, only shows arrays borders. | ||
42 | - * | ||
43 | - * Errors are not expected to happen. | ||
44 | - * | ||
45 | - * The caller is responsible for freeing the visitor with | ||
46 | - * visit_free(). | ||
47 | - */ | ||
48 | -Visitor *hmp_output_visitor_new(char **result); | ||
49 | - | ||
50 | -#endif | ||
51 | diff --git a/net/net.c b/net/net.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/net/net.c | 23 | --- a/hw/virtio/vhost-vdpa.c |
54 | +++ b/net/net.c | 24 | +++ b/hw/virtio/vhost-vdpa.c |
55 | @@ -XXX,XX +XXX,XX @@ | 25 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_one_time_request(struct vhost_dev *dev) |
56 | #include "sysemu/sysemu.h" | 26 | return v->index != 0; |
57 | #include "net/filter.h" | ||
58 | #include "qapi/string-output-visitor.h" | ||
59 | -#include "qapi/hmp-output-visitor.h" | ||
60 | |||
61 | /* Net bridge is currently not supported for W32. */ | ||
62 | #if !defined(_WIN32) | ||
63 | @@ -XXX,XX +XXX,XX @@ static void netfilter_print_info(Monitor *mon, NetFilterState *nf) | ||
64 | monitor_printf(mon, "\n"); | ||
65 | } | 27 | } |
66 | 28 | ||
67 | -static char *generate_info_str(NetClientState *nc) | 29 | +static int vhost_vdpa_get_dev_features(struct vhost_dev *dev, |
68 | -{ | 30 | + uint64_t *features) |
69 | - NetdevInfo *ni = nc->stored_config; | 31 | +{ |
70 | - char *ret_out = NULL; | 32 | + int ret; |
71 | - Visitor *v; | 33 | + |
72 | - | 34 | + ret = vhost_vdpa_call(dev, VHOST_GET_FEATURES, features); |
73 | - /* Use legacy field info_str for NIC and hubports */ | 35 | + trace_vhost_vdpa_get_features(dev, *features); |
74 | - if ((nc->info->type == NET_CLIENT_DRIVER_NIC) || | 36 | + return ret; |
75 | - (nc->info->type == NET_CLIENT_DRIVER_HUBPORT)) { | 37 | +} |
76 | - return g_strdup(nc->info_str ? nc->info_str : ""); | 38 | + |
77 | - } | 39 | static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, |
78 | - | 40 | Error **errp) |
79 | - if (!ni) { | ||
80 | - return g_malloc0(1); | ||
81 | - } | ||
82 | - | ||
83 | - v = hmp_output_visitor_new(&ret_out); | ||
84 | - if (visit_type_NetdevInfo(v, "", &ni, NULL)) { | ||
85 | - visit_complete(v, &ret_out); | ||
86 | - } | ||
87 | - visit_free(v); | ||
88 | - | ||
89 | - return ret_out; | ||
90 | -} | ||
91 | - | ||
92 | void print_net_client(Monitor *mon, NetClientState *nc) | ||
93 | { | 41 | { |
94 | NetFilterState *nf; | 42 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, |
95 | - char *info_str = generate_info_str(nc); | 43 | return 0; |
96 | |||
97 | monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name, | ||
98 | nc->queue_index, | ||
99 | NetClientDriver_str(nc->info->type), | ||
100 | - info_str); | ||
101 | - g_free(info_str); | ||
102 | - | ||
103 | + nc->info_str ? nc->info_str : ""); | ||
104 | if (!QTAILQ_EMPTY(&nc->filters)) { | ||
105 | monitor_printf(mon, "filters:\n"); | ||
106 | } | 44 | } |
107 | diff --git a/qapi/hmp-output-visitor.c b/qapi/hmp-output-visitor.c | 45 | |
108 | deleted file mode 100644 | 46 | - r = hdev->vhost_ops->vhost_get_features(hdev, &dev_features); |
109 | index XXXXXXX..XXXXXXX | 47 | + r = vhost_vdpa_get_dev_features(hdev, &dev_features); |
110 | --- a/qapi/hmp-output-visitor.c | 48 | if (r != 0) { |
111 | +++ /dev/null | 49 | error_setg_errno(errp, -r, "Can't get vdpa device features"); |
112 | @@ -XXX,XX +XXX,XX @@ | 50 | return r; |
113 | -/* | 51 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_mem_table(struct vhost_dev *dev, |
114 | - * HMP string output Visitor | 52 | static int vhost_vdpa_set_features(struct vhost_dev *dev, |
115 | - * | 53 | uint64_t features) |
116 | - * Copyright Yandex N.V., 2021 | 54 | { |
117 | - * | 55 | + struct vhost_vdpa *v = dev->opaque; |
118 | - * This work is licensed under the terms of the GNU GPL, version 2 or later. | 56 | int ret; |
119 | - * See the COPYING file in the top-level directory. | 57 | |
120 | - * | 58 | if (vhost_vdpa_one_time_request(dev)) { |
121 | - */ | 59 | return 0; |
122 | - | 60 | } |
123 | -#include "qemu/osdep.h" | 61 | |
124 | -#include "qemu/cutils.h" | 62 | + if (v->shadow_vqs_enabled) { |
125 | -#include "qapi/hmp-output-visitor.h" | 63 | + if ((v->acked_features ^ features) == BIT_ULL(VHOST_F_LOG_ALL)) { |
126 | -#include "qapi/visitor-impl.h" | 64 | + /* |
127 | - | 65 | + * QEMU is just trying to enable or disable logging. SVQ handles |
128 | -struct HMPOutputVisitor { | 66 | + * this sepparately, so no need to forward this. |
129 | - Visitor visitor; | 67 | + */ |
130 | - char **result; | 68 | + v->acked_features = features; |
131 | - GString *buffer; | 69 | + return 0; |
132 | - bool is_continue; | 70 | + } |
133 | -}; | 71 | + |
134 | - | 72 | + v->acked_features = features; |
135 | -static HMPOutputVisitor *to_hov(Visitor *v) | 73 | + |
136 | -{ | 74 | + /* We must not ack _F_LOG if SVQ is enabled */ |
137 | - return container_of(v, HMPOutputVisitor, visitor); | 75 | + features &= ~BIT_ULL(VHOST_F_LOG_ALL); |
138 | -} | 76 | + } |
139 | - | 77 | + |
140 | -static void hmp_output_append_formatted(Visitor *v, const char *fmt, ...) | 78 | trace_vhost_vdpa_set_features(dev, features); |
141 | -{ | 79 | ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); |
142 | - HMPOutputVisitor *ov = to_hov(v); | 80 | if (ret) { |
143 | - va_list args; | 81 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, |
144 | - | 82 | static int vhost_vdpa_get_features(struct vhost_dev *dev, |
145 | - if (ov->is_continue) { | 83 | uint64_t *features) |
146 | - g_string_append(ov->buffer, ","); | 84 | { |
147 | - } else { | 85 | - int ret; |
148 | - ov->is_continue = true; | 86 | + struct vhost_vdpa *v = dev->opaque; |
149 | - } | 87 | + int ret = vhost_vdpa_get_dev_features(dev, features); |
150 | - | 88 | + |
151 | - va_start(args, fmt); | 89 | + if (ret == 0 && v->shadow_vqs_enabled) { |
152 | - g_string_append_vprintf(ov->buffer, fmt, args); | 90 | + /* Add SVQ logging capabilities */ |
153 | - va_end(args); | 91 | + *features |= BIT_ULL(VHOST_F_LOG_ALL); |
154 | -} | 92 | + } |
155 | - | 93 | |
156 | -static void hmp_output_skip_comma(Visitor *v) | 94 | - ret = vhost_vdpa_call(dev, VHOST_GET_FEATURES, features); |
157 | -{ | 95 | - trace_vhost_vdpa_get_features(dev, *features); |
158 | - HMPOutputVisitor *ov = to_hov(v); | 96 | return ret; |
159 | - | 97 | } |
160 | - ov->is_continue = false; | 98 | |
161 | -} | 99 | diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h |
162 | - | ||
163 | -static bool hmp_output_start_struct(Visitor *v, const char *name, | ||
164 | - void **obj, size_t unused, Error **errp) | ||
165 | -{ | ||
166 | - return true; | ||
167 | -} | ||
168 | - | ||
169 | -static void hmp_output_end_struct(Visitor *v, void **obj) {} | ||
170 | - | ||
171 | -static bool hmp_output_start_list(Visitor *v, const char *name, | ||
172 | - GenericList **listp, size_t size, | ||
173 | - Error **errp) | ||
174 | -{ | ||
175 | - hmp_output_append_formatted(v, "%s=[", name); | ||
176 | - /* First element in array without comma before it */ | ||
177 | - hmp_output_skip_comma(v); | ||
178 | - | ||
179 | - return true; | ||
180 | -} | ||
181 | - | ||
182 | -static GenericList *hmp_output_next_list(Visitor *v, GenericList *tail, | ||
183 | - size_t size) | ||
184 | -{ | ||
185 | - return tail->next; | ||
186 | -} | ||
187 | - | ||
188 | -static void hmp_output_end_list(Visitor *v, void **obj) | ||
189 | -{ | ||
190 | - /* Don't need comma after last array element */ | ||
191 | - hmp_output_skip_comma(v); | ||
192 | - hmp_output_append_formatted(v, "]"); | ||
193 | -} | ||
194 | - | ||
195 | -static bool hmp_output_type_int64(Visitor *v, const char *name, | ||
196 | - int64_t *obj, Error **errp) | ||
197 | -{ | ||
198 | - hmp_output_append_formatted(v, "%s=%" PRId64, name, *obj); | ||
199 | - | ||
200 | - return true; | ||
201 | -} | ||
202 | - | ||
203 | -static bool hmp_output_type_uint64(Visitor *v, const char *name, | ||
204 | - uint64_t *obj, Error **errp) | ||
205 | -{ | ||
206 | - hmp_output_append_formatted(v, "%s=%" PRIu64, name, *obj); | ||
207 | - | ||
208 | - return true; | ||
209 | -} | ||
210 | - | ||
211 | -static bool hmp_output_type_bool(Visitor *v, const char *name, bool *obj, | ||
212 | - Error **errp) | ||
213 | -{ | ||
214 | - hmp_output_append_formatted(v, "%s=%s", name, *obj ? "true" : "false"); | ||
215 | - | ||
216 | - return true; | ||
217 | -} | ||
218 | - | ||
219 | -static bool hmp_output_type_str(Visitor *v, const char *name, char **obj, | ||
220 | - Error **errp) | ||
221 | -{ | ||
222 | - /* Skip already printed or unused fields */ | ||
223 | - if (!*obj || g_str_equal(name, "id") || g_str_equal(name, "type")) { | ||
224 | - return true; | ||
225 | - } | ||
226 | - | ||
227 | - /* Do not print stub name for StringList elements */ | ||
228 | - if (g_str_equal(name, "str")) { | ||
229 | - hmp_output_append_formatted(v, "%s", *obj); | ||
230 | - } else { | ||
231 | - hmp_output_append_formatted(v, "%s=%s", name, *obj); | ||
232 | - } | ||
233 | - | ||
234 | - return true; | ||
235 | -} | ||
236 | - | ||
237 | -static bool hmp_output_type_number(Visitor *v, const char *name, | ||
238 | - double *obj, Error **errp) | ||
239 | -{ | ||
240 | - hmp_output_append_formatted(v, "%s=%.17g", name, *obj); | ||
241 | - | ||
242 | - return true; | ||
243 | -} | ||
244 | - | ||
245 | -/* TODO: remove this function? */ | ||
246 | -static bool hmp_output_type_any(Visitor *v, const char *name, | ||
247 | - QObject **obj, Error **errp) | ||
248 | -{ | ||
249 | - return true; | ||
250 | -} | ||
251 | - | ||
252 | -static bool hmp_output_type_null(Visitor *v, const char *name, | ||
253 | - QNull **obj, Error **errp) | ||
254 | -{ | ||
255 | - hmp_output_append_formatted(v, "%s=NULL", name); | ||
256 | - | ||
257 | - return true; | ||
258 | -} | ||
259 | - | ||
260 | -static void hmp_output_complete(Visitor *v, void *opaque) | ||
261 | -{ | ||
262 | - HMPOutputVisitor *ov = to_hov(v); | ||
263 | - | ||
264 | - *ov->result = g_string_free(ov->buffer, false); | ||
265 | - ov->buffer = NULL; | ||
266 | -} | ||
267 | - | ||
268 | -static void hmp_output_free(Visitor *v) | ||
269 | -{ | ||
270 | - HMPOutputVisitor *ov = to_hov(v); | ||
271 | - | ||
272 | - if (ov->buffer) { | ||
273 | - g_string_free(ov->buffer, true); | ||
274 | - } | ||
275 | - g_free(v); | ||
276 | -} | ||
277 | - | ||
278 | -Visitor *hmp_output_visitor_new(char **result) | ||
279 | -{ | ||
280 | - HMPOutputVisitor *v; | ||
281 | - | ||
282 | - v = g_malloc0(sizeof(*v)); | ||
283 | - | ||
284 | - v->visitor.type = VISITOR_OUTPUT; | ||
285 | - v->visitor.start_struct = hmp_output_start_struct; | ||
286 | - v->visitor.end_struct = hmp_output_end_struct; | ||
287 | - v->visitor.start_list = hmp_output_start_list; | ||
288 | - v->visitor.next_list = hmp_output_next_list; | ||
289 | - v->visitor.end_list = hmp_output_end_list; | ||
290 | - v->visitor.type_int64 = hmp_output_type_int64; | ||
291 | - v->visitor.type_uint64 = hmp_output_type_uint64; | ||
292 | - v->visitor.type_bool = hmp_output_type_bool; | ||
293 | - v->visitor.type_str = hmp_output_type_str; | ||
294 | - v->visitor.type_number = hmp_output_type_number; | ||
295 | - v->visitor.type_any = hmp_output_type_any; | ||
296 | - v->visitor.type_null = hmp_output_type_null; | ||
297 | - v->visitor.complete = hmp_output_complete; | ||
298 | - v->visitor.free = hmp_output_free; | ||
299 | - | ||
300 | - v->result = result; | ||
301 | - v->buffer = g_string_new(""); | ||
302 | - v->is_continue = false; | ||
303 | - | ||
304 | - return &v->visitor; | ||
305 | -} | ||
306 | diff --git a/qapi/meson.build b/qapi/meson.build | ||
307 | index XXXXXXX..XXXXXXX 100644 | 100 | index XXXXXXX..XXXXXXX 100644 |
308 | --- a/qapi/meson.build | 101 | --- a/include/hw/virtio/vhost-vdpa.h |
309 | +++ b/qapi/meson.build | 102 | +++ b/include/hw/virtio/vhost-vdpa.h |
310 | @@ -XXX,XX +XXX,XX @@ util_ss.add(files( | 103 | @@ -XXX,XX +XXX,XX @@ typedef struct vhost_vdpa { |
311 | 'qobject-output-visitor.c', | 104 | bool iotlb_batch_begin_sent; |
312 | 'string-input-visitor.c', | 105 | MemoryListener listener; |
313 | 'string-output-visitor.c', | 106 | struct vhost_vdpa_iova_range iova_range; |
314 | - 'hmp-output-visitor.c', | 107 | + uint64_t acked_features; |
315 | )) | 108 | bool shadow_vqs_enabled; |
316 | if have_system or have_tools | 109 | /* IOVA mapping used by the Shadow Virtqueue */ |
317 | util_ss.add(files( | 110 | VhostIOVATree *iova_tree; |
318 | -- | 111 | -- |
319 | 2.7.4 | 112 | 2.7.4 |
320 | 113 | ||
321 | 114 | diff view generated by jsdifflib |