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=1796387641; b=gytPPQhRITIsEyrEE439YKyMHQhTNiCrJD/e59RoVfErG0fvgAzmtbWK1VkjkM0fFGex cdVt6cPdEah3xbo6Z3lMb9FTPu8cMhoh4yQBCSnp7B7jdB3lRB6LTcJ3qQmL3HxO2PerD +czAj5p2B/xDa7qyusf3zVrcdmrRp6mXfTWEyJqAa5R1anqADRG9i6ua5OXEOZPiWo0FI uEmiZ0gI+rI1Y3j0kYEEEDRN9vzub7uGOhzg2TLL9FTju/MRetGE2ylYOOLQ3aEHNeGFd kwonYl4p2Vg3+KwKEyglLrckwRjoHKDWg6Ay3AMYjihjSY8e2m44ZIBi8+h8nHeekgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387641; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=PE8mChxNGmuOfj9bO8k4Crs//K8VteHwGC+JFd8A/Tk=; b=gKwpgx152RV6oncH/U/+PlgjHXIoyCke2jklWljoc9ZCEK3uElsiTTkMJh/A9tmcGVe9 bfsrA/NADcCyfi8WPqmFe+e0mMtCGvH8tff8D7VWTHilIvWhswFOaSVwCRt/pEzuMO3oK dTTertXLroTBeVW8UsJodJVQuLdXZwS4siIEXMM7P/QOXUc4lmMcGA5QUDs5EKg1+uzho kFMXO6LCogILGFLGIG9eQ3bv0IuG4l3Gp21AuaQFNLv3gYCRmLJ/avwYQpOzZzo3RiNWs 8mGxInG7mAHpXYBd9vcxnfTZ0M5SzZfX6SWmRjVb/9UFkQecKnsIDQdnub6CfQ3rquQ== 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=UHB5r14A; 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 D895E606A333 for ; Fri, 4 Dec 2026 12:34:01 +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=UHB5r14A Received: by smtp.kernel.org (Postfix) with ESMTPSA id A06DC1F00897; Fri, 4 Dec 2026 12:34:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796387641; bh=PE8mChxNGmuOfj9bO8k4Crs//K8VteHwGC+JFd8A/Tk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=UHB5r14AYJYHPjBMoRSUaHOuvWFEXVEYP2xPSdAjgXuoezGzxR/CNPHNRP+iufIIC NGsAlM2y2qDNz10W0lBz1V7xl87LTWQBsiSXcx2H7RnTKtnrartrhD7dlwKrkohYQp MXKdPENOlTbgqXuZUeKcOn0layaQ9VVrrYV0Cd8uJ0DfzfbMHVArrSrM952ac76bzf X6/4UZxi0tq3ZTPgBn8uHZFZOGUxg6qEB3GP3LooJzJYE98HI3aT4csaOLtZ/WPuAW U3RUm0EcKSKDj1JtrGZ0wKFO6pcmzWhbx4R0XuBKJOW680bcitv1ryeQtgtLRhxXB2 5cNYbE3f97AJQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 4/5] mailbox: document direct synchronous transmit Reply-To: sashiko-reviews@lists.linux.dev To: "Anup Patel" Cc: linux-clk@vger.kernel.org In-Reply-To: <20261204111504.3362889-5-anup.patel@oss.qualcomm.com> References: <20261204111504.3362889-1-anup.patel@oss.qualcomm.com> <20261204111504.3362889-5-anup.patel@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 12:34:01 +0000 X-Mailing-List: linux-clk@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 3 potential issues to consider: - [Low] mailbox: doc: spinlock_t in my_send_data_sync() violates PREEMPT_RT contract - [Low] mailbox: doc: unreachable c->busy check and per-channel lock in example - [Low] mailbox: doc: inaccurate deadlock and RX lock note for guard(irqsave)() -- commit 7ea9fb48824dc119ecfc567b53c0fe80f89a4389 Author: Jassi Brar mailbox: document direct synchronous transmit This commit documents the three mailbox transmit models, controller and client contracts for direct synchronous transmit, interaction rules with existing mailbox APIs, and example controller implementations. > diff --git a/Documentation/driver-api/mailbox.rst b/Documentation/driver-= api/mailbox.rst > index d46c60bd5df64..bbb800d88428a 100644 > --- a/Documentation/driver-api/mailbox.rst > +++ b/Documentation/driver-api/mailbox.rst [ ... ] > +Example: atomic-safe controller > +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > + > +.. code-block:: c > + > + struct my_chan { > + void __iomem *tx_reg; > + spinlock_t lock; /* protects this controller's registers */ > + bool busy; > + }; > + > + static int my_send_data_sync(struct mbox_chan *chan, void *data) > + { > + struct my_chan *c =3D chan->con_priv; > + unsigned long flags; > + u32 status; > + int ret =3D 0; > + > + /* > + * The framework does not serialize direct callers and does not > + * disable IRQs. This controller shares one register block acro= ss > + * all CPUs, so it uses its own IRQ-safe lock. > + */ > + spin_lock_irqsave(&c->lock, flags); [Severity: Low] Should this example use raw_spinlock_t instead of spinlock_t? send_data_sync() is documented as safe from hardirq context, but on CONFIG_PREEMPT_RT spin_lock_irqsave() acquires a sleeping rt_spin_lock() without disabling hardware interrupts. A driver modeled on this example would sleep in hardirq context and fail to block same-CPU hardirq re-entry. Using raw_spinlock_t with raw_spin_lock_irqsave() and raw_spin_unlock_irqrestore() (or noting that spinlock_t is not hardirq-safe on PREEMPT_RT) would match the documented contract. > + if (c->busy) { > + ret =3D -EBUSY; > + goto out; > + } > + > + c->busy =3D true; > + writel(*(u32 *)data, c->tx_reg); > + if (readl_poll_timeout_atomic(c->tx_reg + MY_STATUS, status, > + status & MY_DONE, 1, 1000)) > + ret =3D -ETIMEDOUT; > + c->busy =3D false; > + out: > + spin_unlock_irqrestore(&c->lock, flags); > + return ret; > + } > + > + static const struct mbox_chan_ops my_ops =3D { > + .send_data_sync =3D my_send_data_sync, > + /* .send_data may be NULL if every channel is direct-only. */ > + }; > + > + static int my_probe(struct platform_device *pdev) > + { > + ... > + for (i =3D 0; i < MY_NUM_CHANS; i++) > + mbox->chans[i].sync_caps =3D MBOX_CHAN_CAP_SYNC_ATOMIC; > + ... > + return devm_mbox_controller_register(dev, &mbox->controller); > + } [Severity: Low] Can the c->busy check ever be reached here? c->busy is only set and cleared while c->lock is unconditionally held, so the -EBUSY path is dead code and concurrent callers spin on c->lock for up to 1 ms instead of failing fast. To show -EBUSY rejection, the example would need a trylock such as raw_spin_trylock_irqsave() (or drop c->busy). Also, the comments describe a single controller-wide register block shared across CPUs, yet lock lives inside per-channel struct my_chan while my_probe() registers MY_NUM_CHANS channels, leaving distinct channels with separate locks. > +Example: per-CPU shared-memory controller > +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > + > +A controller that hands a per-CPU buffer to firmware must guard the whole > +copy/firmware-call/copy sequence, not just the copy: > + > +.. code-block:: c > + > + static int my_send_data_sync(struct mbox_chan *chan, void *data) > + { > + struct my_msg *msg =3D data; > + int ret; > + > + /* > + * The firmware uses per-CPU scratch memory. A hardirq on this = CPU > + * could otherwise re-enter and clobber it between the copy and = the > + * firmware call. > + */ > + guard(irqsave)(); > + memcpy(this_cpu_ptr(&my_buf)->data, msg->tx, msg->len); > + ret =3D my_firmware_call(this_cpu_ptr(&my_buf)->phys, msg->len); > + if (!ret) > + memcpy(msg->rx, this_cpu_ptr(&my_buf)->data, msg->rx_len); > + return ret; > + } > + > +Every user of the per-CPU buffer must take the same guard. Attribute > +queries, notification fetches, MSI programming, and non-mailbox users th= at > +share the buffer are all part of the same critical section. Delivering = RX > +through ``mbox_chan_received_data()`` while holding that guard can deadl= ock > +if the client sends from ``rx_callback``; release the guard first or use= a > +separate RX lock. [Severity: Low] Does calling mbox_chan_received_data() while holding guard(irqsave)() actually deadlock? guard(irqsave)() maps to local_irq_save(), which is re-entrant on the same CPU. If a client sends from rx_callback, my_send_data_sync() re-enters and silently overwrites this_cpu_ptr(&my_buf) instead of deadlocking (a deadlock only happens with a non-recursive lock like raw_spinlock_t). A separate RX lock is also not a safe alternative to releasing the guard when RX shares the per-CPU buffer, as it will not stop my_send_data_sync() from clobbering my_buf during rx_callback. The controller needs to copy out the RX data and release the guard (or use a separate RX buffer) first. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204111504.3362= 889-1-anup.patel@oss.qualcomm.com?part=3D4