Add Allwinner A523 message box and XuanTie E906 remoteproc support
Subsystems (4)
v3 cover Add Allwinner A523 message box and XuanTie E906 remoteproc support
This series adds a driver for the message box of the Allwinner A523, A527 and T527 (sun55i) and a remoteproc driver for their T-Head XuanTie E906 RISC-V core, with bindings, DT nodes and KUnit tests.
v2: https://lore.kernel.org/linux-sunxi/[email protected]/
Changes in v3 (details in each patch):
- Message box: all four banks are clocked and out of reset (an unclocked bank drops writes). The FIFO is drained before its pending bit is cleared, and messages are delivered after the controller lock is dropped. A kick is done once the receiver's FIFO has room; a full FIFO is never written, and in poll mode the check and the write are under one lock. The shared reset is never asserted, as in
sun6i-msgbox: the other banks carry traffic between the other processors. allwinner,tx-done-irq selects the receiver bank's write interrupt instead of the 1 ms poll. OMAP's ti,mbox-send-noirq is the same kind of per-mailbox switch, in the other direction: it turns the TX interrupt off for the WkupM3.
- Remoteproc: one mailbox channel; the receive callback is deferred to an ordered workqueue; address translation covers only the two SRAM windows; debug reset and power domains added; all register regions, clocks and resets are required, the mailbox is optional. Carveouts and crash dump segments are registered in parse_fw(), and crash dumps contain both SRAMs and the carveouts.
- Bindings: fixed lists for reg, clocks, resets and interrupts; "schema" dropped from the subjects (Krzysztof). All four message box interrupts are required: every A523 has them. The DSP and CPUS message box bank addresses were swapped in v2 and are fixed. The SRAMs are named as in the T527 manual (sram-a3-0, sram-a3-1).
- KUnit patches moved after the drivers. Both suites redirect register access with static stubs to mocks, so they run on any architecture, UML included. Patches 6 and 7 only add tests and can be dropped or taken separately.
- Rebased on next-20261030.
Notes for review:
- The remap register (0x07010364, PRCM) is shared with the DSP: bit 1 shares the 512 KiB SRAM A3_2 with the E906's subsystem, bit 0 belongs to the DSP. The driver maps only this register and read-modify-writes bit 1, which is safe while no other Linux driver writes it. I can move it to a syscon or the R-CCU, or describe SRAM A3_2 through the sunxi SRAM driver (allwinner,sram), if preferred.
- memory-region index 0 is the virtio DMA pool, then dram and trace, as in the TI K3 and MediaTek SCP bindings.
- The optional crash interrupt is supported by the driver but not wired in any DT and not tested on hardware; the A523 has no dedicated line for it and the vendor BSP has none.
- System suspend is not supported: the E906 runs next to a Linux that stays up, so the driver has no PM callbacks.
- Merging: patches 1, 2 and 6 are for the mailbox tree, 3, 4 and 7 for remoteproc, and 5 for sunxi. Patch 5 needs the bindings in patches 1 and 3.
Testing on a Radxa Cubie A5E (A527), Linux 7.1 PREEMPT_RT and PREEMPT with the same driver and test files:
- KUnit: 37/37 message box, 26/26 remoteproc, built in and as modules. Under UML on x86_64 one message box test is skipped (it needs SMP or spinlock debugging).
- rpmsg ping (10000 messages, about 167 us round trip) and stress (100000 messages, 16 in flight, no loss), with vrings in DRAM and in SRAM, TX done by poll and by write interrupt, and message box unbind/bind with the remoteproc driver unbound. One interrupt per message.
- The same tests with PROVE_LOCKING and DEBUG_ATOMIC_SLEEP (and PROVE_RAW_LOCK_NESTING on PREEMPT): no lockdep or sleep-in-atomic report.
- On next-20261030: W=1 build of each patch with GCC and clang, built in and as modules, dt_binding_check and dtbs_check are clean; checkpatch --strict reports only "does MAINTAINERS need updating?" for the new files, which the entries added in patches 2 and 4 cover.
Tools: I used Claude Code (Anthropic) to help review the code against the v2 comments, write the KUnit tests, run the board tests and draft commit messages. I reviewed every change; all tests above ran on my board.
Thanks to Krzysztof Kozlowski, Chen-Yu Tsai and Rob Herring for reviewing v1 and v2.
Tim Michals (7):
dt-bindings: mailbox: Add Allwinner A523 message box
mailbox: sun55i: Add Allwinner A523 message box driver
dt-bindings: remoteproc: Add Allwinner A523 RISC-V remote processor
remoteproc: sunxi: Add Allwinner A523 XuanTie E906 driver
arm64: dts: allwinner: a523: Add message box and remoteproc nodes
mailbox: sun55i: Add KUnit tests
remoteproc: sunxi: Add KUnit tests
.../mailbox/allwinner,sun55i-a523-msgbox.yaml | 146 ++ .../allwinner,sun55i-a523-rproc.yaml | 146 ++ MAINTAINERS | 15 + .../arm64/boot/dts/allwinner/sun55i-a523.dtsi | 47 + drivers/mailbox/Kconfig | 24 + drivers/mailbox/Makefile | 3 + drivers/mailbox/sun55i-msgbox.c | 613 ++++++++ drivers/mailbox/sun55i-msgbox.h | 95 ++ drivers/mailbox/sun55i_msgbox_kunit.c | 1387 +++++++++++++++++ drivers/remoteproc/Kconfig | 26 + drivers/remoteproc/Makefile | 2 + drivers/remoteproc/sunxi_rproc.c | 855 ++++++++++ drivers/remoteproc/sunxi_rproc.h | 124 ++ drivers/remoteproc/sunxi_rproc_kunit.c | 1314 ++++++++++++++++ 14 files changed, 4797 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml create mode 100644 Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml create mode 100644 drivers/mailbox/sun55i-msgbox.c create mode 100644 drivers/mailbox/sun55i-msgbox.h create mode 100644 drivers/mailbox/sun55i_msgbox_kunit.c create mode 100644 drivers/remoteproc/sunxi_rproc.c create mode 100644 drivers/remoteproc/sunxi_rproc.h create mode 100644 drivers/remoteproc/sunxi_rproc_kunit.c
base-commit: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c
Signature · 1 line
2.53.0
PATCH v3 1/7 dt-bindings: mailbox: Add Allwinner A523 message box
The Allwinner A523, A527 and T527 (sun55i) message box connects the Cortex-A55 host with the HiFi4 DSP, the CPUS power management core and the XuanTie E906 RISC-V core. Each processor has its own register bank. A sender writes a message into the receiving processor's bank, and a channel has an 8-entry FIFO in each direction.
The host bank has 12 channels, four for each remote processor. The binding lists all four banks, since the host writes to and reads the FIFO status of the remote banks, and lists the bank interrupts in the same order: the host bank read interrupt and the write interrupts of the three remote banks, which every A523 has. Each bank has its own bus clock and reset, and an unclocked bank drops writes, so all four are described. The optional allwinner,tx-done-irq property selects TX completion by the receiver bank's write interrupt instead of polling.
---
Changes in v3:
- One compatible, allwinner,sun55i-a523-msgbox: the A523, A527 and T527 are the same die; the A733 entry is dropped
- reg, clocks and resets list all four banks in a fixed order, with clock-names and reset-names: every bank has its own bus clock and reset
- interrupts and interrupt-names are a fixed list (arm, dsp, cpus, rv), all four required: every A523 has the four lines, and allwinner,tx-done-irq only selects how TX done is detected. This answers the v1 question of how an interrupt can be optional; no free-form text (Krzysztof)
- Remote bank interrupts in the example corrected to SPI 181/174/205 (T527 manual, Table 2-15; checked on the board)
- reg: the DSP and CPUS bank addresses were swapped in v2 (0x07120000 is the DSP bank, 0x07094000 the CPUS bank)
- Add allwinner,tx-done-irq
- Description rewritten to describe the hardware; "schema" dropped from the subject (Krzysztof)
- Samuel Holland dropped from the maintainers
--- .../mailbox/allwinner,sun55i-a523-msgbox.yaml | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml
Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml new file +146 -0
@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mailbox/allwinner,sun55i-a523-msgbox.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Allwinner A523 Message Box + +maintainers: + - Tim Michals <[email protected]> + +description: + The message box on the Allwinner A523, A527 and T527 (sun55i) SoCs links + four processors - the Cortex-A55 cluster, the HiFi4 DSP, the CPUS power + management core and the XuanTie E906 RISC-V core. Each processor has its + own register bank holding 8-entry receive FIFOs for messages from the + other three, and a sender writes into the receiver's bank. The host side + therefore uses all four banks and exposes 12 channels, 4 per remote + processor. Each bank has its own bus clock and reset, and an unclocked + bank drops writes, so the host needs all four. A bank's read interrupt + goes to the processor that owns it; its write interrupt, raised while the + FIFO has room, goes to the sender on a separate line. + +properties: + compatible: + const: allwinner,sun55i-a523-msgbox + + reg: + items: + - description: Cortex-A55 host bank + - description: HiFi4 DSP bank + - description: CPUS bank + - description: XuanTie RISC-V bank + + reg-names: + items: + - const: arm + - const: dsp + - const: cpus + - const: rv + + clocks: + items: + - description: Cortex-A55 host bank bus clock + - description: HiFi4 DSP bank bus clock + - description: CPUS bank bus clock + - description: XuanTie RISC-V bank bus clock + + clock-names: + items: + - const: arm + - const: dsp + - const: cpus + - const: rv + + resets: + items: + - description: Cortex-A55 host bank reset + - description: HiFi4 DSP bank reset + - description: CPUS bank reset + - description: XuanTie RISC-V bank reset + + reset-names: + items: + - const: arm + - const: dsp + - const: cpus + - const: rv + + interrupts: + items: + - description: Cortex-A55 bank read interrupt, messages for the host + - description: HiFi4 DSP bank write interrupt for the host + - description: CPUS bank write interrupt for the host + - description: XuanTie RISC-V bank write interrupt for the host + + interrupt-names: + items: + - const: arm + - const: dsp + - const: cpus + - const: rv + + allwinner,tx-done-irq: + type: boolean + description: + Signal TX done with the write interrupt of the receiver's bank instead + of polling. A message is done once the receiver's FIFO has room for the + next one either way; the write interrupt is raised while the FIFO has + room. Without this property a full FIFO is polled. Received messages + use the host bank read interrupt either way. + + '#mbox-cells': + const: 1 + description: + Host channel number. Channels 0-3 reach the CPUS, 4-7 the DSP and + 8-11 the RISC-V core. + +required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - resets + - reset-names + - interrupts + - interrupt-names + - '#mbox-cells' + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/sun55i-a523-ccu.h> + #include <dt-bindings/clock/sun55i-a523-mcu-ccu.h> + #include <dt-bindings/clock/sun55i-a523-r-ccu.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/reset/sun55i-a523-ccu.h> + #include <dt-bindings/reset/sun55i-a523-mcu-ccu.h> + #include <dt-bindings/reset/sun55i-a523-r-ccu.h> + + mailbox@3003000 { + compatible = "allwinner,sun55i-a523-msgbox"; + reg = <0x03003000 0x1000>, + <0x07120000 0x1000>, + <0x07094000 0x1000>, + <0x07136000 0x1000>; + reg-names = "arm", "dsp", "cpus", "rv"; + clocks = <&ccu CLK_BUS_MSGBOX>, + <&mcu_ccu CLK_BUS_MCU_DSP_MSGBOX>, + <&r_ccu CLK_BUS_R_MSGBOX>, + <&mcu_ccu CLK_BUS_MCU_RISCV_MSGBOX>; + clock-names = "arm", "dsp", "cpus", "rv"; + resets = <&ccu RST_BUS_MSGBOX>, + <&mcu_ccu RST_BUS_MCU_DSP_MSGBOX>, + <&r_ccu RST_BUS_R_MSGBOX>, + <&mcu_ccu RST_BUS_MCU_RISCV_MSGBOX>; + reset-names = "arm", "dsp", "cpus", "rv"; + interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 181 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 205 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "arm", "dsp", "cpus", "rv"; + #mbox-cells = <1>; + };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 1/7] dt-bindings: mailbox: Add Allwinner A523 message box
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] dt-bindings: mailbox: sun55i-a523: allwinner,tx-done-irq encodes driver policy --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dt-bindings: mailbox: sun55i-a523: allwinner,tx-done-irq encodes driver policy --
commit 84f2f43ac2a1769e84ee3a5f62703aa7b08889d3
Author: Tim Michals <[email protected]>
dt-bindings: mailbox: Add Allwinner A523 message box
This commit adds the Devicetree binding schema for the Allwinner A523, A527, and T527 (sun55i) message box controller, describing the four processor register banks, clocks, resets, interrupts, and an optional allwinner,tx-done-irq property.
Quoted 5 lines
Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml new file +0
-0
[ ... ]
Quoted 12 lines
Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml new file +12
-0+ interrupts: + items: + - description: Cortex-A55 bank read interrupt, messages for the host + - description: HiFi4 DSP bank write interrupt for the host + - description: CPUS bank write interrupt for the host + - description: XuanTie RISC-V bank write interrupt for the host + + interrupt-names: + items: + - const: arm + - const: dsp + - const: cpus
Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml line 91
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml new file +10
-0+ - const: rv + + allwinner,tx-done-irq: + type: boolean + description: + Signal TX done with the write interrupt of the receiver's bank instead + of polling. A message is done once the receiver's FIFO has room for the + next one either way; the write interrupt is raised while the FIFO has + room. Without this property a full FIFO is polled. Received messages + use the host bank read interrupt either way.
[Severity: Medium]
Since the schema unconditionally requires all four hardware interrupt lines (arm, dsp, cpus, and rv) in interrupts and interrupt-names, and every A523 SoC wires the three remote bank write interrupts to the GIC, this boolean property appears to only select between interrupt-driven and polled TX completion in the driver rather than describing a hardware difference.
Given that Devicetree bindings should describe hardware capabilities and wiring rather than OS driver runtime policy, should allwinner,tx-done-irq be dropped from the binding so the driver decides how to handle TX completion?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v3 1/7] dt-bindings: mailbox: Add Allwinner A523 message box
In reply to Tim MichalsQuoted 6 lines · Tim Michals
The Allwinner A523, A527 and T527 (sun55i) message box connects the Cortex-A55 host with the HiFi4 DSP, the CPUS power management core and the XuanTie E906 RISC-V core. Each processor has its own register bank. A sender writes a message into the receiving processor's bank, and a channel has an 8-entry FIFO in each direction.
Quoted 9 lines
The host bank has 12 channels, four for each remote processor. The binding lists all four banks, since the host writes to and reads the FIFO status of the remote banks, and lists the bank interrupts in the same order: the host bank read interrupt and the write interrupts of the three remote banks, which every A523 has. Each bank has its own bus clock and reset, and an unclocked bank drops writes, so all four are described. The optional allwinner,tx-done-irq property selects TX completion by the receiver bank's write interrupt instead of polling.
Sashiko comment looks valid, rest seems ok.
Best regards,
Krzysztof
PATCH v3 2/7 mailbox: sun55i: Add Allwinner A523 message box driver
In reply to Tim MichalsAdd a mailbox controller driver for the sun55i message box. Linux uses the Cortex-A55 host bank, which has 12 channels: 0-3 reach the CPUS, 4-7 the HiFi4 DSP and 8-11 the XuanTie E906.
A message is sent by writing the remote processor's FIFO for the channel. Messages for the host raise the host bank interrupt; the handler drains each FIFO under the controller lock, bounded by the FIFO depth, clears the pending status, and delivers the messages after dropping the lock, so a client may send from its rx callback.
Clocks and shared resets are enabled for all four banks, since the host writes into and reads status from remote banks; an unclocked bank drops writes; the shared resets are deasserted at probe and never asserted. TX completion is polled (last_tx_done() checks FIFO count < 8) or signaled by the receiver bank's write interrupt (allwinner,tx-done-irq).
Based on the vendor sunxi-msgbox driver by Allwinner Technology Co., Ltd.
---
Changes in v3:
- Enable the bus clocks and resets of all four banks: the host writes into the remote banks, and an unclocked bank drops the writes
- Interrupt handler: drain the FIFO, then clear the pending bit. The hardware ignores the clear while the FIFO is not empty, so clearing first raised a second interrupt for every message
- last_tx_done() reports done while the receiver's FIFO has room (count < 8), and send_data() never writes a full FIFO: in timer mode it holds the message and last_tx_done() writes it once a slot is free (the core polls only after a successful send). Sashiko flagged "< FIFO_MAX" on v2 and v2 changed to count == 0; that made every queued kick wait for the 1 ms poll. A kick is a doorbell and the data is in shared memory, so it is done once the FIFO has taken it
- Optional TX done by the receiver bank's write interrupt (allwinner,tx-done-irq)
- Request only the host bank interrupt unless tx-done-irq is set; no array sized from the DT (Sashiko)
- Handler drains under the controller lock, bounded by the FIFO depth (Sashiko), and delivers outside it; shutdown() synchronizes with it
- Startup and shutdown share one bounded flush
- Our write IRQs are disarmed at probe, and again in shutdown() once a running TX-done handler has finished
- Register access goes through sun55i_msgbox_readl()/_writel() so the KUnit tests can model the hardware
- Timer mode: send_data() and last_tx_done() check and write the FIFO under the controller lock, so the poll timer writing a held message and a new send cannot overfill it
- A held message whose blocking send timed out is dropped at the next send instead of being written after it
- probe() sets the channels up before requesting the interrupt (the handler walks them); devm_mutex_init()
- probe() requires four clocks and four resets; the interrupts are looked up by name; the TX-done lines are kept per remote bank and named after it (-cpus, -dsp, -rv)
- The receive handler reads each port's enable and status once
- Allwinner's copyright line: the register definitions come from the vendor driver
- The shared reset is deasserted at probe and never asserted, as in
sun6i-msgbox: the other banks carry traffic between the other processors
- sun60i/A733 support dropped from this series
--- MAINTAINERS | 7 + drivers/mailbox/Kconfig | 12 + drivers/mailbox/Makefile | 2 + drivers/mailbox/sun55i-msgbox.c | 613 ++++++++++++++++++++++++++++++++ drivers/mailbox/sun55i-msgbox.h | 95 +++++ 5 files changed, 729 insertions(+) create mode 100644 drivers/mailbox/sun55i-msgbox.c create mode 100644 drivers/mailbox/sun55i-msgbox.h
MAINTAINERS +7 -0
@@ -947,6 +947,13 @@ S: Maintained F: Documentation/devicetree/bindings/hwlock/allwinner,sun6i-a31-hwspinlock.yaml F: drivers/hwspinlock/sun6i_hwspinlock.c +ALLWINNER SUN55I MESSAGE BOX DRIVER +M: Tim Michals <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml +F: drivers/mailbox/sun55i* + ALLWINNER THERMAL DRIVER M: Vasily Khoruzhick <[email protected]> M: Yangtao Li <[email protected]>
drivers/mailbox/Kconfig +12 -0
@@ -332,6 +332,18 @@ config SUN6I_MSGBOX various Allwinner SoCs. This mailbox is used for communication between the application CPUs and the power management coprocessor. +config SUN55I_MSGBOX + tristate "Allwinner A523 Message Box" + depends on ARCH_SUNXI || COMPILE_TEST + help + Mailbox driver for the message box in Allwinner A523, A527 and T527 + (sun55i) SoCs. It provides 12 hardware FIFO channels between the + Cortex-A55 host and the CPUS, HiFi4 DSP and XuanTie E906 RISC-V + processors. + + To compile this driver as a module, choose M here: the module will + be called sun55i-msgbox. + config SPRD_MBOX tristate "Spreadtrum Mailbox" depends on ARCH_SPRD || COMPILE_TEST
drivers/mailbox/Makefile +2 -0
@@ -71,6 +71,8 @@ obj-$(CONFIG_ZYNQMP_IPI_MBOX) += zynqmp-ipi-mailbox.o obj-$(CONFIG_SUN6I_MSGBOX) += sun6i-msgbox.o +obj-$(CONFIG_SUN55I_MSGBOX) += sun55i-msgbox.o + obj-$(CONFIG_SPRD_MBOX) += sprd-mailbox.o obj-$(CONFIG_QCOM_CPUCP_MBOX) += qcom-cpucp-mbox.o
drivers/mailbox/sun55i-msgbox.c new file +613 -0
613 lines not on this page · raw message
drivers/mailbox/sun55i-msgbox.h new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 2/7] mailbox: sun55i: Add Allwinner A523 message box driver
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] mailbox: sun55i: TX IRQ race in sun55i_msgbox_shutdown() on shared route - [High] mailbox: sun55i…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mailbox: sun55i: TX IRQ race in sun55i_msgbox_shutdown() on shared route
- [High] mailbox: sun55i: UAF and race returning -EBUSY in sun55i_msgbox_send_data()
- [Medium] mailbox: sun55i: lock drop race enabling TX IRQ in sun55i_msgbox_send_data() --
commit e3cf2bfaf2bd6f778a72431227fd527e0aef2173
Author: Tim Michals <[email protected]>
mailbox: sun55i: Add Allwinner A523 message box driver
This commit adds a mailbox controller driver for the Allwinner sun55i (A523) message box, supporting 12 hardware FIFO channels between the Cortex-A55 host and the CPUS, HiFi4 DSP, and XuanTie E906 processors with either polled or write-IRQ TX completion.
Quoted 6 lines
drivers/mailbox/sun55i-msgbox.c new file +0
-0@@ -0,0 +1,613 @@
[ ... ]
Quoted 47 lines
drivers/mailbox/sun55i-msgbox.c new file +47
-0+static void sun55i_msgbox_tx_irq_put (struct sun55i_msgbox *mbox,int local_n) +{ +struct sun55i_tx_irq *tx = &mbox->tx_irqs[local_n]; + +mutex_lock (&mbox->tx_irq_lock); +if (!--tx->users) { +free_irq (tx->irq, tx); + }else { +/* The line stays in use: let a running handler finish with us */ +synchronize_irq (tx->irq); + } +mutex_unlock (&mbox->tx_irq_lock); +} + +static int sun55i_msgbox_send_data (struct mbox_chan *chan,void *data) +{ +struct sun55i_msgbox *mbox =to_sun55i_msgbox (chan); +int n = chan - mbox->controller.chans; +int local_n, p, remote_id, remote_n; +unsigned long flags; +u32 msg =0 ; +bool full; + +if (data) +memcpy (&msg, data,sizeof (msg)); + +sun55i_msgbox_chan_to_route (n, &local_n, &p, &remote_id, &remote_n); + +/* +* Under the lock: in timer mode the poll timer may write a held +* message into the same FIFO from another CPU (last_tx_done()). +*/ +spin_lock_irqsave (&mbox->lock, flags); + +/* +* The core calls send_data() only with no request active, so a message +* still held here is one it gave up on (a blocking send timed out): +* drop it rather than send it after this newer one. +*/ +__clear_bit (n, &mbox->tx_held); + +/* +* Writing a full FIFO corrupts its count, so never do it. In write IRQ +* mode the IRQ armed below retries the message once a slot is free. In +* timer mode the core polls only a channel whose send succeeded, so +* hold the message and let last_tx_done() write it. +*/
drivers/mailbox/sun55i-msgbox.c line 308
Quoted 10 lines
drivers/mailbox/sun55i-msgbox.c new file +10
-0+ full =sun55i_msgbox_tx_count (mbox, remote_id, remote_n, p) >=SUN55I_FIFO_MAX ; +if (!full) { +sun55i_msgbox_writel (msg, mbox->regs[remote_id] + +SUN55I_MSGBOX_MSG_FIFO (remote_n, p)); + }else if (!mbox->tx_done_irq) { + mbox->tx_held_msg[n] = msg; +__set_bit (n, &mbox->tx_held); + } + +spin_unlock_irqrestore (&mbox->lock, flags);
[Severity: Medium]
Can dropping mbox->lock here before calling sun55i_msgbox_tx_irq_enable() cause a premature TX completion when a previous blocking send timed out?
If an earlier blocking send timed out in mbox_send_message() -> tx_tick(chan, -ETIME), SUN55I_MSGBOX_WR_IRQ_EN_BIT(p) stays enabled in the remote bank. When the remote processor later reads a message and frees a slot, SUN55I_MSGBOX_WR_IRQ_PEND_BIT(p) is latched in SUN55I_MSGBOX_WRITE_IRQ_STATUS(remote_n).
When the next sun55i_msgbox_send_data() writes to SUN55I_MSGBOX_MSG_FIFO and fills the FIFO to SUN55I_FIFO_MAX, releasing mbox->lock before clearing the latched status bit in sun55i_msgbox_tx_irq_enable() opens a window where sun55i_msgbox_tx_irq() on another CPU can acquire mbox->lock, see both WR_IRQ_EN_BIT(p) and the stale latched WR_IRQ_PEND_BIT(p) set, and call mbox_chan_txdone() to complete the new message while the FIFO is still full.
Should the write IRQ status clear and enable in sun55i_msgbox_tx_irq_enable() be performed under the same mbox->lock critical section as the FIFO write?
drivers/mailbox/sun55i-msgbox.c line 318
Quoted 10 lines
drivers/mailbox/sun55i-msgbox.c new file +10
-0+ +/* +* A kick is a doorbell, the data is in shared memory: it is done once +* the FIFO accepted it and has room for the next one. The write IRQ +* reports exactly that, at once or when the receiver reads a message. +*/ +if (mbox->tx_done_irq) { +sun55i_msgbox_tx_irq_enable (mbox, remote_id, remote_n, p, true); +return full ? -EBUSY :0 ; + }
[Severity: High]
What happens in write-IRQ mode (mbox->tx_done_irq) when the hardware FIFO is full and sun55i_msgbox_send_data() arms the write IRQ and returns -EBUSY?
In drivers/mailbox/mailbox.c, msg_submit() only sets chan->active_req = data and decrements chan->msg_count when send_data() returns 0:
drivers/mailbox/mailbox.c:msg_submit() {
...
if (chan->cl->tx_prepare)
chan->cl->tx_prepare(chan->cl, data);
/* Try to submit a message to the MBOX controller */
err = chan->mbox->ops->send_data(chan, data);
if (!err) {
chan->active_req = data;
chan->msg_count--;
}
...
}When send_data() returns -EBUSY, chan->active_req remains NULL and the caller's data pointer stays in chan->msg_data[]. If a blocking send in mbox_send_message() then times out in wait_for_completion_timeout(), it calls tx_tick(chan, -ETIME):
drivers/mailbox/mailbox.c:tx_tick() {
...
spin_lock_irqsave(&chan->lock, flags);
mssg = chan->active_req;
chan->active_req = NULL;
spin_unlock_irqrestore(&chan->lock, flags);
/* Submit next message */
msg_submit(chan);
if (!mssg)
return;
...
}Because chan->active_req is NULL, tx_tick() does not remove the timed-out message from chan->msg_data[]. Instead, mbox_send_message() returns -ETIME to the caller while its message pointer (often stack-allocated in blocking mode) is still queued in chan->msg_data[] with the write IRQ enabled. When the remote processor later drains a FIFO slot, sun55i_msgbox_tx_irq() -> mbox_chan_txdone() -> tx_tick() -> msg_submit() will call cl->tx_prepare(), sun55i_msgbox_send_data() (which runs memcpy(&msg, data, sizeof(msg))), and cl->tx_done() on the dangling pointer.
Even without a timeout, while chan->active_req is NULL and the first message waits in chan->msg_data[] for the write IRQ, a second mbox_send_message() call on another CPU can run msg_submit() just as a FIFO slot frees: CPU 0 sees chan->active_req == NULL, calls cl->tx_prepare() a second time on the first message, writes it into the single free FIFO slot (refilling the FIFO), and sets chan->active_req. The concurrent sun55i_msgbox_tx_irq() on CPU 1 then calls mbox_chan_txdone() and prematurely completes the message while the FIFO is full.
Should write-IRQ mode also buffer the message in mbox->tx_held_msg[n] and return 0 when the FIFO is full, writing the held message from sun55i_msgbox_tx_irq() once a slot is free?
[ ... ]
Quoted 25 lines
drivers/mailbox/sun55i-msgbox.c new file +25
-0+static void sun55i_msgbox_shutdown (struct mbox_chan *chan) +{ +struct sun55i_msgbox *mbox =to_sun55i_msgbox (chan); +void __iomem *base = mbox->regs[SUN55I_PROC_ARM ]; +int n = chan - mbox->controller.chans; +int local_n, p, remote_id, remote_n; +u32 stale[SUN55I_FIFO_MAX ]; +unsigned long flags; +u32 val; + +sun55i_msgbox_chan_to_route (n, &local_n, &p, &remote_id, &remote_n); + +/* Disable the receive IRQ; a message held for a full FIFO is dropped */ +spin_lock_irqsave (&mbox->lock, flags); + val =sun55i_msgbox_readl (base +SUN55I_MSGBOX_READ_IRQ_ENABLE (local_n)); + val &= ~SUN55I_MSGBOX_RD_IRQ_EN_BIT (p); +sun55i_msgbox_writel (val, base +SUN55I_MSGBOX_READ_IRQ_ENABLE (local_n)); +__clear_bit (n, &mbox->tx_held); +spin_unlock_irqrestore (&mbox->lock, flags); + +/* The handler delivers outside the lock: let it finish with this channel */ +synchronize_irq (mbox->irq); + +/* Release the line only if this channel's startup() got it */ +if (test_and_clear_bit (n, &mbox->tx_irq_held)) {
drivers/mailbox/sun55i-msgbox.c line 397
Quoted 10 lines
drivers/mailbox/sun55i-msgbox.c new file +10
-0+sun55i_msgbox_tx_irq_enable (mbox, remote_id, remote_n, p, false); +sun55i_msgbox_tx_irq_put (mbox, local_n); +/* +* A TX-done handler that was already running submits the next +* message through send_data(), which arms the IRQ again. It has +* finished now (free_irq() or synchronize_irq() above), so +* disarm once more. +*/ +sun55i_msgbox_tx_irq_enable (mbox, remote_id, remote_n, p, false); + }
[Severity: High]
Can a second sun55i_msgbox_tx_irq() invocation still race with channel teardown here when another channel on the same route remains active (tx->users > 1)?
In mbox_free_channel(), chan->mbox->ops->shutdown(chan) runs before chan->cl is cleared, and queued messages may still be present in chan->msg_data[]. When tx->users > 1 on local_n, sun55i_msgbox_tx_irq_put() only calls synchronize_irq(tx->irq) and leaves tx->irq enabled at the interrupt controller.
If an in-flight sun55i_msgbox_tx_irq() was already past mbox->lock on another CPU, it calls:
sun55i_msgbox_tx_irq()
mbox_chan_txdone()
tx_tick()
msg_submit()
sun55i_msgbox_send_data()
sun55i_msgbox_tx_irq_enable(mbox, remote_id, remote_n, p, true)Because the write IRQ is level-triggered whenever at least one FIFO slot is free, re-enabling SUN55I_MSGBOX_WR_IRQ_EN_BIT(p) in sun55i_msgbox_send_data() can immediately assert tx->irq again as soon as the first handler returns. Waiters in sun55i_msgbox_tx_irq_put()'s synchronize_irq(tx->irq) only wait for that first handler invocation to complete, so a second sun55i_msgbox_tx_irq() can fire before the second sun55i_msgbox_tx_irq_enable(..., false) runs and execute mbox_chan_txdone() -> tx_tick() concurrently with mbox_free_channel() setting chan->cl = NULL (or re-arm the write IRQ again if more messages were queued).
Would checking test_bit(n, &mbox->tx_irq_held) under mbox->lock before arming the write IRQ in sun55i_msgbox_send_data() avoid re-enabling the IRQ after sun55i_msgbox_shutdown() has begun?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v3 2/7] mailbox: sun55i: Add Allwinner A523 message box driver
In reply to Tim Michalsdrivers/mailbox/sun55i-msgbox.c line 24
Quoted 3 lines · Tim Michals
drivers/mailbox/sun55i-msgbox.c new file +2
-0+#include <linux/mod_devicetable.h> +#include <linux/platform_device.h>
Please don't include <linux/mod_devicetable.h> as this pulls in a lot of unneeded build dependencies.
<linux/platform_device.h> already provides of_device_id which is all you seem to use here. If you want full iwyu include <linux/device-id/of.h> instead.
Best regards
Uwe
PATCH v3 3/7 dt-bindings: remoteproc: Add Allwinner A523 RISC-V remote processor
In reply to Tim MichalsThe Allwinner A523, A527 and T527 (sun55i) contain a T-Head XuanTie E906 RISC-V core. It runs from a dedicated 256 KiB SRAM and can use a second 256 KiB SRAM and DRAM; a bit in a PRCM remap register shares a further 512 KiB SRAM (SRAM A3_2) with its subsystem. Its reset vector is set in its configuration block.
Describe the configuration block, both SRAMs and the remap register, the bus, core and SRAM clocks, the configuration, core, SRAM and debug resets, the RISC-V and SRAM power domains, one message box channel, the reserved memory regions (a pool for virtio, DRAM for firmware, a trace buffer) and an optional crash interrupt.
---
Changes in v3:
- File renamed to allwinner,sun55i-a523-rproc.yaml to match the compatible
- reg and reg-names are a fixed list of four (cfg, sram-a3-0, sram-a3-1, remap), all required (Krzysztof); the SRAMs are named as in the T527 manual (SRAMA3_0, SRAMA3_1); the description says the remap bit shares SRAM A3_2, not SRAM space 1
- clocks and resets are fixed lists, no minItems (Krzysztof); add the debug reset. The msgbox and parent clocks and the msgbox reset are
dropped: they belong to the message box node
- Add the RISC-V and SRAM power domains
- One message box channel; mbox-names dropped. mboxes is optional: a user can drive the message box from userspace (UIO) instead
- The crash interrupt description says the A523 has no dedicated line for it; it is the only interrupt, so no interrupt-names
- memory-region[0] is a shared-dma-pool; the example has the memory regions
- "schema" dropped from the subject (Krzysztof)
- Jernej Skrabec and Samuel Holland dropped from the maintainers; the MAINTAINERS entry moves to the driver patch
--- .../allwinner,sun55i-a523-rproc.yaml | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml new file +146 -0
@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/remoteproc/allwinner,sun55i-a523-rproc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Allwinner A523 XuanTie E906 RISC-V Remote Processor + +maintainers: + - Tim Michals <[email protected]> + +description: + The Allwinner A523, A527 and T527 (sun55i) SoCs contain a T-Head XuanTie + E906 RISC-V core next to the Cortex-A55 cluster. The core runs from a + dedicated 256 KiB SRAM, can also use a second 256 KiB SRAM and DRAM, + and a remap register shared with the HiFi4 DSP shares a further 512 KiB + SRAM (SRAM A3_2) with the core's subsystem. Its reset vector is set in a + register of its configuration block, and it exchanges notifications with + the Cortex-A55 host through the message box. + +properties: + compatible: + const: allwinner,sun55i-a523-rproc + + reg: + items: + - description: Configuration block, including the boot address register + - description: SRAM A3_0, the core's dedicated SRAM space 0 + - description: SRAM A3_1, the core's SRAM space 1 + - description: SRAM remap control register + + reg-names: + items: + - const: cfg + - const: sram-a3-0 + - const: sram-a3-1 + - const: remap + + clocks: + items: + - description: Configuration block bus clock + - description: RISC-V core clock + - description: MCU public SRAM bus clock + + clock-names: + items: + - const: bus + - const: core + - const: sram + + resets: + items: + - description: Configuration block reset + - description: RISC-V core reset + - description: MCU public SRAM reset + - description: RISC-V debug module reset + + reset-names: + items: + - const: cfg + - const: core + - const: sram + - const: debug + + mboxes: + description: + Message box channel to the RISC-V core. Each channel has a FIFO in + each direction, so it carries notifications both ways. + maxItems: 1 + + firmware-name: + maxItems: 1 + + memory-region: + minItems: 1 + items: + - description: Virtio vring and buffer pool, a shared-dma-pool + - description: Firmware code and data in DRAM + - description: Trace buffer + + memory-region-names: + minItems: 1 + items: + - const: vram + - const: dram + - const: trace + + interrupts: + maxItems: 1 + description: + Interrupt the RISC-V core raises on a fatal error. The A523 has no + dedicated line for this, so it is present only where the system + integration provides one. + + power-domains: + items: + - description: RISC-V core power domain + - description: SRAM power domain + + power-domain-names: + items: + - const: riscv + - const: sram + +required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - resets + - reset-names + - power-domains + - power-domain-names + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/sun55i-a523-mcu-ccu.h> + #include <dt-bindings/power/allwinner,sun55i-a523-ppu.h> + #include <dt-bindings/reset/sun55i-a523-mcu-ccu.h> + + remoteproc@7130000 { + compatible = "allwinner,sun55i-a523-rproc"; + reg = <0x07130000 0x1000>, + <0x07280000 0x40000>, + <0x072c0000 0x40000>, + <0x07010364 0x4>; + reg-names = "cfg", "sram-a3-0", "sram-a3-1", "remap"; + clocks = <&mcu_ccu CLK_BUS_MCU_RISCV_CFG>, + <&mcu_ccu CLK_MCU_RISCV>, + <&mcu_ccu CLK_BUS_MCU_PUBSRAM>; + clock-names = "bus", "core", "sram"; + resets = <&mcu_ccu RST_BUS_MCU_RISCV_CFG>, + <&mcu_ccu RST_BUS_MCU_RISCV_CORE>, + <&mcu_ccu RST_BUS_MCU_PUBSRAM>, + <&mcu_ccu RST_BUS_MCU_RISCV_DEBUG>; + reset-names = "cfg", "core", "sram", "debug"; + power-domains = <&ppu PD_RISCV>, <&ppu PD_SRAM>; + power-domain-names = "riscv", "sram"; + mboxes = <&msgbox 9>; + memory-region = <&riscv_vram>, <&riscv_dram>; + memory-region-names = "vram", "dram"; + firmware-name = "riscv-firmware.elf"; + };
Signature · 1 line
2.53.0
Re: [PATCH v3 3/7] dt-bindings: remoteproc: Add Allwinner A523 RISC-V remote processor
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml line 75
Quoted 11 lines · Tim Michals
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml new file +11
-0+ mboxes: + description: + Message box channel to the RISC-V core. Each channel has a FIFO in + each direction, so it carries notifications both ways. + maxItems: 1 + + firmware-name: + maxItems: 1 + + memory-region: + minItems: 1
Here
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml line 82
Quoted 7 lines
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml new file +7
-0+ items: + - description: Virtio vring and buffer pool, a shared-dma-pool + - description: Firmware code and data in DRAM + - description: Trace buffer + + memory-region-names: + minItems: 1
here
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml line 89
Quoted 7 lines
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml new file +7
-0+ items: + - const: vram + - const: dram + - const: trace + + interrupts: + maxItems: 1
and here, same comments as for v2.
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml line 93
Quoted 4 lines
Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml new file +4
-0+ description: + Interrupt the RISC-V core raises on a fatal error. The A523 has no + dedicated line for this, so it is present only where the system + integration provides one.
Best regards,
Krzysztof
PATCH v3 4/7 remoteproc: sunxi: Add Allwinner A523 XuanTie E906 driver
In reply to Tim MichalsAdd a remoteproc driver for the XuanTie E906 RISC-V core in the Allwinner A523, A527 and T527 (sun55i).
.prepare() powers the RISC-V and SRAM power domains, holds the core in reset, releases the configuration, SRAM and debug resets, enables the clocks, shares SRAM A3_2 with the core's subsystem through bit 1 of the remap register and clears both SRAM spaces. .parse_fw() registers the memory-region entries as carveouts and both SRAMs and the carveouts as crash dump segments, then loads the resource table. .start() writes the ELF entry point to the boot address register and releases the core reset.
The driver translates the two SRAM windows, by core and by host address; DRAM firmware, the trace buffer and the vrings are resolved by the core from the carveouts. Vring kicks and the core's notifications use one message box channel. The mailbox receive callback runs in atomic context, so it queues work on an ordered workqueue, which calls rproc_vq_interrupt() for every vring. An optional crash interrupt is reported with rproc_report_crash().
Based on the vendor sunxi-rproc driver by Allwinner Technology Co., Ltd.
---
Changes in v3:
- The core is an E906 (RV32IMAFCX), not an E907
- The mailbox receive callback runs in atomic context; queue work on an ordered workqueue instead of calling rproc_vq_interrupt() from it
- da_to_va() translates only the two SRAM windows and returns NULL for anything else; DRAM, the trace buffer and the vrings come from the core's carveout lookup. Unmatched addresses are no longer used as host addresses (Sashiko)
- All register regions, clocks and resets are required; no fallback to the configuration reset for the core reset (Sashiko). The mailbox is optional
- MAINTAINERS entry added here (it was in the binding patch)
- Handle the debug reset and the RISC-V and SRAM power domains
- One mailbox channel for kicks and notifications; a notification checks every vring in rproc->notifyids
- prepare() holds the core in reset before clearing the SRAM
- Kicks send static const per-vring payloads with knows_txdone = false instead of a shared kick_msg (Sashiko)
- Teardown: rproc_del(), then mbox_free_channel(), then cancel_work_sync() (Sashiko)
- The crash interrupt is armed once the core reset is released, with an atomic flag (Sashiko); lookup and request errors fail the probe
- Read back the boot address before releasing the core reset (Sashiko)
- Carveouts mapped MEMREMAP_WC; a region inside an SRAM reuses the SRAM mapping (Sashiko)
- Carveouts and crash dump segments are registered in parse_fw(), which the core undoes only once it has succeeded; registered in prepare() they stayed on the lists after a failed parse_fw()
- Crash dumps: the ELF info is set (ELFCLASS32, EM_RISCV) and both SRAMs and the carveouts are registered as segments; dumps were empty before
- sanity_check() refuses anything but a 32-bit RISC-V ELF
- memory-region[0] must be the DMA pool, released by a devm action; regions above 4 GiB are refused (the device address is a u32), and a region outside the SRAMs may not overlap a window of the core's address map
- The SRAM reg entries are checked against the SoC address map at probe
- A malformed firmware-name fails the probe; only an absent one keeps the default
- pm_runtime_put_sync() in unprepare(); the power domains are attached by name; the crash interrupt is looked up by index
- Register and SRAM access goes through helpers so the KUnit tests can model the hardware
- The SRAM reg-names are sram-a3-0 and sram-a3-1; the remap bit is described as the manual has it: it shares SRAM A3_2 (512 KiB at 0x07300000) with the MCU subsystem
--- MAINTAINERS | 8 + drivers/remoteproc/Kconfig | 11 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/sunxi_rproc.c | 855 +++++++++++++++++++++++++++++++ drivers/remoteproc/sunxi_rproc.h | 124 +++++ 5 files changed, 999 insertions(+) create mode 100644 drivers/remoteproc/sunxi_rproc.c create mode 100644 drivers/remoteproc/sunxi_rproc.h
MAINTAINERS +8 -0
@@ -954,6 +954,14 @@ S: Maintained F: Documentation/devicetree/bindings/mailbox/allwinner,sun55i-a523-msgbox.yaml F: drivers/mailbox/sun55i* +ALLWINNER SUN55I REMOTEPROC DRIVER +M: Tim Michals <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/remoteproc/allwinner,sun55i-a523-rproc.yaml +F: drivers/remoteproc/sunxi_rproc* + ALLWINNER THERMAL DRIVER M: Vasily Khoruzhick <[email protected]> M: Yangtao Li <[email protected]>
drivers/remoteproc/Kconfig +11 -0
@@ -337,6 +337,17 @@ config STM32_RPROC This can be either built-in or a loadable module. +config SUNXI_REMOTEPROC + tristate "Allwinner A523 XuanTie E906 RISC-V remoteproc support" + depends on (ARCH_SUNXI || COMPILE_TEST) && MAILBOX + help + Say y or m here to support the Allwinner XuanTie E906 RISC-V + co-processor on Allwinner A523, A527, and T527 SoCs via the + remote processor framework. + + To compile this driver as a module, choose M here: the module will + be called sunxi_rproc. + config TI_K3_DSP_REMOTEPROC tristate "TI K3 DSP remoteproc support" depends on ARCH_K3 || COMPILE_TEST
drivers/remoteproc/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o +obj-$(CONFIG_SUNXI_REMOTEPROC) += sunxi_rproc.o obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o ti_k3_common.o
drivers/remoteproc/sunxi_rproc.c new file +855 -0
855 lines not on this page · raw message
drivers/remoteproc/sunxi_rproc.h new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 4/7] remoteproc: sunxi: Add Allwinner A523 XuanTie E906 driver
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] remoteproc: sunxi: missing IRQ sync in sunxi_rproc_stop() races crash handler - [High] remoteproc…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] remoteproc: sunxi: missing IRQ sync in sunxi_rproc_stop() races crash handler
- [High] remoteproc: sunxi: race and UAF in sunxi_rproc_vq_work() on notifyids --
commit f895edd61f6cf2e80a5341959b347c747139fe48
Author: Tim Michals <[email protected]>
remoteproc: sunxi: Add Allwinner A523 XuanTie E906 driver
This commit adds a remoteproc driver for the XuanTie E906 RISC-V core on Allwinner A523, A527, and T527 SoCs, handling power domains, clocks, resets, SRAM mappings, memory-region carveouts, mailbox notifications, and crash reporting.
Quoted 6 lines
drivers/remoteproc/sunxi_rproc.c new file +0
-0@@ -0,0 +1,855 @@
[ ... ]
Quoted 8 lines
drivers/remoteproc/sunxi_rproc.c new file +8
-0+VISIBLE_IF_KUNIT +int sunxi_rproc_vq_notify(int id, void *ptr, void *data) +{ +KUNIT_STATIC_STUB_REDIRECT (sunxi_rproc_vq_notify, id, ptr, data); +rproc_vq_interrupt (data, id); +return 0 ; +} +EXPORT_SYMBOL_IF_KUNIT (sunxi_rproc_vq_notify);
drivers/remoteproc/sunxi_rproc.c line 157
Quoted 10 lines
drivers/remoteproc/sunxi_rproc.c new file +10
-0+ +/* One channel carries all notifications: check every vring */ +VISIBLE_IF_KUNIT +void sunxi_rproc_vq_work(struct work_struct *work) +{ + struct sunxi_rproc *priv = container_of(work, struct sunxi_rproc, vq_work); + +idr_for_each (&priv->rproc->notifyids, sunxi_rproc_vq_notify, priv->rproc); +} +EXPORT_SYMBOL_IF_KUNIT (sunxi_rproc_vq_work);
[Severity: High]
As reported by Sashiko on v2 [1], in drivers/remoteproc/sunxi_rproc.c, can sunxi_rproc_vq_work() race with rproc_resource_cleanup() during rproc_shutdown(), rproc_boot_recovery(), or sunxi_rproc_remove() -> rproc_del() and trigger a use-after-free?
Because priv->mbox_chan stays active across remoteproc stops, crash recoveries, and throughout rproc_del() in sunxi_rproc_remove(), and neither sunxi_rproc_stop() nor sunxi_rproc_unprepare() cancels priv->vq_work, sunxi_rproc_vq_work() can run concurrently with rproc_resource_cleanup().
In sunxi_rproc_vq_work(), idr_for_each() iterates priv->rproc->notifyids without holding priv->rproc->lock (unlike stm32_rproc_mb_vq_work() or imx_dsp_rproc_vq_work()) and without RCU read-side protection (which cannot be held across sunxi_rproc_vq_notify() because rproc_vq_interrupt() invokes virtqueue callbacks that can sleep):
lib/idr.c:idr_for_each()
radix_tree_for_each_slot(slot, &idr->idr_rt, &iter, 0)
fn(id, rcu_dereference_raw(*slot), data)
While sunxi_rproc_vq_notify() is executing, a concurrent teardown runs:
rproc_resource_cleanup()
platform_device_unregister(rvdev->pdev)
rproc_virtio_remove()
rproc_free_vring()
idr_remove(&rproc->notifyids, rvring->notifyid)If removing the vring frees the underlying struct radix_tree_node via call_rcu(), the grace period can finish while sunxi_rproc_vq_notify() sleeps, leaving radix_tree_next_slot() in idr_for_each() to dereference a freed slot pointer.
In addition, although __rproc_virtio_del_vqs() clears rvring->vq and runs synchronize_srcu(&rproc->vq_srcu) during rproc_stop_subdevices(), the rvring entry stays in rproc->notifyids until platform_device_unregister(rvdev->pdev) removes it and immediately frees the devm-allocated struct rproc_vdev without another synchronize_srcu(&rproc->vq_srcu). If rproc_vq_interrupt() looks up rvring in rproc->notifyids just before idr_remove(), it can dereference rvring->vq after rvdev has been freed.
Should sunxi_rproc_vq_work() hold mutex_lock(&priv->rproc->lock) around idr_for_each(), or should the driver synchronize and stop queuing vq_work before rproc_resource_cleanup() tears down the vrings?
Quoted 31 lines
drivers/remoteproc/sunxi_rproc.c new file +31
-0+ +/* +* Mailbox rx callbacks run in atomic context, but the virtio/rpmsg receive +* path takes mutexes, so the vring notifications are handled from a work item. +*/ +VISIBLE_IF_KUNIT +void sunxi_rproc_mb_rx_callback(struct mbox_client *cl, void *data) +{ + struct sunxi_rproc *priv = container_of(cl, struct sunxi_rproc, cl); + +queue_work (priv->workqueue, &priv->vq_work); +} +EXPORT_SYMBOL_IF_KUNIT (sunxi_rproc_mb_rx_callback); + +VISIBLE_IF_KUNIT +irqreturn_t sunxi_rproc_crash_handler(int irq, void *data) +{ +struct sunxi_rproc *priv = data; + +/* +* Stays masked until the next start(); recovery runs stop() first. A +* stop() that already disarmed it has disabled the line itself. +*/ +if (test_and_clear_bit (SUNXI_RPROC_CRASH_IRQ_ARMED , &priv->flags)) +disable_irq_nosync (irq); + +rproc_report_crash (priv->rproc,RPROC_FATAL_ERROR ); + +return IRQ_HANDLED ; +} +EXPORT_SYMBOL_IF_KUNIT (sunxi_rproc_crash_handler);
[ ... ]
Quoted 37 lines
drivers/remoteproc/sunxi_rproc.c new file +37
-0+VISIBLE_IF_KUNIT +int sunxi_rproc_start(struct rproc *rproc) +{ +struct sunxi_rproc *priv = rproc->priv; +const struct sunxi_rproc_cfg *cfg = priv->cfg; +int ret; + +dev_dbg (priv->dev,"Starting %s core at entry 0x%llx\n" , + cfg->name, (u64 )rproc->bootaddr); + +if (rproc->bootaddr >U32_MAX ) +return -EINVAL ; + +/* Program the reset vector and flush it before releasing the core */ +sunxi_rproc_writel ((u32 )rproc->bootaddr, priv->cfg_va + cfg->boot_reg_offset); +sunxi_rproc_readl (priv->cfg_va + cfg->boot_reg_offset); + + ret =reset_control_deassert (priv->rst_core); +if (ret) { +dev_err (priv->dev,"failed to release core reset: %d\n" , ret); +return ret; + } + +if (priv->crash_irq >0 && + !test_and_set_bit (SUNXI_RPROC_CRASH_IRQ_ARMED , &priv->flags)) +enable_irq (priv->crash_irq); + +return 0 ; +} +EXPORT_SYMBOL_IF_KUNIT (sunxi_rproc_start); + +static int sunxi_rproc_stop (struct rproc *rproc) +{ +struct sunxi_rproc *priv = rproc->priv; +const struct sunxi_rproc_cfg *cfg = priv->cfg; + +dev_dbg (priv->dev,"Halting %s core...\n" , cfg->name);
drivers/remoteproc/sunxi_rproc.c line 383
Quoted 10 lines
drivers/remoteproc/sunxi_rproc.c new file +10
-0+ +/* Assert reset so the core stops executing */ +reset_control_assert (priv->rst_core); + +if (priv->crash_irq >0 && +test_and_clear_bit (SUNXI_RPROC_CRASH_IRQ_ARMED , &priv->flags)) +disable_irq (priv->crash_irq); + +return 0 ; +}
[Severity: High]
As reported by Sashiko on v2 [2], in drivers/remoteproc/sunxi_rproc.c, what happens if sunxi_rproc_stop() runs right after sunxi_rproc_crash_handler() clears SUNXI_RPROC_CRASH_IRQ_ARMED, while the threaded handler is still executing?
Because sunxi_rproc_crash_handler() is a preemptible IRQ thread, it can clear SUNXI_RPROC_CRASH_IRQ_ARMED and be preempted before calling disable_irq_nosync(irq) or rproc_report_crash(priv->rproc, RPROC_FATAL_ERROR):
CPU0 (IRQ thread) CPU1 (rproc_shutdown / recovery)
sunxi_rproc_crash_handler()
test_and_clear_bit(
SUNXI_RPROC_CRASH_IRQ_ARMED,
&priv->flags) -> true
sunxi_rproc_stop()
test_and_clear_bit(
SUNXI_RPROC_CRASH_IRQ_ARMED,
&priv->flags) -> false
/* returns without waiting */If a subsequent rproc_boot() calls sunxi_rproc_start() before CPU0 reaches disable_irq_nosync(irq), sunxi_rproc_start() sets SUNXI_RPROC_CRASH_IRQ_ARMED and calls enable_irq(priv->crash_irq) while the IRQ disable depth is still 0, triggering an unbalanced enable warning in __enable_irq(). When CPU0 then runs disable_irq_nosync(irq), the IRQ is left disabled while SUNXI_RPROC_CRASH_IRQ_ARMED is set, and the next sunxi_rproc_stop() will increment the disable depth to 2, leaving the crash IRQ permanently masked on later boots.
Furthermore, because sunxi_rproc_stop() does not call synchronize_irq(priv->crash_irq) when test_and_clear_bit() returns false, the in-flight sunxi_rproc_crash_handler() thread can call rproc_report_crash() after the stop (and a subsequent restart) has already completed.
Should sunxi_rproc_stop() still call synchronize_irq(priv->crash_irq) when priv->crash_irq > 0 and SUNXI_RPROC_CRASH_IRQ_ARMED was already cleared by the crash handler?
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v3 4/7] remoteproc: sunxi: Add Allwinner A523 XuanTie E906 driver
In reply to Tim MichalsHello,
drivers/remoteproc/sunxi_rproc.c line 29
Quoted 3 lines · Tim Michals
drivers/remoteproc/sunxi_rproc.c new file +2
-0+#include <linux/mod_devicetable.h> +#include <linux/platform_device.h>
As for patch 2: Please don't use <linux/mod_devicetable.h> and rely on <linux/platform_device.h> to provide of_device_id.
Best regards
Uwe
PATCH v3 5/7 arm64: dts: allwinner: a523: Add message box and remoteproc nodes
In reply to Tim MichalsAdd the message box node, with its four register banks, bank clocks and resets, bank interrupts, and the XuanTie E906 remoteproc node, with the MCU CCU clocks and resets, the RISC-V and SRAM power domains and message box channel 9.
The remoteproc node is disabled; a board enables it together with its firmware name and reserved memory regions.
---
Changes in v3:
- Message box: all four banks with their clocks and resets; the DSP and CPUS bank addresses were swapped in v2; remote bank interrupts corrected to SPI 181/174/205
- Message box: interrupt-names
- Remoteproc: debug reset, RISC-V and SRAM power domains, one message box channel; the message box clock and reset moved to the message box node; reg-names sram-a3-0 and sram-a3-1
--- .../arm64/boot/dts/allwinner/sun55i-a523.dtsi | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+)
arch/arm64/boot/dts/allwinner/sun55i-a523.dtsi +47 -0
@@ -605,6 +605,31 @@ dma: dma-controller@3002000 { #dma-cells = <1>; }; + msgbox: mailbox@3003000 { + compatible = "allwinner,sun55i-a523-msgbox"; + reg = <0x03003000 0x1000>, + <0x07120000 0x1000>, + <0x07094000 0x1000>, + <0x07136000 0x1000>; + reg-names = "arm", "dsp", "cpus", "rv"; + clocks = <&ccu CLK_BUS_MSGBOX>, + <&mcu_ccu CLK_BUS_MCU_DSP_MSGBOX>, + <&r_ccu CLK_BUS_R_MSGBOX>, + <&mcu_ccu CLK_BUS_MCU_RISCV_MSGBOX>; + clock-names = "arm", "dsp", "cpus", "rv"; + resets = <&ccu RST_BUS_MSGBOX>, + <&mcu_ccu RST_BUS_MCU_DSP_MSGBOX>, + <&r_ccu RST_BUS_R_MSGBOX>, + <&mcu_ccu RST_BUS_MCU_RISCV_MSGBOX>; + reset-names = "arm", "dsp", "cpus", "rv"; + interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 181 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 205 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "arm", "dsp", "cpus", "rv"; + #mbox-cells = <1>; + }; + sid: efuse@3006000 { compatible = "allwinner,sun55i-a523-sid", "allwinner,sun50i-a64-sid";
@@ -1144,5 +1169,27 @@ npu: npu@7122000 { resets = <&mcu_ccu RST_BUS_MCU_NPU>; power-domains = <&ppu PD_NPU>; }; + + rproc: remoteproc@7130000 { + compatible = "allwinner,sun55i-a523-rproc"; + reg = <0x07130000 0x1000>, + <0x07280000 0x40000>, + <0x072c0000 0x40000>, + <0x07010364 0x4>; + reg-names = "cfg", "sram-a3-0", "sram-a3-1", "remap"; + clocks = <&mcu_ccu CLK_BUS_MCU_RISCV_CFG>, + <&mcu_ccu CLK_MCU_RISCV>, + <&mcu_ccu CLK_BUS_MCU_PUBSRAM>; + clock-names = "bus", "core", "sram"; + resets = <&mcu_ccu RST_BUS_MCU_RISCV_CFG>, + <&mcu_ccu RST_BUS_MCU_RISCV_CORE>, + <&mcu_ccu RST_BUS_MCU_PUBSRAM>, + <&mcu_ccu RST_BUS_MCU_RISCV_DEBUG>; + reset-names = "cfg", "core", "sram", "debug"; + power-domains = <&ppu PD_RISCV>, <&ppu PD_SRAM>; + power-domain-names = "riscv", "sram"; + mboxes = <&msgbox 9>; + status = "disabled"; + }; }; };
Signature · 1 line
2.53.0
PATCH v3 6/7 mailbox: sun55i: Add KUnit tests
In reply to Tim MichalsAdd 37 KUnit tests for the sun55i message box driver: the routing of all 12 channels, sending on every channel, message order on receive and send, a message for a full FIFO held until there is room (behind the earlier ones, dropped by shutdown, and dropped when its blocking send timed out), last_tx_done() and peek_data() against the FIFO count, startup and shutdown dropping stale messages (bounded by the FIFO depth), and the interrupt handler (spurious and disabled-channel interrupts, empty FIFOs, several channels and routes in one pass, the drain bound, the pending bit cleared after the drain, delivery outside the lock to a client that replies from its callback, no crosstalk between channels). The TX-done line runs on a real descriptor of the dummy irq chip: requested before the receive interrupt is enabled, shared by the channels of a bank, freed by the last shutdown, TX done reported to the core, and a refused message resent through it.
The driver's register helpers are redirected with KUnit static stubs to mock banks that model the hardware: each channel has an 8-deep FIFO, reading it pops and writing it pushes (a write to a full FIFO fails the test), a read pending bit clears only once its FIFO is empty, and a write pending bit is raised while the FIFO has room and cleared only while it is full, as measured on the board. Under forced interrupt threading the registered handler is run from the test thread.
---
Changes in v3:
- Moved after the drivers
- depends on SUN55I_MSGBOX (Sashiko)
- Register access is redirected with KUnit static stubs to mock banks that model the hardware (8-deep FIFOs, the read and write status as measured). No readl() on plain memory, so no architecture restriction and no endianness issue (Sashiko)
- File named sun55i_msgbox_kunit.c (kunit/style.rst)
- The startup flush test now checks that the FIFO is drained; it passed through the failsafe before (Sashiko)
- New tests: drain before clearing the pending bit, full FIFO never written (message held in timer mode), TX done by write interrupt, delivery outside the lock, message order, the abandoned held message, the TX-done line through a real interrupt descriptor, a refused message resent through the core
- Duplicate tests merged (routing is one table)
--- drivers/mailbox/Kconfig | 12 + drivers/mailbox/Makefile | 1 + drivers/mailbox/sun55i_msgbox_kunit.c | 1387 +++++++++++++++++++++++++ 3 files changed, 1400 insertions(+) create mode 100644 drivers/mailbox/sun55i_msgbox_kunit.c
drivers/mailbox/Kconfig +12 -0
@@ -344,6 +344,18 @@ config SUN55I_MSGBOX To compile this driver as a module, choose M here: the module will be called sun55i-msgbox. +config SUN55I_MSGBOX_KUNIT_TEST + tristate "KUnit tests for Allwinner sun55i msgbox" if !KUNIT_ALL_TESTS + depends on SUN55I_MSGBOX && KUNIT + default KUNIT_ALL_TESTS + help + KUnit tests for the Allwinner sun55i-msgbox driver. They run the + channel operations (send, peek, last_tx_done, startup, shutdown) + and the interrupt handlers against mock register banks that model + the 8-deep FIFOs and the read and write status registers, and + request, share and free the TX-done line on a dummy interrupt. + Say Y here to run these tests during boot or via kunit.py. + config SPRD_MBOX tristate "Spreadtrum Mailbox" depends on ARCH_SPRD || COMPILE_TEST
drivers/mailbox/Makefile +1 -0
@@ -72,6 +72,7 @@ obj-$(CONFIG_ZYNQMP_IPI_MBOX) += zynqmp-ipi-mailbox.o obj-$(CONFIG_SUN6I_MSGBOX) += sun6i-msgbox.o obj-$(CONFIG_SUN55I_MSGBOX) += sun55i-msgbox.o +obj-$(CONFIG_SUN55I_MSGBOX_KUNIT_TEST) += sun55i_msgbox_kunit.o obj-$(CONFIG_SPRD_MBOX) += sprd-mailbox.o
drivers/mailbox/sun55i_msgbox_kunit.c new file +1387 -0
1,387 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v3 7/7 remoteproc: sunxi: Add KUnit tests
In reply to Tim MichalsAdd 26 KUnit tests for the sunxi remoteproc driver: translation of both SRAM windows by core and host address, their edges (the windows are adjacent, and an access may not straddle them), rejection of zero length, overflowing da + len and addresses near SRAM that are not E906 SRAM, DRAM and trace left to the core's carveout lookup, boot address programming and the rejection of addresses above 32 bits, the remap bit (leaving the DSP's bit alone) and SRAM clearing, the reset and clock order of .prepare(), .start(), .stop() and .unprepare(), every .prepare() failure unwound (one parameterised test per step, and a power domain that does not power up), a core reset that fails in .start(), the crash interrupt armed only while the core runs, the crash handler through a real threaded interrupt, the firmware machine check, .parse_fw() with no, a rejected and a valid resource table and the memory it registers across two boots, a kick queued behind another keeping its payload, the mailbox receive callback deferring to the workqueue, and the work servicing every vring.
Register and SRAM access is redirected with KUnit static stubs to fake buffers; fake clocks and a fake reset controller on a software node stand in for the hardware, so the tests run on any architecture.
---
Changes in v3:
- Moved after the drivers
- depends on SUNXI_REMOTEPROC (Sashiko)
- Register and SRAM access goes through KUnit static stubs, no readl() on plain memory, so no architecture restriction and no endianness issue (Sashiko); depends on COMMON_CLK and RESET_CONTROLLER for the fake clocks and reset controller
- File named sunxi_rproc_kunit.c (kunit/style.rst)
- The kick_msg test is replaced by one that queues a kick behind another and checks the payload when it is sent (Sashiko)
- New tests: DRAM left to the core carveouts, addresses near SRAM that are not E906 SRAM, both window edges, remap bit 0 (DSP) preserved, boot address rejected before STA_ADD is written, receive callback deferring to the workqueue, every prepare() failure unwound, reset and clock order, crash interrupt arming and handler, machine check, parse_fw(), the vring work
- Duplicate tests merged
--- drivers/remoteproc/Kconfig | 15 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/sunxi_rproc_kunit.c | 1314 ++++++++++++++++++++++++ 3 files changed, 1330 insertions(+) create mode 100644 drivers/remoteproc/sunxi_rproc_kunit.c
drivers/remoteproc/Kconfig +15 -0
@@ -348,6 +348,21 @@ config SUNXI_REMOTEPROC To compile this driver as a module, choose M here: the module will be called sunxi_rproc. +config SUNXI_REMOTEPROC_KUNIT_TEST + tristate "KUnit tests for Allwinner sunxi remoteproc" if !KUNIT_ALL_TESTS + depends on SUNXI_REMOTEPROC && KUNIT && COMMON_CLK && RESET_CONTROLLER + default KUNIT_ALL_TESTS + help + KUnit tests for the Allwinner sunxi_rproc driver: da_to_va() + address translation for both SRAM spaces and DRAM carveouts, + prepare()/unprepare() (reset and clock order, every failure + unwound, remap bit, SRAM clear), start()/stop() (boot address, + crash interrupt), the crash handler, parse_fw() (resource table, + carveouts, crash dump segments), kicks, and the vring + notifications. Fake clocks and a fake reset controller stand in + for the hardware. + Say Y here to run these tests during boot or via kunit.py. + config TI_K3_DSP_REMOTEPROC tristate "TI K3 DSP remoteproc support" depends on ARCH_K3 || COMPILE_TEST
drivers/remoteproc/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o obj-$(CONFIG_SUNXI_REMOTEPROC) += sunxi_rproc.o +obj-$(CONFIG_SUNXI_REMOTEPROC_KUNIT_TEST) += sunxi_rproc_kunit.o obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o ti_k3_common.o
drivers/remoteproc/sunxi_rproc_kunit.c new file +1314 -0
1,314 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 7/7] remoteproc: sunxi: Add KUnit tests
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] remoteproc: sunxi: missing CONFIG_PM dependency in KUnit test - [Low] remoteproc: sunxi: missing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] remoteproc: sunxi: missing CONFIG_PM dependency in KUnit test
- [Low] remoteproc: sunxi: missing __force on __iomem casts in use_mmio_mocks() --
commit 9db9877d3095c9678cf19b6cc5cf48fbc1c0e95d
Author: Tim Michals <[email protected]>
remoteproc: sunxi: Add KUnit tests
This commit adds 26 KUnit tests for the Allwinner sunxi remoteproc driver, covering address translation, lifecycle callbacks, crash handling, firmware parsing, and mailbox notifications using KUnit static stubs and mock providers.
drivers/remoteproc/Kconfig config SUNXI_REMOTEPROC · line 354
Quoted 12 lines
drivers/remoteproc/Kconfig +4
-0@@ -348,6 +348,21 @@ config SUNXI_REMOTEPROC To compile this driver as a module, choose M here: the module will be called sunxi_rproc. +config SUNXI_REMOTEPROC_KUNIT_TEST + tristate "KUnit tests for Allwinner sunxi remoteproc" if !KUNIT_ALL_TESTS + depends on SUNXI_REMOTEPROC && KUNIT && COMMON_CLK && RESET_CONTROLLER + default KUNIT_ALL_TESTS
[Severity: Medium]
Should SUNXI_REMOTEPROC_KUNIT_TEST also depend on PM?
In include/linux/pm.h, the usage_count member of struct dev_pm_info is only defined when CONFIG_PM is enabled:
#ifdef CONFIG_PM
...
atomic_t usage_count;When CONFIG_PM is disabled, expect_powered_off(), test_prepare_unprepare_order(), and test_prepare_power_up_failure() in drivers/remoteproc/sunxi_rproc_kunit.c fail to compile because they read dev->power.usage_count unconditionally.
In addition, test_prepare_power_up_failure() relies on dev_pm_domain_set() and pm_runtime_enable() so that sunxi_rproc_prepare() -> pm_runtime_resume_and_get() invokes mock_failing_pm_domain.ops.runtime_resume and returns -EIO. When CONFIG_PM is disabled, those helpers are no-op stubs and pm_runtime_resume_and_get() returns 0 instead of -EIO.
[ ... ]
Quoted 5 lines
drivers/remoteproc/sunxi_rproc_kunit.c new file +0
-0
[ ... ]
drivers/remoteproc/sunxi_rproc_kunit.c line 395
Quoted 9 lines
drivers/remoteproc/sunxi_rproc_kunit.c new file +9
-0+static void use_mmio_mocks (struct test_context *ctx) +{ + ctx->priv.cfg_va = (void __iomem *)ctx->mock_cfg_regs; + ctx->priv.remap_va = (void __iomem *)&ctx->mock_remap_reg; + ctx->priv.sram0_va = (void __iomem *)ctx->mock_sram_buf; + ctx->priv.sram0_size =sizeof (ctx->mock_sram_buf); + ctx->priv.sram1_va = (void __iomem *)ctx->mock_sram1_buf; + ctx->priv.sram1_size =sizeof (ctx->mock_sram1_buf); +}
[Severity: Low]
Unlike FAKE_SRAM_VA and FAKE_SRAM1_VA, which use (void __force __iomem *), the casts in use_mmio_mocks() omit __force when casting normal kernel memory buffers to __iomem pointers. Should these casts use (void __force __iomem *) to avoid Sparse address-space warnings when building with C=1?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
kernel test robot
build botRe: [PATCH v3 7/7] remoteproc: sunxi: Add KUnit tests
In reply to Tim Michalskernel test robot noticed the following build errors:
Hi Tim,
kernel test robot noticed the following build errors:
[auto build test ERROR on 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c]
url: https://github.com/intel-lab-lkp/linux/commits/Tim-Michals/dt-bindings-mailbox-Add-Allwinner-A523-message-box/20261101-125729 base: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c patch link: https://lore.kernel.org/r/20261101185735.762559-8-tcmichals%40gmail.com patch subject: [PATCH v3 7/7] remoteproc: sunxi: Add KUnit tests config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20261108/[email protected]/config) compiler: hppa-linux-gcc (GCC) 16.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261108/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/kunit/device.h:16,
from drivers/remoteproc/sunxi_rproc_kunit.c:29:
drivers/remoteproc/sunxi_rproc_kunit.c: In function 'expect_powered_off':
>> drivers/remoteproc/sunxi_rproc_kunit.c:962:64: error: 'struct dev_pm_info' has no member named 'usage_count'
962 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 0);
| ^
include/kunit/test.h:840:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
include/kunit/test.h:1037:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
1037 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1034:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c:962:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
962 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 0);
| ^~~~~~~~~~~~~~~
>> drivers/remoteproc/sunxi_rproc_kunit.c:962:64: error: 'struct dev_pm_info' has no member named 'usage_count'
962 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 0);
| ^
include/kunit/test.h:840:38: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
include/kunit/test.h:1037:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
1037 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1034:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c:962:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
962 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 0);
| ^~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c: In function 'test_prepare_unprepare_order':
drivers/remoteproc/sunxi_rproc_kunit.c:977:64: error: 'struct dev_pm_info' has no member named 'usage_count'
977 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 1);
| ^
include/kunit/test.h:840:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
include/kunit/test.h:1037:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
1037 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1034:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c:977:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
977 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 1);
| ^~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c:977:64: error: 'struct dev_pm_info' has no member named 'usage_count'
977 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 1);
| ^
include/kunit/test.h:840:38: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
include/kunit/test.h:1037:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
1037 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1034:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c:977:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
977 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 1);
| ^~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c: In function 'test_prepare_power_up_failure':
drivers/remoteproc/sunxi_rproc_kunit.c:1107:54: error: 'struct dev_pm_info' has no member named 'usage_count'
1107 | KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);
| ^
include/kunit/test.h:840:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
include/kunit/test.h:1037:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
1037 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1034:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c:1107:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
1107 | KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);
| ^~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c:1107:54: error: 'struct dev_pm_info' has no member named 'usage_count'
1107 | KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);
| ^
include/kunit/test.h:840:38: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
include/kunit/test.h:1037:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
1037 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1034:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
drivers/remoteproc/sunxi_rproc_kunit.c:1107:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
1107 | KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);
| ^~~~~~~~~~~~~~~vim +962 drivers/remoteproc/sunxi_rproc_kunit.c
949
950 /* Everything as before prepare(): resets asserted, clocks off, no PM reference */
951 static void expect_powered_off(struct kunit *test, struct test_context *ctx,
952 struct mock_providers *mp, bool core_held)
953 {
954 int i;
955
956 KUNIT_EXPECT_TRUE(test, mp->asserted[RST_CFG]);
957 KUNIT_EXPECT_TRUE(test, mp->asserted[RST_SRAM]);
958 KUNIT_EXPECT_TRUE(test, mp->asserted[RST_DEBUG]);
959 KUNIT_EXPECT_EQ(test, mp->asserted[RST_CORE], core_held);
960 for (i = 0; i < NR_CLK; i++)
961 KUNIT_EXPECT_FALSE_MSG(test, clk_hw_is_prepared(&mp->clk[i].hw), "clock %d", i);
> 962 KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 0);
963 }
964
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v3 7/7] remoteproc: sunxi: Add KUnit tests
In reply to Tim Michalskernel test robot noticed the following build errors:
Hi Tim,
kernel test robot noticed the following build errors:
[auto build test ERROR on 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c]
url: https://github.com/intel-lab-lkp/linux/commits/Tim-Michals/dt-bindings-mailbox-Add-Allwinner-A523-message-box/20261101-125729 base: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c patch link: https://lore.kernel.org/r/20261101185735.762559-8-tcmichals%40gmail.com patch subject: [PATCH v3 7/7] remoteproc: sunxi: Add KUnit tests config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20261108/[email protected]/config) compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project fc9576e3b179738d99c5babe5cd9d6c1f883e0db) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261108/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/remoteproc/sunxi_rproc_kunit.c:962:58: error: no member named 'usage_count' in 'struct dev_pm_info'
962 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 0);
| ~~~~~~~~~~~~~~~~~~~~ ^
include/kunit/test.h:1034:28: note: expanded from macro 'KUNIT_EXPECT_EQ'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~
include/kunit/test.h:1039:8: note: expanded from macro 'KUNIT_EXPECT_EQ_MSG'
1039 | left, ==, right, \
| ^~~~
include/kunit/test.h:874:9: note: expanded from macro 'KUNIT_BINARY_INT_ASSERTION'
874 | left, op, right, \
| ^~~~
include/kunit/test.h:840:15: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
>> drivers/remoteproc/sunxi_rproc_kunit.c:962:58: error: no member named 'usage_count' in 'struct dev_pm_info'
962 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 0);
| ~~~~~~~~~~~~~~~~~~~~ ^
include/kunit/test.h:1034:28: note: expanded from macro 'KUNIT_EXPECT_EQ'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~
include/kunit/test.h:1039:8: note: expanded from macro 'KUNIT_EXPECT_EQ_MSG'
1039 | left, ==, right, \
| ^~~~
include/kunit/test.h:874:9: note: expanded from macro 'KUNIT_BINARY_INT_ASSERTION'
874 | left, op, right, \
| ^~~~
include/kunit/test.h:840:31: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
drivers/remoteproc/sunxi_rproc_kunit.c:977:58: error: no member named 'usage_count' in 'struct dev_pm_info'
977 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 1);
| ~~~~~~~~~~~~~~~~~~~~ ^
include/kunit/test.h:1034:28: note: expanded from macro 'KUNIT_EXPECT_EQ'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~
include/kunit/test.h:1039:8: note: expanded from macro 'KUNIT_EXPECT_EQ_MSG'
1039 | left, ==, right, \
| ^~~~
include/kunit/test.h:874:9: note: expanded from macro 'KUNIT_BINARY_INT_ASSERTION'
874 | left, op, right, \
| ^~~~
include/kunit/test.h:840:15: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
drivers/remoteproc/sunxi_rproc_kunit.c:977:58: error: no member named 'usage_count' in 'struct dev_pm_info'
977 | KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 1);
| ~~~~~~~~~~~~~~~~~~~~ ^
include/kunit/test.h:1034:28: note: expanded from macro 'KUNIT_EXPECT_EQ'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~
include/kunit/test.h:1039:8: note: expanded from macro 'KUNIT_EXPECT_EQ_MSG'
1039 | left, ==, right, \
| ^~~~
include/kunit/test.h:874:9: note: expanded from macro 'KUNIT_BINARY_INT_ASSERTION'
874 | left, op, right, \
| ^~~~
include/kunit/test.h:840:31: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
drivers/remoteproc/sunxi_rproc_kunit.c:1107:48: error: no member named 'usage_count' in 'struct dev_pm_info'
1107 | KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);
| ~~~~~~~~~~ ^
include/kunit/test.h:1034:28: note: expanded from macro 'KUNIT_EXPECT_EQ'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~
include/kunit/test.h:1039:8: note: expanded from macro 'KUNIT_EXPECT_EQ_MSG'
1039 | left, ==, right, \
| ^~~~
include/kunit/test.h:874:9: note: expanded from macro 'KUNIT_BINARY_INT_ASSERTION'
874 | left, op, right, \
| ^~~~
include/kunit/test.h:840:15: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~
drivers/remoteproc/sunxi_rproc_kunit.c:1107:48: error: no member named 'usage_count' in 'struct dev_pm_info'
1107 | KUNIT_EXPECT_EQ(test, atomic_read(&dev->power.usage_count), 0);
| ~~~~~~~~~~ ^
include/kunit/test.h:1034:28: note: expanded from macro 'KUNIT_EXPECT_EQ'
1034 | KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
| ^~~~
include/kunit/test.h:1039:8: note: expanded from macro 'KUNIT_EXPECT_EQ_MSG'
1039 | left, ==, right, \
| ^~~~
include/kunit/test.h:874:9: note: expanded from macro 'KUNIT_BINARY_INT_ASSERTION'
874 | left, op, right, \
| ^~~~
include/kunit/test.h:840:31: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
840 | const typeof(left) __left = (left); \
| ^~~~6 errors generated.
vim +962 drivers/remoteproc/sunxi_rproc_kunit.c
949
950 /* Everything as before prepare(): resets asserted, clocks off, no PM reference */
951 static void expect_powered_off(struct kunit *test, struct test_context *ctx,
952 struct mock_providers *mp, bool core_held)
953 {
954 int i;
955
956 KUNIT_EXPECT_TRUE(test, mp->asserted[RST_CFG]);
957 KUNIT_EXPECT_TRUE(test, mp->asserted[RST_SRAM]);
958 KUNIT_EXPECT_TRUE(test, mp->asserted[RST_DEBUG]);
959 KUNIT_EXPECT_EQ(test, mp->asserted[RST_CORE], core_held);
960 for (i = 0; i < NR_CLK; i++)
961 KUNIT_EXPECT_FALSE_MSG(test, clk_hw_is_prepared(&mp->clk[i].hw), "clock %d", i);
> 962 KUNIT_EXPECT_EQ(test, atomic_read(&ctx->priv.dev->power.usage_count), 0);
963 }
964
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki