Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1117539rwn; Thu, 15 Sep 2022 10:40:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM79UxEnBRlgUelHoeT7H+UeRSrp57mT1nkdxub2WSHrFDk5KPrlMlIv2+h8Gt123zT1b9ps X-Received: by 2002:aa7:9e52:0:b0:53e:49b2:1c6e with SMTP id z18-20020aa79e52000000b0053e49b21c6emr928936pfq.70.1663263658203; Thu, 15 Sep 2022 10:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663263658; cv=none; d=google.com; s=arc-20160816; b=JO5h/UhRsZISugFM19w5GabzRLgzoE3CT4jE8AgTz9R2hRIczUt9yI9q38riUHsuz/ 1onOMkzXPYYTeZQuzUACI0ulDQKNIhOOUZTkkOU3EJseb1SPVhGM1JAv2RM88ISSjz9y RLHisMeV7CJQThmV4l8wDt534PHxntkQ8pHVm5CK2iJw2D0VtCslwcFt3lmBu7PTcy/X 3ebfRXNRQKPgihKGZth+XgpcqW+2XndSlhFfHqGK/4wN77ods4CBo5j4Z5jf+DKxNxu4 xRMtn6W7gkRsEGtVlMx+o8uTsEn+CO8WSkFU6b9/A6rlqIbFwsL9vxTsKAxT6aXFF33r 7khw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xMrARy1sLvYMN9C0F7NWZYkaf/PETUqd8xlWWeAtKYM=; b=C7rb7XEMLWLVjVN+0WLZApIzEoPJhhzLx6yv7gCc91gWdH73+IrHtLCom+FdVa42Mr iD11Qy/PbfaVVjlr1Evx1dApv1LSAudp5/WqnD08c0fMBIx//XnLejdMDsbkJn+XWHPV WJBmWdFLI1mJ8ob0Khii6bs2PFhfyXZhWtTqnb2W/SYqccl7fKXvPZgrpgFlzjs6cEI6 +iuAiQ2S0s/YgBJewkvF6ayxJNvhB5p1CjQca2YqhGBSc8Utuo1IPSAM7stwfNEciOk+ Xr6ZaNaYLO1yur7wL5JIZdrkLD0xuUj/kFfhsMqVfU75yzPC1t77QxcOmuXv2JTXgnbL tehw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yadro.com header.s=mta-01 header.b=Kxmm8Op1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yadro.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d13-20020a170902e14d00b00176da6b5705si16364590pla.145.2022.09.15.10.40.46; Thu, 15 Sep 2022 10:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yadro.com header.s=mta-01 header.b=Kxmm8Op1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yadro.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbiIOQv2 (ORCPT + 99 others); Thu, 15 Sep 2022 12:51:28 -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: 8bit Content-Type: text/plain 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) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 = chan->mbox->ops->send_data(chan, data); - if (!err) { + chan->msg_count--; + if (!err) chan->active_req = data; - chan->msg_count--; - } exit: spin_unlock_irqrestore(&chan->lock, flags); @@ -102,6 +101,7 @@ static void tx_tick(struct mbox_chan *chan, int r) { unsigned long flags; void *mssg; + int err; spin_lock_irqsave(&chan->lock, flags); mssg = chan->active_req; @@ -109,9 +109,8 @@ static void tx_tick(struct mbox_chan *chan, int r) spin_unlock_irqrestore(&chan->lock, flags); /* Submit next message */ - msg_submit(chan); - - if (!mssg) + err = msg_submit(chan); + if (!mssg || err) return; /* Notify the client */ @@ -276,6 +275,8 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg) } err = msg_submit(chan); + if (err) + return err; if (chan->cl->tx_block) { unsigned long wait; @@ -293,7 +294,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg) } } - return (err < 0) ? err : t; + return t; } EXPORT_SYMBOL_GPL(mbox_send_message); -- 2.34.1