Skip to contentSkip to conversation

tools: propogate MTU to vif frontends

PATCH In review Paul Durrant 3 participants 12 messages Aug 11, 2020 – Aug 28, 2020

lore
Share & tools
lore
#0 lore raw

v3 cover tools: propogate MTU to vif frontends

From: Paul Durrant <[email protected]>

This is an expansion from v2 of the series to include the facility to set the MTU in the vif config.

There is also one cleanup patch to remove the defunct 'vif2' script.

Paul Durrant (8):
public/io/netif: specify MTU override node tools/hotplug/Linux: re-factor add_to_bridge() in
xen-network-common.sh
tools/hotplug/Linux: add remove_from_bridge() tools/hotplug/Linux: remove code duplication in vif-bridge
libxl: wire the libxl_device_nic 'mtu' value into xenstore tools/hotplug/Linux: modify set_mtu() to optionally use a configured

    value...

xl: add 'mtu' option to network configuration remove netchannel2 hotplug script... ancient history

 docs/man/xl-network-configuration.5.pod   |  6 +++
 docs/misc/xenstore-paths.pandoc           |  3 ++
 tools/hotplug/Linux/Makefile              |  1 -
 tools/hotplug/Linux/vif-bridge            | 20 +++----
 tools/hotplug/Linux/vif2                  | 54 -------------------
 tools/hotplug/Linux/xen-network-common.sh | 65 +++++++++++++++++++----
 tools/libxl/libxl_nic.c                   | 27 +++++++++-
 tools/xl/xl_cmdtable.c                    |  2 +-
 tools/xl/xl_parse.c                       |  2 +
 xen/include/public/io/netif.h             | 12 +++++
 10 files changed, 110 insertions(+), 82 deletions(-)
 delete mode 100644 tools/hotplug/Linux/vif2

---
Cc: Andrew Cooper <[email protected]>
Cc: Anthony PERARD <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>

Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 1/8 public/io/netif: specify MTU override node

From: Paul Durrant <[email protected]>

There is currently no documentation to state what MTU a frontend should adertise to its network stack. It has however long been assumed that the default value of 1500 is correct.

This patch specifies a mechanism to allow the tools to set the MTU via a xenstore node in the frontend area and states that the absence of that node means the frontend should assume an MTU of 1500 octets.

NOTE: The Windows PV frontend has used an MTU sampled from the xenstore
node specified in this patch.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>

v2:
- Add a note in xenstore-paths highlighting the new xenstore node

---
 docs/misc/xenstore-paths.pandoc |  3 +++
 xen/include/public/io/netif.h   | 12 ++++++++++++
 2 files changed, 15 insertions(+)
docs/misc/xenstore-paths.pandoc +3 -0
index 766e8008dc..5cd5c8a3b9 100644
@@ -298,6 +298,9 @@ A virtual keyboard device frontend. Described by
 A virtual network device frontend. Described by
 [xen/include/public/io/netif.h][NETIF]
 
+NOTE: ~/device/vif/$DEVID/mtu can be used to inform the frontend of an
+      increased MTU. (The default MTU is 1500 octets).
+
 #### ~/device/vscsi/$DEVID/* []
 
 A virtual scsi device frontend. Described by
xen/include/public/io/netif.h +12 -0
index 9fcf91a2fe..00dd258712 100644
@@ -204,6 +204,18 @@
  * present).
  */
 
+/*
+ * MTU
+ * ===
+ *
+ * The toolstack may set a value of MTU for the frontend by setting the
+ * /local/domain/<domid>/device/vif/<vif>/mtu node with the MTU value in
+ * octets. If this node is absent the frontend should assume an MTU value
+ * of 1500 octets. A frontend is also at liberty to ignore this value so
+ * it is only suitable for informing the frontend that a packet payload
+ * >1500 octets is permitted.
+ */
+
 /*
  * Hash types
  * ==========
Signature · 1 line
2.20.1
Acked-by on v3 1/8
#2 lore raw

Re: [PATCH v3 1/8] public/io/netif: specify MTU override node

Quoted 10 lines · Paul Durrant

From: Paul Durrant <[email protected]>

There is currently no documentation to state what MTU a frontend should adertise to its network stack. It has however long been assumed that the default value of 1500 is correct.

This patch specifies a mechanism to allow the tools to set the MTU via a xenstore node in the frontend area and states that the absence of that node means the frontend should assume an MTU of 1500 octets.

Quoted 6 lines

NOTE: The Windows PV frontend has used an MTU sampled from the xenstore
node specified in this patch.

#3 lore raw

PATCH v3 2/8 tools/hotplug/Linux: re-factor add_to_bridge() in xen-network-common.sh

In reply to Paul Durrant

From: Paul Durrant <[email protected]>

Remove duplication of 'ip link set dev'. It is perfectly fine to call it even if the device has already been added to the bridge.

NOTE: This patch also adds code to write a debug log entry if the device
was already on the bridge.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
- Re-factored from "tools/hotplug: add remove_from_bridge() and improve debug output" in v2

---
 tools/hotplug/Linux/xen-network-common.sh | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
tools/hotplug/Linux/xen-network-common.sh +10 -8
index 8dd3a62068..ec3bd4ec4a 100644
@@ -126,16 +126,18 @@ add_to_bridge () {
     local bridge=$1
     local dev=$2
 
-    # Don't add $dev to $bridge if it's already on a bridge.
-    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
-	ip link set dev ${dev} up || true
-	return
-    fi
-    if which brctl >&/dev/null; then
-        brctl addif ${bridge} ${dev}
+    # Don't add $dev to $bridge if it's already on the bridge.
+    if [ ! -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
+        log debug "adding $dev to bridge $bridge"
+        if which brctl >&/dev/null; then
+            brctl addif ${bridge} ${dev}
+        else
+            ip link set ${dev} master ${bridge}
+        fi
     else
-        ip link set ${dev} master ${bridge}
+        log debug "$dev already on bridge $bridge"
     fi
+
     ip link set dev ${dev} up
 }
 
Signature · 1 line
2.20.1
#4 lore raw

PATCH v3 3/8 tools/hotplug/Linux: add remove_from_bridge()

In reply to Paul Durrant

From: Paul Durrant <[email protected]>

This patch adds a remove_from_bridge() function into xen-network-common.sh to partner with the existing add_to_bridge() function. The vif-bridge script is then modified to use it.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
- Re-factored from "tools/hotplug: add remove_from_bridge() and improve debug output" and "tools/hotplug: combine add/online and remove/offline in vif-bridge..." in v2

---
 tools/hotplug/Linux/vif-bridge            |  7 +------
 tools/hotplug/Linux/xen-network-common.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)
tools/hotplug/Linux/vif-bridge +1 -6
index e722090ca8..c3e409926d 100644
@@ -84,12 +84,7 @@ case "$command" in
         ;;
 
     offline)
-        if which brctl >&/dev/null; then
-            do_without_error brctl delif "$bridge" "$dev"
-        else
-            do_without_error ip link set "$dev" nomaster
-        fi
-        do_without_error ifconfig "$dev" down
+        remove_from_bridge "$bridge" "$dev"
         ;;
 
     add)
tools/hotplug/Linux/xen-network-common.sh +19 -0
index ec3bd4ec4a..6a0904361f 100644
@@ -141,6 +141,25 @@ add_to_bridge () {
     ip link set dev ${dev} up
 }
 
+remove_from_bridge () {
+    local bridge=$1
+    local dev=$2
+
+    do_without_error ip link set dev ${dev} down
+
+    # Don't remove $dev from $bridge if it's not on the bridge.
+    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
+        log debug "removing $dev from bridge $bridge"
+        if which brctl >&/dev/null; then
+            do_without_error brctl delif ${bridge} ${dev}
+        else
+            do_without_error ip link set ${dev} nomaster
+        fi
+    else
+        log debug "$dev not on bridge $bridge"
+    fi
+}
+
 # Usage: set_mtu bridge dev
 set_mtu () {
     local bridge=$1
Signature · 1 line
2.20.1
#5 lore raw

PATCH v3 4/8 tools/hotplug/Linux: remove code duplication in vif-bridge

In reply to Paul Durrant

From: Paul Durrant <[email protected]>

The 'add' and 'online' cases do exactly the same thing so have 'add' simply fall through to 'online'.

NOTE: This patch also adds in the missing 'remove' case, which falls though
to 'offline'. (The former is passed for 'tap' devices, the latter for 'vif' devices).

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
- Re-factored from "tools/hotplug: combine add/online and remove/offline in vif-bridge..." in v2

---
 tools/hotplug/Linux/vif-bridge | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
tools/hotplug/Linux/vif-bridge +4 -7
index c3e409926d..e1d7c49788 100644
@@ -77,21 +77,18 @@ then
 fi
 
 case "$command" in
+    add)
+        ;&
     online)
         setup_virtual_bridge_port "$dev"
         set_mtu "$bridge" "$dev"
         add_to_bridge "$bridge" "$dev"
         ;;
-
+    remove)
+        ;&
     offline)
         remove_from_bridge "$bridge" "$dev"
         ;;
-
-    add)
-        setup_virtual_bridge_port "$dev"
-        set_mtu "$bridge" "$dev"
-        add_to_bridge "$bridge" "$dev"
-        ;;
 esac
 
 handle_iptable
Signature · 1 line
2.20.1
#6 lore raw

PATCH v3 5/8 libxl: wire the libxl_device_nic 'mtu' value into xenstore

In reply to Paul Durrant

From: Paul Durrant <[email protected]>

Currently the 'mtu' field of libxl_device_nic objects is effectively ignored:
It is set by libxl__device_nic_setdefault() to a slightly odd default value of 1492 but otherwise ignored.

This patch changes the default value to a more conventional 1500 and modifies libxl__set_xenstore_nic() to write the value into an 'mtu' node in the xenstore backend area (if it is a non-default value), as well as a read-only node of the same name in the frontend area.

The backend node is used to set the value of 'mtu' in libxl__nic_from_xenstore(), when retrieving the configuration.

NOTE: There is currently no way to set a non-default value of 'mtu', hence
the backend node is never written. This, however, will be addressed by a subsequent patch.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>

v3:
- New in v3

---
 tools/libxl/libxl_nic.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
tools/libxl/libxl_nic.c +25 -2
index 07880b39e1..0e5d120ae9 100644
@@ -53,13 +53,15 @@ int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
     return rc;
 }
 
+#define LIBXL_DEVICE_NIC_MTU_DEFAULT 1500
+
 static int libxl__device_nic_setdefault(libxl__gc *gc, uint32_t domid,
                                         libxl_device_nic *nic, bool hotplug)
 {
     int rc;
 
     if (!nic->mtu)
-        nic->mtu = 1492;
+        nic->mtu = LIBXL_DEVICE_NIC_MTU_DEFAULT;
     if (!nic->model) {
         nic->model = strdup("rtl8139");
         if (!nic->model) return ERROR_NOMEM;
@@ -223,6 +225,11 @@ static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid,
                             nic->rate_interval_usecs));
     }
 
+    if (nic->mtu != LIBXL_DEVICE_NIC_MTU_DEFAULT) {
+        flexarray_append(back, "mtu");
+        flexarray_append(back, GCSPRINTF("%u", nic->mtu));
+    }
+    
     flexarray_append(back, "bridge");
     flexarray_append(back, libxl__strdup(gc, nic->bridge));
     flexarray_append(back, "handle");
@@ -237,6 +244,9 @@ static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid,
     flexarray_append(front, GCSPRINTF(
                                     LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
 
+    flexarray_append(ro_front, "mtu");
+    flexarray_append(ro_front, GCSPRINTF("%u", nic->mtu));
+
     return 0;
 }
 
@@ -275,7 +285,20 @@ static int libxl__nic_from_xenstore(libxl__gc *gc, const char *libxl_path,
     rc = libxl__backendpath_parse_domid(gc, tmp, &nic->backend_domid);
     if (rc) goto out;
 
-    /* nic->mtu = */
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+                                GCSPRINTF("%s/mtu", libxl_path), &tmp);
+    if (rc) goto out;
+    if (tmp) {
+        char *endptr;
+
+        nic->mtu = strtol(tmp, &endptr, 10);
+        if (*endptr != '\0') {
+            rc = ERROR_INVAL;
+            goto out;
+        }
+    } else {
+        nic->mtu = LIBXL_DEVICE_NIC_MTU_DEFAULT;
+    }
 
     rc = libxl__xs_read_checked(gc, XBT_NULL,
                                 GCSPRINTF("%s/mac", libxl_path), &tmp);
Signature · 1 line
2.20.1
#7 lore raw

PATCH v3 6/8 tools/hotplug/Linux: modify set_mtu() to optionally use a configured value...

In reply to Paul Durrant

From: Paul Durrant <[email protected]>

...and also inform the frontend.

The set_mtu() function in xen-network-common.sh currently sets the backend vif MTU to match that of the bridge.

A prior patch added code into libxl such that a tools-configured 'mtu' value may be present in the xenstore backend area. If the node is present in xenstore then it should be authoritative. Hence set_mtu() is modified to only read the MTU of the bridge if it is not present.

The function is also modified to write whatever value it applies to the backend vif into the xenstore frontend area where is may then be used to configure the frontend network stack.

NOTE: There is also a small modification replacing '$mtu' with '${mtu}'
for style consistency.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
- Re-factored from "tools/hotplug: modify set_mtu() to inform the frontend via xenstore" in v2

---
 tools/hotplug/Linux/vif-bridge            |  2 +-
 tools/hotplug/Linux/xen-network-common.sh | 28 +++++++++++++++++++++--
 2 files changed, 27 insertions(+), 3 deletions(-)
tools/hotplug/Linux/vif-bridge +1 -1
index e1d7c49788..b99cc82a21 100644
@@ -81,7 +81,7 @@ case "$command" in
         ;&
     online)
         setup_virtual_bridge_port "$dev"
-        set_mtu "$bridge" "$dev"
+        set_mtu "$bridge" "$dev" "$type_if"
         add_to_bridge "$bridge" "$dev"
         ;;
     remove)
tools/hotplug/Linux/xen-network-common.sh +26 -2
index 6a0904361f..82ee70aab4 100644
@@ -164,9 +164,33 @@ remove_from_bridge () {
 set_mtu () {
     local bridge=$1
     local dev=$2
-    mtu="`ip link show dev ${bridge}| awk '/mtu/ { print $5 }'`"
+    local type_if=$3
+
+    XENBUS_PATH="${XENBUS_PATH:?}"
+
+    local mtu=$(xenstore_read_default "$XENBUS_PATH/mtu" "")
+    if [ -z "$mtu" ]
+    then
+        mtu="`ip link show dev ${bridge}| awk '/mtu/ { print $5 }'`"
+        if [ -n "$mtu" ]
+        then
+            log debug "$bridge MTU is $mtu"
+        fi
+    fi
     if [ -n "$mtu" ] && [ "$mtu" -gt 0 ]
     then
-            ip link set dev ${dev} mtu $mtu || :
+        log debug "setting $dev MTU to $mtu"
+        ip link set dev ${dev} mtu ${mtu} || :
+
+        if [ ${type_if} = vif ]
+        then
+            local dev_=${dev#vif}
+            local domid=${dev_%.*}
+            local devid=${dev_#*.}
+
+            local FRONTEND_PATH="/local/domain/$domid/device/vif/$devid"
+
+            xenstore_write "$FRONTEND_PATH/mtu" ${mtu}
+        fi
     fi
 }
Signature · 1 line
2.20.1
#8 lore raw

PATCH v3 7/8 xl: add 'mtu' option to network configuration

In reply to Paul Durrant

From: Paul Durrant <[email protected]>

This patch adds code to parse a value for MTU from the network configuration if it is present. The documentation in xl-network-configuration.5.pod is also modified accordingly.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>

v3:
- New in v3

---
 docs/man/xl-network-configuration.5.pod | 6 ++++++
 tools/xl/xl_cmdtable.c                  | 2 +-
 tools/xl/xl_parse.c                     | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)
docs/man/xl-network-configuration.5.pod +6 -0
index 0ac24c4a18..af058d4d3c 100644
@@ -249,3 +249,9 @@ on the underlying netback implementation.
 Specifies the devid manually instead of letting xl choose the lowest index available.
 
 NOTE: This should not be set unless you have a reason to.
+
+=head2 mtu
+
+Specifies the MTU (i.e. the maximum size of an IP payload, exclusing headers). The
+default value is 1500 but, if the VIF is attached to a bridge, it will be set to match
+unless overridden by this parameter.
tools/xl/xl_cmdtable.c +1 -1
index 08335394e5..2b8e1b321a 100644
@@ -338,7 +338,7 @@ struct cmd_spec cmd_table[] = {
       "Create a new virtual network device",
       "<Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>] "
       "[ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>] "
-      "[rate=<rate>] [model=<model>] [accel=<accel>]",
+      "[rate=<rate>] [model=<model>] [accel=<accel>] [mtu=<mtu>]",
     },
     { "network-list",
       &main_networklist, 0, 0,
tools/xl/xl_parse.c +2 -0
index 61b4ef7b7e..cae8eb679c 100644
@@ -563,6 +563,8 @@ int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token)
         fprintf(stderr, "the accel parameter for vifs is currently not supported\n");
     } else if (MATCH_OPTION("devid", token, oparg)) {
         nic->devid = parse_ulong(oparg);
+    } else if (MATCH_OPTION("mtu", token, oparg)) {
+        nic->mtu = parse_ulong(oparg);
     } else {
         fprintf(stderr, "unrecognized argument `%s'\n", token);
         return 1;
Signature · 1 line
2.20.1
#9 lore raw

PATCH v3 8/8 remove netchannel2 hotplug script... ancient history

In reply to Paul Durrant

From: Paul Durrant <[email protected]>

configuration is not parsed by libxl so there is no reason for the hotplug script to exist

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

v3:
- New in v3

---
 tools/hotplug/Linux/Makefile |  1 -
 tools/hotplug/Linux/vif2     | 54 ------------------------------------
 2 files changed, 55 deletions(-)
 delete mode 100644 tools/hotplug/Linux/vif2
tools/hotplug/Linux/Makefile +0 -1
index 3a90990594..0b1d111d7e 100644
@@ -6,7 +6,6 @@ XEN_SCRIPTS = vif-bridge
 XEN_SCRIPTS += vif-route
 XEN_SCRIPTS += vif-nat
 XEN_SCRIPTS += vif-openvswitch
-XEN_SCRIPTS += vif2
 XEN_SCRIPTS += vif-setup
 XEN_SCRIPTS-$(CONFIG_LIBNL) += remus-netbuf-setup
 XEN_SCRIPTS += block
tools/hotplug/Linux/vif2 deleted +0 -54

54 lines not on this page · raw message

Signature · 1 line
2.20.1
Acked-by on the v3 series
#10 lore raw
In reply to Paul Durrant
Quoted 15 lines · Paul Durrant

From: Paul Durrant <[email protected]>

This is an expansion from v2 of the series to include the facility to set the MTU in the vif config.

There is also one cleanup patch to remove the defunct 'vif2' script.

Paul Durrant (8):
public/io/netif: specify MTU override node tools/hotplug/Linux: re-factor add_to_bridge() in
xen-network-common.sh
tools/hotplug/Linux: add remove_from_bridge() tools/hotplug/Linux: remove code duplication in vif-bridge
libxl: wire the libxl_device_nic 'mtu' value into xenstore tools/hotplug/Linux: modify set_mtu() to optionally use a configured

Quoted 4 lines
    value...

xl: add 'mtu' option to network configuration remove netchannel2 hotplug script... ancient history

Patches 2 - 8:

(I already acked patch 1)

#11 lore raw
Quoted 36 lines

-----Original Message-----
From: Wei Liu <[email protected]>
Sent: 27 August 2020 10:58
To: Paul Durrant <[email protected]>
Cc: [email protected]; Durrant, Paul <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>
Subject: RE: [EXTERNAL] [PATCH v3 0/8] tools: propogate MTU to vif frontends

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 15 lines · Paul Durrant

From: Paul Durrant <[email protected]>

This is an expansion from v2 of the series to include the facility to set the MTU in the vif config.

There is also one cleanup patch to remove the defunct 'vif2' script.

Paul Durrant (8):
public/io/netif: specify MTU override node tools/hotplug/Linux: re-factor add_to_bridge() in
xen-network-common.sh
tools/hotplug/Linux: add remove_from_bridge() tools/hotplug/Linux: remove code duplication in vif-bridge
libxl: wire the libxl_device_nic 'mtu' value into xenstore tools/hotplug/Linux: modify set_mtu() to optionally use a configured

Quoted 4 lines
    value...

xl: add 'mtu' option to network configuration remove netchannel2 hotplug script... ancient history

Quoted 4 lines

Patches 2 - 8:

(I already acked patch 1)

Thanks Wei.

Ian... ping?

Paul