From patchwork Thu Sep 21 07:12:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 142830 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5053672vqi; Thu, 21 Sep 2023 11:29:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxbRGpIYRX2oKY9Eat4jNWZ6B78xUX/DWcgAVfp5SL8ce2m2jgB2TJ5zUVnw5FC2l8r36s X-Received: by 2002:a05:6a21:3e05:b0:14e:b4d5:782e with SMTP id bk5-20020a056a213e0500b0014eb4d5782emr5654207pzc.29.1695320945368; Thu, 21 Sep 2023 11:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695320945; cv=none; d=google.com; s=arc-20160816; b=uG3zOLqA7qqMz6cQxN3E3z8nBr7RdVn8MvsiQuC1y8HTKkVSQSduPsaz9+/Yp9PM0D 3d/w3YPTLlxwIiYcGiG09FJ6QG0Js/wPMHpo32RYT16wsmZpp62iSAfkKjfAtOUmuppN gR4I7KddI8T290wQiBoewsr7asya+3XKGbtnCh+ou4ujnFc9yfQdrLyxGPJUPODs/LnX bCTPMaFbJ7hRTrU/BtM1GnqsRxFpAcaPXgLMi+ioypTq6PhKzTmyygda7dKdVSfWE/TW 0JkF1CujuXQTzITTPjTIaBxPvDFmExbzjCjJ8vhGBjmfLuGfzV8friC/tqdsQG3U0i6B /Czg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=JzE8EMxWLj/oDOEXmW+8iWBMMAkvkoHHPvooBPxC+Vk=; fh=HCPqzS5WAyaXVWG9KZLJubHxk8Z90V0BB6NY7718EfA=; b=dQ+JFOoNwW88gIh7rVfzvryloojf6GhlybXF4TBZXP/WGyhLOmoiksLDZVqT+qj73E iw1YlvwoSK9bRZAnDA3YJrqAw1hbby2bsIXr0k29u4IvmRWbJ0zGgFZGBJSx+Ks8mfZY QholDHnyX4u4u5gvnCauT/KOG9OxEAZowPWiOJxm+clX/GwK1oBHh14mXhdw6njt8JfU MVZM2ZTpe0UEtCpLJFdiYYrUnubtB47o9IC0DywgwW9ypM91JTTl0Ok438jI74em+rQS EA+uT8zF3GdJFp8EWPPMPlPQeuF9bWiotwLXJduMckdWYTV/w0MRcskYTMJIogiIqg5T a+0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=E2Ayg6iE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=70yvtXdq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b5-20020a056a000cc500b0068fccf2541asi2133936pfv.203.2023.09.21.11.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 11:29:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=E2Ayg6iE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=70yvtXdq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D53D882BB550; Thu, 21 Sep 2023 11:14:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229544AbjIUSOW (ORCPT + 29 others); Thu, 21 Sep 2023 14:14:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbjIUSNk (ORCPT ); Thu, 21 Sep 2023 14:13:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B6465A569; Thu, 21 Sep 2023 10:50:11 -0700 (PDT) Date: Thu, 21 Sep 2023 07:12:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695280348; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JzE8EMxWLj/oDOEXmW+8iWBMMAkvkoHHPvooBPxC+Vk=; b=E2Ayg6iET1/sB0RpDrxK6ea+4R50Zv+Z4CD9U7MurtwTq6Dbfwm9vZma7dj7MQMosrTb60 Wt4E7kJv5Ecy0FihCRf7016cY2uIzuzovDFZIXjbXQ/OacM2XJ1x6uIakrpdAlbXzrXFa3 3YiOkzCQYXg+OdOJ8G0/2Qj/tI1ajK5JUb8QhlXbqId5eMdlqyyb4s/VWXdZkrJPOD6WGx 29WI6Hd2yuugbfU4HSUy93Igg1yprFq56VYAJq2rtc9tLnNSG87ZSdgZNnUJ8Z4eflAf5W V/3XZzzwzKjRmzvdu5U1WixbMayszu5e1UC4Ya4vOynyNZtZe/fRTryx8E7Kgg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695280348; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JzE8EMxWLj/oDOEXmW+8iWBMMAkvkoHHPvooBPxC+Vk=; b=70yvtXdq5fLl0GuUZWDc7QFf7ZLV2MC1FLRNzsHyuKkoHdMMYCnXQ/LX9VV8Ib1ZlhM3w/ +vfKjGQ/rXARHDBA== From: "tip-bot2 for Fangrui Song" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] x86/speculation, objtool: Use absolute relocations for annotations Cc: Fangrui Song , Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230920001728.1439947-1-maskray@google.com> References: <20230920001728.1439947-1-maskray@google.com> MIME-Version: 1.0 Message-ID: <169528034747.27769.14777306686927534953.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 11:14:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777513634464936459 X-GMAIL-MSGID: 1777672855851480867 The following commit has been merged into the objtool/core branch of tip: Commit-ID: 0ca0043d89930cb162070598e7e4a9ed3fe57795 Gitweb: https://git.kernel.org/tip/0ca0043d89930cb162070598e7e4a9ed3fe57795 Author: Fangrui Song AuthorDate: Tue, 19 Sep 2023 17:17:28 -07:00 Committer: Ingo Molnar CommitterDate: Thu, 21 Sep 2023 08:42:38 +02:00 x86/speculation, objtool: Use absolute relocations for annotations .discard.retpoline_safe sections do not have the SHF_ALLOC flag. These sections referencing text sections' STT_SECTION symbols with PC-relative relocations like R_386_PC32 [0] is conceptually not suitable. Newer LLD will report warnings for REL relocations even for relocatable links [1]: ld.lld: warning: vmlinux.a(drivers/i2c/busses/i2c-i801.o):(.discard.retpoline_safe+0x120): has non-ABS relocation R_386_PC32 against symbol '' Switch to absolute relocations instead, which indicate link-time addresses. In a relocatable link, these addresses are also output section offsets, used by checks in tools/objtool/check.c. When linking vmlinux, these .discard.* sections will be discarded, therefore it is not a problem that R_X86_64_32 cannot represent a kernel address. Alternatively, we could set the SHF_ALLOC flag for .discard.* sections, but I think non-SHF_ALLOC for sections to be discarded makes more sense. Note: if we decide to never support REL architectures (e.g. arm, i386), we can utilize R_*_NONE relocations (.reloc ., BFD_RELOC_NONE, sym), making .discard.* sections zero-sized. That said, the section content waste is 4 bytes per entry, much smaller than sizeof(Elf{32,64}_Rel). [0] commit 1c0c1faf5692 ("objtool: Use relative pointers for annotations") [1] https://github.com/ClangBuiltLinux/linux/issues/1937 Signed-off-by: Fangrui Song Signed-off-by: Ingo Molnar Cc: Josh Poimboeuf Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20230920001728.1439947-1-maskray@google.com --- arch/x86/include/asm/alternative.h | 4 ++-- arch/x86/include/asm/nospec-branch.h | 4 ++-- include/linux/objtool.h | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index 9c4da69..65f7909 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -58,7 +58,7 @@ #define ANNOTATE_IGNORE_ALTERNATIVE \ "999:\n\t" \ ".pushsection .discard.ignore_alts\n\t" \ - ".long 999b - .\n\t" \ + ".long 999b\n\t" \ ".popsection\n\t" /* @@ -352,7 +352,7 @@ static inline int alternatives_text_reserved(void *start, void *end) .macro ANNOTATE_IGNORE_ALTERNATIVE .Lannotate_\@: .pushsection .discard.ignore_alts - .long .Lannotate_\@ - . + .long .Lannotate_\@ .popsection .endm diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index c55cc24..4952b73 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -196,7 +196,7 @@ .macro ANNOTATE_RETPOLINE_SAFE .Lhere_\@: .pushsection .discard.retpoline_safe - .long .Lhere_\@ - . + .long .Lhere_\@ .popsection .endm @@ -334,7 +334,7 @@ #define ANNOTATE_RETPOLINE_SAFE \ "999:\n\t" \ ".pushsection .discard.retpoline_safe\n\t" \ - ".long 999b - .\n\t" \ + ".long 999b\n\t" \ ".popsection\n\t" typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; diff --git a/include/linux/objtool.h b/include/linux/objtool.h index 03f82c2..6f6da95 100644 --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -48,13 +48,13 @@ #define ANNOTATE_NOENDBR \ "986: \n\t" \ ".pushsection .discard.noendbr\n\t" \ - ".long 986b - .\n\t" \ + ".long 986b\n\t" \ ".popsection\n\t" #define ASM_REACHABLE \ "998:\n\t" \ ".pushsection .discard.reachable\n\t" \ - ".long 998b - .\n\t" \ + ".long 998b\n\t" \ ".popsection\n\t" #else /* __ASSEMBLY__ */ @@ -66,7 +66,7 @@ #define ANNOTATE_INTRA_FUNCTION_CALL \ 999: \ .pushsection .discard.intra_function_calls; \ - .long 999b - .; \ + .long 999b; \ .popsection; /* @@ -118,7 +118,7 @@ .macro ANNOTATE_NOENDBR .Lhere_\@: .pushsection .discard.noendbr - .long .Lhere_\@ - . + .long .Lhere_\@ .popsection .endm @@ -141,7 +141,7 @@ .macro REACHABLE .Lhere_\@: .pushsection .discard.reachable - .long .Lhere_\@ - . + .long .Lhere_\@ .popsection .endm