DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Xia, Chenbo" <chenbo.xia@intel.com>
To: Maxime Coquelin <maxime.coquelin@redhat.com>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"olivier.matz@6wind.com" <olivier.matz@6wind.com>,
	"amorenoz@redhat.com" <amorenoz@redhat.com>,
	"david.marchand@redhat.com" <david.marchand@redhat.com>
Subject: Re: [dpdk-dev] [PATCH v4 44/44] net/virtio: handle Virtio-user setup failure properly
Date: Tue, 26 Jan 2021 12:02:08 +0000
Message-ID: <MN2PR11MB4063F2AE06AEA397FF4421079CBC9@MN2PR11MB4063.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20210126101639.250481-45-maxime.coquelin@redhat.com>

Hi Maxime,

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Tuesday, January 26, 2021 6:17 PM
> To: dev@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; olivier.matz@6wind.com;
> amorenoz@redhat.com; david.marchand@redhat.com
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: [PATCH v4 44/44] net/virtio: handle Virtio-user setup failure
> properly
> 
> This patch fixes virtio_user_dev_setup() error path,
> by cleaning all resources it allocates. It introduces
> virtio_user_dev_uninit_notify() that cleans all open
> FDs. It implies assigning all FDs to -1 at init time.
> 
> With these changes done, virtio_user_dev_init_notify()
> can be simplified.
> 
> Suggested-by: Adrian Moreno <amorenoz@redhat.com>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  .../net/virtio/virtio_user/virtio_user_dev.c  | 70 +++++++++++++------
>  1 file changed, 47 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index a1e32158bb..2998473622 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -283,13 +283,7 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
>  	int callfd;
>  	int kickfd;
> 
> -	for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; ++i) {
> -		if (i >= dev->max_queue_pairs * 2) {
> -			dev->kickfds[i] = -1;
> -			dev->callfds[i] = -1;
> -			continue;
> -		}
> -
> +	for (i = 0; i < dev->max_queue_pairs * 2; i++) {
>  		/* May use invalid flag, but some backend uses kickfd and
>  		 * callfd as criteria to judge if dev is alive. so finally we
>  		 * use real event_fd.
> @@ -297,28 +291,49 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
>  		callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
>  		if (callfd < 0) {
>  			PMD_DRV_LOG(ERR, "(%s) callfd error, %s", dev->path,
> strerror(errno));
> -			break;
> +			goto err;
>  		}
>  		kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
>  		if (kickfd < 0) {
>  			close(callfd);
>  			PMD_DRV_LOG(ERR, "(%s) kickfd error, %s", dev->path,
> strerror(errno));
> -			break;
> +			goto err;
>  		}
>  		dev->callfds[i] = callfd;
>  		dev->kickfds[i] = kickfd;
>  	}
> 
> -	if (i < VIRTIO_MAX_VIRTQUEUES) {
> -		for (j = 0; j < i; ++j) {
> -			close(dev->callfds[j]);
> +	return 0;
> +err:
> +	for (j = 0; j < i; j++) {
> +		if (dev->kickfds[j] >= 0) {
>  			close(dev->kickfds[j]);
> +			dev->kickfds[j] = -1;
> +		}
> +		if (dev->callfds[j] >= 0) {
> +			close(dev->callfds[j]);
> +			dev->callfds[j] = -1;
>  		}
> -
> -		return -1;
>  	}
> 
> -	return 0;
> +	return -1;
> +}
> +
> +static void
> +virtio_user_dev_uninit_notify(struct virtio_user_dev *dev)
> +{
> +	uint32_t i;
> +
> +	for (i = 0; i < dev->max_queue_pairs; ++i) {

Should be 'dev->max_queue_pairs * 2'?

I believe you will fix this in the final version before applying them
in the tree.

So with above fixed:

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>

> +		if (dev->kickfds[i] >= 0) {
> +			close(dev->kickfds[i]);
> +			dev->kickfds[i] = -1;
> +		}
> +		if (dev->callfds[i] >= 0) {
> +			close(dev->callfds[i]);
> +			dev->callfds[i] = -1;
> +		}
> +	}
>  }
> 
>  static int
> @@ -427,15 +442,22 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
> 
>  	if (virtio_user_dev_init_notify(dev) < 0) {
>  		PMD_INIT_LOG(ERR, "(%s) Failed to init notifiers\n", dev->path);
> -		return -1;
> +		goto destroy;
>  	}
> 
>  	if (virtio_user_fill_intr_handle(dev) < 0) {
>  		PMD_INIT_LOG(ERR, "(%s) Failed to init interrupt handler\n", dev-
> >path);
> -		return -1;
> +		goto uninit;
>  	}
> 
>  	return 0;
> +
> +uninit:
> +	virtio_user_dev_uninit_notify(dev);
> +destroy:
> +	dev->ops->destroy(dev);
> +
> +	return -1;
>  }
> 
>  /* Use below macro to filter features from vhost backend */
> @@ -466,9 +488,16 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
> *path, int queues,
>  		     enum virtio_user_backend_type backend_type)
>  {
>  	uint64_t backend_features;
> +	int i;
> 
>  	pthread_mutex_init(&dev->mutex, NULL);
>  	strlcpy(dev->path, path, PATH_MAX);
> +
> +	for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; i++) {
> +		dev->kickfds[i] = -1;
> +		dev->callfds[i] = -1;
> +	}
> +
>  	dev->started = 0;
>  	dev->max_queue_pairs = queues;
>  	dev->queue_pairs = 1; /* mq disabled by default */
> @@ -565,16 +594,11 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
> *path, int queues,
>  void
>  virtio_user_dev_uninit(struct virtio_user_dev *dev)
>  {
> -	uint32_t i;
> -
>  	virtio_user_stop_device(dev);
> 
>  	rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);
> 
> -	for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
> -		close(dev->callfds[i]);
> -		close(dev->kickfds[i]);
> -	}
> +	virtio_user_dev_uninit_notify(dev);
> 
>  	free(dev->ifname);
> 
> --
> 2.29.2


  reply	other threads:[~2021-01-26 12:02 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 10:15 [dpdk-dev] [PATCH v4 00/44] net/virtio: Virtio PMD rework Maxime Coquelin
2021-01-26 10:15 ` [dpdk-dev] [PATCH v4 01/44] bus/vdev: add helper to get vdev from ethdev Maxime Coquelin
2021-01-26 10:15 ` [dpdk-dev] [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement Maxime Coquelin
2021-01-26 11:50   ` Xia, Chenbo
2021-01-26 12:50   ` David Marchand
2021-01-26 13:23     ` Kinsella, Ray
2021-01-26 14:40       ` David Marchand
2021-01-26 15:28         ` Kinsella, Ray
2021-01-27  8:23   ` David Marchand
2021-01-27  8:25     ` Maxime Coquelin
2021-01-26 10:15 ` [dpdk-dev] [PATCH v4 03/44] net/virtio: fix getting old status on reconnect Maxime Coquelin
2021-01-26 10:15 ` [dpdk-dev] [PATCH v4 04/44] net/virtio: introduce Virtio bus type Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 05/44] net/virtio: refactor virtio-user device Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 06/44] net/virtio: introduce PCI device metadata Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 07/44] net/virtio: move PCI device init in dedicated file Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 08/44] net/virtio: move PCI specific dev init to PCI ethdev init Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 09/44] net/virtio: move MSIX detection to PCI ethdev Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 10/44] net/virtio: force IOVA as VA mode for Virtio-user Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 11/44] net/virtio: store PCI type in Virtio device metadata Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 12/44] net/virtio: add callback for device closing Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 13/44] net/virtio: validate features at bus level Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 14/44] net/virtio: remove bus type enum Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 15/44] net/virtio: move PCI-specific fields to PCI device Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 16/44] net/virtio: pack virtio HW struct Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 17/44] net/virtio: move legacy IO to Virtio PCI Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 18/44] net/virtio: introduce generic virtio header Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 19/44] net/virtio: move features definition to generic header Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 20/44] net/virtio: move virtqueue defines in " Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 21/44] net/virtio: move config definitions to " Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 22/44] net/virtio: make interrupt handling more generic Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 23/44] net/virtio: move vring alignment to generic header Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 24/44] net/virtio: remove last PCI refs in non-PCI code Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 25/44] net/virtio: make Vhost-user request sender consistent Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 26/44] net/virtio: add Virtio-user ops to set owner Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 27/44] net/virtio: add Virtio-user features ops Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 28/44] net/virtio: add Virtio-user protocol " Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 29/44] net/virtio: add Virtio-user memory tables ops Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 30/44] net/virtio: add Virtio-user vring setting ops Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 31/44] net/virtio: add Virtio-user vring file ops Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 32/44] net/virtio: add Virtio-user vring address ops Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 33/44] net/virtio: add Virtio-user status ops Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 34/44] net/virtio: remove useless request ops Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 35/44] net/virtio: improve Virtio-user errors handling Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 36/44] net/virtio: move Vhost-user requests to Vhost-user backend Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 37/44] net/virtio: make server mode blocking Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 38/44] net/virtio: move protocol features to Vhost-user Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 39/44] net/virtio: introduce backend data Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 40/44] net/virtio: move Vhost-user specifics to its backend Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 41/44] net/virtio: move Vhost-kernel data " Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 42/44] net/virtio: move Vhost-vDPA " Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 43/44] net/virtio: improve Vhost-user error logging Maxime Coquelin
2021-01-26 10:16 ` [dpdk-dev] [PATCH v4 44/44] net/virtio: handle Virtio-user setup failure properly Maxime Coquelin
2021-01-26 12:02   ` Xia, Chenbo [this message]
2021-01-26 12:59     ` Maxime Coquelin
2021-01-27 11:59 ` [dpdk-dev] [PATCH v4 00/44] net/virtio: Virtio PMD rework Maxime Coquelin
2021-02-01  8:44 ` Wang, Yinan
2021-02-01  8:49   ` Maxime Coquelin
2021-02-01 13:00 ` Ilya Maximets
2021-02-01 13:03   ` Ilya Maximets
2021-02-01 13:16     ` Maxime Coquelin
2021-02-01 13:42       ` Ilya Maximets
2021-02-01 13:51         ` Maxime Coquelin

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=MN2PR11MB4063F2AE06AEA397FF4421079CBC9@MN2PR11MB4063.namprd11.prod.outlook.com \
    --to=chenbo.xia@intel.com \
    --cc=amorenoz@redhat.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=olivier.matz@6wind.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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git