From patchwork Fri Jan 27 20:44:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13119406 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ED20C61DA4 for ; Fri, 27 Jan 2023 20:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229686AbjA0UqS (ORCPT ); Fri, 27 Jan 2023 15:46:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjA0UqQ (ORCPT ); Fri, 27 Jan 2023 15:46:16 -0500 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4856B17CDC; Fri, 27 Jan 2023 12:45:18 -0800 (PST) Received: from lenovo-t14s.redhat.com ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M58OQ-1pKP8G3WNA-0018pB; Fri, 27 Jan 2023 21:45:05 +0100 From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: "David S. Miller" , virtualization@lists.linux-foundation.org, Cindy Lu , "Michael S. Tsirkin" , Eli Cohen , Gautam Dawar , =?utf-8?q?Eugenio_P=C3=A9rez?= , Jason Wang , netdev@vger.kernel.org, Parav Pandit Subject: [PATCH v3 1/2] virtio_net: disable VIRTIO_NET_F_STANDBY if VIRTIO_NET_F_MAC is not set Date: Fri, 27 Jan 2023 21:44:59 +0100 Message-Id: <20230127204500.51930-2-lvivier@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230127204500.51930-1-lvivier@redhat.com> References: <20230127204500.51930-1-lvivier@redhat.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:dDynSjXZJgzJ6rJ90EiWqku5tMQFKKlPs/g0iszfvcj489W0tYY M/vXu6qUMHmP17ThNfHhcYYFzfce031ZX/FXDX2fIw3STSTDtsdSwqOe39QsY052PmuEEde WJ0jKGPMCZbtNnc6HsuayP4zSzWRJTYtAlbHwoJj+CEsZQv6zSuqnvqpKCrgX7Fz/Cjwc9f bKayJwTW1BtSunSJ/1GDQ== UI-OutboundReport: notjunk:1;M01:P0:YSRiWra10ag=;NKQnSarxFDt067Ku9TJc+7zxNck h9kzScSbWvaVcSwSGpUtyC01vMz6C73hZ7seUqPOuALdGFaO1B2dmc8kp2fUnmTcNy4y4aCdi nHam2FG+Zr4bVaPMsCxoGk4sAO0Mi9AQQuomKTOoV5+W3THRiOnjbBWoPwr6c4hjE89djTT5p 744xlGjzpEwrH78e/sSY54HZ2/1vGagtXlN6/ojEi98ZSoMzuELRS5y+voiq8MK6Msq0kxVNo xtC05/+KgGzD8u/chsW689xvfiXfTtFvrN25LF5AOUPKhWovlQ/Ruok5S+c4kHa2kkvIfq9Bo eIpTdn/c+TwhFZ83JR3m9duQ8OZbuEmj+52GvJ6GoGwSEGI2pJi4pgai84gwW4o8gT9c7QRlf Gkb7Au6OU94Uvv4WpwkyAa0Acj9KFjnJqtudC6XyBWMgBEAEwN46KrKcEb+nVKRQYpp8Euql7 cmSY4HHvTspiIWkl4euRLJqo434JuRlCHBlFVen2vJLf2yolj6Pfzl4v1H3HH0u0yH13bRQul SNOnCDAjE6A/AoDvldKhmXNTYaa6QPM4ayIx7PlbalHWnR3f0fLfUc6vfBkExUCqUCg0kOioU IyosR9+pX1ezChe1ylB33IC0CcYzGC+oF9rpDNDclBvlY6Vaqy9KEfNEFe1A+gPztZKD3UlXM hTwN4+Awzl2tT8Sc7p0o5KpuAhfCMlgIB2NCYxyrVA== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org failover relies on the MAC address to pair the primary and the standby devices: "[...] the hypervisor needs to enable VIRTIO_NET_F_STANDBY feature on the virtio-net interface and assign the same MAC address to both virtio-net and VF interfaces." Documentation/networking/net_failover.rst This patch disables the STANDBY feature if the MAC address is not provided by the hypervisor. Signed-off-by: Laurent Vivier Acked-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7723b2a49d8e..7d700f8e545a 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3688,6 +3688,12 @@ static int virtnet_validate(struct virtio_device *vdev) __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU); } + if (virtio_has_feature(vdev, VIRTIO_NET_F_STANDBY) && + !virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) { + dev_warn(&vdev->dev, "device advertises feature VIRTIO_NET_F_STANDBY but not VIRTIO_NET_F_MAC, disabling standby"); + __virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY); + } + return 0; } From patchwork Fri Jan 27 20:45:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13119407 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F404C61DA4 for ; Fri, 27 Jan 2023 20:46:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbjA0UqV (ORCPT ); Fri, 27 Jan 2023 15:46:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbjA0UqS (ORCPT ); Fri, 27 Jan 2023 15:46:18 -0500 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D7A37E6EF; Fri, 27 Jan 2023 12:45:18 -0800 (PST) Received: from lenovo-t14s.redhat.com ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MWSJJ-1pBMAk2xND-00XusM; Fri, 27 Jan 2023 21:45:05 +0100 From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: "David S. Miller" , virtualization@lists.linux-foundation.org, Cindy Lu , "Michael S. Tsirkin" , Eli Cohen , Gautam Dawar , =?utf-8?q?Eugenio_P=C3=A9rez?= , Jason Wang , netdev@vger.kernel.org, Parav Pandit Subject: [PATCH v3 2/2] virtio_net: notify MAC address change on device initialization Date: Fri, 27 Jan 2023 21:45:00 +0100 Message-Id: <20230127204500.51930-3-lvivier@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230127204500.51930-1-lvivier@redhat.com> References: <20230127204500.51930-1-lvivier@redhat.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:vDP/sU3WbWB3aipv6spulG2sZ/1/Qx0NRvtEbQ/95jvDYBrgqmv ZN3NrtTNEg7/lbeTe7M8RMTYDDBTb50tIFBE5sKC1+dGcykmefRnplHi5Jj2SuoDef9L+k8 JsT+qgN5H7TdT7yYUGdVrw20FOcRMzLIMrLttqxHXylaSE9B0r6WpmSiZaB3QykOyrbZxc9 8csVaeU/XH5gJCpVVFPig== UI-OutboundReport: notjunk:1;M01:P0:YlxfpHwCfKI=;F2Z0qtzUOVtZt2dyT7TyrApqXPl /OeE0Hrod1cbH/ILzhse+N7lHTWXmIgWXuf+n0WQUqw1sXa9Jz6i2+MFzbTmxKYl1S2i003tC YGBElKmIKyDskmmbVIS60/ls4uaMq2tvd/qDkPPlxj2SpTgEuz1WnUDbjXnuIXMVy71DBuPCW 5b3zZxB8QgRHmcpbaxiHw3mtN1IYyQP8iiOiS7yM5oMu1hcQomQCjaGVYEst8rTpTRNPDCAOr uA+bYmu8jX0fWae/F9nClQ/NuCO/ssabz0eH17fhN1/3ldHjX8rFB0saoDU38165VHKapeV56 DJ7xFCGdbiMP0JdJLZVQiOQ1/agp6bjCkJg7Gwf2A+NJifDJKbeICCpFU127adGM6ryff4aHU W8r8NvqB+LwFaLKu61vl8Ou2sjxsIk2IM8b1FnJoVJDHioGCuEf3A3X9ld3FTHw6p0ZV2dv1e CnO7jf0pMeuAuje7hEFFT9cfnlDwiob8JwRvgCRDQhHp4f7vz7lkNS+l2UEOXf9FVVWFIQjXl c+lhxAi4lc+CGVdL09P+VjeMFpLzfbZFSoh1cnggzCybxcJVKZ6OMaMp0iaqkFy1hcL7qX0jS t+hBDNoqIHPyBatsD/L2fpOgGL0pNwqy4jzmSTK+3B8bMydMflilJl/5FVKKCYB6r0Q2ZwkoN gW8zeTeUzg/PVIi1dnTOD94brO2eEEoPwf4dvNZtXw== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In virtnet_probe(), if the device doesn't provide a MAC address the driver assigns a random one. As we modify the MAC address we need to notify the device to allow it to update all the related information. The problem can be seen with vDPA and mlx5_vdpa driver as it doesn't assign a MAC address by default. The virtio_net device uses a random MAC address (we can see it with "ip link"), but we can't ping a net namespace from another one using the virtio-vdpa device because the new MAC address has not been provided to the hardware: RX packets are dropped since they don't go through the receive filters, TX packets go through unaffected. Signed-off-by: Laurent Vivier Acked-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7d700f8e545a..704a05f1c279 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3806,6 +3806,8 @@ static int virtnet_probe(struct virtio_device *vdev) eth_hw_addr_set(dev, addr); } else { eth_hw_addr_random(dev); + dev_info(&vdev->dev, "Assigned random MAC address %pM\n", + dev->dev_addr); } /* Set up our device-specific information */ @@ -3933,6 +3935,24 @@ static int virtnet_probe(struct virtio_device *vdev) virtio_device_ready(vdev); + /* a random MAC address has been assigned, notify the device. + * We don't fail probe if VIRTIO_NET_F_CTRL_MAC_ADDR is not there + * because many devices work fine without getting MAC explicitly + */ + if (!virtio_has_feature(vdev, VIRTIO_NET_F_MAC) && + virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) { + struct scatterlist sg; + + sg_init_one(&sg, dev->dev_addr, dev->addr_len); + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, + VIRTIO_NET_CTRL_MAC_ADDR_SET, &sg)) { + pr_debug("virtio_net: setting MAC address failed\n"); + rtnl_unlock(); + err = -EINVAL; + goto free_unregister_netdev; + } + } + rtnl_unlock(); err = virtnet_cpu_notif_add(vi);