From: "Alex Bennée" <alex.bennee@linaro.org>
To: Yajun Wu <yajunw@nvidia.com>
Cc: qemu-devel@nongnu.org, mst@redhat.com, Parav Pandit <parav@nvidia.com>
Subject: Re: [PATCH] vhost-user: Fix out of order vring host notification handling
Date: Tue, 18 Oct 2022 11:34:34 +0100 [thread overview]
Message-ID: <87ilkhcsva.fsf@linaro.org> (raw)
In-Reply-To: <20221018023651.1359420-1-yajunw@nvidia.com>
Yajun Wu <yajunw@nvidia.com> writes:
> vhost backend sends host notification for every VQ. If backend creates
> VQs in parallel, the VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG may
> arrive to QEMU in different order than incremental queue index order.
>
> For example VQ 1's message arrive earlier than VQ 0's:
> After alloc VhostUserHostNotifier for VQ 1. GPtrArray becomes
>
> [ nil, VQ1 pointer ]
>
> After alloc VhostUserHostNotifier for VQ 0. GPtrArray becomes
>
> [ VQ0 pointer, nil, VQ1 pointer ]
>
> This is wrong. fetch_notifier will return NULL for VQ 1 in
> vhost_user_get_vring_base, causes host notifier miss removal(leak).
>
> The fix is to remove current element from GPtrArray, make the right
> position for element to insert.
>
> Fixes: 503e355465 ("virtio/vhost-user: dynamically assign VhostUserHostNotifiers")
> Signed-off-by: Yajun Wu <yajunw@nvidia.com>
> Acked-by: Parav Pandit <parav@nvidia.com>
>
> ---
> hw/virtio/vhost-user.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 03415b6c95..d256ce589b 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -1543,6 +1543,11 @@ static VhostUserHostNotifier *fetch_or_create_notifier(VhostUserState *u,
>
> n = g_ptr_array_index(u->notifiers, idx);
> if (!n) {
> + /*
> + * In case notification arrive out-of-order,
> + * make room for current index.
> + */
> + g_ptr_array_remove_index(u->notifiers, idx);
> n = g_new0(VhostUserHostNotifier, 1);
> n->idx = idx;
> g_ptr_array_insert(u->notifiers, idx, n);
Ahh reading the description of g_ptr_array_insert() it doesn't
explicitly say it shuffles the data currently at index up but I can see
from the code it does. I guess you can imply it from the other function
descriptions.
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
prev parent reply other threads:[~2022-10-18 10:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 2:36 [PATCH] vhost-user: Fix out of order vring host notification handling Yajun Wu
2022-10-18 10:34 ` Alex Bennée [this message]
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=87ilkhcsva.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=mst@redhat.com \
--cc=parav@nvidia.com \
--cc=qemu-devel@nongnu.org \
--cc=yajunw@nvidia.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 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).