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: <20151124102143.GG10750@pathway.suse.cz>
Date:	Tue, 24 Nov 2015 11:21:43 +0100
From:	Petr Mladek <pmladek@...e.com>
To:	Tejun Heo <tj@...nel.org>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	Oleg Nesterov <oleg@...hat.com>,
	Ingo Molnar <mingo@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>,
	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 v3 09/22] kthread: Allow to cancel kthread work

On Mon 2015-11-23 17:58:23, Tejun Heo wrote:
> Hello,
> 
> On Wed, Nov 18, 2015 at 02:25:14PM +0100, Petr Mladek wrote:
> > +static int
> > +try_to_cancel_kthread_work(struct kthread_work *work,
> > +				   spinlock_t *lock,
> > +				   unsigned long *flags)
> > +{
> > +	int ret = 0;
> > +
> > +	if (work->timer) {
> > +		/* Try to cancel the timer if pending. */
> > +		if (del_timer(work->timer)) {
> > +			ret = 1;
> > +			goto out;
> > +		}
> > +
> > +		/* Are we racing with the timer callback? */
> > +		if (timer_active(work->timer)) {
> > +			/* Bad luck, need to avoid a deadlock. */
> > +			spin_unlock_irqrestore(lock, *flags);
> > +			del_timer_sync(work->timer);
> > +			ret = -EAGAIN;
> > +			goto out;
> > +		}
> 
> As the timer side is already kinda trylocking anyway, can't the cancel
> path be made simpler?  Sth like
> 
> 	lock(worker);
> 	work->canceling = true;
> 	del_timer_sync(work->timer);
> 	unlock(worker);
> 
> And the timer can do (ignoring the multiple worker support, do we even
> need that?)
> 
> 	while (!trylock(worker)) {
> 		if (work->canceling)
> 			return;
> 		cpu_relax();
> 	}
> 	queue;
> 	unlock(worker);

Why did I not find out this myself ?:-)

Thanks for hint,
Petr
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ