Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
ccca672
arm_mpam: Ensure in_reset_state is false after applying configuration
henryZe Mar 13, 2026
ef8bca8
arm_mpam: Reset when feature configuration bit unset
benhor01 Mar 13, 2026
362574f
arm64/sysreg: Add MPAMSM_EL1 register
benhor01 Mar 13, 2026
b402200
KVM: arm64: Preserve host MPAM configuration when changing traps
benhor01 Mar 13, 2026
825d05c
KVM: arm64: Make MPAMSM_EL1 accesses UNDEF
benhor01 Mar 13, 2026
95aeaa4
arm64: mpam: Context switch the MPAM registers
Mar 13, 2026
6d0c883
arm64: mpam: Re-initialise MPAM regs when CPU comes online
Mar 13, 2026
b427b9f
arm64: mpam: Drop the CONFIG_EXPERT restriction
benhor01 Mar 13, 2026
e10ca7a
arm64: mpam: Advertise the CPUs MPAM limits to the driver
Mar 13, 2026
3379acc
arm64: mpam: Add cpu_pm notifier to restore MPAM sysregs
Mar 13, 2026
6a0490f
arm64: mpam: Initialise and context switch the MPAMSM_EL1 register
benhor01 Mar 13, 2026
7d4f7f9
arm64: mpam: Add helpers to change a task or cpu's MPAM PARTID/PMG va…
Mar 13, 2026
244511f
arm_mpam: resctrl: Add boilerplate cpuhp and domain allocation
Mar 13, 2026
c8bf60c
arm_mpam: resctrl: Pick the caches we will use as resctrl resources
Mar 13, 2026
81c270c
arm_mpam: resctrl: Implement resctrl_arch_reset_all_ctrls()
Mar 13, 2026
b9dc7e3
arm_mpam: resctrl: Add resctrl_arch_get_config()
Mar 13, 2026
39a8356
arm_mpam: resctrl: Implement helpers to update configuration
Mar 13, 2026
4658533
arm_mpam: resctrl: Add plumbing against arm64 task and cpu hooks
Mar 13, 2026
7c3b464
arm_mpam: resctrl: Add CDP emulation
Mar 13, 2026
baecc1e
arm_mpam: resctrl: Hide CDP emulation behind CONFIG_EXPERT
benhor01 Mar 13, 2026
33377dd
arm_mpam: resctrl: Convert to/from MPAMs fixed-point formats
Mar 13, 2026
7b58c97
arm_mpam: resctrl: Add rmid index helpers
benhor01 Mar 13, 2026
e2da3bf
arm_mpam: resctrl: Wait for cacheinfo to be ready
benhor01 Mar 13, 2026
57d50d7
arm_mpam: resctrl: Add support for 'MB' resource
Mar 13, 2026
aa243ac
arm_mpam: resctrl: Add kunit test for control format conversions
Mar 13, 2026
525443b
arm_mpam: resctrl: Add monitor initialisation and domain boilerplate
benhor01 Mar 13, 2026
2ef3779
arm_mpam: resctrl: Add support for csu counters
Mar 13, 2026
658399c
arm_mpam: resctrl: Allow resctrl to allocate monitors
Mar 13, 2026
864fa57
arm_mpam: resctrl: Add resctrl_arch_rmid_read()
Mar 13, 2026
812ea7b
arm_mpam: resctrl: Update the rmid reallocation limit
Mar 13, 2026
581305c
arm_mpam: resctrl: Add empty definitions for assorted resctrl functions
Mar 13, 2026
1a287f8
ALSA: usb-audio: Replace hard-coded number with MAX_CHANNELS
tiwai Mar 27, 2026
0bbfc01
arm64: mpam: Select ARCH_HAS_CPU_RESCTRL
Mar 13, 2026
9cb919d
arm_mpam: resctrl: Call resctrl_init() on platforms that can support …
Mar 13, 2026
ece939c
arm_mpam: Add quirk framework
shankerd04 Mar 13, 2026
c7e5a30
arm_mpam: Add workaround for T241-MPAM-1
shankerd04 Mar 13, 2026
8e795b7
arm_mpam: Add workaround for T241-MPAM-4
shankerd04 Mar 13, 2026
10792e8
arm_mpam: Add workaround for T241-MPAM-6
shankerd04 Mar 13, 2026
3b4acd3
arm_mpam: Quirk CMN-650's CSU NRDY behaviour
Mar 13, 2026
4664c58
arm64: mpam: Add initial MPAM documentation
benhor01 Mar 13, 2026
bcb4169
fs/resctrl: Report invalid domain ID when parsing io_alloc_cbm
aarontomlin Mar 25, 2026
3fe1d93
fs/resctrl: Add "*" shorthand to set io_alloc CBM for all domains
aarontomlin Mar 25, 2026
068050b
MAINTAINERS: Update resctrl entry
rchatre Apr 7, 2026
5731233
fs/resctrl: Add missing return value descriptions
rchatre Apr 7, 2026
f882f42
arm_mpam: resctrl: Fix MBA CDP alloc_capable handling on unmount
henryZe Apr 13, 2026
5943060
arm_mpam: resctrl: Fix the check for no monitor components found
benhor01 Apr 14, 2026
4a62598
arm_mpam: resctrl: Make resctrl_mon_ctx_waiters static
benhor01 Apr 14, 2026
75d4de9
NVIDIA: SAUCE: Update annotations to set CONFIG_RESCTRL_FS
fyu1 Apr 30, 2026
c673322
NVIDIA: VR: SAUCE: untested: arm_mpam: resctrl: pick classes for use …
Sep 7, 2021
d653685
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Pre-allocate free running monitors
Jul 15, 2025
e520145
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Pre-allocate assignable monitors
Oct 15, 2025
e06479d
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Add kunit test for ABMC/CDP int…
Oct 16, 2025
668c124
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Add resctrl_arch_config_cntr() …
Oct 15, 2025
77c933a
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Add resctrl_arch_rmid_read() an…
Jun 25, 2021
c0fe879
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Add resctrl_arch_cntr_read() & …
Aug 26, 2025
bc1ce80
NVIDIA: VR: SAUCE: fs/resctrl: Avoid a race with dom_data_exit() and …
Jun 10, 2024
465b8ee
NVIDIA: VR: SAUCE: fs/resctrl: Avoid a race with dom_data_exit() and …
Jun 10, 2024
7ce35e0
NVIDIA: VR: SAUCE: debugfs: Add helpers for creating cpumask entries …
Dec 22, 2022
9acc219
NVIDIA: VR: SAUCE: arm_mpam: Add debugfs entries to show the MSC/RIS …
Sep 1, 2021
c4e649f
NVIDIA: VR: SAUCE: arm_mpam: Add force-disable debugfs trigger
Jul 29, 2024
906c88e
NVIDIA: VR: SAUCE: arm_mpam: Expose the number of NRDY retries in deb…
Jul 18, 2025
39be102
NVIDIA: VR: SAUCE: arm_mpam: Add resctrl_arch_round_bw()
Aug 15, 2025
52bb890
NVIDIA: VR: SAUCE: fs/resctrl,x86/resctrl: Factor mba rounding to be …
Aug 15, 2025
17a769b
NVIDIA: VR: SAUCE: arm_mpam: Split the locking around the mon_sel reg…
Sep 29, 2025
434f0c9
NVIDIA: VR: SAUCE: arm_mpam: Allow the maximum partid to be overridde…
Oct 29, 2021
f8daf5c
NVIDIA: VR: SAUCE: arm_mpam: Allow MSC to be forced to have an unknow…
Jul 1, 2025
a048219
NVIDIA: VR: SAUCE: fs/resctrl: Add this_is_not_abi mount option
Sep 15, 2022
7386548
NVIDIA: VR: SAUCE: iommu/arm-smmu-v3: Register SMMU capabilities with…
Sep 17, 2021
d49f014
NVIDIA: VR: SAUCE: iommu/arm-smmu-v3: Add mpam helpers to query and s…
Sep 14, 2021
d8833a4
NVIDIA: VR: SAUCE: iommu: Add helpers to get and set the QoS state
Jul 31, 2023
edd415b
NVIDIA: VR: SAUCE: iommu: Add helpers to retrieve iommu_groups by id …
Sep 16, 2021
71baec2
NVIDIA: VR: SAUCE: iommu: Add helper to retrieve iommu kset
Jul 31, 2023
032978d
NVIDIA: VR: SAUCE: kobject: Add kset_get_next_obj() to allow a kset t…
Sep 16, 2021
1040b3a
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Add iommu helpers to get/set th…
Jul 31, 2023
c6ab755
NVIDIA: VR: SAUCE: fs/resctrl: Add support for assigning iommu_groups…
Sep 16, 2021
aed9791
NVIDIA: VR: SAUCE: firmware: arm_scmi: add MPAM-FB SCMI protocol stub
Andre-ARM May 21, 2024
e493037
NVIDIA: VR: SAUCE: arm_mpam: add MPAM-FB MSC firmware access support
Sep 23, 2025
4275760
NVIDIA: VR: SAUCE: arm_mpam: Allow duplicate PCC subspace_ids
Jun 28, 2024
74270b2
NVIDIA: VR: SAUCE: untested: mpam: Convert pcc_channels list to XArra…
Jul 2, 2025
20f1f56
NVIDIA: VR: SAUCE: x86/resctrl: Add stub to allow other architecture …
Mar 15, 2024
66c73d6
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Determine if any exposed counte…
Mar 15, 2024
27a33ff
NVIDIA: VR: SAUCE: fs/restrl: Allow the overflow handler to be disabled
Mar 15, 2024
573d10f
NVIDIA: VR: SAUCE: fs/resctrl: Uniform data type of component_id/domi…
Mar 11, 2024
7161cdb
NVIDIA: VR: SAUCE: arm_mpam: Allow cmax/cmin to be configured
Aug 27, 2024
de7a05a
NVIDIA: VR: SAUCE: arm_mpam: Rename mbw conversion to 'fract16' for c…
Nov 19, 2024
b5c5316
NVIDIA: VR: SAUCE: fs/resctrl: Group all the MBA specific properties …
Nov 18, 2024
9929d50
NVIDIA: VR: SAUCE: fs/resctrl: Abstract duplicate domain test to a he…
Sep 10, 2024
5531a97
NVIDIA: VR: SAUCE: fs/resctrl: Move MBA supported check to parse_line…
Nov 19, 2024
7ce0bf1
NVIDIA: VR: SAUCE: fs/resctrl: Rename resctrl_get_default_ctrl() to i…
Nov 19, 2024
f59372d
NVIDIA: VR: SAUCE: fs/resctrl: Add a schema format to the schema, all…
Nov 20, 2024
646c7ae
NVIDIA: VR: SAUCE: fs/resctrl: Use schema format to check the resourc…
Sep 27, 2024
9861237
NVIDIA: VR: SAUCE: fs/resctrl: Add specific schema types for 'range'
Nov 20, 2024
89f91ff
NVIDIA: VR: SAUCE: x86/resctrl: Move over to specifying MBA control f…
Nov 20, 2024
418b1eb
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Convert MB resource to use perc…
Nov 20, 2024
0eb3d97
NVIDIA: VR: SAUCE: fs/resctrl: Remove 'range' schema format
Nov 20, 2024
fa292d3
NVIDIA: VR: SAUCE: fs/resctrl: Add additional files for percentage an…
Nov 20, 2024
3121c3e
NVIDIA: VR: SAUCE: fs/resctrl: Add fflags_from_schema() for files bas…
Nov 20, 2024
c4b427f
NVIDIA: VR: SAUCE: fs/resctrl: Expose the schema format to user-space
Sep 10, 2024
8f73325
NVIDIA: VR: SAUCE: fs/resctrl: Add L2 and L3 'MAX' resource schema
Nov 19, 2024
dfc5316
NVIDIA: VR: SAUCE: arm_mpam: resctrl: Add the glue code to convert to…
Nov 19, 2024
a4c9c30
NVIDIA: VR: SAUCE: arm_mpam: Avoid MSC teardown for the SW programmin…
shankerd04 Nov 24, 2025
be85015
NVIDIA: VR: SAUCE: arm_mpam: Handle CPU-less numa nodes
shankerd04 May 13, 2025
7b957b7
NVIDIA: VR: SAUCE: arm_mpam: Include all associated
shankerd04 Nov 24, 2025
3e04efc
NVIDIA: VR: SAUCE: resctrl/mpam: reset RIS by applying explicit defau…
shankerd04 Mar 4, 2026
2f8ad7b
NVIDIA: VR: SAUCE: iommu/arm-smmu-v3: Fix MPAM for indentity-mappings
shankerd04 May 7, 2025
b723c7e
NVIDIA: VR: SAUCE: resctrl: add MB_HLIM resource ID and schema type
fyu1 Apr 6, 2026
2c8a937
NVIDIA: VR: SAUCE: resctrl: wire MB_HLIM schemata parsing and group s…
fyu1 Apr 6, 2026
049ba69
NVIDIA: VR: SAUCE: resctrl/mpam: probe MPAMF_MBW_IDR MAX_LIM and hard…
fyu1 Apr 6, 2026
3fab9aa
NVIDIA: VR: SAUCE: resctrl/mpam: track MBW max hard-limit in config
fyu1 Apr 6, 2026
6353bad
NVIDIA: VR: SAUCE: resctrl/mpam: bind MB_HLIM resource to MBA MPAM class
fyu1 Apr 6, 2026
1d481bd
NVIDIA: VR: SAUCE: resctrl: add membw.mb_max_lim and arch_has_mb_max_lim
fyu1 Apr 6, 2026
6fcf89f
NVIDIA: VR: SAUCE: resctrl/mpam: populate MBA mb_max_lim from MPAM probe
fyu1 Apr 6, 2026
cb558bd
NVIDIA: VR: SAUCE: resctrl: add MBA max_lim sysfs and visibility from…
fyu1 Apr 6, 2026
65d7ed7
NVIDIA: VR: SAUCE: Documentation: resctrl: document max_lim and MB_HL…
fyu1 Apr 6, 2026
475f355
NVIDIA: SAUCE: Fix mbm_L3_assign and mon_local_bytes
fyu1 May 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Documentation/arch/arm64/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ARM64 Architecture
memory
memory-tagging-extension
mops
mpam
perf
pointer-authentication
ptdump
Expand Down
72 changes: 72 additions & 0 deletions Documentation/arch/arm64/mpam.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.. SPDX-License-Identifier: GPL-2.0

====
MPAM
====

What is MPAM
============
MPAM (Memory Partitioning and Monitoring) is a feature in the CPUs and memory
system components such as the caches or memory controllers that allow memory
traffic to be labelled, partitioned and monitored.

Traffic is labelled by the CPU, based on the control or monitor group the
current task is assigned to using resctrl. Partitioning policy can be set
using the schemata file in resctrl, and monitor values read via resctrl.
See Documentation/filesystems/resctrl.rst for more details.

This allows tasks that share memory system resources, such as caches, to be
isolated from each other according to the partitioning policy (so called noisy
neighbours).

Supported Platforms
===================
Use of this feature requires CPU support, support in the memory system
components, and a description from firmware of where the MPAM device controls
are in the MMIO address space. (e.g. the 'MPAM' ACPI table).

The MMIO device that provides MPAM controls/monitors for a memory system
component is called a memory system component. (MSC).

Because the user interface to MPAM is via resctrl, only MPAM features that are
compatible with resctrl can be exposed to user-space.

MSC are considered as a group based on the topology. MSC that correspond with
the L3 cache are considered together, it is not possible to mix MSC between L2
and L3 to 'cover' a resctrl schema.

The supported features are:

* Cache portion bitmap controls (CPOR) on the L2 or L3 caches. To expose
CPOR at L2 or L3, every CPU must have a corresponding CPU cache at this
level that also supports the feature. Mismatched big/little platforms are
not supported as resctrl's controls would then also depend on task
placement.

* Memory bandwidth maximum controls (MBW_MAX) on or after the L3 cache.
resctrl uses the L3 cache-id to identify where the memory bandwidth
control is applied. For this reason the platform must have an L3 cache
with cache-id's supplied by firmware. (It doesn't need to support MPAM.)

To be exported as the 'MB' schema, the topology of the group of MSC chosen
must match the topology of the L3 cache so that the cache-id's can be
repainted. For example: Platforms with Memory bandwidth maximum controls
on CPU-less NUMA nodes cannot expose the 'MB' schema to resctrl as these
nodes do not have a corresponding L3 cache. If the memory bandwidth
control is on the memory rather than the L3 then there must be a single
global L3 as otherwise it is unknown which L3 the traffic came from. There
must be no caches between the L3 and the memory so that the two ends of
the path have equivalent traffic.

When the MPAM driver finds multiple groups of MSC it can use for the 'MB'
schema, it prefers the group closest to the L3 cache.

* Cache Storage Usage (CSU) counters can expose the 'llc_occupancy' provided
there is at least one CSU monitor on each MSC that makes up the L3 group.
Exposing CSU counters from other caches or devices is not supported.

Reporting Bugs
==============
If you are not seeing the counters or controls you expect please share the
debug messages produced when enabling dynamic debug and booting with:
dyndbg="file mpam_resctrl.c +pl"
9 changes: 9 additions & 0 deletions Documentation/arch/arm64/silicon-errata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ stable kernels.
+----------------+-----------------+-----------------+-----------------------------+
| ARM | SI L1 | #4311569 | ARM64_ERRATUM_4311569 |
+----------------+-----------------+-----------------+-----------------------------+
| ARM | CMN-650 | #3642720 | N/A |
+----------------+-----------------+-----------------+-----------------------------+
+----------------+-----------------+-----------------+-----------------------------+
| Broadcom | Brahma-B53 | N/A | ARM64_ERRATUM_845719 |
+----------------+-----------------+-----------------+-----------------------------+
| Broadcom | Brahma-B53 | N/A | ARM64_ERRATUM_843419 |
Expand Down Expand Up @@ -247,6 +250,12 @@ stable kernels.
+----------------+-----------------+-----------------+-----------------------------+
| NVIDIA | T241 GICv3/4.x | T241-FABRIC-4 | N/A |
+----------------+-----------------+-----------------+-----------------------------+
| NVIDIA | T241 MPAM | T241-MPAM-1 | N/A |
+----------------+-----------------+-----------------+-----------------------------+
| NVIDIA | T241 MPAM | T241-MPAM-4 | N/A |
+----------------+-----------------+-----------------+-----------------------------+
| NVIDIA | T241 MPAM | T241-MPAM-6 | N/A |
+----------------+-----------------+-----------------+-----------------------------+
+----------------+-----------------+-----------------+-----------------------------+
| Freescale/NXP | LS2080A/LS1043A | A-008585 | FSL_ERRATUM_A008585 |
+----------------+-----------------+-----------------+-----------------------------+
Expand Down
49 changes: 45 additions & 4 deletions Documentation/filesystems/resctrl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ related to allocation:
# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
0=00ff;1=000f

An ID of "*" configures all domains with the provided CBM.

Example on a system that does not require a minimum number of consecutive bits in the mask::

# echo "*=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm
# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
0=0;1=0

When CDP is enabled "io_alloc_cbm" associated with the CDP_DATA and CDP_CODE
resources may reflect the same values. For example, values read from and
written to /sys/fs/resctrl/info/L3DATA/io_alloc_cbm may be reflected by
Expand All @@ -228,18 +236,30 @@ with respect to allocation:
user can request.

"bandwidth_gran":
The granularity in which the memory bandwidth
The approximate granularity in which the memory bandwidth
percentage is allocated. The allocated
b/w percentage is rounded off to the next
control step available on the hardware. The
available bandwidth control steps are:
min_bandwidth + N * bandwidth_gran.
control step available on the hardware. The available
steps are at least as small as this value.

"delay_linear":
Indicates if the delay scale is linear or
non-linear. This field is purely informational
only.

"max_lim":
Read-only. On ARM MPAM systems where MBA exposes MBW_MAX, this
file contains a single decimal integer: the
``MPAMF_MBW_IDR.MAX_LIM`` field [1:0] (values ``0``–``3``) as probed for the MBA resource.
The file appears only when the platform supports MBA MBW_MAX and
the MAX_LIM value is available; otherwise it is not listed.

The Arm MPAM architecture defines the meaning of each MAX_LIM
encoding. In this kernel, when ``max_lim`` reads ``0``, the
driver treats the ``HARDLIM`` bit of ``MPAMCFG_MBW_MAX`` as
read/write and an optional ``MB_HLIM`` line may appear in
``schemata``. When ``max_lim`` is nonzero, ``MB_HLIM`` is omitted.

"thread_throttle_mode":
Indicator on Intel systems of how tasks running on threads
of a physical core are throttled in cases where they
Expand Down Expand Up @@ -956,6 +976,27 @@ Memory bandwidth domain is L3 cache.

MB:<cache_id0>=bw_MiBps0;<cache_id1>=bw_MiBps1;...

MBW maximum hard limit (ARM MPAM)
---------------------------------
On some ARM systems, resctrl memory bandwidth allocation uses MPAM
maximum bandwidth (MBW_MAX). When ``max_lim`` reads ``0`` (see ``max_lim``
under the ``MB`` allocation ``info`` directory), an additional schemata
line selects the ``HARDLIM`` bit for ``MPAMCFG_MBW_MAX`` independently of
the numeric limit on the ``MB`` line.

The line uses the same cache/domain indices as ``MB``. Each value must
be ``0`` or ``1``: ``0`` clears HARDLIM (soft-limit behaviour for the
max), ``1`` sets HARDLIM (hard limit). When ``max_lim`` is nonzero or
``MB_HLIM`` is not supported for the platform, the line is omitted from
``schemata``.

Format:
::

MB_HLIM:<cache_id0>=0|1;<cache_id1>=0|1;...

The corresponding ``schema_format`` entry under ``info`` is ``mb_hlim``.

Slow Memory Bandwidth Allocation (SMBA)
---------------------------------------
AMD hardware supports Slow Memory Bandwidth Allocation (SMBA).
Expand Down
2 changes: 2 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -22198,11 +22198,13 @@ F: tools/testing/selftests/net/rds/
RDT - RESOURCE ALLOCATION
M: Tony Luck <tony.luck@intel.com>
M: Reinette Chatre <reinette.chatre@intel.com>
M: x86@kernel.org
R: Dave Martin <Dave.Martin@arm.com>
R: James Morse <james.morse@arm.com>
R: Babu Moger <babu.moger@amd.com>
L: linux-kernel@vger.kernel.org
S: Supported
P: Documentation/process/maintainer-tip.rst
F: Documentation/filesystems/resctrl.rst
F: arch/x86/include/asm/resctrl.h
F: arch/x86/kernel/cpu/resctrl/
Expand Down
6 changes: 4 additions & 2 deletions arch/arm64/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2017,8 +2017,8 @@ config ARM64_TLB_RANGE

config ARM64_MPAM
bool "Enable support for MPAM"
select ARM64_MPAM_DRIVER if EXPERT # does nothing yet
select ACPI_MPAM if ACPI
select ARM64_MPAM_DRIVER
select ARCH_HAS_CPU_RESCTRL
help
Memory System Resource Partitioning and Monitoring (MPAM) is an
optional extension to the Arm architecture that allows each
Expand All @@ -2040,6 +2040,8 @@ config ARM64_MPAM

MPAM is exposed to user-space via the resctrl pseudo filesystem.

This option enables the extra context switch code.

endmenu # "ARMv8.4 architectural features"

menu "ARMv8.5 architectural features"
Expand Down
3 changes: 2 additions & 1 deletion arch/arm64/include/asm/el2_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@
check_override id_aa64pfr0, ID_AA64PFR0_EL1_MPAM_SHIFT, .Linit_mpam_\@, .Lskip_mpam_\@, x1, x2

.Linit_mpam_\@:
msr_s SYS_MPAM2_EL2, xzr // use the default partition
mov x0, #MPAM2_EL2_EnMPAMSM_MASK
msr_s SYS_MPAM2_EL2, x0 // use the default partition,
// and disable lower traps
mrs_s x0, SYS_MPAMIDR_EL1
tbz x0, #MPAMIDR_EL1_HAS_HCR_SHIFT, .Lskip_mpam_\@ // skip if no MPAMHCR reg
Expand Down
96 changes: 96 additions & 0 deletions arch/arm64/include/asm/mpam.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2025 Arm Ltd. */

#ifndef __ASM__MPAM_H
#define __ASM__MPAM_H

#include <linux/arm_mpam.h>
#include <linux/bitfield.h>
#include <linux/jump_label.h>
#include <linux/percpu.h>
#include <linux/sched.h>

#include <asm/sysreg.h>

DECLARE_STATIC_KEY_FALSE(mpam_enabled);
DECLARE_PER_CPU(u64, arm64_mpam_default);
DECLARE_PER_CPU(u64, arm64_mpam_current);

/*
* The value of the MPAM0_EL1 sysreg when a task is in resctrl's default group.
* This is used by the context switch code to use the resctrl CPU property
* instead. The value is modified when CDP is enabled/disabled by mounting
* the resctrl filesystem.
*/
extern u64 arm64_mpam_global_default;

#ifdef CONFIG_ARM64_MPAM
static inline u64 __mpam_regval(u16 partid_d, u16 partid_i, u8 pmg_d, u8 pmg_i)
{
return FIELD_PREP(MPAM0_EL1_PARTID_D, partid_d) |
FIELD_PREP(MPAM0_EL1_PARTID_I, partid_i) |
FIELD_PREP(MPAM0_EL1_PMG_D, pmg_d) |
FIELD_PREP(MPAM0_EL1_PMG_I, pmg_i);
}

static inline void mpam_set_cpu_defaults(int cpu, u16 partid_d, u16 partid_i,
u8 pmg_d, u8 pmg_i)
{
u64 default_val = __mpam_regval(partid_d, partid_i, pmg_d, pmg_i);

WRITE_ONCE(per_cpu(arm64_mpam_default, cpu), default_val);
}

/*
* The resctrl filesystem writes to the partid/pmg values for threads and CPUs,
* which may race with reads in mpam_thread_switch(). Ensure only one of the old
* or new values are used. Particular care should be taken with the pmg field as
* mpam_thread_switch() may read a partid and pmg that don't match, causing this
* value to be stored with cache allocations, despite being considered 'free' by
* resctrl.
*/
static inline u64 mpam_get_regval(struct task_struct *tsk)
{
return READ_ONCE(task_thread_info(tsk)->mpam_partid_pmg);
}

static inline void mpam_set_task_partid_pmg(struct task_struct *tsk,
u16 partid_d, u16 partid_i,
u8 pmg_d, u8 pmg_i)
{
u64 regval = __mpam_regval(partid_d, partid_i, pmg_d, pmg_i);

WRITE_ONCE(task_thread_info(tsk)->mpam_partid_pmg, regval);
}

static inline void mpam_thread_switch(struct task_struct *tsk)
{
u64 oldregval;
int cpu = smp_processor_id();
u64 regval = mpam_get_regval(tsk);

if (!static_branch_likely(&mpam_enabled))
return;

if (regval == READ_ONCE(arm64_mpam_global_default))
regval = READ_ONCE(per_cpu(arm64_mpam_default, cpu));

oldregval = READ_ONCE(per_cpu(arm64_mpam_current, cpu));
if (oldregval == regval)
return;

write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
if (system_supports_sme())
write_sysreg_s(regval & (MPAMSM_EL1_PARTID_D | MPAMSM_EL1_PMG_D), SYS_MPAMSM_EL1);
isb();

/* Synchronising the EL0 write is left until the ERET to EL0 */
write_sysreg_s(regval, SYS_MPAM0_EL1);

WRITE_ONCE(per_cpu(arm64_mpam_current, cpu), regval);
}
#else
static inline void mpam_thread_switch(struct task_struct *tsk) {}
#endif /* CONFIG_ARM64_MPAM */

#endif /* __ASM__MPAM_H */
2 changes: 2 additions & 0 deletions arch/arm64/include/asm/resctrl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* SPDX-License-Identifier: GPL-2.0 */
#include <linux/arm_mpam.h>
3 changes: 3 additions & 0 deletions arch/arm64/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct thread_info {
#ifdef CONFIG_SHADOW_CALL_STACK
void *scs_base;
void *scs_sp;
#endif
#ifdef CONFIG_ARM64_MPAM
u64 mpam_partid_pmg;
#endif
u32 cpu;
};
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o
obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o
obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o
obj-$(CONFIG_ARM64_MPAM) += mpam.o
obj-$(CONFIG_ARM64_MTE) += mte.o
obj-y += vdso-wrap.o
obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.o
Expand Down
21 changes: 14 additions & 7 deletions arch/arm64/kernel/cpufeature.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <asm/kvm_host.h>
#include <asm/mmu.h>
#include <asm/mmu_context.h>
#include <asm/mpam.h>
#include <asm/mte.h>
#include <asm/hypervisor.h>
#include <asm/processor.h>
Expand Down Expand Up @@ -2501,13 +2502,19 @@ test_has_mpam(const struct arm64_cpu_capabilities *entry, int scope)
static void
cpu_enable_mpam(const struct arm64_cpu_capabilities *entry)
{
/*
* Access by the kernel (at EL1) should use the reserved PARTID
* which is configured unrestricted. This avoids priority-inversion
* where latency sensitive tasks have to wait for a task that has
* been throttled to release the lock.
*/
write_sysreg_s(0, SYS_MPAM1_EL1);
int cpu = smp_processor_id();
u64 regval = 0;

if (IS_ENABLED(CONFIG_ARM64_MPAM) && static_branch_likely(&mpam_enabled))
regval = READ_ONCE(per_cpu(arm64_mpam_current, cpu));

write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
if (cpus_have_cap(ARM64_SME))
write_sysreg_s(regval & (MPAMSM_EL1_PARTID_D | MPAMSM_EL1_PMG_D), SYS_MPAMSM_EL1);
isb();

/* Synchronising the EL0 write is left until the ERET to EL0 */
write_sysreg_s(regval, SYS_MPAM0_EL1);
}

static bool
Expand Down
Loading
Loading