From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: "Xia, Chenbo" <chenbo.xia@intel.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 v3 44/44] net/virtio: handle Virtio-user setup failure properly
Date: Tue, 26 Jan 2021 10:15:33 +0100 [thread overview]
Message-ID: <305925d5-db1d-3200-cd0d-54875c47c908@redhat.com> (raw)
In-Reply-To: <MN2PR11MB40639CC81B2DA6DD8A1995599CBC9@MN2PR11MB4063.namprd11.prod.outlook.com>
On 1/26/21 7:36 AM, Xia, Chenbo wrote:
> Hi Maxime,
>
>> -----Original Message-----
>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Sent: Tuesday, January 26, 2021 1:15 AM
>> 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 v3 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 | 68 +++++++++++++------
>> 1 file changed, 47 insertions(+), 21 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..7c60022a26 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,25 +291,48 @@ 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 -1;
>> +}
>> +
>> +static int
>
> Use void?
yes.
>> +virtio_user_dev_uninit_notify(struct virtio_user_dev *dev)
>> +{
>> + uint32_t i;
>> +
>> + for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; ++i) {
>
> Do we need to loop for VIRTIO_MAX_VIRTQUEUES? Kick/call fds would only be set
> valid in virtio_user_dev_init_notify, and since virtio_user_dev_init_notify only
> loop for dev->max_queue_pairs * 2, this function will also loop for dev->max_queue_pairs * 2?
> Other fds should be -1, right?
Yes, given max_queue_pairs is never updated during the lifecycle, it is
safe to loop for max_queue_pairs.
I'll fix it in v4.
Thanks,
Maxime
> Thanks,
> Chenbo
>
>> + 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;
>> + }
>> }
>>
>> return 0;
>> @@ -427,15 +444,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 +490,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 +596,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
>
prev parent reply other threads:[~2021-01-26 9:16 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 17:14 [dpdk-dev] [PATCH v3 00/44] net/virtio: Virtio PMD rework Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 01/44] bus/vdev: add helper to get vdev from ethdev Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 02/44] bus/vdev: add driver IOVA VA mode requirement Maxime Coquelin
2021-01-26 9:23 ` Xia, Chenbo
2021-01-26 9:24 ` Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 03/44] net/virtio: fix getting old status on reconnect Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 04/44] net/virtio: introduce Virtio bus type Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 05/44] net/virtio: refactor virtio-user device Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 06/44] net/virtio: introduce PCI device metadata Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 07/44] net/virtio: move PCI device init in dedicated file Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 08/44] net/virtio: move PCI specific dev init to PCI ethdev init Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 09/44] net/virtio: move MSIX detection to PCI ethdev Maxime Coquelin
2021-01-26 5:53 ` Xia, Chenbo
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 10/44] net/virtio: force IOVA as VA mode for Virtio-user Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 11/44] net/virtio: store PCI type in Virtio device metadata Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 12/44] net/virtio: add callback for device closing Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 13/44] net/virtio: validate features at bus level Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 14/44] net/virtio: remove bus type enum Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 15/44] net/virtio: move PCI-specific fields to PCI device Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 16/44] net/virtio: pack virtio HW struct Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 17/44] net/virtio: move legacy IO to Virtio PCI Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 18/44] net/virtio: introduce generic virtio header Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 19/44] net/virtio: move features definition to generic header Maxime Coquelin
2021-01-26 5:55 ` Xia, Chenbo
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 20/44] net/virtio: move virtqueue defines in " Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 21/44] net/virtio: move config definitions to " Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 22/44] net/virtio: make interrupt handling more generic Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 23/44] net/virtio: move vring alignment to generic header Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 24/44] net/virtio: remove last PCI refs in non-PCI code Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 25/44] net/virtio: make Vhost-user request sender consistent Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 26/44] net/virtio: add Virtio-user ops to set owner Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 27/44] net/virtio: add Virtio-user features ops Maxime Coquelin
2021-01-26 5:58 ` Xia, Chenbo
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 28/44] net/virtio: add Virtio-user protocol " Maxime Coquelin
2021-01-26 6:09 ` Xia, Chenbo
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 29/44] net/virtio: add Virtio-user memory tables ops Maxime Coquelin
2021-01-26 6:09 ` Xia, Chenbo
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 30/44] net/virtio: add Virtio-user vring setting ops Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 31/44] net/virtio: add Virtio-user vring file ops Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 32/44] net/virtio: add Virtio-user vring address ops Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 33/44] net/virtio: add Virtio-user status ops Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 34/44] net/virtio: remove useless request ops Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 35/44] net/virtio: improve Virtio-user errors handling Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 36/44] net/virtio: move Vhost-user requests to Vhost-user backend Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 37/44] net/virtio: make server mode blocking Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 38/44] net/virtio: move protocol features to Vhost-user Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 39/44] net/virtio: introduce backend data Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 40/44] net/virtio: move Vhost-user specifics to its backend Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 41/44] net/virtio: move Vhost-kernel data " Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 42/44] net/virtio: move Vhost-vDPA " Maxime Coquelin
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 43/44] net/virtio: improve Vhost-user error logging Maxime Coquelin
2021-01-26 6:25 ` Xia, Chenbo
2021-01-25 17:14 ` [dpdk-dev] [PATCH v3 44/44] net/virtio: handle Virtio-user setup failure properly Maxime Coquelin
2021-01-26 6:36 ` Xia, Chenbo
2021-01-26 9:15 ` Maxime Coquelin [this message]
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=305925d5-db1d-3200-cd0d-54875c47c908@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=amorenoz@redhat.com \
--cc=chenbo.xia@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--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
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).