All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuval Shaia <yuval.shaia@oracle.com>
To: dgilbert@redhat.com, yuval.shaia@oracle.com,
	marcel.apfelbaum@gmail.com, armbru@redhat.com,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2 3/9] hw/rdma: Protect against concurrent execution of poll_cq
Date: Wed, 13 Feb 2019 08:53:51 +0200	[thread overview]
Message-ID: <20190213065357.16076-5-yuval.shaia@oracle.com> (raw)
In-Reply-To: <20190213065357.16076-1-yuval.shaia@oracle.com>

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 <yuval.shaia@oracle.com>
Reviewed-by: Marcel Apfelbaum<marcel.apfelbaum@gmail.com>
---
 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
-- 
2.17.2

  parent reply	other threads:[~2019-02-13  7:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-13  6:53 [Qemu-devel] [PATCH v2 0/9] Misc fixes to pvrdma device Yuval Shaia
2019-02-13  6:53 ` [Qemu-devel] [PATCH v2 1/9] hw/rdma: Switch to generic error reporting way Yuval Shaia
2019-02-13  6:53 ` [Qemu-devel] [PATCH v1 2/9] hw/rdma: Introduce locked qlist Yuval Shaia
2019-02-13  6:53 ` [Qemu-devel] [PATCH v2 2/9] hw/rdma: Introduce protected qlist Yuval Shaia
2019-02-14 13:17   ` Marcel Apfelbaum
2019-02-13  6:53 ` Yuval Shaia [this message]
2019-02-13  6:53 ` [Qemu-devel] [PATCH v2 4/9] {monitor, hw/pvrdma}: Expose device internals via monitor interface Yuval Shaia
2019-02-13 10:21   ` Dr. David Alan Gilbert
2019-02-14 13:17     ` Marcel Apfelbaum
2019-02-13  6:53 ` [Qemu-devel] [PATCH v2 5/9] hw/rdma: Free all MAD receive buffers when device is closed Yuval Shaia
2019-02-13  6:53 ` [Qemu-devel] [PATCH v2 6/9] hw/rdma: Free all receive buffers when QP is destroyed Yuval Shaia
2019-02-13  6:53 ` [Qemu-devel] [PATCH v2 7/9] hw/pvrdma: Delete unneeded function argument Yuval Shaia
2019-02-13 12:40   ` Philippe Mathieu-Daudé
2019-02-13 14:46     ` Yuval Shaia
2019-02-14 13:18       ` Marcel Apfelbaum
2019-02-13 15:40     ` Eric Blake
2019-02-13  6:53 ` [Qemu-devel] [PATCH v2 8/9] hw/pvrdma: Delete pvrdma_exit function Yuval Shaia
2019-02-13  6:53 ` [Qemu-devel] [PATCH v2 9/9] hw/pvrdma: Unregister from shutdown notifier when device goes down Yuval Shaia
2019-02-14 14:14 ` [Qemu-devel] [PATCH v2 0/9] Misc fixes to pvrdma device Marcel Apfelbaum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190213065357.16076-5-yuval.shaia@oracle.com \
    --to=yuval.shaia@oracle.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.