[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH PULL 04/18] hw/rdma: Protect against concurrent exec
From: |
Marcel Apfelbaum |
Subject: |
[Qemu-devel] [PATCH PULL 04/18] hw/rdma: Protect against concurrent execution of poll_cq |
Date: |
Sat, 16 Mar 2019 16:34:07 +0200 |
From: Yuval Shaia <address@hidden>
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 <address@hidden>
Reviewed-by: Marcel Apfelbaum <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Kamal Heib <address@hidden>
Signed-off-by: Marcel Apfelbaum <address@hidden>
---
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 37edf42215..18975401d9 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 66177b42f5..7ea62a9e60 100644
--- a/hw/rdma/rdma_rm.c
+++ b/hw/rdma/rdma_rm.c
@@ -617,12 +617,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.1
- [Qemu-devel] [PATCH PULL 00/18] RDMA queue, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 01/18] contrib/rdmacm-mux: Fix out-of-bounds risk, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 03/18] hw/rdma: Introduce protected qlist, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 04/18] hw/rdma: Protect against concurrent execution of poll_cq,
Marcel Apfelbaum <=
- [Qemu-devel] [PATCH PULL 05/18] hw/pvrdma: Collect debugging statistics, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 07/18] hw/rdma: Free all MAD receive buffers when device is closed, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 10/18] hw/pvrdma: Delete pvrdma_exit function, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 11/18] hw/pvrdma: Unregister from shutdown notifier when device goes down, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 09/18] hw/pvrdma: Delete unneeded function argument, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 08/18] hw/rdma: Free all receive buffers when QP is destroyed, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 12/18] hw/pvrdma: Provide correct value to object_get_typename, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 14/18] hw/rdma: Fix broken paths to docs/devel/tracing.txt, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 16/18] hw/rdma: Use {} instead of {0}, Marcel Apfelbaum, 2019/03/16
- [Qemu-devel] [PATCH PULL 18/18] hw/rdma: Fix the error prints in create_qp_rings(), Marcel Apfelbaum, 2019/03/16