[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 01/25] util/qht: Document memory ordering assumptions
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 01/25] util/qht: Document memory ordering assumptions |
Date: |
Tue, 2 Aug 2016 21:39:11 +0200 |
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 <address@hidden>
[Sergey Fedorov: commit title and message provided;
comment on qht_remove() elided]
Signed-off-by: Sergey Fedorov <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qemu/qht.h | 5 +++++
util/qht.c | 7 ++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/qemu/qht.h b/include/qemu/qht.h
index 70bfc68..311139b 100644
--- a/include/qemu/qht.h
+++ b/include/qemu/qht.h
@@ -69,6 +69,9 @@ void qht_destroy(struct qht *ht);
* Attempting to insert a NULL @p is a bug.
* Inserting the same pointer @p with different @hash values is a bug.
*
+ * In case of successful operation, smp_wmb() is implied before the pointer is
+ * inserted into the hash table.
+ *
* Returns true on sucess.
* Returns false if the @address@hidden pair already exists in the hash table.
*/
@@ -83,6 +86,8 @@ bool qht_insert(struct qht *ht, void *p, uint32_t hash);
*
* Needs to be called under an RCU read-critical section.
*
+ * smp_read_barrier_depends() is implied before the call to @func.
+ *
* The user-provided @func compares pointers in QHT against @userp.
* If the function returns true, a match has been found.
*
diff --git a/util/qht.c b/util/qht.c
index 40d6e21..28ce289 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;
--
2.7.4
- [Qemu-devel] [PULL 00/25] Misc QEMU fixes for 2016-08-02, Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 01/25] util/qht: Document memory ordering assumptions,
Paolo Bonzini <=
- [Qemu-devel] [PULL 02/25] numa: set the memory backend "is_mapped" field, Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 03/25] fix qemu exit on memory hotplug when allocation fails at prealloc time, Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 04/25] checkpatch: add check for bzero, Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 06/25] util: drop unix_nonblocking_connect(), Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 05/25] util: drop inet_nonblocking_connect(), Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 08/25] qht: do not segfault when gathering stats from an uninitialized qht, Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 09/25] target-i386: fix typo in xsetbv implementation, Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 10/25] qdist: fix memory leak during binning, Paolo Bonzini, 2016/08/02
- [Qemu-devel] [PULL 07/25] util: Drop inet_listen(), Paolo Bonzini, 2016/08/02