qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH-for-5.0 2/3] virtio: Document virtqueue_pop()
Date: Wed, 25 Mar 2020 21:51:35 +0100	[thread overview]
Message-ID: <f10101cc-ce81-284f-57bc-55c28da44e87@redhat.com> (raw)
In-Reply-To: <CAJ+F1CLwE7uBsryb2oRJH_4Mi_19XaxeSJUipD=M35W48Kz88g@mail.gmail.com>

On 3/25/20 6:50 PM, Marc-André Lureau wrote:
> On Mon, Mar 23, 2020 at 12:55 PM Marc-André Lureau
> <marcandre.lureau@redhat.com> wrote:
>>
>> On Mon, Mar 23, 2020 at 12:30 PM Philippe Mathieu-Daudé
>> <philmd@redhat.com> wrote:
>>>
>>> Document that virtqueue_pop() returned memory must be released
>>> with free().
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>
>> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> nack, hw/virtio/virtio.c uses g_malloc

Indeed... I opened hw/virtio/ and contrib/libvhost-user/ in the geany 
editor, and when I navigated from virtio.c to the 
virtqueue_alloc_element() definition I ended in libvhost-user.c:

static void *
virtqueue_alloc_element(size_t sz,
                                      unsigned out_num, unsigned in_num)
{
     VuVirtqElement *elem;
     size_t in_sg_ofs = ALIGN_UP(sz, __alignof__(elem->in_sg[0]));
     size_t out_sg_ofs = in_sg_ofs + in_num * sizeof(elem->in_sg[0]);
     size_t out_sg_end = out_sg_ofs + out_num * sizeof(elem->out_sg[0]);

     assert(sz >= sizeof(VuVirtqElement));
     elem = malloc(out_sg_end);
     elem->out_num = out_num;
     elem->in_num = in_num;
     elem->in_sg = (void *)elem + in_sg_ofs;
     elem->out_sg = (void *)elem + out_sg_ofs;
     return elem;
}

> 
>>
>>
>>> ---
>>>   include/hw/virtio/virtio.h | 8 ++++++++
>>>   1 file changed, 8 insertions(+)
>>>
>>> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
>>> index b69d517496..c6e3bfc500 100644
>>> --- a/include/hw/virtio/virtio.h
>>> +++ b/include/hw/virtio/virtio.h
>>> @@ -199,6 +199,14 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
>>>                       unsigned int len, unsigned int idx);
>>>
>>>   void virtqueue_map(VirtIODevice *vdev, VirtQueueElement *elem);
>>> +/**
>>> + * virtqueue_pop:
>>> + * @vq: a VirtQueue queue
>>> + * @sz: the size of struct to return (must be >= VirtQueueElement)
>>> + *
>>> + * Returns: a VirtQueueElement filled from the queue or NULL.
>>> + * The returned element must be free()-d by the caller.
>>> + */
>>>   void *virtqueue_pop(VirtQueue *vq, size_t sz);
>>>   unsigned int virtqueue_drop_all(VirtQueue *vq);
>>>   void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t sz);
>>> --
>>> 2.21.1
>>>
>>
>>
> 
> 



  reply	other threads:[~2020-03-25 20:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23 11:29 [PATCH-for-5.0 0/3] virtio,vhost-gpu: Release memory returned by malloc() with free() Philippe Mathieu-Daudé
2020-03-23 11:29 ` [PATCH-for-5.0 1/3] vhost-user-gpu: Release memory returned by vu_queue_pop() " Philippe Mathieu-Daudé
2020-03-23 11:54   ` Marc-André Lureau
2020-04-15 19:27   ` Peter Maydell
2020-03-23 11:29 ` [PATCH-for-5.0 2/3] virtio: Document virtqueue_pop() Philippe Mathieu-Daudé
2020-03-23 11:54   ` Marc-André Lureau
2020-03-25 17:50     ` Marc-André Lureau
2020-03-25 20:51       ` Philippe Mathieu-Daudé [this message]
2020-03-23 11:29 ` [PATCH-for-5.0 3/3] virtio-gpu: Release memory returned by virtqueue_pop() with free() Philippe Mathieu-Daudé
2020-03-25 14:31   ` Marc-André Lureau
2020-03-23 13:41 ` [PATCH-for-5.0 0/3] virtio, vhost-gpu: Release memory returned by malloc() " Michael S. Tsirkin
2020-04-13 10:59   ` Michael S. Tsirkin
2020-04-14 12:40     ` Philippe Mathieu-Daudé

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=f10101cc-ce81-284f-57bc-55c28da44e87@redhat.com \
    --to=philmd@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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).