Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4578265iog; Wed, 22 Jun 2022 01:27:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sSsfAOSPMOAAWete1u8j/7a9cAVHAN9meswaDdw1YM1+nhkxfU52Mf8biyqucF6eXv9wWq X-Received: by 2002:a17:902:f20a:b0:16a:22ef:b17f with SMTP id m10-20020a170902f20a00b0016a22efb17fmr15360995plc.168.1655886464894; Wed, 22 Jun 2022 01:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655886464; cv=none; d=google.com; s=arc-20160816; b=oORggbCROROgi2OhfWowE7iTApkGwVywA/Qi2vmZai1HHuhj+NKxep/4WCR9IxOWre xT+RXEi+4PymlR4ciupP/YvDsETEfwi1FC7oXl+laQaYQDN8RqPaRNTtoQANOs5EaSZr qp+pnh02Lf6oCYYDXk5AarUrB64qY7bet8StaJLzbJQZIMHu7kQ64lxrsm38oZ34Hyo1 PTpo9Jq0xwUFDnZxvkOYowS5TEH1UHS+WPYR14+w8SfNdev5sEnbkA0+clbOXslqQ9IN JEW8c/gO42s0KoUhWRzXlWHPQIwY7XOsrV/SI0l4uH7qBD7KY3lQzDHeafCMLdn1J4qt zgOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=J5FesIEJNUAYWwzRo/YOZ1QtVKtqRp3mnHCOXbnUhhM=; b=M/JRo4nfd1V6XLTUwRlU5F8ty94cKcdWLw9Ab06PJQcOpIyKiQo47t6baUILlVijqp AzlCcjvpSOqs9SuqvxvGrP062saVXL8K+Mwhhfek+YMwfDly8VFaxnGQkRNW18Rie4jD ieqNnOGtpmr+4daatw/hk0PpwerAbDQGgIvzNusoSn8j76sSmzikGaUJTJ4Lmlkuxlrw NVKJPJtQQ7cfEP7yarVBNJSZPelkuQcF4XlTfctgqEGvirBPpsaw+Fj3Jrbgx4Uv2JQg 0eIGadKKXl9O5fRoz+QeAlTgU0SSii4Kno7ut/ASlzr9t71cLt+lSxmWZCJ9THa4Ax5W qcrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LfFbxj7H; 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 c18-20020a170902b69200b00163a54d2612si20516332pls.418.2022.06.22.01.27.32; Wed, 22 Jun 2022 01:27:44 -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=LfFbxj7H; 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 S1350659AbiFVIGf (ORCPT + 99 others); Wed, 22 Jun 2022 04:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbiFVIGe (ORCPT ); Wed, 22 Jun 2022 04:06:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 38B3CBE32 for ; Wed, 22 Jun 2022 01:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655885192; 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: in-reply-to:in-reply-to:references:references; bh=J5FesIEJNUAYWwzRo/YOZ1QtVKtqRp3mnHCOXbnUhhM=; b=LfFbxj7HPcmtsxrvUXYlqraRTMYJwSfwpaFOk0QAoU4jubBYJI2YtYWmXAG3/sSsJiZf79 NBEX6jGqgrhbSVuGWEArtfQM9eon9ozqBmUKi9aaijspbTUF7Wni1uRy67LJnfN3Us/06S TpHsnGwOKqWOnj+r++IP/5yXUhy2E64= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-386-WzcUTnwyO9Cl96lsk0XMdQ-1; Wed, 22 Jun 2022 04:06:30 -0400 X-MC-Unique: WzcUTnwyO9Cl96lsk0XMdQ-1 Received: by mail-lf1-f70.google.com with SMTP id u5-20020a056512128500b00479784f526cso8127005lfs.13 for ; Wed, 22 Jun 2022 01:06:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=J5FesIEJNUAYWwzRo/YOZ1QtVKtqRp3mnHCOXbnUhhM=; b=gRanUKiTF0XPHUvBp3JvW5RUGxpECDKQHDvteVBezMvwhbhUlBHyNbhHCfcYEKWFlY 24S1S3CfMrlZ1U7qZG6+yac5LVywXJ0hthlgaf4D3ATx43rzzQESJQ57APWW1FLkV9f8 AQU0IKQp0VjEnByaDe24ACm4b5KgUuPgEPvM4lhe5Y0PXy57J4jeLibCFog5V6wumvYl BgiKKHg4iViAEvklNQ3F+jr3Fp7VLC3bKXDKSgQU0frJUCu7RaiMYoGxxB2qGYFSnBRn k1nX4JKJ8GFx/be1LM6L8kShF6iWkifkFkCJiSDoGJnO0xRT145JzH5dDo/uolSNYBkU 3BcA== X-Gm-Message-State: AJIora/PtlphTlgeKu84ep6ugmzkq0KDnw+V/N7RNb+0Gj967CADgLyC gtHKnPNYJGT8Dfyh6u5Mz8mYfofFXBbVypEOc9gfdT77PFpJc5IrfLXds78PFL0pmdTdimf/miQ nMQ/np4NZqOUaN4ap4WJqguHxIgcpAvN3bomMmu6c X-Received: by 2002:a05:6512:13a5:b0:47d:c1d9:dea8 with SMTP id p37-20020a05651213a500b0047dc1d9dea8mr1420546lfa.442.1655885189237; Wed, 22 Jun 2022 01:06:29 -0700 (PDT) X-Received: by 2002:a05:6512:13a5:b0:47d:c1d9:dea8 with SMTP id p37-20020a05651213a500b0047dc1d9dea8mr1420532lfa.442.1655885188954; Wed, 22 Jun 2022 01:06:28 -0700 (PDT) MIME-Version: 1.0 References: <20220621114845.3650258-1-stephan.gerhold@kernkonzept.com> In-Reply-To: <20220621114845.3650258-1-stephan.gerhold@kernkonzept.com> From: Jason Wang Date: Wed, 22 Jun 2022 16:06:17 +0800 Message-ID: Subject: Re: [PATCH net] virtio_net: fix xdp_rxq_info bug after suspend/resume To: Stephan Gerhold Cc: "Michael S. Tsirkin" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , virtualization , netdev , linux-kernel , "open list:XDP (eXpress Data Path)" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Tue, Jun 21, 2022 at 7:50 PM Stephan Gerhold wrote: > > The following sequence currently causes a driver bug warning > when using virtio_net: > > # ip link set eth0 up > # echo mem > /sys/power/state (or e.g. # rtcwake -s 10 -m mem) > > # ip link set eth0 down > > Missing register, driver bug > WARNING: CPU: 0 PID: 375 at net/core/xdp.c:138 xdp_rxq_info_unreg+0x58/0x60 > Call trace: > xdp_rxq_info_unreg+0x58/0x60 > virtnet_close+0x58/0xac > __dev_close_many+0xac/0x140 > __dev_change_flags+0xd8/0x210 > dev_change_flags+0x24/0x64 > do_setlink+0x230/0xdd0 > ... > > This happens because virtnet_freeze() frees the receive_queue > completely (including struct xdp_rxq_info) but does not call > xdp_rxq_info_unreg(). Similarly, virtnet_restore() sets up the > receive_queue again but does not call xdp_rxq_info_reg(). > > Actually, parts of virtnet_freeze_down() and virtnet_restore_up() > are almost identical to virtnet_close() and virtnet_open(): only > the calls to xdp_rxq_info_(un)reg() are missing. This means that > we can fix this easily and avoid such problems in the future by > just calling virtnet_close()/open() from the freeze/restore handlers. > > Aside from adding the missing xdp_rxq_info calls the only difference > is that the refill work is only cancelled if netif_running(). However, > this should not make any functional difference since the refill work > should only be active if the network interface is actually up. > > Fixes: 754b8a21a96d ("virtio_net: setup xdp_rxq_info") > Signed-off-by: Stephan Gerhold Acked-by: Jason Wang > --- > drivers/net/virtio_net.c | 25 ++++++------------------- > 1 file changed, 6 insertions(+), 19 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index db05b5e930be..969a67970e71 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -2768,7 +2768,6 @@ static const struct ethtool_ops virtnet_ethtool_ops = { > static void virtnet_freeze_down(struct virtio_device *vdev) > { > struct virtnet_info *vi = vdev->priv; > - int i; > > /* Make sure no work handler is accessing the device */ > flush_work(&vi->config_work); > @@ -2776,14 +2775,8 @@ static void virtnet_freeze_down(struct virtio_device *vdev) > netif_tx_lock_bh(vi->dev); > netif_device_detach(vi->dev); > netif_tx_unlock_bh(vi->dev); > - cancel_delayed_work_sync(&vi->refill); > - > - if (netif_running(vi->dev)) { > - for (i = 0; i < vi->max_queue_pairs; i++) { > - napi_disable(&vi->rq[i].napi); > - virtnet_napi_tx_disable(&vi->sq[i].napi); > - } > - } > + if (netif_running(vi->dev)) > + virtnet_close(vi->dev); > } > > static int init_vqs(struct virtnet_info *vi); > @@ -2791,7 +2784,7 @@ static int init_vqs(struct virtnet_info *vi); > static int virtnet_restore_up(struct virtio_device *vdev) > { > struct virtnet_info *vi = vdev->priv; > - int err, i; > + int err; > > err = init_vqs(vi); > if (err) > @@ -2800,15 +2793,9 @@ static int virtnet_restore_up(struct virtio_device *vdev) > virtio_device_ready(vdev); > > if (netif_running(vi->dev)) { > - for (i = 0; i < vi->curr_queue_pairs; i++) > - if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL)) > - schedule_delayed_work(&vi->refill, 0); > - > - for (i = 0; i < vi->max_queue_pairs; i++) { > - virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); > - virtnet_napi_tx_enable(vi, vi->sq[i].vq, > - &vi->sq[i].napi); > - } > + err = virtnet_open(vi->dev); > + if (err) > + return err; > } > > netif_tx_lock_bh(vi->dev); > -- > 2.30.2 >