From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8486DCE8D61 for ; Thu, 19 Sep 2024 09:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Dj2SnZc2tGXjjqybW+fv5E5YFwQPNMJo5Jn7VIvNaV0=; b=Us+kI0UyYE3RgLglG36S5h7CLP 8q4gmyVBzYmweVuxg2+6J6Y+u5s6ZVaZWbpm4sXIkK0xiGONRbIaR3+jlgOlV4xvXQfG/r8n0Td6m zUuuE5VnRbesC8vxNUvVN676yxPK3+7QgXbsH6k3+i8SobJVopEall4GAIWa/oC7PVMi4M4ijRx9S 14TCzTF/6LRpmX7Ut34EYI3zALYTuk6PRsshx+HSKhuHK5fyi7piRuSIAmsSxuZfLCn8/vRVcNVdC Ic+JmsLi9ZyxsotVvqNOU3lu9sSTF59HirNbV5SjZe32SwCYW5QgqnQ0wO2go75SAXqcx0rdrd0q+ Db3ud6cg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srDGf-00000009tGr-18k6; Thu, 19 Sep 2024 09:16:05 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srDFX-00000009t2I-3EIy for linux-arm-kernel@lists.infradead.org; Thu, 19 Sep 2024 09:14:57 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F0451007; Thu, 19 Sep 2024 02:15:22 -0700 (PDT) Received: from J2N7QTR9R3 (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9EF2B3F71A; Thu, 19 Sep 2024 02:14:50 -0700 (PDT) Date: Thu, 19 Sep 2024 11:14:45 +0200 From: Mark Rutland To: Ard Biesheuvel Cc: Marc Zyngier , Will Deacon , syzbot , catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Subject: Re: [syzbot] [arm?] upstream test error: KASAN: invalid-access Write in setup_arch Message-ID: References: <000000000000f362e80620e27859@google.com> <20240830095254.GA7769@willie-the-truck> <86wmjwvatn.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240919_021455_881385_7123A3C6 X-CRM114-Status: GOOD ( 22.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 05, 2024 at 04:25:57PM +0200, Ard Biesheuvel wrote: > On Thu, 5 Sept 2024 at 16:03, Mark Rutland wrote: > > Putting the KASAN issue aside (which I'll handle in a separate thread), > > I think there is a real issue here with LLVM. > > > > What's going on here is that .idmap.text ends up more than 128M away > > from .head.text, so the 'b primary_entry' at the start of the Image > > isn't in range: > > > > | [mark@lakrids:~/src/linux]% usekorg 14.1.0 aarch64-linux-objdump -t vmlinux | grep -w _text > > | ffff800080000000 g .head.text 0000000000000000 _text > > | [mark@lakrids:~/src/linux]% usekorg 14.1.0 aarch64-linux-objdump -t vmlinux | grep -w primary_entry > > | ffff8000889df0e0 g .rodata.text 000000000000006c primary_entry > > > > ... as those are ~128MiB apart. > > > > When building with GCC those end up ~101MiB apart: > > > > | [mark@lakrids:~/src/linux]% usekorg 14.1.0 aarch64-linux-objdump -t vmlinux | grep -w _text > > | ffff800080000000 g .head.text 0000000000000000 _text > > | [mark@lakrids:~/src/linux]% usekorg 14.1.0 aarch64-linux-objdump -t vmlinux | grep -w primary_entry > > | ffff8000865ae0e0 g .rodata.text 000000000000006c primary_entry > > > > When that happens, LLD makes the header branch to a veneer/thunk: > > > > | ffff800080000000 <_text>: > > | ffff800080000000: fa405a4d ccmp x18, #0x0, #0xd, pl // pl = nfrst > > | ffff800080000004: 14003fff b ffff800080010000 <__AArch64AbsLongThunk_primary_entry> > > > > ... and unfortunately, that veneer/thunk uses a literal with the > > statically-linked TTBR1 address of primary_entry: > > > > | ffff800080010000 <__AArch64AbsLongThunk_primary_entry>: > > | ffff800080010000: 58000050 ldr x16, ffff800080010008 <__AArch64AbsLongThunk_primary_entry+0x8> > > | ffff800080010004: d61f0200 br x16 > > | ffff800080010008: 889df0e0 .word 0x889df0e0 > > | ffff80008001000c: ffff8000 .word 0xffff8000 > > > ... > > LLVM folk, is there any existing option to ask LLD to use ADRP+ADD for > > the veneer/thunk? ... and if not, would it be possible to add an option > > for that? > > > > ld.lld takes --pic-veneer, which (from looking at the llvm sources) > appears to do what we need here. Ah; now I take another look I see that's in the man page and is also supported by GNU LD, so I'll spin a patch to use that. Thanks for the pointer! Mark.