arm_mpam: Add MPAM-Fb firmware support
Subsystems (4)
v10 cover arm_mpam: Add MPAM-Fb firmware support
Hi,
as promised, this is an updated version of the MPAM-Fb code, for firmware based MSC accesses.
There are not many changes, the most prominent one is preparation for an update to the "ACPI for MPAM" specification (Arm DEN0065 [2]), which adds an MPAM-Fb offset field, to allow private IDs per PCC channel, but still maintain globally unique MSC IDs. The spec is not public yet, but I added two small patches on top that would implement the change. Also the msc struct gains a field to hold that per-PCC value. This allows to support systems with more than one MPAM-Fb manager (read: PCC channel).
Find the changelog below. Based on v7.3-rc1.
=======================
The Arm MPAM specification defines Memory System Components (MSCs), which are devices that are programmed through an MMIO register frame. In some occasions this turned out to be too limiting: the MSC might be located behind a separate bus system (for instance inside an on-board controller), it might be mapped secure-only, or in a different processor socket without direct MMIO mapping. Also the MMIO access might be too slow or it would need to be filtered or otherwise access controlled. Finally there might be bugs in the MSC integration, which require a mediating firmware to be accessible.
To accommodate all those different use cases, the MPAM-Fb specification
[1] describes an alternative way to access MSCs. Accesses to an MSC would be wrapped in a message and communicated to the system using a shared-memory/mailbox system mostly mimicking the Arm SCMI spec. For ACPI systems, this would be abstracted through an ACPI PCC channel, which provides the shared-memory region and the mailbox trigger. We can lean on existing ACPI parsing code to register with these two subsystems, but cannot rely on the existing SCMI code in the kernel. This means we somewhat need to open code a very simplified SCMI handler, which just provides enough functionality for the very basic subset of SCMI that the MPAM-Fb spec requires.
The first eight patches rework all MSC access wrappers to propagate error information. Pure MMIO based MSC accesses would never fail, but the MPAM-Fb access can go wrong in multiple ways. The patches have been split up purely for reviewing reasons, if the number is a problem, we could as well squash them. Please note that until the very last patch of this series any MSC accesses would always only return 0, it's only the final enablement of MPAM-Fb that could possibly introduce errors. Hence all former patches can add error handling gradually, those code paths wouldn't be triggered before patch 12/14.
Patch 9/14 solves a nasty problem: At the moment we protect stateful MSC register accesses (mon_sel) through a spinlock. Unfortunately the mailbox subsystem and the slow nature of the communication through this channel forbid MPAM-Fb access in atomic context. So this patch keeps using a spinlock for MMIO based accesses, but reverts to a mutex otherwise. We just deny taking the lock for MPAM-Fb in atomic context, ideally we wouldn't need that (no need to IPI another core when the MSC access does not need to be local to one particular core), or we simply deny that part of the functionality (access through perf).
Patch 10/14 adds the code to redirect MSC accesses through the PCC shmem/mailbox system.
Patch 11/14 reworks the error interrupt handler to use a threaded IRQ for MPAM-Fb, to be able to do MPAM-Fb MSC accesses inside (which might sleep). Patch 12/14 then adds the code to detect and store the PCC channel information from the ACPI tables, and eventually enables MPAM-Fb accesses.
The final two patches (marked as RFC) implement an "ACPI for MPAM" specification change, which introduces an MPAM-Fb Offset field, which holds the difference between the globally unique MSC IDs as stored in the "Identifier" field of the ACPI MSC node table, and the MSC ID to be used in the MPAM-Fb protocol. For a single MPAM-Fb manager/PCC channel, this is irrelevant, but multiple channels require that change.
This whole series would enable systems where some MSCs are not accessible via MMIO to use those components anyway.
Please have a look and test!
Cheers,
Andre
[1] https://developer.arm.com/documentation/den0144/latest
[2] https://support.arm.com/documentation/den0065/3-0/
Changes in v10:
- rebase on v7.3-rc1
- add tags
- (re-)introduce mpam_fb_msc_id field to allow per-PCC MSC IDs
- add patch to introduce mpam_fb_offset ACPI MSC node field
- add patch to adjust mpam_fb_msc_id if needed
- add mon_sel_mutex comment
- "select" missing KConfig symbols
Changes in v9:
- always create a threaded IRQ, but differ handling between PCC and MMIO
- drop dev ptr setting for shared mailbox client (leave at NULL)
- propagate errors from IRQ setup functions (incl. mpam_disable_msc_ecr)
- improve MPAM-Fb error reporting (drop snprintf call)
Changes in v8:
- disable error IRQ on irqchip level when device side fails
- use MSC dev pointer for dev_err() instead of mailbox one
- smaller white space and formatting fixes
- reorder MPAM-Fb definitions
- rename error translation function to mpam_fb_to_linux_errno()
- add review and test tags
Changes in v7:
- add tags
- add new patch to propagate errors in mpam_reprogram_ris_partid()
- prevent loop when mpam_diable() tries MSC accesses again
- register MMIO error IRQ handler without IRQF_ONESHOT
- re-use existing "err" variable instead of declaring "ret"
- initialise mon_sel_lock later, to wait for interface decision
- convert timeout units for nominal latency, between us and ms
Changes in v6:
- keep using hard IRQ handler for MMIO based accesses
- move shmem buffer size and MPAM-Fb version check into mpam_fb.c
- drop mutex guard in mpam_fb_send_request(), we use gotos anyway
- factor out MPAM-Fb protocol error translation
- add MPAM_FB_ERR_BUSY error code to translation
- explicitly report also MPAM-Fb protocol error number when disabling MPAM
- remove unneeded MPAM-Fb details from mpam_internal.h
- drop leftover mpam_fb_msc_id usage
Changes in v5:
- do not initialise _high variables early
- fix whitespace issues
- add Jonathan's Reviewed-by: tags
- init only either the spinlock OR the mutex for the mon_sel_lock
- drop warning about mapped_hwpage_sz for MPAM-Fb in mpam_msc_zero_mbwu_l()
- change IRQ handler to threaded handler, to allow MPAM-Fb MSC accesses
- disallow per-CPU IRQs (PPIs) for MPAM-Fb
- trigger MPAM disabling on MPAM-Fb protocol errors
- fix MPAM_PROTOCOL_VERSION_CMD name
- use PCC driver defined symbol for PCC_CHAN_FLAGS_IRQ
- add comment about usage of PCC's .signature field
- check for illegal MPAM-Fb command before sending request
- drop CPU accessibility check for MPAM-Fb based MSC accesses
- move MPAM-Fb protocol message structs inside build functions
- add comment about largest message size
- drop extra msc->mpam_fb_msc_id, in favour using pdev->id
- use already defined local dev variable instead of &pdev->dev
- use FIELD_GET() macro for MPAM-Fb protocol check
- drop devm_mutex_init() for pcc_chan_lock
Changes in v4:
- unify error check patterns
- use scoped_guard(mutex) and ACQUIRE to simplify error handling
- use struct kref for PCC channel refcount
- drop unused mailbox rx_callback function
- increase size of props[] array to hold new msc_id property
- set mailbox TX timeout based on ACPI MPAM table field
- use devm_mutex_init() to allow automatic cleanup
- avoid overwriting error value for arm,not-ready-us property read
- prune MPAM-Fb protocol token to fit into bitmask inside register
- check return value for AIDR read
- use two separate MPAM-Fb protocol payload structs
- prune header list for mpam_fb.c
- drop "nrdy handled as an error" change
- fix message size field in MPAM-Fb protocol shmem area
- drop message size return from MPAM-Fb message build functions
- bring back IRQ flag in MPAM-Fb protocol header
Changes in v3:
- drop inner/outer mon_sel lock patch, replace with simpler version
- harmonise code patterns in error propagation changes
- drop mon_sel lock before erroring out in mpam_ris_hw_probe_csu_nrdy()
- refactor mpam_msc_read_mbwu_l() to return an error
- drop special NRDY handling in __ris_msmon_read()
- add IRQ numbers in error interrupt handler to help pinpoint failure
- refactor MPAM-Fb message generation to accommodate more than read/write
- check MPAM-Fb protocol version at probe time
- drop mpam_fb.h header, merge into mpam_internal.h
- translate MPAM-Fb error code in Linux codes where needed
- clear IRQ flag bit in MPAM-Fb protocol header
- drop unneeded endianness conversions when crafting MPAM-Fb message
- use C struct to model MPAM-Fb message payload
Changes in v2:
- add patches to add error propagation to MSC access wrappers
- drop former patch 1/5 (not needed)
- drop lock in mpam_reprogram_msc(), to avoid double lock
- add support for multiple MSCs per PCC channel
- adjust SCMI protocol code to use a PCC subtype 3 channel
- let PCC code handle the PCC channel negotiation (due to subtype 3)
- drop SCMI names in shmem offsets, and use existing PCC type 3 struct
- adjust shmem field offsets to match MPAM-Fb spec, not pure SCMI
- prevent MPAM-Fb calls inside atomic smp_call_function_any() payload
- skip all MSC accesses inside the IRQ handler when using MPAM-Fb
Andre Przywara (14):
arm_mpam: let low level MSC accessors return an error
arm_mpam: propagate MSC access errors for hw_probe functions
arm_mpam: propagate MSC access errors for MBWU counters
arm_mpam: propagate MSC access errors for msmon helpers
arm_mpam: propagate MSC access errors for __ris_msmon_read()
arm_mpam: propagate MSC access errors for state saving function
arm_mpam: propagate MSC access errors for mpam_reprogram_ris_partid()
arm_mpam: propagate MSC access errors for interrupt control
arm_mpam: prepare mon_sel locking for MPAM-Fb
arm_mpam: add MPAM-Fb MSC firmware access support
arm_mpam: change MPAM-Fb error IRQ to use a threaded IRQ handler
arm_mpam: detect and enable MPAM-Fb PCC support
ACPICA: actbl2.h: MPAM: adapt to MPAM ACPI v3.1 changes
acpi: arm64: use MPAM-Fb offset field from ACPI table
drivers/acpi/arm64/mpam.c | 5 +- drivers/resctrl/Kconfig | 2 + drivers/resctrl/Makefile | 2 +- drivers/resctrl/mpam_devices.c | 891 ++++++++++++++++++++++++-------- drivers/resctrl/mpam_fb.c | 252 +++++++++ drivers/resctrl/mpam_internal.h | 68 ++- include/acpi/actbl2.h | 2 +- include/linux/arm_mpam.h | 2 +- 8 files changed, 985 insertions(+), 239 deletions(-) create mode 100644 drivers/resctrl/mpam_fb.c
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
Signature · 1 line
2.43.0
PATCH v10 1/14 arm_mpam: let low level MSC accessors return an error
The upcoming MPAM-Fb support does not use MMIO primitives to access an MSC, but employs a shared-memory/doorbell based firmware protocol. Its complexity means that it must be able to handle errors, whereas we always assume an MMIO based MSC access succeeds today.
Change the __mpam_read_reg() low level accessor function to return the requested data through a pointer, and return an error code instead. Also change the __mpam_write_reg() accessor function to return an error code. At the moment this is always 0, so all error handling paths are not exercised at the moment. This will change later when alternative MSC access methods like MPAM-Fb are activated.
Change all direct users of those MSC wrappers to comply with the new prototypes, though the errors are not propagated all the way up yet.
--- drivers/resctrl/mpam_devices.c | 208 +++++++++++++++++++++------------ 1 file changed, 134 insertions(+), 74 deletions(-)
drivers/resctrl/mpam_devices.c +134 -74
@@ -177,59 +177,68 @@ static void mpam_assert_partid_sizes_fixed(void)WARN_ON_ONCE (!partid_max_published); } -static u32 __mpam_read_reg (struct mpam_msc *msc,u16 reg) +static int __mpam_read_reg (struct mpam_msc *msc,u16 reg,u32 *res) {WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); -return readl_relaxed (msc->mapped_hwpage + reg); + *res =readl_relaxed (msc->mapped_hwpage + reg); + +return 0 ; } -static inline u32 _mpam_read_partsel_reg (struct mpam_msc *msc,u16 reg) +static inline int _mpam_read_partsel_reg (struct mpam_msc *msc,u16 reg, +u32 *res) {lockdep_assert_held_once (&msc->part_sel_lock); -return __mpam_read_reg (msc, reg); +return __mpam_read_reg (msc, reg, res); } -#define mpam_read_partsel_reg (msc, reg) _mpam_read_partsel_reg(msc, MPAMF_##reg) +#define mpam_read_partsel_reg (msc, reg, res) _mpam_read_partsel_reg(msc, MPAMF_##reg, res) -static void __mpam_write_reg (struct mpam_msc *msc,u16 reg,u32 val) +static int __mpam_write_reg (struct mpam_msc *msc,u16 reg,u32 val) {WARN_ON_ONCE (reg +sizeof (u32) > msc->mapped_hwpage_sz);WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility));writel_relaxed (val, msc->mapped_hwpage + reg); + +return 0 ; } -static inline void _mpam_write_partsel_reg (struct mpam_msc *msc,u16 reg,u32 val) +static inline int _mpam_write_partsel_reg (struct mpam_msc *msc,u16 reg,u32 val) {lockdep_assert_held_once (&msc->part_sel_lock); -__mpam_write_reg (msc, reg, val); +return __mpam_write_reg (msc, reg, val); }#define mpam_write_partsel_reg (msc, reg, val) _mpam_write_partsel_reg(msc, MPAMCFG_##reg, val) -static inline u32 _mpam_read_monsel_reg (struct mpam_msc *msc,u16 reg) +static inline int _mpam_read_monsel_reg (struct mpam_msc *msc,u16 reg, +u32 *res) {mpam_mon_sel_lock_held (msc); -return __mpam_read_reg (msc, reg); +return __mpam_read_reg (msc, reg, res); } -#define mpam_read_monsel_reg (msc, reg) _mpam_read_monsel_reg(msc, MSMON_##reg) +#define mpam_read_monsel_reg (msc, reg, res) _mpam_read_monsel_reg(msc, MSMON_##reg, res) -static inline void _mpam_write_monsel_reg (struct mpam_msc *msc,u16 reg,u32 val) +static inline int _mpam_write_monsel_reg (struct mpam_msc *msc,u16 reg,u32 val) {mpam_mon_sel_lock_held (msc); -__mpam_write_reg (msc, reg, val); +return __mpam_write_reg (msc, reg, val); }#define mpam_write_monsel_reg (msc, reg, val) _mpam_write_monsel_reg(msc, MSMON_##reg, val)static bool mpam_msc_check_aidr (struct mpam_msc *msc) { -u32 aidr =__mpam_read_reg (msc,MPAMF_AIDR ); -u32 major =FIELD_GET (MPAMF_AIDR_ARCH_MAJOR_REV , aidr); -u32 minor =FIELD_GET (MPAMF_AIDR_ARCH_MINOR_REV , aidr); +u32 aidr, major, minor; +if (__mpam_read_reg (msc,MPAMF_AIDR , &aidr)) +return false; + + major =FIELD_GET (MPAMF_AIDR_ARCH_MAJOR_REV , aidr); + minor =FIELD_GET (MPAMF_AIDR_ARCH_MINOR_REV , aidr);/* * v0.0 and >v2.x aren't supported, but anything else should be backward * compatible to v0.1 or v1.0.
@@ -242,25 +251,41 @@ static bool mpam_msc_check_aidr(struct mpam_msc *msc)return true; } -static u64 mpam_msc_read_idr (struct mpam_msc *msc) +static int mpam_msc_read_idr (struct mpam_msc *msc,u64 *res) { -u64 idr_high =0 , idr_low; +u32 idr_high, idr_low; +int ret;lockdep_assert_held (&msc->part_sel_lock); - idr_low =mpam_read_partsel_reg (msc,IDR ); -if (FIELD_GET (MPAMF_IDR_EXT , idr_low)) - idr_high =mpam_read_partsel_reg (msc,IDR +4 ); + ret =mpam_read_partsel_reg (msc,IDR , &idr_low); +if (ret) +return ret; + +if (FIELD_GET (MPAMF_IDR_EXT , idr_low)) { + ret =mpam_read_partsel_reg (msc,IDR +4 , &idr_high); +if (ret) +return ret; + }else { + idr_high =0 ; + } + + *res = ((u64 )idr_high <<32 ) | idr_low; -return (idr_high <<32 ) | idr_low; +return 0 ; } -static void mpam_msc_clear_esr (struct mpam_msc *msc) +static int mpam_msc_clear_esr (struct mpam_msc *msc) { -u64 esr_low =__mpam_read_reg (msc,MPAMF_ESR ); +u32 esr_low; +int ret; + + ret =__mpam_read_reg (msc,MPAMF_ESR , &esr_low); +if (ret) +return ret;if (!esr_low) -return ; +return 0 ;/* * Clearing the high/low bits of MPAMF_ESR can not be atomic.
@@ -268,44 +293,59 @@ static void mpam_msc_clear_esr(struct mpam_msc *msc)* lower half prevent hardware from updating either half of the * register. */ -if (msc->has_extd_esr) -__mpam_write_reg (msc,MPAMF_ESR +4 ,0 ); -__mpam_write_reg (msc,MPAMF_ESR ,0 ); +if (msc->has_extd_esr) { + ret =__mpam_write_reg (msc,MPAMF_ESR +4 ,0 ); +if (ret) +return ret; + } + +return __mpam_write_reg (msc,MPAMF_ESR ,0 ); } -static u64 mpam_msc_read_esr (struct mpam_msc *msc) +static int mpam_msc_read_esr (struct mpam_msc *msc,u64 *res) { -u64 esr_high =0 , esr_low; +u32 esr_high, esr_low; +int ret; - esr_low =__mpam_read_reg (msc,MPAMF_ESR ); -if (msc->has_extd_esr) - esr_high =__mpam_read_reg (msc,MPAMF_ESR +4 ); + ret =__mpam_read_reg (msc,MPAMF_ESR , &esr_low); +if (ret) +return ret; -return (esr_high <<32 ) | esr_low; +if (msc->has_extd_esr) { + ret =__mpam_read_reg (msc,MPAMF_ESR +4 , &esr_high); +if (ret) +return ret; + }else { + esr_high =0 ; + } + + *res = ((u64 )esr_high <<32 ) | esr_low; + +return 0 ; } -static void __mpam_part_sel_raw (u32 partsel,struct mpam_msc *msc) +static int __mpam_part_sel_raw (u32 partsel,struct mpam_msc *msc) {lockdep_assert_held (&msc->part_sel_lock); -mpam_write_partsel_reg (msc,PART_SEL , partsel); +return mpam_write_partsel_reg (msc,PART_SEL , partsel); } -static void __mpam_part_sel (u8 ris_idx,u16 partid,struct mpam_msc *msc) +static int __mpam_part_sel (u8 ris_idx,u16 partid,struct mpam_msc *msc) {u32 partsel =FIELD_PREP (MPAMCFG_PART_SEL_RIS , ris_idx) |FIELD_PREP (MPAMCFG_PART_SEL_PARTID_SEL , partid); -__mpam_part_sel_raw (partsel, msc); +return __mpam_part_sel_raw (partsel, msc); } -static void __mpam_intpart_sel (u8 ris_idx,u16 intpartid,struct mpam_msc *msc) +static int __mpam_intpart_sel (u8 ris_idx,u16 intpartid,struct mpam_msc *msc) {u32 partsel =FIELD_PREP (MPAMCFG_PART_SEL_RIS , ris_idx) |FIELD_PREP (MPAMCFG_PART_SEL_PARTID_SEL , intpartid) |MPAMCFG_PART_SEL_INTERNAL ; -__mpam_part_sel_raw (partsel, msc); +return __mpam_part_sel_raw (partsel, msc); }int mpam_register_requestor (u16 partid_max,u8 pmg_max)
@@ -774,13 +814,13 @@ static bool mpam_ris_hw_probe_csu_nrdy(struct mpam_msc_ris *ris)mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val);_mpam_write_monsel_reg (msc,MSMON_CSU ,MSMON___NRDY ); - now =_mpam_read_monsel_reg (msc,MSMON_CSU ); +_mpam_read_monsel_reg (msc,MSMON_CSU , &now); can_set = now &MSMON___NRDY ;_mpam_write_monsel_reg (msc,MSMON_CSU ,0 );/* Configuration change to try and coax hardware into setting nrdy */ mpam_write_monsel_reg (msc,CFG_CSU_FLT ,0x1 ); - now =_mpam_read_monsel_reg (msc,MSMON_CSU ); +_mpam_read_monsel_reg (msc,MSMON_CSU , &now); can_clear = !(now &MSMON___NRDY );mpam_mon_sel_unlock (msc);
@@ -800,7 +840,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)/* Cache Capacity Partitioning */ if (FIELD_GET (MPAMF_IDR_HAS_CCAP_PART , ris->idr)) { -u32 ccap_features =mpam_read_partsel_reg (msc,CCAP_IDR ); +u32 ccap_features; + +mpam_read_partsel_reg (msc,CCAP_IDR , &ccap_features); props->cmax_wd =FIELD_GET (MPAMF_CCAP_IDR_CMAX_WD , ccap_features); if (props->cmax_wd &&
@@ -823,7 +865,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)/* Cache Portion partitioning */ if (FIELD_GET (MPAMF_IDR_HAS_CPOR_PART , ris->idr)) { -u32 cpor_features =mpam_read_partsel_reg (msc,CPOR_IDR ); +u32 cpor_features; + +mpam_read_partsel_reg (msc,CPOR_IDR , &cpor_features); props->cpbm_wd =FIELD_GET (MPAMF_CPOR_IDR_CPBM_WD , cpor_features);if (props->cpbm_wd)
@@ -832,7 +876,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)/* Memory bandwidth partitioning */ if (FIELD_GET (MPAMF_IDR_HAS_MBW_PART , ris->idr)) { -u32 mbw_features =mpam_read_partsel_reg (msc,MBW_IDR ); +u32 mbw_features; + +mpam_read_partsel_reg (msc,MBW_IDR , &mbw_features);/* portion bitmap resolution */ props->mbw_pbm_bits =FIELD_GET (MPAMF_MBW_IDR_BWPBM_WD , mbw_features);
@@ -860,7 +906,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)/* Priority partitioning */ if (FIELD_GET (MPAMF_IDR_HAS_PRI_PART , ris->idr)) { -u32 pri_features =mpam_read_partsel_reg (msc,PRI_IDR ); +u32 pri_features; + +mpam_read_partsel_reg (msc,PRI_IDR , &pri_features); props->intpri_wd =FIELD_GET (MPAMF_PRI_IDR_INTPRI_WD , pri_features);if (props->intpri_wd &&FIELD_GET (MPAMF_PRI_IDR_HAS_INTPRI , pri_features)) {
@@ -879,7 +927,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)/* Performance Monitoring */ if (FIELD_GET (MPAMF_IDR_HAS_MSMON , ris->idr)) { -u32 msmon_features =mpam_read_partsel_reg (msc,MSMON_IDR ); +u32 msmon_features; + +mpam_read_partsel_reg (msc,MSMON_IDR , &msmon_features);/* * If the firmware max-nrdy-us property is missing, the
@@ -892,7 +942,8 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)if (FIELD_GET (MPAMF_MSMON_IDR_MSMON_CSU , msmon_features)) {u32 csumonidr; - csumonidr =mpam_read_partsel_reg (msc,CSUMON_IDR ); +mpam_read_partsel_reg (msc,CSUMON_IDR , &csumonidr); + props->num_csu_mon =FIELD_GET (MPAMF_CSUMON_IDR_NUM_MON , csumonidr);if (props->num_csu_mon) {bool hw_managed;
@@ -915,7 +966,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) }if (FIELD_GET (MPAMF_MSMON_IDR_MSMON_MBWU , msmon_features)) {bool has_long; -u32 mbwumon_idr =mpam_read_partsel_reg (msc,MBWUMON_IDR ); +u32 mbwumon_idr; + +mpam_read_partsel_reg (msc,MBWUMON_IDR , &mbwumon_idr); props->num_mbwu_mon =FIELD_GET (MPAMF_MBWUMON_IDR_NUM_MON , mbwumon_idr);if (props->num_mbwu_mon) {
@@ -945,8 +998,11 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)*/ if (FIELD_GET (MPAMF_IDR_HAS_PARTID_NRW , ris->idr) && class->type !=MPAM_CLASS_UNKNOWN ) { -u32 nrwidr =mpam_read_partsel_reg (msc,PARTID_NRW_IDR ); -u16 partid_max =FIELD_GET (MPAMF_PARTID_NRW_IDR_INTPARTID_MAX , nrwidr); +u16 partid_max; +u32 nrwidr; + +mpam_read_partsel_reg (msc,PARTID_NRW_IDR , &nrwidr); + partid_max =FIELD_GET (MPAMF_PARTID_NRW_IDR_INTPARTID_MAX , nrwidr);mpam_set_feature (mpam_feat_partid_nrw, props); msc->partid_max =min (msc->partid_max, partid_max);
@@ -970,8 +1026,9 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)/* Grab an IDR value to find out how many RIS there are */ mutex_lock (&msc->part_sel_lock); - idr =mpam_msc_read_idr (msc); - msc->iidr =mpam_read_partsel_reg (msc,IIDR ); +mpam_msc_read_idr (msc, &idr); +mpam_read_partsel_reg (msc,IIDR , &msc->iidr); +mutex_unlock (&msc->part_sel_lock);mpam_enable_quirks (msc);
@@ -985,7 +1042,7 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)for (ris_idx =0 ; ris_idx <= msc->ris_max; ris_idx++) {mutex_lock (&msc->part_sel_lock);__mpam_part_sel (ris_idx,0 , msc); - idr =mpam_msc_read_idr (msc); +mpam_msc_read_idr (msc, &idr);mutex_unlock (&msc->part_sel_lock); partid_max =FIELD_GET (MPAMF_IDR_PARTID_MAX , idr);
@@ -1039,24 +1096,24 @@ static u64 mpam_msc_read_mbwu_l(struct mpam_msc *msc) {int retry =3 ;u32 mbwu_l_low; -u64 mbwu_l_high1, mbwu_l_high2; +u32 mbwu_l_high1, mbwu_l_high2;mpam_mon_sel_lock_held (msc);WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz);WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); - mbwu_l_high2 =__mpam_read_reg (msc,MSMON_MBWU_L +4 ); +__mpam_read_reg (msc,MSMON_MBWU_L +4 , &mbwu_l_high2);do { mbwu_l_high1 = mbwu_l_high2; - mbwu_l_low =__mpam_read_reg (msc,MSMON_MBWU_L ); - mbwu_l_high2 =__mpam_read_reg (msc,MSMON_MBWU_L +4 ); +__mpam_read_reg (msc,MSMON_MBWU_L , &mbwu_l_low); +__mpam_read_reg (msc,MSMON_MBWU_L +4 , &mbwu_l_high2); retry--; }while (mbwu_l_high1 != mbwu_l_high2 && retry >0 );if (mbwu_l_high1 == mbwu_l_high2) -return (mbwu_l_high1 <<32 ) | mbwu_l_low; +return ((u64 )mbwu_l_high1 <<32 ) | mbwu_l_low;pr_warn ("Failed to read a stable value\n" );return MSMON___L_NRDY ;
@@ -1120,14 +1177,14 @@ static void read_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val,switch (m->type) {case mpam_feat_msmon_csu: - *ctl_val =mpam_read_monsel_reg (msc,CFG_CSU_CTL ); - *flt_val =mpam_read_monsel_reg (msc,CFG_CSU_FLT ); +mpam_read_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +mpam_read_monsel_reg (msc,CFG_CSU_FLT , flt_val);break ;case mpam_feat_msmon_mbwu_31counter:case mpam_feat_msmon_mbwu_44counter:case mpam_feat_msmon_mbwu_63counter: - *ctl_val =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); - *flt_val =mpam_read_monsel_reg (msc,CFG_MBWU_FLT ); +mpam_read_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); +mpam_read_monsel_reg (msc,CFG_MBWU_FLT , flt_val);break ;default :pr_warn ("Unexpected monitor type %d\n" , m->type);
@@ -1205,6 +1262,7 @@ static u64 mpam_msmon_overflow_val(enum mpam_device_features type,static void __ris_msmon_read (void *arg) {u64 now; +u32 now32;bool nrdy = false;bool config_mismatch;bool overflow = false;
@@ -1267,9 +1325,9 @@ static void __ris_msmon_read(void *arg)switch (m->type) {case mpam_feat_msmon_csu: - now =mpam_read_monsel_reg (msc,CSU ); - nrdy = now &MSMON___NRDY ; - now =FIELD_GET (MSMON___VALUE , now); +mpam_read_monsel_reg (msc,CSU , &now32); + nrdy = now32 &MSMON___NRDY ; + now =FIELD_GET (MSMON___VALUE , now32);if (mpam_has_quirk (IGNORE_CSU_NRDY , msc) && m->waited_timeout) nrdy = false;
@@ -1287,9 +1345,9 @@ static void __ris_msmon_read(void *arg)else now =FIELD_GET (MSMON___L_VALUE , now); }else { - now =mpam_read_monsel_reg (msc,MBWU ); - nrdy = now &MSMON___NRDY ; - now =FIELD_GET (MSMON___VALUE , now); +mpam_read_monsel_reg (msc,MBWU , &now32); + nrdy = now32 &MSMON___NRDY ; + now =FIELD_GET (MSMON___VALUE , now32); }if (mpam_has_quirk (T241_MBW_COUNTER_SCALE_64 , msc))
@@ -1689,16 +1747,18 @@ static int mpam_save_mbwu_state(void *arg) mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , i) |FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx);mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); - - cur_flt =mpam_read_monsel_reg (msc,CFG_MBWU_FLT ); - cur_ctl =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); +mpam_read_monsel_reg (msc,CFG_MBWU_FLT , &cur_flt); +mpam_read_monsel_reg (msc,CFG_MBWU_CTL , &cur_ctl);mpam_write_monsel_reg (msc,CFG_MBWU_CTL ,0 );if (mpam_ris_has_mbwu_long_counter (ris)) { val =mpam_msc_read_mbwu_l (msc);mpam_msc_zero_mbwu_l (msc); }else { - val =mpam_read_monsel_reg (msc,MBWU ); +u32 val32; + +mpam_read_monsel_reg (msc,MBWU , &val32); + val = val32;mpam_write_monsel_reg (msc,MBWU ,0 ); }
@@ -2473,7 +2533,7 @@ static irqreturn_t __mpam_irq_handler(int irq, struct mpam_msc *msc) &msc->accessibility)))return IRQ_NONE ; - reg =mpam_msc_read_esr (msc); +mpam_msc_read_esr (msc, ®); errcode =FIELD_GET (MPAMF_ESR_ERRCODE , reg);if (!errcode)
Signature · 1 line
2.43.0
PATCH v10 2/14 arm_mpam: propagate MSC access errors for hw_probe functions
In reply to Andre PrzywaraAllow the functions probing for MSC hardware and features to return an error, and propagate read and write errors from the lower level up. This uses some "scoped cleanup" functions like scoped_guard() and ACQUIRE() to avoid the complexity of error handling when a lock has been taken. Since the mon_sel_lock is a bit special (even more so in an upcoming patch), we define a new GUARD type for it.
--- drivers/resctrl/mpam_devices.c | 126 +++++++++++++++++++++----------- drivers/resctrl/mpam_internal.h | 4 + 2 files changed, 87 insertions(+), 43 deletions(-)
drivers/resctrl/mpam_devices.c +83 -43
@@ -798,38 +798,46 @@ static bool mpam_ris_hw_probe_csu_nrdy(struct mpam_msc_ris *ris)bool can_set, can_clear;struct mpam_msc *msc = ris->vmsc->msc; -if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +ACQUIRE (mon_sel_lock, guard)(msc); +if (ACQUIRE_ERR (mon_sel_lock, &guard))return false; mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL ,0 ) |FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx); -mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); +if (mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel)) +return false;/* Hardware might ignore nrdy if it's not enabled */ ctl_val =MSMON_CFG_CSU_CTL_TYPE_CSU ; ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; ctl_val |= MSMON_CFG_x_CTL_EN; -mpam_write_monsel_reg (msc,CFG_CSU_FLT ,0 ); -mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +if (mpam_write_monsel_reg (msc,CFG_CSU_FLT ,0 )) +return false; +if (mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val)) +return false; -_mpam_write_monsel_reg (msc,MSMON_CSU ,MSMON___NRDY ); -_mpam_read_monsel_reg (msc,MSMON_CSU , &now); +if (_mpam_write_monsel_reg (msc,MSMON_CSU ,MSMON___NRDY )) +return false; +if (_mpam_read_monsel_reg (msc,MSMON_CSU , &now)) +return false; can_set = now &MSMON___NRDY ; -_mpam_write_monsel_reg (msc,MSMON_CSU ,0 ); +if (_mpam_write_monsel_reg (msc,MSMON_CSU ,0 )) +return false;/* Configuration change to try and coax hardware into setting nrdy */ -mpam_write_monsel_reg (msc,CFG_CSU_FLT ,0x1 ); -_mpam_read_monsel_reg (msc,MSMON_CSU , &now); +if (mpam_write_monsel_reg (msc,CFG_CSU_FLT ,0x1 )) +return false; +if (_mpam_read_monsel_reg (msc,MSMON_CSU , &now)) +return false; can_clear = !(now &MSMON___NRDY ); -mpam_mon_sel_unlock (msc);return (!can_set || !can_clear); } -static void mpam_ris_hw_probe (struct mpam_msc_ris *ris) +static int mpam_ris_hw_probe (struct mpam_msc_ris *ris) { -int err; +int fw_has_nrdy_err, err;struct mpam_msc *msc = ris->vmsc->msc;struct device *dev = &msc->pdev->dev;struct mpam_props *props = &ris->props;
@@ -842,7 +850,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)if (FIELD_GET (MPAMF_IDR_HAS_CCAP_PART , ris->idr)) {u32 ccap_features; -mpam_read_partsel_reg (msc,CCAP_IDR , &ccap_features); + err =mpam_read_partsel_reg (msc,CCAP_IDR , &ccap_features); +if (err) +return err; props->cmax_wd =FIELD_GET (MPAMF_CCAP_IDR_CMAX_WD , ccap_features); if (props->cmax_wd &&
@@ -867,7 +877,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)if (FIELD_GET (MPAMF_IDR_HAS_CPOR_PART , ris->idr)) {u32 cpor_features; -mpam_read_partsel_reg (msc,CPOR_IDR , &cpor_features); + err =mpam_read_partsel_reg (msc,CPOR_IDR , &cpor_features); +if (err) +return err; props->cpbm_wd =FIELD_GET (MPAMF_CPOR_IDR_CPBM_WD , cpor_features);if (props->cpbm_wd)
@@ -877,8 +889,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)/* Memory bandwidth partitioning */ if (FIELD_GET (MPAMF_IDR_HAS_MBW_PART , ris->idr)) {u32 mbw_features; - -mpam_read_partsel_reg (msc,MBW_IDR , &mbw_features); + err =mpam_read_partsel_reg (msc,MBW_IDR , &mbw_features); +if (err) +return err;/* portion bitmap resolution */ props->mbw_pbm_bits =FIELD_GET (MPAMF_MBW_IDR_BWPBM_WD , mbw_features);
@@ -907,8 +920,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)/* Priority partitioning */ if (FIELD_GET (MPAMF_IDR_HAS_PRI_PART , ris->idr)) {u32 pri_features; - -mpam_read_partsel_reg (msc,PRI_IDR , &pri_features); + err =mpam_read_partsel_reg (msc,PRI_IDR , &pri_features); +if (err) +return err; props->intpri_wd =FIELD_GET (MPAMF_PRI_IDR_INTPRI_WD , pri_features);if (props->intpri_wd &&FIELD_GET (MPAMF_PRI_IDR_HAS_INTPRI , pri_features)) {
@@ -929,20 +943,24 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)if (FIELD_GET (MPAMF_IDR_HAS_MSMON , ris->idr)) {u32 msmon_features; -mpam_read_partsel_reg (msc,MSMON_IDR , &msmon_features); + err =mpam_read_partsel_reg (msc,MSMON_IDR , &msmon_features); +if (err) +return err;/* * If the firmware max-nrdy-us property is missing, the * CSU counters can't be used. Should we wait forever? */ - err =device_property_read_u32 (&msc->pdev->dev, -"arm,not-ready-us" , - &msc->nrdy_usec); + fw_has_nrdy_err =device_property_read_u32 (&msc->pdev->dev, +"arm,not-ready-us" , + &msc->nrdy_usec);if (FIELD_GET (MPAMF_MSMON_IDR_MSMON_CSU , msmon_features)) {u32 csumonidr; -mpam_read_partsel_reg (msc,CSUMON_IDR , &csumonidr); + err =mpam_read_partsel_reg (msc,CSUMON_IDR , &csumonidr); +if (err) +return err; props->num_csu_mon =FIELD_GET (MPAMF_CSUMON_IDR_NUM_MON , csumonidr);if (props->num_csu_mon) {
@@ -960,7 +978,7 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)* Accept the missing firmware property if NRDY appears * un-implemented. */ -if (err && hw_managed) +if (fw_has_nrdy_err && hw_managed)dev_err_once (dev,"Counters are not usable because not-ready timeout was not provided by firmware." ); } }
@@ -968,7 +986,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)bool has_long;u32 mbwumon_idr; -mpam_read_partsel_reg (msc,MBWUMON_IDR , &mbwumon_idr); + err =mpam_read_partsel_reg (msc,MBWUMON_IDR , &mbwumon_idr); +if (err) +return err; props->num_mbwu_mon =FIELD_GET (MPAMF_MBWUMON_IDR_NUM_MON , mbwumon_idr);if (props->num_mbwu_mon) {
@@ -1001,16 +1021,22 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)u16 partid_max;u32 nrwidr; -mpam_read_partsel_reg (msc,PARTID_NRW_IDR , &nrwidr); + err =mpam_read_partsel_reg (msc,PARTID_NRW_IDR , &nrwidr); +if (err) +return err; + partid_max =FIELD_GET (MPAMF_PARTID_NRW_IDR_INTPARTID_MAX , nrwidr);mpam_set_feature (mpam_feat_partid_nrw, props); msc->partid_max =min (msc->partid_max, partid_max); } + +return 0 ; }static int mpam_msc_hw_probe (struct mpam_msc *msc) { +int ret;u64 idr;u16 partid_max;u8 ris_idx, pmg_max;
@@ -1025,11 +1051,15 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) }/* Grab an IDR value to find out how many RIS there are */ -mutex_lock (&msc->part_sel_lock); -mpam_msc_read_idr (msc, &idr); -mpam_read_partsel_reg (msc,IIDR , &msc->iidr); + scoped_guard(mutex, &msc->part_sel_lock) { + ret =mpam_msc_read_idr (msc, &idr); +if (ret) +return ret; -mutex_unlock (&msc->part_sel_lock); + ret =mpam_read_partsel_reg (msc,IIDR , &msc->iidr); +if (ret) +return ret; + }mpam_enable_quirks (msc);
@@ -1040,10 +1070,15 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) msc->pmg_max =FIELD_GET (MPAMF_IDR_PMG_MAX , idr);for (ris_idx =0 ; ris_idx <= msc->ris_max; ris_idx++) { -mutex_lock (&msc->part_sel_lock); -__mpam_part_sel (ris_idx,0 , msc); -mpam_msc_read_idr (msc, &idr); -mutex_unlock (&msc->part_sel_lock); + scoped_guard(mutex, &msc->part_sel_lock) { + ret =__mpam_part_sel (ris_idx,0 , msc); +if (ret) +return ret; + + ret =mpam_msc_read_idr (msc, &idr); +if (ret) +return ret; + } partid_max =FIELD_GET (MPAMF_IDR_PARTID_MAX , idr); pmg_max =FIELD_GET (MPAMF_IDR_PMG_MAX , idr);
@@ -1051,17 +1086,22 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) msc->pmg_max =min (msc->pmg_max, pmg_max); msc->has_extd_esr =FIELD_GET (MPAMF_IDR_HAS_EXTD_ESR , idr); -mutex_lock (&mpam_list_lock); - ris =mpam_get_or_create_ris (msc, ris_idx); -mutex_unlock (&mpam_list_lock); -if (IS_ERR (ris)) -return PTR_ERR (ris); + scoped_guard(mutex, &mpam_list_lock) { + ris =mpam_get_or_create_ris (msc, ris_idx); +if (IS_ERR (ris)) +return PTR_ERR (ris); + } ris->idr = idr; -mutex_lock (&msc->part_sel_lock); -__mpam_part_sel (ris_idx,0 , msc); -mpam_ris_hw_probe (ris); -mutex_unlock (&msc->part_sel_lock); + scoped_guard(mutex, &msc->part_sel_lock) { + ret =__mpam_part_sel (ris_idx,0 , msc); +if (ret) +return ret; + + ret =mpam_ris_hw_probe (ris); +if (ret) +return ret; + } }/* Clear any stale errors */
drivers/resctrl/mpam_internal.h +4 -0
@@ -162,6 +162,10 @@ static inline void mpam_mon_sel_lock_init(struct mpam_msc *msc)raw_spin_lock_init (&msc->_mon_sel_lock); } +DEFINE_GUARD(mon_sel, struct mpam_msc *, +mpam_mon_sel_lock (_T),mpam_mon_sel_unlock (_T)); +DEFINE_GUARD_COND (mon_sel, _lock,mpam_mon_sel_lock (_T), _RET); +/* Bits for mpam features bitmaps */ enum mpam_device_features { mpam_feat_cpor_part,
Signature · 1 line
2.43.0
PATCH v10 3/14 arm_mpam: propagate MSC access errors for MBWU counters
In reply to Andre PrzywaraAllow the mpam_msc_read_mbwu_l() function to return an error, and propagate errors from the lower level up. This also changes the users of this function.
--- drivers/resctrl/mpam_devices.c | 45 +++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 14 deletions(-)
drivers/resctrl/mpam_devices.c +31 -14
@@ -1132,8 +1132,9 @@ static bool mpam_ris_has_mbwu_long_counter(struct mpam_msc_ris *ris) mpam_has_feature(mpam_feat_msmon_mbwu_44counter, &ris->props)); } -static u64 mpam_msc_read_mbwu_l (struct mpam_msc *msc) +static int mpam_msc_read_mbwu_l (struct mpam_msc *msc,u64 *res) { +int ret;int retry =3 ;u32 mbwu_l_low;u32 mbwu_l_high1, mbwu_l_high2;
@@ -1143,20 +1144,30 @@ static u64 mpam_msc_read_mbwu_l(struct mpam_msc *msc)WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz);WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); -__mpam_read_reg (msc,MSMON_MBWU_L +4 , &mbwu_l_high2); + ret =__mpam_read_reg (msc,MSMON_MBWU_L +4 , &mbwu_l_high2); +if (ret) +return ret; +do { mbwu_l_high1 = mbwu_l_high2; -__mpam_read_reg (msc,MSMON_MBWU_L , &mbwu_l_low); -__mpam_read_reg (msc,MSMON_MBWU_L +4 , &mbwu_l_high2); + ret =__mpam_read_reg (msc,MSMON_MBWU_L , &mbwu_l_low); +if (ret) +return ret; + ret =__mpam_read_reg (msc,MSMON_MBWU_L +4 , &mbwu_l_high2); +if (ret) +return ret; retry--; }while (mbwu_l_high1 != mbwu_l_high2 && retry >0 ); -if (mbwu_l_high1 == mbwu_l_high2) -return ((u64 )mbwu_l_high1 <<32 ) | mbwu_l_low; +if (mbwu_l_high1 == mbwu_l_high2) { + *res = ((u64 )mbwu_l_high1 <<32 ) | mbwu_l_low; + }else { +pr_warn ("Failed to read a stable value\n" ); + *res =MSMON___L_NRDY ; + } -pr_warn ("Failed to read a stable value\n" ); -return MSMON___L_NRDY ; +return 0 ; }static void mpam_msc_zero_mbwu_l (struct mpam_msc *msc)
@@ -1314,10 +1325,12 @@ static void __ris_msmon_read(void *arg)struct mpam_msc *msc = m->ris->vmsc->msc;u32 mon_sel, ctl_val, flt_val, cur_ctl, cur_flt; -if (!mpam_mon_sel_lock (msc)) { +ACQUIRE (mon_sel_lock, guard)(msc); +if (ACQUIRE_ERR (mon_sel_lock, &guard)) { m->err = -EIO ;return ; } + mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , ctx->mon) |FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx);mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel);
@@ -1377,7 +1390,9 @@ static void __ris_msmon_read(void *arg)case mpam_feat_msmon_mbwu_44counter:case mpam_feat_msmon_mbwu_63counter:if (m->type != mpam_feat_msmon_mbwu_31counter) { - now =mpam_msc_read_mbwu_l (msc); + m->err =mpam_msc_read_mbwu_l (msc, &now); +if (m->err) +return ; nrdy = now &MSMON___L_NRDY ;if (m->type == mpam_feat_msmon_mbwu_63counter)
@@ -1410,7 +1425,6 @@ static void __ris_msmon_read(void *arg)default : m->err = -EINVAL ; } -mpam_mon_sel_unlock (msc);if (nrdy) m->err = -EBUSY ;
@@ -1771,6 +1785,7 @@ static int mpam_save_mbwu_state(void *arg) {int i;u64 val; +int ret;struct mon_cfg *cfg;u32 cur_flt, cur_ctl, mon_sel;struct mpam_msc_ris *ris = arg;
@@ -1781,7 +1796,8 @@ static int mpam_save_mbwu_state(void *arg) mbwu_state = &ris->mbwu_state[i]; cfg = &mbwu_state->cfg; -if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +ACQUIRE (mon_sel_lock, guard)(msc); +if (ACQUIRE_ERR (mon_sel_lock, &guard))return -EIO ; mon_sel = FIELD_PREP(MSMON_CFG_MON_SEL_MON_SEL, i) |
@@ -1792,7 +1808,9 @@ static int mpam_save_mbwu_state(void *arg)mpam_write_monsel_reg (msc,CFG_MBWU_CTL ,0 );if (mpam_ris_has_mbwu_long_counter (ris)) { - val =mpam_msc_read_mbwu_l (msc); + ret =mpam_msc_read_mbwu_l (msc, &val); +if (ret) +return ret;mpam_msc_zero_mbwu_l (msc); }else {u32 val32;
@@ -1808,7 +1826,6 @@ static int mpam_save_mbwu_state(void *arg) cfg->partid =FIELD_GET (MSMON_CFG_x_FLT_PARTID, cur_flt); mbwu_state->correction += val; mbwu_state->enabled =FIELD_GET (MSMON_CFG_x_CTL_EN, cur_ctl); -mpam_mon_sel_unlock (msc); }return 0 ;
Signature · 1 line
2.43.0
PATCH v10 4/14 arm_mpam: propagate MSC access errors for msmon helpers
In reply to Andre PrzywaraAllow the helper functions for msmon accesses to return an error, and propagate read and write errors from the lower level up.
--- drivers/resctrl/mpam_devices.c | 72 ++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 25 deletions(-)
drivers/resctrl/mpam_devices.c +47 -25
@@ -1170,15 +1170,20 @@ static int mpam_msc_read_mbwu_l(struct mpam_msc *msc, u64 *res)return 0 ; } -static void mpam_msc_zero_mbwu_l (struct mpam_msc *msc) +static int mpam_msc_zero_mbwu_l (struct mpam_msc *msc) { +int ret; +mpam_mon_sel_lock_held (msc);WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz);WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); -__mpam_write_reg (msc,MSMON_MBWU_L ,0 ); -__mpam_write_reg (msc,MSMON_MBWU_L +4 ,0 ); + ret =__mpam_write_reg (msc,MSMON_MBWU_L ,0 ); +if (ret) +return ret; + +return __mpam_write_reg (msc,MSMON_MBWU_L +4 ,0 ); } static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val,
@@ -1221,24 +1226,28 @@ static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, } } -static void read_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, -u32 *flt_val) +static int read_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) {struct mpam_msc *msc = m->ris->vmsc->msc; +int ret;switch (m->type) {case mpam_feat_msmon_csu: -mpam_read_monsel_reg (msc,CFG_CSU_CTL , ctl_val); -mpam_read_monsel_reg (msc,CFG_CSU_FLT , flt_val); -break ; + ret =mpam_read_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +if (ret) +return ret; +return mpam_read_monsel_reg (msc,CFG_CSU_FLT , flt_val);case mpam_feat_msmon_mbwu_31counter:case mpam_feat_msmon_mbwu_44counter:case mpam_feat_msmon_mbwu_63counter: -mpam_read_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); -mpam_read_monsel_reg (msc,CFG_MBWU_FLT , flt_val); -break ; + ret =mpam_read_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); +if (ret) +return ret; +return mpam_read_monsel_reg (msc,CFG_MBWU_FLT , flt_val);default :pr_warn ("Unexpected monitor type %d\n" , m->type); +return -EINVAL ; } }
@@ -1251,10 +1260,11 @@ static inline void clean_msmon_ctl_val(u32 *cur_ctl) *cur_ctl &= ~MSMON_CFG_MBWU_CTL_OFLOW_STATUS_L ; } -static void write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val, -u32 flt_val) +static int write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val, +u32 flt_val) {struct mpam_msc *msc = m->ris->vmsc->msc; +int ret;/* * Write the ctl_val with the enable bit cleared, reset the counter,
@@ -1262,25 +1272,37 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,*/ switch (m->type) {case mpam_feat_msmon_csu: -mpam_write_monsel_reg (msc,CFG_CSU_FLT , flt_val); -mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val); -mpam_write_monsel_reg (msc,CSU ,0 ); -mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); -break ; + ret =mpam_write_monsel_reg (msc,CFG_CSU_FLT , flt_val); +if (ret) +return ret; + ret =mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +if (ret) +return ret; + ret =mpam_write_monsel_reg (msc,CSU ,0 ); +if (ret) +return ret; +return mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN);case mpam_feat_msmon_mbwu_31counter:case mpam_feat_msmon_mbwu_44counter:case mpam_feat_msmon_mbwu_63counter: -mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val); -mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); -mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); + ret =mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val); +if (ret) +return ret; + ret =mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); +if (ret) +return ret; + ret =mpam_write_monsel_reg (msc,CFG_MBWU_CTL , + ctl_val | MSMON_CFG_x_CTL_EN); +if (ret) +return ret;/* Counting monitors require NRDY to be reset by software */ if (m->type == mpam_feat_msmon_mbwu_31counter) -mpam_write_monsel_reg (msc,MBWU ,0 ); -else -mpam_msc_zero_mbwu_l (m->ris->vmsc->msc); -break ; +return mpam_write_monsel_reg (msc,MBWU ,0 ); + +return mpam_msc_zero_mbwu_l (m->ris->vmsc->msc);default :pr_warn ("Unexpected monitor type %d\n" , m->type); +return -EINVAL ; } }
Signature · 1 line
2.43.0
PATCH v10 5/14 arm_mpam: propagate MSC access errors for __ris_msmon_read()
In reply to Andre PrzywaraAllow the function for RIS accesses to return an error, and propagate read and write errors from the lower level up.
This function is a bit special, since it can be called via an SMP helper, so the prototype must stay as void. So propagate any errors using the "err" field in the struct passed in as the sole argument to that function.
--- drivers/resctrl/mpam_devices.c | 36 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-)
drivers/resctrl/mpam_devices.c +27 -9
@@ -1332,6 +1332,10 @@ static u64 mpam_msmon_overflow_val(enum mpam_device_features type,return overflow_val; } +/* +* This function might be called via smp_call_function_any(), so propagate +* errors inside the arg struct. +*/ static void __ris_msmon_read (void *arg) {u64 now;
@@ -1355,7 +1359,9 @@ static void __ris_msmon_read(void *arg) mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , ctx->mon) |FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx); -mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); + m->err =mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); +if (m->err) +return ;switch (m->type) {case mpam_feat_msmon_mbwu_31counter:
@@ -1375,7 +1381,9 @@ static void __ris_msmon_read(void *arg)* Read the existing configuration to avoid re-writing the same values. * This saves waiting for 'nrdy' on subsequent reads. */ -read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt); + m->err =read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt); +if (m->err) +return ;if (mpam_feat_msmon_mbwu_31counter == m->type) overflow = cur_ctl & MSMON_CFG_x_CTL_OFLOW_STATUS;
@@ -1389,18 +1397,24 @@ static void __ris_msmon_read(void *arg) cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN);if (config_mismatch || reset_on_next_read) { -write_msmon_ctl_flt_vals (m, ctl_val, flt_val); + m->err =write_msmon_ctl_flt_vals (m, ctl_val, flt_val); +if (m->err) +return ; overflow = false; }else if (overflow) { -mpam_write_monsel_reg (msc,CFG_MBWU_CTL , - cur_ctl & - ~(MSMON_CFG_x_CTL_OFLOW_STATUS | -MSMON_CFG_MBWU_CTL_OFLOW_STATUS_L )); + m->err =mpam_write_monsel_reg (msc,CFG_MBWU_CTL , + cur_ctl & + ~(MSMON_CFG_x_CTL_OFLOW_STATUS | +MSMON_CFG_MBWU_CTL_OFLOW_STATUS_L )); +if (m->err) +return ; }switch (m->type) {case mpam_feat_msmon_csu: -mpam_read_monsel_reg (msc,CSU , &now32); + m->err =mpam_read_monsel_reg (msc,CSU , &now32); +if (m->err) +return ; nrdy = now32 &MSMON___NRDY ; now =FIELD_GET (MSMON___VALUE , now32);
@@ -1422,7 +1436,9 @@ static void __ris_msmon_read(void *arg)else now =FIELD_GET (MSMON___L_VALUE , now); }else { -mpam_read_monsel_reg (msc,MBWU , &now32); + m->err =mpam_read_monsel_reg (msc,MBWU , &now32); +if (m->err) +return ; nrdy = now32 &MSMON___NRDY ; now =FIELD_GET (MSMON___VALUE , now32); }
@@ -1796,6 +1812,8 @@ static int mpam_restore_mbwu_state(void *_ris) mwbu_arg.val = &val;__ris_msmon_read (&mwbu_arg); +if (mwbu_arg.err && mwbu_arg.err != -EBUSY ) +return mwbu_arg.err; } }
Signature · 1 line
2.43.0
PATCH v10 6/14 arm_mpam: propagate MSC access errors for state saving function
In reply to Andre PrzywaraAllow the mpam_save_mbwu_state() function to return an error, and propagate read and write errors from the lower level up.
--- drivers/resctrl/mpam_devices.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/resctrl/mpam_devices.c +22 -7
@@ -1842,22 +1842,37 @@ static int mpam_save_mbwu_state(void *arg) mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , i) |FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx); -mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); -mpam_read_monsel_reg (msc,CFG_MBWU_FLT , &cur_flt); -mpam_read_monsel_reg (msc,CFG_MBWU_CTL , &cur_ctl); -mpam_write_monsel_reg (msc,CFG_MBWU_CTL ,0 ); + ret =mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); +if (ret) +return ret; + ret =mpam_read_monsel_reg (msc,CFG_MBWU_FLT , &cur_flt); +if (ret) +return ret; + ret =mpam_read_monsel_reg (msc,CFG_MBWU_CTL , &cur_ctl); +if (ret) +return ret; + ret =mpam_write_monsel_reg (msc,CFG_MBWU_CTL ,0 ); +if (ret) +return ret;if (mpam_ris_has_mbwu_long_counter (ris)) { ret =mpam_msc_read_mbwu_l (msc, &val);if (ret)return ret; -mpam_msc_zero_mbwu_l (msc); + ret =mpam_msc_zero_mbwu_l (msc); +if (ret) +return ret; }else {u32 val32; -mpam_read_monsel_reg (msc,MBWU , &val32); + ret =mpam_read_monsel_reg (msc,MBWU , &val32); +if (ret) +return ret; val = val32; -mpam_write_monsel_reg (msc,MBWU ,0 ); + + ret =mpam_write_monsel_reg (msc,MBWU ,0 ); +if (ret) +return ret; } cfg->mon = i;
Signature · 1 line
2.43.0
PATCH v10 7/14 arm_mpam: propagate MSC access errors for mpam_reprogram_ris_partid()
In reply to Andre PrzywaraAllow the mpam_reprogram_ris_partid() function to check for and return errors, and propagate MSC read and write errors from the lower level up. This also covers the callers of this function: mpam_reset_ris() and apply_config().
--- drivers/resctrl/mpam_devices.c | 137 ++++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 43 deletions(-)
drivers/resctrl/mpam_devices.c +94 -43
@@ -1599,7 +1599,7 @@ void mpam_msmon_reset_mbwu(struct mpam_component *comp, struct mon_cfg *ctx) } } -static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) +static int mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) {u32 num_words, msb;u32 bm = ~0 ;
@@ -1608,15 +1608,20 @@ static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd)lockdep_assert_held (&msc->part_sel_lock);if (wd ==0 ) -return ; +return 0 ;/* * Write all ~0 to all but the last 32bit-word, which may * have fewer bits... */ num_words =DIV_ROUND_UP (wd,32 ); -for (i =0 ; i < num_words -1 ; i++, reg +=sizeof (bm)) -__mpam_write_reg (msc, reg, bm); +for (i =0 ; i < num_words -1 ; i++, reg +=sizeof (bm)) { +int ret; + + ret =__mpam_write_reg (msc, reg, bm); +if (ret) +return ret; + }/* * ....and then the last (maybe) partial 32bit word. When wd is a
@@ -1624,7 +1629,7 @@ static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd)*/ msb = (wd -1 ) %32 ; bm =GENMASK (msb,0 ); -__mpam_write_reg (msc, reg, bm); +return __mpam_write_reg (msc, reg, bm); }static void mpam_apply_t241_erratum (struct mpam_msc_ris *ris,u16 partid)
@@ -1697,40 +1702,59 @@ static u16 mpam_wa_t241_calc_min_from_max(struct mpam_props *props, }/* Called via IPI. Call while holding an SRCU reference */ -static void mpam_reprogram_ris_partid (struct mpam_msc_ris *ris,u16 partid, -struct mpam_config *cfg) +static int mpam_reprogram_ris_partid (struct mpam_msc_ris *ris,u16 partid, +struct mpam_config *cfg) {u16 cmax =MPAMCFG_CMAX_CMAX ;struct mpam_msc *msc = ris->vmsc->msc;struct mpam_props *rprops = &ris->props; +int ret; -mutex_lock (&msc->part_sel_lock); -__mpam_part_sel (ris->ris_idx, partid, msc); +guard (mutex)(&msc->part_sel_lock); + ret =__mpam_part_sel (ris->ris_idx, partid, msc); +if (ret) +return ret;if (mpam_has_feature (mpam_feat_partid_nrw, rprops)) {/* Update the intpartid mapping */ -mpam_write_partsel_reg (msc,INTPARTID , -MPAMCFG_INTPARTID_INTERNAL | partid); + ret =mpam_write_partsel_reg (msc,INTPARTID , +MPAMCFG_INTPARTID_INTERNAL | partid); +if (ret) +return ret;/* * Then switch to the 'internal' partid to update the * configuration. */ -__mpam_intpart_sel (ris->ris_idx, partid, msc); + ret =__mpam_intpart_sel (ris->ris_idx, partid, msc); +if (ret) +return ret; }if (mpam_has_feature (mpam_feat_cpor_part, rprops)) { -if (mpam_has_feature (mpam_feat_cpor_part, cfg)) -mpam_write_partsel_reg (msc,CPBM , cfg->cpbm); -else -mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , rprops->cpbm_wd); +if (mpam_has_feature (mpam_feat_cpor_part, cfg)) { + ret =mpam_write_partsel_reg (msc,CPBM , cfg->cpbm); +if (ret) +return ret; + }else { + ret =mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , + rprops->cpbm_wd); +if (ret) +return ret; + } }if (mpam_has_feature (mpam_feat_mbw_part, rprops)) { -if (mpam_has_feature (mpam_feat_mbw_part, cfg)) -mpam_write_partsel_reg (msc,MBW_PBM , cfg->mbw_pbm); -else -mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , rprops->mbw_pbm_bits); +if (mpam_has_feature (mpam_feat_mbw_part, cfg)) { + ret =mpam_write_partsel_reg (msc,MBW_PBM , cfg->mbw_pbm); +if (ret) +return ret; + }else { + ret =mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , + rprops->mbw_pbm_bits); +if (ret) +return ret; + } }if (mpam_has_feature (mpam_feat_mbw_min, rprops)) {
@@ -1743,27 +1767,47 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, val =max (val, min); } -mpam_write_partsel_reg (msc,MBW_MIN , val); + ret =mpam_write_partsel_reg (msc,MBW_MIN , val); +if (ret) +return ret; }if (mpam_has_feature (mpam_feat_mbw_max, rprops)) { -if (mpam_has_feature (mpam_feat_mbw_max, cfg)) -mpam_write_partsel_reg (msc,MBW_MAX , cfg->mbw_max); -else -mpam_write_partsel_reg (msc,MBW_MAX ,MPAMCFG_MBW_MAX_MAX ); +if (mpam_has_feature (mpam_feat_mbw_max, cfg)) { + ret =mpam_write_partsel_reg (msc,MBW_MAX , cfg->mbw_max); +if (ret) +return ret; + }else { + ret =mpam_write_partsel_reg (msc,MBW_MAX , +MPAMCFG_MBW_MAX_MAX ); +if (ret) +return ret; + } } -if (mpam_has_feature (mpam_feat_mbw_prop, rprops)) -mpam_write_partsel_reg (msc,MBW_PROP ,0 ); +if (mpam_has_feature (mpam_feat_mbw_prop, rprops)) { + ret =mpam_write_partsel_reg (msc,MBW_PROP ,0 ); +if (ret) +return ret; + } -if (mpam_has_feature (mpam_feat_cmax_cmax, rprops)) -mpam_write_partsel_reg (msc,CMAX , cmax); +if (mpam_has_feature (mpam_feat_cmax_cmax, rprops)) { + ret =mpam_write_partsel_reg (msc,CMAX , cmax); +if (ret) +return ret; + } -if (mpam_has_feature (mpam_feat_cmax_cmin, rprops)) -mpam_write_partsel_reg (msc,CMIN ,0 ); +if (mpam_has_feature (mpam_feat_cmax_cmin, rprops)) { + ret =mpam_write_partsel_reg (msc,CMIN ,0 ); +if (ret) +return ret; + } -if (mpam_has_feature (mpam_feat_cmax_cassoc, rprops)) -mpam_write_partsel_reg (msc,CASSOC ,MPAMCFG_CASSOC_CASSOC ); +if (mpam_has_feature (mpam_feat_cmax_cassoc, rprops)) { + ret =mpam_write_partsel_reg (msc,CASSOC ,MPAMCFG_CASSOC_CASSOC ); +if (ret) +return ret; + }if (mpam_has_feature (mpam_feat_intpri_part, rprops) ||mpam_has_feature (mpam_feat_dspri_part, rprops)) {
@@ -1787,12 +1831,14 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, pri_val |=FIELD_PREP (MPAMCFG_PRI_DSPRI , dspri); } -mpam_write_partsel_reg (msc,PRI , pri_val); + ret =mpam_write_partsel_reg (msc,PRI , pri_val); +if (ret) +return ret; }mpam_quirk_post_config_change (ris, partid, cfg); -mutex_unlock (&msc->part_sel_lock); +return 0 ; }/* Call with msc cfg_lock held */
@@ -1895,6 +1941,7 @@ static int mpam_reset_ris(void *arg)u16 partid, partid_max;struct mpam_config reset_cfg = {};struct mpam_msc_ris *ris = arg; +int ret;if (ris->in_reset_state)return 0 ;
@@ -1902,8 +1949,11 @@ static int mpam_reset_ris(void *arg)spin_lock (&partid_max_lock); partid_max = mpam_partid_max;spin_unlock (&partid_max_lock); -for (partid =0 ; partid <= partid_max; partid++) -mpam_reprogram_ris_partid (ris, partid, &reset_cfg); +for (partid =0 ; partid <= partid_max; partid++) { + ret =mpam_reprogram_ris_partid (ris, partid, &reset_cfg); +if (ret) +return ret; + }return 0 ; }
@@ -1942,9 +1992,8 @@ static int __write_config(void *arg) {struct mpam_write_config_arg *c = arg; -mpam_reprogram_ris_partid (c->ris, c->partid, &c->comp->cfg[c->partid]); - -return 0 ; +return mpam_reprogram_ris_partid (c->ris, c->partid, + &c->comp->cfg[c->partid]); }static void mpam_reprogram_msc (struct mpam_msc *msc)
@@ -3098,6 +3147,7 @@ int mpam_apply_config(struct mpam_component *comp, u16 partid,struct mpam_msc_ris *ris;struct mpam_vmsc *vmsc;struct mpam_msc *msc; +int ret;lockdep_assert_cpus_held ();
@@ -3115,14 +3165,15 @@ int mpam_apply_config(struct mpam_component *comp, u16 partid, srcu_read_lock_held(&mpam_srcu)) { msc = vmsc->msc; -mutex_lock (&msc->cfg_lock); +guard (mutex)(&msc->cfg_lock);list_for_each_entry_srcu (ris, &vmsc->ris, vmsc_list,srcu_read_lock_held (&mpam_srcu)) { arg.ris = ris; -mpam_touch_msc (msc, __write_config, &arg); + ret =mpam_touch_msc (msc, __write_config, &arg); +if (ret) +return ret; ris->in_reset_state = false; } -mutex_unlock (&msc->cfg_lock); }return 0 ;
Signature · 1 line
2.43.0
PATCH v10 8/14 arm_mpam: propagate MSC access errors for interrupt control
In reply to Andre PrzywaraAllow the functions dealing with interrupt registration and enablement to check for and return errors, and propagate MSC read and write errors from the lower level up.
This does not cover the IRQ handler yet, as this needs some more attention.
--- drivers/resctrl/mpam_devices.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
drivers/resctrl/mpam_devices.c +15 -16
@@ -1105,7 +1105,9 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) }/* Clear any stale errors */ -mpam_msc_clear_esr (msc); + ret =mpam_msc_clear_esr (msc); +if (ret) +return ret;spin_lock (&partid_max_lock); mpam_partid_max =min (mpam_partid_max, msc->partid_max);
@@ -2668,9 +2670,7 @@ static int mpam_enable_msc_ecr(void *_msc) {struct mpam_msc *msc = _msc; -__mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); - -return 0 ; +return __mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); }/* This can run in mpam_disable(), and the interrupt handler on the same CPU */
@@ -2678,9 +2678,7 @@ static int mpam_disable_msc_ecr(void *_msc) {struct mpam_msc *msc = _msc; -__mpam_write_reg (msc,MPAMF_ECR ,0 ); - -return 0 ; +return __mpam_write_reg (msc,MPAMF_ECR ,0 ); }static irqreturn_t __mpam_irq_handler (int irq,struct mpam_msc *msc)
@@ -2777,11 +2775,13 @@ static int mpam_register_irqs(void)return err; } -mutex_lock (&msc->error_irq_lock); - msc->error_irq_req = true; -mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); - msc->error_irq_hw_enabled = true; -mutex_unlock (&msc->error_irq_lock); + scoped_guard(mutex, &msc->error_irq_lock) { + msc->error_irq_req = true; + err =mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); +if (err) +return err; + msc->error_irq_hw_enabled = true; + } }return 0 ;
@@ -2800,10 +2800,10 @@ static void mpam_unregister_irqs(void)if (irq <=0 )continue ; -mutex_lock (&msc->error_irq_lock); +guard (mutex)(&msc->error_irq_lock);if (msc->error_irq_hw_enabled) { -mpam_touch_msc (msc, mpam_disable_msc_ecr, msc); - msc->error_irq_hw_enabled = false; +if (!mpam_touch_msc (msc, mpam_disable_msc_ecr, msc)) + msc->error_irq_hw_enabled = false; }if (msc->error_irq_req) {
@@ -2815,7 +2815,6 @@ static void mpam_unregister_irqs(void) } msc->error_irq_req = false; } -mutex_unlock (&msc->error_irq_lock); } }
Signature · 1 line
2.43.0
Ben Horgan
maintainerRe: [PATCH v10 08/14] arm_mpam: propagate MSC access errors for interrupt control
Hi Andre,
Quoted 8 lines · Andre Przywara
Allow the functions dealing with interrupt registration and enablement to check for and return errors, and propagate MSC read and write errors from the lower level up.
This does not cover the IRQ handler yet, as this needs some more attention.Signed-off-by Andre Przywara <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>
Commenting here as this is the last error propagation patch. I think we need a clean boundary for the error propagation. As you said a while back I think we can propagate error for all non-static functions from mpam_devices.c and the callers can discard the errors if appropriate. For instance, mpam_reset_class_locked() should propagate any error.
Thanks,
Ben
Quoted 82 lines
--- drivers/resctrl/mpam_devices.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)drivers/resctrl/mpam_devices.c +15
-16@@ -1105,7 +1105,9 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) }/* Clear any stale errors */ -mpam_msc_clear_esr (msc); + ret =mpam_msc_clear_esr (msc); +if (ret) +return ret;spin_lock (&partid_max_lock); mpam_partid_max =min (mpam_partid_max, msc->partid_max);@@ -2668,9 +2670,7 @@ static int mpam_enable_msc_ecr(void *_msc) {struct mpam_msc *msc = _msc; -__mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); - -return 0 ; +return __mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); }/* This can run in mpam_disable(), and the interrupt handler on the same CPU */ @@ -2678,9 +2678,7 @@ static int mpam_disable_msc_ecr(void *_msc) {struct mpam_msc *msc = _msc; -__mpam_write_reg (msc,MPAMF_ECR ,0 ); - -return 0 ; +return __mpam_write_reg (msc,MPAMF_ECR ,0 ); }static irqreturn_t __mpam_irq_handler (int irq,struct mpam_msc *msc)@@ -2777,11 +2775,13 @@ static int mpam_register_irqs(void)return err; } -mutex_lock (&msc->error_irq_lock); - msc->error_irq_req = true; -mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); - msc->error_irq_hw_enabled = true; -mutex_unlock (&msc->error_irq_lock); + scoped_guard(mutex, &msc->error_irq_lock) { + msc->error_irq_req = true; + err =mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); +if (err) +return err; + msc->error_irq_hw_enabled = true; + } }return 0 ;@@ -2800,10 +2800,10 @@ static void mpam_unregister_irqs(void)if (irq <=0 )continue ; -mutex_lock (&msc->error_irq_lock); +guard (mutex)(&msc->error_irq_lock);if (msc->error_irq_hw_enabled) { -mpam_touch_msc (msc, mpam_disable_msc_ecr, msc); - msc->error_irq_hw_enabled = false; +if (!mpam_touch_msc (msc, mpam_disable_msc_ecr, msc)) + msc->error_irq_hw_enabled = false; }if (msc->error_irq_req) {@@ -2815,7 +2815,6 @@ static void mpam_unregister_irqs(void) } msc->error_irq_req = false; } -mutex_unlock (&msc->error_irq_lock); } }
Re: [PATCH v10 08/14] arm_mpam: propagate MSC access errors for interrupt control
Hi Ben,
Quoted 9 lines · Ben Horgan
Hi Andre,
Quoted 6 lines · Andre Przywara
Allow the functions dealing with interrupt registration and enablement to check for and return errors, and propagate MSC read and write errors from the lower level up.
This does not cover the IRQ handler yet, as this needs some more attention.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>Commenting here as this is the last error propagation patch. I think we need a clean boundary for the error propagation. As you said a while back I think we can propagate error for all non-static functions from
mpam_devices.cand the callers can discard the errors if appropriate. For instance,mpam_reset_class_locked()should propagate any error.
So I checked all non-static functions in mpam_devices.c: most either don't deal with MSCs at all, or already propagate errors.
The two outliers are mpam_disable(), which must be "void", due to it being called via DECLARE_WORK, and mpam_reset_class_locked(), as you write above. The latter is a bit sad, because the caller is void, so any errors would be discarded there anyway, but for the sake of completeness we should indeed propagate here.
And I guess it doesn't make sense to continue the vMSC or RIS list iterations after detecting the first error, but we just bail out immediately? Because any error would trigger mpam_disable() anyway?
Cheers,
Andre
Quoted 88 lines
Thanks,
Ben
Quoted 82 lines
--- drivers/resctrl/mpam_devices.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)drivers/resctrl/mpam_devices.c +15
-16@@ -1105,7 +1105,9 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) }/* Clear any stale errors */ -mpam_msc_clear_esr (msc); + ret =mpam_msc_clear_esr (msc); +if (ret) +return ret;spin_lock (&partid_max_lock); mpam_partid_max =min (mpam_partid_max, msc->partid_max);@@ -2668,9 +2670,7 @@ static int mpam_enable_msc_ecr(void *_msc) {struct mpam_msc *msc = _msc; -__mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); - -return 0 ; +return __mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); }/* This can run in mpam_disable(), and the interrupt handler on the same CPU */ @@ -2678,9 +2678,7 @@ static int mpam_disable_msc_ecr(void *_msc) {struct mpam_msc *msc = _msc; -__mpam_write_reg (msc,MPAMF_ECR ,0 ); - -return 0 ; +return __mpam_write_reg (msc,MPAMF_ECR ,0 ); }static irqreturn_t __mpam_irq_handler (int irq,struct mpam_msc *msc)@@ -2777,11 +2775,13 @@ static int mpam_register_irqs(void)return err; } -mutex_lock (&msc->error_irq_lock); - msc->error_irq_req = true; -mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); - msc->error_irq_hw_enabled = true; -mutex_unlock (&msc->error_irq_lock); + scoped_guard(mutex, &msc->error_irq_lock) { + msc->error_irq_req = true; + err =mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); +if (err) +return err; + msc->error_irq_hw_enabled = true; + } }return 0 ;@@ -2800,10 +2800,10 @@ static void mpam_unregister_irqs(void)if (irq <=0 )continue ; -mutex_lock (&msc->error_irq_lock); +guard (mutex)(&msc->error_irq_lock);if (msc->error_irq_hw_enabled) { -mpam_touch_msc (msc, mpam_disable_msc_ecr, msc); - msc->error_irq_hw_enabled = false; +if (!mpam_touch_msc (msc, mpam_disable_msc_ecr, msc)) + msc->error_irq_hw_enabled = false; }if (msc->error_irq_req) {@@ -2815,7 +2815,6 @@ static void mpam_unregister_irqs(void) } msc->error_irq_req = false; } -mutex_unlock (&msc->error_irq_lock); } }
Ben Horgan
maintainerRe: [PATCH v10 08/14] arm_mpam: propagate MSC access errors for interrupt control
Hi Andre,
Quoted 27 lines · Andre Przywara
Hi Ben,
Quoted 9 lines · Ben Horgan
Hi Andre,
Quoted 6 lines · Andre Przywara
Allow the functions dealing with interrupt registration and enablement to check for and return errors, and propagate MSC read and write errors from the lower level up.
This does not cover the IRQ handler yet, as this needs some more attention.Quoted 7 lines
Quoted 2 lines
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>Commenting here as this is the last error propagation patch. I think we need a clean boundary for the error propagation. As you said a while back I think we can propagate error for all non-static functions from
mpam_devices.cand the callers can discard the errors if appropriate. For instance,mpam_reset_class_locked()should propagate any error.So I checked all non-static functions in
mpam_devices.c: most either don't deal with MSCs at all, or already propagate errors.
The two outliers arempam_disable(), which must be "void", due to it being called viaDECLARE_WORK, andmpam_reset_class_locked(), as you write above. The latter is a bit sad, because the caller is void, so any errors would be discarded there anyway, but for the sake of completeness we should indeed propagate here.
Quoted 2 lines
And I guess it doesn't make sense to continue the vMSC or RIS list iterations after detecting the first error, but we just bail out immediately? Because any error would trigger
mpam_disable()anyway?
Yeah, bailing early makes sense to me.
Thanks,
Ben
Quoted 84 lines
Cheers,
AndreQuoted 78 lines
Thanks,
Ben
Quoted 72 lines
---
drivers/resctrl/mpam_devices.c| 31 +++++++++++++++----------------1 file changed, 15 insertions(+), 16 deletions(-)drivers/resctrl/mpam_devices.c +15
-12@@ -1105,7 +1105,9 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) } /* Clear any stale errors */ - mpam_msc_clear_esr(msc); + ret = mpam_msc_clear_esr(msc); + if (ret) + return ret; spin_lock(&partid_max_lock); mpam_partid_max = min(mpam_partid_max, msc->partid_max);@@ -2668,9 +2670,7 @@ static int mpam_enable_msc_ecr(void *_msc) { struct mpam_msc *msc = _msc; - __mpam_write_reg(msc, MPAMF_ECR, MPAMF_ECR_INTEN); - - return 0; + return __mpam_write_reg(msc, MPAMF_ECR, MPAMF_ECR_INTEN); } /* This can run in mpam_disable(), and the interrupt handler on the same CPU */@@ -2678,9 +2678,7 @@ static int mpam_disable_msc_ecr(void *_msc) { struct mpam_msc *msc = _msc; - __mpam_write_reg(msc, MPAMF_ECR, 0); - - return 0; + return __mpam_write_reg(msc, MPAMF_ECR, 0); } static irqreturn_t __mpam_irq_handler(int irq, struct mpam_msc *msc)@@ -2777,11 +2775,13 @@ static int mpam_register_irqs(void) return err; } - mutex_lock(&msc->error_irq_lock); - msc->error_irq_req = true; - mpam_touch_msc(msc, mpam_enable_msc_ecr, msc); - msc->error_irq_hw_enabled = true; - mutex_unlock(&msc->error_irq_lock); + scoped_guard(mutex, &msc->error_irq_lock) { + msc->error_irq_req = true; + err = mpam_touch_msc(msc, mpam_enable_msc_ecr, msc); + if (err) + return err; + msc->error_irq_hw_enabled = true; + } } return 0;@@ -2800,10 +2800,10 @@ static void mpam_unregister_irqs(void) if (irq <= 0) continue; - mutex_lock(&msc->error_irq_lock); + guard(mutex)(&msc->error_irq_lock); if (msc->error_irq_hw_enabled) { - mpam_touch_msc(msc, mpam_disable_msc_ecr, msc); - msc->error_irq_hw_enabled = false; + if (!mpam_touch_msc(msc, mpam_disable_msc_ecr, msc)) + msc->error_irq_hw_enabled = false; } if (msc->error_irq_req) {@@ -2815,7 +2815,6 @@ static void mpam_unregister_irqs(void) } msc->error_irq_req = false; } - mutex_unlock(&msc->error_irq_lock); } }
PATCH v10 9/14 arm_mpam: prepare mon_sel locking for MPAM-Fb
In reply to Andre PrzywaraThe 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.
--- drivers/resctrl/mpam_devices.c | 6 ++++- drivers/resctrl/mpam_internal.h | 43 +++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 8 deletions(-)
drivers/resctrl/mpam_devices.c +5 -1
@@ -2288,7 +2288,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);
@@ -2309,6 +2308,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;
drivers/resctrl/mpam_internal.h +36 -7
69 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v10 10/14 arm_mpam: add MPAM-Fb MSC firmware access support
In reply to Andre PrzywaraThe Arm MPAM Firmware-backed (Fb) Profile document[1] describes an alternative way of accessing the "Memory System Components" (MSC) in an MPAM enabled system.
Normally the MSCs are MMIO mapped, but in some implementations this might not be possible (MSC located outside of the local socket, MSC mapped secure-only) or desirable (direct MMIO access too slow or needs to be mediated through a control processor). MPAM-fb standardises a protocol to abstract MSC accesses, building on the SCMI protocol.
Add functions that do an MSC read or write access by redirecting the request through a firmware interface. For now this done via an ACPI PCC shared memory and mailbox combination.
Since the protocol used is only a small subset of the full SCMI spec, and the SCMI protocol has no full ACPI support anyway, open-code the (simple) SCMI message generation, for just the fields we need.
[1] https://developer.arm.com/documentation/den0144/latest
--- drivers/acpi/arm64/mpam.c | 2 + drivers/resctrl/Kconfig | 1 + drivers/resctrl/Makefile | 2 +- drivers/resctrl/mpam_devices.c | 65 ++++++++-- drivers/resctrl/mpam_fb.c | 211 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 19 +++ include/linux/arm_mpam.h | 2 +- 7 files changed, 288 insertions(+), 14 deletions(-) create mode 100644 drivers/resctrl/mpam_fb.c
drivers/acpi/arm64/mpam.c +2 -0
@@ -256,6 +256,8 @@ static struct platform_device * __init acpi_mpam_parse_msc(struct acpi_mpam_msc_ }else if (iface ==MPAM_IFACE_PCC ) { props[next_prop++] =PROPERTY_ENTRY_U32 ("pcc-channel" , tbl_msc->base_address); + props[next_prop++] =PROPERTY_ENTRY_U32 ("mpam-fb-msc-id" , + tbl_msc->identifier); }acpi_mpam_parse_irqs (pdev, tbl_msc, res, &next_res);
drivers/resctrl/Kconfig +1 -0
@@ -2,6 +2,7 @@ menuconfig ARM64_MPAM_DRIVER bool "MPAM driver" depends on ARM64 && ARM64_MPAM select ACPI_MPAM if ACPI + select MAILBOX help Memory System Resource Partitioning and Monitoring (MPAM) driver for System IP, e.g. caches and memory controllers.
drivers/resctrl/Makefile +1 -1
@@ -1,5 +1,5 @@ obj-$(CONFIG_ARM64_MPAM_DRIVER) += mpam.o -mpam-y += mpam_devices.o +mpam-y += mpam_devices.o mpam_fb.o mpam-$(CONFIG_ARM64_MPAM_RESCTRL_FS) += mpam_resctrl.o ccflags-$(CONFIG_ARM64_MPAM_DRIVER_DEBUG) += -DDEBUG
drivers/resctrl/mpam_devices.c +53 -12
122 lines not on this page · raw message
drivers/resctrl/mpam_fb.c new file +211 -0
211 lines not on this page · raw message
drivers/resctrl/mpam_internal.h +19 -0
@@ -11,6 +11,7 @@#include <linux/io.h> #include <linux/jump_label.h> #include <linux/llist.h> +#include <linux/mailbox_client.h> #include <linux/mutex.h> #include <linux/resctrl.h> #include <linux/spinlock.h>
@@ -57,6 +58,15 @@ struct mpam_garbage {struct platform_device *pdev; }; +struct mpam_pcc_chan { +struct list_head pcc_chans; +struct mbox_client pcc_cl; +struct pcc_mbox_chan *pcc_chan; +struct mutex pcc_chan_lock;/* only one message at a time */ +struct kref refcount; +int subspace_id; +}; +struct mpam_msc {/* member of mpam_all_msc */ struct list_head all_msc_list;
@@ -66,6 +76,8 @@ struct mpam_msc {/* Not modified after mpam_is_enabled() becomes true */ enum mpam_msc_iface iface; +struct mpam_pcc_chan *pcc_chan; +int mpam_fb_msc_id;u32 nrdy_usec;cpumask_t accessibility;bool has_extd_esr;
@@ -493,6 +505,9 @@ extern u8 mpam_pmg_max;void mpam_enable (struct work_struct *work);void mpam_disable (struct work_struct *work); +/* helper function to call from outside mpam_devices.c */ +void mpam_fb_disable_mpam (int err,int mpam_fb_err); +/* Reset all the RIS in a class under cpus_read_lock() */ void mpam_reset_class_locked (struct mpam_class *class);
@@ -520,6 +535,10 @@ static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }static inline void mpam_resctrl_teardown_class (struct mpam_class *class) { }#endif /* CONFIG_RESCTRL_FS */ +/* MPAM-Fb Firmware-backed protocol wrappers */ +int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result); +int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value); +/* * MPAM MSCs have the following register layout. See: * Arm Memory System Resource Partitioning and Monitoring (MPAM) System
include/linux/arm_mpam.h +1 -1
@@ -12,7 +12,7 @@ struct mpam_msc;enum mpam_msc_iface {MPAM_IFACE_MMIO ,/* a real MPAM MSC */ -MPAM_IFACE_PCC ,/* a fake MPAM MSC */ +MPAM_IFACE_PCC ,/* using the MPAM-Fb firmware redirection */ };enum mpam_class_types {
Signature · 1 line
2.43.0
Ben Horgan
maintainerRe: [PATCH v10 10/14] arm_mpam: add MPAM-Fb MSC firmware access support
Hi Andre,
Quoted 279 lines · Andre Przywara
The Arm MPAM Firmware-backed (Fb) Profile document[1] describes an alternative way of accessing the "Memory System Components" (MSC) in an MPAM enabled system.
Normally the MSCs are MMIO mapped, but in some implementations this might not be possible (MSC located outside of the local socket, MSC mapped secure-only) or desirable (direct MMIO access too slow or needs to be mediated through a control processor). MPAM-fb standardises a protocol to abstract MSC accesses, building on the SCMI protocol.
Add functions that do an MSC read or write access by redirecting the request through a firmware interface. For now this done via an ACPI PCC shared memory and mailbox combination.
Since the protocol used is only a small subset of the full SCMI spec, and the SCMI protocol has no full ACPI support anyway, open-code the (simple) SCMI message generation, for just the fields we need.
[1] https://developer.arm.com/documentation/den0144/latest
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Gavin Shan <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>--- drivers/acpi/arm64/mpam.c | 2 + drivers/resctrl/Kconfig | 1 + drivers/resctrl/Makefile | 2 +- drivers/resctrl/mpam_devices.c | 65 ++++++++-- drivers/resctrl/mpam_fb.c | 211 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 19 +++ include/linux/arm_mpam.h | 2 +- 7 files changed, 288 insertions(+), 14 deletions(-) create mode 100644 drivers/resctrl/mpam_fb.cdrivers/acpi/arm64/mpam.c +2
-0@@ -256,6 +256,8 @@ static struct platform_device * __init acpi_mpam_parse_msc(struct acpi_mpam_msc_ }else if (iface ==MPAM_IFACE_PCC ) { props[next_prop++] =PROPERTY_ENTRY_U32 ("pcc-channel" , tbl_msc->base_address); + props[next_prop++] =PROPERTY_ENTRY_U32 ("mpam-fb-msc-id" , + tbl_msc->identifier); }acpi_mpam_parse_irqs (pdev, tbl_msc, res, &next_res);drivers/resctrl/Kconfig +1
-0@@ -2,6 +2,7 @@ menuconfig ARM64_MPAM_DRIVER bool "MPAM driver" depends on ARM64 && ARM64_MPAM select ACPI_MPAM if ACPI + select MAILBOX help Memory System Resource Partitioning and Monitoring (MPAM) driver for System IP, e.g. caches and memory controllers.drivers/resctrl/Makefile +1
-1@@ -1,5 +1,5 @@ obj-$(CONFIG_ARM64_MPAM_DRIVER) += mpam.o -mpam-y += mpam_devices.o +mpam-y += mpam_devices.o mpam_fb.o mpam-$(CONFIG_ARM64_MPAM_RESCTRL_FS) += mpam_resctrl.o ccflags-$(CONFIG_ARM64_MPAM_DRIVER_DEBUG) += -DDEBUGdrivers/resctrl/mpam_devices.c +53
-12@@ -12,6 +12,7 @@#include <linux/cpu.h> #include <linux/cpumask.h> #include <linux/device.h> +#include <linux/errname.h> #include <linux/errno.h> #include <linux/gfp.h> #include <linux/interrupt.h> @@ -82,6 +83,21 @@ static DECLARE_WORK(mpam_broken_work, &mpam_disable);/* When mpam is disabled, the printed reason to aid debugging */ static char *mpam_disable_reason; +static int mpam_disable_errno; +static int mpam_disable_mpam_fb_err; + +void mpam_fb_disable_mpam (int err,int mpam_fb_err) +{ +/* Prevent repeated calls when mpam_disable() does MSC accesses. */ +if (!mpam_is_enabled ()) +return ; + + mpam_disable_errno = err; + mpam_disable_mpam_fb_err = mpam_fb_err; + + mpam_disable_reason ="MPAM-Fb error" ; +schedule_work (&mpam_broken_work); +}/* * Whether resctrl has been setup. Used by cpuhp in preference to @@ -179,8 +195,11 @@ static void mpam_assert_partid_sizes_fixed(void)static int __mpam_read_reg (struct mpam_msc *msc,u16 reg,u32 *res) { -WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); +if (msc->iface ==MPAM_IFACE_PCC ) +return mpam_fb_send_read_request (msc, reg, res); + +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); *res =readl_relaxed (msc->mapped_hwpage + reg);return 0 ;@@ -197,9 +216,12 @@ static inline int _mpam_read_partsel_reg(struct mpam_msc *msc, u16 reg,static int __mpam_write_reg (struct mpam_msc *msc,u16 reg,u32 val) { -WARN_ON_ONCE (reg +sizeof (u32) > msc->mapped_hwpage_sz); -WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); +if (msc->iface ==MPAM_IFACE_PCC ) +return mpam_fb_send_write_request (msc, reg, val); + +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); +WARN_ON_ONCE (reg +sizeof (u32) > msc->mapped_hwpage_sz);writel_relaxed (val, msc->mapped_hwpage + reg);return 0 ;@@ -1143,8 +1165,11 @@ static int mpam_msc_read_mbwu_l(struct mpam_msc *msc, u64 *res)mpam_mon_sel_lock_held (msc); -WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz); -WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); +if (msc->iface ==MPAM_IFACE_MMIO ) { +WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz); +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), + &msc->accessibility)); + } ret =__mpam_read_reg (msc,MSMON_MBWU_L +4 , &mbwu_l_high2);if (ret)@@ -1178,8 +1203,11 @@ static int mpam_msc_zero_mbwu_l(struct mpam_msc *msc)mpam_mon_sel_lock_held (msc); -WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz); -WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); +if (msc->iface ==MPAM_IFACE_MMIO ) { +WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz); +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), + &msc->accessibility)); + } ret =__mpam_write_reg (msc,MSMON_MBWU_L ,0 );if (ret)@@ -1490,11 +1518,16 @@ static int _msmon_read(struct mpam_component *comp, struct mon_read *arg) srcu_read_lock_held(&mpam_srcu)) { arg->ris = ris; - err =smp_call_function_any (&msc->accessibility, - __ris_msmon_read, arg, - true); -if (!err && arg->err) +if (msc->iface ==MPAM_IFACE_MMIO ) { + err =smp_call_function_any (&msc->accessibility, + __ris_msmon_read, + arg, true); +if (!err) + err = arg->err; + }else { +__ris_msmon_read (arg); err = arg->err; + }/* * Save one error to be returned to the caller, but @@ -1977,6 +2010,9 @@ static int mpam_get_msc_preferred_cpu(struct mpam_msc *msc)static int mpam_touch_msc (struct mpam_msc *msc,int (*fn)(void *a),void *arg) { +if (msc->iface !=MPAM_IFACE_MMIO ) +return fn (arg); +lockdep_assert_irqs_enabled ();lockdep_assert_cpus_held ();WARN_ON_ONCE (!srcu_read_lock_held ((&mpam_srcu)));@@ -3090,7 +3126,12 @@ void mpam_disable(struct work_struct *ignored)mutex_unlock (&mpam_list_lock);mpam_free_garbage (); -pr_err_once ("MPAM disabled due to %s\n" , mpam_disable_reason); +if (mpam_disable_errno || mpam_disable_mpam_fb_err) +pr_err_once ("MPAM disabled due to %s: %s, MPAM-Fb error %d\n" , + mpam_disable_reason,errname (mpam_disable_errno), + mpam_disable_mpam_fb_err); +else +pr_err_once ("MPAM disabled due to %s\n" , mpam_disable_reason); }/* drivers/resctrl/mpam_fb.c new file +66
-0@@ -0,0 +1,211 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2024-2026 Arm Ltd. + +#include <linux/arm_mpam.h> +#include <linux/cleanup.h> +#include <linux/errno.h> +#include <linux/mailbox_client.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/types.h> + +#include <acpi/pcc.h> +#include <asm/mpam.h> + +#include "mpam_internal.h" + +#define MPAM_MSC_TOKEN_MASK GENMASK_U32(27, 18) +#define MPAM_MSC_PROT_ID_MASK GENMASK_U32(17, 10) + +#define MPAM_FB_PROTOCOL_ID 0x1a + +#define MPAM_PROTOCOL_VERSION_CMD 0x0 +#define MPAM_MSC_READ_CMD 0x4 +#define MPAM_MSC_WRITE_CMD 0x5 + +#define MPAM_FB_PROT_HEADER_LEN sizeof(u32) + +#define MPAM_FB_SUCCESS 0 +#define MPAM_FB_ERR_NOT_SUPPORTED -1 +#define MPAM_FB_ERR_INVALID_PARAMETERS -2 +#define MPAM_FB_ERR_DENIED -3 +#define MPAM_FB_ERR_NOT_FOUND -4 +#define MPAM_FB_ERR_OUT_OF_RANGE -5 +#define MPAM_FB_ERR_BUSY -6 +#define MPAM_FB_ERR_COMMS_ERROR -7 +#define MPAM_FB_ERR_GENERIC_ERROR -8 +#define MPAM_FB_ERR_HW_ERROR -9 +#define MPAM_FB_ERR_PROTOCOL_ERROR -10 +#define MPAM_FB_ERR_IN_USE -11 + +static atomic_t mpam_fb_token =ATOMIC_INIT (0 ); + +static int mpam_fb_to_linux_errno (int mpam_fb_code) +{ +switch (mpam_fb_code) { +case MPAM_FB_ERR_NOT_SUPPORTED : +return -EOPNOTSUPP ; +case MPAM_FB_ERR_INVALID_PARAMETERS : +return -EINVAL ; +case MPAM_FB_ERR_NOT_FOUND : +return -ENOENT ; +case MPAM_FB_ERR_OUT_OF_RANGE : +return -ERANGE ; +case MPAM_FB_ERR_BUSY : +return -EBUSY ; +default : +return -EINVAL ; + } +} + +static void mpam_fb_build_version_message (unsigned int token, +void __iomem *msg_buf) +{ +struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_shmem = msg_buf; + +/* .signature is filled by the platform */
drivers/resctrl/mpam_fb.c line 76
Quoted 10 lines
drivers/resctrl/mpam_fb.c new file +10
-0+writel_relaxed (PCC_CMD_COMPLETION_NOTIFY , &pcc_shmem->flags); +writel_relaxed (MPAM_FB_PROT_HEADER_LEN , &pcc_shmem->length); +writel_relaxed (MPAM_PROTOCOL_VERSION_CMD | +FIELD_PREP (MPAM_MSC_TOKEN_MASK , token) | +FIELD_PREP (MPAM_MSC_PROT_ID_MASK ,MPAM_FB_PROTOCOL_ID ), + &pcc_shmem->command); +} + +static void mpam_fb_build_read_message (int msc_id,int reg,unsigned int token, +void __iomem *msg_buf)
As we're anticipating that msc_id may be different from msc->id can be use msc_fb_id instead of msc_id in this file.
Thanks,
Ben
Quoted 206 lines
drivers/resctrl/mpam_fb.c new file +135
-0+{ +struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_shmem = msg_buf; +struct mpam_fb_read_payload { +u32 msc_id; +u32 flags; +u32 reg_offset; + } __packed __iomem *payload = msg_buf + sizeof(*pcc_shmem); +int msg_size =MPAM_FB_PROT_HEADER_LEN +sizeof (*payload); + +/* .signature is filled by the platform */ +writel_relaxed (PCC_CMD_COMPLETION_NOTIFY , &pcc_shmem->flags); +writel_relaxed (msg_size, &pcc_shmem->length); +writel_relaxed (MPAM_MSC_READ_CMD | +FIELD_PREP (MPAM_MSC_TOKEN_MASK , token) | +FIELD_PREP (MPAM_MSC_PROT_ID_MASK ,MPAM_FB_PROTOCOL_ID ), + &pcc_shmem->command); + +writel_relaxed (msc_id, &payload->msc_id); +writel_relaxed (0 , &payload->flags); +writel_relaxed (reg, &payload->reg_offset); +} + +static void mpam_fb_build_write_message (int msc_id,int reg,u32 val, +unsigned int token, +void __iomem *msg_buf) +{ +struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_shmem = msg_buf; +struct mpam_fb_write_payload { +u32 msc_id; +u32 flags; +u32 reg_offset; +u32 value; + } __packed __iomem *payload = msg_buf + sizeof(*pcc_shmem); +int msg_size =MPAM_FB_PROT_HEADER_LEN +sizeof (*payload); + +/* .signature is filled by the platform */ +writel_relaxed (PCC_CMD_COMPLETION_NOTIFY , &pcc_shmem->flags); +writel_relaxed (msg_size, &pcc_shmem->length); +writel_relaxed (MPAM_MSC_WRITE_CMD | +FIELD_PREP (MPAM_MSC_TOKEN_MASK , token) | +FIELD_PREP (MPAM_MSC_PROT_ID_MASK ,MPAM_FB_PROTOCOL_ID ), + &pcc_shmem->command); + +writel_relaxed (msc_id, &payload->msc_id); +writel_relaxed (0 , &payload->flags); +writel_relaxed (reg, &payload->reg_offset); +writel_relaxed (val, &payload->value); +} + +static int mpam_fb_send_request (struct mpam_msc *msc,u32 msc_id, +u16 reg,u32 *result,int mpam_fb_command) +{ +unsigned int token =atomic_inc_return (&mpam_fb_token); +struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_shmem; +struct mpam_pcc_chan *pcc_chan; +struct pcc_mbox_chan *chan; +void __iomem *payload_ofs; +int mpam_fb_err =0 ; +u32 status; +int ret; + + pcc_chan = msc->pcc_chan; +if (!pcc_chan) +return -ENODEV ; + + chan = pcc_chan->pcc_chan; + +/* prune token to fit into the 10 bits inside the command register */ + token =FIELD_GET (MPAM_MSC_TOKEN_MASK , +FIELD_PREP (MPAM_MSC_TOKEN_MASK , token)); + +mutex_lock (&pcc_chan->pcc_chan_lock); + +switch (mpam_fb_command) { +case MPAM_PROTOCOL_VERSION_CMD : +mpam_fb_build_version_message (token, chan->shmem); +break ; +case MPAM_MSC_READ_CMD : +mpam_fb_build_read_message (msc_id, reg, token, chan->shmem); +break ; +case MPAM_MSC_WRITE_CMD : +mpam_fb_build_write_message (msc_id, reg, *result, + token, chan->shmem); +break ; +default : +dev_err (&msc->pdev->dev,"unsupported MPAM-Fb command %d\n" , + mpam_fb_command); + ret = -EINVAL ; + goto out_err; + } + + ret =mbox_send_message (chan->mchan,NULL ); +if (ret <0 ) + goto out_err; + + pcc_shmem = chan->shmem; + payload_ofs = chan->shmem +sizeof (*pcc_shmem); + status =readl (&pcc_shmem->command); +if (FIELD_GET (MPAM_MSC_TOKEN_MASK , status) != token) { + ret = -ETIMEDOUT ; + goto out_err; + } + + mpam_fb_err =readl (payload_ofs +0x0 ); +if (mpam_fb_err <0 ) { + ret =mpam_fb_to_linux_errno (mpam_fb_err); + goto out_err; + } + +if (mpam_fb_command !=MPAM_MSC_WRITE_CMD ) + *result =readl (payload_ofs +0x4 ); + +mutex_unlock (&pcc_chan->pcc_chan_lock); + +return 0 ; + +out_err: +mutex_unlock (&pcc_chan->pcc_chan_lock); + +mpam_fb_disable_mpam (ret, mpam_fb_err); + +return ret; +} + +int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result) +{ +return mpam_fb_send_request (msc, msc->mpam_fb_msc_id, reg, result, +MPAM_MSC_READ_CMD ); +} + +int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value) +{ +return mpam_fb_send_request (msc, msc->mpam_fb_msc_id, reg, &value, +MPAM_MSC_WRITE_CMD ); +}drivers/resctrl/mpam_internal.h +19
-0@@ -11,6 +11,7 @@#include <linux/io.h> #include <linux/jump_label.h> #include <linux/llist.h> +#include <linux/mailbox_client.h> #include <linux/mutex.h> #include <linux/resctrl.h> #include <linux/spinlock.h> @@ -57,6 +58,15 @@ struct mpam_garbage {struct platform_device *pdev; }; +struct mpam_pcc_chan { +struct list_head pcc_chans; +struct mbox_client pcc_cl; +struct pcc_mbox_chan *pcc_chan; +struct mutex pcc_chan_lock;/* only one message at a time */ +struct kref refcount; +int subspace_id; +}; +struct mpam_msc {/* member of mpam_all_msc */ struct list_head all_msc_list;@@ -66,6 +76,8 @@ struct mpam_msc {/* Not modified after mpam_is_enabled() becomes true */ enum mpam_msc_iface iface; +struct mpam_pcc_chan *pcc_chan; +int mpam_fb_msc_id;u32 nrdy_usec;cpumask_t accessibility;bool has_extd_esr;@@ -493,6 +505,9 @@ extern u8 mpam_pmg_max;void mpam_enable (struct work_struct *work);void mpam_disable (struct work_struct *work); +/* helper function to call from outside mpam_devices.c */ +void mpam_fb_disable_mpam (int err,int mpam_fb_err); +/* Reset all the RIS in a class under cpus_read_lock() */ void mpam_reset_class_locked (struct mpam_class *class);@@ -520,6 +535,10 @@ static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }static inline void mpam_resctrl_teardown_class (struct mpam_class *class) { }#endif /* CONFIG_RESCTRL_FS */ +/* MPAM-Fb Firmware-backed protocol wrappers */ +int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result); +int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value); +/* * MPAM MSCs have the following register layout. See: * Arm Memory System Resource Partitioning and Monitoring (MPAM) System include/linux/arm_mpam.h +1
-1@@ -12,7 +12,7 @@ struct mpam_msc;enum mpam_msc_iface {MPAM_IFACE_MMIO ,/* a real MPAM MSC */ -MPAM_IFACE_PCC ,/* a fake MPAM MSC */ +MPAM_IFACE_PCC ,/* using the MPAM-Fb firmware redirection */ };enum mpam_class_types {
Re: [PATCH v10 10/14] arm_mpam: add MPAM-Fb MSC firmware access support
Hi Ben,
thanks for having a look ;-)
Quoted 39 lines · Ben Horgan
Hi Andre,
Quoted 36 lines · Andre Przywara
The Arm MPAM Firmware-backed (Fb) Profile document[1] describes an alternative way of accessing the "Memory System Components" (MSC) in an MPAM enabled system.
Normally the MSCs are MMIO mapped, but in some implementations this might not be possible (MSC located outside of the local socket, MSC mapped secure-only) or desirable (direct MMIO access too slow or needs to be mediated through a control processor). MPAM-fb standardises a protocol to abstract MSC accesses, building on the SCMI protocol.
Add functions that do an MSC read or write access by redirecting the request through a firmware interface. For now this done via an ACPI PCC shared memory and mailbox combination.
Since the protocol used is only a small subset of the full SCMI spec, and the SCMI protocol has no full ACPI support anyway, open-code the (simple) SCMI message generation, for just the fields we need.
[1] https://developer.arm.com/documentation/den0144/latest
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Gavin Shan <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>--- drivers/acpi/arm64/mpam.c | 2 + drivers/resctrl/Kconfig | 1 + drivers/resctrl/Makefile | 2 +- drivers/resctrl/mpam_devices.c | 65 ++++++++-- drivers/resctrl/mpam_fb.c | 211 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 19 +++ include/linux/arm_mpam.h | 2 +- 7 files changed, 288 insertions(+), 14 deletions(-)create mode 100644
drivers/resctrl/mpam_fb.c
[ ... ]
Quoted 77 lines
Quoted 77 lines
drivers/resctrl/mpam_fb.c new file +71
-0@@ -0,0 +1,211 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2024-2026 Arm Ltd. + +#include <linux/arm_mpam.h> +#include <linux/cleanup.h> +#include <linux/errno.h> +#include <linux/mailbox_client.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/types.h> + +#include <acpi/pcc.h> +#include <asm/mpam.h> + +#include "mpam_internal.h" + +#define MPAM_MSC_TOKEN_MASK GENMASK_U32(27, 18) +#define MPAM_MSC_PROT_ID_MASK GENMASK_U32(17, 10) + +#define MPAM_FB_PROTOCOL_ID 0x1a + +#define MPAM_PROTOCOL_VERSION_CMD 0x0 +#define MPAM_MSC_READ_CMD 0x4 +#define MPAM_MSC_WRITE_CMD 0x5 + +#define MPAM_FB_PROT_HEADER_LEN sizeof(u32) + +#define MPAM_FB_SUCCESS 0 +#define MPAM_FB_ERR_NOT_SUPPORTED -1 +#define MPAM_FB_ERR_INVALID_PARAMETERS -2 +#define MPAM_FB_ERR_DENIED -3 +#define MPAM_FB_ERR_NOT_FOUND -4 +#define MPAM_FB_ERR_OUT_OF_RANGE -5 +#define MPAM_FB_ERR_BUSY -6 +#define MPAM_FB_ERR_COMMS_ERROR -7 +#define MPAM_FB_ERR_GENERIC_ERROR -8 +#define MPAM_FB_ERR_HW_ERROR -9 +#define MPAM_FB_ERR_PROTOCOL_ERROR -10 +#define MPAM_FB_ERR_IN_USE -11 + +static atomic_t mpam_fb_token =ATOMIC_INIT (0 ); + +static int mpam_fb_to_linux_errno (int mpam_fb_code) +{ +switch (mpam_fb_code) { +case MPAM_FB_ERR_NOT_SUPPORTED : +return -EOPNOTSUPP ; +case MPAM_FB_ERR_INVALID_PARAMETERS : +return -EINVAL ; +case MPAM_FB_ERR_NOT_FOUND : +return -ENOENT ; +case MPAM_FB_ERR_OUT_OF_RANGE : +return -ERANGE ; +case MPAM_FB_ERR_BUSY : +return -EBUSY ; +default : +return -EINVAL ; + } +} + +static void mpam_fb_build_version_message (unsigned int token, +void __iomem *msg_buf) +{ +struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_shmem = msg_buf; + +/* .signature is filled by the platform */ +writel_relaxed (PCC_CMD_COMPLETION_NOTIFY , &pcc_shmem->flags); +writel_relaxed (MPAM_FB_PROT_HEADER_LEN , &pcc_shmem->length); + writel_relaxed(MPAM_PROTOCOL_VERSION_CMD | + FIELD_PREP(MPAM_MSC_TOKEN_MASK, token) | + FIELD_PREP(MPAM_MSC_PROT_ID_MASK, MPAM_FB_PROTOCOL_ID),
Quoted 8 lines
drivers/resctrl/mpam_fb.c line 76
Quoted 5 lines
drivers/resctrl/mpam_fb.c new file +5
-0+ &pcc_shmem->command); +} + +static void mpam_fb_build_read_message (int msc_id,int reg,unsigned int token, +void __iomem *msg_buf)As we're anticipating that
msc_idmay be different frommsc->idcan be usemsc_fb_idinstead ofmsc_idin this file.
Yes, that's a good idea, changed that.
Cheers,
Andre
Quoted 207 lines
Quoted 206 lines
drivers/resctrl/mpam_fb.c new file +135
-0+{ +struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_shmem = msg_buf; +struct mpam_fb_read_payload { +u32 msc_id; +u32 flags; +u32 reg_offset; + } __packed __iomem *payload = msg_buf + sizeof(*pcc_shmem); +int msg_size =MPAM_FB_PROT_HEADER_LEN +sizeof (*payload); + +/* .signature is filled by the platform */ +writel_relaxed (PCC_CMD_COMPLETION_NOTIFY , &pcc_shmem->flags); +writel_relaxed (msg_size, &pcc_shmem->length); +writel_relaxed (MPAM_MSC_READ_CMD | +FIELD_PREP (MPAM_MSC_TOKEN_MASK , token) | +FIELD_PREP (MPAM_MSC_PROT_ID_MASK ,MPAM_FB_PROTOCOL_ID ), + &pcc_shmem->command); + +writel_relaxed (msc_id, &payload->msc_id); +writel_relaxed (0 , &payload->flags); +writel_relaxed (reg, &payload->reg_offset); +} + +static void mpam_fb_build_write_message (int msc_id,int reg,u32 val, +unsigned int token, +void __iomem *msg_buf) +{ +struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_shmem = msg_buf; +struct mpam_fb_write_payload { +u32 msc_id; +u32 flags; +u32 reg_offset; +u32 value; + } __packed __iomem *payload = msg_buf + sizeof(*pcc_shmem); +int msg_size =MPAM_FB_PROT_HEADER_LEN +sizeof (*payload); + +/* .signature is filled by the platform */ +writel_relaxed (PCC_CMD_COMPLETION_NOTIFY , &pcc_shmem->flags); +writel_relaxed (msg_size, &pcc_shmem->length); +writel_relaxed (MPAM_MSC_WRITE_CMD | +FIELD_PREP (MPAM_MSC_TOKEN_MASK , token) | +FIELD_PREP (MPAM_MSC_PROT_ID_MASK ,MPAM_FB_PROTOCOL_ID ), + &pcc_shmem->command); + +writel_relaxed (msc_id, &payload->msc_id); +writel_relaxed (0 , &payload->flags); +writel_relaxed (reg, &payload->reg_offset); +writel_relaxed (val, &payload->value); +} + +static int mpam_fb_send_request (struct mpam_msc *msc,u32 msc_id, +u16 reg,u32 *result,int mpam_fb_command) +{ +unsigned int token =atomic_inc_return (&mpam_fb_token); +struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_shmem; +struct mpam_pcc_chan *pcc_chan; +struct pcc_mbox_chan *chan; +void __iomem *payload_ofs; +int mpam_fb_err =0 ; +u32 status; +int ret; + + pcc_chan = msc->pcc_chan; +if (!pcc_chan) +return -ENODEV ; + + chan = pcc_chan->pcc_chan; + +/* prune token to fit into the 10 bits inside the command register */ + token =FIELD_GET (MPAM_MSC_TOKEN_MASK , +FIELD_PREP (MPAM_MSC_TOKEN_MASK , token)); + +mutex_lock (&pcc_chan->pcc_chan_lock); + +switch (mpam_fb_command) { +case MPAM_PROTOCOL_VERSION_CMD : +mpam_fb_build_version_message (token, chan->shmem); +break ; +case MPAM_MSC_READ_CMD : +mpam_fb_build_read_message (msc_id, reg, token, chan->shmem); +break ; +case MPAM_MSC_WRITE_CMD : +mpam_fb_build_write_message (msc_id, reg, *result, + token, chan->shmem); +break ; +default : +dev_err (&msc->pdev->dev,"unsupported MPAM-Fb command %d\n" , + mpam_fb_command); + ret = -EINVAL ; + goto out_err; + } + + ret =mbox_send_message (chan->mchan,NULL ); +if (ret <0 ) + goto out_err; + + pcc_shmem = chan->shmem; + payload_ofs = chan->shmem +sizeof (*pcc_shmem); + status =readl (&pcc_shmem->command); +if (FIELD_GET (MPAM_MSC_TOKEN_MASK , status) != token) { + ret = -ETIMEDOUT ; + goto out_err; + } + + mpam_fb_err =readl (payload_ofs +0x0 ); +if (mpam_fb_err <0 ) { + ret =mpam_fb_to_linux_errno (mpam_fb_err); + goto out_err; + } + +if (mpam_fb_command !=MPAM_MSC_WRITE_CMD ) + *result =readl (payload_ofs +0x4 ); + +mutex_unlock (&pcc_chan->pcc_chan_lock); + +return 0 ; + +out_err: +mutex_unlock (&pcc_chan->pcc_chan_lock); + +mpam_fb_disable_mpam (ret, mpam_fb_err); + +return ret; +} + +int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result) +{ +return mpam_fb_send_request (msc, msc->mpam_fb_msc_id, reg, result, +MPAM_MSC_READ_CMD ); +} + +int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value) +{ +return mpam_fb_send_request (msc, msc->mpam_fb_msc_id, reg, &value, +MPAM_MSC_WRITE_CMD ); +}drivers/resctrl/mpam_internal.h +19
-0@@ -11,6 +11,7 @@#include <linux/io.h> #include <linux/jump_label.h> #include <linux/llist.h> +#include <linux/mailbox_client.h> #include <linux/mutex.h> #include <linux/resctrl.h> #include <linux/spinlock.h> @@ -57,6 +58,15 @@ struct mpam_garbage {struct platform_device *pdev; }; +struct mpam_pcc_chan { +struct list_head pcc_chans; +struct mbox_client pcc_cl; +struct pcc_mbox_chan *pcc_chan; +struct mutex pcc_chan_lock;/* only one message at a time */ +struct kref refcount; +int subspace_id; +}; +struct mpam_msc {/* member of mpam_all_msc */ struct list_head all_msc_list;@@ -66,6 +76,8 @@ struct mpam_msc {/* Not modified after mpam_is_enabled() becomes true */ enum mpam_msc_iface iface; +struct mpam_pcc_chan *pcc_chan; +int mpam_fb_msc_id;u32 nrdy_usec;cpumask_t accessibility;bool has_extd_esr;@@ -493,6 +505,9 @@ extern u8 mpam_pmg_max;void mpam_enable (struct work_struct *work);void mpam_disable (struct work_struct *work); +/* helper function to call from outside mpam_devices.c */ +void mpam_fb_disable_mpam (int err,int mpam_fb_err); +/* Reset all the RIS in a class under cpus_read_lock() */ void mpam_reset_class_locked (struct mpam_class *class);@@ -520,6 +535,10 @@ static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }static inline void mpam_resctrl_teardown_class (struct mpam_class *class) { }#endif /* CONFIG_RESCTRL_FS */ +/* MPAM-Fb Firmware-backed protocol wrappers */ +int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result); +int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value); +/* * MPAM MSCs have the following register layout. See: * Arm Memory System Resource Partitioning and Monitoring (MPAM) System include/linux/arm_mpam.h +1
-1@@ -12,7 +12,7 @@ struct mpam_msc;enum mpam_msc_iface {MPAM_IFACE_MMIO ,/* a real MPAM MSC */ -MPAM_IFACE_PCC ,/* a fake MPAM MSC */ +MPAM_IFACE_PCC ,/* using the MPAM-Fb firmware redirection */ };enum mpam_class_types {
PATCH v10 11/14 arm_mpam: change MPAM-Fb error IRQ to use a threaded IRQ handler
In reply to Andre PrzywaraWhen 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.
--- drivers/resctrl/mpam_devices.c | 77 ++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 12 deletions(-)
drivers/resctrl/mpam_devices.c +65 -12
@@ -2721,24 +2721,42 @@ static int mpam_disable_msc_ecr(void *_msc)return __mpam_write_reg (msc,MPAMF_ECR ,0 ); } +/* +* 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, ®); + ret =mpam_msc_read_esr (msc, ®); +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);
@@ -2749,16 +2767,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);
@@ -2773,10 +2799,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); }
@@ -2797,6 +2843,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);
@@ -2808,9 +2859,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; }
Signature · 1 line
2.43.0
PATCH v10 12/14 arm_mpam: detect and enable MPAM-Fb PCC support
In reply to Andre PrzywaraThe Arm MPAM-Fb specification [1] describes a protocol to access MSC registers through a firmware interface. This requires a shared memory region to hold the message, and a mailbox to trigger the access. For ACPI this is wrapped as a PCC channel, described using existing ACPI abstractions.
Add code to parse those PCC table descriptions associated with an MSC, and store the parsed information in the MSC struct.
There can be multiple PCC channels, and each channel can serve multiple MSCs, so we need to keep track of the channel usage, using a list and a refcount.
This will be used by the MPAM-Fb access wrapper code.
[1] https://developer.arm.com/documentation/den0144/latest
--- drivers/resctrl/Kconfig | 1 + drivers/resctrl/mpam_devices.c | 119 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_fb.c | 41 +++++++++++ drivers/resctrl/mpam_internal.h | 2 + 4 files changed, 161 insertions(+), 2 deletions(-)
drivers/resctrl/Kconfig +1 -0
@@ -2,6 +2,7 @@ menuconfig ARM64_MPAM_DRIVER bool "MPAM driver" depends on ARM64 && ARM64_MPAM select ACPI_MPAM if ACPI + select PCC if ACPI select MAILBOX help Memory System Resource Partitioning and Monitoring (MPAM) driver for
drivers/resctrl/mpam_devices.c +117 -2
163 lines not on this page · raw message
drivers/resctrl/mpam_fb.c +41 -0
54 lines not on this page · raw message
drivers/resctrl/mpam_internal.h +2 -0
@@ -538,6 +538,8 @@ static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }/* MPAM-Fb Firmware-backed protocol wrappers */ int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result);int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value); +int mpam_fb_check_protocol_version (struct mpam_msc *msc); +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc);/* * MPAM MSCs have the following register layout. See:
Signature · 1 line
2.43.0
Ben Horgan
maintainerRe: [PATCH v10 12/14] arm_mpam: detect and enable MPAM-Fb PCC support
Hi Andre,
Quoted 201 lines · Andre Przywara
The Arm MPAM-Fb specification [1] describes a protocol to access MSC registers through a firmware interface. This requires a shared memory region to hold the message, and a mailbox to trigger the access. For ACPI this is wrapped as a PCC channel, described using existing ACPI abstractions.
Add code to parse those PCC table descriptions associated with an MSC, and store the parsed information in the MSC struct.
There can be multiple PCC channels, and each channel can serve multiple MSCs, so we need to keep track of the channel usage, using a list and a refcount.This will be used by the MPAM-Fb access wrapper code.
[1] https://developer.arm.com/documentation/den0144/latest
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Tested-by Srivathsa L Rao <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>Reviewed-by Gavin Shan <[email protected]>--- drivers/resctrl/Kconfig | 1 + drivers/resctrl/mpam_devices.c | 119 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_fb.c | 41 +++++++++++ drivers/resctrl/mpam_internal.h | 2 + 4 files changed, 161 insertions(+), 2 deletions(-)drivers/resctrl/Kconfig +1
-0@@ -2,6 +2,7 @@ menuconfig ARM64_MPAM_DRIVER bool "MPAM driver" depends on ARM64 && ARM64_MPAM select ACPI_MPAM if ACPI + select PCC if ACPI select MAILBOX help Memory System Resource Partitioning and Monitoring (MPAM) driver fordrivers/resctrl/mpam_devices.c +107
-2@@ -20,14 +20,19 @@#include <linux/irqdesc.h> #include <linux/list.h> #include <linux/lockdep.h> +#include <linux/mailbox_client.h> #include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <linux/property.h> #include <linux/srcu.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/workqueue.h> +#include <acpi/pcc.h> +#include <acpi/acpi_io.h> +#include "mpam_internal.h" /* Values for the T241 errata workaround */ @@ -50,6 +55,87 @@ static LIST_HEAD(mpam_all_msc);struct srcu_struct mpam_srcu; +/* PCC channels might be serving multiple MSCs, so keep a refcounted list. */ +static DEFINE_MUTEX (pcc_chan_list_lock); +static LIST_HEAD (pcc_chan_list); + +static void mpam_pcc_chan_release (struct kref *ref) +{ + struct mpam_pcc_chan *cur = container_of(ref, struct mpam_pcc_chan, + refcount); + +pcc_mbox_free_channel (cur->pcc_chan); +list_del (&cur->pcc_chans); +mutex_destroy (&cur->pcc_chan_lock); +kfree (cur); +} + +static struct mpam_pcc_chan *mpam_pcc_chan_get (struct device *dev, +int subspace_id) +{ +struct mpam_pcc_chan *cur; + +guard (mutex)(&pcc_chan_list_lock); + +list_for_each_entry (cur, &pcc_chan_list, pcc_chans) { +if (cur->subspace_id == subspace_id) { +kref_get (&cur->refcount); + +return cur; + } + } + + cur =kzalloc_obj (*cur); +if (!cur) +return ERR_PTR (-ENOMEM ); + + cur->pcc_cl.tx_block = true; + + cur->pcc_chan =pcc_mbox_request_channel (&cur->pcc_cl, subspace_id); +if (IS_ERR (cur->pcc_chan)) { +long err =PTR_ERR (cur->pcc_chan); + +kfree (cur); +return ERR_PTR (err); + } + +/* +* Timeout based on the "nominal latency" in us, from the +* PCC ACPI table. tx_tout is in ms. +* Add some margin here to be on the safe side. +*/ + cur->pcc_cl.tx_tout =DIV_ROUND_UP (cur->pcc_chan->latency *5 ,1000 ); + +mutex_init (&cur->pcc_chan_lock); + + cur->subspace_id = subspace_id; +kref_init (&cur->refcount); + +list_add_tail (&cur->pcc_chans, &pcc_chan_list); + +return cur; +} + +static int mpam_pcc_chan_put (struct mpam_pcc_chan *pcc_chan) +{ +struct mpam_pcc_chan *cur, *tmp; + +if (!pcc_chan) +return 0 ; + +guard (mutex)(&pcc_chan_list_lock); + +list_for_each_entry_safe (cur, tmp, &pcc_chan_list, pcc_chans) { +if (cur == pcc_chan) { +kref_put (&cur->refcount, mpam_pcc_chan_release); + +return 0 ; + } + } + +return -ENOENT ; +} +/* * Number of MSCs that have been probed. Once all MSCs have been probed MPAM * can be enabled. @@ -2285,6 +2371,8 @@ static void mpam_msc_drv_remove(struct platform_device *pdev)if (!msc)return ; +mpam_pcc_chan_put (msc->pcc_chan); +mutex_lock (&mpam_list_lock);mpam_msc_destroy (msc);mutex_unlock (&mpam_list_lock);@@ -2295,7 +2383,7 @@ static void mpam_msc_drv_remove(struct platform_device *pdev)static struct mpam_msc *do_mpam_msc_drv_probe (struct platform_device *pdev) {int err; -u32 tmp; +u32 pcc_subspace_id;struct mpam_msc *msc;struct resource *msc_res;struct device *dev = &pdev->dev;@@ -2339,7 +2427,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)if (err)return ERR_PTR (err); -if (device_property_read_u32 (&pdev->dev,"pcc-channel" , &tmp)) +if (device_property_read_u32 (dev,"pcc-channel" , &pcc_subspace_id)) msc->iface =MPAM_IFACE_MMIO ;else msc->iface =MPAM_IFACE_PCC ;@@ -2360,6 +2448,33 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) } msc->mapped_hwpage_sz = msc_res->end - msc_res->start; msc->mapped_hwpage = io; + }else if (msc->iface ==MPAM_IFACE_PCC ) { +u32 mpam_fb_msc_id; + + msc->pcc_chan =mpam_pcc_chan_get (dev, pcc_subspace_id); +if (IS_ERR (msc->pcc_chan)) { +pr_err ("Failed to request MSC PCC channel\n" ); +return ERR_CAST (msc->pcc_chan); + } + + err =mpam_fb_check_shared_buffer_size (msc); +if (err) { +mpam_pcc_chan_put (msc->pcc_chan); + +return ERR_PTR (err); + } + + err =mpam_fb_check_protocol_version (msc);
drivers/resctrl/mpam_devices.c static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) · line 2477
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+if (err) { +mpam_pcc_chan_put (msc->pcc_chan); + +return ERR_PTR (err); + } + +if (device_property_read_u32 (&pdev->dev,"mpam-fb-msc-id" , + &mpam_fb_msc_id)) + mpam_fb_msc_id = msc->id; + msc->mpam_fb_msc_id = mpam_fb_msc_id;
This looks like the change earlier in the series to drivers/acpi/arm64/mpam.c makes no functional effect unless the proposed spec changes are accepted; the default is msc->id. I'd just move the earlier drivers/acpi/arm64/mpam.c to your last patch and introduce this device_property_read_u32() their too (or a separate patch if it's easier for anyone). That way all but the last two patches can be considered for merging without knowing what's going to happen with the spec.
The struct msc property mpam_fb_msc_id is a bit long. Better as msc->fb_id?
Thanks,
Ben
Quoted 76 lines
drivers/resctrl/mpam_devices.c +0
-0}else {return ERR_PTR (-EINVAL ); }drivers/resctrl/mpam_fb.c +41
-0@@ -20,10 +20,15 @@#define MPAM_FB_PROTOCOL_ID 0x1a#define MPAM_PROTOCOL_VERSION_CMD 0x0 +#define MPAM_FB_VERSION_MAJOR_MASK GENMASK_U32(31, 16) +#define MPAM_FB_VERSION_MINOR_MASK GENMASK_U32(15, 0) +#define MPAM_MSC_READ_CMD 0x4#define MPAM_MSC_WRITE_CMD 0x5#define MPAM_FB_PROT_HEADER_LEN sizeof(u32) +/* The longest message is MPAM_MSC_WRITE, with 4 parameters. */ +#define MPAM_FB_MAX_MSG_SIZE (4 * sizeof(u32))#define MPAM_FB_SUCCESS 0#define MPAM_FB_ERR_NOT_SUPPORTED -1@@ -209,3 +214,39 @@ int mpam_fb_send_write_request(struct mpam_msc *msc, u16 reg, u32 value)return mpam_fb_send_request (msc, msc->mpam_fb_msc_id, reg, &value,MPAM_MSC_WRITE_CMD ); } + +/* We only support MPAM-Fb protocol version 1.x */ +int mpam_fb_check_protocol_version (struct mpam_msc *msc) +{ +u32 version; +int ret; + + ret =mpam_fb_send_request (msc,0 ,0 , &version, +MPAM_PROTOCOL_VERSION_CMD ); +if (ret) +return ret; + +if (FIELD_GET (MPAM_FB_VERSION_MAJOR_MASK , version) !=1 ) { +pr_err ("Incompatible MPAM-Fb protocol version %d.%d\n" , +FIELD_GET (MPAM_FB_VERSION_MAJOR_MASK , version), +FIELD_GET (MPAM_FB_VERSION_MINOR_MASK , version)); + +return -EINVAL ; + } + +return 0 ; +} + +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc) +{ +int min_buffer_size =MPAM_FB_MAX_MSG_SIZE + +sizeof (struct acpi_pcct_ext_pcc_shared_memory ); + +if (msc->pcc_chan->pcc_chan->shmem_size < min_buffer_size) { +pr_err ("MPAM-Fb PCC channel size too small.\n" ); + +return -ENOMEM ; + } + +return 0 ; +}drivers/resctrl/mpam_internal.h +2
-0@@ -538,6 +538,8 @@ static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }/* MPAM-Fb Firmware-backed protocol wrappers */ int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result);int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value); +int mpam_fb_check_protocol_version (struct mpam_msc *msc); +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc);/* * MPAM MSCs have the following register layout. See:
Re: [PATCH v10 12/14] arm_mpam: detect and enable MPAM-Fb PCC support
Hi Ben,
Quoted 209 lines · Ben Horgan
Hi Andre,
Quoted 206 lines · Andre Przywara
The Arm MPAM-Fb specification [1] describes a protocol to access MSC registers through a firmware interface. This requires a shared memory region to hold the message, and a mailbox to trigger the access. For ACPI this is wrapped as a PCC channel, described using existing ACPI abstractions.
Add code to parse those PCC table descriptions associated with an MSC, and store the parsed information in the MSC struct.
There can be multiple PCC channels, and each channel can serve multiple MSCs, so we need to keep track of the channel usage, using a list and a refcount.This will be used by the MPAM-Fb access wrapper code.
[1] https://developer.arm.com/documentation/den0144/latest
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Tested-by Srivathsa L Rao <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>Reviewed-by Gavin Shan <[email protected]>--- drivers/resctrl/Kconfig | 1 + drivers/resctrl/mpam_devices.c | 119 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_fb.c | 41 +++++++++++ drivers/resctrl/mpam_internal.h | 2 + 4 files changed, 161 insertions(+), 2 deletions(-)drivers/resctrl/Kconfig +1
-0@@ -2,6 +2,7 @@ menuconfig ARM64_MPAM_DRIVER bool "MPAM driver" depends on ARM64 && ARM64_MPAM select ACPI_MPAM if ACPI + select PCC if ACPI select MAILBOX help Memory System Resource Partitioning and Monitoring (MPAM) driver fordrivers/resctrl/mpam_devices.c +112
-2@@ -20,14 +20,19 @@#include <linux/irqdesc.h> #include <linux/list.h> #include <linux/lockdep.h> +#include <linux/mailbox_client.h> #include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <linux/property.h> #include <linux/srcu.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/workqueue.h> +#include <acpi/pcc.h> +#include <acpi/acpi_io.h> +#include "mpam_internal.h" /* Values for the T241 errata workaround */ @@ -50,6 +55,87 @@ static LIST_HEAD(mpam_all_msc);struct srcu_struct mpam_srcu; +/* PCC channels might be serving multiple MSCs, so keep a refcounted list. */ +static DEFINE_MUTEX (pcc_chan_list_lock); +static LIST_HEAD (pcc_chan_list); + +static void mpam_pcc_chan_release (struct kref *ref) +{ + struct mpam_pcc_chan *cur = container_of(ref, struct mpam_pcc_chan, + refcount); + +pcc_mbox_free_channel (cur->pcc_chan); +list_del (&cur->pcc_chans); +mutex_destroy (&cur->pcc_chan_lock); +kfree (cur); +} + +static struct mpam_pcc_chan *mpam_pcc_chan_get (struct device *dev, +int subspace_id) +{ +struct mpam_pcc_chan *cur; + +guard (mutex)(&pcc_chan_list_lock); + +list_for_each_entry (cur, &pcc_chan_list, pcc_chans) { +if (cur->subspace_id == subspace_id) { +kref_get (&cur->refcount); + +return cur; + } + } + + cur =kzalloc_obj (*cur); +if (!cur) +return ERR_PTR (-ENOMEM ); + + cur->pcc_cl.tx_block = true; + + cur->pcc_chan =pcc_mbox_request_channel (&cur->pcc_cl, subspace_id); +if (IS_ERR (cur->pcc_chan)) { +long err =PTR_ERR (cur->pcc_chan); + +kfree (cur); +return ERR_PTR (err); + } + +/* +* Timeout based on the "nominal latency" in us, from the +* PCC ACPI table. tx_tout is in ms. +* Add some margin here to be on the safe side. +*/ + cur->pcc_cl.tx_tout =DIV_ROUND_UP (cur->pcc_chan->latency *5 ,1000 ); + +mutex_init (&cur->pcc_chan_lock); + + cur->subspace_id = subspace_id; +kref_init (&cur->refcount); + +list_add_tail (&cur->pcc_chans, &pcc_chan_list); + +return cur; +} + +static int mpam_pcc_chan_put (struct mpam_pcc_chan *pcc_chan) +{ +struct mpam_pcc_chan *cur, *tmp; + +if (!pcc_chan) +return 0 ; + +guard (mutex)(&pcc_chan_list_lock); + +list_for_each_entry_safe (cur, tmp, &pcc_chan_list, pcc_chans) { +if (cur == pcc_chan) { +kref_put (&cur->refcount, mpam_pcc_chan_release); + +return 0 ; + } + } + +return -ENOENT ; +} +/* * Number of MSCs that have been probed. Once all MSCs have been probed MPAM * can be enabled. @@ -2285,6 +2371,8 @@ static void mpam_msc_drv_remove(struct platform_device *pdev)if (!msc)return ; +mpam_pcc_chan_put (msc->pcc_chan); +mutex_lock (&mpam_list_lock);mpam_msc_destroy (msc);mutex_unlock (&mpam_list_lock);@@ -2295,7 +2383,7 @@ static void mpam_msc_drv_remove(struct platform_device *pdev)static struct mpam_msc *do_mpam_msc_drv_probe (struct platform_device *pdev) {int err; -u32 tmp; +u32 pcc_subspace_id;struct mpam_msc *msc;struct resource *msc_res;struct device *dev = &pdev->dev;@@ -2339,7 +2427,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)if (err)return ERR_PTR (err); -if (device_property_read_u32 (&pdev->dev,"pcc-channel" , &tmp)) +if (device_property_read_u32 (dev,"pcc-channel" , &pcc_subspace_id)) msc->iface =MPAM_IFACE_MMIO ;else msc->iface =MPAM_IFACE_PCC ;@@ -2360,6 +2448,33 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) } msc->mapped_hwpage_sz = msc_res->end - msc_res->start; msc->mapped_hwpage = io; + }else if (msc->iface ==MPAM_IFACE_PCC ) { +u32 mpam_fb_msc_id; + + msc->pcc_chan =mpam_pcc_chan_get (dev, pcc_subspace_id); +if (IS_ERR (msc->pcc_chan)) { +pr_err ("Failed to request MSC PCC channel\n" ); +return ERR_CAST (msc->pcc_chan); + } + + err =mpam_fb_check_shared_buffer_size (msc); +if (err) { +mpam_pcc_chan_put (msc->pcc_chan); + +return ERR_PTR (err); + } + + err =mpam_fb_check_protocol_version (msc); +if (err) { +mpam_pcc_chan_put (msc->pcc_chan); + +return ERR_PTR (err); + }
Quoted 8 lines
drivers/resctrl/mpam_devices.c static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) · line 2477
Quoted 5 lines
drivers/resctrl/mpam_devices.c +5
-0+ +if (device_property_read_u32 (&pdev->dev,"mpam-fb-msc-id" , + &mpam_fb_msc_id)) + mpam_fb_msc_id = msc->id; + msc->mpam_fb_msc_id = mpam_fb_msc_id;This looks like the change earlier in the series to
drivers/acpi/arm64/mpam.cmakes no functional effect unless the proposed spec changes are accepted; the default ismsc->id. I'd just move the
Yes, but it reduces churn, and more importantly, is more true to the MPAM-Fb spec, which says:
"The MSC identifiers are sequential and start from 0 for each agent which uses this protocol."
So this requires that we have per-channel IDs for the MSCs, that's why I think it's justified to introduce this already now, even when it's somewhat redundant as the code stands now, as we always assign the system-wide ID to it.
I can of course move that out (and have that already on top of v9, internally), but wanted to check this with you.
Quoted 3 lines
earlier
drivers/acpi/arm64/mpam.cto your last patch and introduce thisdevice_property_read_u32()their too (or a separate patch if it's easier for anyone). That way all but the last two patches can be considered for merging without knowing what's going to happen with the spec.
Well, sure, though I think a separation of MPAM-FB MSC IDs and system-wide MSC IDs is inevitable, regardless of which spec is changed and how the numbers are assigned, exactly.
Quoted 1 line
The struct msc property
mpam_fb_msc_idis a bit long. Better asmsc->fb_id?
Sure, can shorten that.
Cheers,
Andre.
Quoted 77 lines
Quoted 76 lines
drivers/resctrl/mpam_devices.c +0
-0}else {return ERR_PTR (-EINVAL ); }drivers/resctrl/mpam_fb.c +41
-0@@ -20,10 +20,15 @@#define MPAM_FB_PROTOCOL_ID 0x1a#define MPAM_PROTOCOL_VERSION_CMD 0x0 +#define MPAM_FB_VERSION_MAJOR_MASK GENMASK_U32(31, 16) +#define MPAM_FB_VERSION_MINOR_MASK GENMASK_U32(15, 0) +#define MPAM_MSC_READ_CMD 0x4#define MPAM_MSC_WRITE_CMD 0x5#define MPAM_FB_PROT_HEADER_LEN sizeof(u32) +/* The longest message is MPAM_MSC_WRITE, with 4 parameters. */ +#define MPAM_FB_MAX_MSG_SIZE (4 * sizeof(u32))#define MPAM_FB_SUCCESS 0#define MPAM_FB_ERR_NOT_SUPPORTED -1@@ -209,3 +214,39 @@ int mpam_fb_send_write_request(struct mpam_msc *msc, u16 reg, u32 value)return mpam_fb_send_request (msc, msc->mpam_fb_msc_id, reg, &value,MPAM_MSC_WRITE_CMD ); } + +/* We only support MPAM-Fb protocol version 1.x */ +int mpam_fb_check_protocol_version (struct mpam_msc *msc) +{ +u32 version; +int ret; + + ret =mpam_fb_send_request (msc,0 ,0 , &version, +MPAM_PROTOCOL_VERSION_CMD ); +if (ret) +return ret; + +if (FIELD_GET (MPAM_FB_VERSION_MAJOR_MASK , version) !=1 ) { +pr_err ("Incompatible MPAM-Fb protocol version %d.%d\n" , +FIELD_GET (MPAM_FB_VERSION_MAJOR_MASK , version), +FIELD_GET (MPAM_FB_VERSION_MINOR_MASK , version)); + +return -EINVAL ; + } + +return 0 ; +} + +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc) +{ +int min_buffer_size =MPAM_FB_MAX_MSG_SIZE + +sizeof (struct acpi_pcct_ext_pcc_shared_memory ); + +if (msc->pcc_chan->pcc_chan->shmem_size < min_buffer_size) { +pr_err ("MPAM-Fb PCC channel size too small.\n" ); + +return -ENOMEM ; + } + +return 0 ; +}drivers/resctrl/mpam_internal.h +2
-0@@ -538,6 +538,8 @@ static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }/* MPAM-Fb Firmware-backed protocol wrappers */ int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result);int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value); +int mpam_fb_check_protocol_version (struct mpam_msc *msc); +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc);/* * MPAM MSCs have the following register layout. See:
Ben Horgan
maintainerRe: [PATCH v10 12/14] arm_mpam: detect and enable MPAM-Fb PCC support
Hi Andre,
Quoted 215 lines · Andre Przywara
Hi Ben,
Quoted 203 lines · Ben Horgan
Hi Andre,
Quoted 200 lines · Andre Przywara
The Arm MPAM-Fb specification [1] describes a protocol to access MSC registers through a firmware interface. This requires a shared memory region to hold the message, and a mailbox to trigger the access. For ACPI this is wrapped as a PCC channel, described using existing ACPI abstractions.
Add code to parse those PCC table descriptions associated with an MSC, and store the parsed information in the MSC struct.
There can be multiple PCC channels, and each channel can serve multiple MSCs, so we need to keep track of the channel usage, using a list and a refcount.This will be used by the MPAM-Fb access wrapper code.
[1] https://developer.arm.com/documentation/den0144/latest
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Tested-by Srivathsa L Rao <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>Reviewed-by Gavin Shan <[email protected]>---
drivers/resctrl/Kconfig | 1 + drivers/resctrl/mpam_devices.c | 119 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_fb.c | 41 +++++++++++drivers/resctrl/mpam_internal.h| 2 +4 files changed, 161 insertions(+), 2 deletions(-)drivers/resctrl/Kconfig +0
-0@@ -2,6 +2,7 @@ menuconfig ARM64_MPAM_DRIVERbool "MPAM driver"
depends on ARM64 &&ARM64_MPAM
selectACPI_MPAMif ACPI
+ select PCC if ACPI
select MAILBOX
help
Memory System Resource Partitioning and Monitoring (MPAM) driver fordrivers/resctrl/mpam_devices.c +2
-0@@ -20,14 +20,19 @@ #include <linux/irqdesc.h> #include <linux/list.h> #include <linux/lockdep.h> +#include <linux/mailbox_client.h> #include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <linux/property.h> #include <linux/srcu.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/workqueue.h>+#include <
acpi/pcc.h>drivers/resctrl/mpam_devices.c +2
-0+#include <acpi/acpi_io.h> +#include "
mpam_internal.h"
/* Values for the T241 errata workaround */drivers/resctrl/mpam_devices.c +0
-0@@ -50,6 +55,87 @@ static LIST_HEAD(mpam_all_msc); struct srcu_struct mpam_srcu;+/* PCC channels might be serving multiple MSCs, so keep a refcounted list. */
drivers/resctrl/mpam_devices.c +80
-0+static DEFINE_MUTEX (pcc_chan_list_lock); +static LIST_HEAD (pcc_chan_list); + +static void mpam_pcc_chan_release (struct kref *ref) +{ + struct mpam_pcc_chan *cur = container_of(ref, struct mpam_pcc_chan, + refcount); + + pcc_mbox_free_channel(cur->pcc_chan); + list_del(&cur->pcc_chans); + mutex_destroy(&cur->pcc_chan_lock); + kfree(cur); +} + +static struct mpam_pcc_chan *mpam_pcc_chan_get (struct device *dev, + int subspace_id) +{ + struct mpam_pcc_chan *cur; + + guard(mutex)(&pcc_chan_list_lock); + + list_for_each_entry(cur, &pcc_chan_list, pcc_chans) { + if (cur->subspace_id == subspace_id) { + kref_get(&cur->refcount); + + return cur; + } + } + + cur = kzalloc_obj(*cur); + if (!cur) + return ERR_PTR(-ENOMEM); + + cur->pcc_cl.tx_block = true; + + cur->pcc_chan = pcc_mbox_request_channel(&cur->pcc_cl, subspace_id); + if (IS_ERR(cur->pcc_chan)) { + long err = PTR_ERR(cur->pcc_chan); + + kfree(cur); + return ERR_PTR(err); + } + + /* + * Timeout based on the "nominal latency" in us, from the + * PCC ACPI table. tx_tout is in ms. + * Add some margin here to be on the safe side. + */ + cur->pcc_cl.tx_tout = DIV_ROUND_UP(cur->pcc_chan->latency * 5, 1000); + + mutex_init(&cur->pcc_chan_lock); + + cur->subspace_id = subspace_id; + kref_init(&cur->refcount); + + list_add_tail(&cur->pcc_chans, &pcc_chan_list); + + return cur; +} + +static int mpam_pcc_chan_put (struct mpam_pcc_chan *pcc_chan) +{ + struct mpam_pcc_chan *cur, *tmp; + + if (!pcc_chan) + return 0; + + guard(mutex)(&pcc_chan_list_lock); + + list_for_each_entry_safe(cur, tmp, &pcc_chan_list, pcc_chans) { + if (cur == pcc_chan) { + kref_put(&cur->refcount, mpam_pcc_chan_release); + + return 0; + } + } + + return -ENOENT; +} +/*
* Number of MSCs that have been probed. Once all MSCs have been probed MPAM
* can be enabled.drivers/resctrl/mpam_devices.c +3
-1@@ -2285,6 +2371,8 @@ static void mpam_msc_drv_remove(struct platform_device *pdev) if (!msc) return; + mpam_pcc_chan_put(msc->pcc_chan); + mutex_lock(&mpam_list_lock); mpam_msc_destroy(msc); mutex_unlock(&mpam_list_lock);@@ -2295,7 +2383,7 @@ static void mpam_msc_drv_remove(struct platform_device *pdev) static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) { int err; - u32 tmp; + u32 pcc_subspace_id; struct mpam_msc *msc; struct resource *msc_res; struct device *dev = &pdev->dev;@@ -2339,7 +2427,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) if (err) return ERR_PTR(err); - if (device_property_read_u32(&pdev->dev, "pcc-channel", &tmp)) + if (device_property_read_u32(dev, "pcc-channel", &pcc_subspace_id)) msc->iface = MPAM_IFACE_MMIO;else
msc->iface=MPAM_IFACE_PCC;drivers/resctrl/mpam_devices.c +22
-0@@ -2360,6 +2448,33 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) } msc->mapped_hwpage_sz = msc_res->end - msc_res->start; msc->mapped_hwpage = io; + } else if (msc->iface == MPAM_IFACE_PCC) { + u32 mpam_fb_msc_id; + + msc->pcc_chan = mpam_pcc_chan_get(dev, pcc_subspace_id); + if (IS_ERR(msc->pcc_chan)) { + pr_err("Failed to request MSC PCC channel\n"); + return ERR_CAST(msc->pcc_chan); + } + + err = mpam_fb_check_shared_buffer_size(msc); + if (err) { + mpam_pcc_chan_put(msc->pcc_chan); + + return ERR_PTR(err); + } + + err = mpam_fb_check_protocol_version(msc); + if (err) { + mpam_pcc_chan_put(msc->pcc_chan); + + return ERR_PTR(err); + }Quoted 8 lines
drivers/resctrl/mpam_devices.c static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) · line 2477
Quoted 5 lines
drivers/resctrl/mpam_devices.c +5
-0+ + if (device_property_read_u32(&pdev->dev, "mpam-fb-msc-id", + &mpam_fb_msc_id)) + mpam_fb_msc_id = msc->id; + msc->mpam_fb_msc_id = mpam_fb_msc_id;This looks like the change earlier in the series to
drivers/acpi/arm64/mpam.cmakes no functional effect unless the proposed spec changes are accepted; the default ismsc->id. I'd just move the
Quoted 8 lines
Yes, but it reduces churn, and more importantly, is more true to the MPAM-Fb spec, which says:
"The MSC identifiers are sequential and start from 0 for each agent which uses this protocol." So this requires that we have per-channel IDs for the MSCs, that's why I think it's justified to introduce this already now, even when it's somewhat redundant as the code stands now, as we always assign the system-wide ID to it.I can of course move that out (and have that already on top of v9, internally), but wanted to check this with you.
I don't really mind. If Lorenzo/Sudeep are happy with doing the preparation work in drivers/acpi/arm64/mpam.c then I'm ok with it. It's currently a non-functional change but does make the expected path forward slightly clearer.
Quoted 7 lines
Quoted 4 lines
earlier
drivers/acpi/arm64/mpam.cto your last patch and introduce thisdevice_property_read_u32()their too (or a separate patch if it's easier for anyone). That way all but the last two patches can be considered for merging without knowing what's going to happen with the spec.Well, sure, though I think a separation of MPAM-FB MSC IDs and system-wide MSC IDs is inevitable, regardless of which spec is changed and how the numbers are assigned, exactly.
It seems so.
Thanks,
Ben
Quoted 81 lines
Quoted 1 line
Quoted 1 line
The struct msc property
mpam_fb_msc_idis a bit long. Better asmsc->fb_id?Sure, can shorten that.
Cheers,
Andre.Quoted 73 lines
Quoted 72 lines
} else {
returnERR_PTR(-EINVAL);
}drivers/resctrl/mpam_fb.c +41
-0@@ -20,10 +20,15 @@ #define MPAM_FB_PROTOCOL_ID 0x1a #define MPAM_PROTOCOL_VERSION_CMD 0x0 +#define MPAM_FB_VERSION_MAJOR_MASK GENMASK_U32(31, 16) +#define MPAM_FB_VERSION_MINOR_MASK GENMASK_U32(15, 0) + #define MPAM_MSC_READ_CMD 0x4 #define MPAM_MSC_WRITE_CMD 0x5 #define MPAM_FB_PROT_HEADER_LEN sizeof(u32) +/* The longest message is MPAM_MSC_WRITE, with 4 parameters. */ +#define MPAM_FB_MAX_MSG_SIZE (4 * sizeof(u32)) #define MPAM_FB_SUCCESS 0 #define MPAM_FB_ERR_NOT_SUPPORTED -1@@ -209,3 +214,39 @@ int mpam_fb_send_write_request(struct mpam_msc *msc, u16 reg, u32 value) return mpam_fb_send_request(msc, msc->mpam_fb_msc_id, reg, &value, MPAM_MSC_WRITE_CMD); } + +/* We only support MPAM-Fb protocol version 1.x */ +int mpam_fb_check_protocol_version (struct mpam_msc *msc) +{ + u32 version; + int ret; + + ret = mpam_fb_send_request(msc, 0, 0, &version, + MPAM_PROTOCOL_VERSION_CMD); + if (ret) + return ret; + + if (FIELD_GET(MPAM_FB_VERSION_MAJOR_MASK, version) != 1) { + pr_err("Incompatible MPAM-Fb protocol version %d.%d\n", + FIELD_GET(MPAM_FB_VERSION_MAJOR_MASK, version), + FIELD_GET(MPAM_FB_VERSION_MINOR_MASK, version)); + + return -EINVAL; + } + + return 0; +} + +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc) +{ + int min_buffer_size = MPAM_FB_MAX_MSG_SIZE + + sizeof(struct acpi_pcct_ext_pcc_shared_memory); + + if (msc->pcc_chan->pcc_chan->shmem_size < min_buffer_size) { + pr_err("MPAM-Fb PCC channel size too small.\n"); + + return -ENOMEM; + } + + return 0; +}drivers/resctrl/mpam_internal.h +2
-0@@ -538,6 +538,8 @@ static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { } /* MPAM-Fb Firmware-backed protocol wrappers */ int mpam_fb_send_read_request(struct mpam_msc *msc, u16 reg, u32 *result); int mpam_fb_send_write_request(struct mpam_msc *msc, u16 reg, u32 value); +int mpam_fb_check_protocol_version (struct mpam_msc *msc); +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc); /** MPAM MSCs have the following register layout. See:
Sudeep Holla
maintainerRe: [PATCH v10 12/14] arm_mpam: detect and enable MPAM-Fb PCC support
Quoted 8 lines · Ben Horgan
Hi Andre,
Quoted 5 lines · Andre Przywara
Hi Ben,
Quoted 2 lines · Ben Horgan
Hi Andre,
[...]
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
This looks like the change earlier in the series to
drivers/acpi/arm64/mpam.cmakes no functional effect unless the proposed spec changes are accepted; the default ismsc->id. I'd just move theYes, but it reduces churn, and more importantly, is more true to the MPAM-Fb spec, which says:"The MSC identifiers are sequential and start from 0 for each agent which uses this protocol." So this requires that we have per-channel IDs for the MSCs, that's why I think it's justified to introduce this already now, even when it's somewhat redundant as the code stands now, as we always assign the system-wide ID to it.
Quoted 8 lines
Quoted 2 lines
I can of course move that out (and have that already on top of v9, internally), but wanted to check this with you.
I don't really mind. If Lorenzo/Sudeep are happy with doing the preparation work in
drivers/acpi/arm64/mpam.cthen I'm ok with it. It's currently a non-functional change but does make the expected path forward slightly clearer.
Sure, I am okay to have it added here if we plan to use it in the future. We can always rip it off if the spec changes its direction or gets deemed as broken 😉.
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v10 12/14] arm_mpam: detect and enable MPAM-Fb PCC support
Hi Sudeep,
Quoted 33 lines · Sudeep Holla
Quoted 8 lines · Ben Horgan
Hi Andre,
Quoted 5 lines · Andre Przywara
Hi Ben,
Quoted 2 lines · Ben Horgan
Hi Andre,
[...]
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
This looks like the change earlier in the series to
drivers/acpi/arm64/mpam.cmakes no functional effect unless the proposed spec changes are accepted; the default ismsc->id. I'd just move theYes, but it reduces churn, and more importantly, is more true to the MPAM-Fb spec, which says:"The MSC identifiers are sequential and start from 0 for each agent which uses this protocol." So this requires that we have per-channel IDs for the MSCs, that's why I think it's justified to introduce this already now, even when it's somewhat redundant as the code stands now, as we always assign the system-wide ID to it.
Quoted 8 lines
Quoted 2 lines
I can of course move that out (and have that already on top of v9, internally), but wanted to check this with you.
I don't really mind. If Lorenzo/Sudeep are happy with doing the preparation work in
drivers/acpi/arm64/mpam.cthen I'm ok with it. It's currently a non-functional change but does make the expected path forward slightly clearer.
Quoted 3 lines
Sure, I am okay to have it added here if we plan to use it in the future. We can always rip it off if the spec changes its direction or gets deemed as broken 😉.
Many thanks, will keep it in then.
Cheers,
Andre
Ben Horgan
maintainerRe: [PATCH v10 12/14] arm_mpam: detect and enable MPAM-Fb PCC support
In reply to Andre PrzywaraHi Andre,
Quoted 154 lines · Andre Przywara
The Arm MPAM-Fb specification [1] describes a protocol to access MSC registers through a firmware interface. This requires a shared memory region to hold the message, and a mailbox to trigger the access. For ACPI this is wrapped as a PCC channel, described using existing ACPI abstractions.
Add code to parse those PCC table descriptions associated with an MSC, and store the parsed information in the MSC struct.
There can be multiple PCC channels, and each channel can serve multiple MSCs, so we need to keep track of the channel usage, using a list and a refcount.This will be used by the MPAM-Fb access wrapper code.
[1] https://developer.arm.com/documentation/den0144/latest
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Tested-by Srivathsa L Rao <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>Reviewed-by Gavin Shan <[email protected]>--- drivers/resctrl/Kconfig | 1 + drivers/resctrl/mpam_devices.c | 119 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_fb.c | 41 +++++++++++ drivers/resctrl/mpam_internal.h | 2 + 4 files changed, 161 insertions(+), 2 deletions(-)drivers/resctrl/Kconfig +1
-0@@ -2,6 +2,7 @@ menuconfig ARM64_MPAM_DRIVER bool "MPAM driver" depends on ARM64 && ARM64_MPAM select ACPI_MPAM if ACPI + select PCC if ACPI select MAILBOX help Memory System Resource Partitioning and Monitoring (MPAM) driver fordrivers/resctrl/mpam_devices.c +86
-0@@ -20,14 +20,19 @@#include <linux/irqdesc.h> #include <linux/list.h> #include <linux/lockdep.h> +#include <linux/mailbox_client.h> #include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <linux/property.h> #include <linux/srcu.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/workqueue.h> +#include <acpi/pcc.h> +#include <acpi/acpi_io.h> +#include "mpam_internal.h" /* Values for the T241 errata workaround */ @@ -50,6 +55,87 @@ static LIST_HEAD(mpam_all_msc);struct srcu_struct mpam_srcu; +/* PCC channels might be serving multiple MSCs, so keep a refcounted list. */ +static DEFINE_MUTEX (pcc_chan_list_lock); +static LIST_HEAD (pcc_chan_list); + +static void mpam_pcc_chan_release (struct kref *ref) +{ + struct mpam_pcc_chan *cur = container_of(ref, struct mpam_pcc_chan, + refcount); + +pcc_mbox_free_channel (cur->pcc_chan); +list_del (&cur->pcc_chans); +mutex_destroy (&cur->pcc_chan_lock); +kfree (cur); +} + +static struct mpam_pcc_chan *mpam_pcc_chan_get (struct device *dev, +int subspace_id) +{ +struct mpam_pcc_chan *cur; + +guard (mutex)(&pcc_chan_list_lock); + +list_for_each_entry (cur, &pcc_chan_list, pcc_chans) { +if (cur->subspace_id == subspace_id) { +kref_get (&cur->refcount); + +return cur; + } + } + + cur =kzalloc_obj (*cur); +if (!cur) +return ERR_PTR (-ENOMEM ); + + cur->pcc_cl.tx_block = true; + + cur->pcc_chan =pcc_mbox_request_channel (&cur->pcc_cl, subspace_id); +if (IS_ERR (cur->pcc_chan)) { +long err =PTR_ERR (cur->pcc_chan); + +kfree (cur); +return ERR_PTR (err); + } + +/* +* Timeout based on the "nominal latency" in us, from the +* PCC ACPI table. tx_tout is in ms. +* Add some margin here to be on the safe side. +*/ + cur->pcc_cl.tx_tout =DIV_ROUND_UP (cur->pcc_chan->latency *5 ,1000 ); + +mutex_init (&cur->pcc_chan_lock); + + cur->subspace_id = subspace_id; +kref_init (&cur->refcount); + +list_add_tail (&cur->pcc_chans, &pcc_chan_list); + +return cur; +} + +static int mpam_pcc_chan_put (struct mpam_pcc_chan *pcc_chan) +{ +struct mpam_pcc_chan *cur, *tmp; + +if (!pcc_chan) +return 0 ; + +guard (mutex)(&pcc_chan_list_lock); + +list_for_each_entry_safe (cur, tmp, &pcc_chan_list, pcc_chans) { +if (cur == pcc_chan) { +kref_put (&cur->refcount, mpam_pcc_chan_release); + +return 0 ; + } + } + +return -ENOENT ; +} +/* * Number of MSCs that have been probed. Once all MSCs have been probed MPAM * can be enabled.
drivers/resctrl/mpam_devices.c static void mpam_msc_drv_remove(struct platform_device *pdev) · line 2375
Quoted 5 lines
drivers/resctrl/mpam_devices.c +2
-0@@ -2285,6 +2371,8 @@ static void mpam_msc_drv_remove(struct platform_device *pdev)if (!msc)return ; +mpam_pcc_chan_put (msc->pcc_chan); +
I think this should be in mpam_msc_destroy() so we don't leak the channel on mpam_disable().
Thanks,
Ben
Quoted 128 lines
drivers/resctrl/mpam_devices.c +29
-2mutex_lock (&mpam_list_lock);mpam_msc_destroy (msc);mutex_unlock (&mpam_list_lock);@@ -2295,7 +2383,7 @@ static void mpam_msc_drv_remove(struct platform_device *pdev)static struct mpam_msc *do_mpam_msc_drv_probe (struct platform_device *pdev) {int err; -u32 tmp; +u32 pcc_subspace_id;struct mpam_msc *msc;struct resource *msc_res;struct device *dev = &pdev->dev;@@ -2339,7 +2427,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)if (err)return ERR_PTR (err); -if (device_property_read_u32 (&pdev->dev,"pcc-channel" , &tmp)) +if (device_property_read_u32 (dev,"pcc-channel" , &pcc_subspace_id)) msc->iface =MPAM_IFACE_MMIO ;else msc->iface =MPAM_IFACE_PCC ;@@ -2360,6 +2448,33 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) } msc->mapped_hwpage_sz = msc_res->end - msc_res->start; msc->mapped_hwpage = io; + }else if (msc->iface ==MPAM_IFACE_PCC ) { +u32 mpam_fb_msc_id; + + msc->pcc_chan =mpam_pcc_chan_get (dev, pcc_subspace_id); +if (IS_ERR (msc->pcc_chan)) { +pr_err ("Failed to request MSC PCC channel\n" ); +return ERR_CAST (msc->pcc_chan); + } + + err =mpam_fb_check_shared_buffer_size (msc); +if (err) { +mpam_pcc_chan_put (msc->pcc_chan); + +return ERR_PTR (err); + } + + err =mpam_fb_check_protocol_version (msc); +if (err) { +mpam_pcc_chan_put (msc->pcc_chan); + +return ERR_PTR (err); + } + +if (device_property_read_u32 (&pdev->dev,"mpam-fb-msc-id" , + &mpam_fb_msc_id)) + mpam_fb_msc_id = msc->id; + msc->mpam_fb_msc_id = mpam_fb_msc_id; }else {return ERR_PTR (-EINVAL ); }drivers/resctrl/mpam_fb.c +41
-0@@ -20,10 +20,15 @@#define MPAM_FB_PROTOCOL_ID 0x1a#define MPAM_PROTOCOL_VERSION_CMD 0x0 +#define MPAM_FB_VERSION_MAJOR_MASK GENMASK_U32(31, 16) +#define MPAM_FB_VERSION_MINOR_MASK GENMASK_U32(15, 0) +#define MPAM_MSC_READ_CMD 0x4#define MPAM_MSC_WRITE_CMD 0x5#define MPAM_FB_PROT_HEADER_LEN sizeof(u32) +/* The longest message is MPAM_MSC_WRITE, with 4 parameters. */ +#define MPAM_FB_MAX_MSG_SIZE (4 * sizeof(u32))#define MPAM_FB_SUCCESS 0#define MPAM_FB_ERR_NOT_SUPPORTED -1@@ -209,3 +214,39 @@ int mpam_fb_send_write_request(struct mpam_msc *msc, u16 reg, u32 value)return mpam_fb_send_request (msc, msc->mpam_fb_msc_id, reg, &value,MPAM_MSC_WRITE_CMD ); } + +/* We only support MPAM-Fb protocol version 1.x */ +int mpam_fb_check_protocol_version (struct mpam_msc *msc) +{ +u32 version; +int ret; + + ret =mpam_fb_send_request (msc,0 ,0 , &version, +MPAM_PROTOCOL_VERSION_CMD ); +if (ret) +return ret; + +if (FIELD_GET (MPAM_FB_VERSION_MAJOR_MASK , version) !=1 ) { +pr_err ("Incompatible MPAM-Fb protocol version %d.%d\n" , +FIELD_GET (MPAM_FB_VERSION_MAJOR_MASK , version), +FIELD_GET (MPAM_FB_VERSION_MINOR_MASK , version)); + +return -EINVAL ; + } + +return 0 ; +} + +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc) +{ +int min_buffer_size =MPAM_FB_MAX_MSG_SIZE + +sizeof (struct acpi_pcct_ext_pcc_shared_memory ); + +if (msc->pcc_chan->pcc_chan->shmem_size < min_buffer_size) { +pr_err ("MPAM-Fb PCC channel size too small.\n" ); + +return -ENOMEM ; + } + +return 0 ; +}drivers/resctrl/mpam_internal.h +2
-0@@ -538,6 +538,8 @@ static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }/* MPAM-Fb Firmware-backed protocol wrappers */ int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result);int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value); +int mpam_fb_check_protocol_version (struct mpam_msc *msc); +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc);/* * MPAM MSCs have the following register layout. See:
Re: [PATCH v10 12/14] arm_mpam: detect and enable MPAM-Fb PCC support
Hi Ben,
Quoted 160 lines · Ben Horgan
Hi Andre,
Quoted 157 lines · Andre Przywara
The Arm MPAM-Fb specification [1] describes a protocol to access MSC registers through a firmware interface. This requires a shared memory region to hold the message, and a mailbox to trigger the access. For ACPI this is wrapped as a PCC channel, described using existing ACPI abstractions.
Add code to parse those PCC table descriptions associated with an MSC, and store the parsed information in the MSC struct.
There can be multiple PCC channels, and each channel can serve multiple MSCs, so we need to keep track of the channel usage, using a list and a refcount.This will be used by the MPAM-Fb access wrapper code.
[1] https://developer.arm.com/documentation/den0144/latest
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Tested-by Srivathsa L Rao <[email protected]>Reviewed-by Srivathsa L Rao <[email protected]>Reviewed-by Gavin Shan <[email protected]>--- drivers/resctrl/Kconfig | 1 + drivers/resctrl/mpam_devices.c | 119 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_fb.c | 41 +++++++++++ drivers/resctrl/mpam_internal.h | 2 + 4 files changed, 161 insertions(+), 2 deletions(-)drivers/resctrl/Kconfig +1
-0@@ -2,6 +2,7 @@ menuconfig ARM64_MPAM_DRIVER bool "MPAM driver" depends on ARM64 && ARM64_MPAM select ACPI_MPAM if ACPI + select PCC if ACPI select MAILBOX help Memory System Resource Partitioning and Monitoring (MPAM) driver fordrivers/resctrl/mpam_devices.c +86
-0@@ -20,14 +20,19 @@#include <linux/irqdesc.h> #include <linux/list.h> #include <linux/lockdep.h> +#include <linux/mailbox_client.h> #include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <linux/property.h> #include <linux/srcu.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/workqueue.h> +#include <acpi/pcc.h> +#include <acpi/acpi_io.h> +#include "mpam_internal.h" /* Values for the T241 errata workaround */ @@ -50,6 +55,87 @@ static LIST_HEAD(mpam_all_msc);struct srcu_struct mpam_srcu; +/* PCC channels might be serving multiple MSCs, so keep a refcounted list. */ +static DEFINE_MUTEX (pcc_chan_list_lock); +static LIST_HEAD (pcc_chan_list); + +static void mpam_pcc_chan_release (struct kref *ref) +{ + struct mpam_pcc_chan *cur = container_of(ref, struct mpam_pcc_chan, + refcount); + +pcc_mbox_free_channel (cur->pcc_chan); +list_del (&cur->pcc_chans); +mutex_destroy (&cur->pcc_chan_lock); +kfree (cur); +} + +static struct mpam_pcc_chan *mpam_pcc_chan_get (struct device *dev, +int subspace_id) +{ +struct mpam_pcc_chan *cur; + +guard (mutex)(&pcc_chan_list_lock); + +list_for_each_entry (cur, &pcc_chan_list, pcc_chans) { +if (cur->subspace_id == subspace_id) { +kref_get (&cur->refcount); + +return cur; + } + } + + cur =kzalloc_obj (*cur); +if (!cur) +return ERR_PTR (-ENOMEM ); + + cur->pcc_cl.tx_block = true; + + cur->pcc_chan =pcc_mbox_request_channel (&cur->pcc_cl, subspace_id); +if (IS_ERR (cur->pcc_chan)) { +long err =PTR_ERR (cur->pcc_chan); + +kfree (cur); +return ERR_PTR (err); + } + +/* +* Timeout based on the "nominal latency" in us, from the +* PCC ACPI table. tx_tout is in ms. +* Add some margin here to be on the safe side. +*/ + cur->pcc_cl.tx_tout =DIV_ROUND_UP (cur->pcc_chan->latency *5 ,1000 ); + +mutex_init (&cur->pcc_chan_lock); + + cur->subspace_id = subspace_id; +kref_init (&cur->refcount); + +list_add_tail (&cur->pcc_chans, &pcc_chan_list); + +return cur; +} + +static int mpam_pcc_chan_put (struct mpam_pcc_chan *pcc_chan) +{ +struct mpam_pcc_chan *cur, *tmp; + +if (!pcc_chan) +return 0 ; + +guard (mutex)(&pcc_chan_list_lock); + +list_for_each_entry_safe (cur, tmp, &pcc_chan_list, pcc_chans) { +if (cur == pcc_chan) { +kref_put (&cur->refcount, mpam_pcc_chan_release); + +return 0 ; + } + } + +return -ENOENT ; +} +/* * Number of MSCs that have been probed. Once all MSCs have been probed MPAM * can be enabled. @@ -2285,6 +2371,8 @@ static void mpam_msc_drv_remove(struct platform_device *pdev)if (!msc)return ;
Quoted 4 lines
drivers/resctrl/mpam_devices.c static void mpam_msc_drv_remove(struct platform_device *pdev) · line 2375
Quoted 2 lines
drivers/resctrl/mpam_devices.c +2
-0+mpam_pcc_chan_put (msc->pcc_chan); +I think this should be in
mpam_msc_destroy()so we don't leak the channel onmpam_disable().
Yes, indeed we would be missing that, when tearing the driver down this way. Moved.
Cheers,
Andre
Quoted 129 lines
Quoted 128 lines
drivers/resctrl/mpam_devices.c +29
-2mutex_lock (&mpam_list_lock);mpam_msc_destroy (msc);mutex_unlock (&mpam_list_lock);@@ -2295,7 +2383,7 @@ static void mpam_msc_drv_remove(struct platform_device *pdev)static struct mpam_msc *do_mpam_msc_drv_probe (struct platform_device *pdev) {int err; -u32 tmp; +u32 pcc_subspace_id;struct mpam_msc *msc;struct resource *msc_res;struct device *dev = &pdev->dev;@@ -2339,7 +2427,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)if (err)return ERR_PTR (err); -if (device_property_read_u32 (&pdev->dev,"pcc-channel" , &tmp)) +if (device_property_read_u32 (dev,"pcc-channel" , &pcc_subspace_id)) msc->iface =MPAM_IFACE_MMIO ;else msc->iface =MPAM_IFACE_PCC ;@@ -2360,6 +2448,33 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) } msc->mapped_hwpage_sz = msc_res->end - msc_res->start; msc->mapped_hwpage = io; + }else if (msc->iface ==MPAM_IFACE_PCC ) { +u32 mpam_fb_msc_id; + + msc->pcc_chan =mpam_pcc_chan_get (dev, pcc_subspace_id); +if (IS_ERR (msc->pcc_chan)) { +pr_err ("Failed to request MSC PCC channel\n" ); +return ERR_CAST (msc->pcc_chan); + } + + err =mpam_fb_check_shared_buffer_size (msc); +if (err) { +mpam_pcc_chan_put (msc->pcc_chan); + +return ERR_PTR (err); + } + + err =mpam_fb_check_protocol_version (msc); +if (err) { +mpam_pcc_chan_put (msc->pcc_chan); + +return ERR_PTR (err); + } + +if (device_property_read_u32 (&pdev->dev,"mpam-fb-msc-id" , + &mpam_fb_msc_id)) + mpam_fb_msc_id = msc->id; + msc->mpam_fb_msc_id = mpam_fb_msc_id; }else {return ERR_PTR (-EINVAL ); }drivers/resctrl/mpam_fb.c +41
-0@@ -20,10 +20,15 @@#define MPAM_FB_PROTOCOL_ID 0x1a#define MPAM_PROTOCOL_VERSION_CMD 0x0 +#define MPAM_FB_VERSION_MAJOR_MASK GENMASK_U32(31, 16) +#define MPAM_FB_VERSION_MINOR_MASK GENMASK_U32(15, 0) +#define MPAM_MSC_READ_CMD 0x4#define MPAM_MSC_WRITE_CMD 0x5#define MPAM_FB_PROT_HEADER_LEN sizeof(u32) +/* The longest message is MPAM_MSC_WRITE, with 4 parameters. */ +#define MPAM_FB_MAX_MSG_SIZE (4 * sizeof(u32))#define MPAM_FB_SUCCESS 0#define MPAM_FB_ERR_NOT_SUPPORTED -1@@ -209,3 +214,39 @@ int mpam_fb_send_write_request(struct mpam_msc *msc, u16 reg, u32 value)return mpam_fb_send_request (msc, msc->mpam_fb_msc_id, reg, &value,MPAM_MSC_WRITE_CMD ); } + +/* We only support MPAM-Fb protocol version 1.x */ +int mpam_fb_check_protocol_version (struct mpam_msc *msc) +{ +u32 version; +int ret; + + ret =mpam_fb_send_request (msc,0 ,0 , &version, +MPAM_PROTOCOL_VERSION_CMD ); +if (ret) +return ret; + +if (FIELD_GET (MPAM_FB_VERSION_MAJOR_MASK , version) !=1 ) { +pr_err ("Incompatible MPAM-Fb protocol version %d.%d\n" , +FIELD_GET (MPAM_FB_VERSION_MAJOR_MASK , version), +FIELD_GET (MPAM_FB_VERSION_MINOR_MASK , version)); + +return -EINVAL ; + } + +return 0 ; +} + +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc) +{ +int min_buffer_size =MPAM_FB_MAX_MSG_SIZE + +sizeof (struct acpi_pcct_ext_pcc_shared_memory ); + +if (msc->pcc_chan->pcc_chan->shmem_size < min_buffer_size) { +pr_err ("MPAM-Fb PCC channel size too small.\n" ); + +return -ENOMEM ; + } + +return 0 ; +}drivers/resctrl/mpam_internal.h +2
-0@@ -538,6 +538,8 @@ static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }/* MPAM-Fb Firmware-backed protocol wrappers */ int mpam_fb_send_read_request (struct mpam_msc *msc,u16 reg,u32 *result);int mpam_fb_send_write_request (struct mpam_msc *msc,u16 reg,u32 value); +int mpam_fb_check_protocol_version (struct mpam_msc *msc); +int mpam_fb_check_shared_buffer_size (struct mpam_msc *msc);/* * MPAM MSCs have the following register layout. See:
RFC PATCH v10 13/14 ACPICA: actbl2.h: MPAM: adapt to MPAM ACPI v3.1 changes
In reply to Andre PrzywaraThere is a pending update to the ACPI for MPAM platform design document (Arm DEN0065: [1]), which re-purposes the "Reserved2" field in the MSC node as holding an MPAM-Fb offset value, to allow several MPAM-Fb firmware managers in a system, each using their own internal MSC ID namespace. The "Identifier" field in the same table still holds an ID which is unique per system, but within the MPAM-Fb protocol a private ID is used. The difference between the two is held in this new field.
Change the name of the struct member from "reserved2" to "mpam_fb_offset", to allow using that value in the code.
[1] https://support.arm.com/documentation/den0065/3-0/
---
Hi,
I do understand that the header file update should go via the ACPICA repo on github first, just wanted to present the full picture here on the kernel side.
Thanks,
Andre
drivers/acpi/arm64/mpam.c | 2 +- include/acpi/actbl2.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/arm64/mpam.c +1 -1
@@ -338,7 +338,7 @@ static int __init acpi_mpam_parse(void)* to enable it safely, because we cannot determine safe * system-wide partid and pmg ranges in this situation. */ -if (tbl_msc->reserved || tbl_msc->reserved1 || tbl_msc->reserved2) { +if (tbl_msc->reserved || tbl_msc->reserved1) {pr_err_once ("Unrecognised MSC, MPAM not usable\n" );pr_debug ("MSC.%u: reserved field set\n" , tbl_msc->identifier);continue ;
include/acpi/actbl2.h +1 -1
@@ -1971,7 +1971,7 @@ struct acpi_mpam_msc_node {u32 overflow_interrupt_affinity;u32 error_interrupt;u32 error_interrupt_flags; -u32 reserved2; +u32 mpam_fb_offset;u32 error_interrupt_affinity;u32 max_nrdy_usec;u64 hardware_id_linked_device;
Signature · 1 line
2.43.0
RFC PATCH v10 14/14 acpi: arm64: use MPAM-Fb offset field from ACPI table
In reply to Andre PrzywaraThe newly introduced mpam_fb_offset field in the MSC node ACPI table holds the difference between the system-wide MSC ID, as held in the "Identifier" field, and the ID to be used on the MPAM-Fb protocol level.
Subtract that value from the MSC ID and store that in the mpam_fb_msc_id property, so that the MPAM-Fb code can correctly address the MSCs. Previously this field was marked as "must-be-zero", so there would be no change when using older tables.
--- drivers/acpi/arm64/mpam.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/acpi/arm64/mpam.c +2 -1
@@ -257,7 +257,8 @@ static struct platform_device * __init acpi_mpam_parse_msc(struct acpi_mpam_msc_ props[next_prop++] =PROPERTY_ENTRY_U32 ("pcc-channel" , tbl_msc->base_address); props[next_prop++] =PROPERTY_ENTRY_U32 ("mpam-fb-msc-id" , - tbl_msc->identifier); + tbl_msc->identifier - + tbl_msc->mpam_fb_offset); }acpi_mpam_parse_irqs (pdev, tbl_msc, res, &next_res);
Signature · 1 line
2.43.0