lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160226162552.GB6356@twins.programming.kicks-ass.net>
Date:	Fri, 26 Feb 2016 17:25:52 +0100
From:	Peter Zijlstra <peterz@...radead.org>
To:	Petr Mladek <pmladek@...e.com>
Cc:	kbuild test robot <lkp@...el.com>, kbuild-all@...org,
	Andrew Morton <akpm@...ux-foundation.org>,
	Oleg Nesterov <oleg@...hat.com>, Tejun Heo <tj@...nel.org>,
	Ingo Molnar <mingo@...hat.com>,
	Steven Rostedt <rostedt@...dmis.org>,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	Josh Triplett <josh@...htriplett.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Jiri Kosina <jkosina@...e.cz>, Borislav Petkov <bp@...e.de>,
	Michal Hocko <mhocko@...e.cz>, linux-mm@...ck.org,
	Vlastimil Babka <vbabka@...e.cz>, linux-api@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work

On Fri, Feb 26, 2016 at 04:38:18PM +0100, Petr Mladek wrote:
> On Thu 2016-02-25 13:59:32, Peter Zijlstra wrote:
> > 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() ?
> 
> We would need to take the lock later and check if nobody has set the timer
> again in the meantime.

Well, if ->cancelling is !0, nobody should be re-queueing, re-arming
timers etc.., right?

And since you do add_timer() while holding the spinlock, this should all
work out, no?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ