From: David Laight <David.Laight@ACULAB.COM>
To: 'Borislav Petkov' <bp@alien8.de>,
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: kernel test robot <lkp@intel.com>,
"llvm@lists.linux.dev" <llvm@lists.linux.dev>,
"oe-kbuild-all@lists.linux.dev" <oe-kbuild-all@lists.linux.dev>,
"rust-for-linux@vger.kernel.org" <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 15:35:55 +0000 [thread overview]
Message-ID: <54dabf8bd3374543b2c72631db4f9c11@AcuMS.aculab.com> (raw)
In-Reply-To: <Y8Ax/I5qOcVDZljG@zn.tnic>
From: Borislav Petkov
> Sent: 12 January 2023 16:15
...
> > 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.
While there would be no padding between any of the stricture members
that is largely irrelevant.
The __packed removes the two pad bytes from the end of the structure
and also tells the compiler that the structure itself may not be
aligned in memory.
So the bitfields can be misaligned in memory.
Quite why they are bitfields is anybodies guess, u16 would suffice.
Using u16 would also generate a known memory layout (bitfields are
best part of compiler defined - certainly not endianness defined.)
If the intent of the __packed is to save 2 bytes on every copy
of the structure then __packed __aligned(2) will have the same
effect while allowing the compiler to use 16-bit accesses.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2023-01-14 15:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-27 12:36 [bp:tip-x86-alternatives 1/1] error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type kernel test robot
2022-12-27 13:52 ` Borislav Petkov
2022-12-27 14:16 ` 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
2023-01-14 12:29 ` Miguel Ojeda
2023-01-14 11:54 ` Miguel Ojeda
2023-01-14 15:35 ` David Laight [this message]
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=54dabf8bd3374543b2c72631db4f9c11@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--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