From nobody Sat Nov 8 07:41:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=oracle.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550042349694938.7217099547221; Tue, 12 Feb 2019 23:19:09 -0800 (PST) Received: from localhost ([127.0.0.1]:52210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtoov-0003xx-MH for importer@patchew.org; Wed, 13 Feb 2019 02:19:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtodT-0003Tw-QD for qemu-devel@nongnu.org; Wed, 13 Feb 2019 02:07:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtoQz-0003x4-Io for qemu-devel@nongnu.org; Wed, 13 Feb 2019 01:54:18 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55158) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtoQz-0003w1-2X for qemu-devel@nongnu.org; Wed, 13 Feb 2019 01:54:17 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1D6n7Lt015564; Wed, 13 Feb 2019 06:54:15 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2qhree06vc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Feb 2019 06:54:15 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1D6sEL3031690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Feb 2019 06:54:14 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1D6sE4P026766; Wed, 13 Feb 2019 06:54:14 GMT Received: from localhost.localdomain (/77.138.186.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 Feb 2019 06:54:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=VTp7+gvv2pnE9z5i8/4Zgr/V3010rBCvURWDTb99+14=; b=e3WQM6EU8wqqIhiW6kp+wOGBdaMj3TCuNE1Ju/6NIJxxCZxQmQJyPaeo9GagGWLGuXiE ZsyylxL3o4O1SvRFcL3MglLFIqASKGvCniFna96T0+YZQ0UdfE7v5YDsWsWmnZuQMSjU aB0u56IJim2GbPbm9u0RefRDD+5HWepOI99d1nV+Fw0M7X/6/is7AWnk9PCCKZNYU3wn 3zPe/fJxMXmosfvfTqTGferG9m4poSbMtiSPBcINz5NkItqIbmiXApHFAKRYhtORU0Jv 2jnfMZ6D+mTBDVsA0VYF6D9ShURCLecRU1BYNYBrz5lmlpls9rc2aX+4aowhbC91nxB/ IQ== From: Yuval Shaia To: dgilbert@redhat.com, yuval.shaia@oracle.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, qemu-devel@nongnu.org Date: Wed, 13 Feb 2019 08:53:51 +0200 Message-Id: <20190213065357.16076-5-yuval.shaia@oracle.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190213065357.16076-1-yuval.shaia@oracle.com> References: <20190213065357.16076-1-yuval.shaia@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9165 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902130050 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 3/9] hw/rdma: Protect against concurrent execution of poll_cq X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The function rdma_poll_cq is called from two contexts - completion handler thread which sense new completion on backend channel and explicitly as result of guest issuing poll_cq command. Add lock to protect against concurrent executions. Signed-off-by: Yuval Shaia Reviewed-by: Marcel Apfelbaum --- hw/rdma/rdma_backend.c | 2 ++ hw/rdma/rdma_rm.c | 4 ++++ hw/rdma/rdma_rm_defs.h | 1 + 3 files changed, 7 insertions(+) diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index 6e9c4617da..3a2913facf 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -70,6 +70,7 @@ static void rdma_poll_cq(RdmaDeviceResources *rdma_dev_re= s, struct ibv_cq *ibcq) BackendCtx *bctx; struct ibv_wc wc[2]; =20 + qemu_mutex_lock(&rdma_dev_res->lock); do { ne =3D ibv_poll_cq(ibcq, ARRAY_SIZE(wc), wc); =20 @@ -89,6 +90,7 @@ static void rdma_poll_cq(RdmaDeviceResources *rdma_dev_re= s, struct ibv_cq *ibcq) g_free(bctx); } } while (ne > 0); + qemu_mutex_unlock(&rdma_dev_res->lock); =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 64c6ea1a4e..7cc597cdc8 100644 --- a/hw/rdma/rdma_rm.c +++ b/hw/rdma/rdma_rm.c @@ -618,12 +618,16 @@ int rdma_rm_init(RdmaDeviceResources *dev_res, struct= ibv_device_attr *dev_attr, =20 init_ports(dev_res); =20 + qemu_mutex_init(&dev_res->lock); + return 0; } =20 void rdma_rm_fini(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_de= v, const char *ifname) { + qemu_mutex_destroy(&dev_res->lock); + fini_ports(dev_res, backend_dev, ifname); =20 res_tbl_free(&dev_res->uc_tbl); diff --git a/hw/rdma/rdma_rm_defs.h b/hw/rdma/rdma_rm_defs.h index 0ba61d1838..f0ee1f3072 100644 --- a/hw/rdma/rdma_rm_defs.h +++ b/hw/rdma/rdma_rm_defs.h @@ -105,6 +105,7 @@ typedef struct RdmaDeviceResources { RdmaRmResTbl cq_tbl; RdmaRmResTbl cqe_ctx_tbl; GHashTable *qp_hash; /* Keeps mapping between real and emulated */ + QemuMutex lock; } RdmaDeviceResources; =20 #endif --=20 2.17.2