All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andres Lagar-Cavilla <andres@lagarcavilla.org>
To: xen-devel@lists.xensource.com
Cc: olaf@aepfle.de, George.Dunlap@eu.citrix.com,
	andres@gridcentric.ca, tim@xen.org, keir.xen@gmail.com,
	adin@gridcentric.ca
Subject: [PATCH 1 of 5] Refactor mm-lock ordering constructs
Date: Mon, 07 Nov 2011 22:28:29 -0500	[thread overview]
Message-ID: <75f1e156386dca6bc568.1320722909@xdev.gridcentric.ca> (raw)
In-Reply-To: <patchbomb.1320722908@xdev.gridcentric.ca>

 xen/arch/x86/mm/mm-locks.h |  27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)


The mm layer has a construct to enforce locks are taken in a pre-
defined order, and thus avert deadlock. Refactor pieces of this
code for later use, no functional changes.

Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>

diff -r 54a5e994a241 -r 75f1e156386d xen/arch/x86/mm/mm-locks.h
--- a/xen/arch/x86/mm/mm-locks.h
+++ b/xen/arch/x86/mm/mm-locks.h
@@ -28,6 +28,7 @@
 
 /* Per-CPU variable for enforcing the lock ordering */
 DECLARE_PER_CPU(int, mm_lock_level);
+#define __get_lock_level()  (this_cpu(mm_lock_level))
 
 static inline void mm_lock_init(mm_lock_t *l)
 {
@@ -42,22 +43,32 @@ static inline int mm_locked_by_me(mm_loc
     return (l->lock.recurse_cpu == current->processor);
 }
 
+/* If you see this crash, the numbers printed are lines in this file 
+ * where the offending locks are declared. */
+#define __check_lock_level(l)                           \
+do {                                                    \
+    if ( unlikely(__get_lock_level()) > (l) )           \
+        panic("mm locking order violation: %i > %i\n",  \
+              __get_lock_level(), (l));                 \
+} while(0)
+
+#define __set_lock_level(l)         \
+do {                                \
+    __get_lock_level() = (l);       \
+} while(0)
+
 static inline void _mm_lock(mm_lock_t *l, const char *func, int level, int rec)
 {
-    /* If you see this crash, the numbers printed are lines in this file 
-     * where the offending locks are declared. */
-    if ( unlikely(this_cpu(mm_lock_level) > level) )
-        panic("mm locking order violation: %i > %i\n", 
-              this_cpu(mm_lock_level), level);
+    __check_lock_level(level);
     spin_lock_recursive(&l->lock);
     if ( l->lock.recurse_cnt == 1 )
     {
         l->locker_function = func;
-        l->unlock_level = this_cpu(mm_lock_level);
+        l->unlock_level = __get_lock_level();
     }
     else if ( (unlikely(!rec)) )
         panic("mm lock already held by %s\n", l->locker_function);
-    this_cpu(mm_lock_level) = level;
+    __set_lock_level(level);
 }
 /* This wrapper uses the line number to express the locking order below */
 #define declare_mm_lock(name)                                                 \
@@ -72,7 +83,7 @@ static inline void mm_unlock(mm_lock_t *
     if ( l->lock.recurse_cnt == 1 )
     {
         l->locker_function = "nobody";
-        this_cpu(mm_lock_level) = l->unlock_level;
+        __set_lock_level(l->unlock_level);
     }
     spin_unlock_recursive(&l->lock);
 }

  reply	other threads:[~2011-11-08  3:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-08  3:28 [PATCH 0 of 5] p2m synchronization groundwork Andres Lagar-Cavilla
2011-11-08  3:28 ` Andres Lagar-Cavilla [this message]
2011-11-08  3:28 ` [PATCH 2 of 5] Declare an order-enforcing construct for external locks used in the mm layer Andres Lagar-Cavilla
2011-11-08  3:28 ` [PATCH 3 of 5] Enforce ordering constraints for the page alloc lock in the PoD code Andres Lagar-Cavilla
2011-11-08  3:28 ` [PATCH 4 of 5] Refactor p2m get_entry accessor Andres Lagar-Cavilla
2011-11-08  3:28 ` [PATCH 5 of 5] Modify naming of queries into the p2m Andres Lagar-Cavilla
2011-11-10 12:26   ` Tim Deegan
2011-11-10 13:54     ` Andres Lagar-Cavilla
2011-11-10 16:47     ` Andres Lagar-Cavilla
2011-11-10 12:27 ` [PATCH 0 of 5] p2m synchronization groundwork Tim Deegan

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=75f1e156386dca6bc568.1320722909@xdev.gridcentric.ca \
    --to=andres@lagarcavilla.org \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=adin@gridcentric.ca \
    --cc=andres@gridcentric.ca \
    --cc=keir.xen@gmail.com \
    --cc=olaf@aepfle.de \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xensource.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.