qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: "Peter Maydell" <peter.maydell@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, "BALATON Zoltan" <balaton@eik.bme.hu>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Alistair Francis" <alistair@alistair23.me>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Jason Wang" <jasowang@redhat.com>,
	"Cédric Le Goater" <clg@kaod.org>, "Greg Kurz" <groug@kaod.org>,
	qemu-arm@nongnu.org,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	qemu-ppc@nongnu.org
Subject: Re: [RFC PATCH-for-8.0 2/3] hw/ppc/spapr: Replace tswap64(HPTE) by cpu_to_be64(HPTE)
Date: Fri, 16 Dec 2022 16:10:56 -0300	[thread overview]
Message-ID: <e8c3fdcb-81f1-7067-217c-c49e8748b84a@gmail.com> (raw)
In-Reply-To: <CAFEAcA96ncqvN9iXybCd2SrVKJ9CKsu5t3_GtdNt1ZEDAkFt0w@mail.gmail.com>



On 12/13/22 10:51, Peter Maydell wrote:
> On Tue, 13 Dec 2022 at 12:52, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> The tswap64() calls introduced in commit 4be21d561d ("pseries:
>> savevm support for pseries machine") are used to store the HTAB
>> in the migration stream (see savevm_htab_handlers) and are in
>> big-endian format.
> 
> I think they're reading the run-time spapr->htab data structure
> (some of which is stuck onto the wire as a stream-of-bytes buffer
> and some of which is not). But either way, it's a target-endian
> data structure, because the code in hw/ppc/spapr_softmmu.c which
> reads and writes entries in it is using ldq_p() and stq_p(),
> and the current in-tree version of these macros is doing a
> "read host 64-bit and convert to/from target endianness wih tswap64".
> 
>>   #define HPTE(_table, _i)   (void *)(((uint64_t *)(_table)) + ((_i) * 2))
>> -#define HPTE_VALID(_hpte)  (tswap64(*((uint64_t *)(_hpte))) & HPTE64_V_VALID)
>> -#define HPTE_DIRTY(_hpte)  (tswap64(*((uint64_t *)(_hpte))) & HPTE64_V_HPTE_DIRTY)
>> -#define CLEAN_HPTE(_hpte)  ((*(uint64_t *)(_hpte)) &= tswap64(~HPTE64_V_HPTE_DIRTY))
>> -#define DIRTY_HPTE(_hpte)  ((*(uint64_t *)(_hpte)) |= tswap64(HPTE64_V_HPTE_DIRTY))
>> +#define HPTE_VALID(_hpte)  (be64_to_cpu(*((uint64_t *)(_hpte))) & HPTE64_V_VALID)
>> +#define HPTE_DIRTY(_hpte)  (be64_to_cpu(*((uint64_t *)(_hpte))) & HPTE64_V_HPTE_DIRTY)
>> +#define CLEAN_HPTE(_hpte)  ((*(uint64_t *)(_hpte)) &= cpu_to_be64(~HPTE64_V_HPTE_DIRTY))
>> +#define DIRTY_HPTE(_hpte)  ((*(uint64_t *)(_hpte)) |= cpu_to_be64(HPTE64_V_HPTE_DIRTY))
> 
> This means we now have one file that's accessing this data structure
> as "this is target-endian", and one file that's accessing it as
> "this is big-endian". It happens that that ends up meaning the same
> thing because PPC is always TARGET_BIG_ENDIAN, but it seems a bit
> inconsistent.
> 
> We should decide whether we're thinking of the data structure
> as target-endian or big-endian and change all the accessors
> appropriately (or none of them -- currently we're completely
> consistent about treating it as "target endian", I think).

Yes, most if not all accesses are being handled as "target endian", even
though the target is always big endian.

IIUC the idea behind Phil's cleanups is exactly to replace uses of
"target-something" if the endianess of the host is irrelevant, which
is the case for ppc64. We would then change the semantics of the code
gradually to make it consistent again.

However, I don't feel comfortable acking this patch alone since 4be21d561d
is from David and I don't know if there's a great design behind the use of
tswap64() to manipulate the hpte. David, would you care to comment?



Daniel

  

> 
> I also think that "cast a pointer into a byte-array to uint64_t*
> and then dereference it" is less preferable than using ldq_p()
> and stq_p(), but that's arguably a separate thing.
> 
> thanks
> -- PMM


  reply	other threads:[~2022-12-16 19:19 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-13 12:52 [RFC PATCH-for-8.0 0/3] hw/ppc: Remove tswap() calls Philippe Mathieu-Daudé
2022-12-13 12:52 ` [RFC PATCH-for-8.0 1/3] hw/ppc: Replace tswap32() by const_le32() Philippe Mathieu-Daudé
2022-12-13 16:00   ` Richard Henderson
2022-12-13 16:10     ` Philippe Mathieu-Daudé
2022-12-13 16:14       ` Richard Henderson
2022-12-13 16:21         ` Peter Maydell
2022-12-13 16:27           ` Richard Henderson
2022-12-13 16:53             ` Cédric Le Goater
2022-12-13 17:23               ` Peter Maydell
2022-12-13 17:51                 ` Edgar E. Iglesias
2022-12-13 18:09                 ` BALATON Zoltan
2022-12-13 21:37                   ` Peter Maydell
2022-12-13 18:13                 ` Cédric Le Goater
2023-05-17 10:51                   ` Thomas Huth
2022-12-13 12:52 ` [RFC PATCH-for-8.0 2/3] hw/ppc/spapr: Replace tswap64(HPTE) by cpu_to_be64(HPTE) Philippe Mathieu-Daudé
2022-12-13 13:51   ` Peter Maydell
2022-12-16 19:10     ` Daniel Henrique Barboza [this message]
2022-12-16 21:39       ` Peter Maydell
2022-12-19  6:31         ` David Gibson
2022-12-19 10:39           ` Peter Maydell
2022-12-21  1:16             ` David Gibson
2022-12-21 12:33               ` Peter Maydell
2022-12-21 16:03                 ` Cédric Le Goater
2022-12-21 22:15                   ` Peter Maydell
2022-12-22  1:56                     ` David Gibson
2022-12-13 12:52 ` [RFC PATCH-for-8.0 3/3] hw/net/xilinx_ethlite: Replace tswap32() by be32_to_cpu() Philippe Mathieu-Daudé
2022-12-13 13:53   ` Peter Maydell
2022-12-13 13:54     ` Edgar E. Iglesias
2022-12-13 14:18       ` Peter Maydell
2022-12-13 14:23         ` Edgar E. Iglesias
2022-12-13 15:22           ` Peter Maydell
2022-12-13 15:41             ` Edgar E. Iglesias
2024-04-22 12:46     ` Philippe Mathieu-Daudé
2022-12-13 16:56 ` [RFC PATCH-for-8.0 0/3] hw/ppc: Remove tswap() calls Cédric Le Goater

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=e8c3fdcb-81f1-7067-217c-c49e8748b84a@gmail.com \
    --to=danielhb413@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=alistair@alistair23.me \
    --cc=balaton@eik.bme.hu \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=edgar.iglesias@gmail.com \
    --cc=groug@kaod.org \
    --cc=jasowang@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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).