From patchwork Tue Feb 6 07:45:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 13546807 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 6D620C4828D for ; Tue, 6 Feb 2024 07:46:16 +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:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=AZ7sLkQB3ytH/KLKlbMM0uIQgmC6+8AxjPbMWWns2+c=; b=1Jy oMwmk+rXny8h5Gu9/LgkFFxncWH90ZBiY9Mo4PVElvZez2E7bwp5akGq8cA5mguSz7/r26jvy5oVI Mv64hIkKISk6MXtMb3NEV68dLGbGoauhdZdusb5I45D/QGeoP+1Mo91IjYEwlRndr32npc5p9x3um ekVsFNKoevXhV1Xvls8SbGJXJQfw2pelAvin1Za4Hp7e0a6CkS/CHXq+qVpeyFm/CKYxili4IQFVM PhngCKTjnkvQm9xZ9u71HatZPL3Qub0GpoqOSr5W1EHFd92gZ0upxSGLrZwDONEmSO76j5MKYxwg2 W4475idij3CaY+qDkbMyOS6ooKnU++w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXG9e-00000006KZ8-1bdG; Tue, 06 Feb 2024 07:46:06 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXG9b-00000006KYg-1BGs for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 07:46:05 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6043c795ee9so32757037b3.0 for ; Mon, 05 Feb 2024 23:46:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707205561; x=1707810361; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=vh0bN2m+L086LhlsbFk+xSPJ48bcUxn6kZUD+9C817M=; b=xEZNr/PlISYeugx9ik37ECLuKcS7G0BF3UjD4DKG1gJfvp2D619TylU5b7ykcs9gj1 WDPFJBoZXcGU81VqesOArKM79GE9gVfwZ766YnbvwGN5U9jpbDzCqf5AeDuaxlEusPOJ FWhidgDIZbUzI/ebrA/5tlcidgVE/DAmR5w1kU7dzDmdBG2B5kLc8foRWSw8a+qvXGgl hLe9e3sg+OWgJAiPCltnIvkyTomeC+i20+2VNJ46QI7fYMI4Lo2Whc2OgW2ZP0wnQg5q 027SciFCUnic8PCAfidat0XMABGLEM1sSDcMqpOT51M3jvEG3uCn5HKMumuabtQAnhJF jK/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707205561; x=1707810361; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vh0bN2m+L086LhlsbFk+xSPJ48bcUxn6kZUD+9C817M=; b=ekvkvESqdSRCmSjRWnNf5MiKH9C4M9bl8ANUBwfv2gXt4e9KxrjmE0ZHjdHgSyjGel HJWXXfVeo84AG+RQm66XhtrEw4fen+WTctCgIPYkCpXb3RIYI1gOqsnWJ69dby7RnRH9 VfH7S+wHnFUyrk41K78Mfo4Q+IiNNVIiusayyj8bFT7MlrovBTNZcQXcI3TDo8JHWZDw 7H38NXEOCRkY5Zblt8Zo3BWqVYcl2vAIOOO/P58mn7Ydr5I9UKRXAL2WiqJv6lBZxPEl g1Os3yW49Cse+tFtSNDxE65j3uFwwNFmEOehQhIXGYUbW/5Fg4Hslr6j97z7lpzvgeM/ PVGQ== X-Gm-Message-State: AOJu0Yz/hZFRBjG9yXGBEXhHraDp+up0p9D1s9syXcE5Qi5rsE5dNfVj LYilQ6LY0I4VxOU3oive+krP4lTiyAslSHo/u2hWpL6qLF3GJbb8r9B6Zo4rs7hnr+A7Sb4bdB+ rJ/6Txg== X-Google-Smtp-Source: AGHT+IFl4LFYjZ3M6ziPbjx7tz10SMlEpgwo6VsR3nz03CG0qKWnus4NRZtwBV755Vj6TmWAAh6cUW72TLuM X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:1950:93e0:1305:9a80]) (user=maskray job=sendgmr) by 2002:a81:574c:0:b0:5ff:5389:526c with SMTP id l73-20020a81574c000000b005ff5389526cmr107762ywb.2.1707205561384; Mon, 05 Feb 2024 23:46:01 -0800 (PST) Date: Mon, 5 Feb 2024 23:45:52 -0800 Mime-Version: 1.0 Message-ID: <20240206074552.541154-1-maskray@google.com> Subject: [PATCH v2] arm64: jump_label: use constraints "Si" instead of "i" From: Fangrui Song To: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org Cc: Jisheng Zhang , Dave Martin , Ard Biesheuvel , Peter Smith , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Fangrui Song X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_234603_364372_303F989C X-CRM114-Status: GOOD ( 11.94 ) 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 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] Acked-by: Mark Rutland --- 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 Changes from v1: * Use asmSymbolicName for readability --- 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..b7716b215f91 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 (%[key] - .) + %[bit0] \n\t" " .popsection \n\t" - : : "i"(&((char *)key)[branch]) : : l_yes); + : : [key]"Si"(key), [bit0]"i"(branch) : : l_yes); 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 (%[key] - .) + %[bit0] \n\t" " .popsection \n\t" - : : "i"(&((char *)key)[branch]) : : l_yes); + : : [key]"Si"(key), [bit0]"i"(branch) : : l_yes); return false; l_yes: