Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp164994rwe; Fri, 14 Apr 2023 00:23:52 -0700 (PDT) X-Google-Smtp-Source: AKy350ZMz/7Ikk3uhtKLPkzcxkZR8R949tj20+eTTwmCk1ChnbVSaxmMFvAg9wq1SSkc48mVARXa X-Received: by 2002:a17:902:d40c:b0:1a6:712c:24c5 with SMTP id b12-20020a170902d40c00b001a6712c24c5mr1535716ple.69.1681457032631; Fri, 14 Apr 2023 00:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681457032; cv=none; d=google.com; s=arc-20160816; b=uptsoQr6zj3fwLMjdihZSPVVZWrNKp4q6g0SM2BW2RFkoclOZzxgn/Tn/S3xcLl/97 /1pFPfufFCxa/KbxVfwZfUFQY3cXF/hlNV5p8wLOUfBewnkbjbnkF/4y6ifg3wsWqKPm oxaEjpmu8SEX78PRXyDt9MLghSpXhCkK/bkxRQqEtQ5+JmWM2jNVG7xNS8Mws3vhJj6u yH8fDRzR4d+L9n9YuBzaZ7asAM+cXGwv1q2RRDDSavshJEjDaDMbSWWtDQuMpTEkftlS nGH335PsqcwIO2JXRYc8GlFuei4BwF5AXybvP/5uMON/5NMkHqX7fRJbsCJ+s+IQIoZZ dXdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=JTjJsirhlxDEZc4I718p3t7VvXQAdTVuI0oKV3etEqI=; b=DcMZdPDv/REUe2jQvDPp+BFOb6cdY60RE7mlIFvCU43+s32b1FR+RNTEHvJXP4QW3o MiFOm4KogKcuS0/EmyL/WhA/H3yOwvvuWxWD+smTzWhIyFHvVzJKAOrnbIp/sib7zEKg N4U89Z06Xjrei4o0XAnAkRoL39/RdoD8JVQSypYa2obwD9+E0Xc2OQWyzA6/xuxkaQaP fGLiTxmHReWKlPNYHqHDXgOp+7zSuWTVNX/F9OzO1al8sS06VO5SJaApe4LKVxcA8Mos yLGnO0ZQ5rQVrgKGF3jzfFK56PeScnTAa53GezcYBd5TJhG94OBdBWdrPSXdfoQMLA8S Uq3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TdexjmFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k15-20020a170902ba8f00b001a19cbd4fb9si3810807pls.244.2023.04.14.00.23.38; Fri, 14 Apr 2023 00:23:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TdexjmFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbjDNHWe (ORCPT + 99 others); Fri, 14 Apr 2023 03:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbjDNHWd (ORCPT ); Fri, 14 Apr 2023 03:22:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86C4C4C0A for ; Fri, 14 Apr 2023 00:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681456905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JTjJsirhlxDEZc4I718p3t7VvXQAdTVuI0oKV3etEqI=; b=TdexjmFgr916LEWtY7pL8NMoyr4g9u3qm4YyiYXdZelVdzfsy14Z52F+vFtiLVXvZAb7HW Lfg9i3slLTWJJY+H+Fjx5B78VMELugk+fnO38ULZgEOMelMiT/7gzfwBdsclcCyKdcQfI0 EjSiMlJJzd5koRKsO8kZgzWQVjMgCy8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-39-JxqsssD5NDuiYvsARjgDkw-1; Fri, 14 Apr 2023 03:21:43 -0400 X-MC-Unique: JxqsssD5NDuiYvsARjgDkw-1 Received: by mail-wm1-f71.google.com with SMTP id bg22-20020a05600c3c9600b003ef6ee937b8so5571614wmb.2 for ; Fri, 14 Apr 2023 00:21:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681456902; x=1684048902; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JTjJsirhlxDEZc4I718p3t7VvXQAdTVuI0oKV3etEqI=; b=UziL7LB9L6t0MY/1wS67NC1MfcEPZksyb6asBkbU+uNeE+AzGwgaMbISaqw+mco/db Hf8gP95/wHkRK8I+MJ22fYfxOSiSohNBV9e0+v2o6X6ZMC9lTxo+IQYmLS0Bf5DU6uuS K3F++T+em0hOh623Lt+I/FT9j4bXnZQQ9V6jsPdwi3HF00TIwkVzQh2SymA/sip688JT s+oBtoxOEaHsrUqQvbPQeRJW1XMdSKipLBKSDH5rpJi4oQ0FhiQTiiXEHL/BEXfuDwnt 5gM+8tTwbeBx0JHIyHdej+/onV5vxqQdN7HWptRmsrIQJSRuabUYvop6HoZP5URiG2G0 hqrA== X-Gm-Message-State: AAQBX9e8zVSDYrEsrhOz0WqCYkftWxDhTJoy8DNtzhPw0PF2oSeAIyJy LDIubfUgfoaplKYfcvBnt8rNjYqFPec1BtO4mMO2UfjQmD2/xAolWfhH5VZRFJ2Pm0iyzgjJWBQ pOIEswSQwTwmnonLvoSIZ/RyN X-Received: by 2002:a5d:4a08:0:b0:2f5:ac53:c04f with SMTP id m8-20020a5d4a08000000b002f5ac53c04fmr3170061wrq.28.1681456902559; Fri, 14 Apr 2023 00:21:42 -0700 (PDT) X-Received: by 2002:a5d:4a08:0:b0:2f5:ac53:c04f with SMTP id m8-20020a5d4a08000000b002f5ac53c04fmr3170036wrq.28.1681456902179; Fri, 14 Apr 2023 00:21:42 -0700 (PDT) Received: from redhat.com ([2a06:c701:742d:fd00:c847:221d:9254:f7ce]) by smtp.gmail.com with ESMTPSA id h8-20020adfe988000000b002efdf3e5be0sm2905088wrm.44.2023.04.14.00.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 00:21:41 -0700 (PDT) Date: Fri, 14 Apr 2023 03:21:38 -0400 From: "Michael S. Tsirkin" To: Jason Wang Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, maxime.coquelin@redhat.com, alvaro.karsz@solid-run.com, eperezma@redhat.com, xuanzhuo@linux.alibaba.com, david.marchand@redhat.com, netdev Subject: Re: [PATCH net-next V2 1/2] virtio-net: convert rx mode setting to use workqueue Message-ID: <20230414031947-mutt-send-email-mst@kernel.org> References: <20230413064027.13267-1-jasowang@redhat.com> <20230413064027.13267-2-jasowang@redhat.com> <20230413121525-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 14, 2023 at 01:04:15PM +0800, Jason Wang wrote: > Forget to cc netdev, adding. > > On Fri, Apr 14, 2023 at 12:25 AM Michael S. Tsirkin wrote: > > > > On Thu, Apr 13, 2023 at 02:40:26PM +0800, Jason Wang wrote: > > > This patch convert rx mode setting to be done in a workqueue, this is > > > a must for allow to sleep when waiting for the cvq command to > > > response since current code is executed under addr spin lock. > > > > > > Signed-off-by: Jason Wang > > > > I don't like this frankly. This means that setting RX mode which would > > previously be reliable, now becomes unreliable. > > It is "unreliable" by design: > > void (*ndo_set_rx_mode)(struct net_device *dev); > > > - first of all configuration is no longer immediate > > Is immediate a hard requirement? I can see a workqueue is used at least: > > mlx5e, ipoib, efx, ... > > > and there is no way for driver to find out when > > it actually took effect > > But we know rx mode is best effort e.g it doesn't support vhost and we > survive from this for years. > > > - second, if device fails command, this is also not > > propagated to driver, again no way for driver to find out > > > > VDUSE needs to be fixed to do tricks to fix this > > without breaking normal drivers. > > It's not specific to VDUSE. For example, when using virtio-net in the > UP environment with any software cvq (like mlx5 via vDPA or cma > transport). > > Thanks Hmm. Can we differentiate between these use-cases? > > > > > > > --- > > > Changes since V1: > > > - use RTNL to synchronize rx mode worker > > > --- > > > drivers/net/virtio_net.c | 55 +++++++++++++++++++++++++++++++++++++--- > > > 1 file changed, 52 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > > index e2560b6f7980..2e56bbf86894 100644 > > > --- a/drivers/net/virtio_net.c > > > +++ b/drivers/net/virtio_net.c > > > @@ -265,6 +265,12 @@ struct virtnet_info { > > > /* Work struct for config space updates */ > > > struct work_struct config_work; > > > > > > + /* Work struct for config rx mode */ > > > + struct work_struct rx_mode_work; > > > + > > > + /* Is rx mode work enabled? */ > > > + bool rx_mode_work_enabled; > > > + > > > /* Does the affinity hint is set for virtqueues? */ > > > bool affinity_hint_set; > > > > > > @@ -388,6 +394,20 @@ static void disable_delayed_refill(struct virtnet_info *vi) > > > spin_unlock_bh(&vi->refill_lock); > > > } > > > > > > +static void enable_rx_mode_work(struct virtnet_info *vi) > > > +{ > > > + rtnl_lock(); > > > + vi->rx_mode_work_enabled = true; > > > + rtnl_unlock(); > > > +} > > > + > > > +static void disable_rx_mode_work(struct virtnet_info *vi) > > > +{ > > > + rtnl_lock(); > > > + vi->rx_mode_work_enabled = false; > > > + rtnl_unlock(); > > > +} > > > + > > > static void virtqueue_napi_schedule(struct napi_struct *napi, > > > struct virtqueue *vq) > > > { > > > @@ -2310,9 +2330,11 @@ static int virtnet_close(struct net_device *dev) > > > return 0; > > > } > > > > > > -static void virtnet_set_rx_mode(struct net_device *dev) > > > +static void virtnet_rx_mode_work(struct work_struct *work) > > > { > > > - struct virtnet_info *vi = netdev_priv(dev); > > > + struct virtnet_info *vi = > > > + container_of(work, struct virtnet_info, rx_mode_work); > > > + struct net_device *dev = vi->dev; > > > struct scatterlist sg[2]; > > > struct virtio_net_ctrl_mac *mac_data; > > > struct netdev_hw_addr *ha; > > > @@ -2325,6 +2347,8 @@ static void virtnet_set_rx_mode(struct net_device *dev) > > > if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX)) > > > return; > > > > > > + rtnl_lock(); > > > + > > > vi->ctrl->promisc = ((dev->flags & IFF_PROMISC) != 0); > > > vi->ctrl->allmulti = ((dev->flags & IFF_ALLMULTI) != 0); > > > > > > @@ -2342,14 +2366,19 @@ static void virtnet_set_rx_mode(struct net_device *dev) > > > dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n", > > > vi->ctrl->allmulti ? "en" : "dis"); > > > > > > + netif_addr_lock_bh(dev); > > > + > > > uc_count = netdev_uc_count(dev); > > > mc_count = netdev_mc_count(dev); > > > /* MAC filter - use one buffer for both lists */ > > > buf = kzalloc(((uc_count + mc_count) * ETH_ALEN) + > > > (2 * sizeof(mac_data->entries)), GFP_ATOMIC); > > > mac_data = buf; > > > - if (!buf) > > > + if (!buf) { > > > + netif_addr_unlock_bh(dev); > > > + rtnl_unlock(); > > > return; > > > + } > > > > > > sg_init_table(sg, 2); > > > > > > @@ -2370,6 +2399,8 @@ static void virtnet_set_rx_mode(struct net_device *dev) > > > netdev_for_each_mc_addr(ha, dev) > > > memcpy(&mac_data->macs[i++][0], ha->addr, ETH_ALEN); > > > > > > + netif_addr_unlock_bh(dev); > > > + > > > sg_set_buf(&sg[1], mac_data, > > > sizeof(mac_data->entries) + (mc_count * ETH_ALEN)); > > > > > > @@ -2377,9 +2408,19 @@ static void virtnet_set_rx_mode(struct net_device *dev) > > > VIRTIO_NET_CTRL_MAC_TABLE_SET, sg)) > > > dev_warn(&dev->dev, "Failed to set MAC filter table.\n"); > > > > > > + rtnl_unlock(); > > > + > > > kfree(buf); > > > } > > > > > > +static void virtnet_set_rx_mode(struct net_device *dev) > > > +{ > > > + struct virtnet_info *vi = netdev_priv(dev); > > > + > > > + if (vi->rx_mode_work_enabled) > > > + schedule_work(&vi->rx_mode_work); > > > +} > > > + > > > static int virtnet_vlan_rx_add_vid(struct net_device *dev, > > > __be16 proto, u16 vid) > > > { > > > @@ -3150,6 +3191,8 @@ static void virtnet_freeze_down(struct virtio_device *vdev) > > > > > > /* Make sure no work handler is accessing the device */ > > > flush_work(&vi->config_work); > > > + disable_rx_mode_work(vi); > > > + flush_work(&vi->rx_mode_work); > > > > > > netif_tx_lock_bh(vi->dev); > > > netif_device_detach(vi->dev); > > > > So now configuration is not propagated to device. > > Won't device later wake up in wrong state? > > > > > > > @@ -3172,6 +3215,7 @@ static int virtnet_restore_up(struct virtio_device *vdev) > > > virtio_device_ready(vdev); > > > > > > enable_delayed_refill(vi); > > > + enable_rx_mode_work(vi); > > > > > > if (netif_running(vi->dev)) { > > > err = virtnet_open(vi->dev); > > > @@ -3969,6 +4013,7 @@ static int virtnet_probe(struct virtio_device *vdev) > > > vdev->priv = vi; > > > > > > INIT_WORK(&vi->config_work, virtnet_config_changed_work); > > > + INIT_WORK(&vi->rx_mode_work, virtnet_rx_mode_work); > > > spin_lock_init(&vi->refill_lock); > > > > > > if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) { > > > @@ -4077,6 +4122,8 @@ static int virtnet_probe(struct virtio_device *vdev) > > > if (vi->has_rss || vi->has_rss_hash_report) > > > virtnet_init_default_rss(vi); > > > > > > + enable_rx_mode_work(vi); > > > + > > > /* serialize netdev register + virtio_device_ready() with ndo_open() */ > > > rtnl_lock(); > > > > > > @@ -4174,6 +4221,8 @@ static void virtnet_remove(struct virtio_device *vdev) > > > > > > /* Make sure no work handler is accessing the device. */ > > > flush_work(&vi->config_work); > > > + disable_rx_mode_work(vi); > > > + flush_work(&vi->rx_mode_work); > > > > > > unregister_netdev(vi->dev); > > > > > > -- > > > 2.25.1 > >