aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-01-12 16:35:58 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2021-06-05 15:03:18 +0000
commitfe7d7ac40881c9d01a54bf57fff71a3af199f237 (patch)
treeac6f7c0fd717c0cf8ef85a421720cdd745f13726
parentc6a311678d667cb1e7b5417edb6567b7f07d148d (diff)
downloadsrc-fe7d7ac40881c9d01a54bf57fff71a3af199f237.tar.gz
src-fe7d7ac40881c9d01a54bf57fff71a3af199f237.zip
hyperv: register intr handler as usermode-mapped if loaded as module
Normally raw interrupt handler is provided by the kernel text. But vmbus module registers its own handler that needs to be mapped into userspace mapping on PTI kernels. Reported and reviewed by: whu Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D30310
-rw-r--r--sys/dev/hyperv/vmbus/vmbus.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/sys/dev/hyperv/vmbus/vmbus.c b/sys/dev/hyperv/vmbus/vmbus.c
index d3568494405e..929eff33e7c9 100644
--- a/sys/dev/hyperv/vmbus/vmbus.c
+++ b/sys/dev/hyperv/vmbus/vmbus.c
@@ -45,6 +45,10 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/taskqueue.h>
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <vm/pmap.h>
+
#include <machine/bus.h>
#include <machine/intr_machdep.h>
#include <machine/metadata.h>
@@ -139,6 +143,7 @@ SYSCTL_INT(_hw_vmbus, OID_AUTO, pin_evttask, CTLFLAG_RDTUN,
&vmbus_pin_evttask, 0, "Pin event tasks to their respective CPU");
extern inthand_t IDTVEC(vmbus_isr), IDTVEC(vmbus_isr_pti);
+#define VMBUS_ISR_ADDR trunc_page((uintptr_t)IDTVEC(vmbus_isr_pti))
uint32_t vmbus_current_version;
@@ -980,6 +985,10 @@ vmbus_intr_setup(struct vmbus_softc *sc)
vmbus_msg_task, sc);
}
+#if defined(__amd64__) && defined(KLD_MODULE)
+ pmap_pti_add_kva(VMBUS_ISR_ADDR, VMBUS_ISR_ADDR + PAGE_SIZE, true);
+#endif
+
/*
* All Hyper-V ISR required resources are setup, now let's find a
* free IDT vector for Hyper-V ISR and set it up.
@@ -987,6 +996,9 @@ vmbus_intr_setup(struct vmbus_softc *sc)
sc->vmbus_idtvec = lapic_ipi_alloc(pti ? IDTVEC(vmbus_isr_pti) :
IDTVEC(vmbus_isr));
if (sc->vmbus_idtvec < 0) {
+#if defined(__amd64__) && defined(KLD_MODULE)
+ pmap_pti_remove_kva(VMBUS_ISR_ADDR, VMBUS_ISR_ADDR + PAGE_SIZE);
+#endif
device_printf(sc->vmbus_dev, "cannot find free IDT vector\n");
return ENXIO;
}
@@ -1007,6 +1019,10 @@ vmbus_intr_teardown(struct vmbus_softc *sc)
sc->vmbus_idtvec = -1;
}
+#if defined(__amd64__) && defined(KLD_MODULE)
+ pmap_pti_remove_kva(VMBUS_ISR_ADDR, VMBUS_ISR_ADDR + PAGE_SIZE);
+#endif
+
CPU_FOREACH(cpu) {
if (VMBUS_PCPU_GET(sc, event_tq, cpu) != NULL) {
taskqueue_free(VMBUS_PCPU_GET(sc, event_tq, cpu));