[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [qemu-s390x] [PATCH v2 1/3] hw/s390x/ipl: Fix alignment problems of

From: Peter Maydell
Subject: Re: [qemu-s390x] [PATCH v2 1/3] hw/s390x/ipl: Fix alignment problems of S390IPLState members
Date: Thu, 27 Sep 2018 14:40:27 +0100

On 26 September 2018 at 08:38, Thomas Huth <address@hidden> wrote:
> The IplParameterBlock and QemuIplParameters structures are declared
> with QEMU_PACKED, so the compiler assumes that the structures do not
> need to be aligned in memory. Since the are listed after a "bool"
> within the S390IPLState, the IplParameterBlock and QemuIplParameters
> are also indeed mis-aligned in memory. This causes problems on Sparc
> during migration, since we use VMSTATE_UINT16 in vmstate_iplb to access
> the devno member for example, and the corresponding migration functions
> (like qemu_get_be16s) then try to access a 16-bit value from a mis-
> aligned memory address.
> The easiest solution to fix this problem is to move the packed structures
> to the beginning of the S390IPLState. Also add some additional comments
> here to prevent that this problem will be introduced again in the future.

> +QEMU_BUILD_BUG_MSG(offsetof(S390IPLState, iplb) & 3, "alignment of iplb 
> wrong");

Incidentally, new gcc has an attribute "warn_if_not_aligned" so you can say

struct S390IPLState {
    IplParameterBlock iplb __attribute__((warn_if_not_aligned(4)));


and then the compiler will warn if the alignment isn't as specified.
But that needs such a new version of gcc we're better off with

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]