Commit 882a0db9 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Thomas Gleixner

objtool: Improve UACCESS coverage

A clang build reported an (obvious) double CLAC while a GCC build did not;
it turns out that objtool only re-visits instructions if the first visit
was with AC=0. If OTOH the first visit was with AC=1, it completely ignores
any subsequent visit, even when it has AC=0.

Fix this by using a visited mask instead of a boolean, and (explicitly)
mark the AC state.

$ ./objtool check -b --no-fp --retpoline --uaccess drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x22: redundant UACCESS disable
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool:   eb_copy_relocations.isra.34()+0xea: (alt)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool:   .altinstr_replacement+0xffffffffffffffff: (branch)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool:   eb_copy_relocations.isra.34()+0xd9: (alt)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool:   eb_copy_relocations.isra.34()+0xb2: (branch)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool:   eb_copy_relocations.isra.34()+0x39: (branch)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool:   eb_copy_relocations.isra.34()+0x0: <=== (func)
Reported-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Reported-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reported-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarNathan Chancellor <natechancellor@gmail.com>
Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Tested-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
Link: https://github.com/ClangBuiltLinux/linux/issues/617
Link: https://lkml.kernel.org/r/5359166aad2d53f3145cd442d83d0e5115e0cd17.1564007838.git.jpoimboe@redhat.com
parent b68b9907
...@@ -1946,6 +1946,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, ...@@ -1946,6 +1946,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
struct alternative *alt; struct alternative *alt;
struct instruction *insn, *next_insn; struct instruction *insn, *next_insn;
struct section *sec; struct section *sec;
u8 visited;
int ret; int ret;
insn = first; insn = first;
...@@ -1972,12 +1973,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, ...@@ -1972,12 +1973,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
return 1; return 1;
} }
visited = 1 << state.uaccess;
if (insn->visited) { if (insn->visited) {
if (!insn->hint && !insn_state_match(insn, &state)) if (!insn->hint && !insn_state_match(insn, &state))
return 1; return 1;
/* If we were here with AC=0, but now have AC=1, go again */ if (insn->visited & visited)
if (insn->state.uaccess || !state.uaccess)
return 0; return 0;
} }
...@@ -2024,7 +2025,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, ...@@ -2024,7 +2025,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
} else } else
insn->state = state; insn->state = state;
insn->visited = true; insn->visited |= visited;
if (!insn->ignore_alts) { if (!insn->ignore_alts) {
bool skip_orig = false; bool skip_orig = false;
......
...@@ -33,8 +33,9 @@ struct instruction { ...@@ -33,8 +33,9 @@ struct instruction {
unsigned int len; unsigned int len;
enum insn_type type; enum insn_type type;
unsigned long immediate; unsigned long immediate;
bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; bool alt_group, dead_end, ignore, hint, save, restore, ignore_alts;
bool retpoline_safe; bool retpoline_safe;
u8 visited;
struct symbol *call_dest; struct symbol *call_dest;
struct instruction *jump_dest; struct instruction *jump_dest;
struct instruction *first_jump_src; struct instruction *first_jump_src;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment