Improve lock annotations
cover Improve lock annotations
A recent bug (see 22aa9a9c7099 ("vhost: fix deadlock in Rx async path")) made more visible a gap in the clang thread safety annotations that DPDK uses: no distinction is made between releasing a read lock and releasing a write lock.
Clang 3.6 and later offers improved thread safety checks.
Marking objects as "lockable" has evolved into flagging some named "capability". clang reports the capability name when an error is reported (making this report a bit easier to understand).
For example, a spinlock is now flagged as:
typedef struct __rte_capability("spinlock") {
volatile RTE_ATOMIC(int) locked;
} rte_spinlock_t;
For "exclusive" locking (spinlocks / write locks), the conversion is:
- exclusive_lock_function -> acquire_capability
- exclusive_trylock_function -> try_acquire_capability
- unlock_function -> release_capability
...
For "shared" locking (read locks):
- shared_lock_function -> acquire_shared_capability
- shared_trylock_function -> try_acquire_shared_capability
- unlock_function -> release_shared_capability
...
This RFC proposes to use those annotations (sticking to the convention of simply prefixing the compiler attributes with __rte_). The existing "old" annotations macros are left in place in case users started to rely on them.
Note: DPDK requirements state that clang version must be >= 3.6 (following use of C11 standard).
No check about availability of the new attributes has been added to this series, let's see what the CI thinks of this assumption...
Comments welcome.
Signature · 33 lines
David Marchand David Marchand (3): eal: add enhanced lock annotations eal: enhance lock annotations for spinlock and seqlock eal: enhance lock annotations for rwlock doc/api/doxy-api.conf.in | 12 ++ drivers/bus/dpaa/base/qbman/qman.c | 4 +- drivers/net/fm10k/fm10k_ethdev.c | 4 +- lib/eal/common/eal_memalloc.h | 2 +- lib/eal/common/eal_private.h | 2 +- lib/eal/include/generic/rte_rwlock.h | 23 ++-- lib/eal/include/generic/rte_spinlock.h | 14 +- lib/eal/include/rte_eal_memconfig.h | 28 ++-- lib/eal/include/rte_lock_annotations.h | 48 +++++++ lib/eal/include/rte_seqlock.h | 4 +- lib/ethdev/ethdev_driver.c | 4 +- lib/ethdev/ethdev_private.h | 4 +- lib/ethdev/rte_ethdev.c | 4 +- lib/graph/graph_private.h | 4 +- lib/hash/rte_cuckoo_hash.c | 8 +- lib/vhost/iotlb.h | 8 +- lib/vhost/vdpa.c | 2 +- lib/vhost/vhost.c | 10 +- lib/vhost/vhost.h | 24 ++-- lib/vhost/vhost_crypto.c | 14 +- lib/vhost/virtio_net.c | 170 ++++++++++++------------- lib/vhost/virtio_net_ctrl.c | 2 +- 22 files changed, 228 insertions(+), 167 deletions(-) -- 2.47.0
RFC 1/3 eal: add enhanced lock annotations
Clang 3.6+ offers enhanced lock annotations when it comes to shared vs exclusive capability/lock release.
Introduce macros for those new function attributes.
--- doc/api/doxy-api.conf.in | 12 +++++++ lib/eal/include/rte_lock_annotations.h | 48 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
doc/api/doxy-api.conf.in +12 -0
@@ -103,6 +103,18 @@ PREDEFINED = __DOXYGEN__ \ __rte_shared_trylock_function(x)= \ __rte_assert_shared_lock(x)= \ __rte_unlock_function(x)= \ + __rte_capability(x)= \ + __rte_requires_capability(x)= \ + __rte_acquire_capability(x)= \ + __rte_try_acquire_capability(x)= \ + __rte_release_capability(x)= \ + __rte_assert_capability(x)= \ + __rte_requires_shared_capability(x)= \ + __rte_acquire_shared_capability(x)= \ + __rte_try_acquire_shared_capability(x)= \ + __rte_release_shared_capability(x)= \ + __rte_assert_shared_capability(x)= \ + __rte_exclude_capability(x)= \ __attribute__(x)= OPTIMIZE_OUTPUT_FOR_C = YES
lib/eal/include/rte_lock_annotations.h +48 -0
60 lines not on this page · raw message
Signature · 1 line
2.47.0
Re: [RFC 1/3] eal: add enhanced lock annotations
Quoted 11 lines · On Mon, 2 Dec 2024 13:53:14 +0100 David Marchand <[email protected]>…
doc/api/doxy-api.conf.in +3
-0@@ -103,6 +103,18 @@ PREDEFINED = __DOXYGEN__ \ __rte_shared_trylock_function(x)= \ __rte_assert_shared_lock(x)= \ __rte_unlock_function(x)= \ + __rte_capability(x)= \ + __rte_requires_capability(x)= \ + __rte_acquire_capability(x)= \
doc/api/doxy-api.conf.in PREDEFINED = __DOXYGEN__ \ · line 118
Quoted 10 lines
doc/api/doxy-api.conf.in +9
-0+ __rte_try_acquire_capability(x)= \ + __rte_release_capability(x)= \ + __rte_assert_capability(x)= \ + __rte_requires_shared_capability(x)= \ + __rte_acquire_shared_capability(x)= \ + __rte_try_acquire_shared_capability(x)= \ + __rte_release_shared_capability(x)= \ + __rte_assert_shared_capability(x)= \ + __rte_exclude_capability(x)= \ __attribute__(x)=
I would suggest shortened names:
__rte_acquires(x) __rte_releases(x) __rte_must_hold(x)
Based on the original source of all these lock annotations which is sparse.
RFC 2/3 eal: enhance lock annotations for spinlock and seqlock
In reply to David MarchandConvert spinlock (and as a consequence seqlock) to the clang capability annotations.
--- drivers/bus/dpaa/base/qbman/qman.c | 4 ++-- drivers/net/fm10k/fm10k_ethdev.c | 4 ++-- lib/eal/include/generic/rte_spinlock.h | 14 +++++++------- lib/eal/include/rte_eal_memconfig.h | 4 ++-- lib/eal/include/rte_seqlock.h | 4 ++-- lib/graph/graph_private.h | 4 ++-- lib/vhost/vdpa.c | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-)
drivers/bus/dpaa/base/qbman/qman.c +2 -2
@@ -45,7 +45,7 @@ static inline int fq_isset(struct qman_fq *fq, u32 mask) }static inline void fq_lock (struct qman_fq *fq) - __rte_exclusive_lock_function(&fq->fqlock) + __rte_acquire_capability(&fq->fqlock) __rte_no_thread_safety_analysis {if (fq_isset (fq,QMAN_FQ_FLAG_LOCKED ))
@@ -53,7 +53,7 @@ static inline void fq_lock(struct qman_fq *fq) }static inline void fq_unlock (struct qman_fq *fq) - __rte_unlock_function(&fq->fqlock) + __rte_release_capability(&fq->fqlock) __rte_no_thread_safety_analysis {if (fq_isset (fq,QMAN_FQ_FLAG_LOCKED ))
drivers/net/fm10k/fm10k_ethdev.c +2 -2
@@ -116,7 +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)) + __rte_acquire_capability(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 );
@@ -124,7 +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_release_capability(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {rte_spinlock_unlock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)); }
lib/eal/include/generic/rte_spinlock.h +7 -7
@@ -32,7 +32,7 @@ extern "C" {/** * The rte_spinlock_t type. */ -typedef struct __rte_lockable { +typedef struct __rte_capability("spinlock") {volatile RTE_ATOMIC (int ) locked;/**< lock status 0 = unlocked, 1 = locked */ } rte_spinlock_t;
@@ -61,7 +61,7 @@ rte_spinlock_init(rte_spinlock_t *sl)*/ static inline void rte_spinlock_lock(rte_spinlock_t *sl) - __rte_exclusive_lock_function(sl); + __rte_acquire_capability(sl);#ifdef RTE_FORCE_INTRINSICS static inline void
@@ -87,7 +87,7 @@ rte_spinlock_lock(rte_spinlock_t *sl)*/ static inline void rte_spinlock_unlock(rte_spinlock_t *sl) - __rte_unlock_function(sl); + __rte_release_capability(sl);#ifdef RTE_FORCE_INTRINSICS static inline void
@@ -109,7 +109,7 @@ rte_spinlock_unlock(rte_spinlock_t *sl)__rte_warn_unused_result static inline int rte_spinlock_trylock(rte_spinlock_t *sl) - __rte_exclusive_trylock_function(1, sl); + __rte_try_acquire_capability(true, sl); #ifdef RTE_FORCE_INTRINSICS static inline int
@@ -158,7 +158,7 @@ static inline int rte_tm_supported(void);*/ static inline void rte_spinlock_lock_tm(rte_spinlock_t *sl) - __rte_exclusive_lock_function(sl); + __rte_acquire_capability(sl);/** * Commit hardware memory transaction or release the spinlock if
@@ -169,7 +169,7 @@ rte_spinlock_lock_tm(rte_spinlock_t *sl)*/ static inline void rte_spinlock_unlock_tm(rte_spinlock_t *sl) - __rte_unlock_function(sl); + __rte_release_capability(sl);/** * Try to execute critical section in a hardware memory transaction,
@@ -190,7 +190,7 @@ rte_spinlock_unlock_tm(rte_spinlock_t *sl) __rte_warn_unused_result static inline int rte_spinlock_trylock_tm(rte_spinlock_t *sl) - __rte_exclusive_trylock_function(1, sl); + __rte_try_acquire_capability(true, sl);/** * The rte_spinlock_recursive_t type.
lib/eal/include/rte_eal_memconfig.h +2 -2
@@ -132,14 +132,14 @@ rte_mcfg_mempool_write_unlock(void)*/ void rte_mcfg_timer_lock(void) - __rte_exclusive_lock_function(rte_mcfg_timer_get_lock()); + __rte_acquire_capability(rte_mcfg_timer_get_lock());/** * Unlock the internal EAL Timer Library lock for exclusive access. */ void rte_mcfg_timer_unlock(void) - __rte_unlock_function(rte_mcfg_timer_get_lock()); + __rte_release_capability(rte_mcfg_timer_get_lock());/** * If true, pages are put in single files (per memseg list),
lib/eal/include/rte_seqlock.h +2 -2
@@ -197,7 +197,7 @@ rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint32_t begin_sn)*/ static inline void rte_seqlock_write_lock (rte_seqlock_t *seqlock) - __rte_exclusive_lock_function(&seqlock->lock) + __rte_acquire_capability(&seqlock->lock) {/* To synchronize with other writers. */ rte_spinlock_lock (&seqlock->lock);
@@ -219,7 +219,7 @@ rte_seqlock_write_lock(rte_seqlock_t *seqlock)*/ static inline void rte_seqlock_write_unlock (rte_seqlock_t *seqlock) - __rte_unlock_function(&seqlock->lock) + __rte_release_capability(&seqlock->lock) {rte_seqcount_write_end (&seqlock->count);
lib/graph/graph_private.h +2 -2
@@ -221,7 +221,7 @@ graph_spinlock_get(void);* Take a lock on the graph internal spin lock. */ void graph_spinlock_lock(void) - __rte_exclusive_lock_function(graph_spinlock_get()); + __rte_acquire_capability(graph_spinlock_get());/** * @internal
@@ -229,7 +229,7 @@ void graph_spinlock_lock(void)* Release a lock on the graph internal spin lock. */ void graph_spinlock_unlock(void) - __rte_unlock_function(graph_spinlock_get()); + __rte_release_capability(graph_spinlock_get());/* Graph operations */ /**
lib/vhost/vdpa.c +1 -1
@@ -32,7 +32,7 @@ static struct vdpa_device_list * const vdpa_device_liststatic struct rte_vdpa_device *__vdpa_find_device_by_name (const char *name) - __rte_exclusive_locks_required(&vdpa_device_list_lock) + __rte_requires_capability(&vdpa_device_list_lock) {struct rte_vdpa_device *dev, *ret =NULL ;
Signature · 1 line
2.47.0
Re: [RFC 2/3] eal: enhance lock annotations for spinlock and seqlock
Quoted 3 lines · David Marchand
Convert spinlock (and as a consequence seqlock) to the clang capability annotations.
Quoted 200 lines
Signed-off-by David Marchand <[email protected]>--- drivers/bus/dpaa/base/qbman/qman.c | 4 ++-- drivers/net/fm10k/fm10k_ethdev.c | 4 ++-- lib/eal/include/generic/rte_spinlock.h | 14 +++++++------- lib/eal/include/rte_eal_memconfig.h | 4 ++-- lib/eal/include/rte_seqlock.h | 4 ++-- lib/graph/graph_private.h | 4 ++-- lib/vhost/vdpa.c | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-)drivers/bus/dpaa/base/qbman/qman.c +2
-2@@ -45,7 +45,7 @@ static inline int fq_isset(struct qman_fq *fq, u32 mask) }static inline void fq_lock (struct qman_fq *fq) - __rte_exclusive_lock_function(&fq->fqlock) + __rte_acquire_capability(&fq->fqlock) __rte_no_thread_safety_analysis {if (fq_isset (fq,QMAN_FQ_FLAG_LOCKED ))@@ -53,7 +53,7 @@ static inline void fq_lock(struct qman_fq *fq) }static inline void fq_unlock (struct qman_fq *fq) - __rte_unlock_function(&fq->fqlock) + __rte_release_capability(&fq->fqlock) __rte_no_thread_safety_analysis {if (fq_isset (fq,QMAN_FQ_FLAG_LOCKED ))drivers/net/fm10k/fm10k_ethdev.c +2
-2@@ -116,7 +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)) + __rte_acquire_capability(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 );@@ -124,7 +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_release_capability(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {rte_spinlock_unlock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)); }lib/eal/include/generic/rte_spinlock.h +7
-7@@ -32,7 +32,7 @@ extern "C" {/** * The rte_spinlock_t type. */ -typedef struct __rte_lockable { +typedef struct __rte_capability("spinlock") {volatile RTE_ATOMIC (int ) locked;/**< lock status 0 = unlocked, 1 = locked */ } rte_spinlock_t;@@ -61,7 +61,7 @@ rte_spinlock_init(rte_spinlock_t *sl)*/ static inline void rte_spinlock_lock(rte_spinlock_t *sl) - __rte_exclusive_lock_function(sl); + __rte_acquire_capability(sl);#ifdef RTE_FORCE_INTRINSICS static inline void@@ -87,7 +87,7 @@ rte_spinlock_lock(rte_spinlock_t *sl)*/ static inline void rte_spinlock_unlock(rte_spinlock_t *sl) - __rte_unlock_function(sl); + __rte_release_capability(sl);#ifdef RTE_FORCE_INTRINSICS static inline void@@ -109,7 +109,7 @@ rte_spinlock_unlock(rte_spinlock_t *sl)__rte_warn_unused_result static inline int rte_spinlock_trylock(rte_spinlock_t *sl) - __rte_exclusive_trylock_function(1, sl); + __rte_try_acquire_capability(true, sl); #ifdef RTE_FORCE_INTRINSICS static inline int@@ -158,7 +158,7 @@ static inline int rte_tm_supported(void);*/ static inline void rte_spinlock_lock_tm(rte_spinlock_t *sl) - __rte_exclusive_lock_function(sl); + __rte_acquire_capability(sl);/** * Commit hardware memory transaction or release the spinlock if @@ -169,7 +169,7 @@ rte_spinlock_lock_tm(rte_spinlock_t *sl)*/ static inline void rte_spinlock_unlock_tm(rte_spinlock_t *sl) - __rte_unlock_function(sl); + __rte_release_capability(sl);/** * Try to execute critical section in a hardware memory transaction, @@ -190,7 +190,7 @@ rte_spinlock_unlock_tm(rte_spinlock_t *sl) __rte_warn_unused_result static inline int rte_spinlock_trylock_tm(rte_spinlock_t *sl) - __rte_exclusive_trylock_function(1, sl); + __rte_try_acquire_capability(true, sl);/** * The rte_spinlock_recursive_t type. lib/eal/include/rte_eal_memconfig.h +2
-2@@ -132,14 +132,14 @@ rte_mcfg_mempool_write_unlock(void)*/ void rte_mcfg_timer_lock(void) - __rte_exclusive_lock_function(rte_mcfg_timer_get_lock()); + __rte_acquire_capability(rte_mcfg_timer_get_lock());/** * Unlock the internal EAL Timer Library lock for exclusive access. */ void rte_mcfg_timer_unlock(void) - __rte_unlock_function(rte_mcfg_timer_get_lock()); + __rte_release_capability(rte_mcfg_timer_get_lock());/** * If true, pages are put in single files (per memseg list), lib/eal/include/rte_seqlock.h +2
-2@@ -197,7 +197,7 @@ rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint32_t begin_sn)*/ static inline void rte_seqlock_write_lock (rte_seqlock_t *seqlock) - __rte_exclusive_lock_function(&seqlock->lock) + __rte_acquire_capability(&seqlock->lock) {/* To synchronize with other writers. */ rte_spinlock_lock (&seqlock->lock);@@ -219,7 +219,7 @@ rte_seqlock_write_lock(rte_seqlock_t *seqlock)*/ static inline void rte_seqlock_write_unlock (rte_seqlock_t *seqlock) - __rte_unlock_function(&seqlock->lock) + __rte_release_capability(&seqlock->lock) {rte_seqcount_write_end (&seqlock->count);lib/graph/graph_private.h +2
-2@@ -221,7 +221,7 @@ graph_spinlock_get(void);* Take a lock on the graph internal spin lock. */ void graph_spinlock_lock(void) - __rte_exclusive_lock_function(graph_spinlock_get()); + __rte_acquire_capability(graph_spinlock_get());/** * @internal @@ -229,7 +229,7 @@ void graph_spinlock_lock(void)* Release a lock on the graph internal spin lock. */ void graph_spinlock_unlock(void) - __rte_unlock_function(graph_spinlock_get()); + __rte_release_capability(graph_spinlock_get());/* Graph operations */ /** lib/vhost/vdpa.c +1
-1@@ -32,7 +32,7 @@ static struct vdpa_device_list * const vdpa_device_liststatic struct rte_vdpa_device *__vdpa_find_device_by_name (const char *name) - __rte_exclusive_locks_required(&vdpa_device_list_lock) + __rte_requires_capability(&vdpa_device_list_lock) {struct rte_vdpa_device *dev, *ret =NULL ;
RFC 3/3 eal: enhance lock annotations for rwlock
In reply to David MarchandConvert rwlock to the clang capability annotations.
--- lib/eal/common/eal_memalloc.h | 2 +- lib/eal/common/eal_private.h | 2 +- lib/eal/include/generic/rte_rwlock.h | 23 ++-- lib/eal/include/rte_eal_memconfig.h | 24 ++-- lib/ethdev/ethdev_driver.c | 4 +- lib/ethdev/ethdev_private.h | 4 +- lib/ethdev/rte_ethdev.c | 4 +- lib/hash/rte_cuckoo_hash.c | 8 +- lib/vhost/iotlb.h | 8 +- lib/vhost/vhost.c | 10 +- lib/vhost/vhost.h | 24 ++-- lib/vhost/vhost_crypto.c | 14 +-- lib/vhost/virtio_net.c | 170 +++++++++++++-------------- lib/vhost/virtio_net_ctrl.c | 2 +- 14 files changed, 150 insertions(+), 149 deletions(-)
lib/eal/common/eal_memalloc.h +1 -1
@@ -92,7 +92,7 @@ eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset); int eal_memalloc_init(void) - __rte_shared_locks_required(rte_mcfg_mem_get_lock()); + __rte_requires_shared_capability(rte_mcfg_mem_get_lock());int eal_memalloc_cleanup (void );
lib/eal/common/eal_private.h +1 -1
@@ -124,7 +124,7 @@ int rte_eal_memseg_init(void);* 0 on success, negative on error */ int rte_eal_memory_init(void) - __rte_shared_locks_required(rte_mcfg_mem_get_lock()); + __rte_requires_shared_capability(rte_mcfg_mem_get_lock());/** * Configure timers
lib/eal/include/generic/rte_rwlock.h +12 -11
@@ -23,6 +23,7 @@*/ #include <errno.h> +#include <stdbool.h> #include <rte_branch_prediction.h> #include <rte_common.h>
@@ -57,7 +58,7 @@ extern "C" {/* Writer is waiting or has lock */ #define RTE_RWLOCK_READ 0x4/* Reader increment */ -typedef struct __rte_lockable { +typedef struct __rte_capability("rwlock") {RTE_ATOMIC (int32_t ) cnt; } rte_rwlock_t;
@@ -90,7 +91,7 @@ rte_rwlock_init(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_read_lock (rte_rwlock_t *rwl) -__rte_shared_lock_function (rwl) +__rte_acquire_shared_capability (rwl) __rte_no_thread_safety_analysis {int32_t x;
@@ -127,7 +128,7 @@ rte_rwlock_read_lock(rte_rwlock_t *rwl)*/ static inline int rte_rwlock_read_trylock (rte_rwlock_t *rwl) -__rte_shared_trylock_function (0 , rwl) +__rte_try_acquire_shared_capability (false, rwl) __rte_no_thread_safety_analysis {int32_t x;
@@ -160,7 +161,7 @@ rte_rwlock_read_trylock(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_read_unlock (rte_rwlock_t *rwl) -__rte_unlock_function (rwl) +__rte_release_shared_capability (rwl) __rte_no_thread_safety_analysis {rte_atomic_fetch_sub_explicit (&rwl->cnt,RTE_RWLOCK_READ , rte_memory_order_release);
@@ -178,7 +179,7 @@ rte_rwlock_read_unlock(rte_rwlock_t *rwl)*/ static inline int rte_rwlock_write_trylock (rte_rwlock_t *rwl) -__rte_exclusive_trylock_function (0 , rwl) +__rte_try_acquire_capability (false, rwl) __rte_no_thread_safety_analysis {int32_t x;
@@ -200,7 +201,7 @@ rte_rwlock_write_trylock(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_write_lock (rte_rwlock_t *rwl) -__rte_exclusive_lock_function (rwl) +__rte_acquire_capability (rwl) __rte_no_thread_safety_analysis {int32_t x;
@@ -238,7 +239,7 @@ rte_rwlock_write_lock(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_write_unlock (rte_rwlock_t *rwl) -__rte_unlock_function (rwl) +__rte_release_capability (rwl) __rte_no_thread_safety_analysis {rte_atomic_fetch_sub_explicit (&rwl->cnt,RTE_RWLOCK_WRITE , rte_memory_order_release);
@@ -276,7 +277,7 @@ rte_rwlock_write_is_locked(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_read_lock_tm(rte_rwlock_t *rwl) - __rte_shared_lock_function(rwl); + __rte_acquire_shared_capability(rwl);/** * Commit hardware memory transaction or release the read lock if the lock is used as a fall-back
@@ -286,7 +287,7 @@ rte_rwlock_read_lock_tm(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl) - __rte_unlock_function(rwl); + __rte_release_shared_capability(rwl);/** * Try to execute critical section in a hardware memory transaction, if it
@@ -303,7 +304,7 @@ rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_write_lock_tm(rte_rwlock_t *rwl) - __rte_exclusive_lock_function(rwl); + __rte_acquire_capability(rwl);/** * Commit hardware memory transaction or release the write lock if the lock is used as a fall-back
@@ -313,7 +314,7 @@ rte_rwlock_write_lock_tm(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_write_unlock_tm(rte_rwlock_t *rwl) - __rte_unlock_function(rwl); + __rte_release_capability(rwl); #ifdef __cplusplus }
lib/eal/include/rte_eal_memconfig.h +12 -12
@@ -48,84 +48,84 @@ rte_mcfg_ethdev_get_lock(void);*/ void rte_mcfg_mem_read_lock(void) - __rte_shared_lock_function(rte_mcfg_mem_get_lock()); + __rte_acquire_shared_capability(rte_mcfg_mem_get_lock());/** * Unlock the internal EAL shared memory configuration for shared access. */ void rte_mcfg_mem_read_unlock(void) - __rte_unlock_function(rte_mcfg_mem_get_lock()); + __rte_release_shared_capability(rte_mcfg_mem_get_lock());/** * Lock the internal EAL shared memory configuration for exclusive access. */ void rte_mcfg_mem_write_lock(void) - __rte_exclusive_lock_function(rte_mcfg_mem_get_lock()); + __rte_acquire_capability(rte_mcfg_mem_get_lock());/** * Unlock the internal EAL shared memory configuration for exclusive access. */ void rte_mcfg_mem_write_unlock(void) - __rte_unlock_function(rte_mcfg_mem_get_lock()); + __rte_release_capability(rte_mcfg_mem_get_lock());/** * Lock the internal EAL TAILQ list for shared access. */ void rte_mcfg_tailq_read_lock(void) - __rte_shared_lock_function(rte_mcfg_tailq_get_lock()); + __rte_acquire_shared_capability(rte_mcfg_tailq_get_lock());/** * Unlock the internal EAL TAILQ list for shared access. */ void rte_mcfg_tailq_read_unlock(void) - __rte_unlock_function(rte_mcfg_tailq_get_lock()); + __rte_release_shared_capability(rte_mcfg_tailq_get_lock());/** * Lock the internal EAL TAILQ list for exclusive access. */ void rte_mcfg_tailq_write_lock(void) - __rte_exclusive_lock_function(rte_mcfg_tailq_get_lock()); + __rte_acquire_capability(rte_mcfg_tailq_get_lock());/** * Unlock the internal EAL TAILQ list for exclusive access. */ void rte_mcfg_tailq_write_unlock(void) - __rte_unlock_function(rte_mcfg_tailq_get_lock()); + __rte_release_capability(rte_mcfg_tailq_get_lock());/** * Lock the internal EAL Mempool list for shared access. */ void rte_mcfg_mempool_read_lock(void) - __rte_shared_lock_function(rte_mcfg_mempool_get_lock()); + __rte_acquire_shared_capability(rte_mcfg_mempool_get_lock());/** * Unlock the internal EAL Mempool list for shared access. */ void rte_mcfg_mempool_read_unlock(void) - __rte_unlock_function(rte_mcfg_mempool_get_lock()); + __rte_release_shared_capability(rte_mcfg_mempool_get_lock());/** * Lock the internal EAL Mempool list for exclusive access. */ void rte_mcfg_mempool_write_lock(void) - __rte_exclusive_lock_function(rte_mcfg_mempool_get_lock()); + __rte_acquire_capability(rte_mcfg_mempool_get_lock());/** * Unlock the internal EAL Mempool list for exclusive access. */ void rte_mcfg_mempool_write_unlock(void) - __rte_unlock_function(rte_mcfg_mempool_get_lock()); + __rte_release_capability(rte_mcfg_mempool_get_lock());/** * Lock the internal EAL Timer Library lock for exclusive access.
lib/ethdev/ethdev_driver.c +2 -2
@@ -48,7 +48,7 @@ eth_dev_allocated(const char *name)static uint16_t eth_dev_find_free_port (void ) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()) +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()) {uint16_t i;
@@ -65,7 +65,7 @@ eth_dev_find_free_port(void)static struct rte_eth_dev *eth_dev_get (uint16_t port_id) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()) +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()) {struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
lib/ethdev/ethdev_private.h +2 -2
@@ -70,9 +70,9 @@ void eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo,void *eth_dev_shared_data_prepare (void ) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()); +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()); void eth_dev_shared_data_release(void) - __rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock()); + __rte_requires_capability(rte_mcfg_ethdev_get_lock());void eth_dev_rxq_release (struct rte_eth_dev *dev,uint16_t qid);void eth_dev_txq_release (struct rte_eth_dev *dev,uint16_t qid);
lib/ethdev/rte_ethdev.c +2 -2
@@ -420,7 +420,7 @@ rte_eth_dev_is_valid_port(uint16_t port_id)static int eth_is_valid_owner_id (uint64_t owner_id) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()) +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()) {if (owner_id ==RTE_ETH_DEV_NO_OWNER || eth_dev_shared_data->next_owner_id <= owner_id)
@@ -471,7 +471,7 @@ rte_eth_dev_owner_new(uint64_t *owner_id)static int eth_dev_owner_set (const uint16_t port_id,const uint64_t old_owner_id,const struct rte_eth_dev_owner *new_owner) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()) +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()) {struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];struct rte_eth_dev_owner *port_owner;
lib/hash/rte_cuckoo_hash.c +4 -4
@@ -620,7 +620,7 @@ 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_acquire_capability(&h->readwrite_lock) __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)
@@ -631,7 +631,7 @@ __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_acquire_shared_capability(&h->readwrite_lock) __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)
@@ -642,7 +642,7 @@ __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_release_capability(&h->readwrite_lock) __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)
@@ -653,7 +653,7 @@ __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_release_shared_capability(&h->readwrite_lock) __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)
lib/vhost/iotlb.h +4 -4
@@ -11,28 +11,28 @@ static __rte_always_inline voidvhost_user_iotlb_rd_lock (struct vhost_virtqueue *vq) - __rte_shared_lock_function(&vq->iotlb_lock) + __rte_acquire_shared_capability(&vq->iotlb_lock) {rte_rwlock_read_lock (&vq->iotlb_lock); } static __rte_always_inline voidvhost_user_iotlb_rd_unlock (struct vhost_virtqueue *vq) - __rte_unlock_function(&vq->iotlb_lock) + __rte_release_shared_capability(&vq->iotlb_lock) {rte_rwlock_read_unlock (&vq->iotlb_lock); } static __rte_always_inline voidvhost_user_iotlb_wr_lock (struct vhost_virtqueue *vq) - __rte_exclusive_lock_function(&vq->iotlb_lock) + __rte_acquire_capability(&vq->iotlb_lock) {rte_rwlock_write_lock (&vq->iotlb_lock); } static __rte_always_inline voidvhost_user_iotlb_wr_unlock (struct vhost_virtqueue *vq) - __rte_unlock_function(&vq->iotlb_lock) + __rte_release_capability(&vq->iotlb_lock) {rte_rwlock_write_unlock (&vq->iotlb_lock); }
lib/vhost/vhost.c +5 -5
@@ -390,7 +390,7 @@ cleanup_device(struct virtio_net *dev, int destroy)static void vhost_free_async_mem (struct vhost_virtqueue *vq) - __rte_exclusive_locks_required(&vq->access_lock) + __rte_requires_capability(&vq->access_lock) {if (!vq->async)return ;
@@ -439,7 +439,7 @@ free_device(struct virtio_net *dev) static __rte_always_inline intlog_translate (struct virtio_net *dev,struct vhost_virtqueue *vq) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {if (likely (!(vq->ring_addrs.flags & (1 <<VHOST_VRING_F_LOG ))))return 0 ;
@@ -488,7 +488,7 @@ translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,static int vring_translate_split (struct virtio_net *dev,struct vhost_virtqueue *vq) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {uint64_t req_size, size;
@@ -527,7 +527,7 @@ vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq)static int vring_translate_packed (struct virtio_net *dev,struct vhost_virtqueue *vq) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {uint64_t req_size, size;
@@ -1772,7 +1772,7 @@ rte_vhost_extern_callback_register(int vid, static __rte_always_inline intasync_channel_register (struct virtio_net *dev,struct vhost_virtqueue *vq) - __rte_exclusive_locks_required(&vq->access_lock) + __rte_requires_capability(&vq->access_lock) {struct vhost_async *async;int node = vq->numa_node;
lib/vhost/vhost.h +12 -12
@@ -576,7 +576,7 @@ vhost_virtqueue_reconnect_log_packed(struct vhost_virtqueue *vq)static inline void vq_assert_lock__ (struct virtio_net *dev,struct vhost_virtqueue *vq,const char *func) - __rte_assert_exclusive_lock(&vq->access_lock) + __rte_assert_capability(&vq->access_lock) {if (unlikely (!rte_rwlock_write_is_locked (&vq->access_lock))) rte_panic("VHOST_CONFIG: (%s) %s() called without access lock taken.\n",
@@ -627,14 +627,14 @@ void __vhost_log_cache_write(struct virtio_net *dev, void __vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t iova, uint64_t len) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock);void __vhost_log_cache_sync (struct virtio_net *dev,struct vhost_virtqueue *vq);void __vhost_log_write (struct virtio_net *dev,uint64_t addr,uint64_t len); void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t iova, uint64_t len) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock); static __rte_always_inline voidvhost_log_write (struct virtio_net *dev,uint64_t addr,uint64_t len)
@@ -684,7 +684,7 @@ vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq, static __rte_always_inline voidvhost_log_cache_write_iova (struct virtio_net *dev,struct vhost_virtqueue *vq,uint64_t iova,uint64_t len) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {if (likely (!(dev->features & (1ULL <<VHOST_F_LOG_ALL ))))return ;
@@ -698,7 +698,7 @@ vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, static __rte_always_inline voidvhost_log_write_iova (struct virtio_net *dev,struct vhost_virtqueue *vq,uint64_t iova,uint64_t len) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {if (likely (!(dev->features & (1ULL <<VHOST_F_LOG_ALL ))))return ;
@@ -904,24 +904,24 @@ void vhost_backend_cleanup(struct virtio_net *dev); uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t iova, uint64_t *len, uint8_t perm) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock);void *vhost_alloc_copy_ind_table (struct virtio_net *dev,struct vhost_virtqueue *vq,uint64_t desc_addr,uint64_t desc_len) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock); int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) - __rte_exclusive_locks_required(&vq->access_lock) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_capability(&vq->access_lock) + __rte_requires_shared_capability(&vq->iotlb_lock); uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t log_addr) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock); void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq) - __rte_exclusive_locks_required(&vq->access_lock); + __rte_requires_capability(&vq->access_lock); static __rte_always_inline uint64_tvhost_iova_to_vva (struct virtio_net *dev,struct vhost_virtqueue *vq,uint64_t iova,uint64_t *len,uint8_t perm) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {if (!(dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )))return rte_vhost_va_from_guest_pa (dev->mem, iova, len);
lib/vhost/vhost_crypto.c +7 -7
@@ -491,7 +491,7 @@ static __rte_always_inline struct virtio_crypto_inhdr * reach_inhdr(struct vhost_crypto_data_req *vc_req, struct vhost_crypto_desc *head, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { struct virtio_crypto_inhdr *inhdr;struct vhost_crypto_desc *last = head + (max_n_descs -1 );
@@ -538,7 +538,7 @@ static __rte_always_inline void * get_data_ptr(struct vhost_crypto_data_req *vc_req, struct vhost_crypto_desc *cur_desc, uint8_t perm) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { void *data;uint64_t dlen = cur_desc->len;
@@ -555,7 +555,7 @@ get_data_ptr(struct vhost_crypto_data_req *vc_req, static __rte_always_inline uint32_tcopy_data_from_desc (void *dst,struct vhost_crypto_data_req *vc_req,struct vhost_crypto_desc *desc,uint32_t size) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) {uint64_t remain;uint64_t addr;
@@ -586,7 +586,7 @@ static __rte_always_inline int copy_data(void *data, struct vhost_crypto_data_req *vc_req, struct vhost_crypto_desc *head, struct vhost_crypto_desc **cur_desc, uint32_t size, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) {struct vhost_crypto_desc *desc = *cur_desc;uint32_t left = size;
@@ -670,7 +670,7 @@ prepare_write_back_data(struct vhost_crypto_data_req *vc_req,uint32_t offset, uint64_t write_back_len, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { struct vhost_crypto_writeback_data *wb_data, *head;struct vhost_crypto_desc *desc = *cur_desc;
@@ -791,7 +791,7 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,struct virtio_crypto_cipher_data_req *cipher, struct vhost_crypto_desc *head, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { struct vhost_crypto_desc *desc = head;struct vhost_crypto_writeback_data *ewb =NULL ;
@@ -945,7 +945,7 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,struct virtio_crypto_alg_chain_data_req *chain, struct vhost_crypto_desc *head, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { struct vhost_crypto_desc *desc = head, *digest_desc;struct vhost_crypto_writeback_data *ewb =NULL , *ewb2 =NULL ;
lib/vhost/virtio_net.c +85 -85
506 lines not on this page · raw message
lib/vhost/virtio_net_ctrl.c +1 -1
@@ -26,7 +26,7 @@ struct virtio_net_ctrl_elem {static int virtio_net_ctrl_pop (struct virtio_net *dev,struct vhost_virtqueue *cvq,struct virtio_net_ctrl_elem *ctrl_elem) - __rte_shared_locks_required(&cvq->iotlb_lock) + __rte_requires_shared_capability(&cvq->iotlb_lock) {uint16_t avail_idx, desc_idx, n_descs =0 ;uint64_t desc_len, desc_addr, desc_iova, data_len =0 ;
Signature · 1 line
2.47.0
v2 cover Improve lock annotations
In reply to David MarchandA recent bug (see 22aa9a9c7099 ("vhost: fix deadlock in Rx async path")) made more visible a gap in the clang thread safety annotations that DPDK uses: no distinction is made between releasing a read lock and releasing a write lock.
Clang 3.6 and later offers improved thread safety checks.
Marking objects as "lockable" has evolved into flagging some named "capability". clang reports the capability name when an error is reported (making this report a bit easier to understand).
For example, a spinlock is now flagged as:
typedef struct __rte_capability("spinlock") {
volatile RTE_ATOMIC(int) locked;
} rte_spinlock_t;
For "exclusive" locking (spinlocks / write locks), the conversion is:
- exclusive_lock_function -> acquire_capability
- exclusive_trylock_function -> try_acquire_capability
- unlock_function -> release_capability
...
For "shared" locking (read locks):
- shared_lock_function -> acquire_shared_capability
- shared_trylock_function -> try_acquire_shared_capability
- unlock_function -> release_shared_capability
...
This series proposes to use those annotations (sticking to the convention of simply prefixing the compiler attributes with __rte_). The existing "old" annotations macros are left in place in case users started to rely on them.
Note: DPDK requirements state that clang version must be >= 3.6 (following use of C11 standard).
Comments welcome.
Signature · 33 lines
David Marchand David Marchand (3): eal: add enhanced lock annotations eal: enhance lock annotations for spinlock and seqlock eal: enhance lock annotations for rwlock doc/api/doxy-api.conf.in | 12 ++ drivers/bus/dpaa/base/qbman/qman.c | 4 +- drivers/net/fm10k/fm10k_ethdev.c | 4 +- lib/eal/common/eal_memalloc.h | 2 +- lib/eal/common/eal_private.h | 2 +- lib/eal/include/generic/rte_rwlock.h | 23 ++-- lib/eal/include/generic/rte_spinlock.h | 14 +- lib/eal/include/rte_eal_memconfig.h | 28 ++-- lib/eal/include/rte_lock_annotations.h | 53 ++++++++ lib/eal/include/rte_seqlock.h | 4 +- lib/ethdev/ethdev_driver.c | 4 +- lib/ethdev/ethdev_private.h | 4 +- lib/ethdev/rte_ethdev.c | 4 +- lib/graph/graph_private.h | 4 +- lib/hash/rte_cuckoo_hash.c | 8 +- lib/vhost/iotlb.h | 8 +- lib/vhost/vdpa.c | 2 +- lib/vhost/vhost.c | 10 +- lib/vhost/vhost.h | 24 ++-- lib/vhost/vhost_crypto.c | 14 +- lib/vhost/virtio_net.c | 170 ++++++++++++------------- lib/vhost/virtio_net_ctrl.c | 2 +- 22 files changed, 233 insertions(+), 167 deletions(-) -- 2.47.0
PATCH v2 1/3 eal: add enhanced lock annotations
Clang 3.6+ offers enhanced lock annotations when it comes to shared vs exclusive capability/lock release.
Introduce macros for those new function attributes.
---
Changes since RFC:
- fixed build with clang < 11,
--- doc/api/doxy-api.conf.in | 12 ++++++ lib/eal/include/rte_lock_annotations.h | 53 ++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
doc/api/doxy-api.conf.in +12 -0
@@ -103,6 +103,18 @@ PREDEFINED = __DOXYGEN__ \ __rte_shared_trylock_function(x)= \ __rte_assert_shared_lock(x)= \ __rte_unlock_function(x)= \ + __rte_capability(x)= \ + __rte_requires_capability(x)= \ + __rte_acquire_capability(x)= \ + __rte_try_acquire_capability(x)= \ + __rte_release_capability(x)= \ + __rte_assert_capability(x)= \ + __rte_requires_shared_capability(x)= \ + __rte_acquire_shared_capability(x)= \ + __rte_try_acquire_shared_capability(x)= \ + __rte_release_shared_capability(x)= \ + __rte_assert_shared_capability(x)= \ + __rte_exclude_capability(x)= \ __attribute__(x)= OPTIMIZE_OUTPUT_FOR_C = YES
lib/eal/include/rte_lock_annotations.h +53 -0
65 lines not on this page · raw message
Signature · 1 line
2.47.0
PATCH v2 2/3 eal: enhance lock annotations for spinlock and seqlock
In reply to David MarchandConvert spinlock (and as a consequence seqlock) to the clang capability annotations.
--- drivers/bus/dpaa/base/qbman/qman.c | 4 ++-- drivers/net/fm10k/fm10k_ethdev.c | 4 ++-- lib/eal/include/generic/rte_spinlock.h | 14 +++++++------- lib/eal/include/rte_eal_memconfig.h | 4 ++-- lib/eal/include/rte_seqlock.h | 4 ++-- lib/graph/graph_private.h | 4 ++-- lib/vhost/vdpa.c | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-)
drivers/bus/dpaa/base/qbman/qman.c +2 -2
@@ -45,7 +45,7 @@ static inline int fq_isset(struct qman_fq *fq, u32 mask) }static inline void fq_lock (struct qman_fq *fq) - __rte_exclusive_lock_function(&fq->fqlock) + __rte_acquire_capability(&fq->fqlock) __rte_no_thread_safety_analysis {if (fq_isset (fq,QMAN_FQ_FLAG_LOCKED ))
@@ -53,7 +53,7 @@ static inline void fq_lock(struct qman_fq *fq) }static inline void fq_unlock (struct qman_fq *fq) - __rte_unlock_function(&fq->fqlock) + __rte_release_capability(&fq->fqlock) __rte_no_thread_safety_analysis {if (fq_isset (fq,QMAN_FQ_FLAG_LOCKED ))
drivers/net/fm10k/fm10k_ethdev.c +2 -2
@@ -116,7 +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)) + __rte_acquire_capability(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 );
@@ -124,7 +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_release_capability(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {rte_spinlock_unlock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)); }
lib/eal/include/generic/rte_spinlock.h +7 -7
@@ -32,7 +32,7 @@ extern "C" {/** * The rte_spinlock_t type. */ -typedef struct __rte_lockable { +typedef struct __rte_capability("spinlock") {volatile RTE_ATOMIC (int ) locked;/**< lock status 0 = unlocked, 1 = locked */ } rte_spinlock_t;
@@ -61,7 +61,7 @@ rte_spinlock_init(rte_spinlock_t *sl)*/ static inline void rte_spinlock_lock(rte_spinlock_t *sl) - __rte_exclusive_lock_function(sl); + __rte_acquire_capability(sl);#ifdef RTE_FORCE_INTRINSICS static inline void
@@ -87,7 +87,7 @@ rte_spinlock_lock(rte_spinlock_t *sl)*/ static inline void rte_spinlock_unlock(rte_spinlock_t *sl) - __rte_unlock_function(sl); + __rte_release_capability(sl);#ifdef RTE_FORCE_INTRINSICS static inline void
@@ -109,7 +109,7 @@ rte_spinlock_unlock(rte_spinlock_t *sl)__rte_warn_unused_result static inline int rte_spinlock_trylock(rte_spinlock_t *sl) - __rte_exclusive_trylock_function(1, sl); + __rte_try_acquire_capability(true, sl); #ifdef RTE_FORCE_INTRINSICS static inline int
@@ -158,7 +158,7 @@ static inline int rte_tm_supported(void);*/ static inline void rte_spinlock_lock_tm(rte_spinlock_t *sl) - __rte_exclusive_lock_function(sl); + __rte_acquire_capability(sl);/** * Commit hardware memory transaction or release the spinlock if
@@ -169,7 +169,7 @@ rte_spinlock_lock_tm(rte_spinlock_t *sl)*/ static inline void rte_spinlock_unlock_tm(rte_spinlock_t *sl) - __rte_unlock_function(sl); + __rte_release_capability(sl);/** * Try to execute critical section in a hardware memory transaction,
@@ -190,7 +190,7 @@ rte_spinlock_unlock_tm(rte_spinlock_t *sl) __rte_warn_unused_result static inline int rte_spinlock_trylock_tm(rte_spinlock_t *sl) - __rte_exclusive_trylock_function(1, sl); + __rte_try_acquire_capability(true, sl);/** * The rte_spinlock_recursive_t type.
lib/eal/include/rte_eal_memconfig.h +2 -2
@@ -132,14 +132,14 @@ rte_mcfg_mempool_write_unlock(void)*/ void rte_mcfg_timer_lock(void) - __rte_exclusive_lock_function(rte_mcfg_timer_get_lock()); + __rte_acquire_capability(rte_mcfg_timer_get_lock());/** * Unlock the internal EAL Timer Library lock for exclusive access. */ void rte_mcfg_timer_unlock(void) - __rte_unlock_function(rte_mcfg_timer_get_lock()); + __rte_release_capability(rte_mcfg_timer_get_lock());/** * If true, pages are put in single files (per memseg list),
lib/eal/include/rte_seqlock.h +2 -2
@@ -197,7 +197,7 @@ rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint32_t begin_sn)*/ static inline void rte_seqlock_write_lock (rte_seqlock_t *seqlock) - __rte_exclusive_lock_function(&seqlock->lock) + __rte_acquire_capability(&seqlock->lock) {/* To synchronize with other writers. */ rte_spinlock_lock (&seqlock->lock);
@@ -219,7 +219,7 @@ rte_seqlock_write_lock(rte_seqlock_t *seqlock)*/ static inline void rte_seqlock_write_unlock (rte_seqlock_t *seqlock) - __rte_unlock_function(&seqlock->lock) + __rte_release_capability(&seqlock->lock) {rte_seqcount_write_end (&seqlock->count);
lib/graph/graph_private.h +2 -2
@@ -221,7 +221,7 @@ graph_spinlock_get(void);* Take a lock on the graph internal spin lock. */ void graph_spinlock_lock(void) - __rte_exclusive_lock_function(graph_spinlock_get()); + __rte_acquire_capability(graph_spinlock_get());/** * @internal
@@ -229,7 +229,7 @@ void graph_spinlock_lock(void)* Release a lock on the graph internal spin lock. */ void graph_spinlock_unlock(void) - __rte_unlock_function(graph_spinlock_get()); + __rte_release_capability(graph_spinlock_get());/* Graph operations */ /**
lib/vhost/vdpa.c +1 -1
@@ -32,7 +32,7 @@ static struct vdpa_device_list * const vdpa_device_liststatic struct rte_vdpa_device *__vdpa_find_device_by_name (const char *name) - __rte_exclusive_locks_required(&vdpa_device_list_lock) + __rte_requires_capability(&vdpa_device_list_lock) {struct rte_vdpa_device *dev, *ret =NULL ;
Signature · 1 line
2.47.0
PATCH v2 3/3 eal: enhance lock annotations for rwlock
In reply to David MarchandConvert rwlock to the clang capability annotations.
--- lib/eal/common/eal_memalloc.h | 2 +- lib/eal/common/eal_private.h | 2 +- lib/eal/include/generic/rte_rwlock.h | 23 ++-- lib/eal/include/rte_eal_memconfig.h | 24 ++-- lib/ethdev/ethdev_driver.c | 4 +- lib/ethdev/ethdev_private.h | 4 +- lib/ethdev/rte_ethdev.c | 4 +- lib/hash/rte_cuckoo_hash.c | 8 +- lib/vhost/iotlb.h | 8 +- lib/vhost/vhost.c | 10 +- lib/vhost/vhost.h | 24 ++-- lib/vhost/vhost_crypto.c | 14 +-- lib/vhost/virtio_net.c | 170 +++++++++++++-------------- lib/vhost/virtio_net_ctrl.c | 2 +- 14 files changed, 150 insertions(+), 149 deletions(-)
lib/eal/common/eal_memalloc.h +1 -1
@@ -92,7 +92,7 @@ eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset); int eal_memalloc_init(void) - __rte_shared_locks_required(rte_mcfg_mem_get_lock()); + __rte_requires_shared_capability(rte_mcfg_mem_get_lock());int eal_memalloc_cleanup (void );
lib/eal/common/eal_private.h +1 -1
@@ -124,7 +124,7 @@ int rte_eal_memseg_init(void);* 0 on success, negative on error */ int rte_eal_memory_init(void) - __rte_shared_locks_required(rte_mcfg_mem_get_lock()); + __rte_requires_shared_capability(rte_mcfg_mem_get_lock());/** * Configure timers
lib/eal/include/generic/rte_rwlock.h +12 -11
@@ -23,6 +23,7 @@*/ #include <errno.h> +#include <stdbool.h> #include <rte_branch_prediction.h> #include <rte_common.h>
@@ -57,7 +58,7 @@ extern "C" {/* Writer is waiting or has lock */ #define RTE_RWLOCK_READ 0x4/* Reader increment */ -typedef struct __rte_lockable { +typedef struct __rte_capability("rwlock") {RTE_ATOMIC (int32_t ) cnt; } rte_rwlock_t;
@@ -90,7 +91,7 @@ rte_rwlock_init(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_read_lock (rte_rwlock_t *rwl) -__rte_shared_lock_function (rwl) +__rte_acquire_shared_capability (rwl) __rte_no_thread_safety_analysis {int32_t x;
@@ -127,7 +128,7 @@ rte_rwlock_read_lock(rte_rwlock_t *rwl)*/ static inline int rte_rwlock_read_trylock (rte_rwlock_t *rwl) -__rte_shared_trylock_function (0 , rwl) +__rte_try_acquire_shared_capability (false, rwl) __rte_no_thread_safety_analysis {int32_t x;
@@ -160,7 +161,7 @@ rte_rwlock_read_trylock(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_read_unlock (rte_rwlock_t *rwl) -__rte_unlock_function (rwl) +__rte_release_shared_capability (rwl) __rte_no_thread_safety_analysis {rte_atomic_fetch_sub_explicit (&rwl->cnt,RTE_RWLOCK_READ , rte_memory_order_release);
@@ -178,7 +179,7 @@ rte_rwlock_read_unlock(rte_rwlock_t *rwl)*/ static inline int rte_rwlock_write_trylock (rte_rwlock_t *rwl) -__rte_exclusive_trylock_function (0 , rwl) +__rte_try_acquire_capability (false, rwl) __rte_no_thread_safety_analysis {int32_t x;
@@ -200,7 +201,7 @@ rte_rwlock_write_trylock(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_write_lock (rte_rwlock_t *rwl) -__rte_exclusive_lock_function (rwl) +__rte_acquire_capability (rwl) __rte_no_thread_safety_analysis {int32_t x;
@@ -238,7 +239,7 @@ rte_rwlock_write_lock(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_write_unlock (rte_rwlock_t *rwl) -__rte_unlock_function (rwl) +__rte_release_capability (rwl) __rte_no_thread_safety_analysis {rte_atomic_fetch_sub_explicit (&rwl->cnt,RTE_RWLOCK_WRITE , rte_memory_order_release);
@@ -276,7 +277,7 @@ rte_rwlock_write_is_locked(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_read_lock_tm(rte_rwlock_t *rwl) - __rte_shared_lock_function(rwl); + __rte_acquire_shared_capability(rwl);/** * Commit hardware memory transaction or release the read lock if the lock is used as a fall-back
@@ -286,7 +287,7 @@ rte_rwlock_read_lock_tm(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl) - __rte_unlock_function(rwl); + __rte_release_shared_capability(rwl);/** * Try to execute critical section in a hardware memory transaction, if it
@@ -303,7 +304,7 @@ rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_write_lock_tm(rte_rwlock_t *rwl) - __rte_exclusive_lock_function(rwl); + __rte_acquire_capability(rwl);/** * Commit hardware memory transaction or release the write lock if the lock is used as a fall-back
@@ -313,7 +314,7 @@ rte_rwlock_write_lock_tm(rte_rwlock_t *rwl)*/ static inline void rte_rwlock_write_unlock_tm(rte_rwlock_t *rwl) - __rte_unlock_function(rwl); + __rte_release_capability(rwl); #ifdef __cplusplus }
lib/eal/include/rte_eal_memconfig.h +12 -12
@@ -48,84 +48,84 @@ rte_mcfg_ethdev_get_lock(void);*/ void rte_mcfg_mem_read_lock(void) - __rte_shared_lock_function(rte_mcfg_mem_get_lock()); + __rte_acquire_shared_capability(rte_mcfg_mem_get_lock());/** * Unlock the internal EAL shared memory configuration for shared access. */ void rte_mcfg_mem_read_unlock(void) - __rte_unlock_function(rte_mcfg_mem_get_lock()); + __rte_release_shared_capability(rte_mcfg_mem_get_lock());/** * Lock the internal EAL shared memory configuration for exclusive access. */ void rte_mcfg_mem_write_lock(void) - __rte_exclusive_lock_function(rte_mcfg_mem_get_lock()); + __rte_acquire_capability(rte_mcfg_mem_get_lock());/** * Unlock the internal EAL shared memory configuration for exclusive access. */ void rte_mcfg_mem_write_unlock(void) - __rte_unlock_function(rte_mcfg_mem_get_lock()); + __rte_release_capability(rte_mcfg_mem_get_lock());/** * Lock the internal EAL TAILQ list for shared access. */ void rte_mcfg_tailq_read_lock(void) - __rte_shared_lock_function(rte_mcfg_tailq_get_lock()); + __rte_acquire_shared_capability(rte_mcfg_tailq_get_lock());/** * Unlock the internal EAL TAILQ list for shared access. */ void rte_mcfg_tailq_read_unlock(void) - __rte_unlock_function(rte_mcfg_tailq_get_lock()); + __rte_release_shared_capability(rte_mcfg_tailq_get_lock());/** * Lock the internal EAL TAILQ list for exclusive access. */ void rte_mcfg_tailq_write_lock(void) - __rte_exclusive_lock_function(rte_mcfg_tailq_get_lock()); + __rte_acquire_capability(rte_mcfg_tailq_get_lock());/** * Unlock the internal EAL TAILQ list for exclusive access. */ void rte_mcfg_tailq_write_unlock(void) - __rte_unlock_function(rte_mcfg_tailq_get_lock()); + __rte_release_capability(rte_mcfg_tailq_get_lock());/** * Lock the internal EAL Mempool list for shared access. */ void rte_mcfg_mempool_read_lock(void) - __rte_shared_lock_function(rte_mcfg_mempool_get_lock()); + __rte_acquire_shared_capability(rte_mcfg_mempool_get_lock());/** * Unlock the internal EAL Mempool list for shared access. */ void rte_mcfg_mempool_read_unlock(void) - __rte_unlock_function(rte_mcfg_mempool_get_lock()); + __rte_release_shared_capability(rte_mcfg_mempool_get_lock());/** * Lock the internal EAL Mempool list for exclusive access. */ void rte_mcfg_mempool_write_lock(void) - __rte_exclusive_lock_function(rte_mcfg_mempool_get_lock()); + __rte_acquire_capability(rte_mcfg_mempool_get_lock());/** * Unlock the internal EAL Mempool list for exclusive access. */ void rte_mcfg_mempool_write_unlock(void) - __rte_unlock_function(rte_mcfg_mempool_get_lock()); + __rte_release_capability(rte_mcfg_mempool_get_lock());/** * Lock the internal EAL Timer Library lock for exclusive access.
lib/ethdev/ethdev_driver.c +2 -2
@@ -48,7 +48,7 @@ eth_dev_allocated(const char *name)static uint16_t eth_dev_find_free_port (void ) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()) +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()) {uint16_t i;
@@ -65,7 +65,7 @@ eth_dev_find_free_port(void)static struct rte_eth_dev *eth_dev_get (uint16_t port_id) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()) +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()) {struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
lib/ethdev/ethdev_private.h +2 -2
@@ -70,9 +70,9 @@ void eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo,void *eth_dev_shared_data_prepare (void ) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()); +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()); void eth_dev_shared_data_release(void) - __rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock()); + __rte_requires_capability(rte_mcfg_ethdev_get_lock());void eth_dev_rxq_release (struct rte_eth_dev *dev,uint16_t qid);void eth_dev_txq_release (struct rte_eth_dev *dev,uint16_t qid);
lib/ethdev/rte_ethdev.c +2 -2
@@ -420,7 +420,7 @@ rte_eth_dev_is_valid_port(uint16_t port_id)static int eth_is_valid_owner_id (uint64_t owner_id) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()) +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()) {if (owner_id ==RTE_ETH_DEV_NO_OWNER || eth_dev_shared_data->next_owner_id <= owner_id)
@@ -471,7 +471,7 @@ rte_eth_dev_owner_new(uint64_t *owner_id)static int eth_dev_owner_set (const uint16_t port_id,const uint64_t old_owner_id,const struct rte_eth_dev_owner *new_owner) -__rte_exclusive_locks_required (rte_mcfg_ethdev_get_lock ()) +__rte_requires_capability (rte_mcfg_ethdev_get_lock ()) {struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];struct rte_eth_dev_owner *port_owner;
lib/hash/rte_cuckoo_hash.c +4 -4
@@ -620,7 +620,7 @@ 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_acquire_capability(&h->readwrite_lock) __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)
@@ -631,7 +631,7 @@ __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_acquire_shared_capability(&h->readwrite_lock) __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)
@@ -642,7 +642,7 @@ __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_release_capability(&h->readwrite_lock) __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)
@@ -653,7 +653,7 @@ __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_release_shared_capability(&h->readwrite_lock) __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)
lib/vhost/iotlb.h +4 -4
@@ -11,28 +11,28 @@ static __rte_always_inline voidvhost_user_iotlb_rd_lock (struct vhost_virtqueue *vq) - __rte_shared_lock_function(&vq->iotlb_lock) + __rte_acquire_shared_capability(&vq->iotlb_lock) {rte_rwlock_read_lock (&vq->iotlb_lock); } static __rte_always_inline voidvhost_user_iotlb_rd_unlock (struct vhost_virtqueue *vq) - __rte_unlock_function(&vq->iotlb_lock) + __rte_release_shared_capability(&vq->iotlb_lock) {rte_rwlock_read_unlock (&vq->iotlb_lock); } static __rte_always_inline voidvhost_user_iotlb_wr_lock (struct vhost_virtqueue *vq) - __rte_exclusive_lock_function(&vq->iotlb_lock) + __rte_acquire_capability(&vq->iotlb_lock) {rte_rwlock_write_lock (&vq->iotlb_lock); } static __rte_always_inline voidvhost_user_iotlb_wr_unlock (struct vhost_virtqueue *vq) - __rte_unlock_function(&vq->iotlb_lock) + __rte_release_capability(&vq->iotlb_lock) {rte_rwlock_write_unlock (&vq->iotlb_lock); }
lib/vhost/vhost.c +5 -5
@@ -390,7 +390,7 @@ cleanup_device(struct virtio_net *dev, int destroy)static void vhost_free_async_mem (struct vhost_virtqueue *vq) - __rte_exclusive_locks_required(&vq->access_lock) + __rte_requires_capability(&vq->access_lock) {if (!vq->async)return ;
@@ -439,7 +439,7 @@ free_device(struct virtio_net *dev) static __rte_always_inline intlog_translate (struct virtio_net *dev,struct vhost_virtqueue *vq) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {if (likely (!(vq->ring_addrs.flags & (1 <<VHOST_VRING_F_LOG ))))return 0 ;
@@ -488,7 +488,7 @@ translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,static int vring_translate_split (struct virtio_net *dev,struct vhost_virtqueue *vq) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {uint64_t req_size, size;
@@ -527,7 +527,7 @@ vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq)static int vring_translate_packed (struct virtio_net *dev,struct vhost_virtqueue *vq) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {uint64_t req_size, size;
@@ -1772,7 +1772,7 @@ rte_vhost_extern_callback_register(int vid, static __rte_always_inline intasync_channel_register (struct virtio_net *dev,struct vhost_virtqueue *vq) - __rte_exclusive_locks_required(&vq->access_lock) + __rte_requires_capability(&vq->access_lock) {struct vhost_async *async;int node = vq->numa_node;
lib/vhost/vhost.h +12 -12
@@ -576,7 +576,7 @@ vhost_virtqueue_reconnect_log_packed(struct vhost_virtqueue *vq)static inline void vq_assert_lock__ (struct virtio_net *dev,struct vhost_virtqueue *vq,const char *func) - __rte_assert_exclusive_lock(&vq->access_lock) + __rte_assert_capability(&vq->access_lock) {if (unlikely (!rte_rwlock_write_is_locked (&vq->access_lock))) rte_panic("VHOST_CONFIG: (%s) %s() called without access lock taken.\n",
@@ -627,14 +627,14 @@ void __vhost_log_cache_write(struct virtio_net *dev, void __vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t iova, uint64_t len) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock);void __vhost_log_cache_sync (struct virtio_net *dev,struct vhost_virtqueue *vq);void __vhost_log_write (struct virtio_net *dev,uint64_t addr,uint64_t len); void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t iova, uint64_t len) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock); static __rte_always_inline voidvhost_log_write (struct virtio_net *dev,uint64_t addr,uint64_t len)
@@ -684,7 +684,7 @@ vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq, static __rte_always_inline voidvhost_log_cache_write_iova (struct virtio_net *dev,struct vhost_virtqueue *vq,uint64_t iova,uint64_t len) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {if (likely (!(dev->features & (1ULL <<VHOST_F_LOG_ALL ))))return ;
@@ -698,7 +698,7 @@ vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, static __rte_always_inline voidvhost_log_write_iova (struct virtio_net *dev,struct vhost_virtqueue *vq,uint64_t iova,uint64_t len) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {if (likely (!(dev->features & (1ULL <<VHOST_F_LOG_ALL ))))return ;
@@ -904,24 +904,24 @@ void vhost_backend_cleanup(struct virtio_net *dev); uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t iova, uint64_t *len, uint8_t perm) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock);void *vhost_alloc_copy_ind_table (struct virtio_net *dev,struct vhost_virtqueue *vq,uint64_t desc_addr,uint64_t desc_len) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock); int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) - __rte_exclusive_locks_required(&vq->access_lock) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_capability(&vq->access_lock) + __rte_requires_shared_capability(&vq->iotlb_lock); uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t log_addr) - __rte_shared_locks_required(&vq->iotlb_lock); + __rte_requires_shared_capability(&vq->iotlb_lock); void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq) - __rte_exclusive_locks_required(&vq->access_lock); + __rte_requires_capability(&vq->access_lock); static __rte_always_inline uint64_tvhost_iova_to_vva (struct virtio_net *dev,struct vhost_virtqueue *vq,uint64_t iova,uint64_t *len,uint8_t perm) - __rte_shared_locks_required(&vq->iotlb_lock) + __rte_requires_shared_capability(&vq->iotlb_lock) {if (!(dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )))return rte_vhost_va_from_guest_pa (dev->mem, iova, len);
lib/vhost/vhost_crypto.c +7 -7
@@ -491,7 +491,7 @@ static __rte_always_inline struct virtio_crypto_inhdr * reach_inhdr(struct vhost_crypto_data_req *vc_req, struct vhost_crypto_desc *head, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { struct virtio_crypto_inhdr *inhdr;struct vhost_crypto_desc *last = head + (max_n_descs -1 );
@@ -538,7 +538,7 @@ static __rte_always_inline void * get_data_ptr(struct vhost_crypto_data_req *vc_req, struct vhost_crypto_desc *cur_desc, uint8_t perm) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { void *data;uint64_t dlen = cur_desc->len;
@@ -555,7 +555,7 @@ get_data_ptr(struct vhost_crypto_data_req *vc_req, static __rte_always_inline uint32_tcopy_data_from_desc (void *dst,struct vhost_crypto_data_req *vc_req,struct vhost_crypto_desc *desc,uint32_t size) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) {uint64_t remain;uint64_t addr;
@@ -586,7 +586,7 @@ static __rte_always_inline int copy_data(void *data, struct vhost_crypto_data_req *vc_req, struct vhost_crypto_desc *head, struct vhost_crypto_desc **cur_desc, uint32_t size, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) {struct vhost_crypto_desc *desc = *cur_desc;uint32_t left = size;
@@ -670,7 +670,7 @@ prepare_write_back_data(struct vhost_crypto_data_req *vc_req,uint32_t offset, uint64_t write_back_len, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { struct vhost_crypto_writeback_data *wb_data, *head;struct vhost_crypto_desc *desc = *cur_desc;
@@ -791,7 +791,7 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,struct virtio_crypto_cipher_data_req *cipher, struct vhost_crypto_desc *head, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { struct vhost_crypto_desc *desc = head;struct vhost_crypto_writeback_data *ewb =NULL ;
@@ -945,7 +945,7 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,struct virtio_crypto_alg_chain_data_req *chain, struct vhost_crypto_desc *head, uint32_t max_n_descs) - __rte_shared_locks_required(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) { struct vhost_crypto_desc *desc = head, *digest_desc;struct vhost_crypto_writeback_data *ewb =NULL , *ewb2 =NULL ;
lib/vhost/virtio_net.c +85 -85
506 lines not on this page · raw message
lib/vhost/virtio_net_ctrl.c +1 -1
@@ -26,7 +26,7 @@ struct virtio_net_ctrl_elem {static int virtio_net_ctrl_pop (struct virtio_net *dev,struct vhost_virtqueue *cvq,struct virtio_net_ctrl_elem *ctrl_elem) - __rte_shared_locks_required(&cvq->iotlb_lock) + __rte_requires_shared_capability(&cvq->iotlb_lock) {uint16_t avail_idx, desc_idx, n_descs =0 ;uint64_t desc_len, desc_addr, desc_iova, data_len =0 ;
Signature · 1 line
2.47.0
Quoted 36 lines · David Marchand
A recent bug (see
22aa9a9c7099("vhost: fix deadlock in Rx async path")) made more visible a gap in the clang thread safety annotations that DPDK uses: no distinction is made between releasing a read lock and releasing a write lock.Clang 3.6 and later offers improved thread safety checks.
Marking objects as "lockable" has evolved into flagging some named "capability". clang reports the capability name when an error is reported (making this report a bit easier to understand).
For example, a spinlock is now flagged as:
typedef struct__rte_capability("spinlock"){
volatileRTE_ATOMIC(int)locked;
}rte_spinlock_t;For "exclusive" locking (spinlocks / write locks), the conversion is:
-exclusive_lock_function->acquire_capability
-exclusive_trylock_function->try_acquire_capability
-unlock_function->release_capability
...For "shared" locking (read locks):
-shared_lock_function->acquire_shared_capability
-shared_trylock_function->try_acquire_shared_capability
-unlock_function->release_shared_capability
...This series proposes to use those annotations (sticking to the convention of simply prefixing the compiler attributes with
__rte_). The existing "old" annotations macros are left in place in case users started to rely on them.
Quoted 4 lines
Note: DPDK requirements state that clang version must be >= 3.6 (following use of C11 standard).
Comments welcome.
Just a note on Intel CI report.
http://mails.dpdk.org/archives/test-report/2024-December/834120.html
(As reported a few times), this CI reports an error on documentation generation. I can't be sure but this failure here is most likely due to this CI filtering out of the patches any update on doc/.
Signature · 1 line
David Marchand
Quoted 31 lines · David Marchand
A recent bug (see
22aa9a9c7099("vhost: fix deadlock in Rx async path")) made more visible a gap in the clang thread safety annotations that DPDK uses: no distinction is made between releasing a read lock and releasing a write lock.Clang 3.6 and later offers improved thread safety checks.
Marking objects as "lockable" has evolved into flagging some named "capability". clang reports the capability name when an error is reported (making this report a bit easier to understand).
For example, a spinlock is now flagged as:
typedef struct__rte_capability("spinlock"){
volatileRTE_ATOMIC(int)locked;
}rte_spinlock_t;For "exclusive" locking (spinlocks / write locks), the conversion is:
-exclusive_lock_function->acquire_capability
-exclusive_trylock_function->try_acquire_capability
-unlock_function->release_capability
...For "shared" locking (read locks):
-shared_lock_function->acquire_shared_capability
-shared_trylock_function->try_acquire_shared_capability
-unlock_function->release_shared_capability
...
Quoted 7 lines
This series proposes to use those annotations (sticking to the convention of simply prefixing the compiler attributes with
__rte_). The existing "old" annotations macros are left in place in case users started to rely on them.Note: DPDK requirements state that clang version must be >= 3.6 (following use of C11 standard).
Series applied, thanks.
Signature · 1 line
David Marchand