qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
	Anthony Liguori <aliguori@amazon.com>
Subject: Re: [Qemu-devel] [PATCH v2] acpi-build: don't access unaligned addresses
Date: Tue, 11 Mar 2014 14:31:39 +0200	[thread overview]
Message-ID: <20140311123139.GA26907@redhat.com> (raw)
In-Reply-To: <CAFEAcA9q-d-qyXh8=Az6RcnPLSnZdsPfVEnJ+e7ccQunn8YZ7w@mail.gmail.com>

On Tue, Mar 11, 2014 at 12:29:05PM +0000, Peter Maydell wrote:
> On 10 March 2014 19:56, Michael S. Tsirkin <mst@redhat.com> wrote:
> > casting an unaligned address to e.g.
> > uint32_t can trigger undefined behaviour in C.
> > Replace cast + assignment with memcpy.
> >
> > Reported-by: Peter Maydell <peter.maydell@linaro.org>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> This does fix the clang warnings.
> 
> > -/* Get pointer within table in a safe manner */
> > -#define ACPI_BUILD_PTR(table, size, off, type) \
> > -    ((type *)(acpi_data_get_ptr(table, size, off, sizeof(type))))
> > +/* Set a value within table in a safe manner */
> > +#define ACPI_BUILD_SET_LE(table, size, off, bits, val) \
> > +    do { \
> > +        uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \
> > +        memcpy(acpi_data_get_ptr(table, size, off, \
> > +                                 (bits) / BITS_PER_BYTE), \
> > +               &ACPI_BUILD_SET_LE_val, \
> > +               (bits) / BITS_PER_BYTE); \
> > +    } while (0)
> 
> Personally I would have done:
> 
> #define acpi_stb(table, size, off, val) \
>     stb_le_p(acpi_data_get_ptr(table, size, off, 1), val)
> #define acpi_stw(table, size, off, val) \
>     stw_le_p(acpi_data_get_ptr(table, size, off, 2), val)
> #define acpi_stl(table, size, off, val) \
>     stl_le_p(acpi_data_get_ptr(table, size, off, 4), val)
> #define acpi_stq(table, size, off, val) \
>     stq_le_p(acpi_data_get_ptr(table, size, off, 8), val)
> 
> which keeps the grubby details of memcpy and byteswapping
> in bswap.h. However since it's purely inside this file and
> not specifying an API to the rest of QEMU I don't object
> if you prefer the approach you've taken.
> 
> thanks
> -- PMM

I'll think about it some more - this can be
a patch on top. Let's fix the bug for now.

  reply	other threads:[~2014-03-11 12:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10 19:56 [Qemu-devel] [PATCH v2] acpi-build: don't access unaligned addresses Michael S. Tsirkin
2014-03-11 12:29 ` Peter Maydell
2014-03-11 12:31   ` Michael S. Tsirkin [this message]
2014-03-12 13:37   ` Peter Maydell

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=20140311123139.GA26907@redhat.com \
    --to=mst@redhat.com \
    --cc=aliguori@amazon.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).