Arm Core Local Accelerator Driver
Subsystems (2)
cover Arm Core Local Accelerator Driver
Hi All,
This RFC introduces a driver for the Arm Core Local Accelerator (CLA), a CPU-local interface for programming attached accelerators. While the interface is agnostic to the accelerator type, the initial (and currently only) target is a compute engine.
The RFC aims to engage the community and get feedback on some key aspects. This will help plan our approach for eventual upstreaming. The patches implement a bare bones driver to aid discussion. Arm plans to publish the CLA spec in future, but for now I hope the documentation included with patch 1 suffices. Note that the CLA is not part of the Arm Architecture.
Patch 1 documents the hardware and driver design, and adds a driver skeleton. Patches 2-4 initialize and probe the device. Patches 5-8 add context management for switching the device between different users.
Aspects I'm seeking feedback for:
* The general structure of the driver: The current shape addresses the performance requirements we have for the use cases, and is therefore our preferred approach. But there are some unusual aspects due to the HW design.
* Driver interaction with architectural support: I've opted to treat the CLA as a device rather than a CPU extension, so it's implemented as a (mostly) self-contained driver. It has some unavoidable coupling to the arch code since it needs to share page tables and ASIDs (arm64_mm_context_[put|get]()).
* The location of the driver: although most accelerators will likely be compute ones, CLA is a generic MMIO interface that could handle any kind of accelerator. It's currently implemented as a misc driver. accel is another potential option, but given the current SVA approach, we would not use any of the services (memory-management or otherwise) that accel provides.
* User space availability: The kernel driver exposes the capabilities of the hardware to user space. Arm plans to open source a user space driver, but does not yet have any committed date. I'd like to understand if the availability of this component will be a prerequisite for upstream acceptance of the kernel driver; either way, I'm hoping we can at least progress with some discussion in its absence.
I'm deliberately constraining the scope to bare-metal support for now. Virtualization is something we are considering (and have prototyped), but plan to post a separate RFC for that as follow-up, once we have agreement on direction for the bare-metal driver.
Source, along with some tests, is available at [1]. Patches based on v7.2-rc3.
[1] https://gitlab.arm.com/linux-arm/linux-rr/-/tree/features/cla-driver-v1-rfc-tests
Thanks,
Ryan
Jean-Philippe Brucker (5):
misc/arm-cla: Add driver skeleton and documentation misc/arm-cla: Add launch operation helpers misc/arm-cla: Probe firmware-described devices misc/arm-cla: Initialize devices on CPU bringup misc/arm-cla: Accelerator context save and restore
Ryan Roberts (3):
misc/arm-cla: Set up memory translation context
misc/arm-cla: Manage domain contexts
misc/arm-cla: Add userspace interface
Documentation/misc-devices/arm-cla.rst | 206 ++++++++++ drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/arm-cla/Kconfig | 10 + drivers/misc/arm-cla/Makefile | 13 + drivers/misc/arm-cla/arm-cla-regs.h | 179 +++++++++ drivers/misc/arm-cla/arm-cla.h | 296 +++++++++++++++ drivers/misc/arm-cla/cla-ctx.c | 142 +++++++ drivers/misc/arm-cla/cla-init.c | 503 +++++++++++++++++++++++++ drivers/misc/arm-cla/cla-mtc.c | 139 +++++++ drivers/misc/arm-cla/cla-ops.c | 342 +++++++++++++++++ drivers/misc/arm-cla/cla-regs.c | 263 +++++++++++++ drivers/misc/arm-cla/cla-sched.c | 474 +++++++++++++++++++++++ drivers/misc/arm-cla/cla-topology.c | 187 +++++++++ drivers/misc/arm-cla/cla-user.c | 351 +++++++++++++++++ include/uapi/linux/arm-cla.h | 207 ++++++++++ 16 files changed, 3314 insertions(+) create mode 100644 Documentation/misc-devices/arm-cla.rst create mode 100644 drivers/misc/arm-cla/Kconfig create mode 100644 drivers/misc/arm-cla/Makefile create mode 100644 drivers/misc/arm-cla/arm-cla-regs.h create mode 100644 drivers/misc/arm-cla/arm-cla.h create mode 100644 drivers/misc/arm-cla/cla-ctx.c create mode 100644 drivers/misc/arm-cla/cla-init.c create mode 100644 drivers/misc/arm-cla/cla-mtc.c create mode 100644 drivers/misc/arm-cla/cla-ops.c create mode 100644 drivers/misc/arm-cla/cla-regs.c create mode 100644 drivers/misc/arm-cla/cla-sched.c create mode 100644 drivers/misc/arm-cla/cla-topology.c create mode 100644 drivers/misc/arm-cla/cla-user.c create mode 100644 include/uapi/linux/arm-cla.h
--
2.43.0
RFC PATCH 1/8 misc/arm-cla: Add driver skeleton and documentation
From: Jean-Philippe Brucker <[email protected]>
Add the initial Kconfig and build-system plumbing for the Arm Core Local Accelerator driver.
Introduce the common driver header and register definitions used by later CLA support. The definitions cover the CLA MMIO frame, launch response and status fields, standard accelerator registers, launch opcodes, error codes and memory translation context state.
Add documentation describing the CLA programming model, its CPU-local MMIO access rules, userspace assignment model, domain grouping and expected boot state.
--- Documentation/misc-devices/arm-cla.rst | 206 +++++++++++++++++++++++++ drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/arm-cla/Kconfig | 10 ++ drivers/misc/arm-cla/Makefile | 1 + drivers/misc/arm-cla/arm-cla-regs.h | 177 +++++++++++++++++++++ drivers/misc/arm-cla/arm-cla.h | 38 +++++ 7 files changed, 434 insertions(+) create mode 100644 Documentation/misc-devices/arm-cla.rst create mode 100644 drivers/misc/arm-cla/Kconfig create mode 100644 drivers/misc/arm-cla/Makefile create mode 100644 drivers/misc/arm-cla/arm-cla-regs.h create mode 100644 drivers/misc/arm-cla/arm-cla.h
Documentation/misc-devices/arm-cla.rst new file +206 -0
@@ -0,0 +1,206 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================ +Arm Core Local Accelerator (CLA) +================================ + +Arm CLA is an interface local to a CPU for programming accelerators that access +memory via the CPU's MMU: + + ┌───────┬───────┬───────┐ ┌───────┐ + │ CPU │ MMU │ CLA │ │ Accel │─┐ + │ │ │ │ │ │ │ + │ ---MMIO--> <--> │ │ + │ │ │ │ │ │ │ + │ │ ,-----DMA-----> │ │ + └───────┴────|──┴───────┘ └───────┘ │ + ┌──────────v────────┐ └───────┘ + │ Caches and memory │ + └───────────────────┘ + + +Hardware +======== + +The CLA supports up to 8 attached accelerators, which are accessed by +programming the CLA's MMIO registers. Operations are launched to an accelerator +and are polled for completion. CLA does not raise interrupts. + + CPU CLA Accel + |--- write DATA[7:0] -->| | + |--- write LAUNCH ----->|---- launch ---->| + |<--- poll LRESP -------| | + | | | + |<--- poll STATUS ------|<--- complete ---| + +Each operation can take a 512-bit payload in the DATA registers. After handling +a LAUNCH write, CLA indicates the launch status in the LRESP register. A further +operation can only be launched after LRESP indicates completion of the previous +launch. + +Some operations continue to run asynchronously on the accelerator after launch +completion. In this case progress is tracked by polling the STATUS register. +When the CLA updates the STATUS register, it also raises an event which will +wake an in-progress WFE (wait for event) instruction on the local CPU. + +The CLA's MMIO registers are not accessible from remote CPUs. Although each CLA +has a unique physical address, accesses from remote CPUs are read as zero and +write ignored. + +The CLA registers are accessible from four different Privilege Level (PL) +frames, with usage inteded to map to EL0 - EL3. The PLxCTRL registers may be +written via a higher PL frame to suppress access to accelerators via a lower PL +frame. + +The CPU and CLA share an MMU, although FEAT_TTCNP (common not private) is +implemented, allowing both CPU and CLA to independently opt into and out of +sharing TLB entries at runtime. TLB invalidation is performed via the CPU TLBI +instructions; any TLBI instruction that targets the CLA's local CPU will also +implicitly target the CLA. + +CLA has its own set of Memory Translation Context (MTC) registers, distinct from +the CPU. A PL can set the MTC registers corresponding to an equivalent CPU +Exception Level (EL) (eg. TCR_EL2 configurable only from the PL2 and PL3 MMIO +frame). + +Faults during address translation are reported by the accelerator in its +registers and in STATUS. While polling for work completion, software fixes up +the faults and notifies the accelerator with RESOLVE operations. + +Accesses to the MMIO registers must be aligned 64-bit loads and stores, and the +registers are mapped with Device-nGnRE attribute. Invalid accesses (unaligned, +atomic, badly sized, etc) to the MMIO frame are either read as zero and write +ignored, or cause a data abort, depending on the platform. Invalid access will +never cause an SError. + + +Inter-Accelerator Communication +------------------------------- + +On some platforms, multiple accelerators, each attached to a separate CLA within +a cluster, are also directly connected to each other via a shared bus to +accelerate cooperation between accelerators. The accelerators sharing a bus +cannot be isolated from each other. When collaborative operations are launched +on each of the participating accelerators, they synchronize over the bus, +stalling until all are ready. + + +Intended SW Usage Model +======================= + +CLA is designed for its PL0 MMIO frame to be mapped into user space and for user +space to directly launch accelerator operations and poll for completion. It has +been observed that for some use cases, the operation execution time is small and +a trip through the kernel would consume a significant amount of the CPU budget +for preparing the next operation leading to a significant reduction in bandwidth +through the accelerator. + +User space software is expected to create a thread to drive each CLA it is +using, and for each thread to be pinned to the CLA's local CPU. + +Software should rely on WFE (wait for event) to reduce power consumption when +polling STATUS. + +The CLA is intended to be configured, by privileged software via PL1 and/or PL2, +so that it shares virtual addresses with the process to which it is assigned +(SVA). In practice this means configuring the CLA's MTC to point to the same +page tables and use the same ASID (and VMID if relevant) as the process to which +it is assigned. This ensures the architectural TLB invalidations also correctly +target the CLA's TLB entries. + +We investigated the possibility of having the CLA driver allocate private page +tables, private ASIDs/VMIDs and implement an MMU notifier for invalidation, but +that suffers from 2 issues; there is a possibility of over-invalidation since +the ASID and VMID spaces overlap with the CPU's (minor), and when issuing a +TLBI, VMID is implicitly taken from CPU's VTTBR_EL2.VMID, which won't match the +CLA's private VMID - therefore, for a virtualization scenario, TLB invalidation +becomes impossible (major). + +Because the CLA has its own MTC registers, it is correct and safe for it to be +executing an operation on behalf of user process A, while its local CPU is +executing a thread from user process B. + + +Difficulties for software to deal with +-------------------------------------- + +Although each CLA is attached to a single CPU, not all CPUs have a CLA, and CLAs +may have a different set of accelerators attached. Users need to probe around to +find a suitable accelerator and bind their process to it. + +Since remote CPUs can't access the CLA, dealing with CPU hotplug migrating tasks +is challenging. And virtualization breaks down if the hypervisor cannot +guarantee that a vCPU is pinned to a CPU. + +Saving and restoring the internal state of the accelerator is an optional +feature. Current platforms only support it when the accelerator is idle, so +preempting an accelerator causes work cancellation. Software must carefully +consider how to balance forward-progress guarantees with preemption latency. + + +Driver +====== + +Booting +------- + +A host expects to be booted with CLAs in the following state: +- All attached accelerators have STATUS_IDLE set. +- PL2CTRL: AVAIL all enabled (no accelerator request made at runtime). + DBG at the firmware's discretion, preferably all enabled. +- TSCTRLOWNER.PL, TSOFFOWNER.PL, PMUOWNER.PL all EL2. + +A guest expects to be booted with CLAs in the following state: +- All attached accelerators have STATUS_IDLE set. +- PL1CTRL: AVAIL all enabled (no accelerator request made at runtime). + DBG at the hypervisor's discretion, preferably all enabled. + +Linux discovers the base address of each CLA device in the firmware tables and +creates platform devices. cla_dev behaves mostly like a regular platform device, +but it can only be accessed from one specific CPU. CPU hotplug notifiers probe +and teardown the CLA device. + +CLAs may be grouped into domains. The topology is described in the firmware +tables, and the driver creates cla_domain objects containing one or more +cla_dev. + + +Assignment to userspace +----------------------- + +A char device provides enumeration and mmap abilities to userspace. The user +task queries the driver to find a suitable set of CLAs, and mmaps their +registers. For each mapped domain, the driver creates a cla_ctx context. When +the user accesses the registers, the driver's fault handler queues the cla_ctx +and waits for assignment. A context reassignment switches the whole cla_domain, +by calling each CPU in the domain to switch the CLA context. A time slice is +given to each context before being deassigned. + +In order to access the registers, the task must be bound to the CLA's CPU with +sched_setaffinity(). Accesses from remote CPUs are ignored. If the CPU gets +offlined, the task is migrated to an online CPU, and the driver disables the +offlined CLA. User space may choose to use a mechanism such as restartable +sequences to be notified when its task has been migrated away from its intended +CLA. + +The accelerators access memory using the CPU's MMU. When assigning a context, +the driver sets up the CLA's Memory Translation Context (MTC) with the page +directory (TTBR), address space ID (ASID) and configuration (TCR) of the +context's mm. When receiving translation faults from the accelerator, the user +space task accesses the faulting address from the CPU to trigger the fault to be +fixed up by the kernel before launching a RESOLVE operation to the accelerator. + + +Power management +---------------- + +When a CPU enters a deep low-power state, then depending on the platform, the +attached CLA and accelerators might not retain their state. In that case the +firmware is expected to save the CLA and accelerator states before entering CPU +low-power state, and restore them after exiting. The CLA driver does not expect +to notice a CPU deep idle. However some accelerators do not support context +saving, in which case userspace will notice from the STATUS register that the +work was canceled during deep idle. Given that userspace would be polling +STATUS, the CPU is unlikely to enter deep idle while the CLA is running. To +ensure forward-progress the admin can disable deep idle states (see +Documentation/admin-guide/pm/cpuidle.rst).
drivers/misc/Kconfig +1 -0
@@ -651,4 +651,5 @@ source "drivers/misc/mchp_pci1xxxx/Kconfig" source "drivers/misc/keba/Kconfig" source "drivers/misc/amd-sbi/Kconfig" source "drivers/misc/rp1/Kconfig" +source "drivers/misc/arm-cla/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -74,3 +74,4 @@ obj-$(CONFIG_MCHP_LAN966X_PCI) += lan966x-pci.o obj-y += keba/ obj-y += amd-sbi/ obj-$(CONFIG_MISC_RP1) += rp1/ +obj-$(CONFIG_ARM_CLA) += arm-cla/
drivers/misc/arm-cla/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +config ARM_CLA + tristate "Arm Core Local Accelerator" + default n + depends on ARM64 + help + Arm Core Local Accelerator (CLA) is coupled with a specific CPU and + provides an interface to enumerate and access attached hardware + accelerators. It is only accessible from its associated CPU. + + If unsure, say N.
drivers/misc/arm-cla/Makefile new file +1 -0
@@ -0,0 +1 @@ +# SPDX-License-Identifier: GPL-2.0-only
drivers/misc/arm-cla/arm-cla-regs.h new file +177 -0
177 lines not on this page · raw message
drivers/misc/arm-cla/arm-cla.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Arm CLA driver - internal definitions +* +* Copyright 2026 Arm Limited. +*/ +#ifndef _ARM_CLA_H_ +#define _ARM_CLA_H_ + +#include <linux/types.h> + +#include "arm-cla-regs.h" + +/* Number of accelerators per CLA */ +#define CLA_NUM_ACC 8 +#define CLA_NUM_DATA_REGS 8 +#define CLA_SRSTATE_LEN 8 + +/** +* struct cla_dev - CLA device +* +* Immutable state: +* @cpu: The CPU this CLA is attached to. +* @dev: The platform device. +*/ +struct cla_dev { +unsigned int cpu; +struct device *dev; +}; + +#define cla_dbg (dev, fmt, ...) \ + dev_dbg((dev)->dev, "[%u] " fmt, (dev)->cpu, ##__VA_ARGS__) +#define cla_info (dev, fmt, ...) \ + dev_info((dev)->dev, "[%u] " fmt, (dev)->cpu, ##__VA_ARGS__) +#define cla_err (dev, fmt, ...) \ + dev_err((dev)->dev, "[%u] " fmt, (dev)->cpu, ##__VA_ARGS__) + +#endif /* _ARM_CLA_H_ */
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The EL2 specific memory translation context (MTC) registers are defined as absolute indices…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The EL2 specific memory translation context (MTC) registers are defined as absolute indices rather than relative offsets, breaking consistency with the common MTC offsets.
- [Low] Headers rely on implicit inclusions for data types and device structs.
--
--- Patch [1]: [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation --- commit 8a70e14ab5fcacc24591a3baaa6d296f8a8f4c6b
Author: Jean-Philippe Brucker <[email protected]>
misc/arm-cla: Add driver skeleton and documentation
This adds the initial Kconfig, build-system plumbing, and driver header definitions for the Arm Core Local Accelerator driver. It also adds documentation describing the CLA programming model and access rules.
Quoted 6 lines
drivers/misc/arm-cla/arm-cla-regs.h new file +0
-0@@ -0,0 +1,177 @@
[ ... ]
Quoted 5 lines
drivers/misc/arm-cla/arm-cla-regs.h new file +5
-0+#include <linux/bitfield.h> +#include <linux/bits.h> + +/* Registers */ +#define CLA_REG_DATA (i) (0x00 + (8 * (i)))
[ ... ]
drivers/misc/arm-cla/arm-cla-regs.h line 37
Quoted 3 lines
drivers/misc/arm-cla/arm-cla-regs.h new file +3
-0+#define CLA_PLxCTRL_AVAIL BIT(0) +#define CLA_PLxCTRL_DBGPERM GENMASK(3, 1) +#define CLA_PLxCTRL_PREP (accid, v) ((u64)(v) << (8 * (accid)))
[Severity: Low]
Should linux/types.h be included in drivers/misc/arm-cla/arm-cla-regs.h?
The CLA_PLxCTRL_PREP macro casts the value to u64, but the header doesn't include linux/types.h. This could lead to build failures if the header is included directly in new source files without prior type inclusions.
[ ... ]
drivers/misc/arm-cla/arm-cla-regs.h line 166
Quoted 13 lines
drivers/misc/arm-cla/arm-cla-regs.h new file +13
-0+/* Common register offsets */ +#define CLA_MTC_PSTATE 0 +#define CLA_MTC_TTBR0 1 +#define CLA_MTC_TTBR1 2 +#define CLA_MTC_TCR 3 +#define CLA_MTC_SCTLR 4 +#define CLA_MTC_MAIR 5 +#define CLA_MTC_TCR2 8 + +/* EL2 specific register offsets */ +#define CLA_MTC_HCR_EL2 80 +#define CLA_MTC_VTTBR_EL2 81 +#define CLA_MTC_VTCR_EL2 82
[Severity: Medium]
Are these EL2 specific register offsets intended to be relative offsets like the common ones (0-8)?
They are currently defined as absolute indices (80, 81, 82). If the driver applies these by adding the base index (e.g., CLA_MTC_REGIDX_PL2, which is 64) to the offset, using CLA_MTC_HCR_EL2 (80) would yield an index of 144. This would exceed the defined CLA_MTC_PL_SIZE (64) and target the wrong hardware address space.
Quoted 6 lines
drivers/misc/arm-cla/arm-cla.h new file +0
-0@@ -0,0 +1,38 @@
[ ... ]
Quoted 13 lines
drivers/misc/arm-cla/arm-cla.h new file +13
-0+#include <linux/types.h> + +#include "arm-cla-regs.h" + +/* Number of accelerators per CLA */ +#define CLA_NUM_ACC 8 +#define CLA_NUM_DATA_REGS 8 +#define CLA_SRSTATE_LEN 8 + +/** +* struct cla_dev - CLA device +* +* Immutable state:
drivers/misc/arm-cla/arm-cla.h line 32
Quoted 10 lines
drivers/misc/arm-cla/arm-cla.h new file +10
-0+* @cpu: The CPU this CLA is attached to. +* @dev: The platform device. +*/ +struct cla_dev { +unsigned int cpu; +struct device *dev; +}; + +#define cla_dbg (dev, fmt, ...) \ + dev_dbg((dev)->dev, "[%u] " fmt, (dev)->cpu, ##__VA_ARGS__)
[Severity: Low]
Does this header need to include linux/device.h and linux/dev_printk.h?
The cla_dbg macro uses dev_dbg() and dereferences struct device. Relying on implicit inclusions can cause build issues if arm-cla.h is included in a different order or in new files.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation
Quoted 13 lines · On Fri, Jul 17, 2026 at 10:56:37AM +0000, [email protected] wrote:
Quoted 5 lines
drivers/misc/arm-cla/arm-cla-regs.h new file +5
-0+#include <linux/bitfield.h> +#include <linux/bits.h> + +/* Registers */ +#define CLA_REG_DATA (i) (0x00 + (8 * (i)))[ ... ]
drivers/misc/arm-cla/arm-cla-regs.h line 37
Quoted 3 lines
drivers/misc/arm-cla/arm-cla-regs.h new file +3
-0+#define CLA_PLxCTRL_AVAIL BIT(0) +#define CLA_PLxCTRL_DBGPERM GENMASK(3, 1) +#define CLA_PLxCTRL_PREP (accid, v) ((u64)(v) << (8 * (accid)))[Severity: Low]
Shouldlinux/types.hbe included indrivers/misc/arm-cla/arm-cla-regs.h?
Quoted 3 lines
The
CLA_PLxCTRL_PREPmacro casts the value to u64, but the header doesn't includelinux/types.h. This could lead to build failures if the header is included directly in new source files without prior type inclusions.
linux/types.h gets included, but 4 levels deep starting from bitfields.h. I'll move the include from arm-cla.h here.
Quoted 18 lines
drivers/misc/arm-cla/arm-cla-regs.h line 166
Quoted 13 lines
drivers/misc/arm-cla/arm-cla-regs.h new file +13
-0+/* Common register offsets */ +#define CLA_MTC_PSTATE 0 +#define CLA_MTC_TTBR0 1 +#define CLA_MTC_TTBR1 2 +#define CLA_MTC_TCR 3 +#define CLA_MTC_SCTLR 4 +#define CLA_MTC_MAIR 5 +#define CLA_MTC_TCR2 8 + +/* EL2 specific register offsets */ +#define CLA_MTC_HCR_EL2 80 +#define CLA_MTC_VTTBR_EL2 81 +#define CLA_MTC_VTCR_EL2 82[Severity: Medium]
Are these EL2 specific register offsets intended to be relative offsets like the common ones (0-8)?
Quoted 5 lines
They are currently defined as absolute indices (80, 81, 82). If the driver applies these by adding the base index (e.g.,
CLA_MTC_REGIDX_PL2, which is 64) to the offset, usingCLA_MTC_HCR_EL2(80) would yield an index of 144. This would exceed the definedCLA_MTC_PL_SIZE(64) and target the wrong hardware address space.
The generic offsets are for both EL1 and EL2. These are differentiated by their _EL2 suffix. Targetting the EL3 frame or beyond causes cla_op_setctx() to fail loudly.
Quoted 12 lines
drivers/misc/arm-cla/arm-cla.h line 32
Quoted 8 lines
drivers/misc/arm-cla/arm-cla.h +7
-0+struct cla_dev { +unsigned int cpu; +struct device *dev; +}; + +#define cla_dbg (dev, fmt, ...) \ + dev_dbg((dev)->dev, "[%u] " fmt, (dev)->cpu, ##__VA_ARGS__)[Severity: Low]
Does this header need to includelinux/device.handlinux/dev_printk.h?
Quoted 3 lines
The
cla_dbgmacro usesdev_dbg()and dereferences struct device. Relying on implicit inclusions can cause build issues ifarm-cla.his included in a different order or in new files.
We include device.h in a later patch. It includes dev_prink.h
Arnd Bergmann
maintainerRe: [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation
In reply to Ryan RobertsQuoted 5 lines · Ryan Roberts
From: Jean-Philippe Brucker <[email protected]>
Add the initial
Kconfigand build-system plumbing for the Arm Core Local Accelerator driver.
Quoted 8 lines
Introduce the common driver header and register definitions used by later CLA support. The definitions cover the CLA MMIO frame, launch response and status fields, standard accelerator registers, launch opcodes, error codes and memory translation context state.
Add documentation describing the CLA programming model, its CPU-local MMIO access rules, userspace assignment model, domain grouping and expected boot state.
I have a few more questions here. Most of the description and the design decisions make perfect sense to me, but there are a few things I don't understand from your current document.
Quoted 6 lines
(quoted diff) +2
-0+The CLA supports up to 8 attached accelerators, which are accessed by +programming the CLA's MMIO registers. Operations are launched to anaccelerator
Documentation/misc-devices/arm-cla.rst new file +3
-0+and are polled for completion. CLA does not raise interrupts. + + CPU CLA Accel
Documentation/misc-devices/arm-cla.rst line 39
Quoted 10 lines
Documentation/misc-devices/arm-cla.rst new file +10
-0+ |--- write DATA[7:0] -->| | + |--- write LAUNCH ----->|---- launch ---->| + |<--- poll LRESP -------| | + | | | + |<--- poll STATUS ------|<--- complete ---| + +Each operation can take a 512-bit payload in the DATA registers. After handling +a LAUNCH write, CLA indicates the launch status in the LRESP register. A further +operation can only be launched after LRESP indicates completion of the previous +launch.
This sounds a lot like st64bv or st64bv0, passing an 8-word payload and returning a single word per accelerator operation with shared addressing.
Why are there now two interfaces to do the same thing?
Can a user process use st64bv to do the four steps in a single instruction?
Documentation/misc-devices/arm-cla.rst line 44
Quoted 4 lines
Documentation/misc-devices/arm-cla.rst new file +4
-0+Some operations continue to run asynchronously on the accelerator after launch +completion. In this case progress is tracked by polling the STATUS register. +When the CLA updates the STATUS register, it also raises an event which will +wake an in-progress WFE (wait for event) instruction on the local CPU.
The asynchronous interface seems very confusing.
How are page faults from the SVA master resolved during an asynchronous operation?
Can a CPU start multiple asynchronous operations concurrently?
Do these continue to run if the starting process is scheduled out and another process also tries to use CLA?
Documentation/misc-devices/arm-cla.rst line 68
Quoted 3 lines
Documentation/misc-devices/arm-cla.rst new file +3
-0+Faults during address translation are reported by the accelerator in its +registers and in STATUS. While polling for work completion, software fixes up +the faults and notifies the accelerator with RESOLVE operations.
I would like to understand the faulting part better. Which instruction specifically causes the fault, is that the poll STATUS read?
Documentation/misc-devices/arm-cla.rst line 85
Quoted 9 lines
Documentation/misc-devices/arm-cla.rst new file +9
-0+Inter-Accelerator Communication +------------------------------- + +On some platforms, multiple accelerators, each attached to a separate CLA within +a cluster, are also directly connected to each other via a shared bus to +accelerate cooperation between accelerators. The accelerators sharing a bus +cannot be isolated from each other. When collaborative operations are launched +on each of the participating accelerators, they synchronize over the bus, +stalling until all are ready.
Could you give an example what this model might be good for?
Does this mean a user may have to start one operation on each CPU from a thread of the same process in order to get a result efficiently across a shared accelerator?
I assume this will become clearer once you can show an example userspace application that uses this type of accelerator.
Documentation/misc-devices/arm-cla.rst line 96
Quoted 9 lines
Documentation/misc-devices/arm-cla.rst new file +9
-0+Intended SW Usage Model +======================= + +CLA is designed for its PL0 MMIO frame to be mapped into user space and for user +space to directly launch accelerator operations and poll for completion. It has +been observed that for some use cases, the operation execution time is small and +a trip through the kernel would consume a significant amount of the CPU budget +for preparing the next operation leading to a significant reduction in bandwidth +through the accelerator.
Do you have any plans for in-kernel usage of the accelerators? I would assume that for things like cryptographic features, these make sense to be exposed to the kernel itself.
Documentation/misc-devices/arm-cla.rst line 99
Quoted 2 lines
Documentation/misc-devices/arm-cla.rst new file +2
-0+User space software is expected to create a thread to drive each CLA it is +using, and for each thread to be pinned to the CLA's local CPU.
What happens if multiple processes have the same chardev open and each mmap() that, e.g. after a fork()? Does each process see its own virtual instance of the accelerator and interact with it through the same physical MMIO register range but its own process address space, or do you have to rely on the registers being mapped only into a single mm_struct to prevent a process from messing with another process data?
Quoted 5 lines
Documentation/misc-devices/arm-cla.rst new file +4
-0+Saving and restoring the internal state of the accelerator is an optional +feature. Current platforms only support it when the accelerator is idle, so +preempting an accelerator causes work cancellation. Software must carefully +consider how to balance forward-progress guarantees with preemptionlatency.
I'm not sure I understand this point. Do you mean any async operation that was started on an accelerator may fail due to preemption, so user space must be able to restart it?
Arnd
Re: [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation
Hi Arnd,
Thanks for all your fast feedback!...
Quoted 30 lines · Arnd Bergmann
Quoted 5 lines · Ryan Roberts
From: Jean-Philippe Brucker <[email protected]>
Add the initial
Kconfigand build-system plumbing for the Arm Core Local Accelerator driver.Quoted 8 lines
Introduce the common driver header and register definitions used by later CLA support. The definitions cover the CLA MMIO frame, launch response and status fields, standard accelerator registers, launch opcodes, error codes and memory translation context state.
Add documentation describing the CLA programming model, its CPU-local MMIO access rules, userspace assignment model, domain grouping and expected boot state.
I have a few more questions here. Most of the description and the design decisions make perfect sense to me, but there are a few things I don't understand from your current document.
Quoted 11 lines
(quoted diff) +2
-0+The CLA supports up to 8 attached accelerators, which are accessed by +programming the CLA's MMIO registers. Operations are launched to anaccelerator
Documentation/misc-devices/arm-cla.rst new file +8
-0+and are polled for completion. CLA does not raise interrupts. + + CPU CLA Accel + |--- write DATA[7:0] -->| | + |--- write LAUNCH ----->|---- launch ---->| + |<--- poll LRESP -------| | + | | | + |<--- poll STATUS ------|<--- complete ---|
Quoted 8 lines
Documentation/misc-devices/arm-cla.rst line 39
Quoted 5 lines
Documentation/misc-devices/arm-cla.rst new file +5
-0+ +Each operation can take a 512-bit payload in the DATA registers. After handling +a LAUNCH write, CLA indicates the launch status in the LRESP register. A further +operation can only be launched after LRESP indicates completion of the previous +launch.This sounds a lot like st64bv or st64bv0, passing an 8-word payload and returning a single word per accelerator operation with shared addressing.
We're actually passing 9 words here; 8 DATA words plus the LAUNCH word. CLA supports only 64 bit aligned and sized accesses (other accesses are RAZ/WI) so they have to be written as 9x64bit stores. Then poll using 64bit loads.
Quoted 2 lines
Why are there now two interfaces to do the same thing?
Good question. This is how the HW operates.
Quoted 3 lines
Can a user process use st64bv to do the four steps in a single instruction?
No, unfortunately not.
Quoted 10 lines
Documentation/misc-devices/arm-cla.rst line 44
Quoted 5 lines
Documentation/misc-devices/arm-cla.rst new file +4
-0+Some operations continue to run asynchronously on the accelerator after launch +completion. In this case progress is tracked by polling the STATUS register. +When the CLA updates the STATUS register, it also raises an event which will +wake an in-progress WFE (wait for event) instruction on the local CPU.The asynchronous interface seems very confusing.
How are page faults from the SVA master resolved during an asynchronous operation?
The STATUS register has a fault bit; the poller notices, reads fault info from accelerator registers and takes actions to resolve the fault (which in practice means access from user space on CPU and fault into the kernel to handle).
Quoted 2 lines
Can a CPU start multiple asynchronous operations concurrently?
Yes; STATUS indicates READY while it can accept more asynchronous operations ("comamnds").
Quoted 3 lines
Do these continue to run if the starting process is scheduled out and another process also tries to use CLA?
Yes; the driver manages assignment of a CLA to a process context completely separately from the thread scheduler's decisions about which threads run on which CPUs and when. If another process is scheduled onto the CPU and it attempts to access it's VA for the CLA, it will fault into the driver's handler and be put to sleep until the driver decides to reassign the CLA.
Quoted 7 lines
Documentation/misc-devices/arm-cla.rst line 68
Quoted 4 lines
Documentation/misc-devices/arm-cla.rst new file +3
-0+Faults during address translation are reported by the accelerator in its +registers and in STATUS. While polling for work completion, software fixes up +the faults and notifies the accelerator with RESOLVE operations.I would like to understand the faulting part better. Which instruction specifically causes the fault, is that the poll STATUS read?
I'm not sure what you mean by "Which instruction specifically causes the fault". A fault occurs within the accelerator if it tries to access a virtual address that is not mapped by the page table or if the permissions of the mapping are not sufficient, etc... The fact that the accelerator has faulted is reported to the SW that is polling the accelerator's STATUS register within user space. That SW is expected to trigger fault handling by the usual kernel mechanisms by accessing the VA. Then it issues a RESOLVE operation to tell the accelerator it can continue.
Quoted 12 lines
Documentation/misc-devices/arm-cla.rst line 85
Quoted 10 lines
Documentation/misc-devices/arm-cla.rst new file +9
-0+Inter-Accelerator Communication +------------------------------- + +On some platforms, multiple accelerators, each attached to a separate CLA within +a cluster, are also directly connected to each other via a shared bus to +accelerate cooperation between accelerators. The accelerators sharing a bus +cannot be isolated from each other. When collaborative operations are launched +on each of the participating accelerators, they synchronize over the bus, +stalling until all are ready.Could you give an example what this model might be good for?
I can't currently share that information. I expect you might be able to have a good guess though :)
Quoted 4 lines
Does this mean a user may have to start one operation on each CPU from a thread of the same process in order to get a result efficiently across a shared accelerator?
Yes, correct. User space threads don't need to be precisesly synchronized because multiple operations can be queued.
Quoted 3 lines
I assume this will become clearer once you can show an example userspace application that uses this type of accelerator.
Yes indeed. As I said, Arm plans to open source a user space driver, but there is no commitment on dates yet.
Quoted 14 lines
Documentation/misc-devices/arm-cla.rst line 96
Quoted 10 lines
Documentation/misc-devices/arm-cla.rst new file +9
-0+Intended SW Usage Model +======================= + +CLA is designed for its PL0 MMIO frame to be mapped into user space and for user +space to directly launch accelerator operations and poll for completion. It has +been observed that for some use cases, the operation execution time is small and +a trip through the kernel would consume a significant amount of the CPU budget +for preparing the next operation leading to a significant reduction in bandwidth +through the accelerator.Do you have any plans for in-kernel usage of the accelerators? I would assume that for things like cryptographic features, these make sense to be exposed to the kernel itself.
As per cover letter: "the initial (and currently only) target is a compute engine". There are not any plans for crypto accelerators (or other things like that). So haven't been considering this as something the kernel would want to use directly.
(Sorry I'm being vague - I'm sure you appreciate I'm limited on what I can say around the use cases for now).
Quoted 11 lines
Documentation/misc-devices/arm-cla.rst line 99
Quoted 3 lines
Documentation/misc-devices/arm-cla.rst new file +2
-0+User space software is expected to create a thread to drive each CLA it is +using, and for each thread to be pinned to the CLA's local CPU.What happens if multiple processes have the same chardev open and each
mmap()that, e.g. after afork()? Does each process see its own virtual instance of the accelerator and interact with it through the same physical MMIO register range but its own process address space, or do you have to rely on the registers being mapped only into a singlemm_structto prevent a process from messing with another process data?
The driver maintains a cla_ctx for each {file description, mm_struct} pair. So in this case, even though the file description is shared between the parent and child processes, they still have distinct mm_structs so still have separate contexts allowing the driver to virtualize access correctly.
Quoted 10 lines
Quoted 6 lines
Documentation/misc-devices/arm-cla.rst new file +4
-0+Saving and restoring the internal state of the accelerator is an optional +feature. Current platforms only support it when the accelerator is idle, so +preempting an accelerator causes work cancellation. Software must carefully +consider how to balance forward-progress guarantees with preemptionlatency.
I'm not sure I understand this point. Do you mean any async operation that was started on an accelerator may fail due to preemption, so user space must be able to restart it?
Yes, at it's simplest. But it gets a bit complicated if you introduce the idea of a priority to each cla_ctx. If a high priority context needs the HW periodically and preempts a low priority context, if we just abort the low priority work on preemption, it may never make forward progress. We've been considering a grace period where the kernel will wait for the accelerators to complete their current work (up to a certain timeout) before reassigning them to the incomming context. But none of that is part of this RFC - I think that's discussion that can come later once we have the basic shape of everything agreed.
Thanks,
Ryan
Quoted 2 lines
Arnd
Arnd Bergmann
maintainerRe: [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation
Quoted 12 lines · Ryan Roberts
Quoted 3 lines · Arnd Bergmann
On Fri, Jul 17, 2026, at 12:47, Ryan Roberts wrote:
This sounds a lot like st64bv or st64bv0, passing an 8-word payload and returning a single word per accelerator operation with shared addressing.We're actually passing 9 words here; 8 DATA words plus the LAUNCH word. CLA supports only 64 bit aligned and sized accesses (other accesses are RAZ/WI) so they have to be written as 9x64bit stores. Then poll using 64bit loads.
Quoted 2 lines
Why are there now two interfaces to do the same thing?
Quoted 8 lines
Good question. This is how the HW operates.
Quoted 3 lines
Can a user process use st64bv to do the four steps in a single instruction?
No, unfortunately not.
Ok
Quoted 4 lines
Quoted 1 line
Can a CPU start multiple asynchronous operations concurrently?
Yes; STATUS indicates READY while it can accept more asynchronous operations ("comamnds").
How does userspace know which operations have already completed then? (not worried about this bit, just trying to understand)
Quoted 8 lines
Quoted 2 lines
Do these continue to run if the starting process is scheduled out and another process also tries to use CLA?
Yes; the driver manages assignment of a CLA to a process context completely separately from the thread scheduler's decisions about which threads run on which CPUs and when. If another process is scheduled onto the CPU and it attempts to access it's VA for the CLA, it will fault into the driver's handler and be put to sleep until the driver decides to reassign the CLA.
This part does sound dangerous, not in the sense that I think it's fundamentally broken, but in the complexity it adds.
I wonder if it's feasible to simplify this by always canceling any ongoing CLA operations during switch_mm():
Is there an upper bound on how long a single operation can take, or a guarantee that an operation at least provides a partial result in hardware?
From your earlier descriptions, it sounds like the CPU is usually assumed to wait for completion with WFE anyway, so from the scheduler's perspective, the thread is active while waiting for the accelerator to complete a job (even if from hardware side the CPU is powered down during WFE).
If this is how it generally operates, and the accelerator jobs are usually fast, forcing the CLA TTBR0 to be the same as the CPU TTBR0 would avoid the entire problem of unmapping the registers on context switch, but instead let this hook into the same place as the corresponding iommu_mm_data switch on x86, which seems to handle this more nicely.
Quoted 8 lines
I'm not sure what you mean by "Which instruction specifically causes the fault". A fault occurs within the accelerator if it tries to access a virtual address that is not mapped by the page table or if the permissions of the mapping are not sufficient, etc... The fact that the accelerator has faulted is reported to the SW that is polling the accelerator's STATUS register within user space. That SW is expected to trigger fault handling by the usual kernel mechanisms by accessing the VA. Then it issues a RESOLVE operation to tell the accelerator it can continue.
Got it now. I had assumed that the page fault is delivered asynchronously to the kernel without user space getting involved. In this case, I think the interface is actually cleaner, though it does add a little bit of overhead for userspace having to decipher the status.
Quoted 11 lines
Quoted 10 lines
Documentation/misc-devices/arm-cla.rst line 99
Quoted 2 lines
Documentation/misc-devices/arm-cla.rst new file +2
-0+User space software is expected to create a thread to drive each CLA it is +using, and for each thread to be pinned to the CLA's local CPU.What happens if multiple processes have the same chardev open and each
mmap()that, e.g. after afork()? Does each process see its own virtual instance of the accelerator and interact with it through the same physical MMIO register range but its own process address space, or do you have to rely on the registers being mapped only into a singlemm_structto prevent a process from messing with another process data?
Quoted 4 lines
The driver maintains a
cla_ctxfor each {file description,mm_struct} pair. So in this case, even though the file description is shared between the parent and child processes, they still have distinctmm_structsso still have separate contexts allowing the driver to virtualize access correctly.
Ok, got it.
Arnd
Re: [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation
Quoted 24 lines · Arnd Bergmann
Quoted 12 lines · Ryan Roberts
Quoted 3 lines · Arnd Bergmann
On Fri, Jul 17, 2026, at 12:47, Ryan Roberts wrote:
This sounds a lot like st64bv or st64bv0, passing an 8-word payload and returning a single word per accelerator operation with shared addressing.We're actually passing 9 words here; 8 DATA words plus the LAUNCH word. CLA supports only 64 bit aligned and sized accesses (other accesses are RAZ/WI) so they have to be written as 9x64bit stores. Then poll using 64bit loads.
Quoted 2 lines
Why are there now two interfaces to do the same thing?
Quoted 8 lines
Good question. This is how the HW operates.
Quoted 3 lines
Can a user process use st64bv to do the four steps in a single instruction?
No, unfortunately not.
Ok
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Can a CPU start multiple asynchronous operations concurrently?
Yes; STATUS indicates READY while it can accept more asynchronous operations ("comamnds").
How does userspace know which operations have already completed then? (not worried about this bit, just trying to understand)
There is nothing architected in the CLA to determine this; You can determine READY (i.e. can accept new commands) and IDLE (i.e. completed all previously submitted commands). If you want to know when a specific command completed without having to wait for all commands to complete, then you need extra knowledge of the specific accelerator.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Do these continue to run if the starting process is scheduled out and another process also tries to use CLA?
Quoted 8 lines
Quoted 5 lines
Yes; the driver manages assignment of a CLA to a process context completely separately from the thread scheduler's decisions about which threads run on which CPUs and when. If another process is scheduled onto the CPU and it attempts to access it's VA for the CLA, it will fault into the driver's handler and be put to sleep until the driver decides to reassign the CLA.
This part does sound dangerous, not in the sense that I think it's fundamentally broken, but in the complexity it adds.
Can you describe more about the complexity you see here? The intention is to _reduce_ complexity by not coupling with the CPU scheduler.
Quoted 3 lines
I wonder if it's feasible to simplify this by always canceling any ongoing CLA operations during
switch_mm():
The advice I've had so far is to avoid at all costs, coupling the CLA context switch with the CPU context switch; there are concerns about the latency impliciaitons for the CLA context switch and also a desire not to couple the CLA device driver with arch code.
Quoted 4 lines
Is there an upper bound on how long a single operation can take, or a guarantee that an operation at least provides a partial result in hardware?
For the compute accelerator we have, operations are gauranteed to complete in finite time, but that time could technically be very large. In practice operations for known use cases range from a few microseconds to ~10 milliseconds.
As I described in a previous response, the accelerator does not support full save/restore so if it is interrupted while running an operation, the operation appears aborted when the state is next restored. Due to forward progress concerns, we are looking at the possibility of a grace period (of the order of a few milliseconds) during CLA reassignment. I'm pretty sure we wouldn't want to insert that into the (non-preemptible) CPU context switch path...
Quoted 6 lines
From your earlier descriptions, it sounds like the CPU is usually assumed to wait for completion with WFE anyway, so from the scheduler's perspective, the thread is active while waiting for the accelerator to complete a job (even if from hardware side the CPU is powered down during WFE).
In practice the CPU will have some parallel work to prepare the next operation(s) for submission, but yes, eventually it will enter a polling loop waiting for accelarator completion with WFE.
Quoted 6 lines
If this is how it generally operates, and the accelerator jobs are usually fast, forcing the CLA TTBR0 to be the same as the
CPU TTBR0 would avoid the entire problem of unmapping the registers on context switch, but instead let this hook into the same place as the correspondingiommu_mm_dataswitch on x86, which seems> to handle this
more nicely.
Quoted 1 line
I agree this feels like a much simpler model on the surface but because the jobs are not always fast and because the accelerator doesn't support full save/restore, I don't think this approach flies in practice.
Thanks,
Ryan
Quoted 33 lines
Quoted 8 lines
I'm not sure what you mean by "Which instruction specifically causes the fault". A fault occurs within the accelerator if it tries to access a virtual address that is not mapped by the page table or if the permissions of the mapping are not sufficient, etc... The fact that the accelerator has faulted is reported to the SW that is polling the accelerator's STATUS register within user space. That SW is expected to trigger fault handling by the usual kernel mechanisms by accessing the VA. Then it issues a RESOLVE operation to tell the accelerator it can continue.
Got it now. I had assumed that the page fault is delivered asynchronously to the kernel without user space getting involved. In this case, I think the interface is actually cleaner, though it does add a little bit of overhead for userspace having to decipher the status.
Quoted 11 lines
Quoted 10 lines
Documentation/misc-devices/arm-cla.rst line 99
Quoted 2 lines
Documentation/misc-devices/arm-cla.rst new file +2
-0+User space software is expected to create a thread to drive each CLA it is +using, and for each thread to be pinned to the CLA's local CPU.What happens if multiple processes have the same chardev open and each
mmap()that, e.g. after afork()? Does each process see its own virtual instance of the accelerator and interact with it through the same physical MMIO register range but its own process address space, or do you have to rely on the registers being mapped only into a singlemm_structto prevent a process from messing with another process data?Quoted 4 lines
The driver maintains a
cla_ctxfor each {file description,mm_struct} pair. So in this case, even though the file description is shared between the parent and child processes, they still have distinctmm_structsso still have separate contexts allowing the driver to virtualize access correctly.Ok, got it.
Arnd
RFC PATCH 2/8 misc/arm-cla: Add launch operation helpers
In reply to Ryan RobertsFrom: Jean-Philippe Brucker <[email protected]>
CLA commands are issued by writing optional payload registers, programming the LAUNCH register and polling LRESP until the hardware accepts or rejects the operation.
Add a common launch helper that performs this sequence on the CLA's local CPU, waits for LRESP completion and translates launch response codes into Linux errors.
Build accelerator reset and register read and write support on top of it. The register read and write helpers split larger accesses into multiple launch operations when an access crosses an eight-register window.
--- drivers/misc/arm-cla/Makefile | 6 + drivers/misc/arm-cla/arm-cla.h | 21 +++ drivers/misc/arm-cla/cla-init.c | 12 ++ drivers/misc/arm-cla/cla-ops.c | 228 ++++++++++++++++++++++++++++++++ 4 files changed, 267 insertions(+) create mode 100644 drivers/misc/arm-cla/cla-init.c create mode 100644 drivers/misc/arm-cla/cla-ops.c
drivers/misc/arm-cla/Makefile +6 -0
@@ -1 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only + +arm-cla-y := \ + cla-init.o \ + cla-ops.o + +obj-$(CONFIG_ARM_CLA) += arm-cla.o
drivers/misc/arm-cla/arm-cla.h +21 -0
@@ -7,6 +7,8 @@#ifndef _ARM_CLA_H_#define _ARM_CLA_H_ +#include <linux/device.h> +#include <linux/io.h> #include <linux/types.h> #include "arm-cla-regs.h"
@@ -21,10 +23,12 @@* * Immutable state: * @cpu: The CPU this CLA is attached to. +* @regs: Registers accessed by the kernel. * @dev: The platform device. */ struct cla_dev {unsigned int cpu; +void __iomem *regs;struct device *dev; };
@@ -35,4 +39,21 @@ struct cla_dev {#define cla_err (dev, fmt, ...) \ dev_err((dev)->dev, "[%u] " fmt, (dev)->cpu, ##__VA_ARGS__) +static inline u64 cla_reg_read (struct cla_dev *dev,off_t reg) +{ +return readq_relaxed (dev->regs + reg); +} + +static inline void cla_reg_write (struct cla_dev *dev,off_t reg,u64 val) +{ +return writeq_relaxed (val, dev->regs + reg); +} + +int cla_op_wait_lresp (struct cla_dev *dev,u64 *lresp); +int cla_op_reset (struct cla_dev *dev,unsigned int accid); +int cla_op_regread (struct cla_dev *dev,unsigned int accid,unsigned int regidx, +size_t nregs,u64 *regs); +int cla_op_regwrite (struct cla_dev *dev,unsigned int accid, +unsigned int regidx,size_t nregs,u64 *regs); +#endif /* _ARM_CLA_H_ */
drivers/misc/arm-cla/cla-init.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Arm CLA driver - probing and initialization +* +* Copyright 2026 Arm Limited. +*/ + +#include <linux/module.h> + +MODULE_DESCRIPTION ("Arm Core Local Accelerator" ); +MODULE_AUTHOR ("Arm Limited" ); +MODULE_LICENSE ("GPL" );
drivers/misc/arm-cla/cla-ops.c new file +228 -0
228 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] A 32-bit integer overflow when calculating `reg_group + 8` causes out-of-bounds memory access on…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] A 32-bit integer overflow when calculating reg_group + 8 causes out-of-bounds memory access on the regs buffer and an infinite loop for high register indices.
- [High] The safety bounds check regidx + nregs > max_regidx is vulnerable to a 64-bit integer overflow, allowing massive nregs values to bypass the limit check. --
--- Patch [2]: [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers --- commit dc6365dd6ad591fc5563520a7266898c01430558
Author: Jean-Philippe Brucker <[email protected]>
misc/arm-cla: Add launch operation helpers
CLA commands are issued by programming the LAUNCH register and polling LRESP. This patch adds a common launch helper to perform this sequence and translates response codes into Linux errors, along with register read and write support.
Quoted 5 lines
drivers/misc/arm-cla/cla-ops.c new file +0
-0
[ ... ]
Quoted 14 lines
drivers/misc/arm-cla/cla-ops.c new file +14
-0+static int cla_op_access_reg (struct cla_dev *dev,u8 op, +enum cla_launch_data_mode data_mode, +unsigned int accid,unsigned int regidx, +size_t nregs,u64 *regs) +{ +int ret = -EINVAL ; +unsigned long max_regidx; +struct cla_launch launch = { + .op = op, + .accid = accid, + .data_mode = data_mode, + }; + +switch (op) {
drivers/misc/arm-cla/cla-ops.c line 169
Quoted 10 lines
drivers/misc/arm-cla/cla-ops.c new file +10
-0+case CLA_LAUNCH_OP_REGREAD : +case CLA_LAUNCH_OP_REGWRITE : + max_regidx =0x100000000 ; +break ; +default : +WARN_ON (1 ); +return -EINVAL ; + } + +if (WARN_ON (regidx + nregs > max_regidx))
[Severity: High]
Does this check adequately protect against integer overflow? If nregs is very large (for example, (size_t)-1), the addition of regidx and nregs can overflow size_t. This would result in a small positive value that bypasses the max_regidx limit.
Could this be rewritten to avoid wrap-around, perhaps by checking if nregs is greater than max_regidx - regidx?
drivers/misc/arm-cla/cla-ops.c line 175
Quoted 6 lines
drivers/misc/arm-cla/cla-ops.c new file +6
-0+return -EINVAL ; + +/* 1 to 8 registers accessed at a time, within the same 8-reg group */ +while (nregs >0 ) { +unsigned int reg_group =ALIGN_DOWN (regidx,8 ); +unsigned int max_reg =min (regidx + nregs, reg_group +8 );
[Severity: High]
Can reg_group + 8 overflow? Since regidx and reg_group are 32-bit unsigned integers, if a caller passes a register index near the 32-bit maximum (for example, 0xFFFFFFF8) and a small nregs value, reg_group + 8 will wrap around to 0.
If max_reg evaluates to 0, ndata becomes 0 - regidx, which can yield a value larger than the original nregs. Will this cause out-of-bounds memory accesses on the regs buffer when passed to cla_op_launch(), and an infinite loop due to underflowing nregs?
Quoted 17 lines
drivers/misc/arm-cla/cla-ops.c new file +17
-0+unsigned int ndata = max_reg - regidx; + + launch.ndata_m1 = ndata -1 ; + launch.regidx = regidx; + launch.data = regs; + + ret =cla_op_launch (dev, &launch); +if (ret) +break ; + + regidx += ndata; + regs += ndata; + nregs -= ndata; + } + +return ret; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers
Quoted 11 lines · On Fri, Jul 17, 2026 at 11:01:07AM +0000, [email protected] wrote:
drivers/misc/arm-cla/cla-ops.c line 175
Quoted 4 lines
drivers/misc/arm-cla/cla-ops.c new file +4
-0+/* 1 to 8 registers accessed at a time, within the same 8-reg group */ +while (nregs >0 ) { +unsigned int reg_group =ALIGN_DOWN (regidx,8 ); +unsigned int max_reg =min (regidx + nregs, reg_group +8 );[Severity: High]
Canreg_group+ 8 overflow? Since regidx andreg_groupare 32-bit unsigned integers, if a caller passes a register index near the 32-bit maximum (for example,0xFFFFFFF8) and a small nregs value,reg_group+ 8 will wrap around to 0.
Quoted 4 lines
If
max_regevaluates to 0, ndata becomes 0 - regidx, which can yield a value larger than the original nregs. Will this cause out-of-bounds memory accesses on the regs buffer when passed tocla_op_launch(), and an infinite loop due to underflowing nregs?
We do need to be careful about regidx overflow since all 32 bits are valid in CLA (custom accel range is 0x00100000-0xffffffff). I'll make it u64 in this function
Arnd Bergmann
maintainerRe: [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers
In reply to Ryan RobertsQuoted 6 lines · Ryan Roberts
From: Jean-Philippe Brucker <[email protected]>
CLA commands are issued by writing optional payload registers, programming the LAUNCH register and polling LRESP until the hardware accepts or rejects the operation.
Quoted 8 lines
Add a common launch helper that performs this sequence on the CLA's local CPU, waits for LRESP completion and translates launch response codes into Linux errors.
Build accelerator reset and register read and write support on top of it. The register read and write helpers split larger accesses into multiple launch operations when an access crosses an eight-register window.
I'm a bit confused by the MMIO register access ordering, if this is not a normal AXI attached device with a DMA master, I think it would make sense to better document what it is.
drivers/misc/arm-cla/arm-cla.h struct cla_dev { · line 50
Quoted 10 lines
drivers/misc/arm-cla/arm-cla.h +6
-0+static inline u64 cla_reg_read (struct cla_dev *dev,off_t reg) +{ +return readq_relaxed (dev->regs + reg); +} + +static inline void cla_reg_write(struct cla_dev *dev, off_t reg, u64val)
drivers/misc/arm-cla/arm-cla.h +3
-0+{ +return writeq_relaxed (val, dev->regs + reg); +}
For regular devices that have a DMA master, you cannot use the relaxed operations by default since they do not serialize against DMA transfers.
To do this properly, you'd have to define separate cla_reg_read() and cla_reg_read_relaxed() helpers and then use them as needed, ideally with a comment for each relaxed instance to explain why that one is both performance critical and safe.
If for some reason this accelerator is not a DMA master (e.g. because it is implemented through CPU microcode and accesses the memory through the CPU's own load/store unit), that should be documented here to explain that you are relying on implementation defined behavior outside of the normal driver and memory model.
drivers/misc/arm-cla/cla-ops.c line 78
Quoted 6 lines
(quoted diff) +2
-0+ /* + * No barrier needed because accesses use Device-nGnRE, within thesame
drivers/misc/arm-cla/cla-ops.c new file +3
-0+* memory-mapped peripheral, so accesses arrive at the endpoint in +* program order. +*/
This comment in turn looks completely useless, as that is true for any MMIO device. The only barriers that you'd normally need here on sane architectures (not Alpha) are to serialize MMIO against DMA.
drivers/misc/arm-cla/cla-ops.c line 106
Quoted 4 lines
drivers/misc/arm-cla/cla-ops.c new file +4
-0+ +if (launch->data_mode ==CLA_DATA_OUT ) +for (i =0 ; i < launch->ndata_m1 +1 ; i++) + launch->data[i] =cla_reg_read (dev,CLA_REG_DATA (i));
Instead of the open-coded loop, maybe this can be built on top of __iowrite32_copy()
drivers/misc/arm-cla/cla-ops.c line 122
Quoted 7 lines
drivers/misc/arm-cla/cla-ops.c new file +7
-0+/** +* cla_op_wait_lresp - Wait for any LAUNCH op to complete. +int cla_op_wait_lresp(struct cla_dev *dev, u64 *lresp) +{ +return readq_relaxed_poll_timeout_atomic(dev->regs + CLA_REG_LRESP, +*lresp, FIELD_GET(CLA_LRESP_PENDING, *lresp) == 0, +CLA_LRESP_DELAY_US, CLA_LRESP_TIMEOUT_US);
Similarly, the readq_relaxed_poll_timeout_atomic() specifically does not wait for DMA, so you may need separate helpers for devices that can do DMA and readq_poll_timeout_atomic() vs devices that never access memory and can use the relaxed version.
You may also need a non-atomic version, as blocking the CPU for 100µs is not great for realtime workloads.
Arnd
Re: [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers
Quoted 40 lines · Arnd Bergmann
Quoted 6 lines · Ryan Roberts
From: Jean-Philippe Brucker <[email protected]>
CLA commands are issued by writing optional payload registers, programming the LAUNCH register and polling LRESP until the hardware accepts or rejects the operation.
Quoted 8 lines
Add a common launch helper that performs this sequence on the CLA's local CPU, waits for LRESP completion and translates launch response codes into Linux errors.
Build accelerator reset and register read and write support on top of it. The register read and write helpers split larger accesses into multiple launch operations when an access crosses an eight-register window.
I'm a bit confused by the MMIO register access ordering, if this is not a normal AXI attached device with a DMA master, I think it would make sense to better document what it is.
drivers/misc/arm-cla/arm-cla.h struct cla_dev { · line 50
Quoted 10 lines
drivers/misc/arm-cla/arm-cla.h +6
-0+static inline u64 cla_reg_read (struct cla_dev *dev,off_t reg) +{ +return readq_relaxed (dev->regs + reg); +} + +static inline void cla_reg_write(struct cla_dev *dev, off_t reg, u64val)
drivers/misc/arm-cla/arm-cla.h +3
-0+{ +return writeq_relaxed (val, dev->regs + reg); +}For regular devices that have a DMA master, you cannot use the relaxed operations by default since they do not serialize against DMA transfers.
To do this properly, you'd have to define separate
cla_reg_read()andcla_reg_read_relaxed()helpers and then use them as needed, ideally with a comment for each relaxed instance to explain why that one is both performance critical and safe.
Quoted 6 lines
If for some reason this accelerator is not a DMA master (e.g. because it is implemented through CPU microcode and accesses the memory through the CPU's own load/store unit), that should be documented here to explain that you are relying on implementation defined behavior outside of the normal driver and memory model.
Good point, this needs better comments. The kernel driver doesn't use any DMA so the accessors can all be _relaxed. The userspace library, which does use DMA and MMIO, needs to insert memory barriers when programming the device.
It's possible we are missing barriers in the context switching path, but I don't think we need any. The driver forces accelerators to idle which, in this hardware, guarantees that all DMA initiated by previous user is complete, and no DMA will be issued until we return to user after assigning a new context. We don't touch the user buffers but for the page table walker, the barriers in the arch mm code should be sufficient.
Quoted 13 lines
drivers/misc/arm-cla/cla-ops.c line 78
Quoted 7 lines
(quoted diff) +2
-0+ /* + * No barrier needed because accesses use Device-nGnRE, within thesame
drivers/misc/arm-cla/cla-ops.c new file +3
-0+* memory-mapped peripheral, so accesses arrive at the endpoint in +* program order. +*/ This comment in turn looks completely useless, as that is true for any MMIO device. The only barriers that you'd normally need here on sane architectures (not Alpha) are to serialize MMIO against DMA.
Quoted 7 lines
drivers/misc/arm-cla/cla-ops.c line 106
Quoted 4 lines
drivers/misc/arm-cla/cla-ops.c new file +4
-0+ +if (launch->data_mode ==CLA_DATA_OUT ) +for (i =0 ; i < launch->ndata_m1 +1 ; i++) + launch->data[i] =cla_reg_read (dev,CLA_REG_DATA (i));Instead of the open-coded loop, maybe this can be built on top of
__iowrite32_copy()
Ah yes, __iowrite64_copy() should work here (reg accesses must be 64-bit).
Quoted 13 lines
drivers/misc/arm-cla/cla-ops.c line 122
Quoted 8 lines
drivers/misc/arm-cla/cla-ops.c new file +7
-0+/** +* cla_op_wait_lresp - Wait for any LAUNCH op to complete. +int cla_op_wait_lresp(struct cla_dev *dev, u64 *lresp) +{ +return readq_relaxed_poll_timeout_atomic(dev->regs + CLA_REG_LRESP, +*lresp, FIELD_GET(CLA_LRESP_PENDING, *lresp) == 0, +CLA_LRESP_DELAY_US, CLA_LRESP_TIMEOUT_US); Similarly, the
readq_relaxed_poll_timeout_atomic()specifically does not wait for DMA, so you may need separate helpers for devices that can do DMA andreadq_poll_timeout_atomic()vs devices that never access memory and can use the relaxed version.
This does not wait for DMA, only for the LAUNCH command issued with MMIO to complete.
Quoted 3 lines
You may also need a non-atomic version, as blocking the CPU for 100µs is not great for realtime workloads.
Agreed
Thanks,
Jean
RFC PATCH 3/8 misc/arm-cla: Probe firmware-described devices
In reply to Ryan RobertsFrom: Jean-Philippe Brucker <[email protected]>
Discover CLA devices from firmware and instantiate the driver with platform_driver_probe(), since the set of devices is fixed at boot. Map the MMIO frame, select the kernel-accessible privilege-level frame and associate each CLA with the CPU named by firmware.
Add the topology code used to group CLAs into domains. Domains represent the smallest unit that can be assigned independently, because CLAs in the same domain cannot be isolated from each other. Build lookup tables indexed by CPU and by mmap page offset for later fast access.
Register CPU hotplug callbacks so that hardware setup and teardown can run on the CPU local to each CLA, which is the only CPU allowed to access that CLA's registers.
--- drivers/misc/arm-cla/Makefile | 3 +- drivers/misc/arm-cla/arm-cla.h | 46 ++++++ drivers/misc/arm-cla/cla-init.c | 211 ++++++++++++++++++++++++++++ drivers/misc/arm-cla/cla-topology.c | 178 +++++++++++++++++++++++ 4 files changed, 437 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/arm-cla/cla-topology.c
drivers/misc/arm-cla/Makefile +2 -1
@@ -2,6 +2,7 @@ arm-cla-y := \ cla-init.o \ - cla-ops.o + cla-ops.o \ + cla-topology.o obj-$(CONFIG_ARM_CLA) += arm-cla.o
drivers/misc/arm-cla/arm-cla.h +46 -0
77 lines not on this page · raw message
drivers/misc/arm-cla/cla-init.c +211 -0
218 lines not on this page · raw message
drivers/misc/arm-cla/cla-topology.c new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Improper handling of `krealloc_array()` failure in `cla_dev_domain_get()` overwrites the array…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Improper handling of krealloc_array() failure in cla_dev_domain_get() overwrites the array pointer with NULL, causing a memory leak and subsequent NULL pointer dereference.
- [High] Missing platform_driver_unregister() on the cla_domains_finalise() error path leaves the driver registered, leading to a Use-After-Free.
- [Medium] Integer overflow when calculating cla_nr_domains causes lookup tables to remain unpopulated, silently breaking device initialization.
--
--- Patch [3]: [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices --- commit f4618493e3d162e6d466cff0e6d759171e5655f5
Author: Jean-Philippe Brucker <[email protected]>
misc/arm-cla: Probe firmware-described devices
Discover CLA devices from firmware and instantiate the driver with platform_driver_probe(). Map the MMIO frame, select the kernel-accessible privilege-level frame and associate each CLA with the CPU named by firmware.
Quoted 3 lines
drivers/misc/arm-cla/cla-init.c +0
-0
[ ... ]
drivers/misc/arm-cla/cla-init.c
Quoted 12 lines
drivers/misc/arm-cla/cla-init.c +0
-0ret =platform_driver_probe (&cla_driver, cla_probe);if (ret) {if (ret != -ENODEV )pr_err ("arm-cla: probe failed with %d\n" , ret);/* Some domains may have been created during probe */ goto err_domains_free; } ret =cla_domains_finalise ();if (ret) {pr_err ("arm-cla: failed to finalise domains: %d" , ret); goto err_domains_free;
[Severity: High]
If cla_domains_finalise() fails, this jumps to err_domains_free, which skips platform_driver_unregister(). Will this leave dangling pointers to the freed cla_driver struct on the platform bus?
Quoted 23 lines
drivers/misc/arm-cla/cla-init.c +0
-0}/* * Each CPU initializes their own CLA. CPUHP uses a pair of smp_mb() * when calling the startup callback, ensuring that cla_dev_setup() * reads fully initialized cla_lut_cpu and cla_dev structures. */ ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"arm-cla" , cla_dev_setup, cla_dev_teardown);if (ret <0 ) {pr_err ("arm-cla: failed to setup cpuhp: %d" , ret); goto err_driver_unregister; } cla_cpuhp_state = ret;return 0 ; err_driver_unregister:platform_driver_unregister (&cla_driver); err_domains_free:cla_domains_free ();return ret; }
[ ... ]
Quoted 3 lines
drivers/misc/arm-cla/cla-topology.c new file +0
-0
[ ... ]
Quoted 6 lines
drivers/misc/arm-cla/cla-topology.c new file +6
-0+struct cla_domain *cla_dev_domain_get (struct cla_dev *dev) +{ +int ret; +unsigned int domain_id; +struct cla_domain *domain; +
drivers/misc/arm-cla/cla-topology.c line 83
Quoted 10 lines
drivers/misc/arm-cla/cla-topology.c new file +10
-0+/* Domain ID is provided by firmware */ + ret =of_property_read_u32 (dev->dev->of_node,"domain" , &domain_id); +if (WARN_ON (ret)) +return ERR_PTR (-EINVAL ); + + domain =xa_load (&cla_domains, domain_id); +if (domain) { + domain->nr_devs++; + domain->devs =krealloc_array (domain->devs, domain->nr_devs, +sizeof (*domain->devs),GFP_KERNEL );
[Severity: High]
Does this code leak the original domain->devs array if krealloc_array() fails and returns NULL? Also, since domain->nr_devs was unconditionally incremented, will a subsequent call to cla_domains_finalise() dereference the NULL pointer at domain->devs[j]?
drivers/misc/arm-cla/cla-topology.c line 94
Quoted 11 lines
drivers/misc/arm-cla/cla-topology.c new file +11
-0+if (!domain->devs) +return ERR_PTR (-ENOMEM ); + domain->devs[domain->nr_devs -1 ] = dev; +return domain; + } + + domain =cla_domain_alloc (dev, domain_id); +if (IS_ERR (domain)) +return domain; + + cla_nr_domains =max (domain_id +1 , cla_nr_domains);
[Severity: Medium]
Can this calculation overflow to 0 if firmware provides a domain_id of UINT_MAX? If it overflows, will cla_domains_finalise() skip its loop and leave the device uninitialized in the lookup tables?
Quoted 3 lines
drivers/misc/arm-cla/cla-topology.c new file +3
-0+ +return domain; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices
Quoted 18 lines · On Fri, Jul 17, 2026 at 10:57:08AM +0000, [email protected] wrote:
Quoted 3 lines
drivers/misc/arm-cla/cla-topology.c new file +0
-0[ ... ]
Quoted 12 lines
drivers/misc/arm-cla/cla-topology.c new file +12
-0+struct cla_domain *cla_dev_domain_get (struct cla_dev *dev) +{ +int ret; +unsigned int domain_id; +struct cla_domain *domain; + +/* Domain ID is provided by firmware */ + ret =of_property_read_u32 (dev->dev->of_node,"domain" , &domain_id); +if (WARN_ON (ret)) +return ERR_PTR (-EINVAL ); + + domain =xa_load (&cla_domains, domain_id);
Quoted 8 lines
drivers/misc/arm-cla/cla-topology.c line 83
Quoted 4 lines
drivers/misc/arm-cla/cla-topology.c new file +4
-0+if (domain) { + domain->nr_devs++; + domain->devs =krealloc_array (domain->devs, domain->nr_devs, +sizeof (*domain->devs),GFP_KERNEL );[Severity: High]
Does this code leak the originaldomain->devsarray ifkrealloc_array()fails and returns NULL?
Yes, needs fix
Quoted 3 lines
Also, since
domain->nr_devswas unconditionally incremented, will a subsequent call tocla_domains_finalise()dereference the NULL pointer at domain->devs[j]?
No subsequent call
Quoted 17 lines
drivers/misc/arm-cla/cla-topology.c line 94
Quoted 12 lines
drivers/misc/arm-cla/cla-topology.c new file +11
-0+if (!domain->devs) +return ERR_PTR (-ENOMEM ); + domain->devs[domain->nr_devs -1 ] = dev; +return domain; + } + + domain =cla_domain_alloc (dev, domain_id); +if (IS_ERR (domain)) +return domain; + + cla_nr_domains =max (domain_id +1 , cla_nr_domains);[Severity: Medium]
Can this calculation overflow to 0 if firmware provides adomain_idofUINT_MAX? If it overflows, willcla_domains_finalise()skip its loop and leave the device uninitialized in the lookup tables?
FW does not provide UINT_MAX as domain ID
Arnd Bergmann
maintainerRe: [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices
In reply to Ryan Robertsdrivers/misc/arm-cla/cla-init.c line 154
Quoted 6 lines · Ryan Roberts
drivers/misc/arm-cla/cla-init.c +6
-0+ +static const struct of_device_id cla_of_match[] = { + {.compatible ="arm,cla" ,}, + {}, +}; +MODULE_DEVICE_TABLE (of, cla_of_match);
This is missing a device tree binding, and probably needs to versioned in some form.
Arnd
Re: [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices
Quoted 10 lines · Arnd Bergmann
drivers/misc/arm-cla/cla-init.c line 154
Quoted 6 lines · Ryan Roberts
drivers/misc/arm-cla/cla-init.c +6
-0+ +static const struct of_device_id cla_of_match[] = { + {.compatible ="arm,cla" ,}, + {}, +}; +MODULE_DEVICE_TABLE (of, cla_of_match);This is missing a device tree binding, and probably needs to versioned in some form.
Given the aims of the RFC, I didn't think this would be a blocker for now - of course it's on the list for if/when we get further along the road.
Thanks,
Ryan
Quoted 2 lines
Arnd
RFC PATCH 4/8 misc/arm-cla: Initialize devices on CPU bringup
In reply to Ryan RobertsFrom: Jean-Philippe Brucker <[email protected]>
CLA registers are only accessible from the CPU local to the CLA, so perform device initialization from the CPU hotplug online callback.
Clear the DATA registers, reset each attached accelerator and verify that it returns to the expected idle state. Record the set of usable accelerators and expose only those through PL0CTRL, and through PL1CTRL when the kernel is running at EL2.
Reset optional timestamp and PMU controls where available so userspace starts from a predictable state, but do not fail probing if those optional controls cannot be programmed.
On CPU teardown, reset all known accelerators and mark the device broken if reset fails, since the hotplug teardown path cannot safely fail.
--- drivers/misc/arm-cla/arm-cla.h | 14 +++ drivers/misc/arm-cla/cla-init.c | 178 ++++++++++++++++++++++++++++++++ drivers/misc/arm-cla/cla-ops.c | 19 ++++ 3 files changed, 211 insertions(+)
drivers/misc/arm-cla/arm-cla.h +14 -0
@@ -28,16 +28,25 @@ struct cla_domain;* @regs: Registers accessed by the kernel. * @dev: The platform device. * @pfn: Page of registers assigned to user. +* @accelerators: Available accelerators. * @pg_offset: Mmap offset of this device. * @domain: The domain this CLA belongs to. +* +* Mutable, only accessed under @lock: +* @lock: Protects the following members. +* @broken: Hardware failure. */ struct cla_dev {unsigned int cpu;void __iomem *regs;struct device *dev;unsigned long pfn; +u8 accelerators;unsigned long pg_offset;struct cla_domain *domain; + +struct mutex lock; +bool broken; };/**
@@ -62,6 +71,10 @@ extern struct cla_dev **cla_lut_cpu;extern struct cla_dev **cla_lut_pg;extern unsigned int cla_nr_devs; +#define cla_for_each_accid (dev, accid) \ + for ((accid) = 0; (accid) < CLA_NUM_ACC; (accid)++) \ + for_each_if((dev)->accelerators & BIT(accid)) +#define cla_dbg (dev, fmt, ...) \ dev_dbg((dev)->dev, "[%u] " fmt, (dev)->cpu, ##__VA_ARGS__)#define cla_info (dev, fmt, ...) \
@@ -97,6 +110,7 @@ void cla_domains_free(void);int cla_op_wait_lresp (struct cla_dev *dev,u64 *lresp);int cla_op_reset (struct cla_dev *dev,unsigned int accid); +int cla_op_reset_all (struct cla_dev *dev);int cla_op_regread (struct cla_dev *dev,unsigned int accid,unsigned int regidx,size_t nregs,u64 *regs); int cla_op_regwrite(struct cla_dev *dev, unsigned int accid,
drivers/misc/arm-cla/cla-init.c +178 -0
208 lines not on this page · raw message
drivers/misc/arm-cla/cla-ops.c +19 -0
@@ -143,6 +143,25 @@ int cla_op_reset(struct cla_dev *dev, unsigned int accid)return ret; } +/** +* cla_op_reset_all - Reset all attached accelerators +* @dev: CLA device. +* +* Return: 0 on success, or an error +*/ +int cla_op_reset_all (struct cla_dev *dev) +{ +int ret; +unsigned int accid; + +cla_for_each_accid (dev, accid) { + ret =cla_op_reset (dev, accid); +if (ret) +return ret <0 ? ret : -ENODEV ; + } +return 0 ; +} + static int cla_op_access_reg(struct cla_dev *dev, u8 op, enum cla_launch_data_mode data_mode, unsigned int accid, unsigned int regidx,
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH v1 4/8] misc/arm-cla: Initialize devices on CPU bringup
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
New issues:
- [High] Incomplete hardware reset in cla_op_reset_all() aborts on the first failure, leaving remaining accelerators running during teardown.
- [Medium] cla_reset_ts() incorrectly uses cla_op_regread() to configure the TSOFFOWNER register, clobbering the setup value.
- [Medium] dev->accelerators mask accumulates stale state across CPU hotplug events, causing false device failures.
- [Medium] Missing explicit clearing of the LRESP register in cla_dev_setup() despite the code comment.
Pre-existing issues:
- [High] Integer overflow in cla_op_access_reg() near the 32-bit boundary causes catastrophic underflow of nregs and out-of-bounds memory access. --
--- Patch [4]: [RFC PATCH v1 4/8] misc/arm-cla: Initialize devices on CPU bringup --- commit 9a23e1cd42d86f5042ad1e97cc30851dba6b1e3e
Author: Jean-Philippe Brucker <[email protected]>
misc/arm-cla: Initialize devices on CPU bringup
CLA registers are only accessible from the CPU local to the CLA, so perform device initialization from the CPU hotplug online callback. Clear the DATA registers, reset each attached accelerator and verify that it returns to the expected idle state.
Quoted 3 lines
drivers/misc/arm-cla/cla-init.c +0
-0
[ ... ]
Quoted 2 lines
drivers/misc/arm-cla/cla-init.c +2
-0+static int cla_reset_ts (struct cla_dev *dev,unsigned int accid) +{
[ ... ]
drivers/misc/arm-cla/cla-init.c line 47
Quoted 2 lines
drivers/misc/arm-cla/cla-init.c +2
-0+ reg =FIELD_PREP (CLA_TSOFFOWNER_PL , cla_kernel_pl); + ret =cla_op_regread (dev, accid,CLA_REG_TSOFFOWNER ,1 , ®);
[Severity: Medium]
Does this code mistakenly call cla_op_regread() instead of cla_op_regwrite() here in cla_reset_ts()? Doing so will clobber the newly prepared configuration value with the current hardware state, meaning the kernel fails to claim ownership of the TSOFFOWNER register. This could cause the subsequent writes to CLA_REG_TSVOFF and CLA_REG_TSPOFF to be ignored.
Quoted 3 lines
drivers/misc/arm-cla/cla-init.c +3
-0+if (!ret) { + reg =0 ; + ret =cla_op_regwrite (dev, accid,CLA_REG_TSVOFF ,1 , ®);
[ ... ]
Quoted 2 lines
drivers/misc/arm-cla/cla-init.c +2
-0+static int cla_dev_setup (unsigned int cpu) +{
[ ... ]
drivers/misc/arm-cla/cla-init.c line 175
Quoted 3 lines
drivers/misc/arm-cla/cla-init.c +3
-0+/* Clear DATA and LRESP_DATANZ */ +for (i =0 ; i <CLA_NUM_DATA_REGS ; i++) +cla_reg_write (dev,CLA_REG_DATA (i),0 );
[Severity: Medium]
The comment above indicates this should clear DATA and LRESP_DATANZ, but is there a missing cla_reg_write() for CLA_REG_LRESP here in cla_dev_setup()? If left uncleared, stale response data from before the CPU was offlined might remain and confuse userspace or the driver later.
drivers/misc/arm-cla/cla-init.c line 188
Quoted 13 lines
drivers/misc/arm-cla/cla-init.c +13
-0+ +/* +* Reset all accelerators. We restrict PLxCTRL to the accelerators that +* are attached and well behaved. +*/ +for (accid =0 ; accid <CLA_NUM_ACC ; accid++) { + ret =cla_dev_setup_accel (dev, accid); +if (ret >0 ) +continue ; +else if (ret <0 ) + goto err; + + dev->accelerators |= (1 << accid);
[Severity: Medium]
Could this accumulate stale state across CPU hotplug events?
Because dev->accelerators is never explicitly cleared to 0 at the start of cla_dev_setup() or during teardown, if a CPU is offlined and an accelerator subsequently fails to probe on the next online event, it will incorrectly remain in the dev->accelerators mask.
During teardown, cla_op_reset_all() might then attempt to reset a non-existent accelerator, fail, and mark the entire device as broken.
Quoted 3 lines
drivers/misc/arm-cla/cla-init.c +3
-0+ plxctrl_val |=CLA_PLxCTRL_PREP (accid, +FIELD_PREP (CLA_PLxCTRL_AVAIL,1 )); + }
[ ... ]
Quoted 3 lines
drivers/misc/arm-cla/cla-ops.c +0
-0
[ ... ]
drivers/misc/arm-cla/cla-ops.c int cla_op_reset(struct cla_dev *dev, unsigned int accid) · line 160
Quoted 9 lines
drivers/misc/arm-cla/cla-ops.c +9
-0+int cla_op_reset_all (struct cla_dev *dev) +{ +int ret; +unsigned int accid; + +cla_for_each_accid (dev, accid) { + ret =cla_op_reset (dev, accid); +if (ret) +return ret <0 ? ret : -ENODEV ;
[Severity: High]
Does returning immediately on the first error leave the remaining attached accelerators running?
When cla_op_reset_all() is called during CPU teardown, an early abort means subsequent accelerators are never quiesced. As the CPU goes offline, these active hardware accelerators could continue issuing DMA transactions or raising interrupts, posing a risk of memory corruption.
Quoted 3 lines
drivers/misc/arm-cla/cla-ops.c +3
-0+ } +return 0 ; +}
[ ... ]
Quoted 5 lines
static int cla_op_access_reg(struct
cla_dev*dev, u8 op,drivers/misc/arm-cla/cla-ops.c +0
-0enum cla_launch_data_mode data_mode, unsigned int accid, unsigned int regidx, size_t nregs, u64 *regs) {
[ ... ]
drivers/misc/arm-cla/cla-ops.c
Quoted 5 lines
drivers/misc/arm-cla/cla-ops.c +0
-0/* 1 to 8 registers accessed at a time, within the same 8-reg group */ while (nregs >0 ) {unsigned int reg_group =ALIGN_DOWN (regidx,8 );unsigned int max_reg =min (regidx + nregs, reg_group +8 );unsigned int ndata = max_reg - regidx;
[Severity: High]
This isn't a bug introduced by this patch, but can the 32-bit addition of reg_group + 8 wrap around to 0 in cla_op_access_reg()?
If a read is requested near the 32-bit boundary (e.g., regidx = 0xFFFFFFFC and nregs = 2), reg_group becomes 0xFFFFFFF8. The calculation reg_group + 8 then wraps around to 0 due to 32-bit unsigned arithmetic.
The call to min(regidx + nregs, reg_group + 8) would evaluate to min(0xFFFFFFFE, 0), returning 0. This causes ndata to become 0 - 0xFFFFFFFC, which is 4. Subtracting this from the 64-bit size_t nregs causes it to underflow to a huge value, leading to a massive out-of-bounds loop and kernel memory corruption.
Quoted 2 lines
launch.ndata_m1 = ndata - 1;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [RFC PATCH v1 4/8] misc/arm-cla: Initialize devices on CPU bringup
Quoted 9 lines · On Fri, Jul 17, 2026 at 10:58:47AM +0000, [email protected] wrote:
drivers/misc/arm-cla/cla-init.c line 47
Quoted 2 lines
drivers/misc/arm-cla/cla-init.c +2
-0+ reg =FIELD_PREP (CLA_TSOFFOWNER_PL , cla_kernel_pl); + ret =cla_op_regread (dev, accid,CLA_REG_TSOFFOWNER ,1 , ®);[Severity: Medium]
Does this code mistakenly callcla_op_regread()instead ofcla_op_regwrite()here incla_reset_ts()? Doing so will clobber the newly prepared configuration value with the current hardware state, meaning the kernel fails to claim ownership of the TSOFFOWNER register. This could cause the subsequent writes toCLA_REG_TSVOFFandCLA_REG_TSPOFFto be ignored.
Yes
Quoted 7 lines
Quoted 3 lines
drivers/misc/arm-cla/cla-init.c +3
-0+if (!ret) { + reg =0 ; + ret =cla_op_regwrite (dev, accid,CLA_REG_TSVOFF ,1 , ®);[ ... ]
Quoted 2 lines
(quoted diff) +2
-0+static int cla_dev_setup(unsigned int cpu) +{[ ... ]
Quoted 9 lines
drivers/misc/arm-cla/cla-init.c line 175
Quoted 3 lines
drivers/misc/arm-cla/cla-init.c +3
-0+/* Clear DATA and LRESP_DATANZ */ +for (i =0 ; i <CLA_NUM_DATA_REGS ; i++) +cla_reg_write (dev,CLA_REG_DATA (i),0 );[Severity: Medium]
The comment above indicates this should clear DATA andLRESP_DATANZ, but is there a missingcla_reg_write()forCLA_REG_LRESPhere incla_dev_setup()? If left uncleared, stale response data from before the CPU was offlined might remain and confuse userspace or the driver later.
No, DATANZ is tied to DATA
Quoted 17 lines
drivers/misc/arm-cla/cla-init.c line 188
Quoted 13 lines
drivers/misc/arm-cla/cla-init.c +13
-0+ +/* +* Reset all accelerators. We restrict PLxCTRL to the accelerators that +* are attached and well behaved. +*/ +for (accid =0 ; accid <CLA_NUM_ACC ; accid++) { + ret =cla_dev_setup_accel (dev, accid); +if (ret >0 ) +continue ; +else if (ret <0 ) + goto err; + + dev->accelerators |= (1 << accid);[Severity: Medium]
Could this accumulate stale state across CPU hotplug events?
Quoted 7 lines
Because
dev->acceleratorsis never explicitly cleared to 0 at the start ofcla_dev_setup()or during teardown, if a CPU is offlined and an accelerator subsequently fails to probe on the next online event, it will incorrectly remain in thedev->acceleratorsmask.During teardown,
cla_op_reset_all()might then attempt to reset a non-existent accelerator, fail, and mark the entire device as broken.
The FW does not change the visible accelerators across CPUHP events
Quoted 14 lines
drivers/misc/arm-cla/cla-ops.c int cla_op_reset(struct cla_dev *dev, unsigned int accid) · line 160
Quoted 9 lines
drivers/misc/arm-cla/cla-ops.c +9
-0+int cla_op_reset_all (struct cla_dev *dev) +{ +int ret; +unsigned int accid; + +cla_for_each_accid (dev, accid) { + ret =cla_op_reset (dev, accid); +if (ret) +return ret <0 ? ret : -ENODEV ;[Severity: High]
Does returning immediately on the first error leave the remaining attached accelerators running?
Quoted 4 lines
When
cla_op_reset_all()is called during CPU teardown, an early abort means subsequent accelerators are never quiesced. As the CPU goes offline, these active hardware accelerators could continue issuing DMA transactions or raising interrupts, posing a risk of memory corruption.
I wouldn't put too much effort into handling HW failures because they normally don't happen at this level, but finishing the iteration even in case of failure seems simple enough here.
RFC PATCH 5/8 misc/arm-cla: Accelerator context save and restore
In reply to Ryan RobertsFrom: Jean-Philippe Brucker <[email protected]>
Add helpers to save and restore CLA context for later domain switching. The saved state includes DATA registers, LRESP, per-accelerator SRSTATE and any implementation-defined internal accelerator state exposed through the IAS register window.
Use ENTERSR to stop each accelerator and collect SRSTATE, then read the advertised internal register state with REGREAD. Restore by entering SR mode from a reset, idle accelerator, writing the saved internal state with REGWRITE and completing the transition with EXITSR.
Reject accelerators that require SAVE/RESTORE operations during setup, since that path needs a DMA buffer for state storage. We don't have any accelerators that support this anyway. Allocate per-device save areas for all CLAs in a domain, sized from the combined IASSIZE discovered at setup time.
--- drivers/misc/arm-cla/Makefile | 1 + drivers/misc/arm-cla/arm-cla.h | 27 ++++ drivers/misc/arm-cla/cla-init.c | 22 +++ drivers/misc/arm-cla/cla-ops.c | 43 ++++++ drivers/misc/arm-cla/cla-regs.c | 263 ++++++++++++++++++++++++++++++++ 5 files changed, 356 insertions(+) create mode 100644 drivers/misc/arm-cla/cla-regs.c
drivers/misc/arm-cla/Makefile +1 -0
@@ -3,6 +3,7 @@ arm-cla-y := \ cla-init.o \ cla-ops.o \ + cla-regs.o \ cla-topology.o obj-$(CONFIG_ARM_CLA) += arm-cla.o
drivers/misc/arm-cla/arm-cla.h +27 -0
@@ -30,6 +30,7 @@ struct cla_domain;* @pfn: Page of registers assigned to user. * @accelerators: Available accelerators. * @pg_offset: Mmap offset of this device. +* @iassizes: Combined regstate of all accels. * @domain: The domain this CLA belongs to. * * Mutable, only accessed under @lock:
@@ -43,6 +44,7 @@ struct cla_dev {unsigned long pfn;u8 accelerators;unsigned long pg_offset; +unsigned long iassizes;struct cla_domain *domain;struct mutex lock;
@@ -65,6 +67,23 @@ struct cla_domain {struct cla_dev **devs; }; +/** +* struct cla_regs - Saved CLA register state +* +* @data: DATA registers. +* @lresp: LRESP register. +* @accel_valid: Accelerator state has been saved once. +* @srstate: Save/restore state for each accelerator. +* @regstate: Internal accelerator state. +*/ +struct cla_regs { +u64 data[CLA_NUM_DATA_REGS ]; +u64 lresp; +bool accel_valid; +u64 srstate[CLA_NUM_ACC ][CLA_SRSTATE_LEN ]; +u64 regstate[]; +}; +extern struct xarray cla_domains;extern unsigned int cla_nr_domains;extern struct cla_dev **cla_lut_cpu;
@@ -115,5 +134,13 @@ int cla_op_regread(struct cla_dev *dev, unsigned int accid, unsigned int regidx, size_t nregs, u64 *regs);int cla_op_regwrite (struct cla_dev *dev,unsigned int accid,unsigned int regidx,size_t nregs,u64 *regs); +int cla_op_entersr (struct cla_dev *dev,unsigned int accid,u64 *srstate); +int cla_op_exitsr (struct cla_dev *dev,unsigned int accid,u64 *srstate); + +int cla_regs_switch_out (struct cla_dev *dev,struct cla_regs *regs, +bool save_regs); +int cla_regs_switch_in (struct cla_dev *dev,struct cla_regs *regs); +struct cla_regs **cla_regs_alloc_domain (struct cla_domain *domain); +void cla_regs_free_domain (struct cla_domain *domain,struct cla_regs **regs);#endif /* _ARM_CLA_H_ */
drivers/misc/arm-cla/cla-init.c +22 -0
@@ -81,6 +81,8 @@ static int cla_reset_pmu(struct cla_dev *dev, unsigned int accid)static int cla_dev_setup_accel (struct cla_dev *dev,unsigned int accid) {u64 status; +u64 iassize; +u64 acap;int ret;/*
@@ -106,6 +108,26 @@ static int cla_dev_setup_accel(struct cla_dev *dev, unsigned int accid)return -EIO ; } +/* +* We don't support SROP (SAVE and RESTORE ops), only context switching +* with REGREAD and REGWRITE. SROP would require finding a DMA buffer +* where to save state, ideally in userspace process to avoid kernel +* DMA. It's complicated and no implementation needs it at the moment. +*/ + ret =cla_op_regread (dev, accid,CLA_REG_ACAP ,1 , &acap); +if (ret) +return ret; +if (FIELD_GET (CLA_ACAP_SROP , acap)) { +cla_err (dev,"[%u] SROP not supported\n" , accid); +return 1 ; + } + + ret =cla_op_regread (dev, accid,CLA_REG_IASSIZE ,1 , &iassize); +if (ret) +return ret; +if (FIELD_GET (CLA_ACAP_REGSTATE , acap) && iassize) + dev->iassizes += iassize; +/* * The following are nice to have, but the accelerator should work * without them.
drivers/misc/arm-cla/cla-ops.c +43 -0
46 lines not on this page · raw message
drivers/misc/arm-cla/cla-regs.c new file +263 -0
263 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH v1 5/8] misc/arm-cla: Accelerator context save and restore
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Heap buffer overflow due to unit mismatch in internal accelerator state (IAS) memory allocation…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Heap buffer overflow due to unit mismatch in internal accelerator state (IAS) memory allocation and bounds checking.
- [Medium] Incomplete context save leaves regs->accel_valid as true, leading to corrupted hardware state on subsequent restore. --
--- Patch [5]: [RFC PATCH v1 5/8] misc/arm-cla: Accelerator context save and restore --- commit 96459db186d7c9fdaf43a3521dada1e5846d6b74
Author: Jean-Philippe Brucker <[email protected]>
misc/arm-cla: Accelerator context save and restore
This commit adds helpers to save and restore CLA context for later domain switching. The saved state includes DATA registers, LRESP, per-accelerator SRSTATE, and internal accelerator state exposed through the IAS register window.
Quoted 6 lines
drivers/misc/arm-cla/cla-regs.c new file +0
-0@@ -0,0 +1,263 @@
[ ... ]
Quoted 3 lines
drivers/misc/arm-cla/cla-regs.c new file +3
-0+static int cla_regs_save_accel (struct cla_dev *dev,unsigned int accid, +struct cla_regs *regs,off_t *regstate_off) +{
[ ... ]
drivers/misc/arm-cla/cla-regs.c line 45
Quoted 3 lines
drivers/misc/arm-cla/cla-regs.c new file +3
-0+ regstate_size =FIELD_GET (CLA_SRSTATE_0_REGSTATE , srstate[0 ]); +if (WARN_ON (*regstate_off + regstate_size *8 > dev->iassizes)) +return -ENOSPC ;
[Severity: High]
Does this bounds check correctly handle the units for *regstate_off?
*regstate_off is incremented by regstate_size (which is a register count), so it is also a register count.
If dev->iassizes is in bytes, this check improperly adds a register count (*regstate_off) to a byte count (regstate_size * 8) and compares it against a byte count.
Because regs->regstate + *regstate_off scales the offset by 8 during the memory access, this check can pass even when the access goes out of bounds.
For example, if dev->iassizes = 160 bytes, *regstate_off = 20, and regstate_size = 10, the check evaluates to 20 + 80 <= 160 (passes). However, the accessed memory is at byte offset (20 + 10) * 8 = 240, overflowing the buffer.
Quoted 4 lines
drivers/misc/arm-cla/cla-regs.c new file +4
-0+ +if (regstate_size) { + ret =cla_op_regread (dev, accid, CLA_REG_IASn, regstate_size, + regs->regstate + *regstate_off);
[ ... ]
Quoted 3 lines
drivers/misc/arm-cla/cla-regs.c new file +3
-0+static int cla_regs_restore_accel (struct cla_dev *dev,unsigned int accid, +struct cla_regs *regs,off_t *regstate_off) +{
[ ... ]
drivers/misc/arm-cla/cla-regs.c line 45
Quoted 3 lines
drivers/misc/arm-cla/cla-regs.c new file +3
-0+ regstate_size =FIELD_GET (CLA_SRSTATE_0_REGSTATE , srstate[0 ]); +if (WARN_ON (*regstate_off + regstate_size *8 > dev->iassizes)) +return -ENOSPC ;
[Severity: High]
This appears to have the exact same unit mismatch issue as cla_regs_save_accel(), which could lead to out-of-bounds memory reads when restoring accelerator state.
Quoted 4 lines
drivers/misc/arm-cla/cla-regs.c new file +4
-0+ +if (regstate_size) { + ret =cla_op_regwrite (dev, accid, CLA_REG_IASn, regstate_size, + regs->regstate + *regstate_off);
[ ... ]
Quoted 3 lines
drivers/misc/arm-cla/cla-regs.c new file +3
-0+int cla_regs_switch_out (struct cla_dev *dev,struct cla_regs *regs, +bool save_regs) +{
[ ... ]
drivers/misc/arm-cla/cla-regs.c line 142
Quoted 8 lines
drivers/misc/arm-cla/cla-regs.c new file +8
-0+if (save_regs) { +for (i =0 ; i <CLA_NUM_DATA_REGS ; i++) + regs->data[i] =cla_reg_read (dev,CLA_REG_DATA (i)); + +cla_for_each_accid (dev, accid) { + ret =cla_regs_save_accel (dev, accid, regs, ®state_off); +if (ret) +return ret;
[Severity: Medium]
If cla_regs_save_accel() fails here, the function returns without clearing regs->accel_valid.
Since regs is allocated once per domain and reused, accel_valid might already be true from a previous successful save. Returning an error here leaves the structure partially overwritten (a mix of old and new accelerator states) but still marked as valid.
If the caller handles this switch-out failure non-fatally and retries the context later, will cla_regs_switch_in() restore this corrupted state to the hardware?
Quoted 4 lines
drivers/misc/arm-cla/cla-regs.c new file +4
-0+ } + + regs->accel_valid = true; + }
[ ... ]
Quoted 2 lines
drivers/misc/arm-cla/cla-regs.c new file +2
-0+struct cla_regs **cla_regs_alloc_domain (struct cla_domain *domain) +{
[ ... ]
drivers/misc/arm-cla/cla-regs.c line 233
Quoted 9 lines
drivers/misc/arm-cla/cla-regs.c new file +9
-0+for (i =0 ; i < domain->nr_devs; i++) { +struct cla_regs *regs; +struct cla_dev *dev = domain->devs[i]; + +/* +* The regs structures are only ever accessed from the CLA +* device's CPU, so try to allocate them on the right NUMA node +*/ + size =sizeof (*regs) + dev->iassizes;
[Severity: High]
If dev->iassizes represents a register count rather than a byte count, should it be scaled by sizeof(u64) here?
If it is unscaled, the allocation for the flexible array regs->regstate will be 8 times too small, leading to heap buffer overflows during save and restore operations.
Quoted 2 lines
drivers/misc/arm-cla/cla-regs.c new file +2
-0+ regs =kvzalloc_node (size,GFP_KERNEL_ACCOUNT , +cpu_to_node (dev->cpu));
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [RFC PATCH v1 5/8] misc/arm-cla: Accelerator context save and restore
Quoted 7 lines · On Fri, Jul 17, 2026 at 10:58:10AM +0000, [email protected] wrote:
drivers/misc/arm-cla/cla-regs.c line 45
Quoted 3 lines
drivers/misc/arm-cla/cla-regs.c new file +3
-0+ regstate_size =FIELD_GET (CLA_SRSTATE_0_REGSTATE , srstate[0 ]); +if (WARN_ON (*regstate_off + regstate_size *8 > dev->iassizes)) +return -ENOSPC ;[Severity: High]
Does this bounds check correctly handle the units for*regstate_off?
Quoted 6 lines
*regstate_offis incremented byregstate_size(which is a register count), so it is also a register count.If
dev->iassizesis in bytes, this check improperly adds a register count (*regstate_off) to a byte count (regstate_size* 8) and compares it against a byte count.
Yes this should be WARN_ON((*regstate_off + regstate_size) * 8 > dev->iassizes)
Quoted 17 lines
Quoted 3 lines
drivers/misc/arm-cla/cla-regs.c new file +3
-0+int cla_regs_switch_out (struct cla_dev *dev,struct cla_regs *regs, +bool save_regs) +{[ ... ]
drivers/misc/arm-cla/cla-regs.c line 142
Quoted 8 lines
drivers/misc/arm-cla/cla-regs.c new file +8
-0+if (save_regs) { +for (i =0 ; i <CLA_NUM_DATA_REGS ; i++) + regs->data[i] =cla_reg_read (dev,CLA_REG_DATA (i)); + +cla_for_each_accid (dev, accid) { + ret =cla_regs_save_accel (dev, accid, regs, ®state_off); +if (ret) +return ret;[Severity: Medium]
Ifcla_regs_save_accel()fails here, the function returns without clearingregs->accel_valid.
Quoted 8 lines
Since regs is allocated once per domain and reused,
accel_validmight already be true from a previous successful save. Returning an error here leaves the structure partially overwritten (a mix of old and new accelerator states) but still marked as valid.If the caller handles this switch-out failure non-fatally and retries the context later, will
cla_regs_switch_in()restore this corrupted state to the hardware?
Switch-out failure is fatal, requires at least module reload
Quoted 8 lines
Quoted 4 lines
drivers/misc/arm-cla/cla-regs.c new file +4
-0+ } + + regs->accel_valid = true; + }[ ... ]
Quoted 2 lines
(quoted diff) +2
-0+struct cla_regs **cla_regs_alloc_domain(struct cla_domain *domain) +{[ ... ]
Quoted 13 lines
drivers/misc/arm-cla/cla-regs.c line 233
Quoted 9 lines
drivers/misc/arm-cla/cla-regs.c new file +9
-0+for (i =0 ; i < domain->nr_devs; i++) { +struct cla_regs *regs; +struct cla_dev *dev = domain->devs[i]; + +/* +* The regs structures are only ever accessed from the CLA +* device's CPU, so try to allocate them on the right NUMA node +*/ + size =sizeof (*regs) + dev->iassizes;[Severity: High]
Ifdev->iassizesrepresents a register count rather than a byte count, should it be scaled by sizeof(u64) here?
iassizes is a byte count
RFC PATCH 6/8 misc/arm-cla: Set up memory translation context
In reply to Ryan RobertsCLA accelerators use a Memory Translation Context to describe the page-table and memory-system configuration used for DMA through the CPU MMU. Set up the kernel-owned MTC during CLA bringup so later context switches only need to replace the user TTBR0 value.
Populate the MTC from the CPU EL1 configuration, including SCTLR, MAIR, TCR and TCR2 where present. Configure the accelerator to run as EL0, put the ASID in TTBR0 and disable TTBR1 translations because the driver only installs user contexts in the TTBR0 range. When running at EL2, also program the host HCR state.
Add SETCTX and GETCTX launch helpers for MTC register access. Use the first available accelerator ID for these operations, since the MTC is shared by the CLA but the operation still requires a valid accelerator ID.
Clear the MTC on CPU teardown, and add helpers to install and uninstall a user translation context by updating TTBR0 with the process page table, ASID and CnP state.
--- drivers/misc/arm-cla/Makefile | 1 + drivers/misc/arm-cla/arm-cla.h | 9 +++ drivers/misc/arm-cla/cla-init.c | 10 ++- drivers/misc/arm-cla/cla-mtc.c | 139 ++++++++++++++++++++++++++++++++ drivers/misc/arm-cla/cla-ops.c | 52 ++++++++++++ 5 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/arm-cla/cla-mtc.c
drivers/misc/arm-cla/Makefile +1 -0
@@ -2,6 +2,7 @@ arm-cla-y := \ cla-init.o \ + cla-mtc.o \ cla-ops.o \ cla-regs.o \ cla-topology.o
drivers/misc/arm-cla/arm-cla.h +9 -0
@@ -134,6 +134,10 @@ int cla_op_regread(struct cla_dev *dev, unsigned int accid, unsigned int regidx, size_t nregs, u64 *regs);int cla_op_regwrite (struct cla_dev *dev,unsigned int accid,unsigned int regidx,size_t nregs,u64 *regs); +int cla_op_setctx (struct cla_dev *dev,unsigned int regidx,size_t nregs, +u64 *regs); +int cla_op_getctx (struct cla_dev *dev,unsigned int regidx,size_t nregs, +u64 *regs);int cla_op_entersr (struct cla_dev *dev,unsigned int accid,u64 *srstate);int cla_op_exitsr (struct cla_dev *dev,unsigned int accid,u64 *srstate);
@@ -143,4 +147,9 @@ int cla_regs_switch_in(struct cla_dev *dev, struct cla_regs *regs);struct cla_regs **cla_regs_alloc_domain (struct cla_domain *domain);void cla_regs_free_domain (struct cla_domain *domain,struct cla_regs **regs); +int cla_mtc_setup (struct cla_dev *dev); +int cla_mtc_clear (struct cla_dev *dev); +int cla_mtc_install (struct cla_dev *dev,pgd_t *pgd,unsigned long asid); +int cla_mtc_uninstall (struct cla_dev *dev); +#endif /* _ARM_CLA_H_ */
drivers/misc/arm-cla/cla-init.c +8 -2
@@ -155,7 +155,8 @@ static void cla_dev_reinit(struct cla_dev *dev)if (broken)return ; -if (WARN_ON (cla_op_reset_all (dev))) { +if (WARN_ON (cla_op_reset_all (dev)) || +WARN_ON (cla_mtc_clear (dev))) {mutex_lock (&dev->lock); dev->broken = true;mutex_unlock (&dev->lock);
@@ -217,9 +218,14 @@ static int cla_dev_setup(unsigned int cpu)cla_reg_write (dev,CLA_REG_PL0CTRL , plxctrl_val); -if (dev->accelerators) +if (dev->accelerators) { + ret =cla_mtc_setup (dev); +if (ret) + goto err; +cla_info (dev,"available accelerators: 0x%02x\n" , dev->accelerators); + }return 0 ; err:
drivers/misc/arm-cla/cla-mtc.c new file +139 -0
139 lines not on this page · raw message
drivers/misc/arm-cla/cla-ops.c +52 -0
64 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH v1 6/8] misc/arm-cla: Set up memory translation context
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Type mismatch in the `min()` macro arguments will trigger strict type-checking compiler errors. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Type mismatch in the min() macro arguments will trigger strict type-checking compiler errors. --
--- Patch [6]: [RFC PATCH v1 6/8] misc/arm-cla: Set up memory translation context --- commit 5af1b39fed17c5b5bbf7cdc121a0531df0a24e2d
Author: Ryan Roberts <[email protected]>
misc/arm-cla: Set up memory translation context
This commit sets up a Memory Translation Context (MTC) during CLA bringup for CPU MMU DMA configurations. It populates the MTC from EL1 configuration, configuring the accelerator to run as EL0 and installing user translation contexts via TTBR0.
Quoted 5 lines
drivers/misc/arm-cla/cla-ops.c +0
-0
drivers/misc/arm-cla/cla-ops.c static int cla_op_access_reg(struct cla_dev *dev, u8 op, · line 189
Quoted 10 lines
drivers/misc/arm-cla/cla-ops.c +4
-0@@ -180,6 +180,10 @@ static int cla_op_access_reg(struct cla_dev *dev, u8 op,case CLA_LAUNCH_OP_REGWRITE : max_regidx =0x100000000 ;break ; +case CLA_LAUNCH_OP_SETCTX : +case CLA_LAUNCH_OP_GETCTX : + max_regidx =0x80 ; +break ;default :WARN_ON (1 );return -EINVAL ;
[Severity: Low]
Will this result in a build failure due to strict type checking in the min() macro?
Further down in cla_op_access_reg(), the code calculates the max register using min():
while (nregs > 0) {
unsigned int reg_group = ALIGN_DOWN(regidx, 8);
unsigned int max_reg = min(regidx + nregs, reg_group + 8);Since nregs is a size_t (64-bit on ARM64) and reg_group is an unsigned int (32-bit), the min() macro will catch the type mismatch between its arguments. Could this be resolved by using min_t() or casting the arguments to matching types?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [RFC PATCH v1 6/8] misc/arm-cla: Set up memory translation context
Quoted 7 lines · On Fri, Jul 17, 2026 at 11:02:14AM +0000, [email protected] wrote:
[Severity: Low]
Will this result in a build failure due to strict type checking in themin()macro?Further down in
cla_op_access_reg(), the code calculates the max register usingmin():
Quoted 6 lines
while (nregs > 0) { unsigned int reg_group = ALIGN_DOWN(regidx, 8); unsigned int max_reg = min(regidx + nregs, reg_group + 8);Since nregs is a
size_t(64-bit on ARM64) andreg_groupis an unsigned int (32-bit)
reg_group is now 64-bit
RFC PATCH 7/8 misc/arm-cla: Manage domain contexts
In reply to Ryan RobertsA CLA domain cannot be used by multiple address spaces concurrently because its devices share a memory translation context and may communicate without isolation. Represent each user of a domain with a context keyed by the mm_struct and device file description, and track contexts in a per-domain hash table.
Add a domain scheduler that queues contexts for assignment and gives each one a fixed time slice. Before switching, revoke the outgoing context's mappings from all VMAs for the device file. Then save its accelerator state and remove its MTC, before installing the incoming context's MTC and restoring the incoming accelerator state.
Run hardware operations through CPU-bound kthread workers, since each CLA can only be accessed from its local CPU. Coordinate the per-device workers with a domain worker so that every CLA in the domain is switched as a single assignment unit.
Defer context deassignment and destruction when the final mapping disappears to avoid taking mmap_lock in the wrong order. Keep the mm and file alive until the context has been removed from hardware and reclaimed.
Treat a failure on any device as a failure of the whole domain. Stop further assignments and wake all waiters when a domain becomes unusable.
--- drivers/misc/arm-cla/Makefile | 2 + drivers/misc/arm-cla/arm-cla.h | 128 ++++++++ drivers/misc/arm-cla/cla-ctx.c | 142 +++++++++ drivers/misc/arm-cla/cla-init.c | 48 +++ drivers/misc/arm-cla/cla-sched.c | 474 ++++++++++++++++++++++++++++ drivers/misc/arm-cla/cla-topology.c | 9 + 6 files changed, 803 insertions(+) create mode 100644 drivers/misc/arm-cla/cla-ctx.c create mode 100644 drivers/misc/arm-cla/cla-sched.c
drivers/misc/arm-cla/Makefile +2 -0
@@ -2,9 +2,11 @@ arm-cla-y := \ cla-init.o \ + cla-ctx.o \ cla-mtc.o \ cla-ops.o \ cla-regs.o \ + cla-sched.o \ cla-topology.o obj-$(CONFIG_ARM_CLA) += arm-cla.o
drivers/misc/arm-cla/arm-cla.h +128 -0
185 lines not on this page · raw message
drivers/misc/arm-cla/cla-ctx.c new file +142 -0
142 lines not on this page · raw message
drivers/misc/arm-cla/cla-init.c +48 -0
78 lines not on this page · raw message
drivers/misc/arm-cla/cla-sched.c new file +474 -0
474 lines not on this page · raw message
drivers/misc/arm-cla/cla-topology.c +9 -0
@@ -37,6 +37,8 @@ static struct cla_domain *cla_domain_alloc(struct cla_dev *dev, unsigned int id)if (!domain)return ERR_PTR (-ENOMEM ); +mutex_init (&domain->lock); + domain->id = id; ret =xa_insert (&cla_domains, id, domain,GFP_KERNEL );if (ret <0 )
@@ -50,8 +52,14 @@ static struct cla_domain *cla_domain_alloc(struct cla_dev *dev, unsigned int id) } domain->devs[0 ] = dev; + ret =cla_domain_sched_init (domain); +if (ret) + goto err_free_devs; +return domain; +err_free_devs: +kfree (domain->devs); err_free_id:xa_erase (&cla_domains, domain->id); err_free_domain:
@@ -155,6 +163,7 @@ int __init cla_domains_finalise(void)static void cla_domain_free (struct cla_domain *domain) { +cla_domain_sched_exit (domain);kfree (domain->devs);xa_erase (&cla_domains, domain->id);kfree (domain);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH v1 7/8] misc/arm-cla: Manage domain contexts
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [Critical] Active hardware context and registers are freed when a domain is broken, allowing hardware to…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] Active hardware context and registers are freed when a domain is broken, allowing hardware to DMA into freed memory.
- [High] Unsafe VMA iteration in cla_domain_zap() without holding an active mm reference, leading to use-after-free.
- [High] Domain context switch silently skips devices with offline CPUs instead of failing, leading to broken context isolation.
- [High] A CLA device coming online via CPU hotplug fails to restore the domain's currently assigned context.
- [Medium] Missing format string argument for %u when creating the per-device kthread worker.
--
--- Patch [7]: [RFC PATCH v1 7/8] misc/arm-cla: Manage domain contexts --- commit 62c539a6d69f0f095ec0d6a00c78d57199599362
Author: Ryan Roberts <[email protected]>
Subject: misc/arm-cla: Manage domain contexts
A CLA domain cannot be used by multiple address spaces concurrently. This commit introduces context tracking and scheduling for CLA domains, running hardware operations via kthread workers.
Quoted 4 lines
drivers/misc/arm-cla/cla-init.c +0
-0
[ ... ]
drivers/misc/arm-cla/cla-init.c static void cla_dev_reinit(struct cla_dev *dev) · line 179
Quoted 9 lines
drivers/misc/arm-cla/cla-init.c +5
-0@@ -171,6 +172,46 @@ static void cla_dev_reinit(struct cla_dev *dev)cla_reg_write (dev,CLA_REG_LRESP ,0 ); } +static int cla_dev_worker_init (struct cla_dev *dev,int cpu) +{ +struct kthread_worker *worker; + + worker =kthread_run_worker_on_cpu (cpu,0 ,"cla-dev-worker/%u" );
[Severity: Medium]
Is it possible this leaks uninitialized memory to user-space? The string "cla-dev-worker/%u" expects an integer argument, but the wrapper macro kthread_run_worker_on_cpu() only takes the name format and does not forward arguments to the underlying kthread_create_worker_on_cpu() function. Will this cause vsnprintf() to consume a random stack slot or register for the thread name?
Quoted 3 lines
drivers/misc/arm-cla/cla-init.c +3
-0+if (IS_ERR (worker)) +return PTR_ERR (worker); +
[ ... ]
drivers/misc/arm-cla/cla-init.c static int cla_dev_setup(unsigned int cpu) · line 275
Quoted 9 lines
drivers/misc/arm-cla/cla-init.c +5
-0@@ -227,6 +268,10 @@ static int cla_dev_setup(unsigned int cpu) dev->accelerators); } + ret =cla_dev_worker_init (dev, cpu); +if (ret) + goto err; + +return 0 ;
[Severity: High]
When a CPU is hotplugged back online, will this setup path leave the hardware out of sync with the domain?
It initializes the worker but does not appear to check domain->assigned_ctx or queue work to restore the active context to the hardware. If the domain only has one active context, a subsequent reassignment will abort in cla_domain_reassign() because next_ctx and prev_ctx evaluate to NULL. Can this permanently bypass context restoration and cause memory faults?
Quoted 7 lines
drivers/misc/arm-cla/cla-init.c +0
-0err:cla_dev_reinit (dev);drivers/misc/arm-cla/cla-sched.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/misc/arm-cla/cla-sched.c new file +4
-0+static int __cla_domain_switch_ctx (struct cla_domain *domain, +struct cla_ctx *prev_ctx, +struct cla_ctx *next_ctx) +{
[ ... ]
drivers/misc/arm-cla/cla-sched.c line 44
Quoted 13 lines
drivers/misc/arm-cla/cla-sched.c new file +13
-0+for (i =0 ; i < domain->nr_devs; i++) { + dev = domain->devs[i]; + call = &dev->call; + + call->sched.prev_ctx = prev_ctx; + call->sched.next_ctx = next_ctx; + call->sched.ctx_id = i; + call->ret =0 ; + +mutex_lock (&dev->lock); +if (dev->worker && !dev->broken) +kthread_queue_work (dev->worker, &call->switch_ctx); +mutex_unlock (&dev->lock);
[Severity: High]
If dev->worker is NULL because the CPU is offline, does this silently bypass the context switch for that device?
Since call->ret is initialized to 0 and there is no else branch to return an error, the domain switch will complete and report success. When the CPU comes back online, could the device retain a stale context and break isolation?
Quoted 1 line
drivers/misc/arm-cla/cla-sched.c new file +1
-0+ }
[ ... ]
Quoted 9 lines
drivers/misc/arm-cla/cla-sched.c new file +9
-0+static void cla_domain_zap (struct cla_domain *domain,struct cla_ctx *ctx) +{ +struct vm_area_struct *vma; +struct vma_iterator vmi; + +/* +* If the context is dying it has already been unmapped, no need to zap +* it here. +*/
drivers/misc/arm-cla/cla-sched.c line 228
Quoted 10 lines
drivers/misc/arm-cla/cla-sched.c new file +10
-0+if (!ctx ||cla_ctx_is_dying (ctx)) +return ; + +/* +* Iterate over vmas in prev_ctx's mm, looking for vmas that map +* prev_ctx's file. Zap any portions of those vmas that map the domain. +*/ +mmap_read_lock (ctx->key.mm); +vma_iter_init (&vmi, ctx->key.mm,0 ); +for_each_vma (vmi, vma) {
[Severity: High]
Is it safe to acquire the mmap_read_lock() and iterate the maple tree here without an active mm reference?
The context only holds a passive mmgrab() reference. If a concurrent unprivileged userspace process exits, mm_users could drop to 0, and exit_mmap() might tear down the VMA maple tree. Should this code use mmget_not_zero() to prevent a use-after-free while walking the tree?
Quoted 2 lines
drivers/misc/arm-cla/cla-sched.c new file +2
-0+if (vma->vm_file != ctx->key.file) +continue ;
[ ... ]
drivers/misc/arm-cla/cla-sched.c line 321
Quoted 12 lines
drivers/misc/arm-cla/cla-sched.c new file +12
-0+static void cla_domain_reclaim (struct kthread_work *work) +{ +struct cla_domain *domain; +struct cla_ctx *ctx, *next; + + domain = container_of(work, struct cla_domain, reclaim.work); + +mutex_lock (&domain->lock); +list_for_each_entry_safe (ctx, next, &domain->dying_ctxs, queue_node) { +list_del_init (&ctx->queue_node); +WARN_ON (domain->assigned_ctx == ctx); +cla_ctx_put (ctx);
[Severity: Critical]
If a domain becomes broken, is it possible for the active hardware context to be freed while still programmed in the device?
In cla_domain_schedule_reassignment(), the reassign work is skipped if the domain is broken, meaning the context is never uninstalled from the hardware. Then here in cla_domain_reclaim(), the dying context is unconditionally freed by calling cla_ctx_put(), which drops the PGD and software state.
Will this allow the broken hardware to perform page walks into freed and reallocated memory?
Quoted 3 lines
drivers/misc/arm-cla/cla-sched.c new file +3
-0+ } +mutex_unlock (&domain->lock); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [RFC PATCH v1 7/8] misc/arm-cla: Manage domain contexts
Quoted 7 lines · On Fri, Jul 17, 2026 at 11:01:14AM +0000, [email protected] wrote:
drivers/misc/arm-cla/cla-init.c static void cla_dev_reinit(struct cla_dev *dev) · line 179
Quoted 1 line
drivers/misc/arm-cla/cla-init.c +1
-0+ worker =kthread_run_worker_on_cpu (cpu,0 ,"cla-dev-worker/%u" );[Severity: Medium]
Is it possible this leaks uninitialized memory to user-space? The string "cla-dev-worker/%u" expects an integer argument, but the wrapper macrokthread_run_worker_on_cpu()only takes the name format and does not forward arguments to the underlyingkthread_create_worker_on_cpu()function.
kthread_create_worker_on_cpu() adds the cpu number
Quoted 3 lines
[Severity: High]
When a CPU is hotplugged back online, will this setup path leave the hardware out of sync with the domain?
Yes save/restore on CPUHP will be added later
Quoted 9 lines
Quoted 9 lines
drivers/misc/arm-cla/cla-sched.c new file +9
-0+for (i =0 ; i < domain->nr_devs; i++) { + dev = domain->devs[i]; + call = &dev->call; + + call->sched.prev_ctx = prev_ctx; + call->sched.next_ctx = next_ctx; + call->sched.ctx_id = i; + call->ret =0 ; +
Quoted 8 lines
drivers/misc/arm-cla/cla-sched.c line 44
Quoted 4 lines
drivers/misc/arm-cla/cla-sched.c new file +4
-0+mutex_lock (&dev->lock); +if (dev->worker && !dev->broken) +kthread_queue_work (dev->worker, &call->switch_ctx); +mutex_unlock (&dev->lock);[Severity: High]
Ifdev->workeris NULL because the CPU is offline, does this silently bypass the context switch for that device?
Context cannot be switched on an offline CPU
Quoted 24 lines
Quoted 9 lines
drivers/misc/arm-cla/cla-sched.c new file +9
-0+static void cla_domain_zap (struct cla_domain *domain,struct cla_ctx *ctx) +{ +struct vm_area_struct *vma; +struct vma_iterator vmi; + +/* +* If the context is dying it has already been unmapped, no need to zap +* it here. +*/ drivers/misc/arm-cla/cla-sched.c line 228
Quoted 10 lines
drivers/misc/arm-cla/cla-sched.c new file +10
-0+if (!ctx ||cla_ctx_is_dying (ctx)) +return ; + +/* +* Iterate over vmas in prev_ctx's mm, looking for vmas that map +* prev_ctx's file. Zap any portions of those vmas that map the domain. +*/ +mmap_read_lock (ctx->key.mm); +vma_iter_init (&vmi, ctx->key.mm,0 ); +for_each_vma (vmi, vma) {[Severity: High]
Is it safe to acquire themmap_read_lock()and iterate the maple tree here without an active mm reference?
Quoted 4 lines
The context only holds a passive
mmgrab()reference. If a concurrent unprivileged userspace process exits,mm_userscould drop to 0, andexit_mmap()might tear down the VMA maple tree. Should this code usemmget_not_zero()to prevent a use-after-free while walking the tree?
Yes probably
Quoted 17 lines
drivers/misc/arm-cla/cla-sched.c line 321
Quoted 12 lines
drivers/misc/arm-cla/cla-sched.c new file +12
-0+static void cla_domain_reclaim (struct kthread_work *work) +{ +struct cla_domain *domain; +struct cla_ctx *ctx, *next; + + domain = container_of(work, struct cla_domain, reclaim.work); + +mutex_lock (&domain->lock); +list_for_each_entry_safe (ctx, next, &domain->dying_ctxs, queue_node) { +list_del_init (&ctx->queue_node); +WARN_ON (domain->assigned_ctx == ctx); +cla_ctx_put (ctx);[Severity: Critical]
If a domain becomes broken, is it possible for the active hardware context to be freed while still programmed in the device?
Quoted 4 lines
In
cla_domain_schedule_reassignment(), the reassign work is skipped if the domain is broken, meaning the context is never uninstalled from the hardware. Then here incla_domain_reclaim(), the dying context is unconditionally freed by callingcla_ctx_put(), which drops the PGD and software state.
No, a reference to the mm is kept
RFC PATCH 8/8 misc/arm-cla: Add userspace interface
In reply to Ryan RobertsExpose CLA devices through a character device so userspace can enumerate the available hardware and map accelerator register frames.
Define version 1 of the CLA UAPI with a GET_PARAM ioctl. Report device topology, CPU affinity, domain membership, mmap offsets, architecture version and attached accelerator masks, together with the IIDR, DEVARCH and REVIDR of each accelerator.
CLA registers can only be read from the CPU local to the device, while enumeration may occur on any CPU. Validate the supported CLA architecture version during device setup and cache the CLA and accelerator identification registers for later ioctl queries.
Support shared read-write mmap of one or more CLA register pages. Create a context for every domain covered by the mapping and resolve faults only while that context owns the domain. Queue unassigned contexts with the domain scheduler, drop mmap_lock while waiting for assignment and retry the fault after the context is woken.
--- drivers/misc/arm-cla/Makefile | 3 +- drivers/misc/arm-cla/arm-cla-regs.h | 2 + drivers/misc/arm-cla/arm-cla.h | 13 ++ drivers/misc/arm-cla/cla-init.c | 26 +++ drivers/misc/arm-cla/cla-user.c | 351 ++++++++++++++++++++++++++++ include/uapi/linux/arm-cla.h | 207 ++++++++++++++++ 6 files changed, 601 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/arm-cla/cla-user.c create mode 100644 include/uapi/linux/arm-cla.h
drivers/misc/arm-cla/Makefile +2 -1
@@ -7,6 +7,7 @@ arm-cla-y := \ cla-ops.o \ cla-regs.o \ cla-sched.o \ - cla-topology.o + cla-topology.o \ + cla-user.o obj-$(CONFIG_ARM_CLA) += arm-cla.o
drivers/misc/arm-cla/arm-cla-regs.h +2 -0
@@ -63,6 +63,8 @@ CLA_STATUS_EXCEPT | \ CLA_STATUS_SRMODE) +#define CLA_AAIDR_1_0 (1ULL << 8) +/* Standard accelerator registers */ #define CLA_REG_IIDR 0x0000#define CLA_REG_DEVARCH 0x0001
drivers/misc/arm-cla/arm-cla.h +13 -0
@@ -45,6 +45,12 @@ struct cla_call_on_cpu {struct kthread_work switch_ctx; }; +struct cla_accel_desc { +u64 iidr; +u64 devarch; +u64 revidr; +}; +/** * struct cla_dev - CLA device *
@@ -57,6 +63,8 @@ struct cla_call_on_cpu {* @pg_offset: Mmap offset of this device. * @iassizes: Combined regstate of all accels. * @domain: The domain this CLA belongs to. +* @aidr: CLA Architecture ID. +* @accel_descs: Accelerator ID registers. * * Mutable, only accessed under @lock: * @lock: Protects the following members.
@@ -74,6 +82,8 @@ struct cla_dev {unsigned long pg_offset;unsigned long iassizes;struct cla_domain *domain; +u64 aidr; +struct cla_accel_desc accel_descs[CLA_NUM_ACC ];struct mutex lock;bool broken;
@@ -280,4 +290,7 @@ int cla_mtc_clear(struct cla_dev *dev);int cla_mtc_install (struct cla_dev *dev,pgd_t *pgd,unsigned long asid);int cla_mtc_uninstall (struct cla_dev *dev); +int cla_user_init (void ); +void cla_user_exit (void ); +#endif /* _ARM_CLA_H_ */
drivers/misc/arm-cla/cla-init.c +26 -0
@@ -80,6 +80,7 @@ static int cla_reset_pmu(struct cla_dev *dev, unsigned int accid)*/ static int cla_dev_setup_accel (struct cla_dev *dev,unsigned int accid) { +struct cla_accel_desc *desc = &dev->accel_descs[accid];u64 status;u64 iassize;u64 acap;
@@ -122,6 +123,20 @@ static int cla_dev_setup_accel(struct cla_dev *dev, unsigned int accid)return 1 ; } +/* +* Cache some standard accelerator registers that user space may query +* via ioctl from a remote CPU. +*/ + ret =cla_op_regread (dev, accid,CLA_REG_IIDR ,1 , &desc->iidr); +if (ret) +return ret; + ret =cla_op_regread (dev, accid,CLA_REG_DEVARCH ,1 , &desc->devarch); +if (ret) +return ret; + ret =cla_op_regread (dev, accid,CLA_REG_REVIDR ,1 , &desc->revidr); +if (ret) +return ret; + ret =cla_op_regread (dev, accid,CLA_REG_IASSIZE ,1 , &iassize);if (ret)return ret;
@@ -234,6 +249,10 @@ static int cla_dev_setup(unsigned int cpu)if (WARN_ON (smp_processor_id () != cpu || dev->cpu != cpu))return -EINVAL ; + dev->aidr =cla_reg_read (dev,CLA_REG_CLAAIDR ); +if (dev->aidr !=CLA_AAIDR_1_0 ) +return -EPROTONOSUPPORT ; +/* Clear DATA and LRESP_DATANZ */ for (i =0 ; i <CLA_NUM_DATA_REGS ; i++)cla_reg_write (dev,CLA_REG_DATA (i),0 );
@@ -453,8 +472,14 @@ static int __init cla_module_init(void) } cla_cpuhp_state = ret; + ret =cla_user_init (); +if (ret) + goto err_cpuhp_remove; +return 0 ; +err_cpuhp_remove: +cpuhp_remove_state (cla_cpuhp_state); err_driver_unregister:platform_driver_unregister (&cla_driver); err_domains_free:
@@ -464,6 +489,7 @@ static int __init cla_module_init(void) static void __exit cla_module_exit(void) { +cla_user_exit ();cpuhp_remove_state (cla_cpuhp_state);platform_driver_unregister (&cla_driver);cla_domains_free ();
drivers/misc/arm-cla/cla-user.c new file +351 -0
351 lines not on this page · raw message
include/uapi/linux/arm-cla.h new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] cla_vma_fault() unconditionally assumes FAULT_FLAG_ALLOW_RETRY is set, triggering a WARN_ON and…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] cla_vma_fault() unconditionally assumes FAULT_FLAG_ALLOW_RETRY is set, triggering a WARN_ON and SIGBUS during normal per-VMA lock faults.
- [High] cla_vma_open() silently ignores errors from cla_ctx_map(), leading to a context refcount imbalance and a deterministic NULL pointer dereference.
- [Medium] Concurrent ioctl queries race with CPU hotplug device setup, leaking uninitialized or partially updated accelerator descriptors to userspace. --
--- Patch [8]: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface --- commit 5559b4038bdef30d19e3f3c9904b6bfa29dc03ab
Author: Ryan Roberts <[email protected]>
Subject: misc/arm-cla: Add userspace interface
This commit adds a character device interface for the Arm CLA driver, allowing userspace to enumerate hardware and map accelerator register frames. It defines version 1 of the UAPI with a GET_PARAM ioctl for querying device telemetry. Additionally, it implements shared read-write mmap support for CLA register pages, utilizing a domain scheduler to resolve faults.
Quoted 5 lines
drivers/misc/arm-cla/cla-user.c new file +0
-0
[ ... ]
Quoted 1 line
drivers/misc/arm-cla/cla-user.c new file +0
-0@@ -0,0 +1,351 @@
[ ... ]
Quoted 2 lines
drivers/misc/arm-cla/cla-user.c new file +2
-0+static long cla_ioctl_get_param (unsigned long arg) +{
[ ... ]
drivers/misc/arm-cla/cla-user.c line 111
Quoted 5 lines
drivers/misc/arm-cla/cla-user.c new file +5
-0+case ARM_CLA_PARAM_DEV_ACCELS : + param.value = cla_lut_pg[dev_id]->accelerators; +break ; +case ARM_CLA_PARAM_ACCEL_IIDR : + param.value = cla_lut_pg[dev_id]->accel_descs[accel_id].iidr;
[Severity: Medium]
Can concurrent ioctl queries race with CPU hotplug device setup here?
During CPU hotplug, cla_dev_setup() calls cla_dev_setup_accel() which modifies accel_descs fields without holding dev->lock.
Concurrently, userspace can invoke this ioctl and read these fields without any locks or memory barriers.
Because there is no synchronization, could an out-of-order read see the dev->accelerators bit set before the corresponding accel_descs fields are visible, returning uninitialized or stale telemetry data to userspace?
Quoted 4 lines
drivers/misc/arm-cla/cla-user.c new file +4
-0+break ; +case ARM_CLA_PARAM_ACCEL_DEVARCH : + param.value = cla_lut_pg[dev_id]->accel_descs[accel_id].devarch; +break ;
[ ... ]
drivers/misc/arm-cla/cla-user.c line 139
Quoted 13 lines
drivers/misc/arm-cla/cla-user.c new file +13
-0+static void cla_vma_open (struct vm_area_struct *vma) +{ +/* +* A vma previously created with cla_file_mmap() has been duplicated +* within the same mm (most likely due to mremap). While this could also +* be called for duplication into a new mm (via fork), we set +* VM_DONTCOPY on the original mmap, so this will never happen. So the +* contexts covered by this new vma already exist. +*/ +struct cla_domain *domain; + +cla_for_each_mapped_domain (vma, domain) +cla_ctx_map (domain, vma->vm_mm, vma->vm_file);
[Severity: High]
Does this code need to check the return value of cla_ctx_map()?
If a VMA is duplicated (e.g., via mremap with MREMAP_MAYMOVE) and the domain is in a broken state, cla_ctx_map() will return ERR_PTR(-EIO) without incrementing the context refcount.
Because cla_vma_open() silently ignores this error, the refcount remains unbalanced. When the old VMA is subsequently closed, cla_ctx_unmap() drops the refcount to zero and frees the context.
When the new VMA is closed, cla_ctx_unmap() will fail to find the context:
drivers/misc/arm-cla/cla-ctx.c:cla_ctx_unmap() {
...
ctx = cla_domain_lookup_ctx(domain, mm, file);
WARN_ON(!ctx);
if (!refcount_dec_and_test(&ctx->mapped)) {
...
}Could this lead to an unconditional NULL pointer dereference of ctx?
Quoted 3 lines
drivers/misc/arm-cla/cla-user.c new file +3
-0+} + +static void cla_vma_close (struct vm_area_struct *vma)
[ ... ]
Quoted 7 lines
drivers/misc/arm-cla/cla-user.c new file +7
-0+static vm_fault_t cla_vma_fault (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma; +struct cla_domain *domain; +struct cla_dev *dev; +struct cla_ctx *ctx; +unsigned long pg;
drivers/misc/arm-cla/cla-user.c line 167
Quoted 10 lines
drivers/misc/arm-cla/cla-user.c new file +10
-0+ +/* +* Reassignment needs mmap_lock, so we cannot wait while holding it. +* Luckily, this flag is only missing in some exotic cases which do not +* apply for this VM_IO | VM_PFNMAP vma. i.e. GUP without +* FOLL_UNLOCKABLE or FOLL_NOWAIT or fixup_user_fault(unlocked=NULL), +* used by futex fault-in path. +*/ +if (WARN_ON (!(vmf->flags &FAULT_FLAG_ALLOW_RETRY ))) +return VM_FAULT_SIGBUS ;
[Severity: High]
Is it safe to unconditionally assume FAULT_FLAG_ALLOW_RETRY is set here?
Under the per-VMA lock fault path (which is the default for modern kernels), FAULT_FLAG_VMA_LOCK is set but FAULT_FLAG_ALLOW_RETRY is explicitly absent.
Consequently, any normal page fault handled under the VMA lock will hit this branch, returning VM_FAULT_SIGBUS and breaking normal memory access.
Additionally, because this is user-controllable, could the WARN_ON allow an unprivileged local attacker to spam the kernel log or crash the system if panic_on_warn is enabled?
Quoted 3 lines
drivers/misc/arm-cla/cla-user.c new file +3
-0+ + pg = vma->vm_pgoff + ((vmf->address - vma->vm_start) >>PAGE_SHIFT ); + dev = cla_lut_pg[pg];
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface
Quoted 17 lines · On Fri, Jul 17, 2026 at 11:10:15AM +0000, [email protected] wrote:
drivers/misc/arm-cla/cla-user.c line 139
Quoted 13 lines
drivers/misc/arm-cla/cla-user.c new file +13
-0+static void cla_vma_open (struct vm_area_struct *vma) +{ +/* +* A vma previously created with cla_file_mmap() has been duplicated +* within the same mm (most likely due to mremap). While this could also +* be called for duplication into a new mm (via fork), we set +* VM_DONTCOPY on the original mmap, so this will never happen. So the +* contexts covered by this new vma already exist. +*/ +struct cla_domain *domain; + +cla_for_each_mapped_domain (vma, domain) +cla_ctx_map (domain, vma->vm_mm, vma->vm_file);[Severity: High]
Does this code need to check the return value ofcla_ctx_map()?
Quoted 7 lines
If a VMA is duplicated (e.g., via mremap with
MREMAP_MAYMOVE) and the domain is in a broken state,cla_ctx_map()will returnERR_PTR(-EIO)without incrementing the context refcount.Because
cla_vma_open()silently ignores this error, the refcount remains unbalanced. When the old VMA is subsequently closed,cla_ctx_unmap()drops the refcount to zero and frees the context.
I think it wouldn't hurt to move the domain->broken check after cla_domain_lookup_ctx()
Quoted 12 lines
Quoted 12 lines
drivers/misc/arm-cla/cla-user.c new file +12
-0+static vm_fault_t cla_vma_fault (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma; +struct cla_domain *domain; +struct cla_dev *dev; +struct cla_ctx *ctx; +unsigned long pg; + +/* +* Reassignment needs mmap_lock, so we cannot wait while holding it. +* Luckily, this flag is only missing in some exotic cases which do not +* apply for this VM_IO | VM_PFNMAP vma. i.e. GUP without
Quoted 8 lines
drivers/misc/arm-cla/cla-user.c line 167
Quoted 5 lines
drivers/misc/arm-cla/cla-user.c new file +5
-0+* FOLL_UNLOCKABLE or FOLL_NOWAIT or fixup_user_fault(unlocked=NULL), +* used by futex fault-in path. +*/ +if (WARN_ON (!(vmf->flags &FAULT_FLAG_ALLOW_RETRY ))) +return VM_FAULT_SIGBUS ;[Severity: High]
Is it safe to unconditionally assumeFAULT_FLAG_ALLOW_RETRYis set here?
I'll have a look myself at some point, but the experts say it is fine.
Quoted 9 lines
Under the per-VMA lock fault path (which is the default for modern kernels),
FAULT_FLAG_VMA_LOCKis set butFAULT_FLAG_ALLOW_RETRYis explicitly absent.Consequently, any normal page fault handled under the VMA lock will hit this branch, returning
VM_FAULT_SIGBUSand breaking normal memory access.Additionally, because this is user-controllable, could the
WARN_ONallow an unprivileged local attacker to spam the kernel log or crash the system ifpanic_on_warnis enabled?
Arnd Bergmann
maintainerRe: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface
In reply to Ryan RobertsQuoted 8 lines · Ryan Roberts
Expose CLA devices through a character device so userspace can enumerate the available hardware and map accelerator register frames.
Define version 1 of the CLA UAPI with a
GET_PARAMioctl. Report device topology, CPU affinity, domain membership, mmap offsets, architecture version and attached accelerator masks, together with the IIDR, DEVARCH and REVIDR of each accelerator.
Quoted 4 lines
CLA registers can only be read from the CPU local to the device, while enumeration may occur on any CPU. Validate the supported CLA architecture version during device setup and cache the CLA and accelerator identification registers for later ioctl queries.
This interface looks very raw at the moment, I expect this will have one or more larger redesigns.
Most importantly, a single character device to expose an arbitrary number of underlying hardware features is an inherently flawed security model. If any specific accelerator is ever found to have a major vulnerability, that would mean administrators will have to disable all of them by default.
Quoted 5 lines
Support shared read-write mmap of one or more CLA register pages. Create a context for every domain covered by the mapping and resolve faults only while that context owns the domain. Queue unassigned contexts with the domain scheduler, drop
mmap_lockwhile waiting for assignment and retry the fault after the context is woken.
I still need some time to better understand what this means. Does a CPU have multiple concurrently running contexts? Is a user process able to starve the allocation of other processes by just requesting a lot of them?
Quoted 7 lines
drivers/misc/arm-cla/cla-user.c new file +7
-0+static long cla_ioctl_get_param (unsigned long arg) +{ +struct arm_cla_param __user *uparam = (void __user *)arg; +struct arm_cla_param param; +int accel_id; +int dev_id; +int ret;
drivers/misc/arm-cla/cla-user.c line 86
Quoted 10 lines
drivers/misc/arm-cla/cla-user.c new file +10
-0+ +if (copy_from_user (¶m, uparam,sizeof (param))) +return -EFAULT ; + + ret =cla_ioctl_validate_param (¶m); +if (ret) +return ret; + + dev_id =dev_nospec (ARM_CLA_PARAM_INDEX_DEV (param.index)); + accel_id =accel_nospec (ARM_CLA_PARAM_INDEX_ACCEL (param.index));
Why is the dev_id/accel_id not a property of the device node itself?
drivers/misc/arm-cla/cla-user.c line 91
Quoted 4 lines
drivers/misc/arm-cla/cla-user.c new file +4
-0+switch (param.param) { +case ARM_CLA_PARAM_UABI_VERSION : + param.value =ARM_CLA_UABI_VERSION ; +break ;
UABI definitions are not versioned, you have to stay compatible indefinitely. If you need something else, add a new command.
drivers/misc/arm-cla/cla-user.c line 218
Quoted 4 lines
drivers/misc/arm-cla/cla-user.c new file +4
-0+wait_event_interruptible (ctx->waitq, +READ_ONCE (domain->assigned_ctx) == ctx || +cla_ctx_is_dying (ctx) || +READ_ONCE (domain->broken));
If you call wait_event_interruptible(), you have to check the return code and deal with it being interrupted.
drivers/misc/arm-cla/cla-user.c line 307
Quoted 7 lines
drivers/misc/arm-cla/cla-user.c new file +7
-0+static const struct file_operations cla_fops = { + .owner =THIS_MODULE , + .mmap = cla_file_mmap, + .unlocked_ioctl = cla_file_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = cla_file_ioctl, +#endif
No need for the #ifdef here. Technically setting .compat_ioctl=compat_ptr_ioctl is the correct way here, though that may change in the future now that s390 compat mode is gone.
Arnd
Re: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · Ryan Roberts
Expose CLA devices through a character device so userspace can enumerate the available hardware and map accelerator register frames.
Define version 1 of the CLA UAPI with a
GET_PARAMioctl. Report device topology, CPU affinity, domain membership, mmap offsets, architecture version and attached accelerator masks, together with the IIDR, DEVARCH and REVIDR of each accelerator.
Quoted 7 lines
Quoted 4 lines
CLA registers can only be read from the CPU local to the device, while enumeration may occur on any CPU. Validate the supported CLA architecture version during device setup and cache the CLA and accelerator identification registers for later ioctl queries.
This interface looks very raw at the moment, I expect this will have one or more larger redesigns.
Are you referring to the overall UABI or specifically to the ioctl interface here? I could imagine the ioctl interface evolving before we get this merged (although it is based on similar patterns used by some DRM and accel drivers - it's intended to be easily extensible while existing params remain stable).
The aspect where the CLA MMIO is directly mapped into user space is an aspect we are keen to keep though since it has significant performance implications if we need to redirect through the kernel.
Quoted 6 lines
Most importantly, a single character device to expose an arbitrary number of underlying hardware features is an inherently flawed security model. If any specific accelerator is ever found to have a major vulnerability, that would mean administrators will have to disable all of them by default.
Note that we are exposing MMIO per CLA, not per accelerator. So preventing access to a single CLA would prevent access to all accelerators attached to it. There is a per-accelerator availability masking control that the kernel can use to disable access to selected accelerators though, which might help with the vulnerability example.
The rationale for choosing a single device file was driven by performance: At domain reassignment time, we need to unmap and invalidate the TLB entries for all the devices in the domain from the out-going process's address space. By having all the devices in a single file and all devices within the same domain adjacent, they can all be mapped to a single VMA, meaning the driver can use a single call to the existing zap_special_vma_range(), which will result in a single TLBI-by-range instruction, which is faster than a TLBI-by-va for every device.
If you think it is important for security to have each CLA exposed by an independent device file, I'll take another look.
Quoted 8 lines
Quoted 6 lines
Support shared read-write mmap of one or more CLA register pages. Create a context for every domain covered by the mapping and resolve faults only while that context owns the domain. Queue unassigned contexts with the domain scheduler, drop
mmap_lockwhile waiting for assignment and retry the fault after the context is woken.I still need some time to better understand what this means.
I can probably do a better job of explaining this: The kernel keeps a cla_ctx object which represents a single {file description, mm_struct} context that wants to use the cla_domain (collection of 1 or more cla_dev). Initially the VMA is not populated so when user space tries to access, it will fault to the driver. If the cla_domain is assigned to a different cla_ctx, the faulting thread is put to sleep until the driver determines that it's the turn of that cla_ctx to be assigned the domain. At that point the waiting thread(s) are woken and map the devices from the domain to the VMA and return to user space. The out-going cla_ctx had it's mappings removed during the reassignment process so any user space access will now fault and sleep waiting for assignment.
Quoted 1 line
Does a CPU have multiple concurrently running contexts?
The HW only has a single HW context, hence the timesliced assignment approach described above (assuming there is more than 1 concurrent user).
Quoted 3 lines
Is a
user process able to starve the allocation of other processes by just requesting a lot of them?
In the current code, a process can theoretically create the same number of cla_ctx as the number of file descriptors it can open(). It would then need to mmap and access to get into the queue to be assigned the domain. I see it as similar to threads; if process A creates 10 threads and process B creates 1 thread, then in the long run (ignoring cgroups et al) you'd expect A to get 10/11th of the CPU time (IIUC?).
Do you think this consitutes a DoS?
Quoted 12 lines
Quoted 12 lines
drivers/misc/arm-cla/cla-user.c new file +11
-0+static long cla_ioctl_get_param (unsigned long arg) +{ +struct arm_cla_param __user *uparam = (void __user *)arg; +struct arm_cla_param param; +int accel_id; +int dev_id; +int ret; + +if (copy_from_user (¶m, uparam,sizeof (param))) +return -EFAULT ; +
Quoted 8 lines
drivers/misc/arm-cla/cla-user.c line 86
Quoted 6 lines
drivers/misc/arm-cla/cla-user.c new file +6
-0+ ret =cla_ioctl_validate_param (¶m); +if (ret) +return ret; + + dev_id =dev_nospec (ARM_CLA_PARAM_INDEX_DEV (param.index)); + accel_id =accel_nospec (ARM_CLA_PARAM_INDEX_ACCEL (param.index));Why is the dev_id/accel_id not a property of the device node itself?
As per above, I can go look again at having a device node per CLA device (i.e. one for each CPU that has a CLA). But it doesn't make sense to have a device node per accelerator (a CLA can have up to 8 connected accelerators); there is only a single HW interface.
Quoted 8 lines
drivers/misc/arm-cla/cla-user.c line 91
Quoted 5 lines
drivers/misc/arm-cla/cla-user.c new file +4
-0+switch (param.param) { +case ARM_CLA_PARAM_UABI_VERSION : + param.value =ARM_CLA_UABI_VERSION ; +break ;UABI definitions are not versioned, you have to stay compatible indefinitely. If you need something else, add a new command.
Yes agreed; my mistake - this is used for the internal development versions where the interface has been changing and I forgot to remove it for the RFC.
Quoted 8 lines
drivers/misc/arm-cla/cla-user.c line 218
Quoted 5 lines
drivers/misc/arm-cla/cla-user.c new file +4
-0+wait_event_interruptible (ctx->waitq, +READ_ONCE (domain->assigned_ctx) == ctx || +cla_ctx_is_dying (ctx) || +READ_ONCE (domain->broken));If you call
wait_event_interruptible(), you have to check the return code and deal with it being interrupted.
I believe this is already correct - I'm reeturning VM_FAULT_RETRY unconditionally at this point, which is also the correct return code if we get interrupted. This unwinds to arm64's do_page_fault() which then notices and handles the fault:
/* Quick path to respond to signals */
if (fault_signal_pending(fault, regs)) {
if (!user_mode(regs))
goto no_context;
return 0;
}I believe GUP and other handle_mm_fault() callers have similar logic.
I'll add a comment to make that clear.
Quoted 12 lines
drivers/misc/arm-cla/cla-user.c line 307
Quoted 8 lines
drivers/misc/arm-cla/cla-user.c new file +7
-0+static const struct file_operations cla_fops = { + .owner =THIS_MODULE , + .mmap = cla_file_mmap, + .unlocked_ioctl = cla_file_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = cla_file_ioctl, +#endifNo need for the #ifdef here. Technically setting .compat_ioctl=compat_ptr_ioctl is the correct way here, though that may change in the future now that s390 compat mode is gone.
ACK, I'll fix this.
Thanks,
Ryan
Quoted 2 lines
Arnd
Arnd Bergmann
maintainerRe: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface
Quoted 18 lines · Ryan Roberts
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · Ryan Roberts
Expose CLA devices through a character device so userspace can enumerate the available hardware and map accelerator register frames.
Define version 1 of the CLA UAPI with a
GET_PARAMioctl. Report device topology, CPU affinity, domain membership, mmap offsets, architecture version and attached accelerator masks, together with the IIDR, DEVARCH and REVIDR of each accelerator.Quoted 7 lines
Quoted 4 lines
CLA registers can only be read from the CPU local to the device, while enumeration may occur on any CPU. Validate the supported CLA architecture version during device setup and cache the CLA and accelerator identification registers for later ioctl queries.
This interface looks very raw at the moment, I expect this will have one or more larger redesigns.
Quoted 8 lines
Are you referring to the overall UABI or specifically to the ioctl interface here? I could imagine the ioctl interface evolving before we get this merged (although it is based on similar patterns used by some DRM and accel drivers - it's intended to be easily extensible while existing params remain stable).
The aspect where the CLA MMIO is directly mapped into user space is an aspect we are keen to keep though since it has significant performance implications if we need to redirect through the kernel.
I see no problem with having a per-accelerator VM area for MMIO operations mapped to userspace, this is obviously part of all designs like this one that sneak custom coprocessor instructions in by disguising them as MMIO.
My concern is about how userspace gets to that mapping, both the chardev itself, but also the ioctls.
Quoted 21 lines
Quoted 5 lines
Most importantly, a single character device to expose an arbitrary number of underlying hardware features is an inherently flawed security model. If any specific accelerator is ever found to have a major vulnerability, that would mean administrators will have to disable all of them by default.
Note that we are exposing MMIO per CLA, not per accelerator. So preventing access to a single CLA would prevent access to all accelerators attached to it. There is a per-accelerator availability masking control that the kernel can use to disable access to selected accelerators though, which might help with the vulnerability example.
The rationale for choosing a single device file was driven by performance: At domain reassignment time, we need to unmap and invalidate the TLB entries for all the devices in the domain from the out-going process's address space. By having all the devices in a single file and all devices within the same domain adjacent, they can all be mapped to a single VMA, meaning the driver can use a single call to the existing
zap_special_vma_range(), which will result in a single TLBI-by-range instruction, which is faster than a TLBI-by-va for every device.
Quoted 2 lines
If you think it is important for security to have each CLA exposed by an independent device file, I'll take another look.
Without concrete implementation examples, I find it hard to imagine how granular the CLA and accelerator blocks are. What I'm interested in is separating things into special character devices when they refer to units that you want to manage separately in userspace.
If you have e.g. one accelerator for tensor operations and one for handling gzip, I would very much want to see those have a separate chardev nodes so a local administrator can give permissions to each one separately, and have device names that are sensible to the functionality underneath.
If you have separate accelerators for AES encryption and decryption, or a large set of identical accelerators that can run concurrently, those would of course get managed as a single device file.
Most importantly, I don't think a global /dev/cla device node is a sensible interface from a management perspective as that would give unprivileged userspace direct control to something that is essentially arbitrary (or buggy) vendor firmware with DMA permissions.
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Support shared read-write mmap of one or more CLA register pages. Create a context for every domain covered by the mapping and resolve faults only while that context owns the domain. Queue unassigned contexts with the domain scheduler, drop
mmap_lockwhile waiting for assignment and retry the fault after the context is woken.I still need some time to better understand what this means.
Quoted 10 lines
I can probably do a better job of explaining this: The kernel keeps a
cla_ctxobject which represents a single {file description,mm_struct} context that wants to use thecla_domain(collection of 1 or morecla_dev). Initially the VMA is not populated so when user space tries to access, it will fault to the driver. If thecla_domainis assigned to a differentcla_ctx, the faulting thread is put to sleep until the driver determines that it's the turn of thatcla_ctxto be assigned the domain. At that point the waiting thread(s) are woken and map the devices from the domain to the VMA and return to user space. The out-goingcla_ctxhad it's mappings removed during the reassignment process so any user space access will now fault and sleep waiting for assignment.
Got it, thanks
Quoted 4 lines
Quoted 1 line
Does a CPU have multiple concurrently running contexts?
The HW only has a single HW context, hence the timesliced assignment approach described above (assuming there is more than 1 concurrent user).
Sorry, I think we have a clash of terminology. I meant whether a CPU can start multiple operations on one or more accelerator in a single cla_domain, and have each of those operate at the same time while the hardware is asynchronously processing them in parallel.
It sounds like a single accelerator has one register to wait for completion and can only have single operation in progress at any time, but if multiple accelerators are in the same cla_ctx, can a single thread start an operation in each one before waiting for the first to complete?
Quoted 4 lines
Quoted 3 lines
Is a
user process able to starve the allocation of other processes by just requesting a lot of them?
Quoted 8 lines
In the current code, a process can theoretically create the same number of
cla_ctxas the number of file descriptors it canopen(). It would then need to mmap and access to get into the queue to be assigned the domain. I see it as similar to threads; if process A creates 10 threads and process B creates 1 thread, then in the long run (ignoring cgroups et al) you'd expect A to get 10/11th of the CPU time (IIUC?).Do you think this consitutes a DoS?
I need to think about it more. Probably not a DoS, but if the resource is managed like CPU timeslices, I wonder whether you'd have to also consider things like realtime tasks or priority inversion.
Quoted 13 lines
Quoted 7 lines
drivers/misc/arm-cla/cla-user.c line 218
Quoted 4 lines
drivers/misc/arm-cla/cla-user.c new file +4
-0+wait_event_interruptible (ctx->waitq, +READ_ONCE (domain->assigned_ctx) == ctx || +cla_ctx_is_dying (ctx) || +READ_ONCE (domain->broken));If you call
wait_event_interruptible(), you have to check the return code and deal with it being interrupted.I believe this is already correct - I'm reeturning
VM_FAULT_RETRYunconditionally at this point, which is also the correct return code if we get interrupted. This unwinds to arm64'sdo_page_fault()which then notices and handles the fault:
Quoted 6 lines
/* Quick path to respond to signals */
if (fault_signal_pending(fault, regs)) {
if (!user_mode(regs))
goto no_context;
return 0;
}Ok, makes sense.
Quoted 3 lines
I believe GUP and other
handle_mm_fault()callers have similar logic.I'll add a comment to make that clear.
Thanks
Arnd
Re: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface
Quoted 28 lines · Arnd Bergmann
Quoted 18 lines · Ryan Roberts
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · Ryan Roberts
Expose CLA devices through a character device so userspace can enumerate the available hardware and map accelerator register frames.
Define version 1 of the CLA UAPI with a
GET_PARAMioctl. Report device topology, CPU affinity, domain membership, mmap offsets, architecture version and attached accelerator masks, together with the IIDR, DEVARCH and REVIDR of each accelerator.Quoted 7 lines
Quoted 4 lines
CLA registers can only be read from the CPU local to the device, while enumeration may occur on any CPU. Validate the supported CLA architecture version during device setup and cache the CLA and accelerator identification registers for later ioctl queries.
This interface looks very raw at the moment, I expect this will have one or more larger redesigns.
Quoted 8 lines
Are you referring to the overall UABI or specifically to the ioctl interface here? I could imagine the ioctl interface evolving before we get this merged (although it is based on similar patterns used by some DRM and accel drivers - it's intended to be easily extensible while existing params remain stable).
The aspect where the CLA MMIO is directly mapped into user space is an aspect we are keen to keep though since it has significant performance implications if we need to redirect through the kernel.
Quoted 7 lines
I see no problem with having a per-accelerator VM area for MMIO operations mapped to userspace, this is obviously part of all designs like this one that sneak custom coprocessor instructions in by disguising them as MMIO.
My concern is about how userspace gets to that mapping, both the chardev itself, but also the ioctls.
OK thanks for the clarification.
Quoted 30 lines
Quoted 22 lines
Quoted 6 lines
Most importantly, a single character device to expose an arbitrary number of underlying hardware features is an inherently flawed security model. If any specific accelerator is ever found to have a major vulnerability, that would mean administrators will have to disable all of them by default.
Note that we are exposing MMIO per CLA, not per accelerator. So preventing access to a single CLA would prevent access to all accelerators attached to it. There is a per-accelerator availability masking control that the kernel can use to disable access to selected accelerators though, which might help with the vulnerability example.
The rationale for choosing a single device file was driven by performance: At domain reassignment time, we need to unmap and invalidate the TLB entries for all the devices in the domain from the out-going process's address space. By having all the devices in a single file and all devices within the same domain adjacent, they can all be mapped to a single VMA, meaning the driver can use a single call to the existing
zap_special_vma_range(), which will result in a single TLBI-by-range instruction, which is faster than a TLBI-by-va for every device.Quoted 2 lines
If you think it is important for security to have each CLA exposed by an independent device file, I'll take another look.
Without concrete implementation examples, I find it hard to imagine how granular the CLA and accelerator blocks are. What I'm interested in is separating things into special character devices when they refer to units that you want to manage separately in userspace.
Quoted 5 lines
If you have e.g. one accelerator for tensor operations and one for handling gzip, I would very much want to see those have a separate chardev nodes so a local administrator can give permissions to each one separately, and have device names that are sensible to the functionality underneath.
Unfortunately this doesn't map well to the HW: the MMIO is for the CLA interface (each CPU has 1 CLA). Once you have access to that interface, you can communicate with all of the accelerators that are connected to the CLA. We could potentially use the availability masking control to only expose a single accelerator for a given context (which would be chosen based on which file you opened), but it wouldn't be possible for (e.g.) 2 different processes to access the different accelerators concurrently - they would have to be subject to the time slice model.
I'll think harder about what we might be able to do though.
Quoted 10 lines
If you have separate accelerators for AES encryption and decryption, or a large set of identical accelerators that can run concurrently, those would of course get managed as a single device file.
Most importantly, I don't think a global
/dev/cladevice node is a sensible interface from a management perspective as that would give unprivileged userspace direct control to something that is essentially arbitrary (or buggy) vendor firmware with DMA permissions.
OK I see your point.
While the interface supports up to 8 connected accelerators, we anticpate there only being a single compute accelerator in practice. We decided to keep the driver interface generic given the CLA spec, but perhaps it would be more straightforward to limit the driver implementation to only permitting a single accelerator?
Quoted 33 lines
Quoted 9 lines
Quoted 8 lines
Quoted 6 lines
Support shared read-write mmap of one or more CLA register pages. Create a context for every domain covered by the mapping and resolve faults only while that context owns the domain. Queue unassigned contexts with the domain scheduler, drop
mmap_lockwhile waiting for assignment and retry the fault after the context is woken.I still need some time to better understand what this means.
Quoted 10 lines
I can probably do a better job of explaining this: The kernel keeps a
cla_ctxobject which represents a single {file description,mm_struct} context that wants to use thecla_domain(collection of 1 or morecla_dev). Initially the VMA is not populated so when user space tries to access, it will fault to the driver. If thecla_domainis assigned to a differentcla_ctx, the faulting thread is put to sleep until the driver determines that it's the turn of thatcla_ctxto be assigned the domain. At that point the waiting thread(s) are woken and map the devices from the domain to the VMA and return to user space. The out-goingcla_ctxhad it's mappings removed during the reassignment process so any user space access will now fault and sleep waiting for assignment.Got it, thanks
Quoted 4 lines
Quoted 1 line
Does a CPU have multiple concurrently running contexts?
The HW only has a single HW context, hence the timesliced assignment approach described above (assuming there is more than 1 concurrent user).
Sorry, I think we have a clash of terminology. I meant whether a CPU can start multiple operations on one or more accelerator in a single
cla_domain, and have each of those operate at the same time while the hardware is asynchronously processing them in parallel.
Quoted 5 lines
It sounds like a single accelerator has one register to wait for completion and can only have single operation in progress at any time, but if multiple accelerators are in the same
cla_ctx, can a single thread start an operation in each one before waiting for the first to complete?
CLAs can only be accessed/controlled from their local CPU. The expected model is that you have a thread per CLA (pinned to the CPU) to submit operations only for it's local CLA.
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
Is a
user process able to starve the allocation of other processes by just requesting a lot of them?In the current code, a process can theoretically create the same number of
cla_ctxas the number of file descriptors it canopen(). It would then need to mmap and access to get into the queue to be assigned the domain. I see it as similar to threads; if process A creates 10 threads and process B creates 1 thread, then in the long run (ignoring cgroups et al) you'd expect A to get 10/11th of the CPU time (IIUC?).
Quoted 5 lines
Quoted 1 line
Do you think this consitutes a DoS?
I need to think about it more. Probably not a DoS, but if the resource is managed like CPU timeslices, I wonder whether you'd have to also consider things like realtime tasks or priority inversion.
Yes... we are considering realtime. I was trying not to dump too much into the initial RFC though :)
Thanks,
Ryan
Quoted 30 lines
Quoted 14 lines
Quoted 8 lines
drivers/misc/arm-cla/cla-user.c line 218
Quoted 5 lines
drivers/misc/arm-cla/cla-user.c new file +4
-0+wait_event_interruptible (ctx->waitq, +READ_ONCE (domain->assigned_ctx) == ctx || +cla_ctx_is_dying (ctx) || +READ_ONCE (domain->broken));If you call
wait_event_interruptible(), you have to check the return code and deal with it being interrupted.I believe this is already correct - I'm reeturning
VM_FAULT_RETRYunconditionally at this point, which is also the correct return code if we get interrupted. This unwinds to arm64'sdo_page_fault()which then notices and handles the fault:Quoted 6 lines
/* Quick path to respond to signals */ if (fault_signal_pending(fault, regs)) { if (!user_mode(regs)) goto no_context; return 0; }Ok, makes sense.
Quoted 3 lines
I believe GUP and other
handle_mm_fault()callers have similar logic.I'll add a comment to make that clear.
Thanks
Arnd
Arnd Bergmann
maintainerRe: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface
Quoted 7 lines · Ryan Roberts
Quoted 6 lines · Arnd Bergmann
Without concrete implementation examples, I find it hard to imagine how granular the CLA and accelerator blocks are. What I'm interested in is separating things into special character devices when they refer to units that you want to manage separately in userspace.
Quoted 8 lines
Quoted 5 lines
If you have e.g. one accelerator for tensor operations and one for handling gzip, I would very much want to see those have a separate chardev nodes so a local administrator can give permissions to each one separately, and have device names that are sensible to the functionality underneath.
Unfortunately this doesn't map well to the HW: the MMIO is for the CLA interface (each CPU has 1 CLA).
I'm sure you mentioned it in the documentation, but I missed that there are never multiple CLA instances.
If the CLA is defined only in terms of its MMIO/DMA interface and listening to TLB broadcast operations, is having a single instance actually required by the design, or just an implementation choice?
Quoted 7 lines
Once you have access to that interface, you can
communicate with all of the accelerators that are connected to the CLA. We could potentially use the availability masking control to only expose a single accelerator for a given context (which would be chosen based on which file you opened), but it wouldn't be possible for (e.g.) 2 different processes to access the different accelerators concurrently - they would have to be subject to the time slice model.
Right, that sounds a bit awkward. It sounds like this would also get simpler with a model that ensures the current CLA ttbr0 matches the CPU ttbr0 and the iotlb_mm setting, since you would never have concurrent uses of a single CLA from multipel tasks. On the other hand, that model would make it harder to use multiple accelerators from a single task, if they have to go through multiple file descriptors but could be accessed on a single mapping.
Quoted 10 lines
Quoted 9 lines
If you have separate accelerators for AES encryption and decryption, or a large set of identical accelerators that can run concurrently, those would of course get managed as a single device file.
Most importantly, I don't think a global
/dev/cladevice node is a sensible interface from a management perspective as that would give unprivileged userspace direct control to something that is essentially arbitrary (or buggy) vendor firmware with DMA permissions.
Quoted 7 lines
OK I see your point.
While the interface supports up to 8 connected accelerators, we anticpate there only being a single compute accelerator in practice. We decided to keep the driver interface generic given the CLA spec, but perhaps it would be more straightforward to limit the driver implementation to only permitting a single accelerator?
Probably, yes. From a kernel perspective, I think we're a bit better off with an abstraction like
- One CLA MMIO range per /type/ of accelerator on a given CPU
- One firmware node per CLA, possibly spanning multiple CPUs if the accelerators behind them are shared.
- One character device per firmware node, named according to the type of CLA
- Possibly multiple CLA nodes on a given CPU if multiple unrelated accelerators are present
- optionally multiple related accelerators on the eight ports of a CLA, if that makes sense for that device type
Not sure how far that is off from what you currently have in the hardware design.
Arnd
Re: [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface
Hi Arnd,
Sorry for the delayed response here - I thought I had replied to everything then went off for holiday. Now I'm back and I noticed I missed this...
Quoted 17 lines · Arnd Bergmann
Quoted 7 lines · Ryan Roberts
Quoted 6 lines · Arnd Bergmann
Without concrete implementation examples, I find it hard to imagine how granular the CLA and accelerator blocks are. What I'm interested in is separating things into special character devices when they refer to units that you want to manage separately in userspace.
Quoted 8 lines
Quoted 5 lines
If you have e.g. one accelerator for tensor operations and one for handling gzip, I would very much want to see those have a separate chardev nodes so a local administrator can give permissions to each one separately, and have device names that are sensible to the functionality underneath.
Unfortunately this doesn't map well to the HW: the MMIO is for the CLA interface (each CPU has 1 CLA).
Quoted 7 lines
I'm sure you mentioned it in the documentation, but I missed that there are never multiple CLA instances.
If the CLA is defined only in terms of its MMIO/DMA interface and listening to TLB broadcast operations, is having a single instance actually required by the design, or just an implementation choice?
The CLA spec states that there is 1 CLA per CPU. But there is nothing inherrent about the design that would prevent it from being extended to support multiple CLAs per CPU AFAICT. The approach I've taken in the RFC would naturally work under this (unlikely) possibility.
Quoted 48 lines
Quoted 8 lines
Once you have access to that interface, you can
communicate with all of the accelerators that are connected to the CLA. We could potentially use the availability masking control to only expose a single accelerator for a given context (which would be chosen based on which file you opened), but it wouldn't be possible for (e.g.) 2 different processes to access the different accelerators concurrently - they would have to be subject to the time slice model.Right, that sounds a bit awkward. It sounds like this would also get simpler with a model that ensures the current CLA ttbr0 matches the CPU ttbr0 and the
iotlb_mmsetting, since you would never have concurrent uses of a single CLA from multipel tasks. On the other hand, that model would make it harder to use multiple accelerators from a single task, if they have to go through multiple file descriptors but could be accessed on a single mapping.Quoted 10 lines
Quoted 9 lines
If you have separate accelerators for AES encryption and decryption, or a large set of identical accelerators that can run concurrently, those would of course get managed as a single device file.
Most importantly, I don't think a global
/dev/cladevice node is a sensible interface from a management perspective as that would give unprivileged userspace direct control to something that is essentially arbitrary (or buggy) vendor firmware with DMA permissions.Quoted 7 lines
OK I see your point.
While the interface supports up to 8 connected accelerators, we anticpate there only being a single compute accelerator in practice. We decided to keep the driver interface generic given the CLA spec, but perhaps it would be more straightforward to limit the driver implementation to only permitting a single accelerator?
Probably, yes. From a kernel perspective, I think we're a bit better off with an abstraction like
- One CLA MMIO range per /type/ of accelerator on a given CPU
- One firmware node per CLA, possibly spanning multiple CPUs if the accelerators behind them are shared.
- One character device per firmware node, named according to the type of CLA
- Possibly multiple CLA nodes on a given CPU if multiple unrelated accelerators are present
- optionally multiple related accelerators on the eight ports of a CLA, if that makes sense for that device type
Quoted 2 lines
Not sure how far that is off from what you currently have in the hardware design.
I've spent some time thinking about this today with Jean-Philippe and I believe we have a proposal that addresses your concerns, (although I confess I haven't understood exactly what you mean in all of your above bullets).
I think the aim is to allow a sysadmin to disable a class of accelerators without having to disable any other class of accelerators?
Let's start with an example topology:
- System has 3 CLAs:
- CLA1 has 2 accelerators:
- ACC1: type=compute
- ACC2: type=aes
- CLA2 has 2 accelerators:
- ACC3: type=compute
- ACC4: type=compute
- CLA3 has 1 accelerator:
- ACC5: type=compute
We have 1 char device per accelerator type; so in this case, 2 files:
- compute
- aes
When "compute" is mmap'ed, it will contain 3 CLAs; CLA1, CLA2, CLA3. When queried, it will report that CLA1 has 1 accelerator (ACC1), CLA2 has 2 accelerators (ACC3, ACC4) and CLA3 has 1 accelerator (ACC5). When CLA1, CLA2 and CLA3 are assigned to the process via this context, their availability masks will be set so that ACC2 can't be accessed.
When "aes" is mmap'ed, it will contain 1 CLA; CLA1. When queried, it will report that CLA1 has 1 accelerator (ACC2). When CLA1 is assigned to the process via this context, its availability mask will be set so that ACC1 can't be accessed.
This scheme wouldn't allow different accelerator types to occupy the same context, but that could be addressed in future by adding an operation to allow the user to move an accelerator into a shared context. I don't see a need for this right now though.
In practice, the kernel driver would infer the accelerator type from it's IIDR (and possibly DEVARCH and REVIDR) register(s) and group them based on that.
For a system that only has 1 type of accelerator (the expected common case) we end up with something very similar to what we have in the RFC (a single device file). But for the case where we have multiple accelerator types, a sysadmin can easily disable a specific class of accelerators if found to be buggy.
What do you think?
Thanks,
Ryan
Quoted 2 lines
Arnd
Hi Ryan,
I haven't bothered to look at the code (looks like Sashiko is having fun with that), but I'm going to jump at this bit:
Quoted 6 lines · Ryan Roberts
* User space availability: The kernel driver exposes the capabilities of the hardware to user space. Arm plans to open source a user space driver, but does not yet have any committed date. I'd like to understand if the availability of this component will be a prerequisite for upstream acceptance of the kernel driver; either way, I'm hoping we can at least progress with some discussion in its absence.
From my perspective, I'm not particularly interested in having code in the upstream kernel tree that we can't meaningfully exercise or benefit from. I also think that the incentive for Arm to open source the user-space driver practically disappears if we merge the kernel part first. So, at the moment, this just looks like a burden to me, especially as it appears to create a brand new, device-specific UAPI for what is ostensibly a form of SVA - something which the community is actively working on already.
Relatedly, is there a spec and/or fastmodel/qemu (sorry...) support for this?
Quoted 4 lines
I'm deliberately constraining the scope to bare-metal support for now. Virtualization is something we are considering (and have prototyped), but plan to post a separate RFC for that as follow-up, once we have agreement on direction for the bare-metal driver.
I'd actually like to see what the virtualisation part looks like first because doing it as a bolt-on later feels like the wrong approach. The structure you have at the moment is remarkably clean, given the architectural/CPU interactions (this thing even apparently builds as a module, nice!), but I'm unsure how far you can push the separation once you need to start hacking at KVM. Maybe the MMU notifiers are enough, but I can't tell.
Will
Thanks Will for roping me in.
Quoted 6 lines · Will Deacon
Quoted 5 lines
I'm deliberately constraining the scope to bare-metal support for now. Virtualization is something we are considering (and have prototyped), but plan to post a separate RFC for that as follow-up, once we have agreement on direction for the bare-metal driver.
Quoted 7 lines
I'd actually like to see what the virtualisation part looks like first because doing it as a bolt-on later feels like the wrong approach. The structure you have at the moment is remarkably clean, given the architectural/CPU interactions (this thing even apparently builds as a module, nice!), but I'm unsure how far you can push the separation once you need to start hacking at KVM. Maybe the MMU notifiers are enough, but I can't tell.
+1.
Virtualisation cannot be a "bolt on the side" exercise. It is an integral part of the arm64 tree, particularly for memory management and scheduling, all of which have a direct impact on KVM.
I don't think we can really evaluate anything here without looking at the full picture.
Thanks,
M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
Quoted 1 line · Marc Zyngier
Thanks Will for roping me in.
Sorry - I intentionally didn't include you because last time we spoke you said you were only really interested in discussions on the virt side of things and I didn't want to spam your inbox. Perhaps the wrong decision...
Quoted 17 lines
Quoted 6 lines · Will Deacon
Quoted 5 lines
I'm deliberately constraining the scope to bare-metal support for now. Virtualization is something we are considering (and have prototyped), but plan to post a separate RFC for that as follow-up, once we have agreement on direction for the bare-metal driver.
Quoted 7 lines
I'd actually like to see what the virtualisation part looks like first because doing it as a bolt-on later feels like the wrong approach. The structure you have at the moment is remarkably clean, given the architectural/CPU interactions (this thing even apparently builds as a module, nice!), but I'm unsure how far you can push the separation once you need to start hacking at KVM. Maybe the MMU notifiers are enough, but I can't tell.
Quoted 8 lines
+1.
Virtualisation cannot be a "bolt on the side" exercise. It is an integral part of the arm64 tree, particularly for memory management and scheduling, all of which have a direct impact on KVM.
I don't think we can really evaluate anything here without looking at the full picture.
OK understood - as per reply to Will, we'll prioritise doing a version with virt support.
Thanks,
Ryan
Quoted 5 lines
Thanks,
M.
Quoted 7 lines · Ryan Roberts
Quoted 1 line · Marc Zyngier
Thanks Will for roping me in.
Sorry - I intentionally didn't include you because last time we spoke you said you were only really interested in discussions on the virt side of things and I didn't want to spam your inbox. Perhaps the wrong decision...
I'm indeed mostly interested in the impacts on the KVM side. However, a lot of the decisions that you make on the non-virt side of the kernel have a two-pronged effect:
- both memory management and scheduling changes have a direct impact on KVM because of the intricate weaving of KVM's own MM with the kernel's.
- most of the requirements that you define for bare-metal will have to be enforced by KVM, because it is not conceivable that you'd have a different behaviour between host and guest.
For these reasons, I think it is necessary to involve KVM reviewers from the beginning, rather than after everything has already been set in stone. Unless you say upfront that virtualisation of CLA will never be supported. And even then, you'd have to look into the effects of a CLA user also being a VMM...
And please don't worry about my Inbox ;-).
Thanks,
M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
Hi Will,
Quoted 4 lines · Will Deacon
Hi Ryan,
I haven't bothered to look at the code (looks like Sashiko is having fun with that), but I'm going to jump at this bit:
Thanks for the quick reply!
JP and I had a quick glance at the Sashiko feedback; looks like some useful stuff, and a few false alarms. Nothing cricial though. Not that it matters too much for this stage of discussion.
Quoted 9 lines · Ryan Roberts
Quoted 6 lines
* User space availability: The kernel driver exposes the capabilities of the hardware to user space. Arm plans to open source a user space driver, but does not yet have any committed date. I'd like to understand if the availability of this component will be a prerequisite for upstream acceptance of the kernel driver; either way, I'm hoping we can at least progress with some discussion in its absence.
Quoted 5 lines
From my perspective, I'm not particularly interested in having code in the upstream kernel tree that we can't meaningfully exercise or benefit from. I also think that the incentive for Arm to open source the user-space driver practically disappears if we merge the kernel part first. So, at the moment, this just looks like a burden to me, especially
Understood. Now that I have such a clear statement, hopefully I can use that to work internally to get commitments and dates to build a proper plan. What I'm trying to get out of this RFC though, is "is having an open source user space the main blocker, or are there other significant challenges here too?".
Quoted 6 lines
as it appears to create a brand new, device-specific UAPI for what is ostensibly a form of SVA - something which the community is actively working on already.
Relatedly, is there a spec and/or fastmodel/qemu (sorry...) support for this?
They both exist internally of course. There is a plan to publish the spec, but I don't think we will converge on a timeframe until after the summer now. I'll follow up regarding fastmodel.
Quoted 6 lines
Quoted 5 lines
I'm deliberately constraining the scope to bare-metal support for now. Virtualization is something we are considering (and have prototyped), but plan to post a separate RFC for that as follow-up, once we have agreement on direction for the bare-metal driver.
Quoted 7 lines
I'd actually like to see what the virtualisation part looks like first because doing it as a bolt-on later feels like the wrong approach. The structure you have at the moment is remarkably clean, given the architectural/CPU interactions (this thing even apparently builds as a module, nice!), but I'm unsure how far you can push the separation once you need to start hacking at KVM. Maybe the MMU notifiers are enough, but I can't tell.
The virtualization implementation is not as advanced as bare-metal and JP can probably comment on it in more detail, but the intention is to expose the HW using VFIO-MDEV (mediated device framework). We will need exported functions from (the arm64 part of) KVM to grab the S2 pgdir and to get/put the VMID - we would not be using MMU notifiers but instead sharing the pgtable and VMID and piggybacking the CPU's TBLI operations. My current expectation is that it can be made to work without deep KVM integration and still as a module, but let's see where we get to with the code. (I have spoken with Marc about this briefly - I would say he doesn't love it, but agreed to look at the code when we have it).
But I think I'm hearing that to get into a deeper discussion we will need to post virt support? In which case, I'll prioritise getting something together. I'm about to be on sabbatical for 4 weeks though, so probably won't be until ~early Sept.
Thanks,
Ryan
Quoted 2 lines
Will
Quoted 4 lines · Will Deacon
first. So, at the moment, this just looks like a burden to me, especially as it appears to create a brand new, device-specific UAPI for what is ostensibly a form of SVA - something which the community is actively working on already.
Yeah, I think it was a mistake to hardwire the invalidation to the CPU. It would fit much better into Linux if the invalidation was separate and independently controllable with an option to follow the CPU.
Then you could use a normal S2 page table through iommufd and not mess with kvm. (though the VMID sharing with KVM for a BTM-like scheme was never solved upstream)
I also wouldn't expect you to use vfio-mdev, if the devices are discovered and known at boot then it should be a normal vfio driver.
Jason
Quoted 11 lines · Jason Gunthorpe
Quoted 4 lines · Will Deacon
first. So, at the moment, this just looks like a burden to me, especially as it appears to create a brand new, device-specific UAPI for what is ostensibly a form of SVA - something which the community is actively working on already.
Yeah, I think it was a mistake to hardwire the invalidation to the CPU. It would fit much better into Linux if the invalidation was separate and independently controllable with an option to follow the CPU.
Well I'm certainly not going to disagree, but the HW is somewhat fixed at this point :-|
Quoted 7 lines
Then you could use a normal S2 page table through iommufd and not mess with kvm. (though the VMID sharing with KVM for a BTM-like scheme was never solved upstream)
I also wouldn't expect you to use vfio-mdev, if the devices are discovered and known at boot then it should be a normal vfio driver.
OK good feedback - I'm not going to claim to be a VFIO expert (especially not in front of an actual VFIO expert) - We'll look closer at this and come back if we have questions (although unlikely over the summer holiday).
Thanks,
Ryan
Quoted 2 lines
Jason