qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: Patrick Venture <venture@google.com>,
	pbonzini@redhat.com, peterx@redhat.com,  david@redhat.com,
	philmd@linaro.org, qemu-devel@nongnu.org,
	 Chris Rauer <crauer@google.com>,
	Peter Foley <pefoley@google.com>
Subject: Re: [PATCH] softmmu/memory: use memcpy for multi-byte accesses
Date: Wed, 15 Nov 2023 10:30:13 +0000	[thread overview]
Message-ID: <CAFEAcA89CADp4FhwHd2O_7F07OfwpFZCb534jOjSK4uUt+sqfA@mail.gmail.com> (raw)
In-Reply-To: <bc43ecb5-f93b-4288-a6e1-624aebfcffcc@linaro.org>

On Tue, 14 Nov 2023 at 21:18, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 11/14/23 12:55, Patrick Venture wrote:
> > Avoids unaligned pointer issues.
> >
> > Reviewed-by: Chris Rauer <crauer@google.com>
> > Reviewed-by: Peter Foley <pefoley@google.com>
> > Signed-off-by: Patrick Venture <venture@google.com>
> > ---
> >   system/memory.c | 16 ++++++++--------
> >   1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/system/memory.c b/system/memory.c
> > index 304fa843ea..02c97d5187 100644
> > --- a/system/memory.c
> > +++ b/system/memory.c
> > @@ -1343,16 +1343,16 @@ static uint64_t memory_region_ram_device_read(void *opaque,
> >
> >       switch (size) {
> >       case 1:
> > -        data = *(uint8_t *)(mr->ram_block->host + addr);
> > +        memcpy(&data, mr->ram_block->host + addr, sizeof(uint8_t));
>
>
> This is incorrect, especially for big-endian hosts.
>
> You want to use "qemu/bswap.h", ld*_he_p(), st*_he_p().

More specifically, we have a ldn_he_p() and stn_he_p() that
take the size in bytes of the data to read, so we should be
able to replace the switch-on-size in these functions with
a single call to the appropriate one of those.

thanks
-- PMM


  parent reply	other threads:[~2023-11-15 10:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 20:55 [PATCH] softmmu/memory: use memcpy for multi-byte accesses Patrick Venture
2023-11-14 21:18 ` Richard Henderson
2023-11-14 21:39   ` Patrick Venture
2023-11-15 10:30   ` Peter Maydell [this message]
2023-11-15 16:57     ` Patrick Venture
2023-11-15 10:34 ` Peter Maydell
2023-11-15 16:58   ` Patrick Venture
2023-11-15 17:02     ` Richard Henderson
2023-11-15 17:26       ` Patrick Venture
2023-11-15 17:26         ` Patrick Venture
2023-11-16 11:30         ` 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=CAFEAcA89CADp4FhwHd2O_7F07OfwpFZCb534jOjSK4uUt+sqfA@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=crauer@google.com \
    --cc=david@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pefoley@google.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=venture@google.com \
    /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).