Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp231548pxx; Wed, 28 Oct 2020 03:33:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWhntYPVIpBuk/bWgkzwty1pbHQrJoAmB+zTJhPLUpO2rFNvfQwk/dDabUdSc2Mg9zT9vd X-Received: by 2002:a05:6402:195:: with SMTP id r21mr6875855edv.164.1603881199331; Wed, 28 Oct 2020 03:33:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603881199; cv=none; d=google.com; s=arc-20160816; b=dNZIYIVsardTmwTL1xAAwi888XEw174Gfg9KhOWoFSUvJKubzVphyC000WulChjGYX xJ3vGzYL1tKSFEyKPQhykP8YDecMm69K8RebvBRCMXmyBYTTx4FFqIa8UKdk6ZGb47QW HarPhURGR6KROJ8wpTkOcU9GalVg89dXyjbzDGWXy4e4PhdeIHcIn3bt+EpXcB7hIQtv F4kRmpVLBgeXOL1ZZi1P0w7Mp0JpKhQhAbfSD6KVLL0f5Iu5y25UPbcg/6D7xhmWfDw6 0m9Al0YecQvb2K+3VrBiM7NXYv3qQ5i29S/GU9jlVfUG3gCsJ/+lyIQVUOooyIUUu0iN AWYw== 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=ByngN8NZvORXf0Fc4nD1hE8NK/fZ/GVYEK/6+kjVWRg=; b=p2DcXAL1L34oWDPTXSLHkmia4XY4tki9VzaP5aZIF9WtkGRquNncx398WY+1Dq4WzA vmFSUmyEjcaxRKcK+PpLy/ypEnLsQGzhXlMuOoPDYFsQVdWyC7qyLHgD/GsNp9BdaS8x /zC3YxeneCliC46E4MYUa0bOLSkcoTwjABjhqHLNgafaWjcWI8zgtnoR8pj9AwvmfJoM RyJTUI/rkHaJCqFcdsdK14GAz9pETLgTUPbieBh2JTYagjqtHu2HqH0igUyGqfeST1p4 vBt/rAEcLWL4QUVTfI6dYNw3L9slXsvPRvqSByq/1yqD+1cbf3GDBjXzAQ1XFe5fbDle tiNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vDBeBir/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bs17si3022913ejb.543.2020.10.28.03.32.57; Wed, 28 Oct 2020 03:33:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vDBeBir/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762512AbgJ0OnM (ORCPT + 99 others); Tue, 27 Oct 2020 10:43:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:39438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761725AbgJ0OkO (ORCPT ); Tue, 27 Oct 2020 10:40:14 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8EF4120773; Tue, 27 Oct 2020 14:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809614; bh=y0GFApQjWZe2gHBjOjdI0yRNIDYlQa3AZzDzTjZdvoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vDBeBir/X32T91M5PRG6rASIvXUNa5Scsk8fD5XhmyydG9QpDrOP4aJUX7ayIfhHJ SBpdiOm1nbTSaUdfZM9lOO1SlTgHKPkDUAKTdhfgQdj+eCS9wTV7ynze2ZHrr4u75u xxzQwl5roS2t0wmH7Uw1hFmj0L0rj/YkyRXuUWIc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Da Xue , Sudeep Holla , Jerome Brunet , Jassi Brar , Sasha Levin Subject: [PATCH 5.4 259/408] mailbox: avoid timer start from callback Date: Tue, 27 Oct 2020 14:53:17 +0100 Message-Id: <20201027135507.056604428@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jassi Brar [ Upstream commit c7dacf5b0f32957b24ef29df1207dc2cd8307743 ] If the txdone is done by polling, it is possible for msg_submit() to start the timer while txdone_hrtimer() callback is running. If the timer needs recheduling, it could already be enqueued by the time hrtimer_forward_now() is called, leading hrtimer to loudly complain. WARNING: CPU: 3 PID: 74 at kernel/time/hrtimer.c:932 hrtimer_forward+0xc4/0x110 CPU: 3 PID: 74 Comm: kworker/u8:1 Not tainted 5.9.0-rc2-00236-gd3520067d01c-dirty #5 Hardware name: Libre Computer AML-S805X-AC (DT) Workqueue: events_freezable_power_ thermal_zone_device_check pstate: 20000085 (nzCv daIf -PAN -UAO BTYPE=--) pc : hrtimer_forward+0xc4/0x110 lr : txdone_hrtimer+0xf8/0x118 [...] This can be fixed by not starting the timer from the callback path. Which requires the timer reloading as long as any message is queued on the channel, and not just when current tx is not done yet. Fixes: 0cc67945ea59 ("mailbox: switch to hrtimer for tx_complete polling") Reported-by: Da Xue Reviewed-by: Sudeep Holla Tested-by: Sudeep Holla Acked-by: Jerome Brunet Tested-by: Jerome Brunet Signed-off-by: Jassi Brar Signed-off-by: Sasha Levin --- drivers/mailbox/mailbox.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 0b821a5b2db84..3e7d4b20ab34f 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -82,9 +82,12 @@ static void msg_submit(struct mbox_chan *chan) exit: spin_unlock_irqrestore(&chan->lock, flags); - if (!err && (chan->txdone_method & TXDONE_BY_POLL)) - /* kick start the timer immediately to avoid delays */ - hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); + /* 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); + } } static void tx_tick(struct mbox_chan *chan, int r) @@ -122,11 +125,10 @@ static enum hrtimer_restart txdone_hrtimer(struct hrtimer *hrtimer) 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; } } -- 2.25.1