aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2016-10-10 10:39:29 +0100
committerPeter Maydell <peter.maydell@linaro.org>2016-10-10 10:39:29 +0100
commit86e121ae75d10d0aa4ef76150e94a2e83bdac3e9 (patch)
treea2feb88ccccb1f6a9480f0b6e15e4e31ad6cce39 /util
parent48f592118ab42f83a1a7561c4bfd2b72a100f241 (diff)
parent78e87797ba0b6612fc1c95216a0b81c744fb85b0 (diff)
downloadqemu-arm-86e121ae75d10d0aa4ef76150e94a2e83bdac3e9.tar.gz
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
* Thread Sanitizer fixes (Alex) * Coverity fixes (David) * test-qht fixes (Emilio) * QOM interface for info irq/info pic (Hervé) * -rtc clock=rt fix (Junlian) * mux chardev fixes (Marc-André) * nicer report on death by signal (Michal) * qemu-tech TLC (Paolo) * MSI support for edu device (Peter) * qemu-nbd --offset fix (Tomáš) # gpg: Signature made Fri 07 Oct 2016 17:25:10 BST # gpg: using RSA key 0xBFFBD25F78C7AE83 # gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" # gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" # Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4 E2F7 7E15 100C CD36 69B1 # Subkey fingerprint: F133 3857 4B66 2389 866C 7682 BFFB D25F 78C7 AE83 * remotes/bonzini/tags/for-upstream: (39 commits) qemu-doc: merge qemu-tech and qemu-doc qemu-tech: rewrite some parts qemu-tech: reorganize content qemu-tech: move TCG test documentation to tests/tcg/README qemu-tech: move user mode emulation features from qemu-tech qemu-tech: document lazy condition code evaluation in cpu.h qemu-tech: move text from qemu-tech to tcg/README qemu-doc: drop installation and compilation notes qemu-doc: replace introduction with the one from the internals manual qemu-tech: drop index test-qht: perform lookups under rcu_read_lock qht: fix unlock-after-free segfault upon resizing qht: simplify qht_reset_size qemu-nbd: Shrink image size by specified offset qemu_kill_report: Report PID name too util: Introduce qemu_get_pid_name char: update read handler in all cases char: use a fixed idx for child muxed chr i8259: give ISA device when registering ISA ioports .travis.yml: add gcc sanitizer build ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util')
-rw-r--r--util/oslib-posix.c27
-rw-r--r--util/oslib-win32.c7
-rw-r--r--util/qht.c65
3 files changed, 69 insertions, 30 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index aaec1891f5..8ec99ccb4f 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -46,6 +46,7 @@
#ifdef __FreeBSD__
#include <sys/sysctl.h>
+#include <libutil.h>
#endif
#include "qemu/mmap-alloc.h"
@@ -434,6 +435,32 @@ int qemu_read_password(char *buf, int buf_size)
}
+char *qemu_get_pid_name(pid_t pid)
+{
+ char *name = NULL;
+
+#if defined(__FreeBSD__)
+ /* BSDs don't have /proc, but they provide a nice substitute */
+ struct kinfo_proc *proc = kinfo_getproc(pid);
+
+ if (proc) {
+ name = g_strdup(proc->ki_comm);
+ free(proc);
+ }
+#else
+ /* Assume a system with reasonable procfs */
+ char *pid_path;
+ size_t len;
+
+ pid_path = g_strdup_printf("/proc/%d/cmdline", pid);
+ g_file_get_contents(pid_path, &name, &len, NULL);
+ g_free(pid_path);
+#endif
+
+ return name;
+}
+
+
pid_t qemu_fork(Error **errp)
{
sigset_t oldmask, newmask;
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 4c1dcf1e66..d09863cc9d 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -575,6 +575,13 @@ int qemu_read_password(char *buf, int buf_size)
}
+char *qemu_get_pid_name(pid_t pid)
+{
+ /* XXX Implement me */
+ abort();
+}
+
+
pid_t qemu_fork(Error **errp)
{
errno = ENOSYS;
diff --git a/util/qht.c b/util/qht.c
index 16a8d7950e..ff4d2e6974 100644
--- a/util/qht.c
+++ b/util/qht.c
@@ -133,7 +133,8 @@ struct qht_map {
/* trigger a resize when n_added_buckets > n_buckets / div */
#define QHT_NR_ADDED_BUCKETS_THRESHOLD_DIV 8
-static void qht_do_resize(struct qht *ht, struct qht_map *new);
+static void qht_do_resize_reset(struct qht *ht, struct qht_map *new,
+ bool reset);
static void qht_grow_maybe(struct qht *ht);
#ifdef QHT_DEBUG
@@ -379,7 +380,7 @@ static void qht_bucket_reset__locked(struct qht_bucket *head)
if (b->pointers[i] == NULL) {
goto done;
}
- b->hashes[i] = 0;
+ atomic_set(&b->hashes[i], 0);
atomic_set(&b->pointers[i], NULL);
}
b = b->next;
@@ -408,12 +409,21 @@ void qht_reset(struct qht *ht)
qht_map_unlock_buckets(map);
}
+static inline void qht_do_resize(struct qht *ht, struct qht_map *new)
+{
+ qht_do_resize_reset(ht, new, false);
+}
+
+static inline void qht_do_resize_and_reset(struct qht *ht, struct qht_map *new)
+{
+ qht_do_resize_reset(ht, new, true);
+}
+
bool qht_reset_size(struct qht *ht, size_t n_elems)
{
- struct qht_map *new;
+ struct qht_map *new = NULL;
struct qht_map *map;
size_t n_buckets;
- bool resize = false;
n_buckets = qht_elems_to_buckets(n_elems);
@@ -421,18 +431,11 @@ bool qht_reset_size(struct qht *ht, size_t n_elems)
map = ht->map;
if (n_buckets != map->n_buckets) {
new = qht_map_create(n_buckets);
- resize = true;
- }
-
- qht_map_lock_buckets(map);
- qht_map_reset__all_locked(map);
- if (resize) {
- qht_do_resize(ht, new);
}
- qht_map_unlock_buckets(map);
+ qht_do_resize_and_reset(ht, new);
qemu_mutex_unlock(&ht->lock);
- return resize;
+ return !!new;
}
static inline
@@ -444,7 +447,7 @@ 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) {
+ if (atomic_read(&b->hashes[i]) == hash) {
/* The pointer is dereferenced before seqlock_read_retry,
* so (unlike qht_insert__locked) we need to use
* atomic_rcu_read here.
@@ -538,8 +541,8 @@ static bool qht_insert__locked(struct qht *ht, struct qht_map *map,
if (new) {
atomic_rcu_set(&prev->next, b);
}
- b->hashes[i] = hash;
/* smp_wmb() implicit in seqlock_write_begin. */
+ atomic_set(&b->hashes[i], hash);
atomic_set(&b->pointers[i], p);
seqlock_write_end(&head->sequence);
return true;
@@ -561,9 +564,7 @@ static __attribute__((noinline)) void qht_grow_maybe(struct qht *ht)
if (qht_map_needs_resize(map)) {
struct qht_map *new = qht_map_create(map->n_buckets * 2);
- qht_map_lock_buckets(map);
qht_do_resize(ht, new);
- qht_map_unlock_buckets(map);
}
qemu_mutex_unlock(&ht->lock);
}
@@ -607,10 +608,10 @@ qht_entry_move(struct qht_bucket *to, int i, struct qht_bucket *from, int j)
qht_debug_assert(to->pointers[i]);
qht_debug_assert(from->pointers[j]);
- to->hashes[i] = from->hashes[j];
+ atomic_set(&to->hashes[i], from->hashes[j]);
atomic_set(&to->pointers[i], from->pointers[j]);
- from->hashes[j] = 0;
+ atomic_set(&from->hashes[j], 0);
atomic_set(&from->pointers[j], NULL);
}
@@ -739,24 +740,31 @@ static void qht_map_copy(struct qht *ht, void *p, uint32_t hash, void *userp)
}
/*
- * Call with ht->lock and all bucket locks held.
- *
- * Creating the @new map here would add unnecessary delay while all the locks
- * are held--holding up the bucket locks is particularly bad, since no writes
- * can occur while these are held. Thus, we let callers create the new map,
- * hopefully without the bucket locks held.
+ * Atomically perform a resize and/or reset.
+ * Call with ht->lock held.
*/
-static void qht_do_resize(struct qht *ht, struct qht_map *new)
+static void qht_do_resize_reset(struct qht *ht, struct qht_map *new, bool reset)
{
struct qht_map *old;
old = ht->map;
- g_assert_cmpuint(new->n_buckets, !=, old->n_buckets);
+ qht_map_lock_buckets(old);
+ if (reset) {
+ qht_map_reset__all_locked(old);
+ }
+
+ if (new == NULL) {
+ qht_map_unlock_buckets(old);
+ return;
+ }
+
+ g_assert_cmpuint(new->n_buckets, !=, old->n_buckets);
qht_map_iter__all_locked(ht, old, qht_map_copy, new);
qht_map_debug__all_locked(new);
atomic_rcu_set(&ht->map, new);
+ qht_map_unlock_buckets(old);
call_rcu(old, qht_map_destroy, rcu);
}
@@ -768,12 +776,9 @@ bool qht_resize(struct qht *ht, size_t n_elems)
qemu_mutex_lock(&ht->lock);
if (n_buckets != ht->map->n_buckets) {
struct qht_map *new;
- struct qht_map *old = ht->map;
new = qht_map_create(n_buckets);
- qht_map_lock_buckets(old);
qht_do_resize(ht, new);
- qht_map_unlock_buckets(old);
ret = true;
}
qemu_mutex_unlock(&ht->lock);