From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342195; b=j5cS6v6fLktsUjdI+b3Es9AhMil5bOfzMg0MWmMdSWloKajEolQDTRFMQrHpYsWHUhVE IKfaJyHTx8TcGRh1QsOVgUfeqI2ERxiGr4a0yzVRUUqxYcliAQ0yzj6gc3AVg/3/e6ToT PvuT8F+aNhkzX4a+XkMbAAGuVoOv/wuhzEQzJ3o62ulOSWKRQkgco7f/Nbg/q6yq9sbDT mEqeSQfJn6ozA13RTnezLBh8uHJHrTMLADRJXC0lNWjMSnEGfjKq2SPW/J14b8UvjmzKf JkwXVAaGj/ZmT3AJQbrzF+qoXGIiTWQFYEF6VSTNB0OdzTP4LMjNeGNXw4WTWGohDQQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342195; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=fWN8Hs+8oKlxW+VASXlcuB8YVyY3UbN0vcD/Qdg9TD4=; b=TdHbGsJNPutic64LeCYGPmfmB3SoYkkgiNMXkzd3qaGTxk63gvGuKt3p4xKqDsKx7Krs AzJGj1REaFEZD8PZJSksuNojdCPgqeW9gssNikZsvTK2mnq52AhPhy3l0oHJ2f1lsqHIU PxpJSW2/RHPwi5t+GyQyu8/x5qKoN6GG53i2bA7/xFPeOz2ym0o72eFrM+yZTw8DTSKyQ 5BEPTFTUzIecBLFQJWQ5z94bTlUAoWAvFjNm4uFctvYQPy7TQ7BMGn5g24QCd8AeYwIIZ Vgc3qK0UUliDseNnNERqhwUvxqBNJ1Q8y2b1rdUx3eU/JvwVIuEOJq68XFmXj5OpaiQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rsmLkH7h; arc=none smtp.remote-ip=209.85.214.181 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69029606A322 for ; Thu, 3 Dec 2026 23:56:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69029606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rsmLkH7h Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2f05bc71e01so2896395ad.0 for ; Thu, 03 Dec 2026 15:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796342194; x=1796946994; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fWN8Hs+8oKlxW+VASXlcuB8YVyY3UbN0vcD/Qdg9TD4=; b=rsmLkH7hZ0l2GdhJ1t9hKOIzLLnfUnjmD4lMWJ4YbPLf7OUnDNQB7SqocHwqxQoysA rd7GTCx2KL9abWX3m0ITy98JwEIBUfa0FPchkuJeOz2L4yIyREOJlBGEZSsuyoK4d4n1 H3DuFEvTmHuxisux8aZD2zeTi2LStw+PGg8xUi+37S8cbU0elKE6FQABcg8SbdCejwsC Fom/fTHF0Bd9gy7paG/Zi0Ua65UjY2TOnNFFjc4EOsa7rCEH4sI4xVyzEozAea6P5iIu C2R0Ac7T8MGVhQhB0TxEM1rFx1rvhWSqQlbXV5AxgC6r3SgwhCPq8PN4LeU3Pr7QK4DG gxig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796342194; x=1796946994; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fWN8Hs+8oKlxW+VASXlcuB8YVyY3UbN0vcD/Qdg9TD4=; b=iCLiQCyGBfUfe2VdT+ivx0FwczWIdlk9OWNpbRxscEuH90mvurETaTUazcBkyIBVjd RdcovAjy1Lh/CdM44jSZVl96Ut8HhUktHMqs+0oLUSTrhoiJQjqsINCloY1X5Tu4m/xK wkybDPgwaHmPuIKOZOdM8UJl6E/ksJBsoIl4Urpa/yQGDnDxnkSi54xACC2QOI8wUz9L 9APpoGIAcONp0EJO4DlsL+hrvKrhxSmhVhsH3ASu5g9CZPXWEYWLr54IEaJrYfbFXwpx 0KN8zIzECX/cH0GLBu/c3MC+rRK9XyiTMcNVAadFRLwzf1sqBBksST6NnWFADKa/i5Dj COGg== X-Forwarded-Encrypted: i=1; AL+hErGsjm3Td0pa2v8rSQPxZlcunCdFFnqNgKSvlSaEQo8vYufTTcwEfB3hCvBteFYHIyxjotGIUrg=@vger.kernel.org X-Gm-Message-State: APuU4Z/68c7Ni07hOp613e358HxC5AmMoJ+1l+faHhOCdMFvFG+lnk39 Q5BuqaCiun0KeKsXSKcfrTxANJAn3Axx+3lVDb2GpVsYaXI0AndvdRVR X-Gm-Gg: AZFdTZdbGdIm4AT+yP0/X3n5+brHyHmwRjDBj/x4WzNofR+h+7oplxPsoY80Umx7yZA zUwrkS9N5FA5a1+jXY0FexcQgyaFW7h5igSHu4kEOVbRjovtQ5+wXYHzVHsyEzJzIa+bATWoB3R M1NPVup5MLlXpiJRkmc7j6F1rVNQTer7BjfB9PPVtjbriFNnshDxKXA0c+nzvhswexbw/jdM5cx HSTBNIc4elfSFtRpbx3lJG7CEHND4Dlfi/cAU+iCUWg95GoCH1r/SKNxfOPJ3CHJw0uL28/FG2D 5b+mW2FwWFaZfNzYX6IXITQvRfc5frJgcwGixGmcttBWopJxWaLcZkzG67W4zVPGqnpJt6OlBAT W0e+GzxybgyywTAip2JEPRvBiQr6hWGa9aReh2iGE8Z5bXFh7U67hJYTUNnLeKXfsbFjxdnHgxR CD3U7QSg2XxPBbYOsfeJkvsYk0+PJRwOGWzOdz70zydu0O+EbcTFFn0onsSmD2IFAA23hqRNdTy sEaPHwVRdD2NmaPE+juJS6OmV0PNfd5CzYSQ0u5ZlJmHbofTmtG6LyZYa4n3Wj8cJ2Q3jegirzd bNI/0mgKKY8TTB12G8XDHnWCnrD94h3YpMFWAEp4UjcEtFNgNxjoo8DGrOO9aHdkNNqIBuF4rz+ 0mR/qNCAfEpeHNo2+q3Fre0jt9zFRGrjlTOP7LXj0sbaHHWt6sEvathbT3Udwu93c9XwAYuDXtN fWLS8CjeCDi+UEkUI3i2nJe0JqxNwr7i0oADVtjfVtIbcZhjZgHvjdCoDfykp51WF6Wg== X-Received: by 2002:a17:902:d504:b0:2df:4dc5:e12e with SMTP id d9443c01a7336-2f1ba173275mr1401695ad.27.1796342193598; Thu, 03 Dec 2026 15:56:33 -0800 (PST) Received: from josephctchan-96c-1t.c.googlers.com.com (95.100.125.34.bc.googleusercontent.com. [34.125.100.95]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b7967a2bsm1660345ad.68.2026.12.03.15.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 15:56:33 -0800 (PST) From: Joseph CT Chan To: Mark Brown Cc: linux-spi@vger.kernel.org, David Lechner , Bart Van Assche , Joseph CT Chan , stable@vger.kernel.org Subject: [PATCH v3 3/5] spi: spi-mux: finalize message when forwarding fails Date: Thu, 3 Dec 2026 23:56:23 +0000 Message-ID: <20261203235626.1437609-4-jctchan@gmail.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog In-Reply-To: <20261203235626.1437609-1-jctchan@gmail.com> References: <20261203235626.1437609-1-jctchan@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Joseph CT Chan spi_mux_transfer_one_message() forwards a child's message to the parent controller. When spi_mux_select() or spi_async() on the parent fails, it returns the error without finalizing the message. The SPI core then logs "failed to transfer one message from queue" and does not finalize it either, so the child's completion callback never runs and spi_sync() on the child waits forever. After a spi_async() failure the mux also stays locked, so the next message on any child of the mux blocks the spi-mux message pump in mux_control_select(), and the message keeps the spi-mux device and callback in place of the child's. This is easy to hit: spi_async() on the parent returns -EBUSY whenever another device on the parent bus holds spi_bus_lock(), which mmc_spi does for every request. It also returns an error when the parent rejects the message, for example a transfer with 16-bit words and an odd length, which spi-mux does not validate because it defers message optimization to the parent. On select failure, set the message status and finalize it; there is nothing to restore yet and, with patch 1 of this series ("spi: spi-mux: release mux when parent setup fails"), spi_mux_select() has already released the mux. On spi_async() failure, set the status and call spi_mux_complete_cb(), which restores the child's pointers, finalizes the message and releases the mux, in the same order as a successful transfer. In both cases return 0: the message is already finalized with m->status set, so the error reaches the caller through the message, and the core does not wait for it. Returning the error would only make the core log "failed to transfer one message from queue" once per -EBUSY while another device holds the bus lock. Behavior change: a device behind spi-mux now gets -EBUSY while another device holds spi_bus_lock() on the parent, instead of hanging. A device wired directly to the parent would instead wait in spi_sync(), because spi_sync() takes the bus_lock_mutex that spi_bus_lock() holds (drivers/spi/spi.c spi_sync() and spi_bus_lock()); spi-mux forwards with spi_async(), which returns -EBUSY while the bus is locked. Making spi-mux wait for the bus lock needs a core helper and is left for a follow-up. spi_async() on the parent optimizes the message for the parent and, since commit 91db5febb159 ("spi: unoptimize message when queuing it fails"), unoptimizes it on queue failure before spi_mux_complete_cb() restores m->spi. Tested with KUnit (spi_mux: spi_mux_error_test, added later in this series) on ARCH=um and x86_64; before this patch they time out with the message never finalized. Builds with W=1 on ARCH=um and x86_64. Not tested on hardware. Developed with help from the Claude and Gemini AI assistants. Fixes: e9e40543ad5b ("spi: Add generic SPI multiplexer") Cc: stable@vger.kernel.org Signed-off-by: Joseph CT Chan --- v3: Rebased on spi/for-7.5; updated commit message now that commit 91db5febb159 ("spi: unoptimize message when queuing it fails") is applied. v2: Updated the patch references in the commit message after the split. drivers/spi/spi-mux.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-mux.c b/drivers/spi/spi-mux.c index a7ea6585b374..0e770137b5bb 100644 --- a/drivers/spi/spi-mux.c +++ b/drivers/spi/spi-mux.c @@ -117,8 +117,12 @@ static int spi_mux_transfer_one_message(struct spi_controller *ctlr, int ret; ret = spi_mux_select(spi); - if (ret) - return ret; + if (ret) { + /* spi_mux_select() released the mux on failure */ + m->status = ret; + spi_finalize_current_message(ctlr); + return 0; + } /* * Replace the complete callback, context and spi_device with our own @@ -133,7 +137,23 @@ static int spi_mux_transfer_one_message(struct spi_controller *ctlr, m->spi = priv->spi; /* do the transfer */ - return spi_async(priv->spi, m); + ret = spi_async(priv->spi, m); + if (ret) { + /* + * The parent did not take the message, so it will not call + * spi_mux_complete_cb(). Call it here to restore the child's + * pointers, finalize the message and release the mux. + */ + m->status = ret; + spi_mux_complete_cb(priv); + } + + /* + * On error the message is already finalized with m->status set, so + * the error reaches the caller; returning it would only make the core + * log it once more. + */ + return 0; } static int spi_mux_probe(struct spi_device *spi) -- 2.56.1.915.g69d5ec7298-goog