qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: Dave Airlie <airlied@redhat.com>,
	virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org,
	virtualization@lists.linux-foundation.org
Subject: Re: [Qemu-devel] [PATCH 1/2] virtio-gpu/2d: add hardware spec include file
Date: Fri, 12 Sep 2014 06:48:09 -0600	[thread overview]
Message-ID: <5412EB89.1080405@redhat.com> (raw)
In-Reply-To: <1410518696.30411.9.camel@nilsson.home.kraxel.org>

[-- Attachment #1: Type: text/plain, Size: 2176 bytes --]

On 09/12/2014 04:44 AM, Gerd Hoffmann wrote:

>>> +enum virtgpu_ctrl_type {
>>> +        VIRTGPU_UNDEFINED = 0,
>>> +
>>> +        /* 2d commands */
>>> +        VIRTGPU_CMD_GET_DISPLAY_INFO = 0x0100,
>>
>> Please consider also adding:
>>
>> #define VIRTGPU_CMD_GET_DISPLAY_INFO VIRTGPU_CMD_GET_DISPLAY_INFO
>>
>> and friends.  It makes it MUCH nicer for application software to probe
>> for later extensions if every member of the enum is also associated with
>> a preprocessor macro.
> 
> I don't think this will ever be shipped as library header for external
> users ...

Fair enough. I wasn't sure, so it didn't hurt to ask.

> 
>>> +struct virtgpu_ctrl_hdr {
>>> +        uint32_t type;
>>> +        uint32_t flags;
>>> +        uint64_t fence_id;
>>> +        uint32_t ctx_id;
>>> +        uint32_t padding;
>>> +};
>>> +
>>
>> Is the padding to ensure that this is aligned regardless of 32-bit or
>> 64-bit hosts?
> 
> Yes.
> 
>> Is it worth adding a compile-time assertion about the
>> size of the struct to ensure the compiler doesn't add any additional
>> padding?
> 
> Makes sense.  What is the usual trick to do that?

Among others,

struct dummy {
  int size_check : (sizeof(virtgpu_ctrl_hdr) == 24 ? 1 : -1);
};

Since bitfields cannot have a negative size, the compiler will
forcefully fail compilation if the struct size ever changes.  Similar
tricks include setting up array bounds that would be negative on
failure, or (inside a function body) declaring a switch that has
colliding case statements on failure.  But depending on the set of
compiler warning options in effect, declaring an otherwise unused struct
may be too noisy.  So if you need more ideas and a good read, check out
the comments in how gnulib does it (the link mentions GPLv3+, but that
file is also shipped as LGPLv2+ so it is compatible with qemu):

git.savannah.gnu.org/cgit/gnulib.git/tree/lib/verify.h

with an end result that a user just writes:

verify(sizeof(virtgpu_ctrl_hdr) == 24);

and calls it a day.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 539 bytes --]

  reply	other threads:[~2014-09-12 12:48 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11 15:09 [Qemu-devel] [PATCH 0/2] virtio-gpu: hardware specification Gerd Hoffmann
2014-09-11 15:09 ` [Qemu-devel] [PATCH 1/2] virtio-gpu/2d: add hardware spec include file Gerd Hoffmann
2014-09-11 15:15   ` Peter Maydell
2014-09-11 15:40     ` Gerd Hoffmann
2014-09-11 15:19   ` Eric Blake
2014-09-12 10:44     ` Gerd Hoffmann
2014-09-12 12:48       ` Eric Blake [this message]
2014-09-12 12:51         ` Eric Blake
2014-09-12 13:03         ` Peter Maydell
2014-09-14 13:46       ` Michael S. Tsirkin
2014-09-14 14:04         ` Peter Maydell
2014-09-14 14:11           ` Michael S. Tsirkin
2014-09-14 14:32             ` Peter Maydell
2014-09-14 15:09               ` Michael S. Tsirkin
2014-09-14 16:11                 ` Peter Maydell
2014-09-14 16:31                   ` Michael S. Tsirkin
2014-09-15 10:36               ` Gerd Hoffmann
2014-09-15 10:40         ` Gerd Hoffmann
2014-09-15 10:55           ` Michael S. Tsirkin
2014-09-11 15:20   ` Peter Maydell
2014-09-11 15:43     ` Gerd Hoffmann
2014-09-11 15:53       ` Christopher Covington
2014-09-11 18:58       ` [Qemu-devel] [virtio-dev] " Paolo Bonzini
2014-09-11 15:09 ` [Qemu-devel] [PATCH 2/2] virtio-gpu/2d: add docs/specs/virtio-gpu.txt Gerd Hoffmann
2014-09-11 15:30   ` Eric Blake
2014-09-12 11:08     ` Gerd Hoffmann
2014-09-12  9:10   ` [Qemu-devel] [virtio-dev] " Stefan Hajnoczi
2014-09-12 11:38     ` Gerd Hoffmann
2014-09-12 21:14       ` Dave Airlie
2014-09-15 10:14         ` Gerd Hoffmann
2014-09-14  9:16   ` [Qemu-devel] " Michael S. Tsirkin
2014-09-14 11:05     ` [Qemu-devel] [virtio-dev] " Dave Airlie
2014-09-12 21:18 ` [Qemu-devel] [virtio-dev] [PATCH 0/2] virtio-gpu: hardware specification Dave Airlie

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=5412EB89.1080405@redhat.com \
    --to=eblake@redhat.com \
    --cc=airlied@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtualization@lists.linux-foundation.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).