From: "tip-bot2 for Dmitry Vyukov" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Dmitry Vyukov <dvyukov@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Alexander Potapenko <glider@google.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
stable@vger.kernel.org, x86@kernel.org,
linux-kernel@vger.kernel.org
Subject: [tip: x86/build] x86/entry: Remove unwanted instrumentation in common_interrupt()
Date: Thu, 08 Aug 2024 15:49:14 -0000 [thread overview]
Message-ID: <172313215486.2215.4344651204261650422.tip-bot2@tip-bot2> (raw)
In-Reply-To: <3f9a1de9e415fcb53d07dc9e19fa8481bb021b1b.1718092070.git.dvyukov@google.com>
The following commit has been merged into the x86/build branch of tip:
Commit-ID: 477d81a1c47a1b79b9c08fc92b5dea3c5143800b
Gitweb: https://git.kernel.org/tip/477d81a1c47a1b79b9c08fc92b5dea3c5143800b
Author: Dmitry Vyukov <dvyukov@google.com>
AuthorDate: Tue, 11 Jun 2024 09:50:30 +02:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 08 Aug 2024 17:36:35 +02:00
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: 6368558c3710 ("x86/entry: Provide IDTENTRY_SYSVEC")
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Alexander Potapenko <glider@google.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/3f9a1de9e415fcb53d07dc9e19fa8481bb021b1b.1718092070.git.dvyukov@google.com
---
arch/x86/include/asm/hardirq.h | 8 ++++++--
arch/x86/include/asm/idtentry.h | 6 +++---
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/hardirq.h b/arch/x86/include/asm/hardirq.h
index c67fa6a..6ffa8b7 100644
--- a/arch/x86/include/asm/hardirq.h
+++ b/arch/x86/include/asm/hardirq.h
@@ -69,7 +69,11 @@ extern u64 arch_irq_stat(void);
#define local_softirq_pending_ref pcpu_hot.softirq_pending
#if IS_ENABLED(CONFIG_KVM_INTEL)
-static inline void kvm_set_cpu_l1tf_flush_l1d(void)
+/*
+ * This function is called from noinstr interrupt contexts
+ * and must be inlined to not get instrumentation.
+ */
+static __always_inline void kvm_set_cpu_l1tf_flush_l1d(void)
{
__this_cpu_write(irq_stat.kvm_cpu_l1tf_flush_l1d, 1);
}
@@ -84,7 +88,7 @@ static __always_inline bool kvm_get_cpu_l1tf_flush_l1d(void)
return __this_cpu_read(irq_stat.kvm_cpu_l1tf_flush_l1d);
}
#else /* !IS_ENABLED(CONFIG_KVM_INTEL) */
-static inline void kvm_set_cpu_l1tf_flush_l1d(void) { }
+static __always_inline void kvm_set_cpu_l1tf_flush_l1d(void) { }
#endif /* IS_ENABLED(CONFIG_KVM_INTEL) */
#endif /* _ASM_X86_HARDIRQ_H */
diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h
index d4f2449..ad5c68f 100644
--- a/arch/x86/include/asm/idtentry.h
+++ b/arch/x86/include/asm/idtentry.h
@@ -212,8 +212,8 @@ __visible noinstr void func(struct pt_regs *regs, \
irqentry_state_t state = irqentry_enter(regs); \
u32 vector = (u32)(u8)error_code; \
\
+ kvm_set_cpu_l1tf_flush_l1d(); \
instrumentation_begin(); \
- kvm_set_cpu_l1tf_flush_l1d(); \
run_irq_on_irqstack_cond(__##func, regs, vector); \
instrumentation_end(); \
irqentry_exit(regs, state); \
@@ -250,7 +250,6 @@ static void __##func(struct pt_regs *regs); \
\
static __always_inline void instr_##func(struct pt_regs *regs) \
{ \
- kvm_set_cpu_l1tf_flush_l1d(); \
run_sysvec_on_irqstack_cond(__##func, regs); \
} \
\
@@ -258,6 +257,7 @@ __visible noinstr void func(struct pt_regs *regs) \
{ \
irqentry_state_t state = irqentry_enter(regs); \
\
+ kvm_set_cpu_l1tf_flush_l1d(); \
instrumentation_begin(); \
instr_##func (regs); \
instrumentation_end(); \
@@ -288,7 +288,6 @@ static __always_inline void __##func(struct pt_regs *regs); \
static __always_inline void instr_##func(struct pt_regs *regs) \
{ \
__irq_enter_raw(); \
- kvm_set_cpu_l1tf_flush_l1d(); \
__##func (regs); \
__irq_exit_raw(); \
} \
@@ -297,6 +296,7 @@ __visible noinstr void func(struct pt_regs *regs) \
{ \
irqentry_state_t state = irqentry_enter(regs); \
\
+ kvm_set_cpu_l1tf_flush_l1d(); \
instrumentation_begin(); \
instr_##func (regs); \
instrumentation_end(); \
next prev parent reply other threads:[~2024-08-08 15:49 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-11 7:50 [PATCH v2 0/4] KCOV fixes Dmitry Vyukov
2024-06-11 7:50 ` [PATCH v2 1/4] x86/entry: Remove unwanted instrumentation in common_interrupt() Dmitry Vyukov
2024-06-19 11:19 ` Peter Zijlstra
2024-06-19 13:05 ` Dmitry Vyukov
2024-08-08 15:49 ` tip-bot2 for Dmitry Vyukov [this message]
2024-06-11 7:50 ` [PATCH v2 2/4] kcov: add interrupt handling self test Dmitry Vyukov
2024-06-11 9:29 ` Marco Elver
2024-06-13 23:01 ` Andrey Konovalov
2024-06-19 11:13 ` Peter Zijlstra
2024-06-19 11:18 ` Dmitry Vyukov
2024-06-19 11:26 ` Peter Zijlstra
2024-08-08 15:49 ` [tip: x86/build] kcov: Add " tip-bot2 for Dmitry Vyukov
2024-06-11 7:50 ` [PATCH v2 3/4] module: Fix KCOV-ignored file name Dmitry Vyukov
2024-06-11 9:29 ` Marco Elver
2024-06-13 22:55 ` Andrey Konovalov
2024-08-08 15:49 ` [tip: x86/build] " tip-bot2 for Dmitry Vyukov
2024-06-11 7:50 ` [PATCH v2 4/4] x86: Ignore stack unwinding in KCOV Dmitry Vyukov
2024-06-13 22:51 ` Andrey Konovalov
2024-06-19 11:23 ` Peter Zijlstra
2024-06-19 13:10 ` Dmitry Vyukov
2024-08-08 15:49 ` [tip: x86/build] " tip-bot2 for Dmitry Vyukov
2024-06-11 9:31 ` [PATCH v2 0/4] KCOV fixes Dmitry Vyukov
2024-06-19 5:20 ` Dmitry Vyukov
2024-06-19 8:30 ` Borislav Petkov
2024-08-05 12:52 ` Andrey Konovalov
2024-08-08 15:18 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=172313215486.2215.4344651204261650422.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®