From: Avi Kivity Subject: [PATCH 3/3] vmexit: fix race in joining smp tests Date: Thu, 6 Jan 2011 12:48:44 +0200 Message-ID: <1294310924-14174-4-git-send-email-avi@redhat.com> References: <1294310924-14174-1-git-send-email-avi@redhat.com> Cc: Rik van Riel To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:50076 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752984Ab1AFKtA (ORCPT ); Thu, 6 Jan 2011 05:49:00 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p06An05Z007102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Jan 2011 05:49:00 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p06Amx4X000385 for ; Thu, 6 Jan 2011 05:49:00 -0500 In-Reply-To: <1294310924-14174-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 'nr_cpus_done' is not incremented atomically; this has been observed to cause tests to stall. Fix by using a proper atomic increment. Signed-off-by: Avi Kivity --- x86/vmexit.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/x86/vmexit.c b/x86/vmexit.c index 875caa3..ad8ab55 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -2,6 +2,7 @@ #include "libcflat.h" #include "smp.h" #include "processor.h" +#include "atomic.h" static unsigned int inl(unsigned short port) { @@ -121,7 +122,7 @@ static struct test { }; unsigned iterations; -volatile int nr_cpus_done; +static atomic_t nr_cpus_done; static void run_test(void *_func) { @@ -131,7 +132,7 @@ static void run_test(void *_func) for (i = 0; i < iterations; ++i) func(); - nr_cpus_done++; + atomic_inc(&nr_cpus_done); } static void do_test(struct test *test) @@ -155,10 +156,10 @@ static void do_test(struct test *test) for (i = 0; i < iterations; ++i) func(); } else { - nr_cpus_done = 0; + atomic_set(&nr_cpus_done, 0); for (i = cpu_count(); i > 0; i--) on_cpu_async(i-1, run_test, func); - while (nr_cpus_done < cpu_count()) + while (atomic_read(&nr_cpus_done) < cpu_count()) ; } t2 = rdtsc(); -- 1.7.1