qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Aaron Conole <aconole@redhat.com>
Subject: [Qemu-devel] [PULL 29/41] vhost-user: Add MTU protocol feature and op
Date: Tue, 10 Jan 2017 07:40:33 +0200	[thread overview]
Message-ID: <1484026704-28027-30-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1484026704-28027-1-git-send-email-mst@redhat.com>

From: Maxime Coquelin <maxime.coquelin@redhat.com>

This patch implements VHOST_USER_PROTOCOL_F_NET_MTU
protocol feature and VHOST_USER_NET_SET_MTU request so
that the backend gets notified of the user defined host
MTU.

If backend supports VHOST_USER_PROTOCOL_F_REPLY_ACK,
QEMU assumes MTU is valid if success is returned.

Vhost-net driver sends this request through a new
vhost_net_set_mtu vhost_ops entry.

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Aaron Conole <aconole@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 docs/specs/vhost-user.txt         | 16 ++++++++++++++++
 include/hw/virtio/vhost-backend.h |  2 ++
 hw/virtio/vhost-user.c            | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)

diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index d70bd83..036890f 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -259,6 +259,7 @@ Protocol features
 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD      1
 #define VHOST_USER_PROTOCOL_F_RARP           2
 #define VHOST_USER_PROTOCOL_F_REPLY_ACK      3
+#define VHOST_USER_PROTOCOL_F_MTU            4
 
 Message types
 -------------
@@ -470,6 +471,21 @@ Message types
       The first 6 bytes of the payload contain the mac address of the guest to
       allow the vhost user backend to construct and broadcast the fake RARP.
 
+ * VHOST_USER_NET_SET_MTU
+
+      Id: 20
+      Equivalent ioctl: N/A
+      Master payload: u64
+
+      Set host MTU value exposed to the guest.
+      This request should be sent only when VIRTIO_NET_F_MTU feature has been
+      successfully negotiated, VHOST_USER_F_PROTOCOL_FEATURES is present in
+      VHOST_USER_GET_FEATURES and protocol feature bit
+      VHOST_USER_PROTOCOL_F_NET_MTU is present in
+      VHOST_USER_GET_PROTOCOL_FEATURES.
+      If VHOST_USER_PROTOCOL_F_REPLY_ACK is negotiated, slave must respond
+      with zero in case the specified MTU is valid, or non-zero otherwise.
+
 VHOST_USER_PROTOCOL_F_REPLY_ACK:
 -------------------------------
 The original vhost-user specification only demands replies for certain
diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
index 6e90703..30abc11 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -32,6 +32,7 @@ typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
 
 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev,
                                 struct vhost_vring_file *file);
+typedef int (*vhost_net_set_mtu_op)(struct vhost_dev *dev, uint16_t mtu);
 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev,
                                   struct vhost_scsi_target *target);
 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev,
@@ -83,6 +84,7 @@ typedef struct VhostOps {
     vhost_backend_cleanup vhost_backend_cleanup;
     vhost_backend_memslots_limit vhost_backend_memslots_limit;
     vhost_net_set_backend_op vhost_net_set_backend;
+    vhost_net_set_mtu_op vhost_net_set_mtu;
     vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint;
     vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint;
     vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version;
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 7ee92b3..9334a8a 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_NET_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_NET_SET_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_NET_SET_MTU:
         return true;
     default:
         return false;
@@ -685,6 +688,36 @@ static bool vhost_user_can_merge(struct vhost_dev *dev,
     return mfd == rfd;
 }
 
+static int vhost_user_net_set_mtu(struct vhost_dev *dev, uint16_t mtu)
+{
+    VhostUserMsg msg;
+    bool reply_supported = virtio_has_feature(dev->protocol_features,
+                                              VHOST_USER_PROTOCOL_F_REPLY_ACK);
+
+    if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU))) {
+        return 0;
+    }
+
+    msg.request = VHOST_USER_NET_SET_MTU;
+    msg.payload.u64 = mtu;
+    msg.size = sizeof(msg.payload.u64);
+    msg.flags = VHOST_USER_VERSION;
+    if (reply_supported) {
+        msg.flags |= VHOST_USER_NEED_REPLY_MASK;
+    }
+
+    if (vhost_user_write(dev, &msg, NULL, 0) < 0) {
+        return -1;
+    }
+
+    /* If reply_ack supported, slave has to ack specified MTU is valid */
+    if (reply_supported) {
+        return process_message_reply(dev, msg.request);
+    }
+
+    return 0;
+}
+
 const VhostOps user_ops = {
         .backend_type = VHOST_BACKEND_TYPE_USER,
         .vhost_backend_init = vhost_user_init,
@@ -708,4 +741,5 @@ const VhostOps user_ops = {
         .vhost_requires_shm_log = vhost_user_requires_shm_log,
         .vhost_migration_done = vhost_user_migration_done,
         .vhost_backend_can_merge = vhost_user_can_merge,
+        .vhost_net_set_mtu = vhost_user_net_set_mtu,
 };
-- 
MST

  parent reply	other threads:[~2017-01-10  5:40 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10  5:39 [Qemu-devel] [PULL 00/41] virtio, vhost, pc: fixes, features Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 01/41] migration: allow to prioritize save state entries Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 02/41] intel_iommu: allow migration Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 03/41] virtio-crypto: fix possible integer and heap overflow Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 04/41] virtio: convert to use DMA api Michael S. Tsirkin
2017-01-18 11:59   ` Paolo Bonzini
2017-01-18 19:10     ` Michael S. Tsirkin
2017-01-19  9:05       ` Paolo Bonzini
2017-01-10  5:39 ` [Qemu-devel] [PULL 05/41] intel_iommu: name vtd address space with devfn Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 06/41] intel_iommu: allocate new key when creating new address space Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 07/41] exec: introduce address_space_get_iotlb_entry() Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 08/41] intel_iommu: support device iotlb descriptor Michael S. Tsirkin
2017-01-18 12:19   ` Paolo Bonzini
2017-01-19  2:50     ` Jason Wang
2017-01-19  3:28       ` Peter Xu
2017-01-19  3:35         ` Jason Wang
2017-01-19  3:32       ` Jason Wang
2017-01-19  9:07         ` Paolo Bonzini
2017-02-16  5:36   ` Liu, Yi L
2017-02-16  5:43     ` Jason Wang
2017-02-16  5:59       ` Jason Wang
2017-02-17  6:18       ` Liu, Yi L
2017-02-17  6:43         ` Jason Wang
2017-02-20  8:27           ` Liu, Yi L
2017-02-20  9:03             ` Jason Wang
2017-02-20  9:13               ` Liu, Yi L
2017-02-20  9:18                 ` Jason Wang
2017-02-17  3:26     ` Peter Xu
2017-02-17  6:36       ` Liu, Yi L
2017-02-17  7:00         ` Peter Xu
2017-02-20  8:47           ` Liu, Yi L
2017-01-10  5:39 ` [Qemu-devel] [PULL 09/41] virtio-pci: address space translation service (ATS) support Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 10/41] acpi: add ATSR for q35 Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 11/41] memory: handle alias for iommu notifier Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 12/41] memory: handle alias in memory_region_is_iommu() Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 13/41] doc/pcie: correct command line examples Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 14/41] virtio-crypto: use the correct length for cipher operation Michael S. Tsirkin
2017-01-10  5:39 ` [Qemu-devel] [PULL 15/41] cryptodev: introduce a new is_used property Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 16/41] cryptodev: wrap the ready flag Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 17/41] virtio-crypto-pci: add check for cryptodev object Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 18/41] virtio-crypto: avoid one cryptodev device is used by multiple virtio crypto devices Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 19/41] virtio-crypto-pci: tag virtio-crypto device hot pluggable Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 20/41] virtio-crypto: zeroize the key material before free Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 21/41] pcie_aer: Convert pcie_aer_init to Error Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 22/41] pcie_aer: support configurable AER capa version Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 23/41] virtio: fix vq->inuse recalc after migr Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 24/41] balloon: Don't balloon roms Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 25/41] net: Add virtio queue interface to update used index from vring state Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 26/41] net: vhost stop updates virtio queue state Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 27/41] virtio: Introduce virtqueue_drop_all procedure Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 28/41] net: virtio-net discards TX data after link down Michael S. Tsirkin
2017-01-10  5:40 ` Michael S. Tsirkin [this message]
2017-01-10  5:40 ` [Qemu-devel] [PULL 30/41] vhost-net: Notify the backend about the host MTU Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 31/41] virtio-net: Add MTU feature support Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 32/41] tests: pc: add memory hotplug acpi tables tests Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 33/41] memhp: move build_memory_hotplug_aml() into memory_hotplug.c Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 34/41] memhp: move build_memory_devices() " Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 35/41] memhp: consolidate scattered MHPD device declaration Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 36/41] memhp: merge build_memory_devices() into build_memory_hotplug_aml() Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 37/41] memhp: move GPE handler_E03 " Michael S. Tsirkin
2017-01-10  5:40 ` [Qemu-devel] [PULL 38/41] memhp: move memory hotplug only defines to memory_hotplug.c Michael S. Tsirkin
2017-01-10  5:41 ` [Qemu-devel] [PULL 39/41] memhp: don't generate memory hotplug AML if it's not enabled/supported Michael S. Tsirkin
2017-01-10  5:41 ` [Qemu-devel] [PULL 40/41] memhp: move DIMM devices into dedicated scope with related common methods Michael S. Tsirkin
2017-01-10  5:41 ` [Qemu-devel] [PULL 41/41] acpi-test: update expected files Michael S. Tsirkin
2017-01-10 14:52 ` [Qemu-devel] [PULL 00/41] virtio, vhost, pc: fixes, features Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484026704-28027-30-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=aconole@redhat.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).