From: isaku.yamahata@intel.com
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com,
Michael Roth <michael.roth@amd.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
linux-coco@lists.linux.dev,
Chao Peng <chao.p.peng@linux.intel.com>
Subject: [PATCH 04/12] x86/mce: Move and export inject_mce() from inject.c to core.c
Date: Tue, 10 Oct 2023 01:35:12 -0700 [thread overview]
Message-ID: <a5109244e6ab4e9a03595a2a8daadd01d13ebc3f.1696926843.git.isaku.yamahata@intel.com> (raw)
In-Reply-To: <cover.1696926843.git.isaku.yamahata@intel.com>
From: Isaku Yamahata <isaku.yamahata@intel.com>
X86 MCE support is kernel builtin. CONFIG_X86_MCE=y or n. The x86 MCE
injection framework can be kernel builtin or kernel module.
CONFIG_X86_MCE_INJECT=y, m, or n. We don't want KVM depend on
CONFIG_X86_MCE_INJECT=y, allow CONFIG_X86_MCE_INJECT=m for KVM mce
injection.
Move the necessary symbols with rename from
arch/x86/kernel/cpu/mce/inject.c to arch/x86/kernel/cpu/mce/core.c and
export symbols for KVM to inject MCE.
Oppertunistically add lockdep_assert_held(&mce_inject_mutex) to show
that injectm is protected by mce_inject_mutex.
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
arch/x86/include/asm/mce.h | 10 +++++++++
arch/x86/kernel/cpu/mce/core.c | 36 ++++++++++++++++++++++++++++++++
arch/x86/kernel/cpu/mce/inject.c | 26 +++--------------------
3 files changed, 49 insertions(+), 23 deletions(-)
diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
index 180b1cbfcc4e..459066ecd922 100644
--- a/arch/x86/include/asm/mce.h
+++ b/arch/x86/include/asm/mce.h
@@ -265,6 +265,16 @@ int mce_notify_irq(void);
DECLARE_PER_CPU(struct mce, injectm);
+#ifdef CONFIG_X86_MCE
+void mce_inject_lock(void);
+void mce_inject_unlock(void);
+void mce_inject(struct mce *m);
+#else
+static inline void mce_inject_lock(void) {}
+static inline void mce_inject_unlock(void) {}
+static inline void mce_inject(struct mce *m) {}
+#endif
+
/* Disable CMCI/polling for MCA bank claimed by firmware */
extern void mce_disable_bank(int bank);
diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
index 6f35f724cc14..6929c3cad278 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -129,9 +129,45 @@ void mce_setup(struct mce *m)
m->ppin = cpu_data(m->extcpu).ppin;
m->microcode = boot_cpu_data.microcode;
}
+EXPORT_SYMBOL_GPL(mce_setup);
DEFINE_PER_CPU(struct mce, injectm);
EXPORT_PER_CPU_SYMBOL_GPL(injectm);
+static DEFINE_MUTEX(mce_inject_mutex);
+
+void mce_inject_lock(void)
+{
+ mutex_lock(&mce_inject_mutex);
+}
+EXPORT_SYMBOL_GPL(mce_inject_lock);
+
+void mce_inject_unlock(void)
+{
+ mutex_unlock(&mce_inject_mutex);
+}
+EXPORT_SYMBOL_GPL(mce_inject_unlock);
+
+/* Update fake mce registers on current CPU. */
+void mce_inject(struct mce *m)
+{
+ struct mce *i = &per_cpu(injectm, m->extcpu);
+
+ lockdep_assert_held(&mce_inject_mutex);
+
+ /* Make sure no one reads partially written injectm */
+ i->finished = 0;
+ mb();
+ m->finished = 0;
+ /* First set the fields after finished */
+ i->extcpu = m->extcpu;
+ mb();
+ /* Now write record in order, finished last (except above) */
+ memcpy(i, m, sizeof(struct mce));
+ /* Finally activate it */
+ mb();
+ i->finished = 1;
+}
+EXPORT_SYMBOL_GPL(mce_inject);
void mce_log(struct mce *m)
{
diff --git a/arch/x86/kernel/cpu/mce/inject.c b/arch/x86/kernel/cpu/mce/inject.c
index 88603a6c0afe..ae3efbeb78bd 100644
--- a/arch/x86/kernel/cpu/mce/inject.c
+++ b/arch/x86/kernel/cpu/mce/inject.c
@@ -126,25 +126,6 @@ static void setup_inj_struct(struct mce *m)
m->microcode = boot_cpu_data.microcode;
}
-/* Update fake mce registers on current CPU. */
-static void inject_mce(struct mce *m)
-{
- struct mce *i = &per_cpu(injectm, m->extcpu);
-
- /* Make sure no one reads partially written injectm */
- i->finished = 0;
- mb();
- m->finished = 0;
- /* First set the fields after finished */
- i->extcpu = m->extcpu;
- mb();
- /* Now write record in order, finished last (except above) */
- memcpy(i, m, sizeof(struct mce));
- /* Finally activate it */
- mb();
- i->finished = 1;
-}
-
static void raise_poll(struct mce *m)
{
unsigned long flags;
@@ -176,7 +157,6 @@ static void raise_exception(struct mce *m, struct pt_regs *pregs)
}
static cpumask_var_t mce_inject_cpumask;
-static DEFINE_MUTEX(mce_inject_mutex);
static int mce_raise_notify(unsigned int cmd, struct pt_regs *regs)
{
@@ -245,7 +225,7 @@ static void __maybe_unused raise_mce(struct mce *m)
{
int context = MCJ_CTX(m->inject_flags);
- inject_mce(m);
+ mce_inject(m);
if (context == MCJ_CTX_RANDOM)
return;
@@ -303,9 +283,9 @@ static int mce_inject_raise(struct notifier_block *nb, unsigned long val,
if (!m)
return NOTIFY_DONE;
- mutex_lock(&mce_inject_mutex);
+ mce_inject_lock();
raise_mce(m);
- mutex_unlock(&mce_inject_mutex);
+ mce_inject_unlock();
return NOTIFY_DONE;
}
--
2.25.1
next prev parent reply other threads:[~2023-10-10 8:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 8:35 [PATCH 00/12] x86/mce, KVM: X86: KVM memory poison and MCE injector support isaku.yamahata
2023-10-10 8:35 ` [PATCH 01/12] x86/mce: Fix hw MCE injection feature detection isaku.yamahata
2023-10-13 15:05 ` Dave Hansen
2023-10-10 8:35 ` [PATCH 02/12] X86/mce/inject: Add mcgstatus for mce-inject debugfs isaku.yamahata
2023-10-10 8:35 ` [PATCH 03/12] x86/mce/inject: Add notrigger entry to suppress MCE injection isaku.yamahata
2023-10-10 8:35 ` isaku.yamahata [this message]
2023-10-10 8:35 ` [PATCH 05/12] mm/fadvise: Add flags to inject hwpoison for posix_fadvise() isaku.yamahata
2023-10-10 8:35 ` [PATCH 06/12] mm/fadvise: Add FADV_MCE_INJECT flag " isaku.yamahata
2023-10-10 8:35 ` [PATCH 07/12] x86/mce/inject: Wire up the x86 MCE injector to FADV_MCE_INJECT isaku.yamahata
2023-10-10 8:35 ` [PATCH 08/12] x86/mce: Define a notifier chain for mce injector isaku.yamahata
2023-10-10 8:35 ` [PATCH 09/12] KVM: X86: Add debugfs to inject machine check on VM exit isaku.yamahata
2023-10-20 0:38 ` Sean Christopherson
2023-10-10 8:35 ` [PATCH 10/12] KVM: selftests: Allow mapping guest memory without host alias isaku.yamahata
2023-10-10 8:35 ` [PATCH 11/12] KVM: selftests: lib: Add src memory type for hwpoison test isaku.yamahata
2023-10-10 8:35 ` [PATCH 12/12] KVM: selftests: hwpoison/mce failure injection isaku.yamahata
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=a5109244e6ab4e9a03595a2a8daadd01d13ebc3f.1696926843.git.isaku.yamahata@intel.com \
--to=isaku.yamahata@intel.com \
--cc=chao.p.peng@linux.intel.com \
--cc=isaku.yamahata@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/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;
as well as URLs for NNTP newsgroup(s).