From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7105938C2C6 for ; Thu, 23 Apr 2026 06:11:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776924673; cv=none; b=mCYUsvqXZu6uCi2sYpMAOTxlm51rhXB9yFbD7UBK4pqCNoZndA8YIHT20wJw5In/W/dDieKbvRlpFLqbqlLZrlS/ueapEEU/mFFmuZAoiEn8N9ysoN1bNu63XDq/SWPNsfU6qHuzSoandkosjSKF3sDTKANyEhfSVQPDDf+gMTw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776924673; c=relaxed/simple; bh=WOrKOJR71lSSEbrOQxKdvEYkwv/rR/+jiveljJNwSCw=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=VwpqPOZib+fYk6m1C39B6alYg7UI0yPcNQ8jVrTrmmRggeI5mfEo5GXHWwsniNLVSwO1uipuE+fMD6r7AA88srcXLU3uZOglQFMh/C1d6XzNRzwhGUQERpkNlfWZ/fTQcYi+fy5dzyicb8eXF4Sf5wo4R6YM5DsP1i+FGNQkTcI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fairphone.com; spf=pass smtp.mailfrom=fairphone.com; dkim=pass (2048-bit key) header.d=fairphone.com header.i=@fairphone.com header.b=IEQSkHuI; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fairphone.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fairphone.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fairphone.com header.i=@fairphone.com header.b="IEQSkHuI" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-66e8cf72a93so7503465a12.0 for ; Wed, 22 Apr 2026 23:11:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fairphone.com; s=fair; t=1776924667; x=1777529467; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4Ct5MwsIQzYx6IC/ibX2+EvebgSz1yi1aAGAGW2PAu4=; b=IEQSkHuIWGs13fzw0Ru5KIF2amckmxeD8Vt76UO864YvMCdlFrlhuEkJIfik253z1i BZje0fPweElYy/q4UnpnLBBXr3i9joiu0hhy/2/aPlFnsddYQpm2e8RIcjXMEhPhAekU 8qBIrrQmQamrBEkESCaleM/+yZIm6Ot8T7B78/KnEShj3SGUtmKCY0cwEQY0Mjn1Ej8j lbt9TBWdEAjgE51l5EMDVeMiVYV0s8y9lOoi9w1a4JypOUW5Gu5E+4bkJVNNVYJ4/iFQ kieX9aVw1gwcYyf1LBnu0LQAlScBu3/6LPgxh426ULmaMrGVfqNhe2SZRMlUT9FL5dWk 4nRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776924667; x=1777529467; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4Ct5MwsIQzYx6IC/ibX2+EvebgSz1yi1aAGAGW2PAu4=; b=lhQ6pg3mLlHLxF1WF6T180vtrZAValYCE19z/wHNobfQM7JpUkQ4S8gxvkuBVjc1ll hS63rPx0WBdRiGF8KaNr0UzQTWz/h3nPhZlkAIvkmV9sGb3+HPSbU9IUc9DKehl3EsPj 7UqXOw1zKfhHF0JH/Uiw3sPlwdtwCIfXB3rySv5uKj/NJPUq/OVa3LvcmVbDR0Z0erAL Y5/aRqiXsNYmJZetOn50J7UrrMstzKLWDqH5E21RzWA6IIE+63EZUUvfMoNolOElr1Ug CbZXGBaZjFbgnAHIg0TN0l5XrKL8vvw1ZBrk1hh7IOmJxJfYkiO8bWCl8IXkxPeTuxjZ +ChA== X-Forwarded-Encrypted: i=1; AFNElJ+D5PF8xic5pLkv5MenVSK3pphsUPBctTpbCl0gTEIhyQq3fGrxkrC39qZcUNiae6Ra5eqqI6mD7af4lvM=@vger.kernel.org X-Gm-Message-State: AOJu0YzLFfS+DmDoPxZ0VnNRr/SyEbV2dCp6dn+wq/OANZMEy3ttm/Qh 6CDMxSLOFk/mI494XEQ8Ti7snCsUTHoQsIrRsU/ds6dSn9YCedyHSPRZUt1ifxiJkuA= X-Gm-Gg: AeBDieuPHZeDtgJVXJBskLB0jIObLJWWygpAV6rL2Q0bv39Uaf3M5a+fqq5z270l5zC 6X+zfvd3qeJpnMfk0tc5Efx8qRr9ZiRdAzwRUPiC/+35uyaPsL0ySBuEILrAByz3/5JVkb/aCRJ E6L1Dl8TirqOSYouLT1x7Lg+74PhyUNbmJ5YbPjTxy9id6ahsg2OBB2Mwgwz5P2GB/62YKasYAE 8pJJugg2b8GMifRkUwWVlUfB+ZbPcNEVMuGuBh7ARI16E7BfCei2VTEInVs9xhXl/Ex7aToiNIP I4z94vkp3CYEnGQno/yfO5kl0FIvPUbnAPUbSSPM6kkLqKqobV14hKSmrCAN/jnADqwWW1jiv+p 4GrTQboJd+OM7TPHU6hCc5Euw4REW83VHnxWSOPn+kXXskmYrA4tfrqwCWkFG+GbtYgPBZwbjG/ /nUxbiWqI6NNpOuNIp2wGlru9qLybCB55wxP/a8d0hQpA36rOMYrbUh4l+STGbq+obvqISR5chn bBpKH6YV3kWPi6Q08TYsnwpfaM/fUjse6E2vJR39ZK+CqM= X-Received: by 2002:a17:907:60d5:b0:bab:e307:7bdf with SMTP id a640c23a62f3a-babe3077ce3mr162415866b.19.1776924666676; Wed, 22 Apr 2026 23:11:06 -0700 (PDT) Received: from localhost (2001-1c04-0504-7401-4b2e-1820-6d24-b264.cable.dynamic.v6.ziggo.nl. [2001:1c04:504:7401:4b2e:1820:6d24:b264]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ba454d1b908sm627916666b.34.2026.04.22.23.11.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Apr 2026 23:11:06 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 23 Apr 2026 08:11:05 +0200 Message-Id: Cc: "Bhushan Shah" , "Luca Weiss" , "Antoine Bernard" , <~postmarketos/upstreaming@lists.sr.ht>, , , , Subject: Re: [PATCH 1/6] ASoC: qcom: qdsp6: q6afe: fix clk vote response type mismatch From: "Luca Weiss" To: "Val Packett" , "Srinivas Kandagatla" , "Liam Girdwood" , "Mark Brown" , "Jaroslav Kysela" , "Takashi Iwai" X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260423050801.210840-2-val@packett.cool> <20260423050801.210840-3-val@packett.cool> In-Reply-To: <20260423050801.210840-3-val@packett.cool> 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 > --- > > Found by reading and comparing with downstream: > https://github.com/YumeMichi/kernel_xiaomi_pipa/blob/27190355fb31284988dd= f505cb7cfba5128104cf/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 =3D 0x100f4 returned erro= r=20 > =3D 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 =3D" message is something that can only be > printed by the callback if it goes into the **other** switch() branch, > i.e. when hdr->opcode =3D=3D APR_BASIC_RSP_RESULT. How reading out-of-bou= nds > 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. 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/107bf0c39e40a207036e963f878f39467f978= 393 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! > > --- > sound/soc/qcom/qdsp6/q6afe.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c > index 40237267fda0..28b5b6b91897 100644 > --- a/sound/soc/qcom/qdsp6/q6afe.c > +++ b/sound/soc/qcom/qdsp6/q6afe.c > @@ -379,6 +379,7 @@ struct q6afe { > struct q6core_svc_api_info ainfo; > struct mutex lock; > struct aprv2_ibasic_rsp_result_t result; > + uint32_t vote_result; > wait_queue_head_t wait; > struct list_head port_list; > spinlock_t port_list_lock; > @@ -968,13 +969,14 @@ static int q6afe_callback(struct apr_device *adev, = const struct apr_resp_pkt *da > const struct aprv2_ibasic_rsp_result_t *res; > const struct apr_hdr *hdr =3D &data->hdr; > struct q6afe_port *port; > + uint32_t *vote_res; > =20 > if (!data->payload_size) > return 0; > =20 > - res =3D data->payload; > switch (hdr->opcode) { > case APR_BASIC_RSP_RESULT: { > + res =3D data->payload; > if (res->status) { > dev_err(afe->dev, "cmd =3D 0x%x returned error =3D 0x%x\n", > res->opcode, res->status); > @@ -1001,8 +1003,10 @@ static int q6afe_callback(struct apr_device *adev,= const struct apr_resp_pkt *da > } > break; > case AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST: > + vote_res =3D data->payload; > afe->result.opcode =3D hdr->opcode; > - afe->result.status =3D res->status; > + afe->result.status =3D 0; > + afe->vote_result =3D *vote_res; > wake_up(&afe->wait); > break; > default: > @@ -1899,6 +1903,8 @@ int q6afe_vote_lpass_core_hw(struct device *dev, ui= nt32_t hw_block_id, > AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST); > if (ret) > dev_err(afe->dev, "AFE failed to vote (%d)\n", hw_block_id); > + else > + *client_handle =3D afe->vote_result; > =20 > return ret; > }