From nobody Sat Feb 7 08:45:17 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 067AD158531; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; cv=none; b=aPGm7hux5H3yqpjmtvUJ4ibzy7SiPtnbNjMJ2MCd62ZW2v68LzEsD0TIZRAbBd6gcGGAFAeyC/gHH45DWRSsgWu0pZLzd9QfTeI+m2OWgNfjAqsAh2o3znAcRPSlVTjvVjZaFiIac7n+5TsswNqA//s5TsOmivTCPihldwOqp6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; c=relaxed/simple; bh=Oe+3vjd2qdkewgyh/k7t04PvR1t241PDwCsmc7iAVRI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=aGpFzCa1z3Lw920npFk1B/h4JYLzD74CKS3Ikytx3HuVdtJ8HlbffnwxWAz6/mDjWPDP8PtuUFqUpEIUsNI/vEU0Vy0C13ws4x3VrU02KZlbYZzzkMFfylpniNZMO4Fs6h6AoOgC4fyEOHh+B3dhQpJ6OQ9W8jqcXbu9BGh5AM0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=JIEyW5r2; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="JIEyW5r2" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=wX5tmmCqoplajf6+NuYtusl+C0AEA6dnIu4zaT2BJ+Y=; b=JIEyW5r20fRmd80e0YLk5B7J6c V3RmIF3V+0UlLCl+5qv5qRs0ebNZmbPZOIFVWDaiTcjehoVF32TzzRBZ14KOutwvGYHeOOxPelKUX JJqJYyRt1fUbll7GBcH6wFXs1A85w78U2aROWiga72KnSnq5ggW38SBTlFhBcLAZz+3mfpMsWQXIS Fspi5NpqVwwShfjq7DHoh7hu5T7NUz6ZRp/IJk3T4OSHMWAIUJpZ1E6C2I3UqVaoLqs+tiCG71GHk WcAoa3zPtsP2KS3rDTqRTwk4+MSLTYXHUzNAiXZ8AIO4S/aCwtB/IMNUimBFIisr6mCJcpTDofuDH tPMDhhkg==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000001a7x-1oJG; Thu, 28 Nov 2024 09:44:03 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 0371B30026A; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094310.932794537@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:38:52 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/16] objtool: Generic annotation infrastructure References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid endless .discard.foo sections for each annotation, create a single .discard.annotate_insn section that takes an annotation type along with the instruction. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- include/linux/objtool.h | 18 ++++++++++++++++++ tools/objtool/check.c | 45 +++++++++++++++++++++++++++++++++++++++++++= ++ 2 files changed, 63 insertions(+) --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -57,6 +57,13 @@ ".long 998b\n\t" \ ".popsection\n\t" =20 +#define ASM_ANNOTATE(type) \ + "911:\n\t" \ + ".pushsection .discard.annotate_insn,\"M\",@progbits,8\n\t" \ + ".long 911b - .\n\t" \ + ".long " __stringify(type) "\n\t" \ + ".popsection\n\t" + #else /* __ASSEMBLY__ */ =20 /* @@ -146,6 +153,14 @@ .popsection .endm =20 +.macro ANNOTATE type:req +.Lhere_\@: + .pushsection .discard.annotate_insn,"M",@progbits,8 + .long .Lhere_\@ - . + .long \type + .popsection +.endm + #endif /* __ASSEMBLY__ */ =20 #else /* !CONFIG_OBJTOOL */ @@ -155,6 +170,7 @@ #define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t" #define STACK_FRAME_NON_STANDARD(func) #define STACK_FRAME_NON_STANDARD_FP(func) +#define ASM_ANNOTATE(type) #define ANNOTATE_NOENDBR #define ASM_REACHABLE #else @@ -167,6 +183,8 @@ .endm .macro REACHABLE .endm +.macro ANNOTATE type:req +.endm #endif =20 #endif /* CONFIG_OBJTOOL */ --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2373,6 +2373,49 @@ static int read_unwind_hints(struct objt return 0; } =20 +static int read_annotate(struct objtool_file *file, void (*func)(int type,= struct instruction *insn)) +{ + struct section *sec; + struct instruction *insn; + struct reloc *reloc; + int type; + + sec =3D find_section_by_name(file->elf, ".discard.annotate_insn"); + if (!sec) + return 0; + + if (!sec->rsec) + return 0; + + if (sec->sh.sh_entsize !=3D 8) { + static bool warned =3D false; + if (!warned) { + WARN("%s: dodgy linker, sh_entsize !=3D 8", sec->name); + warned =3D true; + } + sec->sh.sh_entsize =3D 8; + } + + for_each_reloc(sec->rsec, reloc) { + type =3D *(u32 *)(sec->data->d_buf + (reloc_idx(reloc) * sec->sh.sh_ents= ize) + 4); + + insn =3D find_insn(file, reloc->sym->sec, + reloc->sym->offset + reloc_addend(reloc)); + if (!insn) { + WARN("bad .discard.annotate_insn entry: %d of type %d", reloc_idx(reloc= ), type); + return -1; + } + + func(type, insn); + } + + return 0; +} + +static void __annotate_nop(int type, struct instruction *insn) +{ +} + static int read_noendbr_hints(struct objtool_file *file) { struct instruction *insn; @@ -2670,6 +2713,8 @@ static int decode_sections(struct objtoo if (ret) return ret; =20 + read_annotate(file, __annotate_nop); + /* * Must be before read_unwind_hints() since that needs insn->noendbr. */ From nobody Sat Feb 7 08:45:17 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D51D6157A67; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; cv=none; b=OclWh3WmgnfOfOPFOBUGLg9aeVeRXL2raETCuf4c9sqxS79d59KU38lTb+Jb7ynrm8gspPnilRVmqdrKnhp8+KFtedPXSdpR+fNB4OKzSFUyX4qJ3CTfXXHyO6yxb+zY8/M3sYUxcFs4W2WHdUVcP+DKrJOj/ydbwxQIaV36oNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; c=relaxed/simple; bh=wFlCoEAqlIoCoTTUT6pSSssyVzAtTdlc/NrdEkBZd6E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=SXZJ0CYGLZlNuzVOtWMssVrWzapuP4UPoElleA01HfW/NL77vzrtfa4z9Y3CubIeT65fgO8Lp2HrvdCt9t1ybc/sACXeAGra5O1kcETt+MHe8jfVUlr1MFeyobcMwm1csdJ83FcQqwyBNUgPuTg9wEJnbAfrf5kd9Nm0scQMRU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=CEgObCQc; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CEgObCQc" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=yzOsAdXvgxlBpGX4F0j5KjZUypXDwsaiDmjUhQcqSqU=; b=CEgObCQc7rsXQ7HghTE5Rn7fwZ CUvhzSAPec6Qs4lllEZ+R60oHYJSrFiuMLnXunXchkvmkquGe84M5NRiXhFBNFxcJM/uvXq6JJs9k Y37IQpETCR1u7AjO89DckthSlMMWSSmkDCjqSt9D5C8g3W7PC+cLFTVsPoDJT9xr8keA7t44NO6f8 TIlG3BsIS1L/YbknAjwTkUz8lp9+T7X9hUGMPpin7gqIipS367id3cMH4FcM9FWbObXIo/YA0jQEw Z33dYCnGWK2+zLODYVgRXbe7wikqojmPbQi8qzwjoSXW+C+U7eaXBVqYaMTvJGOpwbulqscd/TzUd QRXLxuWw==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000001a7y-1oJD; Thu, 28 Nov 2024 09:44:03 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 0653B30037D; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.042140333@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:38:53 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/16] objtool: Convert ANNOTATE_NOENDBR to ANNOTATE References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- include/linux/objtool.h | 17 ++++------------- include/linux/objtool_types.h | 5 +++++ tools/include/linux/objtool_types.h | 5 +++++ tools/objtool/check.c | 32 +++++--------------------------- 4 files changed, 19 insertions(+), 40 deletions(-) --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -45,12 +45,6 @@ #define STACK_FRAME_NON_STANDARD_FP(func) #endif =20 -#define ANNOTATE_NOENDBR \ - "986: \n\t" \ - ".pushsection .discard.noendbr\n\t" \ - ".long 986b\n\t" \ - ".popsection\n\t" - #define ASM_REACHABLE \ "998:\n\t" \ ".pushsection .discard.reachable\n\t" \ @@ -64,6 +58,8 @@ ".long " __stringify(type) "\n\t" \ ".popsection\n\t" =20 +#define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) + #else /* __ASSEMBLY__ */ =20 /* @@ -122,13 +118,6 @@ #endif .endm =20 -.macro ANNOTATE_NOENDBR -.Lhere_\@: - .pushsection .discard.noendbr - .long .Lhere_\@ - .popsection -.endm - /* * Use objtool to validate the entry requirement that all code paths do * VALIDATE_UNRET_END before RET. @@ -161,6 +150,8 @@ .popsection .endm =20 +#define ANNOTATE_NOENDBR ANNOTATE type=3DANNOTYPE_NOENDBR + #endif /* __ASSEMBLY__ */ =20 #else /* !CONFIG_OBJTOOL */ --- a/include/linux/objtool_types.h +++ b/include/linux/objtool_types.h @@ -54,4 +54,9 @@ struct unwind_hint { #define UNWIND_HINT_TYPE_SAVE 6 #define UNWIND_HINT_TYPE_RESTORE 7 =20 +/* + * Annotate types + */ +#define ANNOTYPE_NOENDBR 1 + #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/include/linux/objtool_types.h +++ b/tools/include/linux/objtool_types.h @@ -54,4 +54,9 @@ struct unwind_hint { #define UNWIND_HINT_TYPE_SAVE 6 #define UNWIND_HINT_TYPE_RESTORE 7 =20 +/* + * Annotate types + */ +#define ANNOTYPE_NOENDBR 1 + #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2412,32 +2412,12 @@ static int read_annotate(struct objtool_ return 0; } =20 -static void __annotate_nop(int type, struct instruction *insn) +static void __annotate_noendbr(int type, struct instruction *insn) { -} - -static int read_noendbr_hints(struct objtool_file *file) -{ - struct instruction *insn; - struct section *rsec; - struct reloc *reloc; - - rsec =3D find_section_by_name(file->elf, ".rela.discard.noendbr"); - if (!rsec) - return 0; + if (type !=3D ANNOTYPE_NOENDBR) + return; =20 - for_each_reloc(rsec, reloc) { - insn =3D find_insn(file, reloc->sym->sec, - reloc->sym->offset + reloc_addend(reloc)); - if (!insn) { - WARN("bad .discard.noendbr entry"); - return -1; - } - - insn->noendbr =3D 1; - } - - return 0; + insn->noendbr =3D 1; } =20 static int read_retpoline_hints(struct objtool_file *file) @@ -2713,12 +2693,10 @@ static int decode_sections(struct objtoo if (ret) return ret; =20 - read_annotate(file, __annotate_nop); - /* * Must be before read_unwind_hints() since that needs insn->noendbr. */ - ret =3D read_noendbr_hints(file); + ret =3D read_annotate(file, __annotate_noendbr); if (ret) return ret; From nobody Sat Feb 7 08:45:17 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D475157469; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; cv=none; b=DzXVtoC4pLXinqTKxXf72qlD2dVlzZK4FgC5BAb0KahxCSVS4Ht2XhmaJfprvQbBP3so+QM1yRn2B5P/4F7rpBYmssGx0Fc9rFp36IIPvmxo6eEy0yqo14uQySip7uYscI+7W1k68wYtcMxWcjea+zTZ6mZ5VDryfCtrFPK+66Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; c=relaxed/simple; bh=mjGYKOb/9aa0YeN+TcHRcxP5fOQBAHQaQPcv1HRzvd0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=f/Ib71oc9DoyQGa/Y384nrkN5kJLg8uOvnm2vQC3MHkIbkgs8dl+rIAdow6/LzylsvpGIorcvo/vmj0hfBjGnAvdUmRoo4SJZcETMb6SRRLXfLxAK9XIWPEiI82ffuu3xX5tFzaPyXFstko+X4KjouUahTXPdXjK+z/x2v2Oyzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=n6lLEyLW; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="n6lLEyLW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=ebPwFK9/gXudqGrOXnn2CmwIsGPf4asTmbEvTCyk04E=; b=n6lLEyLWrz6K7Bd8hEcV7WXv/z rO1oEnx6loQdZh8ZRPEP0nIOu6GQuKHmrhhCe97vDO5Osl80G9P0FWtG5FHPUZ4h4vfQTeICKQ+Ol CGXfWAh0WUdrhfCNKPzWrTT1HXynuynrUNXuf+9BZbhOeIKC8uW3RNCPuurr4/0/5dzwmwu5yUjlw gnpKiZIJGJNPLBtCax6V1T9nbDnXEQzRuuikKxT6Mk5latohwO9upKGIZF6oWkT1EQH+F62JXJTS2 2KAEuco9zLFkGAUlkB4A5WdIfaKCcZQPgd9GNQHeZElpASZ9R3vg6SR6wes38a4vOOE6B1kiTkCz/ mwmoAkIw==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb46-00000002Tpp-0bpL; Thu, 28 Nov 2024 09:44:03 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 0A62D30050D; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.145275669@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:38:54 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/16] objtool: Convert ANNOTATE_RETPOLINE_SAFE to ANNOTATE References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- arch/x86/include/asm/nospec-branch.h | 13 +------- include/linux/objtool_types.h | 1=20 tools/include/linux/objtool_types.h | 1=20 tools/objtool/check.c | 52 ++++++++++++------------------= ----- 4 files changed, 22 insertions(+), 45 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -184,12 +184,7 @@ * objtool the subsequent indirect jump/call is vouched safe for retpoline * builds. */ -.macro ANNOTATE_RETPOLINE_SAFE -.Lhere_\@: - .pushsection .discard.retpoline_safe - .long .Lhere_\@ - .popsection -.endm +#define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=3DANNOTYPE_RETPOLINE_SAFE =20 /* * (ab)use RETPOLINE_SAFE on RET to annotate away 'bare' RET instructions @@ -350,11 +345,7 @@ =20 #else /* __ASSEMBLY__ */ =20 -#define ANNOTATE_RETPOLINE_SAFE \ - "999:\n\t" \ - ".pushsection .discard.retpoline_safe\n\t" \ - ".long 999b\n\t" \ - ".popsection\n\t" +#define ANNOTATE_RETPOLINE_SAFE ASM_ANNOTATE(ANNOTYPE_RETPOLINE_SAFE) =20 typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; extern retpoline_thunk_t __x86_indirect_thunk_array[]; --- a/include/linux/objtool_types.h +++ b/include/linux/objtool_types.h @@ -58,5 +58,6 @@ struct unwind_hint { * Annotate types */ #define ANNOTYPE_NOENDBR 1 +#define ANNOTYPE_RETPOLINE_SAFE 2 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/include/linux/objtool_types.h +++ b/tools/include/linux/objtool_types.h @@ -58,5 +58,6 @@ struct unwind_hint { * Annotate types */ #define ANNOTYPE_NOENDBR 1 +#define ANNOTYPE_RETPOLINE_SAFE 2 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2373,12 +2373,12 @@ static int read_unwind_hints(struct objt return 0; } =20 -static int read_annotate(struct objtool_file *file, void (*func)(int type,= struct instruction *insn)) +static int read_annotate(struct objtool_file *file, int (*func)(int type, = struct instruction *insn)) { struct section *sec; struct instruction *insn; struct reloc *reloc; - int type; + int type, ret; =20 sec =3D find_section_by_name(file->elf, ".discard.annotate_insn"); if (!sec) @@ -2406,53 +2406,37 @@ static int read_annotate(struct objtool_ return -1; } =20 - func(type, insn); + ret =3D func(type, insn); + if (ret < 0) + return ret; } =20 return 0; } =20 -static void __annotate_noendbr(int type, struct instruction *insn) +static int __annotate_noendbr(int type, struct instruction *insn) { if (type !=3D ANNOTYPE_NOENDBR) - return; + return 0; =20 insn->noendbr =3D 1; + return 0; } =20 -static int read_retpoline_hints(struct objtool_file *file) +static int __annotate_retpoline_safe(int type, struct instruction *insn) { - struct section *rsec; - struct instruction *insn; - struct reloc *reloc; - - rsec =3D find_section_by_name(file->elf, ".rela.discard.retpoline_safe"); - if (!rsec) + if (type !=3D ANNOTYPE_RETPOLINE_SAFE) return 0; =20 - for_each_reloc(rsec, reloc) { - if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", rsec->name); - return -1; - } - - insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); - if (!insn) { - WARN("bad .discard.retpoline_safe entry"); - return -1; - } - - if (insn->type !=3D INSN_JUMP_DYNAMIC && - insn->type !=3D INSN_CALL_DYNAMIC && - insn->type !=3D INSN_RETURN && - insn->type !=3D INSN_NOP) { - WARN_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop"= ); - return -1; - } - - insn->retpoline_safe =3D true; + if (insn->type !=3D INSN_JUMP_DYNAMIC && + insn->type !=3D INSN_CALL_DYNAMIC && + insn->type !=3D INSN_RETURN && + insn->type !=3D INSN_NOP) { + WARN_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop"); + return -1; } =20 + insn->retpoline_safe =3D true; return 0; } =20 @@ -2742,7 +2726,7 @@ static int decode_sections(struct objtoo if (ret) return ret; =20 - ret =3D read_retpoline_hints(file); + ret =3D read_annotate(file, __annotate_retpoline_safe); if (ret) return ret; From nobody Sat Feb 7 08:45:17 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3AB4157493; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787050; cv=none; b=pLyK5z6bVXsap5p/Qhc3MYA/UKHuQ0xbm+zLOtzCcUraXERrQ6WFPl0+ZcLqF87xGVuFPvvIDiCg6Ud8gT5wYN7AMIA8cvvkFXXFOActPTysUO/qrW3QFJzv0qwSDiZ/xqS3Czpos9X8DSBzeY2mRo3RymOx8J9gJuVmqHFrj6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787050; c=relaxed/simple; bh=zGeX2Q5hmN43CvvwJeuQ5uQfmOvAIr3FT8xoXu1/NS4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=plS5hYTm30FDKZwwoHSpTL3iOaRn+0xytWVkIQjPvnh4+y7T1mZ+VWdiaolsFsAhBhG6asf6nPJzNFEbIa282eh3AeG3CtvkNaJneTizp9RzQdlM2OkBj1vgkUQh2Fc9W9hxi21bi+q+gRX9zxwrgkhf1lBaXsGWi9l5Wta6rtk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=OR6uPmZu; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="OR6uPmZu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=H2gMDC/NqQVhMx36aV1q2hSUUdkgY6DQgcGm+BWajhA=; b=OR6uPmZut4eB1MXlLkJR7o57Tl Z9VkY8i5vi8UsSWRkImQbzMHje8U7MXtFOBBNdDPok5pCjV9cGZbysnFp8Umyne7kFl/QwuCCwYyx 1JMLUUADn4pza/WHLmJGi8FwVL8G3lGVjuZveUOVFtfDftEhBmowEEsvaVsUAkPylBOGMtsBl1fp7 gRiww0OqW/WDmxtqc+GTIe8Vs475ep2h/OiQfejH1EAPD8rdaqe3azYAAx1+foimAujm6kB4quPLV 65cvXN3rIZOw1mAdA9CmBlmJFXx6k2UQlNBfe9r+BnRXxVzXKBG7vJMpHOBSJsRcNty+/CN3JjbM4 ShvcMNJQ==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000001a7z-1oIB; Thu, 28 Nov 2024 09:44:03 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 0DFB730072F; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.245980207@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:38:55 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/16] objtool: Convert instrumentation_{begin,end}() to ANNOTATE References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- include/linux/instrumentation.h | 11 +++----- include/linux/objtool.h | 12 ++++++-- include/linux/objtool_types.h | 2 + tools/include/linux/objtool_types.h | 2 + tools/objtool/check.c | 49 +++++++------------------------= ----- 5 files changed, 28 insertions(+), 48 deletions(-) --- a/include/linux/instrumentation.h +++ b/include/linux/instrumentation.h @@ -4,14 +4,14 @@ =20 #ifdef CONFIG_NOINSTR_VALIDATION =20 +#include #include =20 /* Begin/end of an instrumentation safe region */ #define __instrumentation_begin(c) ({ \ asm volatile(__stringify(c) ": nop\n\t" \ - ".pushsection .discard.instr_begin\n\t" \ - ".long " __stringify(c) "b - .\n\t" \ - ".popsection\n\t" : : "i" (c)); \ + __ASM_ANNOTATE(__ASM_BREF(c), ANNOTYPE_INSTR_BEGIN)\ + : : "i" (c)); \ }) #define instrumentation_begin() __instrumentation_begin(__COUNTER__) =20 @@ -48,9 +48,8 @@ */ #define __instrumentation_end(c) ({ \ asm volatile(__stringify(c) ": nop\n\t" \ - ".pushsection .discard.instr_end\n\t" \ - ".long " __stringify(c) "b - .\n\t" \ - ".popsection\n\t" : : "i" (c)); \ + __ASM_ANNOTATE(__ASM_BREF(c), ANNOTYPE_INSTR_END) \ + : : "i" (c)); \ }) #define instrumentation_end() __instrumentation_end(__COUNTER__) #else /* !CONFIG_NOINSTR_VALIDATION */ --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -51,13 +51,18 @@ ".long 998b\n\t" \ ".popsection\n\t" =20 -#define ASM_ANNOTATE(type) \ - "911:\n\t" \ +#define __ASM_BREF(label) label ## b + +#define __ASM_ANNOTATE(label, type) \ ".pushsection .discard.annotate_insn,\"M\",@progbits,8\n\t" \ - ".long 911b - .\n\t" \ + ".long " __stringify(label) " - .\n\t" \ ".long " __stringify(type) "\n\t" \ ".popsection\n\t" =20 +#define ASM_ANNOTATE(type) \ + "911:\n\t" \ + __ASM_ANNOTATE(911b, type) + #define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) =20 #else /* __ASSEMBLY__ */ @@ -161,6 +166,7 @@ #define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t" #define STACK_FRAME_NON_STANDARD(func) #define STACK_FRAME_NON_STANDARD_FP(func) +#define __ASM_ANNOTATE(label, type) #define ASM_ANNOTATE(type) #define ANNOTATE_NOENDBR #define ASM_REACHABLE --- a/include/linux/objtool_types.h +++ b/include/linux/objtool_types.h @@ -59,5 +59,7 @@ struct unwind_hint { */ #define ANNOTYPE_NOENDBR 1 #define ANNOTYPE_RETPOLINE_SAFE 2 +#define ANNOTYPE_INSTR_BEGIN 3 +#define ANNOTYPE_INSTR_END 4 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/include/linux/objtool_types.h +++ b/tools/include/linux/objtool_types.h @@ -59,5 +59,7 @@ struct unwind_hint { */ #define ANNOTYPE_NOENDBR 1 #define ANNOTYPE_RETPOLINE_SAFE 2 +#define ANNOTYPE_INSTR_BEGIN 3 +#define ANNOTYPE_INSTR_END 4 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2440,48 +2440,19 @@ static int __annotate_retpoline_safe(int return 0; } =20 -static int read_instr_hints(struct objtool_file *file) +static int __annotate_instr(int type, struct instruction *insn) { - struct section *rsec; - struct instruction *insn; - struct reloc *reloc; - - rsec =3D find_section_by_name(file->elf, ".rela.discard.instr_end"); - if (!rsec) - return 0; - - for_each_reloc(rsec, reloc) { - if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", rsec->name); - return -1; - } - - insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); - if (!insn) { - WARN("bad .discard.instr_end entry"); - return -1; - } + switch (type) { + case ANNOTYPE_INSTR_BEGIN: + insn->instr++; + break; =20 + case ANNOTYPE_INSTR_END: insn->instr--; - } - - rsec =3D find_section_by_name(file->elf, ".rela.discard.instr_begin"); - if (!rsec) - return 0; + break; =20 - for_each_reloc(rsec, reloc) { - if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", rsec->name); - return -1; - } - - insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); - if (!insn) { - WARN("bad .discard.instr_begin entry"); - return -1; - } - - insn->instr++; + default: + break; } =20 return 0; @@ -2730,7 +2701,7 @@ static int decode_sections(struct objtoo if (ret) return ret; =20 - ret =3D read_instr_hints(file); + ret =3D read_annotate(file, __annotate_instr); if (ret) return ret; From nobody Sat Feb 7 08:45:17 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE195158527; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; cv=none; b=R4BVD8JJgieVaZhafY8QMFTt3hv/tzETkOK1xaOi5OAYE6G0iIUtXOgF1GrGBPBfHZyYTnvXW1tPMiuJdtR+Bo+xakVOuqWlwT8Yxxk4Lg+9R0ydUXLB6KeMxeQwbFdINqLivHMPCCggHmDj4gxJECk4/ZJ9zFGXbIfXjp0eQ1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; c=relaxed/simple; bh=YcfV9sNulwTJAZsqIgdZ4lAcBlsY+5gHFkKNA+RgmF4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=OTj/ccxuPBacvyyRWayigS4M/fm5yU9A9SWshsSkOboUJU12H7uCW7IxUnrreQ7cjE0ivzyhyiz4jFC/uhZuVzk56zBSwjoHZzgrRpGhmfFDnf00wes3JC9CbwlYK/InHeqZRR4Niix25fqZtzq7AlEJCsWUZo1MVofcKx1BFEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=YspFPRzt; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YspFPRzt" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=gj4p7yl7+dkaCocJAkHrhZxZwRJ1S2yOeCSzaopDaGY=; b=YspFPRztAC9wBWB26mKWdL/mwe 5+6xhDtTAjCUKKJdeCMK3G9z+H7Uzx7T8T5YEISf3b+vn8O4rqEauS4zahzAKZK3nP3+22q/HFAg9 LD8JTnB3xF5m21OWRmtQ1x7p39QZ20IwIcmwxxlAyT682b3lyZvC0/vQcokoXhqQhBUALMu4MoiXg lEErU92pCt/aiITS8JKXUa2iRRp5Cppcs+c5aIHEj7XZ6bvHJOMcbeDgVXVc73ZJj7YEs/1zGc8C/ tNAoKdRX5t4k83K1lyKPPO7cWVLeBKXFbbPpDRZWWvR87GPdE0KNuq77n6QN0CZ6pDSXjlDC081M7 OUULcylQ==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb48-00000001a85-1cyd; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 133FA300781; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.358508242@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:38:56 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/16] objtool: Convert VALIDATE_UNRET_BEGIN to ANNOTATE References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- include/linux/objtool.h | 9 +++------ include/linux/objtool_types.h | 1 + tools/include/linux/objtool_types.h | 1 + tools/objtool/check.c | 28 +++++----------------------- 4 files changed, 10 insertions(+), 29 deletions(-) --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -130,15 +130,12 @@ * NOTE: The macro must be used at the beginning of a global symbol, other= wise * it will be ignored. */ -.macro VALIDATE_UNRET_BEGIN #if defined(CONFIG_NOINSTR_VALIDATION) && \ (defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO= )) -.Lhere_\@: - .pushsection .discard.validate_unret - .long .Lhere_\@ - . - .popsection +#define VALIDATE_UNRET_BEGIN ANNOTATE type=3DANNOTYPE_UNRET_BEGIN +#else +#define VALIDATE_UNRET_BEGIN #endif -.endm =20 .macro REACHABLE .Lhere_\@: --- a/include/linux/objtool_types.h +++ b/include/linux/objtool_types.h @@ -61,5 +61,6 @@ struct unwind_hint { #define ANNOTYPE_RETPOLINE_SAFE 2 #define ANNOTYPE_INSTR_BEGIN 3 #define ANNOTYPE_INSTR_END 4 +#define ANNOTYPE_UNRET_BEGIN 5 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/include/linux/objtool_types.h +++ b/tools/include/linux/objtool_types.h @@ -61,5 +61,6 @@ struct unwind_hint { #define ANNOTYPE_RETPOLINE_SAFE 2 #define ANNOTYPE_INSTR_BEGIN 3 #define ANNOTYPE_INSTR_END 4 +#define ANNOTYPE_UNRET_BEGIN 5 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2458,33 +2458,15 @@ static int __annotate_instr(int type, st return 0; } =20 -static int read_validate_unret_hints(struct objtool_file *file) +static int __annotate_unret(int type, struct instruction *insn) { - struct section *rsec; - struct instruction *insn; - struct reloc *reloc; - - rsec =3D find_section_by_name(file->elf, ".rela.discard.validate_unret"); - if (!rsec) + if (type !=3D ANNOTYPE_UNRET_BEGIN) return 0; =20 - for_each_reloc(rsec, reloc) { - if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", rsec->name); - return -1; - } - - insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); - if (!insn) { - WARN("bad .discard.instr_end entry"); - return -1; - } - insn->unret =3D 1; - } - + insn->unret =3D 1; return 0; -} =20 +} =20 static int read_intra_function_calls(struct objtool_file *file) { @@ -2705,7 +2687,7 @@ static int decode_sections(struct objtoo if (ret) return ret; =20 - ret =3D read_validate_unret_hints(file); + ret =3D read_annotate(file, __annotate_unret); if (ret) return ret; From nobody Sat Feb 7 08:45:17 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D234715748F; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787050; cv=none; b=Wiq8LnqTnEOgsMb5C/vID913gQ1+Sxh9Y7pKD4XGbghj9iZq25JHvae37Dqy8n5SDxBh5+B7R+zmReFYPTBf5IavZLO7oWipuG8lfEoIXA+pwDBACjs9b+Y3aS7XL8y0SmdhcUT0F6xpgiNp4X0NHlue4cyQIgJz42PUMOyhk90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787050; c=relaxed/simple; bh=MGVEaUDVmMa1bHIoRD1uKjMF+LQgu8uuDTggC+bpNjQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=CRY2Lc6ha2qegT0ych7wcvsd5B3uQW3HvOIdssLH3nwtciBAWEJK9PcARoVjmFDo/jxXDja3tt0JpLnC57zm2Zh2Wotf13K1N2dVN77DlBMVZWD45NeKjJA6anBWs4kdpLZJim+cvOyaD3Q+klCbf4o0dgNJ8S2XG+2MpDVZ7V0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=GECdJfa8; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GECdJfa8" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=BkVT5DuQEI5JkZLJ/FAjVrWbYzBCZRYT3psUjazDepI=; b=GECdJfa8DeVJ41DEQuaKy+H5HX bcJUlBa62Qjf/H4UI0MN+qWXKNDsRl8I3x/MBXCgjXWU/KMCgxSKVLgCSwu9pneqOn9N1Qu71AObR T91dNPt6SUgju0pv2u1qIpSsHhzvWccVE2y/3Vtry7UHI5GL2Frj/5eV4JyVJXwLjvBznN6H1p6w2 38cvlEDnKGrRkc4ttCIsKZvMQxCOdf6csZwWuKuhT3ro9xvJbPHtTiJjGNOYaFs2f8X2S6u6UeSi9 GzMyITUH7AycfGBJyEMxZD65OO6D2Ld7LZaSm95N2Rkhh8IH29pN867VeQNrabsb0tv5qEbBqMij7 Dt7ag7Uw==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb48-00000001a86-1ZyM; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 154C430081F; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.465691316@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:38:57 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/16] objtool: Convert ANNOTATE_IGNORE_ALTERNATIVE to ANNOTATE References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- arch/x86/include/asm/alternative.h | 14 ++--------- include/linux/objtool_types.h | 1=20 tools/include/linux/objtool_types.h | 1=20 tools/objtool/check.c | 45 ++++++++-----------------------= ----- 4 files changed, 15 insertions(+), 46 deletions(-) --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -4,6 +4,7 @@ =20 #include #include +#include #include =20 #define ALT_FLAGS_SHIFT 16 @@ -58,11 +59,7 @@ * objtool annotation to ignore the alternatives and only consider the ori= ginal * instruction(s). */ -#define ANNOTATE_IGNORE_ALTERNATIVE \ - "999:\n\t" \ - ".pushsection .discard.ignore_alts\n\t" \ - ".long 999b\n\t" \ - ".popsection\n\t" +#define ANNOTATE_IGNORE_ALTERNATIVE ASM_ANNOTATE(ANNOTYPE_IGNORE_ALTS) =20 /* * The patching flags are part of the upper bits of the @ft_flags paramete= r when @@ -314,12 +311,7 @@ void nop_func(void); * objtool annotation to ignore the alternatives and only consider the ori= ginal * instruction(s). */ -.macro ANNOTATE_IGNORE_ALTERNATIVE - .Lannotate_\@: - .pushsection .discard.ignore_alts - .long .Lannotate_\@ - .popsection -.endm +#define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=3DANNOTYPE_IGNORE_ALTS =20 /* * Issue one struct alt_instr descriptor entry (need to put it into --- a/include/linux/objtool_types.h +++ b/include/linux/objtool_types.h @@ -62,5 +62,6 @@ struct unwind_hint { #define ANNOTYPE_INSTR_BEGIN 3 #define ANNOTYPE_INSTR_END 4 #define ANNOTYPE_UNRET_BEGIN 5 +#define ANNOTYPE_IGNORE_ALTS 6 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/include/linux/objtool_types.h +++ b/tools/include/linux/objtool_types.h @@ -62,5 +62,6 @@ struct unwind_hint { #define ANNOTYPE_INSTR_BEGIN 3 #define ANNOTYPE_INSTR_END 4 #define ANNOTYPE_UNRET_BEGIN 5 +#define ANNOTYPE_IGNORE_ALTS 6 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1310,40 +1310,6 @@ static void add_uaccess_safe(struct objt } =20 /* - * FIXME: For now, just ignore any alternatives which add retpolines. Thi= s is - * a temporary hack, as it doesn't allow ORC to unwind from inside a retpo= line. - * But it at least allows objtool to understand the control flow *around* = the - * retpoline. - */ -static int add_ignore_alternatives(struct objtool_file *file) -{ - struct section *rsec; - struct reloc *reloc; - struct instruction *insn; - - rsec =3D find_section_by_name(file->elf, ".rela.discard.ignore_alts"); - if (!rsec) - return 0; - - for_each_reloc(rsec, reloc) { - if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", rsec->name); - return -1; - } - - insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); - if (!insn) { - WARN("bad .discard.ignore_alts entry"); - return -1; - } - - insn->ignore_alts =3D true; - } - - return 0; -} - -/* * Symbols that replace INSN_CALL_DYNAMIC, every (tail) call to such a sym= bol * will be added to the .retpoline_sites section. */ @@ -2414,6 +2380,15 @@ static int read_annotate(struct objtool_ return 0; } =20 +static int __annotate_ignore_alts(int type, struct instruction *insn) +{ + if (type !=3D ANNOTYPE_IGNORE_ALTS) + return 0; + + insn->ignore_alts =3D true; + return 0; +} + static int __annotate_noendbr(int type, struct instruction *insn) { if (type !=3D ANNOTYPE_NOENDBR) @@ -2626,7 +2601,7 @@ static int decode_sections(struct objtoo add_ignores(file); add_uaccess_safe(file); =20 - ret =3D add_ignore_alternatives(file); + ret =3D read_annotate(file, __annotate_ignore_alts); if (ret) return ret; From nobody Sat Feb 7 08:45:17 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6088C156238; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; cv=none; b=chXAzIPamQXM66ftemQiu5k77lbe1+jdJDbtueQjKM8ngVE7WLdOaec/6NHIjTya1PUxHVC/FHu249sgzj8FZeuq//79n+OOjPbXCfAmwsBP3s13xh2aL+qVZxgse/aFWDr3uiRHtD9NkWnSP/SEEa436JRDM5qPp/R0reJOB2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; c=relaxed/simple; bh=M/3PKtxHqMIvdFSOZXdtEiqGXLTIimd/Hh+R4+U7VII=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dQC4F25UreSRC4BZEBrRYSu92E/TpwW++mHVTyGLqf3aCaE3ML062Q3boI4ExmKBkWpWPp5KpJKnJCdx8CZtAO9FAIT0KOtvXkdsJP8OHZ2glnmECtjKDTbBa8KeTjcmAJ8Tlh39dsGJxW26kULYdkAnr0Vt+2DcxWgu0FPiJDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=OL/kk3bE; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="OL/kk3bE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=dZAsfjEPMsf/wnZlid+qdNdjIwAXxCpxPExkT+a73rI=; b=OL/kk3bEJvK2aB4JIwvgcYrqBZ yjPHrjm8qJX6BYqnOg52VlwgJb2MOF4CRLSNxH1ppdYj8vw1iMH6uOCw4VY7Kxrv1Xf9NffC9hdon 3FqMJyYWGS8Ak1KqoKixJSAhAGvSbtJX/cKQdaf3GrgtT/5TSPhtZbmkVYYEM0T5iQ5zoFl11h7hh lbG2yuoxAOTCIlBvMIhgymu7P9xw8E/Pgs6mKQszWjOGkC4XcIrTnZMbsSDOeCkahIl0yjT1gZPhF kBxRuuFOkE3Pfffvx1AWYNyPsqM0DppBu8riX8ORqP3CkzN0m13WfSzkl2N+7+8UfqvKVgFjy50tO U7XD/3fg==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000002Tpu-0TbD; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 1923430114C; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.584892071@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:38:58 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/16] objtool: Convert ANNOTATE_INTRA_FUNCTION_CALL to ANNOTATE References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- include/linux/objtool.h | 16 ++---- include/linux/objtool_types.h | 1=20 tools/include/linux/objtool_types.h | 1=20 tools/objtool/check.c | 96 ++++++++++++++-----------------= ----- 4 files changed, 47 insertions(+), 67 deletions(-) --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -68,16 +68,6 @@ #else /* __ASSEMBLY__ */ =20 /* - * This macro indicates that the following intra-function call is valid. - * Any non-annotated intra-function call will cause objtool to issue a war= ning. - */ -#define ANNOTATE_INTRA_FUNCTION_CALL \ - 999: \ - .pushsection .discard.intra_function_calls; \ - .long 999b; \ - .popsection; - -/* * In asm, there are two kinds of code: normal C-type callable functions a= nd * the rest. The normal callable functions can be called by other code, a= nd * don't do anything unusual with the stack. Such normal callable functio= ns @@ -154,6 +144,12 @@ =20 #define ANNOTATE_NOENDBR ANNOTATE type=3DANNOTYPE_NOENDBR =20 +/* + * This macro indicates that the following intra-function call is valid. + * Any non-annotated intra-function call will cause objtool to issue a war= ning. + */ +#define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=3DANNOTYPE_INTRA_FUNCTI= ON_CALL + #endif /* __ASSEMBLY__ */ =20 #else /* !CONFIG_OBJTOOL */ --- a/include/linux/objtool_types.h +++ b/include/linux/objtool_types.h @@ -63,5 +63,6 @@ struct unwind_hint { #define ANNOTYPE_INSTR_END 4 #define ANNOTYPE_UNRET_BEGIN 5 #define ANNOTYPE_IGNORE_ALTS 6 +#define ANNOTYPE_INTRA_FUNCTION_CALL 7 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/include/linux/objtool_types.h +++ b/tools/include/linux/objtool_types.h @@ -63,5 +63,6 @@ struct unwind_hint { #define ANNOTYPE_INSTR_END 4 #define ANNOTYPE_UNRET_BEGIN 5 #define ANNOTYPE_IGNORE_ALTS 6 +#define ANNOTYPE_INTRA_FUNCTION_CALL 7 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2339,7 +2339,8 @@ static int read_unwind_hints(struct objt return 0; } =20 -static int read_annotate(struct objtool_file *file, int (*func)(int type, = struct instruction *insn)) +static int read_annotate(struct objtool_file *file, + int (*func)(struct objtool_file *file, int type, struct instruction *i= nsn)) { struct section *sec; struct instruction *insn; @@ -2372,7 +2373,7 @@ static int read_annotate(struct objtool_ return -1; } =20 - ret =3D func(type, insn); + ret =3D func(file, type, insn); if (ret < 0) return ret; } @@ -2380,7 +2381,7 @@ static int read_annotate(struct objtool_ return 0; } =20 -static int __annotate_ignore_alts(int type, struct instruction *insn) +static int __annotate_ignore_alts(struct objtool_file *file, int type, str= uct instruction *insn) { if (type !=3D ANNOTYPE_IGNORE_ALTS) return 0; @@ -2389,7 +2390,7 @@ static int __annotate_ignore_alts(int ty return 0; } =20 -static int __annotate_noendbr(int type, struct instruction *insn) +static int __annotate_noendbr(struct objtool_file *file, int type, struct = instruction *insn) { if (type !=3D ANNOTYPE_NOENDBR) return 0; @@ -2398,7 +2399,37 @@ static int __annotate_noendbr(int type, return 0; } =20 -static int __annotate_retpoline_safe(int type, struct instruction *insn) +static int __annotate_ifc(struct objtool_file *file, int type, struct inst= ruction *insn) +{ + unsigned long dest_off; + + if (type !=3D ANNOTYPE_INTRA_FUNCTION_CALL) + return 0; + + if (insn->type !=3D INSN_CALL) { + WARN_INSN(insn, "intra_function_call not a direct call"); + return -1; + } + + /* + * Treat intra-function CALLs as JMPs, but with a stack_op. + * See add_call_destinations(), which strips stack_ops from + * normal CALLs. + */ + insn->type =3D INSN_JUMP_UNCONDITIONAL; + + dest_off =3D arch_jump_destination(insn); + insn->jump_dest =3D find_insn(file, insn->sec, dest_off); + if (!insn->jump_dest) { + WARN_INSN(insn, "can't find call dest at %s+0x%lx", + insn->sec->name, dest_off); + return -1; + } + + return 0; +} + +static int __annotate_retpoline_safe(struct objtool_file *file, int type, = struct instruction *insn) { if (type !=3D ANNOTYPE_RETPOLINE_SAFE) return 0; @@ -2415,7 +2446,7 @@ static int __annotate_retpoline_safe(int return 0; } =20 -static int __annotate_instr(int type, struct instruction *insn) +static int __annotate_instr(struct objtool_file *file, int type, struct in= struction *insn) { switch (type) { case ANNOTYPE_INSTR_BEGIN: @@ -2433,7 +2464,7 @@ static int __annotate_instr(int type, st return 0; } =20 -static int __annotate_unret(int type, struct instruction *insn) +static int __annotate_unret(struct objtool_file *file, int type, struct in= struction *insn) { if (type !=3D ANNOTYPE_UNRET_BEGIN) return 0; @@ -2443,55 +2474,6 @@ static int __annotate_unret(int type, st =20 } =20 -static int read_intra_function_calls(struct objtool_file *file) -{ - struct instruction *insn; - struct section *rsec; - struct reloc *reloc; - - rsec =3D find_section_by_name(file->elf, ".rela.discard.intra_function_ca= lls"); - if (!rsec) - return 0; - - for_each_reloc(rsec, reloc) { - unsigned long dest_off; - - if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", - rsec->name); - return -1; - } - - insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); - if (!insn) { - WARN("bad .discard.intra_function_call entry"); - return -1; - } - - if (insn->type !=3D INSN_CALL) { - WARN_INSN(insn, "intra_function_call not a direct call"); - return -1; - } - - /* - * Treat intra-function CALLs as JMPs, but with a stack_op. - * See add_call_destinations(), which strips stack_ops from - * normal CALLs. - */ - insn->type =3D INSN_JUMP_UNCONDITIONAL; - - dest_off =3D arch_jump_destination(insn); - insn->jump_dest =3D find_insn(file, insn->sec, dest_off); - if (!insn->jump_dest) { - WARN_INSN(insn, "can't find call dest at %s+0x%lx", - insn->sec->name, dest_off); - return -1; - } - } - - return 0; -} - /* * Return true if name matches an instrumentation function, where calls to= that * function from noinstr code can safely be removed, but compilers won't d= o so. @@ -2630,7 +2612,7 @@ static int decode_sections(struct objtoo * Must be before add_call_destination(); it changes INSN_CALL to * INSN_JUMP. */ - ret =3D read_intra_function_calls(file); + ret =3D read_annotate(file, __annotate_ifc); if (ret) return ret; From nobody Sat Feb 7 08:45:17 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6092A156F55; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; cv=none; b=a4W2eB5FyuHZatsRlTXX5r93q7D0f/bKeEmZFinMsdiKQZxWh7YK7yq105ViGz+PU7aC8dNlRAw96NO8kU7OPbabrm5GJplfai6ngL84CrLhbda9H2tHdij+NCUeymdbnZ91NpVCDUKocoMfjWktUeR85tg5mAtylJ0DWbtkdHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; c=relaxed/simple; bh=QqoGUswWnCATEHYv3H6l0MFwT5RLbh6t4mujW8kXHsw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=mzttXnK2JCatfGDcv73dCmwspHCe/gg3g8fv5bsurFkI+9voyBjSpp3Vm19aj843e6WSHt0yaq7TBtEi4tD1P9Jw+/qTyDg0ZOUtI4cNKLHATuVEJ1KXBIVJBwIsX+JP096kWn5kRVDMiApU8k4wi1hxGk6GB2WL/45bqcJgxqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=gTFkEPMQ; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="gTFkEPMQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=FDckB11/j3OVAfIOhlTnymsn2RpaHfCKYThx7MpzQSQ=; b=gTFkEPMQ3LOpkRjIU3kXwsHG+J /t6XIvFleqXxjnx3GbWbI8ttFinZXdN26R88TuPmgn/rzhcXEMzHJI/lge9Ag9Dme96jOIcK67z0x Ai+ZyjtbC4jG7vXI/EB2d5dqWGSWCBQZkgdeYL9QJZCcZNIN3byvEQ6pqe9fi4r39Oc6o/ei8N0di xjCvv3vSrNlUOjtzbUntPf2w1byj4UJGhQZ69+p5Qb3J6XA5ZKCS8d/82gjgWN2fAdIZbED8yaCW8 NdJPHyNXIuA65dyrzfmNeJ/KM8Bv3rbgHo6g34gdOLDUaCUnq8kobt5lPkndNCV4QpdyhyeyPfsWo 8FjrcZiA==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000002Tpt-0Rvh; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 1CCA0301171; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.688871544@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:38:59 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 08/16] objtool: Collapse annotate sequences References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reduce read_annotate() runs by collapsing subsequent runs into a single call. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- tools/objtool/check.c | 87 ++++++++++++++++++---------------------------= ----- 1 file changed, 32 insertions(+), 55 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2381,21 +2381,24 @@ static int read_annotate(struct objtool_ return 0; } =20 -static int __annotate_ignore_alts(struct objtool_file *file, int type, str= uct instruction *insn) +static int __annotate_early(struct objtool_file *file, int type, struct in= struction *insn) { - if (type !=3D ANNOTYPE_IGNORE_ALTS) - return 0; + switch (type) { + case ANNOTYPE_IGNORE_ALTS: + insn->ignore_alts =3D true; + break; =20 - insn->ignore_alts =3D true; - return 0; -} + /* + * Must be before read_unwind_hints() since that needs insn->noendbr. + */ + case ANNOTYPE_NOENDBR: + insn->noendbr =3D 1; + break; =20 -static int __annotate_noendbr(struct objtool_file *file, int type, struct = instruction *insn) -{ - if (type !=3D ANNOTYPE_NOENDBR) - return 0; + default: + break; + } =20 - insn->noendbr =3D 1; return 0; } =20 @@ -2429,26 +2432,21 @@ static int __annotate_ifc(struct objtool return 0; } =20 -static int __annotate_retpoline_safe(struct objtool_file *file, int type, = struct instruction *insn) +static int __annotate_late(struct objtool_file *file, int type, struct ins= truction *insn) { - if (type !=3D ANNOTYPE_RETPOLINE_SAFE) - return 0; - - if (insn->type !=3D INSN_JUMP_DYNAMIC && - insn->type !=3D INSN_CALL_DYNAMIC && - insn->type !=3D INSN_RETURN && - insn->type !=3D INSN_NOP) { - WARN_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop"); - return -1; - } + switch (type) { + case ANNOTYPE_RETPOLINE_SAFE: + if (insn->type !=3D INSN_JUMP_DYNAMIC && + insn->type !=3D INSN_CALL_DYNAMIC && + insn->type !=3D INSN_RETURN && + insn->type !=3D INSN_NOP) { + WARN_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop"= ); + return -1; + } =20 - insn->retpoline_safe =3D true; - return 0; -} + insn->retpoline_safe =3D true; + break; =20 -static int __annotate_instr(struct objtool_file *file, int type, struct in= struction *insn) -{ - switch (type) { case ANNOTYPE_INSTR_BEGIN: insn->instr++; break; @@ -2457,6 +2455,10 @@ static int __annotate_instr(struct objto insn->instr--; break; =20 + case ANNOTYPE_UNRET_BEGIN: + insn->unret =3D 1; + break; + default: break; } @@ -2464,16 +2466,6 @@ static int __annotate_instr(struct objto return 0; } =20 -static int __annotate_unret(struct objtool_file *file, int type, struct in= struction *insn) -{ - if (type !=3D ANNOTYPE_UNRET_BEGIN) - return 0; - - insn->unret =3D 1; - return 0; - -} - /* * Return true if name matches an instrumentation function, where calls to= that * function from noinstr code can safely be removed, but compilers won't d= o so. @@ -2583,14 +2575,7 @@ static int decode_sections(struct objtoo add_ignores(file); add_uaccess_safe(file); =20 - ret =3D read_annotate(file, __annotate_ignore_alts); - if (ret) - return ret; - - /* - * Must be before read_unwind_hints() since that needs insn->noendbr. - */ - ret =3D read_annotate(file, __annotate_noendbr); + ret =3D read_annotate(file, __annotate_early); if (ret) return ret; =20 @@ -2636,15 +2621,7 @@ static int decode_sections(struct objtoo if (ret) return ret; =20 - ret =3D read_annotate(file, __annotate_retpoline_safe); - if (ret) - return ret; - - ret =3D read_annotate(file, __annotate_instr); - if (ret) - return ret; - - ret =3D read_annotate(file, __annotate_unret); + ret =3D read_annotate(file, __annotate_late); if (ret) return ret; From nobody Sat Feb 7 08:45:17 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 608D9156887; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787050; cv=none; b=R26hvKg2F6SKtE3OL1tHM1E++hOcXkwkFk4tr0U8hg+N0H4uS1Kww7wu5LnOJ1JaGZyq6+uLc4KVjc2eD3YnKur44p7BT3SFyKyT2y/8zQXFaGExRQBe8KWbdG4cbmvuFbt8B+jYvrI0S4xHfuhQtZ0/WLEORA0BXtQjAsGSEt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787050; c=relaxed/simple; bh=ITaR2GLJjD8N0qxqVx4qsccbDiOdUCBnuYv4gpCvXDs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=jdDUlaRMhEU02W4sRRkGAXOJJW+o2KJ2/xSuLn0sezy4aRcHyYbsDfh9ZmHs0s2TW0k1wg74Y4E6uTp6cxLIIVVF6a7lPmfmd/jzvvzK1MTEplP+RaJ8uAmIrpPJJXlfl05yEdCnt2GYkdzU4tH3DLGP6P6bNC4d7wq5MBuK4xk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=BgRX0cXB; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BgRX0cXB" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=9kPdLx/gy38dNocF8o8UedzxUuCkNlflSHnB7A+iYrA=; b=BgRX0cXBHBbxPFd7Ao55X3L2La h/c3xWMzOiplOTHPrwJRHpcXenq5rarJm3kSiDQqLAu55tidAOx26sFADkt/pBI1pdA+9M+o0WXYS 9hvRsatukXHQ0O4AC4ZPtYkVo9WW3mcDe2ptuYs2nmis3a0WwhE2WZ6kl9OHatxs0bFE31Viv4y4S MXVXRMzAoWRw96+yJAKleyQDAa6q6SyxSSOg6FcisUHlApGiqKaRymIQIFTy0Fdsw4pZ+Yc01DL5F NSOOjA6Q8kULBYXxAY254jRgQwyPPhh6duwWy4ksKwFJNlHiJiEsme8vqzi1Tts0JK6ax3MWHzdK3 Gb2RMdqQ==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000002Tpv-0VFZ; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 2066A30119B; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.786598147@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:39:00 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Josh Poimboeuf Subject: [PATCH v2 09/16] objtool: Collect more annotations in objtool.h References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Suggested-by: Josh Poimboeuf Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- arch/x86/include/asm/alternative.h | 12 ----- arch/x86/include/asm/nospec-branch.h | 9 --- include/linux/instrumentation.h | 4 - include/linux/objtool.h | 80 +++++++++++++++++++++++-------= ----- 4 files changed, 55 insertions(+), 50 deletions(-) --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -56,12 +56,6 @@ #endif =20 /* - * objtool annotation to ignore the alternatives and only consider the ori= ginal - * instruction(s). - */ -#define ANNOTATE_IGNORE_ALTERNATIVE ASM_ANNOTATE(ANNOTYPE_IGNORE_ALTS) - -/* * The patching flags are part of the upper bits of the @ft_flags paramete= r when * specifying them. The split is currently like this: * @@ -308,12 +302,6 @@ void nop_func(void); #endif =20 /* - * objtool annotation to ignore the alternatives and only consider the ori= ginal - * instruction(s). - */ -#define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=3DANNOTYPE_IGNORE_ALTS - -/* * Issue one struct alt_instr descriptor entry (need to put it into * the section .altinstructions, see below). This entry contains * enough information for the alternatives patching code to patch an --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -180,13 +180,6 @@ #ifdef __ASSEMBLY__ =20 /* - * This should be used immediately before an indirect jump/call. It tells - * objtool the subsequent indirect jump/call is vouched safe for retpoline - * builds. - */ -#define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=3DANNOTYPE_RETPOLINE_SAFE - -/* * (ab)use RETPOLINE_SAFE on RET to annotate away 'bare' RET instructions * vs RETBleed validation. */ @@ -345,8 +338,6 @@ =20 #else /* __ASSEMBLY__ */ =20 -#define ANNOTATE_RETPOLINE_SAFE ASM_ANNOTATE(ANNOTYPE_RETPOLINE_SAFE) - typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; extern retpoline_thunk_t __x86_indirect_thunk_array[]; extern retpoline_thunk_t __x86_indirect_call_thunk_array[]; --- a/include/linux/instrumentation.h +++ b/include/linux/instrumentation.h @@ -10,7 +10,7 @@ /* Begin/end of an instrumentation safe region */ #define __instrumentation_begin(c) ({ \ asm volatile(__stringify(c) ": nop\n\t" \ - __ASM_ANNOTATE(__ASM_BREF(c), ANNOTYPE_INSTR_BEGIN)\ + ANNOTATE_INSTR_BEGIN(__ASM_BREF(c)) \ : : "i" (c)); \ }) #define instrumentation_begin() __instrumentation_begin(__COUNTER__) @@ -48,7 +48,7 @@ */ #define __instrumentation_end(c) ({ \ asm volatile(__stringify(c) ": nop\n\t" \ - __ASM_ANNOTATE(__ASM_BREF(c), ANNOTYPE_INSTR_END) \ + ANNOTATE_INSTR_END(__ASM_BREF(c)) \ : : "i" (c)); \ }) #define instrumentation_end() __instrumentation_end(__COUNTER__) --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -63,8 +63,6 @@ "911:\n\t" \ __ASM_ANNOTATE(911b, type) =20 -#define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) - #else /* __ASSEMBLY__ */ =20 /* @@ -113,19 +111,6 @@ #endif .endm =20 -/* - * Use objtool to validate the entry requirement that all code paths do - * VALIDATE_UNRET_END before RET. - * - * NOTE: The macro must be used at the beginning of a global symbol, other= wise - * it will be ignored. - */ -#if defined(CONFIG_NOINSTR_VALIDATION) && \ - (defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO= )) -#define VALIDATE_UNRET_BEGIN ANNOTATE type=3DANNOTYPE_UNRET_BEGIN -#else -#define VALIDATE_UNRET_BEGIN -#endif =20 .macro REACHABLE .Lhere_\@: @@ -142,14 +127,6 @@ .popsection .endm =20 -#define ANNOTATE_NOENDBR ANNOTATE type=3DANNOTYPE_NOENDBR - -/* - * This macro indicates that the following intra-function call is valid. - * Any non-annotated intra-function call will cause objtool to issue a war= ning. - */ -#define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=3DANNOTYPE_INTRA_FUNCTI= ON_CALL - #endif /* __ASSEMBLY__ */ =20 #else /* !CONFIG_OBJTOOL */ @@ -161,16 +138,12 @@ #define STACK_FRAME_NON_STANDARD_FP(func) #define __ASM_ANNOTATE(label, type) #define ASM_ANNOTATE(type) -#define ANNOTATE_NOENDBR #define ASM_REACHABLE #else -#define ANNOTATE_INTRA_FUNCTION_CALL .macro UNWIND_HINT type:req sp_reg=3D0 sp_offset=3D0 signal=3D0 .endm .macro STACK_FRAME_NON_STANDARD func:req .endm -.macro ANNOTATE_NOENDBR -.endm .macro REACHABLE .endm .macro ANNOTATE type:req @@ -179,4 +152,57 @@ =20 #endif /* CONFIG_OBJTOOL */ =20 +#ifndef __ASSEMBLY__ +/* + * Annotate away the various 'relocation to !ENDBR` complaints; knowing th= at + * these relocations will never be used for indirect calls. + */ +#define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) +/* + * This should be used immediately before an indirect jump/call. It tells + * objtool the subsequent indirect jump/call is vouched safe for retpoline + * builds. + */ +#define ANNOTATE_RETPOLINE_SAFE ASM_ANNOTATE(ANNOTYPE_RETPOLINE_SAFE) +/* + * See linux/instrumentation.h + */ +#define ANNOTATE_INSTR_BEGIN(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_B= EGIN) +#define ANNOTATE_INSTR_END(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_END) +/* + * objtool annotation to ignore the alternatives and only consider the ori= ginal + * instruction(s). + */ +#define ANNOTATE_IGNORE_ALTERNATIVE ASM_ANNOTATE(ANNOTYPE_IGNORE_ALTS) +/* + * This macro indicates that the following intra-function call is valid. + * Any non-annotated intra-function call will cause objtool to issue a war= ning. + */ +#define ANNOTATE_INTRA_FUNCTION_CALL ASM_ANNOTATE(ANNOTYPE_INTRA_FUNCTION_= CALL) +/* + * Use objtool to validate the entry requirement that all code paths do + * VALIDATE_UNRET_END before RET. + * + * NOTE: The macro must be used at the beginning of a global symbol, other= wise + * it will be ignored. + */ +#define ANNOTATE_UNRET_BEGIN ASM_ANNOTATE(ANNOTYPE_UNRET_BEGIN) + +#else +#define ANNOTATE_NOENDBR ANNOTATE type=3DANNOTYPE_NOENDBR +#define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=3DANNOTYPE_RETPOLINE_SAFE +/* ANNOTATE_INSTR_BEGIN ANNOTATE type=3DANNOTYPE_INSTR_BEGIN */ +/* ANNOTATE_INSTR_END ANNOTATE type=3DANNOTYPE_INSTR_END */ +#define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=3DANNOTYPE_IGNORE_ALTS +#define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=3DANNOTYPE_INTRA_FUNCTI= ON_CALL +#define ANNOTATE_UNRET_BEGIN ANNOTATE type=3DANNOTYPE_UNRET_BEGIN +#endif + +#if defined(CONFIG_NOINSTR_VALIDATION) && \ + (defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO= )) +#define VALIDATE_UNRET_BEGIN ANNOTATE_UNRET_BEGIN +#else +#define VALIDATE_UNRET_BEGIN +#endif + #endif /* _LINUX_OBJTOOL_H */ From nobody Sat Feb 7 08:45:17 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D69DB157E6B; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; cv=none; b=thjUkA+0oh3cXVekWHel01ZUSfC8tDKlCtQ44qqHtyLQ7AHlHAIMjdxXkcKqGvxgLCsAF+9umLcaqbc+IZK5xRdatmNc2zvuy24ChgtA9WoMiwUi1Q9UG8sc/5BYBHmWwGSNHrkblzVNLix3s+UHMxic5oACOtYhEztfzcL6ACg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; c=relaxed/simple; bh=N977qjYQyNiH1GU3lPNLCmz25IiPxBBU0fylee/nVqo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=pbpmSAaVFkwdR2SQgP0492bJ7jfvBqbZg6fzB2/WTtNRsvkzwq0DMsJBMZHlO6FZJJp1BaYIaVp330a3MRrISQBuXJr9gmVH0fRoWZEqq5KsH8qpP7YAkIRdRfYMsRuh/RoxxeILsmzweirw7ZkIbAe8+VzxtOLGKymBi79c2CU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=N4t7I81n; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="N4t7I81n" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=4LWTl2H6aL5DsJXRdlt+1kHQPXgTtK8uQyNB3mqvwQ0=; b=N4t7I81nqVpXZjTQb1b/H2gwkv puunr98yWFsnkP/y4Ugtd9d2OTo+OIm3jmjwvq1nmZV3M9fBnj1XilmsXRArkYY+pdx8K7MgbGqDa cVOct1+4N1RF2139IAvwJb6MTUzbUD0FSgKpYTrZviVFSqgKW7rWkWxKS1JCK8kLZwFlPyzJNlOs/ 39n/7HW+ImdE8z/J8kZz+d/Y9AyI09EvKpPY0deHc1pUWGpjuVsYmVbwYedUHSxlYusSeM1C3Z7jQ 7VjPnj9K1S1b22V4hYW3jXh6BxTepqmFadx/r0p2x1UWKYpQ/0CI+sMP54wH3HLSC5Aw0ZrAlxeMy wXj+U2xg==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb48-00000001a87-1hDT; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 23DE030119C; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094311.924381359@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:39:01 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/16] unreachable: Unify References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since barrier_before_unreachable() is empty for !GCC it is trivial to unify the two definitions. Less is more. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- include/linux/compiler-gcc.h | 12 ------------ include/linux/compiler.h | 10 +++++++--- 2 files changed, 7 insertions(+), 15 deletions(-) --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -52,18 +52,6 @@ */ #define barrier_before_unreachable() asm volatile("") =20 -/* - * Mark a position in code as unreachable. This can be used to - * suppress control flow warnings after asm blocks that transfer - * control elsewhere. - */ -#define unreachable() \ - do { \ - annotate_unreachable(); \ - barrier_before_unreachable(); \ - __builtin_unreachable(); \ - } while (0) - #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) #define __HAVE_BUILTIN_BSWAP32__ #define __HAVE_BUILTIN_BSWAP64__ --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -141,12 +141,16 @@ void ftrace_likely_update(struct ftrace_ #define __annotate_jump_table #endif /* CONFIG_OBJTOOL */ =20 -#ifndef unreachable -# define unreachable() do { \ +/* + * Mark a position in code as unreachable. This can be used to + * suppress control flow warnings after asm blocks that transfer + * control elsewhere. + */ +#define unreachable() do { \ annotate_unreachable(); \ + barrier_before_unreachable(); \ __builtin_unreachable(); \ } while (0) -#endif =20 /* * KENTRY - kernel entry point From nobody Sat Feb 7 08:45:17 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E04B17BA5; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; cv=none; b=eey3TRqO9qG1ddtjRUfYPejD/paRJqqRv0HOQQNJAA2CrWJlmKPTM8sK23K9VMm2rrj+3BAHOscOlcQKjGeDTDLB7JKvlLD3V1BdqJLIk6lwa0R0GLMNlqChqsJWFQLAYDMUIXXoFz5UKIxgbIY3CM6EIQ2at7XKOQLh5dqjYO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; c=relaxed/simple; bh=eujJA45cOWzSmPTpJqfQMojlmB6zj3e3t7Jg0VqWyZ0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=E/aGCh7AbjmqCxFlA44K1wjtMMRS46x+uy/Yb4bf92w/gRohOqlZ+mvszvIPO67ILVM3mWCA81/Q/rtnWtTtASFkfITYUSoAmh5gxrfiYFa4a7JKPuj1Q3L4CyZPhd6m/SxlT1bvTxWPcAuOWILQy/fAUGmUfsE5D1HU/SJDs/A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=XwedqdPJ; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XwedqdPJ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=1E58lGeShwswOTOQLOjpYCtc7pMebJYGn4GvdYK70QU=; b=XwedqdPJGej3sI1Xu9hiTch2oL SI4c4FpScJ2m/J3Ov/CL/P7seWQTg4Glq2n/QZrC8PwqzReC9NWjLqlVxwzv/rE37DPsEAFgrGVr2 XY2mwo5UkLe2g80j1/P0YgKnbMijmEulwK/SXm7G8OIWc2Q0lV+SWCKZl0oGkymHzmzTzaNvXxJXV mwTq8/hqbEoWfLjAheXWcUm8kwOv/23u9QthhsmSh4Cvl0uuMeLiiCebDeWdrvcq3K2vKL0QOFvYy +6+g/76lJ+GEEZwqR7GwNm0ZU6mjKg8/fm4L1z8L63Q4lWYzX1IW9RWwQdUrH7sL3115434CidCYR VbDLLBPA==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000002Tpx-0TSH; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 270DF301BD5; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094312.028316261@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:39:02 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/16] x86: Convert unreachable() to BUG() References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid unreachable() as it can (and will in the absence of UBSAN) generate fallthrough code. Use BUG() so we get a UD2 trap (with unreachable annotation). Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- arch/x86/kernel/process.c | 2 +- arch/x86/kernel/reboot.c | 2 +- arch/x86/kvm/svm/sev.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -838,7 +838,7 @@ void __noreturn stop_this_cpu(void *dumm #ifdef CONFIG_SMP if (smp_ops.stop_this_cpu) { smp_ops.stop_this_cpu(); - unreachable(); + BUG(); } #endif =20 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -883,7 +883,7 @@ static int crash_nmi_callback(unsigned i =20 if (smp_ops.stop_this_cpu) { smp_ops.stop_this_cpu(); - unreachable(); + BUG(); } =20 /* Assume hlt works */ --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3820,7 +3820,7 @@ static int snp_begin_psc(struct vcpu_svm goto next_range; } =20 - unreachable(); + BUG(); } =20 static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu) From nobody Sat Feb 7 08:45:17 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6096F156F5F; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; cv=none; b=SXppiGBkxg579WlXlD1vc2q3aJOW6ebKCPnMvc7SOrUbB5QrJtmMxroqv81Z5J+VFcxQ8LtDi0ZZGL+W7loB56jfMPCIYLLXEXmKP3hkBuBPDgayegSS0pTRMFVUyDAB18ZBTnnuvdQrBPz3IDnmwNHyJP5nOsvMl0HEmwpOMmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; c=relaxed/simple; bh=TQ9vA3Xg6DGKteBrAHo0E53uE8gHWzdmqn/rZhL7+P8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Ask/2/vGrEewaMCVh+fmbPz0Bf9VWlZsKSV45dhEMiy1qLiA1tNKaGUudcz3bEfrM7vesI+vgZ5hsA+hD9BFtogR2o99VIBGMQNR8mp2wx5i9GqDbGvED6RVy4G27PMc5B4adXibyOUoji/JuQeuZKJ5azK0gmEovHVIUtzMOQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=odzhO0mw; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="odzhO0mw" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=TrdAdZztiIjpmt3VeZGYbi5G41ypkPElwux/Td18Xc0=; b=odzhO0mw6rKwadCrRb/CbtqKeV hCit0UAFeApZFAiTRUHsst1Yy/tvfbDMX8wV2ZsAVT1lIWfwqrfZWY6yq1GJ3J7j/mKM6vDZKo7dK GlcMZ3qI2ev3nuKa19Xk7mj1wgh6cAucyY4HeGAf3VOMZ7sKyEnYgW8rDAa5oKfaw7miZGAS5mSDV R9B0ZrDj/8S3aYTcUI6yrff9bUkIxVAqSbXg6zX+ZHfgsUfzpSlxSSjfsqTK9ksZXKyAjtg3DPiYW cDhr4S1ucTXDvPBHKrmC0Fpm3XCAOh4INmhKXFOISd/9FyDMVevOwhiu74RzMT3MLjaaMv6LV2+p9 RncZOxXQ==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000002Tpy-0eHV; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 2ADA2301C34; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094312.133437051@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:39:03 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 12/16] loongarch: Use ASM_REACHABLE References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" annotate_reachable() is unreliable since the compiler is free to place random code inbetween two consecutive asm() statements. This removes the last and only annotate_reachable() user. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- arch/loongarch/include/asm/bug.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/arch/loongarch/include/asm/bug.h +++ b/arch/loongarch/include/asm/bug.h @@ -4,6 +4,7 @@ =20 #include #include +#include =20 #ifndef CONFIG_DEBUG_BUGVERBOSE #define _BUGVERBOSE_LOCATION(file, line) @@ -33,25 +34,25 @@ =20 #define ASM_BUG_FLAGS(flags) \ __BUG_ENTRY(flags) \ - break BRK_BUG + break BRK_BUG; =20 #define ASM_BUG() ASM_BUG_FLAGS(0) =20 -#define __BUG_FLAGS(flags) \ - asm_inline volatile (__stringify(ASM_BUG_FLAGS(flags))); +#define __BUG_FLAGS(flags, extra) \ + asm_inline volatile (__stringify(ASM_BUG_FLAGS(flags)) \ + extra); =20 #define __WARN_FLAGS(flags) \ do { \ instrumentation_begin(); \ - __BUG_FLAGS(BUGFLAG_WARNING|(flags)); \ - annotate_reachable(); \ + __BUG_FLAGS(BUGFLAG_WARNING|(flags), ASM_REACHABLE); \ instrumentation_end(); \ } while (0) =20 #define BUG() \ do { \ instrumentation_begin(); \ - __BUG_FLAGS(0); \ + __BUG_FLAGS(0, ""); \ unreachable(); \ } while (0) From nobody Sat Feb 7 08:45:17 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 780C115746F; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; cv=none; b=tqeIoAZNzYm20dFRHlLYUcyPTBGGRUFtbrIJ5wzij0Qqvz4ZfjWKxKXMuXAaxqvoEoK4UR60BkLT1yRcjOdx0mmJwST5GgVElM9KuLacpHHROwOfkKvHlQuaWoY7xG42jant910WzY+fgNmx6GmHKvrNmTiogj0/qi2LNFC5MkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; c=relaxed/simple; bh=UwDAhm94WYMzmdwCr57iKe2v+wiBrV3Pe5j9H0SPak0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=JCfj/293wWI7Nho4uA4TLCxFlnMyUUkPZCPJGmQ43+Xec24M2VoFttflcJ2Pmqxj0kL9UC8loa0JY6ec24hXNKi4E6oduQ6iuWAt/Vc0uFYfk1qQm0gXMi3JwlFT61pmitYMV5f7yjRVQif0GvPHLz0rZc1XCE0QHxOBFzguUOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=GaZGUuyo; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GaZGUuyo" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=RpesRdzRkQjwqb+WxngnuqT7GtZc/MTBiU+SPkIMEI0=; b=GaZGUuyoRZUX27QCOC5mfJ+skx Z/bf6Zam07+XCGaVCu1jCdf2F694g8sPfyTxCncXXLzCPqau6mNLtjuhN+oF9nzRnnii+9oT9rhSm YsKH8jjfcCZYy5UA45zsOyso/WBdQRQk9AJM4f2EYUP//LOONT/9Kr4gHv5tZ4XpgIlOJLE0fju66 xb6s4L6DvWIs+W0/fy5HhP1aitqTtZrEQJyBEXVAfZeL2fFoT2ChIWl3wRGrFypX8e2hbWtVe5yIp kFOkDrQQjNzhCDU6hzBo/FT+dzy5SNT/dVy6U3HOvKrNZ6HnYsimIkan6KTWVXAUT2GBPE/LvOI6D pqiESD6g==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000002Tpw-0V1V; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 2E789301CA1; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094312.235637588@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:39:04 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 13/16] objtool: Remove annotate_{,un}reachable() References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are no users of annotate_reachable() left. And the annotate_unreachable() usage in unreachable() is plain wrong; it will hide dangerous fall-through code-gen. Remove both. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- include/linux/compiler.h | 27 --------------------------- tools/objtool/check.c | 43 ++----------------------------------------- 2 files changed, 2 insertions(+), 68 deletions(-) --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -109,35 +109,9 @@ void ftrace_likely_update(struct ftrace_ =20 /* Unreachable code */ #ifdef CONFIG_OBJTOOL -/* - * These macros help objtool understand GCC code flow for unreachable code. - * The __COUNTER__ based labels are a hack to make each instance of the ma= cros - * unique, to convince GCC not to merge duplicate inline asm statements. - */ -#define __stringify_label(n) #n - -#define __annotate_reachable(c) ({ \ - asm volatile(__stringify_label(c) ":\n\t" \ - ".pushsection .discard.reachable\n\t" \ - ".long " __stringify_label(c) "b - .\n\t" \ - ".popsection\n\t"); \ -}) -#define annotate_reachable() __annotate_reachable(__COUNTER__) - -#define __annotate_unreachable(c) ({ \ - asm volatile(__stringify_label(c) ":\n\t" \ - ".pushsection .discard.unreachable\n\t" \ - ".long " __stringify_label(c) "b - .\n\t" \ - ".popsection\n\t" : : "i" (c)); \ -}) -#define annotate_unreachable() __annotate_unreachable(__COUNTER__) - /* Annotate a C jump table to allow objtool to follow the code flow */ #define __annotate_jump_table __section(".rodata..c_jump_table,\"a\",@prog= bits #") - #else /* !CONFIG_OBJTOOL */ -#define annotate_reachable() -#define annotate_unreachable() #define __annotate_jump_table #endif /* CONFIG_OBJTOOL */ =20 @@ -147,7 +121,6 @@ void ftrace_likely_update(struct ftrace_ * control elsewhere. */ #define unreachable() do { \ - annotate_unreachable(); \ barrier_before_unreachable(); \ __builtin_unreachable(); \ } while (0) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -638,47 +638,8 @@ static int add_dead_ends(struct objtool_ uint64_t offset; =20 /* - * Check for manually annotated dead ends. - */ - rsec =3D find_section_by_name(file->elf, ".rela.discard.unreachable"); - if (!rsec) - goto reachable; - - for_each_reloc(rsec, reloc) { - if (reloc->sym->type =3D=3D STT_SECTION) { - offset =3D reloc_addend(reloc); - } else if (reloc->sym->local_label) { - offset =3D reloc->sym->offset; - } else { - WARN("unexpected relocation symbol type in %s", rsec->name); - return -1; - } - - insn =3D find_insn(file, reloc->sym->sec, offset); - if (insn) - insn =3D prev_insn_same_sec(file, insn); - else if (offset =3D=3D reloc->sym->sec->sh.sh_size) { - insn =3D find_last_insn(file, reloc->sym->sec); - if (!insn) { - WARN("can't find unreachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, offset); - return -1; - } - } else { - WARN("can't find unreachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, offset); - return -1; - } - - insn->dead_end =3D true; - } - -reachable: - /* - * These manually annotated reachable checks are needed for GCC 4.4, - * where the Linux unreachable() macro isn't supported. In that case - * GCC doesn't know the "ud2" is fatal, so it generates code as if it's - * not a dead end. + * UD2 defaults to being a dead-end, allow them to be annotated for + * non-fatal, eg WARN. */ rsec =3D find_section_by_name(file->elf, ".rela.discard.reachable"); if (!rsec) From nobody Sat Feb 7 08:45:17 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC3C8157E82; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; cv=none; b=Q4FWlsBDlkQ3CIpIzR2gxbLDb3J32psQJthI6EY2T3PzHgYFBppd+fV7BdwxG2r5TcE7A8wZLXeEy/U/b5B/vtAekFH391wfL7eaWBjK/lFsy234yzSOGPxO3b5AMdGObBYXdWFsxfOmESGDf+ZU8rLUu7/NBnYLEpAMWhXsFjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787049; c=relaxed/simple; bh=1zB7QCTHqenNuqJa/hFSq5h350ONNN3U6vz5U0PjDLA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VN3ab540kZ4AgXMDjaRCpJjwS07OZVtdNkBwJcHBULuZja7HfP7zn4fYvv0dT864y8eOwwcd94rtn+Kzq08nNA/q0b9FsSCzb7EILtsOresb06i0EszZ2pOi1IXT2GDrjv/fsZyJsZoixpv7bBtPiIMSZuCnMoyXia4JumRQR5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=WIvtZCR7; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="WIvtZCR7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=bCe6p4zd4smqU+6rwokNNvA3uR+14ozb9/hQrP5U9Z8=; b=WIvtZCR7pT7UffRJT8ORirOubm 12nYob7K2zSXAYburYCiGFG9ULPBABPneUcHR6PyrH8U1pSFrVnq+ZlyTSIadlerF/6O7s3rO5Z6S wIwbCHNajfH5+YjeNm7tUbsHRJY11ZP1HOSZA9soETRi1f7YpB8j1ztpdQeFEknq3iUD1U5JFD/LI tN9txs6d1InSXpKL1pADgh77Czon3qBEwwSEviISE5B5Y+DJdWMehPTbSzK37+wbaoZOI/YqAXvBk UcqrG0TZ6xh0iyhmelCbSoqsrquiYQotCbzfD2KCte4YSLBb++M1SvnWOwIMB1hH6DiK2kznJWVJj EO1oy43A==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb48-00000001a88-1hI3; Thu, 28 Nov 2024 09:44:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 31FAB301CEB; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094312.353431347@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:39:05 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Josh Poimboeuf Subject: [PATCH v2 14/16] objtool: Convert {.UN}REACHABLE to ANNOTATE References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Suggested-by: Josh Poimboeuf Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- arch/loongarch/include/asm/bug.h | 2=20 arch/x86/entry/entry_64.S | 4 - arch/x86/include/asm/bug.h | 2=20 arch/x86/include/asm/irq_stack.h | 2=20 include/linux/objtool.h | 18 +++---- include/linux/objtool_types.h | 1=20 tools/include/linux/objtool_types.h | 1=20 tools/objtool/check.c | 82 +++++++++----------------------= ----- 8 files changed, 36 insertions(+), 76 deletions(-) --- a/arch/loongarch/include/asm/bug.h +++ b/arch/loongarch/include/asm/bug.h @@ -45,7 +45,7 @@ #define __WARN_FLAGS(flags) \ do { \ instrumentation_begin(); \ - __BUG_FLAGS(BUGFLAG_WARNING|(flags), ASM_REACHABLE); \ + __BUG_FLAGS(BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE);\ instrumentation_end(); \ } while (0) =20 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -311,7 +311,7 @@ SYM_CODE_END(xen_error_entry) call \cfunc =20 /* For some configurations \cfunc ends up being a noreturn. */ - REACHABLE + ANNOTATE_REACHABLE =20 jmp error_return .endm @@ -532,7 +532,7 @@ SYM_CODE_START(\asmsym) call \cfunc =20 /* For some configurations \cfunc ends up being a noreturn. */ - REACHABLE + ANNOTATE_REACHABLE =20 jmp paranoid_exit =20 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -92,7 +92,7 @@ do { \ do { \ __auto_type __flags =3D BUGFLAG_WARNING|(flags); \ instrumentation_begin(); \ - _BUG_FLAGS(ASM_UD2, __flags, ASM_REACHABLE); \ + _BUG_FLAGS(ASM_UD2, __flags, ANNOTATE_REACHABLE); \ instrumentation_end(); \ } while (0) =20 --- a/arch/x86/include/asm/irq_stack.h +++ b/arch/x86/include/asm/irq_stack.h @@ -101,7 +101,7 @@ =20 #define ASM_CALL_ARG0 \ "call %c[__func] \n" \ - ASM_REACHABLE + ANNOTATE_REACHABLE =20 #define ASM_CALL_ARG1 \ "movq %[arg1], %%rdi \n" \ --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -111,14 +111,6 @@ #endif .endm =20 - -.macro REACHABLE -.Lhere_\@: - .pushsection .discard.reachable - .long .Lhere_\@ - .popsection -.endm - .macro ANNOTATE type:req .Lhere_\@: .pushsection .discard.annotate_insn,"M",@progbits,8 @@ -138,14 +130,11 @@ #define STACK_FRAME_NON_STANDARD_FP(func) #define __ASM_ANNOTATE(label, type) #define ASM_ANNOTATE(type) -#define ASM_REACHABLE #else .macro UNWIND_HINT type:req sp_reg=3D0 sp_offset=3D0 signal=3D0 .endm .macro STACK_FRAME_NON_STANDARD func:req .endm -.macro REACHABLE -.endm .macro ANNOTATE type:req .endm #endif @@ -187,6 +176,12 @@ * it will be ignored. */ #define ANNOTATE_UNRET_BEGIN ASM_ANNOTATE(ANNOTYPE_UNRET_BEGIN) +/* + * This should be used directly after an instruction that is considered + * terminating, like a noreturn CALL or UD2 when we know they are not -- eg + * WARN using UD2. + */ +#define ANNOTATE_REACHABLE ASM_ANNOTATE(ANNOTYPE_REACHABLE) =20 #else #define ANNOTATE_NOENDBR ANNOTATE type=3DANNOTYPE_NOENDBR @@ -196,6 +191,7 @@ #define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=3DANNOTYPE_IGNORE_ALTS #define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=3DANNOTYPE_INTRA_FUNCTI= ON_CALL #define ANNOTATE_UNRET_BEGIN ANNOTATE type=3DANNOTYPE_UNRET_BEGIN +#define ANNOTATE_REACHABLE ANNOTATE type=3DANNOTYPE_REACHABLE #endif =20 #if defined(CONFIG_NOINSTR_VALIDATION) && \ --- a/include/linux/objtool_types.h +++ b/include/linux/objtool_types.h @@ -64,5 +64,6 @@ struct unwind_hint { #define ANNOTYPE_UNRET_BEGIN 5 #define ANNOTYPE_IGNORE_ALTS 6 #define ANNOTYPE_INTRA_FUNCTION_CALL 7 +#define ANNOTYPE_REACHABLE 8 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/include/linux/objtool_types.h +++ b/tools/include/linux/objtool_types.h @@ -64,5 +64,6 @@ struct unwind_hint { #define ANNOTYPE_UNRET_BEGIN 5 #define ANNOTYPE_IGNORE_ALTS 6 #define ANNOTYPE_INTRA_FUNCTION_CALL 7 +#define ANNOTYPE_REACHABLE 8 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -627,56 +627,6 @@ static struct instruction *find_last_ins return insn; } =20 -/* - * Mark "ud2" instructions and manually annotated dead ends. - */ -static int add_dead_ends(struct objtool_file *file) -{ - struct section *rsec; - struct reloc *reloc; - struct instruction *insn; - uint64_t offset; - - /* - * UD2 defaults to being a dead-end, allow them to be annotated for - * non-fatal, eg WARN. - */ - rsec =3D find_section_by_name(file->elf, ".rela.discard.reachable"); - if (!rsec) - return 0; - - for_each_reloc(rsec, reloc) { - if (reloc->sym->type =3D=3D STT_SECTION) { - offset =3D reloc_addend(reloc); - } else if (reloc->sym->local_label) { - offset =3D reloc->sym->offset; - } else { - WARN("unexpected relocation symbol type in %s", rsec->name); - return -1; - } - - insn =3D find_insn(file, reloc->sym->sec, offset); - if (insn) - insn =3D prev_insn_same_sec(file, insn); - else if (offset =3D=3D reloc->sym->sec->sh.sh_size) { - insn =3D find_last_insn(file, reloc->sym->sec); - if (!insn) { - WARN("can't find reachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, offset); - return -1; - } - } else { - WARN("can't find reachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, offset); - return -1; - } - - insn->dead_end =3D false; - } - - return 0; -} - static int create_static_call_sections(struct objtool_file *file) { struct static_call_site *site; @@ -2306,6 +2256,7 @@ static int read_annotate(struct objtool_ struct section *sec; struct instruction *insn; struct reloc *reloc; + uint64_t offset; int type, ret; =20 sec =3D find_section_by_name(file->elf, ".discard.annotate_insn"); @@ -2327,8 +2278,19 @@ static int read_annotate(struct objtool_ for_each_reloc(sec->rsec, reloc) { type =3D *(u32 *)(sec->data->d_buf + (reloc_idx(reloc) * sec->sh.sh_ents= ize) + 4); =20 - insn =3D find_insn(file, reloc->sym->sec, - reloc->sym->offset + reloc_addend(reloc)); + offset =3D reloc->sym->offset + reloc_addend(reloc); + insn =3D find_insn(file, reloc->sym->sec, offset); + + /* + * Reachable annotations are 'funneh' and act on the previous instructio= n :/ + */ + if (type =3D=3D ANNOTYPE_REACHABLE) { + if (insn) + insn =3D prev_insn_same_sec(file, insn); + else if (offset =3D=3D reloc->sym->sec->sh.sh_size) + insn =3D find_last_insn(file, reloc->sym->sec); + } + if (!insn) { WARN("bad .discard.annotate_insn entry: %d of type %d", reloc_idx(reloc= ), type); return -1; @@ -2420,6 +2382,10 @@ static int __annotate_late(struct objtoo insn->unret =3D 1; break; =20 + case ANNOTYPE_REACHABLE: + insn->dead_end =3D false; + break; + default: break; } @@ -2566,14 +2532,6 @@ static int decode_sections(struct objtoo if (ret) return ret; =20 - /* - * Must be after add_call_destinations() such that it can override - * dead_end_function() marks. - */ - ret =3D add_dead_ends(file); - if (ret) - return ret; - ret =3D add_jump_table_alts(file); if (ret) return ret; @@ -2582,6 +2540,10 @@ static int decode_sections(struct objtoo if (ret) return ret; =20 + /* + * Must be after add_call_destinations() such that it can override + * dead_end_function() marks. + */ ret =3D read_annotate(file, __annotate_late); if (ret) return ret; From nobody Sat Feb 7 08:45:17 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E08E155C83; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; cv=none; b=g1Pdk11GfkzwZWfDX/GEtEJ1qcuXPwNdNvOTfJ0XQZRiqeYilqqcPMOUP6JdxA7jl6A0+l7WgTUl0Hsmd9420kjDoP8DT2X4/EJWAjnWwquUfOiJhOqGuTpk36G1xAKn5ANvEgBMmqzxbbzfTMGhK9fJU0tviU+BYPqeAv+oTM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787048; c=relaxed/simple; bh=xtSZebKWsUH+UCo4IBaR0pGfLgkWjIXEJBRZfBMlU2M=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=YhY94IQu9CZejHk3eyg6js1Eq/fnzLWDc2Yk8XXcK4kw+ZlbO/p2B/whKQIWC40NNM8hfE4ZqsGAAxoMGK3a9Ru+ysrY15cizZppxchRJVVqwFoyymmyaOpX2r8i72wOGG0/qvFsPR3O67URfyO+qqdk5eLTl0vUh3wtBOFagZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=tSmu00M2; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="tSmu00M2" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=MaRHRxfWomSomgbkiybbctrnE7Gu06p2gq17dQqKIug=; b=tSmu00M2cslQ/Vkar7t1oTc1Ev WoETsvPRUwSWItwFVpYzyei2H7kmYHwSe/14GkrbrTavpTYWPdUpkDtdI1KSxu0HCB0zdeNA3Eyjf bbA9PxbbyWFQv/BgXazI7fMKLVqO9L6SwzfiIzKffss3RhiEpKiRVnLCkXyryW8zBNvQveexYuZux 4PBTMiSnzuNHpx/vIFn1l0x5doLD5sT2ccAoSOlKZLNtsNlRDw/fPUfgoLvbdmSI/S7TgrTdESB33 yzOneZc+ilm4bD3A3bRmeNOT+WM7iLuRktu7w6dmXlhFjNDwxcTrOLuBEKdyBx8TCF5ve4nvaHdIp moYCJUag==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb47-00000002Tq4-2oiX; Thu, 28 Nov 2024 09:44:05 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 356F7301CFB; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094312.494176035@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:39:06 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 15/16] objtool: Fix ANNOTATE_REACHABLE to be a normal annotation References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently REACHABLE is weird for being on the instruction after the instruction it modifies. Since all REACHABLE annotations have an explicit instruction, flip them around. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- arch/loongarch/include/asm/bug.h | 2 +- arch/x86/entry/entry_64.S | 5 ++--- arch/x86/include/asm/bug.h | 2 +- arch/x86/include/asm/irq_stack.h | 4 ++-- include/linux/objtool.h | 4 ++-- tools/objtool/check.c | 23 ----------------------- 6 files changed, 8 insertions(+), 32 deletions(-) --- a/arch/loongarch/include/asm/bug.h +++ b/arch/loongarch/include/asm/bug.h @@ -45,7 +45,7 @@ #define __WARN_FLAGS(flags) \ do { \ instrumentation_begin(); \ - __BUG_FLAGS(BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE);\ + __BUG_FLAGS(BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE(10001b));\ instrumentation_end(); \ } while (0) =20 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -308,10 +308,9 @@ SYM_CODE_END(xen_error_entry) movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ .endif =20 - call \cfunc - /* For some configurations \cfunc ends up being a noreturn. */ ANNOTATE_REACHABLE + call \cfunc =20 jmp error_return .endm @@ -529,10 +528,10 @@ SYM_CODE_START(\asmsym) movq %rsp, %rdi /* pt_regs pointer into first argument */ movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/ movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ - call \cfunc =20 /* For some configurations \cfunc ends up being a noreturn. */ ANNOTATE_REACHABLE + call \cfunc =20 jmp paranoid_exit =20 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -92,7 +92,7 @@ do { \ do { \ __auto_type __flags =3D BUGFLAG_WARNING|(flags); \ instrumentation_begin(); \ - _BUG_FLAGS(ASM_UD2, __flags, ANNOTATE_REACHABLE); \ + _BUG_FLAGS(ASM_UD2, __flags, ANNOTATE_REACHABLE(1b)); \ instrumentation_end(); \ } while (0) =20 --- a/arch/x86/include/asm/irq_stack.h +++ b/arch/x86/include/asm/irq_stack.h @@ -100,8 +100,8 @@ } =20 #define ASM_CALL_ARG0 \ - "call %c[__func] \n" \ - ANNOTATE_REACHABLE + "1: call %c[__func] \n" \ + ANNOTATE_REACHABLE(1b) =20 #define ASM_CALL_ARG1 \ "movq %[arg1], %%rdi \n" \ --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -177,11 +177,11 @@ */ #define ANNOTATE_UNRET_BEGIN ASM_ANNOTATE(ANNOTYPE_UNRET_BEGIN) /* - * This should be used directly after an instruction that is considered + * This should be used to refer to an instruction that is considered * terminating, like a noreturn CALL or UD2 when we know they are not -- eg * WARN using UD2. */ -#define ANNOTATE_REACHABLE ASM_ANNOTATE(ANNOTYPE_REACHABLE) +#define ANNOTATE_REACHABLE(label) __ASM_ANNOTATE(label, ANNOTYPE_REACHABLE) =20 #else #define ANNOTATE_NOENDBR ANNOTATE type=3DANNOTYPE_NOENDBR --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -614,19 +614,6 @@ static int init_pv_ops(struct objtool_fi return 0; } =20 -static struct instruction *find_last_insn(struct objtool_file *file, - struct section *sec) -{ - struct instruction *insn =3D NULL; - unsigned int offset; - unsigned int end =3D (sec->sh.sh_size > 10) ? sec->sh.sh_size - 10 : 0; - - for (offset =3D sec->sh.sh_size - 1; offset >=3D end && !insn; offset--) - insn =3D find_insn(file, sec, offset); - - return insn; -} - static int create_static_call_sections(struct objtool_file *file) { struct static_call_site *site; @@ -2281,16 +2268,6 @@ static int read_annotate(struct objtool_ offset =3D reloc->sym->offset + reloc_addend(reloc); insn =3D find_insn(file, reloc->sym->sec, offset); =20 - /* - * Reachable annotations are 'funneh' and act on the previous instructio= n :/ - */ - if (type =3D=3D ANNOTYPE_REACHABLE) { - if (insn) - insn =3D prev_insn_same_sec(file, insn); - else if (offset =3D=3D reloc->sym->sec->sh.sh_size) - insn =3D find_last_insn(file, reloc->sym->sec); - } - if (!insn) { WARN("bad .discard.annotate_insn entry: %d of type %d", reloc_idx(reloc= ), type); return -1; From nobody Sat Feb 7 08:45:17 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33D18158534; Thu, 28 Nov 2024 09:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787050; cv=none; b=Hd+MdxcYbAccgfFA41tKFgUXx7T18wbvYafRBrDhrKB618ciOQ82ATDZAF2Rl9T4Ap4rQ2fcdr68IAoZzeKw61V48G844LPMlsyno2ESn8bQPZ7TbvS4vVGqszsaaTgZPavXhnC1Cz8CG1BGEQnRUMw06KMv63j6YftxXH8WW7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732787050; c=relaxed/simple; bh=rUzQRY4Upk9ByEG9JLJSw+zikD2MXdRxtqUBIQZFLPc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sOJo3ajKKqyPlRWkUF/vVg0Ej+QOrLLVJyuEUe1K6qYGxRjJApiRs3wU173R6JrvUNX9j9GEfXs/SdIwXiC8H/zd8fFJPRm08TFXuOXr/zcLRrDgZQ2NiBRy81ixqE0eGhi8XK8Qw2kp39+mD9g7AdVcHkshDmy3ANHItdtC7OE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=THE9Y7Tt; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="THE9Y7Tt" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=TyR7Y3IB+rDfjHmcbI/1IKsZPSstvP5IWO/FJAgpT78=; b=THE9Y7TtDSYNrZQVeNFMZXILJm Ejq8U+pKWx8vhUjkODIhdToP/qshojJaMK4lQVsOJgiQsLjHnZTu9isXR5n8M2nzHBGM9ee43lB9x boMBtifFpjmPNYg/hrK5T9g2Q28MgHrXj1W1YLTcy10ymNP8c0FtLJkxGvSPzHjEi3KsAdBZLMe8a QzUgTBKveyPzadCf/jfrZ/89U7euKsl6Wqs/k+JikWAa9gqLrlg/wT4bsnCynfujFjt90RdKZRq5n gGJ3Z+4t0DvayMZf3XwDwJom3+SL540XOIvKQ43kRuNSWV/vj8abqQSUbxoNZBlYy1YziZ9ycGqk+ tRz0CsZw==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tGb48-00000001a8A-42bR; Thu, 28 Nov 2024 09:44:05 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 38AA4301D03; Thu, 28 Nov 2024 10:44:03 +0100 (CET) Message-ID: <20241128094312.611961175@infradead.org> User-Agent: quilt/0.66 Date: Thu, 28 Nov 2024 10:39:07 +0100 From: Peter Zijlstra To: jpoimboe@kernel.org Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org, peterz@infradead.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 16/16] objtool: Warn about unknown annotation types References: <20241128093851.469225872@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- tools/objtool/check.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2335,6 +2335,10 @@ static int __annotate_ifc(struct objtool static int __annotate_late(struct objtool_file *file, int type, struct ins= truction *insn) { switch (type) { + case ANNOTYPE_NOENDBR: + /* early */ + break; + case ANNOTYPE_RETPOLINE_SAFE: if (insn->type !=3D INSN_JUMP_DYNAMIC && insn->type !=3D INSN_CALL_DYNAMIC && @@ -2359,11 +2363,20 @@ static int __annotate_late(struct objtoo insn->unret =3D 1; break; =20 + case ANNOTYPE_IGNORE_ALTS: + /* early */ + break; + + case ANNOTYPE_INTRA_FUNCTION_CALL: + /* ifc */ + break; + case ANNOTYPE_REACHABLE: insn->dead_end =3D false; break; =20 default: + WARN_INSN(insn, "Unknown annotation type: %d", type); break; }