Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1386785pxu; Fri, 16 Oct 2020 10:37:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyblcmmkp54JwA6kyw1rJmUl+NibWDBlVB9XNKnUMsVTXFInadvJlag51MkBzSRJHg/BcIQ X-Received: by 2002:a17:907:42d6:: with SMTP id ng6mr4734787ejb.464.1602869841041; Fri, 16 Oct 2020 10:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602869841; cv=none; d=google.com; s=arc-20160816; b=cwiqXYAU5rw23wRnwdfmojeQYUAwithCl3RKc6b6wg69egJt4NPAY2sqLBY4am0+jZ jKWfOzHSfcPuzt5L09O6oUCQD/Vjr9uBwfE0Y4BtEoW1G1sNqwHd2z9ayedGlAey+C9Z GjnHC2h3Z4CV5qOVm1YOgYyDCxXwuoR0ZE5CB1NKBNsA47K9QCrMe2gGjITFLZss+6+j 5d/37wUM/uXFe/y/F+3eI/0J5n1I2B5RCyLSPsmc7a9HCt3JDmopYYGDOdqMc3LT/bdn h1pCN89DDYiNe6SHCkkxZnM/mAYJaLdwJ/OIRBxiiCWugQOgBz280PmhAtQAUtrmxVHI HbBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QQNx5lbWWREoG92H9GWCHwFrOsjOJReO5JJROvxhPeA=; b=nkMlRDpTZNMADzu1YW87OppGJ1XKOIxRicUVRHv9yAg1sL0MnO5XkAt09zL+5vnuFM UElbeXT4TS0C/HdOPyhSpp8uxOAC0Pkh4rFPOoopmiutdkF329kMqYAzjrqmZVGxd1+D ZCF2ltVKu5Wu5uiEIzN2SP+g69+8ePTlI08Oo9LrdexaNP0pb2BX47YLyWKiqGIbCSDe NJLRHpcyIcucRR5vE0zW+atP9nR792B4iGjc9JBJHvatzXzCmclZpgdjnVyA0WgTqXZS yQIRtVdPRMyLq7H0skvKjw7zPqKgT0oP56HaRwM3eiTVKI3cz4Nn5lFHwSnwOy47d9Ps CPhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MyFCI1d5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bc8si2166712edb.79.2020.10.16.10.36.55; Fri, 16 Oct 2020 10:37:21 -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=@gmail.com header.s=20161025 header.b=MyFCI1d5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391251AbgJPReI (ORCPT + 99 others); Fri, 16 Oct 2020 13:34:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390235AbgJPReI (ORCPT ); Fri, 16 Oct 2020 13:34:08 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FCBDC061755 for ; Fri, 16 Oct 2020 10:34:08 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id p16so3546548ilq.5 for ; Fri, 16 Oct 2020 10:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QQNx5lbWWREoG92H9GWCHwFrOsjOJReO5JJROvxhPeA=; b=MyFCI1d57eYhGAHzNbPzG0+gwYQAPxbalJwgjSW3Xqd7s2+P4uhkgk30gxqP/ihsvQ KF7AvZIciGhSezS3QwLEja/cPTQDqJafJnNdZxZlCIf0vTsPdXD9Q9cshuO9TkutzWfQ ZAoP/KiSOVuFakNyI8LvzZLyuakFqxRi4ZzsqUJu7Pe8KdVeoKHeIyH+k4OWEFxozyCa 5+TFuqYQOhZzIHK05h9JUTmtHxl9ACg1oGGohQgBDKcXuqyQD19KN3haqgRW3myQ+ppE ofO4JeH99ih+xoeSNvSPp//8olyMBOwbZlIdCeKkgxReTNifQzN5QHAqumDS43rAchzN zmGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QQNx5lbWWREoG92H9GWCHwFrOsjOJReO5JJROvxhPeA=; b=jAW7TPxHZvU41xJvTVmmxYSIHkAsQOHzh0GqwwYjnZ6CMPEmeujQr3MI4iGoHZLdEo vpfVTMsiT2y+l7H/tzEbGamuI955tebqSktfEDnXO9vgFZ/J9+3CO3Xn+6/2S0HDZoWK f+YVCJywbG6F0JDoi+Qk4yvIgZkH9i5ptkx1z7a3FfODdBgDOe369KABTylc2s3QO5D9 B3cUc30xmNjagJnMK61qwGX2D2uajOzKSPNo6OotJbMWqkXt1QrYtcZze85znR/t4VDD oEOZPWjR3x30ZkbVKtzWOTLYAI1WLofgO72zc+zj1puxwUfyXVySycPCxMeuq/bTGBGn o6gg== X-Gm-Message-State: AOAM5317KSwcBbAtCFoSwic75WN5aBDTSzBoSuH5mjACXyP0QitApUXB k43q8qJHr0rWywzQi5b7hyNAjbbErTlbo2l7kjo= X-Received: by 2002:a92:600e:: with SMTP id u14mr3557017ilb.303.1602869647783; Fri, 16 Oct 2020 10:34:07 -0700 (PDT) MIME-Version: 1.0 References: <20200923123916.1115962-1-jbrunet@baylibre.com> <20201015134628.GA11989@arm.com> <1jlfg7k2ux.fsf@starbuckisacylon.baylibre.com> <20201016085217.GA12323@arm.com> <1jk0vqk0ju.fsf@starbuckisacylon.baylibre.com> In-Reply-To: <1jk0vqk0ju.fsf@starbuckisacylon.baylibre.com> From: Jassi Brar Date: Fri, 16 Oct 2020 12:33:57 -0500 Message-ID: Subject: Re: [PATCH] mailbox: cancel timer before starting it To: Jerome Brunet Cc: Ionela Voinescu , Kevin Hilman , "open list:ARM/Amlogic Meson..." , Da Xue , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 16, 2020 at 4:00 AM Jerome Brunet wrote: > > > On Fri 16 Oct 2020 at 10:52, Ionela Voinescu wrote: > > > On Thursday 15 Oct 2020 at 13:45:54 (-0500), Jassi Brar wrote: > > [..] > >> > >> --- a/drivers/mailbox/mailbox.c > >> > >> +++ b/drivers/mailbox/mailbox.c > >> > >> @@ -82,9 +82,13 @@ 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 */ > >> > >> + if (!err && (chan->txdone_method & TXDONE_BY_POLL)) { > >> > >> + /* Disable the timer if already active ... */ > >> > >> + hrtimer_cancel(&chan->mbox->poll_hrt); > >> > >> + > >> > >> + /* ... and kick start it immediately to avoid delays */ > >> > >> hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); > >> > >> + } > >> > >> } > >> > >> > >> > >> static void tx_tick(struct mbox_chan *chan, int r) > >> > > > >> > > I've tracked a regression back to this commit. Details to reproduce: > >> > > >> > Hi Ionela, > >> > > >> > I don't have access to your platform and I don't get what is going on > >> > from the log below. > >> > > >> > Could you please give us a bit more details about what is going on ? > >> > > >> > All this patch does is add hrtimer_cancel(). > >> > * It is needed if the timer had already been started, which is > >> > appropriate AFAIU > >> > * It is a NO-OP is the timer is not active. > >> > > >> Can you please try using hrtimer_try_to_cancel() instead ? > >> > > > > Yes, using hrtimer_try_to_cancel() instead works for me. But doesn't > > this limit how effective this change is? AFAIU, this will possibly only > > reduce the chances for the race condition, but not solve it. > > > > It is also my understanding, hrtimer_try_to_cancel() would remove a > timer which as not already started but would return withtout doing > anything if the callback is already running ... which is the original > problem > If we are running in the callback path, hrtimer_try_to_cancel will return -1, in which case we could skip hrtimer_start. Anyways, I think simply checking for hrtimer_active should effect the same. I have submitted a patch, of course not tested. Thanks