Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1296833

[PATCH v3 4/9] stm class: Fix locking in unbinding policy path

From Alexander Shishkin <alexander.shishkin@linux.intel.com>
Newsgroups linux.kernel
Subject [PATCH v3 4/9] stm class: Fix locking in unbinding policy path
Date 2015-12-22 16:30 +0100
Message-ID <qIx2W-5EL-17@gated-at.bofh.it> (permalink)
References <qIx2W-5EL-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Right now, if stm device removal has to unbind from a policy (that is,
an stm device that has STP policy, gets removed), it will trigger a
nested lock on the stm device's policy mutex.

This patch fixes the problem by moving the locking from the policy
unbinding to policy removal (configfs path), where it's actually needed;
the other caller of the policy unbinding function already takes the
mutex around the call.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 drivers/hwtracing/stm/policy.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/stm/policy.c b/drivers/hwtracing/stm/policy.c
index 11ab6d01ad..94d3abfb73 100644
--- a/drivers/hwtracing/stm/policy.c
+++ b/drivers/hwtracing/stm/policy.c
@@ -272,13 +272,17 @@ void stp_policy_unbind(struct stp_policy *policy)
 {
 	struct stm_device *stm = policy->stm;
 
+	/*
+	 * stp_policy_release() will not call here if the policy is already
+	 * unbound; other users should not either, as no link exists between
+	 * this policy and anything else in that case
+	 */
 	if (WARN_ON_ONCE(!policy->stm))
 		return;
 
-	mutex_lock(&stm->policy_mutex);
-	stm->policy = NULL;
-	mutex_unlock(&stm->policy_mutex);
+	lockdep_assert_held(&stm->policy_mutex);
 
+	stm->policy = NULL;
 	policy->stm = NULL;
 
 	stm_put_device(stm);
@@ -287,8 +291,16 @@ void stp_policy_unbind(struct stp_policy *policy)
 static void stp_policy_release(struct config_item *item)
 {
 	struct stp_policy *policy = to_stp_policy(item);
+	struct stm_device *stm = policy->stm;
 
+	/* a policy *can* be unbound and still exist in configfs tree */
+	if (!stm)
+		return;
+
+	mutex_lock(&stm->policy_mutex);
 	stp_policy_unbind(policy);
+	mutex_unlock(&stm->policy_mutex);
+
 	kfree(policy);
 }
 
-- 
2.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 0/9] stm/intel_th: Updates for 4.4 Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-22 16:30 +0100
  [PATCH v3 4/9] stm class: Fix locking in unbinding policy path Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-22 16:30 +0100
  [PATCH v3 1/9] stm class: Hide STM-specific options if STM is disabled Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-22 16:30 +0100
  [PATCH v3 8/9] intel_th: pci: Add Apollo Lake SOC support Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-22 16:30 +0100
  [PATCH v3 5/9] stm class: Fix link list locking Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-22 16:30 +0100
  [PATCH v3 9/9] intel_th: pci: Add Broxton SOC support Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-12-22 16:40 +0100

csiph-web