diff mbox series

[RESEND,4/6] x86/traps: add external_interrupt() to dispatch external interrupts

Message ID 20221110061545.1531-5-xin3.li@intel.com (mailing list archive)
State New, archived
Headers show
Series x86/traps,VMX: implement software based NMI/IRQ dispatch for VMX NMI/IRQ reinjection | expand

Commit Message

Li, Xin3 Nov. 10, 2022, 6:15 a.m. UTC
Add external_interrupt() to dispatch external interrupts to their
handlers. If an external interrupt is a system interrupt, dipatch
it through system_interrupt_handler_table, otherwise call into
common_interrupt().

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li <xin3.li@intel.com>
---
 arch/x86/kernel/traps.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Sean Christopherson Nov. 10, 2022, 4:24 p.m. UTC | #1
On Wed, Nov 09, 2022, Xin Li wrote:
> +__visible noinstr void external_interrupt(struct pt_regs *regs,
> +					  unsigned int vector)
> +{
> +	unsigned int sysvec = vector - FIRST_SYSTEM_VECTOR;
> +
> +	BUG_ON(vector < FIRST_EXTERNAL_VECTOR);

Why not return an error up the stack?  KVM and/or CPU bugs aren't unheard of.
Dropping an IRQ obviously isn't ideal, but there's a non-zero chance that letting
KVM WARN and kill the VM will keep the host alive and thus other VMs running.  A
somewhat sophisticated setup might even react to the VM being killed by migrating
other VMs off the system and initiating host maintenance.
Li, Xin3 Nov. 10, 2022, 6:02 p.m. UTC | #2
> > +__visible noinstr void external_interrupt(struct pt_regs *regs,
> > +					  unsigned int vector)
> > +{
> > +	unsigned int sysvec = vector - FIRST_SYSTEM_VECTOR;
> > +
> > +	BUG_ON(vector < FIRST_EXTERNAL_VECTOR);
> 
> Why not return an error up the stack?  KVM and/or CPU bugs aren't unheard
> of.
> Dropping an IRQ obviously isn't ideal, but there's a non-zero chance that letting
> KVM WARN and kill the VM will keep the host alive and thus other VMs
> running.  A somewhat sophisticated setup might even react to the VM being
> killed by migrating other VMs off the system and initiating host maintenance.

Make sense.

What about having it return a signed integer?
Sean Christopherson Nov. 10, 2022, 8:10 p.m. UTC | #3
On Thu, Nov 10, 2022, Li, Xin3 wrote:
> > > +__visible noinstr void external_interrupt(struct pt_regs *regs,
> > > +					  unsigned int vector)
> > > +{
> > > +	unsigned int sysvec = vector - FIRST_SYSTEM_VECTOR;
> > > +
> > > +	BUG_ON(vector < FIRST_EXTERNAL_VECTOR);
> > 
> > Why not return an error up the stack?  KVM and/or CPU bugs aren't unheard
> > of.
> > Dropping an IRQ obviously isn't ideal, but there's a non-zero chance that letting
> > KVM WARN and kill the VM will keep the host alive and thus other VMs
> > running.  A somewhat sophisticated setup might even react to the VM being
> > killed by migrating other VMs off the system and initiating host maintenance.
> 
> Make sense.
> 
> What about having it return a signed integer?

Ya, the standard 0/-errno will do nicely.
diff mbox series

Patch

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 9c7826e588bc..c1eb3bd335ce 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -1507,6 +1507,27 @@  void __init install_system_interrupt_handler(unsigned int n, const void *asm_add
 	alloc_intr_gate(n, asm_addr);
 }
 
+/*
+ * External interrupt dispatch function.
+ *
+ * Until/unless common_interrupt() can be taught to deal with the
+ * special system vectors, split the dispatch.
+ *
+ * Note: common_interrupt() already deals with IRQ_MOVE_CLEANUP_VECTOR.
+ */
+__visible noinstr void external_interrupt(struct pt_regs *regs,
+					  unsigned int vector)
+{
+	unsigned int sysvec = vector - FIRST_SYSTEM_VECTOR;
+
+	BUG_ON(vector < FIRST_EXTERNAL_VECTOR);
+
+	if (sysvec < NR_SYSTEM_VECTORS)
+		return system_interrupt_handler_table[sysvec](regs, vector);
+
+	common_interrupt(regs, vector);
+}
+
 void __init trap_init(void)
 {
 	/* Init cpu_entry_area before IST entries are set up */