genirq/matrix: Prevent allocation counter corruption
authorVitaly Kuznetsov <vkuznets@redhat.com>
Fri, 19 Mar 2021 11:18:23 +0000 (12:18 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 May 2021 12:47:17 +0000 (14:47 +0200)
commitdf7452f03b7f27a2805e2a69129a18a5b104108e
tree2f515337d80a242826bc4d63983f8fa814c7fe3d
parentbde50f19ba241a06e6a37f8bf9db77e9ea1ef093
genirq/matrix: Prevent allocation counter corruption

[ Upstream commit c93a5e20c3c2dabef8ea360a3d3f18c6f68233ab ]

When irq_matrix_free() is called for an unallocated vector the
managed_allocated and total_allocated counters get out of sync with the
real state of the matrix. Later, when the last interrupt is freed, these
counters will underflow resulting in UINTMAX because the counters are
unsigned.

While this is certainly a problem of the calling code, this can be catched
in the allocator by checking the allocation bit for the to be freed vector
which simplifies debugging.

An example of the problem described above:
https://lore.kernel.org/lkml/20210318192819.636943062@linutronix.de/

Add the missing sanity check and emit a warning when it triggers.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20210319111823.1105248-1-vkuznets@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/irq/matrix.c