1 | The following changes since commit 43ab9a5376c95c61ae898a222c4d04bdf60e239b: | 1 | The following changes since commit 352998df1c53b366413690d95b35f76d0721ebed: |
---|---|---|---|
2 | 2 | ||
3 | hw/i386/vmport: fix missing definitions with non-log trace backends (2017-12-21 22:52:28 +0000) | 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 0065e915192cdf83c2700bb377e5323c2649476e: | 9 | for you to fetch changes up to 12a195fa343aae2ead1301ce04727bd0ae25eb15: |
10 | 10 | ||
11 | qemu-doc: Update the deprecation information of -tftp, -bootp, -redir and -smb (2017-12-22 10:06:05 +0800) | 11 | vdpa: Expose VHOST_F_LOG_ALL on SVQ (2022-03-15 13:57:44 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | 14 | ||
15 | Changes since V2: | ||
16 | - fix 32bit build errros | ||
17 | |||
15 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
16 | Ed Swierk via Qemu-devel (2): | 19 | Eugenio Pérez (14): |
17 | e1000, e1000e: Move per-packet TX offload flags out of context state | 20 | vhost: Add VhostShadowVirtqueue |
18 | e1000: Separate TSO and non-TSO contexts, fixing UDP TX corruption | 21 | vhost: Add Shadow VirtQueue kick forwarding capabilities |
22 | vhost: Add Shadow VirtQueue call forwarding capabilities | ||
23 | vhost: Add vhost_svq_valid_features to shadow vq | ||
24 | virtio: Add vhost_svq_get_vring_addr | ||
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 | ||
19 | 34 | ||
20 | Mark Cave-Ayland (13): | 35 | Jason Wang (1): |
21 | net: move CRC32 calculation from compute_mcast_idx() into its own net_crc32() function | 36 | virtio-net: fix map leaking on error during receive |
22 | net: introduce net_crc32_le() function | ||
23 | pcnet: switch pcnet over to use net_crc32_le() | ||
24 | eepro100: switch eepro100 e100_compute_mcast_idx() over to use net_crc32() | ||
25 | sunhme: switch sunhme over to use net_crc32_le() | ||
26 | sungem: fix multicast filter CRC calculation | ||
27 | eepro100: use inline net_crc32() and bitshift instead of compute_mcast_idx() | ||
28 | opencores_eth: use inline net_crc32() and bitshift instead of compute_mcast_idx() | ||
29 | lan9118: use inline net_crc32() and bitshift instead of compute_mcast_idx() | ||
30 | ftgmac100: use inline net_crc32() and bitshift instead of compute_mcast_idx() | ||
31 | ne2000: use inline net_crc32() and bitshift instead of compute_mcast_idx() | ||
32 | rtl8139: use inline net_crc32() and bitshift instead of compute_mcast_idx() | ||
33 | net: remove unused compute_mcast_idx() function | ||
34 | 37 | ||
35 | Thomas Huth (3): | 38 | hw/net/virtio-net.c | 1 + |
36 | net: Remove the legacy "-net channel" parameter | 39 | hw/virtio/meson.build | 2 +- |
37 | qemu-doc: The "-net nic" option can be used with "netdev=...", too | 40 | hw/virtio/vhost-iova-tree.c | 110 +++++++ |
38 | qemu-doc: Update the deprecation information of -tftp, -bootp, -redir and -smb | 41 | hw/virtio/vhost-iova-tree.h | 27 ++ |
39 | 42 | hw/virtio/vhost-shadow-virtqueue.c | 636 +++++++++++++++++++++++++++++++++++++ | |
40 | hw/net/e1000.c | 92 ++++++++++++++++++++++++++++---------------------- | 43 | hw/virtio/vhost-shadow-virtqueue.h | 87 +++++ |
41 | hw/net/e1000e.c | 4 +-- | 44 | hw/virtio/vhost-vdpa.c | 522 +++++++++++++++++++++++++++++- |
42 | hw/net/e1000e_core.c | 16 ++++----- | 45 | include/hw/virtio/vhost-vdpa.h | 8 + |
43 | hw/net/e1000e_core.h | 2 ++ | 46 | include/qemu/iova-tree.h | 38 ++- |
44 | hw/net/e1000x_common.h | 2 -- | 47 | util/iova-tree.c | 170 ++++++++++ |
45 | hw/net/eepro100.c | 32 +++--------------- | 48 | 10 files changed, 1584 insertions(+), 17 deletions(-) |
46 | hw/net/ftgmac100.c | 2 +- | 49 | create mode 100644 hw/virtio/vhost-iova-tree.c |
47 | hw/net/lan9118.c | 3 +- | 50 | create mode 100644 hw/virtio/vhost-iova-tree.h |
48 | hw/net/ne2000.c | 4 ++- | 51 | create mode 100644 hw/virtio/vhost-shadow-virtqueue.c |
49 | hw/net/opencores_eth.c | 3 +- | 52 | create mode 100644 hw/virtio/vhost-shadow-virtqueue.h |
50 | hw/net/pcnet.c | 22 ++---------- | ||
51 | hw/net/rtl8139.c | 2 +- | ||
52 | hw/net/sungem.c | 5 ++- | ||
53 | hw/net/sunhme.c | 25 +------------- | ||
54 | include/net/net.h | 5 ++- | ||
55 | include/net/slirp.h | 2 -- | ||
56 | net/net.c | 40 +++++++++++++++------- | ||
57 | net/slirp.c | 34 ------------------- | ||
58 | qemu-doc.texi | 38 +++++++++++---------- | ||
59 | qemu-options.hx | 14 ++++---- | ||
60 | 20 files changed, 144 insertions(+), 203 deletions(-) | ||
61 | 53 | ||
62 | 54 | ||
55 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 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. | ||
2 | 6 | ||
3 | Looks like we missed to document that it is also possible to specify | 7 | Fixing this by detaching the cached elements on error. This addresses |
4 | a netdev with "-net nic" - which is very useful if you want to | 8 | CVE-2022-26353. |
5 | configure your on-board NIC to use a backend that has been specified | ||
6 | with "-netdev". | ||
7 | 9 | ||
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 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> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 15 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
10 | --- | 16 | --- |
11 | qemu-options.hx | 14 ++++++++------ | 17 | hw/net/virtio-net.c | 1 + |
12 | 1 file changed, 8 insertions(+), 6 deletions(-) | 18 | 1 file changed, 1 insertion(+) |
13 | 19 | ||
14 | diff --git a/qemu-options.hx b/qemu-options.hx | 20 | diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c |
15 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/qemu-options.hx | 22 | --- a/hw/net/virtio-net.c |
17 | +++ b/qemu-options.hx | 23 | +++ b/hw/net/virtio-net.c |
18 | @@ -XXX,XX +XXX,XX @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, | 24 | @@ -XXX,XX +XXX,XX @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, |
19 | "-netdev hubport,id=str,hubid=n\n" | 25 | |
20 | " configure a hub port on QEMU VLAN 'n'\n", QEMU_ARCH_ALL) | 26 | err: |
21 | DEF("net", HAS_ARG, QEMU_OPTION_net, | 27 | for (j = 0; j < i; j++) { |
22 | - "-net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n" | 28 | + virtqueue_detach_element(q->rx_vq, elems[j], lens[j]); |
23 | - " old way to create a new NIC and connect it to VLAN 'n'\n" | 29 | g_free(elems[j]); |
24 | - " (use the '-device devtype,netdev=str' option if possible instead)\n" | 30 | } |
25 | + "-net nic[,vlan=n][,netdev=nd][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n" | 31 | |
26 | + " configure or create an on-board (or machine default) NIC and\n" | ||
27 | + " connect it either to VLAN 'n' or the netdev 'nd' (for pluggable\n" | ||
28 | + " NICs please use '-device devtype,netdev=nd' instead)\n" | ||
29 | "-net dump[,vlan=n][,file=f][,len=n]\n" | ||
30 | " dump traffic on vlan 'n' to file 'f' (max n bytes per packet)\n" | ||
31 | "-net none use it alone to have zero network devices. If no -net option\n" | ||
32 | @@ -XXX,XX +XXX,XX @@ DEF("net", HAS_ARG, QEMU_OPTION_net, | ||
33 | " old way to initialize a host network interface\n" | ||
34 | " (use the -netdev option if possible instead)\n", QEMU_ARCH_ALL) | ||
35 | STEXI | ||
36 | -@item -net nic[,vlan=@var{n}][,macaddr=@var{mac}][,model=@var{type}] [,name=@var{name}][,addr=@var{addr}][,vectors=@var{v}] | ||
37 | +@item -net nic[,vlan=@var{n}][,netdev=@var{nd}][,macaddr=@var{mac}][,model=@var{type}] [,name=@var{name}][,addr=@var{addr}][,vectors=@var{v}] | ||
38 | @findex -net | ||
39 | -Create a new Network Interface Card and connect it to VLAN @var{n} (@var{n} | ||
40 | -= 0 is the default). The NIC is an e1000 by default on the PC | ||
41 | +Configure or create an on-board (or machine default) Network Interface Card | ||
42 | +(NIC) and connect it either to VLAN @var{n} (@var{n} = 0 is the default), or | ||
43 | +to the netdev @var{nd}. The NIC is an e1000 by default on the PC | ||
44 | target. Optionally, the MAC address can be changed to @var{mac}, the | ||
45 | device address set to @var{addr} (PCI cards only), | ||
46 | and a @var{name} can be assigned for use in monitor commands. | ||
47 | -- | 32 | -- |
48 | 2.7.4 | 33 | 2.7.4 |
49 | |||
50 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | This makes it much easier to compare the multicast CRC calculation endian and | 3 | Vhost shadow virtqueue (SVQ) is an intermediate jump for virtqueue |
4 | bitshift against the Linux driver implementation. | 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. | ||
5 | 8 | ||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 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> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 14 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 15 | --- |
9 | hw/net/rtl8139.c | 2 +- | 16 | hw/virtio/meson.build | 2 +- |
10 | 1 file changed, 1 insertion(+), 1 deletion(-) | 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 | ||
11 | 22 | ||
12 | diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c | 23 | diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build |
13 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/net/rtl8139.c | 25 | --- a/hw/virtio/meson.build |
15 | +++ b/hw/net/rtl8139.c | 26 | +++ b/hw/virtio/meson.build |
16 | @@ -XXX,XX +XXX,XX @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t | 27 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) |
17 | return size; | 28 | |
18 | } | 29 | virtio_ss = ss.source_set() |
19 | 30 | virtio_ss.add(files('virtio.c')) | |
20 | - int mcast_idx = compute_mcast_idx(buf); | 31 | -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c')) |
21 | + int mcast_idx = net_crc32(buf, ETH_ALEN) >> 26; | 32 | +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c')) |
22 | 33 | virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) | |
23 | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) | 34 | virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) |
24 | { | 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 | ||
25 | -- | 138 | -- |
26 | 2.7.4 | 139 | 2.7.4 |
27 | 140 | ||
28 | 141 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | It has never been documented, so hardly anybody knows about this | 3 | At this mode no buffer forwarding will be performed in SVQ mode: Qemu |
4 | parameter, and it is marked as deprecated since QEMU v2.6. | 4 | will just forward the guest's kicks to the device. |
5 | Time to let it go now. | 5 | |
6 | 6 | Host memory notifiers regions are left out for simplicity, and they will | |
7 | Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> | 7 | not be addressed in this series. |
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 8 | |
9 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
10 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 11 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
10 | --- | 12 | --- |
11 | include/net/slirp.h | 2 -- | 13 | hw/virtio/vhost-shadow-virtqueue.c | 55 ++++++++++++++ |
12 | net/net.c | 7 ------- | 14 | hw/virtio/vhost-shadow-virtqueue.h | 14 ++++ |
13 | net/slirp.c | 34 ---------------------------------- | 15 | hw/virtio/vhost-vdpa.c | 144 ++++++++++++++++++++++++++++++++++++- |
14 | qemu-doc.texi | 5 ----- | 16 | include/hw/virtio/vhost-vdpa.h | 4 ++ |
15 | 4 files changed, 48 deletions(-) | 17 | 4 files changed, 215 insertions(+), 2 deletions(-) |
16 | 18 | ||
17 | diff --git a/include/net/slirp.h b/include/net/slirp.h | 19 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c |
18 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/net/slirp.h | 21 | --- a/hw/virtio/vhost-shadow-virtqueue.c |
20 | +++ b/include/net/slirp.h | 22 | +++ b/hw/virtio/vhost-shadow-virtqueue.c |
21 | @@ -XXX,XX +XXX,XX @@ void hmp_hostfwd_remove(Monitor *mon, const QDict *qdict); | 23 | @@ -XXX,XX +XXX,XX @@ |
22 | 24 | #include "hw/virtio/vhost-shadow-virtqueue.h" | |
23 | int net_slirp_redir(const char *redir_str); | 25 | |
24 | 26 | #include "qemu/error-report.h" | |
25 | -int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret); | 27 | +#include "qemu/main-loop.h" |
26 | - | 28 | +#include "linux-headers/linux/vhost.h" |
27 | int net_slirp_smb(const char *exported_dir); | 29 | + |
28 | 30 | +/** | |
29 | void hmp_info_usernet(Monitor *mon, const QDict *qdict); | 31 | + * Forward guest notifications. |
30 | diff --git a/net/net.c b/net/net.c | 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 | ||
31 | index XXXXXXX..XXXXXXX 100644 | 100 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/net/net.c | 101 | --- a/hw/virtio/vhost-shadow-virtqueue.h |
33 | +++ b/net/net.c | 102 | +++ b/hw/virtio/vhost-shadow-virtqueue.h |
34 | @@ -XXX,XX +XXX,XX @@ int net_init_clients(void) | 103 | @@ -XXX,XX +XXX,XX @@ typedef struct VhostShadowVirtqueue { |
35 | 104 | EventNotifier hdev_kick; | |
36 | int net_client_parse(QemuOptsList *opts_list, const char *optarg) | 105 | /* Shadow call notifier, sent to vhost */ |
37 | { | 106 | EventNotifier hdev_call; |
38 | -#if defined(CONFIG_SLIRP) | 107 | + |
39 | - int ret; | 108 | + /* |
40 | - if (net_slirp_parse_legacy(opts_list, optarg, &ret)) { | 109 | + * Borrowed virtqueue's guest to host notifier. To borrow it in this event |
41 | - return ret; | 110 | + * notifier allows to recover the VhostShadowVirtqueue from the event loop |
42 | - } | 111 | + * easily. If we use the VirtQueue's one, we don't have an easy way to |
43 | -#endif | 112 | + * retrieve VhostShadowVirtqueue. |
44 | - | 113 | + * |
45 | if (!qemu_opts_parse_noisily(opts_list, optarg, true)) { | 114 | + * So shadow virtqueue must not clean it, or we would lose VirtQueue one. |
46 | return -1; | 115 | + */ |
47 | } | 116 | + EventNotifier svq_kick; |
48 | diff --git a/net/slirp.c b/net/slirp.c | 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 | ||
49 | index XXXXXXX..XXXXXXX 100644 | 127 | index XXXXXXX..XXXXXXX 100644 |
50 | --- a/net/slirp.c | 128 | --- a/hw/virtio/vhost-vdpa.c |
51 | +++ b/net/slirp.c | 129 | +++ b/hw/virtio/vhost-vdpa.c |
52 | @@ -XXX,XX +XXX,XX @@ int net_init_slirp(const Netdev *netdev, const char *name, | 130 | @@ -XXX,XX +XXX,XX @@ |
53 | 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, | ||
54 | return ret; | 244 | return ret; |
55 | } | 245 | } |
56 | - | 246 | |
57 | -int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret) | 247 | +static void vhost_vdpa_reset_svq(struct vhost_vdpa *v) |
58 | -{ | 248 | +{ |
59 | - if (strcmp(opts_list->name, "net") != 0 || | 249 | + if (!v->shadow_vqs_enabled) { |
60 | - strncmp(optarg, "channel,", strlen("channel,")) != 0) { | 250 | + return; |
61 | - return 0; | 251 | + } |
62 | - } | 252 | + |
63 | - | 253 | + for (unsigned i = 0; i < v->shadow_vqs->len; ++i) { |
64 | - error_report("The '-net channel' option is deprecated. " | 254 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); |
65 | - "Please use '-netdev user,guestfwd=...' instead."); | 255 | + vhost_svq_stop(svq); |
66 | - | 256 | + } |
67 | - /* handle legacy -net channel,port:chr */ | 257 | +} |
68 | - optarg += strlen("channel,"); | 258 | + |
69 | - | 259 | static int vhost_vdpa_reset_device(struct vhost_dev *dev) |
70 | - if (QTAILQ_EMPTY(&slirp_stacks)) { | 260 | { |
71 | - struct slirp_config_str *config; | 261 | + struct vhost_vdpa *v = dev->opaque; |
72 | - | 262 | int ret; |
73 | - config = g_malloc(sizeof(*config)); | 263 | uint8_t status = 0; |
74 | - pstrcpy(config->str, sizeof(config->str), optarg); | 264 | |
75 | - config->flags = SLIRP_CFG_LEGACY; | 265 | + vhost_vdpa_reset_svq(v); |
76 | - config->next = slirp_configs; | 266 | + |
77 | - slirp_configs = config; | 267 | ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); |
78 | - *ret = 0; | 268 | trace_vhost_vdpa_reset_device(dev, status); |
79 | - } else { | 269 | return ret; |
80 | - Error *err = NULL; | 270 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, |
81 | - *ret = slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), optarg, 1, &err); | 271 | return ret; |
82 | - if (*ret < 0) { | 272 | } |
83 | - error_report_err(err); | 273 | |
84 | - } | 274 | +static int vhost_vdpa_set_vring_dev_kick(struct vhost_dev *dev, |
85 | - } | 275 | + struct vhost_vring_file *file) |
86 | - | 276 | +{ |
87 | - return 1; | 277 | + trace_vhost_vdpa_set_vring_kick(dev, file->index, file->fd); |
88 | -} | 278 | + return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); |
89 | - | 279 | +} |
90 | diff --git a/qemu-doc.texi b/qemu-doc.texi | 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 | ||
91 | index XXXXXXX..XXXXXXX 100644 | 365 | index XXXXXXX..XXXXXXX 100644 |
92 | --- a/qemu-doc.texi | 366 | --- a/include/hw/virtio/vhost-vdpa.h |
93 | +++ b/qemu-doc.texi | 367 | +++ b/include/hw/virtio/vhost-vdpa.h |
94 | @@ -XXX,XX +XXX,XX @@ The ``-smb /some/dir'' argument is now a synonym for setting | 368 | @@ -XXX,XX +XXX,XX @@ |
95 | the ``-netdev user,smb=/some/dir'' argument instead. The new | 369 | #ifndef HW_VIRTIO_VHOST_VDPA_H |
96 | syntax allows different settings to be provided per NIC. | 370 | #define HW_VIRTIO_VHOST_VDPA_H |
97 | 371 | ||
98 | -@subsection -net channel (since 2.6.0) | 372 | +#include <gmodule.h> |
99 | - | 373 | + |
100 | -The ``--net channel,ARGS'' argument is now a synonym for setting | 374 | #include "hw/virtio/virtio.h" |
101 | -the ``-netdev user,guestfwd=ARGS'' argument instead. | 375 | #include "standard-headers/linux/vhost_types.h" |
102 | - | 376 | |
103 | @subsection -net vlan (since 2.9.0) | 377 | @@ -XXX,XX +XXX,XX @@ typedef struct vhost_vdpa { |
104 | 378 | bool iotlb_batch_begin_sent; | |
105 | The ``-net vlan=NN'' argument is partially replaced with the | 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; | ||
106 | -- | 386 | -- |
107 | 2.7.4 | 387 | 2.7.4 |
108 | 388 | ||
109 | 389 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Now that all of the callers have been converted to compute the multicast index | 3 | This will make qemu aware of the device used buffers, allowing it to |
4 | inline using new net CRC functions, this function can now be dropped. | 4 | write the guest memory with its contents if needed. |
5 | 5 | ||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 6 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> |
7 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 8 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 9 | --- |
9 | net/net.c | 5 ----- | 10 | hw/virtio/vhost-shadow-virtqueue.c | 38 ++++++++++++++++++++++++++++++++++++++ |
10 | 1 file changed, 5 deletions(-) | 11 | hw/virtio/vhost-shadow-virtqueue.h | 4 ++++ |
12 | hw/virtio/vhost-vdpa.c | 31 +++++++++++++++++++++++++++++-- | ||
13 | 3 files changed, 71 insertions(+), 2 deletions(-) | ||
11 | 14 | ||
12 | diff --git a/net/net.c b/net/net.c | 15 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c |
13 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/net/net.c | 17 | --- a/hw/virtio/vhost-shadow-virtqueue.c |
15 | +++ b/net/net.c | 18 | +++ b/hw/virtio/vhost-shadow-virtqueue.c |
16 | @@ -XXX,XX +XXX,XX @@ uint32_t net_crc32_le(const uint8_t *p, int len) | 19 | @@ -XXX,XX +XXX,XX @@ static void vhost_handle_guest_kick(EventNotifier *n) |
17 | return crc; | ||
18 | } | 20 | } |
19 | 21 | ||
20 | -unsigned compute_mcast_idx(const uint8_t *ep) | 22 | /** |
21 | -{ | 23 | + * Forward vhost notifications |
22 | - return net_crc32(ep, ETH_ALEN) >> 26; | 24 | + * |
23 | -} | 25 | + * @n: hdev call event notifier, the one that device set to notify svq. |
24 | - | 26 | + */ |
25 | QemuOptsList qemu_netdev_opts = { | 27 | +static void vhost_svq_handle_call(EventNotifier *n) |
26 | .name = "netdev", | 28 | +{ |
27 | .implied_opt_name = "type", | 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 | +} | ||
34 | + | ||
35 | +/** | ||
36 | + * Set the call notifier for the SVQ to call the guest | ||
37 | + * | ||
38 | + * @svq: Shadow virtqueue | ||
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 | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/hw/virtio/vhost-shadow-virtqueue.h | ||
81 | +++ b/hw/virtio/vhost-shadow-virtqueue.h | ||
82 | @@ -XXX,XX +XXX,XX @@ typedef struct VhostShadowVirtqueue { | ||
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"); | ||
136 | } | ||
137 | |||
138 | return r == 0; | ||
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; | ||
146 | + | ||
147 | + if (v->shadow_vqs_enabled) { | ||
148 | + int vdpa_idx = file->index - dev->vq_index; | ||
149 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, vdpa_idx); | ||
150 | + | ||
151 | + vhost_svq_set_svq_call_fd(svq, file->fd); | ||
152 | + return 0; | ||
153 | + } else { | ||
154 | + return vhost_vdpa_set_vring_dev_call(dev, file); | ||
155 | + } | ||
156 | } | ||
157 | |||
158 | static int vhost_vdpa_get_features(struct vhost_dev *dev, | ||
28 | -- | 159 | -- |
29 | 2.7.4 | 160 | 2.7.4 |
30 | 161 | ||
31 | 162 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | This provides a standard ethernet CRC32 little-endian implementation. | 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. | ||
4 | 8 | ||
5 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 9 | Future changes can add support to offer more features to the guest, |
6 | Reviewed-by: Eric Blake <eblake@redhat.com> | 10 | since the use of VirtQueue gives this for free. This is left out at the |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 11 | moment for simplicity. |
12 | |||
13 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | ||
14 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
8 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 15 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
9 | --- | 16 | --- |
10 | include/net/net.h | 2 ++ | 17 | hw/virtio/vhost-shadow-virtqueue.c | 44 ++++++++++++++++++++++++++++++++++++++ |
11 | net/net.c | 22 ++++++++++++++++++++++ | 18 | hw/virtio/vhost-shadow-virtqueue.h | 2 ++ |
12 | 2 files changed, 24 insertions(+) | 19 | hw/virtio/vhost-vdpa.c | 15 +++++++++++++ |
20 | 3 files changed, 61 insertions(+) | ||
13 | 21 | ||
14 | diff --git a/include/net/net.h b/include/net/net.h | 22 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c |
15 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/include/net/net.h | 24 | --- a/hw/virtio/vhost-shadow-virtqueue.c |
17 | +++ b/include/net/net.h | 25 | +++ b/hw/virtio/vhost-shadow-virtqueue.c |
18 | @@ -XXX,XX +XXX,XX @@ NetClientState *net_hub_port_find(int hub_id); | 26 | @@ -XXX,XX +XXX,XX @@ |
19 | void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); | 27 | #include "hw/virtio/vhost-shadow-virtqueue.h" |
20 | 28 | ||
21 | #define POLYNOMIAL_BE 0x04c11db6 | 29 | #include "qemu/error-report.h" |
22 | +#define POLYNOMIAL_LE 0xedb88320 | 30 | +#include "qapi/error.h" |
23 | uint32_t net_crc32(const uint8_t *p, int len); | 31 | #include "qemu/main-loop.h" |
24 | +uint32_t net_crc32_le(const uint8_t *p, int len); | 32 | #include "linux-headers/linux/vhost.h" |
25 | unsigned compute_mcast_idx(const uint8_t *ep); | 33 | |
26 | 34 | /** | |
27 | #define vmstate_offset_macaddr(_state, _field) \ | 35 | + * Validate the transport device features that both guests can use with the SVQ |
28 | diff --git a/net/net.c b/net/net.c | 36 | + * and SVQs can use with the device. |
29 | index XXXXXXX..XXXXXXX 100644 | 37 | + * |
30 | --- a/net/net.c | 38 | + * @dev_features: The features |
31 | +++ b/net/net.c | 39 | + * @errp: Error pointer |
32 | @@ -XXX,XX +XXX,XX @@ uint32_t net_crc32(const uint8_t *p, int len) | 40 | + */ |
33 | return crc; | 41 | +bool vhost_svq_valid_features(uint64_t features, Error **errp) |
34 | } | ||
35 | |||
36 | +uint32_t net_crc32_le(const uint8_t *p, int len) | ||
37 | +{ | 42 | +{ |
38 | + uint32_t crc; | 43 | + bool ok = true; |
39 | + int carry, i, j; | 44 | + uint64_t svq_features = features; |
40 | + uint8_t b; | ||
41 | + | 45 | + |
42 | + crc = 0xffffffff; | 46 | + for (uint64_t b = VIRTIO_TRANSPORT_F_START; b <= VIRTIO_TRANSPORT_F_END; |
43 | + for (i = 0; i < len; i++) { | 47 | + ++b) { |
44 | + b = *p++; | 48 | + switch (b) { |
45 | + for (j = 0; j < 8; j++) { | 49 | + case VIRTIO_F_ANY_LAYOUT: |
46 | + carry = (crc & 0x1) ^ (b & 0x01); | 50 | + continue; |
47 | + crc >>= 1; | 51 | + |
48 | + b >>= 1; | 52 | + case VIRTIO_F_ACCESS_PLATFORM: |
49 | + if (carry) { | 53 | + /* SVQ trust in the host's IOMMU to translate addresses */ |
50 | + crc ^= POLYNOMIAL_LE; | 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; | ||
51 | + } | 66 | + } |
52 | + } | 67 | + } |
53 | + } | 68 | + } |
54 | + | 69 | + |
55 | + return crc; | 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; | ||
56 | +} | 75 | +} |
57 | + | 76 | + |
58 | unsigned compute_mcast_idx(const uint8_t *ep) | 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) | ||
59 | { | 100 | { |
60 | return net_crc32(ep, ETH_ALEN) >> 26; | 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(); | ||
61 | -- | 125 | -- |
62 | 2.7.4 | 126 | 2.7.4 |
63 | 127 | ||
64 | 128 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The information how to update the deprecated parameters was too scarce, | 3 | It reports the shadow virtqueue address from qemu virtual address space. |
4 | so that some people did not update to the new syntax yet. Provide some | ||
5 | more information to make sure that it is clear how to update from the | ||
6 | old syntax to the new one. | ||
7 | 4 | ||
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 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> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 11 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
10 | --- | 12 | --- |
11 | qemu-doc.texi | 33 +++++++++++++++++++++------------ | 13 | hw/virtio/vhost-shadow-virtqueue.c | 29 +++++++++++++++++++++++++++++ |
12 | 1 file changed, 21 insertions(+), 12 deletions(-) | 14 | hw/virtio/vhost-shadow-virtqueue.h | 9 +++++++++ |
15 | 2 files changed, 38 insertions(+) | ||
13 | 16 | ||
14 | diff --git a/qemu-doc.texi b/qemu-doc.texi | 17 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c |
15 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/qemu-doc.texi | 19 | --- a/hw/virtio/vhost-shadow-virtqueue.c |
17 | +++ b/qemu-doc.texi | 20 | +++ b/hw/virtio/vhost-shadow-virtqueue.c |
18 | @@ -XXX,XX +XXX,XX @@ combined with ``-vnc tls-creds=tls0' | 21 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd) |
19 | 22 | } | |
20 | @subsection -tftp (since 2.6.0) | 23 | |
21 | 24 | /** | |
22 | -The ``-tftp /some/dir'' argument is now a synonym for setting | 25 | + * Get the shadow vq vring address. |
23 | -the ``-netdev user,tftp=/some/dir' argument. The new syntax | 26 | + * @svq: Shadow virtqueue |
24 | -allows different settings to be provided per NIC. | 27 | + * @addr: Destination to store address |
25 | +The ``-tftp /some/dir'' argument is replaced by | 28 | + */ |
26 | +``-netdev user,id=x,tftp=/some/dir'', either accompanied with | 29 | +void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, |
27 | +``-device ...,netdev=x'' (for pluggable NICs) or ``-net nic,netdev=x'' | 30 | + struct vhost_vring_addr *addr) |
28 | +(for embedded NICs). The new syntax allows different settings to be | 31 | +{ |
29 | +provided per NIC. | 32 | + addr->desc_user_addr = (uint64_t)(intptr_t)svq->vring.desc; |
30 | 33 | + addr->avail_user_addr = (uint64_t)(intptr_t)svq->vring.avail; | |
31 | @subsection -bootp (since 2.6.0) | 34 | + addr->used_user_addr = (uint64_t)(intptr_t)svq->vring.used; |
32 | 35 | +} | |
33 | -The ``-bootp /some/file'' argument is now a synonym for setting | 36 | + |
34 | -the ``-netdev user,bootp=/some/file' argument. The new syntax | 37 | +size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq) |
35 | -allows different settings to be provided per NIC. | 38 | +{ |
36 | +The ``-bootp /some/file'' argument is replaced by | 39 | + size_t desc_size = sizeof(vring_desc_t) * svq->vring.num; |
37 | +``-netdev user,id=x,bootp=/some/file'', either accompanied with | 40 | + size_t avail_size = offsetof(vring_avail_t, ring) + |
38 | +``-device ...,netdev=x'' (for pluggable NICs) or ``-net nic,netdev=x'' | 41 | + sizeof(uint16_t) * svq->vring.num; |
39 | +(for embedded NICs). The new syntax allows different settings to be | 42 | + |
40 | +provided per NIC. | 43 | + return ROUND_UP(desc_size + avail_size, qemu_real_host_page_size); |
41 | 44 | +} | |
42 | @subsection -redir (since 2.6.0) | 45 | + |
43 | 46 | +size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq) | |
44 | -The ``-redir ARGS'' argument is now a synonym for setting | 47 | +{ |
45 | -the ``-netdev user,hostfwd=ARGS'' argument instead. The new | 48 | + size_t used_size = offsetof(vring_used_t, ring) + |
46 | -syntax allows different settings to be provided per NIC. | 49 | + sizeof(vring_used_elem_t) * svq->vring.num; |
47 | +The ``-redir [tcp|udp]:hostport:[guestaddr]:guestport'' argument is | 50 | + return ROUND_UP(used_size, qemu_real_host_page_size); |
48 | +replaced by ``-netdev | 51 | +} |
49 | +user,id=x,hostfwd=[tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport'', | 52 | + |
50 | +either accompanied with ``-device ...,netdev=x'' (for pluggable NICs) or | 53 | +/** |
51 | +``-net nic,netdev=x'' (for embedded NICs). The new syntax allows different | 54 | * Set a new file descriptor for the guest to kick the SVQ and notify for avail |
52 | +settings to be provided per NIC. | 55 | * |
53 | 56 | * @svq: The svq | |
54 | @subsection -smb (since 2.6.0) | 57 | diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h |
55 | 58 | index XXXXXXX..XXXXXXX 100644 | |
56 | -The ``-smb /some/dir'' argument is now a synonym for setting | 59 | --- a/hw/virtio/vhost-shadow-virtqueue.h |
57 | -the ``-netdev user,smb=/some/dir'' argument instead. The new | 60 | +++ b/hw/virtio/vhost-shadow-virtqueue.h |
58 | -syntax allows different settings to be provided per NIC. | 61 | @@ -XXX,XX +XXX,XX @@ |
59 | +The ``-smb /some/dir'' argument is replaced by | 62 | #define VHOST_SHADOW_VIRTQUEUE_H |
60 | +``-netdev user,id=x,smb=/some/dir'', either accompanied with | 63 | |
61 | +``-device ...,netdev=x'' (for pluggable NICs) or ``-net nic,netdev=x'' | 64 | #include "qemu/event_notifier.h" |
62 | +(for embedded NICs). The new syntax allows different settings to be | 65 | +#include "hw/virtio/virtio.h" |
63 | +provided per NIC. | 66 | +#include "standard-headers/linux/vhost_types.h" |
64 | 67 | ||
65 | @subsection -net vlan (since 2.9.0) | 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); | ||
66 | 86 | ||
67 | -- | 87 | -- |
68 | 2.7.4 | 88 | 2.7.4 |
69 | 89 | ||
70 | 90 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | This makes it much easier to compare the multicast CRC calculation endian and | 3 | First half of the buffers forwarding part, preparing vhost-vdpa |
4 | bitshift against the Linux driver implementation. | 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. | ||
5 | 7 | ||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 8 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> |
9 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 10 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 11 | --- |
9 | hw/net/ne2000.c | 4 +++- | 12 | hw/virtio/vhost-vdpa.c | 48 +++++++++++++++++++++++++++++++++++++++++------- |
10 | 1 file changed, 3 insertions(+), 1 deletion(-) | 13 | 1 file changed, 41 insertions(+), 7 deletions(-) |
11 | 14 | ||
12 | diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c | 15 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c |
13 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/net/ne2000.c | 17 | --- a/hw/virtio/vhost-vdpa.c |
15 | +++ b/hw/net/ne2000.c | 18 | +++ b/hw/virtio/vhost-vdpa.c |
16 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, |
17 | */ | 20 | return ret; |
18 | #include "qemu/osdep.h" | 21 | } |
19 | #include "hw/pci/pci.h" | 22 | |
20 | +#include "net/net.h" | 23 | +static int vhost_vdpa_set_dev_vring_base(struct vhost_dev *dev, |
21 | +#include "net/eth.h" | 24 | + struct vhost_vring_state *ring) |
22 | #include "ne2000.h" | 25 | +{ |
23 | #include "hw/loader.h" | 26 | + trace_vhost_vdpa_set_vring_base(dev, ring->index, ring->num); |
24 | #include "sysemu/sysemu.h" | 27 | + return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); |
25 | @@ -XXX,XX +XXX,XX @@ ssize_t ne2000_receive(NetClientState *nc, const uint8_t *buf, size_t size_) | 28 | +} |
26 | /* multicast */ | 29 | + |
27 | if (!(s->rxcr & 0x08)) | 30 | static int vhost_vdpa_set_vring_dev_kick(struct vhost_dev *dev, |
28 | return size; | 31 | struct vhost_vring_file *file) |
29 | - mcast_idx = compute_mcast_idx(buf); | 32 | { |
30 | + mcast_idx = net_crc32(buf, ETH_ALEN) >> 26; | 33 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_dev_call(struct vhost_dev *dev, |
31 | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) | 34 | return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); |
32 | return size; | 35 | } |
33 | } else if (s->mem[0] == buf[0] && | 36 | |
37 | +static int vhost_vdpa_set_vring_dev_addr(struct vhost_dev *dev, | ||
38 | + struct vhost_vring_addr *addr) | ||
39 | +{ | ||
40 | + trace_vhost_vdpa_set_vring_addr(dev, addr->index, addr->flags, | ||
41 | + addr->desc_user_addr, addr->used_user_addr, | ||
42 | + addr->avail_user_addr, | ||
43 | + addr->log_guest_addr); | ||
44 | + | ||
45 | + return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); | ||
46 | + | ||
47 | +} | ||
48 | + | ||
49 | /** | ||
50 | * Set the shadow virtqueue descriptors to the device | ||
51 | * | ||
52 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, | ||
53 | static int vhost_vdpa_set_vring_addr(struct vhost_dev *dev, | ||
54 | struct vhost_vring_addr *addr) | ||
55 | { | ||
56 | - trace_vhost_vdpa_set_vring_addr(dev, addr->index, addr->flags, | ||
57 | - addr->desc_user_addr, addr->used_user_addr, | ||
58 | - addr->avail_user_addr, | ||
59 | - addr->log_guest_addr); | ||
60 | - return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); | ||
61 | + struct vhost_vdpa *v = dev->opaque; | ||
62 | + | ||
63 | + if (v->shadow_vqs_enabled) { | ||
64 | + /* | ||
65 | + * Device vring addr was set at device start. SVQ base is handled by | ||
66 | + * VirtQueue code. | ||
67 | + */ | ||
68 | + return 0; | ||
69 | + } | ||
70 | + | ||
71 | + return vhost_vdpa_set_vring_dev_addr(dev, addr); | ||
72 | } | ||
73 | |||
74 | static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, | ||
75 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, | ||
76 | static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, | ||
77 | struct vhost_vring_state *ring) | ||
78 | { | ||
79 | - trace_vhost_vdpa_set_vring_base(dev, ring->index, ring->num); | ||
80 | - return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); | ||
81 | + struct vhost_vdpa *v = dev->opaque; | ||
82 | + | ||
83 | + if (v->shadow_vqs_enabled) { | ||
84 | + /* | ||
85 | + * Device vring base was set at device start. SVQ base is handled by | ||
86 | + * VirtQueue code. | ||
87 | + */ | ||
88 | + return 0; | ||
89 | + } | ||
90 | + | ||
91 | + return vhost_vdpa_set_dev_vring_base(dev, ring); | ||
92 | } | ||
93 | |||
94 | static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, | ||
34 | -- | 95 | -- |
35 | 2.7.4 | 96 | 2.7.4 |
36 | 97 | ||
37 | 98 | diff view generated by jsdifflib |
1 | From: Ed Swierk via Qemu-devel <qemu-devel@nongnu.org> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | sum_needed and cptse flags are received from the guest within each | 3 | Initial version of shadow virtqueue that actually forward buffers. There |
4 | transmit data descriptor. They are not part of the offload context; | 4 | is no iommu support at the moment, and that will be addressed in future |
5 | instead, they determine how to apply a previously received context to | 5 | patches of this series. Since all vhost-vdpa devices use forced IOMMU, |
6 | the packet being transmitted: | 6 | this means that SVQ is not usable at this point of the series on any |
7 | 7 | device. | |
8 | - If cptse is set, perform both segmentation and checksum offload | 8 | |
9 | using the parameters in the TSO context; otherwise just do checksum | 9 | For simplicity it only supports modern devices, that expects vring |
10 | offload. (Currently the e1000 device incorrectly stores only one | 10 | in little endian, with split ring and no event idx or indirect |
11 | context, which will be fixed in a subsequent patch.) | 11 | descriptors. Support for them will not be added in this series. |
12 | 12 | ||
13 | - Depending on the bits set in sum_needed, possibly perform L4 | 13 | It reuses the VirtQueue code for the device part. The driver part is |
14 | checksum offload and/or IP checksum offload, using the parameters in | 14 | based on Linux's virtio_ring driver, but with stripped functionality |
15 | the appropriate context. | 15 | and optimizations so it's easier to review. |
16 | 16 | ||
17 | Move these flags out of struct e1000x_txd_props, which is otherwise | 17 | However, forwarding buffers have some particular pieces: One of the most |
18 | dedicated to storing values from a context descriptor, and into the | 18 | unexpected ones is that a guest's buffer can expand through more than |
19 | per-packet TX struct. | 19 | one descriptor in SVQ. While this is handled gracefully by qemu's |
20 | 20 | emulated virtio devices, it may cause unexpected SVQ queue full. This | |
21 | Signed-off-by: Ed Swierk <eswierk@skyportsystems.com> | 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> | ||
22 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 27 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
23 | --- | 28 | --- |
24 | hw/net/e1000.c | 30 ++++++++++++++++-------------- | 29 | hw/virtio/vhost-shadow-virtqueue.c | 352 ++++++++++++++++++++++++++++++++++++- |
25 | hw/net/e1000e.c | 4 ++-- | 30 | hw/virtio/vhost-shadow-virtqueue.h | 26 +++ |
26 | hw/net/e1000e_core.c | 16 ++++++++-------- | 31 | hw/virtio/vhost-vdpa.c | 155 +++++++++++++++- |
27 | hw/net/e1000e_core.h | 2 ++ | 32 | 3 files changed, 522 insertions(+), 11 deletions(-) |
28 | hw/net/e1000x_common.h | 2 -- | 33 | |
29 | 5 files changed, 28 insertions(+), 26 deletions(-) | 34 | diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c |
30 | |||
31 | diff --git a/hw/net/e1000.c b/hw/net/e1000.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/hw/net/e1000.c | 36 | --- a/hw/virtio/vhost-shadow-virtqueue.c |
34 | +++ b/hw/net/e1000.c | 37 | +++ b/hw/virtio/vhost-shadow-virtqueue.c |
35 | @@ -XXX,XX +XXX,XX @@ typedef struct E1000State_st { | 38 | @@ -XXX,XX +XXX,XX @@ |
36 | unsigned char data[0x10000]; | 39 | #include "qemu/error-report.h" |
37 | uint16_t size; | 40 | #include "qapi/error.h" |
38 | unsigned char vlan_needed; | 41 | #include "qemu/main-loop.h" |
39 | + unsigned char sum_needed; | 42 | +#include "qemu/log.h" |
40 | + bool cptse; | 43 | +#include "qemu/memalign.h" |
41 | e1000x_txd_props props; | 44 | #include "linux-headers/linux/vhost.h" |
42 | uint16_t tso_frames; | 45 | |
43 | } tx; | 46 | /** |
44 | @@ -XXX,XX +XXX,XX @@ xmit_seg(E1000State *s) | 47 | @@ -XXX,XX +XXX,XX @@ bool vhost_svq_valid_features(uint64_t features, Error **errp) |
45 | unsigned int frames = s->tx.tso_frames, css, sofar; | ||
46 | struct e1000_tx *tp = &s->tx; | ||
47 | |||
48 | - if (tp->props.tse && tp->props.cptse) { | ||
49 | + if (tp->props.tse && tp->cptse) { | ||
50 | css = tp->props.ipcss; | ||
51 | DBGOUT(TXSUM, "frames %d size %d ipcss %d\n", | ||
52 | frames, tp->size, css); | ||
53 | @@ -XXX,XX +XXX,XX @@ xmit_seg(E1000State *s) | ||
54 | } | ||
55 | } else /* UDP */ | ||
56 | stw_be_p(tp->data+css+4, len); | ||
57 | - if (tp->props.sum_needed & E1000_TXD_POPTS_TXSM) { | ||
58 | + if (tp->sum_needed & E1000_TXD_POPTS_TXSM) { | ||
59 | unsigned int phsum; | ||
60 | // add pseudo-header length before checksum calculation | ||
61 | void *sp = tp->data + tp->props.tucso; | ||
62 | @@ -XXX,XX +XXX,XX @@ xmit_seg(E1000State *s) | ||
63 | tp->tso_frames++; | ||
64 | } | ||
65 | |||
66 | - if (tp->props.sum_needed & E1000_TXD_POPTS_TXSM) { | ||
67 | + if (tp->sum_needed & E1000_TXD_POPTS_TXSM) { | ||
68 | putsum(tp->data, tp->size, tp->props.tucso, | ||
69 | tp->props.tucss, tp->props.tucse); | ||
70 | } | ||
71 | - if (tp->props.sum_needed & E1000_TXD_POPTS_IXSM) { | ||
72 | + if (tp->sum_needed & E1000_TXD_POPTS_IXSM) { | ||
73 | putsum(tp->data, tp->size, tp->props.ipcso, | ||
74 | tp->props.ipcss, tp->props.ipcse); | ||
75 | } | ||
76 | @@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) | ||
77 | } else if (dtype == (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D)) { | ||
78 | // data descriptor | ||
79 | if (tp->size == 0) { | ||
80 | - tp->props.sum_needed = le32_to_cpu(dp->upper.data) >> 8; | ||
81 | + tp->sum_needed = le32_to_cpu(dp->upper.data) >> 8; | ||
82 | } | ||
83 | - tp->props.cptse = (txd_lower & E1000_TXD_CMD_TSE) ? 1 : 0; | ||
84 | + tp->cptse = (txd_lower & E1000_TXD_CMD_TSE) ? 1 : 0; | ||
85 | } else { | ||
86 | // legacy descriptor | ||
87 | - tp->props.cptse = 0; | ||
88 | + tp->cptse = 0; | ||
89 | } | ||
90 | |||
91 | if (e1000x_vlan_enabled(s->mac_reg) && | ||
92 | e1000x_is_vlan_txd(txd_lower) && | ||
93 | - (tp->props.cptse || txd_lower & E1000_TXD_CMD_EOP)) { | ||
94 | + (tp->cptse || txd_lower & E1000_TXD_CMD_EOP)) { | ||
95 | tp->vlan_needed = 1; | ||
96 | stw_be_p(tp->vlan_header, | ||
97 | le16_to_cpu(s->mac_reg[VET])); | ||
98 | @@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) | ||
99 | } | ||
100 | |||
101 | addr = le64_to_cpu(dp->buffer_addr); | ||
102 | - if (tp->props.tse && tp->props.cptse) { | ||
103 | + if (tp->props.tse && tp->cptse) { | ||
104 | msh = tp->props.hdr_len + tp->props.mss; | ||
105 | do { | ||
106 | bytes = split_size; | ||
107 | @@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) | ||
108 | } | ||
109 | split_size -= bytes; | ||
110 | } while (bytes && split_size); | ||
111 | - } else if (!tp->props.tse && tp->props.cptse) { | ||
112 | + } else if (!tp->props.tse && tp->cptse) { | ||
113 | // context descriptor TSE is not set, while data descriptor TSE is set | ||
114 | DBGOUT(TXERR, "TCP segmentation error\n"); | ||
115 | } else { | ||
116 | @@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) | ||
117 | |||
118 | if (!(txd_lower & E1000_TXD_CMD_EOP)) | ||
119 | return; | ||
120 | - if (!(tp->props.tse && tp->props.cptse && tp->size < tp->props.hdr_len)) { | ||
121 | + if (!(tp->props.tse && tp->cptse && tp->size < tp->props.hdr_len)) { | ||
122 | xmit_seg(s); | ||
123 | } | ||
124 | tp->tso_frames = 0; | ||
125 | - tp->props.sum_needed = 0; | ||
126 | + tp->sum_needed = 0; | ||
127 | tp->vlan_needed = 0; | ||
128 | tp->size = 0; | ||
129 | - tp->props.cptse = 0; | ||
130 | + tp->cptse = 0; | ||
131 | } | 48 | } |
132 | 49 | ||
133 | static uint32_t | 50 | /** |
134 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_e1000 = { | 51 | - * Forward guest notifications. |
135 | VMSTATE_UINT16(tx.props.mss, E1000State), | 52 | + * Number of descriptors that the SVQ can make available from the guest. |
136 | VMSTATE_UINT16(tx.size, E1000State), | 53 | + * |
137 | VMSTATE_UINT16(tx.tso_frames, E1000State), | 54 | + * @svq: The svq |
138 | - VMSTATE_UINT8(tx.props.sum_needed, E1000State), | 55 | + */ |
139 | + VMSTATE_UINT8(tx.sum_needed, E1000State), | 56 | +static uint16_t vhost_svq_available_slots(const VhostShadowVirtqueue *svq) |
140 | VMSTATE_INT8(tx.props.ip, E1000State), | 57 | +{ |
141 | VMSTATE_INT8(tx.props.tcp, E1000State), | 58 | + return svq->vring.num - (svq->shadow_avail_idx - svq->shadow_used_idx); |
142 | VMSTATE_BUFFER(tx.header, E1000State), | 59 | +} |
143 | diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c | 60 | + |
144 | index XXXXXXX..XXXXXXX 100644 | 61 | +static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, |
145 | --- a/hw/net/e1000e.c | 62 | + const struct iovec *iovec, size_t num, |
146 | +++ b/hw/net/e1000e.c | 63 | + bool more_descs, bool write) |
147 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription e1000e_vmstate_tx = { | 64 | +{ |
148 | .version_id = 1, | 65 | + uint16_t i = svq->free_head, last = svq->free_head; |
149 | .minimum_version_id = 1, | 66 | + unsigned n; |
150 | .fields = (VMStateField[]) { | 67 | + uint16_t flags = write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; |
151 | - VMSTATE_UINT8(props.sum_needed, struct e1000e_tx), | 68 | + vring_desc_t *descs = svq->vring.desc; |
152 | + VMSTATE_UINT8(sum_needed, struct e1000e_tx), | 69 | + |
153 | VMSTATE_UINT8(props.ipcss, struct e1000e_tx), | 70 | + if (num == 0) { |
154 | VMSTATE_UINT8(props.ipcso, struct e1000e_tx), | 71 | + return; |
155 | VMSTATE_UINT16(props.ipcse, struct e1000e_tx), | 72 | + } |
156 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription e1000e_vmstate_tx = { | 73 | + |
157 | VMSTATE_INT8(props.ip, struct e1000e_tx), | 74 | + for (n = 0; n < num; n++) { |
158 | VMSTATE_INT8(props.tcp, struct e1000e_tx), | 75 | + if (more_descs || (n + 1 < num)) { |
159 | VMSTATE_BOOL(props.tse, struct e1000e_tx), | 76 | + descs[i].flags = flags | cpu_to_le16(VRING_DESC_F_NEXT); |
160 | - VMSTATE_BOOL(props.cptse, struct e1000e_tx), | 77 | + } else { |
161 | + VMSTATE_BOOL(cptse, struct e1000e_tx), | 78 | + descs[i].flags = flags; |
162 | VMSTATE_BOOL(skip_cp, struct e1000e_tx), | 79 | + } |
163 | VMSTATE_END_OF_LIST() | 80 | + descs[i].addr = cpu_to_le64((hwaddr)(intptr_t)iovec[n].iov_base); |
164 | } | 81 | + descs[i].len = cpu_to_le32(iovec[n].iov_len); |
165 | diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c | 82 | + |
166 | index XXXXXXX..XXXXXXX 100644 | 83 | + last = i; |
167 | --- a/hw/net/e1000e_core.c | 84 | + i = cpu_to_le16(descs[i].next); |
168 | +++ b/hw/net/e1000e_core.c | 85 | + } |
169 | @@ -XXX,XX +XXX,XX @@ e1000e_rss_parse_packet(E1000ECore *core, | 86 | + |
170 | static void | 87 | + svq->free_head = le16_to_cpu(descs[last].next); |
171 | e1000e_setup_tx_offloads(E1000ECore *core, struct e1000e_tx *tx) | 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) | ||
172 | { | 221 | { |
173 | - if (tx->props.tse && tx->props.cptse) { | 222 | VhostShadowVirtqueue *svq = container_of(n, VhostShadowVirtqueue, svq_kick); |
174 | + if (tx->props.tse && tx->cptse) { | 223 | event_notifier_test_and_clear(n); |
175 | net_tx_pkt_build_vheader(tx->tx_pkt, true, true, tx->props.mss); | 224 | - event_notifier_set(&svq->hdev_kick); |
176 | net_tx_pkt_update_ip_checksums(tx->tx_pkt); | 225 | + vhost_handle_guest_kick(svq); |
177 | e1000x_inc_reg_if_not_full(core->mac, TSCTC); | 226 | +} |
178 | return; | 227 | + |
179 | } | 228 | +static bool vhost_svq_more_used(VhostShadowVirtqueue *svq) |
180 | 229 | +{ | |
181 | - if (tx->props.sum_needed & E1000_TXD_POPTS_TXSM) { | 230 | + if (svq->last_used_idx != svq->shadow_used_idx) { |
182 | + if (tx->sum_needed & E1000_TXD_POPTS_TXSM) { | 231 | + return true; |
183 | net_tx_pkt_build_vheader(tx->tx_pkt, false, true, 0); | 232 | + } |
184 | } | 233 | + |
185 | 234 | + svq->shadow_used_idx = cpu_to_le16(svq->vring.used->idx); | |
186 | - if (tx->props.sum_needed & E1000_TXD_POPTS_IXSM) { | 235 | + |
187 | + if (tx->sum_needed & E1000_TXD_POPTS_IXSM) { | 236 | + return svq->last_used_idx != svq->shadow_used_idx; |
188 | net_tx_pkt_update_ip_hdr_checksum(tx->tx_pkt); | 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); | ||
189 | } | 400 | } |
190 | } | 401 | } |
191 | @@ -XXX,XX +XXX,XX @@ e1000e_process_tx_desc(E1000ECore *core, | 402 | |
192 | return; | 403 | @@ -XXX,XX +XXX,XX @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd) |
193 | } else if (dtype == (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D)) { | 404 | void vhost_svq_stop(VhostShadowVirtqueue *svq) |
194 | /* data descriptor */ | 405 | { |
195 | - tx->props.sum_needed = le32_to_cpu(dp->upper.data) >> 8; | 406 | event_notifier_set_handler(&svq->svq_kick, NULL); |
196 | - tx->props.cptse = (txd_lower & E1000_TXD_CMD_TSE) ? 1 : 0; | 407 | + g_autofree VirtQueueElement *next_avail_elem = NULL; |
197 | + tx->sum_needed = le32_to_cpu(dp->upper.data) >> 8; | 408 | + |
198 | + tx->cptse = (txd_lower & E1000_TXD_CMD_TSE) ? 1 : 0; | 409 | + if (!svq->vq) { |
199 | e1000e_process_ts_option(core, dp); | 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 | ||
436 | index XXXXXXX..XXXXXXX 100644 | ||
437 | --- a/hw/virtio/vhost-shadow-virtqueue.h | ||
438 | +++ b/hw/virtio/vhost-shadow-virtqueue.h | ||
439 | @@ -XXX,XX +XXX,XX @@ typedef struct VhostShadowVirtqueue { | ||
440 | |||
441 | /* Guest's call notifier, where the SVQ calls guest. */ | ||
442 | EventNotifier svq_call; | ||
443 | + | ||
444 | + /* Virtio queue shadowing */ | ||
445 | + VirtQueue *vq; | ||
446 | + | ||
447 | + /* Virtio device */ | ||
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 | ||
480 | index XXXXXXX..XXXXXXX 100644 | ||
481 | --- a/hw/virtio/vhost-vdpa.c | ||
482 | +++ b/hw/virtio/vhost-vdpa.c | ||
483 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_dev_addr(struct vhost_dev *dev, | ||
484 | * Note that this function does not rewind kick file descriptor if cannot set | ||
485 | * call one. | ||
486 | */ | ||
487 | -static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, | ||
488 | - VhostShadowVirtqueue *svq, unsigned idx, | ||
489 | - Error **errp) | ||
490 | +static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev, | ||
491 | + VhostShadowVirtqueue *svq, unsigned idx, | ||
492 | + Error **errp) | ||
493 | { | ||
494 | struct vhost_vring_file file = { | ||
495 | .index = dev->vq_index + idx, | ||
496 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, | ||
497 | r = vhost_vdpa_set_vring_dev_kick(dev, &file); | ||
498 | if (unlikely(r != 0)) { | ||
499 | error_setg_errno(errp, -r, "Can't set device kick fd"); | ||
500 | - return false; | ||
501 | + return r; | ||
502 | } | ||
503 | |||
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; | ||
599 | } | ||
600 | |||
601 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) | ||
602 | } | ||
603 | |||
604 | for (i = 0; i < v->shadow_vqs->len; ++i) { | ||
605 | + VirtQueue *vq = virtio_get_queue(dev->vdev, dev->vq_index + i); | ||
606 | VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); | ||
607 | + struct vhost_vring_addr addr = { | ||
608 | + .index = i, | ||
609 | + }; | ||
610 | + int r; | ||
611 | bool ok = vhost_vdpa_svq_setup(dev, svq, i, &err); | ||
612 | if (unlikely(!ok)) { | ||
613 | - error_reportf_err(err, "Cannot setup SVQ %u: ", i); | ||
614 | + goto err; | ||
615 | + } | ||
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 | } | ||
664 | } | ||
665 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) | ||
666 | } | ||
667 | vhost_vdpa_set_vring_ready(dev); | ||
200 | } else { | 668 | } else { |
201 | /* legacy descriptor */ | 669 | + ok = vhost_vdpa_svqs_stop(dev); |
202 | e1000e_process_ts_option(core, dp); | 670 | + if (unlikely(!ok)) { |
203 | - tx->props.cptse = 0; | 671 | + return -1; |
204 | + tx->cptse = 0; | 672 | + } |
673 | vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); | ||
205 | } | 674 | } |
206 | 675 | ||
207 | addr = le64_to_cpu(dp->buffer_addr); | ||
208 | @@ -XXX,XX +XXX,XX @@ e1000e_process_tx_desc(E1000ECore *core, | ||
209 | tx->skip_cp = false; | ||
210 | net_tx_pkt_reset(tx->tx_pkt); | ||
211 | |||
212 | - tx->props.sum_needed = 0; | ||
213 | - tx->props.cptse = 0; | ||
214 | + tx->sum_needed = 0; | ||
215 | + tx->cptse = 0; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | diff --git a/hw/net/e1000e_core.h b/hw/net/e1000e_core.h | ||
220 | index XXXXXXX..XXXXXXX 100644 | ||
221 | --- a/hw/net/e1000e_core.h | ||
222 | +++ b/hw/net/e1000e_core.h | ||
223 | @@ -XXX,XX +XXX,XX @@ struct E1000Core { | ||
224 | e1000x_txd_props props; | ||
225 | |||
226 | bool skip_cp; | ||
227 | + unsigned char sum_needed; | ||
228 | + bool cptse; | ||
229 | struct NetTxPkt *tx_pkt; | ||
230 | } tx[E1000E_NUM_QUEUES]; | ||
231 | |||
232 | diff --git a/hw/net/e1000x_common.h b/hw/net/e1000x_common.h | ||
233 | index XXXXXXX..XXXXXXX 100644 | ||
234 | --- a/hw/net/e1000x_common.h | ||
235 | +++ b/hw/net/e1000x_common.h | ||
236 | @@ -XXX,XX +XXX,XX @@ void e1000x_update_regs_on_autoneg_done(uint32_t *mac, uint16_t *phy); | ||
237 | void e1000x_increase_size_stats(uint32_t *mac, const int *size_regs, int size); | ||
238 | |||
239 | typedef struct e1000x_txd_props { | ||
240 | - unsigned char sum_needed; | ||
241 | uint8_t ipcss; | ||
242 | uint8_t ipcso; | ||
243 | uint16_t ipcse; | ||
244 | @@ -XXX,XX +XXX,XX @@ typedef struct e1000x_txd_props { | ||
245 | int8_t ip; | ||
246 | int8_t tcp; | ||
247 | bool tse; | ||
248 | - bool cptse; | ||
249 | } e1000x_txd_props; | ||
250 | |||
251 | void e1000x_read_tx_ctx_descr(struct e1000_context_desc *d, | ||
252 | -- | 676 | -- |
253 | 2.7.4 | 677 | 2.7.4 |
254 | 678 | ||
255 | 679 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Instead of sunhme_crc32_le() using its own implementation, we can simply call | 3 | This iova tree function allows it to look for a hole in allocated |
4 | net_crc32_le() directly and apply the bit shift inline. | 4 | regions and return a totally new translation for a given translated |
5 | 5 | address. | |
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 6 | |
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | 7 | It's usage is mainly to allow devices to access qemu address space, |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 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> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 14 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
10 | --- | 15 | --- |
11 | hw/net/sunhme.c | 25 +------------------------ | 16 | include/qemu/iova-tree.h | 18 +++++++ |
12 | 1 file changed, 1 insertion(+), 24 deletions(-) | 17 | util/iova-tree.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++ |
13 | 18 | 2 files changed, 154 insertions(+) | |
14 | diff --git a/hw/net/sunhme.c b/hw/net/sunhme.c | 19 | |
20 | diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/net/sunhme.c | 22 | --- a/include/qemu/iova-tree.h |
17 | +++ b/hw/net/sunhme.c | 23 | +++ b/include/qemu/iova-tree.h |
18 | @@ -XXX,XX +XXX,XX @@ static inline void sunhme_set_rx_ring_nr(SunHMEState *s, int i) | 24 | @@ -XXX,XX +XXX,XX @@ |
19 | s->erxregs[HME_ERXI_RING >> 2] = ring; | 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; | ||
20 | } | 103 | } |
21 | 104 | ||
22 | -#define POLYNOMIAL_LE 0xedb88320 | 105 | +/** |
23 | -static uint32_t sunhme_crc32_le(const uint8_t *p, int len) | 106 | + * Try to find an unallocated IOVA range between prev and this elements. |
24 | -{ | 107 | + * |
25 | - uint32_t crc; | 108 | + * @args: Arguments to allocation |
26 | - int carry, i, j; | 109 | + * |
27 | - uint8_t b; | 110 | + * Cases: |
28 | - | 111 | + * |
29 | - crc = 0xffffffff; | 112 | + * (1) !prev, !this: No entries allocated, always succeed |
30 | - for (i = 0; i < len; i++) { | 113 | + * |
31 | - b = *p++; | 114 | + * (2) !prev, this: We're iterating at the 1st element. |
32 | - for (j = 0; j < 8; j++) { | 115 | + * |
33 | - carry = (crc & 0x1) ^ (b & 0x01); | 116 | + * (3) prev, !this: We're iterating at the last element. |
34 | - crc >>= 1; | 117 | + * |
35 | - b >>= 1; | 118 | + * (4) prev, this: this is the most common case, we'll try to find a hole |
36 | - if (carry) { | 119 | + * between "prev" and "this" mapping. |
37 | - crc = crc ^ POLYNOMIAL_LE; | 120 | + * |
38 | - } | 121 | + * Note that this function assumes the last valid iova is HWADDR_MAX, but it |
39 | - } | 122 | + * searches linearly so it's easy to discard the result if it's not the case. |
40 | - } | 123 | + */ |
41 | - | 124 | +static void iova_tree_alloc_map_in_hole(struct IOVATreeAllocArgs *args) |
42 | - return crc; | 125 | +{ |
43 | -} | 126 | + const DMAMap *prev = args->prev, *this = args->this; |
44 | - | 127 | + uint64_t hole_start, hole_last; |
45 | #define MIN_BUF_SIZE 60 | 128 | + |
46 | 129 | + if (this && this->iova + this->size < args->iova_begin) { | |
47 | static ssize_t sunhme_receive(NetClientState *nc, const uint8_t *buf, | 130 | + return; |
48 | @@ -XXX,XX +XXX,XX @@ static ssize_t sunhme_receive(NetClientState *nc, const uint8_t *buf, | 131 | + } |
49 | trace_sunhme_rx_filter_bcast_match(); | 132 | + |
50 | } else if (s->macregs[HME_MACI_RXCFG >> 2] & HME_MAC_RXCFG_HENABLE) { | 133 | + hole_start = MAX(prev ? prev->iova + prev->size + 1 : 0, args->iova_begin); |
51 | /* Didn't match local address, check hash filter */ | 134 | + hole_last = this ? this->iova : HWADDR_MAX; |
52 | - int mcast_idx = sunhme_crc32_le(buf, 6) >> 26; | 135 | + |
53 | + int mcast_idx = net_crc32_le(buf, ETH_ALEN) >> 26; | 136 | + if (hole_last - hole_start > args->new_size) { |
54 | if (!(s->macregs[(HME_MACI_HASHTAB0 >> 2) - (mcast_idx >> 4)] & | 137 | + args->iova_result = hole_start; |
55 | (1 << (mcast_idx & 0xf)))) { | 138 | + args->iova_found = true; |
56 | /* Didn't match hash filter */ | 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); | ||
57 | -- | 210 | -- |
58 | 2.7.4 | 211 | 2.7.4 |
59 | 212 | ||
60 | 213 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Separate out the standard ethernet CRC32 calculation into a new net_crc32() | 3 | This function does the reverse operation of iova_tree_find: To look for |
4 | function, renaming the constant POLYNOMIAL to POLYNOMIAL_BE to make it clear | 4 | a mapping that match a translated address so we can do the reverse. |
5 | that this is a big-endian CRC32 calculation. | ||
6 | 5 | ||
7 | As part of the constant rename, remove the duplicate definition of POLYNOMIAL | 6 | This have linear complexity instead of logarithmic, but it supports |
8 | from eepro100.c and use the new POLYNOMIAL_BE constant instead. | 7 | overlapping HVA. Future developments could reduce it. |
9 | 8 | ||
10 | Once this is complete remove the existing CRC32 implementation from | 9 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> |
11 | compute_mcast_idx() and call the new net_crc32() function in its place. | 10 | Acked-by: Michael S. Tsirkin <mst@redhat.com> |
12 | |||
13 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 11 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
16 | --- | 12 | --- |
17 | hw/net/eepro100.c | 4 +--- | 13 | include/qemu/iova-tree.h | 20 +++++++++++++++++++- |
18 | include/net/net.h | 3 ++- | 14 | util/iova-tree.c | 34 ++++++++++++++++++++++++++++++++++ |
19 | net/net.c | 16 +++++++++++----- | 15 | 2 files changed, 53 insertions(+), 1 deletion(-) |
20 | 3 files changed, 14 insertions(+), 9 deletions(-) | ||
21 | 16 | ||
22 | diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c | 17 | diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h |
23 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/hw/net/eepro100.c | 19 | --- a/include/qemu/iova-tree.h |
25 | +++ b/hw/net/eepro100.c | 20 | +++ b/include/qemu/iova-tree.h |
26 | @@ -XXX,XX +XXX,XX @@ static const uint16_t eepro100_mdi_mask[] = { | 21 | @@ -XXX,XX +XXX,XX @@ int iova_tree_remove(IOVATree *tree, const DMAMap *map); |
27 | 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 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; | ||
28 | }; | 61 | }; |
29 | 62 | ||
30 | -#define POLYNOMIAL 0x04c11db6 | 63 | +typedef struct IOVATreeFindIOVAArgs { |
31 | - | 64 | + const DMAMap *needle; |
32 | static E100PCIDeviceInfo *eepro100_get_class(EEPRO100State *s); | 65 | + const DMAMap *result; |
33 | 66 | +} IOVATreeFindIOVAArgs; | |
34 | /* From FreeBSD (locally modified). */ | ||
35 | @@ -XXX,XX +XXX,XX @@ static unsigned e100_compute_mcast_idx(const uint8_t *ep) | ||
36 | crc <<= 1; | ||
37 | b >>= 1; | ||
38 | if (carry) { | ||
39 | - crc = ((crc ^ POLYNOMIAL) | carry); | ||
40 | + crc = ((crc ^ POLYNOMIAL_BE) | carry); | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | diff --git a/include/net/net.h b/include/net/net.h | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/include/net/net.h | ||
47 | +++ b/include/net/net.h | ||
48 | @@ -XXX,XX +XXX,XX @@ NetClientState *net_hub_port_find(int hub_id); | ||
49 | |||
50 | void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); | ||
51 | |||
52 | -#define POLYNOMIAL 0x04c11db6 | ||
53 | +#define POLYNOMIAL_BE 0x04c11db6 | ||
54 | +uint32_t net_crc32(const uint8_t *p, int len); | ||
55 | unsigned compute_mcast_idx(const uint8_t *ep); | ||
56 | |||
57 | #define vmstate_offset_macaddr(_state, _field) \ | ||
58 | diff --git a/net/net.c b/net/net.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/net/net.c | ||
61 | +++ b/net/net.c | ||
62 | @@ -XXX,XX +XXX,XX @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg) | ||
63 | |||
64 | /* From FreeBSD */ | ||
65 | /* XXX: optimize */ | ||
66 | -unsigned compute_mcast_idx(const uint8_t *ep) | ||
67 | +uint32_t net_crc32(const uint8_t *p, int len) | ||
68 | { | ||
69 | uint32_t crc; | ||
70 | int carry, i, j; | ||
71 | uint8_t b; | ||
72 | |||
73 | crc = 0xffffffff; | ||
74 | - for (i = 0; i < 6; i++) { | ||
75 | - b = *ep++; | ||
76 | + for (i = 0; i < len; i++) { | ||
77 | + b = *p++; | ||
78 | for (j = 0; j < 8; j++) { | ||
79 | carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); | ||
80 | crc <<= 1; | ||
81 | b >>= 1; | ||
82 | if (carry) { | ||
83 | - crc = ((crc ^ POLYNOMIAL) | carry); | ||
84 | + crc = ((crc ^ POLYNOMIAL_BE) | carry); | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | - return crc >> 26; | ||
89 | + | 67 | + |
90 | + return crc; | 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; | ||
91 | +} | 92 | +} |
92 | + | 93 | + |
93 | +unsigned compute_mcast_idx(const uint8_t *ep) | 94 | +const DMAMap *iova_tree_find_iova(const IOVATree *tree, const DMAMap *map) |
94 | +{ | 95 | +{ |
95 | + return net_crc32(ep, ETH_ALEN) >> 26; | 96 | + IOVATreeFindIOVAArgs args = { |
96 | } | 97 | + .needle = map, |
97 | 98 | + }; | |
98 | QemuOptsList qemu_netdev_opts = { | 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 }; | ||
99 | -- | 107 | -- |
100 | 2.7.4 | 108 | 2.7.4 |
101 | 109 | ||
102 | 110 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | This makes it much easier to compare the multicast CRC calculation endian and | 3 | This tree is able to look for a translated address from an IOVA address. |
4 | bitshift against the Linux driver implementation. | ||
5 | 4 | ||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 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> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 20 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 21 | --- |
9 | hw/net/ftgmac100.c | 2 +- | 22 | hw/virtio/meson.build | 2 +- |
10 | 1 file changed, 1 insertion(+), 1 deletion(-) | 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 | ||
11 | 28 | ||
12 | diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c | 29 | diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build |
13 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/net/ftgmac100.c | 31 | --- a/hw/virtio/meson.build |
15 | +++ b/hw/net/ftgmac100.c | 32 | +++ b/hw/virtio/meson.build |
16 | @@ -XXX,XX +XXX,XX @@ static int ftgmac100_filter(FTGMAC100State *s, const uint8_t *buf, size_t len) | 33 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) |
17 | } | 34 | |
18 | 35 | virtio_ss = ss.source_set() | |
19 | /* TODO: this does not seem to work for ftgmac100 */ | 36 | virtio_ss.add(files('virtio.c')) |
20 | - mcast_idx = compute_mcast_idx(buf); | 37 | -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c')) |
21 | + mcast_idx = net_crc32(buf, ETH_ALEN) >> 26; | 38 | +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c', 'vhost-iova-tree.c')) |
22 | if (!(s->math[mcast_idx / 32] & (1 << (mcast_idx % 32)))) { | 39 | virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) |
23 | return 0; | 40 | virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) |
24 | } | 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 | ||
25 | -- | 191 | -- |
26 | 2.7.4 | 192 | 2.7.4 |
27 | 193 | ||
28 | 194 | diff view generated by jsdifflib |
1 | From: Ed Swierk via Qemu-devel <qemu-devel@nongnu.org> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The device is supposed to maintain two distinct contexts for transmit | 3 | Use translations added in VhostIOVATree in SVQ. |
4 | offloads: one has parameters for both segmentation and checksum | 4 | |
5 | offload, the other only for checksum offload. The guest driver can | 5 | Only introduce usage here, not allocation and deallocation. As with |
6 | send two context descriptors, one for each context (the TSE flag | 6 | previous patches, we use the dead code paths of shadow_vqs_enabled to |
7 | specifies which). Then the guest can refer to one or the other context | 7 | avoid commiting too many changes at once. These are impossible to take |
8 | in subsequent transmit data descriptors, depending on what offloads it | 8 | at the moment. |
9 | wants applied to each packet. | 9 | |
10 | 10 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> | |
11 | Currently the e1000 device stores just one context, and misinterprets | 11 | Acked-by: Michael S. Tsirkin <mst@redhat.com> |
12 | the TSE flags in the context and data descriptors. This is often okay: | ||
13 | Linux happens to send a fresh context descriptor before every data | ||
14 | descriptor, so forgetting the other context doesn't matter. Windows | ||
15 | does rely on separate contexts for TSO vs. non-TSO packets, but for | ||
16 | mostly-TCP traffic the two contexts have identical TCP-specific | ||
17 | offload parameters so confusing them doesn't matter. | ||
18 | |||
19 | One case where this confusion matters is when a Windows guest sets up | ||
20 | a TSO context for TCP and a non-TSO context for UDP, and then | ||
21 | transmits both TCP and UDP traffic in parallel. The e1000 device | ||
22 | sometimes ends up using TCP-specific parameters while doing checksum | ||
23 | offload on a UDP datagram: it writes the checksum to offset 16 (the | ||
24 | correct location for a TCP checksum), stomping on two bytes of UDP | ||
25 | data, and leaving the wrong value in the actual UDP checksum field at | ||
26 | offset 6. (Even worse, the host network stack may then recompute the | ||
27 | UDP checksum, "correcting" it to match the corrupt data before sending | ||
28 | it out a physical interface.) | ||
29 | |||
30 | Correct this by tracking the TSO context independently of the non-TSO | ||
31 | context, and selecting the appropriate context based on the TSE flag | ||
32 | in each transmit data descriptor. | ||
33 | |||
34 | Signed-off-by: Ed Swierk <eswierk@skyportsystems.com> | ||
35 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 12 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
36 | --- | 13 | --- |
37 | hw/net/e1000.c | 70 +++++++++++++++++++++++++++++++++------------------------- | 14 | hw/virtio/vhost-shadow-virtqueue.c | 86 +++++++++++++++++++++++--- |
38 | 1 file changed, 40 insertions(+), 30 deletions(-) | 15 | hw/virtio/vhost-shadow-virtqueue.h | 6 +- |
39 | 16 | hw/virtio/vhost-vdpa.c | 122 +++++++++++++++++++++++++++++++------ | |
40 | diff --git a/hw/net/e1000.c b/hw/net/e1000.c | 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 | ||
41 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/hw/net/e1000.c | 22 | --- a/hw/virtio/vhost-shadow-virtqueue.c |
43 | +++ b/hw/net/e1000.c | 23 | +++ b/hw/virtio/vhost-shadow-virtqueue.c |
44 | @@ -XXX,XX +XXX,XX @@ typedef struct E1000State_st { | 24 | @@ -XXX,XX +XXX,XX @@ static uint16_t vhost_svq_available_slots(const VhostShadowVirtqueue *svq) |
45 | unsigned char sum_needed; | 25 | return svq->vring.num - (svq->shadow_avail_idx - svq->shadow_used_idx); |
46 | bool cptse; | 26 | } |
47 | e1000x_txd_props props; | 27 | |
48 | + e1000x_txd_props tso_props; | 28 | -static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, |
49 | uint16_t tso_frames; | 29 | +/** |
50 | } tx; | 30 | + * Translate addresses between the qemu's virtual address and the SVQ IOVA |
51 | 31 | + * | |
52 | @@ -XXX,XX +XXX,XX @@ xmit_seg(E1000State *s) | 32 | + * @svq: Shadow VirtQueue |
53 | uint16_t len; | 33 | + * @vaddr: Translated IOVA addresses |
54 | unsigned int frames = s->tx.tso_frames, css, sofar; | 34 | + * @iovec: Source qemu's VA addresses |
55 | struct e1000_tx *tp = &s->tx; | 35 | + * @num: Length of iovec and minimum length of vaddr |
56 | + struct e1000x_txd_props *props = tp->cptse ? &tp->tso_props : &tp->props; | 36 | + */ |
57 | 37 | +static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq, | |
58 | - if (tp->props.tse && tp->cptse) { | 38 | + hwaddr *addrs, const struct iovec *iovec, |
59 | - css = tp->props.ipcss; | 39 | + size_t num) |
60 | + if (tp->cptse) { | 40 | +{ |
61 | + css = props->ipcss; | 41 | + if (num == 0) { |
62 | DBGOUT(TXSUM, "frames %d size %d ipcss %d\n", | 42 | + return true; |
63 | frames, tp->size, css); | 43 | + } |
64 | - if (tp->props.ip) { /* IPv4 */ | 44 | + |
65 | + if (props->ip) { /* IPv4 */ | 45 | + for (size_t i = 0; i < num; ++i) { |
66 | stw_be_p(tp->data+css+2, tp->size - css); | 46 | + DMAMap needle = { |
67 | stw_be_p(tp->data+css+4, | 47 | + .translated_addr = (hwaddr)(uintptr_t)iovec[i].iov_base, |
68 | lduw_be_p(tp->data + css + 4) + frames); | 48 | + .size = iovec[i].iov_len, |
69 | } else { /* IPv6 */ | 49 | + }; |
70 | stw_be_p(tp->data+css+4, tp->size - css); | 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; | ||
71 | } | 88 | } |
72 | - css = tp->props.tucss; | 89 | - descs[i].addr = cpu_to_le64((hwaddr)(intptr_t)iovec[n].iov_base); |
73 | + css = props->tucss; | 90 | + descs[i].addr = cpu_to_le64(sg[n]); |
74 | len = tp->size - css; | 91 | descs[i].len = cpu_to_le32(iovec[n].iov_len); |
75 | - DBGOUT(TXSUM, "tcp %d tucss %d len %d\n", tp->props.tcp, css, len); | 92 | |
76 | - if (tp->props.tcp) { | 93 | last = i; |
77 | - sofar = frames * tp->props.mss; | 94 | @@ -XXX,XX +XXX,XX @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, |
78 | + DBGOUT(TXSUM, "tcp %d tucss %d len %d\n", props->tcp, css, len); | 95 | { |
79 | + if (props->tcp) { | 96 | unsigned avail_idx; |
80 | + sofar = frames * props->mss; | 97 | vring_avail_t *avail = svq->vring.avail; |
81 | stl_be_p(tp->data+css+4, ldl_be_p(tp->data+css+4)+sofar); /* seq */ | 98 | + bool ok; |
82 | - if (tp->props.paylen - sofar > tp->props.mss) { | 99 | + g_autofree hwaddr *sgs = g_new(hwaddr, MAX(elem->out_num, elem->in_num)); |
83 | + if (props->paylen - sofar > props->mss) { | 100 | |
84 | tp->data[css + 13] &= ~9; /* PSH, FIN */ | 101 | *head = svq->free_head; |
85 | } else if (frames) { | 102 | |
86 | e1000x_inc_reg_if_not_full(s->mac_reg, TSCTC); | 103 | @@ -XXX,XX +XXX,XX @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, |
87 | } | 104 | return false; |
88 | - } else /* UDP */ | 105 | } |
89 | + } else { /* UDP */ | 106 | |
90 | stw_be_p(tp->data+css+4, len); | 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; | ||
91 | + } | 213 | + } |
92 | if (tp->sum_needed & E1000_TXD_POPTS_TXSM) { | 214 | + |
93 | unsigned int phsum; | 215 | + iova = mem_region.iova; |
94 | // add pseudo-header length before checksum calculation | 216 | + } |
95 | - void *sp = tp->data + tp->props.tucso; | 217 | |
96 | + void *sp = tp->data + props->tucso; | 218 | vhost_vdpa_iotlb_batch_begin_once(v); |
97 | 219 | ret = vhost_vdpa_dma_map(v, iova, int128_get64(llsize), | |
98 | phsum = lduw_be_p(sp) + len; | 220 | @@ -XXX,XX +XXX,XX @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, |
99 | phsum = (phsum >> 16) + (phsum & 0xffff); | 221 | |
100 | @@ -XXX,XX +XXX,XX @@ xmit_seg(E1000State *s) | 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; | ||
101 | } | 292 | } |
102 | 293 | ||
103 | if (tp->sum_needed & E1000_TXD_POPTS_TXSM) { | 294 | - return vhost_vdpa_svq_unmap_ring(v, svq_addr.used_user_addr, device_size); |
104 | - putsum(tp->data, tp->size, tp->props.tucso, | 295 | + needle.translated_addr = svq_addr.used_user_addr; |
105 | - tp->props.tucss, tp->props.tucse); | 296 | + return vhost_vdpa_svq_unmap_ring(v, &needle); |
106 | + putsum(tp->data, tp->size, props->tucso, props->tucss, props->tucse); | 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; | ||
107 | } | 359 | } |
108 | if (tp->sum_needed & E1000_TXD_POPTS_IXSM) { | 360 | + addr->desc_user_addr = driver_region.iova; |
109 | - putsum(tp->data, tp->size, tp->props.ipcso, | 361 | + avail_offset = svq_addr.avail_user_addr - svq_addr.desc_user_addr; |
110 | - tp->props.ipcss, tp->props.ipcse); | 362 | + addr->avail_user_addr = driver_region.iova + avail_offset; |
111 | + putsum(tp->data, tp->size, props->ipcso, props->ipcss, props->ipcse); | 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); | ||
112 | } | 377 | } |
113 | if (tp->vlan_needed) { | 378 | + addr->used_user_addr = device_region.iova; |
114 | memmove(tp->vlan, tp->data, 4); | 379 | |
115 | @@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) | 380 | - return r == 0; |
116 | 381 | + return ok; | |
117 | s->mit_ide |= (txd_lower & E1000_TXD_CMD_IDE); | 382 | } |
118 | if (dtype == E1000_TXD_CMD_DEXT) { /* context descriptor */ | 383 | |
119 | - e1000x_read_tx_ctx_descr(xp, &tp->props); | 384 | static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, |
120 | - tp->tso_frames = 0; | 385 | diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h |
121 | - if (tp->props.tucso == 0) { /* this is probably wrong */ | 386 | index XXXXXXX..XXXXXXX 100644 |
122 | - DBGOUT(TXSUM, "TCP/UDP: cso 0!\n"); | 387 | --- a/include/hw/virtio/vhost-vdpa.h |
123 | - tp->props.tucso = tp->props.tucss + (tp->props.tcp ? 16 : 6); | 388 | +++ b/include/hw/virtio/vhost-vdpa.h |
124 | + if (le32_to_cpu(xp->cmd_and_length) & E1000_TXD_CMD_TSE) { | 389 | @@ -XXX,XX +XXX,XX @@ |
125 | + e1000x_read_tx_ctx_descr(xp, &tp->tso_props); | 390 | |
126 | + tp->tso_frames = 0; | 391 | #include <gmodule.h> |
127 | + } else { | 392 | |
128 | + e1000x_read_tx_ctx_descr(xp, &tp->props); | 393 | +#include "hw/virtio/vhost-iova-tree.h" |
129 | } | 394 | #include "hw/virtio/virtio.h" |
130 | return; | 395 | #include "standard-headers/linux/vhost_types.h" |
131 | } else if (dtype == (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D)) { | 396 | |
132 | @@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) | 397 | @@ -XXX,XX +XXX,XX @@ typedef struct vhost_vdpa { |
133 | } | 398 | MemoryListener listener; |
134 | 399 | struct vhost_vdpa_iova_range iova_range; | |
135 | addr = le64_to_cpu(dp->buffer_addr); | 400 | bool shadow_vqs_enabled; |
136 | - if (tp->props.tse && tp->cptse) { | 401 | + /* IOVA mapping used by the Shadow Virtqueue */ |
137 | - msh = tp->props.hdr_len + tp->props.mss; | 402 | + VhostIOVATree *iova_tree; |
138 | + if (tp->cptse) { | 403 | GPtrArray *shadow_vqs; |
139 | + msh = tp->tso_props.hdr_len + tp->tso_props.mss; | 404 | struct vhost_dev *dev; |
140 | do { | 405 | VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; |
141 | bytes = split_size; | ||
142 | if (tp->size + bytes > msh) | ||
143 | @@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) | ||
144 | bytes = MIN(sizeof(tp->data) - tp->size, bytes); | ||
145 | pci_dma_read(d, addr, tp->data + tp->size, bytes); | ||
146 | sz = tp->size + bytes; | ||
147 | - if (sz >= tp->props.hdr_len && tp->size < tp->props.hdr_len) { | ||
148 | - memmove(tp->header, tp->data, tp->props.hdr_len); | ||
149 | + if (sz >= tp->tso_props.hdr_len | ||
150 | + && tp->size < tp->tso_props.hdr_len) { | ||
151 | + memmove(tp->header, tp->data, tp->tso_props.hdr_len); | ||
152 | } | ||
153 | tp->size = sz; | ||
154 | addr += bytes; | ||
155 | if (sz == msh) { | ||
156 | xmit_seg(s); | ||
157 | - memmove(tp->data, tp->header, tp->props.hdr_len); | ||
158 | - tp->size = tp->props.hdr_len; | ||
159 | + memmove(tp->data, tp->header, tp->tso_props.hdr_len); | ||
160 | + tp->size = tp->tso_props.hdr_len; | ||
161 | } | ||
162 | split_size -= bytes; | ||
163 | } while (bytes && split_size); | ||
164 | - } else if (!tp->props.tse && tp->cptse) { | ||
165 | - // context descriptor TSE is not set, while data descriptor TSE is set | ||
166 | - DBGOUT(TXERR, "TCP segmentation error\n"); | ||
167 | } else { | ||
168 | split_size = MIN(sizeof(tp->data) - tp->size, split_size); | ||
169 | pci_dma_read(d, addr, tp->data + tp->size, split_size); | ||
170 | @@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) | ||
171 | |||
172 | if (!(txd_lower & E1000_TXD_CMD_EOP)) | ||
173 | return; | ||
174 | - if (!(tp->props.tse && tp->cptse && tp->size < tp->props.hdr_len)) { | ||
175 | + if (!(tp->cptse && tp->size < tp->tso_props.hdr_len)) { | ||
176 | xmit_seg(s); | ||
177 | } | ||
178 | tp->tso_frames = 0; | ||
179 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_e1000_full_mac_state = { | ||
180 | |||
181 | static const VMStateDescription vmstate_e1000 = { | ||
182 | .name = "e1000", | ||
183 | - .version_id = 2, | ||
184 | + .version_id = 3, | ||
185 | .minimum_version_id = 1, | ||
186 | .pre_save = e1000_pre_save, | ||
187 | .post_load = e1000_post_load, | ||
188 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_e1000 = { | ||
189 | VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, RA, 32), | ||
190 | VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, MTA, 128), | ||
191 | VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, VFTA, 128), | ||
192 | + VMSTATE_UINT8_V(tx.tso_props.ipcss, E1000State, 3), | ||
193 | + VMSTATE_UINT8_V(tx.tso_props.ipcso, E1000State, 3), | ||
194 | + VMSTATE_UINT16_V(tx.tso_props.ipcse, E1000State, 3), | ||
195 | + VMSTATE_UINT8_V(tx.tso_props.tucss, E1000State, 3), | ||
196 | + VMSTATE_UINT8_V(tx.tso_props.tucso, E1000State, 3), | ||
197 | + VMSTATE_UINT16_V(tx.tso_props.tucse, E1000State, 3), | ||
198 | + VMSTATE_UINT32_V(tx.tso_props.paylen, E1000State, 3), | ||
199 | + VMSTATE_UINT8_V(tx.tso_props.hdr_len, E1000State, 3), | ||
200 | + VMSTATE_UINT16_V(tx.tso_props.mss, E1000State, 3), | ||
201 | + VMSTATE_INT8_V(tx.tso_props.ip, E1000State, 3), | ||
202 | + VMSTATE_INT8_V(tx.tso_props.tcp, E1000State, 3), | ||
203 | VMSTATE_END_OF_LIST() | ||
204 | }, | ||
205 | .subsections = (const VMStateDescription*[]) { | ||
206 | -- | 406 | -- |
207 | 2.7.4 | 407 | 2.7.4 |
208 | 408 | ||
209 | 409 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | ||
2 | 1 | ||
3 | Instead of lnc_mchash() using its own implementation, we can simply call | ||
4 | net_crc32_le() directly and apply the bit shift inline. | ||
5 | |||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
10 | --- | ||
11 | hw/net/pcnet.c | 22 ++-------------------- | ||
12 | 1 file changed, 2 insertions(+), 20 deletions(-) | ||
13 | |||
14 | diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/net/pcnet.c | ||
17 | +++ b/hw/net/pcnet.c | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | #include "qemu/osdep.h" | ||
20 | #include "hw/qdev.h" | ||
21 | #include "net/net.h" | ||
22 | +#include "net/eth.h" | ||
23 | #include "qemu/timer.h" | ||
24 | #include "qemu/sockets.h" | ||
25 | #include "sysemu/sysemu.h" | ||
26 | @@ -XXX,XX +XXX,XX @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd, | ||
27 | be16_to_cpu(hdr->ether_type)); \ | ||
28 | } while (0) | ||
29 | |||
30 | -#define MULTICAST_FILTER_LEN 8 | ||
31 | - | ||
32 | -static inline uint32_t lnc_mchash(const uint8_t *ether_addr) | ||
33 | -{ | ||
34 | -#define LNC_POLYNOMIAL 0xEDB88320UL | ||
35 | - uint32_t crc = 0xFFFFFFFF; | ||
36 | - int idx, bit; | ||
37 | - uint8_t data; | ||
38 | - | ||
39 | - for (idx = 0; idx < 6; idx++) { | ||
40 | - for (data = *ether_addr++, bit = 0; bit < MULTICAST_FILTER_LEN; bit++) { | ||
41 | - crc = (crc >> 1) ^ (((crc ^ data) & 1) ? LNC_POLYNOMIAL : 0); | ||
42 | - data >>= 1; | ||
43 | - } | ||
44 | - } | ||
45 | - return crc; | ||
46 | -#undef LNC_POLYNOMIAL | ||
47 | -} | ||
48 | - | ||
49 | #define CRC(crc, ch) (crc = (crc >> 8) ^ crctab[(crc ^ (ch)) & 0xff]) | ||
50 | |||
51 | /* generated using the AUTODIN II polynomial | ||
52 | @@ -XXX,XX +XXX,XX @@ static inline int ladr_match(PCNetState *s, const uint8_t *buf, int size) | ||
53 | s->csr[10] & 0xff, s->csr[10] >> 8, | ||
54 | s->csr[11] & 0xff, s->csr[11] >> 8 | ||
55 | }; | ||
56 | - int index = lnc_mchash(hdr->ether_dhost) >> 26; | ||
57 | + int index = net_crc32_le(hdr->ether_dhost, ETH_ALEN) >> 26; | ||
58 | return !!(ladr[index >> 3] & (1 << (index & 7))); | ||
59 | } | ||
60 | return 0; | ||
61 | -- | ||
62 | 2.7.4 | ||
63 | |||
64 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | ||
2 | 1 | ||
3 | Instead of e100_compute_mcast_idx() using its own implementation, we can | ||
4 | simply call net_crc32() directly and apply the bit shift inline. | ||
5 | |||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | ||
7 | Reviewed-by: Stefan Weil <sw@weilnetz.de> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
10 | --- | ||
11 | hw/net/eepro100.c | 28 ++++------------------------ | ||
12 | 1 file changed, 4 insertions(+), 24 deletions(-) | ||
13 | |||
14 | diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/net/eepro100.c | ||
17 | +++ b/hw/net/eepro100.c | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | #include "hw/hw.h" | ||
20 | #include "hw/pci/pci.h" | ||
21 | #include "net/net.h" | ||
22 | +#include "net/eth.h" | ||
23 | #include "hw/nvram/eeprom93xx.h" | ||
24 | #include "sysemu/sysemu.h" | ||
25 | #include "sysemu/dma.h" | ||
26 | @@ -XXX,XX +XXX,XX @@ static const uint16_t eepro100_mdi_mask[] = { | ||
27 | |||
28 | static E100PCIDeviceInfo *eepro100_get_class(EEPRO100State *s); | ||
29 | |||
30 | -/* From FreeBSD (locally modified). */ | ||
31 | -static unsigned e100_compute_mcast_idx(const uint8_t *ep) | ||
32 | -{ | ||
33 | - uint32_t crc; | ||
34 | - int carry, i, j; | ||
35 | - uint8_t b; | ||
36 | - | ||
37 | - crc = 0xffffffff; | ||
38 | - for (i = 0; i < 6; i++) { | ||
39 | - b = *ep++; | ||
40 | - for (j = 0; j < 8; j++) { | ||
41 | - carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); | ||
42 | - crc <<= 1; | ||
43 | - b >>= 1; | ||
44 | - if (carry) { | ||
45 | - crc = ((crc ^ POLYNOMIAL_BE) | carry); | ||
46 | - } | ||
47 | - } | ||
48 | - } | ||
49 | - return (crc & BITS(7, 2)) >> 2; | ||
50 | -} | ||
51 | - | ||
52 | /* Read a 16 bit control/status (CSR) register. */ | ||
53 | static uint16_t e100_read_reg2(EEPRO100State *s, E100RegisterOffset addr) | ||
54 | { | ||
55 | @@ -XXX,XX +XXX,XX @@ static void set_multicast_list(EEPRO100State *s) | ||
56 | uint8_t multicast_addr[6]; | ||
57 | pci_dma_read(&s->dev, s->cb_address + 10 + i, multicast_addr, 6); | ||
58 | TRACE(OTHER, logout("multicast entry %s\n", nic_dump(multicast_addr, 6))); | ||
59 | - unsigned mcast_idx = e100_compute_mcast_idx(multicast_addr); | ||
60 | + unsigned mcast_idx = (net_crc32(multicast_addr, ETH_ALEN) & | ||
61 | + BITS(7, 2)) >> 2; | ||
62 | assert(mcast_idx < 64); | ||
63 | s->mult[mcast_idx >> 3] |= (1 << (mcast_idx & 7)); | ||
64 | } | ||
65 | @@ -XXX,XX +XXX,XX @@ static ssize_t nic_receive(NetClientState *nc, const uint8_t * buf, size_t size) | ||
66 | if (s->configuration[21] & BIT(3)) { | ||
67 | /* Multicast all bit is set, receive all multicast frames. */ | ||
68 | } else { | ||
69 | - unsigned mcast_idx = e100_compute_mcast_idx(buf); | ||
70 | + unsigned mcast_idx = (net_crc32(buf, ETH_ALEN) & BITS(7, 2)) >> 2; | ||
71 | assert(mcast_idx < 64); | ||
72 | if (s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))) { | ||
73 | /* Multicast frame is allowed in hash table. */ | ||
74 | -- | ||
75 | 2.7.4 | ||
76 | |||
77 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | This makes it much easier to compare the multicast CRC calculation endian and | 3 | This is needed to achieve migration, so the destination can restore its |
4 | bitshift against the Linux driver implementation. | 4 | index. |
5 | 5 | ||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 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> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 15 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 16 | --- |
9 | hw/net/lan9118.c | 3 ++- | 17 | hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ |
10 | 1 file changed, 2 insertions(+), 1 deletion(-) | 18 | 1 file changed, 17 insertions(+) |
11 | 19 | ||
12 | diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c | 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/hw/net/lan9118.c | 22 | --- a/hw/virtio/vhost-vdpa.c |
15 | +++ b/hw/net/lan9118.c | 23 | +++ b/hw/virtio/vhost-vdpa.c |
16 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, |
17 | #include "qemu/osdep.h" | 25 | static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, |
18 | #include "hw/sysbus.h" | 26 | struct vhost_vring_state *ring) |
19 | #include "net/net.h" | 27 | { |
20 | +#include "net/eth.h" | 28 | + struct vhost_vdpa *v = dev->opaque; |
21 | #include "hw/devices.h" | 29 | int ret; |
22 | #include "sysemu/sysemu.h" | 30 | |
23 | #include "hw/ptimer.h" | 31 | + if (v->shadow_vqs_enabled) { |
24 | @@ -XXX,XX +XXX,XX @@ static int lan9118_filter(lan9118_state *s, const uint8_t *addr) | 32 | + VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, |
25 | } | 33 | + ring->index); |
26 | } else { | 34 | + |
27 | /* Hash matching */ | 35 | + /* |
28 | - hash = compute_mcast_idx(addr); | 36 | + * Setting base as last used idx, so destination will see as available |
29 | + hash = net_crc32(addr, ETH_ALEN) >> 26; | 37 | + * all the entries that the device did not use, including the in-flight |
30 | if (hash & 0x20) { | 38 | + * processing ones. |
31 | return (s->mac_hashh >> (hash & 0x1f)) & 1; | 39 | + * |
32 | } else { | 40 | + * TODO: This is ok for networking, but other kinds of devices might |
41 | + * have problems with these retransmissions. | ||
42 | + */ | ||
43 | + ring->num = svq->last_used_idx; | ||
44 | + return 0; | ||
45 | + } | ||
46 | + | ||
47 | ret = vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); | ||
48 | trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num); | ||
49 | return ret; | ||
33 | -- | 50 | -- |
34 | 2.7.4 | 51 | 2.7.4 |
35 | 52 | ||
36 | 53 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | This makes it much easier to compare the multicast CRC calculation endian and | 3 | Setting the log address would make the device start reporting invalid |
4 | bitshift against the Linux driver implementation. | 4 | dirty memory because the SVQ vrings are located in qemu's memory. |
5 | 5 | ||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 6 | Signed-off-by: Eugenio Pérez <eperezma@redhat.com> |
7 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 8 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 9 | --- |
9 | hw/net/opencores_eth.c | 3 ++- | 10 | hw/virtio/vhost-vdpa.c | 3 ++- |
10 | 1 file changed, 2 insertions(+), 1 deletion(-) | 11 | 1 file changed, 2 insertions(+), 1 deletion(-) |
11 | 12 | ||
12 | diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c | 13 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/net/opencores_eth.c | 15 | --- a/hw/virtio/vhost-vdpa.c |
15 | +++ b/hw/net/opencores_eth.c | 16 | +++ b/hw/virtio/vhost-vdpa.c |
16 | @@ -XXX,XX +XXX,XX @@ | 17 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) |
17 | #include "hw/net/mii.h" | 18 | static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, |
18 | #include "hw/sysbus.h" | 19 | struct vhost_log *log) |
19 | #include "net/net.h" | 20 | { |
20 | +#include "net/eth.h" | 21 | - if (vhost_vdpa_one_time_request(dev)) { |
21 | #include "sysemu/sysemu.h" | 22 | + struct vhost_vdpa *v = dev->opaque; |
22 | #include "trace.h" | 23 | + if (v->shadow_vqs_enabled || vhost_vdpa_one_time_request(dev)) { |
23 | 24 | return 0; | |
24 | @@ -XXX,XX +XXX,XX @@ static ssize_t open_eth_receive(NetClientState *nc, | 25 | } |
25 | if (memcmp(buf, bcast_addr, sizeof(bcast_addr)) == 0) { | 26 | |
26 | miss = GET_REGBIT(s, MODER, BRO); | ||
27 | } else if ((buf[0] & 0x1) || GET_REGBIT(s, MODER, IAM)) { | ||
28 | - unsigned mcast_idx = compute_mcast_idx(buf); | ||
29 | + unsigned mcast_idx = net_crc32(buf, ETH_ALEN) >> 26; | ||
30 | miss = !(s->regs[HASH0 + mcast_idx / 32] & | ||
31 | (1 << (mcast_idx % 32))); | ||
32 | trace_open_eth_receive_mcast( | ||
33 | -- | 27 | -- |
34 | 2.7.4 | 28 | 2.7.4 |
35 | 29 | ||
36 | 30 | diff view generated by jsdifflib |
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 1 | From: Eugenio Pérez <eperezma@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | From the Linux sungem driver, we know that the multicast filter CRC is | 3 | SVQ is able to log the dirty bits by itself, so let's use it to not |
4 | implemented using ether_crc_le() which isn't the same as calling zlib's | 4 | block migration. |
5 | crc32() function (the zlib implementation requires a complemented initial value | ||
6 | and also returns the complemented result). | ||
7 | 5 | ||
8 | Fix the multicast filter by simply using the new net_crc32_le() function. | 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 | 9 | ||
10 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 10 | The log region is still allocated. Future changes might skip that, but |
11 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 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> | ||
12 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 15 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
13 | --- | 16 | --- |
14 | hw/net/sungem.c | 5 ++--- | 17 | hw/virtio/vhost-vdpa.c | 39 +++++++++++++++++++++++++++++++++++---- |
15 | 1 file changed, 2 insertions(+), 3 deletions(-) | 18 | include/hw/virtio/vhost-vdpa.h | 1 + |
19 | 2 files changed, 36 insertions(+), 4 deletions(-) | ||
16 | 20 | ||
17 | diff --git a/hw/net/sungem.c b/hw/net/sungem.c | 21 | diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c |
18 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/net/sungem.c | 23 | --- a/hw/virtio/vhost-vdpa.c |
20 | +++ b/hw/net/sungem.c | 24 | +++ b/hw/virtio/vhost-vdpa.c |
21 | @@ -XXX,XX +XXX,XX @@ | 25 | @@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_one_time_request(struct vhost_dev *dev) |
22 | #include "hw/pci/pci.h" | 26 | return v->index != 0; |
23 | #include "qemu/log.h" | 27 | } |
24 | #include "net/net.h" | 28 | |
25 | +#include "net/eth.h" | 29 | +static int vhost_vdpa_get_dev_features(struct vhost_dev *dev, |
26 | #include "net/checksum.h" | 30 | + uint64_t *features) |
27 | #include "hw/net/mii.h" | 31 | +{ |
28 | #include "sysemu/sysemu.h" | 32 | + int ret; |
29 | #include "trace.h" | 33 | + |
30 | -/* For crc32 */ | 34 | + ret = vhost_vdpa_call(dev, VHOST_GET_FEATURES, features); |
31 | -#include <zlib.h> | 35 | + trace_vhost_vdpa_get_features(dev, *features); |
32 | 36 | + return ret; | |
33 | #define TYPE_SUNGEM "sungem" | 37 | +} |
34 | 38 | + | |
35 | @@ -XXX,XX +XXX,XX @@ static ssize_t sungem_receive(NetClientState *nc, const uint8_t *buf, | 39 | static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, |
40 | Error **errp) | ||
41 | { | ||
42 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, | ||
43 | return 0; | ||
36 | } | 44 | } |
37 | 45 | ||
38 | /* Get MAC crc */ | 46 | - r = hdev->vhost_ops->vhost_get_features(hdev, &dev_features); |
39 | - mac_crc = crc32(~0, buf, 6); | 47 | + r = vhost_vdpa_get_dev_features(hdev, &dev_features); |
40 | + mac_crc = net_crc32_le(buf, ETH_ALEN); | 48 | if (r != 0) { |
41 | 49 | error_setg_errno(errp, -r, "Can't get vdpa device features"); | |
42 | /* Packet isn't for me ? */ | 50 | return r; |
43 | rx_cond = sungem_check_rx_mac(s, buf, mac_crc); | 51 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_mem_table(struct vhost_dev *dev, |
52 | static int vhost_vdpa_set_features(struct vhost_dev *dev, | ||
53 | uint64_t features) | ||
54 | { | ||
55 | + struct vhost_vdpa *v = dev->opaque; | ||
56 | int ret; | ||
57 | |||
58 | if (vhost_vdpa_one_time_request(dev)) { | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | + if (v->shadow_vqs_enabled) { | ||
63 | + if ((v->acked_features ^ features) == BIT_ULL(VHOST_F_LOG_ALL)) { | ||
64 | + /* | ||
65 | + * QEMU is just trying to enable or disable logging. SVQ handles | ||
66 | + * this sepparately, so no need to forward this. | ||
67 | + */ | ||
68 | + v->acked_features = features; | ||
69 | + return 0; | ||
70 | + } | ||
71 | + | ||
72 | + v->acked_features = features; | ||
73 | + | ||
74 | + /* We must not ack _F_LOG if SVQ is enabled */ | ||
75 | + features &= ~BIT_ULL(VHOST_F_LOG_ALL); | ||
76 | + } | ||
77 | + | ||
78 | trace_vhost_vdpa_set_features(dev, features); | ||
79 | ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); | ||
80 | if (ret) { | ||
81 | @@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, | ||
82 | static int vhost_vdpa_get_features(struct vhost_dev *dev, | ||
83 | uint64_t *features) | ||
84 | { | ||
85 | - int ret; | ||
86 | + struct vhost_vdpa *v = dev->opaque; | ||
87 | + int ret = vhost_vdpa_get_dev_features(dev, features); | ||
88 | + | ||
89 | + if (ret == 0 && v->shadow_vqs_enabled) { | ||
90 | + /* Add SVQ logging capabilities */ | ||
91 | + *features |= BIT_ULL(VHOST_F_LOG_ALL); | ||
92 | + } | ||
93 | |||
94 | - ret = vhost_vdpa_call(dev, VHOST_GET_FEATURES, features); | ||
95 | - trace_vhost_vdpa_get_features(dev, *features); | ||
96 | return ret; | ||
97 | } | ||
98 | |||
99 | diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/include/hw/virtio/vhost-vdpa.h | ||
102 | +++ b/include/hw/virtio/vhost-vdpa.h | ||
103 | @@ -XXX,XX +XXX,XX @@ typedef struct vhost_vdpa { | ||
104 | bool iotlb_batch_begin_sent; | ||
105 | MemoryListener listener; | ||
106 | struct vhost_vdpa_iova_range iova_range; | ||
107 | + uint64_t acked_features; | ||
108 | bool shadow_vqs_enabled; | ||
109 | /* IOVA mapping used by the Shadow Virtqueue */ | ||
110 | VhostIOVATree *iova_tree; | ||
44 | -- | 111 | -- |
45 | 2.7.4 | 112 | 2.7.4 |
46 | 113 | ||
47 | 114 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | ||
2 | 1 | ||
3 | This makes it much easier to compare the multicast CRC calculation endian and | ||
4 | bitshift against the Linux driver implementation. | ||
5 | |||
6 | Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
8 | --- | ||
9 | hw/net/eepro100.c | 2 +- | ||
10 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
11 | |||
12 | diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/hw/net/eepro100.c | ||
15 | +++ b/hw/net/eepro100.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static ssize_t nic_receive(NetClientState *nc, const uint8_t * buf, size_t size) | ||
17 | rfd_status |= 0x0004; | ||
18 | } else if (s->configuration[20] & BIT(6)) { | ||
19 | /* Multiple IA bit set. */ | ||
20 | - unsigned mcast_idx = compute_mcast_idx(buf); | ||
21 | + unsigned mcast_idx = net_crc32(buf, ETH_ALEN) >> 26; | ||
22 | assert(mcast_idx < 64); | ||
23 | if (s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))) { | ||
24 | TRACE(RXTX, logout("%p accepted, multiple IA bit set\n", s)); | ||
25 | -- | ||
26 | 2.7.4 | ||
27 | |||
28 | diff view generated by jsdifflib |