From patchwork Thu Feb 1 22:35:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 13541871 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 CEE81C48286 for ; Thu, 1 Feb 2024 22:37: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=IGU3U0vQEaM100qTQ9O+9y6edOCiehKSUsLIEwqisFg=; b=AmD kiOhc43qmrju0w0Ht+NV7RuWma556i7lr/Sx/m5MuoztAV2MgB24tsJLolLvZ9Bz6d+xv4d8SkFIk mS3pl3ETFnY9GcWt+K4ymMaS+zGIGtFbDlxudu/KqcAdTcKKrb674XpURMkcTxadsHlEwBtGfD4HV 7xL7rOlif02uRCcAtQNK2J8uFaGN5agyx/z3v952eo6eIuhUzyfYOWrcFR1FH6a4V63/KD6GihVne woF+6ghsecN3YUaVzPvFJfOmyiG5pXs/b5oSuScgc8nYhETW8qqdmabqkXACMv1PEmYixXH4oJPPV UFZZNkahth4LvwdCURaBwU5MT5J5AAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVfg9-00000009Y9v-30zv; Thu, 01 Feb 2024 22:37:05 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVfg7-00000009Y98-296L for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 22:37:04 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc6b2681571so2269188276.2 for ; Thu, 01 Feb 2024 14:37:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706827021; x=1707431821; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=3B3tF1HYvRY1UkQ2K7cnSqpuGaSyeDgjRqaJd9RSiXg=; b=KDRb59ptVhy2MDz2oarxh8PYP9MlKuN00OE09PfnFMemVHcJZv8YStteiot+ezhb5c GFb7hfR/iMRgL5InSQghXrvN21HnE+SUKsQ1pN3Nos4VvNRxws3J/yhnFuim5ZPNmje2 ATHyjNUZr9AXTyuv7L/kMrG7w6121TUeUFbqfwgBtoGg5ExmH9tXvAVJjwFi3CG71u4L qx55PQF08RJvaRUBCnLsCGG/P2OLNtRZsu9i0f/BaqOQQTr7T7l+znxqecPBB9EI7MPb fydMFo8a/F4Dc+PkzZKrmX2P9V5IfSzKYjmHj5nuQHVAJ1+hvm1RCTgVHD20rMRWLZ+7 psMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706827021; x=1707431821; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3B3tF1HYvRY1UkQ2K7cnSqpuGaSyeDgjRqaJd9RSiXg=; b=uHtubyUtGsqUR+9WWnb7CBzkHyK185LwxZYJ0DP5Ec8jsjNUpFAL1667MZYImE5jju ML0Rr8Dc16NyKcjlvQsSdG6tjGMEO/Mmj1vru5crDo/4IXnryaWSB0TdX8mhoNkrqZqu b0DyojnWtxHIVRJBiAq7Q+sw7DGmUNNByPo91wdA9VXYQX8Wstb8IRash0j7ly78VAXA t9Lu/yH0NWWvaddl1CrZTHT/saOFYOEmvQ9jLcbRWjLwsEZHpp658URO8gCWH0Wtqxw0 mcC8cYsbpDQL9M+crAVYwFv/XYM3Ah3J0C6eKqzKpDV06LuHp+qeEvC/zC8EnykJGWDJ kbjA== X-Gm-Message-State: AOJu0YxmcubSKNt3SQz3grVxK6UyxeQy/EOHjJ5mzZSwKd6/thfBCKrO A9rdPJB+PLoOymPUskH0BN906kNSY95M15vur4f/MrLmXAXiFYf9TY5gf1MyKMhJwFbVtebWU6m +1ycWOQ== X-Google-Smtp-Source: AGHT+IEtIsVPxgDfG98U8Bbl2kwE3MvRjxByJZVySc1k/DECQFUpeiwq33gwZ/XYHnQ4uktoKoW718gMTm1N X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:7de7:721a:241f:7455]) (user=maskray job=sendgmr) by 2002:a05:6902:cc9:b0:dc2:57c9:b44d with SMTP id cq9-20020a0569020cc900b00dc257c9b44dmr149539ybb.8.1706827021012; Thu, 01 Feb 2024 14:37:01 -0800 (PST) Date: Thu, 1 Feb 2024 14:35:45 -0800 Mime-Version: 1.0 Message-ID: <20240201223545.728028-1-maskray@google.com> Subject: [PATCH] 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-20240201_143703_571808_145CC30A X-CRM114-Status: GOOD ( 12.08 ) 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] --- 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); 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); return false; l_yes: