vhost: support MTU protocol feature
This patch implements the vhost-user MTU protocol feature support. When VIRTIO_NET_F_MTU is negotiated, QEMU notifies the vhost-user backend with the configured MTU if dedicated protocol feature is supported. The value can be used by the application to ensure consistency with value set by the user. Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com> Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
This commit is contained in:
parent
3d3c6590b5
commit
23f1e756ca
@ -160,6 +160,7 @@ struct virtio_net {
|
|||||||
uint64_t log_base;
|
uint64_t log_base;
|
||||||
uint64_t log_addr;
|
uint64_t log_addr;
|
||||||
struct ether_addr mac;
|
struct ether_addr mac;
|
||||||
|
uint16_t mtu;
|
||||||
|
|
||||||
uint32_t nr_guest_pages;
|
uint32_t nr_guest_pages;
|
||||||
uint32_t max_guest_pages;
|
uint32_t max_guest_pages;
|
||||||
|
@ -51,6 +51,9 @@
|
|||||||
#include "vhost.h"
|
#include "vhost.h"
|
||||||
#include "vhost_user.h"
|
#include "vhost_user.h"
|
||||||
|
|
||||||
|
#define VIRTIO_MIN_MTU 68
|
||||||
|
#define VIRTIO_MAX_MTU 65535
|
||||||
|
|
||||||
static const char *vhost_message_str[VHOST_USER_MAX] = {
|
static const char *vhost_message_str[VHOST_USER_MAX] = {
|
||||||
[VHOST_USER_NONE] = "VHOST_USER_NONE",
|
[VHOST_USER_NONE] = "VHOST_USER_NONE",
|
||||||
[VHOST_USER_GET_FEATURES] = "VHOST_USER_GET_FEATURES",
|
[VHOST_USER_GET_FEATURES] = "VHOST_USER_GET_FEATURES",
|
||||||
@ -72,6 +75,7 @@ static const char *vhost_message_str[VHOST_USER_MAX] = {
|
|||||||
[VHOST_USER_GET_QUEUE_NUM] = "VHOST_USER_GET_QUEUE_NUM",
|
[VHOST_USER_GET_QUEUE_NUM] = "VHOST_USER_GET_QUEUE_NUM",
|
||||||
[VHOST_USER_SET_VRING_ENABLE] = "VHOST_USER_SET_VRING_ENABLE",
|
[VHOST_USER_SET_VRING_ENABLE] = "VHOST_USER_SET_VRING_ENABLE",
|
||||||
[VHOST_USER_SEND_RARP] = "VHOST_USER_SEND_RARP",
|
[VHOST_USER_SEND_RARP] = "VHOST_USER_SEND_RARP",
|
||||||
|
[VHOST_USER_NET_SET_MTU] = "VHOST_USER_NET_SET_MTU",
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint64_t
|
static uint64_t
|
||||||
@ -852,6 +856,22 @@ vhost_user_send_rarp(struct virtio_net *dev, struct VhostUserMsg *msg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vhost_user_net_set_mtu(struct virtio_net *dev, struct VhostUserMsg *msg)
|
||||||
|
{
|
||||||
|
if (msg->payload.u64 < VIRTIO_MIN_MTU ||
|
||||||
|
msg->payload.u64 > VIRTIO_MAX_MTU) {
|
||||||
|
RTE_LOG(ERR, VHOST_CONFIG, "Invalid MTU size (%"PRIu64")\n",
|
||||||
|
msg->payload.u64);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev->mtu = msg->payload.u64;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* return bytes# of read on success or negative val on failure. */
|
/* return bytes# of read on success or negative val on failure. */
|
||||||
static int
|
static int
|
||||||
read_vhost_message(int sockfd, struct VhostUserMsg *msg)
|
read_vhost_message(int sockfd, struct VhostUserMsg *msg)
|
||||||
@ -1062,6 +1082,10 @@ vhost_user_msg_handler(int vid, int fd)
|
|||||||
vhost_user_send_rarp(dev, &msg);
|
vhost_user_send_rarp(dev, &msg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case VHOST_USER_NET_SET_MTU:
|
||||||
|
ret = vhost_user_net_set_mtu(dev, &msg);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
|
@ -47,11 +47,13 @@
|
|||||||
#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
|
#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
|
||||||
#define VHOST_USER_PROTOCOL_F_RARP 2
|
#define VHOST_USER_PROTOCOL_F_RARP 2
|
||||||
#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
|
#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
|
||||||
|
#define VHOST_USER_PROTOCOL_F_NET_MTU 4
|
||||||
|
|
||||||
#define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
|
#define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
|
||||||
(1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\
|
(1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\
|
||||||
(1ULL << VHOST_USER_PROTOCOL_F_RARP) | \
|
(1ULL << VHOST_USER_PROTOCOL_F_RARP) | \
|
||||||
(1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK))
|
(1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
|
||||||
|
(1ULL << VHOST_USER_PROTOCOL_F_NET_MTU))
|
||||||
|
|
||||||
typedef enum VhostUserRequest {
|
typedef enum VhostUserRequest {
|
||||||
VHOST_USER_NONE = 0,
|
VHOST_USER_NONE = 0,
|
||||||
@ -74,6 +76,7 @@ typedef enum VhostUserRequest {
|
|||||||
VHOST_USER_GET_QUEUE_NUM = 17,
|
VHOST_USER_GET_QUEUE_NUM = 17,
|
||||||
VHOST_USER_SET_VRING_ENABLE = 18,
|
VHOST_USER_SET_VRING_ENABLE = 18,
|
||||||
VHOST_USER_SEND_RARP = 19,
|
VHOST_USER_SEND_RARP = 19,
|
||||||
|
VHOST_USER_NET_SET_MTU = 20,
|
||||||
VHOST_USER_MAX
|
VHOST_USER_MAX
|
||||||
} VhostUserRequest;
|
} VhostUserRequest;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user