From nobody Sun May 19 15:20:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588321953; cv=none; d=zohomail.com; s=zohoarc; b=ObYFLWavoKKsaW7ylJwuqXWKSxqbG+fYYNTxB+m27aP8n2dgERc3qxeDEd6u5mfnrdviBjRVHLzeaAVrk1soM4DLhYk/jk//U9AXeDp9R8DNPYHcgHWkFKcqHJjKOHMTJooY742JQk5CuPcXhqesXzivIHWPf61x/aIF8COZpB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588321953; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nvIclo+ffBDAjmYLRURHUeFw/kvPZU1fVvZeR8GJz/0=; b=anV+29aLzLMs6XW2PNrHPqLj6dnfnj52Iymnsccw9xJI6E4nLtWg1FmF3IpCPc+Kj+LR9I6jfu1OM15vVNIuqgBZqLuqnaazl/I6aRCcq5iqGtWx7oG1rwVDzIhiQoipaxQksHPCP9Y4rwtp1tJuBSGa4LYlHO8wEcnlEEePCbM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588321953002902.0868678987741; Fri, 1 May 2020 01:32:33 -0700 (PDT) Received: from localhost ([::1]:41072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUR5z-00058D-OU for importer@patchew.org; Fri, 01 May 2020 04:32:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39742) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUR2o-0000YO-HG for qemu-devel@nongnu.org; Fri, 01 May 2020 04:29:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUR2R-0002gY-Il for qemu-devel@nongnu.org; Fri, 01 May 2020 04:29:14 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:28137 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jUR2Q-0002al-W4 for qemu-devel@nongnu.org; Fri, 01 May 2020 04:28:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-514-xdW3XSUnPeGyJUEQ1rWK3g-1; Fri, 01 May 2020 04:28:48 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87034107ACCA; Fri, 1 May 2020 08:28:46 +0000 (UTC) Received: from localhost (ovpn-112-199.ams2.redhat.com [10.36.112.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADE1F2B4BA; Fri, 1 May 2020 08:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588321729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nvIclo+ffBDAjmYLRURHUeFw/kvPZU1fVvZeR8GJz/0=; b=iGR9V3ZH2JNRotIvRT1wpRtb7BixQ73JTJk49l/MwATVJQ3ASpfRMaNj+LdNoQHr8jz92O jzZcRtUsCFApJpBUxTwaSVX8HobNUBYfTBJfQ68vnE85ATOYBXwudIO+4qsuNq9GVztx/4 2fJ4gYdXWJ6Xx27SeGzzOLNT3e3CAak= X-MC-Unique: xdW3XSUnPeGyJUEQ1rWK3g-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 1/4] fuzz: select fuzz target using executable name Date: Fri, 1 May 2020 09:28:03 +0100 Message-Id: <20200501082806.205696-2-stefanha@redhat.com> In-Reply-To: <20200501082806.205696-1-stefanha@redhat.com> References: <20200501082806.205696-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/01 04:28:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , Bandan Das , Markus Armbruster , Juan Quintela , Peter Lieven , Yuval Shaia , Max Reitz , Alexander Bulekov , Alex Williamson , Gerd Hoffmann , Stefan Hajnoczi , Darren Kenny , Paolo Bonzini , Ronnie Sahlberg , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Alexander Bulekov The fuzzers are built into a binary (e.g. qemu-fuzz-i386). To select the device to fuzz/fuzz target, we usually use the --fuzz-target=3D argument. This commit allows the fuzz-target to be specified using the name of the executable. If the executable name ends with -target-FUZZ_TARGET, then we select the fuzz target based on this name, rather than the --fuzz-target argument. This is useful for systems such as oss-fuzz where we don't have control of the arguments passed to the fuzzer. [Fixed incorrect indentation. --Stefan] Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny Message-id: 20200421182230.6313-1-alxndr@bu.edu Signed-off-by: Stefan Hajnoczi --- tests/qtest/fuzz/fuzz.c | 19 +++++++++++-------- slirp | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index 0d78ac8d36..f5c923852e 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -91,6 +91,7 @@ static void usage(char *path) printf(" * %s : %s\n", tmp->target->name, tmp->target->description); } + printf("Alternatively, add -target-FUZZ_TARGET to the executable name\= n"); exit(0); } =20 @@ -143,18 +144,20 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, cha= r ***envp) module_call_init(MODULE_INIT_QOM); module_call_init(MODULE_INIT_LIBQOS); =20 - if (*argc <=3D 1) { + target_name =3D strstr(**argv, "-target-"); + if (target_name) { /* The binary name specifies the target */ + target_name +=3D strlen("-target-"); + } else if (*argc > 1) { /* The target is specified as an argument */ + target_name =3D (*argv)[1]; + if (!strstr(target_name, "--fuzz-target=3D")) { + usage(**argv); + } + target_name +=3D strlen("--fuzz-target=3D"); + } else { usage(**argv); } =20 /* Identify the fuzz target */ - target_name =3D (*argv)[1]; - if (!strstr(target_name, "--fuzz-target=3D")) { - usage(**argv); - } - - target_name +=3D strlen("--fuzz-target=3D"); - fuzz_target =3D fuzz_get_target(target_name); if (!fuzz_target) { usage(**argv); diff --git a/slirp b/slirp index 2faae0f778..55ab21c9a3 160000 --- a/slirp +++ b/slirp @@ -1 +1 @@ -Subproject commit 2faae0f778f818fadc873308f983289df697eb93 +Subproject commit 55ab21c9a36852915b81f1b41ebaf3b6509dd8ba --=20 2.25.3 From nobody Sun May 19 15:20:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588322068; cv=none; d=zohomail.com; s=zohoarc; b=OXwFM3ZKcyGWY2rFoKDxdpbqy6LeIi0cdOB7ar324jWGUlCuX5BOgcCG+78Xe/bThdpscbLQozb/WBCUT0IAPKNN2VsEoJJW2WAoFkYTAzp87a/YtLN/6ML5uPia7V65GmHV4Iqal4XZRzrOxXE3NcG59TywKT+/8k2K2w7f2K4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588322068; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/+mZ1N7dGqM8m4x82r+/xQOUNB890dMBeCU3PxbO+hU=; b=TYWN6Mc15UJ2WMUUjZfTRmzNIpjUWADXwgKbML+O9s+LX4IuRzzzU++uNphzzmdSD1u963EO5e7i3Iz3WuM2k+v4HC7cfFBa7iJ4gyIPWssq/05cjTSk/0KhsL8A+UvEkhIsE5b+yf+/6l1l6Dhx1tVw0cFtZtfUSGrHbLhLbbA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588322068788778.5966726921188; Fri, 1 May 2020 01:34:28 -0700 (PDT) Received: from localhost ([::1]:48726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUR7r-0000RY-5w for importer@patchew.org; Fri, 01 May 2020 04:34:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40056) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUR2x-0000pF-FO for qemu-devel@nongnu.org; Fri, 01 May 2020 04:30:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUR2g-0003qS-NH for qemu-devel@nongnu.org; Fri, 01 May 2020 04:29:23 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:36033 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jUR2g-0003ll-6O for qemu-devel@nongnu.org; Fri, 01 May 2020 04:29:06 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-468-r6XQjbVRO3alRiuBYH7JtQ-1; Fri, 01 May 2020 04:29:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15D5145F; Fri, 1 May 2020 08:28:59 +0000 (UTC) Received: from localhost (ovpn-112-199.ams2.redhat.com [10.36.112.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id F39585EE10; Fri, 1 May 2020 08:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588321745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/+mZ1N7dGqM8m4x82r+/xQOUNB890dMBeCU3PxbO+hU=; b=ZzBz/LlEC8Jz8iQbLRtgZWkRuE55lysF00u0hDYjFuLtU0y/qSMabJ0lwZrHWBfLcuOv/3 Hz5Ujq+P1Ar9osLptkwn8Xgab2+PFoTx4TVfBnkPWlOKch7qZvJLBgf9cneB0HkEXQb6Fs fImpimBJvHfmXEPaHAlWQYOfDSnaO0M= X-MC-Unique: r6XQjbVRO3alRiuBYH7JtQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 2/4] lockable: fix __COUNTER__ macro to be referenced properly Date: Fri, 1 May 2020 09:28:04 +0100 Message-Id: <20200501082806.205696-3-stefanha@redhat.com> In-Reply-To: <20200501082806.205696-1-stefanha@redhat.com> References: <20200501082806.205696-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/01 04:28:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , Bandan Das , Markus Armbruster , Juan Quintela , Peter Lieven , Yuval Shaia , Max Reitz , Daniel Brodsky , Alexander Bulekov , Alex Williamson , Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , Ronnie Sahlberg , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Daniel Brodsky - __COUNTER__ doesn't work with ## concat - replaced ## with glue() macro so __COUNTER__ is evaluated Fixes: 3284c3ddc4 Signed-off-by: Daniel Brodsky Message-id: 20200404042108.389635-2-dnbrdsky@gmail.com Signed-off-by: Stefan Hajnoczi --- include/qemu/lockable.h | 7 ++++--- include/qemu/rcu.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/qemu/lockable.h b/include/qemu/lockable.h index 1aeb2cb1a6..b620023141 100644 --- a/include/qemu/lockable.h +++ b/include/qemu/lockable.h @@ -152,7 +152,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockab= le_auto_unlock) * } */ #define WITH_QEMU_LOCK_GUARD(x) \ - WITH_QEMU_LOCK_GUARD_((x), qemu_lockable_auto##__COUNTER__) + WITH_QEMU_LOCK_GUARD_((x), glue(qemu_lockable_auto, __COUNTER__)) =20 /** * QEMU_LOCK_GUARD - Lock an object until the end of the scope @@ -169,8 +169,9 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockab= le_auto_unlock) * return; <-- mutex is automatically unlocked * } */ -#define QEMU_LOCK_GUARD(x) \ - g_autoptr(QemuLockable) qemu_lockable_auto##__COUNTER__ =3D \ +#define QEMU_LOCK_GUARD(x) \ + g_autoptr(QemuLockable) \ + glue(qemu_lockable_auto, __COUNTER__) G_GNUC_UNUSED =3D \ qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE((x))) =20 #endif diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 9c82683e37..570aa603eb 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -170,7 +170,7 @@ static inline void rcu_read_auto_unlock(RCUReadAuto *r) G_DEFINE_AUTOPTR_CLEANUP_FUNC(RCUReadAuto, rcu_read_auto_unlock) =20 #define WITH_RCU_READ_LOCK_GUARD() \ - WITH_RCU_READ_LOCK_GUARD_(_rcu_read_auto##__COUNTER__) + WITH_RCU_READ_LOCK_GUARD_(glue(_rcu_read_auto, __COUNTER__)) =20 #define WITH_RCU_READ_LOCK_GUARD_(var) \ for (g_autoptr(RCUReadAuto) var =3D rcu_read_auto_lock(); \ --=20 2.25.3 From nobody Sun May 19 15:20:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588321946; cv=none; d=zohomail.com; s=zohoarc; b=bDJ4JPwB4GXSi0YFg3MwXfICOZs6chHL1GTP2sM2vWuL3TxAXOpmLRcamflsFC6G68myltB0kS1iYOcrFEiyHCx4QEjptmGp4cEsq9oiASqQpnQRtlS42e2Z+vd2YFaFiPcJsx32GO/m6OQ3ci4oUoRyjxhNJEMUarGZqYKKqkk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588321946; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9KGTvTCXTH+IUT7wVNc41vXfa+b/bmEwFioywsRrvdo=; b=O7YO1igs6jAj99nXC4xDrzVOHNAcd1y+THqJ8j3IOjKeTvc05C5lIsZjQeiV9ZzxYc9+awOYKCWrhRzFmjLCebe9BjNOgmxWIHFXMiZlb4IsQpSL0U9TevFZksOfA31Z+nvVr0Kbhb7B2RTpxkbrrnuIMkGkqlVsHk0TwtpM3Hg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588321946804987.1914890446176; Fri, 1 May 2020 01:32:26 -0700 (PDT) Received: from localhost ([::1]:40376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUR5t-0004gy-49 for importer@patchew.org; Fri, 01 May 2020 04:32:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40122) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUR2z-0000uU-LN for qemu-devel@nongnu.org; Fri, 01 May 2020 04:30:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUR2i-00040J-C2 for qemu-devel@nongnu.org; Fri, 01 May 2020 04:29:25 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:54574 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jUR2h-0003uF-NL for qemu-devel@nongnu.org; Fri, 01 May 2020 04:29:07 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-_BJmQLRGPhyjNVc6XtofDg-1; Fri, 01 May 2020 04:29:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 543631800D4A; Fri, 1 May 2020 08:29:01 +0000 (UTC) Received: from localhost (ovpn-112-199.ams2.redhat.com [10.36.112.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77EF961520; Fri, 1 May 2020 08:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588321747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9KGTvTCXTH+IUT7wVNc41vXfa+b/bmEwFioywsRrvdo=; b=iiANuj+qcV1TP06XLwrsKz/VIcpp5UbhbB2MuTHM3ahF14nfHdEKkRNjw+IVQmNZY6xsRv AMVYP2FvgWQVpSfQ8aIjntt9Dpla26V5ZkLVUDH4YN36wDwauZ5ifhnDsSpnqdKXr/WE0C R2AnflVtsiWHo5TTBeGw13PnZhSJ2K8= X-MC-Unique: _BJmQLRGPhyjNVc6XtofDg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 3/4] lockable: replaced locks with lock guard macros where appropriate Date: Fri, 1 May 2020 09:28:05 +0100 Message-Id: <20200501082806.205696-4-stefanha@redhat.com> In-Reply-To: <20200501082806.205696-1-stefanha@redhat.com> References: <20200501082806.205696-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/01 04:28:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , Bandan Das , Markus Armbruster , Juan Quintela , Peter Lieven , Yuval Shaia , Max Reitz , Daniel Brodsky , Alexander Bulekov , Alex Williamson , Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , Ronnie Sahlberg , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Daniel Brodsky - ran regexp "qemu_mutex_lock\(.*\).*\n.*if" to find targets - replaced result with QEMU_LOCK_GUARD if all unlocks at function end - replaced result with WITH_QEMU_LOCK_GUARD if unlock not at end Signed-off-by: Daniel Brodsky Reviewed-by: Juan Quintela Message-id: 20200404042108.389635-3-dnbrdsky@gmail.com Signed-off-by: Stefan Hajnoczi --- block/iscsi.c | 7 ++---- block/nfs.c | 51 ++++++++++++++++++++----------------------- cpus-common.c | 14 +++++------- hw/display/qxl.c | 43 +++++++++++++++++------------------- hw/vfio/platform.c | 5 ++--- migration/migration.c | 3 +-- migration/multifd.c | 8 +++---- migration/ram.c | 3 +-- monitor/misc.c | 4 +--- ui/spice-display.c | 14 ++++++------ util/log.c | 4 ++-- util/qemu-timer.c | 17 +++++++-------- util/rcu.c | 8 +++---- util/thread-pool.c | 3 +-- util/vfio-helpers.c | 5 ++--- 15 files changed, 83 insertions(+), 106 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 0b4b7210df..e4fc71d64b 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1394,20 +1394,17 @@ static void iscsi_nop_timed_event(void *opaque) { IscsiLun *iscsilun =3D opaque; =20 - qemu_mutex_lock(&iscsilun->mutex); + QEMU_LOCK_GUARD(&iscsilun->mutex); if (iscsi_get_nops_in_flight(iscsilun->iscsi) >=3D MAX_NOP_FAILURES) { error_report("iSCSI: NOP timeout. Reconnecting..."); iscsilun->request_timed_out =3D true; } else if (iscsi_nop_out_async(iscsilun->iscsi, NULL, NULL, 0, NULL) != =3D 0) { error_report("iSCSI: failed to sent NOP-Out. Disabling NOP message= s."); - goto out; + return; } =20 timer_mod(iscsilun->nop_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) = + NOP_INTERVAL); iscsi_set_events(iscsilun); - -out: - qemu_mutex_unlock(&iscsilun->mutex); } =20 static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp) diff --git a/block/nfs.c b/block/nfs.c index cc2413d5ab..cba8e60b28 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -273,15 +273,14 @@ static int coroutine_fn nfs_co_preadv(BlockDriverStat= e *bs, uint64_t offset, nfs_co_init_task(bs, &task); task.iov =3D iov; =20 - qemu_mutex_lock(&client->mutex); - if (nfs_pread_async(client->context, client->fh, - offset, bytes, nfs_co_generic_cb, &task) !=3D 0) { - qemu_mutex_unlock(&client->mutex); - return -ENOMEM; - } + WITH_QEMU_LOCK_GUARD(&client->mutex) { + if (nfs_pread_async(client->context, client->fh, + offset, bytes, nfs_co_generic_cb, &task) !=3D = 0) { + return -ENOMEM; + } =20 - nfs_set_events(client); - qemu_mutex_unlock(&client->mutex); + nfs_set_events(client); + } while (!task.complete) { qemu_coroutine_yield(); } @@ -320,19 +319,18 @@ static int coroutine_fn nfs_co_pwritev(BlockDriverSta= te *bs, uint64_t offset, buf =3D iov->iov[0].iov_base; } =20 - qemu_mutex_lock(&client->mutex); - if (nfs_pwrite_async(client->context, client->fh, - offset, bytes, buf, - nfs_co_generic_cb, &task) !=3D 0) { - qemu_mutex_unlock(&client->mutex); - if (my_buffer) { - g_free(buf); + WITH_QEMU_LOCK_GUARD(&client->mutex) { + if (nfs_pwrite_async(client->context, client->fh, + offset, bytes, buf, + nfs_co_generic_cb, &task) !=3D 0) { + if (my_buffer) { + g_free(buf); + } + return -ENOMEM; } - return -ENOMEM; - } =20 - nfs_set_events(client); - qemu_mutex_unlock(&client->mutex); + nfs_set_events(client); + } while (!task.complete) { qemu_coroutine_yield(); } @@ -355,15 +353,14 @@ static int coroutine_fn nfs_co_flush(BlockDriverState= *bs) =20 nfs_co_init_task(bs, &task); =20 - qemu_mutex_lock(&client->mutex); - if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb, - &task) !=3D 0) { - qemu_mutex_unlock(&client->mutex); - return -ENOMEM; - } + WITH_QEMU_LOCK_GUARD(&client->mutex) { + if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb, + &task) !=3D 0) { + return -ENOMEM; + } =20 - nfs_set_events(client); - qemu_mutex_unlock(&client->mutex); + nfs_set_events(client); + } while (!task.complete) { qemu_coroutine_yield(); } diff --git a/cpus-common.c b/cpus-common.c index eaf590cb38..55d5df8923 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -22,6 +22,7 @@ #include "exec/cpu-common.h" #include "hw/core/cpu.h" #include "sysemu/cpus.h" +#include "qemu/lockable.h" =20 static QemuMutex qemu_cpu_list_lock; static QemuCond exclusive_cond; @@ -71,7 +72,7 @@ static int cpu_get_free_index(void) =20 void cpu_list_add(CPUState *cpu) { - qemu_mutex_lock(&qemu_cpu_list_lock); + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (cpu->cpu_index =3D=3D UNASSIGNED_CPU_INDEX) { cpu->cpu_index =3D cpu_get_free_index(); assert(cpu->cpu_index !=3D UNASSIGNED_CPU_INDEX); @@ -79,15 +80,13 @@ void cpu_list_add(CPUState *cpu) assert(!cpu_index_auto_assigned); } QTAILQ_INSERT_TAIL_RCU(&cpus, cpu, node); - qemu_mutex_unlock(&qemu_cpu_list_lock); } =20 void cpu_list_remove(CPUState *cpu) { - qemu_mutex_lock(&qemu_cpu_list_lock); + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (!QTAILQ_IN_USE(cpu, node)) { /* there is nothing to undo since cpu_exec_init() hasn't been call= ed */ - qemu_mutex_unlock(&qemu_cpu_list_lock); return; } =20 @@ -95,7 +94,6 @@ void cpu_list_remove(CPUState *cpu) =20 QTAILQ_REMOVE_RCU(&cpus, cpu, node); cpu->cpu_index =3D UNASSIGNED_CPU_INDEX; - qemu_mutex_unlock(&qemu_cpu_list_lock); } =20 struct qemu_work_item { @@ -237,7 +235,7 @@ void cpu_exec_start(CPUState *cpu) * see cpu->running =3D=3D true, and it will kick the CPU. */ if (unlikely(atomic_read(&pending_cpus))) { - qemu_mutex_lock(&qemu_cpu_list_lock); + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (!cpu->has_waiter) { /* Not counted in pending_cpus, let the exclusive item * run. Since we have the lock, just set cpu->running to true @@ -252,7 +250,6 @@ void cpu_exec_start(CPUState *cpu) * waiter at cpu_exec_end. */ } - qemu_mutex_unlock(&qemu_cpu_list_lock); } } =20 @@ -280,7 +277,7 @@ void cpu_exec_end(CPUState *cpu) * next cpu_exec_start. */ if (unlikely(atomic_read(&pending_cpus))) { - qemu_mutex_lock(&qemu_cpu_list_lock); + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (cpu->has_waiter) { cpu->has_waiter =3D false; atomic_set(&pending_cpus, pending_cpus - 1); @@ -288,7 +285,6 @@ void cpu_exec_end(CPUState *cpu) qemu_cond_signal(&exclusive_cond); } } - qemu_mutex_unlock(&qemu_cpu_list_lock); } } =20 diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 227da69a50..d5627119ec 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -478,18 +478,19 @@ static int qxl_track_command(PCIQXLDevice *qxl, struc= t QXLCommandExt *ext) cmd->u.surface_create.stride); return 1; } - qemu_mutex_lock(&qxl->track_lock); - if (cmd->type =3D=3D QXL_SURFACE_CMD_CREATE) { - qxl->guest_surfaces.cmds[id] =3D ext->cmd.data; - qxl->guest_surfaces.count++; - if (qxl->guest_surfaces.max < qxl->guest_surfaces.count) - qxl->guest_surfaces.max =3D qxl->guest_surfaces.count; + WITH_QEMU_LOCK_GUARD(&qxl->track_lock) { + if (cmd->type =3D=3D QXL_SURFACE_CMD_CREATE) { + qxl->guest_surfaces.cmds[id] =3D ext->cmd.data; + qxl->guest_surfaces.count++; + if (qxl->guest_surfaces.max < qxl->guest_surfaces.count) { + qxl->guest_surfaces.max =3D qxl->guest_surfaces.count; + } + } + if (cmd->type =3D=3D QXL_SURFACE_CMD_DESTROY) { + qxl->guest_surfaces.cmds[id] =3D 0; + qxl->guest_surfaces.count--; + } } - if (cmd->type =3D=3D QXL_SURFACE_CMD_DESTROY) { - qxl->guest_surfaces.cmds[id] =3D 0; - qxl->guest_surfaces.count--; - } - qemu_mutex_unlock(&qxl->track_lock); break; } case QXL_CMD_CURSOR: @@ -958,10 +959,9 @@ static void interface_update_area_complete(QXLInstance= *sin, int i; int qxl_i; =20 - qemu_mutex_lock(&qxl->ssd.lock); + QEMU_LOCK_GUARD(&qxl->ssd.lock); if (surface_id !=3D 0 || !num_updated_rects || !qxl->render_update_cookie_num) { - qemu_mutex_unlock(&qxl->ssd.lock); return; } trace_qxl_interface_update_area_complete(qxl->id, surface_id, dirty->l= eft, @@ -980,7 +980,6 @@ static void interface_update_area_complete(QXLInstance = *sin, * Don't bother copying or scheduling the bh since we will flip * the whole area anyway on completion of the update_area async ca= ll */ - qemu_mutex_unlock(&qxl->ssd.lock); return; } qxl_i =3D qxl->num_dirty_rects; @@ -991,7 +990,6 @@ static void interface_update_area_complete(QXLInstance = *sin, trace_qxl_interface_update_area_complete_schedule_bh(qxl->id, qxl->num_dirty_re= cts); qemu_bh_schedule(qxl->update_area_bh); - qemu_mutex_unlock(&qxl->ssd.lock); } =20 /* called from spice server thread context only */ @@ -1694,15 +1692,14 @@ static void ioport_write(void *opaque, hwaddr addr, case QXL_IO_MONITORS_CONFIG_ASYNC: async_common: async =3D QXL_ASYNC; - qemu_mutex_lock(&d->async_lock); - if (d->current_async !=3D QXL_UNDEFINED_IO) { - qxl_set_guest_bug(d, "%d async started before last (%d) comple= te", - io_port, d->current_async); - qemu_mutex_unlock(&d->async_lock); - return; + WITH_QEMU_LOCK_GUARD(&d->async_lock) { + if (d->current_async !=3D QXL_UNDEFINED_IO) { + qxl_set_guest_bug(d, "%d async started before last (%d) co= mplete", + io_port, d->current_async); + return; + } + d->current_async =3D orig_io_port; } - d->current_async =3D orig_io_port; - qemu_mutex_unlock(&d->async_lock); break; default: break; diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 6b2952c034..ac2cefc9b1 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -22,6 +22,7 @@ #include "hw/vfio/vfio-platform.h" #include "migration/vmstate.h" #include "qemu/error-report.h" +#include "qemu/lockable.h" #include "qemu/main-loop.h" #include "qemu/module.h" #include "qemu/range.h" @@ -216,7 +217,7 @@ static void vfio_intp_interrupt(VFIOINTp *intp) VFIOPlatformDevice *vdev =3D intp->vdev; bool delay_handling =3D false; =20 - qemu_mutex_lock(&vdev->intp_mutex); + QEMU_LOCK_GUARD(&vdev->intp_mutex); if (intp->state =3D=3D VFIO_IRQ_INACTIVE) { QLIST_FOREACH(tmp, &vdev->intp_list, next) { if (tmp->state =3D=3D VFIO_IRQ_ACTIVE || @@ -236,7 +237,6 @@ static void vfio_intp_interrupt(VFIOINTp *intp) QSIMPLEQ_INSERT_TAIL(&vdev->pending_intp_queue, intp, pqnext); ret =3D event_notifier_test_and_clear(intp->interrupt); - qemu_mutex_unlock(&vdev->intp_mutex); return; } =20 @@ -266,7 +266,6 @@ static void vfio_intp_interrupt(VFIOINTp *intp) qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + vdev->mmap_timeout); } - qemu_mutex_unlock(&vdev->intp_mutex); } =20 /** diff --git a/migration/migration.c b/migration/migration.c index 187ac0410c..177cce9e95 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1653,11 +1653,10 @@ static void migrate_fd_cleanup_bh(void *opaque) =20 void migrate_set_error(MigrationState *s, const Error *error) { - qemu_mutex_lock(&s->error_mutex); + QEMU_LOCK_GUARD(&s->error_mutex); if (!s->error) { s->error =3D error_copy(error); } - qemu_mutex_unlock(&s->error_mutex); } =20 void migrate_fd_error(MigrationState *s, const Error *error) diff --git a/migration/multifd.c b/migration/multifd.c index cb6a4a3ab8..9123c111a3 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -894,11 +894,11 @@ void multifd_recv_sync_main(void) for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 - qemu_mutex_lock(&p->mutex); - if (multifd_recv_state->packet_num < p->packet_num) { - multifd_recv_state->packet_num =3D p->packet_num; + WITH_QEMU_LOCK_GUARD(&p->mutex) { + if (multifd_recv_state->packet_num < p->packet_num) { + multifd_recv_state->packet_num =3D p->packet_num; + } } - qemu_mutex_unlock(&p->mutex); trace_multifd_recv_sync_main_signal(p->id); qemu_sem_post(&p->sem_sync); } diff --git a/migration/ram.c b/migration/ram.c index 04f13feb2e..580ec24522 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1369,7 +1369,7 @@ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_= t *offset) return NULL; } =20 - qemu_mutex_lock(&rs->src_page_req_mutex); + QEMU_LOCK_GUARD(&rs->src_page_req_mutex); if (!QSIMPLEQ_EMPTY(&rs->src_page_requests)) { struct RAMSrcPageRequest *entry =3D QSIMPLEQ_FIRST(&rs->src_page_requests); @@ -1386,7 +1386,6 @@ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_= t *offset) migration_consume_urgent_request(); } } - qemu_mutex_unlock(&rs->src_page_req_mutex); =20 return block; } diff --git a/monitor/misc.c b/monitor/misc.c index 6c45fa490f..9723b466cd 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -1473,7 +1473,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdse= t_id, int64_t fdset_id, MonFdsetFd *mon_fdset_fd; AddfdInfo *fdinfo; =20 - qemu_mutex_lock(&mon_fdsets_lock); + QEMU_LOCK_GUARD(&mon_fdsets_lock); if (has_fdset_id) { QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { /* Break if match found or match impossible due to ordering by= ID */ @@ -1494,7 +1494,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdse= t_id, int64_t fdset_id, if (fdset_id < 0) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id", "a non-negative value"); - qemu_mutex_unlock(&mon_fdsets_lock); return NULL; } /* Use specified fdset ID */ @@ -1545,7 +1544,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdse= t_id, int64_t fdset_id, fdinfo->fdset_id =3D mon_fdset->id; fdinfo->fd =3D mon_fdset_fd->fd; =20 - qemu_mutex_unlock(&mon_fdsets_lock); return fdinfo; } =20 diff --git a/ui/spice-display.c b/ui/spice-display.c index 6babe24909..19632fdf6c 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -18,6 +18,7 @@ #include "qemu/osdep.h" #include "ui/qemu-spice.h" #include "qemu/timer.h" +#include "qemu/lockable.h" #include "qemu/main-loop.h" #include "qemu/option.h" #include "qemu/queue.h" @@ -483,12 +484,12 @@ void qemu_spice_display_refresh(SimpleSpiceDisplay *s= sd) { graphic_hw_update(ssd->dcl.con); =20 - qemu_mutex_lock(&ssd->lock); - if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) { - qemu_spice_create_update(ssd); - ssd->notify++; + WITH_QEMU_LOCK_GUARD(&ssd->lock) { + if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) { + qemu_spice_create_update(ssd); + ssd->notify++; + } } - qemu_mutex_unlock(&ssd->lock); =20 trace_qemu_spice_display_refresh(ssd->qxl.id, ssd->notify); if (ssd->notify) { @@ -580,7 +581,7 @@ static int interface_get_cursor_command(QXLInstance *si= n, QXLCommandExt *ext) SimpleSpiceDisplay *ssd =3D container_of(sin, SimpleSpiceDisplay, qxl); int ret; =20 - qemu_mutex_lock(&ssd->lock); + QEMU_LOCK_GUARD(&ssd->lock); if (ssd->ptr_define) { *ext =3D ssd->ptr_define->ext; ssd->ptr_define =3D NULL; @@ -592,7 +593,6 @@ static int interface_get_cursor_command(QXLInstance *si= n, QXLCommandExt *ext) } else { ret =3D false; } - qemu_mutex_unlock(&ssd->lock); return ret; } =20 diff --git a/util/log.c b/util/log.c index 2da6cb31dc..bdb3d712e8 100644 --- a/util/log.c +++ b/util/log.c @@ -25,6 +25,7 @@ #include "qemu/cutils.h" #include "trace/control.h" #include "qemu/thread.h" +#include "qemu/lockable.h" =20 static char *logfilename; static QemuMutex qemu_logfile_mutex; @@ -94,7 +95,7 @@ void qemu_set_log(int log_flags) if (qemu_loglevel && (!is_daemonized() || logfilename)) { need_to_open_file =3D true; } - qemu_mutex_lock(&qemu_logfile_mutex); + QEMU_LOCK_GUARD(&qemu_logfile_mutex); if (qemu_logfile && !need_to_open_file) { logfile =3D qemu_logfile; atomic_rcu_set(&qemu_logfile, NULL); @@ -136,7 +137,6 @@ void qemu_set_log(int log_flags) } atomic_rcu_set(&qemu_logfile, logfile); } - qemu_mutex_unlock(&qemu_logfile_mutex); } =20 void qemu_log_needs_buffers(void) diff --git a/util/qemu-timer.c b/util/qemu-timer.c index d548d3c1ad..b6575a2cd5 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -459,17 +459,16 @@ void timer_mod_anticipate_ns(QEMUTimer *ts, int64_t e= xpire_time) QEMUTimerList *timer_list =3D ts->timer_list; bool rearm; =20 - qemu_mutex_lock(&timer_list->active_timers_lock); - if (ts->expire_time =3D=3D -1 || ts->expire_time > expire_time) { - if (ts->expire_time !=3D -1) { - timer_del_locked(timer_list, ts); + WITH_QEMU_LOCK_GUARD(&timer_list->active_timers_lock) { + if (ts->expire_time =3D=3D -1 || ts->expire_time > expire_time) { + if (ts->expire_time !=3D -1) { + timer_del_locked(timer_list, ts); + } + rearm =3D timer_mod_ns_locked(timer_list, ts, expire_time); + } else { + rearm =3D false; } - rearm =3D timer_mod_ns_locked(timer_list, ts, expire_time); - } else { - rearm =3D false; } - qemu_mutex_unlock(&timer_list->active_timers_lock); - if (rearm) { timerlist_rearm(timer_list); } diff --git a/util/rcu.c b/util/rcu.c index 177a675619..60a37f72c3 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -31,6 +31,7 @@ #include "qemu/atomic.h" #include "qemu/thread.h" #include "qemu/main-loop.h" +#include "qemu/lockable.h" #if defined(CONFIG_MALLOC_TRIM) #include #endif @@ -141,14 +142,14 @@ static void wait_for_readers(void) =20 void synchronize_rcu(void) { - qemu_mutex_lock(&rcu_sync_lock); + QEMU_LOCK_GUARD(&rcu_sync_lock); =20 /* Write RCU-protected pointers before reading p_rcu_reader->ctr. * Pairs with smp_mb_placeholder() in rcu_read_lock(). */ smp_mb_global(); =20 - qemu_mutex_lock(&rcu_registry_lock); + QEMU_LOCK_GUARD(&rcu_registry_lock); if (!QLIST_EMPTY(®istry)) { /* In either case, the atomic_mb_set below blocks stores that free * old RCU-protected pointers. @@ -169,9 +170,6 @@ void synchronize_rcu(void) =20 wait_for_readers(); } - - qemu_mutex_unlock(&rcu_registry_lock); - qemu_mutex_unlock(&rcu_sync_lock); } =20 =20 diff --git a/util/thread-pool.c b/util/thread-pool.c index 4ed9b89ab2..d763cea505 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -210,7 +210,7 @@ static void thread_pool_cancel(BlockAIOCB *acb) =20 trace_thread_pool_cancel(elem, elem->common.opaque); =20 - qemu_mutex_lock(&pool->lock); + QEMU_LOCK_GUARD(&pool->lock); if (elem->state =3D=3D THREAD_QUEUED && /* No thread has yet started working on elem. we can try to "steal" * the item from the worker if we can get a signal from the @@ -225,7 +225,6 @@ static void thread_pool_cancel(BlockAIOCB *acb) elem->ret =3D -ECANCELED; } =20 - qemu_mutex_unlock(&pool->lock); } =20 static AioContext *thread_pool_get_aio_context(BlockAIOCB *acb) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index ddd9a96e76..e399e330e2 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -21,6 +21,7 @@ #include "standard-headers/linux/pci_regs.h" #include "qemu/event_notifier.h" #include "qemu/vfio-helpers.h" +#include "qemu/lockable.h" #include "trace.h" =20 #define QEMU_VFIO_DEBUG 0 @@ -667,14 +668,12 @@ int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s) .size =3D QEMU_VFIO_IOVA_MAX - s->high_water_mark, }; trace_qemu_vfio_dma_reset_temporary(s); - qemu_mutex_lock(&s->lock); + QEMU_LOCK_GUARD(&s->lock); if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) { error_report("VFIO_UNMAP_DMA failed: %s", strerror(errno)); - qemu_mutex_unlock(&s->lock); return -errno; } s->high_water_mark =3D QEMU_VFIO_IOVA_MAX; - qemu_mutex_unlock(&s->lock); return 0; } =20 --=20 2.25.3 From nobody Sun May 19 15:20:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588322133; cv=none; d=zohomail.com; s=zohoarc; b=CTqu0BazT4MEXOphdiRwvQgtglT3/uGV5NkoSPxktxvnPtg2icTHxuD/Lz3PJdMTAJ2Uvf0kfrxqK7nxrLNS/wHh8oYrdhHCrehGiJGGjsCikL9EJKuz/4bNdneAfIQPoIC9RpKvers5IDTqKfcEwUgNOOJT+aavIlTGiKWeng8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588322133; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=X1KqxwuQINsvghZKvSRECqg3J3rn5MeI41Ww7TEYuMA=; b=ITc/mDD2qdEc7vH0nYXr31TSmghHN0fglmgZECu3kFar4iHBW8qNwEgCVZStflqZYIZVpLjhadr6NI15GhtzquZnU4gi2p5Jo6gOSSrcL5u/SwmnaBZQmIfp2oxTNSstR5XqFF8hM572/XcBpKeMtL/MESxAYkjvMCeiO0guU0I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158832213323636.10205978838496; Fri, 1 May 2020 01:35:33 -0700 (PDT) Received: from localhost ([::1]:50408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUR8t-0001sO-TA for importer@patchew.org; Fri, 01 May 2020 04:35:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40328) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUR38-0001Co-1r for qemu-devel@nongnu.org; Fri, 01 May 2020 04:30:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUR2s-0004zf-Av for qemu-devel@nongnu.org; Fri, 01 May 2020 04:29:33 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:60343 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jUR2r-0004tR-Mh for qemu-devel@nongnu.org; Fri, 01 May 2020 04:29:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-294-H6KfKyzPNOeR2F_rmS3zeg-1; Fri, 01 May 2020 04:29:15 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F65B80183C; Fri, 1 May 2020 08:29:13 +0000 (UTC) Received: from localhost (ovpn-112-199.ams2.redhat.com [10.36.112.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id B67732B4BC; Fri, 1 May 2020 08:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588321756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X1KqxwuQINsvghZKvSRECqg3J3rn5MeI41Ww7TEYuMA=; b=cr4XGxceZP9AATUNC4QDUojeRiQSsi6QHAra/w3JaBWufI0N7fhMcE9Z8KdqCoVPO74LzU qTAcOLhGf7ImA04bOz3pxfLRSM1S+AuJWWHEab+mGMld+PtqDX0HfVk6oAxC+8y647anAM G+prZpiIyMlyoAiIBgg9Sl3kjh/zJyk= X-MC-Unique: H6KfKyzPNOeR2F_rmS3zeg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 4/4] lockable: Replace locks with lock guard macros Date: Fri, 1 May 2020 09:28:06 +0100 Message-Id: <20200501082806.205696-5-stefanha@redhat.com> In-Reply-To: <20200501082806.205696-1-stefanha@redhat.com> References: <20200501082806.205696-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/01 04:28:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , Bandan Das , Markus Armbruster , Juan Quintela , Peter Lieven , Yuval Shaia , Max Reitz , Alexander Bulekov , Alex Williamson , Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , Simran Singhal , Ronnie Sahlberg , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Simran Singhal Replace manual lock()/unlock() calls with lock guard macros (QEMU_LOCK_GUARD/WITH_QEMU_LOCK_GUARD). Signed-off-by: Simran Singhal Reviewed-by: Yuval Shaia Reviewed-by: Marcel Apfelbaum Tested-by: Yuval Shaia Message-id: 20200402065035.GA15477@simran-Inspiron-5558 Signed-off-by: Stefan Hajnoczi --- hw/hyperv/hyperv.c | 15 ++++++------- hw/rdma/rdma_backend.c | 50 +++++++++++++++++++++--------------------- hw/rdma/rdma_rm.c | 3 +-- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 8ca3706f5b..4ddafe1de1 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -15,6 +15,7 @@ #include "sysemu/kvm.h" #include "qemu/bitops.h" #include "qemu/error-report.h" +#include "qemu/lockable.h" #include "qemu/queue.h" #include "qemu/rcu.h" #include "qemu/rcu_queue.h" @@ -491,7 +492,7 @@ int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandl= er handler, void *data) int ret; MsgHandler *mh; =20 - qemu_mutex_lock(&handlers_mutex); + QEMU_LOCK_GUARD(&handlers_mutex); QLIST_FOREACH(mh, &msg_handlers, link) { if (mh->conn_id =3D=3D conn_id) { if (handler) { @@ -501,7 +502,7 @@ int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandl= er handler, void *data) g_free_rcu(mh, rcu); ret =3D 0; } - goto unlock; + return ret; } } =20 @@ -515,8 +516,7 @@ int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandl= er handler, void *data) } else { ret =3D -ENOENT; } -unlock: - qemu_mutex_unlock(&handlers_mutex); + return ret; } =20 @@ -565,7 +565,7 @@ static int set_event_flag_handler(uint32_t conn_id, Eve= ntNotifier *notifier) int ret; EventFlagHandler *handler; =20 - qemu_mutex_lock(&handlers_mutex); + QEMU_LOCK_GUARD(&handlers_mutex); QLIST_FOREACH(handler, &event_flag_handlers, link) { if (handler->conn_id =3D=3D conn_id) { if (notifier) { @@ -575,7 +575,7 @@ static int set_event_flag_handler(uint32_t conn_id, Eve= ntNotifier *notifier) g_free_rcu(handler, rcu); ret =3D 0; } - goto unlock; + return ret; } } =20 @@ -588,8 +588,7 @@ static int set_event_flag_handler(uint32_t conn_id, Eve= ntNotifier *notifier) } else { ret =3D -ENOENT; } -unlock: - qemu_mutex_unlock(&handlers_mutex); + return ret; } =20 diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index 3dd39fe1a7..db7e5c8be5 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -95,36 +95,36 @@ static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_r= es, struct ibv_cq *ibcq) struct ibv_wc wc[2]; RdmaProtectedGSList *cqe_ctx_list; =20 - qemu_mutex_lock(&rdma_dev_res->lock); - do { - ne =3D ibv_poll_cq(ibcq, ARRAY_SIZE(wc), wc); + WITH_QEMU_LOCK_GUARD(&rdma_dev_res->lock) { + do { + ne =3D ibv_poll_cq(ibcq, ARRAY_SIZE(wc), wc); =20 - trace_rdma_poll_cq(ne, ibcq); + trace_rdma_poll_cq(ne, ibcq); =20 - for (i =3D 0; i < ne; i++) { - bctx =3D rdma_rm_get_cqe_ctx(rdma_dev_res, wc[i].wr_id); - if (unlikely(!bctx)) { - rdma_error_report("No matching ctx for req %"PRId64, - wc[i].wr_id); - continue; - } + for (i =3D 0; i < ne; i++) { + bctx =3D rdma_rm_get_cqe_ctx(rdma_dev_res, wc[i].wr_id); + if (unlikely(!bctx)) { + rdma_error_report("No matching ctx for req %"PRId64, + wc[i].wr_id); + continue; + } =20 - comp_handler(bctx->up_ctx, &wc[i]); + comp_handler(bctx->up_ctx, &wc[i]); =20 - if (bctx->backend_qp) { - cqe_ctx_list =3D &bctx->backend_qp->cqe_ctx_list; - } else { - cqe_ctx_list =3D &bctx->backend_srq->cqe_ctx_list; - } + if (bctx->backend_qp) { + cqe_ctx_list =3D &bctx->backend_qp->cqe_ctx_list; + } else { + cqe_ctx_list =3D &bctx->backend_srq->cqe_ctx_list; + } =20 - rdma_protected_gslist_remove_int32(cqe_ctx_list, wc[i].wr_id); - rdma_rm_dealloc_cqe_ctx(rdma_dev_res, wc[i].wr_id); - g_free(bctx); - } - total_ne +=3D ne; - } while (ne > 0); - atomic_sub(&rdma_dev_res->stats.missing_cqe, total_ne); - qemu_mutex_unlock(&rdma_dev_res->lock); + rdma_protected_gslist_remove_int32(cqe_ctx_list, wc[i].wr_= id); + rdma_rm_dealloc_cqe_ctx(rdma_dev_res, wc[i].wr_id); + g_free(bctx); + } + total_ne +=3D ne; + } while (ne > 0); + atomic_sub(&rdma_dev_res->stats.missing_cqe, total_ne); + } =20 if (ne < 0) { rdma_error_report("ibv_poll_cq fail, rc=3D%d, errno=3D%d", ne, err= no); diff --git a/hw/rdma/rdma_rm.c b/hw/rdma/rdma_rm.c index 7e9ea283c9..60957f88db 100644 --- a/hw/rdma/rdma_rm.c +++ b/hw/rdma/rdma_rm.c @@ -147,14 +147,13 @@ static inline void rdma_res_tbl_dealloc(RdmaRmResTbl = *tbl, uint32_t handle) { trace_rdma_res_tbl_dealloc(tbl->name, handle); =20 - qemu_mutex_lock(&tbl->lock); + QEMU_LOCK_GUARD(&tbl->lock); =20 if (handle < tbl->tbl_sz) { clear_bit(handle, tbl->bitmap); tbl->used--; } =20 - qemu_mutex_unlock(&tbl->lock); } =20 int rdma_rm_alloc_pd(RdmaDeviceResources *dev_res, RdmaBackendDev *backend= _dev, --=20 2.25.3