All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm:Avoid soft lockup due to possible attempt of double locking object's lock in __delete_object
@ 2016-08-30 18:35 Nicholas Krause
  2016-08-31  7:54   ` Catalin Marinas
  0 siblings, 1 reply; 13+ messages in thread
From: Nicholas Krause @ 2016-08-30 18:35 UTC (permalink / raw)
  To: catalin.marinas; +Cc: linux-mm, linux-kernel

This fixes a issue in the current locking logic of the function,
__delete_object where we are trying to attempt to lock the passed
object structure's spinlock again after being previously held
elsewhere by the kmemleak code. Fix this by instead of assuming
we are the only one contending for the object's lock their are
possible other users and create two branches, one where we get
the lock when calling spin_trylock_irqsave on the object's lock
and the other when the lock is held else where by kmemleak.

Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
---
 mm/kmemleak.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 086292f..ad4828f 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -631,12 +631,19 @@ static void __delete_object(struct kmemleak_object *object)
 
 	/*
 	 * Locking here also ensures that the corresponding memory block
-	 * cannot be freed when it is being scanned.
+	 * cannot be freed when it is being scanned. Further more the
+	 * object's lock may have been previously holded by another holder
+	 * in the kmemleak code, therefore attempt to lock the object's lock
+	 * before holding it and unlocking it.
 	 */
-	spin_lock_irqsave(&object->lock, flags);
-	object->flags &= ~OBJECT_ALLOCATED;
-	spin_unlock_irqrestore(&object->lock, flags);
-	put_object(object);
+	if (spin_trylock_irqsave(&object->lock, flags)) {
+		object->flags &= ~OBJECT_ALLOCATED;
+		spin_unlock_irqrestore(&object->lock, flags);
+		put_object(object);
+	} else {
+		object->flags &= ~OBJECT_ALLOCATED;
+		put_object(object);
+	}
 }
 
 /*
-- 
2.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-09-07  1:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-30 18:35 [PATCH] mm:Avoid soft lockup due to possible attempt of double locking object's lock in __delete_object Nicholas Krause
2016-08-31  7:54 ` Catalin Marinas
2016-08-31  7:54   ` Catalin Marinas
2016-08-31 13:24   ` nick
2016-09-07  0:45     ` Rik van Riel
2016-08-31 13:41   ` nick
2016-08-31 14:35     ` Catalin Marinas
2016-08-31 14:35       ` Catalin Marinas
2016-08-31 21:08   ` Valdis.Kletnieks
2016-08-31 21:28     ` nick
2016-09-07  0:51       ` Rik van Riel
2016-09-07  1:12         ` nick
2016-09-07  1:22           ` Rik van Riel

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.