From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>,
dev@dpdk.org, Chenbo Xia <chenbox@nvidia.com>,
Fan Zhang <fanzhang.oss@gmail.com>,
Jay Zhou <jianjay.zhou@huawei.com>
Cc: anoobj@marvell.com, Akhil Goyal <gakhil@marvell.com>, stable@dpdk.org
Subject: Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Date: Thu, 27 Feb 2025 10:15:50 +0100 [thread overview]
Message-ID: <81fac570-cdd7-45f7-b209-ce999d5c3d0e@redhat.com> (raw)
In-Reply-To: <0784f44b63f6161ac8716644acfea979704eca39.1740594750.git.gmuthukrishn@marvell.com>
Hi Gowri,
Thanks for the change, but I think there is an issue with the locking,
more below:
On 2/26/25 7:43 PM, Gowrishankar Muthukrishnan wrote:
> Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR),
> worker thread should not try to fetch crypto op, which would lead to
> memory fault.
>
> Fixes: 939066d96563 ("vhost/crypto: add public function implementation")
> Cc: stable@dpdk.org
>
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> Acked-by: Akhil Goyal <gakhil@marvell.com>
> ---
> v6:
> - added lock checks.
> ---
> lib/vhost/vhost_crypto.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c
> index 3dc41a3bd5..d3d13eff07 100644
> --- a/lib/vhost/vhost_crypto.c
> +++ b/lib/vhost/vhost_crypto.c
> @@ -8,6 +8,7 @@
> #include <rte_mbuf.h>
> #include <rte_cryptodev.h>
>
> +#include "iotlb.h"
> #include "rte_vhost_crypto.h"
> #include "vhost.h"
> #include "vhost_user.h"
> @@ -1580,7 +1581,26 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
>
> vq = dev->virtqueue[qid];
>
> + if (unlikely(vq == NULL)) {
> + VC_LOG_ERR("Invalid virtqueue %u", qid);
> + return 0;
> + }
> +
> + if (unlikely(rte_rwlock_read_trylock(&vq->access_lock) != 0))
> + return 0;
> +
> + vhost_user_iotlb_rd_lock(vq);
> + if (unlikely(!vq->access_ok)) {
> + VC_LOG_DBG("Virtqueue %u vrings not yet initialized", qid);
> + vhost_user_iotlb_rd_unlock(vq);
> + rte_rwlock_read_unlock(&vq->access_lock);
> + return 0;
> + }
> +
> avail_idx = *((volatile uint16_t *)&vq->avail->idx);
> + vhost_user_iotlb_rd_unlock(vq);
> + rte_rwlock_read_unlock(&vq->access_lock);
> +
You should only unlock at the end of the function, otherwise there is
not much protection.
> start_idx = vq->last_used_idx;
> count = avail_idx - start_idx;
> count = RTE_MIN(count, VHOST_CRYPTO_MAX_BURST_SIZE);
next prev parent reply other threads:[~2025-02-27 9:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1740594750.git.gmuthukrishn@marvell.com>
2025-02-26 18:43 ` Gowrishankar Muthukrishnan
2025-02-27 9:15 ` Maxime Coquelin [this message]
2025-02-27 9:19 ` Maxime Coquelin
2025-02-27 13:15 ` [EXTERNAL] " Gowrishankar Muthukrishnan
2025-02-27 18:07 ` Gowrishankar Muthukrishnan
2025-02-28 8:48 ` David Marchand
2025-02-28 9:40 ` Maxime Coquelin
2025-02-28 13:59 ` Gowrishankar Muthukrishnan
2025-02-28 15:16 ` Maxime Coquelin
2025-02-28 13:53 ` Gowrishankar Muthukrishnan
2025-02-26 18:43 ` [v6 3/5] examples/vhost_crypto: fix user callbacks Gowrishankar Muthukrishnan
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=81fac570-cdd7-45f7-b209-ce999d5c3d0e@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=anoobj@marvell.com \
--cc=chenbox@nvidia.com \
--cc=dev@dpdk.org \
--cc=fanzhang.oss@gmail.com \
--cc=gakhil@marvell.com \
--cc=gmuthukrishn@marvell.com \
--cc=jianjay.zhou@huawei.com \
--cc=stable@dpdk.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).