Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mailbox: Fix NULL message support in mbox_send_message()

The active_req field serves double duty as both the "is a TX in
flight" flag (NULL means idle) and the storage for the in-flight
message pointer. When a client sends NULL via mbox_send_message(),
active_req is set to NULL, which the framework misinterprets as
"no active request". This breaks the TX state machine by:

- tx_tick() short-circuits on (!mssg), skipping the tx_done
callback and the tx_complete completion
- txdone_hrtimer() skips the channel entirely since active_req
is NULL, so poll-based TX-done detection never fires.

Fix this by introducing a MBOX_NO_MSG sentinel value that means
"no active request," freeing NULL to be valid message data. The
sentinel is defined in the subsystem-internal mailbox.h so that
controller drivers within drivers/mailbox/ can reference it, but
it is not exposed to clients outside the subsystem.

Fifteen in-tree callers send NULL (doorbell-style IPCs on Qualcomm,
Tegra, TI, Xilinx, i.MX, SCMI, and PCC platforms). All were
audited for regression:

- Most already work around the bug via knows_txdone=true with a
manual mbox_client_txdone() call, making the framework's
tracking irrelevant. These are unaffected.

- Poll-based callers (Xilinx zynqmp/r5) are strictly better off:
the poll timer now correctly detects NULL-active channels
instead of silently skipping them.

- irq-qcom-mpm.c was a pre-existing bug -- the only Qualcomm
caller that omitted the knows_txdone + mbox_client_txdone()
pattern. Fixed in a companion commit ("irqchip/qcom-mpm: Fix
missing mailbox TX done acknowledgment").

- No caller sets both a tx_done callback and sends NULL, nor
combines tx_block=true with NULL sends, so the newly reachable
callback/completion paths are never exercised.

Also update tegra-hsp's flush callback, which directly inspects
active_req to wait for the channel to drain: the old "!= NULL"
check becomes "!= MBOX_NO_MSG", otherwise flush spins until
timeout since the sentinel is non-NULL.

The only tradeoff is that 'MBOX_NO_MSG' can not be used as a message
by clients.

Reported-by: Joonwon Kang <joonwonkang@google.com>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>

+12 -8
+8 -7
drivers/mailbox/mailbox.c
··· 50 50 int err = -EBUSY; 51 51 52 52 scoped_guard(spinlock_irqsave, &chan->lock) { 53 - if (!chan->msg_count || chan->active_req) 53 + if (!chan->msg_count || chan->active_req != MBOX_NO_MSG) 54 54 break; 55 55 56 56 count = chan->msg_count; ··· 85 85 86 86 scoped_guard(spinlock_irqsave, &chan->lock) { 87 87 mssg = chan->active_req; 88 - chan->active_req = NULL; 88 + chan->active_req = MBOX_NO_MSG; 89 89 } 90 90 91 91 /* Submit next message */ 92 92 msg_submit(chan); 93 93 94 - if (!mssg) 94 + if (mssg == MBOX_NO_MSG) 95 95 return; 96 96 97 97 /* Notify the client */ ··· 112 112 for (i = 0; i < mbox->num_chans; i++) { 113 113 struct mbox_chan *chan = &mbox->chans[i]; 114 114 115 - if (chan->active_req && chan->cl) { 115 + if (chan->active_req != MBOX_NO_MSG && chan->cl) { 116 116 txdone = chan->mbox->ops->last_tx_done(chan); 117 117 if (txdone) 118 118 tx_tick(chan, 0); ··· 267 267 { 268 268 int t; 269 269 270 - if (!chan || !chan->cl) 270 + if (!chan || !chan->cl || mssg == MBOX_NO_MSG) 271 271 return -EINVAL; 272 272 273 273 t = add_to_rbuf(chan, mssg); ··· 340 340 scoped_guard(spinlock_irqsave, &chan->lock) { 341 341 chan->msg_free = 0; 342 342 chan->msg_count = 0; 343 - chan->active_req = NULL; 343 + chan->active_req = MBOX_NO_MSG; 344 344 chan->cl = cl; 345 345 init_completion(&chan->tx_complete); 346 346 ··· 498 498 /* The queued TX requests are simply aborted, no callbacks are made */ 499 499 scoped_guard(spinlock_irqsave, &chan->lock) { 500 500 chan->cl = NULL; 501 - chan->active_req = NULL; 501 + chan->active_req = MBOX_NO_MSG; 502 502 if (chan->txdone_method == TXDONE_BY_ACK) 503 503 chan->txdone_method = TXDONE_BY_POLL; 504 504 } ··· 553 553 554 554 chan->cl = NULL; 555 555 chan->mbox = mbox; 556 + chan->active_req = MBOX_NO_MSG; 556 557 chan->txdone_method = txdone; 557 558 spin_lock_init(&chan->lock); 558 559 }
+1 -1
drivers/mailbox/tegra-hsp.c
··· 495 495 mbox_chan_txdone(chan, 0); 496 496 497 497 /* Wait until channel is empty */ 498 - if (chan->active_req != NULL) 498 + if (chan->active_req != MBOX_NO_MSG) 499 499 continue; 500 500 501 501 return 0;
+3
include/linux/mailbox_controller.h
··· 12 12 13 13 struct mbox_chan; 14 14 15 + /* Sentinel value distinguishing "no active request" from "NULL message data" */ 16 + #define MBOX_NO_MSG ((void *)-1) 17 + 15 18 #define TXDONE_BY_IRQ BIT(0) /* controller has remote RTR irq */ 16 19 #define TXDONE_BY_POLL BIT(1) /* controller can read status of last TX */ 17 20 #define TXDONE_BY_ACK BIT(2) /* S/W ACK received by Client ticks the TX */