aboutsummaryrefslogtreecommitdiff
path: root/util/qht.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2016-07-15 20:58:41 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2016-08-02 12:03:58 +0200
commit34506b30e4210b417aa38d1518aa2c53fb7cf39b (patch)
treeeb3653db2474e880a5735baebe8c83a6d395f572 /util/qht.c
parentcc0100f464c94bf80ad36cd432f4a1ed58126b60 (diff)
util/qht: Document memory ordering assumptions
It is naturally expected that some memory ordering should be provided around qht_insert() and qht_lookup(). Document these assumptions in the header file and put some comments in the source to denote how that memory ordering requirements are fulfilled. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [Sergey Fedorov: commit title and message provided; comment on qht_remove() elided] Signed-off-by: Sergey Fedorov <serge.fdrv@gmail.com> Message-Id: <20160715175852.30749-2-sergey.fedorov@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/qht.c')
-rw-r--r--util/qht.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/qht.c b/util/qht.c
index 40d6e218f7..28ce289245 100644
--- a/util/qht.c
+++ b/util/qht.c
@@ -445,7 +445,11 @@ void *qht_do_lookup(struct qht_bucket *head, qht_lookup_func_t func,
do {
for (i = 0; i < QHT_BUCKET_ENTRIES; i++) {
if (b->hashes[i] == hash) {
- void *p = atomic_read(&b->pointers[i]);
+ /* The pointer is dereferenced before seqlock_read_retry,
+ * so (unlike qht_insert__locked) we need to use
+ * atomic_rcu_read here.
+ */
+ void *p = atomic_rcu_read(&b->pointers[i]);
if (likely(p) && likely(func(p, userp))) {
return p;
@@ -535,6 +539,7 @@ static bool qht_insert__locked(struct qht *ht, struct qht_map *map,
atomic_rcu_set(&prev->next, b);
}
b->hashes[i] = hash;
+ /* smp_wmb() implicit in seqlock_write_begin. */
atomic_set(&b->pointers[i], p);
seqlock_write_end(&head->sequence);
return true;