LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Fix for genalloc locking
@ 2008-10-17  6:43 Iwo Mergler
  2008-10-17  6:46 ` [PATCH] " Iwo Mergler
  2008-10-21 15:39 ` Randy Dunlap
  0 siblings, 2 replies; 4+ messages in thread
From: Iwo Mergler @ 2008-10-17  6:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jes Sorensen

Hi,

I hit a little problem while using genalloc with a mix
of interrupt/non-interrupt context. I believe the correct
fix is to replace the locking calls with the _irqsave/_irqrestore
variants. Patch follows.

Is this correct?

BTW, is there any documentation on the Lockdep warnings?
What exactly is the meaning of {--+.} in 

(&pool->lock){--+.}, at: [<c0125d1c>] gen_pool_free+0x34/0x120


Kind regards,

Iwo


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

* Re: [PATCH] Fix for genalloc locking
  2008-10-17  6:43 Fix for genalloc locking Iwo Mergler
@ 2008-10-17  6:46 ` Iwo Mergler
  2008-10-21 15:39 ` Randy Dunlap
  1 sibling, 0 replies; 4+ messages in thread
From: Iwo Mergler @ 2008-10-17  6:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jes Sorensen


Genalloc was using a rwlock without irqsave/irqrestore. This
caused problems when used with a mix of int/non-int calls.
Replaced all locking functions with the irqsave/restore
variants.

Signed-off-by: Iwo.Mergler@call-direct.com.au

---
 lib/genalloc.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/lib/genalloc.c b/lib/genalloc.c
index f6d276d..337f05a 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -49,6 +49,7 @@ EXPORT_SYMBOL(gen_pool_create);
 int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size,
 		 int nid)
 {
+	unsigned long rwflags;
 	struct gen_pool_chunk *chunk;
 	int nbits = size >> pool->min_alloc_order;
 	int nbytes = sizeof(struct gen_pool_chunk) +
@@ -62,9 +63,9 @@ int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size,
 	chunk->start_addr = addr;
 	chunk->end_addr = addr + size;
 
-	write_lock(&pool->lock);
+	write_lock_irqsave(&pool->lock, rwflags);
 	list_add(&chunk->next_chunk, &pool->chunks);
-	write_unlock(&pool->lock);
+	write_unlock_irqrestore(&pool->lock, rwflags);
 
 	return 0;
 }
@@ -83,9 +84,9 @@ void gen_pool_destroy(struct gen_pool *pool)
 	struct gen_pool_chunk *chunk;
 	int order = pool->min_alloc_order;
 	int bit, end_bit;
+	unsigned long rwflags;
 
-
-	write_lock(&pool->lock);
+	write_lock_irqsave(&pool->lock, rwflags);
 	list_for_each_safe(_chunk, _next_chunk, &pool->chunks) {
 		chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
 		list_del(&chunk->next_chunk);
@@ -116,13 +117,14 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
 	unsigned long addr, flags;
 	int order = pool->min_alloc_order;
 	int nbits, bit, start_bit, end_bit;
+	unsigned long rwflags;
 
 	if (size == 0)
 		return 0;
 
 	nbits = (size + (1UL << order) - 1) >> order;
 
-	read_lock(&pool->lock);
+	read_lock_irqsave(&pool->lock, rwflags);
 	list_for_each(_chunk, &pool->chunks) {
 		chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
 
@@ -149,12 +151,12 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
 			while (nbits--)
 				__set_bit(start_bit++, chunk->bits);
 			spin_unlock_irqrestore(&chunk->lock, flags);
-			read_unlock(&pool->lock);
+			read_unlock_irqrestore(&pool->lock, rwflags);
 			return addr;
 		}
 		spin_unlock_irqrestore(&chunk->lock, flags);
 	}
-	read_unlock(&pool->lock);
+	read_unlock_irqrestore(&pool->lock, rwflags);
 	return 0;
 }
 EXPORT_SYMBOL(gen_pool_alloc);
@@ -174,10 +176,11 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size)
 	unsigned long flags;
 	int order = pool->min_alloc_order;
 	int bit, nbits;
+	unsigned long rwflags;
 
 	nbits = (size + (1UL << order) - 1) >> order;
 
-	read_lock(&pool->lock);
+	read_lock_irqsave(&pool->lock, rwflags);
 	list_for_each(_chunk, &pool->chunks) {
 		chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
 
@@ -192,6 +195,6 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size)
 		}
 	}
 	BUG_ON(nbits > 0);
-	read_unlock(&pool->lock);
+	read_unlock_irqrestore(&pool->lock, rwflags);
 }
 EXPORT_SYMBOL(gen_pool_free);
-- 
1.6.0



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

* Re: Fix for genalloc locking
  2008-10-17  6:43 Fix for genalloc locking Iwo Mergler
  2008-10-17  6:46 ` [PATCH] " Iwo Mergler
@ 2008-10-21 15:39 ` Randy Dunlap
  2008-10-21 22:20   ` Iwo Mergler
  1 sibling, 1 reply; 4+ messages in thread
From: Randy Dunlap @ 2008-10-21 15:39 UTC (permalink / raw)
  To: Iwo Mergler; +Cc: linux-kernel, Jes Sorensen

On Fri, 17 Oct 2008 16:43:12 +1000 Iwo Mergler wrote:

> Hi,
> 
> I hit a little problem while using genalloc with a mix
> of interrupt/non-interrupt context. I believe the correct
> fix is to replace the locking calls with the _irqsave/_irqrestore
> variants. Patch follows.
> 
> Is this correct?
> 
> BTW, is there any documentation on the Lockdep warnings?
> What exactly is the meaning of {--+.} in 
> 
> (&pool->lock){--+.}, at: [<c0125d1c>] gen_pool_free+0x34/0x120

Did you read Documentation/lockdep-design.txt ?

---
~Randy

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

* Re: Fix for genalloc locking
  2008-10-21 15:39 ` Randy Dunlap
@ 2008-10-21 22:20   ` Iwo Mergler
  0 siblings, 0 replies; 4+ messages in thread
From: Iwo Mergler @ 2008-10-21 22:20 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: linux-kernel, Jes Sorensen

Randy Dunlap wrote:
> On Fri, 17 Oct 2008 16:43:12 +1000 Iwo Mergler wrote:
>> BTW, is there any documentation on the Lockdep warnings?
>> What exactly is the meaning of {--+.} in 
>>
>> (&pool->lock){--+.}, at: [<c0125d1c>] gen_pool_free+0x34/0x120
> 
> Did you read Documentation/lockdep-design.txt ?
> 

No, I didn't. Selective blindness. Thanks for the hint.

Kind regards,

Iwo


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

end of thread, other threads:[~2008-10-21 22:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-17  6:43 Fix for genalloc locking Iwo Mergler
2008-10-17  6:46 ` [PATCH] " Iwo Mergler
2008-10-21 15:39 ` Randy Dunlap
2008-10-21 22:20   ` Iwo Mergler

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).