Module Name:    src
Committed By:   bouyer
Date:           Thu May 19 09:54:27 UTC 2022

Modified Files:
        src/sys/arch/xen/include: hypervisor.h
        src/sys/arch/xen/x86: hypervisor_machdep.c
        src/sys/arch/xen/xen: evtchn.c

Log Message:
Restore de EOI mechanism for pirq, using the newer hypervisor interface.
It is needed.
Hopefully fixes kern/56291, kern/56793, kern/55667


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/xen/xen/evtchn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.52 src/sys/arch/xen/include/hypervisor.h:1.53
--- src/sys/arch/xen/include/hypervisor.h:1.52	Sat May  2 16:44:36 2020
+++ src/sys/arch/xen/include/hypervisor.h	Thu May 19 09:54:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.52 2020/05/02 16:44:36 bouyer Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.53 2022/05/19 09:54:27 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -159,6 +159,10 @@ extern volatile struct xencons_interface
 struct intrframe;
 struct cpu_info;
 void do_hypervisor_callback(struct intrframe *regs);
+#if defined(XENPV) && (NPCI > 0 || NISA > 0)
+void hypervisor_prime_pirq_event(int, unsigned int);
+void hypervisor_ack_pirq_event(unsigned int);
+#endif /* XENPV && ( NPCI > 0 || NISA > 0 ) */
 
 extern int xen_version;
 #define XEN_MAJOR(x) (((x) & 0xffff0000) >> 16)

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.39 src/sys/arch/xen/x86/hypervisor_machdep.c:1.40
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.39	Sat May  2 16:44:36 2020
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Thu May 19 09:54:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.39 2020/05/02 16:44:36 bouyer Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.40 2022/05/19 09:54:27 bouyer Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.39 2020/05/02 16:44:36 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.40 2022/05/19 09:54:27 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -388,6 +388,9 @@ evt_enable_event(unsigned int port, unsi
 {
 	KASSERT(args == NULL);
 	hypervisor_unmask_event(port);
+#if defined(XENPV) && (NPCI > 0 || NISA > 0)
+	hypervisor_ack_pirq_event(port);
+#endif /* NPCI > 0 || NISA > 0 */
 }
 
 void

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.96 src/sys/arch/xen/xen/evtchn.c:1.97
--- src/sys/arch/xen/xen/evtchn.c:1.96	Sun Nov 15 14:01:06 2020
+++ src/sys/arch/xen/xen/evtchn.c	Thu May 19 09:54:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.96 2020/11/15 14:01:06 bouyer Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.97 2022/05/19 09:54:27 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.96 2020/11/15 14:01:06 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.97 2022/05/19 09:54:27 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -105,11 +105,13 @@ static int virq_timer_to_evtch[XEN_LEGAC
 static int virq_to_evtch[NR_VIRQS];
 
 
-#if NPCI > 0 || NISA > 0
+#if defined(XENPV) && (NPCI > 0 || NISA > 0)
 /* event-channel <-> PIRQ mapping */
 static int pirq_to_evtch[NR_PIRQS];
+/* PIRQ needing notify */
+static int evtch_to_pirq_eoi[NR_EVENT_CHANNELS];
 int pirq_interrupt(void *);
-#endif
+#endif /* defined(XENPV) && (NPCI > 0 || NISA > 0) */
 
 static void xen_evtchn_mask(struct pic *, int);
 static void xen_evtchn_unmask(struct pic *, int);
@@ -235,11 +237,13 @@ events_default_setup(void)
 	for (i = 0; i < NR_VIRQS; i++)
 		virq_to_evtch[i] = -1;
 
-#if NPCI > 0 || NISA > 0
+#if defined(XENPV) && (NPCI > 0 || NISA > 0)
 	/* No PIRQ -> event mappings. */
 	for (i = 0; i < NR_PIRQS; i++)
 		pirq_to_evtch[i] = -1;
-#endif
+	for (i = 0; i < NR_EVENT_CHANNELS; i++)
+		evtch_to_pirq_eoi[i] = -1;
+#endif /* defined(XENPV) && (NPCI > 0 || NISA > 0) */
 
 	/* No event-channel are 'live' right now. */
 	for (i = 0; i < NR_EVENT_CHANNELS; i++) {
@@ -388,6 +392,9 @@ evtchn_do_event(int evtch, struct intrfr
 	}
 	x86_disable_intr();
 	hypervisor_unmask_event(evtch);
+#if defined(XENPV) && (NPCI > 0 || NISA > 0)
+	hypervisor_ack_pirq_event(evtch);
+#endif /* defined(XENPV) && (NPCI > 0 || NISA > 0) */
 
 splx:
 	ci->ci_ilevel = ilevel;
@@ -621,7 +628,7 @@ unbind_virq_from_evtch(int virq)
 	return evtchn;
 }
 
-#if NPCI > 0 || NISA > 0
+#if defined(XENPV) && (NPCI > 0 || NISA > 0) 
 int
 get_pirq_to_evtch(int pirq)
 {
@@ -725,7 +732,9 @@ pirq_establish(int pirq, int evtch, int 
 		return NULL;
 	}
 
+	hypervisor_prime_pirq_event(pirq, evtch);
 	hypervisor_unmask_event(evtch);
+	hypervisor_ack_pirq_event(evtch);
 	return ih;
 }
 
@@ -754,7 +763,7 @@ pirq_interrupt(void *arg)
 	return ret;
 }
 
-#endif /* NPCI > 0 || NISA > 0 */
+#endif /* defined(XENPV) && (NPCI > 0 || NISA > 0) */
 
 
 /*
@@ -1067,6 +1076,42 @@ event_remove_handler(int evtch, int (*fu
 	return 0;
 }
 
+#if defined(XENPV) && (NPCI > 0 || NISA > 0)
+void
+hypervisor_prime_pirq_event(int pirq, unsigned int evtch)
+{
+	struct physdev_irq_status_query irq_status;
+	irq_status.irq = pirq;
+	if (HYPERVISOR_physdev_op(PHYSDEVOP_irq_status_query, &irq_status) < 0)
+		panic("HYPERVISOR_physdev_op(PHYSDEVOP_IRQ_STATUS_QUERY)");
+	if (irq_status.flags & XENIRQSTAT_needs_eoi) {
+		evtch_to_pirq_eoi[evtch] = pirq;
+#ifdef IRQ_DEBUG
+		printf("pirq %d needs notify\n", pirq);
+#endif
+	}
+}
+
+void
+hypervisor_ack_pirq_event(unsigned int evtch)
+{
+#ifdef IRQ_DEBUG
+	if (evtch == IRQ_DEBUG)
+		printf("%s: evtch %d\n", __func__, evtch);
+#endif
+
+	if (evtch_to_pirq_eoi[evtch] > 0) {
+		struct physdev_eoi eoi;
+		eoi.irq = evtch_to_pirq_eoi[evtch];
+#ifdef  IRQ_DEBUG
+		if (evtch == IRQ_DEBUG)
+		    printf("pirq_notify(%d)\n", evtch);
+#endif
+		(void)HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi);
+	}
+}
+#endif /* defined(XENPV) && (NPCI > 0 || NISA > 0) */
+
 int
 xen_debug_handler(void *arg)
 {

Reply via email to