Received: from eggs.gnu.org ([2001:4830:134:3::10]:34334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTf-00043p-G4 for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsYTe-00086j-JP for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTe-000869-Af for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:30 -0400 From: Paolo Bonzini Date: Fri, 7 Oct 2016 18:57:38 +0200 Message-Id: <1475859483-32234-15-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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 14/39] qom/object: update class cache atomically List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= From: Alex Benn=C3=A9e The idiom CPU_GET_CLASS(cpu) is fairly extensively used in various threads and trips of ThreadSanitizer due to the fact it updates obj->class->object_cast_cache behind the scenes. As this is just a fast-path cache there is no need to lock updates. However to ensure defined C11 behaviour across threads we need to use the plain atomic_read/set primitives and keep the sanitizer happy. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20160930213106.20186-7-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- qom/object.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/qom/object.c b/qom/object.c index 8166b7d..7a05e35 100644 --- a/qom/object.c +++ b/qom/object.c @@ -614,7 +614,7 @@ Object *object_dynamic_cast_assert(Object *obj, const= char *typename, Object *inst; =20 for (i =3D 0; obj && i < OBJECT_CLASS_CAST_CACHE; i++) { - if (obj->class->object_cast_cache[i] =3D=3D typename) { + if (atomic_read(&obj->class->object_cast_cache[i]) =3D=3D typena= me) { goto out; } } @@ -631,10 +631,10 @@ Object *object_dynamic_cast_assert(Object *obj, con= st char *typename, =20 if (obj && obj =3D=3D inst) { for (i =3D 1; i < OBJECT_CLASS_CAST_CACHE; i++) { - obj->class->object_cast_cache[i - 1] =3D - obj->class->object_cast_cache[i]; + atomic_set(&obj->class->object_cast_cache[i - 1], + atomic_read(&obj->class->object_cast_cache[i])); } - obj->class->object_cast_cache[i - 1] =3D typename; + atomic_set(&obj->class->object_cast_cache[i - 1], typename); } =20 out: @@ -704,7 +704,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectC= lass *class, int i; =20 for (i =3D 0; class && i < OBJECT_CLASS_CAST_CACHE; i++) { - if (class->class_cast_cache[i] =3D=3D typename) { + if (atomic_read(&class->class_cast_cache[i]) =3D=3D typename) { ret =3D class; goto out; } @@ -725,9 +725,10 @@ ObjectClass *object_class_dynamic_cast_assert(Object= Class *class, #ifdef CONFIG_QOM_CAST_DEBUG if (class && ret =3D=3D class) { for (i =3D 1; i < OBJECT_CLASS_CAST_CACHE; i++) { - class->class_cast_cache[i - 1] =3D class->class_cast_cache[i= ]; + atomic_set(&class->class_cast_cache[i - 1], + atomic_read(&class->class_cast_cache[i])); } - class->class_cast_cache[i - 1] =3D typename; + atomic_set(&class->class_cast_cache[i - 1], typename); } out: #endif --=20 2.7.4