DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 00/14] Enable lock annotations on most libraries and drivers
@ 2023-02-24  8:16 David Marchand
  2023-02-24  8:16 ` [PATCH 01/14] malloc: rework heap lock handling David Marchand
                   ` (15 more replies)
  0 siblings, 16 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas

This is a followup of the series that introduced lock annotations.
I reworked and made annotations work in what seemed the easier cases.
In most cases, I chose to convert inline wrappers around the EAL lock
API to simple macro: I did not see much value in those wrappers and this
is way simpler than adding __rte_*lock_function tags everywhere.

A list of libraries and drivers still need more work as their code have
non obvious locks handling. For those components, the check is opted
out.
I leave it to their respective maintainers to enable the checks later.

Maintainers, please review.


-- 
David Marchand

David Marchand (14):
  malloc: rework heap lock handling
  mem: rework malloc heap init
  mem: annotate shared memory config locks
  hash: annotate cuckoo hash lock
  graph: annotate graph lock
  drivers: inherit lock annotations for Intel drivers
  net/cxgbe: inherit lock annotations
  net/fm10k: annotate mailbox lock
  net/sfc: rework locking in proxy code
  net/sfc: inherit lock annotations
  net/virtio: annotate lock for guest announce
  raw/ifpga: inherit lock annotations
  vdpa/sfc: inherit lock annotations
  enable lock check

 .../prog_guide/env_abstraction_layer.rst      |  5 +-
 drivers/bus/dpaa/meson.build                  |  1 +
 drivers/common/cnxk/meson.build               |  1 +
 drivers/common/iavf/iavf_osdep.h              | 39 +++--------
 drivers/common/iavf/iavf_prototype.h          |  6 --
 drivers/common/idpf/base/idpf_osdep.h         | 26 ++------
 drivers/common/mlx5/meson.build               |  1 +
 drivers/event/cnxk/meson.build                |  1 +
 drivers/meson.build                           |  2 +-
 drivers/net/bnx2x/meson.build                 |  1 +
 drivers/net/bnxt/meson.build                  |  1 +
 drivers/net/cnxk/meson.build                  |  1 +
 drivers/net/cxgbe/base/adapter.h              | 35 ++--------
 drivers/net/enic/meson.build                  |  1 +
 drivers/net/fm10k/fm10k_ethdev.c              |  2 +
 drivers/net/hns3/meson.build                  |  1 +
 drivers/net/i40e/base/i40e_osdep.h            |  8 +--
 drivers/net/i40e/base/i40e_prototype.h        |  5 --
 drivers/net/i40e/i40e_ethdev.c                | 24 -------
 drivers/net/ice/base/ice_osdep.h              | 26 ++------
 drivers/net/mlx5/meson.build                  |  1 +
 drivers/net/sfc/sfc.h                         | 41 ++----------
 drivers/net/sfc/sfc_ev.c                      |  6 +-
 drivers/net/sfc/sfc_repr.c                    | 38 ++---------
 drivers/net/sfc/sfc_repr_proxy.c              | 59 +++++++++--------
 drivers/net/virtio/virtio_ethdev.c            |  8 +--
 drivers/net/virtio/virtio_ethdev.h            |  7 +-
 drivers/raw/ifpga/afu_pmd_core.c              | 17 +----
 drivers/vdpa/sfc/sfc_vdpa.h                   | 41 ++----------
 drivers/vdpa/sfc/sfc_vdpa_ops.c               | 14 ++--
 lib/eal/common/eal_common_mcfg.c              | 66 +++++++++++--------
 lib/eal/common/eal_common_memory.c            | 10 +--
 lib/eal/common/malloc_heap.c                  | 55 +++++++++++-----
 lib/eal/common/malloc_heap.h                  |  3 +
 lib/eal/common/rte_malloc.c                   | 10 ---
 lib/eal/freebsd/eal.c                         | 13 ++++
 lib/eal/include/rte_eal_memconfig.h           | 63 ++++++++++++++----
 lib/eal/linux/eal.c                           | 13 ++++
 lib/eal/version.map                           |  4 ++
 lib/eal/windows/eal.c                         | 13 ++++
 lib/graph/graph.c                             | 10 ++-
 lib/graph/graph_private.h                     | 10 ++-
 lib/hash/rte_cuckoo_hash.c                    |  8 +++
 lib/ipsec/meson.build                         |  1 +
 lib/meson.build                               |  2 +-
 lib/timer/meson.build                         |  1 +
 lib/vhost/meson.build                         |  1 -
 47 files changed, 313 insertions(+), 389 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 01/14] malloc: rework heap lock handling
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 02/14] mem: rework malloc heap init David Marchand
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Anatoly Burakov

Move all heap->lock manipulation to malloc_heap.c to have a single
location where to look at and make higher level code unaware of this
locking constraint.

The destroy helper has been reworked to zero all the heap object but
leave the lock untouched. The heap lock is then released through the
standard API.
This makes the code less scary even though, at this point of its life,
the heap object is probably referenced only by the caller.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/malloc_heap.c | 45 +++++++++++++++++++++++++++---------
 lib/eal/common/rte_malloc.c  | 10 --------
 2 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index d7c410b786..cc84dce672 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -1292,6 +1292,8 @@ int
 malloc_heap_add_external_memory(struct malloc_heap *heap,
 		struct rte_memseg_list *msl)
 {
+	rte_spinlock_lock(&heap->lock);
+
 	/* erase contents of new memory */
 	memset(msl->base_va, 0, msl->len);
 
@@ -1308,6 +1310,11 @@ malloc_heap_add_external_memory(struct malloc_heap *heap,
 	eal_memalloc_mem_event_notify(RTE_MEM_EVENT_ALLOC,
 			msl->base_va, msl->len);
 
+	/* mark it as heap segment */
+	msl->heap = 1;
+
+	rte_spinlock_unlock(&heap->lock);
+
 	return 0;
 }
 
@@ -1315,7 +1322,12 @@ int
 malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,
 		size_t len)
 {
-	struct malloc_elem *elem = heap->first;
+	struct malloc_elem *elem;
+	int ret = -1;
+
+	rte_spinlock_lock(&heap->lock);
+
+	elem = heap->first;
 
 	/* find element with specified va address */
 	while (elem != NULL && elem != va_addr) {
@@ -1323,20 +1335,24 @@ malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,
 		/* stop if we've blown past our VA */
 		if (elem > (struct malloc_elem *)va_addr) {
 			rte_errno = ENOENT;
-			return -1;
+			goto out;
 		}
 	}
 	/* check if element was found */
 	if (elem == NULL || elem->msl->len != len) {
 		rte_errno = ENOENT;
-		return -1;
+		goto out;
 	}
 	/* if element's size is not equal to segment len, segment is busy */
 	if (elem->state == ELEM_BUSY || elem->size != len) {
 		rte_errno = EBUSY;
-		return -1;
+		goto out;
 	}
-	return destroy_elem(elem, len);
+	ret = destroy_elem(elem, len);
+
+out:
+	rte_spinlock_unlock(&heap->lock);
+	return ret;
 }
 
 int
@@ -1372,23 +1388,30 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name)
 int
 malloc_heap_destroy(struct malloc_heap *heap)
 {
+	int ret = -1;
+
+	rte_spinlock_lock(&heap->lock);
+
 	if (heap->alloc_count != 0) {
 		RTE_LOG(ERR, EAL, "Heap is still in use\n");
 		rte_errno = EBUSY;
-		return -1;
+		goto fail;
 	}
 	if (heap->first != NULL || heap->last != NULL) {
 		RTE_LOG(ERR, EAL, "Heap still contains memory segments\n");
 		rte_errno = EBUSY;
-		return -1;
+		goto fail;
 	}
 	if (heap->total_size != 0)
 		RTE_LOG(ERR, EAL, "Total size not zero, heap is likely corrupt\n");
 
-	/* after this, the lock will be dropped */
-	memset(heap, 0, sizeof(*heap));
-
-	return 0;
+	RTE_BUILD_BUG_ON(offsetof(struct malloc_heap, lock) != 0);
+	memset(RTE_PTR_ADD(heap, sizeof(heap->lock)), 0,
+		sizeof(*heap) - sizeof(heap->lock));
+	ret = 0;
+fail:
+	rte_spinlock_unlock(&heap->lock);
+	return ret;
 }
 
 int
diff --git a/lib/eal/common/rte_malloc.c b/lib/eal/common/rte_malloc.c
index d39870bf3c..4f500892f2 100644
--- a/lib/eal/common/rte_malloc.c
+++ b/lib/eal/common/rte_malloc.c
@@ -436,10 +436,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,
 		goto unlock;
 	}
 
-	rte_spinlock_lock(&heap->lock);
 	ret = malloc_heap_add_external_memory(heap, msl);
-	msl->heap = 1; /* mark it as heap segment */
-	rte_spinlock_unlock(&heap->lock);
 
 unlock:
 	rte_mcfg_mem_write_unlock();
@@ -482,9 +479,7 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len)
 		goto unlock;
 	}
 
-	rte_spinlock_lock(&heap->lock);
 	ret = malloc_heap_remove_external_memory(heap, va_addr, len);
-	rte_spinlock_unlock(&heap->lock);
 	if (ret != 0)
 		goto unlock;
 
@@ -655,12 +650,7 @@ rte_malloc_heap_destroy(const char *heap_name)
 		goto unlock;
 	}
 	/* sanity checks done, now we can destroy the heap */
-	rte_spinlock_lock(&heap->lock);
 	ret = malloc_heap_destroy(heap);
-
-	/* if we failed, lock is still active */
-	if (ret < 0)
-		rte_spinlock_unlock(&heap->lock);
 unlock:
 	rte_mcfg_mem_write_unlock();
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 02/14] mem: rework malloc heap init
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
  2023-02-24  8:16 ` [PATCH 01/14] malloc: rework heap lock handling David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 03/14] mem: annotate shared memory config locks David Marchand
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev
  Cc: thomas, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

rte_eal_memory_init() and rte_eal_malloc_heap_init() must be called in
a common section taking rte_mcfg_mem_read_lock().
Split rte_eal_malloc_heap_init() in two so that the mem lock is taken
in rte_eal_init() making lock checks trivial (once annotated in the next
patch).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_memory.c | 10 +---------
 lib/eal/common/malloc_heap.c       | 10 ++++++----
 lib/eal/common/malloc_heap.h       |  3 +++
 lib/eal/freebsd/eal.c              | 13 +++++++++++++
 lib/eal/linux/eal.c                | 13 +++++++++++++
 lib/eal/windows/eal.c              | 13 +++++++++++++
 6 files changed, 49 insertions(+), 13 deletions(-)

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index c917b981bc..5e162a1092 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1078,18 +1078,11 @@ rte_eal_memory_detach(void)
 int
 rte_eal_memory_init(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
-
 	int retval;
-	RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
-
-	if (!mcfg)
-		return -1;
 
-	/* lock mem hotplug here, to prevent races while we init */
-	rte_mcfg_mem_read_lock();
+	RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
 
 	if (rte_eal_memseg_init() < 0)
 		goto fail;
@@ -1108,7 +1101,6 @@ rte_eal_memory_init(void)
 
 	return 0;
 fail:
-	rte_mcfg_mem_read_unlock();
 	return -1;
 }
 
diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index cc84dce672..7498a05ed3 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -1442,18 +1442,20 @@ rte_eal_malloc_heap_init(void)
 		}
 	}
 
-
 	if (register_mp_requests()) {
 		RTE_LOG(ERR, EAL, "Couldn't register malloc multiprocess actions\n");
-		rte_mcfg_mem_read_unlock();
 		return -1;
 	}
 
-	/* unlock mem hotplug here. it's safe for primary as no requests can
+	return 0;
+}
+
+int rte_eal_malloc_heap_populate(void)
+{
+	/* mem hotplug is unlocked here. it's safe for primary as no requests can
 	 * even come before primary itself is fully initialized, and secondaries
 	 * do not need to initialize the heap.
 	 */
-	rte_mcfg_mem_read_unlock();
 
 	/* secondary process does not need to initialize anything */
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
diff --git a/lib/eal/common/malloc_heap.h b/lib/eal/common/malloc_heap.h
index 3b2fbc0aa0..8f3ab57154 100644
--- a/lib/eal/common/malloc_heap.h
+++ b/lib/eal/common/malloc_heap.h
@@ -85,6 +85,9 @@ malloc_socket_to_heap_id(unsigned int socket_id);
 int
 rte_eal_malloc_heap_init(void);
 
+int
+rte_eal_malloc_heap_populate(void);
+
 void
 rte_eal_malloc_heap_cleanup(void);
 
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 7db4239c51..7daf22e314 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -26,6 +26,7 @@
 #include <rte_memory.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <rte_errno.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
@@ -754,13 +755,25 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
 	}
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index fabafbc39b..7242ee2c9a 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -30,6 +30,7 @@
 #include <rte_memory.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <rte_service_component.h>
@@ -1197,7 +1198,10 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
@@ -1207,6 +1211,15 @@ rte_eal_init(int argc, char **argv)
 	eal_hugedirs_unlock();
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index e7d405b91c..033825c14c 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -12,6 +12,7 @@
 #include <rte_debug.h>
 #include <rte_bus.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
@@ -387,13 +388,25 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
 	}
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 03/14] mem: annotate shared memory config locks
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
  2023-02-24  8:16 ` [PATCH 01/14] malloc: rework heap lock handling David Marchand
  2023-02-24  8:16 ` [PATCH 02/14] mem: rework malloc heap init David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 04/14] hash: annotate cuckoo hash lock David Marchand
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas

Expose internal locks via some internal accessors.
Then annotate rte_mcfg_xxx_(read|write)_(|un)lock.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_mcfg.c    | 66 +++++++++++++++++------------
 lib/eal/include/rte_eal_memconfig.h | 63 +++++++++++++++++++++------
 lib/eal/version.map                 |  4 ++
 3 files changed, 91 insertions(+), 42 deletions(-)

diff --git a/lib/eal/common/eal_common_mcfg.c b/lib/eal/common/eal_common_mcfg.c
index cf4a279905..b60d41f7b6 100644
--- a/lib/eal/common/eal_common_mcfg.c
+++ b/lib/eal/common/eal_common_mcfg.c
@@ -69,102 +69,112 @@ eal_mcfg_update_from_internal(void)
 	mcfg->version = RTE_VERSION;
 }
 
+rte_rwlock_t *
+rte_mcfg_mem_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->memory_hotplug_lock;
+}
+
 void
 rte_mcfg_mem_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_read_lock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_read_unlock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_write_lock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_write_unlock(rte_mcfg_mem_get_lock());
+}
+
+rte_rwlock_t *
+rte_mcfg_tailq_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->qlock;
 }
 
 void
 rte_mcfg_tailq_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->qlock);
+	rte_rwlock_read_lock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->qlock);
+	rte_rwlock_read_unlock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->qlock);
+	rte_rwlock_write_lock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->qlock);
+	rte_rwlock_write_unlock(rte_mcfg_tailq_get_lock());
+}
+
+rte_rwlock_t *
+rte_mcfg_mempool_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->mplock;
 }
 
 void
 rte_mcfg_mempool_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->mplock);
+	rte_rwlock_read_lock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->mplock);
+	rte_rwlock_read_unlock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->mplock);
+	rte_rwlock_write_lock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->mplock);
+	rte_rwlock_write_unlock(rte_mcfg_mempool_get_lock());
+}
+
+rte_spinlock_t *
+rte_mcfg_timer_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->tlock;
 }
 
 void
 rte_mcfg_timer_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_spinlock_lock(&mcfg->tlock);
+	rte_spinlock_lock(rte_mcfg_timer_get_lock());
 }
 
 void
 rte_mcfg_timer_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_spinlock_unlock(&mcfg->tlock);
+	rte_spinlock_unlock(rte_mcfg_timer_get_lock());
 }
 
 bool
diff --git a/lib/eal/include/rte_eal_memconfig.h b/lib/eal/include/rte_eal_memconfig.h
index e175564647..c527f9aa29 100644
--- a/lib/eal/include/rte_eal_memconfig.h
+++ b/lib/eal/include/rte_eal_memconfig.h
@@ -7,6 +7,8 @@
 
 #include <stdbool.h>
 
+#include <rte_rwlock.h>
+#include <rte_spinlock.h>
 
 /**
  * @file
@@ -18,89 +20,122 @@
 extern "C" {
 #endif
 
+/**
+ * Internal helpers used for lock annotations.
+ */
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_mem_get_lock(void);
+
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_tailq_get_lock(void);
+
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_mempool_get_lock(void);
+
+__rte_internal
+rte_spinlock_t *
+rte_mcfg_timer_get_lock(void);
+
 /**
  * Lock the internal EAL shared memory configuration for shared access.
  */
 void
-rte_mcfg_mem_read_lock(void);
+rte_mcfg_mem_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Unlock the internal EAL shared memory configuration for shared access.
  */
 void
-rte_mcfg_mem_read_unlock(void);
+rte_mcfg_mem_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Lock the internal EAL shared memory configuration for exclusive access.
  */
 void
-rte_mcfg_mem_write_lock(void);
+rte_mcfg_mem_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Unlock the internal EAL shared memory configuration for exclusive access.
  */
 void
-rte_mcfg_mem_write_unlock(void);
+rte_mcfg_mem_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Lock the internal EAL TAILQ list for shared access.
  */
 void
-rte_mcfg_tailq_read_lock(void);
+rte_mcfg_tailq_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Unlock the internal EAL TAILQ list for shared access.
  */
 void
-rte_mcfg_tailq_read_unlock(void);
+rte_mcfg_tailq_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Lock the internal EAL TAILQ list for exclusive access.
  */
 void
-rte_mcfg_tailq_write_lock(void);
+rte_mcfg_tailq_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Unlock the internal EAL TAILQ list for exclusive access.
  */
 void
-rte_mcfg_tailq_write_unlock(void);
+rte_mcfg_tailq_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Lock the internal EAL Mempool list for shared access.
  */
 void
-rte_mcfg_mempool_read_lock(void);
+rte_mcfg_mempool_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Unlock the internal EAL Mempool list for shared access.
  */
 void
-rte_mcfg_mempool_read_unlock(void);
+rte_mcfg_mempool_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Lock the internal EAL Mempool list for exclusive access.
  */
 void
-rte_mcfg_mempool_write_lock(void);
+rte_mcfg_mempool_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Unlock the internal EAL Mempool list for exclusive access.
  */
 void
-rte_mcfg_mempool_write_unlock(void);
+rte_mcfg_mempool_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Lock the internal EAL Timer Library lock for exclusive access.
  */
 void
-rte_mcfg_timer_lock(void);
+rte_mcfg_timer_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_timer_get_lock());
 
 /**
  * Unlock the internal EAL Timer Library lock for exclusive access.
  */
 void
-rte_mcfg_timer_unlock(void);
+rte_mcfg_timer_unlock(void)
+	__rte_unlock_function(rte_mcfg_timer_get_lock());
 
 /**
  * If true, pages are put in single files (per memseg list),
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 6d6978f108..51a820d829 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -469,6 +469,10 @@ INTERNAL {
 	rte_intr_vec_list_free;
 	rte_intr_vec_list_index_get;
 	rte_intr_vec_list_index_set;
+	rte_mcfg_mem_get_lock;
+	rte_mcfg_mempool_get_lock;
+	rte_mcfg_tailq_get_lock;
+	rte_mcfg_timer_get_lock;
 	rte_mem_lock;
 	rte_mem_map;
 	rte_mem_page_size;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 04/14] hash: annotate cuckoo hash lock
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (2 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 03/14] mem: annotate shared memory config locks David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 05/14] graph: annotate graph lock David Marchand
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev
  Cc: thomas, Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin

__hash_rw_(reader|writer)_(|un)lock helpers take locks depending on
conditions that are fixed at the rte_hash object initialisation.
So we can tell clang that those helpers unconditionally take/release
those locks (and waive the lock check on their implementation).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/hash/rte_cuckoo_hash.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
index 829b79c89a..d92a903bb3 100644
--- a/lib/hash/rte_cuckoo_hash.c
+++ b/lib/hash/rte_cuckoo_hash.c
@@ -575,6 +575,8 @@ rte_hash_count(const struct rte_hash *h)
 /* Read write locks implemented using rte_rwlock */
 static inline void
 __hash_rw_writer_lock(const struct rte_hash *h)
+	__rte_exclusive_lock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->writer_takes_lock && h->hw_trans_mem_support)
 		rte_rwlock_write_lock_tm(h->readwrite_lock);
@@ -584,6 +586,8 @@ __hash_rw_writer_lock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_reader_lock(const struct rte_hash *h)
+	__rte_shared_lock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->readwrite_concur_support && h->hw_trans_mem_support)
 		rte_rwlock_read_lock_tm(h->readwrite_lock);
@@ -593,6 +597,8 @@ __hash_rw_reader_lock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_writer_unlock(const struct rte_hash *h)
+	__rte_unlock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->writer_takes_lock && h->hw_trans_mem_support)
 		rte_rwlock_write_unlock_tm(h->readwrite_lock);
@@ -602,6 +608,8 @@ __hash_rw_writer_unlock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_reader_unlock(const struct rte_hash *h)
+	__rte_unlock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->readwrite_concur_support && h->hw_trans_mem_support)
 		rte_rwlock_read_unlock_tm(h->readwrite_lock);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 05/14] graph: annotate graph lock
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (3 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 04/14] hash: annotate cuckoo hash lock David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 06/14] drivers: inherit lock annotations for Intel drivers David Marchand
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Jerin Jacob, Kiran Kumar K, Nithin Dabilpuram

Export internal lock and annotate associated helper.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/graph/graph.c         | 10 ++++++++--
 lib/graph/graph_private.h | 10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/graph/graph.c b/lib/graph/graph.c
index a839a2803b..5582631b53 100644
--- a/lib/graph/graph.c
+++ b/lib/graph/graph.c
@@ -30,16 +30,22 @@ graph_list_head_get(void)
 	return &graph_list;
 }
 
+rte_spinlock_t *
+graph_spinlock_get(void)
+{
+	return &graph_lock;
+}
+
 void
 graph_spinlock_lock(void)
 {
-	rte_spinlock_lock(&graph_lock);
+	rte_spinlock_lock(graph_spinlock_get());
 }
 
 void
 graph_spinlock_unlock(void)
 {
-	rte_spinlock_unlock(&graph_lock);
+	rte_spinlock_unlock(graph_spinlock_get());
 }
 
 static int
diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h
index 7d1b30b8ac..eacdef45f0 100644
--- a/lib/graph/graph_private.h
+++ b/lib/graph/graph_private.h
@@ -10,6 +10,7 @@
 
 #include <rte_common.h>
 #include <rte_eal.h>
+#include <rte_spinlock.h>
 
 #include "rte_graph.h"
 #include "rte_graph_worker.h"
@@ -148,20 +149,25 @@ STAILQ_HEAD(graph_head, graph);
  */
 struct graph_head *graph_list_head_get(void);
 
+rte_spinlock_t *
+graph_spinlock_get(void);
+
 /* Lock functions */
 /**
  * @internal
  *
  * Take a lock on the graph internal spin lock.
  */
-void graph_spinlock_lock(void);
+void graph_spinlock_lock(void)
+	__rte_exclusive_lock_function(graph_spinlock_get());
 
 /**
  * @internal
  *
  * Release a lock on the graph internal spin lock.
  */
-void graph_spinlock_unlock(void);
+void graph_spinlock_unlock(void)
+	__rte_unlock_function(graph_spinlock_get());
 
 /* Graph operations */
 /**
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 06/14] drivers: inherit lock annotations for Intel drivers
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (4 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 05/14] graph: annotate graph lock David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 07/14] net/cxgbe: inherit lock annotations David Marchand
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Jingjing Wu, Beilei Xing, Yuying Zhang, Qiming Yang, Qi Zhang

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/common/iavf/iavf_osdep.h       | 39 ++++++--------------------
 drivers/common/iavf/iavf_prototype.h   |  6 ----
 drivers/common/idpf/base/idpf_osdep.h  | 26 +++--------------
 drivers/net/i40e/base/i40e_osdep.h     |  8 +++---
 drivers/net/i40e/base/i40e_prototype.h |  5 ----
 drivers/net/i40e/i40e_ethdev.c         | 24 ----------------
 drivers/net/ice/base/ice_osdep.h       | 26 +++--------------
 7 files changed, 20 insertions(+), 114 deletions(-)

diff --git a/drivers/common/iavf/iavf_osdep.h b/drivers/common/iavf/iavf_osdep.h
index 31d3d809f9..263d92400c 100644
--- a/drivers/common/iavf/iavf_osdep.h
+++ b/drivers/common/iavf/iavf_osdep.h
@@ -170,11 +170,6 @@ struct iavf_virt_mem {
 	u32 size;
 } __rte_packed;
 
-/* SW spinlock */
-struct iavf_spinlock {
-	rte_spinlock_t spinlock;
-};
-
 #define iavf_allocate_dma_mem(h, m, unused, s, a) \
 			iavf_allocate_dma_mem_d(h, m, s, a)
 #define iavf_free_dma_mem(h, m) iavf_free_dma_mem_d(h, m)
@@ -182,32 +177,14 @@ struct iavf_spinlock {
 #define iavf_allocate_virt_mem(h, m, s) iavf_allocate_virt_mem_d(h, m, s)
 #define iavf_free_virt_mem(h, m) iavf_free_virt_mem_d(h, m)
 
-static inline void
-iavf_init_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-iavf_acquire_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-iavf_release_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-iavf_destroy_spinlock_d(__rte_unused struct iavf_spinlock *sp)
-{
-}
+/* SW spinlock */
+struct iavf_spinlock {
+	rte_spinlock_t spinlock;
+};
 
-#define iavf_init_spinlock(_sp) iavf_init_spinlock_d(_sp)
-#define iavf_acquire_spinlock(_sp) iavf_acquire_spinlock_d(_sp)
-#define iavf_release_spinlock(_sp) iavf_release_spinlock_d(_sp)
-#define iavf_destroy_spinlock(_sp) iavf_destroy_spinlock_d(_sp)
+#define iavf_init_spinlock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define iavf_acquire_spinlock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define iavf_release_spinlock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define iavf_destroy_spinlock(sp) RTE_SET_USED(sp)
 
 #endif /* _IAVF_OSDEP_H_ */
diff --git a/drivers/common/iavf/iavf_prototype.h b/drivers/common/iavf/iavf_prototype.h
index b5124de5bf..ba78ec5169 100644
--- a/drivers/common/iavf/iavf_prototype.h
+++ b/drivers/common/iavf/iavf_prototype.h
@@ -76,12 +76,6 @@ STATIC INLINE struct iavf_rx_ptype_decoded decode_rx_desc_ptype(u8 ptype)
 	return iavf_ptype_lookup[ptype];
 }
 
-/* prototype for functions used for SW spinlocks */
-void iavf_init_spinlock(struct iavf_spinlock *sp);
-void iavf_acquire_spinlock(struct iavf_spinlock *sp);
-void iavf_release_spinlock(struct iavf_spinlock *sp);
-void iavf_destroy_spinlock(struct iavf_spinlock *sp);
-
 __rte_internal
 void iavf_vf_parse_hw_config(struct iavf_hw *hw,
 			     struct virtchnl_vf_resource *msg);
diff --git a/drivers/common/idpf/base/idpf_osdep.h b/drivers/common/idpf/base/idpf_osdep.h
index 99ae9cf60a..49bd7c4b21 100644
--- a/drivers/common/idpf/base/idpf_osdep.h
+++ b/drivers/common/idpf/base/idpf_osdep.h
@@ -210,28 +210,10 @@ struct idpf_lock {
 	rte_spinlock_t spinlock;
 };
 
-static inline void
-idpf_init_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-idpf_acquire_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-idpf_release_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-idpf_destroy_lock(__rte_unused struct idpf_lock *sp)
-{
-}
+#define idpf_init_lock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define idpf_acquire_lock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define idpf_release_lock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define idpf_destroy_lock(sp) RTE_SET_USED(sp)
 
 struct idpf_hw;
 
diff --git a/drivers/net/i40e/base/i40e_osdep.h b/drivers/net/i40e/base/i40e_osdep.h
index 51537c5cf3..aa5dc61841 100644
--- a/drivers/net/i40e/base/i40e_osdep.h
+++ b/drivers/net/i40e/base/i40e_osdep.h
@@ -215,10 +215,10 @@ struct i40e_spinlock {
 	rte_spinlock_t spinlock;
 };
 
-#define i40e_init_spinlock(_sp) i40e_init_spinlock_d(_sp)
-#define i40e_acquire_spinlock(_sp) i40e_acquire_spinlock_d(_sp)
-#define i40e_release_spinlock(_sp) i40e_release_spinlock_d(_sp)
-#define i40e_destroy_spinlock(_sp) i40e_destroy_spinlock_d(_sp)
+#define i40e_init_spinlock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define i40e_acquire_spinlock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define i40e_release_spinlock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define i40e_destroy_spinlock(sp) RTE_SET_USED(sp)
 
 #define I40E_NTOHS(a) rte_be_to_cpu_16(a)
 #define I40E_NTOHL(a) rte_be_to_cpu_32(a)
diff --git a/drivers/net/i40e/base/i40e_prototype.h b/drivers/net/i40e/base/i40e_prototype.h
index 29c86c7fe8..691c977172 100644
--- a/drivers/net/i40e/base/i40e_prototype.h
+++ b/drivers/net/i40e/base/i40e_prototype.h
@@ -546,11 +546,6 @@ i40e_virtchnl_link_speed(enum i40e_aq_link_speed link_speed)
 	}
 }
 #endif /* PF_DRIVER */
-/* prototype for functions used for SW spinlocks */
-void i40e_init_spinlock(struct i40e_spinlock *sp);
-void i40e_acquire_spinlock(struct i40e_spinlock *sp);
-void i40e_release_spinlock(struct i40e_spinlock *sp);
-void i40e_destroy_spinlock(struct i40e_spinlock *sp);
 
 /* i40e_common for VF drivers*/
 void i40e_vf_parse_hw_config(struct i40e_hw *hw,
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 7726a89d99..cf2969f6ce 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -4622,30 +4622,6 @@ i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
 	return I40E_SUCCESS;
 }
 
-void
-i40e_init_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-void
-i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-void
-i40e_release_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-void
-i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp)
-{
-	return;
-}
-
 /**
  * Get the hardware capabilities, which will be parsed
  * and saved into struct i40e_hw.
diff --git a/drivers/net/ice/base/ice_osdep.h b/drivers/net/ice/base/ice_osdep.h
index 4b92057521..0e14b934c8 100644
--- a/drivers/net/ice/base/ice_osdep.h
+++ b/drivers/net/ice/base/ice_osdep.h
@@ -211,28 +211,10 @@ struct ice_lock {
 	rte_spinlock_t spinlock;
 };
 
-static inline void
-ice_init_lock(struct ice_lock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-ice_acquire_lock(struct ice_lock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-ice_release_lock(struct ice_lock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-ice_destroy_lock(__rte_unused struct ice_lock *sp)
-{
-}
+#define ice_init_lock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define ice_acquire_lock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define ice_release_lock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define ice_destroy_lock(sp) RTE_SET_USED(sp)
 
 struct ice_hw;
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 07/14] net/cxgbe: inherit lock annotations
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (5 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 06/14] drivers: inherit lock annotations for Intel drivers David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 08/14] net/fm10k: annotate mailbox lock David Marchand
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Rahul Lakkireddy

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/cxgbe/base/adapter.h | 35 +++++++-------------------------
 1 file changed, 7 insertions(+), 28 deletions(-)

diff --git a/drivers/net/cxgbe/base/adapter.h b/drivers/net/cxgbe/base/adapter.h
index 16cbc1a345..8f2ffa0eeb 100644
--- a/drivers/net/cxgbe/base/adapter.h
+++ b/drivers/net/cxgbe/base/adapter.h
@@ -351,28 +351,19 @@ struct adapter {
  * t4_os_rwlock_init - initialize rwlock
  * @lock: the rwlock
  */
-static inline void t4_os_rwlock_init(rte_rwlock_t *lock)
-{
-	rte_rwlock_init(lock);
-}
+#define t4_os_rwlock_init(lock) rte_rwlock_init(lock)
 
 /**
  * t4_os_write_lock - get a write lock
  * @lock: the rwlock
  */
-static inline void t4_os_write_lock(rte_rwlock_t *lock)
-{
-	rte_rwlock_write_lock(lock);
-}
+#define t4_os_write_lock(lock) rte_rwlock_write_lock(lock)
 
 /**
  * t4_os_write_unlock - unlock a write lock
  * @lock: the rwlock
  */
-static inline void t4_os_write_unlock(rte_rwlock_t *lock)
-{
-	rte_rwlock_write_unlock(lock);
-}
+#define t4_os_write_unlock(lock) rte_rwlock_write_unlock(lock)
 
 /**
  * ethdev2pinfo - return the port_info structure associated with a rte_eth_dev
@@ -678,37 +669,25 @@ static inline void t4_os_set_hw_addr(struct adapter *adapter, int port_idx,
  * t4_os_lock_init - initialize spinlock
  * @lock: the spinlock
  */
-static inline void t4_os_lock_init(rte_spinlock_t *lock)
-{
-	rte_spinlock_init(lock);
-}
+#define t4_os_lock_init(lock) rte_spinlock_init(lock)
 
 /**
  * t4_os_lock - spin until lock is acquired
  * @lock: the spinlock
  */
-static inline void t4_os_lock(rte_spinlock_t *lock)
-{
-	rte_spinlock_lock(lock);
-}
+#define t4_os_lock(lock) rte_spinlock_lock(lock)
 
 /**
  * t4_os_unlock - unlock a spinlock
  * @lock: the spinlock
  */
-static inline void t4_os_unlock(rte_spinlock_t *lock)
-{
-	rte_spinlock_unlock(lock);
-}
+#define t4_os_unlock(lock) rte_spinlock_unlock(lock)
 
 /**
  * t4_os_trylock - try to get a lock
  * @lock: the spinlock
  */
-static inline int t4_os_trylock(rte_spinlock_t *lock)
-{
-	return rte_spinlock_trylock(lock);
-}
+#define t4_os_trylock(lock) rte_spinlock_trylock(lock)
 
 /**
  * t4_os_init_list_head - initialize
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 08/14] net/fm10k: annotate mailbox lock
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (6 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 07/14] net/cxgbe: inherit lock annotations David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 09/14] net/sfc: rework locking in proxy code David Marchand
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Qi Zhang, Xiao Wang

Expose requirements for helpers dealing with the
FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back) lock.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/fm10k/fm10k_ethdev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 8b83063f0a..4d3c4c10cf 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -116,6 +116,7 @@ fm10k_mbx_initlock(struct fm10k_hw *hw)
 
 static void
 fm10k_mbx_lock(struct fm10k_hw *hw)
+	__rte_exclusive_lock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
 {
 	while (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)))
 		rte_delay_us(FM10K_MBXLOCK_DELAY_US);
@@ -123,6 +124,7 @@ fm10k_mbx_lock(struct fm10k_hw *hw)
 
 static void
 fm10k_mbx_unlock(struct fm10k_hw *hw)
+	__rte_unlock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
 {
 	rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 09/14] net/sfc: rework locking in proxy code
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (7 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 08/14] net/fm10k: annotate mailbox lock David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 10/14] net/sfc: inherit lock annotations David Marchand
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Andrew Rybchenko

Remove one extra layer for proxy code: sfc_get_adapter_by_pf_port_id()
now only resolves the sa object and sfc_adapter_(|un)lock() are added
were necessary.

This will simplify lock checks later.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/sfc/sfc_repr_proxy.c | 59 ++++++++++++++++----------------
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/drivers/net/sfc/sfc_repr_proxy.c b/drivers/net/sfc/sfc_repr_proxy.c
index 4b958ced61..4ba7683370 100644
--- a/drivers/net/sfc/sfc_repr_proxy.c
+++ b/drivers/net/sfc/sfc_repr_proxy.c
@@ -51,17 +51,9 @@ sfc_get_adapter_by_pf_port_id(uint16_t pf_port_id)
 	dev = &rte_eth_devices[pf_port_id];
 	sa = sfc_adapter_by_eth_dev(dev);
 
-	sfc_adapter_lock(sa);
-
 	return sa;
 }
 
-static void
-sfc_put_adapter(struct sfc_adapter *sa)
-{
-	sfc_adapter_unlock(sa);
-}
-
 static struct sfc_repr_proxy_port *
 sfc_repr_proxy_find_port(struct sfc_repr_proxy *rp, uint16_t repr_id)
 {
@@ -1289,6 +1281,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1341,7 +1334,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 	}
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
@@ -1352,7 +1345,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 fail_alloc_port:
 fail_port_exists:
 	sfc_log_init(sa, "failed: %s", rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1366,6 +1359,7 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1393,14 +1387,14 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)
 
 	sfc_log_init(sa, "done");
 
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
 fail_port_remove:
 fail_no_port:
 	sfc_log_init(sa, "failed: %s", rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1416,6 +1410,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1423,14 +1418,14 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
 	rxq = &port->rxq[queue_id];
 	if (rp->dp_rxq[queue_id].mp != NULL && rp->dp_rxq[queue_id].mp != mp) {
 		sfc_err(sa, "multiple mempools per queue are not supported");
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOTSUP;
 	}
 
@@ -1440,7 +1435,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	rp->dp_rxq[queue_id].ref_count++;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1455,6 +1450,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1462,7 +1458,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return;
 	}
 
@@ -1475,7 +1471,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 		rp->dp_rxq[queue_id].mp = NULL;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 }
 
 int
@@ -1489,6 +1485,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1496,7 +1493,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
@@ -1507,7 +1504,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	*egress_mport = port->egress_mport;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1522,6 +1519,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1529,7 +1527,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return;
 	}
 
@@ -1538,7 +1536,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	txq->ring = NULL;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 }
 
 int
@@ -1551,6 +1549,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1594,7 +1593,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 	}
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
@@ -1606,7 +1605,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 fail_not_found:
 	sfc_err(sa, "failed to start repr %u proxy port: %s", repr_id,
 		rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1621,6 +1620,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1628,14 +1628,14 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
 	if (!port->enabled) {
 		sfc_log_init(sa, "repr %u proxy port is not started - skip",
 			     repr_id);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return 0;
 	}
 
@@ -1662,7 +1662,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 			sfc_err(sa,
 				"failed to stop representor proxy TxQ %u: %s",
 				repr_id, rte_strerror(rc));
-			sfc_put_adapter(sa);
+			sfc_adapter_unlock(sa);
 			return rc;
 		}
 	}
@@ -1670,7 +1670,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	port->enabled = false;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1685,13 +1685,14 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port (repr_id=%u)",
 			__func__, repr_id);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
@@ -1703,7 +1704,7 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,
 			__func__, repr_id, rte_strerror(rc));
 	}
 
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 10/14] net/sfc: inherit lock annotations
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (8 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 09/14] net/sfc: rework locking in proxy code David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 11/14] net/virtio: annotate lock for guest announce David Marchand
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Andrew Rybchenko

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

One additional change is required in sfc_ev_qpoll() so that clang does
see the same lock is being manipulated.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/sfc/sfc.h      | 41 ++++++--------------------------------
 drivers/net/sfc/sfc_ev.c   |  6 ++++--
 drivers/net/sfc/sfc_repr.c | 38 +++++------------------------------
 3 files changed, 15 insertions(+), 70 deletions(-)

diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index 0a1e224fa2..730d054aea 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -333,41 +333,12 @@ sfc_sa2shared(struct sfc_adapter *sa)
  * change the lock in one place.
  */
 
-static inline void
-sfc_adapter_lock_init(struct sfc_adapter *sa)
-{
-	rte_spinlock_init(&sa->lock);
-}
-
-static inline int
-sfc_adapter_is_locked(struct sfc_adapter *sa)
-{
-	return rte_spinlock_is_locked(&sa->lock);
-}
-
-static inline void
-sfc_adapter_lock(struct sfc_adapter *sa)
-{
-	rte_spinlock_lock(&sa->lock);
-}
-
-static inline int
-sfc_adapter_trylock(struct sfc_adapter *sa)
-{
-	return rte_spinlock_trylock(&sa->lock);
-}
-
-static inline void
-sfc_adapter_unlock(struct sfc_adapter *sa)
-{
-	rte_spinlock_unlock(&sa->lock);
-}
-
-static inline void
-sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_adapter_lock_init(sa) rte_spinlock_init(&(sa)->lock)
+#define sfc_adapter_is_locked(sa) rte_spinlock_is_locked(&(sa)->lock)
+#define sfc_adapter_lock(sa) rte_spinlock_lock(&(sa)->lock)
+#define sfc_adapter_trylock(sa) rte_spinlock_trylock(&(sa)->lock)
+#define sfc_adapter_unlock(sa) rte_spinlock_unlock(&(sa)->lock)
+#define sfc_adapter_lock_fini(sa) RTE_SET_USED(sa)
 
 static inline unsigned int
 sfc_nb_counter_rxq(const struct sfc_adapter_shared *sas)
diff --git a/drivers/net/sfc/sfc_ev.c b/drivers/net/sfc/sfc_ev.c
index f949abbfc3..c0d58c9554 100644
--- a/drivers/net/sfc/sfc_ev.c
+++ b/drivers/net/sfc/sfc_ev.c
@@ -570,6 +570,8 @@ static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {
 void
 sfc_ev_qpoll(struct sfc_evq *evq)
 {
+	struct sfc_adapter *sa;
+
 	SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED ||
 		   evq->init_state == SFC_EVQ_STARTING);
 
@@ -577,8 +579,8 @@ sfc_ev_qpoll(struct sfc_evq *evq)
 
 	efx_ev_qpoll(evq->common, &evq->read_ptr, evq->callbacks, evq);
 
-	if (unlikely(evq->exception) && sfc_adapter_trylock(evq->sa)) {
-		struct sfc_adapter *sa = evq->sa;
+	sa = evq->sa;
+	if (unlikely(evq->exception) && sfc_adapter_trylock(sa)) {
 		int rc;
 
 		if (evq->dp_rxq != NULL) {
diff --git a/drivers/net/sfc/sfc_repr.c b/drivers/net/sfc/sfc_repr.c
index 4b03b101d8..017c3fb247 100644
--- a/drivers/net/sfc/sfc_repr.c
+++ b/drivers/net/sfc/sfc_repr.c
@@ -112,39 +112,11 @@ sfc_repr_by_eth_dev(struct rte_eth_dev *eth_dev)
  * change the lock in one place.
  */
 
-static inline void
-sfc_repr_lock_init(struct sfc_repr *sr)
-{
-	rte_spinlock_init(&sr->lock);
-}
-
-#if defined(RTE_LIBRTE_SFC_EFX_DEBUG) || defined(RTE_ENABLE_ASSERT)
-
-static inline int
-sfc_repr_lock_is_locked(struct sfc_repr *sr)
-{
-	return rte_spinlock_is_locked(&sr->lock);
-}
-
-#endif
-
-static inline void
-sfc_repr_lock(struct sfc_repr *sr)
-{
-	rte_spinlock_lock(&sr->lock);
-}
-
-static inline void
-sfc_repr_unlock(struct sfc_repr *sr)
-{
-	rte_spinlock_unlock(&sr->lock);
-}
-
-static inline void
-sfc_repr_lock_fini(__rte_unused struct sfc_repr *sr)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_repr_lock_init(sr) rte_spinlock_init(&(sr)->lock)
+#define sfc_repr_lock_is_locked(sr) rte_spinlock_is_locked(&(sr)->lock)
+#define sfc_repr_lock(sr) rte_spinlock_lock(&(sr)->lock)
+#define sfc_repr_unlock(sr) rte_spinlock_unlock(&(sr)->lock)
+#define sfc_repr_lock_fini(sr) RTE_SET_USED(sr)
 
 static void
 sfc_repr_rx_queue_stop(void *queue)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 11/14] net/virtio: annotate lock for guest announce
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (9 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 10/14] net/sfc: inherit lock annotations David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 12/14] raw/ifpga: inherit lock annotations David Marchand
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Maxime Coquelin, Chenbo Xia

Expose requirements for helpers dealing with the
VIRTIO_DEV_TO_HW(dev)->state_lock lock.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/virtio/virtio_ethdev.c | 8 ++++----
 drivers/net/virtio/virtio_ethdev.h | 7 +++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 0103d95920..a3de44958c 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1149,11 +1149,11 @@ virtio_dev_pause(struct rte_eth_dev *dev)
 {
 	struct virtio_hw *hw = dev->data->dev_private;
 
-	rte_spinlock_lock(&hw->state_lock);
+	rte_spinlock_lock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
 
 	if (hw->started == 0) {
 		/* Device is just stopped. */
-		rte_spinlock_unlock(&hw->state_lock);
+		rte_spinlock_unlock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
 		return -1;
 	}
 	hw->started = 0;
@@ -1174,7 +1174,7 @@ virtio_dev_resume(struct rte_eth_dev *dev)
 	struct virtio_hw *hw = dev->data->dev_private;
 
 	hw->started = 1;
-	rte_spinlock_unlock(&hw->state_lock);
+	rte_spinlock_unlock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
 }
 
 /*
@@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev)
 	}
 
 	/* If virtio port just stopped, no need to send RARP */
-	if (virtio_dev_pause(dev) < 0) {
+	if (virtio_dev_pause(dev) != 0) {
 		rte_pktmbuf_free(rarp_mbuf);
 		return;
 	}
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index c08f382791..ece0130603 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
 
 void virtio_interrupt_handler(void *param);
 
-int virtio_dev_pause(struct rte_eth_dev *dev);
-void virtio_dev_resume(struct rte_eth_dev *dev);
+#define VIRTIO_DEV_TO_HW(dev) ((struct virtio_hw *)(dev)->data->dev_private)
+int virtio_dev_pause(struct rte_eth_dev *dev)
+	__rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)->state_lock);
+void virtio_dev_resume(struct rte_eth_dev *dev)
+	__rte_unlock_function(&VIRTIO_DEV_TO_HW(dev)->state_lock);
 int virtio_dev_stop(struct rte_eth_dev *dev);
 int virtio_dev_close(struct rte_eth_dev *dev);
 int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 12/14] raw/ifpga: inherit lock annotations
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (10 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 11/14] net/virtio: annotate lock for guest announce David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 13/14] vdpa/sfc: " David Marchand
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Rosen Xu, Tianfei Zhang

The checks in those helpers are useless:
- all (start/stop/reset/test) callers ensure that dev != NULL,
- dev->sd can't be NULL either as it would mean the application is calling
  those helpers for a dev pointer that did not pass initialisation,

Once the checks are removed, the only thing that remains is calls to the
rte_spinlock API, so simply use macros and inherit annotations from the
lock API.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/raw/ifpga/afu_pmd_core.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/raw/ifpga/afu_pmd_core.c b/drivers/raw/ifpga/afu_pmd_core.c
index ddf7a34f33..3ab1f47ac1 100644
--- a/drivers/raw/ifpga/afu_pmd_core.c
+++ b/drivers/raw/ifpga/afu_pmd_core.c
@@ -23,21 +23,8 @@ static struct rte_afu_uuid afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1];
 TAILQ_HEAD(afu_drv_list, afu_rawdev_drv);
 static struct afu_drv_list afu_pmd_list = TAILQ_HEAD_INITIALIZER(afu_pmd_list);
 
-static inline int afu_rawdev_trylock(struct afu_rawdev *dev)
-{
-	if (!dev || !dev->sd)
-		return 0;
-
-	return rte_spinlock_trylock(&dev->sd->lock);
-}
-
-static inline void afu_rawdev_unlock(struct afu_rawdev *dev)
-{
-	if (!dev || !dev->sd)
-		return;
-
-	rte_spinlock_unlock(&dev->sd->lock);
-}
+#define afu_rawdev_trylock(dev) rte_spinlock_trylock(&dev->sd->lock)
+#define afu_rawdev_unlock(dev) rte_spinlock_unlock(&dev->sd->lock)
 
 static int afu_rawdev_configure(const struct rte_rawdev *rawdev,
 	rte_rawdev_obj_t config, size_t config_size)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 13/14] vdpa/sfc: inherit lock annotations
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (11 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 12/14] raw/ifpga: inherit lock annotations David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24  8:16 ` [PATCH 14/14] enable lock check David Marchand
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev; +Cc: thomas, Vijay Kumar Srivastava

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

sfc_vdpa_ops.c was relying on an implicit cast of the dev_handle to a
vdpa adapter object. Add an explicit conversion.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/vdpa/sfc/sfc_vdpa.h     | 41 +++++----------------------------
 drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 +++++------
 2 files changed, 13 insertions(+), 42 deletions(-)

diff --git a/drivers/vdpa/sfc/sfc_vdpa.h b/drivers/vdpa/sfc/sfc_vdpa.h
index b25eb3a5fe..2b843e563d 100644
--- a/drivers/vdpa/sfc/sfc_vdpa.h
+++ b/drivers/vdpa/sfc/sfc_vdpa.h
@@ -122,40 +122,11 @@ sfc_vdpa_adapter_by_dev_handle(void *dev_handle)
  * Add wrapper functions to acquire/release lock to be able to remove or
  * change the lock in one place.
  */
-static inline void
-sfc_vdpa_adapter_lock_init(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_init(&sva->lock);
-}
-
-static inline int
-sfc_vdpa_adapter_is_locked(struct sfc_vdpa_adapter *sva)
-{
-	return rte_spinlock_is_locked(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_lock(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_lock(&sva->lock);
-}
-
-static inline int
-sfc_vdpa_adapter_trylock(struct sfc_vdpa_adapter *sva)
-{
-	return rte_spinlock_trylock(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_unlock(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_unlock(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_lock_fini(__rte_unused struct sfc_vdpa_adapter *sva)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_vdpa_adapter_lock_init(sva) rte_spinlock_init(&(sva)->lock)
+#define sfc_vdpa_adapter_is_locked(sva) rte_spinlock_is_locked(&(sva)->lock)
+#define sfc_vdpa_adapter_lock(sva) rte_spinlock_lock(&(sva)->lock)
+#define sfc_vdpa_adapter_trylock(sva) rte_spinlock_trylock(&(sva)->lock)
+#define sfc_vdpa_adapter_unlock(sva) rte_spinlock_unlock(&(sva)->lock)
+#define sfc_vdpa_adapter_lock_fini(sva) RTE_SET_USED(sva)
 
 #endif  /* _SFC_VDPA_H */
diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.c b/drivers/vdpa/sfc/sfc_vdpa_ops.c
index 6401d4e16f..afa6b7e8ef 100644
--- a/drivers/vdpa/sfc/sfc_vdpa_ops.c
+++ b/drivers/vdpa/sfc/sfc_vdpa_ops.c
@@ -577,7 +577,7 @@ sfc_vdpa_notify_ctrl(void *arg)
 	if (ops_data == NULL)
 		return NULL;
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	vid = ops_data->vid;
 
@@ -586,7 +586,7 @@ sfc_vdpa_notify_ctrl(void *arg)
 			      "vDPA (%s): Notifier could not get configured",
 			      ops_data->vdpa_dev->device->name);
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return NULL;
 }
@@ -637,7 +637,7 @@ sfc_vdpa_dev_config(int vid)
 
 	ops_data->vid = vid;
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	sfc_vdpa_log_init(ops_data->dev_handle, "configuring");
 	rc = sfc_vdpa_configure(ops_data);
@@ -653,7 +653,7 @@ sfc_vdpa_dev_config(int vid)
 	if (rc != 0)
 		goto fail_vdpa_notify;
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	sfc_vdpa_log_init(ops_data->dev_handle, "done");
 
@@ -666,7 +666,7 @@ sfc_vdpa_dev_config(int vid)
 	sfc_vdpa_close(ops_data);
 
 fail_vdpa_config:
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return -1;
 }
@@ -688,7 +688,7 @@ sfc_vdpa_dev_close(int vid)
 		return -1;
 	}
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 	if (ops_data->is_notify_thread_started == true) {
 		void *status;
 		ret = pthread_cancel(ops_data->notify_tid);
@@ -710,7 +710,7 @@ sfc_vdpa_dev_close(int vid)
 	sfc_vdpa_stop(ops_data);
 	sfc_vdpa_close(ops_data);
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 14/14] enable lock check
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (12 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 13/14] vdpa/sfc: " David Marchand
@ 2023-02-24  8:16 ` David Marchand
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
  15 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24  8:16 UTC (permalink / raw)
  To: dev
  Cc: thomas, Anatoly Burakov, Hemant Agrawal, Sachin Saxena,
	Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Matan Azrad, Viacheslav Ovsiienko, Pavan Nikhilesh,
	Shijith Thotton, Rasesh Mody, Shahed Shaikh, Ajit Khaparde,
	Somnath Kotur, John Daley, Hyong Youb Kim, Dongdong Liu,
	Yisen Zhuang, Konstantin Ananyev, Vladimir Medvedkin,
	Erik Gabriel Carrillo, Maxime Coquelin, Chenbo Xia

Now that a lot of components can be compiled with the lock checks,
invert the logic and opt out for components not ready yet:
- drivers/bus/dpaa,
- drivers/common/cnxk,
- drivers/common/mlx5,
- drivers/event/cnxk,
- drivers/net/bnx2x,
- drivers/net/bnxt,
- drivers/net/cnxk,
- drivers/net/enic,
- drivers/net/hns3,
- drivers/net/mlx5,
- lib/ipsec,
- lib/timer,

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++--
 drivers/bus/dpaa/meson.build                    | 1 +
 drivers/common/cnxk/meson.build                 | 1 +
 drivers/common/mlx5/meson.build                 | 1 +
 drivers/event/cnxk/meson.build                  | 1 +
 drivers/meson.build                             | 2 +-
 drivers/net/bnx2x/meson.build                   | 1 +
 drivers/net/bnxt/meson.build                    | 1 +
 drivers/net/cnxk/meson.build                    | 1 +
 drivers/net/enic/meson.build                    | 1 +
 drivers/net/hns3/meson.build                    | 1 +
 drivers/net/mlx5/meson.build                    | 1 +
 lib/ipsec/meson.build                           | 1 +
 lib/meson.build                                 | 2 +-
 lib/timer/meson.build                           | 1 +
 lib/vhost/meson.build                           | 1 -
 16 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
index 3f33621e05..93c8a031be 100644
--- a/doc/guides/prog_guide/env_abstraction_layer.rst
+++ b/doc/guides/prog_guide/env_abstraction_layer.rst
@@ -550,8 +550,9 @@ Some general comments:
   waiving checks with ``__rte_no_thread_safety_analysis`` in your code, please
   discuss it on the mailing list,
 
-A DPDK library/driver can enable/disable the checks by setting
-``annotate_locks`` accordingly in its ``meson.build`` file.
+The checks are enabled by default for libraries and drivers.
+They can be disabled by setting ``annotate_locks`` to ``false`` in
+the concerned library/driver ``meson.build``.
 
 IOVA Mode Detection
 ~~~~~~~~~~~~~~~~~~~
diff --git a/drivers/bus/dpaa/meson.build b/drivers/bus/dpaa/meson.build
index 5506f2bffc..183b251459 100644
--- a/drivers/bus/dpaa/meson.build
+++ b/drivers/bus/dpaa/meson.build
@@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith')
 endif
 
 includes += include_directories('include', 'base/qbman')
+annotate_locks = false
diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
index 849735921c..9beb1cddba 100644
--- a/drivers/common/cnxk/meson.build
+++ b/drivers/common/cnxk/meson.build
@@ -88,3 +88,4 @@ sources += files('cnxk_telemetry_bphy.c',
 
 deps += ['bus_pci', 'net', 'telemetry']
 pmd_supports_disable_iova_as_pa = true
+annotate_locks = false
diff --git a/drivers/common/mlx5/meson.build b/drivers/common/mlx5/meson.build
index 60ccd95cbc..d38255dc82 100644
--- a/drivers/common/mlx5/meson.build
+++ b/drivers/common/mlx5/meson.build
@@ -40,3 +40,4 @@ endif
 mlx5_config = configuration_data()
 subdir(exec_env)
 configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config)
+annotate_locks = false
diff --git a/drivers/event/cnxk/meson.build b/drivers/event/cnxk/meson.build
index aa42ab3a90..20c6a0484a 100644
--- a/drivers/event/cnxk/meson.build
+++ b/drivers/event/cnxk/meson.build
@@ -480,3 +480,4 @@ endforeach
 
 deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk']
 pmd_supports_disable_iova_as_pa = true
+annotate_locks = false
diff --git a/drivers/meson.build b/drivers/meson.build
index 0618c31a69..d529980fc5 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -91,7 +91,7 @@ foreach subpath:subdirs
         build = true # set to false to disable, e.g. missing deps
         reason = '<unknown reason>' # set if build == false to explain
         name = drv
-        annotate_locks = false
+        annotate_locks = true
         sources = []
         headers = []
         driver_sdk_headers = [] # public headers included by drivers
diff --git a/drivers/net/bnx2x/meson.build b/drivers/net/bnx2x/meson.build
index 156f97d31f..dbf9c7225d 100644
--- a/drivers/net/bnx2x/meson.build
+++ b/drivers/net/bnx2x/meson.build
@@ -21,3 +21,4 @@ sources = files(
         'ecore_sp.c',
         'elink.c',
 )
+annotate_locks = false
diff --git a/drivers/net/bnxt/meson.build b/drivers/net/bnxt/meson.build
index 09d494e90f..f43dbfc445 100644
--- a/drivers/net/bnxt/meson.build
+++ b/drivers/net/bnxt/meson.build
@@ -68,3 +68,4 @@ if arch_subdir == 'x86'
 elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64')
     sources += files('bnxt_rxtx_vec_neon.c')
 endif
+annotate_locks = false
diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
index c7ca24d437..86ed2d13dd 100644
--- a/drivers/net/cnxk/meson.build
+++ b/drivers/net/cnxk/meson.build
@@ -196,3 +196,4 @@ endforeach
 
 headers = files('rte_pmd_cnxk.h')
 pmd_supports_disable_iova_as_pa = true
+annotate_locks = false
diff --git a/drivers/net/enic/meson.build b/drivers/net/enic/meson.build
index 7131a25f09..1523511ba5 100644
--- a/drivers/net/enic/meson.build
+++ b/drivers/net/enic/meson.build
@@ -39,3 +39,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64')
             c_args: [cflags, '-mavx2'])
     objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c')
 endif
+annotate_locks = false
diff --git a/drivers/net/hns3/meson.build b/drivers/net/hns3/meson.build
index e1a5afa2ec..43e52e6107 100644
--- a/drivers/net/hns3/meson.build
+++ b/drivers/net/hns3/meson.build
@@ -38,6 +38,7 @@ sources = files(
         'hns3_common.c',
         'hns3_dump.c',
 )
+annotate_locks = false
 
 deps += ['hash']
 
diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
index abd507bd88..5e7d0d4e1a 100644
--- a/drivers/net/mlx5/meson.build
+++ b/drivers/net/mlx5/meson.build
@@ -79,3 +79,4 @@ testpmd_sources += files('mlx5_testpmd.c')
 subdir(exec_env)
 
 subdir('hws')
+annotate_locks = false
diff --git a/lib/ipsec/meson.build b/lib/ipsec/meson.build
index 0b8b935cd2..ff44d6fbdf 100644
--- a/lib/ipsec/meson.build
+++ b/lib/ipsec/meson.build
@@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c',
 
 headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h')
 indirect_headers += files('rte_ipsec_group.h')
+annotate_locks = false
 
 deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
diff --git a/lib/meson.build b/lib/meson.build
index 2bc0932ad5..9b5e412454 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -120,7 +120,7 @@ foreach l:libraries
     reason = '<unknown reason>' # set if build == false to explain why
     name = l
     use_function_versioning = false
-    annotate_locks = false
+    annotate_locks = true
     sources = []
     headers = []
     indirect_headers = [] # public headers not directly included by apps
diff --git a/lib/timer/meson.build b/lib/timer/meson.build
index 89b17e0397..87bbb10592 100644
--- a/lib/timer/meson.build
+++ b/lib/timer/meson.build
@@ -3,3 +3,4 @@
 
 sources = files('rte_timer.c')
 headers = files('rte_timer.h')
+annotate_locks = false
diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build
index 197a51d936..0d1abf6283 100644
--- a/lib/vhost/meson.build
+++ b/lib/vhost/meson.build
@@ -18,7 +18,6 @@ endif
 dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h'))
 cflags += '-fno-strict-aliasing'
 
-annotate_locks = true
 sources = files(
         'fd_man.c',
         'iotlb.c',
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (13 preceding siblings ...)
  2023-02-24  8:16 ` [PATCH 14/14] enable lock check David Marchand
@ 2023-02-24 15:11 ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 01/20] malloc: rework heap lock handling David Marchand
                     ` (20 more replies)
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
  15 siblings, 21 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas

This is a followup of the series that introduced lock annotations.
I reworked and made annotations work in what seemed the easier cases.
In most cases, I chose to convert inline wrappers around the EAL lock
API to simple macro: I did not see much value in those wrappers and this
is way simpler than adding __rte_*lock_function tags everywhere.

A list of libraries and drivers still need more work as their code have
non obvious locks handling. For those components, the check is opted
out.
I leave it to their respective maintainers to enable the checks later.

FreeBSD libc pthread API has lock annotations while Linux glibc has
none.
We could simply disable the check on FreeBSD, but having this check,
a few issues got raised in drivers that are built with FreeBSD.
For now, I went with a simple #ifdef FreeBSD for pthread mutex related
annotations in our code.

Maintainers, please review.


-- 
David Marchand

Changes since v1:
- annotate code relying on pthread mutexes for FreeBSD libc that
  put annotations on its pthread API,
- annotate Windows alarm code,


David Marchand (20):
  malloc: rework heap lock handling
  mem: rework malloc heap init
  mem: annotate shared memory config locks
  hash: annotate cuckoo hash lock
  graph: annotate graph lock
  drivers: inherit lock annotations for Intel drivers
  net/cxgbe: inherit lock annotations
  net/fm10k: annotate mailbox lock
  net/sfc: rework locking in proxy code
  net/sfc: inherit lock annotations
  net/virtio: annotate lock for guest announce
  raw/ifpga: inherit lock annotations
  vdpa/sfc: inherit lock annotations
  ipc: annotate pthread mutex
  ethdev: annotate pthread mutex
  net/failsafe: fix mutex locking
  net/failsafe: annotate pthread mutex
  net/hinic: annotate pthread mutex
  eal/windows: disable lock check on alarm code
  enable lock check

 .../prog_guide/env_abstraction_layer.rst      |   5 +-
 drivers/bus/dpaa/meson.build                  |   1 +
 drivers/common/cnxk/meson.build               |   1 +
 drivers/common/iavf/iavf_osdep.h              |  39 +----
 drivers/common/iavf/iavf_prototype.h          |   6 -
 drivers/common/idpf/base/idpf_osdep.h         |  26 +---
 drivers/common/mlx5/meson.build               |   1 +
 drivers/event/cnxk/meson.build                |   1 +
 drivers/meson.build                           |   2 +-
 drivers/net/bnx2x/meson.build                 |   1 +
 drivers/net/bnxt/meson.build                  |   1 +
 drivers/net/cnxk/meson.build                  |   1 +
 drivers/net/cxgbe/base/adapter.h              |  35 +----
 drivers/net/enic/meson.build                  |   1 +
 drivers/net/failsafe/failsafe_ether.c         |   3 +-
 drivers/net/failsafe/failsafe_flow.c          |  23 ++-
 drivers/net/failsafe/failsafe_ops.c           | 142 +++++++++++++-----
 drivers/net/failsafe/failsafe_private.h       |   6 +
 drivers/net/fm10k/fm10k_ethdev.c              |   2 +
 drivers/net/hinic/base/hinic_compat.h         |   6 +
 drivers/net/hns3/meson.build                  |   1 +
 drivers/net/i40e/base/i40e_osdep.h            |   8 +-
 drivers/net/i40e/base/i40e_prototype.h        |   5 -
 drivers/net/i40e/i40e_ethdev.c                |  24 ---
 drivers/net/ice/base/ice_osdep.h              |  26 +---
 drivers/net/mlx5/meson.build                  |   1 +
 drivers/net/sfc/sfc.h                         |  41 +----
 drivers/net/sfc/sfc_ev.c                      |   6 +-
 drivers/net/sfc/sfc_repr.c                    |  38 +----
 drivers/net/sfc/sfc_repr_proxy.c              |  59 ++++----
 drivers/net/virtio/virtio_ethdev.c            |   8 +-
 drivers/net/virtio/virtio_ethdev.h            |   7 +-
 drivers/raw/ifpga/afu_pmd_core.c              |  17 +--
 drivers/vdpa/sfc/sfc_vdpa.h                   |  41 +----
 drivers/vdpa/sfc/sfc_vdpa_ops.c               |  14 +-
 lib/eal/common/eal_common_mcfg.c              |  66 ++++----
 lib/eal/common/eal_common_memory.c            |  10 +-
 lib/eal/common/eal_common_proc.c              |   3 +
 lib/eal/common/malloc_heap.c                  |  55 +++++--
 lib/eal/common/malloc_heap.h                  |   3 +
 lib/eal/common/rte_malloc.c                   |  10 --
 lib/eal/freebsd/eal.c                         |  13 ++
 lib/eal/include/rte_eal_memconfig.h           |  63 ++++++--
 lib/eal/linux/eal.c                           |  13 ++
 lib/eal/version.map                           |   4 +
 lib/eal/windows/eal.c                         |  13 ++
 lib/eal/windows/eal_alarm.c                   |   2 +
 lib/ethdev/rte_flow.c                         |   8 +
 lib/graph/graph.c                             |  10 +-
 lib/graph/graph_private.h                     |  10 +-
 lib/hash/rte_cuckoo_hash.c                    |   8 +
 lib/ipsec/meson.build                         |   1 +
 lib/meson.build                               |   2 +-
 lib/timer/meson.build                         |   1 +
 lib/vhost/meson.build                         |   1 -
 55 files changed, 461 insertions(+), 434 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 01/20] malloc: rework heap lock handling
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 02/20] mem: rework malloc heap init David Marchand
                     ` (19 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Anatoly Burakov

Move all heap->lock manipulation to malloc_heap.c to have a single
location where to look at and make higher level code unaware of this
locking constraint.

The destroy helper has been reworked to zero all the heap object but
leave the lock untouched. The heap lock is then released through the
standard API.
This makes the code less scary even though, at this point of its life,
the heap object is probably referenced only by the caller.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/malloc_heap.c | 45 +++++++++++++++++++++++++++---------
 lib/eal/common/rte_malloc.c  | 10 --------
 2 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index d7c410b786..cc84dce672 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -1292,6 +1292,8 @@ int
 malloc_heap_add_external_memory(struct malloc_heap *heap,
 		struct rte_memseg_list *msl)
 {
+	rte_spinlock_lock(&heap->lock);
+
 	/* erase contents of new memory */
 	memset(msl->base_va, 0, msl->len);
 
@@ -1308,6 +1310,11 @@ malloc_heap_add_external_memory(struct malloc_heap *heap,
 	eal_memalloc_mem_event_notify(RTE_MEM_EVENT_ALLOC,
 			msl->base_va, msl->len);
 
+	/* mark it as heap segment */
+	msl->heap = 1;
+
+	rte_spinlock_unlock(&heap->lock);
+
 	return 0;
 }
 
@@ -1315,7 +1322,12 @@ int
 malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,
 		size_t len)
 {
-	struct malloc_elem *elem = heap->first;
+	struct malloc_elem *elem;
+	int ret = -1;
+
+	rte_spinlock_lock(&heap->lock);
+
+	elem = heap->first;
 
 	/* find element with specified va address */
 	while (elem != NULL && elem != va_addr) {
@@ -1323,20 +1335,24 @@ malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,
 		/* stop if we've blown past our VA */
 		if (elem > (struct malloc_elem *)va_addr) {
 			rte_errno = ENOENT;
-			return -1;
+			goto out;
 		}
 	}
 	/* check if element was found */
 	if (elem == NULL || elem->msl->len != len) {
 		rte_errno = ENOENT;
-		return -1;
+		goto out;
 	}
 	/* if element's size is not equal to segment len, segment is busy */
 	if (elem->state == ELEM_BUSY || elem->size != len) {
 		rte_errno = EBUSY;
-		return -1;
+		goto out;
 	}
-	return destroy_elem(elem, len);
+	ret = destroy_elem(elem, len);
+
+out:
+	rte_spinlock_unlock(&heap->lock);
+	return ret;
 }
 
 int
@@ -1372,23 +1388,30 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name)
 int
 malloc_heap_destroy(struct malloc_heap *heap)
 {
+	int ret = -1;
+
+	rte_spinlock_lock(&heap->lock);
+
 	if (heap->alloc_count != 0) {
 		RTE_LOG(ERR, EAL, "Heap is still in use\n");
 		rte_errno = EBUSY;
-		return -1;
+		goto fail;
 	}
 	if (heap->first != NULL || heap->last != NULL) {
 		RTE_LOG(ERR, EAL, "Heap still contains memory segments\n");
 		rte_errno = EBUSY;
-		return -1;
+		goto fail;
 	}
 	if (heap->total_size != 0)
 		RTE_LOG(ERR, EAL, "Total size not zero, heap is likely corrupt\n");
 
-	/* after this, the lock will be dropped */
-	memset(heap, 0, sizeof(*heap));
-
-	return 0;
+	RTE_BUILD_BUG_ON(offsetof(struct malloc_heap, lock) != 0);
+	memset(RTE_PTR_ADD(heap, sizeof(heap->lock)), 0,
+		sizeof(*heap) - sizeof(heap->lock));
+	ret = 0;
+fail:
+	rte_spinlock_unlock(&heap->lock);
+	return ret;
 }
 
 int
diff --git a/lib/eal/common/rte_malloc.c b/lib/eal/common/rte_malloc.c
index d39870bf3c..4f500892f2 100644
--- a/lib/eal/common/rte_malloc.c
+++ b/lib/eal/common/rte_malloc.c
@@ -436,10 +436,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,
 		goto unlock;
 	}
 
-	rte_spinlock_lock(&heap->lock);
 	ret = malloc_heap_add_external_memory(heap, msl);
-	msl->heap = 1; /* mark it as heap segment */
-	rte_spinlock_unlock(&heap->lock);
 
 unlock:
 	rte_mcfg_mem_write_unlock();
@@ -482,9 +479,7 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len)
 		goto unlock;
 	}
 
-	rte_spinlock_lock(&heap->lock);
 	ret = malloc_heap_remove_external_memory(heap, va_addr, len);
-	rte_spinlock_unlock(&heap->lock);
 	if (ret != 0)
 		goto unlock;
 
@@ -655,12 +650,7 @@ rte_malloc_heap_destroy(const char *heap_name)
 		goto unlock;
 	}
 	/* sanity checks done, now we can destroy the heap */
-	rte_spinlock_lock(&heap->lock);
 	ret = malloc_heap_destroy(heap);
-
-	/* if we failed, lock is still active */
-	if (ret < 0)
-		rte_spinlock_unlock(&heap->lock);
 unlock:
 	rte_mcfg_mem_write_unlock();
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 02/20] mem: rework malloc heap init
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
  2023-02-24 15:11   ` [PATCH v2 01/20] malloc: rework heap lock handling David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 03/20] mem: annotate shared memory config locks David Marchand
                     ` (18 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

rte_eal_memory_init() and rte_eal_malloc_heap_init() must be called in
a common section taking rte_mcfg_mem_read_lock().
Split rte_eal_malloc_heap_init() in two so that the mem lock is taken
in rte_eal_init() making lock checks trivial (once annotated in the next
patch).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_memory.c | 10 +---------
 lib/eal/common/malloc_heap.c       | 10 ++++++----
 lib/eal/common/malloc_heap.h       |  3 +++
 lib/eal/freebsd/eal.c              | 13 +++++++++++++
 lib/eal/linux/eal.c                | 13 +++++++++++++
 lib/eal/windows/eal.c              | 13 +++++++++++++
 6 files changed, 49 insertions(+), 13 deletions(-)

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index c917b981bc..5e162a1092 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1078,18 +1078,11 @@ rte_eal_memory_detach(void)
 int
 rte_eal_memory_init(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
-
 	int retval;
-	RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
-
-	if (!mcfg)
-		return -1;
 
-	/* lock mem hotplug here, to prevent races while we init */
-	rte_mcfg_mem_read_lock();
+	RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
 
 	if (rte_eal_memseg_init() < 0)
 		goto fail;
@@ -1108,7 +1101,6 @@ rte_eal_memory_init(void)
 
 	return 0;
 fail:
-	rte_mcfg_mem_read_unlock();
 	return -1;
 }
 
diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index cc84dce672..7498a05ed3 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -1442,18 +1442,20 @@ rte_eal_malloc_heap_init(void)
 		}
 	}
 
-
 	if (register_mp_requests()) {
 		RTE_LOG(ERR, EAL, "Couldn't register malloc multiprocess actions\n");
-		rte_mcfg_mem_read_unlock();
 		return -1;
 	}
 
-	/* unlock mem hotplug here. it's safe for primary as no requests can
+	return 0;
+}
+
+int rte_eal_malloc_heap_populate(void)
+{
+	/* mem hotplug is unlocked here. it's safe for primary as no requests can
 	 * even come before primary itself is fully initialized, and secondaries
 	 * do not need to initialize the heap.
 	 */
-	rte_mcfg_mem_read_unlock();
 
 	/* secondary process does not need to initialize anything */
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
diff --git a/lib/eal/common/malloc_heap.h b/lib/eal/common/malloc_heap.h
index 3b2fbc0aa0..8f3ab57154 100644
--- a/lib/eal/common/malloc_heap.h
+++ b/lib/eal/common/malloc_heap.h
@@ -85,6 +85,9 @@ malloc_socket_to_heap_id(unsigned int socket_id);
 int
 rte_eal_malloc_heap_init(void);
 
+int
+rte_eal_malloc_heap_populate(void);
+
 void
 rte_eal_malloc_heap_cleanup(void);
 
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 7db4239c51..7daf22e314 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -26,6 +26,7 @@
 #include <rte_memory.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <rte_errno.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
@@ -754,13 +755,25 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
 	}
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index fabafbc39b..7242ee2c9a 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -30,6 +30,7 @@
 #include <rte_memory.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <rte_service_component.h>
@@ -1197,7 +1198,10 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
@@ -1207,6 +1211,15 @@ rte_eal_init(int argc, char **argv)
 	eal_hugedirs_unlock();
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index e7d405b91c..033825c14c 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -12,6 +12,7 @@
 #include <rte_debug.h>
 #include <rte_bus.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
@@ -387,13 +388,25 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
 	}
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 03/20] mem: annotate shared memory config locks
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
  2023-02-24 15:11   ` [PATCH v2 01/20] malloc: rework heap lock handling David Marchand
  2023-02-24 15:11   ` [PATCH v2 02/20] mem: rework malloc heap init David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 04/20] hash: annotate cuckoo hash lock David Marchand
                     ` (17 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas

Expose internal locks via some internal accessors.
Then annotate rte_mcfg_xxx_(read|write)_(|un)lock.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_mcfg.c    | 66 +++++++++++++++++------------
 lib/eal/include/rte_eal_memconfig.h | 63 +++++++++++++++++++++------
 lib/eal/version.map                 |  4 ++
 3 files changed, 91 insertions(+), 42 deletions(-)

diff --git a/lib/eal/common/eal_common_mcfg.c b/lib/eal/common/eal_common_mcfg.c
index cf4a279905..b60d41f7b6 100644
--- a/lib/eal/common/eal_common_mcfg.c
+++ b/lib/eal/common/eal_common_mcfg.c
@@ -69,102 +69,112 @@ eal_mcfg_update_from_internal(void)
 	mcfg->version = RTE_VERSION;
 }
 
+rte_rwlock_t *
+rte_mcfg_mem_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->memory_hotplug_lock;
+}
+
 void
 rte_mcfg_mem_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_read_lock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_read_unlock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_write_lock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_write_unlock(rte_mcfg_mem_get_lock());
+}
+
+rte_rwlock_t *
+rte_mcfg_tailq_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->qlock;
 }
 
 void
 rte_mcfg_tailq_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->qlock);
+	rte_rwlock_read_lock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->qlock);
+	rte_rwlock_read_unlock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->qlock);
+	rte_rwlock_write_lock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->qlock);
+	rte_rwlock_write_unlock(rte_mcfg_tailq_get_lock());
+}
+
+rte_rwlock_t *
+rte_mcfg_mempool_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->mplock;
 }
 
 void
 rte_mcfg_mempool_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->mplock);
+	rte_rwlock_read_lock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->mplock);
+	rte_rwlock_read_unlock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->mplock);
+	rte_rwlock_write_lock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->mplock);
+	rte_rwlock_write_unlock(rte_mcfg_mempool_get_lock());
+}
+
+rte_spinlock_t *
+rte_mcfg_timer_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->tlock;
 }
 
 void
 rte_mcfg_timer_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_spinlock_lock(&mcfg->tlock);
+	rte_spinlock_lock(rte_mcfg_timer_get_lock());
 }
 
 void
 rte_mcfg_timer_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_spinlock_unlock(&mcfg->tlock);
+	rte_spinlock_unlock(rte_mcfg_timer_get_lock());
 }
 
 bool
diff --git a/lib/eal/include/rte_eal_memconfig.h b/lib/eal/include/rte_eal_memconfig.h
index e175564647..c527f9aa29 100644
--- a/lib/eal/include/rte_eal_memconfig.h
+++ b/lib/eal/include/rte_eal_memconfig.h
@@ -7,6 +7,8 @@
 
 #include <stdbool.h>
 
+#include <rte_rwlock.h>
+#include <rte_spinlock.h>
 
 /**
  * @file
@@ -18,89 +20,122 @@
 extern "C" {
 #endif
 
+/**
+ * Internal helpers used for lock annotations.
+ */
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_mem_get_lock(void);
+
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_tailq_get_lock(void);
+
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_mempool_get_lock(void);
+
+__rte_internal
+rte_spinlock_t *
+rte_mcfg_timer_get_lock(void);
+
 /**
  * Lock the internal EAL shared memory configuration for shared access.
  */
 void
-rte_mcfg_mem_read_lock(void);
+rte_mcfg_mem_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Unlock the internal EAL shared memory configuration for shared access.
  */
 void
-rte_mcfg_mem_read_unlock(void);
+rte_mcfg_mem_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Lock the internal EAL shared memory configuration for exclusive access.
  */
 void
-rte_mcfg_mem_write_lock(void);
+rte_mcfg_mem_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Unlock the internal EAL shared memory configuration for exclusive access.
  */
 void
-rte_mcfg_mem_write_unlock(void);
+rte_mcfg_mem_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Lock the internal EAL TAILQ list for shared access.
  */
 void
-rte_mcfg_tailq_read_lock(void);
+rte_mcfg_tailq_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Unlock the internal EAL TAILQ list for shared access.
  */
 void
-rte_mcfg_tailq_read_unlock(void);
+rte_mcfg_tailq_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Lock the internal EAL TAILQ list for exclusive access.
  */
 void
-rte_mcfg_tailq_write_lock(void);
+rte_mcfg_tailq_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Unlock the internal EAL TAILQ list for exclusive access.
  */
 void
-rte_mcfg_tailq_write_unlock(void);
+rte_mcfg_tailq_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Lock the internal EAL Mempool list for shared access.
  */
 void
-rte_mcfg_mempool_read_lock(void);
+rte_mcfg_mempool_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Unlock the internal EAL Mempool list for shared access.
  */
 void
-rte_mcfg_mempool_read_unlock(void);
+rte_mcfg_mempool_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Lock the internal EAL Mempool list for exclusive access.
  */
 void
-rte_mcfg_mempool_write_lock(void);
+rte_mcfg_mempool_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Unlock the internal EAL Mempool list for exclusive access.
  */
 void
-rte_mcfg_mempool_write_unlock(void);
+rte_mcfg_mempool_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Lock the internal EAL Timer Library lock for exclusive access.
  */
 void
-rte_mcfg_timer_lock(void);
+rte_mcfg_timer_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_timer_get_lock());
 
 /**
  * Unlock the internal EAL Timer Library lock for exclusive access.
  */
 void
-rte_mcfg_timer_unlock(void);
+rte_mcfg_timer_unlock(void)
+	__rte_unlock_function(rte_mcfg_timer_get_lock());
 
 /**
  * If true, pages are put in single files (per memseg list),
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 6d6978f108..51a820d829 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -469,6 +469,10 @@ INTERNAL {
 	rte_intr_vec_list_free;
 	rte_intr_vec_list_index_get;
 	rte_intr_vec_list_index_set;
+	rte_mcfg_mem_get_lock;
+	rte_mcfg_mempool_get_lock;
+	rte_mcfg_tailq_get_lock;
+	rte_mcfg_timer_get_lock;
 	rte_mem_lock;
 	rte_mem_map;
 	rte_mem_page_size;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 04/20] hash: annotate cuckoo hash lock
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (2 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 03/20] mem: annotate shared memory config locks David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 05/20] graph: annotate graph lock David Marchand
                     ` (16 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin

__hash_rw_(reader|writer)_(|un)lock helpers take locks depending on
conditions that are fixed at the rte_hash object initialisation.
So we can tell clang that those helpers unconditionally take/release
those locks (and waive the lock check on their implementation).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/hash/rte_cuckoo_hash.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
index 829b79c89a..d92a903bb3 100644
--- a/lib/hash/rte_cuckoo_hash.c
+++ b/lib/hash/rte_cuckoo_hash.c
@@ -575,6 +575,8 @@ rte_hash_count(const struct rte_hash *h)
 /* Read write locks implemented using rte_rwlock */
 static inline void
 __hash_rw_writer_lock(const struct rte_hash *h)
+	__rte_exclusive_lock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->writer_takes_lock && h->hw_trans_mem_support)
 		rte_rwlock_write_lock_tm(h->readwrite_lock);
@@ -584,6 +586,8 @@ __hash_rw_writer_lock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_reader_lock(const struct rte_hash *h)
+	__rte_shared_lock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->readwrite_concur_support && h->hw_trans_mem_support)
 		rte_rwlock_read_lock_tm(h->readwrite_lock);
@@ -593,6 +597,8 @@ __hash_rw_reader_lock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_writer_unlock(const struct rte_hash *h)
+	__rte_unlock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->writer_takes_lock && h->hw_trans_mem_support)
 		rte_rwlock_write_unlock_tm(h->readwrite_lock);
@@ -602,6 +608,8 @@ __hash_rw_writer_unlock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_reader_unlock(const struct rte_hash *h)
+	__rte_unlock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->readwrite_concur_support && h->hw_trans_mem_support)
 		rte_rwlock_read_unlock_tm(h->readwrite_lock);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 05/20] graph: annotate graph lock
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (3 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 04/20] hash: annotate cuckoo hash lock David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 06/20] drivers: inherit lock annotations for Intel drivers David Marchand
                     ` (15 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Jerin Jacob, Kiran Kumar K, Nithin Dabilpuram

Export internal lock and annotate associated helper.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/graph/graph.c         | 10 ++++++++--
 lib/graph/graph_private.h | 10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/graph/graph.c b/lib/graph/graph.c
index a839a2803b..5582631b53 100644
--- a/lib/graph/graph.c
+++ b/lib/graph/graph.c
@@ -30,16 +30,22 @@ graph_list_head_get(void)
 	return &graph_list;
 }
 
+rte_spinlock_t *
+graph_spinlock_get(void)
+{
+	return &graph_lock;
+}
+
 void
 graph_spinlock_lock(void)
 {
-	rte_spinlock_lock(&graph_lock);
+	rte_spinlock_lock(graph_spinlock_get());
 }
 
 void
 graph_spinlock_unlock(void)
 {
-	rte_spinlock_unlock(&graph_lock);
+	rte_spinlock_unlock(graph_spinlock_get());
 }
 
 static int
diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h
index 7d1b30b8ac..eacdef45f0 100644
--- a/lib/graph/graph_private.h
+++ b/lib/graph/graph_private.h
@@ -10,6 +10,7 @@
 
 #include <rte_common.h>
 #include <rte_eal.h>
+#include <rte_spinlock.h>
 
 #include "rte_graph.h"
 #include "rte_graph_worker.h"
@@ -148,20 +149,25 @@ STAILQ_HEAD(graph_head, graph);
  */
 struct graph_head *graph_list_head_get(void);
 
+rte_spinlock_t *
+graph_spinlock_get(void);
+
 /* Lock functions */
 /**
  * @internal
  *
  * Take a lock on the graph internal spin lock.
  */
-void graph_spinlock_lock(void);
+void graph_spinlock_lock(void)
+	__rte_exclusive_lock_function(graph_spinlock_get());
 
 /**
  * @internal
  *
  * Release a lock on the graph internal spin lock.
  */
-void graph_spinlock_unlock(void);
+void graph_spinlock_unlock(void)
+	__rte_unlock_function(graph_spinlock_get());
 
 /* Graph operations */
 /**
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 06/20] drivers: inherit lock annotations for Intel drivers
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (4 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 05/20] graph: annotate graph lock David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 07/20] net/cxgbe: inherit lock annotations David Marchand
                     ` (14 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Jingjing Wu, Beilei Xing, Yuying Zhang, Qiming Yang, Qi Zhang

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/common/iavf/iavf_osdep.h       | 39 ++++++--------------------
 drivers/common/iavf/iavf_prototype.h   |  6 ----
 drivers/common/idpf/base/idpf_osdep.h  | 26 +++--------------
 drivers/net/i40e/base/i40e_osdep.h     |  8 +++---
 drivers/net/i40e/base/i40e_prototype.h |  5 ----
 drivers/net/i40e/i40e_ethdev.c         | 24 ----------------
 drivers/net/ice/base/ice_osdep.h       | 26 +++--------------
 7 files changed, 20 insertions(+), 114 deletions(-)

diff --git a/drivers/common/iavf/iavf_osdep.h b/drivers/common/iavf/iavf_osdep.h
index 31d3d809f9..263d92400c 100644
--- a/drivers/common/iavf/iavf_osdep.h
+++ b/drivers/common/iavf/iavf_osdep.h
@@ -170,11 +170,6 @@ struct iavf_virt_mem {
 	u32 size;
 } __rte_packed;
 
-/* SW spinlock */
-struct iavf_spinlock {
-	rte_spinlock_t spinlock;
-};
-
 #define iavf_allocate_dma_mem(h, m, unused, s, a) \
 			iavf_allocate_dma_mem_d(h, m, s, a)
 #define iavf_free_dma_mem(h, m) iavf_free_dma_mem_d(h, m)
@@ -182,32 +177,14 @@ struct iavf_spinlock {
 #define iavf_allocate_virt_mem(h, m, s) iavf_allocate_virt_mem_d(h, m, s)
 #define iavf_free_virt_mem(h, m) iavf_free_virt_mem_d(h, m)
 
-static inline void
-iavf_init_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-iavf_acquire_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-iavf_release_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-iavf_destroy_spinlock_d(__rte_unused struct iavf_spinlock *sp)
-{
-}
+/* SW spinlock */
+struct iavf_spinlock {
+	rte_spinlock_t spinlock;
+};
 
-#define iavf_init_spinlock(_sp) iavf_init_spinlock_d(_sp)
-#define iavf_acquire_spinlock(_sp) iavf_acquire_spinlock_d(_sp)
-#define iavf_release_spinlock(_sp) iavf_release_spinlock_d(_sp)
-#define iavf_destroy_spinlock(_sp) iavf_destroy_spinlock_d(_sp)
+#define iavf_init_spinlock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define iavf_acquire_spinlock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define iavf_release_spinlock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define iavf_destroy_spinlock(sp) RTE_SET_USED(sp)
 
 #endif /* _IAVF_OSDEP_H_ */
diff --git a/drivers/common/iavf/iavf_prototype.h b/drivers/common/iavf/iavf_prototype.h
index b5124de5bf..ba78ec5169 100644
--- a/drivers/common/iavf/iavf_prototype.h
+++ b/drivers/common/iavf/iavf_prototype.h
@@ -76,12 +76,6 @@ STATIC INLINE struct iavf_rx_ptype_decoded decode_rx_desc_ptype(u8 ptype)
 	return iavf_ptype_lookup[ptype];
 }
 
-/* prototype for functions used for SW spinlocks */
-void iavf_init_spinlock(struct iavf_spinlock *sp);
-void iavf_acquire_spinlock(struct iavf_spinlock *sp);
-void iavf_release_spinlock(struct iavf_spinlock *sp);
-void iavf_destroy_spinlock(struct iavf_spinlock *sp);
-
 __rte_internal
 void iavf_vf_parse_hw_config(struct iavf_hw *hw,
 			     struct virtchnl_vf_resource *msg);
diff --git a/drivers/common/idpf/base/idpf_osdep.h b/drivers/common/idpf/base/idpf_osdep.h
index 99ae9cf60a..49bd7c4b21 100644
--- a/drivers/common/idpf/base/idpf_osdep.h
+++ b/drivers/common/idpf/base/idpf_osdep.h
@@ -210,28 +210,10 @@ struct idpf_lock {
 	rte_spinlock_t spinlock;
 };
 
-static inline void
-idpf_init_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-idpf_acquire_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-idpf_release_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-idpf_destroy_lock(__rte_unused struct idpf_lock *sp)
-{
-}
+#define idpf_init_lock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define idpf_acquire_lock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define idpf_release_lock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define idpf_destroy_lock(sp) RTE_SET_USED(sp)
 
 struct idpf_hw;
 
diff --git a/drivers/net/i40e/base/i40e_osdep.h b/drivers/net/i40e/base/i40e_osdep.h
index 51537c5cf3..aa5dc61841 100644
--- a/drivers/net/i40e/base/i40e_osdep.h
+++ b/drivers/net/i40e/base/i40e_osdep.h
@@ -215,10 +215,10 @@ struct i40e_spinlock {
 	rte_spinlock_t spinlock;
 };
 
-#define i40e_init_spinlock(_sp) i40e_init_spinlock_d(_sp)
-#define i40e_acquire_spinlock(_sp) i40e_acquire_spinlock_d(_sp)
-#define i40e_release_spinlock(_sp) i40e_release_spinlock_d(_sp)
-#define i40e_destroy_spinlock(_sp) i40e_destroy_spinlock_d(_sp)
+#define i40e_init_spinlock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define i40e_acquire_spinlock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define i40e_release_spinlock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define i40e_destroy_spinlock(sp) RTE_SET_USED(sp)
 
 #define I40E_NTOHS(a) rte_be_to_cpu_16(a)
 #define I40E_NTOHL(a) rte_be_to_cpu_32(a)
diff --git a/drivers/net/i40e/base/i40e_prototype.h b/drivers/net/i40e/base/i40e_prototype.h
index 29c86c7fe8..691c977172 100644
--- a/drivers/net/i40e/base/i40e_prototype.h
+++ b/drivers/net/i40e/base/i40e_prototype.h
@@ -546,11 +546,6 @@ i40e_virtchnl_link_speed(enum i40e_aq_link_speed link_speed)
 	}
 }
 #endif /* PF_DRIVER */
-/* prototype for functions used for SW spinlocks */
-void i40e_init_spinlock(struct i40e_spinlock *sp);
-void i40e_acquire_spinlock(struct i40e_spinlock *sp);
-void i40e_release_spinlock(struct i40e_spinlock *sp);
-void i40e_destroy_spinlock(struct i40e_spinlock *sp);
 
 /* i40e_common for VF drivers*/
 void i40e_vf_parse_hw_config(struct i40e_hw *hw,
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 7726a89d99..cf2969f6ce 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -4622,30 +4622,6 @@ i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
 	return I40E_SUCCESS;
 }
 
-void
-i40e_init_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-void
-i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-void
-i40e_release_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-void
-i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp)
-{
-	return;
-}
-
 /**
  * Get the hardware capabilities, which will be parsed
  * and saved into struct i40e_hw.
diff --git a/drivers/net/ice/base/ice_osdep.h b/drivers/net/ice/base/ice_osdep.h
index 4b92057521..0e14b934c8 100644
--- a/drivers/net/ice/base/ice_osdep.h
+++ b/drivers/net/ice/base/ice_osdep.h
@@ -211,28 +211,10 @@ struct ice_lock {
 	rte_spinlock_t spinlock;
 };
 
-static inline void
-ice_init_lock(struct ice_lock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-ice_acquire_lock(struct ice_lock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-ice_release_lock(struct ice_lock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-ice_destroy_lock(__rte_unused struct ice_lock *sp)
-{
-}
+#define ice_init_lock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define ice_acquire_lock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define ice_release_lock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define ice_destroy_lock(sp) RTE_SET_USED(sp)
 
 struct ice_hw;
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 07/20] net/cxgbe: inherit lock annotations
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (5 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 06/20] drivers: inherit lock annotations for Intel drivers David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 08/20] net/fm10k: annotate mailbox lock David Marchand
                     ` (13 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Rahul Lakkireddy

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/cxgbe/base/adapter.h | 35 +++++++-------------------------
 1 file changed, 7 insertions(+), 28 deletions(-)

diff --git a/drivers/net/cxgbe/base/adapter.h b/drivers/net/cxgbe/base/adapter.h
index 16cbc1a345..8f2ffa0eeb 100644
--- a/drivers/net/cxgbe/base/adapter.h
+++ b/drivers/net/cxgbe/base/adapter.h
@@ -351,28 +351,19 @@ struct adapter {
  * t4_os_rwlock_init - initialize rwlock
  * @lock: the rwlock
  */
-static inline void t4_os_rwlock_init(rte_rwlock_t *lock)
-{
-	rte_rwlock_init(lock);
-}
+#define t4_os_rwlock_init(lock) rte_rwlock_init(lock)
 
 /**
  * t4_os_write_lock - get a write lock
  * @lock: the rwlock
  */
-static inline void t4_os_write_lock(rte_rwlock_t *lock)
-{
-	rte_rwlock_write_lock(lock);
-}
+#define t4_os_write_lock(lock) rte_rwlock_write_lock(lock)
 
 /**
  * t4_os_write_unlock - unlock a write lock
  * @lock: the rwlock
  */
-static inline void t4_os_write_unlock(rte_rwlock_t *lock)
-{
-	rte_rwlock_write_unlock(lock);
-}
+#define t4_os_write_unlock(lock) rte_rwlock_write_unlock(lock)
 
 /**
  * ethdev2pinfo - return the port_info structure associated with a rte_eth_dev
@@ -678,37 +669,25 @@ static inline void t4_os_set_hw_addr(struct adapter *adapter, int port_idx,
  * t4_os_lock_init - initialize spinlock
  * @lock: the spinlock
  */
-static inline void t4_os_lock_init(rte_spinlock_t *lock)
-{
-	rte_spinlock_init(lock);
-}
+#define t4_os_lock_init(lock) rte_spinlock_init(lock)
 
 /**
  * t4_os_lock - spin until lock is acquired
  * @lock: the spinlock
  */
-static inline void t4_os_lock(rte_spinlock_t *lock)
-{
-	rte_spinlock_lock(lock);
-}
+#define t4_os_lock(lock) rte_spinlock_lock(lock)
 
 /**
  * t4_os_unlock - unlock a spinlock
  * @lock: the spinlock
  */
-static inline void t4_os_unlock(rte_spinlock_t *lock)
-{
-	rte_spinlock_unlock(lock);
-}
+#define t4_os_unlock(lock) rte_spinlock_unlock(lock)
 
 /**
  * t4_os_trylock - try to get a lock
  * @lock: the spinlock
  */
-static inline int t4_os_trylock(rte_spinlock_t *lock)
-{
-	return rte_spinlock_trylock(lock);
-}
+#define t4_os_trylock(lock) rte_spinlock_trylock(lock)
 
 /**
  * t4_os_init_list_head - initialize
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 08/20] net/fm10k: annotate mailbox lock
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (6 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 07/20] net/cxgbe: inherit lock annotations David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 09/20] net/sfc: rework locking in proxy code David Marchand
                     ` (12 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Qi Zhang, Xiao Wang

Expose requirements for helpers dealing with the
FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back) lock.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/fm10k/fm10k_ethdev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 8b83063f0a..4d3c4c10cf 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -116,6 +116,7 @@ fm10k_mbx_initlock(struct fm10k_hw *hw)
 
 static void
 fm10k_mbx_lock(struct fm10k_hw *hw)
+	__rte_exclusive_lock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
 {
 	while (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)))
 		rte_delay_us(FM10K_MBXLOCK_DELAY_US);
@@ -123,6 +124,7 @@ fm10k_mbx_lock(struct fm10k_hw *hw)
 
 static void
 fm10k_mbx_unlock(struct fm10k_hw *hw)
+	__rte_unlock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
 {
 	rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 09/20] net/sfc: rework locking in proxy code
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (7 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 08/20] net/fm10k: annotate mailbox lock David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 10/20] net/sfc: inherit lock annotations David Marchand
                     ` (11 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Andrew Rybchenko

Remove one extra layer for proxy code: sfc_get_adapter_by_pf_port_id()
now only resolves the sa object and sfc_adapter_(|un)lock() are added
were necessary.

This will simplify lock checks later.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/sfc/sfc_repr_proxy.c | 59 ++++++++++++++++----------------
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/drivers/net/sfc/sfc_repr_proxy.c b/drivers/net/sfc/sfc_repr_proxy.c
index 4b958ced61..4ba7683370 100644
--- a/drivers/net/sfc/sfc_repr_proxy.c
+++ b/drivers/net/sfc/sfc_repr_proxy.c
@@ -51,17 +51,9 @@ sfc_get_adapter_by_pf_port_id(uint16_t pf_port_id)
 	dev = &rte_eth_devices[pf_port_id];
 	sa = sfc_adapter_by_eth_dev(dev);
 
-	sfc_adapter_lock(sa);
-
 	return sa;
 }
 
-static void
-sfc_put_adapter(struct sfc_adapter *sa)
-{
-	sfc_adapter_unlock(sa);
-}
-
 static struct sfc_repr_proxy_port *
 sfc_repr_proxy_find_port(struct sfc_repr_proxy *rp, uint16_t repr_id)
 {
@@ -1289,6 +1281,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1341,7 +1334,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 	}
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
@@ -1352,7 +1345,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 fail_alloc_port:
 fail_port_exists:
 	sfc_log_init(sa, "failed: %s", rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1366,6 +1359,7 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1393,14 +1387,14 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)
 
 	sfc_log_init(sa, "done");
 
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
 fail_port_remove:
 fail_no_port:
 	sfc_log_init(sa, "failed: %s", rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1416,6 +1410,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1423,14 +1418,14 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
 	rxq = &port->rxq[queue_id];
 	if (rp->dp_rxq[queue_id].mp != NULL && rp->dp_rxq[queue_id].mp != mp) {
 		sfc_err(sa, "multiple mempools per queue are not supported");
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOTSUP;
 	}
 
@@ -1440,7 +1435,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	rp->dp_rxq[queue_id].ref_count++;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1455,6 +1450,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1462,7 +1458,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return;
 	}
 
@@ -1475,7 +1471,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 		rp->dp_rxq[queue_id].mp = NULL;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 }
 
 int
@@ -1489,6 +1485,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1496,7 +1493,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
@@ -1507,7 +1504,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	*egress_mport = port->egress_mport;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1522,6 +1519,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1529,7 +1527,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return;
 	}
 
@@ -1538,7 +1536,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	txq->ring = NULL;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 }
 
 int
@@ -1551,6 +1549,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1594,7 +1593,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 	}
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
@@ -1606,7 +1605,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 fail_not_found:
 	sfc_err(sa, "failed to start repr %u proxy port: %s", repr_id,
 		rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1621,6 +1620,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1628,14 +1628,14 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
 	if (!port->enabled) {
 		sfc_log_init(sa, "repr %u proxy port is not started - skip",
 			     repr_id);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return 0;
 	}
 
@@ -1662,7 +1662,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 			sfc_err(sa,
 				"failed to stop representor proxy TxQ %u: %s",
 				repr_id, rte_strerror(rc));
-			sfc_put_adapter(sa);
+			sfc_adapter_unlock(sa);
 			return rc;
 		}
 	}
@@ -1670,7 +1670,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	port->enabled = false;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1685,13 +1685,14 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port (repr_id=%u)",
 			__func__, repr_id);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
@@ -1703,7 +1704,7 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,
 			__func__, repr_id, rte_strerror(rc));
 	}
 
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 10/20] net/sfc: inherit lock annotations
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (8 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 09/20] net/sfc: rework locking in proxy code David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 11/20] net/virtio: annotate lock for guest announce David Marchand
                     ` (10 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Andrew Rybchenko

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

One additional change is required in sfc_ev_qpoll() so that clang does
see the same lock is being manipulated.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/sfc/sfc.h      | 41 ++++++--------------------------------
 drivers/net/sfc/sfc_ev.c   |  6 ++++--
 drivers/net/sfc/sfc_repr.c | 38 +++++------------------------------
 3 files changed, 15 insertions(+), 70 deletions(-)

diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index 0a1e224fa2..730d054aea 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -333,41 +333,12 @@ sfc_sa2shared(struct sfc_adapter *sa)
  * change the lock in one place.
  */
 
-static inline void
-sfc_adapter_lock_init(struct sfc_adapter *sa)
-{
-	rte_spinlock_init(&sa->lock);
-}
-
-static inline int
-sfc_adapter_is_locked(struct sfc_adapter *sa)
-{
-	return rte_spinlock_is_locked(&sa->lock);
-}
-
-static inline void
-sfc_adapter_lock(struct sfc_adapter *sa)
-{
-	rte_spinlock_lock(&sa->lock);
-}
-
-static inline int
-sfc_adapter_trylock(struct sfc_adapter *sa)
-{
-	return rte_spinlock_trylock(&sa->lock);
-}
-
-static inline void
-sfc_adapter_unlock(struct sfc_adapter *sa)
-{
-	rte_spinlock_unlock(&sa->lock);
-}
-
-static inline void
-sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_adapter_lock_init(sa) rte_spinlock_init(&(sa)->lock)
+#define sfc_adapter_is_locked(sa) rte_spinlock_is_locked(&(sa)->lock)
+#define sfc_adapter_lock(sa) rte_spinlock_lock(&(sa)->lock)
+#define sfc_adapter_trylock(sa) rte_spinlock_trylock(&(sa)->lock)
+#define sfc_adapter_unlock(sa) rte_spinlock_unlock(&(sa)->lock)
+#define sfc_adapter_lock_fini(sa) RTE_SET_USED(sa)
 
 static inline unsigned int
 sfc_nb_counter_rxq(const struct sfc_adapter_shared *sas)
diff --git a/drivers/net/sfc/sfc_ev.c b/drivers/net/sfc/sfc_ev.c
index f949abbfc3..c0d58c9554 100644
--- a/drivers/net/sfc/sfc_ev.c
+++ b/drivers/net/sfc/sfc_ev.c
@@ -570,6 +570,8 @@ static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {
 void
 sfc_ev_qpoll(struct sfc_evq *evq)
 {
+	struct sfc_adapter *sa;
+
 	SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED ||
 		   evq->init_state == SFC_EVQ_STARTING);
 
@@ -577,8 +579,8 @@ sfc_ev_qpoll(struct sfc_evq *evq)
 
 	efx_ev_qpoll(evq->common, &evq->read_ptr, evq->callbacks, evq);
 
-	if (unlikely(evq->exception) && sfc_adapter_trylock(evq->sa)) {
-		struct sfc_adapter *sa = evq->sa;
+	sa = evq->sa;
+	if (unlikely(evq->exception) && sfc_adapter_trylock(sa)) {
 		int rc;
 
 		if (evq->dp_rxq != NULL) {
diff --git a/drivers/net/sfc/sfc_repr.c b/drivers/net/sfc/sfc_repr.c
index 4b03b101d8..017c3fb247 100644
--- a/drivers/net/sfc/sfc_repr.c
+++ b/drivers/net/sfc/sfc_repr.c
@@ -112,39 +112,11 @@ sfc_repr_by_eth_dev(struct rte_eth_dev *eth_dev)
  * change the lock in one place.
  */
 
-static inline void
-sfc_repr_lock_init(struct sfc_repr *sr)
-{
-	rte_spinlock_init(&sr->lock);
-}
-
-#if defined(RTE_LIBRTE_SFC_EFX_DEBUG) || defined(RTE_ENABLE_ASSERT)
-
-static inline int
-sfc_repr_lock_is_locked(struct sfc_repr *sr)
-{
-	return rte_spinlock_is_locked(&sr->lock);
-}
-
-#endif
-
-static inline void
-sfc_repr_lock(struct sfc_repr *sr)
-{
-	rte_spinlock_lock(&sr->lock);
-}
-
-static inline void
-sfc_repr_unlock(struct sfc_repr *sr)
-{
-	rte_spinlock_unlock(&sr->lock);
-}
-
-static inline void
-sfc_repr_lock_fini(__rte_unused struct sfc_repr *sr)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_repr_lock_init(sr) rte_spinlock_init(&(sr)->lock)
+#define sfc_repr_lock_is_locked(sr) rte_spinlock_is_locked(&(sr)->lock)
+#define sfc_repr_lock(sr) rte_spinlock_lock(&(sr)->lock)
+#define sfc_repr_unlock(sr) rte_spinlock_unlock(&(sr)->lock)
+#define sfc_repr_lock_fini(sr) RTE_SET_USED(sr)
 
 static void
 sfc_repr_rx_queue_stop(void *queue)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 11/20] net/virtio: annotate lock for guest announce
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (9 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 10/20] net/sfc: inherit lock annotations David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-27  2:05     ` Xia, Chenbo
  2023-02-24 15:11   ` [PATCH v2 12/20] raw/ifpga: inherit lock annotations David Marchand
                     ` (9 subsequent siblings)
  20 siblings, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Maxime Coquelin, Chenbo Xia

Expose requirements for helpers dealing with the
VIRTIO_DEV_TO_HW(dev)->state_lock lock.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/virtio/virtio_ethdev.c | 8 ++++----
 drivers/net/virtio/virtio_ethdev.h | 7 +++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 0103d95920..a3de44958c 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1149,11 +1149,11 @@ virtio_dev_pause(struct rte_eth_dev *dev)
 {
 	struct virtio_hw *hw = dev->data->dev_private;
 
-	rte_spinlock_lock(&hw->state_lock);
+	rte_spinlock_lock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
 
 	if (hw->started == 0) {
 		/* Device is just stopped. */
-		rte_spinlock_unlock(&hw->state_lock);
+		rte_spinlock_unlock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
 		return -1;
 	}
 	hw->started = 0;
@@ -1174,7 +1174,7 @@ virtio_dev_resume(struct rte_eth_dev *dev)
 	struct virtio_hw *hw = dev->data->dev_private;
 
 	hw->started = 1;
-	rte_spinlock_unlock(&hw->state_lock);
+	rte_spinlock_unlock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
 }
 
 /*
@@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev)
 	}
 
 	/* If virtio port just stopped, no need to send RARP */
-	if (virtio_dev_pause(dev) < 0) {
+	if (virtio_dev_pause(dev) != 0) {
 		rte_pktmbuf_free(rarp_mbuf);
 		return;
 	}
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index c08f382791..ece0130603 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
 
 void virtio_interrupt_handler(void *param);
 
-int virtio_dev_pause(struct rte_eth_dev *dev);
-void virtio_dev_resume(struct rte_eth_dev *dev);
+#define VIRTIO_DEV_TO_HW(dev) ((struct virtio_hw *)(dev)->data->dev_private)
+int virtio_dev_pause(struct rte_eth_dev *dev)
+	__rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)->state_lock);
+void virtio_dev_resume(struct rte_eth_dev *dev)
+	__rte_unlock_function(&VIRTIO_DEV_TO_HW(dev)->state_lock);
 int virtio_dev_stop(struct rte_eth_dev *dev);
 int virtio_dev_close(struct rte_eth_dev *dev);
 int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 12/20] raw/ifpga: inherit lock annotations
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (10 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 11/20] net/virtio: annotate lock for guest announce David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-27  6:29     ` Xu, Rosen
  2023-02-24 15:11   ` [PATCH v2 13/20] vdpa/sfc: " David Marchand
                     ` (8 subsequent siblings)
  20 siblings, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Rosen Xu, Tianfei Zhang

The checks in those helpers are useless:
- all (start/stop/reset/test) callers ensure that dev != NULL,
- dev->sd can't be NULL either as it would mean the application is calling
  those helpers for a dev pointer that did not pass initialisation,

Once the checks are removed, the only thing that remains is calls to the
rte_spinlock API, so simply use macros and inherit annotations from the
lock API.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/raw/ifpga/afu_pmd_core.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/raw/ifpga/afu_pmd_core.c b/drivers/raw/ifpga/afu_pmd_core.c
index ddf7a34f33..3ab1f47ac1 100644
--- a/drivers/raw/ifpga/afu_pmd_core.c
+++ b/drivers/raw/ifpga/afu_pmd_core.c
@@ -23,21 +23,8 @@ static struct rte_afu_uuid afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1];
 TAILQ_HEAD(afu_drv_list, afu_rawdev_drv);
 static struct afu_drv_list afu_pmd_list = TAILQ_HEAD_INITIALIZER(afu_pmd_list);
 
-static inline int afu_rawdev_trylock(struct afu_rawdev *dev)
-{
-	if (!dev || !dev->sd)
-		return 0;
-
-	return rte_spinlock_trylock(&dev->sd->lock);
-}
-
-static inline void afu_rawdev_unlock(struct afu_rawdev *dev)
-{
-	if (!dev || !dev->sd)
-		return;
-
-	rte_spinlock_unlock(&dev->sd->lock);
-}
+#define afu_rawdev_trylock(dev) rte_spinlock_trylock(&dev->sd->lock)
+#define afu_rawdev_unlock(dev) rte_spinlock_unlock(&dev->sd->lock)
 
 static int afu_rawdev_configure(const struct rte_rawdev *rawdev,
 	rte_rawdev_obj_t config, size_t config_size)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 13/20] vdpa/sfc: inherit lock annotations
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (11 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 12/20] raw/ifpga: inherit lock annotations David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 14/20] ipc: annotate pthread mutex David Marchand
                     ` (7 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Vijay Kumar Srivastava

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

sfc_vdpa_ops.c was relying on an implicit cast of the dev_handle to a
vdpa adapter object. Add an explicit conversion.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/vdpa/sfc/sfc_vdpa.h     | 41 +++++----------------------------
 drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 +++++------
 2 files changed, 13 insertions(+), 42 deletions(-)

diff --git a/drivers/vdpa/sfc/sfc_vdpa.h b/drivers/vdpa/sfc/sfc_vdpa.h
index b25eb3a5fe..2b843e563d 100644
--- a/drivers/vdpa/sfc/sfc_vdpa.h
+++ b/drivers/vdpa/sfc/sfc_vdpa.h
@@ -122,40 +122,11 @@ sfc_vdpa_adapter_by_dev_handle(void *dev_handle)
  * Add wrapper functions to acquire/release lock to be able to remove or
  * change the lock in one place.
  */
-static inline void
-sfc_vdpa_adapter_lock_init(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_init(&sva->lock);
-}
-
-static inline int
-sfc_vdpa_adapter_is_locked(struct sfc_vdpa_adapter *sva)
-{
-	return rte_spinlock_is_locked(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_lock(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_lock(&sva->lock);
-}
-
-static inline int
-sfc_vdpa_adapter_trylock(struct sfc_vdpa_adapter *sva)
-{
-	return rte_spinlock_trylock(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_unlock(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_unlock(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_lock_fini(__rte_unused struct sfc_vdpa_adapter *sva)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_vdpa_adapter_lock_init(sva) rte_spinlock_init(&(sva)->lock)
+#define sfc_vdpa_adapter_is_locked(sva) rte_spinlock_is_locked(&(sva)->lock)
+#define sfc_vdpa_adapter_lock(sva) rte_spinlock_lock(&(sva)->lock)
+#define sfc_vdpa_adapter_trylock(sva) rte_spinlock_trylock(&(sva)->lock)
+#define sfc_vdpa_adapter_unlock(sva) rte_spinlock_unlock(&(sva)->lock)
+#define sfc_vdpa_adapter_lock_fini(sva) RTE_SET_USED(sva)
 
 #endif  /* _SFC_VDPA_H */
diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.c b/drivers/vdpa/sfc/sfc_vdpa_ops.c
index 6401d4e16f..afa6b7e8ef 100644
--- a/drivers/vdpa/sfc/sfc_vdpa_ops.c
+++ b/drivers/vdpa/sfc/sfc_vdpa_ops.c
@@ -577,7 +577,7 @@ sfc_vdpa_notify_ctrl(void *arg)
 	if (ops_data == NULL)
 		return NULL;
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	vid = ops_data->vid;
 
@@ -586,7 +586,7 @@ sfc_vdpa_notify_ctrl(void *arg)
 			      "vDPA (%s): Notifier could not get configured",
 			      ops_data->vdpa_dev->device->name);
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return NULL;
 }
@@ -637,7 +637,7 @@ sfc_vdpa_dev_config(int vid)
 
 	ops_data->vid = vid;
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	sfc_vdpa_log_init(ops_data->dev_handle, "configuring");
 	rc = sfc_vdpa_configure(ops_data);
@@ -653,7 +653,7 @@ sfc_vdpa_dev_config(int vid)
 	if (rc != 0)
 		goto fail_vdpa_notify;
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	sfc_vdpa_log_init(ops_data->dev_handle, "done");
 
@@ -666,7 +666,7 @@ sfc_vdpa_dev_config(int vid)
 	sfc_vdpa_close(ops_data);
 
 fail_vdpa_config:
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return -1;
 }
@@ -688,7 +688,7 @@ sfc_vdpa_dev_close(int vid)
 		return -1;
 	}
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 	if (ops_data->is_notify_thread_started == true) {
 		void *status;
 		ret = pthread_cancel(ops_data->notify_tid);
@@ -710,7 +710,7 @@ sfc_vdpa_dev_close(int vid)
 	sfc_vdpa_stop(ops_data);
 	sfc_vdpa_close(ops_data);
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 14/20] ipc: annotate pthread mutex
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (12 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 13/20] vdpa/sfc: " David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 15/20] ethdev: " David Marchand
                     ` (6 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Anatoly Burakov

pthread_cond_timedwait() requires pending_requests.lock being taken.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_proc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c
index 1fc1d6c53b..aa060ae4dc 100644
--- a/lib/eal/common/eal_common_proc.c
+++ b/lib/eal/common/eal_common_proc.c
@@ -908,6 +908,9 @@ mp_request_async(const char *dst, struct rte_mp_msg *req,
 static int
 mp_request_sync(const char *dst, struct rte_mp_msg *req,
 	       struct rte_mp_reply *reply, const struct timespec *ts)
+#ifdef RTE_EXEC_ENV_FREEBSD
+	__rte_exclusive_locks_required(pending_requests.lock)
+#endif
 {
 	int ret;
 	pthread_condattr_t attr;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 15/20] ethdev: annotate pthread mutex
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (13 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 14/20] ipc: annotate pthread mutex David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 16/20] net/failsafe: fix mutex locking David Marchand
                     ` (5 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Ori Kam, Ferruh Yigit, Andrew Rybchenko

fts_enter/exit take mutexes depending on device flags set at
initialisation.
Annotate those helpers and, since clang does not support conditional
locking, waive the lock check on their implementation.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/ethdev/rte_flow.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 69e6e749f7..c66625d1fe 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -297,6 +297,10 @@ rte_flow_dynf_metadata_register(void)
 
 static inline void
 fts_enter(struct rte_eth_dev *dev)
+#ifdef RTE_EXEC_ENV_FREEBSD
+	__rte_exclusive_lock_function(dev->data->flow_ops_mutex)
+	__rte_no_thread_safety_analysis
+#endif
 {
 	if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
 		pthread_mutex_lock(&dev->data->flow_ops_mutex);
@@ -304,6 +308,10 @@ fts_enter(struct rte_eth_dev *dev)
 
 static inline void
 fts_exit(struct rte_eth_dev *dev)
+#ifdef RTE_EXEC_ENV_FREEBSD
+	__rte_unlock_function(dev->data->flow_ops_mutex)
+	__rte_no_thread_safety_analysis
+#endif
 {
 	if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
 		pthread_mutex_unlock(&dev->data->flow_ops_mutex);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 16/20] net/failsafe: fix mutex locking
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (14 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 15/20] ethdev: " David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:35     ` Gaëtan Rivet
  2023-02-24 15:11   ` [PATCH v2 17/20] net/failsafe: annotate pthread mutex David Marchand
                     ` (4 subsequent siblings)
  20 siblings, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Gaetan Rivet

The pthread mutex API describes cases where locking might fail.
Check fts_enter wrapper return code.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/failsafe/failsafe_ether.c |   3 +-
 drivers/net/failsafe/failsafe_flow.c  |  23 +++--
 drivers/net/failsafe/failsafe_ops.c   | 142 +++++++++++++++++++-------
 3 files changed, 123 insertions(+), 45 deletions(-)

diff --git a/drivers/net/failsafe/failsafe_ether.c b/drivers/net/failsafe/failsafe_ether.c
index 10b90fd837..031f3eb13f 100644
--- a/drivers/net/failsafe/failsafe_ether.c
+++ b/drivers/net/failsafe/failsafe_ether.c
@@ -592,7 +592,8 @@ failsafe_eth_rmv_event_callback(uint16_t port_id __rte_unused,
 {
 	struct sub_device *sdev = cb_arg;
 
-	fs_lock(fs_dev(sdev), 0);
+	if (fs_lock(fs_dev(sdev), 0) != 0)
+		return -1;
 	/* Switch as soon as possible tx_dev. */
 	fs_switch_dev(fs_dev(sdev), sdev);
 	/* Use safe bursts in any case. */
diff --git a/drivers/net/failsafe/failsafe_flow.c b/drivers/net/failsafe/failsafe_flow.c
index 354f9fec20..707e6c63b5 100644
--- a/drivers/net/failsafe/failsafe_flow.c
+++ b/drivers/net/failsafe/failsafe_flow.c
@@ -72,7 +72,9 @@ fs_flow_validate(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_flow_validate on sub_device %d", i);
 		ret = rte_flow_validate(PORT_ID(sdev),
@@ -99,7 +101,8 @@ fs_flow_create(struct rte_eth_dev *dev,
 	struct rte_flow *flow;
 	uint8_t i;
 
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return NULL;
 	flow = fs_flow_allocate(attr, patterns, actions);
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		flow->flows[i] = rte_flow_create(PORT_ID(sdev),
@@ -137,8 +140,9 @@ fs_flow_destroy(struct rte_eth_dev *dev,
 		ERROR("Invalid flow");
 		return -EINVAL;
 	}
-	ret = 0;
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		int local_ret;
 
@@ -169,7 +173,9 @@ fs_flow_flush(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_flow_flush on sub_device %d", i);
 		ret = rte_flow_flush(PORT_ID(sdev), error);
@@ -197,7 +203,8 @@ fs_flow_query(struct rte_eth_dev *dev,
 {
 	struct sub_device *sdev;
 
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return -1;
 	sdev = TX_SUBDEV(dev);
 	if (sdev != NULL) {
 		int ret = rte_flow_query(PORT_ID(sdev),
@@ -223,7 +230,9 @@ fs_flow_isolate(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV(sdev, i, dev) {
 		if (sdev->state < DEV_PROBED)
 			continue;
diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c
index d357e1bc83..35649b6244 100644
--- a/drivers/net/failsafe/failsafe_ops.c
+++ b/drivers/net/failsafe/failsafe_ops.c
@@ -28,7 +28,9 @@ fs_dev_configure(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV(sdev, i, dev) {
 		int rmv_interrupt = 0;
 		int lsc_interrupt = 0;
@@ -129,7 +131,9 @@ fs_dev_start(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	ret = failsafe_rx_intr_install(dev);
 	if (ret) {
 		fs_unlock(dev, 0);
@@ -189,7 +193,9 @@ fs_dev_stop(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	PRIV(dev)->state = DEV_STARTED - 1;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) {
 		ret = rte_eth_dev_stop(PORT_ID(sdev));
@@ -217,7 +223,9 @@ fs_dev_set_link_up(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", i);
 		ret = rte_eth_dev_set_link_up(PORT_ID(sdev));
@@ -239,7 +247,9 @@ fs_dev_set_link_down(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_set_link_down on sub_device %d", i);
 		ret = rte_eth_dev_set_link_down(PORT_ID(sdev));
@@ -263,7 +273,9 @@ fs_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 	int err = 0;
 	bool failure = true;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		uint16_t port_id = ETH(sdev)->data->port_id;
 
@@ -289,7 +301,9 @@ fs_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		uint16_t port_id = ETH(sdev)->data->port_id;
 
@@ -316,7 +330,9 @@ fs_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
 	int err = 0;
 	bool failure = true;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		uint16_t port_id = ETH(sdev)->data->port_id;
 
@@ -342,7 +358,9 @@ fs_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		uint16_t port_id = ETH(sdev)->data->port_id;
 
@@ -369,7 +387,8 @@ fs_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (rxq == NULL)
 		return;
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return;
 	if (rxq->event_fd >= 0)
 		close(rxq->event_fd);
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
@@ -395,7 +414,9 @@ fs_rx_queue_setup(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	if (rx_conf->rx_deferred_start) {
 		FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
 			if (SUBOPS(sdev, rx_queue_start) == NULL) {
@@ -466,7 +487,9 @@ fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
 	int ret;
 	int rc = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	if (idx >= dev->data->nb_rx_queues) {
 		rc = -EINVAL;
 		goto unlock;
@@ -506,7 +529,9 @@ fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
 	int rc = 0;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	if (idx >= dev->data->nb_rx_queues) {
 		rc = -EINVAL;
 		goto unlock;
@@ -542,7 +567,8 @@ fs_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (txq == NULL)
 		return;
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		if (ETH(sdev)->data->tx_queues != NULL &&
 		    ETH(sdev)->data->tx_queues[txq->qid] != NULL)
@@ -565,7 +591,9 @@ fs_tx_queue_setup(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	if (tx_conf->tx_deferred_start) {
 		FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
 			if (SUBOPS(sdev, tx_queue_start) == NULL) {
@@ -639,7 +667,9 @@ failsafe_eth_dev_close(struct rte_eth_dev *dev)
 	uint8_t i;
 	int err, ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	failsafe_hotplug_alarm_cancel(dev);
 	if (PRIV(dev)->state == DEV_STARTED) {
 		ret = dev->dev_ops->dev_stop(dev);
@@ -693,7 +723,9 @@ fs_promiscuous_enable(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_promiscuous_enable(PORT_ID(sdev));
 		ret = fs_err(sdev, ret);
@@ -725,7 +757,9 @@ fs_promiscuous_disable(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_promiscuous_disable(PORT_ID(sdev));
 		ret = fs_err(sdev, ret);
@@ -757,7 +791,9 @@ fs_allmulticast_enable(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_allmulticast_enable(PORT_ID(sdev));
 		ret = fs_err(sdev, ret);
@@ -789,7 +825,9 @@ fs_allmulticast_disable(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_allmulticast_disable(PORT_ID(sdev));
 		ret = fs_err(sdev, ret);
@@ -822,7 +860,9 @@ fs_link_update(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling link_update on sub_device %d", i);
 		ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete);
@@ -859,7 +899,9 @@ fs_stats_get(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	rte_memcpy(stats, &PRIV(dev)->stats_accumulator, sizeof(*stats));
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		struct rte_eth_stats *snapshot = &sdev->stats_snapshot.stats;
@@ -893,7 +935,9 @@ fs_stats_reset(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_stats_reset(PORT_ID(sdev));
 		if (ret) {
@@ -983,7 +1027,9 @@ fs_xstats_get_names(struct rte_eth_dev *dev,
 {
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	ret = __fs_xstats_get_names(dev, xstats_names, limit);
 	fs_unlock(dev, 0);
 	return ret;
@@ -1035,7 +1081,9 @@ fs_xstats_get(struct rte_eth_dev *dev,
 {
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	ret = __fs_xstats_get(dev, xstats, n);
 	fs_unlock(dev, 0);
 
@@ -1048,9 +1096,11 @@ fs_xstats_reset(struct rte_eth_dev *dev)
 {
 	struct sub_device *sdev;
 	uint8_t i;
-	int r = 0;
+	int r;
 
-	fs_lock(dev, 0);
+	r = fs_lock(dev, 0);
+	if (r != 0)
+		return r;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		r = rte_eth_xstats_reset(PORT_ID(sdev));
 		if (r < 0)
@@ -1238,7 +1288,8 @@ fs_dev_supported_ptypes_get(struct rte_eth_dev *dev)
 	struct rte_eth_dev *edev;
 	const uint32_t *ret;
 
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return NULL;
 	sdev = TX_SUBDEV(dev);
 	if (sdev == NULL) {
 		ret = NULL;
@@ -1270,7 +1321,9 @@ fs_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_set_mtu on sub_device %d", i);
 		ret = rte_eth_dev_set_mtu(PORT_ID(sdev), mtu);
@@ -1292,7 +1345,9 @@ fs_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_vlan_filter on sub_device %d", i);
 		ret = rte_eth_dev_vlan_filter(PORT_ID(sdev), vlan_id, on);
@@ -1314,7 +1369,9 @@ fs_flow_ctrl_get(struct rte_eth_dev *dev,
 	struct sub_device *sdev;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	sdev = TX_SUBDEV(dev);
 	if (sdev == NULL) {
 		ret = 0;
@@ -1338,7 +1395,9 @@ fs_flow_ctrl_set(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_flow_ctrl_set on sub_device %d", i);
 		ret = rte_eth_dev_flow_ctrl_set(PORT_ID(sdev), fc_conf);
@@ -1359,7 +1418,8 @@ fs_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
 	struct sub_device *sdev;
 	uint8_t i;
 
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return;
 	/* No check: already done within the rte_eth_dev_mac_addr_remove
 	 * call for the fail-safe device.
 	 */
@@ -1381,7 +1441,9 @@ fs_mac_addr_add(struct rte_eth_dev *dev,
 	uint8_t i;
 
 	RTE_ASSERT(index < FAILSAFE_MAX_ETHADDR);
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), mac_addr, vmdq);
 		if ((ret = fs_err(sdev, ret))) {
@@ -1407,7 +1469,9 @@ fs_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr);
 		ret = fs_err(sdev, ret);
@@ -1432,7 +1496,9 @@ fs_set_mc_addr_list(struct rte_eth_dev *dev,
 	int ret;
 	void *mcast_addrs;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
@@ -1480,7 +1546,9 @@ fs_rss_hash_update(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_rss_hash_update(PORT_ID(sdev), rss_conf);
 		ret = fs_err(sdev, ret);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 17/20] net/failsafe: annotate pthread mutex
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (15 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 16/20] net/failsafe: fix mutex locking David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 18/20] net/hinic: " David Marchand
                     ` (3 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Gaetan Rivet

Annotate wrappers on top of the pthread mutex API.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/failsafe/failsafe_private.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h
index 53a451c1b1..97b6f5300d 100644
--- a/drivers/net/failsafe/failsafe_private.h
+++ b/drivers/net/failsafe/failsafe_private.h
@@ -403,6 +403,9 @@ fs_dev(struct sub_device *sdev) {
  */
 static inline int
 fs_lock(struct rte_eth_dev *dev, unsigned int is_alarm)
+#ifdef RTE_EXEC_ENV_FREEBSD
+	__rte_exclusive_trylock_function(0, PRIV(dev)->hotplug_mutex)
+#endif
 {
 	int ret;
 
@@ -430,6 +433,9 @@ fs_lock(struct rte_eth_dev *dev, unsigned int is_alarm)
  */
 static inline void
 fs_unlock(struct rte_eth_dev *dev, unsigned int is_alarm)
+#ifdef RTE_EXEC_ENV_FREEBSD
+	__rte_unlock_function(PRIV(dev)->hotplug_mutex)
+#endif
 {
 	int ret;
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 18/20] net/hinic: annotate pthread mutex
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (16 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 17/20] net/failsafe: annotate pthread mutex David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 19/20] eal/windows: disable lock check on alarm code David Marchand
                     ` (2 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev; +Cc: thomas, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou

Annotate wrappers on top of the pthread mutex API.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/hinic/base/hinic_compat.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/hinic/base/hinic_compat.h b/drivers/net/hinic/base/hinic_compat.h
index aea332046e..89732ca11a 100644
--- a/drivers/net/hinic/base/hinic_compat.h
+++ b/drivers/net/hinic/base/hinic_compat.h
@@ -224,6 +224,9 @@ static inline int hinic_mutex_destroy(pthread_mutex_t *pthreadmutex)
 }
 
 static inline int hinic_mutex_lock(pthread_mutex_t *pthreadmutex)
+#ifdef RTE_EXEC_ENV_FREEBSD
+	__rte_exclusive_trylock_function(0, *pthreadmutex)
+#endif
 {
 	int err;
 	struct timespec tout;
@@ -239,6 +242,9 @@ static inline int hinic_mutex_lock(pthread_mutex_t *pthreadmutex)
 }
 
 static inline int hinic_mutex_unlock(pthread_mutex_t *pthreadmutex)
+#ifdef RTE_EXEC_ENV_FREEBSD
+	__rte_unlock_function(*pthreadmutex)
+#endif
 {
 	return pthread_mutex_unlock(pthreadmutex);
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 19/20] eal/windows: disable lock check on alarm code
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (17 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 18/20] net/hinic: " David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-24 15:11   ` [PATCH v2 20/20] enable lock check David Marchand
  2023-02-24 15:58   ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers Gaëtan Rivet
  20 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

This code uses locks to implement synchronisation between two threads.
There seems nothing wrong with it, just silence the clang lock check.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/windows/eal_alarm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c
index 48203a2870..34b52380ce 100644
--- a/lib/eal/windows/eal_alarm.c
+++ b/lib/eal/windows/eal_alarm.c
@@ -224,6 +224,7 @@ struct intr_task {
 
 static void
 intr_thread_entry(void *arg)
+	__rte_no_thread_safety_analysis
 {
 	struct intr_task *task = arg;
 	task->func(task->arg);
@@ -232,6 +233,7 @@ intr_thread_entry(void *arg)
 
 static int
 intr_thread_exec_sync(void (*func)(void *arg), void *arg)
+	__rte_no_thread_safety_analysis
 {
 	struct intr_task task;
 	int ret;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v2 20/20] enable lock check
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (18 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 19/20] eal/windows: disable lock check on alarm code David Marchand
@ 2023-02-24 15:11   ` David Marchand
  2023-02-27  2:32     ` Xia, Chenbo
  2023-02-24 15:58   ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers Gaëtan Rivet
  20 siblings, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-02-24 15:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, Anatoly Burakov, Hemant Agrawal, Sachin Saxena,
	Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Matan Azrad, Viacheslav Ovsiienko, Pavan Nikhilesh,
	Shijith Thotton, Rasesh Mody, Shahed Shaikh, Ajit Khaparde,
	Somnath Kotur, John Daley, Hyong Youb Kim, Dongdong Liu,
	Yisen Zhuang, Konstantin Ananyev, Vladimir Medvedkin,
	Erik Gabriel Carrillo, Maxime Coquelin, Chenbo Xia

Now that a lot of components can be compiled with the lock checks,
invert the logic and opt out for components not ready yet:
- drivers/bus/dpaa,
- drivers/common/cnxk,
- drivers/common/mlx5,
- drivers/event/cnxk,
- drivers/net/bnx2x,
- drivers/net/bnxt,
- drivers/net/cnxk,
- drivers/net/enic,
- drivers/net/hns3,
- drivers/net/mlx5,
- lib/ipsec,
- lib/timer,

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++--
 drivers/bus/dpaa/meson.build                    | 1 +
 drivers/common/cnxk/meson.build                 | 1 +
 drivers/common/mlx5/meson.build                 | 1 +
 drivers/event/cnxk/meson.build                  | 1 +
 drivers/meson.build                             | 2 +-
 drivers/net/bnx2x/meson.build                   | 1 +
 drivers/net/bnxt/meson.build                    | 1 +
 drivers/net/cnxk/meson.build                    | 1 +
 drivers/net/enic/meson.build                    | 1 +
 drivers/net/hns3/meson.build                    | 1 +
 drivers/net/mlx5/meson.build                    | 1 +
 lib/ipsec/meson.build                           | 1 +
 lib/meson.build                                 | 2 +-
 lib/timer/meson.build                           | 1 +
 lib/vhost/meson.build                           | 1 -
 16 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
index 3f33621e05..93c8a031be 100644
--- a/doc/guides/prog_guide/env_abstraction_layer.rst
+++ b/doc/guides/prog_guide/env_abstraction_layer.rst
@@ -550,8 +550,9 @@ Some general comments:
   waiving checks with ``__rte_no_thread_safety_analysis`` in your code, please
   discuss it on the mailing list,
 
-A DPDK library/driver can enable/disable the checks by setting
-``annotate_locks`` accordingly in its ``meson.build`` file.
+The checks are enabled by default for libraries and drivers.
+They can be disabled by setting ``annotate_locks`` to ``false`` in
+the concerned library/driver ``meson.build``.
 
 IOVA Mode Detection
 ~~~~~~~~~~~~~~~~~~~
diff --git a/drivers/bus/dpaa/meson.build b/drivers/bus/dpaa/meson.build
index 5506f2bffc..183b251459 100644
--- a/drivers/bus/dpaa/meson.build
+++ b/drivers/bus/dpaa/meson.build
@@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith')
 endif
 
 includes += include_directories('include', 'base/qbman')
+annotate_locks = false
diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
index 849735921c..9beb1cddba 100644
--- a/drivers/common/cnxk/meson.build
+++ b/drivers/common/cnxk/meson.build
@@ -88,3 +88,4 @@ sources += files('cnxk_telemetry_bphy.c',
 
 deps += ['bus_pci', 'net', 'telemetry']
 pmd_supports_disable_iova_as_pa = true
+annotate_locks = false
diff --git a/drivers/common/mlx5/meson.build b/drivers/common/mlx5/meson.build
index 60ccd95cbc..d38255dc82 100644
--- a/drivers/common/mlx5/meson.build
+++ b/drivers/common/mlx5/meson.build
@@ -40,3 +40,4 @@ endif
 mlx5_config = configuration_data()
 subdir(exec_env)
 configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config)
+annotate_locks = false
diff --git a/drivers/event/cnxk/meson.build b/drivers/event/cnxk/meson.build
index aa42ab3a90..20c6a0484a 100644
--- a/drivers/event/cnxk/meson.build
+++ b/drivers/event/cnxk/meson.build
@@ -480,3 +480,4 @@ endforeach
 
 deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk']
 pmd_supports_disable_iova_as_pa = true
+annotate_locks = false
diff --git a/drivers/meson.build b/drivers/meson.build
index 0618c31a69..d529980fc5 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -91,7 +91,7 @@ foreach subpath:subdirs
         build = true # set to false to disable, e.g. missing deps
         reason = '<unknown reason>' # set if build == false to explain
         name = drv
-        annotate_locks = false
+        annotate_locks = true
         sources = []
         headers = []
         driver_sdk_headers = [] # public headers included by drivers
diff --git a/drivers/net/bnx2x/meson.build b/drivers/net/bnx2x/meson.build
index 156f97d31f..dbf9c7225d 100644
--- a/drivers/net/bnx2x/meson.build
+++ b/drivers/net/bnx2x/meson.build
@@ -21,3 +21,4 @@ sources = files(
         'ecore_sp.c',
         'elink.c',
 )
+annotate_locks = false
diff --git a/drivers/net/bnxt/meson.build b/drivers/net/bnxt/meson.build
index 09d494e90f..f43dbfc445 100644
--- a/drivers/net/bnxt/meson.build
+++ b/drivers/net/bnxt/meson.build
@@ -68,3 +68,4 @@ if arch_subdir == 'x86'
 elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64')
     sources += files('bnxt_rxtx_vec_neon.c')
 endif
+annotate_locks = false
diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
index c7ca24d437..86ed2d13dd 100644
--- a/drivers/net/cnxk/meson.build
+++ b/drivers/net/cnxk/meson.build
@@ -196,3 +196,4 @@ endforeach
 
 headers = files('rte_pmd_cnxk.h')
 pmd_supports_disable_iova_as_pa = true
+annotate_locks = false
diff --git a/drivers/net/enic/meson.build b/drivers/net/enic/meson.build
index 7131a25f09..1523511ba5 100644
--- a/drivers/net/enic/meson.build
+++ b/drivers/net/enic/meson.build
@@ -39,3 +39,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64')
             c_args: [cflags, '-mavx2'])
     objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c')
 endif
+annotate_locks = false
diff --git a/drivers/net/hns3/meson.build b/drivers/net/hns3/meson.build
index e1a5afa2ec..43e52e6107 100644
--- a/drivers/net/hns3/meson.build
+++ b/drivers/net/hns3/meson.build
@@ -38,6 +38,7 @@ sources = files(
         'hns3_common.c',
         'hns3_dump.c',
 )
+annotate_locks = false
 
 deps += ['hash']
 
diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
index abd507bd88..5e7d0d4e1a 100644
--- a/drivers/net/mlx5/meson.build
+++ b/drivers/net/mlx5/meson.build
@@ -79,3 +79,4 @@ testpmd_sources += files('mlx5_testpmd.c')
 subdir(exec_env)
 
 subdir('hws')
+annotate_locks = false
diff --git a/lib/ipsec/meson.build b/lib/ipsec/meson.build
index 0b8b935cd2..ff44d6fbdf 100644
--- a/lib/ipsec/meson.build
+++ b/lib/ipsec/meson.build
@@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c',
 
 headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h')
 indirect_headers += files('rte_ipsec_group.h')
+annotate_locks = false
 
 deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
diff --git a/lib/meson.build b/lib/meson.build
index 2bc0932ad5..9b5e412454 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -120,7 +120,7 @@ foreach l:libraries
     reason = '<unknown reason>' # set if build == false to explain why
     name = l
     use_function_versioning = false
-    annotate_locks = false
+    annotate_locks = true
     sources = []
     headers = []
     indirect_headers = [] # public headers not directly included by apps
diff --git a/lib/timer/meson.build b/lib/timer/meson.build
index 89b17e0397..87bbb10592 100644
--- a/lib/timer/meson.build
+++ b/lib/timer/meson.build
@@ -3,3 +3,4 @@
 
 sources = files('rte_timer.c')
 headers = files('rte_timer.h')
+annotate_locks = false
diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build
index 197a51d936..0d1abf6283 100644
--- a/lib/vhost/meson.build
+++ b/lib/vhost/meson.build
@@ -18,7 +18,6 @@ endif
 dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h'))
 cflags += '-fno-strict-aliasing'
 
-annotate_locks = true
 sources = files(
         'fd_man.c',
         'iotlb.c',
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 16/20] net/failsafe: fix mutex locking
  2023-02-24 15:11   ` [PATCH v2 16/20] net/failsafe: fix mutex locking David Marchand
@ 2023-02-24 15:35     ` Gaëtan Rivet
  0 siblings, 0 replies; 76+ messages in thread
From: Gaëtan Rivet @ 2023-02-24 15:35 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Thomas Monjalon

On Fri, Feb 24, 2023, at 16:11, David Marchand wrote:
> The pthread mutex API describes cases where locking might fail.
> Check fts_enter wrapper return code.
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Hello David,

Thanks for the fix,
Acked-by: Gaetan Rivet <grive@u256.net>

-- 
Gaetan Rivet

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
                     ` (19 preceding siblings ...)
  2023-02-24 15:11   ` [PATCH v2 20/20] enable lock check David Marchand
@ 2023-02-24 15:58   ` Gaëtan Rivet
  2023-02-25 10:16     ` David Marchand
  20 siblings, 1 reply; 76+ messages in thread
From: Gaëtan Rivet @ 2023-02-24 15:58 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Thomas Monjalon

On Fri, Feb 24, 2023, at 16:11, David Marchand wrote:
> This is a followup of the series that introduced lock annotations.
> I reworked and made annotations work in what seemed the easier cases.
> In most cases, I chose to convert inline wrappers around the EAL lock
> API to simple macro: I did not see much value in those wrappers and this
> is way simpler than adding __rte_*lock_function tags everywhere.
>
> A list of libraries and drivers still need more work as their code have
> non obvious locks handling. For those components, the check is opted
> out.
> I leave it to their respective maintainers to enable the checks later.
>
> FreeBSD libc pthread API has lock annotations while Linux glibc has
> none.
> We could simply disable the check on FreeBSD, but having this check,
> a few issues got raised in drivers that are built with FreeBSD.
> For now, I went with a simple #ifdef FreeBSD for pthread mutex related
> annotations in our code.
>

Hi David,

This is a great change, thanks for doing it.
However I am not sure I understand the logic regarding the '#ifdef FREEBSD'.

These annotations provide static hints to clang's thread safety analysis.
What is the dependency on FreeBSD glibc?

-- 
Gaetan Rivet

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-02-24 15:58   ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers Gaëtan Rivet
@ 2023-02-25 10:16     ` David Marchand
  2023-02-27 16:12       ` Gaëtan Rivet
  0 siblings, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-02-25 10:16 UTC (permalink / raw)
  To: Gaëtan Rivet; +Cc: dev, Thomas Monjalon

Salut Gaëtan,

On Fri, Feb 24, 2023 at 4:59 PM Gaëtan Rivet <grive@u256.net> wrote:
> > FreeBSD libc pthread API has lock annotations while Linux glibc has
> > none.
> > We could simply disable the check on FreeBSD, but having this check,
> > a few issues got raised in drivers that are built with FreeBSD.
> > For now, I went with a simple #ifdef FreeBSD for pthread mutex related
> > annotations in our code.
> >
>
> Hi David,
>
> This is a great change, thanks for doing it.
> However I am not sure I understand the logic regarding the '#ifdef FREEBSD'.
>
> These annotations provide static hints to clang's thread safety analysis.
> What is the dependency on FreeBSD glibc?

FreeBSD libc added clang annotations, while glibc did not.

FreeBSD 13.1 libc:
int             pthread_mutex_lock(pthread_mutex_t * __mutex)
                    __locks_exclusive(*__mutex);

With:

#if __has_extension(c_thread_safety_attributes)
#define __lock_annotate(x)      __attribute__((x))
#else
#define __lock_annotate(x)
#endif

/* Function acquires an exclusive or shared lock. */
#define __locks_exclusive(...) \
        __lock_annotate(exclusive_lock_function(__VA_ARGS__))


glibc:
extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
     __THROWNL __nonnull ((1));



Since glibc does not declare that pthread_mutex_t is lockable, adding
an annotation triggers an error for Linux (taking eal_common_proc.c
patch 14 as an example):

../lib/eal/common/eal_common_proc.c:911:2: error:
'exclusive_locks_required' attribute requires arguments whose type is
annotated with 'capability' attribute; type here is 'pthread_mutex_t'
[-Werror,-Wthread-safety-attributes]
        __rte_exclusive_locks_required(pending_requests.lock)
        ^
../lib/eal/include/rte_lock_annotations.h:23:17: note: expanded from
macro '__rte_exclusive_locks_required'
        __attribute__((exclusive_locks_required(__VA_ARGS__)))
                       ^

We could wrap this annotation in a new construct (which would require
some build time check wrt pthread API state).
Not sure it is worth the effort though, for now.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 76+ messages in thread

* RE: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
  2023-02-24 15:11   ` [PATCH v2 11/20] net/virtio: annotate lock for guest announce David Marchand
@ 2023-02-27  2:05     ` Xia, Chenbo
  2023-02-27  8:24       ` David Marchand
  0 siblings, 1 reply; 76+ messages in thread
From: Xia, Chenbo @ 2023-02-27  2:05 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: thomas, Maxime Coquelin

Hi David,

> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Friday, February 24, 2023 11:12 PM
> To: dev@dpdk.org
> Cc: thomas@monjalon.net; Maxime Coquelin <maxime.coquelin@redhat.com>; Xia,
> Chenbo <chenbo.xia@intel.com>
> Subject: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
> 
> Expose requirements for helpers dealing with the
> VIRTIO_DEV_TO_HW(dev)->state_lock lock.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  drivers/net/virtio/virtio_ethdev.c | 8 ++++----
>  drivers/net/virtio/virtio_ethdev.h | 7 +++++--
>  2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_ethdev.c
> b/drivers/net/virtio/virtio_ethdev.c
> index 0103d95920..a3de44958c 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -1149,11 +1149,11 @@ virtio_dev_pause(struct rte_eth_dev *dev)
>  {
>  	struct virtio_hw *hw = dev->data->dev_private;
> 
> -	rte_spinlock_lock(&hw->state_lock);
> +	rte_spinlock_lock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
> 
>  	if (hw->started == 0) {
>  		/* Device is just stopped. */
> -		rte_spinlock_unlock(&hw->state_lock);
> +		rte_spinlock_unlock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
>  		return -1;
>  	}
>  	hw->started = 0;
> @@ -1174,7 +1174,7 @@ virtio_dev_resume(struct rte_eth_dev *dev)
>  	struct virtio_hw *hw = dev->data->dev_private;
> 
>  	hw->started = 1;
> -	rte_spinlock_unlock(&hw->state_lock);
> +	rte_spinlock_unlock(&VIRTIO_DEV_TO_HW(dev)->state_lock);
>  }
> 
>  /*
> @@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev)
>  	}
> 
>  	/* If virtio port just stopped, no need to send RARP */
> -	if (virtio_dev_pause(dev) < 0) {
> +	if (virtio_dev_pause(dev) != 0) {
>  		rte_pktmbuf_free(rarp_mbuf);
>  		return;
>  	}
> diff --git a/drivers/net/virtio/virtio_ethdev.h
> b/drivers/net/virtio/virtio_ethdev.h
> index c08f382791..ece0130603 100644
> --- a/drivers/net/virtio/virtio_ethdev.h
> +++ b/drivers/net/virtio/virtio_ethdev.h
> @@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
> 
>  void virtio_interrupt_handler(void *param);
> 
> -int virtio_dev_pause(struct rte_eth_dev *dev);
> -void virtio_dev_resume(struct rte_eth_dev *dev);
> +#define VIRTIO_DEV_TO_HW(dev) ((struct virtio_hw *)(dev)->data-
> >dev_private)
> +int virtio_dev_pause(struct rte_eth_dev *dev)
> +	__rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)-
> >state_lock);

Just curious, why this is trylock instead of lock?

Thanks,
Chenbo

> +void virtio_dev_resume(struct rte_eth_dev *dev)
> +	__rte_unlock_function(&VIRTIO_DEV_TO_HW(dev)->state_lock);
>  int virtio_dev_stop(struct rte_eth_dev *dev);
>  int virtio_dev_close(struct rte_eth_dev *dev);
>  int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
> --
> 2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* RE: [PATCH v2 20/20] enable lock check
  2023-02-24 15:11   ` [PATCH v2 20/20] enable lock check David Marchand
@ 2023-02-27  2:32     ` Xia, Chenbo
  0 siblings, 0 replies; 76+ messages in thread
From: Xia, Chenbo @ 2023-02-27  2:32 UTC (permalink / raw)
  To: David Marchand, dev
  Cc: thomas, Burakov, Anatoly, Hemant Agrawal, Sachin Saxena,
	Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Matan Azrad, Viacheslav Ovsiienko, Pavan Nikhilesh,
	Shijith Thotton, Rasesh Mody, Shahed Shaikh, Ajit Khaparde,
	Somnath Kotur, Daley, John, Hyong Youb Kim, Dongdong Liu,
	Yisen Zhuang, Konstantin Ananyev, Medvedkin, Vladimir, Carrillo,
	Erik G, Maxime Coquelin

> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Friday, February 24, 2023 11:12 PM
> To: dev@dpdk.org
> Cc: thomas@monjalon.net; Burakov, Anatoly <anatoly.burakov@intel.com>;
> Hemant Agrawal <hemant.agrawal@nxp.com>; Sachin Saxena
> <sachin.saxena@nxp.com>; Nithin Dabilpuram <ndabilpuram@marvell.com>;
> Kiran Kumar K <kirankumark@marvell.com>; Sunil Kumar Kori
> <skori@marvell.com>; Satha Rao <skoteshwar@marvell.com>; Matan Azrad
> <matan@nvidia.com>; Viacheslav Ovsiienko <viacheslavo@nvidia.com>; Pavan
> Nikhilesh <pbhagavatula@marvell.com>; Shijith Thotton
> <sthotton@marvell.com>; Rasesh Mody <rmody@marvell.com>; Shahed Shaikh
> <shshaikh@marvell.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>;
> Somnath Kotur <somnath.kotur@broadcom.com>; Daley, John
> <johndale@cisco.com>; Hyong Youb Kim <hyonkim@cisco.com>; Dongdong Liu
> <liudongdong3@huawei.com>; Yisen Zhuang <yisen.zhuang@huawei.com>;
> Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>; Medvedkin, Vladimir
> <vladimir.medvedkin@intel.com>; Carrillo, Erik G
> <erik.g.carrillo@intel.com>; Maxime Coquelin <maxime.coquelin@redhat.com>;
> Xia, Chenbo <chenbo.xia@intel.com>
> Subject: [PATCH v2 20/20] enable lock check
> 
> Now that a lot of components can be compiled with the lock checks,
> invert the logic and opt out for components not ready yet:
> - drivers/bus/dpaa,
> - drivers/common/cnxk,
> - drivers/common/mlx5,
> - drivers/event/cnxk,
> - drivers/net/bnx2x,
> - drivers/net/bnxt,
> - drivers/net/cnxk,
> - drivers/net/enic,
> - drivers/net/hns3,
> - drivers/net/mlx5,
> - lib/ipsec,
> - lib/timer,
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++--
>  drivers/bus/dpaa/meson.build                    | 1 +
>  drivers/common/cnxk/meson.build                 | 1 +
>  drivers/common/mlx5/meson.build                 | 1 +
>  drivers/event/cnxk/meson.build                  | 1 +
>  drivers/meson.build                             | 2 +-
>  drivers/net/bnx2x/meson.build                   | 1 +
>  drivers/net/bnxt/meson.build                    | 1 +
>  drivers/net/cnxk/meson.build                    | 1 +
>  drivers/net/enic/meson.build                    | 1 +
>  drivers/net/hns3/meson.build                    | 1 +
>  drivers/net/mlx5/meson.build                    | 1 +
>  lib/ipsec/meson.build                           | 1 +
>  lib/meson.build                                 | 2 +-
>  lib/timer/meson.build                           | 1 +
>  lib/vhost/meson.build                           | 1 -
>  16 files changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst
> b/doc/guides/prog_guide/env_abstraction_layer.rst
> index 3f33621e05..93c8a031be 100644
> --- a/doc/guides/prog_guide/env_abstraction_layer.rst
> +++ b/doc/guides/prog_guide/env_abstraction_layer.rst
> @@ -550,8 +550,9 @@ Some general comments:
>    waiving checks with ``__rte_no_thread_safety_analysis`` in your code,
> please
>    discuss it on the mailing list,
> 
> -A DPDK library/driver can enable/disable the checks by setting
> -``annotate_locks`` accordingly in its ``meson.build`` file.
> +The checks are enabled by default for libraries and drivers.
> +They can be disabled by setting ``annotate_locks`` to ``false`` in
> +the concerned library/driver ``meson.build``.
> 
>  IOVA Mode Detection
>  ~~~~~~~~~~~~~~~~~~~
> diff --git a/drivers/bus/dpaa/meson.build b/drivers/bus/dpaa/meson.build
> index 5506f2bffc..183b251459 100644
> --- a/drivers/bus/dpaa/meson.build
> +++ b/drivers/bus/dpaa/meson.build
> @@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith')
>  endif
> 
>  includes += include_directories('include', 'base/qbman')
> +annotate_locks = false
> diff --git a/drivers/common/cnxk/meson.build
> b/drivers/common/cnxk/meson.build
> index 849735921c..9beb1cddba 100644
> --- a/drivers/common/cnxk/meson.build
> +++ b/drivers/common/cnxk/meson.build
> @@ -88,3 +88,4 @@ sources += files('cnxk_telemetry_bphy.c',
> 
>  deps += ['bus_pci', 'net', 'telemetry']
>  pmd_supports_disable_iova_as_pa = true
> +annotate_locks = false
> diff --git a/drivers/common/mlx5/meson.build
> b/drivers/common/mlx5/meson.build
> index 60ccd95cbc..d38255dc82 100644
> --- a/drivers/common/mlx5/meson.build
> +++ b/drivers/common/mlx5/meson.build
> @@ -40,3 +40,4 @@ endif
>  mlx5_config = configuration_data()
>  subdir(exec_env)
>  configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config)
> +annotate_locks = false
> diff --git a/drivers/event/cnxk/meson.build
> b/drivers/event/cnxk/meson.build
> index aa42ab3a90..20c6a0484a 100644
> --- a/drivers/event/cnxk/meson.build
> +++ b/drivers/event/cnxk/meson.build
> @@ -480,3 +480,4 @@ endforeach
> 
>  deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk']
>  pmd_supports_disable_iova_as_pa = true
> +annotate_locks = false
> diff --git a/drivers/meson.build b/drivers/meson.build
> index 0618c31a69..d529980fc5 100644
> --- a/drivers/meson.build
> +++ b/drivers/meson.build
> @@ -91,7 +91,7 @@ foreach subpath:subdirs
>          build = true # set to false to disable, e.g. missing deps
>          reason = '<unknown reason>' # set if build == false to explain
>          name = drv
> -        annotate_locks = false
> +        annotate_locks = true
>          sources = []
>          headers = []
>          driver_sdk_headers = [] # public headers included by drivers
> diff --git a/drivers/net/bnx2x/meson.build b/drivers/net/bnx2x/meson.build
> index 156f97d31f..dbf9c7225d 100644
> --- a/drivers/net/bnx2x/meson.build
> +++ b/drivers/net/bnx2x/meson.build
> @@ -21,3 +21,4 @@ sources = files(
>          'ecore_sp.c',
>          'elink.c',
>  )
> +annotate_locks = false
> diff --git a/drivers/net/bnxt/meson.build b/drivers/net/bnxt/meson.build
> index 09d494e90f..f43dbfc445 100644
> --- a/drivers/net/bnxt/meson.build
> +++ b/drivers/net/bnxt/meson.build
> @@ -68,3 +68,4 @@ if arch_subdir == 'x86'
>  elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64')
>      sources += files('bnxt_rxtx_vec_neon.c')
>  endif
> +annotate_locks = false
> diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
> index c7ca24d437..86ed2d13dd 100644
> --- a/drivers/net/cnxk/meson.build
> +++ b/drivers/net/cnxk/meson.build
> @@ -196,3 +196,4 @@ endforeach
> 
>  headers = files('rte_pmd_cnxk.h')
>  pmd_supports_disable_iova_as_pa = true
> +annotate_locks = false
> diff --git a/drivers/net/enic/meson.build b/drivers/net/enic/meson.build
> index 7131a25f09..1523511ba5 100644
> --- a/drivers/net/enic/meson.build
> +++ b/drivers/net/enic/meson.build
> @@ -39,3 +39,4 @@ elif cc.has_argument('-mavx2') and
> dpdk_conf.get('RTE_ARCH_64')
>              c_args: [cflags, '-mavx2'])
>      objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c')
>  endif
> +annotate_locks = false
> diff --git a/drivers/net/hns3/meson.build b/drivers/net/hns3/meson.build
> index e1a5afa2ec..43e52e6107 100644
> --- a/drivers/net/hns3/meson.build
> +++ b/drivers/net/hns3/meson.build
> @@ -38,6 +38,7 @@ sources = files(
>          'hns3_common.c',
>          'hns3_dump.c',
>  )
> +annotate_locks = false
> 
>  deps += ['hash']
> 
> diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
> index abd507bd88..5e7d0d4e1a 100644
> --- a/drivers/net/mlx5/meson.build
> +++ b/drivers/net/mlx5/meson.build
> @@ -79,3 +79,4 @@ testpmd_sources += files('mlx5_testpmd.c')
>  subdir(exec_env)
> 
>  subdir('hws')
> +annotate_locks = false
> diff --git a/lib/ipsec/meson.build b/lib/ipsec/meson.build
> index 0b8b935cd2..ff44d6fbdf 100644
> --- a/lib/ipsec/meson.build
> +++ b/lib/ipsec/meson.build
> @@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c',
> 
>  headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h')
>  indirect_headers += files('rte_ipsec_group.h')
> +annotate_locks = false
> 
>  deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
> diff --git a/lib/meson.build b/lib/meson.build
> index 2bc0932ad5..9b5e412454 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -120,7 +120,7 @@ foreach l:libraries
>      reason = '<unknown reason>' # set if build == false to explain why
>      name = l
>      use_function_versioning = false
> -    annotate_locks = false
> +    annotate_locks = true
>      sources = []
>      headers = []
>      indirect_headers = [] # public headers not directly included by apps
> diff --git a/lib/timer/meson.build b/lib/timer/meson.build
> index 89b17e0397..87bbb10592 100644
> --- a/lib/timer/meson.build
> +++ b/lib/timer/meson.build
> @@ -3,3 +3,4 @@
> 
>  sources = files('rte_timer.c')
>  headers = files('rte_timer.h')
> +annotate_locks = false
> diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build
> index 197a51d936..0d1abf6283 100644
> --- a/lib/vhost/meson.build
> +++ b/lib/vhost/meson.build
> @@ -18,7 +18,6 @@ endif
>  dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY',
> cc.has_header('linux/userfaultfd.h'))
>  cflags += '-fno-strict-aliasing'
> 
> -annotate_locks = true
>  sources = files(
>          'fd_man.c',
>          'iotlb.c',
> --
> 2.39.2

For lib/vhost:

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

^ permalink raw reply	[flat|nested] 76+ messages in thread

* RE: [PATCH v2 12/20] raw/ifpga: inherit lock annotations
  2023-02-24 15:11   ` [PATCH v2 12/20] raw/ifpga: inherit lock annotations David Marchand
@ 2023-02-27  6:29     ` Xu, Rosen
  2023-02-27  7:15       ` Huang, Wei
  0 siblings, 1 reply; 76+ messages in thread
From: Xu, Rosen @ 2023-02-27  6:29 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: thomas, Zhang, Tianfei, Huang, Wei

Hi,

> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Friday, February 24, 2023 11:12 PM
> To: dev@dpdk.org
> Cc: thomas@monjalon.net; Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
> <tianfei.zhang@intel.com>
> Subject: [PATCH v2 12/20] raw/ifpga: inherit lock annotations
> 
> The checks in those helpers are useless:
> - all (start/stop/reset/test) callers ensure that dev != NULL,
> - dev->sd can't be NULL either as it would mean the application is calling
>   those helpers for a dev pointer that did not pass initialisation,
> 
> Once the checks are removed, the only thing that remains is calls to the
> rte_spinlock API, so simply use macros and inherit annotations from the lock
> API.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  drivers/raw/ifpga/afu_pmd_core.c | 17 ++---------------
>  1 file changed, 2 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/raw/ifpga/afu_pmd_core.c
> b/drivers/raw/ifpga/afu_pmd_core.c
> index ddf7a34f33..3ab1f47ac1 100644
> --- a/drivers/raw/ifpga/afu_pmd_core.c
> +++ b/drivers/raw/ifpga/afu_pmd_core.c
> @@ -23,21 +23,8 @@ static struct rte_afu_uuid
> afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1];
>  TAILQ_HEAD(afu_drv_list, afu_rawdev_drv);  static struct afu_drv_list
> afu_pmd_list = TAILQ_HEAD_INITIALIZER(afu_pmd_list);
> 
> -static inline int afu_rawdev_trylock(struct afu_rawdev *dev) -{
> -	if (!dev || !dev->sd)
> -		return 0;
> -
> -	return rte_spinlock_trylock(&dev->sd->lock);
> -}
> -
> -static inline void afu_rawdev_unlock(struct afu_rawdev *dev) -{
> -	if (!dev || !dev->sd)
> -		return;
> -
> -	rte_spinlock_unlock(&dev->sd->lock);
> -}
> +#define afu_rawdev_trylock(dev) rte_spinlock_trylock(&dev->sd->lock)
> +#define afu_rawdev_unlock(dev) rte_spinlock_unlock(&dev->sd->lock)
> 
>  static int afu_rawdev_configure(const struct rte_rawdev *rawdev,
>  	rte_rawdev_obj_t config, size_t config_size)
> --
> 2.39.2


It looks good for me.
Reviewed-by: Rosen Xu <rosen.xu@intel.com>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* RE: [PATCH v2 12/20] raw/ifpga: inherit lock annotations
  2023-02-27  6:29     ` Xu, Rosen
@ 2023-02-27  7:15       ` Huang, Wei
  0 siblings, 0 replies; 76+ messages in thread
From: Huang, Wei @ 2023-02-27  7:15 UTC (permalink / raw)
  To: Xu, Rosen, David Marchand, dev; +Cc: thomas, Zhang, Tianfei

Hi,

> -----Original Message-----
> From: Xu, Rosen <rosen.xu@intel.com>
> Sent: Monday, February 27, 2023 14:29
> To: David Marchand <david.marchand@redhat.com>; dev@dpdk.org
> Cc: thomas@monjalon.net; Zhang, Tianfei <tianfei.zhang@intel.com>; Huang,
> Wei <wei.huang@intel.com>
> Subject: RE: [PATCH v2 12/20] raw/ifpga: inherit lock annotations
> 
> Hi,
> 
> > -----Original Message-----
> > From: David Marchand <david.marchand@redhat.com>
> > Sent: Friday, February 24, 2023 11:12 PM
> > To: dev@dpdk.org
> > Cc: thomas@monjalon.net; Xu, Rosen <rosen.xu@intel.com>; Zhang,
> > Tianfei <tianfei.zhang@intel.com>
> > Subject: [PATCH v2 12/20] raw/ifpga: inherit lock annotations
> >
> > The checks in those helpers are useless:
> > - all (start/stop/reset/test) callers ensure that dev != NULL,
> > - dev->sd can't be NULL either as it would mean the application is calling
> >   those helpers for a dev pointer that did not pass initialisation,
> >
> > Once the checks are removed, the only thing that remains is calls to
> > the rte_spinlock API, so simply use macros and inherit annotations
> > from the lock API.
> >
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
> >  drivers/raw/ifpga/afu_pmd_core.c | 17 ++---------------
> >  1 file changed, 2 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/raw/ifpga/afu_pmd_core.c
> > b/drivers/raw/ifpga/afu_pmd_core.c
> > index ddf7a34f33..3ab1f47ac1 100644
> > --- a/drivers/raw/ifpga/afu_pmd_core.c
> > +++ b/drivers/raw/ifpga/afu_pmd_core.c
> > @@ -23,21 +23,8 @@ static struct rte_afu_uuid
> > afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1];
> >  TAILQ_HEAD(afu_drv_list, afu_rawdev_drv);  static struct afu_drv_list
> > afu_pmd_list = TAILQ_HEAD_INITIALIZER(afu_pmd_list);
> >
> > -static inline int afu_rawdev_trylock(struct afu_rawdev *dev) -{
> > -	if (!dev || !dev->sd)
> > -		return 0;
> > -
> > -	return rte_spinlock_trylock(&dev->sd->lock);
> > -}
> > -
> > -static inline void afu_rawdev_unlock(struct afu_rawdev *dev) -{
> > -	if (!dev || !dev->sd)
> > -		return;
> > -
> > -	rte_spinlock_unlock(&dev->sd->lock);
> > -}
> > +#define afu_rawdev_trylock(dev) rte_spinlock_trylock(&dev->sd->lock)
> > +#define afu_rawdev_unlock(dev) rte_spinlock_unlock(&dev->sd->lock)
> >
> >  static int afu_rawdev_configure(const struct rte_rawdev *rawdev,
> >  	rte_rawdev_obj_t config, size_t config_size)
> > --
> > 2.39.2
> 
> 
> It looks good for me.
> Reviewed-by: Rosen Xu <rosen.xu@intel.com>

Agree that pointer check is redundant, rte_spinlock API can be called directly.
Reviewed-by: Wei Huang <wei.huang@intel.com>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
  2023-02-27  2:05     ` Xia, Chenbo
@ 2023-02-27  8:24       ` David Marchand
  2023-02-27 16:28         ` Maxime Coquelin
  0 siblings, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-02-27  8:24 UTC (permalink / raw)
  To: Xia, Chenbo, Maxime Coquelin; +Cc: dev, thomas

Hello Chenbo,

Adding Maxime too.

On Mon, Feb 27, 2023 at 3:05 AM Xia, Chenbo <chenbo.xia@intel.com> wrote:
> > @@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev)
> >       }
> >
> >       /* If virtio port just stopped, no need to send RARP */
> > -     if (virtio_dev_pause(dev) < 0) {
> > +     if (virtio_dev_pause(dev) != 0) {
> >               rte_pktmbuf_free(rarp_mbuf);
> >               return;
> >       }
> > diff --git a/drivers/net/virtio/virtio_ethdev.h
> > b/drivers/net/virtio/virtio_ethdev.h
> > index c08f382791..ece0130603 100644
> > --- a/drivers/net/virtio/virtio_ethdev.h
> > +++ b/drivers/net/virtio/virtio_ethdev.h
> > @@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
> >
> >  void virtio_interrupt_handler(void *param);
> >
> > -int virtio_dev_pause(struct rte_eth_dev *dev);
> > -void virtio_dev_resume(struct rte_eth_dev *dev);
> > +#define VIRTIO_DEV_TO_HW(dev) ((struct virtio_hw *)(dev)->data-
> > >dev_private)
> > +int virtio_dev_pause(struct rte_eth_dev *dev)
> > +     __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)-
> > >state_lock);
>
> Just curious, why this is trylock instead of lock?

I wrote this patch some time ago.
At the time, I must say that I preferred removing those helpers (the
only caller is virtio_notify_peers()).
It seems those helpers were added as a kind of api for future
usecases, it seemed a reason for keeping them.
So I changed my mind and just annotated them.


For your question, annotating with "lock" would tell clang that the
function always takes the lock, regardless of the function return
value.

One alternative to this patch could be to always take the lock
(+annotate dev_pause as "lock"), and have the caller release the lock
if != 0 return value.
But it seems counterintuitive to me.

WDYT?


-- 
David Marchand


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-02-25 10:16     ` David Marchand
@ 2023-02-27 16:12       ` Gaëtan Rivet
  2023-03-02  8:52         ` David Marchand
  0 siblings, 1 reply; 76+ messages in thread
From: Gaëtan Rivet @ 2023-02-27 16:12 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Thomas Monjalon

On Sat, Feb 25, 2023, at 11:16, David Marchand wrote:
> Salut Gaëtan,
>
> On Fri, Feb 24, 2023 at 4:59 PM Gaëtan Rivet <grive@u256.net> wrote:
>> > FreeBSD libc pthread API has lock annotations while Linux glibc has
>> > none.
>> > We could simply disable the check on FreeBSD, but having this check,
>> > a few issues got raised in drivers that are built with FreeBSD.
>> > For now, I went with a simple #ifdef FreeBSD for pthread mutex related
>> > annotations in our code.
>> >
>>
>> Hi David,
>>
>> This is a great change, thanks for doing it.
>> However I am not sure I understand the logic regarding the '#ifdef FREEBSD'.
>>
>> These annotations provide static hints to clang's thread safety analysis.
>> What is the dependency on FreeBSD glibc?
>
> FreeBSD libc added clang annotations, while glibc did not.
>
> FreeBSD 13.1 libc:
> int             pthread_mutex_lock(pthread_mutex_t * __mutex)
>                     __locks_exclusive(*__mutex);
>
> With:
>
> #if __has_extension(c_thread_safety_attributes)
> #define __lock_annotate(x)      __attribute__((x))
> #else
> #define __lock_annotate(x)
> #endif
>
> /* Function acquires an exclusive or shared lock. */
> #define __locks_exclusive(...) \
>         __lock_annotate(exclusive_lock_function(__VA_ARGS__))
>
>
> glibc:
> extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
>      __THROWNL __nonnull ((1));
>
>
>
> Since glibc does not declare that pthread_mutex_t is lockable, adding
> an annotation triggers an error for Linux (taking eal_common_proc.c
> patch 14 as an example):
>
> ../lib/eal/common/eal_common_proc.c:911:2: error:
> 'exclusive_locks_required' attribute requires arguments whose type is
> annotated with 'capability' attribute; type here is 'pthread_mutex_t'
> [-Werror,-Wthread-safety-attributes]
>         __rte_exclusive_locks_required(pending_requests.lock)
>         ^
> ../lib/eal/include/rte_lock_annotations.h:23:17: note: expanded from
> macro '__rte_exclusive_locks_required'
>         __attribute__((exclusive_locks_required(__VA_ARGS__)))
>                        ^
>
> We could wrap this annotation in a new construct (which would require
> some build time check wrt pthread API state).
> Not sure it is worth the effort though, for now.
>
>
> -- 
> David Marchand

Ah ok, so if I understand correctly, DPDK would need to declare some
'__rte_lockable rte_mutex' and associated functions for transparent support,
to wrap above the pthread API.

Unless it happens, would it be possible to condition the thread-safety annotations
to FREEBSD as well?

Maybe have two versions of the annotations:

  __rte_exclusive_locks_required() /* Conditioned on clang */
  __pthread_exclusive_locks_required() /* Conditioned on glibc/pthread support */

the first one to use on RTE types that can be declared with __rte_lockable,
the second for pthread objects that we don't want to replace.
I know the namespace is not great so maybe named another way.

The '#ifdef FREEBSD' ossifies the annotation support at the function level,
when this is a matter of types. This impedance mismatch would mean large
changes if someone was to make this support evolve at some point.

-- 
Gaetan Rivet

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
  2023-02-27  8:24       ` David Marchand
@ 2023-02-27 16:28         ` Maxime Coquelin
  2023-02-28  2:45           ` Xia, Chenbo
  2023-03-02  9:26           ` David Marchand
  0 siblings, 2 replies; 76+ messages in thread
From: Maxime Coquelin @ 2023-02-27 16:28 UTC (permalink / raw)
  To: David Marchand, Xia, Chenbo; +Cc: dev, thomas

Hi,

On 2/27/23 09:24, David Marchand wrote:
> Hello Chenbo,
> 
> Adding Maxime too.
> 
> On Mon, Feb 27, 2023 at 3:05 AM Xia, Chenbo <chenbo.xia@intel.com> wrote:
>>> @@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev)
>>>        }
>>>
>>>        /* If virtio port just stopped, no need to send RARP */
>>> -     if (virtio_dev_pause(dev) < 0) {
>>> +     if (virtio_dev_pause(dev) != 0) {
>>>                rte_pktmbuf_free(rarp_mbuf);
>>>                return;
>>>        }
>>> diff --git a/drivers/net/virtio/virtio_ethdev.h
>>> b/drivers/net/virtio/virtio_ethdev.h
>>> index c08f382791..ece0130603 100644
>>> --- a/drivers/net/virtio/virtio_ethdev.h
>>> +++ b/drivers/net/virtio/virtio_ethdev.h
>>> @@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
>>>
>>>   void virtio_interrupt_handler(void *param);
>>>
>>> -int virtio_dev_pause(struct rte_eth_dev *dev);
>>> -void virtio_dev_resume(struct rte_eth_dev *dev);
>>> +#define VIRTIO_DEV_TO_HW(dev) ((struct virtio_hw *)(dev)->data-
>>>> dev_private)
>>> +int virtio_dev_pause(struct rte_eth_dev *dev)
>>> +     __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)-
>>>> state_lock);
>>
>> Just curious, why this is trylock instead of lock?
> 
> I wrote this patch some time ago.
> At the time, I must say that I preferred removing those helpers (the
> only caller is virtio_notify_peers()).
> It seems those helpers were added as a kind of api for future
> usecases, it seemed a reason for keeping them.
> So I changed my mind and just annotated them.
> 
> 
> For your question, annotating with "lock" would tell clang that the
> function always takes the lock, regardless of the function return
> value.
> 
> One alternative to this patch could be to always take the lock
> (+annotate dev_pause as "lock"), and have the caller release the lock
> if != 0 return value.
> But it seems counterintuitive to me.
> 
> WDYT?
> 
> 

As discussed with David off-list, I think we could simplify and inline 
virtio_dev_pause()/virtio_dev_resume() into virtio_notify_peers() since 
there are no other users of these functions (see below).

Any objection?

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index 0103d95920..dbd84e25ea 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1144,43 +1144,10 @@ virtio_ethdev_negotiate_features(struct 
virtio_hw *hw, uint64_t req_features)
         return 0;
  }

-int
-virtio_dev_pause(struct rte_eth_dev *dev)
-{
-       struct virtio_hw *hw = dev->data->dev_private;
-
-       rte_spinlock_lock(&hw->state_lock);
-
-       if (hw->started == 0) {
-               /* Device is just stopped. */
-               rte_spinlock_unlock(&hw->state_lock);
-               return -1;
-       }
-       hw->started = 0;
-       /*
-        * Prevent the worker threads from touching queues to avoid 
contention,
-        * 1 ms should be enough for the ongoing Tx function to finish.
-        */
-       rte_delay_ms(1);
-       return 0;
-}
-
-/*
- * Recover hw state to let the worker threads continue.
- */
-void
-virtio_dev_resume(struct rte_eth_dev *dev)
-{
-       struct virtio_hw *hw = dev->data->dev_private;
-
-       hw->started = 1;
-       rte_spinlock_unlock(&hw->state_lock);
-}
-
  /*
   * Should be called only after device is paused.
   */
-int
+static int
  virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
                 int nb_pkts)
  {
@@ -1216,14 +1183,25 @@ virtio_notify_peers(struct rte_eth_dev *dev)
                 return;
         }

-       /* If virtio port just stopped, no need to send RARP */
-       if (virtio_dev_pause(dev) < 0) {
+       rte_spinlock_lock(&hw->state_lock);
+
+       if (hw->started == 0) {
+               /* If virtio port just stopped, no need to send RARP */
                 rte_pktmbuf_free(rarp_mbuf);
-               return;
+               goto out_unlock;
         }

+       /*
+        * Prevent the worker threads from touching queues to avoid 
contention,
+        * 1 ms should be enough for the ongoing Tx function to finish.
+        */
+       rte_delay_ms(1);
+
         virtio_inject_pkts(dev, &rarp_mbuf, 1);
-       virtio_dev_resume(dev);
+       hw->started = 1;
+
+out_unlock:
+       rte_spinlock_unlock(&hw->state_lock);
  }

  static void
diff --git a/drivers/net/virtio/virtio_ethdev.h 
b/drivers/net/virtio/virtio_ethdev.h
index c08f382791..7be1c9acd0 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -112,12 +112,8 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);

  void virtio_interrupt_handler(void *param);

-int virtio_dev_pause(struct rte_eth_dev *dev);
-void virtio_dev_resume(struct rte_eth_dev *dev);
  int virtio_dev_stop(struct rte_eth_dev *dev);
  int virtio_dev_close(struct rte_eth_dev *dev);
-int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
-               int nb_pkts);

  bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t 
rx_buf_size,
                         bool rx_scatter_enabled, const char **error);


^ permalink raw reply	[flat|nested] 76+ messages in thread

* RE: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
  2023-02-27 16:28         ` Maxime Coquelin
@ 2023-02-28  2:45           ` Xia, Chenbo
  2023-03-02  9:26           ` David Marchand
  1 sibling, 0 replies; 76+ messages in thread
From: Xia, Chenbo @ 2023-02-28  2:45 UTC (permalink / raw)
  To: Maxime Coquelin, David Marchand; +Cc: dev, thomas

Hi David & Maxime,

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Tuesday, February 28, 2023 12:28 AM
> To: David Marchand <david.marchand@redhat.com>; Xia, Chenbo
> <chenbo.xia@intel.com>
> Cc: dev@dpdk.org; thomas@monjalon.net
> Subject: Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
> 
> Hi,
> 
> On 2/27/23 09:24, David Marchand wrote:
> > Hello Chenbo,
> >
> > Adding Maxime too.
> >
> > On Mon, Feb 27, 2023 at 3:05 AM Xia, Chenbo <chenbo.xia@intel.com> wrote:
> >>> @@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev)
> >>>        }
> >>>
> >>>        /* If virtio port just stopped, no need to send RARP */
> >>> -     if (virtio_dev_pause(dev) < 0) {
> >>> +     if (virtio_dev_pause(dev) != 0) {
> >>>                rte_pktmbuf_free(rarp_mbuf);
> >>>                return;
> >>>        }
> >>> diff --git a/drivers/net/virtio/virtio_ethdev.h
> >>> b/drivers/net/virtio/virtio_ethdev.h
> >>> index c08f382791..ece0130603 100644
> >>> --- a/drivers/net/virtio/virtio_ethdev.h
> >>> +++ b/drivers/net/virtio/virtio_ethdev.h
> >>> @@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev
> *eth_dev);
> >>>
> >>>   void virtio_interrupt_handler(void *param);
> >>>
> >>> -int virtio_dev_pause(struct rte_eth_dev *dev);
> >>> -void virtio_dev_resume(struct rte_eth_dev *dev);
> >>> +#define VIRTIO_DEV_TO_HW(dev) ((struct virtio_hw *)(dev)->data-
> >>>> dev_private)
> >>> +int virtio_dev_pause(struct rte_eth_dev *dev)
> >>> +     __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)-
> >>>> state_lock);
> >>
> >> Just curious, why this is trylock instead of lock?
> >
> > I wrote this patch some time ago.
> > At the time, I must say that I preferred removing those helpers (the
> > only caller is virtio_notify_peers()).
> > It seems those helpers were added as a kind of api for future
> > usecases, it seemed a reason for keeping them.
> > So I changed my mind and just annotated them.
> >
> >
> > For your question, annotating with "lock" would tell clang that the
> > function always takes the lock, regardless of the function return
> > value.
> >
> > One alternative to this patch could be to always take the lock
> > (+annotate dev_pause as "lock"), and have the caller release the lock
> > if != 0 return value.
> > But it seems counterintuitive to me.
> >
> > WDYT?
> >
> >
> 
> As discussed with David off-list, I think we could simplify and inline
> virtio_dev_pause()/virtio_dev_resume() into virtio_notify_peers() since
> there are no other users of these functions (see below).
> 
> Any objection?

This LGTM, it makes things easier..

Thanks,
Chenbo

> 
> diff --git a/drivers/net/virtio/virtio_ethdev.c
> b/drivers/net/virtio/virtio_ethdev.c
> index 0103d95920..dbd84e25ea 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -1144,43 +1144,10 @@ virtio_ethdev_negotiate_features(struct
> virtio_hw *hw, uint64_t req_features)
>          return 0;
>   }
> 
> -int
> -virtio_dev_pause(struct rte_eth_dev *dev)
> -{
> -       struct virtio_hw *hw = dev->data->dev_private;
> -
> -       rte_spinlock_lock(&hw->state_lock);
> -
> -       if (hw->started == 0) {
> -               /* Device is just stopped. */
> -               rte_spinlock_unlock(&hw->state_lock);
> -               return -1;
> -       }
> -       hw->started = 0;
> -       /*
> -        * Prevent the worker threads from touching queues to avoid
> contention,
> -        * 1 ms should be enough for the ongoing Tx function to finish.
> -        */
> -       rte_delay_ms(1);
> -       return 0;
> -}
> -
> -/*
> - * Recover hw state to let the worker threads continue.
> - */
> -void
> -virtio_dev_resume(struct rte_eth_dev *dev)
> -{
> -       struct virtio_hw *hw = dev->data->dev_private;
> -
> -       hw->started = 1;
> -       rte_spinlock_unlock(&hw->state_lock);
> -}
> -
>   /*
>    * Should be called only after device is paused.
>    */
> -int
> +static int
>   virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
>                  int nb_pkts)
>   {
> @@ -1216,14 +1183,25 @@ virtio_notify_peers(struct rte_eth_dev *dev)
>                  return;
>          }
> 
> -       /* If virtio port just stopped, no need to send RARP */
> -       if (virtio_dev_pause(dev) < 0) {
> +       rte_spinlock_lock(&hw->state_lock);
> +
> +       if (hw->started == 0) {
> +               /* If virtio port just stopped, no need to send RARP */
>                  rte_pktmbuf_free(rarp_mbuf);
> -               return;
> +               goto out_unlock;
>          }
> 
> +       /*
> +        * Prevent the worker threads from touching queues to avoid
> contention,
> +        * 1 ms should be enough for the ongoing Tx function to finish.
> +        */
> +       rte_delay_ms(1);
> +
>          virtio_inject_pkts(dev, &rarp_mbuf, 1);
> -       virtio_dev_resume(dev);
> +       hw->started = 1;
> +
> +out_unlock:
> +       rte_spinlock_unlock(&hw->state_lock);
>   }
> 
>   static void
> diff --git a/drivers/net/virtio/virtio_ethdev.h
> b/drivers/net/virtio/virtio_ethdev.h
> index c08f382791..7be1c9acd0 100644
> --- a/drivers/net/virtio/virtio_ethdev.h
> +++ b/drivers/net/virtio/virtio_ethdev.h
> @@ -112,12 +112,8 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
> 
>   void virtio_interrupt_handler(void *param);
> 
> -int virtio_dev_pause(struct rte_eth_dev *dev);
> -void virtio_dev_resume(struct rte_eth_dev *dev);
>   int virtio_dev_stop(struct rte_eth_dev *dev);
>   int virtio_dev_close(struct rte_eth_dev *dev);
> -int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
> -               int nb_pkts);
> 
>   bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t
> rx_buf_size,
>                          bool rx_scatter_enabled, const char **error);


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-02-27 16:12       ` Gaëtan Rivet
@ 2023-03-02  8:52         ` David Marchand
  2023-04-03 10:52           ` David Marchand
  0 siblings, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-03-02  8:52 UTC (permalink / raw)
  To: Gaëtan Rivet; +Cc: dev, Thomas Monjalon, Tyler Retzlaff

On Mon, Feb 27, 2023 at 5:13 PM Gaëtan Rivet <grive@u256.net> wrote:
> Ah ok, so if I understand correctly, DPDK would need to declare some
> '__rte_lockable rte_mutex' and associated functions for transparent support,
> to wrap above the pthread API.

Yes, this is what I had in mind for the mid/long term but it was too
late for 23.03 after -rc1.

The Windows porting effort will probably need this abstraction too as
we are trying to stop relying on the pthread API.
I don't see this item in Microsoft roadmap, though.


>
> Unless it happens, would it be possible to condition the thread-safety annotations
> to FREEBSD as well?
>
> Maybe have two versions of the annotations:
>
>   __rte_exclusive_locks_required() /* Conditioned on clang */
>   __pthread_exclusive_locks_required() /* Conditioned on glibc/pthread support */
>
> the first one to use on RTE types that can be declared with __rte_lockable,
> the second for pthread objects that we don't want to replace.
> I know the namespace is not great so maybe named another way.
>
> The '#ifdef FREEBSD' ossifies the annotation support at the function level,
> when this is a matter of types. This impedance mismatch would mean large
> changes if someone was to make this support evolve at some point.

I don't see how it requires large changes with the current approach.
The patches in this series are a matter of lines.
If we come up with the right abstraction later, this uglyness will be removed.

In any case, I am running short of time for 23.03.
I am missing reviews from driver maintainers, which is a pity.
Thomas raised an eyebrow on the malloc: and mem: patches too.

I will probably defer this series to the next release.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
  2023-02-27 16:28         ` Maxime Coquelin
  2023-02-28  2:45           ` Xia, Chenbo
@ 2023-03-02  9:26           ` David Marchand
  2023-03-02  9:28             ` Maxime Coquelin
  1 sibling, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-03-02  9:26 UTC (permalink / raw)
  To: Maxime Coquelin, Xia, Chenbo; +Cc: dev, thomas

On Mon, Feb 27, 2023 at 5:28 PM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
> As discussed with David off-list, I think we could simplify and inline
> virtio_dev_pause()/virtio_dev_resume() into virtio_notify_peers() since
> there are no other users of these functions (see below).

I was looking at doing this and, as we discussed offlist, realised
what the "inject" code was doing.

I don't like the idea of keeping virtio_inject_pkts as a helper.
This is tightly linked to the hw->started + usleep() trick, and this
code has no check about its requirement on hw->started == 0.
I'd rather "inline" and remove this helper too.

As a second step, I wrote a fix using an additional lock per txq to
remove this usleep() thing.
Though I think it is too late to consider merging this new change in
the release.
WDYT?


-- 
David Marchand


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
  2023-03-02  9:26           ` David Marchand
@ 2023-03-02  9:28             ` Maxime Coquelin
  2023-03-02 12:35               ` David Marchand
  0 siblings, 1 reply; 76+ messages in thread
From: Maxime Coquelin @ 2023-03-02  9:28 UTC (permalink / raw)
  To: David Marchand, Xia, Chenbo; +Cc: dev, thomas



On 3/2/23 10:26, David Marchand wrote:
> On Mon, Feb 27, 2023 at 5:28 PM Maxime Coquelin
> <maxime.coquelin@redhat.com> wrote:
>> As discussed with David off-list, I think we could simplify and inline
>> virtio_dev_pause()/virtio_dev_resume() into virtio_notify_peers() since
>> there are no other users of these functions (see below).
> 
> I was looking at doing this and, as we discussed offlist, realised
> what the "inject" code was doing.
> 
> I don't like the idea of keeping virtio_inject_pkts as a helper.
> This is tightly linked to the hw->started + usleep() trick, and this
> code has no check about its requirement on hw->started == 0.
> I'd rather "inline" and remove this helper too.

Makes sense, do you want to submit it or are you willing me to do it?

> As a second step, I wrote a fix using an additional lock per txq to
> remove this usleep() thing.
> Though I think it is too late to consider merging this new change in
> the release.
> WDYT?

I agree this is too late for this release. Let's try this for v23.07.

Thanks,
Maxime


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
  2023-03-02  9:28             ` Maxime Coquelin
@ 2023-03-02 12:35               ` David Marchand
  0 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-03-02 12:35 UTC (permalink / raw)
  To: Maxime Coquelin; +Cc: Xia, Chenbo, dev, thomas

On Thu, Mar 2, 2023 at 10:28 AM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
> On 3/2/23 10:26, David Marchand wrote:
> > On Mon, Feb 27, 2023 at 5:28 PM Maxime Coquelin
> > <maxime.coquelin@redhat.com> wrote:
> >> As discussed with David off-list, I think we could simplify and inline
> >> virtio_dev_pause()/virtio_dev_resume() into virtio_notify_peers() since
> >> there are no other users of these functions (see below).
> >
> > I was looking at doing this and, as we discussed offlist, realised
> > what the "inject" code was doing.
> >
> > I don't like the idea of keeping virtio_inject_pkts as a helper.
> > This is tightly linked to the hw->started + usleep() trick, and this
> > code has no check about its requirement on hw->started == 0.
> > I'd rather "inline" and remove this helper too.
>
> Makes sense, do you want to submit it or are you willing me to do it?

I'll handle it, either during this release, or the next one.
This code has always been ugly, this can wait one more release.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-03-02  8:52         ` David Marchand
@ 2023-04-03 10:52           ` David Marchand
  2023-04-03 15:03             ` Tyler Retzlaff
  2023-04-03 15:36             ` Tyler Retzlaff
  0 siblings, 2 replies; 76+ messages in thread
From: David Marchand @ 2023-04-03 10:52 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, Thomas Monjalon, Gaëtan Rivet

Hello Tyler,

On Thu, Mar 2, 2023 at 9:52 AM David Marchand <david.marchand@redhat.com> wrote:
> On Mon, Feb 27, 2023 at 5:13 PM Gaëtan Rivet <grive@u256.net> wrote:
> > Ah ok, so if I understand correctly, DPDK would need to declare some
> > '__rte_lockable rte_mutex' and associated functions for transparent support,
> > to wrap above the pthread API.
>
> Yes, this is what I had in mind for the mid/long term but it was too
> late for 23.03 after -rc1.
>
> The Windows porting effort will probably need this abstraction too as
> we are trying to stop relying on the pthread API.
> I don't see this item in Microsoft roadmap, though.

Do you have an opinion on this topic?

Thanks.

-- 
David Marchand


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-04-03 10:52           ` David Marchand
@ 2023-04-03 15:03             ` Tyler Retzlaff
  2023-04-03 15:36             ` Tyler Retzlaff
  1 sibling, 0 replies; 76+ messages in thread
From: Tyler Retzlaff @ 2023-04-03 15:03 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Thomas Monjalon, Gaëtan Rivet

On Mon, Apr 03, 2023 at 12:52:06PM +0200, David Marchand wrote:
> Hello Tyler,
> 
> On Thu, Mar 2, 2023 at 9:52 AM David Marchand <david.marchand@redhat.com> wrote:
> > On Mon, Feb 27, 2023 at 5:13 PM Gaëtan Rivet <grive@u256.net> wrote:
> > > Ah ok, so if I understand correctly, DPDK would need to declare some
> > > '__rte_lockable rte_mutex' and associated functions for transparent support,
> > > to wrap above the pthread API.
> >
> > Yes, this is what I had in mind for the mid/long term but it was too
> > late for 23.03 after -rc1.
> >
> > The Windows porting effort will probably need this abstraction too as
> > we are trying to stop relying on the pthread API.
> > I don't see this item in Microsoft roadmap, though.
> 
> Do you have an opinion on this topic?

Sorry David I got distracted I'll review the thread again.  I think with
Windows toolsets we left off with expanding empty for now?

Anyway, I'll take another pass today if I get a chance.

> 
> Thanks.
> 
> -- 
> David Marchand

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-04-03 10:52           ` David Marchand
  2023-04-03 15:03             ` Tyler Retzlaff
@ 2023-04-03 15:36             ` Tyler Retzlaff
  2023-04-04  7:45               ` David Marchand
  1 sibling, 1 reply; 76+ messages in thread
From: Tyler Retzlaff @ 2023-04-03 15:36 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Thomas Monjalon, Gaëtan Rivet

On Mon, Apr 03, 2023 at 12:52:06PM +0200, David Marchand wrote:
> Hello Tyler,
> 
> On Thu, Mar 2, 2023 at 9:52 AM David Marchand <david.marchand@redhat.com> wrote:
> > On Mon, Feb 27, 2023 at 5:13 PM Gaëtan Rivet <grive@u256.net> wrote:
> > > Ah ok, so if I understand correctly, DPDK would need to declare some
> > > '__rte_lockable rte_mutex' and associated functions for transparent support,
> > > to wrap above the pthread API.
> >
> > Yes, this is what I had in mind for the mid/long term but it was too
> > late for 23.03 after -rc1.
> >
> > The Windows porting effort will probably need this abstraction too as
> > we are trying to stop relying on the pthread API.
> > I don't see this item in Microsoft roadmap, though.
> 
> Do you have an opinion on this topic?

Okay, trying to grok the question here. If the question is do we want to
introduce a mutex/condition variable and lock/unlock signal/wait
abstraction?

I would certainly like to see reduced conditional compilation that
applications have to perform for the platform features. I also really
would like to purge the remaining pthread_{mutex,condvar} shim since it
is unsightly.

With msvc I think we could probably achieve the same with C11 threads but
I haven't investigated feasability and said with no investigation older
glibc may not provide the optional feature.

In the absence of C11 threads we can provide an rte_ abstraction but I
don't think I can put it on the roadmap until basic msvc support is
stood up (a question of resource prioritization as always).

I could commit to looking at it once msvc and atomics changes are merged
the earliest possible time frame for that is the start of the 23.11
cycle. If that happens at decent velocity I could even see adding it to
23.11 roadmap.

For now if someone else decides to introduce an abstraction I would just
caution strongly not to remove __rte_experimental from any API added
until I get a chance to focus on it.

ty

> 
> Thanks.
> 
> -- 
> David Marchand

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers
  2023-04-03 15:36             ` Tyler Retzlaff
@ 2023-04-04  7:45               ` David Marchand
  0 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04  7:45 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, Thomas Monjalon, Gaëtan Rivet

On Mon, Apr 3, 2023 at 5:37 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> On Mon, Apr 03, 2023 at 12:52:06PM +0200, David Marchand wrote:
> > Hello Tyler,
> >
> > On Thu, Mar 2, 2023 at 9:52 AM David Marchand <david.marchand@redhat.com> wrote:
> > > On Mon, Feb 27, 2023 at 5:13 PM Gaëtan Rivet <grive@u256.net> wrote:
> > > > Ah ok, so if I understand correctly, DPDK would need to declare some
> > > > '__rte_lockable rte_mutex' and associated functions for transparent support,
> > > > to wrap above the pthread API.
> > >
> > > Yes, this is what I had in mind for the mid/long term but it was too
> > > late for 23.03 after -rc1.
> > >
> > > The Windows porting effort will probably need this abstraction too as
> > > we are trying to stop relying on the pthread API.
> > > I don't see this item in Microsoft roadmap, though.
> >
> > Do you have an opinion on this topic?
>
> Okay, trying to grok the question here. If the question is do we want to
> introduce a mutex/condition variable and lock/unlock signal/wait
> abstraction?
>
> I would certainly like to see reduced conditional compilation that
> applications have to perform for the platform features. I also really
> would like to purge the remaining pthread_{mutex,condvar} shim since it
> is unsightly.
>
> With msvc I think we could probably achieve the same with C11 threads but
> I haven't investigated feasability and said with no investigation older
> glibc may not provide the optional feature.
>
> In the absence of C11 threads we can provide an rte_ abstraction but I
> don't think I can put it on the roadmap until basic msvc support is
> stood up (a question of resource prioritization as always).
>
> I could commit to looking at it once msvc and atomics changes are merged
> the earliest possible time frame for that is the start of the 23.11
> cycle. If that happens at decent velocity I could even see adding it to
> 23.11 roadmap.

Ok for me.


>
> For now if someone else decides to introduce an abstraction I would just
> caution strongly not to remove __rte_experimental from any API added
> until I get a chance to focus on it.

We *could* introduce an internal API.
But I prefer we wait for your input on this topic rather than
introduce some artificial API.

I'll simply disable those checks on FreeBSD.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 00/16] Enable lock annotations on most libraries and drivers
  2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
                   ` (14 preceding siblings ...)
  2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
@ 2023-04-04 12:48 ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 01/16] malloc: rework heap destroy David Marchand
                     ` (16 more replies)
  15 siblings, 17 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas

This is a followup of the series that introduced lock annotations.
I reworked and made annotations work in what seemed the easier cases.
In most cases, I chose to convert inline wrappers around the EAL lock
API to simple macro: I did not see much value in those wrappers and this
is way simpler than adding __rte_*lock_function tags everywhere.

A list of libraries and drivers still need more work as their code have
non obvious locks handling. For those components, the check is opted
out.
I leave it to their respective maintainers to enable the checks later.

FreeBSD libc pthread API has lock annotations while Linux glibc has
none. Until we get a proper abstraction for mutexes, the simpler is
to disable the check on FreeBSD.

Maintainers, please review.


-- 
David Marchand

Changes since v2:
- simplify malloc heap change,
- rework virtio code,
- disable check on FreeBSD when using pthread mutexes,

Changes since v1:
- annotate code relying on pthread mutexes for FreeBSD libc that
  put annotations on its pthread API,
- annotate Windows alarm code,

David Marchand (16):
  malloc: rework heap destroy
  mem: rework malloc heap init
  mem: annotate shared memory config locks
  hash: annotate cuckoo hash lock
  graph: annotate graph lock
  drivers: inherit lock annotations for Intel drivers
  net/cxgbe: inherit lock annotations
  net/fm10k: annotate mailbox lock
  net/sfc: rework locking in proxy code
  net/sfc: inherit lock annotations
  net/virtio: rework guest announce notify helper
  raw/ifpga: inherit lock annotations
  vdpa/sfc: inherit lock annotations
  net/failsafe: fix mutex locking
  eal/windows: disable lock check on alarm code
  enable lock check

 .../prog_guide/env_abstraction_layer.rst      |   5 +-
 drivers/bus/dpaa/meson.build                  |   1 +
 drivers/common/cnxk/meson.build               |   1 +
 drivers/common/iavf/iavf_osdep.h              |  39 +----
 drivers/common/iavf/iavf_prototype.h          |   6 -
 drivers/common/idpf/base/idpf_osdep.h         |  26 +---
 drivers/common/mlx5/meson.build               |   1 +
 drivers/event/cnxk/meson.build                |   1 +
 drivers/meson.build                           |   2 +-
 drivers/net/bnx2x/meson.build                 |   1 +
 drivers/net/bnxt/meson.build                  |   1 +
 drivers/net/cnxk/meson.build                  |   1 +
 drivers/net/cxgbe/base/adapter.h              |  35 +----
 drivers/net/enic/meson.build                  |   1 +
 drivers/net/failsafe/failsafe_ether.c         |   3 +-
 drivers/net/failsafe/failsafe_flow.c          |  23 ++-
 drivers/net/failsafe/failsafe_ops.c           | 142 +++++++++++++-----
 drivers/net/failsafe/meson.build              |   4 +
 drivers/net/fm10k/fm10k_ethdev.c              |   2 +
 drivers/net/hinic/meson.build                 |   4 +
 drivers/net/hns3/meson.build                  |   1 +
 drivers/net/i40e/base/i40e_osdep.h            |   8 +-
 drivers/net/i40e/base/i40e_prototype.h        |   5 -
 drivers/net/i40e/i40e_ethdev.c                |  24 ---
 drivers/net/ice/base/ice_osdep.h              |  26 +---
 drivers/net/mlx5/meson.build                  |   1 +
 drivers/net/sfc/sfc.h                         |  41 +----
 drivers/net/sfc/sfc_ev.c                      |   6 +-
 drivers/net/sfc/sfc_repr.c                    |  38 +----
 drivers/net/sfc/sfc_repr_proxy.c              |  59 ++++----
 drivers/net/virtio/virtio_ethdev.c            |  75 +++------
 drivers/net/virtio/virtio_ethdev.h            |   4 -
 drivers/raw/ifpga/afu_pmd_core.c              |  17 +--
 drivers/vdpa/sfc/sfc_vdpa.h                   |  41 +----
 drivers/vdpa/sfc/sfc_vdpa_ops.c               |  14 +-
 lib/eal/common/eal_common_mcfg.c              |  66 ++++----
 lib/eal/common/eal_common_memory.c            |  10 +-
 lib/eal/common/malloc_heap.c                  |  16 +-
 lib/eal/common/malloc_heap.h                  |   3 +
 lib/eal/common/rte_malloc.c                   |   5 +-
 lib/eal/freebsd/eal.c                         |  13 ++
 lib/eal/include/rte_eal_memconfig.h           |  63 ++++++--
 lib/eal/linux/eal.c                           |  13 ++
 lib/eal/meson.build                           |   4 +
 lib/eal/version.map                           |   4 +
 lib/eal/windows/eal.c                         |  13 ++
 lib/eal/windows/eal_alarm.c                   |   2 +
 lib/ethdev/meson.build                        |   4 +
 lib/graph/graph.c                             |  10 +-
 lib/graph/graph_private.h                     |  10 +-
 lib/hash/rte_cuckoo_hash.c                    |   8 +
 lib/ipsec/meson.build                         |   1 +
 lib/meson.build                               |   2 +-
 lib/timer/meson.build                         |   1 +
 lib/vhost/meson.build                         |   1 -
 55 files changed, 435 insertions(+), 473 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 01/16] malloc: rework heap destroy
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 02/16] mem: rework malloc heap init David Marchand
                     ` (15 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Anatoly Burakov

The destroy helper has been reworked to zero all the heap object but
leave the lock untouched. The heap lock is then released through the
standard API.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v2:
- shrinked the change to the required part,

---
 lib/eal/common/malloc_heap.c | 6 ++++--
 lib/eal/common/rte_malloc.c  | 5 +----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index d7c410b786..d3c474d79c 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -1385,8 +1385,10 @@ malloc_heap_destroy(struct malloc_heap *heap)
 	if (heap->total_size != 0)
 		RTE_LOG(ERR, EAL, "Total size not zero, heap is likely corrupt\n");
 
-	/* after this, the lock will be dropped */
-	memset(heap, 0, sizeof(*heap));
+	/* Reset all of the heap but the (hold) lock so caller can release it. */
+	RTE_BUILD_BUG_ON(offsetof(struct malloc_heap, lock) != 0);
+	memset(RTE_PTR_ADD(heap, sizeof(heap->lock)), 0,
+		sizeof(*heap) - sizeof(heap->lock));
 
 	return 0;
 }
diff --git a/lib/eal/common/rte_malloc.c b/lib/eal/common/rte_malloc.c
index d39870bf3c..ebafef3f6c 100644
--- a/lib/eal/common/rte_malloc.c
+++ b/lib/eal/common/rte_malloc.c
@@ -657,10 +657,7 @@ rte_malloc_heap_destroy(const char *heap_name)
 	/* sanity checks done, now we can destroy the heap */
 	rte_spinlock_lock(&heap->lock);
 	ret = malloc_heap_destroy(heap);
-
-	/* if we failed, lock is still active */
-	if (ret < 0)
-		rte_spinlock_unlock(&heap->lock);
+	rte_spinlock_unlock(&heap->lock);
 unlock:
 	rte_mcfg_mem_write_unlock();
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 02/16] mem: rework malloc heap init
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
  2023-04-04 12:48   ` [PATCH v3 01/16] malloc: rework heap destroy David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 03/16] mem: annotate shared memory config locks David Marchand
                     ` (14 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev
  Cc: thomas, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

rte_eal_memory_init() and rte_eal_malloc_heap_init() must be called in
a common section taking rte_mcfg_mem_read_lock().
Split rte_eal_malloc_heap_init() in two so that the mem lock is taken
in rte_eal_init() making lock checks trivial (once annotated in the next
patch).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_memory.c | 10 +---------
 lib/eal/common/malloc_heap.c       | 10 ++++++----
 lib/eal/common/malloc_heap.h       |  3 +++
 lib/eal/freebsd/eal.c              | 13 +++++++++++++
 lib/eal/linux/eal.c                | 13 +++++++++++++
 lib/eal/windows/eal.c              | 13 +++++++++++++
 6 files changed, 49 insertions(+), 13 deletions(-)

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index c2a4c8f9e7..e21fc7cfae 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1078,18 +1078,11 @@ rte_eal_memory_detach(void)
 int
 rte_eal_memory_init(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
-
 	int retval;
-	RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
-
-	if (!mcfg)
-		return -1;
 
-	/* lock mem hotplug here, to prevent races while we init */
-	rte_mcfg_mem_read_lock();
+	RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
 
 	if (rte_eal_memseg_init() < 0)
 		goto fail;
@@ -1108,7 +1101,6 @@ rte_eal_memory_init(void)
 
 	return 0;
 fail:
-	rte_mcfg_mem_read_unlock();
 	return -1;
 }
 
diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index d3c474d79c..d25bdc98f9 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -1421,18 +1421,20 @@ rte_eal_malloc_heap_init(void)
 		}
 	}
 
-
 	if (register_mp_requests()) {
 		RTE_LOG(ERR, EAL, "Couldn't register malloc multiprocess actions\n");
-		rte_mcfg_mem_read_unlock();
 		return -1;
 	}
 
-	/* unlock mem hotplug here. it's safe for primary as no requests can
+	return 0;
+}
+
+int rte_eal_malloc_heap_populate(void)
+{
+	/* mem hotplug is unlocked here. it's safe for primary as no requests can
 	 * even come before primary itself is fully initialized, and secondaries
 	 * do not need to initialize the heap.
 	 */
-	rte_mcfg_mem_read_unlock();
 
 	/* secondary process does not need to initialize anything */
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
diff --git a/lib/eal/common/malloc_heap.h b/lib/eal/common/malloc_heap.h
index 3b2fbc0aa0..8f3ab57154 100644
--- a/lib/eal/common/malloc_heap.h
+++ b/lib/eal/common/malloc_heap.h
@@ -85,6 +85,9 @@ malloc_socket_to_heap_id(unsigned int socket_id);
 int
 rte_eal_malloc_heap_init(void);
 
+int
+rte_eal_malloc_heap_populate(void);
+
 void
 rte_eal_malloc_heap_cleanup(void);
 
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 7db4239c51..7daf22e314 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -26,6 +26,7 @@
 #include <rte_memory.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <rte_errno.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
@@ -754,13 +755,25 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
 	}
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index c37868b7f0..ae323cd492 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -30,6 +30,7 @@
 #include <rte_memory.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <rte_service_component.h>
@@ -1193,7 +1194,10 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
@@ -1203,6 +1207,15 @@ rte_eal_init(int argc, char **argv)
 	eal_hugedirs_unlock();
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index e7d405b91c..033825c14c 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -12,6 +12,7 @@
 #include <rte_debug.h>
 #include <rte_bus.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
@@ -387,13 +388,25 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	rte_mcfg_mem_read_lock();
+
 	if (rte_eal_memory_init() < 0) {
+		rte_mcfg_mem_read_unlock();
 		rte_eal_init_alert("Cannot init memory");
 		rte_errno = ENOMEM;
 		return -1;
 	}
 
 	if (rte_eal_malloc_heap_init() < 0) {
+		rte_mcfg_mem_read_unlock();
+		rte_eal_init_alert("Cannot init malloc heap");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
+	rte_mcfg_mem_read_unlock();
+
+	if (rte_eal_malloc_heap_populate() < 0) {
 		rte_eal_init_alert("Cannot init malloc heap");
 		rte_errno = ENODEV;
 		return -1;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 03/16] mem: annotate shared memory config locks
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
  2023-04-04 12:48   ` [PATCH v3 01/16] malloc: rework heap destroy David Marchand
  2023-04-04 12:48   ` [PATCH v3 02/16] mem: rework malloc heap init David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 04/16] hash: annotate cuckoo hash lock David Marchand
                     ` (13 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas

Expose internal locks via some internal accessors.
Then annotate rte_mcfg_xxx_(read|write)_(|un)lock.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_mcfg.c    | 66 +++++++++++++++++------------
 lib/eal/include/rte_eal_memconfig.h | 63 +++++++++++++++++++++------
 lib/eal/version.map                 |  4 ++
 3 files changed, 91 insertions(+), 42 deletions(-)

diff --git a/lib/eal/common/eal_common_mcfg.c b/lib/eal/common/eal_common_mcfg.c
index cf4a279905..b60d41f7b6 100644
--- a/lib/eal/common/eal_common_mcfg.c
+++ b/lib/eal/common/eal_common_mcfg.c
@@ -69,102 +69,112 @@ eal_mcfg_update_from_internal(void)
 	mcfg->version = RTE_VERSION;
 }
 
+rte_rwlock_t *
+rte_mcfg_mem_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->memory_hotplug_lock;
+}
+
 void
 rte_mcfg_mem_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_read_lock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_read_unlock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_write_lock(rte_mcfg_mem_get_lock());
 }
 
 void
 rte_mcfg_mem_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
+	rte_rwlock_write_unlock(rte_mcfg_mem_get_lock());
+}
+
+rte_rwlock_t *
+rte_mcfg_tailq_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->qlock;
 }
 
 void
 rte_mcfg_tailq_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->qlock);
+	rte_rwlock_read_lock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->qlock);
+	rte_rwlock_read_unlock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->qlock);
+	rte_rwlock_write_lock(rte_mcfg_tailq_get_lock());
 }
 
 void
 rte_mcfg_tailq_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->qlock);
+	rte_rwlock_write_unlock(rte_mcfg_tailq_get_lock());
+}
+
+rte_rwlock_t *
+rte_mcfg_mempool_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->mplock;
 }
 
 void
 rte_mcfg_mempool_read_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_lock(&mcfg->mplock);
+	rte_rwlock_read_lock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_read_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_read_unlock(&mcfg->mplock);
+	rte_rwlock_read_unlock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_write_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_lock(&mcfg->mplock);
+	rte_rwlock_write_lock(rte_mcfg_mempool_get_lock());
 }
 
 void
 rte_mcfg_mempool_write_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_rwlock_write_unlock(&mcfg->mplock);
+	rte_rwlock_write_unlock(rte_mcfg_mempool_get_lock());
+}
+
+rte_spinlock_t *
+rte_mcfg_timer_get_lock(void)
+{
+	return &rte_eal_get_configuration()->mem_config->tlock;
 }
 
 void
 rte_mcfg_timer_lock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_spinlock_lock(&mcfg->tlock);
+	rte_spinlock_lock(rte_mcfg_timer_get_lock());
 }
 
 void
 rte_mcfg_timer_unlock(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	rte_spinlock_unlock(&mcfg->tlock);
+	rte_spinlock_unlock(rte_mcfg_timer_get_lock());
 }
 
 bool
diff --git a/lib/eal/include/rte_eal_memconfig.h b/lib/eal/include/rte_eal_memconfig.h
index e175564647..c527f9aa29 100644
--- a/lib/eal/include/rte_eal_memconfig.h
+++ b/lib/eal/include/rte_eal_memconfig.h
@@ -7,6 +7,8 @@
 
 #include <stdbool.h>
 
+#include <rte_rwlock.h>
+#include <rte_spinlock.h>
 
 /**
  * @file
@@ -18,89 +20,122 @@
 extern "C" {
 #endif
 
+/**
+ * Internal helpers used for lock annotations.
+ */
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_mem_get_lock(void);
+
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_tailq_get_lock(void);
+
+__rte_internal
+rte_rwlock_t *
+rte_mcfg_mempool_get_lock(void);
+
+__rte_internal
+rte_spinlock_t *
+rte_mcfg_timer_get_lock(void);
+
 /**
  * Lock the internal EAL shared memory configuration for shared access.
  */
 void
-rte_mcfg_mem_read_lock(void);
+rte_mcfg_mem_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Unlock the internal EAL shared memory configuration for shared access.
  */
 void
-rte_mcfg_mem_read_unlock(void);
+rte_mcfg_mem_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Lock the internal EAL shared memory configuration for exclusive access.
  */
 void
-rte_mcfg_mem_write_lock(void);
+rte_mcfg_mem_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Unlock the internal EAL shared memory configuration for exclusive access.
  */
 void
-rte_mcfg_mem_write_unlock(void);
+rte_mcfg_mem_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_mem_get_lock());
 
 /**
  * Lock the internal EAL TAILQ list for shared access.
  */
 void
-rte_mcfg_tailq_read_lock(void);
+rte_mcfg_tailq_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Unlock the internal EAL TAILQ list for shared access.
  */
 void
-rte_mcfg_tailq_read_unlock(void);
+rte_mcfg_tailq_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Lock the internal EAL TAILQ list for exclusive access.
  */
 void
-rte_mcfg_tailq_write_lock(void);
+rte_mcfg_tailq_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Unlock the internal EAL TAILQ list for exclusive access.
  */
 void
-rte_mcfg_tailq_write_unlock(void);
+rte_mcfg_tailq_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_tailq_get_lock());
 
 /**
  * Lock the internal EAL Mempool list for shared access.
  */
 void
-rte_mcfg_mempool_read_lock(void);
+rte_mcfg_mempool_read_lock(void)
+	__rte_shared_lock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Unlock the internal EAL Mempool list for shared access.
  */
 void
-rte_mcfg_mempool_read_unlock(void);
+rte_mcfg_mempool_read_unlock(void)
+	__rte_unlock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Lock the internal EAL Mempool list for exclusive access.
  */
 void
-rte_mcfg_mempool_write_lock(void);
+rte_mcfg_mempool_write_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Unlock the internal EAL Mempool list for exclusive access.
  */
 void
-rte_mcfg_mempool_write_unlock(void);
+rte_mcfg_mempool_write_unlock(void)
+	__rte_unlock_function(rte_mcfg_mempool_get_lock());
 
 /**
  * Lock the internal EAL Timer Library lock for exclusive access.
  */
 void
-rte_mcfg_timer_lock(void);
+rte_mcfg_timer_lock(void)
+	__rte_exclusive_lock_function(rte_mcfg_timer_get_lock());
 
 /**
  * Unlock the internal EAL Timer Library lock for exclusive access.
  */
 void
-rte_mcfg_timer_unlock(void);
+rte_mcfg_timer_unlock(void)
+	__rte_unlock_function(rte_mcfg_timer_get_lock());
 
 /**
  * If true, pages are put in single files (per memseg list),
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 6d6978f108..51a820d829 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -469,6 +469,10 @@ INTERNAL {
 	rte_intr_vec_list_free;
 	rte_intr_vec_list_index_get;
 	rte_intr_vec_list_index_set;
+	rte_mcfg_mem_get_lock;
+	rte_mcfg_mempool_get_lock;
+	rte_mcfg_tailq_get_lock;
+	rte_mcfg_timer_get_lock;
 	rte_mem_lock;
 	rte_mem_map;
 	rte_mem_page_size;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 04/16] hash: annotate cuckoo hash lock
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (2 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 03/16] mem: annotate shared memory config locks David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 05/16] graph: annotate graph lock David Marchand
                     ` (12 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev
  Cc: thomas, Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin

__hash_rw_(reader|writer)_(|un)lock helpers take locks depending on
conditions that are fixed at the rte_hash object initialisation.
So we can tell clang that those helpers unconditionally take/release
those locks (and waive the lock check on their implementation).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/hash/rte_cuckoo_hash.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
index 829b79c89a..d92a903bb3 100644
--- a/lib/hash/rte_cuckoo_hash.c
+++ b/lib/hash/rte_cuckoo_hash.c
@@ -575,6 +575,8 @@ rte_hash_count(const struct rte_hash *h)
 /* Read write locks implemented using rte_rwlock */
 static inline void
 __hash_rw_writer_lock(const struct rte_hash *h)
+	__rte_exclusive_lock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->writer_takes_lock && h->hw_trans_mem_support)
 		rte_rwlock_write_lock_tm(h->readwrite_lock);
@@ -584,6 +586,8 @@ __hash_rw_writer_lock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_reader_lock(const struct rte_hash *h)
+	__rte_shared_lock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->readwrite_concur_support && h->hw_trans_mem_support)
 		rte_rwlock_read_lock_tm(h->readwrite_lock);
@@ -593,6 +597,8 @@ __hash_rw_reader_lock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_writer_unlock(const struct rte_hash *h)
+	__rte_unlock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->writer_takes_lock && h->hw_trans_mem_support)
 		rte_rwlock_write_unlock_tm(h->readwrite_lock);
@@ -602,6 +608,8 @@ __hash_rw_writer_unlock(const struct rte_hash *h)
 
 static inline void
 __hash_rw_reader_unlock(const struct rte_hash *h)
+	__rte_unlock_function(&h->readwrite_lock)
+	__rte_no_thread_safety_analysis
 {
 	if (h->readwrite_concur_support && h->hw_trans_mem_support)
 		rte_rwlock_read_unlock_tm(h->readwrite_lock);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 05/16] graph: annotate graph lock
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (3 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 04/16] hash: annotate cuckoo hash lock David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 06/16] drivers: inherit lock annotations for Intel drivers David Marchand
                     ` (11 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Jerin Jacob, Kiran Kumar K, Nithin Dabilpuram

Export internal lock and annotate associated helper.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/graph/graph.c         | 10 ++++++++--
 lib/graph/graph_private.h | 10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/graph/graph.c b/lib/graph/graph.c
index a839a2803b..5582631b53 100644
--- a/lib/graph/graph.c
+++ b/lib/graph/graph.c
@@ -30,16 +30,22 @@ graph_list_head_get(void)
 	return &graph_list;
 }
 
+rte_spinlock_t *
+graph_spinlock_get(void)
+{
+	return &graph_lock;
+}
+
 void
 graph_spinlock_lock(void)
 {
-	rte_spinlock_lock(&graph_lock);
+	rte_spinlock_lock(graph_spinlock_get());
 }
 
 void
 graph_spinlock_unlock(void)
 {
-	rte_spinlock_unlock(&graph_lock);
+	rte_spinlock_unlock(graph_spinlock_get());
 }
 
 static int
diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h
index 7d1b30b8ac..eacdef45f0 100644
--- a/lib/graph/graph_private.h
+++ b/lib/graph/graph_private.h
@@ -10,6 +10,7 @@
 
 #include <rte_common.h>
 #include <rte_eal.h>
+#include <rte_spinlock.h>
 
 #include "rte_graph.h"
 #include "rte_graph_worker.h"
@@ -148,20 +149,25 @@ STAILQ_HEAD(graph_head, graph);
  */
 struct graph_head *graph_list_head_get(void);
 
+rte_spinlock_t *
+graph_spinlock_get(void);
+
 /* Lock functions */
 /**
  * @internal
  *
  * Take a lock on the graph internal spin lock.
  */
-void graph_spinlock_lock(void);
+void graph_spinlock_lock(void)
+	__rte_exclusive_lock_function(graph_spinlock_get());
 
 /**
  * @internal
  *
  * Release a lock on the graph internal spin lock.
  */
-void graph_spinlock_unlock(void);
+void graph_spinlock_unlock(void)
+	__rte_unlock_function(graph_spinlock_get());
 
 /* Graph operations */
 /**
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 06/16] drivers: inherit lock annotations for Intel drivers
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (4 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 05/16] graph: annotate graph lock David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 07/16] net/cxgbe: inherit lock annotations David Marchand
                     ` (10 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Jingjing Wu, Beilei Xing, Yuying Zhang, Qiming Yang, Qi Zhang

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/common/iavf/iavf_osdep.h       | 39 ++++++--------------------
 drivers/common/iavf/iavf_prototype.h   |  6 ----
 drivers/common/idpf/base/idpf_osdep.h  | 26 +++--------------
 drivers/net/i40e/base/i40e_osdep.h     |  8 +++---
 drivers/net/i40e/base/i40e_prototype.h |  5 ----
 drivers/net/i40e/i40e_ethdev.c         | 24 ----------------
 drivers/net/ice/base/ice_osdep.h       | 26 +++--------------
 7 files changed, 20 insertions(+), 114 deletions(-)

diff --git a/drivers/common/iavf/iavf_osdep.h b/drivers/common/iavf/iavf_osdep.h
index 31d3d809f9..263d92400c 100644
--- a/drivers/common/iavf/iavf_osdep.h
+++ b/drivers/common/iavf/iavf_osdep.h
@@ -170,11 +170,6 @@ struct iavf_virt_mem {
 	u32 size;
 } __rte_packed;
 
-/* SW spinlock */
-struct iavf_spinlock {
-	rte_spinlock_t spinlock;
-};
-
 #define iavf_allocate_dma_mem(h, m, unused, s, a) \
 			iavf_allocate_dma_mem_d(h, m, s, a)
 #define iavf_free_dma_mem(h, m) iavf_free_dma_mem_d(h, m)
@@ -182,32 +177,14 @@ struct iavf_spinlock {
 #define iavf_allocate_virt_mem(h, m, s) iavf_allocate_virt_mem_d(h, m, s)
 #define iavf_free_virt_mem(h, m) iavf_free_virt_mem_d(h, m)
 
-static inline void
-iavf_init_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-iavf_acquire_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-iavf_release_spinlock_d(struct iavf_spinlock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-iavf_destroy_spinlock_d(__rte_unused struct iavf_spinlock *sp)
-{
-}
+/* SW spinlock */
+struct iavf_spinlock {
+	rte_spinlock_t spinlock;
+};
 
-#define iavf_init_spinlock(_sp) iavf_init_spinlock_d(_sp)
-#define iavf_acquire_spinlock(_sp) iavf_acquire_spinlock_d(_sp)
-#define iavf_release_spinlock(_sp) iavf_release_spinlock_d(_sp)
-#define iavf_destroy_spinlock(_sp) iavf_destroy_spinlock_d(_sp)
+#define iavf_init_spinlock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define iavf_acquire_spinlock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define iavf_release_spinlock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define iavf_destroy_spinlock(sp) RTE_SET_USED(sp)
 
 #endif /* _IAVF_OSDEP_H_ */
diff --git a/drivers/common/iavf/iavf_prototype.h b/drivers/common/iavf/iavf_prototype.h
index b5124de5bf..ba78ec5169 100644
--- a/drivers/common/iavf/iavf_prototype.h
+++ b/drivers/common/iavf/iavf_prototype.h
@@ -76,12 +76,6 @@ STATIC INLINE struct iavf_rx_ptype_decoded decode_rx_desc_ptype(u8 ptype)
 	return iavf_ptype_lookup[ptype];
 }
 
-/* prototype for functions used for SW spinlocks */
-void iavf_init_spinlock(struct iavf_spinlock *sp);
-void iavf_acquire_spinlock(struct iavf_spinlock *sp);
-void iavf_release_spinlock(struct iavf_spinlock *sp);
-void iavf_destroy_spinlock(struct iavf_spinlock *sp);
-
 __rte_internal
 void iavf_vf_parse_hw_config(struct iavf_hw *hw,
 			     struct virtchnl_vf_resource *msg);
diff --git a/drivers/common/idpf/base/idpf_osdep.h b/drivers/common/idpf/base/idpf_osdep.h
index 99ae9cf60a..49bd7c4b21 100644
--- a/drivers/common/idpf/base/idpf_osdep.h
+++ b/drivers/common/idpf/base/idpf_osdep.h
@@ -210,28 +210,10 @@ struct idpf_lock {
 	rte_spinlock_t spinlock;
 };
 
-static inline void
-idpf_init_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-idpf_acquire_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-idpf_release_lock(struct idpf_lock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-idpf_destroy_lock(__rte_unused struct idpf_lock *sp)
-{
-}
+#define idpf_init_lock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define idpf_acquire_lock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define idpf_release_lock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define idpf_destroy_lock(sp) RTE_SET_USED(sp)
 
 struct idpf_hw;
 
diff --git a/drivers/net/i40e/base/i40e_osdep.h b/drivers/net/i40e/base/i40e_osdep.h
index 51537c5cf3..aa5dc61841 100644
--- a/drivers/net/i40e/base/i40e_osdep.h
+++ b/drivers/net/i40e/base/i40e_osdep.h
@@ -215,10 +215,10 @@ struct i40e_spinlock {
 	rte_spinlock_t spinlock;
 };
 
-#define i40e_init_spinlock(_sp) i40e_init_spinlock_d(_sp)
-#define i40e_acquire_spinlock(_sp) i40e_acquire_spinlock_d(_sp)
-#define i40e_release_spinlock(_sp) i40e_release_spinlock_d(_sp)
-#define i40e_destroy_spinlock(_sp) i40e_destroy_spinlock_d(_sp)
+#define i40e_init_spinlock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define i40e_acquire_spinlock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define i40e_release_spinlock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define i40e_destroy_spinlock(sp) RTE_SET_USED(sp)
 
 #define I40E_NTOHS(a) rte_be_to_cpu_16(a)
 #define I40E_NTOHL(a) rte_be_to_cpu_32(a)
diff --git a/drivers/net/i40e/base/i40e_prototype.h b/drivers/net/i40e/base/i40e_prototype.h
index 29c86c7fe8..691c977172 100644
--- a/drivers/net/i40e/base/i40e_prototype.h
+++ b/drivers/net/i40e/base/i40e_prototype.h
@@ -546,11 +546,6 @@ i40e_virtchnl_link_speed(enum i40e_aq_link_speed link_speed)
 	}
 }
 #endif /* PF_DRIVER */
-/* prototype for functions used for SW spinlocks */
-void i40e_init_spinlock(struct i40e_spinlock *sp);
-void i40e_acquire_spinlock(struct i40e_spinlock *sp);
-void i40e_release_spinlock(struct i40e_spinlock *sp);
-void i40e_destroy_spinlock(struct i40e_spinlock *sp);
 
 /* i40e_common for VF drivers*/
 void i40e_vf_parse_hw_config(struct i40e_hw *hw,
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index cb0070f94b..f9d8f9791f 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -4635,30 +4635,6 @@ i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
 	return I40E_SUCCESS;
 }
 
-void
-i40e_init_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-void
-i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-void
-i40e_release_spinlock_d(struct i40e_spinlock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-void
-i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp)
-{
-	return;
-}
-
 /**
  * Get the hardware capabilities, which will be parsed
  * and saved into struct i40e_hw.
diff --git a/drivers/net/ice/base/ice_osdep.h b/drivers/net/ice/base/ice_osdep.h
index 4b92057521..0e14b934c8 100644
--- a/drivers/net/ice/base/ice_osdep.h
+++ b/drivers/net/ice/base/ice_osdep.h
@@ -211,28 +211,10 @@ struct ice_lock {
 	rte_spinlock_t spinlock;
 };
 
-static inline void
-ice_init_lock(struct ice_lock *sp)
-{
-	rte_spinlock_init(&sp->spinlock);
-}
-
-static inline void
-ice_acquire_lock(struct ice_lock *sp)
-{
-	rte_spinlock_lock(&sp->spinlock);
-}
-
-static inline void
-ice_release_lock(struct ice_lock *sp)
-{
-	rte_spinlock_unlock(&sp->spinlock);
-}
-
-static inline void
-ice_destroy_lock(__rte_unused struct ice_lock *sp)
-{
-}
+#define ice_init_lock(sp) rte_spinlock_init(&(sp)->spinlock)
+#define ice_acquire_lock(sp) rte_spinlock_lock(&(sp)->spinlock)
+#define ice_release_lock(sp) rte_spinlock_unlock(&(sp)->spinlock)
+#define ice_destroy_lock(sp) RTE_SET_USED(sp)
 
 struct ice_hw;
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 07/16] net/cxgbe: inherit lock annotations
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (5 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 06/16] drivers: inherit lock annotations for Intel drivers David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 08/16] net/fm10k: annotate mailbox lock David Marchand
                     ` (9 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Rahul Lakkireddy

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/cxgbe/base/adapter.h | 35 +++++++-------------------------
 1 file changed, 7 insertions(+), 28 deletions(-)

diff --git a/drivers/net/cxgbe/base/adapter.h b/drivers/net/cxgbe/base/adapter.h
index 16cbc1a345..8f2ffa0eeb 100644
--- a/drivers/net/cxgbe/base/adapter.h
+++ b/drivers/net/cxgbe/base/adapter.h
@@ -351,28 +351,19 @@ struct adapter {
  * t4_os_rwlock_init - initialize rwlock
  * @lock: the rwlock
  */
-static inline void t4_os_rwlock_init(rte_rwlock_t *lock)
-{
-	rte_rwlock_init(lock);
-}
+#define t4_os_rwlock_init(lock) rte_rwlock_init(lock)
 
 /**
  * t4_os_write_lock - get a write lock
  * @lock: the rwlock
  */
-static inline void t4_os_write_lock(rte_rwlock_t *lock)
-{
-	rte_rwlock_write_lock(lock);
-}
+#define t4_os_write_lock(lock) rte_rwlock_write_lock(lock)
 
 /**
  * t4_os_write_unlock - unlock a write lock
  * @lock: the rwlock
  */
-static inline void t4_os_write_unlock(rte_rwlock_t *lock)
-{
-	rte_rwlock_write_unlock(lock);
-}
+#define t4_os_write_unlock(lock) rte_rwlock_write_unlock(lock)
 
 /**
  * ethdev2pinfo - return the port_info structure associated with a rte_eth_dev
@@ -678,37 +669,25 @@ static inline void t4_os_set_hw_addr(struct adapter *adapter, int port_idx,
  * t4_os_lock_init - initialize spinlock
  * @lock: the spinlock
  */
-static inline void t4_os_lock_init(rte_spinlock_t *lock)
-{
-	rte_spinlock_init(lock);
-}
+#define t4_os_lock_init(lock) rte_spinlock_init(lock)
 
 /**
  * t4_os_lock - spin until lock is acquired
  * @lock: the spinlock
  */
-static inline void t4_os_lock(rte_spinlock_t *lock)
-{
-	rte_spinlock_lock(lock);
-}
+#define t4_os_lock(lock) rte_spinlock_lock(lock)
 
 /**
  * t4_os_unlock - unlock a spinlock
  * @lock: the spinlock
  */
-static inline void t4_os_unlock(rte_spinlock_t *lock)
-{
-	rte_spinlock_unlock(lock);
-}
+#define t4_os_unlock(lock) rte_spinlock_unlock(lock)
 
 /**
  * t4_os_trylock - try to get a lock
  * @lock: the spinlock
  */
-static inline int t4_os_trylock(rte_spinlock_t *lock)
-{
-	return rte_spinlock_trylock(lock);
-}
+#define t4_os_trylock(lock) rte_spinlock_trylock(lock)
 
 /**
  * t4_os_init_list_head - initialize
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 08/16] net/fm10k: annotate mailbox lock
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (6 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 07/16] net/cxgbe: inherit lock annotations David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 09/16] net/sfc: rework locking in proxy code David Marchand
                     ` (8 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Qi Zhang, Xiao Wang

Expose requirements for helpers dealing with the
FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back) lock.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/fm10k/fm10k_ethdev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 8b83063f0a..4d3c4c10cf 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -116,6 +116,7 @@ fm10k_mbx_initlock(struct fm10k_hw *hw)
 
 static void
 fm10k_mbx_lock(struct fm10k_hw *hw)
+	__rte_exclusive_lock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
 {
 	while (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)))
 		rte_delay_us(FM10K_MBXLOCK_DELAY_US);
@@ -123,6 +124,7 @@ fm10k_mbx_lock(struct fm10k_hw *hw)
 
 static void
 fm10k_mbx_unlock(struct fm10k_hw *hw)
+	__rte_unlock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
 {
 	rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 09/16] net/sfc: rework locking in proxy code
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (7 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 08/16] net/fm10k: annotate mailbox lock David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 10/16] net/sfc: inherit lock annotations David Marchand
                     ` (7 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Andrew Rybchenko

Remove one extra layer for proxy code: sfc_get_adapter_by_pf_port_id()
now only resolves the sa object. sfc_adapter_(|un)lock() are added
were necessary.

This will simplify lock checks later.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/sfc/sfc_repr_proxy.c | 59 ++++++++++++++++----------------
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/drivers/net/sfc/sfc_repr_proxy.c b/drivers/net/sfc/sfc_repr_proxy.c
index 4b958ced61..4ba7683370 100644
--- a/drivers/net/sfc/sfc_repr_proxy.c
+++ b/drivers/net/sfc/sfc_repr_proxy.c
@@ -51,17 +51,9 @@ sfc_get_adapter_by_pf_port_id(uint16_t pf_port_id)
 	dev = &rte_eth_devices[pf_port_id];
 	sa = sfc_adapter_by_eth_dev(dev);
 
-	sfc_adapter_lock(sa);
-
 	return sa;
 }
 
-static void
-sfc_put_adapter(struct sfc_adapter *sa)
-{
-	sfc_adapter_unlock(sa);
-}
-
 static struct sfc_repr_proxy_port *
 sfc_repr_proxy_find_port(struct sfc_repr_proxy *rp, uint16_t repr_id)
 {
@@ -1289,6 +1281,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1341,7 +1334,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 	}
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
@@ -1352,7 +1345,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 fail_alloc_port:
 fail_port_exists:
 	sfc_log_init(sa, "failed: %s", rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1366,6 +1359,7 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1393,14 +1387,14 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)
 
 	sfc_log_init(sa, "done");
 
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
 fail_port_remove:
 fail_no_port:
 	sfc_log_init(sa, "failed: %s", rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1416,6 +1410,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1423,14 +1418,14 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
 	rxq = &port->rxq[queue_id];
 	if (rp->dp_rxq[queue_id].mp != NULL && rp->dp_rxq[queue_id].mp != mp) {
 		sfc_err(sa, "multiple mempools per queue are not supported");
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOTSUP;
 	}
 
@@ -1440,7 +1435,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	rp->dp_rxq[queue_id].ref_count++;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1455,6 +1450,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1462,7 +1458,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return;
 	}
 
@@ -1475,7 +1471,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,
 		rp->dp_rxq[queue_id].mp = NULL;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 }
 
 int
@@ -1489,6 +1485,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1496,7 +1493,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
@@ -1507,7 +1504,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,
 	*egress_mport = port->egress_mport;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1522,6 +1519,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	struct sfc_adapter *sa;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1529,7 +1527,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return;
 	}
 
@@ -1538,7 +1536,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 	txq->ring = NULL;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 }
 
 int
@@ -1551,6 +1549,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1594,7 +1593,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 	}
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 
@@ -1606,7 +1605,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)
 fail_not_found:
 	sfc_err(sa, "failed to start repr %u proxy port: %s", repr_id,
 		rte_strerror(rc));
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
@@ -1621,6 +1620,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	sfc_log_init(sa, "entry");
@@ -1628,14 +1628,14 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port", __func__);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
 	if (!port->enabled) {
 		sfc_log_init(sa, "repr %u proxy port is not started - skip",
 			     repr_id);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return 0;
 	}
 
@@ -1662,7 +1662,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 			sfc_err(sa,
 				"failed to stop representor proxy TxQ %u: %s",
 				repr_id, rte_strerror(rc));
-			sfc_put_adapter(sa);
+			sfc_adapter_unlock(sa);
 			return rc;
 		}
 	}
@@ -1670,7 +1670,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 	port->enabled = false;
 
 	sfc_log_init(sa, "done");
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return 0;
 }
@@ -1685,13 +1685,14 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,
 	int rc;
 
 	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	sfc_adapter_lock(sa);
 	rp = sfc_repr_proxy_by_adapter(sa);
 
 	port = sfc_repr_proxy_find_port(rp, repr_id);
 	if (port == NULL) {
 		sfc_err(sa, "%s() failed: no such port (repr_id=%u)",
 			__func__, repr_id);
-		sfc_put_adapter(sa);
+		sfc_adapter_unlock(sa);
 		return ENOENT;
 	}
 
@@ -1703,7 +1704,7 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,
 			__func__, repr_id, rte_strerror(rc));
 	}
 
-	sfc_put_adapter(sa);
+	sfc_adapter_unlock(sa);
 
 	return rc;
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 10/16] net/sfc: inherit lock annotations
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (8 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 09/16] net/sfc: rework locking in proxy code David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 11/16] net/virtio: rework guest announce notify helper David Marchand
                     ` (6 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Andrew Rybchenko

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

One additional change is required in sfc_ev_qpoll() so that clang does
see the same lock is being manipulated.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/sfc/sfc.h      | 41 ++++++--------------------------------
 drivers/net/sfc/sfc_ev.c   |  6 ++++--
 drivers/net/sfc/sfc_repr.c | 38 +++++------------------------------
 3 files changed, 15 insertions(+), 70 deletions(-)

diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index 0a1e224fa2..730d054aea 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -333,41 +333,12 @@ sfc_sa2shared(struct sfc_adapter *sa)
  * change the lock in one place.
  */
 
-static inline void
-sfc_adapter_lock_init(struct sfc_adapter *sa)
-{
-	rte_spinlock_init(&sa->lock);
-}
-
-static inline int
-sfc_adapter_is_locked(struct sfc_adapter *sa)
-{
-	return rte_spinlock_is_locked(&sa->lock);
-}
-
-static inline void
-sfc_adapter_lock(struct sfc_adapter *sa)
-{
-	rte_spinlock_lock(&sa->lock);
-}
-
-static inline int
-sfc_adapter_trylock(struct sfc_adapter *sa)
-{
-	return rte_spinlock_trylock(&sa->lock);
-}
-
-static inline void
-sfc_adapter_unlock(struct sfc_adapter *sa)
-{
-	rte_spinlock_unlock(&sa->lock);
-}
-
-static inline void
-sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_adapter_lock_init(sa) rte_spinlock_init(&(sa)->lock)
+#define sfc_adapter_is_locked(sa) rte_spinlock_is_locked(&(sa)->lock)
+#define sfc_adapter_lock(sa) rte_spinlock_lock(&(sa)->lock)
+#define sfc_adapter_trylock(sa) rte_spinlock_trylock(&(sa)->lock)
+#define sfc_adapter_unlock(sa) rte_spinlock_unlock(&(sa)->lock)
+#define sfc_adapter_lock_fini(sa) RTE_SET_USED(sa)
 
 static inline unsigned int
 sfc_nb_counter_rxq(const struct sfc_adapter_shared *sas)
diff --git a/drivers/net/sfc/sfc_ev.c b/drivers/net/sfc/sfc_ev.c
index f949abbfc3..c0d58c9554 100644
--- a/drivers/net/sfc/sfc_ev.c
+++ b/drivers/net/sfc/sfc_ev.c
@@ -570,6 +570,8 @@ static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {
 void
 sfc_ev_qpoll(struct sfc_evq *evq)
 {
+	struct sfc_adapter *sa;
+
 	SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED ||
 		   evq->init_state == SFC_EVQ_STARTING);
 
@@ -577,8 +579,8 @@ sfc_ev_qpoll(struct sfc_evq *evq)
 
 	efx_ev_qpoll(evq->common, &evq->read_ptr, evq->callbacks, evq);
 
-	if (unlikely(evq->exception) && sfc_adapter_trylock(evq->sa)) {
-		struct sfc_adapter *sa = evq->sa;
+	sa = evq->sa;
+	if (unlikely(evq->exception) && sfc_adapter_trylock(sa)) {
 		int rc;
 
 		if (evq->dp_rxq != NULL) {
diff --git a/drivers/net/sfc/sfc_repr.c b/drivers/net/sfc/sfc_repr.c
index 919048e278..d4134ec91b 100644
--- a/drivers/net/sfc/sfc_repr.c
+++ b/drivers/net/sfc/sfc_repr.c
@@ -112,39 +112,11 @@ sfc_repr_by_eth_dev(struct rte_eth_dev *eth_dev)
  * change the lock in one place.
  */
 
-static inline void
-sfc_repr_lock_init(struct sfc_repr *sr)
-{
-	rte_spinlock_init(&sr->lock);
-}
-
-#if defined(RTE_LIBRTE_SFC_EFX_DEBUG) || defined(RTE_ENABLE_ASSERT)
-
-static inline int
-sfc_repr_lock_is_locked(struct sfc_repr *sr)
-{
-	return rte_spinlock_is_locked(&sr->lock);
-}
-
-#endif
-
-static inline void
-sfc_repr_lock(struct sfc_repr *sr)
-{
-	rte_spinlock_lock(&sr->lock);
-}
-
-static inline void
-sfc_repr_unlock(struct sfc_repr *sr)
-{
-	rte_spinlock_unlock(&sr->lock);
-}
-
-static inline void
-sfc_repr_lock_fini(__rte_unused struct sfc_repr *sr)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_repr_lock_init(sr) rte_spinlock_init(&(sr)->lock)
+#define sfc_repr_lock_is_locked(sr) rte_spinlock_is_locked(&(sr)->lock)
+#define sfc_repr_lock(sr) rte_spinlock_lock(&(sr)->lock)
+#define sfc_repr_unlock(sr) rte_spinlock_unlock(&(sr)->lock)
+#define sfc_repr_lock_fini(sr) RTE_SET_USED(sr)
 
 static void
 sfc_repr_rx_queue_stop(void *queue)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 11/16] net/virtio: rework guest announce notify helper
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (9 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 10/16] net/sfc: inherit lock annotations David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 12/16] raw/ifpga: inherit lock annotations David Marchand
                     ` (5 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Maxime Coquelin, Chenbo Xia

Inline existing helpers virtio_dev_(pause|resume) into
virtio_notify_peers().
This makes the lock check on hw->state_lock trivial.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/virtio/virtio_ethdev.c | 75 ++++++++----------------------
 drivers/net/virtio/virtio_ethdev.h |  4 --
 2 files changed, 19 insertions(+), 60 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index ae84d313be..07e53d2b97 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1144,57 +1144,6 @@ virtio_ethdev_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 	return 0;
 }
 
-int
-virtio_dev_pause(struct rte_eth_dev *dev)
-{
-	struct virtio_hw *hw = dev->data->dev_private;
-
-	rte_spinlock_lock(&hw->state_lock);
-
-	if (hw->started == 0) {
-		/* Device is just stopped. */
-		rte_spinlock_unlock(&hw->state_lock);
-		return -1;
-	}
-	hw->started = 0;
-	/*
-	 * Prevent the worker threads from touching queues to avoid contention,
-	 * 1 ms should be enough for the ongoing Tx function to finish.
-	 */
-	rte_delay_ms(1);
-	return 0;
-}
-
-/*
- * Recover hw state to let the worker threads continue.
- */
-void
-virtio_dev_resume(struct rte_eth_dev *dev)
-{
-	struct virtio_hw *hw = dev->data->dev_private;
-
-	hw->started = 1;
-	rte_spinlock_unlock(&hw->state_lock);
-}
-
-/*
- * Should be called only after device is paused.
- */
-int
-virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
-		int nb_pkts)
-{
-	struct virtio_hw *hw = dev->data->dev_private;
-	struct virtnet_tx *txvq = dev->data->tx_queues[0];
-	int ret;
-
-	hw->inject_pkts = tx_pkts;
-	ret = dev->tx_pkt_burst(txvq, tx_pkts, nb_pkts);
-	hw->inject_pkts = NULL;
-
-	return ret;
-}
-
 static void
 virtio_notify_peers(struct rte_eth_dev *dev)
 {
@@ -1216,14 +1165,28 @@ virtio_notify_peers(struct rte_eth_dev *dev)
 		return;
 	}
 
-	/* If virtio port just stopped, no need to send RARP */
-	if (virtio_dev_pause(dev) < 0) {
+	rte_spinlock_lock(&hw->state_lock);
+	if (hw->started == 0) {
+		/* If virtio port just stopped, no need to send RARP */
 		rte_pktmbuf_free(rarp_mbuf);
-		return;
+		goto out;
 	}
+	hw->started = 0;
 
-	virtio_inject_pkts(dev, &rarp_mbuf, 1);
-	virtio_dev_resume(dev);
+	/*
+	 * Prevent the worker threads from touching queues to avoid contention,
+	 * 1 ms should be enough for the ongoing Tx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	hw->inject_pkts = &rarp_mbuf;
+	dev->tx_pkt_burst(dev->data->tx_queues[0], &rarp_mbuf, 1);
+	hw->inject_pkts = NULL;
+
+	hw->started = 1;
+
+out:
+	rte_spinlock_unlock(&hw->state_lock);
 }
 
 static void
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index c08f382791..7be1c9acd0 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -112,12 +112,8 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
 
 void virtio_interrupt_handler(void *param);
 
-int virtio_dev_pause(struct rte_eth_dev *dev);
-void virtio_dev_resume(struct rte_eth_dev *dev);
 int virtio_dev_stop(struct rte_eth_dev *dev);
 int virtio_dev_close(struct rte_eth_dev *dev);
-int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
-		int nb_pkts);
 
 bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
 			bool rx_scatter_enabled, const char **error);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 12/16] raw/ifpga: inherit lock annotations
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (10 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 11/16] net/virtio: rework guest announce notify helper David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 13/16] vdpa/sfc: " David Marchand
                     ` (4 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Rosen Xu, Wei Huang, Tianfei Zhang

The checks in those helpers are useless:
- all (start/stop/reset/test) callers ensure that dev != NULL,
- dev->sd can't be NULL either as it would mean the application is calling
  those helpers for a dev pointer that did not pass initialisation,

Once the checks are removed, the only thing that remains is calls to the
rte_spinlock API, so simply use macros and inherit annotations from the
lock API.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Rosen Xu <rosen.xu@intel.com>
Reviewed-by: Wei Huang <wei.huang@intel.com>
---
 drivers/raw/ifpga/afu_pmd_core.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/raw/ifpga/afu_pmd_core.c b/drivers/raw/ifpga/afu_pmd_core.c
index ddf7a34f33..3ab1f47ac1 100644
--- a/drivers/raw/ifpga/afu_pmd_core.c
+++ b/drivers/raw/ifpga/afu_pmd_core.c
@@ -23,21 +23,8 @@ static struct rte_afu_uuid afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1];
 TAILQ_HEAD(afu_drv_list, afu_rawdev_drv);
 static struct afu_drv_list afu_pmd_list = TAILQ_HEAD_INITIALIZER(afu_pmd_list);
 
-static inline int afu_rawdev_trylock(struct afu_rawdev *dev)
-{
-	if (!dev || !dev->sd)
-		return 0;
-
-	return rte_spinlock_trylock(&dev->sd->lock);
-}
-
-static inline void afu_rawdev_unlock(struct afu_rawdev *dev)
-{
-	if (!dev || !dev->sd)
-		return;
-
-	rte_spinlock_unlock(&dev->sd->lock);
-}
+#define afu_rawdev_trylock(dev) rte_spinlock_trylock(&dev->sd->lock)
+#define afu_rawdev_unlock(dev) rte_spinlock_unlock(&dev->sd->lock)
 
 static int afu_rawdev_configure(const struct rte_rawdev *rawdev,
 	rte_rawdev_obj_t config, size_t config_size)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 13/16] vdpa/sfc: inherit lock annotations
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (11 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 12/16] raw/ifpga: inherit lock annotations David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 14/16] net/failsafe: fix mutex locking David Marchand
                     ` (3 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Vijay Kumar Srivastava

Due to clang limitation, inline helpers don't inherit lock annotations
from the EAL lock API.
Replace them with macros.

sfc_vdpa_ops.c was relying on an implicit cast of the dev_handle to a
vdpa adapter object. Add an explicit conversion.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/vdpa/sfc/sfc_vdpa.h     | 41 +++++----------------------------
 drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 +++++------
 2 files changed, 13 insertions(+), 42 deletions(-)

diff --git a/drivers/vdpa/sfc/sfc_vdpa.h b/drivers/vdpa/sfc/sfc_vdpa.h
index b25eb3a5fe..2b843e563d 100644
--- a/drivers/vdpa/sfc/sfc_vdpa.h
+++ b/drivers/vdpa/sfc/sfc_vdpa.h
@@ -122,40 +122,11 @@ sfc_vdpa_adapter_by_dev_handle(void *dev_handle)
  * Add wrapper functions to acquire/release lock to be able to remove or
  * change the lock in one place.
  */
-static inline void
-sfc_vdpa_adapter_lock_init(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_init(&sva->lock);
-}
-
-static inline int
-sfc_vdpa_adapter_is_locked(struct sfc_vdpa_adapter *sva)
-{
-	return rte_spinlock_is_locked(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_lock(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_lock(&sva->lock);
-}
-
-static inline int
-sfc_vdpa_adapter_trylock(struct sfc_vdpa_adapter *sva)
-{
-	return rte_spinlock_trylock(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_unlock(struct sfc_vdpa_adapter *sva)
-{
-	rte_spinlock_unlock(&sva->lock);
-}
-
-static inline void
-sfc_vdpa_adapter_lock_fini(__rte_unused struct sfc_vdpa_adapter *sva)
-{
-	/* Just for symmetry of the API */
-}
+#define sfc_vdpa_adapter_lock_init(sva) rte_spinlock_init(&(sva)->lock)
+#define sfc_vdpa_adapter_is_locked(sva) rte_spinlock_is_locked(&(sva)->lock)
+#define sfc_vdpa_adapter_lock(sva) rte_spinlock_lock(&(sva)->lock)
+#define sfc_vdpa_adapter_trylock(sva) rte_spinlock_trylock(&(sva)->lock)
+#define sfc_vdpa_adapter_unlock(sva) rte_spinlock_unlock(&(sva)->lock)
+#define sfc_vdpa_adapter_lock_fini(sva) RTE_SET_USED(sva)
 
 #endif  /* _SFC_VDPA_H */
diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.c b/drivers/vdpa/sfc/sfc_vdpa_ops.c
index e88c7eeaa6..f63af7d478 100644
--- a/drivers/vdpa/sfc/sfc_vdpa_ops.c
+++ b/drivers/vdpa/sfc/sfc_vdpa_ops.c
@@ -577,7 +577,7 @@ sfc_vdpa_notify_ctrl(void *arg)
 	if (ops_data == NULL)
 		return NULL;
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	vid = ops_data->vid;
 
@@ -586,7 +586,7 @@ sfc_vdpa_notify_ctrl(void *arg)
 			      "vDPA (%s): Notifier could not get configured",
 			      ops_data->vdpa_dev->device->name);
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return NULL;
 }
@@ -637,7 +637,7 @@ sfc_vdpa_dev_config(int vid)
 
 	ops_data->vid = vid;
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	sfc_vdpa_log_init(ops_data->dev_handle, "configuring");
 	rc = sfc_vdpa_configure(ops_data);
@@ -653,7 +653,7 @@ sfc_vdpa_dev_config(int vid)
 	if (rc != 0)
 		goto fail_vdpa_notify;
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	sfc_vdpa_log_init(ops_data->dev_handle, "done");
 
@@ -666,7 +666,7 @@ sfc_vdpa_dev_config(int vid)
 	sfc_vdpa_close(ops_data);
 
 fail_vdpa_config:
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return -1;
 }
@@ -688,7 +688,7 @@ sfc_vdpa_dev_close(int vid)
 		return -1;
 	}
 
-	sfc_vdpa_adapter_lock(ops_data->dev_handle);
+	sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 	if (ops_data->is_notify_thread_started == true) {
 		void *status;
 		ret = pthread_cancel(ops_data->notify_tid);
@@ -710,7 +710,7 @@ sfc_vdpa_dev_close(int vid)
 	sfc_vdpa_stop(ops_data);
 	sfc_vdpa_close(ops_data);
 
-	sfc_vdpa_adapter_unlock(ops_data->dev_handle);
+	sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle));
 
 	return 0;
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 14/16] net/failsafe: fix mutex locking
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (12 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 13/16] vdpa/sfc: " David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 12:48   ` [PATCH v3 15/16] eal/windows: disable lock check on alarm code David Marchand
                     ` (2 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev; +Cc: thomas, Gaetan Rivet

The pthread mutex API describes cases where locking might fail.
Check fts_enter wrapper return code.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Gaetan Rivet <grive@u256.net>
---
 drivers/net/failsafe/failsafe_ether.c |   3 +-
 drivers/net/failsafe/failsafe_flow.c  |  23 +++--
 drivers/net/failsafe/failsafe_ops.c   | 142 +++++++++++++++++++-------
 3 files changed, 123 insertions(+), 45 deletions(-)

diff --git a/drivers/net/failsafe/failsafe_ether.c b/drivers/net/failsafe/failsafe_ether.c
index 10b90fd837..031f3eb13f 100644
--- a/drivers/net/failsafe/failsafe_ether.c
+++ b/drivers/net/failsafe/failsafe_ether.c
@@ -592,7 +592,8 @@ failsafe_eth_rmv_event_callback(uint16_t port_id __rte_unused,
 {
 	struct sub_device *sdev = cb_arg;
 
-	fs_lock(fs_dev(sdev), 0);
+	if (fs_lock(fs_dev(sdev), 0) != 0)
+		return -1;
 	/* Switch as soon as possible tx_dev. */
 	fs_switch_dev(fs_dev(sdev), sdev);
 	/* Use safe bursts in any case. */
diff --git a/drivers/net/failsafe/failsafe_flow.c b/drivers/net/failsafe/failsafe_flow.c
index 354f9fec20..707e6c63b5 100644
--- a/drivers/net/failsafe/failsafe_flow.c
+++ b/drivers/net/failsafe/failsafe_flow.c
@@ -72,7 +72,9 @@ fs_flow_validate(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_flow_validate on sub_device %d", i);
 		ret = rte_flow_validate(PORT_ID(sdev),
@@ -99,7 +101,8 @@ fs_flow_create(struct rte_eth_dev *dev,
 	struct rte_flow *flow;
 	uint8_t i;
 
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return NULL;
 	flow = fs_flow_allocate(attr, patterns, actions);
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		flow->flows[i] = rte_flow_create(PORT_ID(sdev),
@@ -137,8 +140,9 @@ fs_flow_destroy(struct rte_eth_dev *dev,
 		ERROR("Invalid flow");
 		return -EINVAL;
 	}
-	ret = 0;
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		int local_ret;
 
@@ -169,7 +173,9 @@ fs_flow_flush(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_flow_flush on sub_device %d", i);
 		ret = rte_flow_flush(PORT_ID(sdev), error);
@@ -197,7 +203,8 @@ fs_flow_query(struct rte_eth_dev *dev,
 {
 	struct sub_device *sdev;
 
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return -1;
 	sdev = TX_SUBDEV(dev);
 	if (sdev != NULL) {
 		int ret = rte_flow_query(PORT_ID(sdev),
@@ -223,7 +230,9 @@ fs_flow_isolate(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV(sdev, i, dev) {
 		if (sdev->state < DEV_PROBED)
 			continue;
diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c
index d357e1bc83..35649b6244 100644
--- a/drivers/net/failsafe/failsafe_ops.c
+++ b/drivers/net/failsafe/failsafe_ops.c
@@ -28,7 +28,9 @@ fs_dev_configure(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV(sdev, i, dev) {
 		int rmv_interrupt = 0;
 		int lsc_interrupt = 0;
@@ -129,7 +131,9 @@ fs_dev_start(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	ret = failsafe_rx_intr_install(dev);
 	if (ret) {
 		fs_unlock(dev, 0);
@@ -189,7 +193,9 @@ fs_dev_stop(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	PRIV(dev)->state = DEV_STARTED - 1;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) {
 		ret = rte_eth_dev_stop(PORT_ID(sdev));
@@ -217,7 +223,9 @@ fs_dev_set_link_up(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", i);
 		ret = rte_eth_dev_set_link_up(PORT_ID(sdev));
@@ -239,7 +247,9 @@ fs_dev_set_link_down(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_set_link_down on sub_device %d", i);
 		ret = rte_eth_dev_set_link_down(PORT_ID(sdev));
@@ -263,7 +273,9 @@ fs_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 	int err = 0;
 	bool failure = true;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		uint16_t port_id = ETH(sdev)->data->port_id;
 
@@ -289,7 +301,9 @@ fs_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		uint16_t port_id = ETH(sdev)->data->port_id;
 
@@ -316,7 +330,9 @@ fs_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
 	int err = 0;
 	bool failure = true;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		uint16_t port_id = ETH(sdev)->data->port_id;
 
@@ -342,7 +358,9 @@ fs_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		uint16_t port_id = ETH(sdev)->data->port_id;
 
@@ -369,7 +387,8 @@ fs_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (rxq == NULL)
 		return;
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return;
 	if (rxq->event_fd >= 0)
 		close(rxq->event_fd);
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
@@ -395,7 +414,9 @@ fs_rx_queue_setup(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	if (rx_conf->rx_deferred_start) {
 		FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
 			if (SUBOPS(sdev, rx_queue_start) == NULL) {
@@ -466,7 +487,9 @@ fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
 	int ret;
 	int rc = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	if (idx >= dev->data->nb_rx_queues) {
 		rc = -EINVAL;
 		goto unlock;
@@ -506,7 +529,9 @@ fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
 	int rc = 0;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	if (idx >= dev->data->nb_rx_queues) {
 		rc = -EINVAL;
 		goto unlock;
@@ -542,7 +567,8 @@ fs_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (txq == NULL)
 		return;
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		if (ETH(sdev)->data->tx_queues != NULL &&
 		    ETH(sdev)->data->tx_queues[txq->qid] != NULL)
@@ -565,7 +591,9 @@ fs_tx_queue_setup(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	if (tx_conf->tx_deferred_start) {
 		FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
 			if (SUBOPS(sdev, tx_queue_start) == NULL) {
@@ -639,7 +667,9 @@ failsafe_eth_dev_close(struct rte_eth_dev *dev)
 	uint8_t i;
 	int err, ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	failsafe_hotplug_alarm_cancel(dev);
 	if (PRIV(dev)->state == DEV_STARTED) {
 		ret = dev->dev_ops->dev_stop(dev);
@@ -693,7 +723,9 @@ fs_promiscuous_enable(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_promiscuous_enable(PORT_ID(sdev));
 		ret = fs_err(sdev, ret);
@@ -725,7 +757,9 @@ fs_promiscuous_disable(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_promiscuous_disable(PORT_ID(sdev));
 		ret = fs_err(sdev, ret);
@@ -757,7 +791,9 @@ fs_allmulticast_enable(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_allmulticast_enable(PORT_ID(sdev));
 		ret = fs_err(sdev, ret);
@@ -789,7 +825,9 @@ fs_allmulticast_disable(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret = 0;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_allmulticast_disable(PORT_ID(sdev));
 		ret = fs_err(sdev, ret);
@@ -822,7 +860,9 @@ fs_link_update(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling link_update on sub_device %d", i);
 		ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete);
@@ -859,7 +899,9 @@ fs_stats_get(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	rte_memcpy(stats, &PRIV(dev)->stats_accumulator, sizeof(*stats));
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		struct rte_eth_stats *snapshot = &sdev->stats_snapshot.stats;
@@ -893,7 +935,9 @@ fs_stats_reset(struct rte_eth_dev *dev)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_stats_reset(PORT_ID(sdev));
 		if (ret) {
@@ -983,7 +1027,9 @@ fs_xstats_get_names(struct rte_eth_dev *dev,
 {
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	ret = __fs_xstats_get_names(dev, xstats_names, limit);
 	fs_unlock(dev, 0);
 	return ret;
@@ -1035,7 +1081,9 @@ fs_xstats_get(struct rte_eth_dev *dev,
 {
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	ret = __fs_xstats_get(dev, xstats, n);
 	fs_unlock(dev, 0);
 
@@ -1048,9 +1096,11 @@ fs_xstats_reset(struct rte_eth_dev *dev)
 {
 	struct sub_device *sdev;
 	uint8_t i;
-	int r = 0;
+	int r;
 
-	fs_lock(dev, 0);
+	r = fs_lock(dev, 0);
+	if (r != 0)
+		return r;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		r = rte_eth_xstats_reset(PORT_ID(sdev));
 		if (r < 0)
@@ -1238,7 +1288,8 @@ fs_dev_supported_ptypes_get(struct rte_eth_dev *dev)
 	struct rte_eth_dev *edev;
 	const uint32_t *ret;
 
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return NULL;
 	sdev = TX_SUBDEV(dev);
 	if (sdev == NULL) {
 		ret = NULL;
@@ -1270,7 +1321,9 @@ fs_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_set_mtu on sub_device %d", i);
 		ret = rte_eth_dev_set_mtu(PORT_ID(sdev), mtu);
@@ -1292,7 +1345,9 @@ fs_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_vlan_filter on sub_device %d", i);
 		ret = rte_eth_dev_vlan_filter(PORT_ID(sdev), vlan_id, on);
@@ -1314,7 +1369,9 @@ fs_flow_ctrl_get(struct rte_eth_dev *dev,
 	struct sub_device *sdev;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	sdev = TX_SUBDEV(dev);
 	if (sdev == NULL) {
 		ret = 0;
@@ -1338,7 +1395,9 @@ fs_flow_ctrl_set(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		DEBUG("Calling rte_eth_dev_flow_ctrl_set on sub_device %d", i);
 		ret = rte_eth_dev_flow_ctrl_set(PORT_ID(sdev), fc_conf);
@@ -1359,7 +1418,8 @@ fs_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
 	struct sub_device *sdev;
 	uint8_t i;
 
-	fs_lock(dev, 0);
+	if (fs_lock(dev, 0) != 0)
+		return;
 	/* No check: already done within the rte_eth_dev_mac_addr_remove
 	 * call for the fail-safe device.
 	 */
@@ -1381,7 +1441,9 @@ fs_mac_addr_add(struct rte_eth_dev *dev,
 	uint8_t i;
 
 	RTE_ASSERT(index < FAILSAFE_MAX_ETHADDR);
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), mac_addr, vmdq);
 		if ((ret = fs_err(sdev, ret))) {
@@ -1407,7 +1469,9 @@ fs_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr);
 		ret = fs_err(sdev, ret);
@@ -1432,7 +1496,9 @@ fs_set_mc_addr_list(struct rte_eth_dev *dev,
 	int ret;
 	void *mcast_addrs;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
@@ -1480,7 +1546,9 @@ fs_rss_hash_update(struct rte_eth_dev *dev,
 	uint8_t i;
 	int ret;
 
-	fs_lock(dev, 0);
+	ret = fs_lock(dev, 0);
+	if (ret != 0)
+		return ret;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_rss_hash_update(PORT_ID(sdev), rss_conf);
 		ret = fs_err(sdev, ret);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 15/16] eal/windows: disable lock check on alarm code
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (13 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 14/16] net/failsafe: fix mutex locking David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-04 16:08     ` Tyler Retzlaff
  2023-04-04 21:02     ` Dmitry Kozlyuk
  2023-04-04 12:48   ` [PATCH v3 16/16] enable lock check David Marchand
  2023-04-23 20:09   ` [PATCH v3 00/16] Enable lock annotations on most libraries and drivers Thomas Monjalon
  16 siblings, 2 replies; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev
  Cc: thomas, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

This code uses locks to implement synchronisation between two threads.
There seems nothing wrong with it, just silence the clang lock check.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/windows/eal_alarm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c
index 48203a2870..34b52380ce 100644
--- a/lib/eal/windows/eal_alarm.c
+++ b/lib/eal/windows/eal_alarm.c
@@ -224,6 +224,7 @@ struct intr_task {
 
 static void
 intr_thread_entry(void *arg)
+	__rte_no_thread_safety_analysis
 {
 	struct intr_task *task = arg;
 	task->func(task->arg);
@@ -232,6 +233,7 @@ intr_thread_entry(void *arg)
 
 static int
 intr_thread_exec_sync(void (*func)(void *arg), void *arg)
+	__rte_no_thread_safety_analysis
 {
 	struct intr_task task;
 	int ret;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH v3 16/16] enable lock check
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (14 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 15/16] eal/windows: disable lock check on alarm code David Marchand
@ 2023-04-04 12:48   ` David Marchand
  2023-04-11  3:21     ` Sachin Saxena (OSS)
  2023-04-23 20:09   ` [PATCH v3 00/16] Enable lock annotations on most libraries and drivers Thomas Monjalon
  16 siblings, 1 reply; 76+ messages in thread
From: David Marchand @ 2023-04-04 12:48 UTC (permalink / raw)
  To: dev
  Cc: thomas, Chenbo Xia, Anatoly Burakov, Hemant Agrawal,
	Sachin Saxena, Nithin Dabilpuram, Kiran Kumar K,
	Sunil Kumar Kori, Satha Rao, Matan Azrad, Viacheslav Ovsiienko,
	Pavan Nikhilesh, Shijith Thotton, Rasesh Mody, Shahed Shaikh,
	Ajit Khaparde, Somnath Kotur, John Daley, Hyong Youb Kim,
	Gaetan Rivet, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou,
	Dongdong Liu, Yisen Zhuang, Ferruh Yigit, Andrew Rybchenko,
	Konstantin Ananyev, Vladimir Medvedkin, Erik Gabriel Carrillo,
	Maxime Coquelin

Now that a lot of components can be compiled with the lock checks,
invert the logic and opt out for components not ready yet:
- drivers/bus/dpaa,
- drivers/common/cnxk,
- drivers/common/mlx5,
- drivers/event/cnxk,
- drivers/net/bnx2x,
- drivers/net/bnxt,
- drivers/net/cnxk,
- drivers/net/enic,
- drivers/net/hns3,
- drivers/net/mlx5,
- lib/ipsec,
- lib/timer,

The FreeBSD pthread API has been annotated but Linux glibc does not have
those annotations. Disable lock checks for FreeBSD where pthread_mutex_*
are used:
- drivers/net/failsafe,
- drivers/net/hinic,
- lib/eal,
- lib/ethdev,


Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
---
Changes since v2:
- disabled checks on FreeBSD when code relies on pthread mutexes,

---
 doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++--
 drivers/bus/dpaa/meson.build                    | 1 +
 drivers/common/cnxk/meson.build                 | 1 +
 drivers/common/mlx5/meson.build                 | 1 +
 drivers/event/cnxk/meson.build                  | 1 +
 drivers/meson.build                             | 2 +-
 drivers/net/bnx2x/meson.build                   | 1 +
 drivers/net/bnxt/meson.build                    | 1 +
 drivers/net/cnxk/meson.build                    | 1 +
 drivers/net/enic/meson.build                    | 1 +
 drivers/net/failsafe/meson.build                | 4 ++++
 drivers/net/hinic/meson.build                   | 4 ++++
 drivers/net/hns3/meson.build                    | 1 +
 drivers/net/mlx5/meson.build                    | 1 +
 lib/eal/meson.build                             | 4 ++++
 lib/ethdev/meson.build                          | 4 ++++
 lib/ipsec/meson.build                           | 1 +
 lib/meson.build                                 | 2 +-
 lib/timer/meson.build                           | 1 +
 lib/vhost/meson.build                           | 1 -
 20 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
index 3f33621e05..93c8a031be 100644
--- a/doc/guides/prog_guide/env_abstraction_layer.rst
+++ b/doc/guides/prog_guide/env_abstraction_layer.rst
@@ -550,8 +550,9 @@ Some general comments:
   waiving checks with ``__rte_no_thread_safety_analysis`` in your code, please
   discuss it on the mailing list,
 
-A DPDK library/driver can enable/disable the checks by setting
-``annotate_locks`` accordingly in its ``meson.build`` file.
+The checks are enabled by default for libraries and drivers.
+They can be disabled by setting ``annotate_locks`` to ``false`` in
+the concerned library/driver ``meson.build``.
 
 IOVA Mode Detection
 ~~~~~~~~~~~~~~~~~~~
diff --git a/drivers/bus/dpaa/meson.build b/drivers/bus/dpaa/meson.build
index 5506f2bffc..183b251459 100644
--- a/drivers/bus/dpaa/meson.build
+++ b/drivers/bus/dpaa/meson.build
@@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith')
 endif
 
 includes += include_directories('include', 'base/qbman')
+annotate_locks = false
diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
index 402c3249cd..b32fae9f5a 100644
--- a/drivers/common/cnxk/meson.build
+++ b/drivers/common/cnxk/meson.build
@@ -89,3 +89,4 @@ sources += files('cnxk_telemetry_bphy.c',
 
 deps += ['bus_pci', 'net', 'telemetry']
 require_iova_in_mbuf = false
+annotate_locks = false
diff --git a/drivers/common/mlx5/meson.build b/drivers/common/mlx5/meson.build
index 9dc809f192..b5fc4c9346 100644
--- a/drivers/common/mlx5/meson.build
+++ b/drivers/common/mlx5/meson.build
@@ -45,3 +45,4 @@ endif
 mlx5_config = configuration_data()
 subdir(exec_env)
 configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config)
+annotate_locks = false
diff --git a/drivers/event/cnxk/meson.build b/drivers/event/cnxk/meson.build
index 3517e79341..89e1aa860f 100644
--- a/drivers/event/cnxk/meson.build
+++ b/drivers/event/cnxk/meson.build
@@ -480,3 +480,4 @@ endforeach
 
 deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk']
 require_iova_in_mbuf = false
+annotate_locks = false
diff --git a/drivers/meson.build b/drivers/meson.build
index b85bec235d..74ae8cb96b 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -92,7 +92,7 @@ foreach subpath:subdirs
         build = true # set to false to disable, e.g. missing deps
         reason = '<unknown reason>' # set if build == false to explain
         name = drv
-        annotate_locks = false
+        annotate_locks = true
         sources = []
         headers = []
         driver_sdk_headers = [] # public headers included by drivers
diff --git a/drivers/net/bnx2x/meson.build b/drivers/net/bnx2x/meson.build
index 156f97d31f..dbf9c7225d 100644
--- a/drivers/net/bnx2x/meson.build
+++ b/drivers/net/bnx2x/meson.build
@@ -21,3 +21,4 @@ sources = files(
         'ecore_sp.c',
         'elink.c',
 )
+annotate_locks = false
diff --git a/drivers/net/bnxt/meson.build b/drivers/net/bnxt/meson.build
index 0288ed6262..72d4f82e7c 100644
--- a/drivers/net/bnxt/meson.build
+++ b/drivers/net/bnxt/meson.build
@@ -72,3 +72,4 @@ if arch_subdir == 'x86'
 elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64')
     sources += files('bnxt_rxtx_vec_neon.c')
 endif
+annotate_locks = false
diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
index 8b5773ce65..abece91e40 100644
--- a/drivers/net/cnxk/meson.build
+++ b/drivers/net/cnxk/meson.build
@@ -197,3 +197,4 @@ endforeach
 headers = files('rte_pmd_cnxk.h')
 
 require_iova_in_mbuf = false
+annotate_locks = false
diff --git a/drivers/net/enic/meson.build b/drivers/net/enic/meson.build
index 0a0992c3cb..bde7428953 100644
--- a/drivers/net/enic/meson.build
+++ b/drivers/net/enic/meson.build
@@ -43,3 +43,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64')
             c_args: [cflags, '-mavx2'])
     objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c')
 endif
+annotate_locks = false
diff --git a/drivers/net/failsafe/meson.build b/drivers/net/failsafe/meson.build
index 3066d37995..6013e13722 100644
--- a/drivers/net/failsafe/meson.build
+++ b/drivers/net/failsafe/meson.build
@@ -29,3 +29,7 @@ sources = files(
 )
 
 require_iova_in_mbuf = false
+
+if is_freebsd
+    annotate_locks = false
+endif
diff --git a/drivers/net/hinic/meson.build b/drivers/net/hinic/meson.build
index dbcf177782..8242e0052e 100644
--- a/drivers/net/hinic/meson.build
+++ b/drivers/net/hinic/meson.build
@@ -18,3 +18,7 @@ sources = files(
 )
 
 includes += include_directories('base')
+
+if is_freebsd
+    annotate_locks = false
+endif
diff --git a/drivers/net/hns3/meson.build b/drivers/net/hns3/meson.build
index 97cb85dcc8..7dcf21f72a 100644
--- a/drivers/net/hns3/meson.build
+++ b/drivers/net/hns3/meson.build
@@ -32,6 +32,7 @@ sources = files(
         'hns3_common.c',
         'hns3_dump.c',
 )
+annotate_locks = false
 
 require_iova_in_mbuf = false
 
diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
index dba911693e..3184a41a25 100644
--- a/drivers/net/mlx5/meson.build
+++ b/drivers/net/mlx5/meson.build
@@ -82,3 +82,4 @@ testpmd_sources += files('mlx5_testpmd.c')
 subdir(exec_env)
 
 subdir('hws')
+annotate_locks = false
diff --git a/lib/eal/meson.build b/lib/eal/meson.build
index 056beb9461..9aa941a5ae 100644
--- a/lib/eal/meson.build
+++ b/lib/eal/meson.build
@@ -32,3 +32,7 @@ endif
 if cc.has_function('getentropy', prefix : '#include <unistd.h>')
     cflags += '-DRTE_LIBEAL_USE_GETENTROPY'
 endif
+
+if is_freebsd
+    annotate_locks = false
+endif
diff --git a/lib/ethdev/meson.build b/lib/ethdev/meson.build
index 9e97f05983..1ba0fac5c0 100644
--- a/lib/ethdev/meson.build
+++ b/lib/ethdev/meson.build
@@ -44,3 +44,7 @@ driver_sdk_headers += files(
 )
 
 deps += ['net', 'kvargs', 'meter', 'telemetry']
+
+if is_freebsd
+    annotate_locks = false
+endif
diff --git a/lib/ipsec/meson.build b/lib/ipsec/meson.build
index 0b8b935cd2..ff44d6fbdf 100644
--- a/lib/ipsec/meson.build
+++ b/lib/ipsec/meson.build
@@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c',
 
 headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h')
 indirect_headers += files('rte_ipsec_group.h')
+annotate_locks = false
 
 deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
diff --git a/lib/meson.build b/lib/meson.build
index 0812ce6026..dc8aa4ac84 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -121,7 +121,7 @@ foreach l:libraries
     reason = '<unknown reason>' # set if build == false to explain why
     name = l
     use_function_versioning = false
-    annotate_locks = false
+    annotate_locks = true
     sources = []
     headers = []
     indirect_headers = [] # public headers not directly included by apps
diff --git a/lib/timer/meson.build b/lib/timer/meson.build
index 89b17e0397..87bbb10592 100644
--- a/lib/timer/meson.build
+++ b/lib/timer/meson.build
@@ -3,3 +3,4 @@
 
 sources = files('rte_timer.c')
 headers = files('rte_timer.h')
+annotate_locks = false
diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build
index 197a51d936..0d1abf6283 100644
--- a/lib/vhost/meson.build
+++ b/lib/vhost/meson.build
@@ -18,7 +18,6 @@ endif
 dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h'))
 cflags += '-fno-strict-aliasing'
 
-annotate_locks = true
 sources = files(
         'fd_man.c',
         'iotlb.c',
-- 
2.39.2


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v3 15/16] eal/windows: disable lock check on alarm code
  2023-04-04 12:48   ` [PATCH v3 15/16] eal/windows: disable lock check on alarm code David Marchand
@ 2023-04-04 16:08     ` Tyler Retzlaff
  2023-04-04 21:02     ` Dmitry Kozlyuk
  1 sibling, 0 replies; 76+ messages in thread
From: Tyler Retzlaff @ 2023-04-04 16:08 UTC (permalink / raw)
  To: David Marchand
  Cc: dev, thomas, Dmitry Kozlyuk, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam

On Tue, Apr 04, 2023 at 02:48:39PM +0200, David Marchand wrote:
> This code uses locks to implement synchronisation between two threads.
> There seems nothing wrong with it, just silence the clang lock check.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v3 15/16] eal/windows: disable lock check on alarm code
  2023-04-04 12:48   ` [PATCH v3 15/16] eal/windows: disable lock check on alarm code David Marchand
  2023-04-04 16:08     ` Tyler Retzlaff
@ 2023-04-04 21:02     ` Dmitry Kozlyuk
  1 sibling, 0 replies; 76+ messages in thread
From: Dmitry Kozlyuk @ 2023-04-04 21:02 UTC (permalink / raw)
  To: David Marchand
  Cc: dev, thomas, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

On Tue, Apr 4, 2023 at 3:49 PM David Marchand <david.marchand@redhat.com> wrote:
>
> This code uses locks to implement synchronisation between two threads.
> There seems nothing wrong with it, just silence the clang lock check.
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v3 16/16] enable lock check
  2023-04-04 12:48   ` [PATCH v3 16/16] enable lock check David Marchand
@ 2023-04-11  3:21     ` Sachin Saxena (OSS)
  0 siblings, 0 replies; 76+ messages in thread
From: Sachin Saxena (OSS) @ 2023-04-11  3:21 UTC (permalink / raw)
  To: David Marchand, dev
  Cc: thomas, Chenbo Xia, Anatoly Burakov, Hemant Agrawal,
	Sachin Saxena, Nithin Dabilpuram, Kiran Kumar K,
	Sunil Kumar Kori, Satha Rao, Matan Azrad, Viacheslav Ovsiienko,
	Pavan Nikhilesh, Shijith Thotton, Rasesh Mody, Shahed Shaikh,
	Ajit Khaparde, Somnath Kotur, John Daley, Hyong Youb Kim,
	Gaetan Rivet, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou,
	Dongdong Liu, Yisen Zhuang, Ferruh Yigit, Andrew Rybchenko,
	Konstantin Ananyev, Vladimir Medvedkin, Erik Gabriel Carrillo,
	Maxime Coquelin

On 4/4/2023 6:18 PM, David Marchand wrote:
> Now that a lot of components can be compiled with the lock checks,
> invert the logic and opt out for components not ready yet:
> - drivers/bus/dpaa,
> - drivers/common/cnxk,
> - drivers/common/mlx5,
> - drivers/event/cnxk,
> - drivers/net/bnx2x,
> - drivers/net/bnxt,
> - drivers/net/cnxk,
> - drivers/net/enic,
> - drivers/net/hns3,
> - drivers/net/mlx5,
> - lib/ipsec,
> - lib/timer,
> 
> The FreeBSD pthread API has been annotated but Linux glibc does not have
> those annotations. Disable lock checks for FreeBSD where pthread_mutex_*
> are used:
> - drivers/net/failsafe,
> - drivers/net/hinic,
> - lib/eal,
> - lib/ethdev,
> 
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
> ---
> Changes since v2:
> - disabled checks on FreeBSD when code relies on pthread mutexes,
> 
> ---
>   doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++--
>   drivers/bus/dpaa/meson.build                    | 1 +
>   drivers/common/cnxk/meson.build                 | 1 +
>   drivers/common/mlx5/meson.build                 | 1 +
>   drivers/event/cnxk/meson.build                  | 1 +
>   drivers/meson.build                             | 2 +-
>   drivers/net/bnx2x/meson.build                   | 1 +
>   drivers/net/bnxt/meson.build                    | 1 +
>   drivers/net/cnxk/meson.build                    | 1 +
>   drivers/net/enic/meson.build                    | 1 +
>   drivers/net/failsafe/meson.build                | 4 ++++
>   drivers/net/hinic/meson.build                   | 4 ++++
>   drivers/net/hns3/meson.build                    | 1 +
>   drivers/net/mlx5/meson.build                    | 1 +
>   lib/eal/meson.build                             | 4 ++++
>   lib/ethdev/meson.build                          | 4 ++++
>   lib/ipsec/meson.build                           | 1 +
>   lib/meson.build                                 | 2 +-
>   lib/timer/meson.build                           | 1 +
>   lib/vhost/meson.build                           | 1 -
>   20 files changed, 33 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
> index 3f33621e05..93c8a031be 100644
> --- a/doc/guides/prog_guide/env_abstraction_layer.rst
> +++ b/doc/guides/prog_guide/env_abstraction_layer.rst
> @@ -550,8 +550,9 @@ Some general comments:
>     waiving checks with ``__rte_no_thread_safety_analysis`` in your code, please
>     discuss it on the mailing list,
>   
> -A DPDK library/driver can enable/disable the checks by setting
> -``annotate_locks`` accordingly in its ``meson.build`` file.
> +The checks are enabled by default for libraries and drivers.
> +They can be disabled by setting ``annotate_locks`` to ``false`` in
> +the concerned library/driver ``meson.build``.
>   
>   IOVA Mode Detection
>   ~~~~~~~~~~~~~~~~~~~
> diff --git a/drivers/bus/dpaa/meson.build b/drivers/bus/dpaa/meson.build
> index 5506f2bffc..183b251459 100644
> --- a/drivers/bus/dpaa/meson.build
> +++ b/drivers/bus/dpaa/meson.build
> @@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith')
>   endif
>   
>   includes += include_directories('include', 'base/qbman')
> +annotate_locks = false


Acked-by: Sachin Saxena <sachin.saxena@oss.nxp.com>




> diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
> index 402c3249cd..b32fae9f5a 100644
> --- a/drivers/common/cnxk/meson.build
> +++ b/drivers/common/cnxk/meson.build
> @@ -89,3 +89,4 @@ sources += files('cnxk_telemetry_bphy.c',
>   
>   deps += ['bus_pci', 'net', 'telemetry']
>   require_iova_in_mbuf = false
> +annotate_locks = false
> diff --git a/drivers/common/mlx5/meson.build b/drivers/common/mlx5/meson.build
> index 9dc809f192..b5fc4c9346 100644
> --- a/drivers/common/mlx5/meson.build
> +++ b/drivers/common/mlx5/meson.build
> @@ -45,3 +45,4 @@ endif
>   mlx5_config = configuration_data()
>   subdir(exec_env)
>   configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config)
> +annotate_locks = false
> diff --git a/drivers/event/cnxk/meson.build b/drivers/event/cnxk/meson.build
> index 3517e79341..89e1aa860f 100644
> --- a/drivers/event/cnxk/meson.build
> +++ b/drivers/event/cnxk/meson.build
> @@ -480,3 +480,4 @@ endforeach
>   
>   deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk']
>   require_iova_in_mbuf = false
> +annotate_locks = false
> diff --git a/drivers/meson.build b/drivers/meson.build
> index b85bec235d..74ae8cb96b 100644
> --- a/drivers/meson.build
> +++ b/drivers/meson.build
> @@ -92,7 +92,7 @@ foreach subpath:subdirs
>           build = true # set to false to disable, e.g. missing deps
>           reason = '<unknown reason>' # set if build == false to explain
>           name = drv
> -        annotate_locks = false
> +        annotate_locks = true
>           sources = []
>           headers = []
>           driver_sdk_headers = [] # public headers included by drivers
> diff --git a/drivers/net/bnx2x/meson.build b/drivers/net/bnx2x/meson.build
> index 156f97d31f..dbf9c7225d 100644
> --- a/drivers/net/bnx2x/meson.build
> +++ b/drivers/net/bnx2x/meson.build
> @@ -21,3 +21,4 @@ sources = files(
>           'ecore_sp.c',
>           'elink.c',
>   )
> +annotate_locks = false
> diff --git a/drivers/net/bnxt/meson.build b/drivers/net/bnxt/meson.build
> index 0288ed6262..72d4f82e7c 100644
> --- a/drivers/net/bnxt/meson.build
> +++ b/drivers/net/bnxt/meson.build
> @@ -72,3 +72,4 @@ if arch_subdir == 'x86'
>   elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64')
>       sources += files('bnxt_rxtx_vec_neon.c')
>   endif
> +annotate_locks = false
> diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
> index 8b5773ce65..abece91e40 100644
> --- a/drivers/net/cnxk/meson.build
> +++ b/drivers/net/cnxk/meson.build
> @@ -197,3 +197,4 @@ endforeach
>   headers = files('rte_pmd_cnxk.h')
>   
>   require_iova_in_mbuf = false
> +annotate_locks = false
> diff --git a/drivers/net/enic/meson.build b/drivers/net/enic/meson.build
> index 0a0992c3cb..bde7428953 100644
> --- a/drivers/net/enic/meson.build
> +++ b/drivers/net/enic/meson.build
> @@ -43,3 +43,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64')
>               c_args: [cflags, '-mavx2'])
>       objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c')
>   endif
> +annotate_locks = false
> diff --git a/drivers/net/failsafe/meson.build b/drivers/net/failsafe/meson.build
> index 3066d37995..6013e13722 100644
> --- a/drivers/net/failsafe/meson.build
> +++ b/drivers/net/failsafe/meson.build
> @@ -29,3 +29,7 @@ sources = files(
>   )
>   
>   require_iova_in_mbuf = false
> +
> +if is_freebsd
> +    annotate_locks = false
> +endif
> diff --git a/drivers/net/hinic/meson.build b/drivers/net/hinic/meson.build
> index dbcf177782..8242e0052e 100644
> --- a/drivers/net/hinic/meson.build
> +++ b/drivers/net/hinic/meson.build
> @@ -18,3 +18,7 @@ sources = files(
>   )
>   
>   includes += include_directories('base')
> +
> +if is_freebsd
> +    annotate_locks = false
> +endif
> diff --git a/drivers/net/hns3/meson.build b/drivers/net/hns3/meson.build
> index 97cb85dcc8..7dcf21f72a 100644
> --- a/drivers/net/hns3/meson.build
> +++ b/drivers/net/hns3/meson.build
> @@ -32,6 +32,7 @@ sources = files(
>           'hns3_common.c',
>           'hns3_dump.c',
>   )
> +annotate_locks = false
>   
>   require_iova_in_mbuf = false
>   
> diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
> index dba911693e..3184a41a25 100644
> --- a/drivers/net/mlx5/meson.build
> +++ b/drivers/net/mlx5/meson.build
> @@ -82,3 +82,4 @@ testpmd_sources += files('mlx5_testpmd.c')
>   subdir(exec_env)
>   
>   subdir('hws')
> +annotate_locks = false
> diff --git a/lib/eal/meson.build b/lib/eal/meson.build
> index 056beb9461..9aa941a5ae 100644
> --- a/lib/eal/meson.build
> +++ b/lib/eal/meson.build
> @@ -32,3 +32,7 @@ endif
>   if cc.has_function('getentropy', prefix : '#include <unistd.h>')
>       cflags += '-DRTE_LIBEAL_USE_GETENTROPY'
>   endif
> +
> +if is_freebsd
> +    annotate_locks = false
> +endif
> diff --git a/lib/ethdev/meson.build b/lib/ethdev/meson.build
> index 9e97f05983..1ba0fac5c0 100644
> --- a/lib/ethdev/meson.build
> +++ b/lib/ethdev/meson.build
> @@ -44,3 +44,7 @@ driver_sdk_headers += files(
>   )
>   
>   deps += ['net', 'kvargs', 'meter', 'telemetry']
> +
> +if is_freebsd
> +    annotate_locks = false
> +endif
> diff --git a/lib/ipsec/meson.build b/lib/ipsec/meson.build
> index 0b8b935cd2..ff44d6fbdf 100644
> --- a/lib/ipsec/meson.build
> +++ b/lib/ipsec/meson.build
> @@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c',
>   
>   headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h')
>   indirect_headers += files('rte_ipsec_group.h')
> +annotate_locks = false
>   
>   deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
> diff --git a/lib/meson.build b/lib/meson.build
> index 0812ce6026..dc8aa4ac84 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -121,7 +121,7 @@ foreach l:libraries
>       reason = '<unknown reason>' # set if build == false to explain why
>       name = l
>       use_function_versioning = false
> -    annotate_locks = false
> +    annotate_locks = true
>       sources = []
>       headers = []
>       indirect_headers = [] # public headers not directly included by apps
> diff --git a/lib/timer/meson.build b/lib/timer/meson.build
> index 89b17e0397..87bbb10592 100644
> --- a/lib/timer/meson.build
> +++ b/lib/timer/meson.build
> @@ -3,3 +3,4 @@
>   
>   sources = files('rte_timer.c')
>   headers = files('rte_timer.h')
> +annotate_locks = false
> diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build
> index 197a51d936..0d1abf6283 100644
> --- a/lib/vhost/meson.build
> +++ b/lib/vhost/meson.build
> @@ -18,7 +18,6 @@ endif
>   dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h'))
>   cflags += '-fno-strict-aliasing'
>   
> -annotate_locks = true
>   sources = files(
>           'fd_man.c',
>           'iotlb.c',

-- 
Thanks,
Sachin Saxena
(NXP)


^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH v3 00/16] Enable lock annotations on most libraries and drivers
  2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
                     ` (15 preceding siblings ...)
  2023-04-04 12:48   ` [PATCH v3 16/16] enable lock check David Marchand
@ 2023-04-23 20:09   ` Thomas Monjalon
  16 siblings, 0 replies; 76+ messages in thread
From: Thomas Monjalon @ 2023-04-23 20:09 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

04/04/2023 14:48, David Marchand:
> This is a followup of the series that introduced lock annotations.
> I reworked and made annotations work in what seemed the easier cases.
> In most cases, I chose to convert inline wrappers around the EAL lock
> API to simple macro: I did not see much value in those wrappers and this
> is way simpler than adding __rte_*lock_function tags everywhere.
> 
> A list of libraries and drivers still need more work as their code have
> non obvious locks handling. For those components, the check is opted
> out.
> I leave it to their respective maintainers to enable the checks later.

Some drivers require some effort to enable the lock checks at compilation:
	bnx2x, bnxt, cnxk, dpaa, enic, failsafe, hinic, hns3, mlx5

> FreeBSD libc pthread API has lock annotations while Linux glibc has
> none. Until we get a proper abstraction for mutexes, the simpler is
> to disable the check on FreeBSD.
> 
> Maintainers, please review.

Applied, thanks.



^ permalink raw reply	[flat|nested] 76+ messages in thread

end of thread, other threads:[~2023-04-23 20:09 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24  8:16 [PATCH 00/14] Enable lock annotations on most libraries and drivers David Marchand
2023-02-24  8:16 ` [PATCH 01/14] malloc: rework heap lock handling David Marchand
2023-02-24  8:16 ` [PATCH 02/14] mem: rework malloc heap init David Marchand
2023-02-24  8:16 ` [PATCH 03/14] mem: annotate shared memory config locks David Marchand
2023-02-24  8:16 ` [PATCH 04/14] hash: annotate cuckoo hash lock David Marchand
2023-02-24  8:16 ` [PATCH 05/14] graph: annotate graph lock David Marchand
2023-02-24  8:16 ` [PATCH 06/14] drivers: inherit lock annotations for Intel drivers David Marchand
2023-02-24  8:16 ` [PATCH 07/14] net/cxgbe: inherit lock annotations David Marchand
2023-02-24  8:16 ` [PATCH 08/14] net/fm10k: annotate mailbox lock David Marchand
2023-02-24  8:16 ` [PATCH 09/14] net/sfc: rework locking in proxy code David Marchand
2023-02-24  8:16 ` [PATCH 10/14] net/sfc: inherit lock annotations David Marchand
2023-02-24  8:16 ` [PATCH 11/14] net/virtio: annotate lock for guest announce David Marchand
2023-02-24  8:16 ` [PATCH 12/14] raw/ifpga: inherit lock annotations David Marchand
2023-02-24  8:16 ` [PATCH 13/14] vdpa/sfc: " David Marchand
2023-02-24  8:16 ` [PATCH 14/14] enable lock check David Marchand
2023-02-24 15:11 ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers David Marchand
2023-02-24 15:11   ` [PATCH v2 01/20] malloc: rework heap lock handling David Marchand
2023-02-24 15:11   ` [PATCH v2 02/20] mem: rework malloc heap init David Marchand
2023-02-24 15:11   ` [PATCH v2 03/20] mem: annotate shared memory config locks David Marchand
2023-02-24 15:11   ` [PATCH v2 04/20] hash: annotate cuckoo hash lock David Marchand
2023-02-24 15:11   ` [PATCH v2 05/20] graph: annotate graph lock David Marchand
2023-02-24 15:11   ` [PATCH v2 06/20] drivers: inherit lock annotations for Intel drivers David Marchand
2023-02-24 15:11   ` [PATCH v2 07/20] net/cxgbe: inherit lock annotations David Marchand
2023-02-24 15:11   ` [PATCH v2 08/20] net/fm10k: annotate mailbox lock David Marchand
2023-02-24 15:11   ` [PATCH v2 09/20] net/sfc: rework locking in proxy code David Marchand
2023-02-24 15:11   ` [PATCH v2 10/20] net/sfc: inherit lock annotations David Marchand
2023-02-24 15:11   ` [PATCH v2 11/20] net/virtio: annotate lock for guest announce David Marchand
2023-02-27  2:05     ` Xia, Chenbo
2023-02-27  8:24       ` David Marchand
2023-02-27 16:28         ` Maxime Coquelin
2023-02-28  2:45           ` Xia, Chenbo
2023-03-02  9:26           ` David Marchand
2023-03-02  9:28             ` Maxime Coquelin
2023-03-02 12:35               ` David Marchand
2023-02-24 15:11   ` [PATCH v2 12/20] raw/ifpga: inherit lock annotations David Marchand
2023-02-27  6:29     ` Xu, Rosen
2023-02-27  7:15       ` Huang, Wei
2023-02-24 15:11   ` [PATCH v2 13/20] vdpa/sfc: " David Marchand
2023-02-24 15:11   ` [PATCH v2 14/20] ipc: annotate pthread mutex David Marchand
2023-02-24 15:11   ` [PATCH v2 15/20] ethdev: " David Marchand
2023-02-24 15:11   ` [PATCH v2 16/20] net/failsafe: fix mutex locking David Marchand
2023-02-24 15:35     ` Gaëtan Rivet
2023-02-24 15:11   ` [PATCH v2 17/20] net/failsafe: annotate pthread mutex David Marchand
2023-02-24 15:11   ` [PATCH v2 18/20] net/hinic: " David Marchand
2023-02-24 15:11   ` [PATCH v2 19/20] eal/windows: disable lock check on alarm code David Marchand
2023-02-24 15:11   ` [PATCH v2 20/20] enable lock check David Marchand
2023-02-27  2:32     ` Xia, Chenbo
2023-02-24 15:58   ` [PATCH v2 00/20] Enable lock annotations on most libraries and drivers Gaëtan Rivet
2023-02-25 10:16     ` David Marchand
2023-02-27 16:12       ` Gaëtan Rivet
2023-03-02  8:52         ` David Marchand
2023-04-03 10:52           ` David Marchand
2023-04-03 15:03             ` Tyler Retzlaff
2023-04-03 15:36             ` Tyler Retzlaff
2023-04-04  7:45               ` David Marchand
2023-04-04 12:48 ` [PATCH v3 00/16] " David Marchand
2023-04-04 12:48   ` [PATCH v3 01/16] malloc: rework heap destroy David Marchand
2023-04-04 12:48   ` [PATCH v3 02/16] mem: rework malloc heap init David Marchand
2023-04-04 12:48   ` [PATCH v3 03/16] mem: annotate shared memory config locks David Marchand
2023-04-04 12:48   ` [PATCH v3 04/16] hash: annotate cuckoo hash lock David Marchand
2023-04-04 12:48   ` [PATCH v3 05/16] graph: annotate graph lock David Marchand
2023-04-04 12:48   ` [PATCH v3 06/16] drivers: inherit lock annotations for Intel drivers David Marchand
2023-04-04 12:48   ` [PATCH v3 07/16] net/cxgbe: inherit lock annotations David Marchand
2023-04-04 12:48   ` [PATCH v3 08/16] net/fm10k: annotate mailbox lock David Marchand
2023-04-04 12:48   ` [PATCH v3 09/16] net/sfc: rework locking in proxy code David Marchand
2023-04-04 12:48   ` [PATCH v3 10/16] net/sfc: inherit lock annotations David Marchand
2023-04-04 12:48   ` [PATCH v3 11/16] net/virtio: rework guest announce notify helper David Marchand
2023-04-04 12:48   ` [PATCH v3 12/16] raw/ifpga: inherit lock annotations David Marchand
2023-04-04 12:48   ` [PATCH v3 13/16] vdpa/sfc: " David Marchand
2023-04-04 12:48   ` [PATCH v3 14/16] net/failsafe: fix mutex locking David Marchand
2023-04-04 12:48   ` [PATCH v3 15/16] eal/windows: disable lock check on alarm code David Marchand
2023-04-04 16:08     ` Tyler Retzlaff
2023-04-04 21:02     ` Dmitry Kozlyuk
2023-04-04 12:48   ` [PATCH v3 16/16] enable lock check David Marchand
2023-04-11  3:21     ` Sachin Saxena (OSS)
2023-04-23 20:09   ` [PATCH v3 00/16] Enable lock annotations on most libraries and drivers Thomas Monjalon

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).