Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1694450rwr; Fri, 5 May 2023 19:43:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Zl+ofEyA/xOh3zFAlu1p4646ctUkz9qNR1MWpyXaq1QTqbjf8EjCbpNQcUt/wBCHXVDh9 X-Received: by 2002:a17:90a:c70e:b0:24e:a0b:426 with SMTP id o14-20020a17090ac70e00b0024e0a0b0426mr3535411pjt.24.1683340980438; Fri, 05 May 2023 19:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683340980; cv=none; d=google.com; s=arc-20160816; b=n7gqjQujFZWKBr0oVL+ViZAV1vhCDqqtJrpBs0UX5YMfuL5uKHwnmvHqG6w+qCykNl YYftqouorlkFFZiA5SfTGxZ4s4+D4kk2VmrfsNhUKWV1Ky1tCjMGpIcl4YHQqNMMZwZ5 3KMHEk8+B1DqUYlUaq63V6TXKNFXnyOyDJN+wh74RtVFcoOT/eESLHdm0Sijb8IxFjZd /kx6TmOTo0d1cVJEeenXoaZ2ww44bwTey4cTg8g8lW1jhP9q+Wsbn+/zKuaM6zaTMmI0 uxNGvkUNiOd9LSgVagY7UrPWJF2u7aikM5wxBC+uhOm3a+r8rFOC1Qx/gp066HpKTKXt B1yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:cc:to:from:date:subject :message-id; bh=du7AOuQQcV8nWuBeFyvgn20VkeqqzYMpbwZUJ97HYXQ=; b=VkFheviGkCgRoBkhiAaaTBonQbvj5x7RtY/8CRHf0tnPW+pu2wQXsO9Pmahh+Fz0GG VWEauuyx7VuPrzHSHEGtpJdEvnWQ6TB9UDd4YjRWiV59iLpVsFoDNSW+zmDt4H/YGiig EwwcuBuHdQp7Gku7EsT787DS7TcB5kQhwhMrN7dfKH2sLq6J1ucJkhieeGobIg9URB6M Z6hL7UPyWTUv1kFj8avqJi9vJFG5Emlaylw/fK25j2Esq0Iz7D7W58wHyUDj6Fcjw+kK vLBxHhebEDikHWCgK7/aL44SC7qkxYNwF/CW7gM165M/v3022YXy5KNwX9pI8Vub4njN TPKg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u189-20020a6385c6000000b0050bf5a43800si3387659pgd.242.2023.05.05.19.42.45; Fri, 05 May 2023 19:43:00 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229816AbjEFCfm (ORCPT + 99 others); Fri, 5 May 2023 22:35:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbjEFCfk (ORCPT ); Fri, 5 May 2023 22:35:40 -0400 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5380561B0; Fri, 5 May 2023 19:35:38 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R391e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0VhrT5Eo_1683340534; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0VhrT5Eo_1683340534) by smtp.aliyun-inc.com; Sat, 06 May 2023 10:35:34 +0800 Message-ID: <1683340417.612963-3-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH net v3] virtio_net: Fix error unwinding of XDP initialization Date: Sat, 6 May 2023 10:33:37 +0800 From: Xuan Zhuo To: Feng Liu Cc: Jason Wang , "Michael S . Tsirkin" , Simon Horman , Bodong Wang , Feng Liu , William Tu , Parav Pandit , , , , References: <20230503003525.48590-1-feliu@nvidia.com> In-Reply-To: <20230503003525.48590-1-feliu@nvidia.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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, 2 May 2023 20:35:25 -0400, Feng Liu wrote: > When initializing XDP in virtnet_open(), some rq xdp initialization > may hit an error causing net device open failed. However, previous > rqs have already initialized XDP and enabled NAPI, which is not the > expected behavior. Need to roll back the previous rq initialization > to avoid leaks in error unwinding of init code. > > Also extract a helper function of disable queue pairs, and use newly > introduced helper function in error unwinding and virtnet_close; > > Issue: 3383038 > Fixes: 754b8a21a96d ("virtio_net: setup xdp_rxq_info") > Signed-off-by: Feng Liu > Reviewed-by: William Tu > Reviewed-by: Parav Pandit > Reviewed-by: Simon Horman > Acked-by: Michael S. Tsirkin > Change-Id: Ib4c6a97cb7b837cfa484c593dd43a435c47ea68f > --- > drivers/net/virtio_net.c | 30 ++++++++++++++++++++---------- > 1 file changed, 20 insertions(+), 10 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 8d8038538fc4..3737cf120cb7 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -1868,6 +1868,13 @@ static int virtnet_poll(struct napi_struct *napi, int budget) > return received; > } > > +static void virtnet_disable_qp(struct virtnet_info *vi, int qp_index) > +{ > + virtnet_napi_tx_disable(&vi->sq[qp_index].napi); > + napi_disable(&vi->rq[qp_index].napi); > + xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); > +} > + > static int virtnet_open(struct net_device *dev) > { > struct virtnet_info *vi = netdev_priv(dev); > @@ -1883,20 +1890,26 @@ static int virtnet_open(struct net_device *dev) > > err = xdp_rxq_info_reg(&vi->rq[i].xdp_rxq, dev, i, vi->rq[i].napi.napi_id); > if (err < 0) > - return err; > + goto err_xdp_info_reg; > > err = xdp_rxq_info_reg_mem_model(&vi->rq[i].xdp_rxq, > MEM_TYPE_PAGE_SHARED, NULL); > - if (err < 0) { > - xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq); > - return err; > - } > + if (err < 0) > + goto err_xdp_reg_mem_model; > > virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); > virtnet_napi_tx_enable(vi, vi->sq[i].vq, &vi->sq[i].napi); > } > > return 0; > + > +err_xdp_reg_mem_model: > + xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq); > +err_xdp_info_reg: > + for (i = i - 1; i >= 0; i--) > + virtnet_disable_qp(vi, i); I would to know should we handle for these: disable_delayed_refill(vi); cancel_delayed_work_sync(&vi->refill); Maybe we should call virtnet_close() with "i" directly. Thanks. > + > + return err; > } > > static int virtnet_poll_tx(struct napi_struct *napi, int budget) > @@ -2305,11 +2318,8 @@ static int virtnet_close(struct net_device *dev) > /* Make sure refill_work doesn't re-enable napi! */ > cancel_delayed_work_sync(&vi->refill); > > - for (i = 0; i < vi->max_queue_pairs; i++) { > - virtnet_napi_tx_disable(&vi->sq[i].napi); > - napi_disable(&vi->rq[i].napi); > - xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq); > - } > + for (i = 0; i < vi->max_queue_pairs; i++) > + virtnet_disable_qp(vi, i); > > return 0; > } > -- > 2.37.1 (Apple Git-137.1) >