Devicetree
 help / color / mirror / Atom feed
* [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl
@ 2026-08-11 13:30 Yin Li
  2026-08-11 13:30 ` [PATCH RFC 01/15] dt-bindings: arm: Add MPAM MSC binding Yin Li
                   ` (16 more replies)
  0 siblings, 17 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Notes for James, Shanker and Rob
--------------------------------
This series builds directly on your not-yet-upstream MPAM snapshot
patches from the mpam/snapshot+extras/v6.18-rc1 branch. Two things I'd
like your guidance on:

1. Do you mind us picking these up and continuing to extend them? We have
   kept the original authorship and Signed-off-by intact and documented
   the inherited-vs-new split below. If you would prefer a different
   attribution arrangement, or have your own plans to upstream MPAM DT
   support, please let us know so we can avoid duplicating effort.

2. The fixes to the inherited patches are kept as small, self-contained
   patches on top, purely to make review easier. Since fixes to
   not-yet-upstream patches would normally be squashed into the original
   commit by its author, please point out which of these you would like
   folded back, and we will reorganize accordingly.

Rob kindly provided some early off-list feedback on an earlier draft,
which this series has tried to address.

Add Arm MPAM resctrl basic device tree support.

Arm Memory System Resource Partitioning and Monitoring (MPAM) with
resctrl requires device tree (DT) support as a prerequisite before any
higher-level functionality can be enabled. This series provides the
foundational DT binding and parsing support for MPAM, laying the
groundwork for subsequent features such as MPAM Firmware-backed
(MPAM-FB) partitioning.

The patches are based on earlier work by James Morse, Shanker
Donthineni and Rob Herring, with fixes and additions on top:

Inherited (authorship preserved, with fixes noted in each patch):
- dt-bindings: MPAM MSC binding [1]
- cacheinfo: expose cache-id generation from a device_node [2]
- arm_mpam: device tree support for MSC probing [3]
- arm_mpam: memory controller MSC support on DT platforms [4]

New on top:
- standalone fixes extracted from the inherited patches (device_node
  refcount, cache-id sentinel/type, RIS index range checks, MSC window
  size, accessibility return type, foundling MSC creation, cache-id
  error path)
- dt-bindings: schema and example fixes
- arm_mpam: derive MSC accessibility from per-RIS nodes as a fallback

[1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=b38bed339681
[2] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=2af39084438c
[3] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=a6ab8b6c77cb
[4] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=c1be40782ace

DT affinity model
-----------------
An MSC node is nested under the device it partitions or monitors. For a
cache MSC this is the cache node, so the MSC's CPU affinity is derived
from its parent cache; for a memory-controller MSC the parent is the
memory device, which is accessible from all CPUs. A per-RIS fallback is
also provided: when an MSC sits under a generic container with no
affinity-bearing parent, affinity is resolved from an explicit 'cpus'
phandle or an 'arm,mpam-device' phandle on each RIS node.

The Kaanapali DTS patch is for local enabling and verification only and
cannot be upstreamed: the platform is already upstream with a public
device tree, and production firmware does not allow the OS to write the
MSC registers, so this path only works on a local test setup. The MSC
nodes are disabled by default, serving as a reference example for other
platform DT authors.

Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
To: James Morse <james.morse@arm.com>
To: Rob Herring <robh@kernel.org>
To: Shanker Donthineni <sdonthineni@nvidia.com>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Ben Horgan <ben.horgan@arm.com>
To: Conor Dooley <conor+dt@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
To: Danilo Krummrich <dakr@kernel.org>
To: Reinette Chatre <reinette.chatre@intel.com>
To: Fenghua Yu <fenghuay@nvidia.com>
To: Bjorn Andersson <andersson@kernel.org>
To: Konrad Dybcio <konradybcio@kernel.org>
Cc: trilok.soni@oss.qualcomm.com
Cc: aiqun.yu@oss.qualcomm.com
Cc: ganapatrao.kulkarni@oss.qualcomm.com
Cc: Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: driver-core@lists.linux.dev
Cc: devicetree@vger.kernel.org
Cc: trilok.soni@oss.qualcomm.com
Cc: aiqun.yu@oss.qualcomm.com
Cc: ganapatrao.kulkarni@oss.qualcomm.com
Cc: Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>

---
James Morse (2):
      cacheinfo: Expose the code to generate a cache-id from a device_node
      arm_mpam: Add device tree support for MSC probing

Rob Herring (1):
      dt-bindings: arm: Add MPAM MSC binding

Shanker Donthineni (1):
      arm_mpam: Add support for memory controller MSC on DT platforms

Yin Li (11):
      arm_mpam: Fix device_node refcount in DT resource parsing
      arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type
      arm_mpam: Fix the RIS index range check in mpam_ris_create_locked
      arm_mpam: Fix ris_idx type to prevent range check bypass on truncation
      arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start
      arm_mpam: Fix update_msc_accessibility() return type to void
      arm_mpam: Fix mpam_dt_create_foundling_msc() to create MSC platform devices
      arm_mpam: Fix get_cpumask_from_cache() to clear mask on error
      dt-bindings: arm: Fix MPAM MSC binding schema and examples
      arm_mpam: Support MSC accessibility derivation from RIS nodes
      [DNM] arm64: dts: qcom: kaanapali: Add MPAM MSC nodes for the L2 caches

 .../devicetree/bindings/arm/arm,mpam-msc.yaml      | 202 +++++++++++
 arch/arm64/boot/dts/qcom/kaanapali.dtsi            |  50 ++-
 drivers/base/cacheinfo.c                           |  19 +-
 drivers/resctrl/mpam_devices.c                     | 401 +++++++++++++++++++--
 drivers/resctrl/mpam_internal.h                    |   2 +-
 include/linux/arm_mpam.h                           |   4 +-
 include/linux/cacheinfo.h                          |   3 +
 7 files changed, 638 insertions(+), 43 deletions(-)
---
base-commit: 3d08ff75a47a3e7e2ab45a3bcab6723b4d906422
change-id: 20260731-mpam-resctrl-dt-knp-support-c15dcc3a4a98

Best regards,
--  
Yin Li <yin.li@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH RFC 01/15] dt-bindings: arm: Add MPAM MSC binding
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-09-03 10:03   ` Ben Horgan
  2026-08-11 13:30 ` [PATCH RFC 02/15] cacheinfo: Expose the code to generate a cache-id from a device_node Yin Li
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

From: Rob Herring <robh@kernel.org>

The binding is designed around the assumption that an MSC will be a
sub-block of something else such as a memory controller, cache controller,
or IOMMU. However, it's certainly possible a design does not have that
association or has a mixture of both, so the binding illustrates how we can
support that with RIS child nodes.

A key part of MPAM is we need to know about all of the MSCs in the system
before it can be enabled. This drives the need for the genericish
'arm,mpam-msc' compatible. Though we can't assume an MSC is accessible
until a h/w specific driver potentially enables the h/w.

Cc: James Morse <james.morse@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 .../devicetree/bindings/arm/arm,mpam-msc.yaml      | 199 +++++++++++++++++++++
 1 file changed, 199 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml b/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml
new file mode 100644
index 000000000000..53a6fdbbf05f
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml
@@ -0,0 +1,199 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/arm,mpam-msc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Arm Memory System Resource Partitioning and Monitoring (MPAM)
+
+description: |
+  The Arm MPAM specification can be found here:
+
+  https://developer.arm.com/documentation/ddi0598/latest
+
+maintainers:
+  - Rob Herring <robh@kernel.org>
+
+properties:
+  compatible:
+    items:
+      - const: arm,mpam-msc                   # Further details are discoverable
+      - const: arm,mpam-memory-controller-msc
+
+  reg:
+    maxItems: 1
+    description: A memory region containing registers as defined in the MPAM
+      specification.
+
+  interrupts:
+    minItems: 1
+    items:
+      - description: error (optional)
+      - description: overflow (optional, only for monitoring)
+
+  interrupt-names:
+    oneOf:
+      - items:
+          - enum: [ error, overflow ]
+      - items:
+          - const: error
+          - const: overflow
+
+  arm,not-ready-us:
+    description: The maximum time in microseconds for monitoring data to be
+      accurate after a settings change. For more information, see the
+      Not-Ready (NRDY) bit description in the MPAM specification.
+
+  numa-node-id: true # see NUMA binding
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+patternProperties:
+  '^ris@[0-9a-f]+$':
+    type: object
+    additionalProperties: false
+    description:
+      RIS nodes for each resource instance in an MSC. These nodes are required
+      for each resource instance implementing known MPAM controls
+
+    properties:
+      compatible:
+        enum:
+          - arm,mpam-cache
+          # Memory bandwidth
+          - arm,mpam-memory
+
+      reg:
+        minimum: 0
+        maximum: 0xf
+
+      cpus:
+        description:
+          Phandle(s) to the CPU node(s) this RIS belongs to. By default, the parent
+          device's affinity is used.
+
+      arm,mpam-device:
+        $ref: /schemas/types.yaml#/definitions/phandle
+        description:
+          By default, the MPAM enabled device associated with a RIS is the MSC's
+          parent node. It is possible for each RIS to be associated with different
+          devices in which case 'arm,mpam-device' should be used.
+
+    required:
+      - compatible
+      - reg
+
+required:
+  - compatible
+  - reg
+
+dependencies:
+  interrupts: [ interrupt-names ]
+
+additionalProperties: false
+
+examples:
+  - |
+    L3: cache-controller@30000000 {
+        compatible = "arm,dsu-l3-cache", "cache";
+        cache-level = <3>;
+        cache-unified;
+
+        ranges = <0x0 0x30000000 0x800000>;
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        msc@10000 {
+            compatible = "arm,mpam-msc";
+
+            reg = <0x10000 0x2000>;
+            interrupts = <1>, <2>;
+            interrupt-names = "error", "overflow";
+            arm,not-ready-us = <1>;
+            /* CPU affinity implied by parent cache node  */
+        };
+    };
+
+    mem: memory-controller@20000 {
+        compatible = "foo,a-memory-controller";
+        reg = <0x20000 0x1000>;
+
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges;
+
+        msc@21000 {
+            compatible = "arm,mpam-memory-controller-msc", "arm,mpam-msc";
+            reg = <0x21000 0x1000>;
+            interrupts = <3>;
+            interrupt-names = "error";
+            arm,not-ready-us = <1>;
+            numa-node-id = <1>;
+        };
+    };
+
+    iommu@40000 {
+        reg = <0x40000 0x1000>;
+
+        ranges;
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        msc@41000 {
+            compatible = "arm,mpam-msc";
+            reg = <0 0x1000>;
+            interrupts = <5>, <6>;
+            interrupt-names = "error", "overflow";
+            arm,not-ready-us = <1>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            ris@2 {
+                compatible = "arm,mpam-cache";
+                reg = <0>;
+                // TODO: How to map to device(s)?
+            };
+        };
+    };
+
+    msc@80000 {
+        compatible = "foo,a-standalone-msc";
+        reg = <0x80000 0x1000>;
+
+        clocks = <&clks 123>;
+
+        ranges;
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        msc@10000 {
+            compatible = "arm,mpam-msc";
+
+            reg = <0x10000 0x2000>;
+            interrupts = <7>;
+            interrupt-names = "overflow";
+            arm,not-ready-us = <1>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            ris@0 {
+                compatible = "arm,mpam-cache";
+                reg = <0>;
+                arm,mpam-device = <&L2_0>;
+            };
+
+            ris@1 {
+                compatible = "arm,mpam-memory";
+                reg = <1>;
+                arm,mpam-device = <&mem>;
+            };
+        };
+    };
+
+...

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 02/15] cacheinfo: Expose the code to generate a cache-id from a device_node
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
  2026-08-11 13:30 ` [PATCH RFC 01/15] dt-bindings: arm: Add MPAM MSC binding Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-08-25 19:11   ` Drew Fustini
  2026-08-11 13:30 ` [PATCH RFC 03/15] arm_mpam: Add device tree support for MSC probing Yin Li
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

From: James Morse <james.morse@arm.com>

The MPAM driver identifies caches by id for use with resctrl. It
needs to know the cache-id when probe-ing, but the value isn't set
in cacheinfo until device_initcall(). Even after device_initcall(),
the cache-id is only available if at least one CPU associated with
the cache is online.

Instead of making the driver wait, expose the code that generates the
cache-id. The parts of the MPAM driver that run early can use this to
set up the resctrl structures before cacheinfo is ready in
device_initcall().

Signed-off-by: James Morse <james.morse@arm.com>
[ Yin Li: fix context conflicts in cacheinfo.c and cacheinfo.h; guard the
  cache_of_calculate_id() declaration with CONFIG_OF to prevent build
  errors when CONFIG_OF is not set ]
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/base/cacheinfo.c  | 17 ++++++++++++-----
 include/linux/cacheinfo.h |  3 +++
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index 9f9c72727a05..f75e7f64038b 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -226,8 +226,7 @@ static bool match_cache_node(struct device_node *cpu,
 #define arch_compact_of_hwid(_x)	(_x)
 #endif
 
-static void cache_of_set_id(struct cacheinfo *this_leaf,
-			    struct device_node *cache_node)
+u32 cache_of_calculate_id(struct device_node *cache_node)
 {
 	struct device_node *cpu;
 	u32 min_id = ~0;
@@ -238,15 +237,23 @@ static void cache_of_set_id(struct cacheinfo *this_leaf,
 		id = arch_compact_of_hwid(id);
 		if (FIELD_GET(GENMASK_ULL(63, 32), id)) {
 			of_node_put(cpu);
-			return;
+			return ~0;
 		}
 
 		if (match_cache_node(cpu, cache_node))
 			min_id = min(min_id, id);
 	}
 
-	if (min_id != ~0) {
-		this_leaf->id = min_id;
+	return min_id;
+}
+
+static void cache_of_set_id(struct cacheinfo *this_leaf,
+			    struct device_node *cache_node)
+{
+	u32 id = cache_of_calculate_id(cache_node);
+
+	if (id != ~0) {
+		this_leaf->id = id;
 		this_leaf->attributes |= CACHE_ID;
 	}
 }
diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
index fc879ac4cc4f..c33bb3c8bd63 100644
--- a/include/linux/cacheinfo.h
+++ b/include/linux/cacheinfo.h
@@ -113,6 +113,9 @@ int acpi_get_cache_info(unsigned int cpu,
 #endif
 
 const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf);
+#ifdef CONFIG_OF
+u32 cache_of_calculate_id(struct device_node *np);
+#endif
 
 /*
  * Get the cacheinfo structure for the cache associated with @cpu at

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 03/15] arm_mpam: Add device tree support for MSC probing
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
  2026-08-11 13:30 ` [PATCH RFC 01/15] dt-bindings: arm: Add MPAM MSC binding Yin Li
  2026-08-11 13:30 ` [PATCH RFC 02/15] cacheinfo: Expose the code to generate a cache-id from a device_node Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-08-11 13:30 ` [PATCH RFC 04/15] arm_mpam: Add support for memory controller MSC on DT platforms Yin Li
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

From: James Morse <james.morse@arm.com>

The MPAM driver currently discovers MSCs only via ACPI. Add a device
tree path so MSCs can be probed on DT-based platforms: parse MSC nodes
from the device tree, compute cache-id and affinity from the cache
nodes and create the RIS entries.

Signed-off-by: James Morse <james.morse@arm.com>
[ Yin Li: fix context conflicts; drop the existing ACPI-only stub of
  mpam_get_cpumask_from_cache_id() which conflicted with the new
  implementation that supports both ACPI and DT; fix
  update_msc_accessibility() return type conflict: drop the existing
  void implementation and apply the int version from this patch ]
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 256 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 238 insertions(+), 18 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index dd422c56fbb1..6f2854fe08ca 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -20,6 +20,9 @@
 #include <linux/list.h>
 #include <linux/lockdep.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/printk.h>
 #include <linux/srcu.h>
@@ -161,6 +164,163 @@ static void mpam_free_garbage(void)
 	}
 }
 
+/* Called recursively to walk the list of caches from a particular CPU */
+static void __mpam_get_cpumask_from_cache_id(int cpu, struct device_node *cache_node,
+					     unsigned long cache_id,
+					     u32 cache_level,
+					     cpumask_t *affinity)
+{
+	int err;
+	u32 iter_level;
+	unsigned long iter_cache_id;
+	struct device_node *iter_node __free(device_node) = of_find_next_cache_node(cache_node);
+
+	if (!iter_node)
+		return;
+
+	err = of_property_read_u32(iter_node, "cache-level", &iter_level);
+	if (err)
+		return;
+
+	/*
+	 * get_cpu_cacheinfo_id() isn't ready until sometime
+	 * during device_initcall(). Use cache_of_calculate_id().
+	 */
+	iter_cache_id = cache_of_calculate_id(iter_node);
+	if (iter_cache_id == ~0UL)
+		return;
+
+	if (iter_level == cache_level && iter_cache_id == cache_id)
+		cpumask_set_cpu(cpu, affinity);
+
+	if (iter_level < cache_level)
+		__mpam_get_cpumask_from_cache_id(cpu, iter_node, cache_id,
+						 cache_level, affinity);
+}
+
+/*
+ * The cacheinfo structures are only populated when CPUs are online.
+ * This helper walks the device tree to include offline CPUs too.
+ */
+int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
+				   cpumask_t *affinity)
+{
+	int cpu;
+
+	if (!acpi_disabled)
+		return acpi_pptt_get_cpumask_from_cache_id(cache_id, affinity);
+
+	for_each_possible_cpu(cpu) {
+		struct device_node *cpu_node __free(device_node) = of_get_cpu_node(cpu, NULL);
+		if (!cpu_node) {
+			pr_err("Failed to find cpu%d device node\n", cpu);
+			return -ENOENT;
+		}
+
+		__mpam_get_cpumask_from_cache_id(cpu, cpu_node, cache_id,
+						 cache_level, affinity);
+	}
+
+	return 0;
+}
+
+static int get_cpumask_from_cache(struct device_node *cache,
+				  cpumask_t *affinity)
+{
+	int err;
+	u32 cache_level;
+	unsigned long cache_id;
+
+	err = of_property_read_u32(cache, "cache-level", &cache_level);
+	if (err) {
+		pr_err("Failed to read cache-level from cache node\n");
+		return -ENOENT;
+	}
+
+	cache_id = cache_of_calculate_id(cache);
+	if (cache_id == ~0UL) {
+		pr_err("Failed to calculate cache-id from cache node\n");
+		return -ENOENT;
+	}
+
+	return mpam_get_cpumask_from_cache_id(cache_id, cache_level, affinity);
+}
+
+static int mpam_dt_count_msc(void)
+{
+	int count = 0;
+	struct device_node *np;
+
+	for_each_compatible_node(np, NULL, "arm,mpam-msc") {
+		if (of_device_is_available(np))
+			count++;
+	}
+
+	return count;
+}
+
+static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
+				  u32 ris_idx)
+{
+	int err = 0;
+	u32 level = 0;
+	unsigned long cache_id;
+	struct device *dev = &msc->pdev->dev;
+	struct device_node *cache __free(device_node) = NULL;
+	struct device_node *parent __free(device_node) = of_get_parent(np);
+
+	if (of_device_is_compatible(np, "arm,mpam-cache")) {
+		cache = of_parse_phandle(np, "arm,mpam-device", 0);
+		if (!cache) {
+			dev_err_once(dev, "Failed to read phandle\n");
+			return -EINVAL;
+		}
+	} else if (of_device_is_compatible(parent, "cache")) {
+		cache = parent;
+	} else {
+		/* For now, only caches are supported */
+		cache = NULL;
+		return err;
+	}
+
+	err = of_property_read_u32(cache, "cache-level", &level);
+	if (err) {
+		dev_err_once(dev, "Failed to read cache-level\n");
+		return err;
+	}
+
+	cache_id = cache_of_calculate_id(cache);
+	if (cache_id == ~0) {
+		dev_err_once(dev, "Failed to calculate cache-id\n");
+		return -ENOENT;
+	}
+
+	return mpam_ris_create(msc, ris_idx, MPAM_CLASS_CACHE, level, cache_id);
+}
+
+static int mpam_dt_parse_resources(struct mpam_msc *msc, void *ignored)
+{
+	u64 ris_idx = 0;
+	int err, num_ris = 0;
+	struct device_node *np;
+
+	np = msc->pdev->dev.of_node;
+	for_each_available_child_of_node_scoped(np, iter) {
+		err = of_property_read_reg(iter, 0, &ris_idx, NULL);
+		if (!err) {
+			num_ris++;
+			err = mpam_dt_parse_resource(msc, iter, ris_idx);
+			if (err)
+				return err;
+		}
+	}
+
+	if (!num_ris)
+		err = mpam_dt_parse_resource(msc, np, 0);
+
+	return err;
+}
+
 /*
  * Once mpam is enabled, new requestors cannot further reduce the available
  * partid. Assert that the size is fixed, and new requestors will be turned
@@ -481,16 +641,6 @@ mpam_vmsc_find(struct mpam_component *comp, struct mpam_msc *msc)
 	return mpam_vmsc_alloc(comp, msc);
 }
 
-/*
- * The cacheinfo structures are only populated when CPUs are online.
- * This helper walks the acpi tables to include offline CPUs too.
- */
-int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
-				   cpumask_t *affinity)
-{
-	return acpi_pptt_get_cpumask_from_cache_id(cache_id, affinity);
-}
-
 /*
  * cpumask_of_node() only knows about online CPUs. This can't tell us whether
  * a class is represented on all possible CPUs.
@@ -1985,17 +2135,42 @@ static int mpam_msc_setup_error_irq(struct mpam_msc *msc)
  * corresponding cache may also be powered off. By making accesses from
  * one of those CPUs, we ensure we don't access a cache that's powered off.
  */
-static void update_msc_accessibility(struct mpam_msc *msc)
+static int update_msc_accessibility(struct mpam_msc *msc)
 {
+	struct device *dev = &msc->pdev->dev;
+	struct device_node *parent;
 	u32 affinity_id;
 	int err;
 
-	err = device_property_read_u32(&msc->pdev->dev, "cpu_affinity",
-				       &affinity_id);
-	if (err)
+	if (!acpi_disabled) {
+		err = device_property_read_u32(&msc->pdev->dev, "cpu_affinity",
+					       &affinity_id);
+		if (err)
+			cpumask_copy(&msc->accessibility, cpu_possible_mask);
+		else
+			acpi_pptt_get_cpus_from_container(affinity_id,
+							  &msc->accessibility);
+
+		return 0;
+	}
+
+	/* Where an MSC can be accessed from depends on the path to of_node. */
+	parent = of_get_parent(msc->pdev->dev.of_node);
+	if (parent == of_root) {
 		cpumask_copy(&msc->accessibility, cpu_possible_mask);
-	else
-		acpi_pptt_get_cpus_from_container(affinity_id, &msc->accessibility);
+		err = 0;
+	} else {
+		if (of_device_is_compatible(parent, "cache")) {
+			err = get_cpumask_from_cache(parent,
+						     &msc->accessibility);
+		} else {
+			err = -EINVAL;
+			dev_err_once(dev, "Cannot determine accessibility of MSC.\n");
+		}
+	}
+	of_node_put(parent);
+
+	return err;
 }
 
 /*
@@ -2123,7 +2298,10 @@ static int mpam_msc_drv_probe(struct platform_device *pdev)
 		return PTR_ERR(msc);
 
 	/* Create RIS entries described by firmware */
-	err = acpi_mpam_parse_resources(msc, plat_data);
+	if (!acpi_disabled)
+		err = acpi_mpam_parse_resources(msc, plat_data);
+	else
+		err = mpam_dt_parse_resources(msc, plat_data);
 	if (err) {
 		mpam_msc_drv_remove(pdev);
 		return err;
@@ -2136,15 +2314,51 @@ static int mpam_msc_drv_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id mpam_of_match[] = {
+	{ .compatible = "arm,mpam-msc", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, mpam_of_match);
+
 static struct platform_driver mpam_msc_driver = {
 	.driver = {
 		.name = "mpam_msc",
 		.suppress_bind_attrs = true,
+		.of_match_table = of_match_ptr(mpam_of_match),
 	},
 	.probe = mpam_msc_drv_probe,
 	.remove = mpam_msc_drv_remove,
 };
 
+/*
+ * MSCs that are declared by the firmware as being part of a cache may not
+ * be created automatically as platform devices, since there is no
+ * dedicated cache driver.
+ *
+ * Deal with theo MSCs here.
+ */
+static void mpam_dt_create_foundling_msc(void)
+{
+	struct platform_device *pdev;
+	struct device_node *cache;
+
+	for_each_compatible_node(cache, NULL, "cache") {
+		struct device_node *cache_device;
+
+		if (of_node_check_flag(cache, OF_POPULATED))
+			continue;
+
+		cache_device = of_find_matching_node_and_match(cache, mpam_of_match, NULL);
+		if (!cache_device)
+			continue;
+		of_node_put(cache_device);
+
+		pdev = of_platform_device_create(cache, "cache", NULL);
+		if (!pdev)
+			pr_err_once("Failed to create MSC devices under caches\n");
+	}
+}
+
 /* Any of these features mean the BWA_WD field is valid. */
 static bool mpam_has_bwa_wd_feature(struct mpam_props *props)
 {
@@ -2963,12 +3177,18 @@ static int __init mpam_msc_driver_init(void)
 
 	init_srcu_struct(&mpam_srcu);
 
-	fw_num_msc = acpi_mpam_count_msc();
+	if (!acpi_disabled)
+		fw_num_msc = acpi_mpam_count_msc();
+	else
+		fw_num_msc = mpam_dt_count_msc();
 	if (fw_num_msc <= 0) {
 		pr_err("No MSC devices found in firmware\n");
 		return -EINVAL;
 	}
 
+	if (acpi_disabled)
+		mpam_dt_create_foundling_msc();
+
 	return platform_driver_register(&mpam_msc_driver);
 }
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 04/15] arm_mpam: Add support for memory controller MSC on DT platforms
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (2 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 03/15] arm_mpam: Add device tree support for MSC probing Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-08-11 13:30 ` [PATCH RFC 05/15] arm_mpam: Fix device_node refcount in DT resource parsing Yin Li
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

From: Shanker Donthineni <sdonthineni@nvidia.com>

The MPAM DT path only handles cache MSCs. Memory-controller MSCs
cannot be probed yet.

Add support to discover memory-controller MSCs from the device tree:
derive the component id from the NUMA node and create a 'memory' class
RIS, and treat a memory parent as accessible from all CPUs.

Signed-off-by: Shanker Donthineni <sdonthineni@nvidia.com>
[ morse: split out of a bigger patch, added affinity piece ]
Signed-off-by: James Morse <james.morse@arm.com>
[ Yin Li: fix context offset conflicts caused by line number mismatches ]
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 56 +++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 15 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 6f2854fe08ca..975ddab771b4 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -263,10 +263,12 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
 				  u32 ris_idx)
 {
 	int err = 0;
-	u32 level = 0;
-	unsigned long cache_id;
+	u32 class_id = 0;
+	unsigned long component_id = 0;
 	struct device *dev = &msc->pdev->dev;
+	enum mpam_class_types type = MPAM_CLASS_UNKNOWN;
 	struct device_node *cache __free(device_node) = NULL;
+	struct device_node *memory __free(device_node) = NULL;
 	struct device_node *parent __free(device_node) = of_get_parent(np);
 
 	if (of_device_is_compatible(np, "arm,mpam-cache")) {
@@ -275,27 +277,48 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
 			dev_err_once(dev, "Failed to read phandle\n");
 			return -EINVAL;
 		}
+		type = MPAM_CLASS_CACHE;
+
 	} else if (of_device_is_compatible(parent, "cache")) {
 		cache = parent;
+		type = MPAM_CLASS_CACHE;
+	} else if (of_device_is_compatible(np, "arm,mpam-memory")) {
+		memory = of_parse_phandle(np, "arm,mpam-device", 0);
+		if (!memory) {
+			dev_err_once(dev, "Failed to read phandle\n");
+			return -EINVAL;
+		}
+		type = MPAM_CLASS_MEMORY;
+	} else if (of_device_is_compatible(np, "arm,mpam-memory-controller-msc")) {
+		memory = parent;
+		type = MPAM_CLASS_MEMORY;
 	} else {
-		/* For now, only caches are supported */
-		cache = NULL;
-		return err;
-	}
-
-	err = of_property_read_u32(cache, "cache-level", &level);
-	if (err) {
-		dev_err_once(dev, "Failed to read cache-level\n");
+		/*
+		 * For now, only caches and memory controllers are
+		 * supported.
+		 */
 		return err;
 	}
 
-	cache_id = cache_of_calculate_id(cache);
-	if (cache_id == ~0) {
-		dev_err_once(dev, "Failed to calculate cache-id\n");
-		return -ENOENT;
+	/* Determine the class and component ids, based on type. */
+	if (type == MPAM_CLASS_CACHE) {
+		err = of_property_read_u32(cache, "cache-level", &class_id);
+		if (err) {
+			dev_err_once(dev, "Failed to read cache-level\n");
+			return err;
+		}
+		component_id = cache_of_calculate_id(cache);
+		if (component_id == ~0) {
+			dev_err_once(dev, "Failed to calculate cache-id\n");
+			return -ENOENT;
+		}
+	} else if (type == MPAM_CLASS_MEMORY) {
+		err = of_node_to_nid(np);
+		component_id = (err == NUMA_NO_NODE) ? 0 : err;
+		class_id = MPAM_CLASS_ID_DEFAULT;
 	}
 
-	return mpam_ris_create(msc, ris_idx, MPAM_CLASS_CACHE, level, cache_id);
+	return mpam_ris_create(msc, ris_idx, type, class_id, component_id);
 }
 
 static int mpam_dt_parse_resources(struct mpam_msc *msc, void *ignored)
@@ -2163,6 +2186,9 @@ static int update_msc_accessibility(struct mpam_msc *msc)
 		if (of_device_is_compatible(parent, "cache")) {
 			err = get_cpumask_from_cache(parent,
 						     &msc->accessibility);
+		} else if (of_device_is_compatible(parent, "memory")) {
+			cpumask_copy(&msc->accessibility, cpu_possible_mask);
+			err = 0;
 		} else {
 			err = -EINVAL;
 			dev_err_once(dev, "Cannot determine accessibility of MSC.\n");

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 05/15] arm_mpam: Fix device_node refcount in DT resource parsing
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (3 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 04/15] arm_mpam: Add support for memory controller MSC on DT platforms Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-09-02 13:29   ` Andre Przywara
  2026-08-11 13:30 ` [PATCH RFC 06/15] arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type Yin Li
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

When a cache-parented or memory-controller-parented MSC is probed via
device tree, the parent node was assigned directly to a
__free(device_node) variable without incrementing its reference count.
Both the parent and the cache/memory variable are declared with
__free(device_node), which causes the compiler to automatically insert
an of_node_put() call for each variable when they go out of scope.
Since both variables point to the same node but the reference count was
only incremented once by of_get_parent(), the node ends up being
released twice, causing a refcount underflow.

Use of_node_get() to take an explicit reference so each __free variable
holds its own reference.

Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 975ddab771b4..559fa09128b4 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -280,7 +280,7 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
 		type = MPAM_CLASS_CACHE;
 
 	} else if (of_device_is_compatible(parent, "cache")) {
-		cache = parent;
+		cache = of_node_get(parent);
 		type = MPAM_CLASS_CACHE;
 	} else if (of_device_is_compatible(np, "arm,mpam-memory")) {
 		memory = of_parse_phandle(np, "arm,mpam-device", 0);
@@ -290,7 +290,7 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
 		}
 		type = MPAM_CLASS_MEMORY;
 	} else if (of_device_is_compatible(np, "arm,mpam-memory-controller-msc")) {
-		memory = parent;
+		memory = of_node_get(parent);
 		type = MPAM_CLASS_MEMORY;
 	} else {
 		/*

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 06/15] arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (4 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 05/15] arm_mpam: Fix device_node refcount in DT resource parsing Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-09-02 13:49   ` Andre Przywara
  2026-08-11 13:30 ` [PATCH RFC 07/15] arm_mpam: Fix the RIS index range check in mpam_ris_create_locked Yin Li
                   ` (10 subsequent siblings)
  16 siblings, 1 reply; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

cache_of_calculate_id() returns u32, but callers stored the result in
unsigned long variables and compared against ~0UL. On 64-bit systems,
U32_MAX (0xffffffff) assigned to unsigned long becomes 0x00000000ffffffff,
which does not equal ~0UL (0xffffffffffffffff), so invalid cache IDs are
silently accepted instead of being rejected.

Fix by changing all cache ID and component ID variables that receive the
return value of cache_of_calculate_id() to u32, and replace all ~0 and
~0UL sentinel comparisons with U32_MAX.

Also fix the sentinel values in cache_of_calculate_id() itself for
consistency.

Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/base/cacheinfo.c        |  6 +++---
 drivers/resctrl/mpam_devices.c  | 16 ++++++++--------
 drivers/resctrl/mpam_internal.h |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index f75e7f64038b..a4e0d1d47e71 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -229,7 +229,7 @@ static bool match_cache_node(struct device_node *cpu,
 u32 cache_of_calculate_id(struct device_node *cache_node)
 {
 	struct device_node *cpu;
-	u32 min_id = ~0;
+	u32 min_id = U32_MAX;
 
 	for_each_of_cpu_node(cpu) {
 		u64 id = of_get_cpu_hwid(cpu, 0);
@@ -237,7 +237,7 @@ u32 cache_of_calculate_id(struct device_node *cache_node)
 		id = arch_compact_of_hwid(id);
 		if (FIELD_GET(GENMASK_ULL(63, 32), id)) {
 			of_node_put(cpu);
-			return ~0;
+			return U32_MAX;
 		}
 
 		if (match_cache_node(cpu, cache_node))
@@ -252,7 +252,7 @@ static void cache_of_set_id(struct cacheinfo *this_leaf,
 {
 	u32 id = cache_of_calculate_id(cache_node);
 
-	if (id != ~0) {
+	if (id != U32_MAX) {
 		this_leaf->id = id;
 		this_leaf->attributes |= CACHE_ID;
 	}
diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 559fa09128b4..ddc15249ec1e 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -166,13 +166,13 @@ static void mpam_free_garbage(void)
 
 /* Called recursively to walk the list of caches from a particular CPU */
 static void __mpam_get_cpumask_from_cache_id(int cpu, struct device_node *cache_node,
-					     unsigned long cache_id,
+					     u32 cache_id,
 					     u32 cache_level,
 					     cpumask_t *affinity)
 {
 	int err;
 	u32 iter_level;
-	unsigned long iter_cache_id;
+	u32 iter_cache_id;
 	struct device_node *iter_node __free(device_node) = of_find_next_cache_node(cache_node);
 
 	if (!iter_node)
@@ -187,7 +187,7 @@ static void __mpam_get_cpumask_from_cache_id(int cpu, struct device_node *cache_
 	 * during device_initcall(). Use cache_of_calculate_id().
 	 */
 	iter_cache_id = cache_of_calculate_id(iter_node);
-	if (iter_cache_id == ~0UL)
+	if (iter_cache_id == U32_MAX)
 		return;
 
 	if (iter_level == cache_level && iter_cache_id == cache_id)
@@ -202,7 +202,7 @@ static void __mpam_get_cpumask_from_cache_id(int cpu, struct device_node *cache_
  * The cacheinfo structures are only populated when CPUs are online.
  * This helper walks the device tree to include offline CPUs too.
  */
-int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
+int mpam_get_cpumask_from_cache_id(u32 cache_id, u32 cache_level,
 				   cpumask_t *affinity)
 {
 	int cpu;
@@ -229,7 +229,7 @@ static int get_cpumask_from_cache(struct device_node *cache,
 {
 	int err;
 	u32 cache_level;
-	unsigned long cache_id;
+	u32 cache_id;
 
 	err = of_property_read_u32(cache, "cache-level", &cache_level);
 	if (err) {
@@ -238,7 +238,7 @@ static int get_cpumask_from_cache(struct device_node *cache,
 	}
 
 	cache_id = cache_of_calculate_id(cache);
-	if (cache_id == ~0UL) {
+	if (cache_id == U32_MAX) {
 		pr_err("Failed to calculate cache-id from cache node\n");
 		return -ENOENT;
 	}
@@ -264,7 +264,7 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
 {
 	int err = 0;
 	u32 class_id = 0;
-	unsigned long component_id = 0;
+	u32 component_id = 0;
 	struct device *dev = &msc->pdev->dev;
 	enum mpam_class_types type = MPAM_CLASS_UNKNOWN;
 	struct device_node *cache __free(device_node) = NULL;
@@ -308,7 +308,7 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
 			return err;
 		}
 		component_id = cache_of_calculate_id(cache);
-		if (component_id == ~0) {
+		if (component_id == U32_MAX) {
 			dev_err_once(dev, "Failed to calculate cache-id\n");
 			return -ENOENT;
 		}
diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
index def0e3a65c23..aa45d00bcd07 100644
--- a/drivers/resctrl/mpam_internal.h
+++ b/drivers/resctrl/mpam_internal.h
@@ -470,7 +470,7 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,
 		    enum mpam_device_features, u64 *val);
 void mpam_msmon_reset_mbwu(struct mpam_component *comp, struct mon_cfg *ctx);
 
-int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
+int mpam_get_cpumask_from_cache_id(u32 cache_id, u32 cache_level,
 				   cpumask_t *affinity);
 
 #ifdef CONFIG_RESCTRL_FS

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 07/15] arm_mpam: Fix the RIS index range check in mpam_ris_create_locked
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (5 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 06/15] arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-09-02 14:50   ` Andre Przywara
  2026-08-11 13:30 ` [PATCH RFC 08/15] arm_mpam: Fix ris_idx type to prevent range check bypass on truncation Yin Li
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

The RIS selector field is defined as MPAMCFG_PART_SEL_RIS (bits 27:24),
which is 4 bits wide and gives valid indices 0..15. MPAM_MSC_MAX_NUM_RIS
is defined as 16, so the check should use >= to reject index 16 and
above. The previous > check incorrectly accepted index 16 as valid.

Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index ddc15249ec1e..cc9fa1d78925 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -725,7 +725,7 @@ static int mpam_ris_create_locked(struct mpam_msc *msc, u8 ris_idx,
 
 	lockdep_assert_held(&mpam_list_lock);
 
-	if (ris_idx > MPAM_MSC_MAX_NUM_RIS)
+	if (ris_idx >= MPAM_MSC_MAX_NUM_RIS)
 		return -EINVAL;
 
 	if (test_and_set_bit(ris_idx, &msc->ris_idxs))

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 08/15] arm_mpam: Fix ris_idx type to prevent range check bypass on truncation
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (6 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 07/15] arm_mpam: Fix the RIS index range check in mpam_ris_create_locked Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-09-02 16:22   ` Andre Przywara
  2026-08-11 13:30 ` [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start Yin Li
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

The RIS index is read from device tree as u64 via of_property_read_reg(),
but was narrowed to u32 when passed to mpam_dt_parse_resource() and
further to u8 when passed to mpam_ris_create(). A value exceeding
MPAM_MSC_MAX_NUM_RIS could be silently truncated to a small index that
passes the range check in mpam_ris_create_locked(), leading to incorrect
RIS creation.

Widen the ris_idx parameter through mpam_dt_parse_resource(),
mpam_ris_create_locked(), and mpam_ris_create() to u64 so the value
is preserved until the range check in mpam_ris_create_locked() rejects
out-of-range indices.

Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 6 +++---
 include/linux/arm_mpam.h       | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index cc9fa1d78925..1e082fb60e30 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -260,7 +260,7 @@ static int mpam_dt_count_msc(void)
 }
 
 static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
-				  u32 ris_idx)
+				  u64 ris_idx)
 {
 	int err = 0;
 	u32 class_id = 0;
@@ -712,7 +712,7 @@ static int mpam_ris_get_affinity(struct mpam_msc *msc, cpumask_t *affinity,
 	return 0;
 }
 
-static int mpam_ris_create_locked(struct mpam_msc *msc, u8 ris_idx,
+static int mpam_ris_create_locked(struct mpam_msc *msc, u64 ris_idx,
 				  enum mpam_class_types type, u8 class_id,
 				  int component_id)
 {
@@ -799,7 +799,7 @@ static void mpam_ris_destroy(struct mpam_msc_ris *ris)
 		mpam_vmsc_destroy(vmsc);
 }
 
-int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
+int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
 		    enum mpam_class_types type, u8 class_id, int component_id)
 {
 	int err;
diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h
index f92a36187a52..30461cd71199 100644
--- a/include/linux/arm_mpam.h
+++ b/include/linux/arm_mpam.h
@@ -39,10 +39,10 @@ static inline int acpi_mpam_count_msc(void) { return -EINVAL; }
 #endif
 
 #ifdef CONFIG_ARM64_MPAM_DRIVER
-int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
+int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
 		    enum mpam_class_types type, u8 class_id, int component_id);
 #else
-static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
+static inline int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
 				  enum mpam_class_types type, u8 class_id,
 				  int component_id)
 {

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (7 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 08/15] arm_mpam: Fix ris_idx type to prevent range check bypass on truncation Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-09-02 13:16   ` Andre Przywara
  2026-09-03 10:20   ` Ben Horgan
  2026-08-11 13:30 ` [PATCH RFC 10/15] arm_mpam: Fix update_msc_accessibility() return type to void Yin Li
                   ` (7 subsequent siblings)
  16 siblings, 2 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

struct resource uses an inclusive end address, so the correct size is
end - start + 1. The previous calculation of end - start was off by one,
resulting in a mapped window one byte smaller than the actual resource.
Use resource_size() which correctly computes end - start + 1.

Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 1e082fb60e30..5d1854d97371 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -2296,7 +2296,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)
 			dev_err_once(dev, "Failed to map MSC base address\n");
 			return ERR_CAST(io);
 		}
-		msc->mapped_hwpage_sz = msc_res->end - msc_res->start;
+		msc->mapped_hwpage_sz = resource_size(msc_res);
 		msc->mapped_hwpage = io;
 	} else {
 		return ERR_PTR(-EINVAL);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 10/15] arm_mpam: Fix update_msc_accessibility() return type to void
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (8 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-08-11 13:30 ` [PATCH RFC 11/15] arm_mpam: Fix mpam_dt_create_foundling_msc() to create MSC platform devices Yin Li
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

The function update_msc_accessibility() was changed to return int in
the DT support patch to propagate errors from the DT accessibility
derivation path. However, the function silently ignores errors from
get_cpumask_from_cache() and does not propagate them to the caller.

Revert the return type to void and remove the unused error variable,
keeping the dev_err_once() diagnostic for unrecognised parent nodes.
The caller checks cpumask_empty() after the call to detect failure.

Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 5d1854d97371..b0e67c8349c7 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -2158,7 +2158,7 @@ static int mpam_msc_setup_error_irq(struct mpam_msc *msc)
  * corresponding cache may also be powered off. By making accesses from
  * one of those CPUs, we ensure we don't access a cache that's powered off.
  */
-static int update_msc_accessibility(struct mpam_msc *msc)
+static void update_msc_accessibility(struct mpam_msc *msc)
 {
 	struct device *dev = &msc->pdev->dev;
 	struct device_node *parent;
@@ -2174,29 +2174,22 @@ static int update_msc_accessibility(struct mpam_msc *msc)
 			acpi_pptt_get_cpus_from_container(affinity_id,
 							  &msc->accessibility);
 
-		return 0;
+		return;
 	}
 
 	/* Where an MSC can be accessed from depends on the path to of_node. */
 	parent = of_get_parent(msc->pdev->dev.of_node);
 	if (parent == of_root) {
 		cpumask_copy(&msc->accessibility, cpu_possible_mask);
-		err = 0;
 	} else {
-		if (of_device_is_compatible(parent, "cache")) {
-			err = get_cpumask_from_cache(parent,
-						     &msc->accessibility);
-		} else if (of_device_is_compatible(parent, "memory")) {
+		if (of_device_is_compatible(parent, "cache"))
+			get_cpumask_from_cache(parent, &msc->accessibility);
+		else if (of_device_is_compatible(parent, "memory"))
 			cpumask_copy(&msc->accessibility, cpu_possible_mask);
-			err = 0;
-		} else {
-			err = -EINVAL;
+		else
 			dev_err_once(dev, "Cannot determine accessibility of MSC.\n");
-		}
 	}
 	of_node_put(parent);
-
-	return err;
 }
 
 /*

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 11/15] arm_mpam: Fix mpam_dt_create_foundling_msc() to create MSC platform devices
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (9 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 10/15] arm_mpam: Fix update_msc_accessibility() return type to void Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-08-11 13:30 ` [PATCH RFC 12/15] arm_mpam: Fix get_cpumask_from_cache() to clear mask on error Yin Li
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

The original code created a platform device for the cache node itself
rather than for the MSC, so the MSC was never created. Instead, walk
the cache's children using for_each_child_of_node_scoped() and create
the platform device for the MSC child node, skipping cache parents
that firmware has marked disabled.

Co-developed-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index b0e67c8349c7..eac3bc695fd1 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -2358,23 +2358,20 @@ static struct platform_driver mpam_msc_driver = {
  */
 static void mpam_dt_create_foundling_msc(void)
 {
-	struct platform_device *pdev;
-	struct device_node *cache;
-
-	for_each_compatible_node(cache, NULL, "cache") {
-		struct device_node *cache_device;
-
-		if (of_node_check_flag(cache, OF_POPULATED))
-			continue;
-
-		cache_device = of_find_matching_node_and_match(cache, mpam_of_match, NULL);
-		if (!cache_device)
+	for_each_compatible_node_scoped(cache, NULL, "cache") {
+		if (!of_device_is_available(cache))
 			continue;
-		of_node_put(cache_device);
 
-		pdev = of_platform_device_create(cache, "cache", NULL);
-		if (!pdev)
-			pr_err_once("Failed to create MSC devices under caches\n");
+		for_each_child_of_node_scoped(cache, child) {
+			if (!of_match_node(mpam_of_match, child))
+				continue;
+			if (!of_device_is_available(child))
+				continue;
+			if (of_node_check_flag(child, OF_POPULATED))
+				continue;
+			if (!of_platform_device_create(child, NULL, NULL))
+				pr_err("Failed to create MSC device for %pOF\n", child);
+		}
 	}
 }
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 12/15] arm_mpam: Fix get_cpumask_from_cache() to clear mask on error
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (10 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 11/15] arm_mpam: Fix mpam_dt_create_foundling_msc() to create MSC platform devices Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-09-02 16:03   ` Andre Przywara
  2026-08-11 13:30 ` [PATCH RFC 13/15] dt-bindings: arm: Fix MPAM MSC binding schema and examples Yin Li
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

If mpam_get_cpumask_from_cache_id() fails, the affinity mask may have
been partially filled before the error occurred. The caller has no way
to distinguish a partial mask from a valid one, so it may misuse the
incomplete result.

Clear the affinity mask before returning the error so the caller always
receives either a fully valid mask or an empty one.

Co-developed-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index eac3bc695fd1..d8856864e89a 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -243,7 +243,12 @@ static int get_cpumask_from_cache(struct device_node *cache,
 		return -ENOENT;
 	}
 
-	return mpam_get_cpumask_from_cache_id(cache_id, cache_level, affinity);
+	err = mpam_get_cpumask_from_cache_id(cache_id, cache_level, affinity);
+	if (err)
+		/* Don't leave a partially-filled mask for the caller to misuse */
+		cpumask_clear(affinity);
+
+	return err;
 }
 
 static int mpam_dt_count_msc(void)

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 13/15] dt-bindings: arm: Fix MPAM MSC binding schema and examples
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (11 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 12/15] arm_mpam: Fix get_cpumask_from_cache() to clear mask on error Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-08-11 13:30 ` [PATCH RFC 14/15] arm_mpam: Support MSC accessibility derivation from RIS nodes Yin Li
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Fix multiple issues in the MPAM MSC device tree binding:

Schema fixes:
- Move maintainers field before description to follow standard field order
- Change compatible from fixed items list to oneOf to allow both standalone
  arm,mpam-msc and the two-item arm,mpam-memory-controller-msc +
  arm,mpam-msc combination
- Constrain numa-node-id as uint32 with description instead of
  unconstrained
- Add phandle-array type constraint to cpus property
- Fix bracket spacing to pass yamllint

Example fixes:
- Replace arm,dsu-l3-cache with foo,a-l3-cache (no upstream schema exists)
- Fix msc@41000 reg address from 0x0 to 0x41000 to match unit-address
- Fix ris@2 reg value from 0 to 2 to match unit-address
- Add arm,mpam-device phandle reference and remove TODO comment
- Remove unnecessary blank lines for consistency

Co-developed-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 .../devicetree/bindings/arm/arm,mpam-msc.yaml      | 39 ++++++++++++----------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml b/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml
index 53a6fdbbf05f..3c7b13a23ff2 100644
--- a/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml
+++ b/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml
@@ -6,19 +6,21 @@ $schema: http://devicetree.org/meta-schemas/core.yaml#
 
 title: Arm Memory System Resource Partitioning and Monitoring (MPAM)
 
+maintainers:
+  - Rob Herring <robh@kernel.org>
+
 description: |
   The Arm MPAM specification can be found here:
 
   https://developer.arm.com/documentation/ddi0598/latest
 
-maintainers:
-  - Rob Herring <robh@kernel.org>
-
 properties:
   compatible:
-    items:
+    oneOf:
       - const: arm,mpam-msc                   # Further details are discoverable
-      - const: arm,mpam-memory-controller-msc
+      - items:
+          - const: arm,mpam-memory-controller-msc
+          - const: arm,mpam-msc
 
   reg:
     maxItems: 1
@@ -34,7 +36,7 @@ properties:
   interrupt-names:
     oneOf:
       - items:
-          - enum: [ error, overflow ]
+          - enum: [error, overflow]
       - items:
           - const: error
           - const: overflow
@@ -44,7 +46,9 @@ properties:
       accurate after a settings change. For more information, see the
       Not-Ready (NRDY) bit description in the MPAM specification.
 
-  numa-node-id: true # see NUMA binding
+  numa-node-id:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: NUMA node identifier for the memory resource this MSC controls.
 
   '#address-cells':
     const: 1
@@ -72,16 +76,17 @@ patternProperties:
         maximum: 0xf
 
       cpus:
+        $ref: /schemas/types.yaml#/definitions/phandle-array
         description:
-          Phandle(s) to the CPU node(s) this RIS belongs to. By default, the parent
-          device's affinity is used.
+          Phandle(s) to the CPU node(s) this RIS belongs to. By default, the
+          parent device's affinity is used.
 
       arm,mpam-device:
         $ref: /schemas/types.yaml#/definitions/phandle
         description:
           By default, the MPAM enabled device associated with a RIS is the MSC's
-          parent node. It is possible for each RIS to be associated with different
-          devices in which case 'arm,mpam-device' should be used.
+          parent node. It is possible for each RIS to be associated with
+          different devices in which case 'arm,mpam-device' should be used.
 
     required:
       - compatible
@@ -92,14 +97,14 @@ required:
   - reg
 
 dependencies:
-  interrupts: [ interrupt-names ]
+  interrupts: [interrupt-names]
 
 additionalProperties: false
 
 examples:
   - |
     L3: cache-controller@30000000 {
-        compatible = "arm,dsu-l3-cache", "cache";
+        compatible = "foo,a-l3-cache", "cache";
         cache-level = <3>;
         cache-unified;
 
@@ -109,7 +114,6 @@ examples:
 
         msc@10000 {
             compatible = "arm,mpam-msc";
-
             reg = <0x10000 0x2000>;
             interrupts = <1>, <2>;
             interrupt-names = "error", "overflow";
@@ -145,7 +149,7 @@ examples:
 
         msc@41000 {
             compatible = "arm,mpam-msc";
-            reg = <0 0x1000>;
+            reg = <0x41000 0x1000>;
             interrupts = <5>, <6>;
             interrupt-names = "error", "overflow";
             arm,not-ready-us = <1>;
@@ -155,8 +159,8 @@ examples:
 
             ris@2 {
                 compatible = "arm,mpam-cache";
-                reg = <0>;
-                // TODO: How to map to device(s)?
+                reg = <2>;
+                arm,mpam-device = <&L3>;
             };
         };
     };
@@ -173,7 +177,6 @@ examples:
 
         msc@10000 {
             compatible = "arm,mpam-msc";
-
             reg = <0x10000 0x2000>;
             interrupts = <7>;
             interrupt-names = "overflow";

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH RFC 14/15] arm_mpam: Support MSC accessibility derivation from RIS nodes
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (12 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 13/15] dt-bindings: arm: Fix MPAM MSC binding schema and examples Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-08-11 13:30 ` [PATCH DNM RFC 15/15] arm64: dts: qcom: kaanapali: Add MPAM MSC nodes for the L2 caches Yin Li
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

The DT accessibility derivation only handled MSCs whose parent node is
a cache or memory device. When the MSC is placed under a generic
container (e.g. directly under /soc), the parent gives no affinity hint
and there is no fallback.

Add a per-RIS fallback path for when the parent node is not a
recognised cache or memory device. For each available RIS child node,
affinity is resolved in two steps: first from an explicit 'cpus'
phandle-array on the RIS node, then from the 'arm,mpam-device' phandle.
The final accessibility mask is the union of all RIS masks; if any RIS
fails to resolve, the mask is cleared and the MSC fails to probe rather
than come up with a partial affinity.

Factor the DT-specific logic into mpam_dt_update_msc_accessibility() so
that update_msc_accessibility() dispatches cleanly between ACPI and DT
paths.

Co-developed-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 drivers/resctrl/mpam_devices.c | 146 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 131 insertions(+), 15 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index d8856864e89a..d0462239deeb 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -2156,6 +2156,136 @@ static int mpam_msc_setup_error_irq(struct mpam_msc *msc)
 	return 0;
 }
 
+/*
+ * Resolve a RIS to its CPU affinity from its 'cpus' phandle-array.
+ * Returns -ENODEV when 'cpus' is absent (the caller may use another source),
+ * -EINVAL when any phandle is invalid, or 0 on full success.
+ */
+static int get_cpumask_from_ris_cpus(struct device_node *ris_np,
+				     cpumask_t *affinity)
+{
+	int i, cpu_phandle_count;
+
+	cpu_phandle_count = of_count_phandle_with_args(ris_np, "cpus", NULL);
+	if (cpu_phandle_count <= 0)
+		return -ENODEV;
+
+	for (i = 0; i < cpu_phandle_count; i++) {
+		struct device_node *phandle_np __free(device_node) =
+			of_parse_phandle(ris_np, "cpus", i);
+		int cpu, matched = -1;
+
+		if (phandle_np) {
+			for_each_possible_cpu(cpu) {
+				struct device_node *cpu_node __free(device_node) =
+					of_get_cpu_node(cpu, NULL);
+
+				if (phandle_np == cpu_node) {
+					matched = cpu;
+					break;
+				}
+			}
+		}
+
+		if (matched < 0) {
+			pr_warn("MPAM: RIS %pOF cpus[%d] (%pOF) is not a possible CPU\n",
+				ris_np, i, phandle_np);
+			return -EINVAL;
+		}
+
+		cpumask_set_cpu(matched, affinity);
+	}
+
+	return 0;
+}
+
+/*
+ * Resolve a RIS to its CPU affinity from its 'arm,mpam-device' phandle.
+ * Returns -EINVAL when 'arm,mpam-device' is absent or the phandle is invalid.
+ * 0 on full success.
+ */
+static int get_cpumask_from_ris_phandle(struct device_node *ris,
+					cpumask_t *affinity)
+{
+	struct device_node *mpam_device __free(device_node) =
+		of_parse_phandle(ris, "arm,mpam-device", 0);
+
+	if (!mpam_device) {
+		pr_warn("MPAM: RIS %pOF has neither 'cpus' nor 'arm,mpam-device'\n",
+			ris);
+		return -EINVAL;
+	}
+
+	if (of_device_is_compatible(mpam_device, "cache"))
+		return get_cpumask_from_cache(mpam_device, affinity);
+
+	if (of_device_is_compatible(mpam_device, "memory")) {
+		cpumask_or(affinity, affinity, cpu_possible_mask);
+		return 0;
+	}
+
+	return -EINVAL;
+}
+
+static int get_cpumask_from_ris(struct device_node *ris, cpumask_t *affinity)
+{
+	int err;
+
+	err = get_cpumask_from_ris_cpus(ris, affinity);
+	if (err != -ENODEV)
+		return err;
+
+	return get_cpumask_from_ris_phandle(ris, affinity);
+}
+
+/*
+ * Returns -ENODEV when the parent is just a container (not a recognised device),
+ * so the caller falls back to the per-RIS description.
+ */
+static int get_cpumask_from_parent(struct mpam_msc *msc, cpumask_t *affinity)
+{
+	struct device_node *parent __free(device_node) =
+		of_get_parent(msc->pdev->dev.of_node);
+
+	if (parent == of_root) {
+		cpumask_copy(affinity, cpu_possible_mask);
+		return 0;
+	}
+
+	if (of_device_is_compatible(parent, "cache"))
+		return get_cpumask_from_cache(parent, affinity);
+
+	if (of_device_is_compatible(parent, "memory")) {
+		cpumask_copy(affinity, cpu_possible_mask);
+		return 0;
+	}
+
+	return -ENODEV;
+}
+
+/*
+ * An MSC's CPU affinity is described either by its parent node or, when the
+ * parent is just a container, per-RIS inside the MSC. In the per-RIS case the
+ * accessibility is the union of the RIS affinities: every RIS must resolve, so
+ * a single failure clears the mask and stops and the MSC fails to probe rather
+ * than come up with a partial affinity.
+ */
+static void mpam_dt_update_msc_accessibility(struct mpam_msc *msc)
+{
+	cpumask_t *affinity = &msc->accessibility;
+
+	cpumask_clear(affinity);
+
+	if (get_cpumask_from_parent(msc, affinity) == -ENODEV) {
+		for_each_available_child_of_node_scoped(msc->pdev->dev.of_node, ris) {
+			if (get_cpumask_from_ris(ris, affinity)) {
+				cpumask_clear(affinity);
+				break;
+			}
+		}
+	}
+}
+
 /*
  * An MSC can control traffic from a set of CPUs, but may only be accessible
  * from a (hopefully wider) set of CPUs. The common reason for this is power
@@ -2165,8 +2295,6 @@ static int mpam_msc_setup_error_irq(struct mpam_msc *msc)
  */
 static void update_msc_accessibility(struct mpam_msc *msc)
 {
-	struct device *dev = &msc->pdev->dev;
-	struct device_node *parent;
 	u32 affinity_id;
 	int err;
 
@@ -2182,19 +2310,7 @@ static void update_msc_accessibility(struct mpam_msc *msc)
 		return;
 	}
 
-	/* Where an MSC can be accessed from depends on the path to of_node. */
-	parent = of_get_parent(msc->pdev->dev.of_node);
-	if (parent == of_root) {
-		cpumask_copy(&msc->accessibility, cpu_possible_mask);
-	} else {
-		if (of_device_is_compatible(parent, "cache"))
-			get_cpumask_from_cache(parent, &msc->accessibility);
-		else if (of_device_is_compatible(parent, "memory"))
-			cpumask_copy(&msc->accessibility, cpu_possible_mask);
-		else
-			dev_err_once(dev, "Cannot determine accessibility of MSC.\n");
-	}
-	of_node_put(parent);
+	mpam_dt_update_msc_accessibility(msc);
 }
 
 /*

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH DNM RFC 15/15] arm64: dts: qcom: kaanapali: Add MPAM MSC nodes for the L2 caches
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (13 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH RFC 14/15] arm_mpam: Support MSC accessibility derivation from RIS nodes Yin Li
@ 2026-08-11 13:30 ` Yin Li
  2026-08-25  8:27 ` [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
  2026-09-03 10:11 ` Ben Horgan
  16 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-11 13:30 UTC (permalink / raw)
  To: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Add an MPAM MSC device node for each L2 cache. Each MSC is nested
directly under its L2 cache node so that the cache node is the MSC's
parent device and its CPU affinity is derived from that cache.

The L2 cache nodes are placed directly under the root node. The root is
the root of the physical address space, so each cache node only needs an
identity 'ranges' property for its nested MSC's 'reg' to be resolved to
a physical address. The two caches use distinct node names (l2-cache-0
and l2-cache-1) since a cache node has no MMIO unit-address of its own.

The nodes are disabled by default. Production firmware does not expose
MSC register access to the OS, so these nodes can only be enabled on a
local test setup where firmware permits direct MMIO access to the MSCs.
This DTS is therefore only an example for other platform DT authors and
is not intended to be merged.

Co-developed-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
---
 arch/arm64/boot/dts/qcom/kaanapali.dtsi | 50 +++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 12 deletions(-)

diff --git a/arch/arm64/boot/dts/qcom/kaanapali.dtsi b/arch/arm64/boot/dts/qcom/kaanapali.dtsi
index 131fd2a16c54..b1dcb1e9c570 100644
--- a/arch/arm64/boot/dts/qcom/kaanapali.dtsi
+++ b/arch/arm64/boot/dts/qcom/kaanapali.dtsi
@@ -48,12 +48,6 @@ cpu0: cpu@0 {
 			power-domains = <&cpu_pd0>, <&scmi_perf 0>;
 			power-domain-names = "psci", "perf";
 			#cooling-cells = <2>;
-
-			l2_0: l2-cache {
-				compatible = "cache";
-				cache-level = <2>;
-				cache-unified;
-			};
 		};
 
 		cpu1: cpu@100 {
@@ -120,12 +114,6 @@ cpu6: cpu@10000 {
 			power-domains = <&cpu_pd6>, <&scmi_perf 1>;
 			power-domain-names = "psci", "perf";
 			#cooling-cells = <2>;
-
-			l2_1: l2-cache {
-				compatible = "cache";
-				cache-level = <2>;
-				cache-unified;
-			};
 		};
 
 		cpu7: cpu@10100 {
@@ -531,6 +519,44 @@ soccp_smp2p_in: slave-kernel {
 		};
 	};
 
+	l2_0: l2-cache-0 {
+		compatible = "cache";
+		cache-level = <2>;
+		cache-unified;
+		cache-size = <0xc00000>;
+		ranges;
+
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		msc@19870000 {
+			compatible = "arm,mpam-msc";
+			reg = <0x0 0x19870000 0x0 0x10000>;
+			arm,not-ready-us = <1>;
+			status = "disabled";
+		};
+
+	};
+
+	l2_1: l2-cache-1 {
+		compatible = "cache";
+		cache-level = <2>;
+		cache-unified;
+		cache-size = <0xc00000>;
+		ranges;
+
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		msc@1a870000 {
+			compatible = "arm,mpam-msc";
+			reg = <0x0 0x1a870000 0x0 0x10000>;
+			arm,not-ready-us = <1>;
+			status = "disabled";
+		};
+
+	};
+
 	soc: soc@0 {
 		compatible = "simple-bus";
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (14 preceding siblings ...)
  2026-08-11 13:30 ` [PATCH DNM RFC 15/15] arm64: dts: qcom: kaanapali: Add MPAM MSC nodes for the L2 caches Yin Li
@ 2026-08-25  8:27 ` Yin Li
  2026-09-03 10:11 ` Ben Horgan
  16 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-25  8:27 UTC (permalink / raw)
  To: James Morse, Rob Herring, Shanker Donthineni, Ben Horgan,
	Rafael J. Wysocki, Conor Dooley, Fenghua Yu, Krzysztof Kozlowski,
	Reinette Chatre, Konrad Dybcio, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel



On 8/11/2026 9:30 PM, Yin Li wrote:
> Notes for James, Shanker and Rob
> --------------------------------
> This series builds directly on your not-yet-upstream MPAM snapshot
> patches from the mpam/snapshot+extras/v6.18-rc1 branch. Two things I'd
> like your guidance on:
> 
> 1. Do you mind us picking these up and continuing to extend them? We have
>     kept the original authorship and Signed-off-by intact and documented
>     the inherited-vs-new split below. If you would prefer a different
>     attribution arrangement, or have your own plans to upstream MPAM DT
>     support, please let us know so we can avoid duplicating effort.
> 
> 2. The fixes to the inherited patches are kept as small, self-contained
>     patches on top, purely to make review easier. Since fixes to
>     not-yet-upstream patches would normally be squashed into the original
>     commit by its author, please point out which of these you would like
>     folded back, and we will reorganize accordingly.
> 
> Rob kindly provided some early off-list feedback on an earlier draft,
> which this series has tried to address.
> 
> Add Arm MPAM resctrl basic device tree support.
> 
> Arm Memory System Resource Partitioning and Monitoring (MPAM) with
> resctrl requires device tree (DT) support as a prerequisite before any
> higher-level functionality can be enabled. This series provides the
> foundational DT binding and parsing support for MPAM, laying the
> groundwork for subsequent features such as MPAM Firmware-backed
> (MPAM-FB) partitioning.
> 

Hi all,

Just a friendly ping on this RFC series.

In particular, I'd appreciate any guidance on whether this is a
reasonable direction for upstream DT support of MPAM/resctrl, before
spending more effort preparing the next revision.

Any high-level feedback would be very helpful.

Thanks for your time.



> The patches are based on earlier work by James Morse, Shanker
> Donthineni and Rob Herring, with fixes and additions on top:
> 
> Inherited (authorship preserved, with fixes noted in each patch):
> - dt-bindings: MPAM MSC binding [1]
> - cacheinfo: expose cache-id generation from a device_node [2]
> - arm_mpam: device tree support for MSC probing [3]
> - arm_mpam: memory controller MSC support on DT platforms [4]
> 
> New on top:
> - standalone fixes extracted from the inherited patches (device_node
>    refcount, cache-id sentinel/type, RIS index range checks, MSC window
>    size, accessibility return type, foundling MSC creation, cache-id
>    error path)
> - dt-bindings: schema and example fixes
> - arm_mpam: derive MSC accessibility from per-RIS nodes as a fallback
> 
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=b38bed339681
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=2af39084438c
> [3] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=a6ab8b6c77cb
> [4] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=c1be40782ace
> 
> DT affinity model
> -----------------
> An MSC node is nested under the device it partitions or monitors. For a
> cache MSC this is the cache node, so the MSC's CPU affinity is derived
> from its parent cache; for a memory-controller MSC the parent is the
> memory device, which is accessible from all CPUs. A per-RIS fallback is
> also provided: when an MSC sits under a generic container with no
> affinity-bearing parent, affinity is resolved from an explicit 'cpus'
> phandle or an 'arm,mpam-device' phandle on each RIS node.
> 
> The Kaanapali DTS patch is for local enabling and verification only and
> cannot be upstreamed: the platform is already upstream with a public
> device tree, and production firmware does not allow the OS to write the
> MSC registers, so this path only works on a local test setup. The MSC
> nodes are disabled by default, serving as a reference example for other
> platform DT authors.
> 
> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> ---
> To: James Morse <james.morse@arm.com>
> To: Rob Herring <robh@kernel.org>
> To: Shanker Donthineni <sdonthineni@nvidia.com>
> To: Krzysztof Kozlowski <krzk+dt@kernel.org>
> To: Ben Horgan <ben.horgan@arm.com>
> To: Conor Dooley <conor+dt@kernel.org>
> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> To: "Rafael J. Wysocki" <rafael@kernel.org>
> To: Danilo Krummrich <dakr@kernel.org>
> To: Reinette Chatre <reinette.chatre@intel.com>
> To: Fenghua Yu <fenghuay@nvidia.com>
> To: Bjorn Andersson <andersson@kernel.org>
> To: Konrad Dybcio <konradybcio@kernel.org>
> Cc: trilok.soni@oss.qualcomm.com
> Cc: aiqun.yu@oss.qualcomm.com
> Cc: ganapatrao.kulkarni@oss.qualcomm.com
> Cc: Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: driver-core@lists.linux.dev
> Cc: devicetree@vger.kernel.org
> Cc: trilok.soni@oss.qualcomm.com
> Cc: aiqun.yu@oss.qualcomm.com
> Cc: ganapatrao.kulkarni@oss.qualcomm.com
> Cc: Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>
> 
> ---
> James Morse (2):
>        cacheinfo: Expose the code to generate a cache-id from a device_node
>        arm_mpam: Add device tree support for MSC probing
> 
> Rob Herring (1):
>        dt-bindings: arm: Add MPAM MSC binding
> 
> Shanker Donthineni (1):
>        arm_mpam: Add support for memory controller MSC on DT platforms
> 
> Yin Li (11):
>        arm_mpam: Fix device_node refcount in DT resource parsing
>        arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type
>        arm_mpam: Fix the RIS index range check in mpam_ris_create_locked
>        arm_mpam: Fix ris_idx type to prevent range check bypass on truncation
>        arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start
>        arm_mpam: Fix update_msc_accessibility() return type to void
>        arm_mpam: Fix mpam_dt_create_foundling_msc() to create MSC platform devices
>        arm_mpam: Fix get_cpumask_from_cache() to clear mask on error
>        dt-bindings: arm: Fix MPAM MSC binding schema and examples
>        arm_mpam: Support MSC accessibility derivation from RIS nodes
>        [DNM] arm64: dts: qcom: kaanapali: Add MPAM MSC nodes for the L2 caches
> 
>   .../devicetree/bindings/arm/arm,mpam-msc.yaml      | 202 +++++++++++
>   arch/arm64/boot/dts/qcom/kaanapali.dtsi            |  50 ++-
>   drivers/base/cacheinfo.c                           |  19 +-
>   drivers/resctrl/mpam_devices.c                     | 401 +++++++++++++++++++--
>   drivers/resctrl/mpam_internal.h                    |   2 +-
>   include/linux/arm_mpam.h                           |   4 +-
>   include/linux/cacheinfo.h                          |   3 +
>   7 files changed, 638 insertions(+), 43 deletions(-)
> ---
> base-commit: 3d08ff75a47a3e7e2ab45a3bcab6723b4d906422
> change-id: 20260731-mpam-resctrl-dt-knp-support-c15dcc3a4a98
> 
> Best regards,
> --
> Yin Li <yin.li@oss.qualcomm.com>
> 

-- 
Thx and BRs,
Yin


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 02/15] cacheinfo: Expose the code to generate a cache-id from a device_node
  2026-08-11 13:30 ` [PATCH RFC 02/15] cacheinfo: Expose the code to generate a cache-id from a device_node Yin Li
@ 2026-08-25 19:11   ` Drew Fustini
  2026-08-31  5:43     ` Yin Li
  0 siblings, 1 reply; 35+ messages in thread
From: Drew Fustini @ 2026-08-25 19:11 UTC (permalink / raw)
  To: Yin Li
  Cc: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman, linux-arm-msm, ganapatrao.kulkarni,
	trilok.soni, devicetree, driver-core, Srivathsa L Rao,
	Huang Yiwei, aiqun.yu, linux-kernel

On Tue, Aug 11, 2026 at 09:30:31PM +0800, Yin Li wrote:
> From: James Morse <james.morse@arm.com>
> 
> The MPAM driver identifies caches by id for use with resctrl. It
> needs to know the cache-id when probe-ing, but the value isn't set
> in cacheinfo until device_initcall(). Even after device_initcall(),
> the cache-id is only available if at least one CPU associated with
> the cache is online.
> 
> Instead of making the driver wait, expose the code that generates the
> cache-id. The parts of the MPAM driver that run early can use this to
> set up the resctrl structures before cacheinfo is ready in
> device_initcall().

This patch would also be helpful for resctrl support on RISC-V, too. The
probe function in the CBQRI capacity allocation platform driver [1] has
the same problem. The current solution is to scan the online CPUs for a
cacheinfo leaf whose fw_token is the cache node from the phandle.
However, that does not work if no cpu sharing that cache is online yet.

[..]
> +u32 cache_of_calculate_id(struct device_node *cache_node)
>  {
>  	struct device_node *cpu;
>  	u32 min_id = ~0;
> @@ -238,15 +237,23 @@ static void cache_of_set_id(struct cacheinfo *this_leaf,
>  		id = arch_compact_of_hwid(id);
>  		if (FIELD_GET(GENMASK_ULL(63, 32), id)) {
>  			of_node_put(cpu);
> -			return;
> +			return ~0;

Maybe this should be U32_MAX instead?

Thanks,
Drew

[1] https://lore.kernel.org/all/20260729-dfustini-atl-sc-cbqri-dt-v6-8-7c22b05d461b@kernel.org/

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 02/15] cacheinfo: Expose the code to generate a cache-id from a device_node
  2026-08-25 19:11   ` Drew Fustini
@ 2026-08-31  5:43     ` Yin Li
  0 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-08-31  5:43 UTC (permalink / raw)
  To: Drew Fustini
  Cc: Rafael J. Wysocki, Shanker Donthineni, Conor Dooley, Fenghua Yu,
	Krzysztof Kozlowski, Rob Herring, Reinette Chatre, Konrad Dybcio,
	James Morse, Ben Horgan, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman, linux-arm-msm, ganapatrao.kulkarni,
	trilok.soni, devicetree, driver-core, Srivathsa L Rao,
	Huang Yiwei, aiqun.yu, linux-kernel



On 8/26/2026 3:11 AM, Drew Fustini wrote:
> On Tue, Aug 11, 2026 at 09:30:31PM +0800, Yin Li wrote:
>> From: James Morse <james.morse@arm.com>
>>
>> The MPAM driver identifies caches by id for use with resctrl. It
>> needs to know the cache-id when probe-ing, but the value isn't set
>> in cacheinfo until device_initcall(). Even after device_initcall(),
>> the cache-id is only available if at least one CPU associated with
>> the cache is online.
>>
>> Instead of making the driver wait, expose the code that generates the
>> cache-id. The parts of the MPAM driver that run early can use this to
>> set up the resctrl structures before cacheinfo is ready in
>> device_initcall().
> 
> This patch would also be helpful for resctrl support on RISC-V, too. The
> probe function in the CBQRI capacity allocation platform driver [1] has
> the same problem. The current solution is to scan the online CPUs for a
> cacheinfo leaf whose fw_token is the cache node from the phandle.
> However, that does not work if no cpu sharing that cache is online yet.
> 

Hi Drew,

Thanks for the review.

Good to know that cache_of_calculate_id() could help with the RISC-V
CBQRI driver as well. Since the function is guarded by CONFIG_OF in
cacheinfo.h, it should be available on DT-based RISC-V platforms
without any issue. You're welcome to use it.

> [..]
>> +u32 cache_of_calculate_id(struct device_node *cache_node)
>>   {
>>   	struct device_node *cpu;
>>   	u32 min_id = ~0;
>> @@ -238,15 +237,23 @@ static void cache_of_set_id(struct cacheinfo *this_leaf,
>>   		id = arch_compact_of_hwid(id);
>>   		if (FIELD_GET(GENMASK_ULL(63, 32), id)) {
>>   			of_node_put(cpu);
>> -			return;
>> +			return ~0;
> 
> Maybe this should be U32_MAX instead?
> 

Regarding the ~0 vs U32_MAX point:
You're right that U32_MAX is more appropriate than ~0 here. This is
addressed in patch 06/15 ("arm_mpam: Fix cache ID sentinel from ~0UL
to U32_MAX to match u32 return type").
https://lore.kernel.org/all/20260811-mpam-resctrl-dt-knp-support-v1-6-ea6397bead59@oss.qualcomm.com/

The fix is in a separate patch because this patch is based on James
Morse's original unmerged work — I kept my fixes separate for easier
review. The plan is to fold them back in once James has responded.

> Thanks,
> Drew
> 
> [1] https://lore.kernel.org/all/20260729-dfustini-atl-sc-cbqri-dt-v6-8-7c22b05d461b@kernel.org/

-- 
Thx and BRs,
Yin


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start
  2026-08-11 13:30 ` [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start Yin Li
@ 2026-09-02 13:16   ` Andre Przywara
  2026-09-03  9:45     ` Yin Li
  2026-09-03 10:20   ` Ben Horgan
  1 sibling, 1 reply; 35+ messages in thread
From: Andre Przywara @ 2026-09-02 13:16 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Ben Horgan, Bjorn Andersson,
	Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi,

On 8/11/26 15:30, Yin Li wrote:
> struct resource uses an inclusive end address, so the correct size is
> end - start + 1. The previous calculation of end - start was off by one,
> resulting in a mapped window one byte smaller than the actual resource.
> Use resource_size() which correctly computes end - start + 1.

Yes, thanks for catching this and making a patch. We found this 
independently during other MPAM work, but no one got around to make a 
patch ;-)

> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

So this patch is independent from and non-conflicting with the DT work, 
so either Ben or James pick this one directly, or you put those kind of 
fixes first in the series, when you repost.

Cheers,
Andre

> ---
>   drivers/resctrl/mpam_devices.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index 1e082fb60e30..5d1854d97371 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -2296,7 +2296,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)
>   			dev_err_once(dev, "Failed to map MSC base address\n");
>   			return ERR_CAST(io);
>   		}
> -		msc->mapped_hwpage_sz = msc_res->end - msc_res->start;
> +		msc->mapped_hwpage_sz = resource_size(msc_res);
>   		msc->mapped_hwpage = io;
>   	} else {
>   		return ERR_PTR(-EINVAL);
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 05/15] arm_mpam: Fix device_node refcount in DT resource parsing
  2026-08-11 13:30 ` [PATCH RFC 05/15] arm_mpam: Fix device_node refcount in DT resource parsing Yin Li
@ 2026-09-02 13:29   ` Andre Przywara
  2026-09-03  8:07     ` Yin Li
  0 siblings, 1 reply; 35+ messages in thread
From: Andre Przywara @ 2026-09-02 13:29 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Ben Horgan, Bjorn Andersson,
	Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi,

On 8/11/26 15:30, Yin Li wrote:
> When a cache-parented or memory-controller-parented MSC is probed via
> device tree, the parent node was assigned directly to a
> __free(device_node) variable without incrementing its reference count.
> Both the parent and the cache/memory variable are declared with
> __free(device_node), which causes the compiler to automatically insert
> an of_node_put() call for each variable when they go out of scope.
> Since both variables point to the same node but the reference count was
> only incremented once by of_get_parent(), the node ends up being
> released twice, causing a refcount underflow.

Yes, looks about right: there is another assignment to both memory and 
cache, they call of_parse_phandle(), which increments the refcount, so 
we need to do the same for the direct assignments, to get the free'ing 
done consistently.

> Use of_node_get() to take an explicit reference so each __free variable
> holds its own reference.
> 
> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

... though this should definitely be squashed into the respective DT 
patches. Feel free to do so.

Cheers,
Andre

> ---
>   drivers/resctrl/mpam_devices.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index 975ddab771b4..559fa09128b4 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -280,7 +280,7 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
>   		type = MPAM_CLASS_CACHE;
>   
>   	} else if (of_device_is_compatible(parent, "cache")) {
> -		cache = parent;
> +		cache = of_node_get(parent);
>   		type = MPAM_CLASS_CACHE;
>   	} else if (of_device_is_compatible(np, "arm,mpam-memory")) {
>   		memory = of_parse_phandle(np, "arm,mpam-device", 0);
> @@ -290,7 +290,7 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
>   		}
>   		type = MPAM_CLASS_MEMORY;
>   	} else if (of_device_is_compatible(np, "arm,mpam-memory-controller-msc")) {
> -		memory = parent;
> +		memory = of_node_get(parent);
>   		type = MPAM_CLASS_MEMORY;
>   	} else {
>   		/*
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 06/15] arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type
  2026-08-11 13:30 ` [PATCH RFC 06/15] arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type Yin Li
@ 2026-09-02 13:49   ` Andre Przywara
  0 siblings, 0 replies; 35+ messages in thread
From: Andre Przywara @ 2026-09-02 13:49 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Ben Horgan, Bjorn Andersson,
	Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi,

On 8/11/26 15:30, Yin Li wrote:
> cache_of_calculate_id() returns u32, but callers stored the result in
> unsigned long variables and compared against ~0UL. On 64-bit systems,
> U32_MAX (0xffffffff) assigned to unsigned long becomes 0x00000000ffffffff,
> which does not equal ~0UL (0xffffffffffffffff), so invalid cache IDs are
> silently accepted instead of being rejected.

Yes, I agree about this one, long is not right, it's u32 (acpi) or even 
a plain int elsewhere (get_cpu_cacheinfo_id()).

> 
> Fix by changing all cache ID and component ID variables that receive the
> return value of cache_of_calculate_id() to u32, and replace all ~0 and
> ~0UL sentinel comparisons with U32_MAX.

... but am not so sure about the U32_MAX change. I think ~0U is a common 
idiom in the kernel to mean "mask of all 1's", and while U32_MAX is the 
same, the _MAX part is slightly misleading here, I think.

So I think this patch should focus on dropping the long and L parts, but 
keep the ~0U notation. Which means cacheinfo.c should not change, for 
instance.

And also I wonder if that should be split up: one part to fix the 
existing usage in v7.3-rc1, so basically the function prototype, and the 
other part for the newly introduced DT code, which should then be squashed.

Cheers,
Andre

> 
> Also fix the sentinel values in cache_of_calculate_id() itself for
> consistency.
> 
> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> ---
>   drivers/base/cacheinfo.c        |  6 +++---
>   drivers/resctrl/mpam_devices.c  | 16 ++++++++--------
>   drivers/resctrl/mpam_internal.h |  2 +-
>   3 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
> index f75e7f64038b..a4e0d1d47e71 100644
> --- a/drivers/base/cacheinfo.c
> +++ b/drivers/base/cacheinfo.c
> @@ -229,7 +229,7 @@ static bool match_cache_node(struct device_node *cpu,
>   u32 cache_of_calculate_id(struct device_node *cache_node)
>   {
>   	struct device_node *cpu;
> -	u32 min_id = ~0;
> +	u32 min_id = U32_MAX;
>   
>   	for_each_of_cpu_node(cpu) {
>   		u64 id = of_get_cpu_hwid(cpu, 0);
> @@ -237,7 +237,7 @@ u32 cache_of_calculate_id(struct device_node *cache_node)
>   		id = arch_compact_of_hwid(id);
>   		if (FIELD_GET(GENMASK_ULL(63, 32), id)) {
>   			of_node_put(cpu);
> -			return ~0;
> +			return U32_MAX;
>   		}
>   
>   		if (match_cache_node(cpu, cache_node))
> @@ -252,7 +252,7 @@ static void cache_of_set_id(struct cacheinfo *this_leaf,
>   {
>   	u32 id = cache_of_calculate_id(cache_node);
>   
> -	if (id != ~0) {
> +	if (id != U32_MAX) {
>   		this_leaf->id = id;
>   		this_leaf->attributes |= CACHE_ID;
>   	}
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index 559fa09128b4..ddc15249ec1e 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -166,13 +166,13 @@ static void mpam_free_garbage(void)
>   
>   /* Called recursively to walk the list of caches from a particular CPU */
>   static void __mpam_get_cpumask_from_cache_id(int cpu, struct device_node *cache_node,
> -					     unsigned long cache_id,
> +					     u32 cache_id,
>   					     u32 cache_level,
>   					     cpumask_t *affinity)
>   {
>   	int err;
>   	u32 iter_level;
> -	unsigned long iter_cache_id;
> +	u32 iter_cache_id;
>   	struct device_node *iter_node __free(device_node) = of_find_next_cache_node(cache_node);
>   
>   	if (!iter_node)
> @@ -187,7 +187,7 @@ static void __mpam_get_cpumask_from_cache_id(int cpu, struct device_node *cache_
>   	 * during device_initcall(). Use cache_of_calculate_id().
>   	 */
>   	iter_cache_id = cache_of_calculate_id(iter_node);
> -	if (iter_cache_id == ~0UL)
> +	if (iter_cache_id == U32_MAX)
>   		return;
>   
>   	if (iter_level == cache_level && iter_cache_id == cache_id)
> @@ -202,7 +202,7 @@ static void __mpam_get_cpumask_from_cache_id(int cpu, struct device_node *cache_
>    * The cacheinfo structures are only populated when CPUs are online.
>    * This helper walks the device tree to include offline CPUs too.
>    */
> -int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
> +int mpam_get_cpumask_from_cache_id(u32 cache_id, u32 cache_level,
>   				   cpumask_t *affinity)
>   {
>   	int cpu;
> @@ -229,7 +229,7 @@ static int get_cpumask_from_cache(struct device_node *cache,
>   {
>   	int err;
>   	u32 cache_level;
> -	unsigned long cache_id;
> +	u32 cache_id;
>   
>   	err = of_property_read_u32(cache, "cache-level", &cache_level);
>   	if (err) {
> @@ -238,7 +238,7 @@ static int get_cpumask_from_cache(struct device_node *cache,
>   	}
>   
>   	cache_id = cache_of_calculate_id(cache);
> -	if (cache_id == ~0UL) {
> +	if (cache_id == U32_MAX) {
>   		pr_err("Failed to calculate cache-id from cache node\n");
>   		return -ENOENT;
>   	}
> @@ -264,7 +264,7 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
>   {
>   	int err = 0;
>   	u32 class_id = 0;
> -	unsigned long component_id = 0;
> +	u32 component_id = 0;
>   	struct device *dev = &msc->pdev->dev;
>   	enum mpam_class_types type = MPAM_CLASS_UNKNOWN;
>   	struct device_node *cache __free(device_node) = NULL;
> @@ -308,7 +308,7 @@ static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
>   			return err;
>   		}
>   		component_id = cache_of_calculate_id(cache);
> -		if (component_id == ~0) {
> +		if (component_id == U32_MAX) {
>   			dev_err_once(dev, "Failed to calculate cache-id\n");
>   			return -ENOENT;
>   		}
> diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
> index def0e3a65c23..aa45d00bcd07 100644
> --- a/drivers/resctrl/mpam_internal.h
> +++ b/drivers/resctrl/mpam_internal.h
> @@ -470,7 +470,7 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,
>   		    enum mpam_device_features, u64 *val);
>   void mpam_msmon_reset_mbwu(struct mpam_component *comp, struct mon_cfg *ctx);
>   
> -int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
> +int mpam_get_cpumask_from_cache_id(u32 cache_id, u32 cache_level,
>   				   cpumask_t *affinity);
>   
>   #ifdef CONFIG_RESCTRL_FS
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 07/15] arm_mpam: Fix the RIS index range check in mpam_ris_create_locked
  2026-08-11 13:30 ` [PATCH RFC 07/15] arm_mpam: Fix the RIS index range check in mpam_ris_create_locked Yin Li
@ 2026-09-02 14:50   ` Andre Przywara
  2026-09-03  8:18     ` Yin Li
  0 siblings, 1 reply; 35+ messages in thread
From: Andre Przywara @ 2026-09-02 14:50 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Ben Horgan, Bjorn Andersson,
	Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi,

On 8/11/26 15:30, Yin Li wrote:
> The RIS selector field is defined as MPAMCFG_PART_SEL_RIS (bits 27:24),
> which is 4 bits wide and gives valid indices 0..15. MPAM_MSC_MAX_NUM_RIS
> is defined as 16, so the check should use >= to reject index 16 and
> above. The previous > check incorrectly accepted index 16 as valid.

Indeed. Either the maintainers pick this one independently, or put it up 
front in any repost.

And add:
Fixes: 01fb4b822472 ("arm_mpam: Add the class and component structures 
for firmware described ris")

> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
>   drivers/resctrl/mpam_devices.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index ddc15249ec1e..cc9fa1d78925 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -725,7 +725,7 @@ static int mpam_ris_create_locked(struct mpam_msc *msc, u8 ris_idx,
>   
>   	lockdep_assert_held(&mpam_list_lock);
>   
> -	if (ris_idx > MPAM_MSC_MAX_NUM_RIS)
> +	if (ris_idx >= MPAM_MSC_MAX_NUM_RIS)
>   		return -EINVAL;
>   
>   	if (test_and_set_bit(ris_idx, &msc->ris_idxs))
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 12/15] arm_mpam: Fix get_cpumask_from_cache() to clear mask on error
  2026-08-11 13:30 ` [PATCH RFC 12/15] arm_mpam: Fix get_cpumask_from_cache() to clear mask on error Yin Li
@ 2026-09-02 16:03   ` Andre Przywara
  2026-09-03  9:59     ` Yin Li
  0 siblings, 1 reply; 35+ messages in thread
From: Andre Przywara @ 2026-09-02 16:03 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Ben Horgan, Bjorn Andersson,
	Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi,

On 8/11/26 15:30, Yin Li wrote:
> If mpam_get_cpumask_from_cache_id() fails, the affinity mask may have
> been partially filled before the error occurred. The caller has no way
> to distinguish a partial mask from a valid one, so it may misuse the
> incomplete result.

But it returns an error, in which case any caller should ignore what's 
in the affinity pointer?
I am not sure that clearing the mask in necessarily the right solution.
Either we leave it untouched (which might be tricky), or we check that 
the callers restore or discard the affinity mask when the function 
returns an error.

Did this trigger any real problem, or was it some bored^Woverzealous AI 
review tool pointing that out?

Cheers,
Andre

> Clear the affinity mask before returning the error so the caller always
> receives either a fully valid mask or an empty one.
> 
> Co-developed-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
> Signed-off-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> ---
>   drivers/resctrl/mpam_devices.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index eac3bc695fd1..d8856864e89a 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -243,7 +243,12 @@ static int get_cpumask_from_cache(struct device_node *cache,
>   		return -ENOENT;
>   	}
>   
> -	return mpam_get_cpumask_from_cache_id(cache_id, cache_level, affinity);
> +	err = mpam_get_cpumask_from_cache_id(cache_id, cache_level, affinity);
> +	if (err)
> +		/* Don't leave a partially-filled mask for the caller to misuse */
> +		cpumask_clear(affinity);
> +
> +	return err;
>   }
>   
>   static int mpam_dt_count_msc(void)
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 08/15] arm_mpam: Fix ris_idx type to prevent range check bypass on truncation
  2026-08-11 13:30 ` [PATCH RFC 08/15] arm_mpam: Fix ris_idx type to prevent range check bypass on truncation Yin Li
@ 2026-09-02 16:22   ` Andre Przywara
  2026-09-03  9:42     ` Yin Li
  0 siblings, 1 reply; 35+ messages in thread
From: Andre Przywara @ 2026-09-02 16:22 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Ben Horgan, Bjorn Andersson,
	Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi,

On 8/11/26 15:30, Yin Li wrote:
> The RIS index is read from device tree as u64 via of_property_read_reg(),

what does it do that using an u64, actually? Do you refer to the reg 
property of the ris subnode, which has a limit of 0xf in the DT binding? 
So shouldn't it be an u8 all along, and we fix the types up at the 
sources, rather than widening everything needlessly to u64?

Cheers,
Andre

> but was narrowed to u32 when passed to mpam_dt_parse_resource() and
> further to u8 when passed to mpam_ris_create(). A value exceeding
> MPAM_MSC_MAX_NUM_RIS could be silently truncated to a small index that
> passes the range check in mpam_ris_create_locked(), leading to incorrect
> RIS creation.
> 
> Widen the ris_idx parameter through mpam_dt_parse_resource(),
> mpam_ris_create_locked(), and mpam_ris_create() to u64 so the value
> is preserved until the range check in mpam_ris_create_locked() rejects
> out-of-range indices.
> 
> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> ---
>   drivers/resctrl/mpam_devices.c | 6 +++---
>   include/linux/arm_mpam.h       | 4 ++--
>   2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index cc9fa1d78925..1e082fb60e30 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -260,7 +260,7 @@ static int mpam_dt_count_msc(void)
>   }
>   
>   static int mpam_dt_parse_resource(struct mpam_msc *msc, struct device_node *np,
> -				  u32 ris_idx)
> +				  u64 ris_idx)
>   {
>   	int err = 0;
>   	u32 class_id = 0;
> @@ -712,7 +712,7 @@ static int mpam_ris_get_affinity(struct mpam_msc *msc, cpumask_t *affinity,
>   	return 0;
>   }
>   
> -static int mpam_ris_create_locked(struct mpam_msc *msc, u8 ris_idx,
> +static int mpam_ris_create_locked(struct mpam_msc *msc, u64 ris_idx,
>   				  enum mpam_class_types type, u8 class_id,
>   				  int component_id)
>   {
> @@ -799,7 +799,7 @@ static void mpam_ris_destroy(struct mpam_msc_ris *ris)
>   		mpam_vmsc_destroy(vmsc);
>   }
>   
> -int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
> +int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>   		    enum mpam_class_types type, u8 class_id, int component_id)
>   {
>   	int err;
> diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h
> index f92a36187a52..30461cd71199 100644
> --- a/include/linux/arm_mpam.h
> +++ b/include/linux/arm_mpam.h
> @@ -39,10 +39,10 @@ static inline int acpi_mpam_count_msc(void) { return -EINVAL; }
>   #endif
>   
>   #ifdef CONFIG_ARM64_MPAM_DRIVER
> -int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
> +int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>   		    enum mpam_class_types type, u8 class_id, int component_id);
>   #else
> -static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
> +static inline int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>   				  enum mpam_class_types type, u8 class_id,
>   				  int component_id)
>   {
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 05/15] arm_mpam: Fix device_node refcount in DT resource parsing
  2026-09-02 13:29   ` Andre Przywara
@ 2026-09-03  8:07     ` Yin Li
  0 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-09-03  8:07 UTC (permalink / raw)
  To: Andre Przywara, Rafael J. Wysocki, Shanker Donthineni,
	Conor Dooley, Fenghua Yu, Krzysztof Kozlowski, Rob Herring,
	Reinette Chatre, Konrad Dybcio, James Morse, Ben Horgan,
	Bjorn Andersson, Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel



On 9/2/2026 9:29 PM, Andre Przywara wrote:
> Hi,
> 
> On 8/11/26 15:30, Yin Li wrote:
>> When a cache-parented or memory-controller-parented MSC is probed via
>> device tree, the parent node was assigned directly to a
>> __free(device_node) variable without incrementing its reference count.
>> Both the parent and the cache/memory variable are declared with
>> __free(device_node), which causes the compiler to automatically insert
>> an of_node_put() call for each variable when they go out of scope.
>> Since both variables point to the same node but the reference count was
>> only incremented once by of_get_parent(), the node ends up being
>> released twice, causing a refcount underflow.
> 
> Yes, looks about right: there is another assignment to both memory and 
> cache, they call of_parse_phandle(), which increments the refcount, so 
> we need to do the same for the direct assignments, to get the free'ing 
> done consistently.
> 
>> Use of_node_get() to take an explicit reference so each __free variable
>> holds its own reference.
>>
>> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> 
> Reviewed-by: Andre Przywara <andre.przywara@arm.com>
> 

Hi Andre,

Thanks for the review and the Reviewed-by tag.

> ... though this should definitely be squashed into the respective DT 
> patches. Feel free to do so.
> 

You're right that these fixes should be squashed into the respective
DT patches. I kept them as separate fix patches for now because those
DT patches are based on James Morse's and Shanker's original unmerged
work — this way the changes I made on top are easier to review in
isolation. I plan to fold them back into the original patches once
James and Shanker have had a chance to respond.

> Cheers,
> Andre
> 
>> ---
>>   drivers/resctrl/mpam_devices.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/ 
>> mpam_devices.c
>> index 975ddab771b4..559fa09128b4 100644
>> --- a/drivers/resctrl/mpam_devices.c
>> +++ b/drivers/resctrl/mpam_devices.c
>> @@ -280,7 +280,7 @@ static int mpam_dt_parse_resource(struct mpam_msc 
>> *msc, struct device_node *np,
>>           type = MPAM_CLASS_CACHE;
>>       } else if (of_device_is_compatible(parent, "cache")) {
>> -        cache = parent;
>> +        cache = of_node_get(parent);
>>           type = MPAM_CLASS_CACHE;
>>       } else if (of_device_is_compatible(np, "arm,mpam-memory")) {
>>           memory = of_parse_phandle(np, "arm,mpam-device", 0);
>> @@ -290,7 +290,7 @@ static int mpam_dt_parse_resource(struct mpam_msc 
>> *msc, struct device_node *np,
>>           }
>>           type = MPAM_CLASS_MEMORY;
>>       } else if (of_device_is_compatible(np, "arm,mpam-memory- 
>> controller-msc")) {
>> -        memory = parent;
>> +        memory = of_node_get(parent);
>>           type = MPAM_CLASS_MEMORY;
>>       } else {
>>           /*
>>
> 

-- 
Thx and BRs,
Yin


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 07/15] arm_mpam: Fix the RIS index range check in mpam_ris_create_locked
  2026-09-02 14:50   ` Andre Przywara
@ 2026-09-03  8:18     ` Yin Li
  0 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-09-03  8:18 UTC (permalink / raw)
  To: Andre Przywara, Rafael J. Wysocki, Shanker Donthineni,
	Conor Dooley, Fenghua Yu, Krzysztof Kozlowski, Rob Herring,
	Reinette Chatre, Konrad Dybcio, James Morse, Ben Horgan,
	Bjorn Andersson, Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel



On 9/2/2026 10:50 PM, Andre Przywara wrote:
> Hi,
> 
> On 8/11/26 15:30, Yin Li wrote:
>> The RIS selector field is defined as MPAMCFG_PART_SEL_RIS (bits 27:24),
>> which is 4 bits wide and gives valid indices 0..15. MPAM_MSC_MAX_NUM_RIS
>> is defined as 16, so the check should use >= to reject index 16 and
>> above. The previous > check incorrectly accepted index 16 as valid.
> 
> Indeed. Either the maintainers pick this one independently, or put it up 
> front in any repost.
> 
> And add:
> Fixes: 01fb4b822472 ("arm_mpam: Add the class and component structures 
> for firmware described ris")
> 
>> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> 
> Reviewed-by: Andre Przywara <andre.przywara@arm.com>
> 

Hi Andre,

Thanks for the review and the Reviewed-by tag.

Agreed — this is an independent fix to existing code, so I'll move it to
the front of the series in the next repost and add the Fixes tag.

> Cheers,
> Andre
> 
>> ---
>>   drivers/resctrl/mpam_devices.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/ 
>> mpam_devices.c
>> index ddc15249ec1e..cc9fa1d78925 100644
>> --- a/drivers/resctrl/mpam_devices.c
>> +++ b/drivers/resctrl/mpam_devices.c
>> @@ -725,7 +725,7 @@ static int mpam_ris_create_locked(struct mpam_msc 
>> *msc, u8 ris_idx,
>>       lockdep_assert_held(&mpam_list_lock);
>> -    if (ris_idx > MPAM_MSC_MAX_NUM_RIS)
>> +    if (ris_idx >= MPAM_MSC_MAX_NUM_RIS)
>>           return -EINVAL;
>>       if (test_and_set_bit(ris_idx, &msc->ris_idxs))
>>
> 

-- 
Thx and BRs,
Yin


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 08/15] arm_mpam: Fix ris_idx type to prevent range check bypass on truncation
  2026-09-02 16:22   ` Andre Przywara
@ 2026-09-03  9:42     ` Yin Li
  2026-09-03 13:27       ` Andre Przywara
  0 siblings, 1 reply; 35+ messages in thread
From: Yin Li @ 2026-09-03  9:42 UTC (permalink / raw)
  To: Andre Przywara, Rafael J. Wysocki, Shanker Donthineni,
	Conor Dooley, Fenghua Yu, Krzysztof Kozlowski, Rob Herring,
	Reinette Chatre, Konrad Dybcio, James Morse, Ben Horgan,
	Bjorn Andersson, Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel



On 9/3/2026 12:22 AM, Andre Przywara wrote:
> Hi,
> 
> On 8/11/26 15:30, Yin Li wrote:
>> The RIS index is read from device tree as u64 via of_property_read_reg(),
> 
> what does it do that using an u64, actually? Do you refer to the reg 
> property of the ris subnode, which has a limit of 0xf in the DT binding? 
> So shouldn't it be an u8 all along, and we fix the types up at the 
> sources, rather than widening everything needlessly to u64?
> 

Hi Andre,

Thanks for the review.

Yes, this is the reg property of the ris subnode. The reason it starts
as u64 is that it's read via of_property_read_reg(), whose API takes a
u64* for the value — so ris_idx has to be u64 at that point, regardless
of the 0xf limit in the binding.

If ris_idx were narrowed to u8 before reaching the range check in
mpam_ris_create_locked() (ris_idx >= MPAM_MSC_MAX_NUM_RIS), an
out-of-range value such as 0x100 would be truncated to 0x00 and silently
bypass that check. Keeping the wider type through the chain lets that
check see the real value and reject invalid indices.

If you feel an explicit check right after of_property_read_reg() (with
the downstream types kept as u8) is cleaner, I'm glad to go that way —
whichever you prefer.


> Cheers,
> Andre
> 
>> but was narrowed to u32 when passed to mpam_dt_parse_resource() and
>> further to u8 when passed to mpam_ris_create(). A value exceeding
>> MPAM_MSC_MAX_NUM_RIS could be silently truncated to a small index that
>> passes the range check in mpam_ris_create_locked(), leading to incorrect
>> RIS creation.
>>
>> Widen the ris_idx parameter through mpam_dt_parse_resource(),
>> mpam_ris_create_locked(), and mpam_ris_create() to u64 so the value
>> is preserved until the range check in mpam_ris_create_locked() rejects
>> out-of-range indices.
>>
>> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
>> ---
>>   drivers/resctrl/mpam_devices.c | 6 +++---
>>   include/linux/arm_mpam.h       | 4 ++--
>>   2 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/ 
>> mpam_devices.c
>> index cc9fa1d78925..1e082fb60e30 100644
>> --- a/drivers/resctrl/mpam_devices.c
>> +++ b/drivers/resctrl/mpam_devices.c
>> @@ -260,7 +260,7 @@ static int mpam_dt_count_msc(void)
>>   }
>>   static int mpam_dt_parse_resource(struct mpam_msc *msc, struct 
>> device_node *np,
>> -                  u32 ris_idx)
>> +                  u64 ris_idx)
>>   {
>>       int err = 0;
>>       u32 class_id = 0;
>> @@ -712,7 +712,7 @@ static int mpam_ris_get_affinity(struct mpam_msc 
>> *msc, cpumask_t *affinity,
>>       return 0;
>>   }
>> -static int mpam_ris_create_locked(struct mpam_msc *msc, u8 ris_idx,
>> +static int mpam_ris_create_locked(struct mpam_msc *msc, u64 ris_idx,
>>                     enum mpam_class_types type, u8 class_id,
>>                     int component_id)
>>   {
>> @@ -799,7 +799,7 @@ static void mpam_ris_destroy(struct mpam_msc_ris 
>> *ris)
>>           mpam_vmsc_destroy(vmsc);
>>   }
>> -int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
>> +int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>>               enum mpam_class_types type, u8 class_id, int component_id)
>>   {
>>       int err;
>> diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h
>> index f92a36187a52..30461cd71199 100644
>> --- a/include/linux/arm_mpam.h
>> +++ b/include/linux/arm_mpam.h
>> @@ -39,10 +39,10 @@ static inline int acpi_mpam_count_msc(void) 
>> { return -EINVAL; }
>>   #endif
>>   #ifdef CONFIG_ARM64_MPAM_DRIVER
>> -int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
>> +int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>>               enum mpam_class_types type, u8 class_id, int component_id);
>>   #else
>> -static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
>> +static inline int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>>                     enum mpam_class_types type, u8 class_id,
>>                     int component_id)
>>   {
>>
> 

-- 
Thx and BRs,
Yin


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start
  2026-09-02 13:16   ` Andre Przywara
@ 2026-09-03  9:45     ` Yin Li
  0 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-09-03  9:45 UTC (permalink / raw)
  To: Andre Przywara, Rafael J. Wysocki, Shanker Donthineni,
	Conor Dooley, Fenghua Yu, Krzysztof Kozlowski, Rob Herring,
	Reinette Chatre, Konrad Dybcio, James Morse, Ben Horgan,
	Bjorn Andersson, Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel



On 9/2/2026 9:16 PM, Andre Przywara wrote:
> Hi,
> 
> On 8/11/26 15:30, Yin Li wrote:
>> struct resource uses an inclusive end address, so the correct size is
>> end - start + 1. The previous calculation of end - start was off by one,
>> resulting in a mapped window one byte smaller than the actual resource.
>> Use resource_size() which correctly computes end - start + 1.
> 
> Yes, thanks for catching this and making a patch. We found this 
> independently during other MPAM work, but no one got around to make a 
> patch ;-)
> 
>> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> 
> Reviewed-by: Andre Przywara <andre.przywara@arm.com>
> 
> So this patch is independent from and non-conflicting with the DT work, 
> so either Ben or James pick this one directly, or you put those kind of 
> fixes first in the series, when you repost.
> 

Hi Andre,

Thanks for the review and the Reviewed-by tag.

Agreed — like the RIS range-check fix, this one is independent of the DT
work, so I'll move it to the front of the series in the next repost.

> Cheers,
> Andre
> 
>> ---
>>   drivers/resctrl/mpam_devices.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/ 
>> mpam_devices.c
>> index 1e082fb60e30..5d1854d97371 100644
>> --- a/drivers/resctrl/mpam_devices.c
>> +++ b/drivers/resctrl/mpam_devices.c
>> @@ -2296,7 +2296,7 @@ static struct mpam_msc 
>> *do_mpam_msc_drv_probe(struct platform_device *pdev)
>>               dev_err_once(dev, "Failed to map MSC base address\n");
>>               return ERR_CAST(io);
>>           }
>> -        msc->mapped_hwpage_sz = msc_res->end - msc_res->start;
>> +        msc->mapped_hwpage_sz = resource_size(msc_res);
>>           msc->mapped_hwpage = io;
>>       } else {
>>           return ERR_PTR(-EINVAL);
>>
> 

-- 
Thx and BRs,
Yin


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 12/15] arm_mpam: Fix get_cpumask_from_cache() to clear mask on error
  2026-09-02 16:03   ` Andre Przywara
@ 2026-09-03  9:59     ` Yin Li
  0 siblings, 0 replies; 35+ messages in thread
From: Yin Li @ 2026-09-03  9:59 UTC (permalink / raw)
  To: Andre Przywara, Rafael J. Wysocki, Shanker Donthineni,
	Conor Dooley, Fenghua Yu, Krzysztof Kozlowski, Rob Herring,
	Reinette Chatre, Konrad Dybcio, James Morse, Ben Horgan,
	Bjorn Andersson, Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel



On 9/3/2026 12:03 AM, Andre Przywara wrote:
> Hi,
> 
> On 8/11/26 15:30, Yin Li wrote:
>> If mpam_get_cpumask_from_cache_id() fails, the affinity mask may have
>> been partially filled before the error occurred. The caller has no way
>> to distinguish a partial mask from a valid one, so it may misuse the
>> incomplete result.
> 
> But it returns an error, in which case any caller should ignore what's 
> in the affinity pointer?
> I am not sure that clearing the mask in necessarily the right solution.
> Either we leave it untouched (which might be tricky), or we check that 
> the callers restore or discard the affinity mask when the function 
> returns an error.
> 
> Did this trigger any real problem, or was it some bored^Woverzealous AI 
> review tool pointing that out?
> 

Hi Andre,

Thanks for the review, and for the honest question.

This came out of internal review with AI-assisted checking — it didn't
trigger a real problem, just the observation that the mask could be left
partially filled on the error path.

You're right that a caller should ignore the affinity contents when the
function returns an error, so clearing the mask isn't strictly 
necessary. I'll drop it.


> Cheers,
> Andre
> 
>> Clear the affinity mask before returning the error so the caller always
>> receives either a fully valid mask or an empty one.
>>
>> Co-developed-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
>> Signed-off-by: Huang Yiwei <huang.yiwei@oss.qualcomm.com>
>> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
>> ---
>>   drivers/resctrl/mpam_devices.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/ 
>> mpam_devices.c
>> index eac3bc695fd1..d8856864e89a 100644
>> --- a/drivers/resctrl/mpam_devices.c
>> +++ b/drivers/resctrl/mpam_devices.c
>> @@ -243,7 +243,12 @@ static int get_cpumask_from_cache(struct 
>> device_node *cache,
>>           return -ENOENT;
>>       }
>> -    return mpam_get_cpumask_from_cache_id(cache_id, cache_level, 
>> affinity);
>> +    err = mpam_get_cpumask_from_cache_id(cache_id, cache_level, 
>> affinity);
>> +    if (err)
>> +        /* Don't leave a partially-filled mask for the caller to 
>> misuse */
>> +        cpumask_clear(affinity);
>> +
>> +    return err;
>>   }
>>   static int mpam_dt_count_msc(void)
>>
> 

-- 
Thx and BRs,
Yin


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 01/15] dt-bindings: arm: Add MPAM MSC binding
  2026-08-11 13:30 ` [PATCH RFC 01/15] dt-bindings: arm: Add MPAM MSC binding Yin Li
@ 2026-09-03 10:03   ` Ben Horgan
  0 siblings, 0 replies; 35+ messages in thread
From: Ben Horgan @ 2026-09-03 10:03 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi Rob,

On 11/08/2026 14:30, Yin Li wrote:
> From: Rob Herring <robh@kernel.org>
> 
> The binding is designed around the assumption that an MSC will be a
> sub-block of something else such as a memory controller, cache controller,
> or IOMMU. However, it's certainly possible a design does not have that
> association or has a mixture of both, so the binding illustrates how we can
> support that with RIS child nodes.
> 
> A key part of MPAM is we need to know about all of the MSCs in the system
> before it can be enabled. This drives the need for the genericish
> 'arm,mpam-msc' compatible. Though we can't assume an MSC is accessible
> until a h/w specific driver potentially enables the h/w.

Do you have sufficient evidence of platforms that would benefit from MPAM device tree support to
consider this binding for upstream?

Thanks,

Ben

> 
> Cc: James Morse <james.morse@arm.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> Signed-off-by: James Morse <james.morse@arm.com>
> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> ---
>  .../devicetree/bindings/arm/arm,mpam-msc.yaml      | 199 +++++++++++++++++++++
>  1 file changed, 199 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml b/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml
> new file mode 100644
> index 000000000000..53a6fdbbf05f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/arm/arm,mpam-msc.yaml
> @@ -0,0 +1,199 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/arm/arm,mpam-msc.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Arm Memory System Resource Partitioning and Monitoring (MPAM)
> +
> +description: |
> +  The Arm MPAM specification can be found here:
> +
> +  https://developer.arm.com/documentation/ddi0598/latest
> +
> +maintainers:
> +  - Rob Herring <robh@kernel.org>
> +
> +properties:
> +  compatible:
> +    items:
> +      - const: arm,mpam-msc                   # Further details are discoverable
> +      - const: arm,mpam-memory-controller-msc
> +
> +  reg:
> +    maxItems: 1
> +    description: A memory region containing registers as defined in the MPAM
> +      specification.
> +
> +  interrupts:
> +    minItems: 1
> +    items:
> +      - description: error (optional)
> +      - description: overflow (optional, only for monitoring)
> +
> +  interrupt-names:
> +    oneOf:
> +      - items:
> +          - enum: [ error, overflow ]
> +      - items:
> +          - const: error
> +          - const: overflow
> +
> +  arm,not-ready-us:
> +    description: The maximum time in microseconds for monitoring data to be
> +      accurate after a settings change. For more information, see the
> +      Not-Ready (NRDY) bit description in the MPAM specification.
> +
> +  numa-node-id: true # see NUMA binding
> +
> +  '#address-cells':
> +    const: 1
> +
> +  '#size-cells':
> +    const: 0
> +
> +patternProperties:
> +  '^ris@[0-9a-f]+$':
> +    type: object
> +    additionalProperties: false
> +    description:
> +      RIS nodes for each resource instance in an MSC. These nodes are required
> +      for each resource instance implementing known MPAM controls
> +
> +    properties:
> +      compatible:
> +        enum:
> +          - arm,mpam-cache
> +          # Memory bandwidth
> +          - arm,mpam-memory
> +
> +      reg:
> +        minimum: 0
> +        maximum: 0xf
> +
> +      cpus:
> +        description:
> +          Phandle(s) to the CPU node(s) this RIS belongs to. By default, the parent
> +          device's affinity is used.
> +
> +      arm,mpam-device:
> +        $ref: /schemas/types.yaml#/definitions/phandle
> +        description:
> +          By default, the MPAM enabled device associated with a RIS is the MSC's
> +          parent node. It is possible for each RIS to be associated with different
> +          devices in which case 'arm,mpam-device' should be used.
> +
> +    required:
> +      - compatible
> +      - reg
> +
> +required:
> +  - compatible
> +  - reg
> +
> +dependencies:
> +  interrupts: [ interrupt-names ]
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    L3: cache-controller@30000000 {
> +        compatible = "arm,dsu-l3-cache", "cache";
> +        cache-level = <3>;
> +        cache-unified;
> +
> +        ranges = <0x0 0x30000000 0x800000>;
> +        #address-cells = <1>;
> +        #size-cells = <1>;
> +
> +        msc@10000 {
> +            compatible = "arm,mpam-msc";
> +
> +            reg = <0x10000 0x2000>;
> +            interrupts = <1>, <2>;
> +            interrupt-names = "error", "overflow";
> +            arm,not-ready-us = <1>;
> +            /* CPU affinity implied by parent cache node  */
> +        };
> +    };
> +
> +    mem: memory-controller@20000 {
> +        compatible = "foo,a-memory-controller";
> +        reg = <0x20000 0x1000>;
> +
> +        #address-cells = <1>;
> +        #size-cells = <1>;
> +        ranges;
> +
> +        msc@21000 {
> +            compatible = "arm,mpam-memory-controller-msc", "arm,mpam-msc";
> +            reg = <0x21000 0x1000>;
> +            interrupts = <3>;
> +            interrupt-names = "error";
> +            arm,not-ready-us = <1>;
> +            numa-node-id = <1>;
> +        };
> +    };
> +
> +    iommu@40000 {
> +        reg = <0x40000 0x1000>;
> +
> +        ranges;
> +        #address-cells = <1>;
> +        #size-cells = <1>;
> +
> +        msc@41000 {
> +            compatible = "arm,mpam-msc";
> +            reg = <0 0x1000>;
> +            interrupts = <5>, <6>;
> +            interrupt-names = "error", "overflow";
> +            arm,not-ready-us = <1>;
> +
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            ris@2 {
> +                compatible = "arm,mpam-cache";
> +                reg = <0>;
> +                // TODO: How to map to device(s)?
> +            };
> +        };
> +    };
> +
> +    msc@80000 {
> +        compatible = "foo,a-standalone-msc";
> +        reg = <0x80000 0x1000>;
> +
> +        clocks = <&clks 123>;
> +
> +        ranges;
> +        #address-cells = <1>;
> +        #size-cells = <1>;
> +
> +        msc@10000 {
> +            compatible = "arm,mpam-msc";
> +
> +            reg = <0x10000 0x2000>;
> +            interrupts = <7>;
> +            interrupt-names = "overflow";
> +            arm,not-ready-us = <1>;
> +
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            ris@0 {
> +                compatible = "arm,mpam-cache";
> +                reg = <0>;
> +                arm,mpam-device = <&L2_0>;
> +            };
> +
> +            ris@1 {
> +                compatible = "arm,mpam-memory";
> +                reg = <1>;
> +                arm,mpam-device = <&mem>;
> +            };
> +        };
> +    };
> +
> +...
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl
  2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
                   ` (15 preceding siblings ...)
  2026-08-25  8:27 ` [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
@ 2026-09-03 10:11 ` Ben Horgan
  16 siblings, 0 replies; 35+ messages in thread
From: Ben Horgan @ 2026-09-03 10:11 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi Yin,

On 11/08/2026 14:30, Yin Li wrote:
> Notes for James, Shanker and Rob
> --------------------------------
> This series builds directly on your not-yet-upstream MPAM snapshot
> patches from the mpam/snapshot+extras/v6.18-rc1 branch. Two things I'd
> like your guidance on:
> 
> 1. Do you mind us picking these up and continuing to extend them? We have
>    kept the original authorship and Signed-off-by intact and documented
>    the inherited-vs-new split below. If you would prefer a different
>    attribution arrangement, or have your own plans to upstream MPAM DT
>    support, please let us know so we can avoid duplicating effort.
> > 2. The fixes to the inherited patches are kept as small, self-contained
>    patches on top, purely to make review easier. Since fixes to
>    not-yet-upstream patches would normally be squashed into the original
>    commit by its author, please point out which of these you would like
>    folded back, and we will reorganize accordingly.

Yes, MPAM DT support would be good but does rely on the DT maintainers having sufficient evidence of
platforms that would benefit from it. Folding fixes into the patches is the way to go, you can use
square brackets, e.g. [li: <what you changed>], in the trailers to make the differences clear. This
way we avoid having commits with known bugs.

Thanks,

Ben

> 
> Rob kindly provided some early off-list feedback on an earlier draft,
> which this series has tried to address.
> 
> Add Arm MPAM resctrl basic device tree support.
> 
> Arm Memory System Resource Partitioning and Monitoring (MPAM) with
> resctrl requires device tree (DT) support as a prerequisite before any
> higher-level functionality can be enabled. This series provides the
> foundational DT binding and parsing support for MPAM, laying the
> groundwork for subsequent features such as MPAM Firmware-backed
> (MPAM-FB) partitioning.
> 
> The patches are based on earlier work by James Morse, Shanker
> Donthineni and Rob Herring, with fixes and additions on top:
> 
> Inherited (authorship preserved, with fixes noted in each patch):
> - dt-bindings: MPAM MSC binding [1]
> - cacheinfo: expose cache-id generation from a device_node [2]
> - arm_mpam: device tree support for MSC probing [3]
> - arm_mpam: memory controller MSC support on DT platforms [4]
> 
> New on top:
> - standalone fixes extracted from the inherited patches (device_node
>   refcount, cache-id sentinel/type, RIS index range checks, MSC window
>   size, accessibility return type, foundling MSC creation, cache-id
>   error path)
> - dt-bindings: schema and example fixes
> - arm_mpam: derive MSC accessibility from per-RIS nodes as a fallback
> 
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=b38bed339681
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=2af39084438c
> [3] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=a6ab8b6c77cb
> [4] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot+extras/v6.18-rc1&id=c1be40782ace
> 
> DT affinity model
> -----------------
> An MSC node is nested under the device it partitions or monitors. For a
> cache MSC this is the cache node, so the MSC's CPU affinity is derived
> from its parent cache; for a memory-controller MSC the parent is the
> memory device, which is accessible from all CPUs. A per-RIS fallback is
> also provided: when an MSC sits under a generic container with no
> affinity-bearing parent, affinity is resolved from an explicit 'cpus'
> phandle or an 'arm,mpam-device' phandle on each RIS node.
> 
> The Kaanapali DTS patch is for local enabling and verification only and
> cannot be upstreamed: the platform is already upstream with a public
> device tree, and production firmware does not allow the OS to write the
> MSC registers, so this path only works on a local test setup. The MSC
> nodes are disabled by default, serving as a reference example for other
> platform DT authors.
> 
> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> ---
> To: James Morse <james.morse@arm.com>
> To: Rob Herring <robh@kernel.org>
> To: Shanker Donthineni <sdonthineni@nvidia.com>
> To: Krzysztof Kozlowski <krzk+dt@kernel.org>
> To: Ben Horgan <ben.horgan@arm.com>
> To: Conor Dooley <conor+dt@kernel.org>
> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> To: "Rafael J. Wysocki" <rafael@kernel.org>
> To: Danilo Krummrich <dakr@kernel.org>
> To: Reinette Chatre <reinette.chatre@intel.com>
> To: Fenghua Yu <fenghuay@nvidia.com>
> To: Bjorn Andersson <andersson@kernel.org>
> To: Konrad Dybcio <konradybcio@kernel.org>
> Cc: trilok.soni@oss.qualcomm.com
> Cc: aiqun.yu@oss.qualcomm.com
> Cc: ganapatrao.kulkarni@oss.qualcomm.com
> Cc: Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: driver-core@lists.linux.dev
> Cc: devicetree@vger.kernel.org
> Cc: trilok.soni@oss.qualcomm.com
> Cc: aiqun.yu@oss.qualcomm.com
> Cc: ganapatrao.kulkarni@oss.qualcomm.com
> Cc: Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>
> 
> ---
> James Morse (2):
>       cacheinfo: Expose the code to generate a cache-id from a device_node
>       arm_mpam: Add device tree support for MSC probing
> 
> Rob Herring (1):
>       dt-bindings: arm: Add MPAM MSC binding
> 
> Shanker Donthineni (1):
>       arm_mpam: Add support for memory controller MSC on DT platforms
> 
> Yin Li (11):
>       arm_mpam: Fix device_node refcount in DT resource parsing
>       arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type
>       arm_mpam: Fix the RIS index range check in mpam_ris_create_locked
>       arm_mpam: Fix ris_idx type to prevent range check bypass on truncation
>       arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start
>       arm_mpam: Fix update_msc_accessibility() return type to void
>       arm_mpam: Fix mpam_dt_create_foundling_msc() to create MSC platform devices
>       arm_mpam: Fix get_cpumask_from_cache() to clear mask on error
>       dt-bindings: arm: Fix MPAM MSC binding schema and examples
>       arm_mpam: Support MSC accessibility derivation from RIS nodes
>       [DNM] arm64: dts: qcom: kaanapali: Add MPAM MSC nodes for the L2 caches
> 
>  .../devicetree/bindings/arm/arm,mpam-msc.yaml      | 202 +++++++++++
>  arch/arm64/boot/dts/qcom/kaanapali.dtsi            |  50 ++-
>  drivers/base/cacheinfo.c                           |  19 +-
>  drivers/resctrl/mpam_devices.c                     | 401 +++++++++++++++++++--
>  drivers/resctrl/mpam_internal.h                    |   2 +-
>  include/linux/arm_mpam.h                           |   4 +-
>  include/linux/cacheinfo.h                          |   3 +
>  7 files changed, 638 insertions(+), 43 deletions(-)
> ---
> base-commit: 3d08ff75a47a3e7e2ab45a3bcab6723b4d906422
> change-id: 20260731-mpam-resctrl-dt-knp-support-c15dcc3a4a98
> 
> Best regards,
> --  
> Yin Li <yin.li@oss.qualcomm.com>
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start
  2026-08-11 13:30 ` [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start Yin Li
  2026-09-02 13:16   ` Andre Przywara
@ 2026-09-03 10:20   ` Ben Horgan
  2026-09-03 13:23     ` Ben Horgan
  1 sibling, 1 reply; 35+ messages in thread
From: Ben Horgan @ 2026-09-03 10:20 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi Yin,

On 11/08/2026 14:30, Yin Li wrote:
> struct resource uses an inclusive end address, so the correct size is
> end - start + 1. The previous calculation of end - start was off by one,
> resulting in a mapped window one byte smaller than the actual resource.
> Use resource_size() which correctly computes end - start + 1.
> 
> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>

I just got a kernel ci report for this one which asks for tags:

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202609030809.ObirDhR3-lkp@intel.com/

It doesn't look to give a useful fixes tag though. I'd go with this as that's where the error was
introduced.

Fixes: f04046f2577a ("arm_mpam: Add probe/remove for mpam msc driver and kbuild boiler plate")

Looks good to me.

Reviewed-by: Ben Horgan <ben.horgan@arm.com>

Thanks,

Ben

> ---
>  drivers/resctrl/mpam_devices.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index 1e082fb60e30..5d1854d97371 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -2296,7 +2296,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)
>  			dev_err_once(dev, "Failed to map MSC base address\n");
>  			return ERR_CAST(io);
>  		}
> -		msc->mapped_hwpage_sz = msc_res->end - msc_res->start;
> +		msc->mapped_hwpage_sz = resource_size(msc_res);
>  		msc->mapped_hwpage = io;
>  	} else {
>  		return ERR_PTR(-EINVAL);
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start
  2026-09-03 10:20   ` Ben Horgan
@ 2026-09-03 13:23     ` Ben Horgan
  0 siblings, 0 replies; 35+ messages in thread
From: Ben Horgan @ 2026-09-03 13:23 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Bjorn Andersson, Danilo Krummrich,
	Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi Yin,

On 03/09/2026 11:20, Ben Horgan wrote:
> Hi Yin,
> 
> On 11/08/2026 14:30, Yin Li wrote:
>> struct resource uses an inclusive end address, so the correct size is
>> end - start + 1. The previous calculation of end - start was off by one,
>> resulting in a mapped window one byte smaller than the actual resource.
>> Use resource_size() which correctly computes end - start + 1.
>>
>> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
> 
> I just got a kernel ci report for this one which asks for tags:
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202609030809.ObirDhR3-lkp@intel.com/
> 
> It doesn't look to give a useful fixes tag though. I'd go with this as that's where the error was
> introduced.
> 
> Fixes: f04046f2577a ("arm_mpam: Add probe/remove for mpam msc driver and kbuild boiler plate")
> 
> Looks good to me.
> 
> Reviewed-by: Ben Horgan <ben.horgan@arm.com>

Scratch that. As Ilpo points out,[1], there is no functional bug but just some misleading naming
which never the less would be good to fix. This does require > in the warnings becoming >= though
and there would be no need for fixes tag. Do you agree with this analysis?

Thanks,

Ben

[1]
https://lore.kernel.org/lkml/03055fbc-281f-4ed9-9282-4853d560e17f@arm.com/T/#mdb57d40c888ff4ce656a9d9a00ecf5d99466530c


> 
> Thanks,
> 
> Ben
> 
>> ---
>>  drivers/resctrl/mpam_devices.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
>> index 1e082fb60e30..5d1854d97371 100644
>> --- a/drivers/resctrl/mpam_devices.c
>> +++ b/drivers/resctrl/mpam_devices.c
>> @@ -2296,7 +2296,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev)
>>  			dev_err_once(dev, "Failed to map MSC base address\n");
>>  			return ERR_CAST(io);
>>  		}
>> -		msc->mapped_hwpage_sz = msc_res->end - msc_res->start;
>> +		msc->mapped_hwpage_sz = resource_size(msc_res);
>>  		msc->mapped_hwpage = io;
>>  	} else {
>>  		return ERR_PTR(-EINVAL);
>>
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH RFC 08/15] arm_mpam: Fix ris_idx type to prevent range check bypass on truncation
  2026-09-03  9:42     ` Yin Li
@ 2026-09-03 13:27       ` Andre Przywara
  0 siblings, 0 replies; 35+ messages in thread
From: Andre Przywara @ 2026-09-03 13:27 UTC (permalink / raw)
  To: Yin Li, Rafael J. Wysocki, Shanker Donthineni, Conor Dooley,
	Fenghua Yu, Krzysztof Kozlowski, Rob Herring, Reinette Chatre,
	Konrad Dybcio, James Morse, Ben Horgan, Bjorn Andersson,
	Danilo Krummrich, Greg Kroah-Hartman
  Cc: linux-arm-msm, ganapatrao.kulkarni, trilok.soni, devicetree,
	driver-core, Srivathsa L Rao, Huang Yiwei, aiqun.yu, linux-kernel

Hi,

On 9/3/26 11:42, Yin Li wrote:
> 
> 
> On 9/3/2026 12:22 AM, Andre Przywara wrote:
>> Hi,
>>
>> On 8/11/26 15:30, Yin Li wrote:
>>> The RIS index is read from device tree as u64 via 
>>> of_property_read_reg(),
>>
>> what does it do that using an u64, actually? Do you refer to the reg 
>> property of the ris subnode, which has a limit of 0xf in the DT 
>> binding? So shouldn't it be an u8 all along, and we fix the types up 
>> at the sources, rather than widening everything needlessly to u64?
>>
> 
> Hi Andre,
> 
> Thanks for the review.
> 
> Yes, this is the reg property of the ris subnode. The reason it starts
> as u64 is that it's read via of_property_read_reg(), whose API takes a

Yes, I figured as much, *after* hitting the Send button ;-)

> u64* for the value — so ris_idx has to be u64 at that point, regardless
> of the 0xf limit in the binding.

Which actually makes me wonder whether this is the right function to 
use, since there would be no translation (as indeed guaranteed by this 
function), but also no size, and I guess no cell size requirements 
beyond 1. I think it has the added benefit of checking #address-cells 
and #size-cells, but technically a standard of_property_read_u32() would 
do as well? Though this probably has the same problem, just with u32 ...

> If ris_idx were narrowed to u8 before reaching the range check in
> mpam_ris_create_locked() (ris_idx >= MPAM_MSC_MAX_NUM_RIS), an
> out-of-range value such as 0x100 would be truncated to 0x00 and silently
> bypass that check. Keeping the wider type through the chain lets that
> check see the real value and reject invalid indices.
> 
> If you feel an explicit check right after of_property_read_reg() (with
> the downstream types kept as u8) is cleaner, I'm glad to go that way —
> whichever you prefer.

Yeah, I feel it's sane to already check the limit directly after parsing 
from the DT, not only in mpam_ris_create() later. Do you know of any 
particular reason this is done so late?
If there is none, I think the cleanest is to keep of_property_read_reg() 
and check against the limit already in that function. Then we can use a 
u8 all along.

Cheers,
Andre

>>> but was narrowed to u32 when passed to mpam_dt_parse_resource() and
>>> further to u8 when passed to mpam_ris_create(). A value exceeding
>>> MPAM_MSC_MAX_NUM_RIS could be silently truncated to a small index that
>>> passes the range check in mpam_ris_create_locked(), leading to incorrect
>>> RIS creation.
>>>
>>> Widen the ris_idx parameter through mpam_dt_parse_resource(),
>>> mpam_ris_create_locked(), and mpam_ris_create() to u64 so the value
>>> is preserved until the range check in mpam_ris_create_locked() rejects
>>> out-of-range indices.
>>>
>>> Signed-off-by: Yin Li <yin.li@oss.qualcomm.com>
>>> ---
>>>   drivers/resctrl/mpam_devices.c | 6 +++---
>>>   include/linux/arm_mpam.h       | 4 ++--
>>>   2 files changed, 5 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/ 
>>> mpam_devices.c
>>> index cc9fa1d78925..1e082fb60e30 100644
>>> --- a/drivers/resctrl/mpam_devices.c
>>> +++ b/drivers/resctrl/mpam_devices.c
>>> @@ -260,7 +260,7 @@ static int mpam_dt_count_msc(void)
>>>   }
>>>   static int mpam_dt_parse_resource(struct mpam_msc *msc, struct 
>>> device_node *np,
>>> -                  u32 ris_idx)
>>> +                  u64 ris_idx)
>>>   {
>>>       int err = 0;
>>>       u32 class_id = 0;
>>> @@ -712,7 +712,7 @@ static int mpam_ris_get_affinity(struct mpam_msc 
>>> *msc, cpumask_t *affinity,
>>>       return 0;
>>>   }
>>> -static int mpam_ris_create_locked(struct mpam_msc *msc, u8 ris_idx,
>>> +static int mpam_ris_create_locked(struct mpam_msc *msc, u64 ris_idx,
>>>                     enum mpam_class_types type, u8 class_id,
>>>                     int component_id)
>>>   {
>>> @@ -799,7 +799,7 @@ static void mpam_ris_destroy(struct mpam_msc_ris 
>>> *ris)
>>>           mpam_vmsc_destroy(vmsc);
>>>   }
>>> -int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
>>> +int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>>>               enum mpam_class_types type, u8 class_id, int component_id)
>>>   {
>>>       int err;
>>> diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h
>>> index f92a36187a52..30461cd71199 100644
>>> --- a/include/linux/arm_mpam.h
>>> +++ b/include/linux/arm_mpam.h
>>> @@ -39,10 +39,10 @@ static inline int acpi_mpam_count_msc(void) 
>>> { return -EINVAL; }
>>>   #endif
>>>   #ifdef CONFIG_ARM64_MPAM_DRIVER
>>> -int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
>>> +int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>>>               enum mpam_class_types type, u8 class_id, int 
>>> component_id);
>>>   #else
>>> -static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
>>> +static inline int mpam_ris_create(struct mpam_msc *msc, u64 ris_idx,
>>>                     enum mpam_class_types type, u8 class_id,
>>>                     int component_id)
>>>   {
>>>
>>
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2026-09-03 13:27 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11 13:30 [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
2026-08-11 13:30 ` [PATCH RFC 01/15] dt-bindings: arm: Add MPAM MSC binding Yin Li
2026-09-03 10:03   ` Ben Horgan
2026-08-11 13:30 ` [PATCH RFC 02/15] cacheinfo: Expose the code to generate a cache-id from a device_node Yin Li
2026-08-25 19:11   ` Drew Fustini
2026-08-31  5:43     ` Yin Li
2026-08-11 13:30 ` [PATCH RFC 03/15] arm_mpam: Add device tree support for MSC probing Yin Li
2026-08-11 13:30 ` [PATCH RFC 04/15] arm_mpam: Add support for memory controller MSC on DT platforms Yin Li
2026-08-11 13:30 ` [PATCH RFC 05/15] arm_mpam: Fix device_node refcount in DT resource parsing Yin Li
2026-09-02 13:29   ` Andre Przywara
2026-09-03  8:07     ` Yin Li
2026-08-11 13:30 ` [PATCH RFC 06/15] arm_mpam: Fix cache ID sentinel from ~0UL to U32_MAX to match u32 return type Yin Li
2026-09-02 13:49   ` Andre Przywara
2026-08-11 13:30 ` [PATCH RFC 07/15] arm_mpam: Fix the RIS index range check in mpam_ris_create_locked Yin Li
2026-09-02 14:50   ` Andre Przywara
2026-09-03  8:18     ` Yin Li
2026-08-11 13:30 ` [PATCH RFC 08/15] arm_mpam: Fix ris_idx type to prevent range check bypass on truncation Yin Li
2026-09-02 16:22   ` Andre Przywara
2026-09-03  9:42     ` Yin Li
2026-09-03 13:27       ` Andre Przywara
2026-08-11 13:30 ` [PATCH RFC 09/15] arm_mpam: Fix MSC MMIO window size to use resource_size() instead of end - start Yin Li
2026-09-02 13:16   ` Andre Przywara
2026-09-03  9:45     ` Yin Li
2026-09-03 10:20   ` Ben Horgan
2026-09-03 13:23     ` Ben Horgan
2026-08-11 13:30 ` [PATCH RFC 10/15] arm_mpam: Fix update_msc_accessibility() return type to void Yin Li
2026-08-11 13:30 ` [PATCH RFC 11/15] arm_mpam: Fix mpam_dt_create_foundling_msc() to create MSC platform devices Yin Li
2026-08-11 13:30 ` [PATCH RFC 12/15] arm_mpam: Fix get_cpumask_from_cache() to clear mask on error Yin Li
2026-09-02 16:03   ` Andre Przywara
2026-09-03  9:59     ` Yin Li
2026-08-11 13:30 ` [PATCH RFC 13/15] dt-bindings: arm: Fix MPAM MSC binding schema and examples Yin Li
2026-08-11 13:30 ` [PATCH RFC 14/15] arm_mpam: Support MSC accessibility derivation from RIS nodes Yin Li
2026-08-11 13:30 ` [PATCH DNM RFC 15/15] arm64: dts: qcom: kaanapali: Add MPAM MSC nodes for the L2 caches Yin Li
2026-08-25  8:27 ` [PATCH RFC 00/15] arm-mpam: Add basic device tree support for resctrl Yin Li
2026-09-03 10:11 ` Ben Horgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox