Skip to contentSkip to conversation

sparc/srmmu: clear trailing edge of bitmap properly

PATCH Applied Akinobu Mita 3 participants 3 messages Mar 29, 2013 – Mar 31, 2013 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc/srmmu: clear trailing edge of bitmap properly

srmmu_nocache_bitmap is cleared by bit_map_init(). But bit_map_init() attempts to clear by memset(), so it can't clear the trailing edge of bitmap properly on big-endian architecture if the number of bits is not a multiple of BITS_PER_LONG.

Actually, the number of bits in srmmu_nocache_bitmap is not always a multiple of BITS_PER_LONG. It is calculated as below:

        bitmap_bits = srmmu_nocache_size >> SRMMU_NOCACHE_BITMAP_SHIFT;

srmmu_nocache_size is decided proportionally by the amount of system RAM and it is rounded to a multiple of PAGE_SIZE. SRMMU_NOCACHE_BITMAP_SHIFT is defined as (PAGE_SHIFT - 4). So it can only be said that bitmap_bits is a multiple of 16.

This fixes the problem by using bitmap_clear() instead of memset() in bit_map_init() and this also uses BITS_TO_LONGS() to calculate correct size at bitmap allocation time.

---

This patch is a combination of the patches I sent:
"sparc: clear bitmap correctly in bit_map_init()" and "sparc/srmmu: use BITS_TO_LONGS() to calculate bitmap size", but the patch description is rewritten.

 arch/sparc/lib/bitext.c | 6 +-----
 arch/sparc/mm/srmmu.c   | 4 +++-
 2 files changed, 4 insertions(+), 6 deletions(-)
arch/sparc/lib/bitext.c +1 -5
index d516fda..04d8bad 100644
@@ -111,11 +111,7 @@ void bit_map_clear(struct bit_map *t, int offset, int len)
 
 void bit_map_init(struct bit_map *t, unsigned long *map, int size)
 {
-
-	if ((size & 07) != 0)
-		BUG();
-	memset(map, 0, size>>3);
-
+	bitmap_zero(map, size);
 	memset(t, 0, sizeof *t);
 	spin_lock_init(&t->lock);
 	t->map = map;
arch/sparc/mm/srmmu.c +2 -1
index c38bb72..036c279 100644
@@ -280,7 +280,9 @@ static void __init srmmu_nocache_init(void)
 		SRMMU_NOCACHE_ALIGN_MAX, 0UL);
 	memset(srmmu_nocache_pool, 0, srmmu_nocache_size);
 
-	srmmu_nocache_bitmap = __alloc_bootmem(bitmap_bits >> 3, SMP_CACHE_BYTES, 0UL);
+	srmmu_nocache_bitmap +		__alloc_bootmem(BITS_TO_LONGS(bitmap_bits) * sizeof(long),
+				SMP_CACHE_BYTES, 0UL);
 	bit_map_init(&srmmu_nocache_map, srmmu_nocache_bitmap, bitmap_bits);
 
 	srmmu_swapper_pg_dir = __srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 40 lines · Akinobu Mita

srmmu_nocache_bitmap is cleared by bit_map_init(). But bit_map_init() attempts to clear by memset(), so it can't clear the trailing edge of bitmap properly on big-endian architecture if the number of bits is not a multiple of BITS_PER_LONG.

Actually, the number of bits in srmmu_nocache_bitmap is not always a multiple of BITS_PER_LONG. It is calculated as below:

        bitmap_bits = srmmu_nocache_size >> SRMMU_NOCACHE_BITMAP_SHIFT;

srmmu_nocache_size is decided proportionally by the amount of system RAM and it is rounded to a multiple of PAGE_SIZE. SRMMU_NOCACHE_BITMAP_SHIFT is defined as (PAGE_SHIFT - 4). So it can only be said that bitmap_bits is a multiple of 16.

This fixes the problem by using bitmap_clear() instead of memset() in bit_map_init() and this also uses BITS_TO_LONGS() to calculate correct size at bitmap allocation time.

---

This patch is a combination of the patches I sent:
"sparc: clear bitmap correctly in bit_map_init()" and "sparc/srmmu: use BITS_TO_LONGS() to calculate bitmap size", but the patch description is rewritten.

 arch/sparc/lib/bitext.c | 6 +-----
 arch/sparc/mm/srmmu.c   | 4 +++-
 2 files changed, 4 insertions(+), 6 deletions(-)
arch/sparc/lib/bitext.c +0 -0
index d516fda..04d8bad 100644
@@ -111,11 +111,7 @@ void bit_map_clear(struct bit_map *t, int offset, int len)
 
 void bit_map_init(struct bit_map *t, unsigned long *map, int size)

arch/sparc/lib/bitext.c void bit_map_clear(struct bit_map *t, int offset, int len) · line 117

Quoted 10 lines
arch/sparc/lib/bitext.c +1 -5
 {
-
-	if ((size & 07) != 0)
-		BUG();
-	memset(map, 0, size>>3);
-
+	bitmap_zero(map, size);
 	memset(t, 0, sizeof *t);
 	spin_lock_init(&t->lock);
 	t->map = map;

This mixes sparc internal bit_map functions with lib/bitmap functions. Please do not do this.

arch/sparc/mm/srmmu.c static void __init srmmu_nocache_init(void) · line 284

Quoted 11 lines
arch/sparc/mm/srmmu.c +2 -1
index c38bb72..036c279 100644
@@ -280,7 +280,9 @@ static void __init srmmu_nocache_init(void)
 		SRMMU_NOCACHE_ALIGN_MAX, 0UL);
 	memset(srmmu_nocache_pool, 0, srmmu_nocache_size);
 
-	srmmu_nocache_bitmap = __alloc_bootmem(bitmap_bits >> 3, SMP_CACHE_BYTES, 0UL);
+	srmmu_nocache_bitmap > +		__alloc_bootmem(BITS_TO_LONGS(bitmap_bits) * sizeof(long),
+				SMP_CACHE_BYTES, 0UL);

Anything that touches the sparc32 nocache stuff should improve read-ability or fix real bugs. This does neither - so I prefer to leave it as is.

Sam

maintainer Applied
#2 lore raw
In reply to Akinobu Mita

From: Akinobu Mita <[email protected]>
Date: Fri, 29 Mar 2013 22:44:43 +0900

Quoted 15 lines

srmmu_nocache_bitmap is cleared by bit_map_init(). But bit_map_init() attempts to clear by memset(), so it can't clear the trailing edge of bitmap properly on big-endian architecture if the number of bits is not a multiple of BITS_PER_LONG.

Actually, the number of bits in srmmu_nocache_bitmap is not always a multiple of BITS_PER_LONG. It is calculated as below:

        bitmap_bits = srmmu_nocache_size >> SRMMU_NOCACHE_BITMAP_SHIFT;

srmmu_nocache_size is decided proportionally by the amount of system RAM and it is rounded to a multiple of PAGE_SIZE. SRMMU_NOCACHE_BITMAP_SHIFT is defined as (PAGE_SHIFT - 4). So it can only be said that bitmap_bits is a multiple of 16.

Quoted 5 lines

This fixes the problem by using bitmap_clear() instead of memset() in bit_map_init() and this also uses BITS_TO_LONGS() to calculate correct size at bitmap allocation time.

Applied.