From nobody Sun Apr 28 23:13:36 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576243340; cv=none; d=zohomail.com; s=zohoarc; b=XrRP0W4L1T2qV/TJx4ZQsXUzBlYU3Gupub6Ld1jDIiXUdjKmQ5bDLVXWiP0Y8VFP60oNb1HM6aZtXE1Cn40gQQ3BonOL3a31NnQyIsVuY/v/0KUVMip4pPwXOCHEhkIySItq96bLlyLZuaKl7WW7pJPliabOrdtyj3rOKfQ5MkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576243340; h=Content-Type:Content-Transfer-Encoding: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=GXo9tVXDH6HFrV94NzJ2m+iYX5hY6kkuhMDS3waH5+c=; b=Dnj/EzVSSfGirKQ4pwxmX1Kqut9qquNZQG201FPat9RcBXuNjy8qqHmWC3zYkmRxrPkXYV3jqyhGWqeue0DM+8KOnGXRCYtztVa7bfV9x6CMlNWz9XA1g6+gb3GViw0s9DNDrutjm4g6oSUSxq7YgH1+hBJnRwWs++AQkkK+lTg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1576243340348621.2960840132006; Fri, 13 Dec 2019 05:22:20 -0800 (PST) Received: from localhost ([::1]:49202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifktf-0001GI-9A for importer@patchew.org; Fri, 13 Dec 2019 08:22:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46676) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifkrJ-0007Sr-02 for qemu-devel@nongnu.org; Fri, 13 Dec 2019 08:19:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifkrH-0003Vu-Hk for qemu-devel@nongnu.org; Fri, 13 Dec 2019 08:19:52 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55622 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ifkr7-0003NW-C0 for qemu-devel@nongnu.org; Fri, 13 Dec 2019 08:19:51 -0500 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-178-yhPnapwlPYKwfWtG4N98Xw-1; Fri, 13 Dec 2019 08:19:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55D76107AD4C; Fri, 13 Dec 2019 13:19:36 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.117.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5750B60C05; Fri, 13 Dec 2019 13:19:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576243180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GXo9tVXDH6HFrV94NzJ2m+iYX5hY6kkuhMDS3waH5+c=; b=IQa+Vo6Jqr8Ig6U6l3i2tdiLjCuWr4gdE4nwNstLI3JNaDQ0ZaP0UqtQVkCTXL/SFpDdDe E+zFIshJ1LNh3hbk9aoMqDDrcb7LvQCRUC1h1iBSHapc8SZWtKss3dvmIi3gZgalN67c0r 6Cg8KNVG3b3xVfBzUQ8NJbrVWX+LSBM= From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, pbonzini@redhat.com, cota@braap.org, rkagan@virtuozzo.com Subject: [PATCH 1/2] hyperv: Use auto rcu_read macros Date: Fri, 13 Dec 2019 13:19:30 +0000 Message-Id: <20191213131931.143878-2-dgilbert@redhat.com> In-Reply-To: <20191213131931.143878-1-dgilbert@redhat.com> References: <20191213131931.143878-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: yhPnapwlPYKwfWtG4N98Xw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Use RCU_READ_LOCK_GUARD and WITH_RCU_READ_LOCK_GUARD to replace the manual rcu_read_(un)lock calls. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Roman Kagan --- hw/hyperv/hyperv.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 6ebf31c310..da8ce82725 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -546,14 +546,14 @@ uint16_t hyperv_hcall_post_message(uint64_t param, bo= ol fast) } =20 ret =3D HV_STATUS_INVALID_CONNECTION_ID; - rcu_read_lock(); - QLIST_FOREACH_RCU(mh, &msg_handlers, link) { - if (mh->conn_id =3D=3D (msg->connection_id & HV_CONNECTION_ID_MASK= )) { - ret =3D mh->handler(msg, mh->data); - break; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH_RCU(mh, &msg_handlers, link) { + if (mh->conn_id =3D=3D (msg->connection_id & HV_CONNECTION_ID_= MASK)) { + ret =3D mh->handler(msg, mh->data); + break; + } } } - rcu_read_unlock(); =20 unmap: cpu_physical_memory_unmap(msg, len, 0, 0); @@ -619,7 +619,6 @@ int hyperv_set_event_flag_handler(uint32_t conn_id, Eve= ntNotifier *notifier) =20 uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) { - uint16_t ret; EventFlagHandler *handler; =20 if (unlikely(!fast)) { @@ -645,15 +644,12 @@ uint16_t hyperv_hcall_signal_event(uint64_t param, bo= ol fast) return HV_STATUS_INVALID_HYPERCALL_INPUT; } =20 - ret =3D HV_STATUS_INVALID_CONNECTION_ID; - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); QLIST_FOREACH_RCU(handler, &event_flag_handlers, link) { if (handler->conn_id =3D=3D param) { event_notifier_set(handler->notifier); - ret =3D 0; - break; + return 0; } } - rcu_read_unlock(); - return ret; + return HV_STATUS_INVALID_CONNECTION_ID; } --=20 2.23.0 From nobody Sun Apr 28 23:13:36 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576243271; cv=none; d=zohomail.com; s=zohoarc; b=KFeOBOmuNjwmmHVyuY8pP9cnF5hGrFmBF6XyFskunMvvzzAAO20CI4KL1YRgfkC5vmif0FFvTCn4szv1RD1MFMomoBeiEqoDvyyRRuVN3PI0ifx+cHrbVK9iDHibq9OnrCtfzYsBaLSV+DhrVKi+OwpE0O91NzZlTl8H130v3Fo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576243271; h=Content-Type:Content-Transfer-Encoding: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=wZYL7F6gvK4pRsIDqosx/JqqT5tyk+i8zgLBy3ZPN04=; b=PVjz+GmZbYevcX7MESsLY6YK2RD1oanm+SpKOIx6cCi0XQCCNKgJ1pt7V/x9IthoAYB2ez24nnAlmFEz9252VAEb7v6L+O/tgH6Q5CxUORATTIUW0YsMZlQtwad7b4EWUAzdFQpUDlw8/nG2l90kYLhkt0PHvNmaD1yyZV2RnKE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1576243271545326.8185515512406; Fri, 13 Dec 2019 05:21:11 -0800 (PST) Received: from localhost ([::1]:49192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifksY-0008OQ-1I for importer@patchew.org; Fri, 13 Dec 2019 08:21:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46677) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifkrJ-0007Ss-0N for qemu-devel@nongnu.org; Fri, 13 Dec 2019 08:19:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifkrH-0003Vl-H3 for qemu-devel@nongnu.org; Fri, 13 Dec 2019 08:19:52 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:38125 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ifkrA-0003PE-56 for qemu-devel@nongnu.org; Fri, 13 Dec 2019 08:19:48 -0500 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-126-wEqf63WfMPe_sin7gSsXQw-1; Fri, 13 Dec 2019 08:19:38 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9EC6918552A8; Fri, 13 Dec 2019 13:19:37 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.117.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F3ED60C05; Fri, 13 Dec 2019 13:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576243183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wZYL7F6gvK4pRsIDqosx/JqqT5tyk+i8zgLBy3ZPN04=; b=fjcyhzf/BxxrEcpZLddHPuyBmWvyPK3qalr+bCcdle17qP1ivg1jiYVHWtn6Ro/LXaKSa7 r+1RZgofrDwEE0JupjXQmiDPZQKk3i6HwDczH4OkTCm2o2J1rlb1H+S4kZh1wpDaxwbBEP 5P9n2+gwQnXvl6/JZqziPN2ok/3nmGo= From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, pbonzini@redhat.com, cota@braap.org, rkagan@virtuozzo.com Subject: [PATCH 2/2] qsp: Use WITH_RCU_READ_LOCK_GUARD Date: Fri, 13 Dec 2019 13:19:31 +0000 Message-Id: <20191213131931.143878-3-dgilbert@redhat.com> In-Reply-To: <20191213131931.143878-1-dgilbert@redhat.com> References: <20191213131931.143878-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: wEqf63WfMPe_sin7gSsXQw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The automatic rcu read lock maintenance works quite nicely in this case where it previously relied on a comment to delimit the lifetime and now has a block. Signed-off-by: Dr. David Alan Gilbert --- util/qsp.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/util/qsp.c b/util/qsp.c index 62265417fd..7d5147f1b2 100644 --- a/util/qsp.c +++ b/util/qsp.c @@ -598,7 +598,6 @@ static void qsp_ht_delete(void *p, uint32_t h, void *ht= p) =20 static void qsp_mktree(GTree *tree, bool callsite_coalesce) { - QSPSnapshot *snap; struct qht ht, coalesce_ht; struct qht *htp; =20 @@ -610,20 +609,19 @@ static void qsp_mktree(GTree *tree, bool callsite_coa= lesce) * We must remain in an RCU read-side critical section until we're done * with the snapshot. */ - rcu_read_lock(); - snap =3D atomic_rcu_read(&qsp_snapshot); + WITH_RCU_READ_LOCK_GUARD() { + QSPSnapshot *snap =3D atomic_rcu_read(&qsp_snapshot); =20 - /* Aggregate all results from the global hash table into a local one */ - qht_init(&ht, qsp_entry_no_thread_cmp, QSP_INITIAL_SIZE, - QHT_MODE_AUTO_RESIZE | QHT_MODE_RAW_MUTEXES); - qht_iter(&qsp_ht, qsp_aggregate, &ht); + /* Aggregate all results from the global hash table into a local o= ne */ + qht_init(&ht, qsp_entry_no_thread_cmp, QSP_INITIAL_SIZE, + QHT_MODE_AUTO_RESIZE | QHT_MODE_RAW_MUTEXES); + qht_iter(&qsp_ht, qsp_aggregate, &ht); =20 - /* compute the difference wrt the snapshot, if any */ - if (snap) { - qsp_diff(&snap->ht, &ht); + /* compute the difference wrt the snapshot, if any */ + if (snap) { + qsp_diff(&snap->ht, &ht); + } } - /* done with the snapshot; RCU can reclaim it */ - rcu_read_unlock(); =20 htp =3D &ht; if (callsite_coalesce) { --=20 2.23.0