diff mbox series

[v3,3/5] x86: track when in #MC context

Message ID 20200224104645.96381-4-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Roger Pau Monné Feb. 24, 2020, 10:46 a.m. UTC
Add helpers to track when executing in #MC context. This is modeled
after the in_irq helpers.

Note that there are no users of in_mc() introduced by the change,
further users will be added by followup changes.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v2:
 - Move definition of mc_count to x86 hardirq.h.
---
 xen/arch/x86/cpu/mcheck/mce.c | 2 ++
 xen/include/asm-x86/hardirq.h | 6 ++++++
 2 files changed, 8 insertions(+)

Comments

Jan Beulich Feb. 25, 2020, 5:06 p.m. UTC | #1
On 24.02.2020 11:46, Roger Pau Monne wrote:
> Add helpers to track when executing in #MC context. This is modeled
> after the in_irq helpers.

Same concern regarding the name as for NMI, i.e. perhaps
in_mce_handler() here. (Note also the added 'e', which I think
would make for slightly less in risk of becoming ambiguous
names.) It may be worthwhile also talking about the possible
(in theory) nesting here, as you do in the NMI patch
description. (In practice nesting of #MC is fatal, because of
the stack switch we request when the handler gets invoked.
But this is something that could be changed, so assuming here
that nesting is possible seems appropriate to me.)

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c
index d61e582af3..93ed5752ac 100644
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -93,7 +93,9 @@  void x86_mce_vector_register(x86_mce_vector_t hdlr)
 
 void do_machine_check(const struct cpu_user_regs *regs)
 {
+    mc_enter();
     _machine_check_vector(regs);
+    mc_exit();
 }
 
 /*
diff --git a/xen/include/asm-x86/hardirq.h b/xen/include/asm-x86/hardirq.h
index 6ccce75881..16dbe27de4 100644
--- a/xen/include/asm-x86/hardirq.h
+++ b/xen/include/asm-x86/hardirq.h
@@ -8,6 +8,7 @@  typedef struct {
 	unsigned int __softirq_pending;
 	unsigned int __local_irq_count;
 	unsigned int nmi_count;
+	unsigned int mc_count;
 	bool_t __mwait_wakeup;
 } __cacheline_aligned irq_cpustat_t;
 
@@ -23,6 +24,11 @@  typedef struct {
 #define nmi_enter()	(nmi_count(smp_processor_id())++)
 #define nmi_exit()	(nmi_count(smp_processor_id())--)
 
+#define mc_count(cpu)	__IRQ_STAT((cpu), mc_count)
+#define in_mc() 	(mc_count(smp_processor_id()) != 0)
+#define mc_enter()	(mc_count(smp_processor_id())++)
+#define mc_exit()	(mc_count(smp_processor_id())--)
+
 void ack_bad_irq(unsigned int irq);
 
 extern void apic_intr_init(void);