From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABFEA29D288 for ; Sun, 17 May 2026 20:02:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779048137; cv=none; b=FouPvK1/k9J+qcHQi+tQ6pwYuxgQAC5wWY/Ip15NY2HZ8zaytxU+r+q1PEnLgDLC0X1aVQeL2TCg51pL8AwkfTWVjQiZ+ZnOf+TZ3Ovqf/laO/RZoJ96/FMjmO1LHouSl2bc1CRv9BHkicPYzHscDgUGr/IMYFRbIflQqQ24nak= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779048137; c=relaxed/simple; bh=gw7quq6RgQdiMCX6/Y0QFC8a1e+wzw8pYP6Sses50AE=; h=Date:Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=R6r+j4LkC7KtfXrfICndBuoOR6ZTwBD4CJqYaPzFCXVAP8i7s8SWz3BNNPCydynoMboUI2G23Ba+1EbtlhmtKM6+HSL5opCftno2oL9I/4j3NLI+K7cFqIcMPgktyz+eX5dHbhpknLsL50i0ieUQRgF/gg4+/fXnkvI3sCIj38E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ISKZYd/7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ISKZYd/7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD8D1C2BCB0; Sun, 17 May 2026 20:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779048137; bh=gw7quq6RgQdiMCX6/Y0QFC8a1e+wzw8pYP6Sses50AE=; h=Date:From:To:Cc:Subject:References:From; b=ISKZYd/7NbwJTO9SPZlHgXYP7mIbZqUXrEHUQUo5Sc6ndeGSt+NXZSXOjTKsEOCrX lgS5ibSqyXdy06aP3xD8RR7PXFdwit0In5qiyDOyNNnfUsci5794RgPufkHlK1uUHN 4kTr3FjNvOOxcJwo8ZKKFxS6994C3Dj9sgCvBgfAKKvobz++wXFljN4ePWOT/gt1Ku 3XkK8NOin0UaGaAo2KBL9B5qNjmvdp9MyyFb802eowaz+5aVJ42O69EOO+wjh7ho6K umIQu3lSqh2oX/5Qw1b0Z2LLsLIfiYrGX22ZiCiKRIb5/21TMr5TxLjY5dsRQzLNjx 0vb3oHGe3DsXw== Date: Sun, 17 May 2026 22:02:14 +0200 Message-ID: <20260517194931.601972758@kernel.org> User-Agent: quilt/0.68 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Michael Kelley , Dmitry Ilvokhin , Radu Rendec , Jan Kiszka , Kieran Bingham , Florian Fainelli , Marc Zyngier Subject: [patch V6 09/16] genirq/manage: Make NMI cleanup RT safe References: <20260517194421.705253664@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: Thomas Gleixner Eventually blocking functions cannot be invoked with interrupts disabled and a raw spin lock held. Restructure the code so this happens outside of the descriptor lock held region. Signed-off-by: Thomas Gleixner Tested-by: Michael Kelley --- V4: New patch. Found when adding the validation update to it --- kernel/irq/manage.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -2026,24 +2026,30 @@ const void *free_irq(unsigned int irq, v } EXPORT_SYMBOL(free_irq); -/* This function must be called with desc->lock held */ static const void *__cleanup_nmi(unsigned int irq, struct irq_desc *desc) { + struct irqaction *action = NULL; const char *devname = NULL; - desc->istate &= ~IRQS_NMI; + scoped_guard(raw_spinlock_irqsave, &desc->lock) { + irq_nmi_teardown(desc); - if (!WARN_ON(desc->action == NULL)) { - irq_pm_remove_action(desc, desc->action); - devname = desc->action->name; - unregister_handler_proc(irq, desc->action); + desc->istate &= ~IRQS_NMI; - kfree(desc->action); + if (!WARN_ON(desc->action == NULL)) { + action = desc->action; + irq_pm_remove_action(desc, action); + devname = action->name; + } desc->action = NULL; + + irq_settings_clr_disable_unlazy(desc); + irq_shutdown_and_deactivate(desc); } - irq_settings_clr_disable_unlazy(desc); - irq_shutdown_and_deactivate(desc); + if (action) + unregister_handler_proc(irq, action); + kfree(action); irq_release_resources(desc); @@ -2067,8 +2073,6 @@ const void *free_nmi(unsigned int irq, v if (WARN_ON(desc->depth == 0)) disable_nmi_nosync(irq); - guard(raw_spinlock_irqsave)(&desc->lock); - irq_nmi_teardown(desc); return __cleanup_nmi(irq, desc); } @@ -2318,13 +2322,14 @@ int request_nmi(unsigned int irq, irq_ha /* Setup NMI state */ desc->istate |= IRQS_NMI; retval = irq_nmi_setup(desc); - if (retval) { - __cleanup_nmi(irq, desc); - return -EINVAL; - } - return 0; } + if (retval) { + __cleanup_nmi(irq, desc); + return -EINVAL; + } + return 0; + err_irq_setup: irq_chip_pm_put(&desc->irq_data); err_out: