From: Paolo Abeni <pabeni@redhat.com>
To: Jason Wang <jasowang@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
Cc: rbradford@rivosinc.com, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] virtio-net: Fix probe of virtio-net on kvmtool
Date: Thu, 02 Mar 2023 10:45:00 +0100 [thread overview]
Message-ID: <82084397a98d55e17657b32a09c2909912498b41.camel@redhat.com> (raw)
In-Reply-To: <CACGkMEsG10CWigz+S6JgSVK8XfbpT=L=30hZ8LDvohtaanAiZQ@mail.gmail.com>
On Thu, 2023-03-02 at 16:10 +0800, Jason Wang wrote:
> On Wed, Mar 1, 2023 at 10:44 PM Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > On Wed, Mar 01, 2023 at 01:59:52PM +0000, Rob Bradford via B4 Relay wrote:
> > > From: Rob Bradford <rbradford@rivosinc.com>
> > >
> > > Since the following commit virtio-net on kvmtool has printed a warning
> > > during the probe:
> > >
> > > commit dbcf24d153884439dad30484a0e3f02350692e4c
> > > Author: Jason Wang <jasowang@redhat.com>
> > > Date: Tue Aug 17 16:06:59 2021 +0800
> > >
> > > virtio-net: use NETIF_F_GRO_HW instead of NETIF_F_LRO
> > >
> > > [ 1.865992] net eth0: Fail to set guest offload.
> > > [ 1.872491] virtio_net virtio2 eth0: set_features() failed (-22); wanted 0x0000000000134829, left 0x0080000000134829
> > >
> > > This is because during the probing the underlying netdev device has
> > > identified that the netdev features on the device has changed and
> > > attempts to update the virtio-net offloads through the virtio-net
> > > control queue. kvmtool however does not have a control queue that supports
> > > offload changing (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS is not advertised)
> > >
> > > The netdev features have changed due to validation checks in
> > > netdev_fix_features():
> > >
> > > if (!(features & NETIF_F_RXCSUM)) {
> > > /* NETIF_F_GRO_HW implies doing RXCSUM since every packet
> > > * successfully merged by hardware must also have the
> > > * checksum verified by hardware. If the user does not
> > > * want to enable RXCSUM, logically, we should disable GRO_HW.
> > > */
> > > if (features & NETIF_F_GRO_HW) {
> > > netdev_dbg(dev, "Dropping NETIF_F_GRO_HW since no RXCSUM feature.\n");
> > > features &= ~NETIF_F_GRO_HW;
> > > }
> > > }
> > >
> > > Since kvmtool does not advertise the VIRTIO_NET_F_GUEST_CSUM feature the
> > > NETIF_F_RXCSUM bit is not present and so the NETIF_F_GRO_HW bit is
> > > cleared. This results in the netdev features changing, which triggers
> > > the attempt to reprogram the virtio-net offloads which then fails.
> > >
> > > This commit prevents that set of netdev features from changing by
> > > preemptively applying the same validation and only setting
> > > NETIF_F_GRO_HW if NETIF_F_RXCSUM is set because the device supports both
> > > VIRTIO_NET_F_GUEST_CSUM and VIRTIO_NET_F_GUEST_TSO{4,6}
> > >
> > > Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
> > > ---
> > > Changes in v3:
> > > - Identified root-cause of feature bit changing and updated conditions
> > > check
> > > - Link to v2: https://lore.kernel.org/r/20230223-virtio-net-kvmtool-v2-1-8ec93511e67f@rivosinc.com
> > >
> > > Changes in v2:
> > > - Use parentheses to group logical OR of features
> > > - Link to v1:
> > > https://lore.kernel.org/r/20230223-virtio-net-kvmtool-v1-1-fc23d29b9d7a@rivosinc.com
> > > ---
> > > drivers/net/virtio_net.c | 10 ++++++----
> > > 1 file changed, 6 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > > index 61e33e4dd0cd..2e7705142ca5 100644
> > > --- a/drivers/net/virtio_net.c
> > > +++ b/drivers/net/virtio_net.c
> > > @@ -3778,11 +3778,13 @@ static int virtnet_probe(struct virtio_device *vdev)
> > > dev->features |= dev->hw_features & NETIF_F_ALL_TSO;
> > > /* (!csum && gso) case will be fixed by register_netdev() */
> > > }
> > > - if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))
> > > + if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM)) {
> > > dev->features |= NETIF_F_RXCSUM;
> > > - if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
> > > - virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6))
> > > - dev->features |= NETIF_F_GRO_HW;
> > > + /* This dependency is enforced by netdev_fix_features */
> > > + if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
> > > + virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6))
> > > + dev->features |= NETIF_F_GRO_HW;
> > > + }
> > > if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))
> > > dev->hw_features |= NETIF_F_GRO_HW;
>
> Should we move this also under the check of RXCSUM, otherwise we may
> end up the following case:
>
> when CSUM is not negotiated but GUEST_OFFLOADS, can still try to
> enable-or-disable guest offloads? Or do we need to fail the probe in
> the case via virtnet_validate_features()?
>
> > >
> >
> > I see. It is annoying that we are duplicating the logic from
> > netdev_fix_features here though :(
> > Maybe we should call netdev_update_features, in the callback check
> > the flags and decide what to set and what to clear?
> > Or export netdev_fix_features to modules?
>
> There's a ndo_fix_features() that might be used here.
I agree with Jason: I think a virtio_net specific ndo_fix_features()
should be the right place to implement the above logic.
Cheers,
Paolo
next prev parent reply other threads:[~2023-03-02 9:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-01 13:59 Rob Bradford via B4 Relay
2023-03-01 14:44 ` Michael S. Tsirkin
2023-03-02 8:10 ` Jason Wang
2023-03-02 9:45 ` Paolo Abeni [this message]
2023-03-02 9:48 ` Michael S. Tsirkin
2023-03-04 0:46 ` Jakub Kicinski
2023-03-05 9:53 ` Michael S. Tsirkin
2023-03-06 8:44 ` Xuan Zhuo
2023-03-06 18:12 ` Jakub Kicinski
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=82084397a98d55e17657b32a09c2909912498b41.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=rbradford@rivosinc.com \
--cc=virtualization@lists.linux-foundation.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
all inboxes | Powered by JetHome®