Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: James Morse <james.morse@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Ben Horgan <ben.horgan@arm.com>,
	Andre Przywara <andre.przywara@arm.com>,
	Fuad Tabba <fuad.tabba@linux.dev>, Gavin Shan <gshan@redhat.com>,
	Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>,
	Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>,
	James Morse <james.morse@arm.com>
Subject: [PATCH 26/27] arm_mpam: change MPAM-Fb error IRQ to use a threaded IRQ handler
Date: Fri,  2 Oct 2026 18:39:39 +0100	[thread overview]
Message-ID: <20261002173941.292319-27-james.morse@arm.com> (raw)
In-Reply-To: <20261002173941.292319-1-james.morse@arm.com>

From: Andre Przywara <andre.przywara@arm.com>

When an MPAM MSC gets into an error condition, it can trigger an error
IRQ. We cannot really do much about those errors, but we at least query
and log the error, then disable MPAM functionality.

This error report relies on reading the MSC's error status register
(ESR) in the current hard-IRQ handler, which is not possible for MPAM-Fb
based MSC accesses, since they involve mailbox routines that might sleep.
The same is true for clearing the interrupt at the source, which requires
a (potentially sleeping) MSC access as well.

Change the error IRQ handler to be a threaded interrupt, but keep the
handling in the hard-IRQ part for MMIO MSCs. This is needed since the
CPU affinity check in the MSC accessors requires a non-preemptible
context.
When the MSC is using an MPAM-Fb based access, we push the work into the
threaded part of the handler, where the accessors are allowed to sleep.
Also forbid per-CPU interrupts (PPIs) for MPAM-Fb, as we cannot use a
threaded IRQ here.

The actual IRQ handler learns how to deal with errors. We cannot really
handle them, but we can try our best to disable the IRQ anyway.
Should the level IRQ line deactivation fail on the device side, we mask
the IRQ on the irqchip level, to prevent an interrupt storm.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
---
 drivers/resctrl/mpam_devices.c | 77 ++++++++++++++++++++++++++++------
 1 file changed, 65 insertions(+), 12 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 89706106e890..95caa151b27a 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -2767,24 +2767,42 @@ static char *mpam_errcode_names[16] = {
 	[12 ... 15] = "Reserved"
 };
 
+/*
+ * This will run as the threaded IRQ handler part when using MPAM-Fb, but
+ * as the sole hard-IRQ handler for MMIO based accesses.
+ */
 static irqreturn_t __mpam_irq_handler(int irq, struct mpam_msc *msc)
 {
 	u64 reg;
+	int ret;
 	u16 partid;
 	u8 errcode, pmg, ris;
 
-	if (WARN_ON_ONCE(!msc) ||
+	if (WARN_ON_ONCE(!msc))
+		return IRQ_NONE;
+
+	if (msc->iface == MPAM_IFACE_MMIO &&
 	    WARN_ON_ONCE(!cpumask_test_cpu(smp_processor_id(),
 					   &msc->accessibility)))
 		return IRQ_NONE;
 
-	mpam_msc_read_esr(msc, &reg);
+	ret = mpam_msc_read_esr(msc, &reg);
+	if (ret) {
+		pr_err_ratelimited("unknown error irq from msc:%u\n", msc->id);
+
+		/* Try out best here ... */
+		goto out_disable;
+	}
 
 	errcode = FIELD_GET(MPAMF_ESR_ERRCODE, reg);
 	if (!errcode)
 		return IRQ_NONE;
 
-	/* Clear level triggered irq */
+	/*
+	 * Clear the level triggered IRQ. If that fails, we cannot do anything
+	 * about it, so ignore any errors. We will disable the IRQ either on
+	 * the device side or on the irqchip level next anyway.
+	 */
 	mpam_msc_clear_esr(msc);
 
 	partid = FIELD_GET(MPAMF_ESR_PARTID_MON, reg);
@@ -2795,16 +2813,24 @@ static irqreturn_t __mpam_irq_handler(int irq, struct mpam_msc *msc)
 			   msc->id, mpam_errcode_names[errcode], partid, pmg,
 			   ris);
 
-	/* Disable this interrupt. */
-	mpam_disable_msc_ecr(msc);
+out_disable:
+	/*
+	 * Disable this interrupt on the device side. If that fails, disable
+	 * the IRQ on the irqchip level, as we must prevent further handler
+	 * invocations. We only take the interrupt once anyway, as we
+	 * are going to free the IRQ next, in mpam_disable().
+	 */
+	ret = mpam_disable_msc_ecr(msc);
+	if (ret)
+		disable_irq_nosync(irq);
 
-	/* Are we racing with the thread disabling MPAM? */
+	/* Check whether we are racing with the thread disabling MPAM. */
 	if (!mpam_is_enabled())
 		return IRQ_HANDLED;
 
 	/*
-	 * Schedule the teardown work. Don't use a threaded IRQ as we can't
-	 * unregister the interrupt from the threaded part of the handler.
+	 * Schedule the teardown work. We have to defer it as we can't
+	 * unregister the interrupt from the threaded part of a handler.
 	 */
 	mpam_disable_reason = "hardware error interrupt";
 	schedule_work(&mpam_broken_work);
@@ -2819,10 +2845,30 @@ static irqreturn_t mpam_ppi_handler(int irq, void *dev_id)
 	return __mpam_irq_handler(irq, msc);
 }
 
-static irqreturn_t mpam_spi_handler(int irq, void *dev_id)
+/*
+ * MMIO based MSC accesses must run in non-preemptible context, as they
+ * might have affinity requirements to check.
+ * MPAM-Fb based MSC accesses must NOT run in hard-IRQ context, as they
+ * can sleep.
+ * So split the IRQ handling up, depending on the MSC access type.
+ */
+static irqreturn_t mpam_shared_hard_irq(int irq, void *dev_id)
 {
 	struct mpam_msc *msc = dev_id;
 
+	if (msc->iface == MPAM_IFACE_MMIO)
+		return __mpam_irq_handler(irq, msc);
+
+	return IRQ_WAKE_THREAD;
+}
+
+static irqreturn_t mpam_shared_thread_irq(int irq, void *dev_id)
+{
+	struct mpam_msc *msc = dev_id;
+
+	if (msc->iface == MPAM_IFACE_MMIO)
+		return IRQ_HANDLED;
+
 	return __mpam_irq_handler(irq, msc);
 }
 
@@ -2843,6 +2889,11 @@ static int mpam_register_irqs(void)
 		/* The MPAM spec says the interrupt can be SPI, PPI or LPI */
 		/* We anticipate sharing the interrupt with other MSCs */
 		if (irq_is_percpu(irq)) {
+			if (msc->iface != MPAM_IFACE_MMIO) {
+				dev_err(&msc->pdev->dev,
+					"Only MMIO MSCs can use per-CPU interrupts\n");
+				return -EINVAL;
+			}
 			err = request_percpu_irq(irq, &mpam_ppi_handler,
 						 "mpam:msc:error",
 						 msc->error_dev_id);
@@ -2854,9 +2905,11 @@ static int mpam_register_irqs(void)
 					       &_enable_percpu_irq, &irq,
 					       true);
 		} else {
-			err = devm_request_irq(&msc->pdev->dev, irq,
-					       &mpam_spi_handler, IRQF_SHARED,
-					       "mpam:msc:error", msc);
+			err = devm_request_threaded_irq(&msc->pdev->dev, irq,
+							&mpam_shared_hard_irq,
+							&mpam_shared_thread_irq,
+							IRQF_SHARED | IRQF_ONESHOT,
+							"mpam:msc:error", msc);
 			if (err)
 				return err;
 		}
-- 
2.53.0



  parent reply	other threads:[~2026-10-02 17:41 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 17:39 [GIT PULL/PATCH 00/27] MPAM driver changes for v7.4 James Morse
2026-10-02 17:39 ` [PATCH 01/27] arm_mpam: Move MPAMF_ECR write helpers to allow reuse James Morse
2026-10-02 17:39 ` [PATCH 02/27] arm_mpam: Restore the error interrupt enable from mpam_cpu_online() James Morse
2026-10-02 17:39 ` [PATCH 03/27] arm_mpam: Set mpam_feat_msmon_mbwu_31counter when there are bandwidth counters James Morse
2026-10-02 17:39 ` [PATCH 04/27] arm_mpam: Add missing mon_sel locking in MBWU save and restore James Morse
2026-10-02 17:39 ` [PATCH 05/27] arm_mpam: Ensure MBWU counters are reset on restore James Morse
2026-10-02 17:39 ` [PATCH 06/27] arm_mpam: Use __ris_msmon_read() for saving MBWU state James Morse
2026-10-02 18:52   ` Ben Horgan
2026-10-02 18:54     ` Catalin Marinas
2026-10-02 17:39 ` [PATCH 07/27] arm_mpam: Initialize all of struct mon_read in mpam_restore_mbwu_state() James Morse
2026-10-02 17:39 ` [PATCH 08/27] arm_mpam: resctrl: Correct check that existing class is L3 James Morse
2026-10-02 17:39 ` [PATCH 09/27] arm_mpam: resctrl: Make read_mon_cdp_safe() self consistent James Morse
2026-10-02 17:39 ` [PATCH 10/27] arm_mpam: Don't loop forever if there is the maximum possible amount of PARTIDs James Morse
2026-10-02 17:39 ` [PATCH 11/27] arm_mpam: Switch to kvzmalloc_objs() for allocation of component cfg James Morse
2026-10-02 17:39 ` [PATCH 12/27] arm_mpam: resctrl: Don't stop early when tearing down a class James Morse
2026-10-02 17:39 ` [PATCH 13/27] MAINTAINERS: Add mpam.rst to the MPAM DRIVER entry James Morse
2026-10-02 17:39 ` [PATCH 15/27] arm_mpam: let low level MSC accessors return an error James Morse
2026-10-02 17:39 ` [PATCH 16/27] arm_mpam: propagate MSC access errors for hw_probe functions James Morse
2026-10-02 17:39 ` [PATCH 17/27] arm_mpam: propagate MSC access errors for MBWU counters James Morse
2026-10-02 17:39 ` [PATCH 18/27] arm_mpam: propagate MSC access errors for msmon helpers James Morse
2026-10-02 17:39 ` [PATCH 19/27] arm_mpam: propagate MSC access errors for __ris_msmon_read() James Morse
2026-10-02 17:39 ` [PATCH 20/27] arm_mpam: propagate MSC access errors for state saving function James Morse
2026-10-02 17:39 ` [PATCH 21/27] arm_mpam: propagate MSC access errors for mpam_reprogram_ris_partid() James Morse
2026-10-02 17:39 ` [PATCH 22/27] arm_mpam: propagate MSC access errors for interrupt control James Morse
2026-10-02 17:39 ` [PATCH 23/27] arm_mpam: propagate MSC access errors in mpam_reset_class_locked() James Morse
2026-10-02 17:39 ` [PATCH 24/27] arm_mpam: prepare mon_sel locking for MPAM-Fb James Morse
2026-10-02 17:39 ` [PATCH 25/27] arm_mpam: add MPAM-Fb MSC firmware access support James Morse
2026-10-02 17:39 ` James Morse [this message]
2026-10-02 17:39 ` [PATCH 27/27] arm_mpam: detect and enable MPAM-Fb PCC support James Morse
2026-10-02 19:02 ` [GIT PULL/PATCH 00/27] MPAM driver changes for v7.4 Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261002173941.292319-27-james.morse@arm.com \
    --to=james.morse@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=ben.horgan@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=gshan@redhat.com \
    --cc=jonathan.cameron@oss.qualcomm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=srivathsa.rao@oss.qualcomm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox