[PATCH v2 0/3] net/tap, virtio-net: auto-detect MTU from host tap device

Nariman Sayed posted 3 patches 1 month, 2 weeks ago
Failed in applying to current master (apply log)
hw/net/virtio-net.c            | 10 ++++++++++
include/hw/virtio/virtio-net.h |  1 +
include/net/net.h              |  3 +++
net/net.c                      |  9 +++++++++
net/tap-bsd.c                  |  5 +++++
net/tap-linux.c                | 30 ++++++++++++++++++++++++++++++
net/tap-solaris.c              |  5 +++++
net/tap-stub.c                 |  5 +++++
net/tap.c                      |  8 ++++++++
net/tap_int.h                  |  1 +
10 files changed, 77 insertions(+)
[PATCH v2 0/3] net/tap, virtio-net: auto-detect MTU from host tap device
Posted by Nariman Sayed 1 month, 2 weeks ago
This series adds automatic detection of the host tap device's MTU
and exposes it to the guest via VIRTIO_NET_F_MTU, addressing
gitlab.com/qemu-project/qemu/-/issues/3155.

Currently, host_mtu= must be set manually on the virtio-net-pci
device, duplicating the MTU already configured on the host's tap
interface. This series adds a new mtu-from-tap boolean property
(default off) that, when enabled, automatically reads the backend's
MTU and uses it for the guest, avoiding the need to specify the
value twice.

v2:
 - Addressed feedback from Eugenio Perez Martin: rather than
   checking for NET_CLIENT_DRIVER_TAP and calling tap_get_mtu()
   directly, added a generic get_mtu callback to NetClientInfo and
   a qemu_get_mtu() wrapper, following the existing qemu_has_ufo()
   pattern. virtio-net.c now calls qemu_get_mtu() without any
   backend-type check, so other backends (e.g. vhost-user,
   vhost-vdpa) can implement get_mtu in the future without
   requiring any change to virtio-net.c. (patch 2 is new as a
   result; patch 3 updated accordingly)

The series is split into three patches:
 - patch 1 adds a helper to query a tap fd's host MTU (Linux only,
   with build-safe stubs for BSD/Solaris/stub backends)
 - patch 2 adds a generic get_mtu NetClientInfo callback and wires
   it up for the tap backend
 - patch 3 adds the new virtio-net property and wires it up,
   including a note on a config-space sizing timing issue
   discovered during testing

Tested manually with a tap device configured for MTU 9000 and an
Alpine Linux guest, confirming the guest correctly negotiates
VIRTIO_NET_F_MTU and reports the expected MTU. Also tested by
Aniket Sahu on ppc64le/POWER10 with a SLES guest.

Nariman Sayed (3):
  net/tap: add tap_fd_get_mtu() to query host tap MTU
  net: add generic get_mtu NetClientInfo callback
  virtio-net: add mtu-from-tap property for automatic MTU detection

 hw/net/virtio-net.c            | 10 ++++++++++
 include/hw/virtio/virtio-net.h |  1 +
 include/net/net.h              |  3 +++
 net/net.c                      |  9 +++++++++
 net/tap-bsd.c                  |  5 +++++
 net/tap-linux.c                | 30 ++++++++++++++++++++++++++++++
 net/tap-solaris.c              |  5 +++++
 net/tap-stub.c                 |  5 +++++
 net/tap.c                      |  8 ++++++++
 net/tap_int.h                  |  1 +
 10 files changed, 77 insertions(+)

-- 
2.34.1
Re: [PATCH v2 0/3] net/tap, virtio-net: auto-detect MTU from host tap device
Posted by Eugenio Perez Martin 1 month ago
On Wed, Oct 7, 2026 at 10:55 AM Nariman Sayed <narimansayed28@gmail.com> wrote:
>
> This series adds automatic detection of the host tap device's MTU
> and exposes it to the guest via VIRTIO_NET_F_MTU, addressing
> gitlab.com/qemu-project/qemu/-/issues/3155.
>
> Currently, host_mtu= must be set manually on the virtio-net-pci
> device, duplicating the MTU already configured on the host's tap
> interface. This series adds a new mtu-from-tap boolean property
> (default off) that, when enabled, automatically reads the backend's
> MTU and uses it for the guest, avoiding the need to specify the
> value twice.
>
> v2:
>  - Addressed feedback from Eugenio Perez Martin: rather than
>    checking for NET_CLIENT_DRIVER_TAP and calling tap_get_mtu()
>    directly, added a generic get_mtu callback to NetClientInfo and
>    a qemu_get_mtu() wrapper, following the existing qemu_has_ufo()
>    pattern. virtio-net.c now calls qemu_get_mtu() without any
>    backend-type check, so other backends (e.g. vhost-user,
>    vhost-vdpa) can implement get_mtu in the future without
>    requiring any change to virtio-net.c. (patch 2 is new as a
>    result; patch 3 updated accordingly)
>
> The series is split into three patches:
>  - patch 1 adds a helper to query a tap fd's host MTU (Linux only,
>    with build-safe stubs for BSD/Solaris/stub backends)
>  - patch 2 adds a generic get_mtu NetClientInfo callback and wires
>    it up for the tap backend
>  - patch 3 adds the new virtio-net property and wires it up,
>    including a note on a config-space sizing timing issue
>    discovered during testing
>
> Tested manually with a tap device configured for MTU 9000 and an
> Alpine Linux guest, confirming the guest correctly negotiates
> VIRTIO_NET_F_MTU and reports the expected MTU. Also tested by
> Aniket Sahu on ppc64le/POWER10 with a SLES guest.
>

Acked-by: Eugenio Pérez <eperezma@redhat.com>

Thanks!

> Nariman Sayed (3):
>   net/tap: add tap_fd_get_mtu() to query host tap MTU
>   net: add generic get_mtu NetClientInfo callback
>   virtio-net: add mtu-from-tap property for automatic MTU detection
>
>  hw/net/virtio-net.c            | 10 ++++++++++
>  include/hw/virtio/virtio-net.h |  1 +
>  include/net/net.h              |  3 +++
>  net/net.c                      |  9 +++++++++
>  net/tap-bsd.c                  |  5 +++++
>  net/tap-linux.c                | 30 ++++++++++++++++++++++++++++++
>  net/tap-solaris.c              |  5 +++++
>  net/tap-stub.c                 |  5 +++++
>  net/tap.c                      |  8 ++++++++
>  net/tap_int.h                  |  1 +
>  10 files changed, 77 insertions(+)
>
> --
> 2.34.1
>
>
Re: [PATCH v2 0/3] net/tap, virtio-net: auto-detect MTU from host tap device
Posted by Nariman Sayed 1 month ago
Hi all,

Gentle ping on this series. v2 addresses Eugenio's feedback by adding
a generic get_mtu callback to NetClientInfo, so virtio-net no longer
checks the backend type.

Jason, Michael, could you please take a look when you have time?

Thanks,
Nariman
Re: [PATCH v2 0/3] net/tap, virtio-net: auto-detect MTU from host tap device
Posted by Michael S. Tsirkin 1 month ago
On Tue, Oct 20, 2026 at 08:19:19AM +0300, Nariman Sayed wrote:
> Hi all,
> 
> Gentle ping on this series. v2 addresses Eugenio's feedback by adding
> a generic get_mtu callback to NetClientInfo, so virtio-net no longer
> checks the backend type.
> 
> Jason, Michael, could you please take a look when you have time?
> 
> Thanks,
> Nariman

Given Eugenio gave feedback on this one, I'd like his ack that
his comments have been addressed.
Re: [PATCH v2 0/3] net/tap, virtio-net: auto-detect MTU from host tap device
Posted by Eugenio Perez Martin 1 month ago
On Tue, Oct 20, 2026 at 9:38 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Oct 20, 2026 at 08:19:19AM +0300, Nariman Sayed wrote:
> > Hi all,
> >
> > Gentle ping on this series. v2 addresses Eugenio's feedback by adding
> > a generic get_mtu callback to NetClientInfo, so virtio-net no longer
> > checks the backend type.
> >
> > Jason, Michael, could you please take a look when you have time?
> >
> > Thanks,
> > Nariman
>
> Given Eugenio gave feedback on this one, I'd like his ack that
> his comments have been addressed.
>

Yes it does! I missed the v2, thanks for the heads up!