From patchwork Sat Feb 23 14:16:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 10827553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE1C06C2 for ; Sat, 23 Feb 2019 14:23:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5E612EF2A for ; Sat, 23 Feb 2019 14:23:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A707E2EF31; Sat, 23 Feb 2019 14:23:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4EAC92EF2A for ; Sat, 23 Feb 2019 14:23:10 +0000 (UTC) Received: from localhost ([127.0.0.1]:38589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxYCr-0002Uw-HY for patchwork-qemu-devel@patchwork.kernel.org; Sat, 23 Feb 2019 09:23:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxY6t-0006UN-55 for qemu-devel@nongnu.org; Sat, 23 Feb 2019 09:16:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxY6r-0002Nc-CU for qemu-devel@nongnu.org; Sat, 23 Feb 2019 09:16:59 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:38158) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gxY6q-0002NI-Eo for qemu-devel@nongnu.org; Sat, 23 Feb 2019 09:16:56 -0500 Received: by mail-wm1-x343.google.com with SMTP id v26so4344963wmh.3 for ; Sat, 23 Feb 2019 06:16:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U8MQwPEgkzy09ckEHhmxHP6Tt3sT15z3F6xuiIEowL0=; b=dVRoZsvb5zmH1Q6mKP+Dfy7cPBVfPkQFrbBVHsXze6jWDOpA+S22mKLDJQjoHWcMKk rugjbgcqtF630JVMMifXgAfyCFl3o0LgH22jfm6cwvo3vAW7G63iYmdvbIsbl9YxTdAa G4sIwwDH6fBwp1ZNrvQhH2TPz1McM77W+5cPsQIPo+nBLHMovEQqa49H0UkjtC+fzg0S LCXsjyNjK3umgNOPtHrNUPptFtjnu/kg18J7tobkgRHwhvWqxxo+Qse8JrOD3ktXdEWw eE2kP8aA/UTUB/up1vP+CwdC9k1DPKT8fRO78Ux5BRrjcU5GlL9H14vvLYLtMJ4hU3MW iE0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=U8MQwPEgkzy09ckEHhmxHP6Tt3sT15z3F6xuiIEowL0=; b=nigb+ctztZsEhAFM3LrYSx5wJSl1me8X9CnuYpgkPBrxZHZK2nMjMffegjjjCGzIZO UABoypuEmiGL6wNG4t2g7eESpjLeNse6gmLeBLIqqpJlR5WieE+0tLQh+RToqkOOpSNR OA8iojJnKwBlwrEXQuu20Iv+2ikypdNYknfKksKrLhDf5+S133XnTk4fCMVSDNZZsB9U wudI/liITtZBHkPNrGCR92RiZa/vD/PHiv/qSAh0LD1cDsFCyGLDBbd/7Q62/eYHkqf1 BqHW3TKflPIFgtYPkbsZTdzcHtkD0EcHW8hA3PdJSyXtLlhTYL9/3Q5U4Dr6nPs4jCDr GSsQ== X-Gm-Message-State: AHQUAuYoVxuFhgxQTvw1RrPgQLaRAAstgg41Gh/60WiMzkyo4CPaRYIX HYq04jLtjGKzYe2iuXwjd1PNFy2K X-Google-Smtp-Source: AHgI3IY4sY8k6aXd4qwCb82g8uEQucXEQM1KoFLaNBFTWomkiQC4iuDEyUtmAO0PpADdeLS3i/cX+Q== X-Received: by 2002:a7b:c448:: with SMTP id l8mr222052wmi.4.1550931415075; Sat, 23 Feb 2019 06:16:55 -0800 (PST) Received: from localhost.localdomain ([176.228.155.165]) by smtp.gmail.com with ESMTPSA id x3sm3310506wru.76.2019.02.23.06.16.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Feb 2019 06:16:54 -0800 (PST) From: Marcel Apfelbaum To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sat, 23 Feb 2019 16:16:37 +0200 Message-Id: <20190223141644.6609-5-marcel.apfelbaum@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190223141644.6609-1-marcel.apfelbaum@gmail.com> References: <20190223141644.6609-1-marcel.apfelbaum@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PATCH PULL 04/11] 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: , Cc: philmd@redhat.com, kamalheib1@gmail.com, yuval.shaia@oracle.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Yuval Shaia 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 Message-Id: <20190213065357.16076-5-yuval.shaia@oracle.com> Signed-off-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_res, struct ibv_cq *ibcq) BackendCtx *bctx; struct ibv_wc wc[2]; + qemu_mutex_lock(&rdma_dev_res->lock); do { ne = ibv_poll_cq(ibcq, ARRAY_SIZE(wc), wc); @@ -89,6 +90,7 @@ static void rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq *ibcq) g_free(bctx); } } while (ne > 0); + qemu_mutex_unlock(&rdma_dev_res->lock); if (ne < 0) { rdma_error_report("ibv_poll_cq fail, rc=%d, errno=%d", ne, errno); 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, init_ports(dev_res); + qemu_mutex_init(&dev_res->lock); + return 0; } void rdma_rm_fini(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev, const char *ifname) { + qemu_mutex_destroy(&dev_res->lock); + fini_ports(dev_res, backend_dev, ifname); 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; #endif