From nobody Fri Apr 3 05:45:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10129ECAAA1 for ; Thu, 15 Sep 2022 16:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiIOQvS (ORCPT ); Thu, 15 Sep 2022 12:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230159AbiIOQuq (ORCPT ); Thu, 15 Sep 2022 12:50:46 -0400 Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E41073330 for ; Thu, 15 Sep 2022 09:49:57 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 327B241399; Thu, 15 Sep 2022 16:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received:received; s= mta-01; t=1663260595; x=1665074996; bh=6UEUP+y+Z7RGWxNREbm/5xo+C 7aE6gcUmSI1T3jT2l4=; b=pv77DRPjgezXzXD+gD1vfdbrjqaP3r47rCRcHF+sE wmqGJn50mDP5QF46C8QamfAQ2gWlTt3QOk1zlHgmw3JYH8rgEWBVVnvWe0IzvZip YUhso7c7w5crTtw8/O/GczrUiGVl7xD5+FoFhD2peWEuvl7bZvt14hLIjJy5WPdQ hM= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4C9GCwduArZf; Thu, 15 Sep 2022 19:49:55 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (T-EXCH-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 8B7174525E; Thu, 15 Sep 2022 19:48:57 +0300 (MSK) Received: from T-EXCH-08.corp.yadro.com (172.17.11.58) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 15 Sep 2022 19:48:57 +0300 Received: from t14gen1.yadro.com (10.199.21.212) by T-EXCH-08.corp.yadro.com (172.17.11.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.9; Thu, 15 Sep 2022 19:48:56 +0300 From: Evgenii Shatokhin To: Jassi Brar CC: , Ilya Kuznetsov , , Evgenii Shatokhin Subject: [PATCH 1/2] mailbox: Propagate errors from .send_data() callback to mbox_send_message() Date: Thu, 15 Sep 2022 19:47:29 +0300 Message-ID: <20220915164730.515767-2-e.shatokhin@yadro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220915164730.515767-1-e.shatokhin@yadro.com> References: <20220915164730.515767-1-e.shatokhin@yadro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.199.21.212] X-ClientProxiedBy: T-EXCH-02.corp.yadro.com (172.17.10.102) To T-EXCH-08.corp.yadro.com (172.17.11.58) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" msg_submit() calls .send_data() function from the mailbox controller driver to place the first of the queued messages to the mailbox. Depending on the actual driver used, this operation could fail. In this case, if mbox_send_message() is called in blocking mode, it will always return -ETIME rather than the actual error reported by the underlying driver. This could be confusing, so let us propagate the error from msg_submit() to mbox_send_message(). The errors from msg_submit() called in tx_tick() should be handled in a subsequent patch. Signed-off-by: Evgenii Shatokhin --- drivers/mailbox/mailbox.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 4229b9b5da98..04db5ef58f93 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -50,17 +50,24 @@ static int add_to_rbuf(struct mbox_chan *chan, void *ms= sg) return idx; } =20 -static void msg_submit(struct mbox_chan *chan) +static int msg_submit(struct mbox_chan *chan) { unsigned count, idx; unsigned long flags; void *data; - int err =3D -EBUSY; + int err =3D 0; =20 spin_lock_irqsave(&chan->lock, flags); =20 - if (!chan->msg_count || chan->active_req) + if (!chan->msg_count) { + spin_unlock_irqrestore(&chan->lock, flags); + return 0; + } + + if (chan->active_req) { + err =3D -EBUSY; goto exit; + } =20 count =3D chan->msg_count; idx =3D chan->msg_free; @@ -88,6 +95,7 @@ static void msg_submit(struct mbox_chan *chan) hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); spin_unlock_irqrestore(&chan->mbox->poll_hrt_lock, flags); } + return err; } =20 static void tx_tick(struct mbox_chan *chan, int r) @@ -256,6 +264,7 @@ EXPORT_SYMBOL_GPL(mbox_client_peek_data); int mbox_send_message(struct mbox_chan *chan, void *mssg) { int t; + int err; =20 if (!chan || !chan->cl) return -EINVAL; @@ -266,7 +275,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mss= g) return t; } =20 - msg_submit(chan); + err =3D msg_submit(chan); =20 if (chan->cl->tx_block) { unsigned long wait; @@ -284,7 +293,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mss= g) } } =20 - return t; + return (err < 0) ? err : t; } EXPORT_SYMBOL_GPL(mbox_send_message); =20 --=20 2.34.1 From nobody Fri Apr 3 05:45:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E7CAECAAA1 for ; Thu, 15 Sep 2022 16:51:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230221AbiIOQva (ORCPT ); Thu, 15 Sep 2022 12:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230113AbiIOQuy (ORCPT ); Thu, 15 Sep 2022 12:50:54 -0400 Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F290C9E136 for ; Thu, 15 Sep 2022 09:50:06 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 1871841399; Thu, 15 Sep 2022 16:50:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received:received; s= mta-01; t=1663260603; x=1665075004; bh=FkFg8EtCr1O369CBvSqL1CQwl CG3BKdMuG2XI5r9JS8=; b=Kxmm8Op1xDnwrVcPZZnih9GDzambZUL+I+yAuaUn0 U36aDDWvlbbpw2ux3wl32wv3VHcyKlITaGf5qrlh/QC/OVdI006pXiKgqZI7811J IEaU4PLymMRNy0mzaSIQvJSwk4dcKHklqGkwypSzy9Mu6oB/6eS3hDX17kypkJbM Ak= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V_sxolbgcA_t; Thu, 15 Sep 2022 19:50:03 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (T-EXCH-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id A4C82452C4; Thu, 15 Sep 2022 19:49:12 +0300 (MSK) Received: from T-EXCH-08.corp.yadro.com (172.17.11.58) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 15 Sep 2022 19:49:12 +0300 Received: from t14gen1.yadro.com (10.199.21.212) by T-EXCH-08.corp.yadro.com (172.17.11.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.9; Thu, 15 Sep 2022 19:49:11 +0300 From: Evgenii Shatokhin To: Jassi Brar CC: , Ilya Kuznetsov , , Evgenii Shatokhin Subject: [PATCH 2/2] mailbox: Error out early if the mbox driver has failed to submit the message Date: Thu, 15 Sep 2022 19:47:30 +0300 Message-ID: <20220915164730.515767-3-e.shatokhin@yadro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220915164730.515767-1-e.shatokhin@yadro.com> References: <20220915164730.515767-1-e.shatokhin@yadro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.199.21.212] X-ClientProxiedBy: T-EXCH-02.corp.yadro.com (172.17.10.102) To T-EXCH-08.corp.yadro.com (172.17.11.58) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" mbox_send_message() places the pointer to the message to the queue (add_to_rbuf) then calls msg_submit(chan) to submit the first of the queued messaged to the mailbox. Some of mailbox drivers can return errors from their .send_data() callbacks, e.g., if the message is invalid or there is something wrong with the mailbox device. In this case: * hrtimer is not started by msg_submit(); * the pointer to that message remains in the queue; * if mbox_send_message() is called in blocking mode, it will needlessly wait for tx_tout ms (or for an hour if tx_out is not set), then it will call tx_tick(chan, -ETIME). tx_tick() will then try to submit the first message in the queue - the same message as before. The underlying driver might reject it again. The problematic message could then remain in the queue forever, which would prevent the system from sending other, maybe unrelated messages via the same mailbox channel. Moreover, the caller would be unable to free or reuse the message structure. Let us remove the message from the queue and error out from mbox_send_message() early if sending of the message fails. As for tx_tick() - not sure, if chan->cl->tx_done() should still be called if msg_submit(chan) reports an error. For now, tx_tick() will exit early too. Signed-off-by: Evgenii Shatokhin --- drivers/mailbox/mailbox.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 04db5ef58f93..32d9ba05427e 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -82,10 +82,9 @@ static int msg_submit(struct mbox_chan *chan) chan->cl->tx_prepare(chan->cl, data); /* Try to submit a message to the MBOX controller */ err =3D chan->mbox->ops->send_data(chan, data); - if (!err) { + chan->msg_count--; + if (!err) chan->active_req =3D data; - chan->msg_count--; - } exit: spin_unlock_irqrestore(&chan->lock, flags); =20 @@ -102,6 +101,7 @@ static void tx_tick(struct mbox_chan *chan, int r) { unsigned long flags; void *mssg; + int err; =20 spin_lock_irqsave(&chan->lock, flags); mssg =3D chan->active_req; @@ -109,9 +109,8 @@ static void tx_tick(struct mbox_chan *chan, int r) spin_unlock_irqrestore(&chan->lock, flags); =20 /* Submit next message */ - msg_submit(chan); - - if (!mssg) + err =3D msg_submit(chan); + if (!mssg || err) return; =20 /* Notify the client */ @@ -276,6 +275,8 @@ int mbox_send_message(struct mbox_chan *chan, void *mss= g) } =20 err =3D msg_submit(chan); + if (err) + return err; =20 if (chan->cl->tx_block) { unsigned long wait; @@ -293,7 +294,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mss= g) } } =20 - return (err < 0) ? err : t; + return t; } EXPORT_SYMBOL_GPL(mbox_send_message); =20 --=20 2.34.1