Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1229722
| From | Linus Torvalds <torvalds@linux-foundation.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 4/5] locking/rwsem: Use acquire/release semantics |
| Date | 2015-09-21 22:40 +0200 |
| Message-ID | <qbg2t-Cu-7@gated-at.bofh.it> (permalink) |
| References | <qbfJ7-fE-3@gated-at.bofh.it> <qbfJ8-fE-13@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Mon, Sep 21, 2015 at 1:17 PM, Davidlohr Bueso <dave@stgolabs.net> wrote:
> @@ -114,7 +114,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
> {
> long tmp;
>
> - tmp = atomic_long_add_return(-RWSEM_WAITING_BIAS,
> + tmp = atomic_long_add_return_acquire(-RWSEM_WAITING_BIAS,
> (atomic_long_t *)&sem->count);
> if (tmp < 0)
> rwsem_downgrade_wake(sem);
Careful. I'm pretty sure this is wrong.
When we downgrade exclusive ownership to non-exclusive, that should be
a *release* operation. Anything we did inside the write-locked region
had damn better _stay_ inside the write-locked region, we can not
allow it to escape down into the read-locked side. So it needs to be
at least a release.
In contrast, anything that we do in the read-locked part is fine to be
re-ordered into the write-locked exclusive part, so it does *not* need
acquire ordering (the original write locking obviously did use
acquire, and acts as a barrier for everything that comes in the locked
region).
I tried to look through everything, and I think this is the only thing
you got wrong, but I'd like somebody to double-checks. Getting the
acquire/release semantics wrong will cause some really really subtle
and hard-as-hell-to-find bugs. So let's be careful out there, ok?
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/5] locking: Use acquire/release semantics Davidlohr Bueso <dave@stgolabs.net> - 2015-09-21 22:20 +0200
[PATCH 4/5] locking/rwsem: Use acquire/release semantics Davidlohr Bueso <dave@stgolabs.net> - 2015-09-21 22:20 +0200
Re: [PATCH 4/5] locking/rwsem: Use acquire/release semantics Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-21 22:40 +0200
[PATCH v2] locking/rwsem: Use acquire/release semantics Davidlohr Bueso <dave@stgolabs.net> - 2015-09-24 03:10 +0200
[PATCH 3/5] locking/rtmutex: Use acquire/release semantics Davidlohr Bueso <dave@stgolabs.net> - 2015-09-21 22:20 +0200
Re: [PATCH 3/5] locking/rtmutex: Use acquire/release semantics Thomas Gleixner <tglx@linutronix.de> - 2015-09-22 17:40 +0200
Re: [PATCH 3/5] locking/rtmutex: Use acquire/release semantics Davidlohr Bueso <dave@stgolabs.net> - 2015-09-22 18:00 +0200
[PATCH v2] locking/rtmutex: Use acquire/release semantics Davidlohr Bueso <dave@stgolabs.net> - 2015-09-24 03:10 +0200
Re: [PATCH v2] locking/rtmutex: Use acquire/release semantics Thomas Gleixner <tglx@linutronix.de> - 2015-09-27 12:40 +0200
Re: [PATCH v2] locking/rtmutex: Use acquire/release semantics Davidlohr Bueso <dave@stgolabs.net> - 2015-09-28 22:00 +0200
Re: [PATCH v2] locking/rtmutex: Use acquire/release semantics Thomas Gleixner <tglx@linutronix.de> - 2015-09-29 23:00 +0200
[PATCH 1/5] asm-generic: Add _{relaxed|acquire|release}() variants for inc/dec atomics Davidlohr Bueso <dave@stgolabs.net> - 2015-09-21 22:20 +0200
csiph-web