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=1796006884; b=MoFLRrRrKEIjf/QJiQWvib+m8zGqEgtYm3A+abCrvdMbWfuiu2U0M5RUfTaIEF1kKuGi OuamkBT8mqNri+M6Bl0UT2iVVFdpDHujG3+R+RSBKVvAdVH+fw85z63efc0Jos4QYgU0C ccINTkjjIZq+Fqsy0Gaa2K8Ok3dfHpMMYCU9EhXbo9CAjSVVO74zZdxIQzRc08PMbFPIk FLSlw8lRvk0CgLgCGXl7hsriHj4giUhN83xLnEgiutYQMEXM9D1HH2xuWGnB+Z0zUQMEL 71T3jqwvG1HN6eY1xPXKRWqBRlTomdT2D8SE4zOzDgEqKZ/u8G7WjqIwPoO8XjG1EcQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796006884; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=H+Hr3xWq2VZaaaA121oyWOGGOh0A+xGI3F9k6BaRLT4=; b=gHiuoZL31fKWzNKShVgiK21or8vUFL8FKgPSlb4rjbVD6f2/bBtslhLfDArpH30e580j yADlBIYphEZj8MnpvzSHv6NXEhS7p4NLGwLiQLYifBi+Iia/1Wtysdi8qzxAuWjAY33Es PAQTyX5+dvLgk6vAWR6gyyoAPx287/z7psw1IzVPSjzOIfjt83Ip71aogXGNVx9UGwBRq ODgg2lGRQjNdmR4kbi6gl5fjKAmMAaj/RJz3rTca/sG6+rwUyO5hbbHRaDoAE3pImilz6 5A7TsGhDaGsHlI7JYK9sAE9AAtVNU2gjHanRaL+WENmvLQPk/dq6n6icGI888/M69xQ== 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=SX6DSTy+; 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 DDB12606A31C for ; Mon, 30 Nov 2026 02:48:04 +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=SX6DSTy+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C3A81F00897; Mon, 30 Nov 2026 02:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796006884; bh=H+Hr3xWq2VZaaaA121oyWOGGOh0A+xGI3F9k6BaRLT4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=SX6DSTy+H1TxO1dTx3ciPKWjDZfv8HytqVBp6PODcwEGJKChQub8XKa71uvbmgdCR 9lXU7i6nOmUM05a3+aLeeTyOBYJVRntW3XArca2VeHa8t8H1H4ecDgIww9Me547RKj O8yMzHZPh86aWiQGKnkV00QnXvsDu48RN78xdnaRWfERmR9tF40TM9ARZKst2JT/US KuU2U+tIKlWa3RkJJDp1q2FeollDdfDMv43JzISvuyzrlLGBHz6I7uOVD2jjjCS5C9 396zV8Dh1kLTXbbwexQpHvw7VksH8y3LWGi55KJ4ccv0zRmENLMG0t9YekPRFJN2R+ 4V6KHlEgAooPA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 3/5] spi: loongson: Add spi-io interrupt-driven driver Reply-To: sashiko-reviews@lists.linux.dev To: "Binbin Zhou" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <3d3e3f7ec2b784b72020fe7887046c5e5cbbd9f2.1796005812.git.zhoubinbin@loongson.cn> References: <3d3e3f7ec2b784b72020fe7887046c5e5cbbd9f2.1796005812.git.zhoubinbin@loongson.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 02:48:03 +0000 X-Mailing-List: devicetree@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 2 potential issues to consider: - [High] spi: loongson: CS glitch in loongson_spi_io_cfg_write() while CS is active - [Medium] spi: loongson: unsynchronized IRQ and active engine on timeout in loongson_spi_io_transfer_one_irq() -- commit 142d6eaee16a385552bbf9c942915b74af0d7e00 Author: Binbin Zhou spi: loongson: Add spi-io interrupt-driven driver This commit adds an interrupt-driven platform driver for the Loongson-2K0300 SPI-IO controller. > diff --git a/drivers/spi/spi-loongson-io.c b/drivers/spi/spi-loongson-io.c > new file mode 100644 > index 0000000000000..2ca9ee7e2d1da > --- /dev/null > +++ b/drivers/spi/spi-loongson-io.c [ ... ] > +/** > + * loongson_spi_io_cfg_write() - Write a configuration register > + * @priv: controller private data > + * @reg: configuration register offset > + * @val: value to write > + * > + * CFG1/CFG2/CFG3 and CRCx writes are rejected while CR1.SPE is set. > + * Temporarily disable the peripheral and restore CR1 around the write. > + * The caller must ensure that no transfer is active. In normal SS mode > + * ss_o =3D !SPE, so callers must also ensure CS is deasserted; toggling= SPE > + * while CS is active glitches the CS line. > + */ > +static void loongson_spi_io_cfg_write(struct loongson_spi_priv *priv, u3= 2 reg, u32 val) > +{ > + u32 cr1 =3D loongson_spi_readl(priv, LOONGSON_SPI_IO_CR1_REG); > + > + loongson_spi_writel(priv, LOONGSON_SPI_IO_CR1_REG, > + cr1 & ~LOONGSON_SPI_IO_CR1_SPE); > + loongson_spi_writel(priv, reg, val); > + loongson_spi_writel(priv, LOONGSON_SPI_IO_CR1_REG, cr1); > +} [ ... ] > +static void loongson_spi_io_update_state(struct spi_device *spi, struct = spi_transfer *t) > +{ > + struct loongson_spi_priv *priv =3D spi_controller_get_devdata(spi->cont= roller); > + u8 bits_per_word =3D spi->bits_per_word; > + > + if (t && t->bits_per_word) > + bits_per_word =3D t->bits_per_word; > + > + if (t && priv->hz !=3D t->speed_hz) > + loongson_spi_io_set_clk(priv, t->speed_hz); > + > + if (((spi->mode ^ priv->mode) & (SPI_MODE_X_MASK | SPI_LSB_FIRST)) || > + priv->bits_per_word !=3D bits_per_word) > + loongson_spi_io_set_mode(priv, spi->mode, bits_per_word); > +} [Severity: High] Does calling loongson_spi_io_set_clk() and loongson_spi_io_set_mode() from loongson_spi_io_transfer_one() glitch the hardware chip-select line? spi_transfer_one_message() asserts CS via loongson_spi_io_set_cs() and waits cs_setup before calling transfer_one(). Inside transfer_one(), loongson_spi_io_set_clk() and loongson_spi_io_set_mode() invoke loongson_spi_io_cfg_write(), which clears and restores LOONGSON_SPI_IO_CR1_SPE while CS is active (on the first transfer after probe and whenever speed_hz, bits_per_word, or spi->mode changes). As noted above loongson_spi_io_cfg_write(), toggling SPE while CS is asserted pulses CS high mid-transaction, and also changes CPOL/CPHA in LOONGSON_SPI_IO_CFG1_REG while the target is selected. Similarly, loongson_spi_io_unprepare_message() calls loongson_spi_io_reset_state() -> loongson_spi_io_reginit() -> loongson_spi_io_cfg_write(), which toggles SPE at the end of a message even when the final transfer sets cs_change to keep CS active. In addition, loongson_spi_io_reginit() sets LOONGSON_SPI_IO_CR1_SPE during probe without setting LOONGSON_SPI_IO_CR1_SSREV, driving the active-low CS line low at probe time before any SPI device is set up. [ ... ] > +static int loongson_spi_io_transfer_one_irq(struct spi_device *spi, stru= ct spi_transfer *xfer) > +{ > + struct loongson_spi_priv *priv =3D spi_controller_get_devdata(spi->cont= roller); > + int ret; > + > + loongson_spi_io_set_thresh(priv); > + > + priv->tx_buf =3D xfer->tx_buf; > + priv->rx_buf =3D xfer->rx_buf; > + priv->remaining =3D xfer->len; > + priv->xfer_ret =3D 0; > + > + reinit_completion(&priv->xfer_completion); > + priv->xfer_mode =3D XFER_INTERRUPT; > + > + loongson_spi_update_bits(priv, LOONGSON_SPI_IO_CR1_REG, > + LOONGSON_SPI_IO_CR1_AUTOSUS, LOONGSON_SPI_IO_CR1_AUTOSUS); > + loongson_spi_update_bits(priv, LOONGSON_SPI_IO_IER_REG, > + LOONGSON_SPI_IO_IER_EOTIE | LOONGSON_SPI_IO_IER_ERR_MASK, > + LOONGSON_SPI_IO_IER_EOTIE | LOONGSON_SPI_IO_IER_ERR_MASK); > + > + loongson_spi_io_start_batch(priv); > + > + ret =3D wait_for_completion_timeout(&priv->xfer_completion, > + loongson_spi_io_timeout(priv, xfer)); > + priv->xfer_mode =3D XFER_IDLE; > + > + if (ret =3D=3D 0) { > + loongson_spi_writel(priv, LOONGSON_SPI_IO_IER_REG, 0); > + dev_err(&spi->dev, "Interrupt transfer timeout"); > + return -ETIMEDOUT; > + } > + > + return priv->xfer_ret; > +} [Severity: Medium] When wait_for_completion_timeout() times out, can an in-flight loongson_spi_io_irq_handler() race with the timeout path before loongson_spi_io_handle_err() runs synchronize_irq()? CPU0 CPU1 loongson_spi_io_transfer_one_irq() wait_for_completion_timeout() --> times out loongson_spi_io_irq_handler() switch (priv->xfer_mode) case XFER_INTERRUPT: priv->xfer_mode =3D XFER_IDLE; loongson_spi_writel(..., IER_REG, 0); return -ETIMEDOUT; spi_transfer_one_message() spi_dma_sync_for_cpu() spi_set_cs() loongson_spi_io_set_cs() loongson_spi_update_bits(..., CR1_REG, ...) memcpy(priv->rx_buf, ...) loongson_spi_update_bits(..., CR1_REG= , ...) <-- data race on rx_buf and CR1_REG The timeout path returns -ETIMEDOUT without clearing LOONGSON_SPI_IO_CR1_START_MASK or calling synchronize_irq(priv->irq). Before spi_transfer_one_message() reaches ctlr->handle_err(), an in-flight ISR on CPU1 can still write to priv->rx_buf after spi_dma_sync_for_cpu(), start another batch from priv->tx_buf, or perform unlocked read-modify-writes on LOONGSON_SPI_IO_IER_REG and LOONGSON_SPI_IO_CR1_REG concurrently with loongson_spi_io_set_cs(). Also, LOONGSON_SPI_IO_IER_REG is enabled before loongson_spi_io_start_batch() initializes priv->batch_size, leaving a window where priv->batch_size holds the previous transfer's final batch size. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796005812.gi= t.zhoubinbin@loongson.cn?part=3D3