vdpa_device_list access must be protected with vdpa_device_list_lock
spinlock.

Signed-off-by: David Marchand <david.march...@redhat.com>
---
 lib/vhost/vdpa.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/vhost/vdpa.c b/lib/vhost/vdpa.c
index 8fa2153023..e2caa2bf28 100644
--- a/lib/vhost/vdpa.c
+++ b/lib/vhost/vdpa.c
@@ -22,21 +22,24 @@
 /** Double linked list of vDPA devices. */
 TAILQ_HEAD(vdpa_device_list, rte_vdpa_device);
 
-static struct vdpa_device_list vdpa_device_list =
-               TAILQ_HEAD_INITIALIZER(vdpa_device_list);
+static struct vdpa_device_list vdpa_device_list__ =
+               TAILQ_HEAD_INITIALIZER(vdpa_device_list__);
 static rte_spinlock_t vdpa_device_list_lock = RTE_SPINLOCK_INITIALIZER;
+static struct vdpa_device_list * const vdpa_device_list
+       RTE_GUARDED_BY(&vdpa_device_list_lock) = &vdpa_device_list__;
 
 
 /* Unsafe, needs to be called with vdpa_device_list_lock held */
 static struct rte_vdpa_device *
 __vdpa_find_device_by_name(const char *name)
+       RTE_EXC_LOCK_REQUIRES(&vdpa_device_list_lock)
 {
        struct rte_vdpa_device *dev, *ret = NULL;
 
        if (name == NULL)
                return NULL;
 
-       TAILQ_FOREACH(dev, &vdpa_device_list, next) {
+       TAILQ_FOREACH(dev, vdpa_device_list, next) {
                if (!strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN)) {
                        ret = dev;
                        break;
@@ -100,7 +103,7 @@ rte_vdpa_register_device(struct rte_device *rte_dev,
 
        dev->device = rte_dev;
        dev->ops = ops;
-       TAILQ_INSERT_TAIL(&vdpa_device_list, dev, next);
+       TAILQ_INSERT_TAIL(vdpa_device_list, dev, next);
 out_unlock:
        rte_spinlock_unlock(&vdpa_device_list_lock);
 
@@ -114,11 +117,11 @@ rte_vdpa_unregister_device(struct rte_vdpa_device *dev)
        int ret = -1;
 
        rte_spinlock_lock(&vdpa_device_list_lock);
-       RTE_TAILQ_FOREACH_SAFE(cur_dev, &vdpa_device_list, next, tmp_dev) {
+       RTE_TAILQ_FOREACH_SAFE(cur_dev, vdpa_device_list, next, tmp_dev) {
                if (dev != cur_dev)
                        continue;
 
-               TAILQ_REMOVE(&vdpa_device_list, dev, next);
+               TAILQ_REMOVE(vdpa_device_list, dev, next);
                rte_free(dev);
                ret = 0;
                break;
@@ -316,7 +319,7 @@ vdpa_find_device(const struct rte_vdpa_device *start, 
rte_vdpa_cmp_t cmp,
 
        rte_spinlock_lock(&vdpa_device_list_lock);
        if (start == NULL)
-               dev = TAILQ_FIRST(&vdpa_device_list);
+               dev = TAILQ_FIRST(vdpa_device_list);
        else
                dev = TAILQ_NEXT(start, next);
 
-- 
2.23.0

Reply via email to