arm64: expose CPU prefetch and cache modulation controls
Subsystems (3)
cover arm64: expose CPU prefetch and cache modulation controls
From: Koba Ko <[email protected]>
This series adds CONFIG_ARM64_CPUMOD, a default-off arm64 interface for controlled performance characterization of selected implementation-defined CPU prefetch and cache-management fields. It exposes a small set of named, per-CPU attributes under the path below, with writable control fields range-checked before register state is changed:
/sys/devices/system/cpu/cpuN/cpumod/
The directory is created for online CPUs whose MIDR matches a recognized Grace or Vera profile, with common and profile-specific attributes selected for that CPU. Register accesses execute on the CPU that owns the sysfs instance, and CPU hotplug creates or removes the per-CPU subtree as the CPU transitions online or offline. Unsupported CPU profiles are skipped without blocking module load or CPU hotplug.
The implementation keeps each dynamically allocated kobject in a private per-CPU pointer, avoiding use of the CPU device's shared driver-data slot. The documentation defines the ABI, firmware prerequisite, and hotplug lifecycle. The kselftest validates profile-specific layout, unsupported-CPU skipping, decimal affected_cpus reporting, value validation, optional writes, all-online-CPU coverage, and cleanup.
The controls require firmware to permit EL1 access to the relevant implementation control registers. This is an RFC interface for controlled evaluation, not a general raw-register or production-default tuning ABI.
Compile and static verification passed. DUT runtime validation was not run.
Koba Ko (3):
arm64: add CPU prefetch and cache modulation sysfs interface Documentation/arch/arm64: document arm_cpumod
selftests: arm64: add arm_cpumod kselftest
Documentation/arch/arm64/arm-cpumod.rst | 89 +++ Documentation/arch/arm64/index.rst | 1 + arch/arm64/Kconfig | 17 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/arm_cpumod.c | 471 ++++++++++++++++ arch/arm64/kernel/arm_cpumod_internal.h | 113 ++++ tools/testing/selftests/arm64/Makefile | 2 +- .../selftests/arm64/arm_cpumod/Makefile | 5 + .../selftests/arm64/arm_cpumod/arm_cpumod.sh | 526 ++++++++++++++++++ 9 files changed, 1224 insertions(+), 1 deletion(-) create mode 100644 Documentation/arch/arm64/arm-cpumod.rst create mode 100644 arch/arm64/kernel/arm_cpumod.c create mode 100644 arch/arm64/kernel/arm_cpumod_internal.h create mode 100644 tools/testing/selftests/arm64/arm_cpumod/Makefile create mode 100755 tools/testing/selftests/arm64/arm_cpumod/arm_cpumod.sh
Signature · 1 line
2.43.0
RFC PATCH 1/3 arm64: add CPU prefetch and cache modulation sysfs interface
From: Koba Ko <[email protected]>
Performance characterization on arm64 systems sometimes needs a way to inspect and bracket selected implementation-defined prefetch and cache controls without exposing raw register contents. Add an RFC-only arm64 cpumod interface that presents a small set of named, range-checked per-CPU sysfs attributes under each CPU device.
Establish the Kconfig and Makefile plumbing, CPU profile detection for Grace and Vera from the target CPU's MIDR, register-field descriptors, per-CPU kobject and attribute helpers, locking, and target-CPU read/write callbacks. Common attributes are exposed for all supported profiles, while Grace- and Vera-specific fields are exposed only for the matching profile. Place the option at the end of the top-level Kernel Features menu because these implementation controls are not tied to an Arm architecture revision.
Per-CPU cpumod sysfs state follows the CPU lifecycle. Module initialization populates subtrees for every online CPU while holding cpus_read_lock(), so initial enumeration and CPU hotplug state registration are serialized against concurrent topology changes. Offline CPUs are intentionally skipped during initial setup because target-CPU MIDR detection requires an IPI-capable online CPU; a later online callback creates their subtree.
Profile detection reads MIDR through a synchronous callback on the CPU owning the sysfs subtree and returns nonzero only when that dispatch fails, so no IPI error can be hidden. After a successful read, retain CPUMOD_PROFILE_UNKNOWN as the unsupported-profile sentinel. Subtree creation skips that profile during both initial online enumeration and later CPUHP online callbacks without blocking module load or CPU hotplug. Object and sysfs setup failures remain fatal and are propagated.
Keep the dynamically allocated kobject state in a private per-CPU pointer instead of the CPU device's generic driver-data slot. The online callback is idempotent when that pointer already records a subtree. The offline callback clears the private pointer before dropping the kobject reference, allowing the release callback to retain ownership of the final free.
Register the dynamic CPUHP state with cpuhp_setup_state_nocalls_cpuslocked(). The nocalls form avoids replaying startup callbacks for CPUs already initialized by the explicit online enumeration. On init failure, release the CPU read lock, destroy all subtrees created so far, and return the error. Module exit removes the CPUHP state with the matching nocalls helper and tears down all remaining per-CPU state across possible CPUs.
--- arch/arm64/Kconfig | 17 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/arm_cpumod.c | 471 ++++++++++++++++++++++++ arch/arm64/kernel/arm_cpumod_internal.h | 113 ++++++ 4 files changed, 602 insertions(+) create mode 100644 arch/arm64/kernel/arm_cpumod.c create mode 100644 arch/arm64/kernel/arm_cpumod_internal.h
arch/arm64/Kconfig +17 -0
@@ -2417,6 +2417,23 @@ config ARM64_CONTPTE bit, for any mappings that meet the size and alignment requirements. This reduces TLB pressure and improves performance. +config ARM64_CPUMOD + tristate "Arm CPU prefetch modulation sysfs controls" + help + Expose selected CPU implementation control register fields through + per-CPU sysfs attributes for performance characterization. + + The exposed controls allow hardware prefetch and cache-management + policy fields to be inspected and adjusted on CPUs where firmware + permits EL1 access to the relevant implementation control registers. + Systems where firmware traps or blocks these writes cannot use this + interface. + + This interface is intended for controlled performance evaluation and + should not be enabled by default on production systems. + + If unsure, say N. + endmenu # "Kernel Features" menu "Boot options"
arch/arm64/kernel/Makefile +1 -0
@@ -69,6 +69,7 @@ obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_ARM64_MPAM) += mpam.o +obj-$(CONFIG_ARM64_CPUMOD) += arm_cpumod.o obj-$(CONFIG_ARM64_MTE) += mte.o obj-y += vdso-wrap.o obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.o
arch/arm64/kernel/arm_cpumod.c new file +471 -0
471 lines not on this page · raw message
arch/arm64/kernel/arm_cpumod_internal.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH 2/3 Documentation/arch/arm64: document arm_cpumod
In reply to KobaKFrom: Koba Ko <[email protected]>
Document the ABI intent and scope for the new arm64 cpumod interface. The sysfs directory is per-CPU and is created only for recognized Grace and Vera profiles:
/sys/devices/system/cpu/cpuN/cpumod/
CPUs with unsupported MIDRs are skipped without blocking module load or CPU hotplug and do not receive a cpumod directory.
Describe the common attributes, the Grace- and Vera-specific attributes, and the accepted range for each writable field. Out-of-range writes are documented as failing before either cached sysfs state or target CPU register state is changed.
Document the CPU hotplug lifecycle explicitly: the cpumod directory is present only while a supported CPU is online, is removed when that CPU goes offline, and is recreated when it returns online. Reads and writes therefore require an online target CPU.
Also document the firmware prerequisite: EL1 must be allowed to access the relevant implementation control registers. The interface remains an RFC for controlled performance characterization, is not a general production tuning ABI, and should stay disabled by default on production systems.
--- Documentation/arch/arm64/arm-cpumod.rst | 89 +++++++++++++++++++++++++ Documentation/arch/arm64/index.rst | 1 + 2 files changed, 90 insertions(+) create mode 100644 Documentation/arch/arm64/arm-cpumod.rst
Documentation/arch/arm64/arm-cpumod.rst new file +89 -0
@@ -0,0 +1,89 @@ +.. SPDX-License-Identifier: GPL-2.0 + +==================================== +Arm CPU prefetch modulation controls +==================================== + +``ARM64_CPUMOD`` exposes selected CPU implementation control register fields +through per-CPU sysfs attributes under:: + + /sys/devices/system/cpu/cpuN/cpumod/ + +The ``cpumod`` directory is created only when the CPU MIDR matches a recognized +Grace or Vera profile. CPUs with unsupported MIDRs are skipped without blocking +module load or CPU hotplug and do not have a ``cpumod`` directory. + +The interface is intended for controlled performance characterization and +evaluation. It is not intended as a general production tuning ABI, and the +configuration should remain disabled by default on production systems. + +Configuration and placement +=========================== + +The controls are built when ``CONFIG_ARM64_CPUMOD`` is enabled. The code lives +under ``arch/arm64/kernel/`` because the exposed state is CPU implementation +control state accessed by the arm64 kernel, similar in placement to other +architecture CPU-facing helpers. + +The ABI remains separate from the existing arm64 ``cpu*/regs`` sysfs files: +``cpumod`` exposes a small set of named, range-checked control fields rather +than a general raw register dump. + +CPU hotplug +=========== + +A ``cpumod`` directory is created only for online CPUs with a supported +profile. The directory is removed when a CPU goes offline and recreated when +the CPU comes back online, again only when its MIDR matches a supported +profile. Reads and writes require the target CPU to be online. + +Firmware requirement +==================== + +The controls require firmware to permit EL1 reads and writes to the relevant +CPU implementation control registers. On systems where firmware traps or +blocks those accesses, the interface cannot be used. + +Current ABI +=========== + +Common attributes: + +``affected_cpus`` + Read-only decimal CPU identifier for the sysfs instance. + +``pf_dis`` + Hardware prefetch disable control. Valid values are ``0`` and ``1``. + +``pf_mode`` + Hardware prefetch aggressiveness mode. Valid values are ``0`` through ``9``. + Values ``10`` through ``15`` are reserved and rejected. + +Grace-only attributes: + +``cbusy_filter_threshold`` + Valid values are ``0`` through ``3``. + +``cbusy_filter_window`` + Valid values are ``0`` through ``3``. + +``cmc_min_ways`` + Valid values are ``0`` through ``7``. + +Vera-only attributes: + +``l2spr_cmc_max_ways`` + Valid values are ``0`` through ``7``. + +Invalid writes +============== + +Writes outside the documented range fail with ``-EINVAL`` before the cached +sysfs state or remote CPU register state is updated. + +Open register inventory +======================= + +The first RFC intentionally exposes only the currently validated subset. A +complete documented-field inventory, including L2CDP, should be reviewed before +adding further ABI nodes.
Documentation/arch/arm64/index.rst +1 -0
@@ -8,6 +8,7 @@ ARM64 Architecture :maxdepth: 1 acpi_object_usage + arm-cpumod amu arm-acpi arm-cca
Signature · 1 line
2.43.0
RFC PATCH 3/3 selftests: arm64: add arm_cpumod kselftest
In reply to KobaKFrom: Koba Ko <[email protected]>
Add a kselftest for the arm_cpumod sysfs ABI. The test loads or reuses the module and selects either one target CPU or a snapshot of all online CPUs. In single-CPU mode, skip an offline target before module validation. Observe the per-CPU online attribute first. If it is absent, immediately require the CPU directory to still exist before treating the CPU as non-hotpluggable and online. If the attribute exists, it must be readable and contain 1.
After module load, recheck the online state before classifying a selected CPU without a cpumod directory as an unsupported profile. Fail if the CPU went offline or disappeared, log and skip CPUs that remain online without a directory, and require at least one selected CPU to expose a supported Grace or Vera profile. Return KSFT_SKIP if none do.
For supported CPUs, recognize the exposed Grace or Vera profile-specific layout and validate the matching attributes. Only ARM_CPUMOD_EXPECT_PROFILE supplies an external profile expectation.
Verify read paths by checking that attributes return decimal values and that affected_cpus identifies the current CPU as a decimal CPU number. Optional valid-write testing writes each current value back. Optional invalid-write testing checks selected out-of-range values and confirms that the prior value remains unchanged.
Both write paths are opt-in. Valid writeback can alter implementation-defined CPU controls; invalid-write checks exercise rejection through the same firmware-sensitive interface, but are expected not to update state. Cover all-online-CPU mode through /sys/devices/system/cpu/online and, when the test loaded the module, verify cleanup by removing it and checking that the selected CPU subtrees disappear. The test does not offline or online CPUs.
--- tools/testing/selftests/arm64/Makefile | 2 +- .../selftests/arm64/arm_cpumod/Makefile | 5 + .../selftests/arm64/arm_cpumod/arm_cpumod.sh | 526 ++++++++++++++++++ 3 files changed, 532 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/arm64/arm_cpumod/Makefile create mode 100755 tools/testing/selftests/arm64/arm_cpumod/arm_cpumod.sh
tools/testing/selftests/arm64/Makefile +1 -1
@@ -4,7 +4,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),aarch64 arm64)) -ARM64_SUBTARGETS ?= tags signal pauth fp mte bti abi gcs + ARM64_SUBTARGETS ?= tags signal pauth fp mte bti abi gcs arm_cpumod else ARM64_SUBTARGETS := endif
tools/testing/selftests/arm64/arm_cpumod/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +TEST_PROGS := arm_cpumod.sh + +include ../../lib.mk
tools/testing/selftests/arm64/arm_cpumod/arm_cpumod.sh new file +526 -0
526 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [RFC PATCH 2/3] Documentation/arch/arm64: document arm_cpumod
In reply to KobaKQuoted 78 lines · KobaK
From: Koba Ko <[email protected]>
Document the ABI intent and scope for the new arm64 cpumod interface. The sysfs directory is per-CPU and is created only for recognized Grace and Vera profiles:
/sys/devices/system/cpu/cpuN/cpumod/CPUs with unsupported MIDRs are skipped without blocking module load or CPU hotplug and do not receive a cpumod directory.
Describe the common attributes, the Grace- and Vera-specific attributes, and the accepted range for each writable field. Out-of-range writes are documented as failing before either cached sysfs state or target CPU register state is changed.
Document the CPU hotplug lifecycle explicitly: the cpumod directory is present only while a supported CPU is online, is removed when that CPU goes offline, and is recreated when it returns online. Reads and writes therefore require an online target CPU.
Also document the firmware prerequisite: EL1 must be allowed to access the relevant implementation control registers. The interface remains an RFC for controlled performance characterization, is not a general production tuning ABI, and should stay disabled by default on production systems.
Reviewed-by Fenghua Yu <[email protected]>Reviewed-by Tushar Dave <[email protected]>Reviewed-by Kai-Heng Feng <[email protected]>Signed-off-by Koba Ko <[email protected]>--- Documentation/arch/arm64/arm-cpumod.rst | 89 +++++++++++++++++++++++++ Documentation/arch/arm64/index.rst | 1 + 2 files changed, 90 insertions(+) create mode 100644 Documentation/arch/arm64/arm-cpumod.rstDocumentation/arch/arm64/arm-cpumod.rst new file +35
-0@@ -0,0 +1,89 @@ +.. SPDX-License-Identifier: GPL-2.0 + +==================================== +Arm CPU prefetch modulation controls +==================================== + +``ARM64_CPUMOD`` exposes selected CPU implementation control register fields +through per-CPU sysfs attributes under:: + + /sys/devices/system/cpu/cpuN/cpumod/ + +The ``cpumod`` directory is created only when the CPU MIDR matches a recognized +Grace or Vera profile. CPUs with unsupported MIDRs are skipped without blocking +module load or CPU hotplug and do not have a ``cpumod`` directory. + +The interface is intended for controlled performance characterization and +evaluation. It is not intended as a general production tuning ABI, and the +configuration should remain disabled by default on production systems. + +Configuration and placement +=========================== + +The controls are built when ``CONFIG_ARM64_CPUMOD`` is enabled. The code lives +under ``arch/arm64/kernel/`` because the exposed state is CPU implementation +control state accessed by the arm64 kernel, similar in placement to other +architecture CPU-facing helpers. + +The ABI remains separate from the existing arm64 ``cpu*/regs`` sysfs files: +``cpumod`` exposes a small set of named, range-checked control fields rather +than a general raw register dump. + +CPU hotplug +=========== + +A ``cpumod`` directory is created only for online CPUs with a supported
Documentation/arch/arm64/arm-cpumod.rst line 45
Quoted 10 lines
Documentation/arch/arm64/arm-cpumod.rst new file +10
-0+profile. The directory is removed when a CPU goes offline and recreated when +the CPU comes back online, again only when its MIDR matches a supported +profile. Reads and writes require the target CPU to be online. + +Firmware requirement +==================== + +The controls require firmware to permit EL1 reads and writes to the relevant +CPU implementation control registers. On systems where firmware traps or +blocks those accesses, the interface cannot be used.
How does the kernel discover if the interface can be enabled? Write a register and if we're still alive we can enable it?
Documentation/arch/arm64/arm-cpumod.rst line 47
Quoted 2 lines
Documentation/arch/arm64/arm-cpumod.rst new file +2
-0+ +Current ABI
Is the future ABI going to be different? ;)
Quoted 19 lines
Documentation/arch/arm64/arm-cpumod.rst new file +19
-0+=========== + +Common attributes: + +``affected_cpus`` + Read-only decimal CPU identifier for the sysfs instance. + +``pf_dis`` + Hardware prefetch disable control. Valid values are ``0`` and ``1``. + +``pf_mode`` + Hardware prefetch aggressiveness mode. Valid values are ``0`` through ``9``. + Values ``10`` through ``15`` are reserved and rejected. + +Grace-only attributes: + +``cbusy_filter_threshold`` + Valid values are ``0`` through ``3``. +
Documentation/arch/arm64/arm-cpumod.rst line 76
Quoted 10 lines
Documentation/arch/arm64/arm-cpumod.rst new file +10
-0+``cbusy_filter_window`` + Valid values are ``0`` through ``3``. + +``cmc_min_ways`` + Valid values are ``0`` through ``7``. + +Vera-only attributes: + +``l2spr_cmc_max_ways`` + Valid values are ``0`` through ``7``.
There is already a standard way to document sysfs entries. Use that.
Rob
Re: [RFC PATCH 1/3] arm64: add CPU prefetch and cache modulation sysfs interface
In reply to KobaKQuoted 106 lines · KobaK
From: Koba Ko <[email protected]>
Performance characterization on arm64 systems sometimes needs a way to inspect and bracket selected implementation-defined prefetch and cache controls without exposing raw register contents. Add an RFC-only arm64 cpumod interface that presents a small set of named, range-checked per-CPU sysfs attributes under each CPU device.
Establish the
KconfigandMakefileplumbing, CPU profile detection for Grace and Vera from the target CPU's MIDR, register-field descriptors, per-CPU kobject and attribute helpers, locking, and target-CPU read/write callbacks. Common attributes are exposed for all supported profiles, while Grace- and Vera-specific fields are exposed only for the matching profile. Place the option at the end of the top-level Kernel Features menu because these implementation controls are not tied to an Arm architecture revision.Per-CPU cpumod sysfs state follows the CPU lifecycle. Module initialization populates subtrees for every online CPU while holding
cpus_read_lock(), so initial enumeration and CPU hotplug state registration are serialized against concurrent topology changes. Offline CPUs are intentionally skipped during initial setup because target-CPU MIDR detection requires an IPI-capable online CPU; a later online callback creates their subtree.Profile detection reads MIDR through a synchronous callback on the CPU owning the sysfs subtree and returns nonzero only when that dispatch fails, so no IPI error can be hidden. After a successful read, retain
CPUMOD_PROFILE_UNKNOWNas the unsupported-profile sentinel. Subtree creation skips that profile during both initial online enumeration and later CPUHP online callbacks without blocking module load or CPU hotplug. Object and sysfs setup failures remain fatal and are propagated.Keep the dynamically allocated kobject state in a private per-CPU pointer instead of the CPU device's generic driver-data slot. The online callback is idempotent when that pointer already records a subtree. The offline callback clears the private pointer before dropping the kobject reference, allowing the release callback to retain ownership of the final free.
Register the dynamic CPUHP state with
cpuhp_setup_state_nocalls_cpuslocked(). The nocalls form avoids replaying startup callbacks for CPUs already initialized by the explicit online enumeration. On init failure, release the CPU read lock, destroy all subtrees created so far, and return the error. Module exit removes the CPUHP state with the matching nocalls helper and tears down all remaining per-CPU state across possible CPUs.Reviewed-by Fenghua Yu <[email protected]>Reviewed-by Tushar Dave <[email protected]>Reviewed-by Kai-Heng Feng <[email protected]>Signed-off-by Koba Ko <[email protected]>--- arch/arm64/Kconfig | 17 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/arm_cpumod.c | 471 ++++++++++++++++++++++++ arch/arm64/kernel/arm_cpumod_internal.h | 113 ++++++ 4 files changed, 602 insertions(+) create mode 100644 arch/arm64/kernel/arm_cpumod.c create mode 100644 arch/arm64/kernel/arm_cpumod_internal.harch/arm64/Kconfig +17
-0@@ -2417,6 +2417,23 @@ config ARM64_CONTPTE bit, for any mappings that meet the size and alignment requirements. This reduces TLB pressure and improves performance. +config ARM64_CPUMOD + tristate "Arm CPU prefetch modulation sysfs controls" + help + Expose selected CPU implementation control register fields through + per-CPU sysfs attributes for performance characterization. + + The exposed controls allow hardware prefetch and cache-management + policy fields to be inspected and adjusted on CPUs where firmware + permits EL1 access to the relevant implementation control registers. + Systems where firmware traps or blocks these writes cannot use this + interface. + + This interface is intended for controlled performance evaluation and + should not be enabled by default on production systems. + + If unsure, say N. + endmenu # "Kernel Features" menu "Boot options"arch/arm64/kernel/Makefile +1
-0@@ -69,6 +69,7 @@ obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_ARM64_MPAM) += mpam.o +obj-$(CONFIG_ARM64_CPUMOD) += arm_cpumod.o obj-$(CONFIG_ARM64_MTE) += mte.o obj-y += vdso-wrap.o obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.oarch/arm64/kernel/arm_cpumod.c new file +0
-0
arch/arm64/kernel/arm_cpumod.c line 1
Quoted 1 line
arch/arm64/kernel/arm_cpumod.c new file +1
-0@@ -0,0 +1,471 @@ +// SPDX-License-Identifier: GPL-2.0-only
Since the introduction of this...
arch/arm64/kernel/arm_cpumod.c line 12
Quoted 11 lines
arch/arm64/kernel/arm_cpumod.c new file +11
-0+/* +* Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details.
We stopped putting license text in.
Before you go work on my comments, I'd wait for arm64 maintainers comments. I doubt this whole thing will be accepted. In general, we don't put in impdef interfaces to userspace.
Rob
Re: [RFC PATCH 1/3] arm64: add CPU prefetch and cache modulation sysfs interface
In reply to KobaKarch/arm64/kernel/arm_cpumod.c line 170
Quoted 7 lines · KobaK
arch/arm64/kernel/arm_cpumod.c new file +7
-0+static void cpumod_attr_read_remote (void *info) +{ +struct cpumod_attr_call *call = info; +u64 *value =cpumod_attr_value_ptr (call->subsys, call->attr); + + *value =cpumod_attr_read_reg (call->attr); +}
Why do you need value in this case? Also, isn't cpumod_attr_read_reg() anmd returning to a variable that is never read?
Re: [RFC PATCH 1/3] arm64: add CPU prefetch and cache modulation sysfs interface
In reply to KobaKQuoted 47 lines · KobaK
From: Koba Ko <[email protected]>
Performance characterization on arm64 systems sometimes needs a way to inspect and bracket selected implementation-defined prefetch and cache controls without exposing raw register contents. Add an RFC-only arm64 cpumod interface that presents a small set of named, range-checked per-CPU sysfs attributes under each CPU device.
Establish the
KconfigandMakefileplumbing, CPU profile detection for Grace and Vera from the target CPU's MIDR, register-field descriptors, per-CPU kobject and attribute helpers, locking, and target-CPU read/write callbacks. Common attributes are exposed for all supported profiles, while Grace- and Vera-specific fields are exposed only for the matching profile. Place the option at the end of the top-level Kernel Features menu because these implementation controls are not tied to an Arm architecture revision.Per-CPU cpumod sysfs state follows the CPU lifecycle. Module initialization populates subtrees for every online CPU while holding
cpus_read_lock(), so initial enumeration and CPU hotplug state registration are serialized against concurrent topology changes. Offline CPUs are intentionally skipped during initial setup because target-CPU MIDR detection requires an IPI-capable online CPU; a later online callback creates their subtree.Profile detection reads MIDR through a synchronous callback on the CPU owning the sysfs subtree and returns nonzero only when that dispatch fails, so no IPI error can be hidden. After a successful read, retain
CPUMOD_PROFILE_UNKNOWNas the unsupported-profile sentinel. Subtree creation skips that profile during both initial online enumeration and later CPUHP online callbacks without blocking module load or CPU hotplug. Object and sysfs setup failures remain fatal and are propagated.Keep the dynamically allocated kobject state in a private per-CPU pointer instead of the CPU device's generic driver-data slot. The online callback is idempotent when that pointer already records a subtree. The offline callback clears the private pointer before dropping the kobject reference, allowing the release callback to retain ownership of the final free.
Register the dynamic CPUHP state with
cpuhp_setup_state_nocalls_cpuslocked(). The nocalls form avoids replaying startup callbacks for CPUs already initialized by the explicit online enumeration. On init failure, release the CPU read lock, destroy all subtrees created so far, and return the error. Module exit removes the CPUHP state with the matching nocalls helper and tears down all remaining per-CPU state across possible CPUs.
Quoted 4 lines
Reviewed-by Fenghua Yu <[email protected]>Reviewed-by Tushar Dave <[email protected]>Reviewed-by Kai-Heng Feng <[email protected]>Signed-off-by Koba Ko <[email protected]>
arch/arm64/kernel/arm_cpumod.c line 279
Quoted 10 lines
arch/arm64/kernel/arm_cpumod.c new file +10
-0+static struct cpumod_attr _name##_attr = { \ + .kattr =__ATTR (_name,0644 , cpumod_attr_show, cpumod_attr_store), \ + .value_offset = offsetof(struct cpumod_subsys , _field), \ + .reg = _reg, \ + .shift = _shift, \ + .field_mask = _field_mask, \ + .max_value = _max_value, \ + .debug_name = _debug_name, \ + .visible_profiles = _visible_profiles, \ +}
0644 makes every one of these world-readable, and cpumod_attr_show() is not a cheap read: it takes subsys->lock and then does a synchronous smp_call_function_single() to the target CPU, whose callback executes an implementation-defined mrs.
So any unprivileged user can pick a CPU and hold it under a steady stream of IPIs just by reading the file in a loop. On a Grace box running this series:
# su -s /bin/sh nobody -c 'cat /sys/devices/system/cpu/cpu0/cpumod/pf_dis' 0
Re: [RFC PATCH 1/3] arm64: add CPU prefetch and cache modulation sysfs interface
In reply to Rob HerringHi Rob,
Thanks for the review.
I will remove the obsolete GPL boilerplate and retain only the SPDX identifier and copyright notice.
I also understand the broader concern about exposing implementation-defined controls through a userspace ABI. I will hold v2 until the arm64 maintainers provide direction rather than continuing to refine an interface they may not accept. If the preferred direction is a different abstraction—or no userspace interface—I will rework or withdraw the RFC accordingly.
Thanks,
Koba
Re: [RFC PATCH 2/3] Documentation/arch/arm64: document arm_cpumod
In reply to Rob HerringHi Rob,
Thanks for the documentation feedback.
I have prepared the documentation changes: the arm64 guide no longer uses “Current ABI” or duplicates the file descriptions, and the seven sysfs files are now documented using the standard Documentation/ABI format.
The driver accesses IMP_CPUECTLR_EL1 (S3_0_C15_C1_4) and IMP_CPUECTLR2_EL1 (S3_0_C15_C1_5). I am checking with our firmware team for the kernel-visible contract that guarantees or reports EL1 access. I will not add a speculative write-and-see-if-the-system-survives probe.
I will hold v2 pending that answer and the arm64 maintainers’ direction on the interface.
Thanks,
Koba
Re: [RFC PATCH 1/3] arm64: add CPU prefetch and cache modulation sysfs interface
In reply to Breno LeitaoHi Breno,
Thanks for reviewing and testing this.
The current read result is consumed by cpumod_attr_show(), but you are right that the persistent cached-value plumbing is unnecessary. For v2, I plan to return the value through call.value, emit it directly, and remove the cached fields and helpers that no longer have a consumer.
I also agree about the permissions issue. The register-backed reads perform a synchronous IPI, so allowing unprivileged reads could generate a steady IPI stream. I plan to change the six register-backed controls to 0600 and retain affected_cpus as 0444 metadata.
I have recorded your Tested-by, but I will confirm that it still applies after these changes before carrying it into v2. The resend is currently on hold pending arm64 maintainer direction.
Thanks,
Koba