From nobody Sat Sep 21 00:47:31 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=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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1585810362; cv=none; d=zohomail.com; s=zohoarc; b=lCINqgdGGcUhSJgSSJOEH0epmvmoFQD/les8YiPsPGQ7MMM/12IBqy8uYRgYKgJpHKu71/73oL0TPaLw5RXGs/z6/zfrzWv3dnxQrtZ+HpPrgjWmKGzxGaIBtLRJVQq0vp3WFWcV1Fy3ZpxazNAGf7DAPaNNH4mC1S1Gq/AC5Jw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585810362; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=TDZ5CnfeNXghIA9f6Ou0fvdmTp8E2Tj43AhBn/pmGRI=; b=IuwgB3Xzya1isMpaDzF9QSyunaOUOPzMHFxAOO83d4W/lU9oxPu2TCoyBsF2a6hr98uK8RrrfZv7SDdELcqfRcLNDdJS8dI672Fi3iA8SZnBQ29Xig7CwDZEgARME5tFBp7BnB3OBdMSsdS9EO3WJGiSnUUqErmjKb3SigwuEZA= 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 158581036212240.021918805769474; Wed, 1 Apr 2020 23:52:42 -0700 (PDT) Received: from localhost ([::1]:34138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJtiS-0004t7-Tg for importer@patchew.org; Thu, 02 Apr 2020 02:52:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49972) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJtgb-0002hm-Gv for qemu-devel@nongnu.org; Thu, 02 Apr 2020 02:50:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJtgZ-0005SB-UL for qemu-devel@nongnu.org; Thu, 02 Apr 2020 02:50:45 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:45018) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJtgZ-0005Rl-DY for qemu-devel@nongnu.org; Thu, 02 Apr 2020 02:50:43 -0400 Received: by mail-pl1-x643.google.com with SMTP id h11so972960plr.11 for ; Wed, 01 Apr 2020 23:50:43 -0700 (PDT) Received: from simran-Inspiron-5558 ([2409:4052:99d:cf8:4926:6e0b:60ca:635c]) by smtp.gmail.com with ESMTPSA id e9sm3012349pfl.179.2020.04.01.23.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 23:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=TDZ5CnfeNXghIA9f6Ou0fvdmTp8E2Tj43AhBn/pmGRI=; b=iHbplEaX4JX9H6ldm56x2bXE8z9zuHQCWGIiJ+c8q619Ri2KxY4S51w7CltRiY3oCB PAjGrMXFDqJRAp0zmRZWTKXPBkwXzCzWp7iX7BwL+ZpfXuxAhYDRqbdIIRxVyT+CIMbh S5hy0ZlOm9Q0zxNXLlA3ylJ8oOAn7udKwsX+Tkt0dQbXvai8K3AvU7uet0/b/E8Ak3j7 l4r+PAJl70idY1TsYnU4XwsrV1uWm6UCZ/yL4QVr/Jg1ztpWOEXP41Ldpf2lM4qvNPVI IhFHbzZPXHUqYUTD3ttgrODBwjTs+BsY9wtCeIrlTFEGKSBcrCynbg+2gNelNu2TT59c KIwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=TDZ5CnfeNXghIA9f6Ou0fvdmTp8E2Tj43AhBn/pmGRI=; b=GXEf0w5/NHy4eVfWNaIOVPhwy4eZFRT7l+UM3WlAS8WFlx5ckPqWlhHWjMl9KkPM1n zmcKAvL5z1g2A4yGgmOSxCf3BcsAQjww5mrYXVWJFzEbvpH2XCqJFiAHUsblsPvKh55H n49uZqh90WolDOemIFYAfJarwGQrg3WeBCrOhf2EBHVMexr29naIpqTlRuGH3M+5ZNN8 FfjvtsplRorCat7Tr+Gv4q6zXVv7OVC1GMLea+Ib5J+4xulBPRhKMs5Fm0SBpvP1aISl 591r8WeQM8tqAWf/eJeB2zahovlPtF0zzvg1sNYZAjoxiQBu6+nbkHQ0NLKmVwOPpQZk 6RXw== X-Gm-Message-State: AGi0PubQxsGNrLkkdWRpD6Up6OwBr8Pr5wR2r+kUINiIVyuM6H7pOSv3 /Pmd2AGV5YSCJosQPoD4COs= X-Google-Smtp-Source: APiQypIOl0d17PEgbBfc09bCD4I8paMAYMaPQ0sy8r7JCtmV4rqlEkNmSsrZtwVtGqr2H58o4MjR8Q== X-Received: by 2002:a17:902:26a:: with SMTP id 97mr1680561plc.82.1585810242119; Wed, 01 Apr 2020 23:50:42 -0700 (PDT) Date: Thu, 2 Apr 2020 12:20:35 +0530 From: Simran Singhal To: qemu-devel@nongnu.org Subject: [PATCH v2] lockable: Replace locks with lock guard macros Message-ID: <20200402065035.GA15477@simran-Inspiron-5558> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 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: Stefan Hajnoczi , Julia Suvorova , Yuval Shaia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace manual lock()/unlock() calls with lock guard macros (QEMU_LOCK_GUARD/WITH_QEMU_LOCK_GUARD). Signed-off-by: Simran Singhal Reviewed-by: Marcel Apfelbaum Reviewed-by: Yuval Shaia Tested-by: Yuval Shaia --- Changes in v2: -Drop changes in file hw/rdma/rdma_utils.c 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.17.1