From: Pavel Pisa <pisa@cmp.felk.cvut.cz>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Jason Wang <jasowang@redhat.com>,
Vikram Garhwal <fnu.vikram@xilinx.com>,
qemu-devel@nongnu.org
Subject: Re: [PATCH for-5.2 3/4] hw/net/can/ctucan_core: Handle big-endian hosts
Date: Fri, 6 Nov 2020 19:46:09 +0100 [thread overview]
Message-ID: <202011061946.09189.pisa@cmp.felk.cvut.cz> (raw)
In-Reply-To: <51da5abd-bb51-2ee0-d1e8-dd3f0c93e2fa@amsat.org>
On Friday 06 of November 2020 19:29:27 Philippe Mathieu-Daudé wrote:
> On 11/6/20 6:11 PM, Peter Maydell wrote:
> > The ctucan driver defines types for its registers which are a union
> > of a uint32_t with a struct with bitfields for the individual
> > fields within that register. This is a bad idea, because bitfields
> > aren't portable. The ctu_can_fd_regs.h header works around the
> > most glaring of the portability issues by defining the
> > fields in two different orders depending on the setting of the
> > __LITTLE_ENDIAN_BITFIELD define. However, in ctucan_core.h this
> > is unconditionally set to 1, which is wrong for big-endian hosts.
> >
> > Set it only if HOST_WORDS_BIGENDIAN is not set. There is no need
> > for a "have we defined it already" guard, because the only place
> > that should set it is ctucan_core.h, which has the usual
> > double-inclusion guard.
> >
> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> > ---
> > Ideally all that bitfield-using code would be rewritten to use
> > extract32 and deposit32 instead, IMHO.
> > ---
> > hw/net/can/ctucan_core.h | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/hw/net/can/ctucan_core.h b/hw/net/can/ctucan_core.h
> > index f21cb1c5ec3..bbc09ae0678 100644
> > --- a/hw/net/can/ctucan_core.h
> > +++ b/hw/net/can/ctucan_core.h
> > @@ -31,8 +31,7 @@
> > #include "exec/hwaddr.h"
> > #include "net/can_emu.h"
> >
> > -
> > -#ifndef __LITTLE_ENDIAN_BITFIELD
> > +#ifndef HOST_WORDS_BIGENDIAN
> > #define __LITTLE_ENDIAN_BITFIELD 1
> > #endif
>
> Alternatively s/#ifdef __LITTLE_ENDIAN_BITFIELD/#ifndef
> HOST_WORDS_BIGENDIAN/ the codebase and remove this here...
But then we cannot have same generated, untouch header file
common for Linux kernel and QEMU. Each uses different defines.
Or at least it was the goal, but after mainline Linux review
we switch in longer run to defines with use of BIT, GENMASK
FIELD_GET and FIELD_PREP.
But even GENMASK does not seem to be defined in QEMU headers
even that it is referenced in include/hw/usb/dwc2-regs.h
and include/standard-headers/asm-x86/kvm_para.h
So idea to have nice common generated headers which can
be checked for consistency and right version by diff
for Linux kernel, QEMU and even userspace tests
and other OSes (there with Linux defines substitution)
seems to be only dream.
Anyway, we switch to solution which is matching requirements
of each project if it is suggested. But it takes time.
Best wishes,
Pavel
next prev parent reply other threads:[~2020-11-06 18:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-06 17:11 [PATCH for-5.2 0/4] hw/net/can/ctucan: fix Coverity and other issues Peter Maydell
2020-11-06 17:11 ` [PATCH for-5.2 1/4] hw/net/can/ctucan: Don't allow guest to write off end of tx_buffer Peter Maydell
2020-11-06 17:47 ` Pavel Pisa
2020-11-06 18:04 ` Peter Maydell
2020-11-06 18:30 ` Pavel Pisa
2020-11-06 17:11 ` [PATCH for-5.2 2/4] hw/net/can/ctucan: Avoid unused value in ctucan_send_ready_buffers() Peter Maydell
2020-11-06 18:11 ` Pavel Pisa
2020-11-09 11:07 ` Peter Maydell
2020-11-06 17:11 ` [PATCH for-5.2 3/4] hw/net/can/ctucan_core: Handle big-endian hosts Peter Maydell
2020-11-06 18:29 ` Philippe Mathieu-Daudé
2020-11-06 18:46 ` Pavel Pisa [this message]
2020-11-06 17:11 ` [PATCH for-5.2 4/4] hw/net/ctucan_core: Use stl_le_p to write to tx_buffers Peter Maydell
2020-11-06 18:18 ` Pavel Pisa
2020-11-06 18:34 ` Peter Maydell
2020-11-06 18:31 ` Philippe Mathieu-Daudé
2020-11-06 18:36 ` Philippe Mathieu-Daudé
2020-11-06 18:39 ` 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=202011061946.09189.pisa@cmp.felk.cvut.cz \
--to=pisa@cmp.felk.cvut.cz \
--cc=f4bug@amsat.org \
--cc=fnu.vikram@xilinx.com \
--cc=jasowang@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).