From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, Greg Kurz <groug@kaod.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] virtio-scsi: Fix build with gcc 9
Date: Fri, 1 Mar 2019 14:19:02 +0100 [thread overview]
Message-ID: <13630cdf-77c5-9708-ff96-da687be52d89@redhat.com> (raw)
In-Reply-To: <CAFEAcA94Y5jt8wr3Os7PWT_hA_OLRyL7FQqxdp5B_Lfg1Gy+_A@mail.gmail.com>
On 28/02/19 19:31, Peter Maydell wrote:
> On Thu, 28 Feb 2019 at 17:59, Greg Kurz <groug@kaod.org> wrote:
>>
>> Build fails with gcc 9:
>>
>> CC ppc64-softmmu/hw/scsi/virtio-scsi.o
>> hw/scsi/virtio-scsi.c: In function ‘virtio_scsi_do_tmf’:
>> hw/scsi/virtio-scsi.c:265:39: error: taking address of packed member of ‘struct virtio_scsi_ctrl_tmf_req’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
>> 265 | virtio_tswap32s(VIRTIO_DEVICE(s), &req->req.tmf.subtype);
>> | ^~~~~~~~~~~~~~~~~~~~~
>> cc1: all warnings being treated as errors
>>
>> All the fields in struct virtio_scsi_ctrl_tmf_req are naturally aligned,
>> so we could in theory drop QEMU_PACKED. Unfortunately, the header file
>> is imported from linux which already has the packed attribute. Trying to
>> fix that in the update-linux-headers.sh script is likely to produce
>> ugliness. Turn the call to virtio_tswap32s() into an assignment instead.
>>
>> Signed-off-by: Greg Kurz <groug@kaod.org>
>> ---
>> hw/scsi/virtio-scsi.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
>> index ce99d288b035..839f1202567d 100644
>> --- a/hw/scsi/virtio-scsi.c
>> +++ b/hw/scsi/virtio-scsi.c
>> @@ -262,7 +262,13 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
>> /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
>> req->resp.tmf.response = VIRTIO_SCSI_S_OK;
>>
>> - virtio_tswap32s(VIRTIO_DEVICE(s), &req->req.tmf.subtype);
>> + /*
>> + * req->req.tmf has the QEMU_PACKED attribute. Don't use virtio_tswap32s()
>> + * to avoid compiler errors.
>> + */
>> + req->req.tmf.subtype =
>> + virtio_tswap32(VIRTIO_DEVICE(s), req->req.tmf.subtype);
>> +
>> switch (req->req.tmf.subtype) {
>> case VIRTIO_SCSI_T_TMF_ABORT_TASK:
>> case VIRTIO_SCSI_T_TMF_QUERY_TASK:
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>
> I haven't generally bothered to add comments about packed
> structs when I've switched away from the *s versions of byteswap
> functions, but it doesn't hurt.
>
> We should consider just replacing the other dozen uses
> of virtio_tswap*s() with the non-s versions and dropping the
> s functions entirely...
Applied, thanks.
Paolo
prev parent reply other threads:[~2019-03-01 13:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 17:59 [Qemu-devel] [PATCH] virtio-scsi: Fix build with gcc 9 Greg Kurz
2019-02-28 18:31 ` Peter Maydell
2019-03-01 13:19 ` Paolo Bonzini [this message]
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=13630cdf-77c5-9708-ff96-da687be52d89@redhat.com \
--to=pbonzini@redhat.com \
--cc=groug@kaod.org \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--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).