From: Gerd Hoffmann <kraxel@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: Dave Airlie <airlied@redhat.com>,
qemu-devel@nongnu.org, Anthony Liguori <aliguori@amazon.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [RfC PATCH 06/15] virtio-gpu/2d: add virtio gpu core code
Date: Fri, 27 Feb 2015 12:10:30 +0100 [thread overview]
Message-ID: <1425035430.20883.44.camel@nilsson.home.kraxel.org> (raw)
In-Reply-To: <54EF44F1.1090507@redhat.com>
On Do, 2015-02-26 at 11:08 -0500, Max Reitz wrote:
> On 2015-02-23 at 05:23, Gerd Hoffmann wrote:
> > This patch adds the core code for virtio gpu emulation,
> > covering 2d support.
> >
> > Written by Dave Airlie and Gerd Hoffmann.
> >
> > Signed-off-by: Dave Airlie<airlied@redhat.com>
> > Signed-off-by: Gerd Hoffmann<kraxel@redhat.com>
> > ---
> > hw/display/Makefile.objs | 2 +
> > hw/display/virtio-gpu.c | 903 +++++++++++++++++++++++++++++++++++++++++
> > include/hw/virtio/virtio-gpu.h | 147 +++++++
> > trace-events | 14 +
> > 4 files changed, 1066 insertions(+)
> > create mode 100644 hw/display/virtio-gpu.c
> > create mode 100644 include/hw/virtio/virtio-gpu.h
>
> Again I mostly only have formal complaints...
>
> But one non-formal question: As far as I understood virtio-gpu's mode of
> operation from this patch, it looks like there is one resource per
> scanout, and that resource is basically the whole screen (which can be
> updated partially).
This is correct (for 2d mode, 3d will be different).
> If that is the case, what do we gain from being able to display a
> resource on multiple scanouts? If we don't associate a scanout to a
> resource with set_scanout, the resource won't ever be displayed on that
> scanout; and if we associate it, the scanout's position and dimension
> will be exactly the same as the resource's, so associating a resource
> with multiple scanouts means that all those scanouts will be duplicates
> of each other, which in turn means we can duplicate heads. But that
> seems more like a frontend feature to me...
It's handled this way to mimic behavior of physical hardware, where you
can configure your scanouts (monitor plugs of gfx hardware) in a simliar
way.
Main advantage of taking this route is that virtual hardware and
physical hardware can be configued the same way, i.e. you can -- for
example -- setup screen mirroring with xrandr.
> > +static void update_cursor_data_simple(VirtIOGPU *g,
> > + struct virtio_gpu_scanout *s,
> > + uint32_t resource_id)
> > +{
> > + struct virtio_gpu_simple_resource *res;
> > + uint32_t pixels;
> > +
> > + res = virtio_gpu_find_resource(g, resource_id);
> > + if (!res) {
> > + return;
> > + }
> > +
> > + pixels = s->current_cursor->width * s->current_cursor->height;
>
> This multiplication might overflow (but I can't imagine that one could
> use this for an exploit).
Added checks.
> > +static struct virtio_gpu_simple_resource *
> > +virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id)
> > +{
> > + struct virtio_gpu_simple_resource *res;
> > +
> > + QTAILQ_FOREACH(res, &g->reslist, next) {
> > + if (res->resource_id == resource_id) {
> > + return res;
> > + }
> > + }
> > + return NULL;
> > +}
>
> How often do you think this function is called, and how many resources
> do you expect there to be? Would it make sense to make this a hash table?
Not for 2d, it's only scanouts and cursors.
In 3d mode virglrenderer will manage resources, and there will be alot
more (textures, buffers, ....).
> > + cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
> > + return;
> > + }
> > +
> > + res = g_new0(struct virtio_gpu_simple_resource, 1);
> > +
> > + res->width = c2d.width;
> > + res->height = c2d.height;
> > + res->format = c2d.format;
> > + res->resource_id = c2d.resource_id;
>
> Considering resource_id == 0 is sometimes (apparently) used as "no
> resource" (e.g. in transfer_to_host_2d), would it make sense to test
> against that here?
Added check.
> > + format = pixman_image_get_format(res->image);
> > + bpp = (PIXMAN_FORMAT_BPP(format) + 7) / 8;
>
> Could have used DIV_ROUND_UP(); also, I don't find it anywhere in the
> virtio-gpu spec (at least not in the one spec I found), so will this
> really work if PIXMAN_FORMAT_BPP(format) is not a multiple of 8? I can
> imagine this being correct for *_BPP() == 15, but maybe not so much for
> *_BPP() == 1; but then again, maybe you don't plan on supporting
> sub-byte pixel formats anyway.
Yes, it's for bpp=15.
> > + if (t2d.offset || t2d.r.x || t2d.r.y ||
> > + t2d.r.width != pixman_image_get_width(res->image)) {
> > + void *img_data = pixman_image_get_data(res->image);
> > + for (h = 0; h < t2d.r.height; h++) {
> > + src_offset = t2d.offset + stride * h;
> > + dst_offset = (t2d.r.y + h) * stride + (t2d.r.x * bpp);
> > +
> > + iov_to_buf(res->iov, res->iov_cnt, src_offset,
> > + (uint8_t *)img_data
> > + + dst_offset, t2d.r.width * bpp);
> > + }
> > + } else {
> > + iov_to_buf(res->iov, res->iov_cnt, 0,
> > + pixman_image_get_data(res->image),
> > + pixman_image_get_stride(res->image)
> > + * pixman_image_get_height(res->image));
>
> Will this work with stride != t2d.r.width * bpp?
Those cases should take the if branch above and loop over all lines to
handle it correctly.
> > + res = virtio_gpu_find_resource(g, ss.resource_id);
>
> If ss.resource_id == 0, the result is unused; this function call could
> therefore be put after the next if block.
Done.
> > + g->enable = 1;
> > + if (ss.resource_id == 0) {
> > + scanout = &g->scanout[ss.scanout_id];
> > + if (g->scanout[ss.scanout_id].resource_id) {
>
> Would be shorter as "if (scanout->resource_id)".
Yep, fixed.
> > +int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab,
> > + struct virtio_gpu_ctrl_command *cmd,
> > + struct iovec **iov)
> > +{
> > + struct virtio_gpu_mem_entry *ents;
> > + size_t esize, s;
> > + int i;
> > +
> > + esize = sizeof(*ents) * ab->nr_entries;
>
> Can overflow (on 32 bit hosts).
[ ... ]
> However, I think it's best to simply limit ab->nr_entries to some sane
> value
Done.
thanks,
Gerd
next prev parent reply other threads:[~2015-02-27 11:10 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 10:23 [Qemu-devel] [RfC PATCH 00/15] virtio-gpu: Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 01/15] virtio-pci: add flags to enable/disable legacy/modern Gerd Hoffmann
2015-02-26 16:41 ` Max Reitz
2015-02-27 11:15 ` Gerd Hoffmann
2015-02-27 14:20 ` Max Reitz
2015-03-02 12:34 ` Michael S. Tsirkin
2015-03-02 13:25 ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 02/15] virtio-pci: make QEMU_VIRTIO_PCI_QUEUE_MEM_MULT smaller Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 03/15] virtio-pci: make pci bars configurable Gerd Hoffmann
2015-03-02 12:30 ` Michael S. Tsirkin
2015-03-02 13:10 ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 04/15] virtio-pci: make modern bar 64bit prefetchable Gerd Hoffmann
2015-03-02 12:33 ` Michael S. Tsirkin
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 05/15] virtio-gpu/2d: add hardware spec include file Gerd Hoffmann
2015-02-25 20:04 ` Max Reitz
2015-02-27 9:37 ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 06/15] virtio-gpu/2d: add virtio gpu core code Gerd Hoffmann
2015-02-26 16:08 ` Max Reitz
2015-02-27 11:10 ` Gerd Hoffmann [this message]
2015-02-27 14:20 ` Max Reitz
2015-02-27 14:31 ` Gerd Hoffmann
2015-02-27 14:33 ` Max Reitz
2015-03-01 22:03 ` Dave Airlie
2015-03-02 12:57 ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 07/15] virtio-gpu-pci: add virtio pci support Gerd Hoffmann
2015-02-26 16:25 ` Max Reitz
2015-02-27 11:13 ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 08/15] virtio-gpu-pci: virtio-1.0 adaptions [fixup] Gerd Hoffmann
2015-02-26 16:46 ` Max Reitz
2015-02-27 11:18 ` Gerd Hoffmann
2015-02-27 14:30 ` Max Reitz
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 09/15] virtio-vga: add virtio gpu device with vga compatibility Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 10/15] virtio-vga: virtio-1.0 adaptions [fixup] Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 11/15] virtio-vga: add '-vga virtio' support Gerd Hoffmann
2015-02-24 16:26 ` Marc-André Lureau
2015-02-27 9:27 ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 12/15] virtio-vga: add vgabios configuration Gerd Hoffmann
2015-02-26 18:13 ` Max Reitz
2015-02-27 11:25 ` Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 13/15] virtio-vga: add vgabios binary Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 14/15] virtio-gpu: add to display-vga test Gerd Hoffmann
2015-02-23 10:23 ` [Qemu-devel] [RfC PATCH 15/15] [hack] virtio-gpu: maskerade as -device VGA Gerd Hoffmann
2015-02-26 18:40 ` [Qemu-devel] [RfC PATCH 00/15] virtio-gpu: Max Reitz
2015-02-27 11:30 ` Gerd Hoffmann
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=1425035430.20883.44.camel@nilsson.home.kraxel.org \
--to=kraxel@redhat.com \
--cc=airlied@redhat.com \
--cc=aliguori@amazon.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--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).