From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Zijlstra Subject: Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work Date: Thu, 25 Feb 2016 13:59:32 +0100 Message-ID: <20160225125932.GI6357@twins.programming.kicks-ass.net> References: <1456153030-12400-9-git-send-email-pmladek@suse.com> <201602230025.uuCAc4Tn%fengguang.wu@intel.com> <20160224161805.GB3305@pathway.suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20160224161805.GB3305@pathway.suse.cz> Sender: owner-linux-mm@kvack.org To: Petr Mladek Cc: kbuild test robot , kbuild-all@01.org, Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Steven Rostedt , "Paul E. McKenney" , Josh Triplett , Thomas Gleixner , Linus Torvalds , Jiri Kosina , Borislav Petkov , Michal Hocko , linux-mm@kvack.org, Vlastimil Babka , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org List-Id: linux-api@vger.kernel.org On Wed, Feb 24, 2016 at 05:18:05PM +0100, Petr Mladek wrote: > @@ -770,7 +782,22 @@ void delayed_kthread_work_timer_fn(unsigned long __data) > if (WARN_ON_ONCE(!worker)) > return; > > - spin_lock(&worker->lock); > + /* > + * We might be unable to take the lock if someone is trying to > + * cancel this work and calls del_timer_sync() when this callback > + * has already been removed from the timer list. > + */ > + while (!spin_trylock(&worker->lock)) { > + /* > + * Busy wait with spin_is_locked() to avoid cache bouncing. > + * Break when canceling is set to avoid a deadlock. > + */ > + do { > + if (work->canceling) > + return; > + cpu_relax(); > + } while (spin_is_locked(&worker->lock)); > + } > /* Work must not be used with more workers, see queue_kthread_work(). */ > WARN_ON_ONCE(work->worker != worker); > This is pretty vile; why can't you drop the lock over del_timer_sync() ? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760333AbcBYM7r (ORCPT ); Thu, 25 Feb 2016 07:59:47 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:38457 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759934AbcBYM7q (ORCPT ); Thu, 25 Feb 2016 07:59:46 -0500 Date: Thu, 25 Feb 2016 13:59:32 +0100 From: Peter Zijlstra To: Petr Mladek Cc: kbuild test robot , kbuild-all@01.org, Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Steven Rostedt , "Paul E. McKenney" , Josh Triplett , Thomas Gleixner , Linus Torvalds , Jiri Kosina , Borislav Petkov , Michal Hocko , linux-mm@kvack.org, Vlastimil Babka , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work Message-ID: <20160225125932.GI6357@twins.programming.kicks-ass.net> References: <1456153030-12400-9-git-send-email-pmladek@suse.com> <201602230025.uuCAc4Tn%fengguang.wu@intel.com> <20160224161805.GB3305@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160224161805.GB3305@pathway.suse.cz> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 24, 2016 at 05:18:05PM +0100, Petr Mladek wrote: > @@ -770,7 +782,22 @@ void delayed_kthread_work_timer_fn(unsigned long __data) > if (WARN_ON_ONCE(!worker)) > return; > > - spin_lock(&worker->lock); > + /* > + * We might be unable to take the lock if someone is trying to > + * cancel this work and calls del_timer_sync() when this callback > + * has already been removed from the timer list. > + */ > + while (!spin_trylock(&worker->lock)) { > + /* > + * Busy wait with spin_is_locked() to avoid cache bouncing. > + * Break when canceling is set to avoid a deadlock. > + */ > + do { > + if (work->canceling) > + return; > + cpu_relax(); > + } while (spin_is_locked(&worker->lock)); > + } > /* Work must not be used with more workers, see queue_kthread_work(). */ > WARN_ON_ONCE(work->worker != worker); > This is pretty vile; why can't you drop the lock over del_timer_sync() ?