lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.64.0711081048490.7871@schroedinger.engr.sgi.com>
Date:	Thu, 8 Nov 2007 10:50:00 -0800 (PST)
From:	Christoph Lameter <clameter@....com>
To:	Peter Zijlstra <peterz@...radead.org>
cc:	akpm@...ux-foundation.org,
	linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [patch 01/28] cpu alloc: The allocator

On Thu, 8 Nov 2007, Christoph Lameter wrote:

> > Also, looking at the lock usage, this thing is not IRQ safe, so it
> > should not be called from hardirq context. Please document this.

Well I went the other way and made it work like the slab allocators.


cpu_alloc: Make it irq safe

Use the same method as used in SLAB/SLUB to make the allocator interrupt safe.
disable interrupts when allocator metadata is processed. Reenable interrupts
during page allocator calls if __GFP_WAIT is set in the flags passed to the
allocator.

Signed-off-by: Christoph Lameter <clameter@....com>

---
 mm/cpu_alloc.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Index: linux-2.6/mm/cpu_alloc.c
===================================================================
--- linux-2.6.orig/mm/cpu_alloc.c	2007-11-07 16:49:40.069701326 -0800
+++ linux-2.6/mm/cpu_alloc.c	2007-11-08 10:45:43.172294260 -0800
@@ -186,6 +186,8 @@ static int expand_cpu_area(gfp_t flags)
 		goto out;
 
 	spin_unlock(&cpu_alloc_map_lock);
+	if (flags & __GFP_WAIT)
+		local_irq_enable();
 
 	/*
 	 * Determine the size of the bit map needed
@@ -212,6 +214,8 @@ static int expand_cpu_area(gfp_t flags)
 			goto out;
 	}
 
+	if (flags & __GFP_WAIT)
+		local_irq_disable();
 	spin_lock(&cpu_alloc_map_lock);
 
 	/*
@@ -312,10 +316,11 @@ void *cpu_alloc(unsigned long size, gfp_
 	void *ptr;
 	int first;
 	unsigned long map_size;
+	unsigned long flags;
 
 	BUG_ON(gfpflags & ~(GFP_RECLAIM_MASK | __GFP_ZERO));
 
-	spin_lock(&cpu_alloc_map_lock);
+	spin_lock_irqsave(&cpu_alloc_map_lock, flags);
 
 restart:
 	map_size = PAGE_SIZE << cpu_alloc_map_order;
@@ -358,7 +363,7 @@ restart:
 	units_free -= units;
 	__count_vm_events(CPU_BYTES, units * UNIT_SIZE);
 
-	spin_unlock(&cpu_alloc_map_lock);
+	spin_unlock_irqrestore(&cpu_alloc_map_lock, flags);
 
 	ptr = cpu_area + start * UNIT_SIZE;
 
@@ -372,7 +377,7 @@ restart:
 	return ptr;
 
 out_of_memory:
-	spin_unlock(&cpu_alloc_map_lock);
+	spin_unlock_irqrestore(&cpu_alloc_map_lock, flags);
 	return NULL;
 }
 EXPORT_SYMBOL(cpu_alloc);
@@ -386,13 +391,14 @@ void cpu_free(void *start, unsigned long
 	int units = size_to_units(size);
 	int index;
 	u8 *p = start;
+	unsigned long flags;
 
 	BUG_ON(p < cpu_area);
 	index = (p - cpu_area) / UNIT_SIZE;
 	BUG_ON(!test_bit(index, cpu_alloc_map) ||
 			index >= units_total);
 
-	spin_lock(&cpu_alloc_map_lock);
+	spin_lock_irqsave(&cpu_alloc_map_lock, flags);
 
 	clear_map(index, units);
 	units_free += units;
@@ -400,6 +406,6 @@ void cpu_free(void *start, unsigned long
 	if (index < first_free)
 		first_free = index;
 
-	spin_unlock(&cpu_alloc_map_lock);
+	spin_unlock_irqrestore(&cpu_alloc_map_lock, flags);
 }
 EXPORT_SYMBOL(cpu_free);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ