pci: introduce a global hotplug lock
Despite the scary commit title, this patch just unifies per-driver mutexes into a single pci mutex. On each hotplug we modify some DPDK global resources, which per-driver locks aren't sufficient for. If multiple threads try to attach devices at the same time, then we'll likely have a data race. DPDK hotplug APIs don't provide any kind of thread safety on their own. Change-Id: I89cca9fea04ecf576ec5854c662bae1d3712b3fb Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/433864 (master) Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448368 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
3cc92124d0
commit
dacd34969b
@ -74,7 +74,6 @@ struct spdk_pci_enum_ctx {
|
||||
struct rte_pci_driver driver;
|
||||
spdk_pci_enum_cb cb_fn;
|
||||
void *cb_arg;
|
||||
pthread_mutex_t mtx;
|
||||
bool is_registered;
|
||||
};
|
||||
|
||||
|
@ -40,6 +40,8 @@
|
||||
#define PCI_CFG_SIZE 256
|
||||
#define PCI_EXT_CAP_ID_SN 0x03
|
||||
|
||||
static pthread_mutex_t g_pci_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
int
|
||||
spdk_pci_device_init(struct rte_pci_driver *driver,
|
||||
struct rte_pci_device *device)
|
||||
@ -122,7 +124,7 @@ spdk_pci_device_attach(struct spdk_pci_enum_ctx *ctx,
|
||||
addr.function = pci_address->func;
|
||||
#endif
|
||||
|
||||
pthread_mutex_lock(&ctx->mtx);
|
||||
pthread_mutex_lock(&g_pci_mutex);
|
||||
|
||||
if (!ctx->is_registered) {
|
||||
ctx->is_registered = true;
|
||||
@ -147,13 +149,13 @@ spdk_pci_device_attach(struct spdk_pci_enum_ctx *ctx,
|
||||
#endif
|
||||
ctx->cb_arg = NULL;
|
||||
ctx->cb_fn = NULL;
|
||||
pthread_mutex_unlock(&ctx->mtx);
|
||||
pthread_mutex_unlock(&g_pci_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->cb_arg = NULL;
|
||||
ctx->cb_fn = NULL;
|
||||
pthread_mutex_unlock(&ctx->mtx);
|
||||
pthread_mutex_unlock(&g_pci_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -167,7 +169,7 @@ spdk_pci_enumerate(struct spdk_pci_enum_ctx *ctx,
|
||||
spdk_pci_enum_cb enum_cb,
|
||||
void *enum_ctx)
|
||||
{
|
||||
pthread_mutex_lock(&ctx->mtx);
|
||||
pthread_mutex_lock(&g_pci_mutex);
|
||||
|
||||
if (!ctx->is_registered) {
|
||||
ctx->is_registered = true;
|
||||
@ -190,13 +192,13 @@ spdk_pci_enumerate(struct spdk_pci_enum_ctx *ctx,
|
||||
#endif
|
||||
ctx->cb_arg = NULL;
|
||||
ctx->cb_fn = NULL;
|
||||
pthread_mutex_unlock(&ctx->mtx);
|
||||
pthread_mutex_unlock(&g_pci_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->cb_arg = NULL;
|
||||
ctx->cb_fn = NULL;
|
||||
pthread_mutex_unlock(&ctx->mtx);
|
||||
pthread_mutex_unlock(&g_pci_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -105,7 +105,6 @@ static struct spdk_pci_enum_ctx g_ioat_pci_drv = {
|
||||
|
||||
.cb_fn = NULL,
|
||||
.cb_arg = NULL,
|
||||
.mtx = PTHREAD_MUTEX_INITIALIZER,
|
||||
.is_registered = false,
|
||||
};
|
||||
|
||||
|
@ -71,7 +71,6 @@ static struct spdk_pci_enum_ctx g_nvme_pci_drv = {
|
||||
|
||||
.cb_fn = NULL,
|
||||
.cb_arg = NULL,
|
||||
.mtx = PTHREAD_MUTEX_INITIALIZER,
|
||||
.is_registered = false,
|
||||
};
|
||||
|
||||
|
@ -62,7 +62,6 @@ static struct spdk_pci_enum_ctx g_virtio_pci_drv = {
|
||||
|
||||
.cb_fn = NULL,
|
||||
.cb_arg = NULL,
|
||||
.mtx = PTHREAD_MUTEX_INITIALIZER,
|
||||
.is_registered = false,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user