From nobody Fri Apr 3 22:38:22 2026 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (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 337161B4156 for ; Sun, 22 Mar 2026 17:17:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774199879; cv=none; b=QFXvL0rXL34SDRfXi98eJ89PSPHQw61JIkRhc3SPTMk1Yd0tm11a71OcC7lndzK6YTUIjWwRdvgmu4JInyORIKKUGE6ocE4XWZsU2MNuOpcpDg+4s6oEvbLMlq5GouNbIKo561SHkUGbmNO2q5kJL2CKOWHwTGdVn6HHUEO+1JY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774199879; c=relaxed/simple; bh=knwR+x+KbyGQeI0D/y5xe5g9j4ScAC9NPUHZVYuXd6g=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WUQ2fN222swTp8uvkJkU0JJyIa7m9V3BWgOmv7f4hhxPPJVsTkvwet+jpRSMKg2MMS2x/qxSmF+MvQAkl5QrLpfVODeAiu4+dJ7M2IqeLC0tDBY5HyJDS03rY2Q+v/JBD4PNIi1Hygb+ANo5Muo5pronC7Wtej1m3m3hGMaYPAM= 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=UKF9kqAQ; arc=none smtp.client-ip=209.85.222.170 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="UKF9kqAQ" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-8cd8dbf4f2eso364353685a.2 for ; Sun, 22 Mar 2026 10:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774199877; x=1774804677; 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=cSMooCIC7eRFhSt8FxFqoAMmRD4C+XMgbM/hUvAjw1Y=; b=UKF9kqAQHOjYOkVnTbNB3PPtjaDef8Fj1P6IYOMadZY7cIBpaAsdfsmrWPZWa462HK lAw/Fla/A4dN+l7BSFw0xFsXk3PPArpnVuNZpfMVAroaHCT/Rb7HmjqUnqITBGSrYaHp OXSx/tKvSoZrfkiH/NrE6UY1IoDG3syiq9418zdUfmVQypqSy60Zy2AvpiY5B4vIVXy1 GEMZACSw9R2Lv8V1ORvxxvkKVfIddNjUmSpXPp1xR/ubYA7HSAjhcjXhkob49E5JgGNP ki4MC0HMTbKi0p09XjpyHevjnNlrKvZcz4j5cgtHv2DLIJNVKDKdBqnzHPHKtNsrz5nX hmiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774199877; x=1774804677; 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=cSMooCIC7eRFhSt8FxFqoAMmRD4C+XMgbM/hUvAjw1Y=; b=qo6E05dbqcXomJn3vO4NTy5WqeZc8JG3QVNE7HkymFpKiGhH8Vj6hf5KPPDa8szqf9 EcGiM3E9t/aacvbsxkzDChkURQpzx0S5+RaMzPf+0LHHfauN42211WX8hQjzMjXTO3HW mhIGsnh/masbg0P+WLCF7LOJKNMW60mAmca/XT+pMFSFY4XecB8DVduDg6sZiQ6Z5fDM J5OS/hTO7nKjdZPcaBXQtqrHPxDHw0H1CXZHJrtqpgoElfZvWkozaM6Dl6bLqRyx8NFY VYlqeVL5OJ+ufo76aMAEii9CtaonbIyShpyKhaZNYY4zh0Uow8Prb9MaJFTTWbaesjGy rXVw== X-Gm-Message-State: AOJu0Ywsn4USmOpyH1dF9KqZfio+DcVfCXr8WiMxSVqhaHg0RlqFYpcL AzWZ5edti44zGGNC5LJpyspA2Jjc2jsUcOa1aRY3B+AQMRoLie9d763vKNUHww== X-Gm-Gg: ATEYQzy95wewAJgeWJUfX07smn7Fq3rZ5nakbOiMzUHIGIvcSmCjWLiEJ9DZ6PC8y+c aDaL8ppAoV4iBvljmQF1Kbi4m/R0SRvkKUtgGHe4fsVbJFtDWtsJ9Kj48M9+39vyAyKKClswAQQ BnLTmKawb9n9kNAz+k66Sd69KE31LulfB4n2J8OgQcFYXFTwfBeqMXAwoiZFn+KIdUrrN1hTmOu i10xz3rceCtRAy+xClUwLqHrHllfjanAJE+CwyLQaOaPDpiu3bpbdniMD0iTvDbaWpVvWR5j5f3 uMYn9fRbM+ZVqgeAYcvSjuYYtTif/+N5rrNiZHBOb6Mr/MRpGyXHiKAcJ7tAki2loi5z1FiwshG IshOQ+rj/0GTeG6xew/kjRRb/AMZgFG3iZ2VARrX699jt9XABXKOV+eSO40cjCaqm6m3qZ12iP/ UbK2QFtg2vRNM6w9iR3md8lKtDLrwU2u9Ro9odQdDzXBM4JA5SOJDZc94cbA9GLfqrm2uhkgsDY xNziw+n4kSrQG47YkSF2bK/ X-Received: by 2002:a05:620a:440b:b0:8cf:e152:592d with SMTP id af79cd13be357-8cfe1525999mr433128585a.21.1774199876857; Sun, 22 Mar 2026 10:17:56 -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 af79cd13be357-8cfc90e7587sm597838785a.46.2026.03.22.10.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 10:17:56 -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, stable@vger.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: Sun, 22 Mar 2026 12:17:52 -0500 Message-ID: <20260322171752.608486-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. Signed-off-by: Jassi Brar Reviewed-by: Douglas Anderson --- drivers/mailbox/mailbox.c | 13 +++++++------ drivers/mailbox/mailbox.h | 3 +++ drivers/mailbox/tegra-hsp.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 617ba505691d..2a7fc7395144 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); @@ -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.43.0