This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
Home Products Support Community News


[Xen-devel] Re: [Qemu-devel] [PATCH 5/7] xen: add block device backend d

To: Paul Brook <paul@xxxxxxxxxxxxxxxx>
Subject: [Xen-devel] Re: [Qemu-devel] [PATCH 5/7] xen: add block device backend driver.
From: Gerd Hoffmann <kraxel@xxxxxxxxxx>
Date: Tue, 05 Aug 2008 09:18:33 +0200
Cc: Blue Swirl <blauwirbel@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx, qemu-devel@xxxxxxxxxx
Delivery-date: Tue, 05 Aug 2008 00:23:02 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <200808042104.16383.paul@xxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1217865045-10722-1-git-send-email-kraxel@xxxxxxxxxx> <f43fc5580808041026t49c8962fhe6ef926608e3db6c@xxxxxxxxxxxxxx> <48975D9A.7070109@xxxxxxxxxx> <200808042104.16383.paul@xxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird (X11/20080501)
Paul Brook wrote:
> On Monday 04 August 2008, Gerd Hoffmann wrote:
>> Blue Swirl wrote:
>>> On 8/4/08, Gerd Hoffmann <kraxel@xxxxxxxxxx> wrote:
>>>>  +/* i386 protocol version */
>>>>  +#pragma pack(push, 4)
>>> What's wrong with __attribute__(__aligned__)?
>> That one is tricky because we must be binary compatible with xen.  And
>> the block driver protocol has a small design flaw:  It has a 64bit value
>>  which is not aligned on a 64bit border.  This leads to different struct
>> layouts on i386 and x86_64 due to different alignment rules.  Unless you
>> force them into something else, like we do in that header file to deal
>> with it.  Which is needed to run 32bit guests on 64bit hosts.
> qemu should be host independent. You need to use packed structures with 
> appropriate padding.

I think the current code is correct.  Ok, the verbose version.  The
struct in question looks like this:

   struct blkif_request {
           uint8_t        operation;
           uint8_t        nr_segments;
           blkif_vdev_t   handle;
           uint64_t       id;
           [ ... ]

The critical element is id.  blkif_vdev_t is uint16_t, which means id is
32bit aligned but not 64bit aligned.

On i386 64bit values get 32bit alignments by default.
On x86_64 64bit values get 64bit alignments by default.
Thus x86_64 has a 32bit padding hole just before id.  i386 hasn't.

So we define a i386 and a x86_64 version of the struct.  The i386
version is wrapped into a pragma like this ...

   #pragma pack(push, 4)
   struct blkif_x86_32_request {
           [ ... ]
   #pragma pack(pop)

... to enforce i386 alignment rules everythere.
The x86_64 version looks like this ...

   struct blkif_x86_64_request {
           [ ... ]
           uint64_t       __attribute__((__aligned__(8))) id;
           [ ... ]

... to make sure the id element is 64bit aligned everythere.

That gives us the correct struct layouts for both i386 and x86_64 builds.



Xen-devel mailing list

<Prev in Thread] Current Thread [Next in Thread>