* [Qemu-devel] [RFC 1/4] virtio-net: reuse MTU related bits from Linux header
2016-09-06 16:11 [Qemu-devel] [RFC 0/4] virtio-net: Add support to MTU feature Maxime Coquelin
@ 2016-09-06 16:11 ` Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 2/4] vhost-user: Add new protocol feature MTU Maxime Coquelin
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Maxime Coquelin @ 2016-09-06 16:11 UTC (permalink / raw)
To: mst, qemu-devel; +Cc: jasowang, Maxime Coquelin, Aaron Conole
VIRTIO_NET_F_MTU has been introduced in Linux v4.8-rc1.
Reuse its define and the related virtio_net_config struct
update.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Aaron Conole <aconole@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
include/standard-headers/linux/virtio_net.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/standard-headers/linux/virtio_net.h b/include/standard-headers/linux/virtio_net.h
index a78f33e..30ff249 100644
--- a/include/standard-headers/linux/virtio_net.h
+++ b/include/standard-headers/linux/virtio_net.h
@@ -35,6 +35,7 @@
#define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */
#define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */
#define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Dynamic offload configuration. */
+#define VIRTIO_NET_F_MTU 3 /* Initial MTU advice */
#define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */
#define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */
#define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */
@@ -73,6 +74,8 @@ struct virtio_net_config {
* Legal values are between 1 and 0x8000
*/
uint16_t max_virtqueue_pairs;
+ /* Default maximum transmit unit advice */
+ uint16_t mtu;
} QEMU_PACKED;
/*
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [RFC 2/4] vhost-user: Add new protocol feature MTU
2016-09-06 16:11 [Qemu-devel] [RFC 0/4] virtio-net: Add support to MTU feature Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 1/4] virtio-net: reuse MTU related bits from Linux header Maxime Coquelin
@ 2016-09-06 16:11 ` Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 3/4] vhost-net: Add new MTU feature support Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 4/4] virtio-net: Add " Maxime Coquelin
3 siblings, 0 replies; 7+ messages in thread
From: Maxime Coquelin @ 2016-09-06 16:11 UTC (permalink / raw)
To: mst, qemu-devel; +Cc: jasowang, Maxime Coquelin, Aaron Conole
This patch adds VHOST_USER_PROTOCOL_F_MTU protocol feature.
If supported, QEMU sends VHOST_USER_GET_MTU request to the client,
and expects a u64 reply containing the MTU advised for the guest.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Aaron Conole <aconole@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
hw/virtio/vhost-user.c | 11 +++++++++++
include/hw/virtio/vhost.h | 1 +
2 files changed, 12 insertions(+)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index b57454a..d72dd37 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -32,6 +32,7 @@ enum VhostUserProtocolFeature {
VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
VHOST_USER_PROTOCOL_F_RARP = 2,
VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
+ VHOST_USER_PROTOCOL_F_MTU = 4,
VHOST_USER_PROTOCOL_F_MAX
};
@@ -59,6 +60,7 @@ typedef enum VhostUserRequest {
VHOST_USER_GET_QUEUE_NUM = 17,
VHOST_USER_SET_VRING_ENABLE = 18,
VHOST_USER_SEND_RARP = 19,
+ VHOST_USER_GET_MTU = 20,
VHOST_USER_MAX
} VhostUserRequest;
@@ -186,6 +188,7 @@ static bool vhost_user_one_time_request(VhostUserRequest request)
case VHOST_USER_RESET_OWNER:
case VHOST_USER_SET_MEM_TABLE:
case VHOST_USER_GET_QUEUE_NUM:
+ case VHOST_USER_GET_MTU:
return true;
default:
return false;
@@ -602,6 +605,14 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
return err;
}
}
+
+ /* query the MTU we support if backend supports MTU feature */
+ if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MTU)) {
+ err = vhost_user_get_u64(dev, VHOST_USER_GET_MTU, &dev->mtu);
+ if (err < 0) {
+ return err;
+ }
+ }
}
if (dev->migration_blocker == NULL &&
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index e433089..99c8d9b 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -50,6 +50,7 @@ struct vhost_dev {
uint64_t backend_features;
uint64_t protocol_features;
uint64_t max_queues;
+ uint64_t mtu;
bool started;
bool log_enabled;
uint64_t log_size;
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [RFC 3/4] vhost-net: Add new MTU feature support
2016-09-06 16:11 [Qemu-devel] [RFC 0/4] virtio-net: Add support to MTU feature Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 1/4] virtio-net: reuse MTU related bits from Linux header Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 2/4] vhost-user: Add new protocol feature MTU Maxime Coquelin
@ 2016-09-06 16:11 ` Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 4/4] virtio-net: Add " Maxime Coquelin
3 siblings, 0 replies; 7+ messages in thread
From: Maxime Coquelin @ 2016-09-06 16:11 UTC (permalink / raw)
To: mst, qemu-devel; +Cc: jasowang, Maxime Coquelin, Aaron Conole
If VHOST_USER_F_MTU feature is negociated, vhost-net makes the
advised MTU available to virtio-net through a vhost_net_get_mtu()
call.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Aaron Conole <aconole@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
hw/net/vhost_net.c | 11 +++++++++++
include/net/vhost_net.h | 2 ++
2 files changed, 13 insertions(+)
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index f2d49ad..21057d6 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -74,6 +74,7 @@ static const int user_feature_bits[] = {
VIRTIO_NET_F_HOST_ECN,
VIRTIO_NET_F_HOST_UFO,
VIRTIO_NET_F_MRG_RXBUF,
+ VIRTIO_NET_F_MTU,
/* This bit implies RARP isn't sent by QEMU out of band */
VIRTIO_NET_F_GUEST_ANNOUNCE,
@@ -435,6 +436,11 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
return 0;
}
+uint64_t vhost_net_get_mtu(struct vhost_net *net)
+{
+ return net->dev.mtu;
+}
+
#else
uint64_t vhost_net_get_max_queues(VHostNetState *net)
{
@@ -501,4 +507,9 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
{
return 0;
}
+
+uint64_t vhost_net_get_mtu(struct vhost_net *net)
+{
+ return 0;
+}
#endif
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 5a08eff..37de17b 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -35,4 +35,6 @@ int vhost_set_vring_enable(NetClientState * nc, int enable);
uint64_t vhost_net_get_acked_features(VHostNetState *net);
+uint64_t vhost_net_get_mtu(struct vhost_net *net);
+
#endif
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [RFC 4/4] virtio-net: Add MTU feature support
2016-09-06 16:11 [Qemu-devel] [RFC 0/4] virtio-net: Add support to MTU feature Maxime Coquelin
` (2 preceding siblings ...)
2016-09-06 16:11 ` [Qemu-devel] [RFC 3/4] vhost-net: Add new MTU feature support Maxime Coquelin
@ 2016-09-06 16:11 ` Maxime Coquelin
2016-09-15 22:16 ` Paolo Bonzini
3 siblings, 1 reply; 7+ messages in thread
From: Maxime Coquelin @ 2016-09-06 16:11 UTC (permalink / raw)
To: mst, qemu-devel; +Cc: jasowang, Maxime Coquelin, Aaron Conole
If negociated, virtio-net gets the advised MTU from vhost-net,
and provides it to the guest through a new virtio_net_config
entry.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Aaron Conole <aconole@redhat.com
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
hw/net/virtio-net.c | 16 ++++++++++++++++
include/hw/virtio/virtio-net.h | 1 +
2 files changed, 17 insertions(+)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 01f1351..0974d87 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -50,6 +50,8 @@ static VirtIOFeature feature_sizes[] = {
.end = endof(struct virtio_net_config, status)},
{.flags = 1 << VIRTIO_NET_F_MQ,
.end = endof(struct virtio_net_config, max_virtqueue_pairs)},
+ {.flags = 1 << VIRTIO_NET_F_MTU,
+ .end = endof(struct virtio_net_config, mtu)},
{}
};
@@ -74,6 +76,10 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
VirtIONet *n = VIRTIO_NET(vdev);
struct virtio_net_config netcfg;
+ if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_MTU)) {
+ virtio_stw_p(vdev, &netcfg.mtu, n->mtu);
+ }
+
virtio_stw_p(vdev, &netcfg.status, n->status);
virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues);
memcpy(netcfg.mac, n->mac, ETH_ALEN);
@@ -526,6 +532,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
features |= n->host_features;
virtio_add_feature(&features, VIRTIO_NET_F_MAC);
+ virtio_add_feature(&features, VIRTIO_NET_F_MTU);
if (!peer_has_vnet_hdr(n)) {
virtio_clear_feature(&features, VIRTIO_NET_F_CSUM);
@@ -627,6 +634,14 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
} else {
memset(n->vlans, 0xff, MAX_VLAN >> 3);
}
+
+ if (virtio_has_feature(features, VIRTIO_NET_F_MTU)) {
+ NetClientState *nc = qemu_get_queue(n->nic);
+
+ if (get_vhost_net(nc->peer)) {
+ n->mtu = vhost_net_get_mtu(get_vhost_net(nc->peer));
+ }
+ }
}
static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
@@ -1688,6 +1703,7 @@ static void virtio_net_set_config_size(VirtIONet *n, uint64_t host_features)
{
int i, config_size = 0;
virtio_add_feature(&host_features, VIRTIO_NET_F_MAC);
+ virtio_add_feature(&host_features, VIRTIO_NET_F_MTU);
for (i = 0; feature_sizes[i].flags != 0; i++) {
if (host_features & feature_sizes[i].flags) {
config_size = MAX(feature_sizes[i].end, config_size);
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 91ed97c..13b2a8d 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -95,6 +95,7 @@ typedef struct VirtIONet {
QEMUTimer *announce_timer;
int announce_counter;
bool needs_vnet_hdr_swap;
+ uint16_t mtu;
} VirtIONet;
void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [RFC 4/4] virtio-net: Add MTU feature support
2016-09-06 16:11 ` [Qemu-devel] [RFC 4/4] virtio-net: Add " Maxime Coquelin
@ 2016-09-15 22:16 ` Paolo Bonzini
2016-09-16 6:36 ` Maxime Coquelin
0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2016-09-15 22:16 UTC (permalink / raw)
To: Maxime Coquelin, mst, qemu-devel; +Cc: jasowang, Aaron Conole
On 06/09/2016 18:11, Maxime Coquelin wrote:
> VirtIONet *n = VIRTIO_NET(vdev);
> struct virtio_net_config netcfg;
>
> + if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_MTU)) {
> + virtio_stw_p(vdev, &netcfg.mtu, n->mtu);
> + }
This write needs to be unconditional, otherwise you are leaking a few
bytes of QEMU's stack (corresponding to netcfg.mtu) to the guest.
Paolo
> virtio_stw_p(vdev, &netcfg.status, n->status);
> virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues);
> memcpy(netcfg.mac, n->mac, ETH_ALEN);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [RFC 4/4] virtio-net: Add MTU feature support
2016-09-15 22:16 ` Paolo Bonzini
@ 2016-09-16 6:36 ` Maxime Coquelin
0 siblings, 0 replies; 7+ messages in thread
From: Maxime Coquelin @ 2016-09-16 6:36 UTC (permalink / raw)
To: Paolo Bonzini, mst, qemu-devel; +Cc: jasowang, Aaron Conole
On 09/16/2016 12:16 AM, Paolo Bonzini wrote:
>
>
> On 06/09/2016 18:11, Maxime Coquelin wrote:
>> VirtIONet *n = VIRTIO_NET(vdev);
>> struct virtio_net_config netcfg;
>>
>> + if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_MTU)) {
>> + virtio_stw_p(vdev, &netcfg.mtu, n->mtu);
>> + }
>
> This write needs to be unconditional, otherwise you are leaking a few
> bytes of QEMU's stack (corresponding to netcfg.mtu) to the guest.
Right, thanks for pointing this out. I'll make it unconditional.
Maxime
> Paolo
>
>> virtio_stw_p(vdev, &netcfg.status, n->status);
>> virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues);
>> memcpy(netcfg.mac, n->mac, ETH_ALEN);
^ permalink raw reply [flat|nested] 7+ messages in thread