Skip to contentSkip to conversation

seqlock: provide the same ordering semantics as mainline

PATCH In review Julia Cartwright 2 participants 2 messages Apr 26, 2018 – May 28, 2018 1 message not in the archive Locking primitives

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 seqlock: provide the same ordering semantics as mainline

The mainline implementation of read_seqbegin() orders prior loads w.r.t. the read-side critical section. Fixup the RT writer-boosting implementation to provide the same guarantee.

Also, while we're here, update the usage of ACCESS_ONCE() to use READ_ONCE().

Fixes e69f15cf77c23 ("seqlock: Prevent rt starvation")

---
Found during code inspection of the RT seqlock implementation.

Julia

 include/linux/seqlock.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/seqlock.h +2 -1
index a59751276b94..597ce5a9e013 100644
@@ -453,7 +453,7 @@ static inline unsigned read_seqbegin(seqlock_t *sl)
 	unsigned ret;
 
 repeat:
-	ret = ACCESS_ONCE(sl->seqcount.sequence);
+	ret = READ_ONCE(sl->seqcount.sequence);
 	if (unlikely(ret & 1)) {
 		/*
 		 * Take the lock and let the writer proceed (i.e. evtl
@@ -462,6 +462,7 @@ static inline unsigned read_seqbegin(seqlock_t *sl)
 		spin_unlock_wait(&sl->lock);
 		goto repeat;
 	}
+	smp_rmb();
 	return ret;
 }
 #endif
Signature · 1 line
2.16.1
#2 lore raw
Quoted 6 lines · Julia Cartwright

The mainline implementation of read_seqbegin() orders prior loads w.r.t. the read-side critical section. Fixup the RT writer-boosting implementation to provide the same guarantee.

Also, while we're here, update the usage of ACCESS_ONCE() to use READ_ONCE().

I'm taking this without the READ_ONCE hunk because ACCESS_ONCE is gone since v4.15 and I had to move on in v4.16.

Quoted 3 lines
Fixes e69f15cf77c23 ("seqlock: Prevent rt starvation")

Sebastian