[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210319111823.1105248-1-vkuznets@redhat.com>
Date: Fri, 19 Mar 2021 12:18:23 +0100
From: Vitaly Kuznetsov <vkuznets@...hat.com>
To: Thomas Gleixner <tglx@...utronix.de>, x86@...nel.org
Cc: Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org
Subject: [PATCH] genirq/matrix: Prevent managed_allocated/total_allocated counters getting out-of-sync
When irq_matrix_free() is called for an unallocated interrupt,
managed_allocated/total_allocated counters get out of sync with the real
state of the matrix. Later, when the last interrupt is freed, these
counters will go negative (overflow). While this is certainly a problem of
the calling code, we can do better in irq_matrix_free() and simplify
debugging.
An example of a problem described above:
https://lore.kernel.org/lkml/20210318192819.636943062@linutronix.de/
Suggested-by: Thomas Gleixner <tglx@...utronix.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@...hat.com>
---
kernel/irq/matrix.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c
index 651a4ad6d711..8e586858bcf4 100644
--- a/kernel/irq/matrix.c
+++ b/kernel/irq/matrix.c
@@ -423,7 +423,9 @@ void irq_matrix_free(struct irq_matrix *m, unsigned int cpu,
if (WARN_ON_ONCE(bit < m->alloc_start || bit >= m->alloc_end))
return;
- clear_bit(bit, cm->alloc_map);
+ if (WARN_ON_ONCE(!test_and_clear_bit(bit, cm->alloc_map)))
+ return;
+
cm->allocated--;
if(managed)
cm->managed_allocated--;
--
2.30.2
Powered by blists - more mailing lists