Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5265550rwr; Mon, 8 May 2023 21:52:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5J0C9EV7CjG9x6Ol9PZJZgQnjoLfVi1B/0e+RIUwzP2MlleRdOPw/s4szb9JfKvjJKiCD3 X-Received: by 2002:a05:6a20:42a5:b0:101:3046:8db3 with SMTP id o37-20020a056a2042a500b0010130468db3mr1715619pzj.22.1683607972767; Mon, 08 May 2023 21:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683607972; cv=none; d=google.com; s=arc-20160816; b=ByOXPAD0wK22zTYdj6+kKUDGYNA2cy9WAhIVs2iIHcomcDx5Vsh3zDpMVPWiYk/ujm qzwNk1gBBrTqBcoxp6j1mUS8iDoiiZhQI5EtLV/R3nVIW5QenBp1Rilteg9oYVWWJF1Q IOg01wsiu2W8XuYw3m+ZavTBar17ti2QvcgwQnGF2enCaNJM5Md0qhO4PtlRn6jOHMb4 1jCnjnJaZzKq9HS2WGACLi9oufCBieLWMIy3GsfUkV7IEE9qJvKDBGjpwgyNzO5VJepg fRn58QZ27Mu5bEcCfx0hddlVbqAy0HOgMA95eB3LeyLowLvGHi14E/cjxwzIrSKLU5Vc Urew== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=W7lkveXXMx28z2hQQkgi6XifNwekRx4w5U94EsCpzfo=; b=c9A7MjPgJxsDGGnkOVRBjvA++sIh70qGFvVcvB1XCYEFduLhyVM4e6saP1CtbKRBe1 nx3FNigHQG74AMNZYNJbsykf6XrVEjKx4crKyPFZBbVtDVXYhmJoDf9uTQbsQxKQgki1 gk5Of1Xmpe3u8uohGHrjQCpVlBkzkdOIuT7+vHfYvC92NOi1VbqB+kKCAF3hFucU4BfB HfYDHDE5YRSagZjgvHCdmxxLYK8ju+wrZhCyxZ0QfuwczqHj9QTN3ZjyCLtCPLSJ6p78 Nd8R6SGTNeoSjn9X+xEezAho8LZEOgkn1oqcqGwZ3xJuw7F56NSWA71weaeXKIPkLACd tlZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TG2ZWeNK; 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 g9-20020a63fa49000000b0052c73367c13si591501pgk.871.2023.05.08.21.52.38; Mon, 08 May 2023 21:52: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=TG2ZWeNK; 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 S234652AbjEIEnj (ORCPT + 99 others); Tue, 9 May 2023 00:43:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234636AbjEIEng (ORCPT ); Tue, 9 May 2023 00:43:36 -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 ESMTPS id 29FC5619E for ; Mon, 8 May 2023 21:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683607370; 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=W7lkveXXMx28z2hQQkgi6XifNwekRx4w5U94EsCpzfo=; b=TG2ZWeNKZFsGST2PvpfMl3tGc6OMDLD6MXZiIUINq+XwLKf2CSycbaJZ5qy3/kvZulo+Sq 4NpoCFGxxX4XoL9jOUHu22WHBDAXrC6rYOLB7F4TRXqhkPghVDsi28oP2NJS9R/Y7I3Bv4 d2UdI4ppyHrQWsb83KJKWsM4goBagf4= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-E9SkXULNPNKwJjI1NCPjUQ-1; Tue, 09 May 2023 00:42:48 -0400 X-MC-Unique: E9SkXULNPNKwJjI1NCPjUQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7578369dff3so621924285a.0 for ; Mon, 08 May 2023 21:42:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683607368; x=1686199368; h=in-reply-to: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=W7lkveXXMx28z2hQQkgi6XifNwekRx4w5U94EsCpzfo=; b=JeVFu32D/LVL+SZOoKmM0bG5UH5YPen4ynZLjFbfNlRa3MR8xicIyUcy4TqhHsa2i0 qH8UsUuppEXzY60PTIr8amDRkMcNFGULDOdAO+9YxNA9SDs+IIi3alGigOr8JkwTUbE6 4ylCgpxRCb2uWnP3sfzxPBXO04hXCwvXUKNOncrc817q1lxLaRLM6NtWsF309SWOoCd3 Xwt1zDyEfFSh9seTCFLc2UK+a3xhjjr/qp8PulBjeDLsb3slnaP7fQhMzzH7W8Zdugta Vb9o7kcPIFyBosAKNRL3CzHuFh81HiPnxB8IU4LFdS5ep3t1gJotIMAwv/Tsz2g/Rf5X xWDA== X-Gm-Message-State: AC+VfDzNAh+lBsI2Pm1nAhnGu0bg8M7/mb8nlq+VnTAP+KBp1oszIa1C eqKZBg5QgCPN11t48/tsai+PNs11KuHYZqwviceJh7X13bBXeo9WMqLHAlOksSR6BaQ8FLqLtCy M54BeeeGtoZTJ7hJNs0mLGQG2 X-Received: by 2002:a05:6214:408:b0:5dd:b986:b44 with SMTP id z8-20020a056214040800b005ddb9860b44mr22544259qvx.6.1683607368247; Mon, 08 May 2023 21:42:48 -0700 (PDT) X-Received: by 2002:a05:6214:408:b0:5dd:b986:b44 with SMTP id z8-20020a056214040800b005ddb9860b44mr22544245qvx.6.1683607367963; Mon, 08 May 2023 21:42:47 -0700 (PDT) Received: from redhat.com ([185.187.243.118]) by smtp.gmail.com with ESMTPSA id r3-20020a0ce283000000b005dd8b9345aesm492559qvl.70.2023.05.08.21.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 21:42:47 -0700 (PDT) Date: Tue, 9 May 2023 00:42:39 -0400 From: "Michael S. Tsirkin" To: Feng Liu Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Jason Wang , Xuan Zhuo , Simon Horman , Bodong Wang , Jiri Pirko Subject: Re: [PATCH net v4] virtio_net: Fix error unwinding of XDP initialization Message-ID: <20230509004010-mutt-send-email-mst@kernel.org> References: <20230508222708.68281-1-feliu@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230508222708.68281-1-feliu@nvidia.com> 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,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 Mon, May 08, 2023 at 06:27:08PM -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 helper functions of disable and enable queue pairs. > Use newly introduced disable helper function in error unwinding and > virtnet_close. Use enable helper function in virtnet_open. > > Fixes: 754b8a21a96d ("virtio_net: setup xdp_rxq_info") > Signed-off-by: Feng Liu > Reviewed-by: Jiri Pirko > --- > > v3 -> v4 > feedbacks from Jiri Pirko > - Add symmetric helper function virtnet_enable_qp to enable queues. > - Error handle: cleanup current queue pair in virtnet_enable_qp, > and complete the reset queue pairs cleanup in virtnet_open. > - Fix coding style. > feedbacks from Parav Pandit > - Remove redundant debug message and white space. > > v2 -> v3 > feedbacks from Michael S. Tsirkin > - Remove redundant comment. > > v1 -> v2 > feedbacks from Michael S. Tsirkin > - squash two patches together. > > --- > drivers/net/virtio_net.c | 58 ++++++++++++++++++++++++++++------------ > 1 file changed, 41 insertions(+), 17 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 8d8038538fc4..df7c08048fa7 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -1868,6 +1868,38 @@ static int virtnet_poll(struct napi_struct *napi, int budget) > return received; > } > > +static void virtnet_disable_qp(struct virtnet_info *vi, int qp_index) I am guessing _qp stands for queue pair? Let's call it virtnet_disable_queue_pair please, consistently with max_queue_pairs. > +{ > + 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_enable_qp(struct virtnet_info *vi, int qp_index) Similarly, virtnet_enable_queue_pair > +{ > + struct net_device *dev = vi->dev; > + int err; > + > + err = xdp_rxq_info_reg(&vi->rq[qp_index].xdp_rxq, dev, qp_index, > + vi->rq[qp_index].napi.napi_id); > + if (err < 0) > + return err; > + > + err = xdp_rxq_info_reg_mem_model(&vi->rq[qp_index].xdp_rxq, > + MEM_TYPE_PAGE_SHARED, NULL); > + if (err < 0) > + goto err_xdp_reg_mem_model; > + > + virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); > + virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi); > + > + return 0; > + > +err_xdp_reg_mem_model: > + xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); > + return err; > +} > + > static int virtnet_open(struct net_device *dev) > { > struct virtnet_info *vi = netdev_priv(dev); > @@ -1881,22 +1913,17 @@ static int virtnet_open(struct net_device *dev) > if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL)) > schedule_delayed_work(&vi->refill, 0); > > - err = xdp_rxq_info_reg(&vi->rq[i].xdp_rxq, dev, i, vi->rq[i].napi.napi_id); > + err = virtnet_enable_qp(vi, i); > if (err < 0) > - return err; > - > - 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; > - } > - > - virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); > - virtnet_napi_tx_enable(vi, vi->sq[i].vq, &vi->sq[i].napi); > + goto err_enable_qp; > } > > return 0; > + > +err_enable_qp: > + for (i--; i >= 0; i--) > + virtnet_disable_qp(vi, i); > + return err; > } > > static int virtnet_poll_tx(struct napi_struct *napi, int budget) > @@ -2305,11 +2332,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)