Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp188478pxx; Wed, 28 Oct 2020 02:09:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAJgiiXqfH1kl8sVg3gdp2fxADyNuICIPK6OEPoDX/qApo+LG3CBajtHE+opLvSCmrLFad X-Received: by 2002:a17:906:4a03:: with SMTP id w3mr6685554eju.15.1603876140070; Wed, 28 Oct 2020 02:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603876140; cv=none; d=google.com; s=arc-20160816; b=wHfbkoDDyl4+2XXaciDFXq4ra1zjtlCYHD3jyPivizu4+t8eLCItti4ZTGUSmXmQJt HdXU0gPlNAmmx3BbpmeLFvqTVBkbRMDqWOpZlwmxIW0XxOwquxLUy+/HP70ANa9nr2Pz pMb+u8FEGWJ8cyjLpOi+Bhw09DtwzZDmTLyLLnZ9FLfcgIHcnNsEL0kdMP+LNVxmQb/J Qjp3oGEveCWtLsLWJ2UmDK9sWq3Ml1z4dvvyFpWd1Zgo4dar+TFmELWqMI8APvWkm9Fv F+SZaqXmLzTC7nusGKbmcPkOonSZMtqBUdjRlwVm3aMg1RWUsGwfWJVFuh9bYM23DY7F 9xGQ== 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=XbtVY+ZaniqOqRLTM4/BasPesgMfjytlvetYTpVWM+o=; b=Rc+1L3YdaFVq8yypNAH5GgxbnxVh90cWbEX+LeZX9RypFFu9Y0kuMOOy9516X5GIj1 DJFSvatBgu8NxkTzBURh/qLfIF7+OfCEdwlFyNdP0+4B64rplTM6EHRMj6WaBL+XU0kG YXXJ4L75//eL/rEDJ7+Fbs6tNgY5qYVU+PCmPOA+4COmS+SWCYRp7p5GEjeALU6dLsbj 3TZ2aTpDEg+Pq55AFBfYeMFj+dUEcc1aV3NAZSQfltDb2G2qkeQRWp2xVIrk8ToJPG+B cx1DR258jUVDDcAEySdYvIaWV0kYN+Px0y8zC3/5hJPDa8ImiohJ/s2dePvvXfxAQQaa Yzzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Pw8aKHgJ; 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 lg14si2653130ejb.82.2020.10.28.02.08.37; Wed, 28 Oct 2020 02:09:00 -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=Pw8aKHgJ; 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 S1757196AbgJ0OQm (ORCPT + 99 others); Tue, 27 Oct 2020 10:16:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:34258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756375AbgJ0OM4 (ORCPT ); Tue, 27 Oct 2020 10:12:56 -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 8194A206F7; Tue, 27 Oct 2020 14:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807976; bh=XO1slJuy6Cd3iCL3vp7XmhG9W9rFGULZpdZ0D9mMAVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pw8aKHgJvzyxw2eMy9NXypierrXZE7ucd0AZlS01DPSBuu3dTyfhVQP88o8Xx+iRb k9fZiaX0f+wHKHvatB2nZ1XhiHV8k4V0uM8E2TrXmEdZOmtVsyO85M/F9greBqwknR jzQO5Jrb3fIXjDPQfozBatpkTWNXbegFIT6olJaI= 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 4.14 111/191] mailbox: avoid timer start from callback Date: Tue, 27 Oct 2020 14:49:26 +0100 Message-Id: <20201027134915.046390238@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@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 055c90b8253cb..10a559cfb7ea3 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -85,9 +85,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) @@ -125,11 +128,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