From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342194; b=JZlwLa7GNiuVpPWIWf3i2dTYoEm67AcZpGXOR3lk5YSN1VtSl1kIglVxOWVzeaGMZL2Y DKWpn2SHwS74JDFS5ohmz12vY5KnDzFkxlPQAht4ncRI4Z7psde2y19rJvcAo3GUeGToG BOae0i/+0P+unNuoUKfYrNyWfpgX+hQwV3i2RlhuzPJXYeaCWnHBKee4vhgiyTRu2+9E+ a3IpuJM8Hf6tDfFtcOn3xkDyjgnJRPzV5AAT5AQdlXqKnc4JwyxOJkhBlMyayW8yrj9mX 8PkrsN8wGhI5DNJAyFQhdkl1Zt/6s7U8H1HwFIzjnBX6Hm0pPC0GCbCx2SLl/CEPNxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342194; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=DsO6ocyLR8rlA0K2wGILhNzMkbZBvYSG5FwZ38l5C77vYZ0L4woRYDLq2MFiS4QV66/m PZJmm3GK+yITKw6eW5HsZCf+d5dYOZsCWOKPy+7pfmyy971NFdwEyMsp0jM7lapNwq6XZ G896F41nUtuhjGEbR3r4lZcWwUWETNjryhWOaWrwHw0F+p8a94uo487Sc3hSjBoxNHey7 RCjm/ss9uLlZ9eVO0w3JKzv1U6yEDmm1/rinqP3sqv/w+Ti1Y0FQ6EihAzkknRQn/rCpt eWhZIBcoPizUoJxPQJ0kGr34MW8AhFnAEPqGzEzHgE6a2Y4kAxs5x7oAE6sWOEV3X6g== 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.169 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 6DDBA606A32C for ; Thu, 3 Dec 2026 23:56:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6DDBA606A32C 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-f169.google.com with SMTP id d9443c01a7336-2f052ae3c86so2818835ad.1 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=dK/RidAeGwaHO6lqp5xZ/avdQbpOSXklZbkhhYKLMg2V9+ddw+UBtvZETnX6gI8XCj Lpfhvaai7381UBeXGZuJ6zoEZuaWKuYmI5gVB+qVWZW6AQ/ANxTDx6kK+OtmRwyJQqyH uL8P8+Ayu9SQpVlCveTgBx3bYLqmH/I75r7jIJrd6oNm1HTVmUuxqM0aWpYFDX6txpDF tEVUgJU6RwSEchLkKZxFR1AXAmGf8tHRz1KR1u4FVYu2FImqZz4Brc0b8lHYf+Krp5ST KtXvuw+R6+7T0KcI44bbuDSCw9z2GF+HVXzQL+/D3a9sD3kvVbuuKcm6znEucaGfZL5B JySA== X-Gm-Message-State: APuU4Z/UPIW0BSogNgxhfqp7/9YfIvNjG+Twj4izQa0SaDO4drbzwMLV zOSB2b8xSlfHxEWb68l9E22oCKD+IdtCxyPiN6+7rcU1k3VJvUycFkjG X-Gm-Gg: AZFdTZff90fhYUeVHd9cxB3zn4iIo65o8rCqXrNGwnQlReXaNC2GWaQ8lgGk/t5xJKW 9Cf7oSGrs0eck8YspikMTDfYj5aDaDBmMs0WqPBI7/0gecTpfld7aYfv/cdn+VFqWHbIx5X3ojb oImMeakoHU87hdv8T27Bcl9YQ++7B9x7K8MvXCDSCVUQRcJ0b0UJboq4pRI32rh5mUv1rCEIA8k 47alntGmzsXCuNn31gIhZo8O4gu8yT5FdlBelkqD2MkBawN6SFMS0E0w0Am0Pb795GQSua8SZI3 UoBWOGqca04cEHhcitjHU/AN4vqeKBPA+r7Fdg7k8lu8p2pYSnmF/QnHqlpQJjAx3utj7qvFU+U mm3LwlE9gWpNZaiHrwl5CdrK63STjpZRcQheejJMSB59/IuIcq7qfuoVXDoQfLXFKAVtCU3jVH2 +IdzvcLI9TIl1I73Lk05oMiyZ3b7mjs/eHKu6HHUeXCoCE0rsv3FqLYfuJuZp6EJsdzRC561Ga+ tXl9iZ0It+p5y3f1FdUtEylvtuRrOBsxKKZ0L0GECqjdSYZCqsncA8ATqwD/oEF6AoATsPm0B0Q 7Bt5+orJIZl7YH8+bVLNwpj+i3ljfykSIdkl38CmgqwUlGJx3LDaJlTeBL42dxZu7sSCshj7OLd Vt7w9tYEfAd5udJ9iBD/HlJhCQp0WzCtZahUQyTCGEivqDdI1z1+sYLXlntJ9xRYeQDgarTgjeM brLuyCODKyuotA1aEERO5sl/5FC/IHi37ysvMS4kwDk5WPvakN7Ymp0XwQwh7zDHR2xQ== 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: linux-spi@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