From: "Michael S. Tsirkin" <mst@redhat.com>
To: Feng Liu <feliu@nvidia.com>
Cc: virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, Jason Wang <jasowang@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Simon Horman <simon.horman@corigine.com>,
Bodong Wang <bodong@nvidia.com>, Jiri Pirko <jiri@nvidia.com>
Subject: Re: [PATCH net v4] virtio_net: Fix error unwinding of XDP initialization
Date: Tue, 9 May 2023 00:42:39 -0400 [thread overview]
Message-ID: <20230509004010-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230508222708.68281-1-feliu@nvidia.com>
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 <feliu@nvidia.com>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> ---
>
> 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)
next prev parent reply other threads:[~2023-05-09 4:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-08 22:27 [PATCH net v4] virtio_net: Fix error unwinding of XDP initialization Feng Liu
2023-05-09 4:42 ` Michael S. Tsirkin [this message]
2023-05-09 14:08 ` Feng Liu
2023-05-11 13:41 ` Michal Kubiak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230509004010-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=bodong@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=feliu@nvidia.com \
--cc=jasowang@redhat.com \
--cc=jiri@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=simon.horman@corigine.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).