DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Thomas Monjalon <thomas@monjalon.net>, dev@dpdk.org
Cc: matan@mellanox.com, ferruh.yigit@intel.com
Subject: Re: [dpdk-dev] [PATCH] bus/vdev: reduce scope of device list lock
Date: Tue, 22 May 2018 10:05:11 +0100	[thread overview]
Message-ID: <8f0eb83d-5090-c7c8-5c3d-c4eecb96e596@intel.com> (raw)
In-Reply-To: <20180521161156.25724-1-thomas@monjalon.net>

On 21-May-18 5:11 PM, Thomas Monjalon wrote:
> The lock vdev_device_list_lock was taken before calling
> "remove" function for the device.
> So it prevents to remove sub-devices (as in failsafe) inside
> its own "remove" function, because of a deadlock.
> 
> The lock is now only protecting the device list inside
> the bus driver.
> 
> Fixes: 35f462839b69 ("bus/vdev: add lock on device list")
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>   drivers/bus/vdev/vdev.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
> index 099b9ff85..2fbc86806 100644
> --- a/drivers/bus/vdev/vdev.c
> +++ b/drivers/bus/vdev/vdev.c
> @@ -293,25 +293,23 @@ rte_vdev_uninit(const char *name)
>   	if (name == NULL)
>   		return -EINVAL;
>   
> -	rte_spinlock_lock(&vdev_device_list_lock);
> -
>   	dev = find_vdev(name);
>   	if (!dev) {
>   		ret = -ENOENT;
> -		goto unlock;
> +		return ret;
>   	}

Without that lock, all of this would be racy - find_dev would iterate a 
tailq that might change under its feet, and tailq_remove may be called 
with a pointer that has already been removed.

How about changing the lock to a recursive lock? Failsafe would be 
removing devices from within the same thread, correct?

>   
>   	ret = vdev_remove_driver(dev);
>   	if (ret)
> -		goto unlock;
> +		return ret;
>   
> +	rte_spinlock_lock(&vdev_device_list_lock);
>   	TAILQ_REMOVE(&vdev_device_list, dev, next);
>   	devargs = dev->device.devargs;
>   	rte_devargs_remove(devargs->bus->name, devargs->name);
>   	free(dev);
> -
> -unlock:
>   	rte_spinlock_unlock(&vdev_device_list_lock);
> +
>   	return ret;
>   }
>   
> 


-- 
Thanks,
Anatoly

  parent reply	other threads:[~2018-05-22  9:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-21 16:11 Thomas Monjalon
2018-05-21 16:45 ` [dpdk-dev] [PATCH v2] bus/vdev: fix " Thomas Monjalon
2018-05-21 17:28   ` Matan Azrad
2018-05-22  9:11     ` Gaëtan Rivet
2018-05-22  9:05 ` Burakov, Anatoly [this message]
2018-05-22  9:20   ` [dpdk-dev] [PATCH] bus/vdev: reduce " Thomas Monjalon
2018-05-22 11:37     ` [dpdk-dev] [PATCH v3] bus/vdev: replace device list lock by a recursive one Thomas Monjalon
2018-05-22 12:08       ` Matan Azrad
2018-05-22 13:34       ` Burakov, Anatoly
2018-05-22 14:38         ` Thomas Monjalon

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=8f0eb83d-5090-c7c8-5c3d-c4eecb96e596@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=matan@mellanox.com \
    --cc=thomas@monjalon.net \
    /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).