linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org,
	linux-rt-users <linux-rt-users@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Carsten Emde <C.Emde@osadl.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	John Kacur <jkacur@redhat.com>, <stable-rt@vger.kernel.org>,
	Paul Gortmaker <paul.gortmaker@windriver.com>
Subject: [PATCH RT 04/16] list_bl.h: make list head locking RT safe
Date: Mon, 09 Sep 2013 10:35:21 -0400	[thread overview]
Message-ID: <20130909143534.807208609@goodmis.org> (raw)
In-Reply-To: 20130909143517.641735717@goodmis.org

[-- Attachment #1: 0004-list_bl.h-make-list-head-locking-RT-safe.patch --]
[-- Type: text/plain, Size: 3645 bytes --]

From: Paul Gortmaker <paul.gortmaker@windriver.com>

As per changes in include/linux/jbd_common.h for avoiding the
bit_spin_locks on RT ("fs: jbd/jbd2: Make state lock and journal
head lock rt safe") we do the same thing here.

We use the non atomic __set_bit and __clear_bit inside the scope of
the lock to preserve the ability of the existing LIST_DEBUG code to
use the zero'th bit in the sanity checks.

As a bit spinlock, we had no lockdep visibility into the usage
of the list head locking.  Now, if we were to implement it as a
standard non-raw spinlock, we would see:

BUG: sleeping function called from invalid context at kernel/rtmutex.c:658
in_atomic(): 1, irqs_disabled(): 0, pid: 122, name: udevd
5 locks held by udevd/122:
 #0:  (&sb->s_type->i_mutex_key#7/1){+.+.+.}, at: [<ffffffff811967e8>] lock_rename+0xe8/0xf0
 #1:  (rename_lock){+.+...}, at: [<ffffffff811a277c>] d_move+0x2c/0x60
 #2:  (&dentry->d_lock){+.+...}, at: [<ffffffff811a0763>] dentry_lock_for_move+0xf3/0x130
 #3:  (&dentry->d_lock/2){+.+...}, at: [<ffffffff811a0734>] dentry_lock_for_move+0xc4/0x130
 #4:  (&dentry->d_lock/3){+.+...}, at: [<ffffffff811a0747>] dentry_lock_for_move+0xd7/0x130
Pid: 122, comm: udevd Not tainted 3.4.47-rt62 #7
Call Trace:
 [<ffffffff810b9624>] __might_sleep+0x134/0x1f0
 [<ffffffff817a24d4>] rt_spin_lock+0x24/0x60
 [<ffffffff811a0c4c>] __d_shrink+0x5c/0xa0
 [<ffffffff811a1b2d>] __d_drop+0x1d/0x40
 [<ffffffff811a24be>] __d_move+0x8e/0x320
 [<ffffffff811a278e>] d_move+0x3e/0x60
 [<ffffffff81199598>] vfs_rename+0x198/0x4c0
 [<ffffffff8119b093>] sys_renameat+0x213/0x240
 [<ffffffff817a2de5>] ? _raw_spin_unlock+0x35/0x60
 [<ffffffff8107781c>] ? do_page_fault+0x1ec/0x4b0
 [<ffffffff817a32ca>] ? retint_swapgs+0xe/0x13
 [<ffffffff813eb0e6>] ? trace_hardirqs_on_thunk+0x3a/0x3f
 [<ffffffff8119b0db>] sys_rename+0x1b/0x20
 [<ffffffff817a3b96>] system_call_fastpath+0x1a/0x1f

Since we are only taking the lock during short lived list operations,
lets assume for now that it being raw won't be a significant latency
concern.

Cc: stable-rt@vger.kernel.org
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 include/linux/list_bl.h |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/linux/list_bl.h b/include/linux/list_bl.h
index 31f9d75..ddfd46a 100644
--- a/include/linux/list_bl.h
+++ b/include/linux/list_bl.h
@@ -2,6 +2,7 @@
 #define _LINUX_LIST_BL_H
 
 #include <linux/list.h>
+#include <linux/spinlock.h>
 #include <linux/bit_spinlock.h>
 
 /*
@@ -32,13 +33,22 @@
 
 struct hlist_bl_head {
 	struct hlist_bl_node *first;
+#ifdef CONFIG_PREEMPT_RT_BASE
+	raw_spinlock_t lock;
+#endif
 };
 
 struct hlist_bl_node {
 	struct hlist_bl_node *next, **pprev;
 };
-#define INIT_HLIST_BL_HEAD(ptr) \
-	((ptr)->first = NULL)
+
+static inline void INIT_HLIST_BL_HEAD(struct hlist_bl_head *h)
+{
+	h->first = NULL;
+#ifdef CONFIG_PREEMPT_RT_BASE
+	raw_spin_lock_init(&h->lock);
+#endif
+}
 
 static inline void INIT_HLIST_BL_NODE(struct hlist_bl_node *h)
 {
@@ -117,12 +127,22 @@ static inline void hlist_bl_del_init(struct hlist_bl_node *n)
 
 static inline void hlist_bl_lock(struct hlist_bl_head *b)
 {
+#ifndef CONFIG_PREEMPT_RT_BASE
 	bit_spin_lock(0, (unsigned long *)b);
+#else
+	raw_spin_lock(&b->lock);
+	__set_bit(0, (unsigned long *)b);
+#endif
 }
 
 static inline void hlist_bl_unlock(struct hlist_bl_head *b)
 {
+#ifndef CONFIG_PREEMPT_RT_BASE
 	__bit_spin_unlock(0, (unsigned long *)b);
+#else
+	__clear_bit(0, (unsigned long *)b);
+	raw_spin_unlock(&b->lock);
+#endif
 }
 
 /**
-- 
1.7.10.4

  parent reply	other threads:[~2013-09-09 14:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-09 14:35 [PATCH RT 00/16] 3.0.89-rt118-rc1 stable review Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 01/16] sched/workqueue: Only wake up idle workers if not blocked on sleeping spin lock Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 02/16] x86/mce: fix mce timer interval Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 03/16] genirq: Set irq thread to RT priority on creation Steven Rostedt
2013-09-09 14:35 ` Steven Rostedt [this message]
2013-09-09 14:35 ` [PATCH RT 05/16] list_bl.h: fix it for for !SMP && !DEBUG_SPINLOCK Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 06/16] timers: prepare for full preemption improve Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 07/16] kernel/cpu: fix cpu down problem if kthreads cpu is going down Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 08/16] kernel/hotplug: restore original cpu mask oncpu/down Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 09/16] drm/i915: drop trace_i915_gem_ring_dispatch on rt Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 10/16] rt,ntp: Move call to schedule_delayed_work() to helper thread Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 11/16] hwlat-detector: Update hwlat_detector to add outer loop detection Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 12/16] hwlat-detect/trace: Export trace_clock_local for hwlat-detector Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 13/16] hwlat-detector: Use trace_clock_local if available Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 14/16] hwlat-detector: Use thread instead of stop machine Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 15/16] genirq: do not invoke the affinity callback via a workqueue Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 16/16] Linux 3.0.89-rt118-rc1 Steven Rostedt
  -- strict thread matches above, loose matches on Subject: below --
2013-09-09 12:47 [PATCH RT 00/16] 3.2.50-rt71-rc1 stable review Steven Rostedt
2013-09-09 12:47 ` [PATCH RT 04/16] list_bl.h: make list head locking RT safe Steven Rostedt
2013-09-09 12:45 [PATCH RT 00/16] 3.4.57-rt73-rc1 stable review Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 04/16] list_bl.h: make list head locking RT safe Steven Rostedt

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=20130909143534.807208609@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=C.Emde@osadl.org \
    --cc=bigeasy@linutronix.de \
    --cc=jkacur@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=stable-rt@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).