Skip to content

Commit 2d12c6f

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool: Remove ANNOTATE_IGNORE_ALTERNATIVE from CLAC/STAC
ANNOTATE_IGNORE_ALTERNATIVE adds additional noise to the code generated by CLAC/STAC alternatives, hurting readability for those whose read uaccess-related code generation on a regular basis. Remove the annotation specifically for the "NOP patched with CLAC/STAC" case in favor of a manual check. Leave the other uses of that annotation in place as they're less common and more difficult to detect. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/r/fc972ba4995d826fcfb8d02733a14be8d670900b.1744098446.git.jpoimboe@kernel.org
1 parent 2dbbca9 commit 2d12c6f

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

arch/x86/include/asm/smap.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616
#ifdef __ASSEMBLER__
1717

1818
#define ASM_CLAC \
19-
ALTERNATIVE __stringify(ANNOTATE_IGNORE_ALTERNATIVE), "clac", X86_FEATURE_SMAP
19+
ALTERNATIVE "", "clac", X86_FEATURE_SMAP
2020

2121
#define ASM_STAC \
22-
ALTERNATIVE __stringify(ANNOTATE_IGNORE_ALTERNATIVE), "stac", X86_FEATURE_SMAP
22+
ALTERNATIVE "", "stac", X86_FEATURE_SMAP
2323

2424
#else /* __ASSEMBLER__ */
2525

2626
static __always_inline void clac(void)
2727
{
2828
/* Note: a barrier is implicit in alternative() */
29-
alternative(ANNOTATE_IGNORE_ALTERNATIVE "", "clac", X86_FEATURE_SMAP);
29+
alternative("", "clac", X86_FEATURE_SMAP);
3030
}
3131

3232
static __always_inline void stac(void)
3333
{
3434
/* Note: a barrier is implicit in alternative() */
35-
alternative(ANNOTATE_IGNORE_ALTERNATIVE "", "stac", X86_FEATURE_SMAP);
35+
alternative("", "stac", X86_FEATURE_SMAP);
3636
}
3737

3838
static __always_inline unsigned long smap_save(void)
@@ -59,9 +59,9 @@ static __always_inline void smap_restore(unsigned long flags)
5959

6060
/* These macros can be used in asm() statements */
6161
#define ASM_CLAC \
62-
ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE "", "clac", X86_FEATURE_SMAP)
62+
ALTERNATIVE("", "clac", X86_FEATURE_SMAP)
6363
#define ASM_STAC \
64-
ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE "", "stac", X86_FEATURE_SMAP)
64+
ALTERNATIVE("", "stac", X86_FEATURE_SMAP)
6565

6666
#define ASM_CLAC_UNSAFE \
6767
ALTERNATIVE("", ANNOTATE_IGNORE_ALTERNATIVE "clac", X86_FEATURE_SMAP)

tools/objtool/check.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,34 @@ static struct instruction *next_insn_to_validate(struct objtool_file *file,
35053505
return next_insn_same_sec(file, alt_group->orig_group->last_insn);
35063506
}
35073507

3508+
static bool skip_alt_group(struct instruction *insn)
3509+
{
3510+
struct instruction *alt_insn = insn->alts ? insn->alts->insn : NULL;
3511+
3512+
/* ANNOTATE_IGNORE_ALTERNATIVE */
3513+
if (insn->alt_group && insn->alt_group->ignore)
3514+
return true;
3515+
3516+
/*
3517+
* For NOP patched with CLAC/STAC, only follow the latter to avoid
3518+
* impossible code paths combining patched CLAC with unpatched STAC
3519+
* or vice versa.
3520+
*
3521+
* ANNOTATE_IGNORE_ALTERNATIVE could have been used here, but Linus
3522+
* requested not to do that to avoid hurting .s file readability
3523+
* around CLAC/STAC alternative sites.
3524+
*/
3525+
3526+
if (!alt_insn)
3527+
return false;
3528+
3529+
/* Don't override ASM_{CLAC,STAC}_UNSAFE */
3530+
if (alt_insn->alt_group && alt_insn->alt_group->ignore)
3531+
return false;
3532+
3533+
return alt_insn->type == INSN_CLAC || alt_insn->type == INSN_STAC;
3534+
}
3535+
35083536
/*
35093537
* Follow the branch starting at the given instruction, and recursively follow
35103538
* any other branches (jumps). Meanwhile, track the frame pointer state at
@@ -3625,7 +3653,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
36253653
}
36263654
}
36273655

3628-
if (insn->alt_group && insn->alt_group->ignore)
3656+
if (skip_alt_group(insn))
36293657
return 0;
36303658

36313659
if (handle_insn_ops(insn, next_insn, &state))

0 commit comments

Comments
 (0)