All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org,
	netdev@vger.kernel.org, akpm@linux-foundation.org,
	mingo@redhat.com, dave@stgolabs.net, manfred@colorfullife.com,
	tj@kernel.org, arnd@arndb.de, linux-arch@vger.kernel.org,
	will.deacon@arm.com, peterz@infradead.org,
	stern@rowland.harvard.edu, parri.andrea@gmail.com,
	torvalds@linux-foundation.org
Subject: Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair
Date: Fri, 30 Jun 2017 10:21:01 -0700	[thread overview]
Message-ID: <20170630172101.GA3162@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170630161607.GX2393@linux.vnet.ibm.com>

On Fri, Jun 30, 2017 at 09:16:07AM -0700, Paul E. McKenney wrote:
> On Fri, Jun 30, 2017 at 05:20:10PM +0200, Oleg Nesterov wrote:
> > On 06/30, Paul E. McKenney wrote:
> > >
> > > > > +		raw_spin_lock_irq(&task->pi_lock);
> > > > > +		raw_spin_unlock_irq(&task->pi_lock);
> > >
> > > I agree that the spin_unlock_wait() implementations would avoid the
> > > deadlock with an acquisition from an interrupt handler, while also
> > > avoiding the need to momentarily disable interrupts.  The ->pi_lock is
> > > a per-task lock, so I am assuming (perhaps naively) that contention is
> > > not a problem.  So is the overhead of interrupt disabling likely to be
> > > noticeable here?
> > 
> > I do not think the overhead will be noticeable in this particular case.
> > 
> > But I am not sure I understand why do we want to unlock_wait. Yes I agree,
> > it has some problems, but still...

Well, I tried documenting exactly what it did and did not do, which got
an ack from Peter.

	https://marc.info/?l=linux-kernel&m=149575078313105

However, my later pull request spawned a bit of discussion:

	https://marc.info/?l=linux-kernel&m=149730349001044

This discussion led me to propose strengthening spin_unlock_wait()
to act as a lock/unlock pair.  This can be implemented on x86 as
an smp_mb() followed by a read-only spinloop, as shown on branch
spin_unlock_wait.2017.06.23a on my -rcu tree.

Linus was not amused, and said that if we were going to make
spin_unlock_wait() have the semantics of lock+unlock, we should just
open-code that, especially given that there are way more definitions
of spin_unlock_wait() than there are uses.  He also suggested making
spin_unlock_wait() have only acquire semantics (x86 spin loop with
no memory-barrier instructions) and add explicit barriers where
required.

	https://marc.info/?l=linux-kernel&m=149860012913036

I did a series for this which may be found on branch
spin_unlock_wait.2017.06.27a on my -rcu tree.

This approach was not loved by others (see later on the above thread), and
Linus's reply (which reiterated his opposition to lock+unlock semantics)
suggested the possibility of removing spin_unlock_wait() entirely.

	https://marc.info/?l=linux-kernel&m=149869476911620

So I figured, in for a penny, in for a pound, and therefore did the series
that includes this patch.  The most recent update (which does not yet
include your improved version) is on branch spin_unlock_wait.2017.06.30b
of my -rcu tree.

Hey, you asked!  ;-)

							Thanx, Paul

> > The code above looks strange for me. If we are going to repeat this pattern
> > the perhaps we should add a helper for lock+unlock and name it unlock_wait2 ;)
> > 
> > If not, we should probably change this code more:
> 
> This looks -much- better than my patch!  May I have your Signed-off-by?
> 
> 							Thanx, Paul
> 
> > --- a/kernel/task_work.c
> > +++ b/kernel/task_work.c
> > @@ -96,20 +96,16 @@ void task_work_run(void)
> >  		 * work->func() can do task_work_add(), do not set
> >  		 * work_exited unless the list is empty.
> >  		 */
> > +		raw_spin_lock_irq(&task->pi_lock);
> >  		do {
> >  			work = READ_ONCE(task->task_works);
> >  			head = !work && (task->flags & PF_EXITING) ?
> >  				&work_exited : NULL;
> >  		} while (cmpxchg(&task->task_works, work, head) != work);
> > +		raw_spin_unlock_irq(&task->pi_lock);
> > 
> >  		if (!work)
> >  			break;
> > -		/*
> > -		 * Synchronize with task_work_cancel(). It can't remove
> > -		 * the first entry == work, cmpxchg(task_works) should
> > -		 * fail, but it can play with *work and other entries.
> > -		 */
> > -		raw_spin_unlock_wait(&task->pi_lock);
> > 
> >  		do {
> >  			next = work->next;
> > 
> > performance-wise this is almost the same, and if we do not really care about
> > overhead we can simplify the code: this way it is obvious that we can't race
> > with task_work_cancel().
> > 
> > Oleg.
> > 

  reply	other threads:[~2017-06-30 17:21 UTC|newest]

Thread overview: 211+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29 23:59 [PATCH RFC 0/26] Remove spin_unlock_wait() Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 01/26] netfilter: Replace spin_unlock_wait() with lock/unlock pair Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
     [not found]   ` <a6642feb-2f3a-980f-5ed6-2deb79563e6b@colorfullife.com>
2017-07-02  2:00     ` Paul E. McKenney
2017-07-03 14:39     ` Alan Stern
2017-07-03 14:39       ` Alan Stern
2017-07-03 17:14       ` Paul E. McKenney
2017-07-03 19:01         ` Manfred Spraul
2017-07-03 19:57           ` Alan Stern
2017-07-03 19:57             ` Alan Stern
2017-07-06 18:43             ` Manfred Spraul
2017-07-06 18:43               ` Manfred Spraul
2017-07-06 18:43               ` Manfred Spraul
2017-07-03 20:04         ` Alan Stern
2017-07-03 20:04           ` Alan Stern
2017-07-03 20:53           ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 02/26] task_work: " Paul E. McKenney
2017-06-30 11:04   ` Oleg Nesterov
2017-06-30 12:50     ` Paul E. McKenney
2017-06-30 15:20       ` Oleg Nesterov
2017-06-30 16:16         ` Paul E. McKenney
2017-06-30 17:21           ` Paul E. McKenney [this message]
2017-06-30 19:21           ` Oleg Nesterov
2017-06-30 19:50             ` Alan Stern
2017-06-30 19:50               ` Alan Stern
2017-06-30 20:04               ` Paul E. McKenney
2017-06-30 20:02             ` Paul E. McKenney
2017-06-30 20:19               ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 03/26] sched: " Paul E. McKenney
2017-06-30 10:31   ` Arnd Bergmann
2017-06-30 12:35     ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 04/26] completion: " Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 05/26] exit: " Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 06/26] ipc: " Paul E. McKenney
2017-07-01 19:23   ` Manfred Spraul
2017-07-02  3:16     ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 07/26] drivers/ata: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 08/26] locking: Remove spin_unlock_wait() generic definitions Paul E. McKenney
2017-06-30  9:19   ` Will Deacon
2017-06-30 12:38     ` Paul E. McKenney
2017-06-30 13:13       ` Will Deacon
2017-06-30 22:18         ` Paul E. McKenney
2017-07-03 13:15           ` Will Deacon
2017-07-03 16:18             ` Paul E. McKenney
2017-07-03 16:40               ` Linus Torvalds
2017-07-03 17:13                 ` Will Deacon
2017-07-03 22:30                   ` Paul E. McKenney
2017-07-03 22:49                     ` Linus Torvalds
2017-07-04  0:39                       ` Paul E. McKenney
2017-07-04  0:54                         ` Paul E. McKenney
2017-07-03 21:10                 ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 09/26] alpha: Remove spin_unlock_wait() arch-specific definitions Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 10/26] arc: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 11/26] arm: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 12/26] arm64: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  9:20   ` Will Deacon
2017-06-30  9:20     ` Will Deacon
2017-06-30 17:29     ` Paul E. McKenney
2017-06-30 17:29       ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 13/26] blackfin: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 14/26] hexagon: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 15/26] ia64: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 16/26] m32r: " Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 17/26] metag: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 18/26] mips: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 19/26] mn10300: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 20/26] parisc: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 21/26] powerpc: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-07-02  3:58   ` Boqun Feng
2017-07-05 23:57     ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 22/26] s390: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 23/26] sh: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 24/26] sparc: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 25/26] tile: " Paul E. McKenney
2017-06-30  0:06   ` Linus Torvalds
2017-06-30  0:09     ` Paul E. McKenney
2017-06-30  0:14       ` Paul E. McKenney
2017-06-30  0:10     ` Linus Torvalds
2017-06-30  0:24       ` Paul E. McKenney
2017-06-30  0:01 ` [PATCH RFC 26/26] xtensa: " Paul E. McKenney
2017-06-30  0:01   ` Paul E. McKenney
2017-07-05 23:29 ` [PATCH v2 0/9] Remove spin_unlock_wait() Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 1/9] net/netfilter/nf_conntrack_core: Fix net_conntrack_lock() Paul E. McKenney
2017-07-05 23:31     ` Paul E. McKenney
2017-07-06 18:45     ` Manfred Spraul
2017-07-06 18:45       ` Manfred Spraul
2017-07-06 18:45       ` Manfred Spraul
2017-07-06 20:26       ` Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 2/9] task_work: Replace spin_unlock_wait() with lock/unlock pair Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 3/9] sched: " Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 4/9] completion: " Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 5/9] exit: " Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 6/9] ipc: " Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 7/9] drivers/ata: " Paul E. McKenney
2017-07-05 23:31     ` Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 8/9] locking: Remove spin_unlock_wait() generic definitions Paul E. McKenney
2017-07-05 23:31   ` [PATCH v2 9/9] arch: Remove spin_unlock_wait() arch-specific definitions Paul E. McKenney
2017-07-06 14:12   ` [PATCH v2 0/9] Remove spin_unlock_wait() David Laight
2017-07-06 15:21     ` Paul E. McKenney
2017-07-06 15:21       ` Paul E. McKenney
2017-07-06 15:21       ` Paul E. McKenney
2017-07-06 16:10       ` Peter Zijlstra
2017-07-06 16:10         ` Peter Zijlstra
2017-07-06 16:10         ` Peter Zijlstra
2017-07-06 16:24         ` Paul E. McKenney
2017-07-06 16:24           ` Paul E. McKenney
2017-07-06 16:24           ` Paul E. McKenney
2017-07-06 16:41           ` Peter Zijlstra
2017-07-06 16:41             ` Peter Zijlstra
2017-07-06 16:41             ` Peter Zijlstra
2017-07-06 17:03             ` Paul E. McKenney
2017-07-06 17:03               ` Paul E. McKenney
2017-07-06 17:03               ` Paul E. McKenney
2017-07-06 16:49           ` Alan Stern
2017-07-06 16:54             ` Peter Zijlstra
2017-07-06 16:54               ` Peter Zijlstra
2017-07-06 19:37               ` Alan Stern
2017-07-06 19:37                 ` Alan Stern
2017-07-06 16:05     ` Peter Zijlstra
2017-07-06 16:05       ` Peter Zijlstra
2017-07-06 16:05       ` Peter Zijlstra
2017-07-06 16:20       ` Paul E. McKenney
2017-07-06 16:20         ` Paul E. McKenney
2017-07-06 16:20         ` Paul E. McKenney
2017-07-06 16:50         ` Peter Zijlstra
2017-07-06 16:50           ` Peter Zijlstra
2017-07-06 16:50           ` Peter Zijlstra
2017-07-06 17:08           ` Will Deacon
2017-07-06 17:08             ` Will Deacon
2017-07-06 17:08             ` Will Deacon
2017-07-06 17:29             ` Paul E. McKenney
2017-07-06 17:29               ` Paul E. McKenney
2017-07-06 17:29               ` Paul E. McKenney
2017-07-06 17:18           ` Paul E. McKenney
2017-07-06 17:18             ` Paul E. McKenney
2017-07-06 17:18             ` Paul E. McKenney
2017-07-07  8:31           ` Ingo Molnar
2017-07-07  8:31             ` Ingo Molnar
2017-07-07  8:31             ` Ingo Molnar
2017-07-07  8:44             ` Peter Zijlstra
2017-07-07  8:44               ` Peter Zijlstra
2017-07-07  8:44               ` Peter Zijlstra
2017-07-07 10:33               ` Ingo Molnar
2017-07-07 10:33                 ` Ingo Molnar
2017-07-07 10:33                 ` Ingo Molnar
2017-07-07 11:23                 ` Peter Zijlstra
2017-07-07 11:23                   ` Peter Zijlstra
2017-07-07 11:23                   ` Peter Zijlstra
2017-07-07 14:41             ` Paul E. McKenney
2017-07-07 14:41               ` Paul E. McKenney
2017-07-08  8:43               ` Ingo Molnar
2017-07-08  8:43                 ` Ingo Molnar
2017-07-08 11:41                 ` Paul E. McKenney
2017-07-08 11:41                   ` Paul E. McKenney
2017-07-07 17:47             ` Manfred Spraul
2017-07-07 17:47               ` Manfred Spraul
2017-07-07 17:47               ` Manfred Spraul
2017-07-08  8:35               ` Ingo Molnar
2017-07-08  8:35                 ` Ingo Molnar
2017-07-08 11:39                 ` Paul E. McKenney
2017-07-08 11:39                   ` Paul E. McKenney
2017-07-08 12:30                   ` Ingo Molnar
2017-07-08 12:30                     ` Ingo Molnar
2017-07-08 14:45                     ` Paul E. McKenney
2017-07-08 14:45                       ` Paul E. McKenney
2017-07-08 16:21                     ` Alan Stern
2017-07-08 16:21                       ` Alan Stern
2017-07-10 17:22                       ` Manfred Spraul
2017-07-07  8:06       ` Ingo Molnar
2017-07-07  8:06         ` Ingo Molnar
2017-07-07  8:06         ` Ingo Molnar
2017-07-07  9:32         ` Ingo Molnar
2017-07-07  9:32           ` Ingo Molnar
2017-07-07  9:32           ` Ingo Molnar
2017-07-07 19:27   ` [PATCH v3 " Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 1/9] net/netfilter/nf_conntrack_core: Fix net_conntrack_lock() Paul E. McKenney
2017-07-07 19:28       ` Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 2/9] task_work: Replace spin_unlock_wait() with lock/unlock pair Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 3/9] sched: " Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 4/9] completion: " Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 5/9] exit: " Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 6/9] ipc: " Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 7/9] drivers/ata: " Paul E. McKenney
2017-07-07 19:28       ` Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 8/9] locking: Remove spin_unlock_wait() generic definitions Paul E. McKenney
2017-07-07 19:28     ` [PATCH v3 9/9] arch: Remove spin_unlock_wait() arch-specific definitions Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170630172101.GA3162@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=dave@stgolabs.net \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=parri.andrea@gmail.com \
    --cc=peterz@infradead.org \
    --cc=stern@rowland.harvard.edu \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.