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 3EA1FC433FE for ; Thu, 28 Apr 2022 10:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Vnz1wYOgKJX9xyxb92WNxcBNxjq9IxO4lpOciBrsZYE=; b=qq6J60zIrqvgxg ifo9e3cEhIfG7cxoritqtaodlJhhw7zoaiUr004UN9NH+KHyDqp0rhcK0v4umyatYqUxF7bhd3vfO 5XHTp2lwlycNT0J7lriUBkj6vi5zmGChKA9qvThhiNX9YADnkKsIefaZ7IDvzqDAa0tOqqTHql/34 Diay5gEbhFZV5jJvTjf190Ke9l9zM6/lT4qy7DJr36fWm2ZrO3dzH9L+YHrP200p2e/QAsGL/AX5j bLGgnqN+I65AB4okLp6RelVP4rQsIz3jFUZKL3/iu4hLjy0wyZX85L2AH1cRxqTubzAcXdBsL5etu wavWlSIP6JfkrCia19wg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0yl-005ws7-Ie; Thu, 28 Apr 2022 10:02:31 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk0oC-005s82-26 for linux-arm-kernel@lists.infradead.org; Thu, 28 Apr 2022 09:51:38 +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 9C4B51474; Thu, 28 Apr 2022 02:51:34 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.44.187]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 109613F774; Thu, 28 Apr 2022 02:51:32 -0700 (PDT) Date: Thu, 28 Apr 2022 10:51:28 +0100 From: Mark Rutland To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, clang-built-linux@googlegroups.com, will@kernel.org, catalin.marinas@arm.com, keescook@chromium.org, nathan@kernel.org, Sami Tolvanen , Nick Desaulniers Subject: Re: [RFC PATCH 1/2] arm64: jump_label: use more precise asm constraints Message-ID: References: <20220427171241.2426592-1-ardb@kernel.org> <20220427171241.2426592-2-ardb@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220427171241.2426592-2-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220428_025136_286232_7B5EDA0A X-CRM114-Status: GOOD ( 22.71 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Ard, On Wed, Apr 27, 2022 at 07:12:40PM +0200, Ard Biesheuvel wrote: > In order to set bit #0 of the struct static_key pointer in the the jump > label struct I think you mean jump_entry::key here? > , we currently cast the pointer to char[], and take the > address of either the 0th or 1st array member, depending on the value of > 'branch'. This works but creates problems with -fpie code generation: > GCC complains about the constraint being unsatisfiable, and Clang > miscompiles the code in a way that causes stability issues (immediate > panic on 'attempt to kill init') I couldn't reproduce that stability issue locally playing with Clang 12.0.0 and 14.0.0 (and just applying patch 2 of this series atop v5.18-rc1). I built defconfig and booted that under a QEMU HVF VM on an M1 Mac. FWIW, I used the binaries from llvm.org and built with: // magic script to add the toolchains to my PATH usellvm 12.0.0 make LLVM=1 ARCH=arm64 defconfig usellvm 12.0.0 make LLVM=1 ARCH=arm64 -j50 Image ... and QEMU isn't providing entropy to the guest, so it's possible that: * This only goes wrong when randomizing VAs (maybe we get a redundant relocation, and corrupt the key offset?). * This is specific to the LLVM binaries you're using. * This is down to a combination of LLVM + binutils, if you're not building with LLVM=1? I had a go with Clang 12.0.0 and the kernel.org crosstool GCC 11.1.0 release's binutils. I made the constraint "Si" but left the indexing logic, and that still worked fine. > So instead, pass the struct static_key reference and the 'branch' > immediate individually, in a way that satisfies both GCC and Clang (GCC > wants the 'S' constraint, whereas Clang wants the 'i' constraint for > argument %0) > > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/include/asm/jump_label.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h > index cea441b6aa5d..f741bbacf175 100644 > --- a/arch/arm64/include/asm/jump_label.h > +++ b/arch/arm64/include/asm/jump_label.h > @@ -23,9 +23,9 @@ static __always_inline bool arch_static_branch(struct static_key *key, > " .pushsection __jump_table, \"aw\" \n\t" > " .align 3 \n\t" > " .long 1b - ., %l[l_yes] - . \n\t" > - " .quad %c0 - . \n\t" > + " .quad %c0 - . + %1 \n\t" > " .popsection \n\t" > - : : "i"(&((char *)key)[branch]) : : l_yes); > + : : "Si"(key), "i"(branch) : : l_yes); Nice! I like that this clearly separate the "set bit 0" portion out, and IMO that's much clearer than the array indexing. Thanks, Mark. > > return false; > l_yes: > @@ -40,9 +40,9 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, > " .pushsection __jump_table, \"aw\" \n\t" > " .align 3 \n\t" > " .long 1b - ., %l[l_yes] - . \n\t" > - " .quad %c0 - . \n\t" > + " .quad %c0 - . + %1 \n\t" > " .popsection \n\t" > - : : "i"(&((char *)key)[branch]) : : l_yes); > + : : "Si"(key), "i"(branch) : : l_yes); > > return false; > l_yes: > -- > 2.30.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel