Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2906807iog; Mon, 27 Jun 2022 05:31:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t3UEj13QDUg+dMuEPbwvnw+JrJWM1o/hKNIry2sgi12mbshwvbH9ervivUtWSYx74U/UNZ X-Received: by 2002:a05:6402:43c7:b0:435:8a92:e8d0 with SMTP id p7-20020a05640243c700b004358a92e8d0mr16520653edc.174.1656333088005; Mon, 27 Jun 2022 05:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333088; cv=none; d=google.com; s=arc-20160816; b=eEvQN8E0GWA5JuFHsO+JQzg+Gw/UVsXjaPnO37cOxbz+FPSwusr5na21KgRYLJngmc CiE6ZTqUyXiETl4OS8WR36tvfy6JWaRPq+bxGl2RGVKkZ5VYF7h9UjdcoJwbvkkIqeuB 1HcU+wLTpDTVk1sRtfHmCp04s/+9JVxhARIQnLXJSCiMqyBKchkn/ngrkWH/KQwbsIpx eIJbnorVHYi0AXUWEoZhwH0yL37gvfSENGIrjPG+IPKOFuOGFvooC7Tn1moWWNm/NSQx 42PR3aC9BLl1TNjNjcP969taBvb1LgdvoGJOt6PxMi/FWnpngWr5sNkQGR+QrnoBxFIY HIVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I3Io7VtaQZq56Ne9gaYydYT1klsRCfdyp+ea3U1N0uk=; b=i+ZxjRreEuaq0d4PwAxDwEXKDYWbqZgqFtNFV44won1+81qnEFqkoGFAPpgH3f1IEb dO0BsoSMS1g5MwlsMCHgjAtV+apy4N3RUhA+1jCc/le7tu5ukuZwUolEOjLwhqbTubYT w0QL/RAmCc0eQ3VkEz+4pvrE+WKAEYJd5uYetkIxOp8JhcjKf83yguz9cNeJWpXOjTvg pfRe+TdzOXGPiylMO0wQBGIZdD36f9gOrQUO1jPc8hVRjzUY/CVf3+7WZ6eSRFXIXGeA gHrxmctUiAncWLBiX8HTYmB98wk3D1pHTO7qIoCUYVSeoz0O+TgEbAhOnR3yJPdvzySz +AGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NBKF9VYv; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a17-20020a509b51000000b00435660ad459si523791edj.518.2022.06.27.05.31.03; Mon, 27 Jun 2022 05:31:27 -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=@linuxfoundation.org header.s=korg header.b=NBKF9VYv; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239676AbiF0L56 (ORCPT + 99 others); Mon, 27 Jun 2022 07:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238423AbiF0LvJ (ORCPT ); Mon, 27 Jun 2022 07:51:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E59264D1; Mon, 27 Jun 2022 04:44:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1FABAB80D92; Mon, 27 Jun 2022 11:44:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E515C3411D; Mon, 27 Jun 2022 11:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656330256; bh=4VFdD5ys/qbvFUCShz71aRXQVy+VKR+nSZ616eGOviU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NBKF9VYvrxa+RiH9DfV1ZSLWpwjfiK0mW4bzYRDisCIGVMv+8/X41Y/rrzI8Bo7Z1 jEji94gkLzHsnQ3gcocuSmXHbK+XW32gqBtLXwRJ6Js0SWh//dAfZUAgqM7HVwdkl9 LVjgH7Jtj1RtbptoXOApcdhAiR9NPwLJ8lgHtByI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephan Gerhold , Jesper Dangaard Brouer , Jason Wang , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.18 096/181] virtio_net: fix xdp_rxq_info bug after suspend/resume Date: Mon, 27 Jun 2022 13:21:09 +0200 Message-Id: <20220627111947.343327836@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111944.553492442@linuxfoundation.org> References: <20220627111944.553492442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 From: Stephan Gerhold [ Upstream commit 8af52fe9fd3bf5e7478da99193c0632276e1dfce ] 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: Jesper Dangaard Brouer Acked-by: Jason Wang Link: https://lore.kernel.org/r/20220621114845.3650258-1-stephan.gerhold@kernkonzept.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- 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 cbba9d2e8f32..10d548b07b9c 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.35.1