1 ext4: ext4_find_next_zero_bit needs an aligned address on some arch
3 From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
5 ext4_find_next_zero_bit and ext4_find_next_bit needs a long aligned
6 address on x8_64. Add mb_find_next_zero_bit and mb_find_next_bit
7 and use them in the mballoc.
9 Fix: https://bugzilla.redhat.com/show_bug.cgi?id=433286
11 Eric Sandeen debugged the problem and suggested the fix.
13 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
14 Acked-by: Eric Sandeen <sandeen@redhat.com>
15 Signed-off-by: Mingming Cao <cmm@us.ibm.com>
16 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
18 fs/ext4/mballoc.c | 62 ++++++++++++++++++++++++++++++++++--------------------
19 1 file changed, 40 insertions(+), 22 deletions(-)
21 Index: linux-2.6.25-rc2/fs/ext4/mballoc.c
22 ===================================================================
23 --- linux-2.6.25-rc2.orig/fs/ext4/mballoc.c 2008-02-20 08:18:30.000000000 -0800
24 +++ linux-2.6.25-rc2/fs/ext4/mballoc.c 2008-02-20 08:20:30.000000000 -0800
25 @@ -627,21 +627,19 @@ static ext4_fsblk_t ext4_grp_offs_to_blo
29 +static inline void *mb_correct_addr_and_bit(int *bit, void *addr)
31 #if BITS_PER_LONG == 64
32 -#define mb_correct_addr_and_bit(bit, addr) \
34 - bit += ((unsigned long) addr & 7UL) << 3; \
35 - addr = (void *) ((unsigned long) addr & ~7UL); \
37 + *bit += ((unsigned long) addr & 7UL) << 3;
38 + addr = (void *) ((unsigned long) addr & ~7UL);
39 #elif BITS_PER_LONG == 32
40 -#define mb_correct_addr_and_bit(bit, addr) \
42 - bit += ((unsigned long) addr & 3UL) << 3; \
43 - addr = (void *) ((unsigned long) addr & ~3UL); \
45 + *bit += ((unsigned long) addr & 3UL) << 3;
46 + addr = (void *) ((unsigned long) addr & ~3UL);
48 #error "how many bits you are?!"
53 static inline int mb_test_bit(int bit, void *addr)
55 @@ -649,34 +647,54 @@ static inline int mb_test_bit(int bit, v
56 * ext4_test_bit on architecture like powerpc
57 * needs unsigned long aligned address
59 - mb_correct_addr_and_bit(bit, addr);
60 + addr = mb_correct_addr_and_bit(&bit, addr);
61 return ext4_test_bit(bit, addr);
64 static inline void mb_set_bit(int bit, void *addr)
66 - mb_correct_addr_and_bit(bit, addr);
67 + addr = mb_correct_addr_and_bit(&bit, addr);
68 ext4_set_bit(bit, addr);
71 static inline void mb_set_bit_atomic(spinlock_t *lock, int bit, void *addr)
73 - mb_correct_addr_and_bit(bit, addr);
74 + addr = mb_correct_addr_and_bit(&bit, addr);
75 ext4_set_bit_atomic(lock, bit, addr);
78 static inline void mb_clear_bit(int bit, void *addr)
80 - mb_correct_addr_and_bit(bit, addr);
81 + addr = mb_correct_addr_and_bit(&bit, addr);
82 ext4_clear_bit(bit, addr);
85 static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr)
87 - mb_correct_addr_and_bit(bit, addr);
88 + addr = mb_correct_addr_and_bit(&bit, addr);
89 ext4_clear_bit_atomic(lock, bit, addr);
92 +static inline int mb_find_next_zero_bit(void *addr, int max, int start)
95 + addr = mb_correct_addr_and_bit(&fix, addr);
99 + return ext4_find_next_zero_bit(addr, max, start) - fix;
102 +static inline int mb_find_next_bit(void *addr, int max, int start)
105 + addr = mb_correct_addr_and_bit(&fix, addr);
109 + return ext4_find_next_bit(addr, max, start) - fix;
112 static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max)
115 @@ -946,12 +964,12 @@ static void ext4_mb_generate_buddy(struc
117 /* initialize buddy from bitmap which is aggregation
118 * of on-disk bitmap and preallocations */
119 - i = ext4_find_next_zero_bit(bitmap, max, 0);
120 + i = mb_find_next_zero_bit(bitmap, max, 0);
121 grp->bb_first_free = i;
125 - i = ext4_find_next_bit(bitmap, max, i);
126 + i = mb_find_next_bit(bitmap, max, i);
130 @@ -959,7 +977,7 @@ static void ext4_mb_generate_buddy(struc
132 grp->bb_counters[0]++;
134 - i = ext4_find_next_zero_bit(bitmap, max, i);
135 + i = mb_find_next_zero_bit(bitmap, max, i);
137 grp->bb_fragments = fragments;
139 @@ -1782,7 +1800,7 @@ static void ext4_mb_simple_scan_group(st
140 buddy = mb_find_buddy(e4b, i, &max);
141 BUG_ON(buddy == NULL);
143 - k = ext4_find_next_zero_bit(buddy, max, 0);
144 + k = mb_find_next_zero_bit(buddy, max, 0);
148 @@ -1822,7 +1840,7 @@ static void ext4_mb_complex_scan_group(s
149 i = e4b->bd_info->bb_first_free;
151 while (free && ac->ac_status == AC_STATUS_CONTINUE) {
152 - i = ext4_find_next_zero_bit(bitmap,
153 + i = mb_find_next_zero_bit(bitmap,
154 EXT4_BLOCKS_PER_GROUP(sb), i);
155 if (i >= EXT4_BLOCKS_PER_GROUP(sb)) {
157 @@ -3750,10 +3768,10 @@ static int ext4_mb_release_inode_pa(stru
161 - bit = ext4_find_next_zero_bit(bitmap_bh->b_data, end, bit);
162 + bit = mb_find_next_zero_bit(bitmap_bh->b_data, end, bit);
165 - next = ext4_find_next_bit(bitmap_bh->b_data, end, bit);
166 + next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
169 start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit +