Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp918680rdb; Fri, 2 Feb 2024 07:56:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuQDnHeJjEJdpN6tkZgNa3ZSX3HxWfza6AzNX/T4UNFhYMvUpiIdMW7ao0QevwG0qNblAf X-Received: by 2002:ae9:e003:0:b0:785:3e8f:d379 with SMTP id m3-20020ae9e003000000b007853e8fd379mr2550354qkk.60.1706889418882; Fri, 02 Feb 2024 07:56:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706889418; cv=pass; d=google.com; s=arc-20160816; b=kA6+8j0XKvEl2YtUieg7qkLBhFoLM0/1RY0I3QBzohzC50Ni7bw4TmJCviIrmGaaI+ tQDdeZ7qNgnpayAxS4DDA6yMYY+a89yaRLK7JwZK6Tfkrl16DsH7ehmWzOYkN1/moWyz cNQEqH06bnwxCHe9akzs+3VeFkPUAXvlg25tDBG+scRRUgDowIoRL5vJ7Ql0QJIZ2V40 xc/hl4ph1FBHLoWkao4Niu6hbvQE09r46Diev8D5cIrC948PS6c2BOOPXY0wnUVUJAZ2 ei/++aq30aJMBjnjqJHg9+mPsKtrjWqjjPCDgyqdD+SHR4val3E+HOcVACwC/Nzg+GZA hOXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=qNWbF0usspWcCYmKR0Jyac2QfMTXSu4Maudoxyn3cbs=; fh=am72dpt4/r5PBcUBkQiDMLz8kpDujxPCSrba5/n0C8s=; b=SQ6jxDJ7jijTm6qUoM4CzTvVNbaokxF6n7pCIBoEK94qBwL9mr6ziy5DIogdsPRfpz ZkKJGzugSlcXYYq8uclDSr5Bk7PH2INCs/AI5ds3wp68F0G3QREMvMq277SQwvJxkwXG f+jEJTezDoQ52rlmea7oC5d8mGrPgNVfaXIL1JSZEHScPQUOWXbXppSbx1+XaguFOb42 A8BbQ8KfC1mi+Q90DKHBgni1Z60lC9lC0fzMKM1No8A80uaqrTx6kOtLii/O2CKcmWB1 feKlEA4G3hbCvFQz+TeJtsd7U+e84U1rYsCGiCyF6N1zTwcuA7EYhTfqYWLC9hAzg7mZ Vl7A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-50055-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50055-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCUN8iyLaeeA+vdAms2AGAMAVCgYhxLiT1QbxlycPOCL5RlMtB1xba9SpACj7AwnodXE30qlJbiApiA1DYB7l5N3h3KDtxOObna1BGzg3Q== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i24-20020a05620a145800b00781706eb820si2191699qkl.196.2024.02.02.07.56.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 07:56:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50055-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-50055-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50055-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8168A1C2360F for ; Fri, 2 Feb 2024 15:56:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3291146916; Fri, 2 Feb 2024 15:56:50 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A2AF1474A7 for ; Fri, 2 Feb 2024 15:56:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889410; cv=none; b=GJGSdQ+SBPoPhgfhJc/tzFQ1u116FZQZHniLsKEYFGaBJoPxn5K1EgY5JPxrB6iBWWB2/OlP0swsGE92JZ1132OYUz2P9DO+1tlSTnsEXM/VtBWtx9eOtjqpDft+lfmX76xBJP3GfaMF44b4LSsSXirUteTdcBz6pAwqaBESGXI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889410; c=relaxed/simple; bh=dahtuyjDRHri9WwVOjAn6Bjcc8J+qhEPsGjjMokJuwU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WZhrlnTBdO8GQua80zVGq/BUdISVJ8oAlyWU2nuQq0kmHBym4Mnr3ZUucfNjBCee69RIfS645y90bdezNczzQLKime+V+wzS7T19nFMrOgsd2KZlFOFsQHPwGH4ZvcnBsbztXPNo+hpD+nZi3/pM1Wm7RELV9aKllgp8JUbxbTc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 BEEB9DA7; Fri, 2 Feb 2024 07:57:29 -0800 (PST) Received: from e133380.arm.com (e133380.arm.com [10.1.197.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A81C3F5A1; Fri, 2 Feb 2024 07:56:46 -0800 (PST) Date: Fri, 2 Feb 2024 15:56:43 +0000 From: Dave Martin To: Fangrui Song Cc: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, Jisheng Zhang , Ard Biesheuvel , Peter Smith , llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: jump_label: use constraints "Si" instead of "i" Message-ID: References: <20240201223545.728028-1-maskray@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240201223545.728028-1-maskray@google.com> On Thu, Feb 01, 2024 at 02:35:45PM -0800, Fangrui Song wrote: > The generic constraint "i" seems to be copied from x86 or arm (and with > a redundant generic operand modifier "c"). It works with -fno-PIE but > not with -fPIE/-fPIC in GCC's aarch64 port. > > The machine constraint "S", which denotes a symbol or label reference > with a constant offset, supports PIC and has been available in GCC since > 2012 and in Clang since 7.0. However, Clang before 19 does not support > "S" on a symbol with a constant offset [1] (e.g. > `static_key_false(&nf_hooks_needed[pf][hook])` in > include/linux/netfilter.h), so we use "i" as a fallback. > > Suggested-by: Ard Biesheuvel > Signed-off-by: Fangrui Song > Link: https://github.com/llvm/llvm-project/pull/80255 [1] > > --- > Changes from > arm64: jump_label: use constraint "S" instead of "i" (https://lore.kernel.org/all/20240131065322.1126831-1-maskray@google.com/) > > * Use "Si" as Ard suggested to support Clang<19 > * Make branch a separate operand > --- > arch/arm64/include/asm/jump_label.h | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h > index 48ddc0f45d22..1f7d529be608 100644 > --- a/arch/arm64/include/asm/jump_label.h > +++ b/arch/arm64/include/asm/jump_label.h > @@ -15,6 +15,10 @@ > > #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE > > +/* > + * Prefer the constraint "S" to support PIC with GCC. Clang before 19 does not > + * support "S" on a symbol with a constant offset, so we use "i" as a fallback. > + */ > static __always_inline bool arch_static_branch(struct static_key * const key, > const bool branch) > { > @@ -23,9 +27,9 @@ static __always_inline bool arch_static_branch(struct static_key * const key, > " .pushsection __jump_table, \"aw\" \n\t" > " .align 3 \n\t" > " .long 1b - ., %l[l_yes] - . \n\t" > - " .quad %c0 - . \n\t" > + " .quad %0 + %1 - . \n\t" > " .popsection \n\t" > - : : "i"(&((char *)key)[branch]) : : l_yes); > + : : "Si"(key), "i"(branch) : : l_yes); Is the meaning of multi-alternatives well defined if different arguments specify different numbers of alternatives? The GCC documentation says: https://gcc.gnu.org/onlinedocs/gcc/Multi-Alternative.html: -8<- [...] All operands for a single instruction must have the same number of alternatives. ->8- Also, I still think it may be redundant to move the addition inside the asm, so long as Clang is happy with the symbol having an offset. I.e., leave the .quad the same and revert to the one-liner - : : "i"(&((char *)key)[branch]) : : l_yes); + : : "Si"(&((char *)key)[branch]) : : l_yes); This remains a bit nasty, but splitting the arguments and adding them inside the asm is not really any cleaner. Changing the way this works doesn't seem relevant to what this patch is fixing (and apologies if I created confusion here...) > > return false; > l_yes: > @@ -40,9 +44,9 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke > " .pushsection __jump_table, \"aw\" \n\t" > " .align 3 \n\t" > " .long 1b - ., %l[l_yes] - . \n\t" > - " .quad %c0 - . \n\t" > + " .quad %0 + %1 - . \n\t" > " .popsection \n\t" > - : : "i"(&((char *)key)[branch]) : : l_yes); > + : : "Si"(key), "i"(branch) : : l_yes); Ditto. [...] Cheers ---Dave