From: Igor Mammedov <imammedo@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] tests/bios-tables-test: Fix endianess problems when passing data to iasl
Date: Tue, 21 Nov 2017 17:58:12 +0100 [thread overview]
Message-ID: <20171121175812.6f922e2e@redhat.com> (raw)
In-Reply-To: <20171121182432-mutt-send-email-mst@kernel.org>
On Tue, 21 Nov 2017 18:31:19 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Tue, Nov 21, 2017 at 05:22:36PM +0100, Igor Mammedov wrote:
> > > > > > > > probably it's been discussed but, why not do
> > > > > > > > leXX_to_cpu()
> > > > > > > > here, instead of making each place that access read field
> > > > > > > > to do leXX_to_cpu() manually.?
> > > > > > > >
> > > > > > > > Beside of keeping access to structure in natural host order,
> > > > > > > > it should also be less error-prone as field users don't
> > > > > > > > have to worry about endianness.
> > > > > > >
> > > > > > > Yes, I suggested that.
> > > > > > > The issue is that we don't byte-swap all of the tables
> > > > > > > (we can't, that would require a full ACPI parser).
> > > > > > > So when byte-swapping we end up with a mixed host/LE
> > > > > > > structures.
> > > > ...
> > > > > > What tables/use-cases do you have in mind where we'd need full
> > > > > > ACPI parser /whatever it is/?
> > > > >
> > > > > We dump ACPI tables for parsing by iasl.
> > > > I don't really see a problem here (i.e. how dumping blobs for
> > > > iasl would require byte-swap all of the tables).
> > >
> > > It's not all the tables. We would need to track what is and
> > > what isn't swapped.
> > Why we need track swapping at all?
> > Why not just convert everything to host order and work with that
> > in C code, so we won't have to deal with mixed endianness anywhere
> > in code beside of accessors wrappers?
>
> It's a tooling issue really.
>
> Consider any structure, e.g. AcpiRsdtDescriptorRev1. We want its fields
> to have specific endian-ness so we can use static checking for that down
> the line.
>
> So it must be LE since we use it to format guest tables.
>
> Therefore this change:
> - uint32_t addr = data->rsdp_table.rsdt_physical_address;
> + uint32_t addr = le32_to_cpu(data->rsdp_table.rsdt_physical_address);
>
> is really a requirement, otherwise we end up with converting
> field format in-place and static checkers can't support that
> right now.
I didn't really used static checker for this purpose but in my humble
experience of writing portable cross platform code, mixed endianness
always was a source of bugs and reviewing corresponding code is much
harder and a way to reduce/simplify code was isolate byte-swapping to
accessors while the the rest of the code works with native encoding.
it seems a bit wrong to make code twisted (when we don't have) for
the sake of some tooling to work.
anyways, if you prefer having mixed endianness here, I won't mind much,
as impact of test case is much smaller so we'll see down the road
if it became any better. (as far as we continue going in direction
of using host byteorder within main qemu acpi code, which we were
doing by gradually converting acpi structures to build_append_foo API)
>
> >
> > > > Where bios-tables-test.c is concerned we should just read
> > > > a blob from qemu (get its location/len/name) and dump it to
> > > > disk without changing anything in it.
> > >
> > > Exactly.
> > >
> > > > > >
> > > > > > > Keeping it all LE seems cleaner.
> > > > > > >
> > > > > > >
next prev parent reply other threads:[~2017-11-21 16:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-16 12:17 [Qemu-devel] [PATCH v2] tests/bios-tables-test: Fix endianess problems when passing data to iasl Thomas Huth
2017-11-20 16:55 ` Igor Mammedov
2017-11-20 20:00 ` Thomas Huth
2017-11-20 20:32 ` Michael S. Tsirkin
2017-11-21 13:26 ` Igor Mammedov
2017-11-21 14:47 ` Michael S. Tsirkin
2017-11-21 15:58 ` Igor Mammedov
2017-11-21 16:02 ` Michael S. Tsirkin
2017-11-21 16:22 ` Igor Mammedov
2017-11-21 16:31 ` Michael S. Tsirkin
2017-11-21 16:58 ` Igor Mammedov [this message]
2017-11-21 17:09 ` Michael S. Tsirkin
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=20171121175812.6f922e2e@redhat.com \
--to=imammedo@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.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).