From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 73ED841B9E; Wed, 1 Feb 2023 12:16:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D778042D3C; Wed, 1 Feb 2023 12:16:03 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id DDF574021F for ; Wed, 1 Feb 2023 12:16:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675250161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6o/XSwjlvIUwbtrX+Whqin61X9r3y3q7grQRkbfS/LQ=; b=FwJoGMsrzpJCQwqmF9L87AkPFZM8l2uXmRkEkQq737OcsrxNY1dr5LmKZeMAiDf4cz2FNn +bvEZZt/uyPPD9ps0/EFWwNspebBhulSzUWqNPO0SW6nT0vXLJwwqOjMqBNrNyycuRj5Si kh5PihtWcf7pjiG4eC++jdUyTdeg/6U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-294-FZrRK9zgMFq9Bmdx61muDQ-1; Wed, 01 Feb 2023 06:15:58 -0500 X-MC-Unique: FZrRK9zgMFq9Bmdx61muDQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00373858F09; Wed, 1 Feb 2023 11:15:58 +0000 (UTC) Received: from dmarchan.redhat.com (ovpn-192-67.brq.redhat.com [10.40.192.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72373400EAD6; Wed, 1 Feb 2023 11:15:56 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, stephen@networkplumber.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, xuan.ding@intel.com, mb@smartsharesystems.com Subject: [PATCH v5 3/9] vhost: terminate when access lock is not taken Date: Wed, 1 Feb 2023 12:14:05 +0100 Message-Id: <20230201111411.1509520-4-david.marchand@redhat.com> In-Reply-To: <20230201111411.1509520-1-david.marchand@redhat.com> References: <20220328121758.26632-1-david.marchand@redhat.com> <20230201111411.1509520-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Be a bit more strict when a programmatic error is detected with regards to the access_lock not being taken. Mark the new helper with __rte_assert_exclusive_lock so that clang understands where locks are expected to be taken. Signed-off-by: David Marchand Acked-by: Morten Brørup Reviewed-by: Maxime Coquelin --- lib/vhost/vhost.c | 18 +++--------------- lib/vhost/vhost.h | 10 ++++++++++ lib/vhost/virtio_net.c | 6 +----- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 19c7b92c32..8cd727ca2f 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1781,11 +1781,7 @@ rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id) if (unlikely(vq == NULL || !dev->async_copy)) return -1; - if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) { - VHOST_LOG_CONFIG(dev->ifname, ERR, "%s() called without access lock taken.\n", - __func__); - return -1; - } + vq_assert_lock(dev, vq); return async_channel_register(dev, vq); } @@ -1847,11 +1843,7 @@ rte_vhost_async_channel_unregister_thread_unsafe(int vid, uint16_t queue_id) if (vq == NULL) return -1; - if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) { - VHOST_LOG_CONFIG(dev->ifname, ERR, "%s() called without access lock taken.\n", - __func__); - return -1; - } + vq_assert_lock(dev, vq); if (!vq->async) return 0; @@ -1994,11 +1986,7 @@ rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id) if (vq == NULL) return ret; - if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) { - VHOST_LOG_CONFIG(dev->ifname, ERR, "%s() called without access lock taken.\n", - __func__); - return -1; - } + vq_assert_lock(dev, vq); if (!vq->async) return ret; diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index ef211ed519..f6b2930efd 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -512,6 +512,16 @@ struct virtio_net { struct rte_vhost_user_extern_ops extern_ops; } __rte_cache_aligned; +static inline void +vq_assert_lock__(struct virtio_net *dev, struct vhost_virtqueue *vq, const char *func) + __rte_assert_exclusive_lock(&vq->access_lock) +{ + if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) + rte_panic("VHOST_CONFIG: (%s) %s() called without access lock taken.\n", + dev->ifname, func); +} +#define vq_assert_lock(dev, vq) vq_assert_lock__(dev, vq, __func__) + static __rte_always_inline bool vq_is_packed(struct virtio_net *dev) { diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 9abf752f30..2a75cda7b6 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -2185,11 +2185,7 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id, vq = dev->virtqueue[queue_id]; - if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) { - VHOST_LOG_DATA(dev->ifname, ERR, "%s() called without access lock taken.\n", - __func__); - return -1; - } + vq_assert_lock(dev, vq); if (unlikely(!vq->async)) { VHOST_LOG_DATA(dev->ifname, ERR, -- 2.39.1