From 4b6a48f4ae220cbfe4b6e94b12412aeac3e50140 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Fri, 31 Jul 2020 22:26:20 +0200 Subject: [PATCH] kernel: Check interrupt vector isn't assigned to a CPU on free. If the vector is assigned to a CPU it means that the assignment structure is still referenced from the CPU side and must not be reset. This can happen when an interrupt vector is freed that still has a handler installed, i.e. when the order of removing the handler and freeing the vector is reversed. Change-Id: Ib2dc5fa8f95a28b36e8f150dc8f16236ca4b2275 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3113 Reviewed-by: waddlesplash --- src/system/kernel/int.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/system/kernel/int.cpp b/src/system/kernel/int.cpp index b34ba01c7f..e9e5a0c5fb 100644 --- a/src/system/kernel/int.cpp +++ b/src/system/kernel/int.cpp @@ -708,7 +708,15 @@ free_io_interrupt_vectors(long count, long startVector) startVector + i); } - sVectors[startVector + i].assigned_cpu = NULL; + io_vector& vector = sVectors[startVector + i]; + InterruptsSpinLocker vectorLocker(vector.vector_lock); + if (vector.assigned_cpu != NULL && vector.assigned_cpu->cpu != -1) { + panic("freeing io interrupt vector %ld that is still asigned to a " + "cpu", startVector + i); + continue; + } + + vector.assigned_cpu = NULL; sAllocatedIOInterruptVectors[startVector + i] = false; } }