From nobody Sun May 24 21:37:37 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 824B2367B89 for ; Thu, 21 May 2026 09:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779354285; cv=none; b=IAt4J6ySYWCS2j4c4tYbo/VPBLUdxehqybZdQtwNfCL6q7lXrLs3XGScTjDJdOP6t4c/rM6Qbxb7jOiud/3uTuEK9jOqQEhhF4w3xjJ4SqBXwFEKOy4UTt/iR0DFipfm1ujk5oDNzk9iWXwRxjKkOAIubBJnbxhT0J+fxFwObnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779354285; c=relaxed/simple; bh=WXqyDP2WNgily0u8Lr9ZKcp8fbMxSlVPzEqcVTVrC3w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Jw5wLrb+QjmMJ2ee/GKMTy93fBbrWHl4g0PLPe3bDlVokbdswlSi1bRa8+GufzQTT6lb8ecQ1+/bV1Utx51uO/HAyfpjQxgOk6R3Qng6Kdj0eLZeQi5BgeVO+DWrJj1iMRt1vM2vzbgVWrhGFEhydZ+ccXCWOzweGn4O5MKUL18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--joonwonkang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jJiexMpB; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--joonwonkang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jJiexMpB" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-367bb9caa54so5303710a91.2 for ; Thu, 21 May 2026 02:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779354283; x=1779959083; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=me5xxEdS5RmvRxAYfqP7SoJKhExweEkQR6HZlR29D38=; b=jJiexMpBsIImU952SZYilrK0yfgDaIc3VBCL+kIC3ILi4TNq/2x2TKrvO+Q0Wzb1si 73/9SJ6nmaRKyFwYxQMjefNpy7UTIsB4wfeKIcK5A2U7MOwUPN19CJGSPPPl48vBU7BJ WGawdB2Q+dYMT9APJk9NmSQ+OEkNBz1O7u0nV+Syq+Yjeb+yhjnRWxY471dQW7Z5EOuf QaapKC+4CXA4DVprucgOiH3C+97CleeSU3YVxazmObzogBk52VvPTmjmC/EHDbndP5Ul 7VfFRUtIboFJxshqqliu/cOfoiCsJBqIaTIJ4U0KrhE8pzsjvc96PL9SwKF8zCmjqJ51 XNFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779354283; x=1779959083; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=me5xxEdS5RmvRxAYfqP7SoJKhExweEkQR6HZlR29D38=; b=XFWcvb0l7mFBnz36RxOh8nJrpWHcabNE7O7g2bcVa01brFMEMo7WT+7Q5OtlxOsMzA 9QIHNcPz/6CE8hA2bVnbSMNoJoRAgg7CTaprt7p15TUV89HZrP8oOCdfgLC4leR7ptFR 7DskBO9hFGDMaVXKrwnHr6FHrB5PqUvgp4x8N3E/nOCYwB5+5Gt+ZTkWnMOHbDQt0O5q sC1WU+muEqHdgOM0s7RUGuaHrRce0rKM0ct2waIrlYK2OLf+MBOa4FL9ISVpo1Xxlb47 BCCP7IXdg+XT3GYi51ilLQwdf24eYRqsmo2Yn9jPqs8qSu1rjQr6l8ztNwg+Ok2YZVto 0AcA== X-Forwarded-Encrypted: i=1; AFNElJ/9Hxt6zNlPcgR3pCFa8CHkjPxPSYewMTiQj16FdBNSiblzjeHWuHtfrT9rKRI6ooY3te2LBVxTbAi3s98=@vger.kernel.org X-Gm-Message-State: AOJu0YyRN7TPhw2TYZyBjdk+aeaWqctp4ryt7q5RH+K6lCqaA1ttymwd DUNoXtYyEQ0jZfdl8fazucXt27EY2cXHYkWDumE/RL9I+GZyHoUnzbeMnP8NYagTVXaUf/2qkVc XJc3zwgqgfOAjqeLsHtAd6wlqDQ== X-Received: from pjbco1.prod.google.com ([2002:a17:90a:fe81:b0:366:3645:4115]) (user=joonwonkang job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2f8d:b0:366:132:fda6 with SMTP id 98e67ed59e1d1-36a45180833mr2175577a91.11.1779354282756; Thu, 21 May 2026 02:04:42 -0700 (PDT) Date: Thu, 21 May 2026 09:04:33 +0000 In-Reply-To: <20260521090433.1353240-1-joonwonkang@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260521090433.1353240-1-joonwonkang@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260521090433.1353240-3-joonwonkang@google.com> Subject: [PATCH v7.0.y] mailbox: Fix NULL message support in mbox_send_message() From: Joonwon Kang To: sashal@kernel.org, stable@vger.kernel.org, jassisinghbrar@gmail.com, greg@kroah.com Cc: thierry.reding@gmail.com, jonathanh@nvidia.com, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, joonwonkang@google.com, dianders@chromium.org, sudeep.holla@arm.com, linux-acpi@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jassi Brar commit c58e9456e30c ("mailbox: Fix NULL message support in mbox_send_messag= e()") upstream. 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 Signed-off-by: Joonwon Kang --- drivers/mailbox/mailbox.c | 15 ++++++++------- drivers/mailbox/tegra-hsp.c | 2 +- include/linux/mailbox_controller.h | 3 +++ 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/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; diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_con= troller.h index 80a427c7ca29..1db0069c27c5 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -11,6 +11,9 @@ =20 struct mbox_chan; =20 +/* Sentinel value distinguishing "no active request" from "NULL message da= ta" */ +#define MBOX_NO_MSG ((void *)-1) + /** * struct mbox_chan_ops - methods to control mailbox channels * @send_data: The API asks the MBOX controller driver, in atomic --=20 2.54.0.746.g67dd491aae-goog