Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1700135

Re: [tip:locking/urgent] locking/static_key: Fix concurrent static_key_slow_inc()

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [tip:locking/urgent] locking/static_key: Fix concurrent static_key_slow_inc()
Date 2017-07-31 17:50 +0200
Message-ID <u9l7b-82B-1@gated-at.bofh.it> (permalink)
References (1 earlier) <rNvhE-6a1-51@gated-at.bofh.it> <u9fl7-4xv-5@gated-at.bofh.it> <u9iCl-6GI-1@gated-at.bofh.it> <u9j5o-6QC-19@gated-at.bofh.it> <u9kXw-7Zm-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Jul 31, 2017 at 05:35:40PM +0200, Paolo Bonzini wrote:
> On 31/07/2017 15:33, Peter Zijlstra wrote:
> > On Mon, Jul 31, 2017 at 03:04:06PM +0200, Paolo Bonzini wrote:
> >> - the smp_mb (though it could be a smp_wmb or atomic_set_release)
> >> initially triggered my paranoia indeed.  But even then, I can't see why
> >> you would need it because there's nothing it pairs with.
> > 
> > So this one would pair with the mb implied by the cmpxchg loop for
> > inc-if-positive. The ordering being that if we see a positive v, we must
> > then also see all the text modifications.
> > 
> > So if jump_label_update() were to not fully serialize things, it would
> > be possible for the v=1 store to appear before the last text changes.
> > And in that case we'd allow the fast path to complete
> > static_key_slow_inc() before it was in fact done with changing all text.
> > 
> > Now, I suspect (but did not audit) that anything that changes text must
> > in fact serialize world, but I wasn't sure.
> 
> I see.  Then yes, I agree a smp_wmb would be nicer here.

I'll make it atomic_set_release() and a comment.

> >> Rather, it's *any use of key->enabled outside jump_label_lock*
> >> (meaning: any use of static_key_enabled and static_key_count outside
> >> the core jump_label.c code) that should be handled with care.
> > 
> >> - net/ipv4/udp.c and net/ipv6/udp.c want to implement a "once-only"
> >> increment of the static key.  It's racy and maybe we should provide a
> >> new API static_key_enable_forever:
> >>
> >> 	void static_key_enable_forever(struct static_key *key)
> >> 	{
> >> 	        STATIC_KEY_CHECK_USE();
> >> 	        if (atomic_read(&key->enabled) > 0)
> >> 	                return;
> >>
> >> 	        cpus_read_lock();
> >> 	        jump_label_lock();
> >> 	        if (atomic_read(&key->enabled) == 0) {
> >> 	                atomic_set(&key->enabled, -1);
> >> 	                jump_label_update(key);
> >> 	                atomic_set(&key->enabled, 1);
> >> 	        }
> >> 	        jump_label_unlock();
> >> 	        cpus_read_unlock();
> >> 	}
> >> 	EXPORT_SYMBOL_GPL(static_key_enable_forever);
> >>
> >> I can prepare a patch if you agree.
> > 
> > Isn't that what we have static_key_enable() for? Which btw also uses
> > static_key_count() outside of the mutex.
> 
> Yes, they should be fixed and net/ can then use static_key_enable.

Right, let me try and fix _enable().

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [tip:locking/urgent] locking/static_key: Fix concurrent  static_key_slow_inc() Peter Zijlstra <peterz@infradead.org> - 2017-07-31 11:40 +0200
  Re: [tip:locking/urgent] locking/static_key: Fix concurrent  static_key_slow_inc() Paolo Bonzini <pbonzini@redhat.com> - 2017-07-31 15:10 +0200
    Re: [tip:locking/urgent] locking/static_key: Fix concurrent  static_key_slow_inc() Peter Zijlstra <peterz@infradead.org> - 2017-07-31 15:40 +0200
      Re: [tip:locking/urgent] locking/static_key: Fix concurrent  static_key_slow_inc() Paolo Bonzini <pbonzini@redhat.com> - 2017-07-31 17:40 +0200
        Re: [tip:locking/urgent] locking/static_key: Fix concurrent  static_key_slow_inc() Peter Zijlstra <peterz@infradead.org> - 2017-07-31 17:50 +0200
          Re: [tip:locking/urgent] locking/static_key: Fix concurrent  static_key_slow_inc() Paolo Bonzini <pbonzini@redhat.com> - 2017-07-31 21:30 +0200
      Re: [tip:locking/urgent] locking/static_key: Fix concurrent static_key_slow_inc() Dima Zavin <dmitriyz@waymo.com> - 2017-07-31 19:20 +0200

csiph-web