Skip to content

Commit 477d81a

Browse files
dvyukovKAGA-KOKO
authored andcommitted
x86/entry: Remove unwanted instrumentation in common_interrupt()
common_interrupt() and related variants call kvm_set_cpu_l1tf_flush_l1d(), which is neither marked noinstr nor __always_inline. So compiler puts it out of line and adds instrumentation to it. Since the call is inside of instrumentation_begin/end(), objtool does not warn about it. The manifestation is that KCOV produces spurious coverage in kvm_set_cpu_l1tf_flush_l1d() in random places because the call happens when preempt count is not yet updated to say that the kernel is in an interrupt. Mark kvm_set_cpu_l1tf_flush_l1d() as __always_inline and move it out of the instrumentation_begin/end() section. It only calls __this_cpu_write() which is already safe to call in noinstr contexts. Fixes: 6368558 ("x86/entry: Provide IDTENTRY_SYSVEC") Signed-off-by: Dmitry Vyukov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Alexander Potapenko <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/all/3f9a1de9e415fcb53d07dc9e19fa8481bb021b1b.1718092070.git.dvyukov@google.com
1 parent de9c2c6 commit 477d81a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

arch/x86/include/asm/hardirq.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ extern u64 arch_irq_stat(void);
6969
#define local_softirq_pending_ref pcpu_hot.softirq_pending
7070

7171
#if IS_ENABLED(CONFIG_KVM_INTEL)
72-
static inline void kvm_set_cpu_l1tf_flush_l1d(void)
72+
/*
73+
* This function is called from noinstr interrupt contexts
74+
* and must be inlined to not get instrumentation.
75+
*/
76+
static __always_inline void kvm_set_cpu_l1tf_flush_l1d(void)
7377
{
7478
__this_cpu_write(irq_stat.kvm_cpu_l1tf_flush_l1d, 1);
7579
}
@@ -84,7 +88,7 @@ static __always_inline bool kvm_get_cpu_l1tf_flush_l1d(void)
8488
return __this_cpu_read(irq_stat.kvm_cpu_l1tf_flush_l1d);
8589
}
8690
#else /* !IS_ENABLED(CONFIG_KVM_INTEL) */
87-
static inline void kvm_set_cpu_l1tf_flush_l1d(void) { }
91+
static __always_inline void kvm_set_cpu_l1tf_flush_l1d(void) { }
8892
#endif /* IS_ENABLED(CONFIG_KVM_INTEL) */
8993

9094
#endif /* _ASM_X86_HARDIRQ_H */

arch/x86/include/asm/idtentry.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ __visible noinstr void func(struct pt_regs *regs, \
212212
irqentry_state_t state = irqentry_enter(regs); \
213213
u32 vector = (u32)(u8)error_code; \
214214
\
215+
kvm_set_cpu_l1tf_flush_l1d(); \
215216
instrumentation_begin(); \
216-
kvm_set_cpu_l1tf_flush_l1d(); \
217217
run_irq_on_irqstack_cond(__##func, regs, vector); \
218218
instrumentation_end(); \
219219
irqentry_exit(regs, state); \
@@ -250,14 +250,14 @@ static void __##func(struct pt_regs *regs); \
250250
\
251251
static __always_inline void instr_##func(struct pt_regs *regs) \
252252
{ \
253-
kvm_set_cpu_l1tf_flush_l1d(); \
254253
run_sysvec_on_irqstack_cond(__##func, regs); \
255254
} \
256255
\
257256
__visible noinstr void func(struct pt_regs *regs) \
258257
{ \
259258
irqentry_state_t state = irqentry_enter(regs); \
260259
\
260+
kvm_set_cpu_l1tf_flush_l1d(); \
261261
instrumentation_begin(); \
262262
instr_##func (regs); \
263263
instrumentation_end(); \
@@ -288,7 +288,6 @@ static __always_inline void __##func(struct pt_regs *regs); \
288288
static __always_inline void instr_##func(struct pt_regs *regs) \
289289
{ \
290290
__irq_enter_raw(); \
291-
kvm_set_cpu_l1tf_flush_l1d(); \
292291
__##func (regs); \
293292
__irq_exit_raw(); \
294293
} \
@@ -297,6 +296,7 @@ __visible noinstr void func(struct pt_regs *regs) \
297296
{ \
298297
irqentry_state_t state = irqentry_enter(regs); \
299298
\
299+
kvm_set_cpu_l1tf_flush_l1d(); \
300300
instrumentation_begin(); \
301301
instr_##func (regs); \
302302
instrumentation_end(); \

0 commit comments

Comments
 (0)