Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp595140iog; Mon, 13 Jun 2022 08:49:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1thi30lL6SFwqDLY1bRl2Tyjum9IBR3mbgV3Zao0ikG1e8FoBWNDvak6YJL4HKsfAlnMw93 X-Received: by 2002:a17:90b:3b8a:b0:1e2:ee1e:6340 with SMTP id pc10-20020a17090b3b8a00b001e2ee1e6340mr482326pjb.38.1655135352157; Mon, 13 Jun 2022 08:49:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655135352; cv=none; d=google.com; s=arc-20160816; b=lWyAMjBbgyRTcg6mdtiaczLrfJu+rpXacYC8GO2LzC+msqLLy7YEZ7XV0g9+8Ghwpo Vc7wfTHSJPKPDFfc77bi23PvPBS0Q/l6ljo0XEOhJYaBoQ21ilp4sckHpEhwTtKgj9ta uVdRzTkyU5SNEfbOfXXIdVikKIX7Pt9Bo57QVk7tSDC6au+IUZ73YpwzN3/8kTlQzX/J AyIiA0Q3jMbNtcwzKVq4b3CrThcvBlpG7CdNBrvxrNQ+OEMi3tJx4Ny9oR3vBN9aBYkr Qxm0cQIJkuVWskRmEFsKFvvQxDA/Sq/eOqd9wtQX2Jy0OSDa5W3MvwWLM6GshDG9oO+o 62DA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M1szxmphUqgEyHZxmg7EGj9SEvxVZtJK4RZxgvN/qPA=; b=V0n/CXs5/UkszhKxYqoL+jwf6YkJ8CBvI/BrIMAVcVwpw5wU6u7abiXakqrJLMB5fN EW6b75C8vM5/TXuc7GPLy+2TtuEqY/IQI1wDyZbmDpQXzUxi52aLWvuxhQuB1g0MO1Vw ckf5zA0pv8BtCT02Nr7Xdt4uW1gEGrs3RIJ3gJpcY/lFVTrKwGFE3RkPJ4soKIcS3vXW 80LTUK3Pwq6dKh/DbgrApTlNJBtVaom+5tV/TcdD6IeHDviOnWvEx2gBMUPncvAOoYM6 hmIP3oOUo2vf9TjwwH73ohVmzVNzZ+Cj8LDhAxx+TkAXPnMwsS/OX+1wIET/CRjUphNH 4Lug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="XWskt4O/"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l2-20020a170903244200b00153b2d16577si11145627pls.383.2022.06.13.08.48.58; Mon, 13 Jun 2022 08:49:12 -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=@linuxfoundation.org header.s=korg header.b="XWskt4O/"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344282AbiFMKuC (ORCPT + 99 others); Mon, 13 Jun 2022 06:50:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345326AbiFMKs2 (ORCPT ); Mon, 13 Jun 2022 06:48:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4BFA2C676; Mon, 13 Jun 2022 03:26:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B895460F0B; Mon, 13 Jun 2022 10:26:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA411C34114; Mon, 13 Jun 2022 10:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115965; bh=ViJROby02GyZyQYTg0MYFcHMxaI8kXhKPs9s2mAtsnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XWskt4O/vtcWOgiMXupj3rSc8PlOL1d5zncrScHW4zLMPrHZU+WgK1wuRB69aeQAq KaoX/tHvOBN8ryVywXH99mej2315zYSPx03XG1ZuaaaAzpsssYVCQuOmIH4PI0J/3Z ymL4qV5tJaCWsjAn3o++NuMqVRWIUiHocZlE+aa4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Bj=C3=B6rn=20Ard=C3=B6?= , Jassi Brar , Sasha Levin Subject: [PATCH 4.14 096/218] mailbox: forward the hrtimer if not queued and under a lock Date: Mon, 13 Jun 2022 12:09:14 +0200 Message-Id: <20220613094923.460487927@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Björn Ardö [ Upstream commit bca1a1004615efe141fd78f360ecc48c60bc4ad5 ] This reverts commit c7dacf5b0f32957b24ef29df1207dc2cd8307743, "mailbox: avoid timer start from callback" The previous commit was reverted since it lead to a race that caused the hrtimer to not be started at all. The check for hrtimer_active() in msg_submit() will return true if the callback function txdone_hrtimer() is currently running. This function could return HRTIMER_NORESTART and then the timer will not be restarted, and also msg_submit() will not start the timer. This will lead to a message actually being submitted but no timer will start to check for its compleation. The original fix that added checking hrtimer_active() was added to avoid a warning with hrtimer_forward. Looking in the kernel another solution to avoid this warning is to check hrtimer_is_queued() before calling hrtimer_forward_now() instead. This however requires a lock so the timer is not started by msg_submit() inbetween this check and the hrtimer_forward() call. Fixes: c7dacf5b0f32 ("mailbox: avoid timer start from callback") Signed-off-by: Björn Ardö Signed-off-by: Jassi Brar Signed-off-by: Sasha Levin --- drivers/mailbox/mailbox.c | 19 +++++++++++++------ include/linux/mailbox_controller.h | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 10a559cfb7ea..aa28fdcb81b9 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -85,11 +85,11 @@ static void msg_submit(struct mbox_chan *chan) exit: spin_unlock_irqrestore(&chan->lock, flags); - /* kick start the timer immediately to avoid delays */ if (!err && (chan->txdone_method & TXDONE_BY_POLL)) { - /* but only if not already active */ - if (!hrtimer_active(&chan->mbox->poll_hrt)) - hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); + /* kick start the timer immediately to avoid delays */ + spin_lock_irqsave(&chan->mbox->poll_hrt_lock, flags); + hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); + spin_unlock_irqrestore(&chan->mbox->poll_hrt_lock, flags); } } @@ -123,20 +123,26 @@ static enum hrtimer_restart txdone_hrtimer(struct hrtimer *hrtimer) container_of(hrtimer, struct mbox_controller, poll_hrt); bool txdone, resched = false; int i; + unsigned long flags; for (i = 0; i < mbox->num_chans; i++) { struct mbox_chan *chan = &mbox->chans[i]; if (chan->active_req && chan->cl) { - resched = true; txdone = chan->mbox->ops->last_tx_done(chan); if (txdone) tx_tick(chan, 0); + else + resched = true; } } if (resched) { - hrtimer_forward_now(hrtimer, ms_to_ktime(mbox->txpoll_period)); + spin_lock_irqsave(&mbox->poll_hrt_lock, flags); + if (!hrtimer_is_queued(hrtimer)) + hrtimer_forward_now(hrtimer, ms_to_ktime(mbox->txpoll_period)); + spin_unlock_irqrestore(&mbox->poll_hrt_lock, flags); + return HRTIMER_RESTART; } return HRTIMER_NORESTART; @@ -473,6 +479,7 @@ int mbox_controller_register(struct mbox_controller *mbox) hrtimer_init(&mbox->poll_hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL); mbox->poll_hrt.function = txdone_hrtimer; + spin_lock_init(&mbox->poll_hrt_lock); } for (i = 0; i < mbox->num_chans; i++) { diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h index 74deadb42d76..5a4524f66ea1 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -83,6 +83,7 @@ struct mbox_controller { const struct of_phandle_args *sp); /* Internal to API */ struct hrtimer poll_hrt; + spinlock_t poll_hrt_lock; struct list_head node; }; -- 2.35.1