From patchwork Mon Sep 25 16:36:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 131892 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 24F9342637; Mon, 25 Sep 2023 18:36:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7F67440E6E; Mon, 25 Sep 2023 18:36:34 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 78ED740E7C for ; Mon, 25 Sep 2023 18:36:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695659792; 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=7eLsUy5+wGCD98MgwufspfVJ+nl4Rlbe/LEwp4wj3S4=; b=jTOWLL2dflG4OKVT810erO2qyMjKih/h9JCiLdxXUKT93D71U6qbGNJk3t9tk+YjkL1fho vcC3pvUbR7UYJ1bJNnaciRTlDyZq8p94hLD7gOXLVZRTB+L78RPRuIrepMQWET3YsO0VBe R5K2DacUy2ayfP9txrasgPIHXiMRZeU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-645-LNPppveIMwSW68olzc3hqg-1; Mon, 25 Sep 2023 12:36:28 -0400 X-MC-Unique: LNPppveIMwSW68olzc3hqg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FD141C0758C; Mon, 25 Sep 2023 16:36:27 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id C261210EE402; Mon, 25 Sep 2023 16:36:24 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com, mb@smartsharesystems.com Cc: Maxime Coquelin , stable@dpdk.org, Li Feng Subject: [PATCH 1/7] vhost: fix missing vring call check on virtqueue access Date: Mon, 25 Sep 2023 18:36:04 +0200 Message-ID: <20230925163610.3307750-2-maxime.coquelin@redhat.com> In-Reply-To: <20230925163610.3307750-1-maxime.coquelin@redhat.com> References: <20230925163610.3307750-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Acquiring the access lock is not enough to ensure virtqueue's metadata such as vring pointers are valid. The access status must also be checked. Fixes: c5736998305d ("vhost: fix missing virtqueue lock protection") Fixes: 830f7e790732 ("vhost: add non-blocking API for posting interrupt") Cc: stable@dpdk.org Reported-by: Li Feng Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index c03bb9c6eb..e9c775fa26 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1328,6 +1328,7 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx) { struct virtio_net *dev; struct vhost_virtqueue *vq; + int ret = 0; dev = get_device(vid); if (!dev) @@ -1342,14 +1343,20 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx) rte_rwlock_read_lock(&vq->access_lock); + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + if (vq_is_packed(dev)) vhost_vring_call_packed(dev, vq); else vhost_vring_call_split(dev, vq); +out_unlock: rte_rwlock_read_unlock(&vq->access_lock); - return 0; + return ret; } int @@ -1357,6 +1364,7 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx) { struct virtio_net *dev; struct vhost_virtqueue *vq; + int ret = 0; dev = get_device(vid); if (!dev) @@ -1372,14 +1380,20 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx) if (rte_rwlock_read_trylock(&vq->access_lock)) return -EAGAIN; + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + if (vq_is_packed(dev)) vhost_vring_call_packed(dev, vq); else vhost_vring_call_split(dev, vq); +out_unlock: rte_rwlock_read_unlock(&vq->access_lock); - return 0; + return ret; } uint16_t From patchwork Mon Sep 25 16:36:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 131894 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8AF3642637; Mon, 25 Sep 2023 18:36:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D1FDC40ED9; Mon, 25 Sep 2023 18:36:36 +0200 (CEST) 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 3DFD140E7C for ; Mon, 25 Sep 2023 18:36:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695659792; 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=boW3UgISU7lLi+7RP/CaTK242QvWeCQi+/Q0kBQYyig=; b=J2t0iHCMWh4MzYCHaWfPd93poWNGTkVvnVffgqVPi3NuKZ1yW9CRHamwAIuQnP6WqzmDtu p6QrZ9+SJpNZd2i1GsdLSKDkqElAOV1DJOlS8bz7SbwVy6ju8nd55U1Bb7y2WTSsMmRwNC H58GjhsKqEbH82DT3azb0YW3Wv34xSI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-E1mjboD4NRmT6w0ZX-GT7Q-1; Mon, 25 Sep 2023 12:36:29 -0400 X-MC-Unique: E1mjboD4NRmT6w0ZX-GT7Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C30529A9D4F; Mon, 25 Sep 2023 16:36:29 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id D715F10EE6C9; Mon, 25 Sep 2023 16:36:27 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com, mb@smartsharesystems.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [PATCH 2/7] vhost: fix missing check on virtqueue access Date: Mon, 25 Sep 2023 18:36:05 +0200 Message-ID: <20230925163610.3307750-3-maxime.coquelin@redhat.com> In-Reply-To: <20230925163610.3307750-1-maxime.coquelin@redhat.com> References: <20230925163610.3307750-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Acquiring the access lock is not enough to ensure virtqueue's metadata such as vring pointers are valid. The access status must also be checked. Fixes: 4e0de8dac853 ("vhost: protect vring access done by application") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index e9c775fa26..83b71ffb23 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1416,7 +1416,10 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) rte_rwlock_write_lock(&vq->access_lock); - if (unlikely(!vq->enabled || vq->avail == NULL)) + if (unlikely(!vq->access_ok)) + goto out; + + if (unlikely(!vq->enabled)) goto out; ret = *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx; @@ -1508,9 +1511,15 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) rte_rwlock_write_lock(&vq->access_lock); + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + vq->notif_enable = enable; ret = vhost_enable_guest_notification(dev, vq, enable); +out_unlock: rte_rwlock_write_unlock(&vq->access_lock); return ret; @@ -1601,7 +1610,10 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) rte_rwlock_write_lock(&vq->access_lock); - if (unlikely(!vq->enabled || vq->avail == NULL)) + if (unlikely(!vq->access_ok)) + goto out; + + if (unlikely(!vq->enabled)) goto out; ret = *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx; From patchwork Mon Sep 25 16:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 131893 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B13D742637; Mon, 25 Sep 2023 18:36:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AFEBC40EAB; Mon, 25 Sep 2023 18:36:35 +0200 (CEST) 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 2F78D40E68 for ; Mon, 25 Sep 2023 18:36:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695659792; 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=1JrSFRc1MugUGewshNGqtGDYHSvBGYJlhMK66Dte57w=; b=Pg1akftbnxWDcrFxN9bTM17XpDk5UZ6IanApSC+QZViQlE7IzZ5g53BEzviBS4X7W2Q5RS jCgi8XybvI1AJUWnccCEQi2m9jicNqqx82x+9AH8rVHCwosYKffVdiWT+xjwrCPmrwjtYf lpt7u82ks6Erfsp4k3jBYt0Fhw80AuY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-584-CL7Q0qN6PZSd_WAJ_0Kpog-1; Mon, 25 Sep 2023 12:36:31 -0400 X-MC-Unique: CL7Q0qN6PZSd_WAJ_0Kpog-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DE37C3800BA9; Mon, 25 Sep 2023 16:36:30 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 839EE1005E29; Mon, 25 Sep 2023 16:36:29 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com, mb@smartsharesystems.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [PATCH 3/7] vhost: fix checking virtqueue access when notifying guest Date: Mon, 25 Sep 2023 18:36:06 +0200 Message-ID: <20230925163610.3307750-4-maxime.coquelin@redhat.com> In-Reply-To: <20230925163610.3307750-1-maxime.coquelin@redhat.com> References: <20230925163610.3307750-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Acquiring the access lock is not enough to ensure virtqueue's metadata such as vring pointers are valid. The access status must also be checked. Fixes: d761d455a0e4 ("vhost: add operation to offload the interrupt kick") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 83b71ffb23..f07674334d 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1540,6 +1540,9 @@ rte_vhost_notify_guest(int vid, uint16_t queue_id) rte_rwlock_read_lock(&vq->access_lock); + if (unlikely(!vq->access_ok)) + goto out_unlock; + if (dev->backend_ops->inject_irq(dev, vq)) { if (dev->flags & VIRTIO_DEV_STATS_ENABLED) __atomic_fetch_add(&vq->stats.guest_notifications_error, @@ -1552,6 +1555,7 @@ rte_vhost_notify_guest(int vid, uint16_t queue_id) dev->notify_ops->guest_notified(dev->vid); } +out_unlock: rte_rwlock_read_unlock(&vq->access_lock); } From patchwork Mon Sep 25 16:36:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 131895 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EBDD942637; Mon, 25 Sep 2023 18:37:01 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 31EC040EF1; Mon, 25 Sep 2023 18:36:38 +0200 (CEST) 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 1CA0C40ECF for ; Mon, 25 Sep 2023 18:36:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695659794; 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=9rL6Xmtu9kRygElKC+We1OjSUvcjI5Z/BL3h8m/HzNc=; b=B/03jSxf5gKH0il6hlms4pvFZZoIctJtD8MVti5oRUr9TaU2IWHb0LPQwDVfd73/yvaFMw 9DO6gk5I9YIkmpo/Gu4nG35m5a/F0GvVZTwYHn3G2YUCPJBqNtSGrS9/xuFhOYUcmRr0Bt /QqgZrWV/zzh33ZgtLdJFdFLNqoNdGo= 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-166-OCS2nbQ4N8q5JiGV2mL9kw-1; Mon, 25 Sep 2023 12:36:33 -0400 X-MC-Unique: OCS2nbQ4N8q5JiGV2mL9kw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E09A85A5BF; Mon, 25 Sep 2023 16:36:32 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34AF710EE6C9; Mon, 25 Sep 2023 16:36:31 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com, mb@smartsharesystems.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [PATCH 4/7] vhost: fix check on virtqueue access in async registration Date: Mon, 25 Sep 2023 18:36:07 +0200 Message-ID: <20230925163610.3307750-5-maxime.coquelin@redhat.com> In-Reply-To: <20230925163610.3307750-1-maxime.coquelin@redhat.com> References: <20230925163610.3307750-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Acquiring the access lock is not enough to ensure virtqueue's metadata such as vring pointers are valid. The access status must also be checked. Fixes: 78639d54563a ("vhost: introduce async enqueue registration API") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index f07674334d..7f5d25255a 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1853,7 +1853,15 @@ rte_vhost_async_channel_register(int vid, uint16_t queue_id) return -1; rte_rwlock_write_lock(&vq->access_lock); + + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + ret = async_channel_register(dev, vq); + +out_unlock: rte_rwlock_write_unlock(&vq->access_lock); return ret; @@ -1905,6 +1913,11 @@ rte_vhost_async_channel_unregister(int vid, uint16_t queue_id) return ret; } + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + if (!vq->async) { ret = 0; } else if (vq->async->pkts_inflight_n) { @@ -1916,6 +1929,7 @@ rte_vhost_async_channel_unregister(int vid, uint16_t queue_id) ret = 0; } +out_unlock: rte_rwlock_write_unlock(&vq->access_lock); return ret; From patchwork Mon Sep 25 16:36:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 131896 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3B96042637; Mon, 25 Sep 2023 18:37:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EF01C40EE4; Mon, 25 Sep 2023 18:36:40 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 7ABFA40EDC for ; Mon, 25 Sep 2023 18:36:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695659798; 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=5KwkOJ4IPmRqOlxjJzKRyefLLUQQM1DYpQdXYdSCPfs=; b=dL5XmtH10xx5CUGR/qq4gmG32D4QEBqKURCXLvTUuMzCSdsnoKMZ8D73jo3eDBbcmkwY5t vcAd+lfs2QetAxLV/2h6gJdpy2IENODNuYRZnmDbiGhQKOwXikL8LdyTAKO1//2u+SExa4 fjUD9mwoqAB65b5mOI1XE0YFJgQzu+Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-163-hRdc4-TUORGwrnLATNu1Hg-1; Mon, 25 Sep 2023 12:36:34 -0400 X-MC-Unique: hRdc4-TUORGwrnLATNu1Hg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3CCA129A9CA8; Mon, 25 Sep 2023 16:36:34 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id D54C31005B90; Mon, 25 Sep 2023 16:36:32 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com, mb@smartsharesystems.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [PATCH 5/7] vhost: Fix check on virtqueue access in in-flight getter Date: Mon, 25 Sep 2023 18:36:08 +0200 Message-ID: <20230925163610.3307750-6-maxime.coquelin@redhat.com> In-Reply-To: <20230925163610.3307750-1-maxime.coquelin@redhat.com> References: <20230925163610.3307750-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Acquiring the access lock is not enough to ensure virtqueue's metadata such as vring pointers are valid. The access status must also be checked. Fixes: 0c0935c5f794 ("vhost: allow to check in-flight packets for async vhost") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 7f5d25255a..51383410bf 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -2069,9 +2069,15 @@ rte_vhost_async_get_inflight(int vid, uint16_t queue_id) return ret; } + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + if (vq->async) ret = vq->async->pkts_inflight_n; +out_unlock: rte_rwlock_write_unlock(&vq->access_lock); return ret; From patchwork Mon Sep 25 16:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 131897 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0F9A942637; Mon, 25 Sep 2023 18:37:22 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F9D64111C; Mon, 25 Sep 2023 18:36:42 +0200 (CEST) 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 DF914410FB for ; Mon, 25 Sep 2023 18:36:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695659799; 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=pBsuT9WW90WzMtf8VlqlirKuelOpaKWp8Otbi/JKlfc=; b=YN80Wn0mHuH5jtKAl8K/ljk2A6xRT6BWvHN7pSpmqLdWYbpp1wjzVT/fuTcTNqcZWXT/UC Qj0kAH+Gv4hjo/rKaY+gIfmjeS+f/ccevndK8BQjKr7pYbHaBQYBdsqgR1n13pxIDelIZI puwoqk5jFlPdQusu01ypGf7bJ3l3lVg= 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-408-uRauMFy_OTS8kpAIWSx3OQ-1; Mon, 25 Sep 2023 12:36:36 -0400 X-MC-Unique: uRauMFy_OTS8kpAIWSx3OQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E6913811E88; Mon, 25 Sep 2023 16:36:35 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BE361054FC1; Mon, 25 Sep 2023 16:36:34 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com, mb@smartsharesystems.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [PATCH 6/7] vhost: fix missing lock protection in power monitor API Date: Mon, 25 Sep 2023 18:36:09 +0200 Message-ID: <20230925163610.3307750-7-maxime.coquelin@redhat.com> In-Reply-To: <20230925163610.3307750-1-maxime.coquelin@redhat.com> References: <20230925163610.3307750-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 The power monitor get API is missing both access lock protection and access status check. Fixes: 34fd4373ce76 ("vhost: add power monitor API") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 51383410bf..28eedf11d9 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -2117,6 +2117,7 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id, { struct virtio_net *dev = get_device(vid); struct vhost_virtqueue *vq; + int ret = 0; if (dev == NULL) return -1; @@ -2127,6 +2128,13 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id, if (vq == NULL) return -1; + rte_rwlock_read_lock(&vq->access_lock); + + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + if (vq_is_packed(dev)) { struct vring_packed_desc *desc; desc = vq->desc_packed; @@ -2146,7 +2154,10 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id, pmc->match = 0; } - return 0; +out_unlock: + rte_rwlock_read_unlock(&vq->access_lock); + + return ret; } From patchwork Mon Sep 25 16:36:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 131898 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C0DDD42637; Mon, 25 Sep 2023 18:37:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9B54E41148; Mon, 25 Sep 2023 18:36:43 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id C27E9410FD for ; Mon, 25 Sep 2023 18:36:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695659801; 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=RBGLhIuGI3Fxuv4WCaul9eq/w9buRjUa4lJOLKHWExo=; b=UMd1o0vL+Dz2P28yVutwsrKmbHGsXPdNYIwAgEjibSUW8stSOAZ2ZJeAYoT/F2BtRhrucL HA5xw6NoXaKRQxlNhd0lznlN70Ov9WMHNLxL0AZbjas1uW7GkZpvwxkVS3irFiMJKGS4g3 jx+XhjoMtncMv4lq1n1y6BjG17ZOXGU= 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-101-nAlh-cXwMH293X-M-10r4Q-1; Mon, 25 Sep 2023 12:36:38 -0400 X-MC-Unique: nAlh-cXwMH293X-M-10r4Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FA57801FA9; Mon, 25 Sep 2023 16:36:37 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43AE110EE402; Mon, 25 Sep 2023 16:36:36 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com, mb@smartsharesystems.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [PATCH 7/7] vhost: fix checking virtqueue access ins stats API Date: Mon, 25 Sep 2023 18:36:10 +0200 Message-ID: <20230925163610.3307750-8-maxime.coquelin@redhat.com> In-Reply-To: <20230925163610.3307750-1-maxime.coquelin@redhat.com> References: <20230925163610.3307750-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Acquiring the access lock is not enough to ensure virtqueue's metadata such as vring pointers are valid. The access status must also be checked. Fixes: be75dc99ea1f ("vhost: support per-virtqueue statistics") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 28eedf11d9..7b0bdda520 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -2195,6 +2195,7 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id, struct virtio_net *dev = get_device(vid); struct vhost_virtqueue *vq; unsigned int i; + int ret = VHOST_NB_VQ_STATS; if (dev == NULL) return -1; @@ -2211,6 +2212,12 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id, vq = dev->virtqueue[queue_id]; rte_rwlock_write_lock(&vq->access_lock); + + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + for (i = 0; i < VHOST_NB_VQ_STATS; i++) { /* * No need to the read atomic counters as such, due to the @@ -2220,15 +2227,18 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id, *(uint64_t *)(((char *)vq) + vhost_vq_stat_strings[i].offset); stats[i].id = i; } + +out_unlock: rte_rwlock_write_unlock(&vq->access_lock); - return VHOST_NB_VQ_STATS; + return ret; } int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id) { struct virtio_net *dev = get_device(vid); struct vhost_virtqueue *vq; + int ret = 0; if (dev == NULL) return -1; @@ -2242,14 +2252,21 @@ int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id) vq = dev->virtqueue[queue_id]; rte_rwlock_write_lock(&vq->access_lock); + + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } /* * No need to the reset atomic counters as such, due to the * above write access_lock preventing them to be updated. */ memset(&vq->stats, 0, sizeof(vq->stats)); + +out_unlock: rte_rwlock_write_unlock(&vq->access_lock); - return 0; + return ret; } int