From: Vineet Gupta <Vineet.Gupta1@synopsys.com>
To: Arnd Bergmann <arnd@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Masahiro Yamada <masahiroy@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Jann Horn <jannh@google.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
arcml <linux-snps-arc@lists.infradead.org>,
"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>
Subject: Heads up: gcc miscompiling initramfs zlib decompression code at -O3
Date: Fri, 30 Apr 2021 20:46:16 +0000 [thread overview]
Message-ID: <75d07691-1e4f-741f-9852-38c0b4f520bc@synopsys.com> (raw)
Hi,
I've hit a mainline gcc 10.2 (also gcc 9.3) bug which triggers at -O3
causing wrong codegen.
Config needs to have initramfs + gzip compressed.
CONFIG_HAVE_KERNEL_GZIP=y
CONFIG_KERNEL_GZIP=y
CONFIG_DECOMPRESS_GZIP=y
CONFIG_INITRAMFS_COMPRESSION_GZIP=y
lib/zlib_inflate/inffast.c
if (dist > 2) {
unsigned short *sfrom;
sfrom = (unsigned short *)(from);
loops = len >> 1;
do
*sout++ = *sfrom++;
^^^^^^ ^^^^^^^^
while (--loops);
out = (unsigned char *)sout;
from = (unsigned char *)sfrom;
}
...
The gist of issue is that despite use of unsigned short pointers, gcc is
generating wider load/stores (8-byte LDD/STD on arcv2 and 16-byte on
aarch64) causing extraneous bytes to copied into inflated gzip binaries
manifesting later as corrupted fragments in the binaries.
I've opened a gcc bug at:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100363
The workaround is to build lib/zlib_inflate/inffast.c with -O2, although
I reckon not many arches build with -O3 as default. I'll be proposing an
ARC only patch to build this file with -O2, unless people think it needs
to be generalized.
Also problem originally seen on 5.6 kernel, although I confirm it shows
on latest mainline as well.
Unraveling this pretty fun, gory details for those interested at:
https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/372
Thx,
-Vineet
next reply other threads:[~2021-04-30 20:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-30 20:46 Vineet Gupta [this message]
2021-04-30 22:06 ` Heads up: gcc miscompiling initramfs zlib decompression code at -O3 Linus Torvalds
2021-04-30 22:44 ` Vineet Gupta
2021-04-30 22:52 ` Linus Torvalds
2021-05-01 21:03 ` Oleksandr Natalenko
2021-05-03 17:41 ` Linus Torvalds
2021-05-03 19:18 ` Vineet Gupta
2021-05-05 17:44 ` Heiko Carstens
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=75d07691-1e4f-741f-9852-38c0b4f520bc@synopsys.com \
--to=vineet.gupta1@synopsys.com \
--cc=arnd@kernel.org \
--cc=jannh@google.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=masahiroy@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.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).