Received: from eggs.gnu.org ([2001:4830:134:3::10]:34534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYU6-0004UF-VY for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:59:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsYU4-0008QZ-0E for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYU3-0008QR-Ql for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:55 -0400 From: Paolo Bonzini Date: Fri, 7 Oct 2016 18:57:53 +0200 Message-Id: <1475859483-32234-30-git-send-email-pbonzini@redhat.com> In-Reply-To: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> References: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 29/39] test-qht: perform lookups under rcu_read_lock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "Emilio G. Cota" From: "Emilio G. Cota" qht_lookup is meant to be called from an RCU read-critical section. Make sure we're in such a section in test-qht when performing lookups, despite the fact that no races in qht can be triggered by test-qht since it is single-threaded. Note that rcu_register_thread is already called by the rcu_after_fork hook, and therefore duplicating it here would be a bug. Signed-off-by: Emilio G. Cota Message-Id: <1475706880-10667-4-git-send-email-cota@braap.org> Signed-off-by: Paolo Bonzini --- tests/test-qht.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test-qht.c b/tests/test-qht.c index 46a64b6..9b7423a 100644 --- a/tests/test-qht.c +++ b/tests/test-qht.c @@ -6,6 +6,7 @@ */ #include "qemu/osdep.h" #include "qemu/qht.h" +#include "qemu/rcu.h" #define N 5000 @@ -51,6 +52,7 @@ static void check(int a, int b, bool expected) struct qht_stats stats; int i; + rcu_read_lock(); for (i = a; i < b; i++) { void *p; uint32_t hash; @@ -61,6 +63,8 @@ static void check(int a, int b, bool expected) p = qht_lookup(&ht, is_equal, &val, hash); g_assert_true(!!p == expected); } + rcu_read_unlock(); + qht_statistics_init(&ht, &stats); if (stats.used_head_buckets) { g_assert_cmpfloat(qdist_avg(&stats.chain), >=, 1.0); -- 2.7.4