ASoC: qcom: enable audio on stage-2 protected DSPs (mDSP)
Subsystems (5)
v5 cover ASoC: qcom: enable audio on stage-2 protected DSPs (mDSP)
On platforms such as Qualcomm Shikra, audio is served by the modem DSP (mDSP) rather than the ADSP. The mDSP runs in a stage-2 protected context and cannot use the SMMU, so the PCM buffers it consumes must live in reserved-memory carveouts that are handed to the consumer VMIDs via a hypervisor (SCM) memory assignment. This series adds that access model to the q6apm DAI driver and its binding, alongside the existing stage-1/SMMU (iommus) path, which is left untouched.
The driver detects the mDSP target at runtime from the GPR domain_id (GPR_DOMAIN_ID_MODEM) and enables the SCM assignment path automatically. VMIDs are hardcoded in the driver (HLOS + MSS_MSA + LPASS) rather than read from DT, following the consensus from v2 review discussion with Krzysztof Kozlowski and Srinivas Kandagatla.
Tested on Qualcomm Shikra with mDSP audio playback and capture.
Prior versions:
v1 (VMID binding + driver + GPR domain):
https://lore.kernel.org/all/[email protected]/
v1 (memory-region binding + DTS):
https://lore.kernel.org/all/[email protected]/
v2:
https://lore.kernel.org/all/[email protected]/
v3:
https://lore.kernel.org/all/[email protected]/
v4:
https://lore.kernel.org/all/[email protected]/
Changes since v4:
- Resend — v4 was partially delivered due to SMTP failure, no code changes.
Changes since v3:
- Split DT binding changes into a separate patch (3/4) from the driver implementation (4/4). (Rob Herring)
- SCM-assign the data-path pool (memory-region[1]) as a single whole-pool operation at probe instead of per-stream in pcm_new()/compr_open().
- SCM-assign compressed audio stream buffers in compr_open() and unassign in compr_free() when no data-path pool is present. v3 only covered PCM streams.
- Fix error path in pcm_new: unassign SCM region if memory_map fails after a successful SCM assign, preventing a resource leak.
- Account for PAGE_SIZE padding in reserved-memory pool budget calculation. v3 under-reserved by PAGE_SIZE per stream, which could overflow the pool at maximum concurrent stream count.
---
Ajay Kumar Nandam (4):
ASoC: qcom: q6apm: clear g_apm on driver removal
ASoC: qcom: qdsp6: generalize GPR service domain
dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
ASoC: qcom: q6apm-dai: add SCM buffer assignment for mDSP platforms
.../devicetree/bindings/sound/qcom,q6apm-dai.yaml | 12 +- sound/soc/qcom/Kconfig | 1 + sound/soc/qcom/qdsp6/audioreach.c | 12 +- sound/soc/qcom/qdsp6/audioreach.h | 22 +- sound/soc/qcom/qdsp6/q6apm-dai.c | 300 +++++++++++++++++++-- sound/soc/qcom/qdsp6/q6apm.c | 9 +- sound/soc/qcom/qdsp6/q6apm.h | 2 +- sound/soc/qcom/qdsp6/q6prm.c | 2 + 8 files changed, 326 insertions(+), 34 deletions(-)
---
base-commit: 3d5670d672ae08b8c534b7beed6f57c8b44e7b43
change-id: 20260921-vmid-v4-0116efe5937b
Best regards,
Signature · 1 line
Ajay Kumar Nandam <[email protected]>
PATCH v5 1/4 ASoC: qcom: q6apm: clear g_apm on driver removal
The global g_apm pointer is set during apm_probe() but never cleared in apm_remove(). After the driver is removed the devm-managed struct q6apm is freed, leaving g_apm dangling. A subsequent call to q6apm_is_adsp_ready() dereferences the freed pointer.
Clear g_apm in apm_remove() before the component is unregistered so that q6apm_is_adsp_ready() returns false instead of triggering a use-after-free.
--- sound/soc/qcom/qdsp6/q6apm.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/qcom/qdsp6/q6apm.c +1 -0
@@ -894,6 +894,7 @@ static int apm_probe(gpr_device_t *gdev)static void apm_remove (gpr_device_t *gdev) { + g_apm =NULL ;of_platform_depopulate (&gdev->dev);snd_soc_unregister_component (&gdev->dev); }
Signature · 1 line
2.34.1
PATCH v5 2/4 ASoC: qcom: qdsp6: generalize GPR service domain
In reply to Ajay Kumar NandamAudioReach builds APM and PRM command packets with the GPR destination domain hardcoded to GPR_DOMAIN_ID_ADSP. This assumes audio is always served by the ADSP, which is true for all currently supported targets.
On platforms such as Qualcomm Shikra, audio is served by the modem DSP (mDSP) instead. The GPR node in DT already describes which DSP backs the service via its qcom,domain property (e.g. GPR_DOMAIN_ID_MODEM), and the GPR core exposes it as gdev->domain_id. But the AudioReach packet builders ignore this and always target the ADSP, so every APM/PRM command is routed to the wrong DSP on mDSP targets and audio does not function.
Fix this by reading the GPR destination domain from gdev->domain_id and stamping it in the send helpers (q6apm_send_cmd_sync, audioreach_graph_send_cmd_sync, q6prm_send_cmd_sync) just before dispatch. This centralizes the domain decision at the send layer rather than threading it through every packet-allocation call site. For the small number of async data-path sends that bypass the sync helpers (write, read, compr, EOS), the domain is stamped inline before gpr_send_port_pkt(). When no domain is available the helper falls back to GPR_DOMAIN_ID_ADSP, so all existing ADSP targets remain unchanged.
--- sound/soc/qcom/qdsp6/audioreach.c | 12 +++++++++--- sound/soc/qcom/qdsp6/audioreach.h | 22 +++++++++++++++------- sound/soc/qcom/qdsp6/q6apm.c | 8 +++++++- sound/soc/qcom/qdsp6/q6apm.h | 2 +- sound/soc/qcom/qdsp6/q6prm.c | 2 ++ 5 files changed, 34 insertions(+), 12 deletions(-)
sound/soc/qcom/qdsp6/audioreach.c +9 -3
@@ -579,10 +579,10 @@ EXPORT_SYMBOL_GPL(audioreach_alloc_graph_pkt);int audioreach_send_cmd_sync (struct device *dev,gpr_device_t *gdev,struct gpr_ibasic_rsp_result_t *result,struct mutex *cmd_lock,gpr_port_t *port,wait_queue_head_t *cmd_wait, -const struct gpr_pkt *pkt,uint32_t rsp_opcode) +struct gpr_pkt *pkt,uint32_t rsp_opcode) { -const struct gpr_hdr *hdr = &pkt->hdr; +struct gpr_hdr *hdr = &pkt->hdr;int rc;mutex_lock (cmd_lock);
@@ -622,10 +622,12 @@ int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev, }EXPORT_SYMBOL_GPL (audioreach_send_cmd_sync); -int audioreach_graph_send_cmd_sync (struct q6apm_graph *graph,const struct gpr_pkt *pkt, +int audioreach_graph_send_cmd_sync (struct q6apm_graph *graph,struct gpr_pkt *pkt,uint32_t rsp_opcode) { + pkt->hdr.dest_domain =audioreach_gpr_dest_domain (graph->apm->gdev); +return audioreach_send_cmd_sync (graph->dev,NULL , &graph->result, &graph->lock, graph->port, &graph->cmd_wait, pkt, rsp_opcode); }
@@ -970,6 +972,8 @@ int audioreach_compr_set_param(struct q6apm_graph *graph,if (rc)return rc; + pkt->hdr.dest_domain =audioreach_gpr_dest_domain (graph->apm->gdev); +return gpr_send_port_pkt (graph->port, pkt); }EXPORT_SYMBOL_GPL (audioreach_compr_set_param);
@@ -1489,6 +1493,8 @@ int audioreach_shared_memory_send_eos(struct q6apm_graph *graph) eos->policy =WR_SH_MEM_EP_EOS_POLICY_LAST ; + pkt->hdr.dest_domain =audioreach_gpr_dest_domain (graph->apm->gdev); +return gpr_send_port_pkt (graph->port, pkt); }EXPORT_SYMBOL_GPL (audioreach_shared_memory_send_eos);
sound/soc/qcom/qdsp6/audioreach.h +15 -7
@@ -912,14 +912,19 @@ struct audioreach_module_config { };/* Packet Allocation routines */ -void *audioreach_alloc_apm_cmd_pkt (int pkt_size,uint32_t opcode,uint32_t - token); +static inline u16 audioreach_gpr_dest_domain (gpr_device_t *gdev) +{ +return gdev && gdev->domain_id ? gdev->domain_id :GPR_DOMAIN_ID_ADSP ; +} + +void *audioreach_alloc_apm_cmd_pkt (int pkt_size,uint32_t opcode, +uint32_t token);void audioreach_set_default_channel_mapping (u8 *ch_map,int num_channels);void *audioreach_alloc_cmd_pkt (int payload_size,uint32_t opcode,uint32_t token,uint32_t src_port,uint32_t dest_port);void *audioreach_alloc_apm_pkt (int pkt_size,uint32_t opcode,uint32_t token, -uint32_t src_port); +uint32_t src_port);void *audioreach_alloc_pkt (int payload_size,uint32_t opcode,uint32_t token,uint32_t src_port,uint32_t dest_port);
@@ -930,10 +935,13 @@ int audioreach_tplg_init(struct snd_soc_component *component);/* Module specific */ void audioreach_graph_free_buf (struct q6apm_graph *graph); -int audioreach_send_cmd_sync (struct device *dev,gpr_device_t *gdev,struct gpr_ibasic_rsp_result_t *result, -struct mutex *cmd_lock,gpr_port_t *port,wait_queue_head_t *cmd_wait, -const struct gpr_pkt *pkt,uint32_t rsp_opcode); -int audioreach_graph_send_cmd_sync (struct q6apm_graph *graph,const struct gpr_pkt *pkt, +int audioreach_send_cmd_sync (struct device *dev,gpr_device_t *gdev, +struct gpr_ibasic_rsp_result_t *result, +struct mutex *cmd_lock,gpr_port_t *port, +wait_queue_head_t *cmd_wait, +struct gpr_pkt *pkt,uint32_t rsp_opcode); +int audioreach_graph_send_cmd_sync (struct q6apm_graph *graph, +struct gpr_pkt *pkt,uint32_t rsp_opcode); int audioreach_set_media_format(struct q6apm_graph *graph, const struct audioreach_module *module,
sound/soc/qcom/qdsp6/q6apm.c +7 -1
@@ -29,11 +29,13 @@ struct apm_graph_mgmt_cmd {static struct q6apm *g_apm; -int q6apm_send_cmd_sync (struct q6apm *apm,const struct gpr_pkt *pkt, +int q6apm_send_cmd_sync (struct q6apm *apm,struct gpr_pkt *pkt,uint32_t rsp_opcode) {gpr_device_t *gdev = apm->gdev; + pkt->hdr.dest_domain =audioreach_gpr_dest_domain (gdev); +return audioreach_send_cmd_sync (&gdev->dev, gdev, &apm->result, &apm->lock,NULL , &apm->wait, pkt, rsp_opcode); }
@@ -502,6 +504,8 @@ int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts,mutex_unlock (&graph->lock); + pkt->hdr.dest_domain =audioreach_gpr_dest_domain (graph->apm->gdev); +return gpr_send_port_pkt (graph->port, pkt); }EXPORT_SYMBOL_GPL (q6apm_write_async);
@@ -536,6 +540,8 @@ int q6apm_read(struct q6apm_graph *graph)mutex_unlock (&graph->lock); + pkt->hdr.dest_domain =audioreach_gpr_dest_domain (graph->apm->gdev); +return gpr_send_port_pkt (graph->port, pkt); }EXPORT_SYMBOL_GPL (q6apm_read);
sound/soc/qcom/qdsp6/q6apm.h +1 -1
@@ -147,7 +147,7 @@ int q6apm_alloc_fragments(struct q6apm_graph *graph,int q6apm_free_fragments (struct q6apm_graph *graph,unsigned int dir);int q6apm_unmap_memory_fixed_region (struct device *dev,unsigned int graph_id);/* Helpers */ -int q6apm_send_cmd_sync (struct q6apm *apm,const struct gpr_pkt *pkt, +int q6apm_send_cmd_sync (struct q6apm *apm,struct gpr_pkt *pkt,uint32_t rsp_opcode);/* Callback for graph specific */
sound/soc/qcom/qdsp6/q6prm.c +2 -0
@@ -51,6 +51,8 @@ struct prm_cmd_release_rsc {static int q6prm_send_cmd_sync (struct q6prm *prm,struct gpr_pkt *pkt,uint32_t rsp_opcode) { + pkt->hdr.dest_domain =audioreach_gpr_dest_domain (prm->gdev); +return audioreach_send_cmd_sync (prm->dev, prm->gdev, &prm->result, &prm->lock,NULL , &prm->wait, pkt, rsp_opcode); }
Signature · 1 line
2.34.1
PATCH v5 3/4 dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
In reply to Ajay Kumar NandamOn modem-DSP (mDSP) platforms the DSP runs in a stage-2 protected context and cannot use the SMMU. PCM buffers must live in reserved-memory carveouts that are SCM-assigned to the appropriate VMIDs.
Add an optional memory-region property (1-2 entries) for the control-path and data-path carveouts, and remove iommus from the required list since mDSP platforms have neither IOMMU nor VMID DT properties.
--- Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml +11 -1
@@ -20,9 +20,19 @@ properties: minItems: 1 maxItems: 2 + memory-region: + minItems: 1 + maxItems: 2 + items: + - description: + Control-path buffer (audio_heap_mem) for platforms where the DSP + runs in a stage-2 protected context (e.g. modem-DSP). + - description: + Data-path buffer pool from which per-stream DMA buffers are + allocated. + required: - compatible - - iommus additionalProperties: false
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v5 3/4] dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] dt-bindings: sound: q6apm-dai: schema allows omitting both iommus and memory-region --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dt-bindings: sound: q6apm-dai: schema allows omitting both iommus and memory-region --
commit 0ba7ab9d36bf919ab318abe00f3ad28279a11313
Author: Ajay Kumar Nandam <[email protected]>
dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
This commit adds an optional memory-region property for control-path and data-path carveouts on modem-DSP platforms. It also removes iommus from the required list because mDSP platforms lack IOMMU or VMID device tree properties.
Quoted 12 lines
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml +4
-0@@ -20,9 +20,19 @@ properties: minItems: 1 maxItems: 2 + memory-region: + minItems: 1 + maxItems: 2 + items:
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml properties: · line 25
Quoted 10 lines
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml +7
-1+ - description: + Control-path buffer (audio_heap_mem) for platforms where the DSP + runs in a stage-2 protected context (e.g. modem-DSP). + - description: + Data-path buffer pool from which per-stream DMA buffers are + allocated. + required: - compatible - - iommus
[Severity: Medium]
Does removing iommus here without adding a constraint like oneOf or anyOf allow the schema to silently pass if both properties are omitted?
If a device tree is written without either iommus or memory-region, it looks like it will incorrectly pass schema validation. At runtime, the driver would then allocate normal memory, and when the DSP attempts to access it, it could trigger an SMMU or stage-2 translation fault and crash the DSP/subsystem.
Should we add a structural constraint to enforce that at least one of the memory protection mechanisms is specified?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Mark Brown
maintainerRe: [PATCH v5 3/4] dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
In reply to Ajay Kumar NandamQuoted 3 lines · Ajay Kumar Nandam
On modem-DSP (mDSP) platforms the DSP runs in a stage-2 protected context and cannot use the SMMU. PCM buffers must live in reserved-memory carveouts that are SCM-assigned to the appropriate VMIDs.
Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.
Re: [PATCH v5 3/4] dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
Quoted 10 lines · Mark Brown
Quoted 3 lines · Ajay Kumar Nandam
On modem-DSP (mDSP) platforms the DSP runs in a stage-2 protected context and cannot use the SMMU. PCM buffers must live in reserved-memory carveouts that are SCM-assigned to the appropriate VMIDs.
Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.
Thanks Mark, I will fix the binding patch subject in v6 to match the ASoC subsystem style
Thanks
Ajay kumar Nandam
Rob Herring (Arm)
maintainerRe: [PATCH v5 3/4] dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
In reply to Ajay Kumar NandamQuoted 9 lines · Ajay Kumar Nandam
On modem-DSP (mDSP) platforms the DSP runs in a stage-2 protected context and cannot use the SMMU. PCM buffers must live in reserved-memory carveouts that are SCM-assigned to the appropriate VMIDs.
Add an optional memory-region property (1-2 entries) for the control-path and data-path carveouts, and remove iommus from the required list since mDSP platforms have neither IOMMU nor VMID DT properties.
Quoted 5 lines
Signed-off-by Ajay Kumar Nandam <[email protected]>--- Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml: properties:memory-region: {'minItems': 1, 'maxItems': 2, 'items': [{'description': 'Control-path buffer (audio_heap_mem) for platforms where the DSP runs in a stage-2 protected context (e.g. modem-DSP).'}, {'description': 'Data-path buffer pool from which per-stream DMA buffers are allocated.'}]} should not be valid under {'required': ['maxItems']}
hint: "maxItems" is not needed with an "items" list
from schema $id: http://devicetree.org/meta-schemas/items.yaml
doc reference errors (make refcheckdocs):
See https://patchwork.kernel.org/project/devicetree/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v5 3/4] dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
Quoted 37 lines · Rob Herring (Arm)
Quoted 9 lines · Ajay Kumar Nandam
On modem-DSP (mDSP) platforms the DSP runs in a stage-2 protected context and cannot use the SMMU. PCM buffers must live in reserved-memory carveouts that are SCM-assigned to the appropriate VMIDs.
Add an optional memory-region property (1-2 entries) for the control-path and data-path carveouts, and remove iommus from the required list since mDSP platforms have neither IOMMU nor VMID DT properties.
Quoted 5 lines
Signed-off-by Ajay Kumar Nandam <[email protected]>--- Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)My bot found errors running 'make
dt_binding_check' on your patch:yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml: properties:memory-region: {'minItems': 1, 'maxItems': 2, 'items': [{'description': 'Control-path buffer (audio_heap_mem) for platforms where the DSP runs in a stage-2 protected context (e.g. modem-DSP).'}, {'description': 'Data-path buffer pool from which per-stream DMA buffers are allocated.'}]} should not be valid under {'required': ['maxItems']}
hint: "maxItems" is not needed with an "items" list
from schema $id: http://devicetree.org/meta-schemas/items.yamldoc reference errors (make refcheckdocs):
See https://patchwork.kernel.org/project/devicetree/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make
dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
Quoted 6 lines
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that
DT_SCHEMA_FILEScan be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Thanks Rob, fixed in v6 by dropping the redundant maxItems from memory-region. The focused binding validation passes locally, and I will
include the base-commit trailer in v6.
Thanks
Ajay Kumar Nandam
Re: [PATCH v5 3/4] dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
In reply to Ajay Kumar NandamQuoted 26 lines · Ajay Kumar Nandam
On modem-DSP (mDSP) platforms the DSP runs in a stage-2 protected context and cannot use the SMMU. PCM buffers must live in reserved-memory carveouts that are SCM-assigned to the appropriate VMIDs.
Add an optional memory-region property (1-2 entries) for the control-path and data-path carveouts, and remove iommus from the required list since mDSP platforms have neither IOMMU nor VMID DT properties.
Signed-off-by Ajay Kumar Nandam <[email protected]>--- Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml +4
-0@@ -20,9 +20,19 @@ properties: minItems: 1 maxItems: 2 + memory-region: + minItems: 1 + maxItems: 2 + items:
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml properties: · line 25
Quoted 10 lines
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml +7
-1+ - description: + Control-path buffer (audio_heap_mem) for platforms where the DSP + runs in a stage-2 protected context (e.g. modem-DSP). + - description: + Data-path buffer pool from which per-stream DMA buffers are + allocated. + required: - compatible - - iommus
I imagine you either have iommus or memory-region, no? IOW, oneOf:
- required:
- iommus
- required:
- memory-region
?
Best regards,
Krzysztof
Re: [PATCH v5 3/4] dt-bindings: sound: qcom,q6apm-dai: add memory-region and relax iommus
Quoted 21 lines · Krzysztof Kozlowski
Quoted 21 lines
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml +11
-0@@ -20,9 +20,19 @@ properties: minItems: 1 maxItems: 2 + memory-region: + minItems: 1 + maxItems: 2 + items: + - description: + Control-path buffer (audio_heap_mem) for platforms where the DSP + runs in a stage-2 protected context (e.g. modem-DSP). + - description: + Data-path buffer pool from which per-stream DMA buffers are + allocated. + required: - compatible
Quoted 8 lines
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml properties: · line 25
Quoted 1 line
Documentation/devicetree/bindings/sound/qcom,q6apm-dai.yaml +0
-1- - iommusI imagine you either have iommus or memory-region, no? IOW, oneOf:
- required:
- iommus
- required:
- memory-region
?
Yes, that matches the intended split.
For existing ADSP/SMMU platforms, q6apm-dais uses iommus. For the mDSP/VMID path, the DSP cannot access normal SMMU-backed system memory,so the buffers have to come from reserved-memory carveouts which the driver SCM-assigns to the fixed VMIDs.
I will add the oneOf constraint in v6 to require either iommus or memory-region. VMIDs remain internal to the driver and are not described in DT.
Thanks
Ajay Kumar Nandam
Quoted 3 lines
Best regards,
Krzysztof
PATCH v5 4/4 ASoC: qcom: q6apm-dai: add SCM buffer assignment for mDSP platforms
In reply to Ajay Kumar NandamOn platforms such as Qualcomm Shikra, audio is served by the modem DSP (mDSP) which runs in a stage-2 protected context. Unlike ADSP targets where SMMU-mapped system RAM is directly accessible, the mDSP cannot reach the PCM buffers unless they are explicitly SCM-assigned to the appropriate Virtual Machine IDs (VMIDs). Without this assignment, audio does not function on these platforms.
At probe time, the driver reads the GPR domain_id from the parent APM device to determine which DSP serves audio. When domain_id matches GPR_DOMAIN_ID_ADSP the existing SMMU/iommus path is taken and no new code is exercised. When domain_id matches GPR_DOMAIN_ID_MODEM, the driver verifies that qcom_scm is available (deferring otherwise) and that iommus is absent (the two mechanisms are mutually exclusive), then enables the SCM assignment path.
In the SCM path the driver parses the optional memory-region entries in DT. The first entry (memory-region[0] / audio_heap_mem) is the control-path carveout used by the DSP firmware for command traffic; since the mDSP operates on stage-2 protected memory, this carveout must be SCM-assigned at probe time itself for the firmware to function. It is SCM-assigned to HLOS (retained as source owner, RW) plus MSS_MSA and LPASS (consumer VMIDs, both RW) and restored to HLOS-only ownership via devm_add_action_or_reset() at device removal. The second entry (memory-region[1]) is the data-path buffer pool from which per-stream DMA buffers are carved out. This pool is attached via of_reserved_mem_device_init_by_idx() so that PCM buffers allocate directly from the carveout instead of system RAM.
The data-path pool (memory-region[1]) is SCM-assigned to the consumer VMIDs as a single whole-pool operation at probe time, rather than per-stream in pcm_new()/compr_open(). qcom_scm_assign_mem() consumes an entry in a small fixed-size TZ memory-protection table that is shared platform-wide; assigning individual per-stream slices (up to Q6APM_POOL_MAX_STREAMS times) exhausts that table and hangs the SMC call, which was observed as a crash while bringing up the sound card on Shikra. Since the whole pool is already accessible to the mDSP once assigned, pcm_new()/pcm_free()/compr_open()/compr_free() skip the per-buffer SCM assign/unassign entirely when the data-path pool is in use (has_reserved_mem), and only fall back to per-buffer assignment when use_scm_assign is set without a data-path pool present.
Compressed audio streams follow the same pattern: the DMA buffer allocated in compr_open() is SCM-assigned immediately after allocation and unassigned in compr_free() before the buffer is freed, unless it was carved from the pre-assigned data-path pool.
The VMIDs are static per SoC and hardcoded in the driver (HLOS, MSS_MSA, LPASS) rather than read from DT, following the upstream pattern used by rmtfs_mem and qcom_q6v5_pas. Buffer constraints are capped at reserved_buf_size when the data-path pool is present, and snd_pcm_set_fixed_buffer_all() is used for both paths so the carveout is not subject to the preallocate_dma module parameter.
All new code paths are gated on use_scm_assign (false when domain_id is not GPR_DOMAIN_ID_MODEM), ensuring existing ADSP/iommus targets are completely unaffected.
--- sound/soc/qcom/Kconfig | 1 + sound/soc/qcom/qdsp6/q6apm-dai.c | 300 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 280 insertions(+), 21 deletions(-)
sound/soc/qcom/Kconfig +1 -0
@@ -102,6 +102,7 @@ config SND_SOC_QDSP6_ASM_DAI config SND_SOC_QDSP6_APM_DAI tristate select SND_SOC_COMPRESS + select QCOM_SCM config SND_SOC_QDSP6_APM_LPASS_DAI tristate
sound/soc/qcom/qdsp6/q6apm-dai.c +279 -21
444 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v5 4/4] ASoC: qcom: q6apm-dai: add SCM buffer assignment for mDSP platforms
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] asoc: qcom: compress stream allocation bypasses reserved pool size limits - [Medium] asoc: qcom…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] asoc: qcom: compress stream allocation bypasses reserved pool size limits
- [Medium] asoc: qcom: SCM assignment expands beyond reserved memory bounds
- [Medium] asoc: qcom: memory and graph leak in q6apm_dai_compr_open() error path
- [Medium] asoc: qcom: capture stream lacks dynamic buffer size constraint --
commit 8016abb309ec8211ded913589c6a8b5656e3fed2
Author: Ajay Kumar Nandam <[email protected]>
Subject: ASoC: qcom: q6apm-dai: add SCM buffer assignment for mDSP platforms
This commit adds support for mDSP platforms by explicitly assigning PCM buffers to the appropriate Virtual Machine IDs via SCM calls at probe time and during stream opening. It manages whole-pool assignment for data-path buffers when a memory region is provided, falling back to per-buffer assignments when no data-path pool is present.
Quoted 4 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +0
-0
[ ... ]
sound/soc/qcom/qdsp6/q6apm-dai.c static int q6apm_dai_open(struct snd_soc_component *component, · line 509
Quoted 10 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +4
-1@@ -409,8 +502,11 @@ static int q6apm_dai_open(struct snd_soc_component *component, }if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +size_t buf_max = pdata->has_reserved_mem ? pdata->reserved_buf_size : +BUFFER_BYTES_MAX ; + ret =snd_pcm_hw_constraint_minmax (runtime,SNDRV_PCM_HW_PARAM_BUFFER_BYTES , -BUFFER_BYTES_MIN ,BUFFER_BYTES_MAX ); +BUFFER_BYTES_MIN , buf_max);
[Severity: Medium]
Since this constraint is only applied when the stream is SNDRV_PCM_STREAM_PLAYBACK, capture streams still advertise a static BUFFER_BYTES_MAX of 512KB. If the reserved memory pool limits reserved_buf_size to something smaller than 512KB, couldn't userspace request a capture size up to 512KB, causing hw_params to fail because the preallocated buffer is too small?
Quoted 1 line
sound/soc/qcom/qdsp6/q6apm-dai.c +0
-0if (ret <0 ) {
[ ... ]
sound/soc/qcom/qdsp6/q6apm-dai.c static int q6apm_dai_compr_open(struct snd_soc_component *component, · line 817
Quoted 5 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +1
-0@@ -683,6 +814,17 @@ static int q6apm_dai_compr_open(struct snd_soc_component *component,if (ret)return ret; +if (pdata->use_scm_assign && !pdata->has_reserved_mem) {
[Severity: High]
When has_reserved_mem is true, the device's DMA allocations are fulfilled from the memory-region[1] pool. However, this function unconditionally allocates 8MB (COMPR_PLAYBACK_MAX_FRAGMENT_SIZE * COMPR_PLAYBACK_MAX_NUM_FRAGMENTS) without capping it to pdata->reserved_buf_size like the PCM streams do. Will this massive allocation immediately exhaust the shared data-path pool, starving all other streams, or fail outright if the pool slice is smaller than 8MB?
sound/soc/qcom/qdsp6/q6apm-dai.c static int q6apm_dai_compr_open(struct snd_soc_component *component, · line 824
Quoted 7 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +7
-0+ ret =q6apm_dai_scm_assign (pdata, prtd->dma_buffer.addr, +ALIGN (size,PAGE_SIZE )); +if (ret) { +dev_err (dev,"SCM assign compr buffer failed: %d\n" , + ret); +snd_dma_free_pages (&prtd->dma_buffer); +return ret;
[Severity: Medium]
If q6apm_dai_scm_assign() fails here, the driver frees the DMA buffer and returns directly. Doesn't this bypass freeing the prtd structure (allocated via kzalloc_obj) and closing the DSP graph (opened via q6apm_graph_open)? The ALSA core does not invoke the .free callback when .open returns an error, so this appears to cause a permanent memory and graph resource leak.
Quoted 3 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +3
-0+ } + } +
[ ... ]
Quoted 1 line
sound/soc/qcom/qdsp6/q6apm-dai.c +0
-0@@ -1029,12 +1177,122 @@ static int q6apm_dai_probe(struct platform_device *pdev)
[ ... ]
Quoted 5 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +5
-0+if (mem_count >=1 ) { +struct device_node *mem_node; +struct reserved_mem *rmem; + + mem_node =of_parse_phandle (node,"memory-region" ,0 );
sound/soc/qcom/qdsp6/q6apm-dai.c static int q6apm_dai_probe(struct platform_device *pdev) · line 1226
Quoted 10 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +10
-0+ rmem =of_reserved_mem_lookup (mem_node); +of_node_put (mem_node); +if (!rmem) { +dev_err (dev, +"memory-region[0]: lookup failed\n" ); +return -ENODEV ; + } + + rc =q6apm_dai_scm_assign (pdata, rmem->base, +ALIGN (rmem->size,PAGE_SIZE ));
[Severity: Medium]
SCM assignments modify memory protections at the TrustZone level. Since the ALIGN macro indiscriminately rounds up the size, what happens if the device tree provides a carveout size that is not a multiple of PAGE_SIZE? It seems the driver will request TrustZone to reassign the trailing bytes that belong to adjacent, unreserved kernel memory, which revokes HLOS access to that adjacent memory and could cause a kernel crash when accessed by other subsystems.
Quoted 1 line
sound/soc/qcom/qdsp6/q6apm-dai.c +1
-0+if (rc) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Mark Brown
maintainerRe: [PATCH v5 4/4] ASoC: qcom: q6apm-dai: add SCM buffer assignment for mDSP platforms
In reply to Ajay Kumar Nandamsound/soc/qcom/qdsp6/q6apm-dai.c struct q6apm_dai_rtd { · line 129
Quoted 12 lines · Ajay Kumar Nandam
On platforms such as Qualcomm Shikra, audio is served by the modem DSP (mDSP) which runs in a stage-2 protected context. Unlike ADSP targets where SMMU-mapped system RAM is directly accessible, the mDSP cannot reach the PCM buffers unless they are explicitly SCM-assigned to the appropriate Virtual Machine IDs (VMIDs). Without this assignment, audio does not function on these platforms.
sound/soc/qcom/qdsp6/q6apm-dai.c +4
-0+static int q6apm_dai_scm_assign (struct q6apm_dai_data *pdata, +phys_addr_t addr,size_t size) +{ + r = &pdata->scm_regions[pdata->num_scm_regions++];
This needs a lock.
sound/soc/qcom/qdsp6/q6apm-dai.c static int q6apm_dai_probe(struct platform_device *pdev) · line 1173
Quoted 7 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +4
-0@@ -1021,6 +1168,7 @@ static int q6apm_dai_probe(struct platform_device *pdev) { +if (per_stream <=POS_BUFFER_BYTES +PAGE_SIZE ) { +dev_err (dev, +"reserved-memory pool too small: %llu bytes\n" , + (u64 )rmem->size);
%pa
Re: [PATCH v5 4/4] ASoC: qcom: q6apm-dai: add SCM buffer assignment for mDSP platforms
Quoted 12 lines · Mark Brown
sound/soc/qcom/qdsp6/q6apm-dai.c struct q6apm_dai_rtd { · line 129
Quoted 10 lines
On platforms such as Qualcomm Shikra, audio is served by the modem DSP (mDSP) which runs in a stage-2 protected context. Unlike ADSP targets where SMMU-mapped system RAM is directly accessible, the mDSP cannot reach the PCM buffers unless they are explicitly SCM-assigned to the appropriate Virtual Machine IDs (VMIDs). Without this assignment, audio does not function on these platforms.
sound/soc/qcom/qdsp6/q6apm-dai.c +4
-0+static int q6apm_dai_scm_assign (struct q6apm_dai_data *pdata, +phys_addr_t addr,size_t size) +{ + r = &pdata->scm_regions[pdata->num_scm_regions++];This needs a lock.
Quoted 7 lines
sound/soc/qcom/qdsp6/q6apm-dai.c static int q6apm_dai_probe(struct platform_device *pdev) · line 1172
Quoted 6 lines
sound/soc/qcom/qdsp6/q6apm-dai.c +4
-0@@ -1021,6 +1168,7 @@ static int q6apm_dai_probe(struct platform_device *pdev) { +if (per_stream <=POS_BUFFER_BYTES +PAGE_SIZE ) { +dev_err (dev, +"reserved-memory pool too small: %llu bytes\n" , + (u64 )rmem->size);%pa
Thanks Mark, fixed both in v6.
I added a mutex to serialize scm_regions[] / num_scm_regions updates in q6apm_dai_scm_assign() and q6apm_dai_scm_unassign(), and changed the reserved-memory size diagnostic to use %pa
Thanks
Ajay Kumar Nandam