From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796285304; b=nq3VyhfjptfxYaKOMXpU9Iug7ECGWBawcg0wMZTdoelAI/MV2eZD4By4nRfodUw3HAck hzE6PDwMzP+NzFHgm5OdSxngiM6Pm8Jj3PRLFB7kANUyY+1cNTGLiMGtWz5glByJdLrBy TEma0+AFHn0MeCi73h0Ctb8y8WRNjWn1iCt4ZfpaRPDV1OSz/BUkR9d4yGfYFyp8u1+8j 2H/tULRRZ2GTOtp8VpKoxTSn0juKz1wCcBgmwaBPXIWGlnWEXq5axNqYjLJmiuQJ9U4uS 7UpGfnm9c8kV+wnT0ZyImabZBKC3XNbD5wRv7971vFS+eo2lqySkilgpq4pwwY397zg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796285304; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=QeMCcRLolujUSZPEBrbfc5zy61dz3sAlv0qHGpUy+3E=; b=5fuEFG+zt7mgfqFf+rG9EXSm8Zb/MKp4qIZ5pmOgTf2PCt1IsS2/rl0vtiGANmqRo50N 8kr2aWeK3WiTZlcAmUCDAIAdrB3YWTod5O0E4YkaGBQRLdOix2XdhAwuDVQ6l6Qr2a7vY mnMoN4XSY6V5eUXZJi21PeT98Vt22dbxmU1B+HcDj8xha13zxUlZyEO7b4gvJDutTRT5F TKfjH1RURRfbuipuMQQW4p4oHRj62ZSQ43ZhZKgf+uZrqAkel+rD/jFyq15y1fqU6PQSB NwzyjMrjHQJdsF19lVGj010WF+2qlH9vJzedVw+TE1c4eILWjfYr3tm/ZEdBjEXE27A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Mhm6nKtJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14F4A606A32C for ; Thu, 3 Dec 2026 08:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Mhm6nKtJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2DBF1F000C1; Thu, 3 Dec 2026 08:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796285303; bh=QeMCcRLolujUSZPEBrbfc5zy61dz3sAlv0qHGpUy+3E=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Mhm6nKtJXbP+1fFz9Tx242rkgOrfAi4Hr6YcGToPxKL1vOJdh+ytmNtkox6ozo+ie 0IEYw/9UywXV1CBNqm3QvVQtQruZ+ktXwUVjeRAYiw+zBao8ZI1htRH/zk0f6Qe/fH Fb0ZPQ5dQRDMpQw3wIVa+v9639biY8tDNKC0Eb93Z2KcbYuHlyT3Na5Rq9tMXlDe+8 PIOrg0vp58AdHU7ncUvO8SF9Cc5WbosNENre+cRky2L87+ZMuC23pWS+UWKD8lGBJ0 wMnbiWnJ+qcW+iYNszHHncPxQFHUkUgH7+oci+8aTOBmfQc58ylmq1xE6eumq201tR 8cSOl0PTO3hJw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe Reply-To: sashiko-reviews@lists.linux.dev To: "Ajay Kumar Nandam" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-4-046ce68c8b0e@oss.qualcomm.com> References: <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com> <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-4-046ce68c8b0e@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 08:08:23 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [High] soundwire: qcom: swrm_reconcile_slaves() clobbers ctrl->slave_status - [High] soundwire: qcom: missing clock_stop_not_supported update on reconcile - [Medium] soundwire: qcom: swrm_reconcile_slaves() skips alerting peripherals - [Medium] soundwire: qcom: swrm_reconcile_slaves() may assign duplicate dev_num - [Low] soundwire: qcom: redundant reads and checks in swrm_reconcile_slaves() - [Low] soundwire: qcom: missing break on FIFO read error in swrm_reconcile_slaves() - [Low] soundwire: qcom: swrm_reconcile_slaves() reads DevIDs of already-bound slaves -- commit b4c7c081a46d27523980bc34cc988e2f4829cddd Author: Ajay Kumar Nandam soundwire: qcom: reconcile a retained peripheral after controller re-probe This commit adds swrm_reconcile_slaves() to scan attached device-number slots after the enumeration wait in qcom_swrm_probe() and bind any uniquely matching unbound peripheral that retained its device number across a controller re-probe. It disables ctrl->irq while reconciling slot state. > diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c > index b1656412ffab1..95d3e4ecd2a9c 100644 > --- a/drivers/soundwire/qcom.c > +++ b/drivers/soundwire/qcom.c > @@ -772,6 +772,73 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus) > return 0; > } > =20 > +/* Caller must disable the status IRQ while updating slot state. */ > +static void swrm_reconcile_slaves(struct qcom_swrm_ctrl *ctrl) > +{ > + struct sdw_bus *bus =3D &ctrl->bus; > + u32 slv_status_raw =3D 0; > + int i; > + > + ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &slv_status_raw); > + > + for (i =3D 1; i <=3D SDW_MAX_DEVICES; i++) { > + u32 slot_status =3D (slv_status_raw >> (i * SWRM_MCP_SLV_STATUS_SZ)) & > + SWRM_MCP_SLV_STATUS_MASK; > + u8 buf[SDW_NUM_DEV_ID_REGISTERS] =3D {0}; > + struct sdw_slave *slave, *match =3D NULL; > + struct sdw_slave_id id; > + int nmatch =3D 0, n, all_ok =3D 1; > + u32 recheck_raw =3D 0, recheck_slot; > + u64 addr; > + > + if (slot_status !=3D SDW_SLAVE_ATTACHED) > + continue; [Severity: Medium] Can a retained peripheral reporting SDW_SLAVE_ALERT be skipped here and left permanently unbound? Unlike a freshly reset peripheral, one that stayed attached across a controller re-probe keeps its previously programmed SDW_SCP_INTMASK1 (for example bus clash and parity enabled by wsa881x_probe()). If an interrupt latches during an ADSP restart, SWRM_MCP_SLV_STATUS reports SDW_SLAVE_ALERT instead of SDW_SLAVE_ATTACHED, so this check, the recheck below, and qcom_swrm_set_slave_dev_num() all skip it. Once enable_irq() runs, sdw_handle_slave_status() ignores unassigned slots, so the alert is never cleared and the peripheral never returns to SDW_SLAVE_ATTACHED. > + > + mutex_lock(&bus->msg_lock); > + for (n =3D 0; n < SDW_NUM_DEV_ID_REGISTERS; n++) { > + if (qcom_swrm_cmd_fifo_rd_cmd(ctrl, i, SDW_SCP_DEVID_0 + n, > + 1, &buf[n]) !=3D SDW_CMD_OK) > + all_ok =3D 0; > + } > + mutex_unlock(&bus->msg_lock); > + if (!all_ok) > + continue; [Severity: Low] Does this execute six sleeping FIFO reads for every already-bound peripheral on normal boots? Each qcom_swrm_cmd_fifo_rd_cmd() sleeps at least 350 us via usleep_range(), adding over 2 ms per already-bound peripheral across synchronous controller probes while ctrl->irq is disabled, only to discard the result below. Checking up front whether bus->slaves has any unbound entry, and skipping slots already owned by a slave's dev_num, would avoid this bus I/O when enumeration already succeeded. [Severity: Low] Should this loop break on the first qcom_swrm_cmd_fifo_rd_cmd() failure? Because !all_ok discards buf[] right after unlocking bus->msg_lock, continuing issues up to five extra failing reads. On a read FIFO underflow, swrm_wait_for_rd_fifo_avail() sleeps ~15.5 ms per call, turning one timeout into ~95 ms per failing slot with ctrl->irq disabled. [ ... ] > + if (!(match->dev_num =3D=3D 0 && match->status =3D=3D SDW_SLAVE_UNATTA= CHED)) > + continue; > + > + /* Re-check the slot after the SCP reads. */ > + ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &recheck_raw); > + recheck_slot =3D (recheck_raw >> (i * SWRM_MCP_SLV_STATUS_SZ)) & > + SWRM_MCP_SLV_STATUS_MASK; > + if (recheck_slot !=3D SDW_SLAVE_ATTACHED || > + match->dev_num !=3D 0 || > + match->status !=3D SDW_SLAVE_UNATTACHED) > + continue; [Severity: Low] Are the match->dev_num and match->status checks here redundant? The same condition was just verified above with only ctrl->reg_read() in between while ctrl->irq is disabled, so nothing can mutate those fields here. Skipping already-bound slots before the FIFO reads and breaking on the first read error would also avoid redundant bus traffic and repeated error logs. > + > + qcom_swrm_set_slave_dev_num(bus, match, i); [Severity: Medium] Can this assign a duplicate dev_num if another slave in bus->slaves already owns slot i? When a peripheral detaches, sdw_modify_slave_status() marks it SDW_SLAVE_UNATTACHED without clearing its dev_num. If slave A attached on slot i during the enumeration wait, detached, and hardware auto-enumeration reused slot i for unbound slave B before reconciliation, this assigns dev_num =3D i to slave B as well. Because sdw_get_slave() returns the first matching entry in bus->slaves, subsequent status transitions, alerts, and initialization for slot i are misdirected to slave A while slave B remains stuck unattached. Checking whether any slave in bus->slaves already has dev_num =3D=3D i before binding would prevent this. [Severity: High] Does binding match here miss updating ctrl->clock_stop_not_supported? In qcom_swrm_enumerate(), binding a slave with prop.clk_stop_mode1 set (such as wsa881x_probe()) sets ctrl->clock_stop_not_supported =3D true. Leaving it false here causes swrm_runtime_suspend() and swrm_runtime_resume() to run SoundWire clock-stop sequences instead of performing SWRM_COMP_SW_RESET and re-initializing the controller when the 3-second autosuspend timer fires. > + qcom_swrm_get_device_status(ctrl); > + sdw_handle_slave_status(&ctrl->bus, ctrl->status); [Severity: High] Can calling qcom_swrm_get_device_status() here clobber ctrl->slave_status and drop attach events for other peripherals on the bus? swrm_reconcile_slaves() snapshots SWRM_MCP_SLV_STATUS once before the loop and runs with ctrl->irq disabled, so another peripheral on slot j can finish attaching during the SCP DevID reads: CPU0 (probe) Hardware / IRQ qcom_swrm_probe() disable_irq(ctrl->irq) swrm_reconcile_slaves() read SWRM_MCP_SLV_STATUS (slot i attached, slot j unattached) SCP DevID reads on slot i slot j attaches, IRQ pending qcom_swrm_set_slave_dev_num(match, i) qcom_swrm_get_device_status() ctrl->slave_status =3D live <-- absorbs slot j =3D ATTACHED sdw_handle_slave_status() <-- skips unassigned slot j enable_irq(ctrl->irq) qcom_swrm_irq_handler() ctrl->slave_status =3D=3D live skips qcom_swrm_enumerate() When enable_irq() delivers the pending attach interrupt, qcom_swrm_irq_handler() sees ctrl->slave_status =3D=3D slave_status, skips qcom_swrm_enumerate(), and leaves peripheral j permanently unbound. Calling sdw_handle_slave_status() inside the loop also re-invokes sdw_update_slave_status() on every already-attached slave for each reconciled slot. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-ak-gt-soun= dwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com?part=3D4