Skip to content

Commit 0d8ba24

Browse files
committed
Merge tag 'x86_bugs_retbleed' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull lockdep fix for x86 retbleed from Borislav Petkov: - Fix lockdep complaint for __static_call_fixup() * tag 'x86_bugs_retbleed' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/static_call: Serialize __static_call_fixup() properly
2 parents ce114c8 + c27c753 commit 0d8ba24

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

arch/x86/kernel/static_call.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ static const u8 xor5rax[] = { 0x2e, 0x2e, 0x2e, 0x31, 0xc0 };
2525

2626
static const u8 retinsn[] = { RET_INSN_OPCODE, 0xcc, 0xcc, 0xcc, 0xcc };
2727

28-
static void __ref __static_call_transform(void *insn, enum insn_type type, void *func)
28+
static void __ref __static_call_transform(void *insn, enum insn_type type,
29+
void *func, bool modinit)
2930
{
3031
const void *emulate = NULL;
3132
int size = CALL_INSN_SIZE;
@@ -60,7 +61,7 @@ static void __ref __static_call_transform(void *insn, enum insn_type type, void
6061
if (memcmp(insn, code, size) == 0)
6162
return;
6263

63-
if (unlikely(system_state == SYSTEM_BOOTING))
64+
if (system_state == SYSTEM_BOOTING || modinit)
6465
return text_poke_early(insn, code, size);
6566

6667
text_poke_bp(insn, code, size, emulate);
@@ -114,12 +115,12 @@ void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
114115

115116
if (tramp) {
116117
__static_call_validate(tramp, true, true);
117-
__static_call_transform(tramp, __sc_insn(!func, true), func);
118+
__static_call_transform(tramp, __sc_insn(!func, true), func, false);
118119
}
119120

120121
if (IS_ENABLED(CONFIG_HAVE_STATIC_CALL_INLINE) && site) {
121122
__static_call_validate(site, tail, false);
122-
__static_call_transform(site, __sc_insn(!func, tail), func);
123+
__static_call_transform(site, __sc_insn(!func, tail), func, false);
123124
}
124125

125126
mutex_unlock(&text_mutex);
@@ -145,8 +146,10 @@ bool __static_call_fixup(void *tramp, u8 op, void *dest)
145146
return false;
146147
}
147148

149+
mutex_lock(&text_mutex);
148150
if (op == RET_INSN_OPCODE || dest == &__x86_return_thunk)
149-
__static_call_transform(tramp, RET, NULL);
151+
__static_call_transform(tramp, RET, NULL, true);
152+
mutex_unlock(&text_mutex);
150153

151154
return true;
152155
}

0 commit comments

Comments
 (0)