From: Val Packett <val@packett.cool>
To: Luca Weiss <luca.weiss@fairphone.com>,
Srinivas Kandagatla <srini@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>
Cc: Bhushan Shah <bhushan.shah@machinesoul.in>,
Antoine Bernard <zalnir@proton.me>,
~postmarketos/upstreaming@lists.sr.ht,
phone-devel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] ASoC: qcom: qdsp6: q6afe: fix clk vote response type mismatch
Date: Fri, 24 Apr 2026 16:57:49 -0300 [thread overview]
Message-ID: <0f465991-0ad7-47f4-8cc3-237e131f3fdb@packett.cool> (raw)
In-Reply-To: <DI0B81W07N33.3HZQ4R8DEJ9EJ@fairphone.com>
On 4/23/26 3:11 AM, Luca Weiss wrote:
> Hi Val,
>
> On Thu Apr 23, 2026 at 6:41 AM CEST, Val Packett wrote:
>> The response sent by the firmware when requesting a clock vote (opcode
>> AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST) does not actually have
>> the same opcode + status payload as APR_BASIC_RSP_RESULT. Rather, it
>> returns one single u32 which is the client_handle that must be used in
>> future unvote requests for the same clock.
>>
>> As a result of this type confusion, the status returned by the callback
>> to q6afe_vote_lpass_core_hw was actually an out-of-bounds read. It was
>> only interpreted as success (0) most of the time due to luck, but there
>> are reports of random ("more likely on cold boot", "depending on hacks
>> made in other drivers") errors such as:
>>
>> [ 20.961100] qcom-q6afe aprsvc:service:4:4: AFE failed to vote (3)
>> [ 20.961131] Failed to prepare clk 'core': -110
>>
>> Fix by correctly interpreting the response as a single u32, and actually
>> store it as the client_handle to ensure unvote would work correctly.
>>
>> Link: https://lore.kernel.org/all/5976946.DvuYhMxLoT@antlia/
>> Signed-off-by: Val Packett <val@packett.cool>
>> ---
>>
>> Found by reading and comparing with downstream:
>> https://github.com/YumeMichi/kernel_xiaomi_pipa/blob/27190355fb31284988ddf505cb7cfba5128104cf/techpack/audio/dsp/q6afe.c#L1261-L1263
>>
>> What's really bizzare though is that some of the logs go:
>>
>> [ 10.827469] qcom-q6afe aprsvc:service:4:4: cmd = 0x100f4 returned error
>> = 0x16
>> [ 10.827512] qcom-q6afe aprsvc:service:4:4: Unknown cmd 0x100f4
>> [ 14.052896] qcom-q6afe aprsvc:service:4:4: AFE failed to vote (3)
>>
>> ..where the "returned error =" message is something that can only be
>> printed by the callback if it goes into the **other** switch() branch,
>> i.e. when hdr->opcode == APR_BASIC_RSP_RESULT. How reading out-of-bounds
>> only in the AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST branch would
>> cause that to happen (even on a subsequent vote after the first one to
>> perform the read) is beyond me.
>>
>> Still, the person that reported this heisenbug told me that this has
>> actually completely fixed it.
(upd: not really it seems, as expected.. there's gotta be something
else, could it be trying to use the vote command too early before the
firmware is ready for it or something?)
> This seems conceptually similar to what I needed to do for SM6350/SM7225
> microphone (wip) - it's not necessary for just speaker btw:
> https://github.com/z3ntu/linux/commit/107bf0c39e40a207036e963f878f39467f978393
>
> There I'm storing this handle per 'block' and not just one "vote_res",
> essentially copying how downstream Linux does it. Your solution
> definitely has less lines of diff, but I can't judge whether it's enough
> to store it like that :)
>
> Thanks for looking into this though!
Oh wow, didn't know you looked into this already! I'm surprised it was
already necessary for getting something to work. We actually shouldn't
be getting to the unvote part at runtime yet?? o.0 As only the recent
"ASoC: codecs: lpass-*-macro: Switch to PM clock framework for runtime
PM" series change that (and tx/rx weren't posted yet).
The downstream multiple storage thing seems completely unnecessary as
the entire request-response cycle (afe_apr_send_pkt) happens under the
&afe->lock mutex. If another block starts a vote request while another
is in progress, it will wait for the first one to unlock the mutex,
which would only happen after the response is processed.
~val
next prev parent reply other threads:[~2026-04-24 19:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 4:41 [PATCH 0/6] ASoC: qcom: fixes and improvements Val Packett
2026-04-23 4:41 ` [PATCH 1/6] ASoC: qcom: qdsp6: q6afe: fix clk vote response type mismatch Val Packett
2026-04-23 6:11 ` Luca Weiss
2026-04-24 19:57 ` Val Packett [this message]
2026-04-27 12:06 ` Srinivas Kandagatla
2026-04-23 4:41 ` [PATCH 2/6] ASoC: qcom: qdsp6: q6routing: add Senary MI2S ports Val Packett
2026-04-23 4:41 ` [PATCH 3/6] ASoC: qcom: sm8250: add Senary MI2S RX support Val Packett
2026-04-23 4:41 ` [PATCH 4/6] ASoC: qcom: sm8250: add TDM " Val Packett
2026-04-23 4:41 ` [PATCH 5/6] ASoC: qcom: sm8250: shut down MI2S/TDM AFE port clocks Val Packett
2026-04-23 4:41 ` [PATCH 6/6] ASoC: qcom: sm8250: apply codec_fmt to all codec DAIs Val Packett
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0f465991-0ad7-47f4-8cc3-237e131f3fdb@packett.cool \
--to=val@packett.cool \
--cc=bhushan.shah@machinesoul.in \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=luca.weiss@fairphone.com \
--cc=perex@perex.cz \
--cc=phone-devel@vger.kernel.org \
--cc=srini@kernel.org \
--cc=tiwai@suse.com \
--cc=zalnir@proton.me \
--cc=~postmarketos/upstreaming@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®