From: David Laight <david.laight.linux@gmail.com>
To: Ian Rogers <irogers@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
kernel test robot <lkp@intel.com>,
Eric Biggers <ebiggers@google.com>,
Yuzhuo Jing <yuzhuo@google.com>,
Andy Lutomirski <luto@kernel.org>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev
Subject: Re: [PATCH v3 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
Date: Wed, 23 Jul 2025 23:14:03 +0100 [thread overview]
Message-ID: <20250723231403.6ef5c162@pumpkin> (raw)
In-Reply-To: <CAP-5=fWeK4RnL8=BQm3o3u0KoONYEptwEYFBC5_DkJTbgpbx9g@mail.gmail.com>
On Tue, 22 Jul 2025 10:00:51 -0700
Ian Rogers <irogers@google.com> wrote:
...
> Oh, the actual warning is "leaves the object uninitialized". It is
> possible to silence this by changing:
>
> const U16 __get_unaligned_ctrl_type __always_unused;
>
> to something like:
>
> const U16 __get_unaligned_ctrl_type __always_unused = 0;
>
> You then get complained at that the code is using 0 instead of NULL
> when instead of U16 the type of the __get_unaligned_t is a pointer.
> Basically I've entered into an analysis tool wac-a-mole and I don't
> have a combination to make them all happy.
Can you embed the variable inside a struct and then initialise with {} ?
Does this code actually work all the time?
There have always been 'problems' because gcc remembers the alignment
of pointers through (void *) casts.
So if your misaligned pointer has a type that should be aligned
them memcpy(&dest, (void *)misaligned_int_ptr, 4) will still do an
aligned read.
You also really need the compiler to optimise the memcpy into two
memory reads, some shifts, masks and ors, and a single write to a
register.
I'm not at all sure that is going to happen.
(Especially since I've never seen it optimised to only two reads
even when reading 'packed' variables.
David
>
> Thanks,
> Ian
>
next prev parent reply other threads:[~2025-07-23 22:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-26 5:48 [PATCH v3 0/3] Switch get/put unaligned to use memcpy Ian Rogers
2025-06-26 5:48 ` [PATCH v3 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
2025-06-27 7:58 ` kernel test robot
2025-07-05 0:05 ` kernel test robot
2025-07-22 15:56 ` Thomas Gleixner
2025-07-22 16:44 ` Ian Rogers
2025-07-22 17:00 ` Ian Rogers
2025-07-23 22:14 ` David Laight [this message]
2025-08-18 16:03 ` Ian Rogers
2025-06-26 5:48 ` [PATCH v3 2/3] tools headers: Update the linux/unaligned.h copy with the kernel sources Ian Rogers
2025-06-26 5:48 ` [PATCH v3 3/3] tools headers: Remove unneeded ignoring of warnings in unaligned.h Ian Rogers
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=20250723231403.6ef5c162@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=Jason@zx2c4.com \
--cc=acme@redhat.com \
--cc=christophe.leroy@csgroup.eu \
--cc=ebiggers@google.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=lkp@intel.com \
--cc=llvm@lists.linux.dev \
--cc=luto@kernel.org \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=tglx@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=yuzhuo@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.