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>,
Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>,
Gavin Shan <gshan@redhat.com>, James Morse <james.morse@arm.com>
Subject: [PATCH 24/27] arm_mpam: prepare mon_sel locking for MPAM-Fb
Date: Fri, 2 Oct 2026 18:39:37 +0100 [thread overview]
Message-ID: <20261002173941.292319-25-james.morse@arm.com> (raw)
In-Reply-To: <20261002173941.292319-1-james.morse@arm.com>
From: Andre Przywara <andre.przywara@arm.com>
The MSC MON_SEL register needs to be accessed from hardirq for the overflow
interrupt, and when taking an IPI to access these registers on platforms
where MSCs are not accesible from every CPU. This makes an irqsave
spinlock the obvious lock to protect these registers. On systems with
MPAM-Fb mailbox MSC access it must be able to sleep, meaning a mutex must
be used. So MPAM-Fb platforms cannot support an overflow interrupt easily.
Clearly these two methods can't exist for one MSC at the same time.
Change the mon_sel locking wrapper function to only use a spinlock when
the MSC is accessed directly via MMIO. In case of MPAM-Fb, we use a
mutex, but only if we are in a sleepable context. If that's not the
case, we return an error. This should not happen, as MPAM-Fb by design
does not require an MSC access to happen from a specific CPU, so there
is no need for any IPIs or preemption disabling to satisfy CPU
constraints. And since overflow interrupts are not supported at the moment
anyway, we also wouldn't meet the other case.
Bailing out early is already happening in rare occasions today.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Gavin Shan <gshan@redhat.com> # on NVIDIA Grace Hopper
Signed-off-by: James Morse <james.morse@arm.com>
---
drivers/resctrl/mpam_devices.c | 6 ++++-
drivers/resctrl/mpam_internal.h | 43 +++++++++++++++++++++++++++------
2 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 31f4826ab399..2a0ac23cc042 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -2349,7 +2349,6 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)
if (err)
return ERR_PTR(err);
- mpam_mon_sel_lock_init(msc);
msc->id = pdev->id;
msc->pdev = pdev;
INIT_LIST_HEAD_RCU(&msc->all_msc_list);
@@ -2370,6 +2369,11 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)
else
msc->iface = MPAM_IFACE_PCC;
+ /* Lock type depends on MSC interface used */
+ err = mpam_mon_sel_lock_init(dev, msc);
+ if (err)
+ return ERR_PTR(err);
+
if (msc->iface == MPAM_IFACE_MMIO) {
void __iomem *io;
diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
index 09f8168fb4d2..58f7523bc087 100644
--- a/drivers/resctrl/mpam_internal.h
+++ b/drivers/resctrl/mpam_internal.h
@@ -126,6 +126,12 @@ struct mpam_msc {
*/
raw_spinlock_t _mon_sel_lock;
unsigned long _mon_sel_flags;
+ /*
+ * mon_sel_mutex is the mutex version of the _mon_sel_lock above.
+ * Always use the mpam_mon_sel_lock() helpers when taking the lock,
+ * as this will select the correct lock type automatically.
+ */
+ struct mutex mon_sel_mutex;
void __iomem *mapped_hwpage;
size_t mapped_hwpage_sz;
@@ -139,27 +145,50 @@ struct mpam_msc {
/* Returning false here means accesses to mon_sel must fail and report an error. */
static inline bool __must_check mpam_mon_sel_lock(struct mpam_msc *msc)
{
- /* Locking will require updating to support a firmware backed interface */
- if (WARN_ON_ONCE(msc->iface != MPAM_IFACE_MMIO))
+ if (msc->iface == MPAM_IFACE_MMIO) {
+ raw_spin_lock_irqsave(&msc->_mon_sel_lock, msc->_mon_sel_flags);
+
+ return true;
+ }
+
+ if (!preemptible())
return false;
- raw_spin_lock_irqsave(&msc->_mon_sel_lock, msc->_mon_sel_flags);
+ mutex_lock(&msc->mon_sel_mutex);
+
return true;
}
static inline void mpam_mon_sel_unlock(struct mpam_msc *msc)
{
- raw_spin_unlock_irqrestore(&msc->_mon_sel_lock, msc->_mon_sel_flags);
+ if (msc->iface == MPAM_IFACE_MMIO) {
+ raw_spin_unlock_irqrestore(&msc->_mon_sel_lock,
+ msc->_mon_sel_flags);
+
+ return;
+ }
+
+ mutex_unlock(&msc->mon_sel_mutex);
}
static inline void mpam_mon_sel_lock_held(struct mpam_msc *msc)
{
- lockdep_assert_held_once(&msc->_mon_sel_lock);
+ if (msc->iface == MPAM_IFACE_MMIO)
+ lockdep_assert_held_once(&msc->_mon_sel_lock);
+ else
+ lockdep_assert_held_once(&msc->mon_sel_mutex);
}
-static inline void mpam_mon_sel_lock_init(struct mpam_msc *msc)
+static inline int mpam_mon_sel_lock_init(struct device *dev,
+ struct mpam_msc *msc)
{
- raw_spin_lock_init(&msc->_mon_sel_lock);
+ if (msc->iface == MPAM_IFACE_MMIO) {
+ raw_spin_lock_init(&msc->_mon_sel_lock);
+
+ return 0;
+ }
+
+ return devm_mutex_init(dev, &msc->mon_sel_mutex);
}
DEFINE_GUARD(mon_sel, struct mpam_msc *,
--
2.53.0
next prev 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 ` James Morse [this message]
2026-10-02 17:39 ` [PATCH 25/27] arm_mpam: add MPAM-Fb MSC firmware access support James Morse
2026-10-02 17:39 ` [PATCH 26/27] arm_mpam: change MPAM-Fb error IRQ to use a threaded IRQ handler James Morse
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-25-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=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