Skip to contentSkip to conversation

Make rheap safe for spinlocks

PATCH Applied Timur Tabi 2 participants 4 messages Apr 14, 2008 – Apr 17, 2008 PowerPC

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH 1/1 Make rheap safe for spinlocks

The rheap allocation function, rh_alloc, could call kmalloc with GFP_KERNEL. This can sleep, which means you couldn't hold a spinlock while called rh_alloc. Change all kmalloc calls to use GFP_ATOMIC so that it won't sleep. This is safe because only small blocks are allocated.

---

This patch is for 2.6.26.

 arch/powerpc/lib/rheap.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/lib/rheap.c +2 -2
index 22c3b4f..29b2941 100644
@@ -54,7 +54,7 @@ static int grow(rh_info_t * info, int max_blocks)
 
 	new_blocks = max_blocks - info->max_blocks;
 
-	block = kmalloc(sizeof(rh_block_t) * max_blocks, GFP_KERNEL);
+	block = kmalloc(sizeof(rh_block_t) * max_blocks, GFP_ATOMIC);
 	if (block == NULL)
 		return -ENOMEM;
 
@@ -258,7 +258,7 @@ rh_info_t *rh_create(unsigned int alignment)
 	if ((alignment & (alignment - 1)) != 0)
 		return ERR_PTR(-EINVAL);
 
-	info = kmalloc(sizeof(*info), GFP_KERNEL);
+	info = kmalloc(sizeof(*info), GFP_ATOMIC);
 	if (info == NULL)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
1.5.3
#1 lore raw
Quoted 9 lines · Timur Tabi

The rheap allocation function, rh_alloc, could call kmalloc with GFP_KERNEL. This can sleep, which means you couldn't hold a spinlock while called rh_alloc. Change all kmalloc calls to use GFP_ATOMIC so that it won't sleep. This is safe because only small blocks are allocated.

---

This patch is for 2.6.26.

Is this need to fix a bug with an existing driver of for a new driver?

- k

author
#2 lore raw
Quoted 1 line · Kumar Gala

Is this need to fix a bug with an existing driver of for a new driver?

Both. The ucc_geth driver calls qe_muram_alloc() with spinlocks held. The 8610 DIU driver does something similar, but it's targeted for 2.6.26.

I'm hesitant to recommend inclusion in 2.6.25 because I haven't tested the fix throughly enough to know that it doesn't break something else. Technically, it could result in qe_muram_alloc() failing.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
Applied
#3 lore raw
In reply to Timur Tabi
Quoted 5 lines · Timur Tabi

The rheap allocation function, rh_alloc, could call kmalloc with GFP_KERNEL. This can sleep, which means you couldn't hold a spinlock while called rh_alloc. Change all kmalloc calls to use GFP_ATOMIC so that it won't sleep. This is safe because only small blocks are allocated.

Quoted 7 lines

---

This patch is for 2.6.26.

arch/powerpc/lib/rheap.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)

applied.

- k