From nobody Thu Apr 2 14:06:35 2026 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2B182C21D0 for ; Fri, 27 Mar 2026 22:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774648848; cv=none; b=tzgKxDSj3+GxycBXPGwY5GeFwx7e0LM7ZJbb2mD8ZV9n4E1LGR4llN1bEcZdzHVRl7qzZyrQzgQOfBfE1VxlsqQhhSgTRGdgMGIHxE1myOYECL+yeQpa5bxLPrQd2xBAiQWKNgs7y5Hb9dxi4eeRCASYnVB8xOebmfw5vRVtTnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774648848; c=relaxed/simple; bh=3S+UNES62iX0tCjot0MLxgNR37cCDz+KaI+dYDnxjaw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QjOosNlek00V4oEgHbkLRKLekoRhvyDrqEZVWEBs0qQMmoXzdZlBH18W73QYmM1MNvX+/4IetD+FyuTP6VA2faipHhNQ7CO8/LQEKVoJRasmqe52LsZqdONDjt1+gmJg6zITcS2yJiGAslVIoDz4WEYeuODaALywh6FWZahQSm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cTDaYHvr; arc=none smtp.client-ip=209.85.222.173 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.b="cTDaYHvr" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-8cfd44fa075so374716785a.0 for ; Fri, 27 Mar 2026 15:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774648845; x=1775253645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5pe4fNuksLvBr6m40iWLP0RWVZihoYn68/6iv6BlIG4=; b=cTDaYHvr/M/Fod+h1X/y2M7y2FK4GaCyfSPf3wLblfQVlEnXSbISEeni6XtUYC9yQ5 KS1NTFiNPKSemr16PpWRSqUFuCk7r/X8RunXJtjZ2nlXq/xhNA8ctI57oD8SCRWNTNfC nWRaquyQ00CGo1tAxl1qQKhlwwIwGlWYE/vT6UT3aBnrr3tObRt0UZCQo19tKWUT/Fuc TSzEFQRwgG3MpNVFlQryj02V/fPVfge4T9oOQZrbHa67Jx7p1M+K7wnMH2xo3Zn8bM0Y OREltz4JaFr1DYfVOOcECVEafcOyWsSMwtkvZsHRFoe5Rpda27UCtTZKGxGlj6jFBckD u9bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774648845; x=1775253645; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5pe4fNuksLvBr6m40iWLP0RWVZihoYn68/6iv6BlIG4=; b=eIsSE9+zgyeP/nIopWjrXfzCbXYNOc8dwRWUULLZspxFa58NyYQ7J1MIup1Zx4zPD0 4J75qfpsAahaLp/l5/KTW35VuIHbzM8gCnSzWH0Yc+ft1Qu9T386d6zQFUOTmxNrEd2d W42sd3pB0g3fIM9gJE6Sv3ts2VwnqSf3KfGFq3EDOd5mqxLq0spAnVv91aH08UbpPb8C 0wQ1t3PONUuwP9U4QVsOxxLg/+gN70XXfAgEzNPw2LDGYkhiVLj668pIeayV54gxo8pn 4Qdmp94oHjhvv70UUfSXN/V0Ev2Qg/nMpqpj+lVUVo1wkLbJkv0x2Gygw+o2pb+IOsf0 MYbA== X-Gm-Message-State: AOJu0Yx5YrkwyJUnnt+muvfisVg789WPzwVQBc2hi2Aoh1sLActqZprK HnS5F5LVpp+R/Iuj7IwOD3fxVTp3V+MfhJx8dC1BPyYG79eqrSYez2KoiIIyvg== X-Gm-Gg: ATEYQzw6ZKTBMCw2SqdNed6Z/otgf13TtkXQvbMgKVSicdBy1uRSnI0hTefpYeUfg5/ 1fNoa7/sWU2gV1rADDT+rHPK0ubdLtJlkLiUCmilzIzMkSn9Ni77ZtN443mAZoOgrvN1LDm/fwV O/lD1Opmp8nIcQnhblGDVIiyUDSXMQr/5qS5OwkT0kWjl1KASkl68+qfxOPKLwRnd2TOyZVGPUL vvfYo/skQZ+WsimdiwjuUQIfhwD/clICPsw1fi3G/WvAXoAXvqabMaIPLXqskP6qX/zlA+LQI8e o5w1YqiIFucvB14Sj3oQDgGnUICizZde95VKKWx3uUhPrV8O/HSKPZBbwgCE9gm1NcBW0PDNJN8 WA2eLUX2NNTHUgkQmFyRBkDxetPEN9+g6qsKFHPTSlRpG1snrN/sV/pgA0ZnkI0mRDgLnmUIkkg fHOMK3g2hL7lkBcAx9fl44N8BRC0RXKHCdGJIGu2OZgMa8H3z2vQdCoZe79NXEEfXbnew2Wf5yt BwAAyuEmI+iXA== X-Received: by 2002:a05:620a:29c7:b0:8cf:de1c:edea with SMTP id af79cd13be357-8d01c595cb2mr593582585a.13.1774648845186; Fri, 27 Mar 2026 15:00:45 -0700 (PDT) Received: from Desktop-PC.. (wnpgmb0311w-ds01-161-217-39.dynamic.bellmts.net. [142.161.217.39]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89ecf867c24sm3011196d6.36.2026.03.27.15.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 15:00:44 -0700 (PDT) From: jassisinghbrar@gmail.com To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: dianders@chromium.org, shawn.guo@linaro.org, maz@kernel.org, andersson@kernel.org, tglx@kernel.org, joonwonkang@google.com, Jassi Brar Subject: [PATCH] mailbox: Fix NULL message support in mbox_send_message() Date: Fri, 27 Mar 2026 17:00:40 -0500 Message-ID: <20260327220040.53326-1-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jassi Brar 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=3Dtrue 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=3Dtrue 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 "!=3D NULL" check becomes "!=3D 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 Reviewed-by: Douglas Anderson Signed-off-by: Jassi Brar --- drivers/mailbox/mailbox.c | 15 ++++++++------- drivers/mailbox/mailbox.h | 3 +++ drivers/mailbox/tegra-hsp.c | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 617ba505691d..9622369cab66 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -52,7 +52,7 @@ static void msg_submit(struct mbox_chan *chan) int err =3D -EBUSY; =20 scoped_guard(spinlock_irqsave, &chan->lock) { - if (!chan->msg_count || chan->active_req) + if (!chan->msg_count || chan->active_req !=3D MBOX_NO_MSG) break; =20 count =3D chan->msg_count; @@ -87,13 +87,13 @@ static void tx_tick(struct mbox_chan *chan, int r) =20 scoped_guard(spinlock_irqsave, &chan->lock) { mssg =3D chan->active_req; - chan->active_req =3D NULL; + chan->active_req =3D MBOX_NO_MSG; } =20 /* Submit next message */ msg_submit(chan); =20 - if (!mssg) + if (mssg =3D=3D MBOX_NO_MSG) return; =20 /* Notify the client */ @@ -114,7 +114,7 @@ static enum hrtimer_restart txdone_hrtimer(struct hrtim= er *hrtimer) for (i =3D 0; i < mbox->num_chans; i++) { struct mbox_chan *chan =3D &mbox->chans[i]; =20 - if (chan->active_req && chan->cl) { + if (chan->active_req !=3D MBOX_NO_MSG && chan->cl) { txdone =3D chan->mbox->ops->last_tx_done(chan); if (txdone) tx_tick(chan, 0); @@ -246,7 +246,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mss= g) { int t; =20 - if (!chan || !chan->cl) + if (!chan || !chan->cl || mssg =3D=3D MBOX_NO_MSG) return -EINVAL; =20 t =3D add_to_rbuf(chan, mssg); @@ -319,7 +319,7 @@ static int __mbox_bind_client(struct mbox_chan *chan, s= truct mbox_client *cl) scoped_guard(spinlock_irqsave, &chan->lock) { chan->msg_free =3D 0; chan->msg_count =3D 0; - chan->active_req =3D NULL; + chan->active_req =3D MBOX_NO_MSG; chan->cl =3D cl; init_completion(&chan->tx_complete); =20 @@ -477,7 +477,7 @@ void mbox_free_channel(struct mbox_chan *chan) /* The queued TX requests are simply aborted, no callbacks are made */ scoped_guard(spinlock_irqsave, &chan->lock) { chan->cl =3D NULL; - chan->active_req =3D NULL; + chan->active_req =3D MBOX_NO_MSG; if (chan->txdone_method =3D=3D TXDONE_BY_ACK) chan->txdone_method =3D TXDONE_BY_POLL; } @@ -532,6 +532,7 @@ int mbox_controller_register(struct mbox_controller *mb= ox) =20 chan->cl =3D NULL; chan->mbox =3D mbox; + chan->active_req =3D MBOX_NO_MSG; chan->txdone_method =3D txdone; spin_lock_init(&chan->lock); } diff --git a/drivers/mailbox/mailbox.h b/drivers/mailbox/mailbox.h index e1ec4efab693..c77dd6fc5b8a 100644 --- a/drivers/mailbox/mailbox.h +++ b/drivers/mailbox/mailbox.h @@ -5,6 +5,9 @@ =20 #include =20 +/* Sentinel value distinguishing "no active request" from "NULL message da= ta" */ +#define MBOX_NO_MSG ((void *)-1) + #define TXDONE_BY_IRQ BIT(0) /* controller has remote RTR irq */ #define TXDONE_BY_POLL BIT(1) /* controller can read status of last TX */ #define TXDONE_BY_ACK BIT(2) /* S/W ACK received by Client ticks the TX */ diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c index ed9a0bb2bcd8..7991e8dba579 100644 --- a/drivers/mailbox/tegra-hsp.c +++ b/drivers/mailbox/tegra-hsp.c @@ -497,7 +497,7 @@ static int tegra_hsp_mailbox_flush(struct mbox_chan *ch= an, mbox_chan_txdone(chan, 0); =20 /* Wait until channel is empty */ - if (chan->active_req !=3D NULL) + if (chan->active_req !=3D MBOX_NO_MSG) continue; =20 return 0; --=20 2.52.0