From: Stefan Hajnoczi <stefanha@redhat.com>
To: Ladi Prosek <lprosek@redhat.com>
Cc: Stefan Hajnoczi <stefanha@gmail.com>,
qemu-devel <qemu-devel@nongnu.org>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element()
Date: Tue, 27 Sep 2016 16:03:55 +0100 [thread overview]
Message-ID: <20160927150355.GA2835@stefanha-x1.localdomain> (raw)
In-Reply-To: <CABdb735HJzbpWKzPxEA_T2tg5M55XVz3DQE2vD4BTXBN0A-RAw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2481 bytes --]
On Tue, Sep 27, 2016 at 02:12:09PM +0200, Ladi Prosek wrote:
> On Tue, Sep 27, 2016 at 12:08 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> > On Tue, Sep 27, 2016 at 09:32:40AM +0200, Ladi Prosek wrote:
> >> On Mon, Sep 19, 2016 at 3:28 PM, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> >> > During device res> > +/* virtqueue_discard:
> >> > + * @vq: The #VirtQueue
> >> > + * @elem: The #VirtQueueElement
> >> > + * @len: number of bytes written
> >> > + *
> >> > + * Pretend the most recent element wasn't popped from the virtqueue. The next
> >> > + * call to virtqueue_pop() will refetch the element.
> >> > + */
> >> > void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
> >> > unsigned int len)
> >> > {
> >> > vq->last_avail_idx--;
> >> > - vq->inuse--;
> >> > - virtqueue_unmap_sg(vq, elem, len);
> >> > + virtqueue_detach_element(vq, elem, len);
> >>
> >> Random comment, not directly related to this change. Would it be worth
> >> adding an assert to this function that elem->index and
> >> vq->last_avail_idx match? In other words, enforce the "most recent"
> >> qualifier mentioned in the comment. As more virtqueue_* functions are
> >> added and the complexity goes up, it is easy to get confused. Also, I
> >> think that naming this function virtqueue_unpop instead of
> >> virtqueue_discard would help.
> >
> > elem->index is a descriptor ring index. vq->last_avail_idx is an index
> > into the available ring. They are different but your suggestion makes
> > sense in general.
>
> Oh, right, I didn't mean they would be identical but something like this:
>
> g_assert(elem->index == virtqueue_get_head(vq, vq->last_avail_idx));
>
> > We shouldn't read from vring memory again for an assertion so
> > deferencing the available ring isn't possible (because we cannot rely on
> > vring memory contents after processing the request).
>
> Not sure I follow, shouldn't available ring memory at that index still
> be the same? Basically I'd like to assert that the next virtqueue_pop
> would return the same element.
Assertions cannot be guest-triggerable. The guest can make the
assertion fail by writing a new value to the available ring.
That might not sound like an issue but consider a scenario where the
virtio PCI device is passed through to a nested guest. Now the nested
guest can kill the parent hypervisor and all sibling VMs.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2016-09-27 15:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-19 13:28 [Qemu-devel] [PATCH 0/3] virtio: detach VirtQueueElements freed by reset Stefan Hajnoczi
2016-09-19 13:28 ` [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element() Stefan Hajnoczi
2016-09-26 8:43 ` Greg Kurz
2016-09-27 7:32 ` Ladi Prosek
2016-09-27 10:08 ` Stefan Hajnoczi
2016-09-27 12:12 ` Ladi Prosek
2016-09-27 15:03 ` Stefan Hajnoczi [this message]
2016-09-27 15:24 ` Ladi Prosek
2016-09-19 13:28 ` [Qemu-devel] [PATCH 2/3] virtio-blk: add missing virtio_detach_element() call Stefan Hajnoczi
2016-09-27 7:49 ` Ladi Prosek
2016-09-27 8:07 ` Greg Kurz
2016-09-19 13:28 ` [Qemu-devel] [PATCH 3/3] virtio-serial: " Stefan Hajnoczi
2016-09-30 10:08 ` Ladi Prosek
2016-09-27 10:08 ` [Qemu-devel] [PATCH 0/3] virtio: detach VirtQueueElements freed by reset Stefan Hajnoczi
2016-10-05 13:12 ` Greg Kurz
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=20160927150355.GA2835@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=lprosek@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.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).