[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from st
From: |
Thomas Huth |
Subject: |
Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId |
Date: |
Wed, 26 Sep 2018 10:09:17 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
On 2018-09-26 10:07, David Hildenbrand wrote:
> On 26/09/2018 10:04, David Hildenbrand wrote:
>> On 26/09/2018 09:38, Thomas Huth wrote:
>>> The uint16_t member cu_type of struct SenseId is not naturally aligned,
>>> and since the struct is marked with QEMU_PACKED, this can lead to
>>> unaligned memory accesses - which does not work on architectures like
>>> Sparc. Thus remove the QEMU_PACKED here and rather copy the struct
>>> byte by byte when we do copy_sense_id_to_guest().
>>>
>>> Signed-off-by: Thomas Huth <address@hidden>
>>> ---
>>> hw/s390x/css.c | 33 +++++++++++++++++----------------
>>> include/hw/s390x/css.h | 2 +-
>>> 2 files changed, 18 insertions(+), 17 deletions(-)
>>>
>>> diff --git a/hw/s390x/css.c b/hw/s390x/css.c
>>> index 5a9fe45..0e51b85 100644
>>> --- a/hw/s390x/css.c
>>> +++ b/hw/s390x/css.c
>>> @@ -750,20 +750,20 @@ static void sch_handle_halt_func(SubchDev *sch)
>>>
>>> }
>>>
>>> -static void copy_sense_id_to_guest(SenseId *dest, SenseId *src)
>>> +static void copy_sense_id_to_guest(uint8_t *dest, SenseId *src)
>>> {
>>> int i;
>>>
>>> - dest->reserved = src->reserved;
>>> - dest->cu_type = cpu_to_be16(src->cu_type);
>>> - dest->cu_model = src->cu_model;
>>> - dest->dev_type = cpu_to_be16(src->dev_type);
>>> - dest->dev_model = src->dev_model;
>>> - dest->unused = src->unused;
>>> - for (i = 0; i < ARRAY_SIZE(dest->ciw); i++) {
>>> - dest->ciw[i].type = src->ciw[i].type;
>>> - dest->ciw[i].command = src->ciw[i].command;
>>> - dest->ciw[i].count = cpu_to_be16(src->ciw[i].count);
>>> + dest[0] = src->reserved;
>>> + stw_be_p(dest + 1, src->cu_type);
>>> + dest[3] = src->cu_model;
>>> + stw_be_p(dest + 4, src->dev_type);
>>> + dest[6] = src->dev_model;
>>> + dest[7] = src->unused;
>>> + for (i = 0; i < ARRAY_SIZE(src->ciw); i++) {
>>> + dest[8 + i * 4] = src->ciw[i].type;
>>> + dest[9 + i * 4] = src->ciw[i].command;
>>> + stw_be_p(dest + 10 + i * 4, src->ciw[i].count);
>>
>>
>> Not really a fan of this, as we sacrifice readability due to one
>> unaligned member. What about only converting the unaligned members (e.g.
>> cu_type) from uint16_t to uint8_t[2] and adding a comment why this is
>> split. Then the structure is naturally packed.
>>
>> We only have to fixup the places that check cu_type.
>>
>
> Just realized this was basically suggested by Peter. If it would be as
> simple as splitting VMSTATE_UINT16 into two VMSTATE_UINT8 or similar, I
> would prefer that.
It's not that simple, it would break migration from older versions of
QEMU due to endianness issues then.
Thomas
- Re: [qemu-s390x] [PATCH v2 1/3] hw/s390x/ipl: Fix alignment problems of S390IPLState members, (continued)
Re: [qemu-s390x] [PATCH v2 1/3] hw/s390x/ipl: Fix alignment problems of S390IPLState members, Peter Maydell, 2018/09/27
[qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, Thomas Huth, 2018/09/26
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, David Hildenbrand, 2018/09/26
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, David Hildenbrand, 2018/09/26
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId,
Thomas Huth <=
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, David Hildenbrand, 2018/09/26
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, Thomas Huth, 2018/09/26
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, David Hildenbrand, 2018/09/26
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, Cornelia Huck, 2018/09/26
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, Thomas Huth, 2018/09/26
- Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, David Hildenbrand, 2018/09/26
- Re: [qemu-s390x] [Qemu-devel] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, Philippe Mathieu-Daudé, 2018/09/26
- Re: [qemu-s390x] [Qemu-devel] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, David Hildenbrand, 2018/09/26
- Re: [qemu-s390x] [Qemu-devel] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, Thomas Huth, 2018/09/26
Re: [qemu-s390x] [PATCH v2 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId, Thomas Huth, 2018/09/26