Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Anup Patel" <anup.patel@oss.qualcomm.com>
Cc: linux-clk@vger.kernel.org
Subject: Re: [PATCH v3 3/5] mailbox: add direct synchronous transmit API
Date: Fri, 04 Dec 2026 12:26:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-249788@kernel.org> (raw)
In-Reply-To: <20261204111504.3362889-4-anup.patel@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] mailbox: appending sync_caps bloats struct mbox_chan and
  causes false sharing
- [Low] mailbox: struct mbox_client kernel-doc omits tx_prepare and
  tx_done
- [Low] mailbox: lockdep_assert_not_held() false positive on PREEMPT_RT
  hardirq
--

commit 710773999a3f8b3a62dd32451d8d433420cb359f
Author: Jassi Brar <jassisinghbrar@gmail.com>

mailbox: add direct synchronous transmit API

This commit adds an opt-in per-channel direct synchronous transmit path
(mbox_send_message_sync() and mbox_send_message_sync_sleepable()) that
bypasses the queued TX ring buffer and txdone state machine.

> diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
> index efacd24a085d1..0cc7d2eed7cff 100644
> --- a/drivers/mailbox/mailbox.c
> +++ b/drivers/mailbox/mailbox.c

[ ... ]

> @@ -308,6 +328,78 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
>  }
>  EXPORT_SYMBOL_GPL(mbox_send_message);
>  
> +/**
> + * mbox_send_message_sync - directly transmit a message from atomic context
> + * @chan: Mailbox channel assigned to this client.
> + * @mssg: Client specific message typecasted.
> + *
> + * Directly invoke the controller's atomic-safe synchronous transmit
> + * operation.  The operation runs in the caller's context, without
> + * chan->lock and without touching the queued state machine, and returns
> + * the controller's per-call result.  This function does not sleep and may
> + * be called from any context in which the controller's send_data_sync()
> + * operation is safe, including hardirq context.
> + *
> + * The message buffer must remain valid until this function returns; the
> + * controller must not retain it afterwards.  The caller is responsible for
> + * serializing this call against mbox_free_channel() and driver removal.
> + *
> + * Return: 0 on success, -EINVAL for invalid arguments, -EOPNOTSUPP if the
> + * channel does not support atomic-safe direct transmit, or another
> + * negative errno from the controller.
> + */
> +int mbox_send_message_sync(struct mbox_chan *chan, void *mssg)
> +{
> +	if (!chan || !READ_ONCE(chan->cl) || mssg == MBOX_NO_MSG)
> +		return -EINVAL;
> +
> +	lockdep_assert_not_held(&chan->lock);

[Severity: Low]
Can lockdep_assert_not_held(&chan->lock) trigger a false-positive
WARN_ON on CONFIG_PREEMPT_RT when called from hardirq context?

mbox_seq_show() takes chan->lock with spin_lock_irqsave() on every
channel, including active direct channels.  Because chan->lock is a
spinlock_t, spin_lock_irqsave() maps to rt_spin_lock() on PREEMPT_RT
and leaves hardware interrupts enabled while chan->lock is recorded in
current->held_locks:

mbox_seq_show()
  spin_lock_irqsave(&chan->lock)   (PREEMPT_RT: IRQs stay enabled)
  <hardirq>
    mbox_send_message_sync(chan, ...)
      lockdep_assert_not_held(&chan->lock)  <-- false-positive WARN_ON

__lock_is_held() checks current->held_locks without filtering by
irq_context, so a hardirq preempting mbox_seq_show() on the same CPU
hits a spurious lockdep splat (and panics under panic_on_warn).

[ ... ]

> diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h
> index e5997120f45cf..49b778aa4b9ab 100644
> --- a/include/linux/mailbox_client.h
> +++ b/include/linux/mailbox_client.h
> @@ -16,11 +16,13 @@ struct mbox_chan;
>   * struct mbox_client - User of a mailbox
>   * @dev:		The client device
>   * @tx_block:		If the mbox_send_message should block until data is
> - *			transmitted.
> - * @tx_tout:		Max block period in ms before TX is assumed failure
> + *			transmitted.  Ignored on direct channels.
> + * @tx_tout:		Max block period in ms before TX is assumed failure.
> + *			Ignored on direct channels.
>   * @knows_txdone:	If the client could run the TX state machine. Usually
>   *			if the client receives some ACK packet for transmission.
>   *			Unused if the controller already has TX_Done/RTR IRQ.
> + *			Ignored on direct channels.
>   * @rx_callback:	Atomic callback to provide client the data received
>   * @tx_prepare: 	Atomic callback to ask client to prepare the payload
>   *			before initiating the transmission if required.

[Severity: Low]
Should @tx_prepare and @tx_done (just below in struct mbox_client) also
be documented as ignored on direct channels?

Neither mbox_send_message_sync() nor mbox_send_message_sync_sleepable()
invokes tx_prepare() or tx_done().  Marking @tx_block, @tx_tout, and
@knows_txdone as ignored while leaving @tx_prepare and @tx_done
unannotated suggests they are still called like @rx_callback.

[ ... ]

> diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h
> index 26a238a6f941c..34724bfc683d7 100644
> --- a/include/linux/mailbox_controller.h
> +++ b/include/linux/mailbox_controller.h

[ ... ]

> @@ -127,6 +157,8 @@ struct mbox_controller {
>   * @msg_data:		Hook for data packet
>   * @lock:		Serialise access to the channel
>   * @con_priv:		Hook for controller driver to attach private data
> + * @sync_caps:		Per-channel direct transmit capabilities, immutable
> + *			after registration.  Zero means a queued channel.
>   */
>  struct mbox_chan {
>  	struct mbox_controller *mbox;
> @@ -139,8 +171,14 @@ struct mbox_chan {
>  	void *msg_data[MBOX_TX_QUEUE_LEN];
>  	spinlock_t lock; /* Serialise access to the channel */
>  	void *con_priv;
> +	unsigned int sync_caps;	/* MBOX_CHAN_CAP_SYNC_* */
>  };

[Severity: Medium]
Can appending sync_caps here grow struct mbox_chan from 256 to 264 bytes
on 64-bit SMP and introduce cross-channel false sharing?

Every queued and direct transmit or txdone hot path reads chan->sync_caps
alongside chan->mbox and chan->cl.  Putting sync_caps at the end puts it
on a fifth cacheline, and in contiguous mbox->chans[] arrays (such as in
tegra_hsp_probe()) the 264-byte stride breaks 64-byte channel alignment so
chans[i].lock shares a cacheline with chans[i + 1]'s mbox and cl fields.

Moving sync_caps directly after txdone_method fills an existing 4-byte
padding hole on cacheline 0, keeping sizeof(struct mbox_chan) at 256 bytes
and avoiding both the extra cacheline load and cross-channel bouncing.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204111504.3362889-1-anup.patel@oss.qualcomm.com?part=3

  reply	other threads:[~2026-12-04 12:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 11:14 [PATCH v3 0/5] Parallel message send using SBI MPXY Anup Patel
2026-12-04 11:15 ` [PATCH v3 1/5] RISC-V: Move common MPXY helper routines to arch/riscv Anup Patel
2026-12-04 11:47   ` sashiko-bot
2026-12-04 11:15 ` [PATCH v3 2/5] RISC-V: Prevent interrupt when accessing MPXY shared memory Anup Patel
2026-12-04 12:06   ` sashiko-bot
2026-12-04 11:15 ` [PATCH v3 3/5] mailbox: add direct synchronous transmit API Anup Patel
2026-12-04 12:26   ` sashiko-bot [this message]
2026-12-04 11:15 ` [PATCH v3 4/5] mailbox: document direct synchronous transmit Anup Patel
2026-12-04 12:34   ` sashiko-bot
2026-12-04 11:15 ` [PATCH v3 5/5] mailbox: convert RISC-V SBI MPXY to direct transmit Anup Patel
2026-12-04 13:30   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-249788@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=anup.patel@oss.qualcomm.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox