From nobody Sat Feb 7 22:21:22 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 F1F7B18B466 for ; Fri, 22 Nov 2024 12:16:49 +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=1732277811; cv=none; b=Ko9bwO/HsxspA0gH2+0oKNdaNu1a26A4RCugttDPJdlG3OwZU6T8thsUMweQWbTGEwYqFCaMHEEiPjUEieKxpetoWRrza3sz6gd9KZVgIbCQz6wB+UQoWUHK0pl65Snjby4q63UrBeaXsLR08Uy6pzWdyS8wk0SG0rludz27PTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277811; c=relaxed/simple; bh=3EViGVtiv5ZKDg5nuZD7B+Kiri68iPzlBDpVXHwHSbg=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BHZmaSQ0XIlQeBaD9rKPzp5kvBs8KPH+PIJ3x8KyiSfchwSedX3QgowdV6wp2UuqSyFzrTrUI598Ro1Obbx/SA1/HZfYEml2n/4pmLxUyQmF5+8cGij4A3tKjNFsMwDLRg7E6yIgLifN5u+9Tx3+5gqCd28IYPp1QgqTHiyGToY= 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=LWfx/+/c; 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="LWfx/+/c" 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=5k6+52P5B35R+WjAC8g6iI0mXf3jovg2NbzDOJS2H5A=; b=LWfx/+/cFneSYXFOTYcMRWchyJ ZAYJV0plOZjNhQ/gXekpDmMSiwS25B/fMhlgPjqhfRW4uRI0NZ1Boy7YnJN+XZHaHCY4zcjHOatYp UwDTaQSKQ4HjrDVDHxCaz97UZitmvK/hk/UkHtH2FqteIuTmE2Dscndq4oZnedm+2Lml85rmBAWh6 2SiI16MvY4M7z6RDkE3kowM3JBQj99UBX/A7GRGHoGbNCk8X6xMrhECBmgSWk+mzSedwteRRt9FXb i+VNqaKlRRdHRUxoH8edwqoFwsp+F7q0Si9naszzqyJckaLhIwbyjw9c5pThnyPlwIHu7WZbbalsd xIYAQPDg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESae-00000000hao-0CFX; Fri, 22 Nov 2024 12:16:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id DD3C7300E95; Fri, 22 Nov 2024 13:16:46 +0100 (CET) Message-Id: <20241122121555.621070802@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:17 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 1/9] objtool: Generic annotation infrastructure References: <20241122121016.372005127@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 section that takes an annotation type along with the instruction. Signed-off-by: Peter Zijlstra (Intel) --- 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(x) \ + "911:\n\t" \ + ".pushsection .discard.annotate,\"M\",@progbits,8\n\t" \ + ".long 911b - .\n\t" \ + ".long " __stringify(x) "\n\t" \ + ".popsection\n\t" + #else /* __ASSEMBLY__ */ =20 /* @@ -146,6 +153,14 @@ .popsection .endm =20 +.macro ANNOTATE type:req +.Lhere_\@: + .pushsection .discard.annotate,"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(x) #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"); + 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 entry: %d of type %d", reloc_idx(reloc), ty= pe); + 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 22:21:22 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 0C2C31DE2B3 for ; Fri, 22 Nov 2024 12:16:49 +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=1732277812; cv=none; b=LrYZNQAUyiXqmsoMJ5tIPo8Qm0Yxf+vtWizK9Q3lPVDJdgzTPyxlnwylfkiBHkMtWS+NGEsZgeZ5O8gUUkGTWahkV2dY14eF6fZeh02GRlZ1yhskAz9ZS0zkSE3fFIy/up3K0EB4pMxoVgNQhDTvkMeVfqmNx0lvvSJ3f/46zYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277812; c=relaxed/simple; bh=6Szio8eOyHDBpl65HFmw6k+IdFMuOAQlksIiABq4l5M=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=pZbEsee7CcginvAFOP/W3wv4Z8EhdpFqMzUQEr11WfbjAVEX1xrirDYbThF58lpfyliHDfVbIOAPO8+oXZvUeyK7QRHLVbXV7slHWscKgortXKtBlOv8LIcIFLDByjhIMJ8ttVCgCES+vjWCXkbF3YwT7ikygPlM7rGLsee3QaA= 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=TVmg1PHc; 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="TVmg1PHc" 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=B6opN5MpeDT3Yz+qLMJgiO+trHgJ54BWfaP4MBuFTWY=; b=TVmg1PHc8g5uHsmb9Ay+cQykYv ZTxaGQS0myHnsVsVVquz8tVhaiyOndrKZCt97StusAy9aFo20v95pVXqe5I6D3NTwGUSmGKRiHAtq i5OIvbhWlCIFF0+CQLLuSK7IHQYL4lLFAQIQbNHT6LQ44ILCB0L67BQ7GnRk/7GF+dye4S69eYXjw IbLwom5Nh4KjLDWv6wZt6hW3SegfgCMo57F85xN4EKIr3UJx3cdB+lOOTOQgvUWONNuhcx3RgC3G3 b+VwR3oQxnipMsxY0j4OL8O4YQP974P+ZeJhR63cH/4zR6XlgGijMukV3Jp4mez9QgY2ABNNUWLlG syVsKNVw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESae-00000000han-08RY; Fri, 22 Nov 2024 12:16:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id E1CB730119C; Fri, 22 Nov 2024 13:16:46 +0100 (CET) Message-Id: <20241122121555.727837221@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:18 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 2/9] objtool: Convert ANNOTATE_NOENDBR to ANNOTATE References: <20241122121016.372005127@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) --- 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(x) "\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 22:21:22 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 0C3181DE2BF for ; Fri, 22 Nov 2024 12:16:49 +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=1732277813; cv=none; b=bRoATvuU4TbpUTye6fOpaKt6eC/wY5HLUhkq0ty97c3M7rHmQ23BuM9wbjEFwWjWTlRF5hHbKdboJ2mRZTUxdHm+nEHYDLzefY2AlLhnWqpyTLy2UbDTtLv4f8Z6p7nHgz2aidJufrrqLZSR2Z62eYxx1ugjH+NRMiNohNugEI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277813; c=relaxed/simple; bh=8xa9UQlw4yHAq//FYbtjmItB4uOY1IOJYo7v7iQCT7Q=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=FXPTdfWCvpIG+QNG00LM09VKCz5RATllDWdj0S7Sy0xMTFPTeVjb0QG6z+CsApFIvy3yy43G/7PZCQfcjCEWCBR3TC9EW4qceN1O+RUXC9Yrympq34ZFlMIuf8ltrwPUakcYRd/KAE4U0gSQJeoIIDkM2eGjEopx2H/jPYLhC20= 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=AG6DwzDh; 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="AG6DwzDh" 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=vd/eo+06mSr8TeyFSi1NAWzmjcm+r66j/vwECKla4Zk=; b=AG6DwzDhEME8vh64i3hP6HGLxI OZkigLX+fTmOLZ+Ex70Y6duZ/hIVvo3NS0JZlTkxJdkJGR40J9bZAvsdFJDP6LxAjyGQG2lDk/gcA zc85F9dJ0EpjlqsbH5A3ndojGSIXzcP3iRVh005U9K3stviU/jcL5xD3h8sGWmK0SkTOot0+V/i13 wf6o6aAXEmGH+7owXfoaxz5a8wqfKXJnLgg5Oc+Vy7yHzrjD0fzZ28m0gPnHt2rqf8pu45/hL3jZK M/3NQ+oTq7pcskjxA4nirgFSY2DYST97dDbBOQPJoaJTJL/jV8Vd98Iw8ksRDYlkAdW7Nt4KSKBDK 4PP9mSUA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESae-00000000hap-0CIc; Fri, 22 Nov 2024 12:16:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id E602A301D99; Fri, 22 Nov 2024 13:16:46 +0100 (CET) Message-Id: <20241122121555.835566984@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:19 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 3/9] objtool: Convert ANNOTATE_RETPOLINE_SAFE to ANNOTATE References: <20241122121016.372005127@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) --- 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"); 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 22:21:22 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 BF2A91DC1BA for ; Fri, 22 Nov 2024 12:16:49 +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=1732277811; cv=none; b=nzR+dUgKjkJCwwQj+nWwGQN/4uLkroUpF//G2WgKWsMKv0KfPtTiTlMtjVnfn8oRNdGvRPgZhEsFbqzLzhFHykbqorx+hvs7sJsDcAvBw/pQu207oTjMJFfQxqgOYykewtIiN3rjdbbl5UengTIJbDsNoE71ewHnZWgfAcN6zGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277811; c=relaxed/simple; bh=oGt7d2/1AZ6ttNQD3Hxor5BKbIHGTlMU4ITcmaa5IXY=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=W6k9VUG8iSU/5wsRRSWSEkrEKDPoPmoRzIDNLuq+dt4AX0at15wdduF+ZmxpHM86CM1OaLvQGtTJGUtfQJBf9843oMhbtw+0nmWreyfX+Z8TDaOKTySo4k6OutcJ04LdsaWfg7RaQnypaUnBPrXwjbb8NzxmeRLzRKvQ8vUkizA= 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=sqbIin57; 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="sqbIin57" 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=gAZk8BfSgMbnXgBVXT4gwmRA5jBGKu/1a0p5ZQUwXz4=; b=sqbIin57NOM30pSQ+3hk4/m8XM BP6yE2ZPmelffkCcZO1RpzAiwLAfr31tn9tdibk9lzeGc15PQTsCZhvAKpvCuJ/FFmmcIIwJuV528 wt5D1oSUkXmlQ4Sjul3MWIzt4nrJSD2OsA4SI1NObpr05JxeldJRimv9TFlDNOESIxE65Aj7GWPTW KuXbcrExKz9ok//+zkJR/hxLBgKKoA/KRuYryu7vjFzGaIwYczkvnmCcVhGLYex4fQ22MFl89OPeG aWBfNgt2cY747bBChuE2JI1EhkTE6+8pl3rTM0AJZ2Y1uz1Z3L8+JElVY8CwXeTZAQa/NBG/OVTYP jxCZOBxQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESac-00000007dTM-2EEW; Fri, 22 Nov 2024 12:16:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id EA0DB3021DA; Fri, 22 Nov 2024 13:16:46 +0100 (CET) Message-Id: <20241122121555.941999497@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:20 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 4/9] objtool: Convert instrumentation_{begin,end}() to ANNOTATE References: <20241122121016.372005127@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) --- include/linux/instrumentation.h | 12 ++++---- include/linux/objtool.h | 9 ++++-- include/linux/objtool_types.h | 2 + tools/include/linux/objtool_types.h | 2 + tools/objtool/check.c | 49 +++++++------------------------= ----- 5 files changed, 26 insertions(+), 48 deletions(-) --- a/include/linux/instrumentation.h +++ b/include/linux/instrumentation.h @@ -4,14 +4,15 @@ =20 #ifdef CONFIG_NOINSTR_VALIDATION =20 +#include #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(CONCATENATE(c, b), ANNOTYPE_INSTR_BEGIN) \ + : : "i" (c)); \ }) #define instrumentation_begin() __instrumentation_begin(__COUNTER__) =20 @@ -48,9 +49,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(CONCATENATE(c, b), 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,16 @@ ".long 998b\n\t" \ ".popsection\n\t" =20 -#define ASM_ANNOTATE(x) \ - "911:\n\t" \ +#define __ASM_ANNOTATE(s, x) \ ".pushsection .discard.annotate,\"M\",@progbits,8\n\t" \ - ".long 911b - .\n\t" \ + ".long " __stringify(s) " - .\n\t" \ ".long " __stringify(x) "\n\t" \ ".popsection\n\t" =20 +#define ASM_ANNOTATE(x) \ + "911:\n\t" \ + __ASM_ANNOTATE(911b, x) + #define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) =20 #else /* __ASSEMBLY__ */ --- 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 22:21:22 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 0C2501DD0E7 for ; Fri, 22 Nov 2024 12:16:49 +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=1732277812; cv=none; b=LvnjAY9obswjes+k5M2sFiOuciuTPrtVXh3UA9cegA/Ehg1486edun3bEXaKGQG5jIGrofDL0lDWhJXnxR8jXZF2RSIBKcdCBuTiQSraTSnWhPJ3LExthmCpf0xPDI1qMY6VIttCAnuLPjOMcoCq/YC+NZP5EO9oDitoYp+btf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277812; c=relaxed/simple; bh=Yn8q4QXUFlxAK46m/412Srx0seyBg8HOXUGBVXU1ZX4=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=jxuGZuiPTuyYEy0rVkidgYq/+Hr8IH7yyHr0TgJfXf+s/aRtgok7V1nNUiuMb/QFPFjTXFsVM0oRkLjvoTofd1lO9NEe1flfnxINQdKvqLROfBCSUyQgF2SV6aQkWUqK7wKRiP0kgFyAVqgpdszo1R04LqZjRsydWFH2PAjfvFw= 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=W6xJ5bEk; 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="W6xJ5bEk" 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=v+L6BbfOg0jwO5KFbIbrKS0ECVjAfimoVQrz+6GrR9E=; b=W6xJ5bEkMBqn1EPt/HBNOM+OKL p2QvfXo9qwq+VXKp4Aur3lS/FwwV7itlOlwdIwymappbNvoDlz5QOWAXAFoMvFrts/aUJERmJzCer bd7RWp8THNpYw6tXSag0kPJ+vYXi0AJ7dbTFr+BsiAEsahLUkXQn1yTgrj1gbSeltjLdtUrX2WHA7 1FGs01ilbtt8XEgy1+vpzTa4JGArsRmqC+8XXk+vPPFtl4t7xj+Re2XXxcUNnX4+Wc+kXQBqzwuJl trdPwGQAjXm+6Vk9k/vIM0GjFKAIpCPyx57fa7N1k1+FkU7TOp192jWYroaZu9tmX01+ot76yiiL+ mczeVNfQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESae-00000000haq-1l3t; Fri, 22 Nov 2024 12:16:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id EDF4C3021E5; Fri, 22 Nov 2024 13:16:46 +0100 (CET) Message-Id: <20241122121556.048520690@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:21 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 5/9] objtool: Convert VALIDATE_UNRET_BEGIN to ANNOTATE References: <20241122121016.372005127@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) --- 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 @@ -128,15 +128,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 @@ -2450,33 +2450,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) { @@ -2697,7 +2679,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 22:21:22 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 913171BC091 for ; Fri, 22 Nov 2024 12:16:50 +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=1732277812; cv=none; b=Vh21I8ut10EqI1RclVCjW1Y1xuNx1S+iSlECjkInDUm2wyDbxAkXVtjn4iHuwtmqYwha9mFDDo2bIKblWVGHFE1Ox2/7MB3l6FUJrBESG8xJLOPwPxmvsU16JKf/LGSi0r5ET8KUwQhaWemR5cE7dj8IcRrC4FCW25dySJFc4cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277812; c=relaxed/simple; bh=J4qe9kzMeaC+48JT9UPo1D22Cwz02M19mcNneZ0NCOo=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=G31twRfOJKCzJJkFVkDmEuDBXTPUArHPHdstIfXdYy0QO1GHvx5hFiNATTSSCuBagOm4HQc5W1wUADNRnnh7qYXQOOXD985c+841xPZlB8LAP3EYV8/1q6+uIBJ7IbwCWGvKoIzFRgY1NXZlvkcLX0CpJy8sfUDtg+XoH453LDs= 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=Jxi9YcBO; 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="Jxi9YcBO" 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=iT8rZBU1kFBBncA0eT4LO89fZPLO0VJsqubseEy0Iso=; b=Jxi9YcBOgUmTDHGeHm8smpmeUB gq3j8D6vULfed0mlwbWkuDhKW4TktTZwaKAWpEB6rk3GbS/WKY4fQqJRQBM2L84BdXgNHViLJohq5 tKKW16EeB/giZE2vZL8dvVGo00763aFsFmTeol0PX1Q5S+ZTfN7yyWG0JGUOAJ4KPQ3wAC8m5eUKL 0IrE/SqiCZxBYyQxF5AJrrFD+3Vseo5D3Hifx4bmsAGtFXuwGk1MQxIqODRfbAQOPJ9NvBOBix90P JccPySBsG0oE40s8yz2cHQgTgrPgFPg6bhDl53R00C/8qxsgeU4bFa6P5Vu+rN9a1rLBzv8eW8RX5 yfSIuZOw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESad-00000007dTR-0sY2; Fri, 22 Nov 2024 12:16:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id F185C30221D; Fri, 22 Nov 2024 13:16:46 +0100 (CET) Message-Id: <20241122121556.172693402@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:22 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 6/9] objtool: Convert ANNOTATE_IGNORE_ALTERNATIVE to ANNOTATE References: <20241122121016.372005127@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) --- 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 @@ -55,11 +56,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 @@ -349,12 +346,7 @@ static inline int alternatives_text_rese * 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 @@ -1255,40 +1255,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. */ @@ -2341,6 +2307,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) @@ -2550,7 +2525,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 22:21:22 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 E0B201DE3A5 for ; Fri, 22 Nov 2024 12:16:50 +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=1732277812; cv=none; b=FTIS46eWPpTi8ZQMHJrn8TZENn4TjRtXWLdDZeiXg2hCFua2XwxZDxzbeq9nKPFMQ51BtmRZ6IE6cKdtZ06P2cbj66wFUKnVhujbgpPie4oqGGR77p4flD3gBg87FK74fafMVBQ0g59u6acc8IalxO3jf6elzuKhft6XNxJwbSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277812; c=relaxed/simple; bh=urQS2yElTEETyLW5CU+NAf/gKKL/T9AYgcHyh9xnDqE=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=aKrIa3l9R0XBl/8o+7UaakyLtUQfdhTwlnqudtxUXD7LMb+cx6PGfVGLcVkrmAdibRh6JMzto2ancK1Tqd93mw9COtzkOR2bK9p6rx1gP/wdXeKx0d9pgmgOP/AQrFINhAdJlogLljZD968ggjCGjnTuYUkD8ysXUqb0yvHvgZA= 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=h9QWmZAb; 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="h9QWmZAb" 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=v1B4si17lsJiu/eTcPxww45FJaJL5S2ZR+MPXXr7Od4=; b=h9QWmZAbIeT3t4zE8dsrFChqx3 nkooOCmbqlDGRz5eIIQ3w3Ax2DoosP0/nZtMGBvtHTgD3oGPGhzx4K/Ld3MSjQwDlWVstIeUtVt51 Ag0Qhifwr0ou1m29vCihtJXs5Vtm7Pr5HKnjE2qQttW26f3/nQUeMMt1Qr14ymDLiBdt4w19UTiGi 9kc3lrLtP4ZdlKzraR7+ejd96W47zeueBQrZ1+v6pnBvrIo05c85a1qYffkpHroL50Rfki/T1dYb8 wIWlX4FHkL3Sc5Gy4bp4qjiiAe+k4GuQAZRfPChNdcm6tMrDLhJoqxezZJQeUrJJv+ed9CkPgct6p Ca6ohGwQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESad-00000007dTS-0rUG; Fri, 22 Nov 2024 12:16:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 016FE302795; Fri, 22 Nov 2024 13:16:46 +0100 (CET) Message-Id: <20241122121556.315596549@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:23 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 7/9] objtool: Convert ANNOTATE_INTRA_FUNCTION_CALLS to ANNOTATE References: <20241122121016.372005127@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) --- 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 @@ -66,16 +66,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 @@ -152,6 +142,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 22:21:22 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 E0A851BC9ED for ; Fri, 22 Nov 2024 12:16:50 +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=1732277813; cv=none; b=IlCS9sW2MRc6Gc2Fm2y2u9wArZ99udfIXVYSoCxf7U5Vfe4/GADSN0RXUjSx8aE15YCH7nIn7CxfgGHVB0CGUNrO/vTPvm2KNuX60QjPyxaf0VliujWKMt1HNfM1QXNtDTyvNakApAZ4cEepdoET4Lujt0+71hQLKrcCDQkPHBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277813; c=relaxed/simple; bh=lwA0wdJRXuY7SHVj38Dd3BUpN2SRWnmL+R4sBJPinaI=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=eaCAgpFHObq7/641PiQlAdA9jxDJKaLc9RCgRo3HP4zFYXhj9viIXhUn/N4U2AGCSY3JwWYGDARef/wUFyCcernyQsN84E4mAE2C8P4xfcEGby7MvnSr7ffsgq+hyJSXPV0YukccVXU7L2R8JdDBpZsCcP0kE8dUbWxigKViM/I= 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=auNUiqDJ; 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="auNUiqDJ" 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=Qwvok3TZbwDxhY8xOhIpf0sVTqtWf/2n8qGfU0FRsjI=; b=auNUiqDJtsnD4lT6BYvWrAlovb u/xesgrAqoadRGXCqwtAyD8IVyjsmuXQ95RG68t3fYG4inqCI7Jf455rWlWsNUeeNn5P7W9SiN+97 tkaCRo3G9Mq8Lzwrw0IuuU3RlXhNKnh54biPY3VDmXt67+ZEmn5gUMbcPCRsdD2npg9l3GbLK2s/m fmie7CopxMdrJMQ7ke3HovOOlPFJjxM7KLnP5lcm4Z2naCC9fX/jv7To3BcanM99xNPZijGxEk/Zj WLXKC6r6DxFLICEn7eu2TnOZ4Y621ApKUsetKJJNQSnM5OqPRbXQuWLAqIHbfChxrwe+UnS9BjKqt NzCzkW1A==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESad-00000007dTT-0t2f; Fri, 22 Nov 2024 12:16:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 05358302DAF; Fri, 22 Nov 2024 13:16:47 +0100 (CET) Message-Id: <20241122121556.447242540@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:24 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 8/9] objtool: Collapse annotate sequences References: <20241122121016.372005127@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) Link: https://lkml.kernel.org/r/20241111125218.921110073@infradead.org --- tools/objtool/check.c | 87 ++++++++++++++++++---------------------------= ----- 1 file changed, 32 insertions(+), 55 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2308,21 +2308,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 @@ -2356,26 +2359,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; @@ -2384,6 +2382,10 @@ static int __annotate_instr(struct objto insn->instr--; break; =20 + case ANNOTYPE_UNRET_BEGIN: + insn->unret =3D 1; + break; + default: break; } @@ -2391,16 +2393,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. @@ -2507,14 +2499,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 @@ -2560,15 +2545,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 22:21:22 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 5C6451DE2DA for ; Fri, 22 Nov 2024 12:16:50 +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=1732277812; cv=none; b=hvbpRz8uGcQxazCWQyI2VxtgfR7hS744Cjtp/sWjJgjPE1rO9Nk/A4JlEfVIQKU1mclewwmTHGVEDCP7MEcGya5HiX0OcPu56hfop1EVy/cg0c9f5JEHAQQPWUUGzW7RmjfkSa/EytgRsUKszNLP0y/K4fob0Hl+PKhc35yMYlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732277812; c=relaxed/simple; bh=EhZ1VmUBU3oU2QwB906u37VFOFY9mXd6AAqr8QHO0/s=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=c5Mlip5n9cEInSke2AoIPWIdP/XiYBoC0Vef9VJ1x+dK0oOKdtb0cBeHFyJsqS7h05UtYUMOh1wJBuOvCS0H5SR1FZGJmLMH7n0Nj9hz2x0tKkJAd8/tkfu/oyUcY/uH6LCvehPB9VcRvKETtrFERolcA8EOYlLESzzEp7Q+hNM= 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=IYs9fu+P; 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="IYs9fu+P" 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=LpPe5pTofDOreIRlTEa7ME57/EzH98eTbxi5ud5+/n0=; b=IYs9fu+PLMEwChw1rd72VIUxej sft4FMEFTyFoEoaL3Ae1W8IWHWVoH2qzBWsG9jwryduC60tF+2lvnzjYtKXzp6nv4cKmDpex7ZiR3 WpZRADnPkN+VwGIagCcbfxJ5ZCQCCZX5sMaq8bOvx7PQwkLxLGgNSY1eTEtIGLrKt6plq7FcQIWPl kOjHeQvP5QX8+PYO5CHTVHGPkOFJFVOki9QJwZbYIGf+Cxo69mDvmaCTfg6Bh42RGxlGm6liJUpU4 1EzjOuYYdw/017kbwUZWWAVhmpN8pkwhyKJpAFHiF3pgLhYX/RLv9xfHvTCfkEwX/GhhmqopZsIFp Ma+tHP8w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tESae-00000000hax-2wLl; Fri, 22 Nov 2024 12:16:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 093FA302DC2; Fri, 22 Nov 2024 13:16:47 +0100 (CET) Message-Id: <20241122121556.560621502@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Nov 2024 13:10:25 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 9/9] objtool: Collect all annotations in objtool.h References: <20241122121016.372005127@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) --- arch/x86/include/asm/alternative.h | 12 ------------ arch/x86/include/asm/nospec-branch.h | 9 --------- include/linux/objtool.h | 30 +++++++++++++++++++++++------- 3 files changed, 23 insertions(+), 28 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/objtool.h +++ b/include/linux/objtool.h @@ -61,8 +61,6 @@ "911:\n\t" \ __ASM_ANNOTATE(911b, x) =20 -#define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) - #else /* __ASSEMBLY__ */ =20 /* @@ -140,8 +138,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. @@ -158,7 +154,6 @@ #define STACK_FRAME_NON_STANDARD(func) #define STACK_FRAME_NON_STANDARD_FP(func) #define ASM_ANNOTATE(x) -#define ANNOTATE_NOENDBR #define ASM_REACHABLE #else #define ANNOTATE_INTRA_FUNCTION_CALL @@ -166,8 +161,6 @@ .endm .macro STACK_FRAME_NON_STANDARD func:req .endm -.macro ANNOTATE_NOENDBR -.endm .macro REACHABLE .endm .macro ANNOTATE type:req @@ -176,4 +169,27 @@ =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) +/* + * objtool annotation to ignore the alternatives and only consider the ori= ginal + * instruction(s). + */ +#define ANNOTATE_IGNORE_ALTERNATIVE ASM_ANNOTATE(ANNOTYPE_IGNORE_ALTS) +#else +#define ANNOTATE_NOENDBR ANNOTATE type=3DANNOTYPE_NOENDBR +#define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=3DANNOTYPE_RETPOLINE_SAFE +#define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=3DANNOTYPE_IGNORE_ALTS +#endif + #endif /* _LINUX_OBJTOOL_H */