From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A669CC2BA83 for ; Thu, 13 Feb 2020 08:33:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C63021734 for ; Thu, 13 Feb 2020 08:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729526AbgBMIdg (ORCPT ); Thu, 13 Feb 2020 03:33:36 -0500 Received: from mx2.suse.de ([195.135.220.15]:39770 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbgBMIdg (ORCPT ); Thu, 13 Feb 2020 03:33:36 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5767EAB92; Thu, 13 Feb 2020 08:33:34 +0000 (UTC) Date: Thu, 13 Feb 2020 09:33:33 +0100 From: Petr Mladek To: Grygorii Strashko Cc: "linux-kernel@vger.kernel.org" , linux-rt-users@vger.kernel.org, Linux ARM , netdev , Richard Cochran Subject: Re: Question about kthread_mod_delayed_work() allowed context Message-ID: <20200213083333.jglatxs5j76z2634@pathway.suse.cz> References: <20200212154116.hh2vdyi7e2xflxr5@pathway.suse.cz> <59802c56-1013-3042-167d-89f288f51b58@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <59802c56-1013-3042-167d-89f288f51b58@ti.com> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org On Wed 2020-02-12 21:17:53, Grygorii Strashko wrote: > > > On 12/02/2020 17:41, Petr Mladek wrote: > > On Tue 2020-02-11 12:23:59, Grygorii Strashko wrote: > > > Hi All, > > > > > > I'd like to ask question about allowed calling context for kthread_mod_delayed_work(). > > > > > > The comment to kthread_mod_delayed_work() says: > > > > > > * This function is safe to call from any context including IRQ handler. > > > * See __kthread_cancel_work() and kthread_delayed_work_timer_fn() > > > * for details. > > > */ > > > > > > But it has del_timer_sync() inside which seems can't be called from hard_irq context: > > > kthread_mod_delayed_work() > > > |-__kthread_cancel_work() > > > |- del_timer_sync() > > > |- WARN_ON(in_irq() && !(timer->flags & TIMER_IRQSAFE)); > > > > It is safe because kthread_delayed_work_timer_fn() is IRQ safe. > > Note that it uses raw_spin_lock_irqsave(). It is the reason why > > the timer could have set TIMER_IRQSAFE flag, see > > KTHREAD_DELAYED_WORK_INIT(). > > > > In more details. The timer is either canceled before the callback > > is called. Or it waits for the callback but the callback is safe > > because it can't sleep. > > I think, my issue (warning) could be related to the fact that kthread_init_delayed_work() > is used, which seems doesn't set TIMER_IRQSAFE flag. Great catch! It is a bug. Would you like to send the fix for kthread_init_delayed_work() or would you prefer me doing so? Best Regards, Petr