All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: maxime.coquelin@redhat.com, chenbo.xia@intel.com,
	jiayu.hu@intel.com, yuanx.wang@intel.com, xuan.ding@intel.com
Subject: [RFC PATCH v2 5/9] vhost: annotate async acesses
Date: Wed, 30 Mar 2022 15:49:52 +0200	[thread overview]
Message-ID: <20220330134956.18927-6-david.marchand@redhat.com> (raw)
In-Reply-To: <20220330134956.18927-1-david.marchand@redhat.com>

vq->async is initialised and must be accessed under vq->access_lock.

Top level "_thread_unsafe" functions could be checked at runtime (clang
provides a lock aware assert()-like check), but they are simply skipped
because those functions are not called in-tree, and as a result,
their annotations would not be tested.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/vhost/vhost.c      | 14 +++++++++-----
 lib/vhost/vhost.h      |  2 +-
 lib/vhost/vhost_user.c |  2 ++
 lib/vhost/virtio_net.c | 15 +++++++++++++++
 4 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index a93e41f314..637aa65ffb 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -334,6 +334,7 @@ cleanup_device(struct virtio_net *dev, int destroy)
 
 static void
 vhost_free_async_mem(struct vhost_virtqueue *vq)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	if (!vq->async)
 		return;
@@ -352,6 +353,7 @@ vhost_free_async_mem(struct vhost_virtqueue *vq)
 
 void
 free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq)
+	RTE_NO_ANNOTATED_LOCK_CHECK
 {
 	if (vq_is_packed(dev))
 		rte_free(vq->shadow_used_packed);
@@ -1622,10 +1624,10 @@ rte_vhost_extern_callback_register(int vid,
 }
 
 static __rte_always_inline int
-async_channel_register(int vid, uint16_t queue_id)
+async_channel_register(struct virtio_net *dev, struct vhost_virtqueue *vq,
+	uint16_t queue_id)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
-	struct virtio_net *dev = get_device(vid);
-	struct vhost_virtqueue *vq = dev->virtqueue[queue_id];
 	struct vhost_async *async;
 	int node = vq->numa_node;
 
@@ -1709,7 +1711,7 @@ rte_vhost_async_channel_register(int vid, uint16_t queue_id)
 		return -1;
 
 	rte_spinlock_lock(&vq->access_lock);
-	ret = async_channel_register(vid, queue_id);
+	ret = async_channel_register(dev, vq, queue_id);
 	rte_spinlock_unlock(&vq->access_lock);
 
 	return ret;
@@ -1717,6 +1719,7 @@ rte_vhost_async_channel_register(int vid, uint16_t queue_id)
 
 int
 rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id)
+	RTE_NO_ANNOTATED_LOCK_CHECK
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
@@ -1732,7 +1735,7 @@ rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id)
 	if (unlikely(vq == NULL || !dev->async_copy))
 		return -1;
 
-	return async_channel_register(vid, queue_id);
+	return async_channel_register(dev, vq, queue_id);
 }
 
 int
@@ -1777,6 +1780,7 @@ rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
 
 int
 rte_vhost_async_channel_unregister_thread_unsafe(int vid, uint16_t queue_id)
+	RTE_NO_ANNOTATED_LOCK_CHECK
 {
 	struct vhost_virtqueue *vq;
 	struct virtio_net *dev = get_device(vid);
diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h
index 158460b7d7..7c44fba0a1 100644
--- a/lib/vhost/vhost.h
+++ b/lib/vhost/vhost.h
@@ -299,7 +299,7 @@ struct vhost_virtqueue {
 	struct rte_vhost_resubmit_info *resubmit_inflight;
 	uint64_t		global_counter;
 
-	struct vhost_async	*async;
+	struct vhost_async	*async RTE_GUARDED_VAR;
 
 	int			notif_enable;
 #define VIRTIO_UNINITIALIZED_NOTIF	(-1)
diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 87eaa2ab4a..0cfa2d6f82 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2199,6 +2199,8 @@ static int
 vhost_user_set_vring_enable(struct virtio_net **pdev,
 			struct vhu_msg_context *ctx,
 			int main_fd __rte_unused)
+	/* vq->access_lock is taken in vhost_user_lock_all_queue_pairs() */
+	RTE_NO_ANNOTATED_LOCK_CHECK
 {
 	struct virtio_net *dev = *pdev;
 	bool enable = !!ctx->msg.payload.state.num;
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 514ee00993..c0d9d3db3e 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -51,6 +51,7 @@ static __rte_always_inline int64_t
 vhost_async_dma_transfer_one(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		int16_t dma_id, uint16_t vchan_id, uint16_t flag_idx,
 		struct vhost_iov_iter *pkt)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct async_dma_vchan_info *dma_info = &dma_copy_track[dma_id].vchans[vchan_id];
 	uint16_t ring_mask = dma_info->ring_mask;
@@ -99,6 +100,7 @@ static __rte_always_inline uint16_t
 vhost_async_dma_transfer(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		int16_t dma_id, uint16_t vchan_id, uint16_t head_idx,
 		struct vhost_iov_iter *pkts, uint16_t nr_pkts)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct async_dma_vchan_info *dma_info = &dma_copy_track[dma_id].vchans[vchan_id];
 	int64_t ret, nr_copies = 0;
@@ -1000,6 +1002,7 @@ static __rte_always_inline int
 async_mbuf_to_desc_seg(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		struct rte_mbuf *m, uint32_t mbuf_offset,
 		uint64_t buf_iova, uint32_t cpy_len)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct vhost_async *async = vq->async;
 	uint64_t mapped_len;
@@ -1057,6 +1060,7 @@ static __rte_always_inline int
 mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		struct rte_mbuf *m, struct buf_vector *buf_vec,
 		uint16_t nr_vec, uint16_t num_buffers, bool is_async)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	uint32_t vec_idx = 0;
 	uint32_t mbuf_offset, mbuf_avail;
@@ -1186,6 +1190,7 @@ vhost_enqueue_single_packed(struct virtio_net *dev,
 			    struct rte_mbuf *pkt,
 			    struct buf_vector *buf_vec,
 			    uint16_t *nr_descs)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	uint16_t nr_vec = 0;
 	uint16_t avail_idx = vq->last_avail_idx;
@@ -1417,6 +1422,7 @@ static __rte_always_inline int16_t
 virtio_dev_rx_single_packed(struct virtio_net *dev,
 			    struct vhost_virtqueue *vq,
 			    struct rte_mbuf *pkt)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct buf_vector buf_vec[BUF_VECTOR_MAX];
 	uint16_t nr_descs = 0;
@@ -1541,6 +1547,7 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
 
 static __rte_always_inline uint16_t
 async_get_first_inflight_pkt_idx(struct vhost_virtqueue *vq)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct vhost_async *async = vq->async;
 
@@ -1587,6 +1594,7 @@ static __rte_noinline uint32_t
 virtio_dev_rx_async_submit_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		uint16_t queue_id, struct rte_mbuf **pkts, uint32_t count,
 		int16_t dma_id, uint16_t vchan_id)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct buf_vector buf_vec[BUF_VECTOR_MAX];
 	uint32_t pkt_idx = 0;
@@ -1691,6 +1699,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev,
 			    struct buf_vector *buf_vec,
 			    uint16_t *nr_descs,
 			    uint16_t *nr_buffers)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	uint16_t nr_vec = 0;
 	uint16_t avail_idx = vq->last_avail_idx;
@@ -1748,6 +1757,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev,
 static __rte_always_inline int16_t
 virtio_dev_rx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			    struct rte_mbuf *pkt, uint16_t *nr_descs, uint16_t *nr_buffers)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct buf_vector buf_vec[BUF_VECTOR_MAX];
 
@@ -1766,6 +1776,7 @@ virtio_dev_rx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 static __rte_always_inline void
 dma_error_handler_packed(struct vhost_virtqueue *vq, uint16_t slot_idx,
 			uint32_t nr_err, uint32_t *pkt_idx)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	uint16_t descs_err = 0;
 	uint16_t buffers_err = 0;
@@ -1793,6 +1804,7 @@ static __rte_noinline uint32_t
 virtio_dev_rx_async_submit_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		uint16_t queue_id, struct rte_mbuf **pkts, uint32_t count,
 		int16_t dma_id, uint16_t vchan_id)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	uint32_t pkt_idx = 0;
 	uint32_t remained = count;
@@ -1863,6 +1875,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, struct vhost_virtqueue
 
 static __rte_always_inline void
 write_back_completed_descs_split(struct vhost_virtqueue *vq, uint16_t n_descs)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct vhost_async *async = vq->async;
 	uint16_t nr_left = n_descs;
@@ -1895,6 +1908,7 @@ write_back_completed_descs_split(struct vhost_virtqueue *vq, uint16_t n_descs)
 static __rte_always_inline void
 write_back_completed_descs_packed(struct vhost_virtqueue *vq,
 				uint16_t n_buffers)
+	RTE_EXC_LOCK_REQUIRES(vq->access_lock)
 {
 	struct vhost_async *async = vq->async;
 	uint16_t from = async->last_buffer_idx_packed;
@@ -2076,6 +2090,7 @@ uint16_t
 rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		struct rte_mbuf **pkts, uint16_t count, int16_t dma_id,
 		uint16_t vchan_id)
+	RTE_NO_ANNOTATED_LOCK_CHECK
 {
 	struct virtio_net *dev = get_device(vid);
 	struct vhost_virtqueue *vq;
-- 
2.23.0


  parent reply	other threads:[~2022-03-30 13:50 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-28 12:17 [RFC PATCH 0/5] vhost lock annotations David Marchand
2022-03-28 12:17 ` [RFC PATCH 1/5] vhost: fix missing virtqueue lock protection David Marchand
2022-03-28 12:17 ` [RFC PATCH 2/5] vhost: annotate virtqueue access lock David Marchand
2022-03-28 12:17 ` [RFC PATCH 3/5] vhost: fix async access David Marchand
2022-03-28 12:17 ` [RFC PATCH 4/5] vhost: annotate async locking requirement David Marchand
2022-03-28 12:17 ` [RFC PATCH 5/5] vhost: annotate IOTLB locks David Marchand
2022-03-30 13:49 ` [RFC PATCH v2 0/9] vhost lock annotations David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 1/9] vhost: fix missing virtqueue lock protection David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 2/9] eal: annotate spinlock and rwlock David Marchand
2022-03-31  9:22     ` David Marchand
2022-04-04  6:21     ` Stephen Hemminger
2022-04-07  8:20       ` David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 3/9] vhost: annotate virtqueue access lock David Marchand
2022-04-07  1:40     ` Hu, Jiayu
2022-04-07  7:03       ` David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 4/9] vhost: fix async access David Marchand
2022-03-31  8:00     ` Maxime Coquelin
2022-03-31 10:23       ` Hu, Jiayu
2022-04-04  6:57     ` Pai G, Sunil
2022-03-30 13:49   ` David Marchand [this message]
2022-03-30 13:49   ` [RFC PATCH v2 6/9] vhost: annotate need reply handling David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 7/9] vhost: annotate VDPA device list accesses David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 8/9] vhost: annotate IOTLB locks David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 9/9] vhost: enable lock check David Marchand
2022-03-30 14:03   ` [RFC PATCH v2 0/9] vhost lock annotations David Marchand
2022-03-30 14:37     ` Ali Alnubani
2022-04-05  7:11       ` David Marchand
2022-04-11 11:00 ` [RFC PATCH v3 0/8] " David Marchand
2022-04-11 11:00   ` [RFC PATCH v3 1/8] eal: annotate spinlock and rwlock David Marchand
2022-04-21 13:48     ` Maxime Coquelin
2022-04-28 12:16       ` David Marchand
2022-04-11 11:00   ` [RFC PATCH v3 2/8] vhost: annotate virtqueue access lock David Marchand
2022-04-21 15:25     ` Maxime Coquelin
2022-04-22  9:49       ` David Marchand
2022-04-11 11:00   ` [RFC PATCH v3 3/8] vhost: fix async access David Marchand
2022-04-21 19:21     ` Maxime Coquelin
2022-05-17 13:24     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 4/8] vhost: annotate async accesses David Marchand
2022-04-22  7:20     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 5/8] vhost: annotate need reply handling David Marchand
2022-04-22  7:25     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 6/8] vhost: annotate vDPA device list accesses David Marchand
2022-04-22  7:26     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 7/8] vhost: annotate IOTLB locks David Marchand
2022-04-22  7:46     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 8/8] vhost: enable lock check David Marchand
2022-04-22  7:47     ` Maxime Coquelin
2023-01-19 18:46 ` [PATCH v4 0/9] vhost lock annotations David Marchand
2023-01-19 18:46   ` [PATCH v4 1/9] eal: annotate spinlock, rwlock and seqlock David Marchand
2023-01-19 19:42     ` Stephen Hemminger
2023-01-19 20:39       ` Tyler Retzlaff
2023-01-19 21:16         ` David Marchand
2023-01-19 21:50           ` Tyler Retzlaff
2023-01-26 12:18             ` David Marchand
2023-01-19 20:55       ` David Marchand
2023-01-19 19:43     ` Stephen Hemminger
2023-01-31 16:18     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 2/9] vhost: simplify need reply handling David Marchand
2023-01-31 16:41     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 3/9] vhost: terminate when access lock is not taken David Marchand
2023-01-31 16:47     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 4/9] vhost: annotate virtqueue access lock David Marchand
2023-01-31 16:50     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 5/9] vhost: annotate async accesses David Marchand
2023-01-31 16:54     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 6/9] vhost: always take IOTLB lock David Marchand
2023-01-31 16:59     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 7/9] vhost: annotate " David Marchand
2023-01-31 17:05     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 8/9] vhost: annotate vDPA device list accesses David Marchand
2023-01-31 17:08     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 9/9] vhost: enable lock check David Marchand
2023-01-31 17:14     ` Maxime Coquelin
2023-01-19 19:20   ` [PATCH v4 0/9] vhost lock annotations Morten Brørup
2023-02-01 11:14 ` [PATCH v5 0/9] Lock annotations David Marchand
2023-02-01 11:14   ` [PATCH v5 1/9] eal: annotate spinlock, rwlock and seqlock David Marchand
2023-02-01 12:32     ` David Marchand
2023-02-06  1:01       ` Tu, Lijuan
2023-02-06  8:12         ` David Marchand
2023-02-01 11:14   ` [PATCH v5 2/9] vhost: simplify need reply handling David Marchand
2023-02-01 11:14   ` [PATCH v5 3/9] vhost: terminate when access lock is not taken David Marchand
2023-02-01 11:14   ` [PATCH v5 4/9] vhost: annotate virtqueue access lock David Marchand
2023-02-01 11:14   ` [PATCH v5 5/9] vhost: annotate async accesses David Marchand
2023-02-01 11:14   ` [PATCH v5 6/9] vhost: always take IOTLB lock David Marchand
2023-02-01 11:14   ` [PATCH v5 7/9] vhost: annotate " David Marchand
2023-02-01 11:14   ` [PATCH v5 8/9] vhost: annotate vDPA device list accesses David Marchand
2023-02-01 11:14   ` [PATCH v5 9/9] vhost: enable lock check David Marchand
2023-02-07 10:45 ` [PATCH v6 0/9] Lock annotations David Marchand
2023-02-07 10:45   ` [PATCH v6 1/9] eal: annotate spinlock, rwlock and seqlock David Marchand
2023-02-09  8:00     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 2/9] vhost: simplify need reply handling David Marchand
2023-02-09  8:00     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 3/9] vhost: terminate when access lock is not taken David Marchand
2023-02-09  8:01     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 4/9] vhost: annotate virtqueue access lock David Marchand
2023-02-09  8:01     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 5/9] vhost: annotate async accesses David Marchand
2023-02-09  8:01     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 6/9] vhost: always take IOTLB lock David Marchand
2023-02-09  8:01     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 7/9] vhost: annotate " David Marchand
2023-02-09  8:02     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 8/9] vhost: annotate vDPA device list accesses David Marchand
2023-02-09  8:02     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 9/9] vhost: enable lock check David Marchand
2023-02-09  8:05     ` Xia, Chenbo
2023-02-09  7:59   ` [PATCH v6 0/9] Lock annotations Xia, Chenbo
2023-02-09  8:08     ` David Marchand
2023-02-09  8:24       ` Xia, Chenbo
2023-02-09 13:48   ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220330134956.18927-6-david.marchand@redhat.com \
    --to=david.marchand@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=jiayu.hu@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=xuan.ding@intel.com \
    --cc=yuanx.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.