Skip to contentSkip to conversation

net: wwan: qcom_bam_dmux: Add restricted DMA pool support

PATCH Applied Vishnu Santhosh 5 participants 11 messages Nov 12 – Nov 19

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v6 cover net: wwan: qcom_bam_dmux: Add restricted DMA pool support

Some Qualcomm SoCs, such as Shikra, run the modem in a separate security domain with restricted access to system memory. BAM-DMUX DMA mappings and BAM descriptor FIFOs must therefore be constrained to a designated memory region that can be shared with the modem. Accesses outside that region can trigger an XPU violation.

Add memory-region and qcom,vmid properties to the BAM-DMUX binding, and a qcom,shikra-bam-dmux compatible that requires them. When qcom,vmid is present, the driver SCM-assigns the entire restricted DMA pool to the local and remote execution environments before requesting the DMA channels.

The restricted pool then contains the BAM-DMUX mappings. When the BAM DMA controller references the same pool, its descriptor FIFOs are covered by the assignment as well.

A related binding change allows the BAM DMA controller to use the same restricted pool for descriptor FIFO allocations:

https://lore.kernel.org/all/20261021-qcom-bam-dma-vmid-ext-v3-1-299355e8dd3b@oss.qualcomm.com/
("dt-bindings: dma: qcom,bam-dma: Allow memory-region property")

---
Changes in v6:
- Request the PC IRQ disabled and enable it at the end of probe, instead
of reusing remove() on late probe failure (Loic)
- Link to v5: https://lore.kernel.org/r/20261105-qcom-bam-dmux-vmid-ext-v5-0-5c7903385b4b@oss.qualcomm.com

Changes in v5:
- Drop the redundant restricted-dma-pool compatible check, since
is_swiotlb_for_alloc() already covers it (Loic)
- Link to v4: https://lore.kernel.org/r/20261103-qcom-bam-dmux-vmid-ext-v4-0-3690cc5ca0fd@oss.qualcomm.com

Changes in v4:
- Decide the pool reclaim on the remote power vote after disabling the
PC IRQ (Sashiko)
- Link to v3: https://lore.kernel.org/r/20261021-qcom-bam-dmux-vmid-ext-v3-0-cedd1f681102@oss.qualcomm.com

Changes in v3:
- dt-bindings: Add qcom,shikra-bam-dmux, with qcom,bam-dmux as fallback,
and require memory-region and qcom,vmid for it (Krzysztof)
- dt-bindings: Drop minItems from qcom,vmid (Krzysztof)
- dt-bindings: Drop the example changes (Krzysztof)
- dt-bindings: Drop the statement about the local VMID from the
qcom,vmid description (Sashiko)
- Reuse remove() on late probe failure, since the PC IRQ may already
have powered up the RX path (Sashiko)
- Skip the pool reclaim when the remote did not acknowledge the
power-down (Sashiko)
- Fail probe if the restricted pool is not attached to the device
(Sashiko)
- Link to v2: https://lore.kernel.org/r/20260920-qcom-bam-dmux-vmid-ext-v2-0-ef5ca2178378@oss.qualcomm.com

Changes in v2:
- Replace the Shikra-specific compatible and coherent RX allocation with
memory-region and qcom,vmid properties.
- Use a restricted DMA pool for BAM-DMUX mappings and BAM descriptor FIFOs.
- SCM-assign the complete pool before requesting the DMA channels.
- Validate the remote VMID and restricted DMA pool configuration.
- Link to v1: https://lore.kernel.org/r/20260714-qcom-bam-dmux-vmid-ext-v1-0-3f29da7cca76@oss.qualcomm.com

---
Vishnu Santhosh (2):
dt-bindings: net: qcom,bam-dmux: Add memory-region and qcom,vmid properties
net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

 .../devicetree/bindings/net/qcom,bam-dmux.yaml     |  36 ++++++-
 drivers/net/wwan/Kconfig                           |   1 +
 drivers/net/wwan/qcom_bam_dmux.c                   | 103 ++++++++++++++++++++-
 3 files changed, 138 insertions(+), 2 deletions(-)

---
base-commit: c88fd6989aea9237a60a4859139a265bfb7ddc0b
change-id: 20260714-qcom-bam-dmux-vmid-ext-d9289db310c1

Best regards,

Signature · 1 line
Vishnu Santhosh <[email protected]>
#1 lore raw

PATCH v6 1/2 dt-bindings: net: qcom,bam-dmux: Add memory-region and qcom,vmid properties

Some Qualcomm SoCs, such as Shikra, run the modem in a separate security domain with restricted access to system memory. BAM-DMUX DMA mappings must therefore be constrained to a designated region that can be shared with the modem.

Add an optional memory-region property to reference a restricted DMA pool used for BAM-DMUX mappings, and a qcom,vmid property to identify the remote execution environment that is granted access to the pool through SCM.

Require memory-region whenever qcom,vmid is specified.

Add the qcom,shikra-bam-dmux compatible, with qcom,bam-dmux as fallback, and require both properties for it.

---
 .../devicetree/bindings/net/qcom,bam-dmux.yaml     | 36 +++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +35 -1
index 33746c238513d72366bc52359fb10f275475b331..f7388d24c8612b5a99d5d0e66cfbe2de3b1c9e0d 100644
@@ -22,7 +22,11 @@ description: |
 
 properties:
   compatible:
-    const: qcom,bam-dmux
+    oneOf:
+      - const: qcom,bam-dmux
+      - items:
+          - const: qcom,shikra-bam-dmux
+          - const: qcom,bam-dmux
 
   interrupts:
     description:
@@ -72,6 +76,22 @@ properties:
       - const: tx
       - const: rx
 
+  memory-region:
+    maxItems: 1
+    description:
+      Phandle to a reserved-memory node compatible with restricted-dma-pool.
+      The BAM-DMUX device uses the pool for DMA mappings.
+
+  qcom,vmid:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    maxItems: 1
+    items:
+      minimum: 1
+      maximum: 63
+    description:
+      VMID of the remote execution environment that is granted access to the
+      restricted DMA pool through SCM.
+
 required:
   - compatible
   - interrupts
@@ -81,6 +101,20 @@ required:
   - dmas
   - dma-names
 
+dependencies:
+  qcom,vmid: [ memory-region ]
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: qcom,shikra-bam-dmux
+    then:
+      required:
+        - memory-region
+        - qcom,vmid
+
 additionalProperties: false
 
 examples:
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH net-next v6 1/2] dt-bindings: net: qcom,bam-dmux: Add memory-region and qcom,vmid properties

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The series confines only the BAM-DMUX client's own DMA mappings to the restricted-dma-pool.
- [Low] The patch adds the Shikra-specific compatible qcom,shikra-bam- dmux, but the only placement the driver supports cannot pass schema…

--

dt-bindings: net: qcom,bam-dmux: Add memory-region and qcom,vmid properties

This patch adds optional memory-region and qcom,vmid properties to the BAM-DMUX binding. With them, DMA mappings can be confined to a restricted DMA pool that is shared with the modem through SCM. It also adds the qcom,shikra-bam-dmux compatible, with qcom,bam-dmux as fallback, and requires both new properties for it.

Quoted 5 lines
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +0 -0
index 33746c238513d..f7388d24c8612 100644

Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml description: | · line 29

Quoted 9 lines
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +5 -1
@@ -22,7 +22,11 @@ description: |
 
 properties:
   compatible:
-    const: qcom,bam-dmux
+    oneOf:
+      - const: qcom,bam-dmux
+      - items:
+          - const: qcom,shikra-bam-dmux
+          - const: qcom,bam-dmux

[Severity: Low]
Will a Shikra DT that uses this compatible pass dtbs_check?

The bam-dmux device is only created from a child of the PAS remoteproc node:

drivers/remoteproc/qcom_q6v5_pas.c:qcom_pas_probe() {
    ...
	node = of_get_compatible_child(pdev->dev.of_node, "qcom,bam-dmux");
	pas->bam_dmux = of_platform_device_create(node, NULL, &pdev->dev);
    ...
}

So on Shikra the node has to sit under the qcom,shikra-mpss-pas node.

Documentation/devicetree/bindings/remoteproc/qcom,shikra-pas.yaml does not define a bam-dmux child and ends with unevaluatedProperties: false. The qcom,pas-common.yaml schema it references does not define one either.

Should the series also update the Shikra PAS binding to allow the bam-dmux child node?

[ ... ]

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +6 -0
@@ -72,6 +76,22 @@ properties:
       - const: tx
       - const: rx
 
+  memory-region:
+    maxItems: 1
+    description:
+      Phandle to a reserved-memory node compatible with restricted-dma-pool.
+      The BAM-DMUX device uses the pool for DMA mappings.
+

Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml properties: · line 94

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +10 -0
+  qcom,vmid:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    maxItems: 1
+    items:
+      minimum: 1
+      maximum: 63
+    description:
+      VMID of the remote execution environment that is granted access to the
+      restricted DMA pool through SCM.
+

[Severity: High]
Does this also cover the BAM descriptor FIFOs, or only the bam-dmux buffers?

Only the bam-dmux node gets the restricted pool. qcom_bam_dmux.c maps the skb buffers with dmux->dev, so only the payload buffers go through the pool. The descriptor FIFO is allocated on the BAM DMA controller device instead:

drivers/dma/qcom/bam_dma.c:bam_alloc_chan() {
    ...
	bchan->fifo_virt = dma_alloc_wc(bdev->dev, BAM_DESC_FIFO_SIZE,
					&bchan->fifo_phys, GFP_KERNEL);
    ...
}

That address is then programmed into the hardware:

drivers/dma/qcom/bam_dma.c:bam_chan_init_hw() {
    ...
	writel_relaxed(ALIGN(bchan->fifo_phys, sizeof(struct bam_desc_hw)),
			bam_addr(bdev, bchan->id, BAM_P_DESC_FIFO_ADDR));
    ...
}

The follow-up commit "net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor" says "BAM-DMUX DMA mappings and BAM descriptor FIFOs must therefore be constrained to a designated memory region", and that accesses outside the region can trigger an XPU violation. It relies on "When the BAM DMA controller references the same pool, its descriptor FIFOs are covered by the assignment as well."

However, Documentation/devicetree/bindings/dma/qcom,bam-dma.yaml does not define memory-region and has additionalProperties: false. The dma-controller.yaml and dma-common.yaml schemas it references do not define it either.

With a schema-valid Shikra DT, wouldn't bam_alloc_chan() allocate the FIFO from ordinary memory outside the SCM-assigned region? The BAM descriptor fetches would then land outside the shared region.

Should the series also extend qcom,bam-dma.yaml to accept memory-region? It may also need to check how iommus interacts with of_dma_set_restricted_buffer(). Failing that, could one of the bindings document where the descriptor FIFO has to live?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-qcom-bam-dmux-vmid-ext-v6-0-7a16bd3dff18%40oss.qualcomm.com
#3 lore raw

Re: [PATCH net-next v6 1/2] dt-bindings: net: qcom,bam-dmux: Add memory-region and qcom,vmid properties

Quoted 53 lines · On 16-11-2026 07:24 pm, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The series confines only the BAM-DMUX client's own DMA mappings to the restricted-dma-pool.
- [Low] The patch adds the Shikra-specific compatible qcom,shikra-bam- dmux, but the only placement the driver supports cannot pass schema…

--

dt-bindings: net: qcom,bam-dmux: Add memory-region and qcom,vmid properties

This patch adds optional memory-region and qcom,vmid properties to the BAM-DMUX binding. With them, DMA mappings can be confined to a restricted DMA pool that is shared with the modem through SCM. It also adds the qcom,shikra-bam-dmux compatible, with qcom,bam-dmux as fallback, and requires both new properties for it.

Quoted 5 lines
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +0 -0
index 33746c238513d..f7388d24c8612 100644

Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml description: | · line 29

Quoted 9 lines
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +5 -1
@@ -22,7 +22,11 @@ description: |
 
  properties:
    compatible:
-    const: qcom,bam-dmux
+    oneOf:
+      - const: qcom,bam-dmux
+      - items:
+          - const: qcom,shikra-bam-dmux
+          - const: qcom,bam-dmux

[Severity: Low]
Will a Shikra DT that uses this compatible pass dtbs_check?

The bam-dmux device is only created from a child of the PAS remoteproc node:

drivers/remoteproc/qcom_q6v5_pas.c:qcom_pas_probe() {
     ...
	node = of_get_compatible_child(pdev->dev.of_node, "qcom,bam-dmux");
	pas->bam_dmux = of_platform_device_create(node, NULL, &pdev->dev);
     ...
}
Quoted 8 lines

So on Shikra the node has to sit under the qcom,shikra-mpss-pas node.

Documentation/devicetree/bindings/remoteproc/qcom,shikra-pas.yaml does not define a bam-dmux child and ends with unevaluatedProperties: false. The qcom,pas-common.yaml schema it references does not define one either.

Should the series also update the Shikra PAS binding to allow the bam-dmux child node?

This is handled separately:
https://lore.kernel.org/all/20260908-shikra-pas-bam-dmux-binding-v4-1-6044889e7e3d@oss.qualcomm.com/

Quoted 60 lines

[ ... ]

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +6 -0
@@ -72,6 +76,22 @@ properties:
        - const: tx
        - const: rx
 
+  memory-region:
+    maxItems: 1
+    description:
+      Phandle to a reserved-memory node compatible with restricted-dma-pool.
+      The BAM-DMUX device uses the pool for DMA mappings.
+

Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml properties: · line 94

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom,bam-dmux.yaml +10 -0
+  qcom,vmid:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    maxItems: 1
+    items:
+      minimum: 1
+      maximum: 63
+    description:
+      VMID of the remote execution environment that is granted access to the
+      restricted DMA pool through SCM.
+

[Severity: High]
Does this also cover the BAM descriptor FIFOs, or only the bam-dmux buffers?

Only the bam-dmux node gets the restricted pool. qcom_bam_dmux.c maps the skb buffers with dmux->dev, so only the payload buffers go through the pool. The descriptor FIFO is allocated on the BAM DMA controller device instead:

drivers/dma/qcom/bam_dma.c:bam_alloc_chan() {
     ...
	bchan->fifo_virt = dma_alloc_wc(bdev->dev, BAM_DESC_FIFO_SIZE,
					&bchan->fifo_phys, GFP_KERNEL);
     ...
}

That address is then programmed into the hardware:

drivers/dma/qcom/bam_dma.c:bam_chan_init_hw() {
     ...
	writel_relaxed(ALIGN(bchan->fifo_phys, sizeof(struct bam_desc_hw)),
			bam_addr(bdev, bchan->id, BAM_P_DESC_FIFO_ADDR));
     ...
}

The follow-up commit "net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor" says "BAM-DMUX DMA mappings and BAM descriptor FIFOs must therefore be constrained to a designated memory region", and that accesses outside the region can trigger an XPU violation. It relies on "When the BAM DMA controller references the same pool, its descriptor FIFOs are covered by the assignment as well."

However, Documentation/devicetree/bindings/dma/qcom,bam-dma.yaml does not define memory-region and has additionalProperties: false. The dma-controller.yaml and dma-common.yaml schemas it references do not define it either.

Quoted 8 lines

With a schema-valid Shikra DT, wouldn't bam_alloc_chan() allocate the FIFO from ordinary memory outside the SCM-assigned region? The BAM descriptor fetches would then land outside the shared region.

Should the series also extend qcom,bam-dma.yaml to accept memory-region? It may also need to check how iommus interacts with of_dma_set_restricted_buffer(). Failing that, could one of the bindings document where the descriptor FIFO has to live?

This is covered by a separate binding change for the BAM DMA controller, which goes through the dmaengine tree:
https://lore.kernel.org/all/20261021-qcom-bam-dma-vmid-ext-v3-1-299355e8dd3b@oss.qualcomm.com/

Thanks,
Vishnu

Quoted 3 lines
#4 lore raw

PATCH v6 2/2 net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

In reply to Vishnu Santhosh

Some Qualcomm SoCs, such as Shikra, run the modem in a separate security domain with restricted access to system memory. BAM-DMUX DMA mappings and BAM descriptor FIFOs must therefore be constrained to a designated memory region that can be shared with the modem. Accesses outside that region can trigger an XPU violation.

When qcom,vmid is present, require a restricted DMA pool and assign the entire pool to both the local and remote execution environments before requesting the DMA channels.

This ensures that BAM-DMUX mappings are within the assigned region. When the BAM DMA controller references the same pool, its descriptor FIFOs are covered by the assignment as well.

Track the assigned execution environments explicitly and reclaim the pool for the local environment after DMA channels and mappings are released during remove or probe error cleanup. Skip the reclaim and leave the pool assigned if the remote side still holds its power vote, since it may still access the pool.

Request the PC IRQ with IRQF_NO_AUTOEN and enable it only at the end of probe, so the probe error path cannot race with RX power-up.

Fail probing when restricted DMA pool support is unavailable, when the VMID property is malformed, when memory-region is missing, or when the restricted DMA pool is not attached to the device.

---
 drivers/net/wwan/Kconfig         |   1 +
 drivers/net/wwan/qcom_bam_dmux.c | 103 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 103 insertions(+), 1 deletion(-)
drivers/net/wwan/Kconfig +1 -0
index 958dbc7347fa84ee869439bf8b503037faab8bef..1b133c56231615269698140187ca3141dfe48dbf 100644
@@ -65,6 +65,7 @@ config MHI_WWAN_MBIM
 config QCOM_BAM_DMUX
 	tristate "Qualcomm BAM-DMUX WWAN network driver"
 	depends on (DMA_ENGINE && PM && QCOM_SMEM_STATE) || COMPILE_TEST
+	select QCOM_SCM
 	help
 	  The BAM Data Multiplexer provides access to the network data channels
 	  of modems integrated into many older Qualcomm SoCs, e.g. Qualcomm
drivers/net/wwan/qcom_bam_dmux.c +102 -1

158 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH net-next v6 2/2] net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: wwan: qcom_bam_dmux: lost PC edge in bam_dmux_probe() with IRQF_NO_AUTOEN --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: wwan: qcom_bam_dmux: lost PC edge in bam_dmux_probe() with IRQF_NO_AUTOEN
--

commit 4515119c8a0e425457d7366d017600d0d4e872df
Author: Vishnu Santhosh <[email protected]>

net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

This commit assigns a restricted DMA pool to both the local and remote execution environments via SCM when qcom,vmid is present, reclaims the pool on teardown, and defers enabling pc_irq until the end of probe.

Quoted 4 lines
drivers/net/wwan/qcom_bam_dmux.c +0 -0
index 1479f8362e04e..04f3d46d4c3f3 100644

[ ... ]

Quoted 10 lines
drivers/net/wwan/qcom_bam_dmux.c +1 -1
@@ -821,7 +913,7 @@ static int bam_dmux_probe(struct platform_device *pdev)
 		goto err_disable_pm;
 
 	ret = devm_request_threaded_irq(dev, dmux->pc_irq, NULL, bam_dmux_pc_irq,
-					IRQF_ONESHOT, NULL, dmux);
+					IRQF_ONESHOT | IRQF_NO_AUTOEN, NULL, dmux);
 	if (ret)
 		goto err_disable_pm;
 

drivers/net/wwan/qcom_bam_dmux.c static int bam_dmux_probe(struct platform_device *pdev) · line 935

Quoted 6 lines
drivers/net/wwan/qcom_bam_dmux.c +2 -0
@@ -838,11 +930,14 @@ static int bam_dmux_probe(struct platform_device *pdev)
 			bam_dmux_power_off(dmux);
 	}
 
+	enable_irq(dmux->pc_irq);
+
 	return 0;

[Severity: Medium]
Can requesting dmux->pc_irq with IRQF_NO_AUTOEN drop a power-control edge between irq_get_irqchip_state() and enable_irq(), permanently inverting dmux->pc_state?

CPU0 Remote modem
bam_dmux_probe()
devm_request_threaded_irq(...,

    IRQF_NO_AUTOEN, ...)
  irq_get_irqchip_state(...,
    &dmux->pc_state) -> false
                                  toggles pc line (0 -> 1)

enable_irq(dmux->pc_irq)
smsm_unmask_irq() / smp2p
caches remote_state = 1 <-- edge lost, pc_state stays false

With IRQF_NO_AUTOEN, dmux->pc_irq stays unstarted in the underlying Qualcomm shared-memory irqchip (qcom,smsm or qcom,smp2p) while bam_dmux_probe() samples the initial line level and handles initial power on. Neither irqchip latches transitions that happen before enable_irq():

drivers/soc/qcom/smsm.c:smsm_unmask_irq() {
	...
	/* Make sure our last cached state is up-to-date */
	assign_bit(irq, &entry->last_value,
		   readl(entry->remote_state) & BIT(irq));

	set_bit(irq, entry->irq_enabled);
	...
}

drivers/soc/qcom/smp2p.c:qcom_smp2p_notify_in() similarly updates entry->last_value for all bits while only delivering interrupts for bits already set in entry->irq_enabled.

Because bam_dmux_pc_irq() tracks state by toggling
new_state = !dmux->pc_state on each edge rather than reading the line level, missing an edge before enable_irq() leaves dmux->pc_state inverted for the lifetime of the driver, breaking power control and DMA pool reclaim on remove.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20261112-qcom-bam-dmux-vmid-ext-v6-0-7a16bd3dff18@oss.qualcomm.com?part=2
#6 lore raw

Re: [PATCH net-next v6 2/2] net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

Quoted 71 lines · On 13-11-2026 02:44 pm, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: wwan: qcom_bam_dmux: lost PC edge in bam_dmux_probe() with IRQF_NO_AUTOEN
--

commit 4515119c8a0e425457d7366d017600d0d4e872df
Author: Vishnu Santhosh <[email protected]>

net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

This commit assigns a restricted DMA pool to both the local and remote execution environments via SCM when qcom,vmid is present, reclaims the pool on teardown, and defers enabling pc_irq until the end of probe.

Quoted 4 lines
drivers/net/wwan/qcom_bam_dmux.c +0 -0
index 1479f8362e04e..04f3d46d4c3f3 100644

[ ... ]

Quoted 10 lines
drivers/net/wwan/qcom_bam_dmux.c +1 -1
@@ -821,7 +913,7 @@ static int bam_dmux_probe(struct platform_device *pdev)
  		goto err_disable_pm;
 
  	ret = devm_request_threaded_irq(dev, dmux->pc_irq, NULL, bam_dmux_pc_irq,
-					IRQF_ONESHOT, NULL, dmux);
+					IRQF_ONESHOT | IRQF_NO_AUTOEN, NULL, dmux);
  	if (ret)
  		goto err_disable_pm;
 

drivers/net/wwan/qcom_bam_dmux.c static int bam_dmux_probe(struct platform_device *pdev) · line 935

Quoted 6 lines
drivers/net/wwan/qcom_bam_dmux.c +2 -0
@@ -838,11 +930,14 @@ static int bam_dmux_probe(struct platform_device *pdev)
  			bam_dmux_power_off(dmux);
  	}
 
+	enable_irq(dmux->pc_irq);
+
  	return 0;

[Severity: Medium]
Can requesting dmux->pc_irq with IRQF_NO_AUTOEN drop a power-control edge between irq_get_irqchip_state() and enable_irq(), permanently inverting dmux->pc_state?

CPU0 Remote modem
bam_dmux_probe()
devm_request_threaded_irq(...,

     IRQF_NO_AUTOEN, ...)
   irq_get_irqchip_state(...,
     &dmux->pc_state) -> false
                                   toggles pc line (0 -> 1)

enable_irq(dmux->pc_irq)
smsm_unmask_irq() / smp2p
caches remote_state = 1 <-- edge lost, pc_state stays false

With IRQF_NO_AUTOEN, dmux->pc_irq stays unstarted in the underlying Qualcomm shared-memory irqchip (qcom,smsm or qcom,smp2p) while bam_dmux_probe() samples the initial line level and handles initial power on. Neither irqchip latches transitions that happen before enable_irq():

drivers/soc/qcom/smsm.c:smsm_unmask_irq() {
	...
	/* Make sure our last cached state is up-to-date */
	assign_bit(irq, &entry->last_value,
		   readl(entry->remote_state) & BIT(irq));

	set_bit(irq, entry->irq_enabled);
	...
}

drivers/soc/qcom/smp2p.c:qcom_smp2p_notify_in() similarly updates entry->last_value for all bits while only delivering interrupts for bits already set in entry->irq_enabled.

Quoted 5 lines

Because bam_dmux_pc_irq() tracks state by toggling
new_state = !dmux->pc_state on each edge rather than reading the line level, missing an edge before enable_irq() leaves dmux->pc_state inverted for the lifetime of the driver, breaking power control and DMA pool reclaim on remove.

Yes, a PC transition in this window is not seen, since the SMSM irqchip resynchronizes its cached state on enable_irq(). This was a known trade off when moving to IRQF_NO_AUTOEN.

Making bam_dmux_pc_irq() derive the state from the line level instead of toggling, and re-checking it after enable_irq(), would close this window. This changes the PC handshake on all BAM-DMUX platforms and can be addressed in a separate patch if needed.

Thanks,
Vishnu

Quoted 1 line
#7 lore raw

Re: [PATCH net-next v6 2/2] net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

In reply to Vishnu Santhosh
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The patch does not do what the commit message says for BAM descriptor FIFOs.
- [Medium] The driver can unbind while the restricted DMA pool is still assigned to {HLOS, vmid}, and then it loses the only record of that.
- [Medium] Requesting the PC IRQ with IRQF_NO_AUTOEN and enabling it only at the end of bam_dmux_probe() means any change in the remote's power-…
- [Medium] bam_dmux_remove() decides whether to take the restricted DMA pool away from the remote VM using the cached software flag…

--

net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

When qcom,vmid is present, this patch requires a restricted DMA pool to be attached to the device. It then calls qcom_scm_assign_mem() to share that pool between HLOS and the modem VMID before the DMA channels are requested. The pool is handed back to HLOS on remove or on a probe error, unless the remote still holds its power vote, and the PC IRQ is now requested with IRQF_NO_AUTOEN and enabled at the end of probe.

Quoted 4 lines
drivers/net/wwan/qcom_bam_dmux.c +0 -0
index 1479f8362e04e..04f3d46d4c3f3 100644

[ ... ]

Quoted 11 lines
drivers/net/wwan/qcom_bam_dmux.c +7 -0
@@ -760,6 +766,88 @@ static int __maybe_unused bam_dmux_runtime_resume(struct device *dev)
 	return 0;
 }
 
+static int bam_dmux_assign_dma_pool(struct bam_dmux *dmux)
+{
+	struct device *dev = dmux->dev;
+	struct device_node *rmem_np;
+	struct reserved_mem *rmem;
+	struct qcom_scm_vmperm dst[2];
+	u64 src = BIT_ULL(QCOM_SCM_VMID_HLOS);

[ ... ]

drivers/net/wwan/qcom_bam_dmux.c static int __maybe_unused bam_dmux_runtime_resume(struct device *dev) · line 805

Quoted 3 lines
drivers/net/wwan/qcom_bam_dmux.c +3 -0
+	if (!is_swiotlb_for_alloc(dev))
+		return dev_err_probe(dev, -EINVAL,
+				     "Restricted DMA pool not attached\n");

[Severity: Medium]
Does this cover the BAM descriptor FIFOs the way the commit message describes? The commit message says:

"BAM-DMUX DMA mappings and BAM descriptor FIFOs must therefore be constrained to a designated memory region"

and:

"When the BAM DMA controller references the same pool, its descriptor FIFOs are covered by the assignment as well."

The FIFOs are allocated on the BAM DMA controller's own device, not on dmux->dev:

drivers/dma/qcom/bam_dma.c:bam_alloc_chan() {
    ...
	bchan->fifo_virt = dma_alloc_wc(bdev->dev, BAM_DESC_FIFO_SIZE,
					&bchan->fifo_phys, GFP_KERNEL);
    ...
}

The FIFOs only come from the restricted pool if the BAM DMA node has its own memory-region that points at the restricted-dma-pool. The binding doesn't allow that. qcom,bam-dma.yaml has no memory-region property and sets additionalProperties: false, and this series only updates qcom,bam-dmux.yaml.

The check here only looks at is_swiotlb_for_alloc(dmux->dev). Nothing checks the device behind the rx/tx channels.

With a DT that follows the bindings, probe would succeed without a warning. Meanwhile, bam_dmux_power_on()->dma_request_chan()-> bam_alloc_chan() would allocate the FIFOs outside the assigned region. Wouldn't that leave the XPU violation the patch is meant to prevent?

Is a bam-dma binding update or a check on the channel device needed here?

[ ... ]

Quoted 8 lines
drivers/net/wwan/qcom_bam_dmux.c +8 -0
+static void bam_dmux_reclaim_dma_pool(struct bam_dmux *dmux)
+{
+	struct qcom_scm_vmperm hlos = {
+		.vmid = QCOM_SCM_VMID_HLOS,
+		.perm = QCOM_SCM_PERM_RW,
+	};
+	u64 src = dmux->dma_pool_perms;
+	int ret;

drivers/net/wwan/qcom_bam_dmux.c static int __maybe_unused bam_dmux_runtime_resume(struct device *dev) · line 846

Quoted 10 lines
drivers/net/wwan/qcom_bam_dmux.c +10 -0
+
+	if (!dmux->dma_pool_perms)
+		return;
+
+	ret = qcom_scm_assign_mem(dmux->dma_pool_base, dmux->dma_pool_size, &src,
+				  &hlos, 1);
+	if (ret) {
+		dev_err(dmux->dev, "SCM reclaim restricted DMA pool failed: %d\n", ret);
+		return;
+	}

[Severity: Medium]
What happens to the pool ownership when this call fails? The same question applies when bam_dmux_remove() skips the reclaim on purpose because pc_state is still set:

	if (!dmux->pc_state)
		bam_dmux_reclaim_dma_pool(dmux);
	else if (dmux->dma_pool_perms)
		dev_warn(dev, "Leaving restricted DMA pool assigned to remote\n");

In both cases the region stays assigned to HLOS and the modem VMID. The only record of that is dmux->dma_pool_perms, which lives in the devm_kzalloc'd struct bam_dmux. devres frees it as soon as remove() or the failed probe returns.

On the next probe (module reload, sysfs rebind, deferred re-probe), bam_dmux_assign_dma_pool() always starts from:

	u64 src = BIT_ULL(QCOM_SCM_VMID_HLOS);

That no longer matches the real owners (HLOS | vmid). Hyp-assign checks the source VM list against the current ownership, which is why users such as rmtfs_mem keep their perms around for the reclaim.

Wouldn't qcom_scm_assign_mem() then fail with "SCM assign restricted DMA pool failed" on every probe until reboot?

The commit message says the execution environments are tracked explicitly for the reclaim. Isn't that record lost in exactly the unbind case it is meant to handle?

Quoted 3 lines
drivers/net/wwan/qcom_bam_dmux.c +3 -0
+
+	dmux->dma_pool_perms = 0;
+}

[ ... ]

Quoted 10 lines
drivers/net/wwan/qcom_bam_dmux.c +1 -1
@@ -821,7 +913,7 @@ static int bam_dmux_probe(struct platform_device *pdev)
 		goto err_disable_pm;
 
 	ret = devm_request_threaded_irq(dev, dmux->pc_irq, NULL, bam_dmux_pc_irq,
-					IRQF_ONESHOT, NULL, dmux);
+					IRQF_ONESHOT | IRQF_NO_AUTOEN, NULL, dmux);
 	if (ret)
 		goto err_disable_pm;
 

drivers/net/wwan/qcom_bam_dmux.c static int bam_dmux_probe(struct platform_device *pdev) · line 933

Quoted 4 lines
drivers/net/wwan/qcom_bam_dmux.c +1 -0
@@ -838,11 +930,14 @@ static int bam_dmux_probe(struct platform_device *pdev)
 			bam_dmux_power_off(dmux);
 	}
 
+	enable_irq(dmux->pc_irq);

[Severity: Medium]
Can a remote power-control transition get lost between the line-level sample and this enable_irq()? In bam_dmux_probe() the sequence is now:

	ret = irq_get_irqchip_state(dmux->pc_irq, IRQCHIP_STATE_LINE_LEVEL,
				    &dmux->pc_state);
	...
	if (dmux->pc_state) {
		if (bam_dmux_power_on(dmux))
	...
	enable_irq(dmux->pc_irq);

With IRQF_NO_AUTOEN, __setup_irq() skips irq_startup(), so the smp2p and smsm unmask callbacks don't run until enable_irq(). During that window, qcom_smp2p_notify_in() still updates last_value but only dispatches bits set in irq_enabled:

drivers/soc/qcom/smp2p.c:qcom_smp2p_notify_in() {
    ...
		status = val ^ entry->last_value;
		entry->last_value = val;
    ...
		for_each_set_bit(i, entry->irq_enabled, 32) {
    ...
}

smsm_intr() also updates last_value, and smsm_unmask_irq() resyncs the cached state when the IRQ is enabled:

drivers/soc/qcom/smsm.c:smsm_unmask_irq() {
    ...
	/* Make sure our last cached state is up-to-date */
	assign_bit(irq, &entry->last_value,
		   readl(entry->remote_state) & BIT(irq));
    ...
}

handle_nested_irq() is never called, so IRQS_PENDING is never set and enable_irq() has nothing to resend.

bam_dmux_pc_irq() flips the cached value instead of reading the line:

	bool new_state = !dmux->pc_state;

A single missed edge would therefore leave the driver's view inverted from then on. The remote's transition is never acked, later edges are handled with the wrong polarity, and the pc_state check in bam_dmux_remove() that gates the pool reclaim is wrong too.

When the modem is already up at probe time, the window also covers bam_dmux_power_on() (dma_request_chan(), skb allocation, DMA mapping). IRQF_NO_AUTOEN is set unconditionally. Wouldn't this regression affect every BAM-DMUX platform, not just the ones with qcom,vmid?

Quoted 11 lines
drivers/net/wwan/qcom_bam_dmux.c +1 -0
 	return 0;
 
 err_disable_pm:
 	pm_runtime_disable(dev);
 	pm_runtime_dont_use_autosuspend(dev);
+	bam_dmux_reclaim_dma_pool(dmux);
 	return ret;
 }
 

drivers/net/wwan/qcom_bam_dmux.c static void bam_dmux_remove(struct platform_device *pdev) · line 980

Quoted 9 lines
drivers/net/wwan/qcom_bam_dmux.c +6 -0
@@ -877,6 +972,12 @@ static void bam_dmux_remove(struct platform_device *pdev)
 	disable_irq(dmux->pc_irq);
 	bam_dmux_power_off(dmux);
 	bam_dmux_free_skbs(dmux->tx_skbs, DMA_TO_DEVICE);
+
+	/* The remote side may still access the pool if it holds its power vote */
+	if (!dmux->pc_state)
+		bam_dmux_reclaim_dma_pool(dmux);
+	else if (dmux->dma_pool_perms)
+		dev_warn(dev, "Leaving restricted DMA pool assigned to remote\n");

[Severity: Medium]
Can dmux->pc_state still be trusted at this point? Once disable_irq(dmux->pc_irq) has run above, bam_dmux_pc_irq() no longer runs. pc_state then shows the last edge that was processed, not the remote's current power vote.

The RX side is started by the remote. The comment in probe says "the RX path may be active even if we are runtime suspended, since it is controlled by the remote side".

Suppose the remote raises its vote after disable_irq(), or pc_state is already inverted by the lost edge in bam_dmux_probe(). This code would still call bam_dmux_reclaim_dma_pool() and remove the modem VMID while the remote holds its vote.

That seems to contradict the commit message:

"Skip the reclaim and leave the pool assigned if the remote side still holds its power vote, since it may still access the pool."

Should the line level be read again here before deciding whether to reclaim, for example with irq_get_irqchip_state(dmux->pc_irq, IRQCHIP_STATE_LINE_LEVEL, ...)?

Quoted 1 line
drivers/net/wwan/qcom_bam_dmux.c +0 -0
 }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-qcom-bam-dmux-vmid-ext-v6-0-7a16bd3dff18%40oss.qualcomm.com
#8 lore raw

Re: [PATCH net-next v6 2/2] net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

Quoted 84 lines · On 16-11-2026 07:24 pm, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The patch does not do what the commit message says for BAM descriptor FIFOs.
- [Medium] The driver can unbind while the restricted DMA pool is still assigned to {HLOS, vmid}, and then it loses the only record of that.
- [Medium] Requesting the PC IRQ with IRQF_NO_AUTOEN and enabling it only at the end of bam_dmux_probe() means any change in the remote's power-…
- [Medium] bam_dmux_remove() decides whether to take the restricted DMA pool away from the remote VM using the cached software flag…

--

net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

When qcom,vmid is present, this patch requires a restricted DMA pool to be attached to the device. It then calls qcom_scm_assign_mem() to share that pool between HLOS and the modem VMID before the DMA channels are requested. The pool is handed back to HLOS on remove or on a probe error, unless the remote still holds its power vote, and the PC IRQ is now requested with IRQF_NO_AUTOEN and enabled at the end of probe.

Quoted 4 lines
drivers/net/wwan/qcom_bam_dmux.c +0 -0
index 1479f8362e04e..04f3d46d4c3f3 100644

[ ... ]

Quoted 11 lines
drivers/net/wwan/qcom_bam_dmux.c +7 -0
@@ -760,6 +766,88 @@ static int __maybe_unused bam_dmux_runtime_resume(struct device *dev)
  	return 0;
  }
 
+static int bam_dmux_assign_dma_pool(struct bam_dmux *dmux)
+{
+	struct device *dev = dmux->dev;
+	struct device_node *rmem_np;
+	struct reserved_mem *rmem;
+	struct qcom_scm_vmperm dst[2];
+	u64 src = BIT_ULL(QCOM_SCM_VMID_HLOS);

[ ... ]

drivers/net/wwan/qcom_bam_dmux.c static int __maybe_unused bam_dmux_runtime_resume(struct device *dev) · line 805

Quoted 3 lines
drivers/net/wwan/qcom_bam_dmux.c +3 -0
+	if (!is_swiotlb_for_alloc(dev))
+		return dev_err_probe(dev, -EINVAL,
+				     "Restricted DMA pool not attached\n");

[Severity: Medium]
Does this cover the BAM descriptor FIFOs the way the commit message describes? The commit message says:

"BAM-DMUX DMA mappings and BAM descriptor FIFOs must therefore be constrained to a designated memory region"

and:

"When the BAM DMA controller references the same pool, its descriptor FIFOs are covered by the assignment as well."

The FIFOs are allocated on the BAM DMA controller's own device, not on dmux->dev:

drivers/dma/qcom/bam_dma.c:bam_alloc_chan() {
     ...
	bchan->fifo_virt = dma_alloc_wc(bdev->dev, BAM_DESC_FIFO_SIZE,
					&bchan->fifo_phys, GFP_KERNEL);
     ...
}

The FIFOs only come from the restricted pool if the BAM DMA node has its own memory-region that points at the restricted-dma-pool. The binding doesn't allow that. qcom,bam-dma.yaml has no memory-region property and sets additionalProperties: false, and this series only updates qcom,bam-dmux.yaml.

The check here only looks at is_swiotlb_for_alloc(dmux->dev). Nothing checks the device behind the rx/tx channels.

Quoted 7 lines

With a DT that follows the bindings, probe would succeed without a warning. Meanwhile, bam_dmux_power_on()->dma_request_chan()-> bam_alloc_chan() would allocate the FIFOs outside the assigned region. Wouldn't that leave the XPU violation the patch is meant to prevent?

Is a bam-dma binding update or a check on the channel device needed here?

This is covered by the separate BAM DMA binding change:
https://lore.kernel.org/all/20261021-qcom-bam-dma-vmid-ext-v3-1-299355e8dd3b@oss.qualcomm.com/

Quoted 45 lines

[ ... ]

Quoted 8 lines
drivers/net/wwan/qcom_bam_dmux.c +8 -0
+static void bam_dmux_reclaim_dma_pool(struct bam_dmux *dmux)
+{
+	struct qcom_scm_vmperm hlos = {
+		.vmid = QCOM_SCM_VMID_HLOS,
+		.perm = QCOM_SCM_PERM_RW,
+	};
+	u64 src = dmux->dma_pool_perms;
+	int ret;

drivers/net/wwan/qcom_bam_dmux.c static int __maybe_unused bam_dmux_runtime_resume(struct device *dev) · line 846

Quoted 10 lines
drivers/net/wwan/qcom_bam_dmux.c +10 -0
+
+	if (!dmux->dma_pool_perms)
+		return;
+
+	ret = qcom_scm_assign_mem(dmux->dma_pool_base, dmux->dma_pool_size, &src,
+				  &hlos, 1);
+	if (ret) {
+		dev_err(dmux->dev, "SCM reclaim restricted DMA pool failed: %d\n", ret);
+		return;
+	}

[Severity: Medium]
What happens to the pool ownership when this call fails? The same question applies when bam_dmux_remove() skips the reclaim on purpose because pc_state is still set:

	if (!dmux->pc_state)
		bam_dmux_reclaim_dma_pool(dmux);
	else if (dmux->dma_pool_perms)
		dev_warn(dev, "Leaving restricted DMA pool assigned to remote\n");

In both cases the region stays assigned to HLOS and the modem VMID. The only record of that is dmux->dma_pool_perms, which lives in the devm_kzalloc'd struct bam_dmux. devres frees it as soon as remove() or the failed probe returns.

On the next probe (module reload, sysfs rebind, deferred re-probe), bam_dmux_assign_dma_pool() always starts from:

	u64 src = BIT_ULL(QCOM_SCM_VMID_HLOS);

That no longer matches the real owners (HLOS | vmid). Hyp-assign checks the source VM list against the current ownership, which is why users such as rmtfs_mem keep their perms around for the reclaim.

Quoted 6 lines

Wouldn't qcom_scm_assign_mem() then fail with "SCM assign restricted DMA pool failed" on every probe until reboot?

The commit message says the execution environments are tracked explicitly for the reclaim. Isn't that record lost in exactly the unbind case it is meant to handle?

The tracked permissions are used for the reclaim in remove(). If the reclaim is skipped or fails, the pool stays assigned, which is fail-safe, since the pool is static reserved memory that is never returned to the page allocator. This matches the existing qcom_scm_assign_mem() users, which also only log reclaim failures.

Quoted 69 lines
Quoted 4 lines
drivers/net/wwan/qcom_bam_dmux.c +3 -0
+
+	dmux->dma_pool_perms = 0;
+}

[ ... ]

Quoted 10 lines
drivers/net/wwan/qcom_bam_dmux.c +1 -1
@@ -821,7 +913,7 @@ static int bam_dmux_probe(struct platform_device *pdev)
  		goto err_disable_pm;
 
  	ret = devm_request_threaded_irq(dev, dmux->pc_irq, NULL, bam_dmux_pc_irq,
-					IRQF_ONESHOT, NULL, dmux);
+					IRQF_ONESHOT | IRQF_NO_AUTOEN, NULL, dmux);
  	if (ret)
  		goto err_disable_pm;
 

drivers/net/wwan/qcom_bam_dmux.c static int bam_dmux_probe(struct platform_device *pdev) · line 933

Quoted 4 lines
drivers/net/wwan/qcom_bam_dmux.c +1 -0
@@ -838,11 +930,14 @@ static int bam_dmux_probe(struct platform_device *pdev)
  			bam_dmux_power_off(dmux);
  	}
 
+	enable_irq(dmux->pc_irq);

[Severity: Medium]
Can a remote power-control transition get lost between the line-level sample and this enable_irq()? In bam_dmux_probe() the sequence is now:

	ret = irq_get_irqchip_state(dmux->pc_irq, IRQCHIP_STATE_LINE_LEVEL,
				    &dmux->pc_state);
	...
	if (dmux->pc_state) {
		if (bam_dmux_power_on(dmux))
	...
	enable_irq(dmux->pc_irq);

With IRQF_NO_AUTOEN, __setup_irq() skips irq_startup(), so the smp2p and smsm unmask callbacks don't run until enable_irq(). During that window, qcom_smp2p_notify_in() still updates last_value but only dispatches bits set in irq_enabled:

drivers/soc/qcom/smp2p.c:qcom_smp2p_notify_in() {
     ...
		status = val ^ entry->last_value;
		entry->last_value = val;
     ...
		for_each_set_bit(i, entry->irq_enabled, 32) {
     ...
}

smsm_intr() also updates last_value, and smsm_unmask_irq() resyncs the cached state when the IRQ is enabled:

drivers/soc/qcom/smsm.c:smsm_unmask_irq() {
     ...
	/* Make sure our last cached state is up-to-date */
	assign_bit(irq, &entry->last_value,
		   readl(entry->remote_state) & BIT(irq));
     ...
}

handle_nested_irq() is never called, so IRQS_PENDING is never set and enable_irq() has nothing to resend.

bam_dmux_pc_irq() flips the cached value instead of reading the line:

	bool new_state = !dmux->pc_state;

A single missed edge would therefore leave the driver's view inverted from then on. The remote's transition is never acked, later edges are handled with the wrong polarity, and the pc_state check in bam_dmux_remove() that gates the pool reclaim is wrong too.

Quoted 4 lines

When the modem is already up at probe time, the window also covers bam_dmux_power_on() (dma_request_chan(), skb allocation, DMA mapping). IRQF_NO_AUTOEN is set unconditionally. Wouldn't this regression affect every BAM-DMUX platform, not just the ones with qcom,vmid?

Yes, this was a known trade-off when moving to IRQF_NO_AUTOEN. Closing the window needs a level-based bam_dmux_pc_irq(), which changes the PC handshake on all BAM-DMUX platforms and can be addressed in a separate patch if needed.

Quoted 36 lines
Quoted 12 lines
drivers/net/wwan/qcom_bam_dmux.c +1 -0
  	return 0;
 
  err_disable_pm:
  	pm_runtime_disable(dev);
  	pm_runtime_dont_use_autosuspend(dev);
+	bam_dmux_reclaim_dma_pool(dmux);
  	return ret;
  }
 

drivers/net/wwan/qcom_bam_dmux.c static void bam_dmux_remove(struct platform_device *pdev) · line 980

Quoted 9 lines
drivers/net/wwan/qcom_bam_dmux.c +6 -0
@@ -877,6 +972,12 @@ static void bam_dmux_remove(struct platform_device *pdev)
  	disable_irq(dmux->pc_irq);
  	bam_dmux_power_off(dmux);
  	bam_dmux_free_skbs(dmux->tx_skbs, DMA_TO_DEVICE);
+
+	/* The remote side may still access the pool if it holds its power vote */
+	if (!dmux->pc_state)
+		bam_dmux_reclaim_dma_pool(dmux);
+	else if (dmux->dma_pool_perms)
+		dev_warn(dev, "Leaving restricted DMA pool assigned to remote\n");

[Severity: Medium]
Can dmux->pc_state still be trusted at this point? Once disable_irq(dmux->pc_irq) has run above, bam_dmux_pc_irq() no longer runs. pc_state then shows the last edge that was processed, not the remote's current power vote.

The RX side is started by the remote. The comment in probe says "the RX path may be active even if we are runtime suspended, since it is controlled by the remote side".

Suppose the remote raises its vote after disable_irq(), or pc_state is already inverted by the lost edge in bam_dmux_probe(). This code would still call bam_dmux_reclaim_dma_pool() and remove the modem VMID while the remote holds its vote.

Quoted 8 lines

That seems to contradict the commit message:

"Skip the reclaim and leave the pool assigned if the remote side still holds its power vote, since it may still access the pool."

Should the line level be read again here before deciding whether to reclaim, for example with irq_get_irqchip_state(dmux->pc_irq, IRQCHIP_STATE_LINE_LEVEL, ...)?

In both cases, the reclaim runs after bam_dmux_power_off(), which has already reset the BAM pipes and freed their descriptor FIFOs, so no transfers that access the pool are left. A vote raised after disable_irq() is also never acked. Reading the line level here can be done together with the level-based PC handling mentioned above if needed.

Thanks,
Vishnu

Quoted 2 lines
Quoted 2 lines
drivers/net/wwan/qcom_bam_dmux.c +0 -0
  }
maintainer Reviewed-by on v6 2/2
#9 lore raw

Re: [PATCH net-next v6 2/2] net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor

In reply to Vishnu Santhosh
Quoted 24 lines · Vishnu Santhosh

Some Qualcomm SoCs, such as Shikra, run the modem in a separate security domain with restricted access to system memory. BAM-DMUX DMA mappings and BAM descriptor FIFOs must therefore be constrained to a designated memory region that can be shared with the modem. Accesses outside that region can trigger an XPU violation.

When qcom,vmid is present, require a restricted DMA pool and assign the entire pool to both the local and remote execution environments before requesting the DMA channels.

This ensures that BAM-DMUX mappings are within the assigned region. When the BAM DMA controller references the same pool, its descriptor FIFOs are covered by the assignment as well.

Track the assigned execution environments explicitly and reclaim the pool for the local environment after DMA channels and mappings are released during remove or probe error cleanup. Skip the reclaim and leave the pool assigned if the remote side still holds its power vote, since it may still access the pool.

Request the PC IRQ with IRQF_NO_AUTOEN and enable it only at the end of probe, so the probe error path cannot race with RX power-up.

Quoted 7 lines

Fail probing when restricted DMA pool support is unavailable, when the VMID property is malformed, when memory-region is missing, or when the restricted DMA pool is not attached to the device.

Quoted 190 lines
---
 drivers/net/wwan/Kconfig         |   1 +
 drivers/net/wwan/qcom_bam_dmux.c | 103 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 103 insertions(+), 1 deletion(-)
drivers/net/wwan/Kconfig +1 -0
index 958dbc7347fa84ee869439bf8b503037faab8bef..1b133c56231615269698140187ca3141dfe48dbf 100644
@@ -65,6 +65,7 @@ config MHI_WWAN_MBIM
 config QCOM_BAM_DMUX
        tristate "Qualcomm BAM-DMUX WWAN network driver"
        depends on (DMA_ENGINE && PM && QCOM_SMEM_STATE) || COMPILE_TEST
+       select QCOM_SCM
        help
          The BAM Data Multiplexer provides access to the network data channels
          of modems integrated into many older Qualcomm SoCs, e.g. Qualcomm
drivers/net/wwan/qcom_bam_dmux.c +102 -2
index 1479f8362e04e4a5f60219922dea3540921de13d..04f3d46d4c3f3e18cd5313a407b8096d04dd857f 100644
@@ -9,14 +9,17 @@
 #include <linux/completion.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
+#include <linux/firmware/qcom/qcom_scm.h>
 #include <linux/if_arp.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/soc/qcom/smem_state.h>
 #include <linux/spinlock.h>
+#include <linux/swiotlb.h>
 #include <linux/wait.h>
 #include <linux/workqueue.h>
 #include <net/pkt_sched.h>
@@ -75,6 +78,9 @@ struct bam_dmux {
        struct completion pc_ack_completion;
 
        struct dma_chan *rx, *tx;
+       phys_addr_t dma_pool_base;
+       size_t dma_pool_size;
+       u64 dma_pool_perms;
        struct bam_dmux_skb_dma rx_skbs[BAM_DMUX_NUM_SKB];
        struct bam_dmux_skb_dma tx_skbs[BAM_DMUX_NUM_SKB];
        spinlock_t tx_lock; /* Protect tx_skbs, tx_next_skb */
@@ -760,6 +766,88 @@ static int __maybe_unused bam_dmux_runtime_resume(struct device *dev)
        return 0;
 }
 
+static int bam_dmux_assign_dma_pool(struct bam_dmux *dmux)
+{
+       struct device *dev = dmux->dev;
+       struct device_node *rmem_np;
+       struct reserved_mem *rmem;
+       struct qcom_scm_vmperm dst[2];
+       u64 src = BIT_ULL(QCOM_SCM_VMID_HLOS);
+       u32 vmid;
+       int ret;
+
+       if (!of_property_present(dev->of_node, "qcom,vmid"))
+               return 0;
+
+       ret = of_property_read_u32(dev->of_node, "qcom,vmid", &vmid);
+       if (ret)
+               return dev_err_probe(dev, ret, "Failed to read qcom,vmid\n");
+       if (vmid == QCOM_SCM_VMID_HLOS || vmid >= BITS_PER_TYPE(u64))
+               return dev_err_probe(dev, -EINVAL, "Invalid qcom,vmid %u\n", vmid);
+
+       if (!IS_ENABLED(CONFIG_DMA_RESTRICTED_POOL))
+               return dev_err_probe(dev, -EOPNOTSUPP,
+                                    "qcom,vmid requires DMA_RESTRICTED_POOL\n");
+
+       rmem_np = of_parse_phandle(dev->of_node, "memory-region", 0);
+       if (!rmem_np)
+               return dev_err_probe(dev, -EINVAL,
+                                            "qcom,vmid requires memory-region\n");
+
+       rmem = of_reserved_mem_lookup(rmem_np);
+       of_node_put(rmem_np);
+       if (!rmem)
+               return dev_err_probe(dev, -EINVAL,
+                                            "Failed to look up restricted DMA pool\n");
+
+       if (!is_swiotlb_for_alloc(dev))
+               return dev_err_probe(dev, -EINVAL,
+                                    "Restricted DMA pool not attached\n");
+
+       if (!qcom_scm_is_available())
+               return -EPROBE_DEFER;
+
+       dst[0].vmid = QCOM_SCM_VMID_HLOS;
+       dst[0].perm = QCOM_SCM_PERM_RW;
+       dst[1].vmid = vmid;
+       dst[1].perm = QCOM_SCM_PERM_RW;
+
+       ret = qcom_scm_assign_mem(rmem->base, rmem->size, &src, dst,
+                                 ARRAY_SIZE(dst));
+       if (ret)
+               return dev_err_probe(dev, ret,
+                                    "SCM assign restricted DMA pool failed\n");
+
+       dmux->dma_pool_base = rmem->base;
+       dmux->dma_pool_size = rmem->size;
+       /* Track the destination VMIDs explicitly for the reclaim operation. */
+       dmux->dma_pool_perms = BIT_ULL(QCOM_SCM_VMID_HLOS) | BIT_ULL(vmid);
+
+       return 0;
+}
+
+static void bam_dmux_reclaim_dma_pool(struct bam_dmux *dmux)
+{
+       struct qcom_scm_vmperm hlos = {
+               .vmid = QCOM_SCM_VMID_HLOS,
+               .perm = QCOM_SCM_PERM_RW,
+       };
+       u64 src = dmux->dma_pool_perms;
+       int ret;
+
+       if (!dmux->dma_pool_perms)
+               return;
+
+       ret = qcom_scm_assign_mem(dmux->dma_pool_base, dmux->dma_pool_size, &src,
+                                 &hlos, 1);
+       if (ret) {
+               dev_err(dmux->dev, "SCM reclaim restricted DMA pool failed: %d\n", ret);
+               return;
+       }
+
+       dmux->dma_pool_perms = 0;
+}
+
 static int bam_dmux_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
@@ -794,6 +882,10 @@ static int bam_dmux_probe(struct platform_device *pdev)
                                     "Failed to get pc-ack state\n");
        dmux->pc_ack_mask = BIT(bit);
 
+       ret = bam_dmux_assign_dma_pool(dmux);
+       if (ret)
+               return ret;
+
        init_waitqueue_head(&dmux->pc_wait);
        init_completion(&dmux->pc_ack_completion);
        complete_all(&dmux->pc_ack_completion);
@@ -821,7 +913,7 @@ static int bam_dmux_probe(struct platform_device *pdev)
                goto err_disable_pm;
 
        ret = devm_request_threaded_irq(dev, dmux->pc_irq, NULL, bam_dmux_pc_irq,
-                                       IRQF_ONESHOT, NULL, dmux);
+                                       IRQF_ONESHOT | IRQF_NO_AUTOEN, NULL, dmux);
        if (ret)
                goto err_disable_pm;
 
@@ -838,11 +930,14 @@ static int bam_dmux_probe(struct platform_device *pdev)
                        bam_dmux_power_off(dmux);
        }
 
+       enable_irq(dmux->pc_irq);
+
        return 0;
 
 err_disable_pm:
        pm_runtime_disable(dev);
        pm_runtime_dont_use_autosuspend(dev);
+       bam_dmux_reclaim_dma_pool(dmux);
        return ret;
 }
 
@@ -877,6 +972,12 @@ static void bam_dmux_remove(struct platform_device *pdev)
        disable_irq(dmux->pc_irq);
        bam_dmux_power_off(dmux);
        bam_dmux_free_skbs(dmux->tx_skbs, DMA_TO_DEVICE);
+
+       /* The remote side may still access the pool if it holds its power vote */
+       if (!dmux->pc_state)
+               bam_dmux_reclaim_dma_pool(dmux);
+       else if (dmux->dma_pool_perms)
+               dev_warn(dev, "Leaving restricted DMA pool assigned to remote\n");
 }
 
 static const struct dev_pm_ops bam_dmux_pm_ops = {
 
--

2.34.1

#10 lore raw
In reply to Vishnu Santhosh
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 6 lines · On Thu, 12 Nov 2026 14:43:30 +0530 you wrote:

Some Qualcomm SoCs, such as Shikra, run the modem in a separate security domain with restricted access to system memory. BAM-DMUX DMA mappings and BAM descriptor FIFOs must therefore be constrained to a designated memory region that can be shared with the modem. Accesses outside that region can trigger an XPU violation.

Quoted 7 lines

Add memory-region and qcom,vmid properties to the BAM-DMUX binding, and a qcom,shikra-bam-dmux compatible that requires them. When qcom,vmid is present, the driver SCM-assigns the entire restricted DMA pool to the local and remote execution environments before requesting the DMA channels.

[...]

Here is the summary with links:
- [net-next,v6,1/2] dt-bindings: net: qcom,bam-dmux: Add memory-region and qcom,vmid properties

    https://git.kernel.org/netdev/net-next/c/ed5087bd84ec
  - [net-next,v6,2/2] net: wwan: qcom_bam_dmux: Assign restricted DMA pool to remote processor
    https://git.kernel.org/netdev/net-next/c/a5ce83fc0b37

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html