linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] genirq/matrix: Prevent managed_allocated/total_allocated counters getting out-of-sync
@ 2021-03-19 11:18 Vitaly Kuznetsov
  2021-03-19 21:53 ` [tip: irq/core] genirq/matrix: Prevent allocation counter corruption tip-bot2 for Vitaly Kuznetsov
  0 siblings, 1 reply; 2+ messages in thread
From: Vitaly Kuznetsov @ 2021-03-19 11:18 UTC (permalink / raw)
  To: Thomas Gleixner, x86
  Cc: Ingo Molnar, Borislav Petkov, H. Peter Anvin, linux-kernel

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@linutronix.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-19 21:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-19 11:18 [PATCH] genirq/matrix: Prevent managed_allocated/total_allocated counters getting out-of-sync Vitaly Kuznetsov
2021-03-19 21:53 ` [tip: irq/core] genirq/matrix: Prevent allocation counter corruption tip-bot2 for Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).