From 745118acb9205e502c145963f7c7afb7f4da10b3 Mon Sep 17 00:00:00 2001 From: Oron Peled Date: Sun, 29 Sep 2013 13:20:38 +0200 Subject: [PATCH] xpp: Serialize dahdi registration xpp: Serialize dahdi registration: Cause races under highly-parallel workloads (with dahdi_autoreg=0). Signed-off-by: Tzafrir Cohen --- drivers/dahdi/xpp/xbus-core.c | 22 ++++++++++++++++++++-- drivers/dahdi/xpp/xbus-sysfs.c | 9 +++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/dahdi/xpp/xbus-core.c b/drivers/dahdi/xpp/xbus-core.c index c2fb00f..7a7c368 100644 --- a/drivers/dahdi/xpp/xbus-core.c +++ b/drivers/dahdi/xpp/xbus-core.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #ifdef PROTOCOL_DEBUG @@ -937,6 +938,8 @@ static void xbus_free_ddev(xbus_t *xbus) xbus->ddev = NULL; } +static DEFINE_MUTEX(dahdi_registration_mutex); + int xbus_register_dahdi_device(xbus_t *xbus) { int i; @@ -944,6 +947,11 @@ int xbus_register_dahdi_device(xbus_t *xbus) int ret; XBUS_DBG(DEVICES, xbus, "Entering %s\n", __func__); + ret = mutex_lock_interruptible(&dahdi_registration_mutex); + if (ret < 0) { + XBUS_ERR(xbus, "dahdi_registration_mutex already taken\n"); + goto err; + } if (xbus_is_registered(xbus)) { XBUS_ERR(xbus, "Already registered to DAHDI\n"); WARN_ON(1); @@ -1008,17 +1016,26 @@ int xbus_register_dahdi_device(xbus_t *xbus) xpd_dahdi_postregister(xpd); } } - return 0; + ret = 0; +out: + mutex_unlock(&dahdi_registration_mutex); + return ret; err: xbus_free_ddev(xbus); - return ret; + goto out; } void xbus_unregister_dahdi_device(xbus_t *xbus) { int i; + int ret; XBUS_NOTICE(xbus, "%s\n", __func__); + ret = mutex_lock_interruptible(&dahdi_registration_mutex); + if (ret < 0) { + XBUS_ERR(xbus, "dahdi_registration_mutex already taken\n"); + return; + } for (i = 0; i < MAX_XPDS; i++) { xpd_t *xpd = xpd_of(xbus, i); xpd_dahdi_preunregister(xpd); @@ -1033,6 +1050,7 @@ void xbus_unregister_dahdi_device(xbus_t *xbus) xpd_t *xpd = xpd_of(xbus, i); xpd_dahdi_postunregister(xpd); } + mutex_unlock(&dahdi_registration_mutex); } /* diff --git a/drivers/dahdi/xpp/xbus-sysfs.c b/drivers/dahdi/xpp/xbus-sysfs.c index ad58e15..956e765 100644 --- a/drivers/dahdi/xpp/xbus-sysfs.c +++ b/drivers/dahdi/xpp/xbus-sysfs.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #ifdef PROTOCOL_DEBUG #include @@ -582,6 +583,8 @@ static DEVICE_ATTR_READER(span_show, dev, buf) return len; } +static DEFINE_MUTEX(span_store_mutex); + /* * For backward compatibility with old dahdi-tools * Remove after dahdi_registration is upgraded @@ -603,6 +606,11 @@ static DEVICE_ATTR_WRITER(span_store, dev, buf, count) return -ENODEV; XPD_DBG(DEVICES, xpd, "%s -- deprecated (should use pinned-spans)\n", (dahdi_reg) ? "register" : "unregister"); + ret = mutex_lock_interruptible(&span_store_mutex); + if (ret < 0) { + XBUS_ERR(xpd->xbus, "span_store_mutex already taken\n"); + return ret; + } if (xbus_is_registered(xpd->xbus)) { if (dahdi_reg) { XPD_DBG(DEVICES, xpd, @@ -620,6 +628,7 @@ static DEVICE_ATTR_WRITER(span_store, dev, buf, count) xbus_register_dahdi_device(xpd->xbus); } } + mutex_unlock(&span_store_mutex); return count; }