From: Gary Guo <gary@garyguo.net>
To: Borislav Petkov <bp@alien8.de>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
kernel test robot <lkp@intel.com>,
llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
rust-for-linux@vger.kernel.org,
lkml <linux-kernel@vger.kernel.org>,
Yujie Liu <yujie.liu@intel.com>
Subject: Re: [bp:tip-x86-alternatives 1/1] error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
Date: Sat, 14 Jan 2023 02:18:35 +0000 [thread overview]
Message-ID: <20230114021835.06749ef7.gary@garyguo.net> (raw)
In-Reply-To: <Y8Ax/I5qOcVDZljG@zn.tnic>
On Thu, 12 Jan 2023 17:14:52 +0100
Borislav Petkov <bp@alien8.de> wrote:
> On Sat, Jan 07, 2023 at 01:38:42AM +0100, Miguel Ojeda wrote:
> > You are of course right that the instructions are not complete, I just
> > meant to add a bit of context, i.e. that Rust got enabled due to the
> > config, but as far as I understand, it shouldn't be getting enabled in
> > the other ones for the moment.
>
> Right, or at least the repro instructions should state it clear.
>
> Btw, this is part of a long-running feedback process we're giving to the 0day
> bot in order to make their reports as user friendly as possible.
>
> > My point was that the script expects some variables set by `Makefile`,
> > similar to `$CC` etc., so that output does not imply you have (or not)
> > a suitable Rust toolchain installed (i.e. it will currently also fail
> > if you have it installed).
>
> Aha.
>
> > Meanwhile (of course it is not the same as proper reproduction
> > instructions since the LKP team may do something different), the
> > documentation on how to set it up for a normal developer is at:
> > https://www.kernel.org/doc/html/latest/rust/quick-start.html, in case
> > it helps (if you are up for it... :)
>
> Probably that link should be part of those reproduction instructions.
>
> > > And while we're reporting bugs: the error message from the compiler itself could
> > > use some "humanization" - I have zero clue what it is trying to tell me.
> >
> > What would you want to see? We can ask the relevant Rust team to see
> > if they can improve it.
> >
> > In general, note that you can ask `rustc` to further explain an error
> > giving it the code with `--explain`. The compiler suggests this
> > itself, but sadly the robot cut it out :(
>
> Well, I find having an --explain option too much. But there are perhaps reasons
> for it.
>
> One improvement could be, IMHO, they could turn on --explain automatically when
> it results in a build error. So that you don't have to do it yourself.
>
> What would be better, tho, is if there were no --explain option at all and the
> warnings are as human readable as possible.
>
> > For more information about this error, try `rustc --explain E0588`
> >
> > In this case, it gives:
> >
> > A type with `packed` representation hint has a field with `align`
> > representation hint.
> > ...
>
> so the struct is:
>
> struct alt_instr {
> s32 instr_offset; /* original instruction */
> s32 repl_offset; /* offset to replacement instruction */
>
> union {
> struct {
> u32 cpuid: 16; /* CPUID bit set for replacement */
> u32 flags: 16; /* patching control flags */
> };
> u32 ft_flags;
> };
>
> u8 instrlen; /* length of original instruction */
> u8 replacementlen; /* length of new instruction */
> } __packed;
>
> and everything is naturally aligned.
>
> So I'm guessing this is a rust bindings glue shortcoming or so...
>
> Thx.
>
Hi Borislav,
Thanks for the MCVE. I'm able to figure out what exactly went
wrong.
In the struct you shown, `alt_instr.cpuid` and `alt_instr.flags` are
16-bit aligned (TIL bitfields alignments are related to their bit width
only, *NOT* the declared type), while the whole anonymous struct
containing them is 32-bit aligned (because u32 is used as type of
bitfields).
When generating bindings, bindgen decides to put a `#[repr(align(4))]`
when generating the anonymous struct to raise its alignment from 16 to
32 so that the struct is ABI compatible with C again. As a result, it
generates a `#[repr(align(...))` struct nested within `#[repr(packed)]`
struct, which is in turn rejected by rustc.
This isn't the only issue however, it seems that bindgen doesn't
consider alignment of bitfields when deciding if an explicit
`#[repr(align)]` is needed anyway, so it will stick such an attribute
to all struct containing only bitfields. So it doesn't help if `u32` is
changed to `u16` here.
This is a definitely a bindgen bug. I'll have a think about how to fix
it...
Best,
Gary
next prev parent reply other threads:[~2023-01-14 2:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <202212272003.rgQDX8DQ-lkp@intel.com>
[not found] ` <Y6r4mXz5NS0+HVXo@zn.tnic>
2022-12-27 14:16 ` [bp:tip-x86-alternatives 1/1] error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type Borislav Petkov
2022-12-27 20:31 ` Alexander Altman
2022-12-27 21:14 ` Borislav Petkov
2023-01-06 23:26 ` Miguel Ojeda
2023-01-07 0:42 ` Miguel Ojeda
2023-01-06 23:25 ` Miguel Ojeda
2023-01-06 23:57 ` Borislav Petkov
2023-01-07 0:38 ` Miguel Ojeda
2023-01-12 16:14 ` Borislav Petkov
2023-01-14 2:18 ` Gary Guo [this message]
2023-01-14 12:29 ` Miguel Ojeda
2023-01-14 11:54 ` Miguel Ojeda
2023-01-14 15:35 ` David Laight
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=20230114021835.06749ef7.gary@garyguo.net \
--to=gary@garyguo.net \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=llvm@lists.linux.dev \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
--cc=yujie.liu@intel.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).