From: Mingming Cao <cmm@us.ibm.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: tytso@mit.edu, sandeen@redhat.com, linux-ext4@vger.kernel.org
Subject: Re: [PATCH] ext4: Fix mb_find_next_bit not to return larger than max
Date: Wed, 09 Jul 2008 17:27:23 -0700 [thread overview]
Message-ID: <1215649643.6978.16.camel@mingming-laptop> (raw)
In-Reply-To: <1215535496-15125-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>
在 2008-07-08二的 22:14 +0530,Aneesh Kumar K.V写道:
> Some architectures implement ext4_find_next_bit and
> ext4_find_next_zero_bit in such a way that they return
> greater than max for some input values. Make sure
> mb_find_next_bit and mb_find_next_zero_bit return the
> right values.
>
I am not quite clear what bad things happen when ext4_find_next_bit()
returns greater than max? Not sure why we need to force it return
within the range..
Just looking at the code it seems all handles properly that if the
return > max, only one is missing is checking in t ext4_find_next_bit
(), (as the lustr e patch does), no?
> On 2.6.25 we have include/asm-x86/bitops_32.h
> static inline unsigned find_first_bit(const unsigned long *addr, unsigned size)
> {
> unsigned x = 0;
>
> while (x < size) {
> unsigned long val = *addr++;
> if (val)
> return __ffs(val) + x;
> x += (sizeof(*addr)<<3);
> }
> return x;
> }
>
> This can return value greater than size.
>
> Reported and fixed here for lustre
>
> https://bugzilla.lustre.org/show_bug.cgi?id=15932
> https://bugzilla.lustre.org/attachment.cgi?id=17205
>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> ---
> fs/ext4/mballoc.c | 20 ++++++++++++--------
> 1 files changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index a1e58fb..d2c61eb 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -381,22 +381,28 @@ static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr)
>
> static inline int mb_find_next_zero_bit(void *addr, int max, int start)
> {
> - int fix = 0;
> + int fix = 0, ret, tmpmax;
> addr = mb_correct_addr_and_bit(&fix, addr);
> - max += fix;
> + tmpmax = max + fix;
> start += fix;
>
> - return ext4_find_next_zero_bit(addr, max, start) - fix;
> + ret = ext4_find_next_zero_bit(addr, tmpmax, start) - fix;
> + if (ret > max)
> + return max;
> + return ret;
> }
>
I missed something basic here, why we need to check ret against the
tmpmax instead of the max after adjust? (Actually not quite sure why we
need to correct the address in the first place).
> static inline int mb_find_next_bit(void *addr, int max, int start)
> {
> - int fix = 0;
> + int fix = 0, ret, tmpmax;
> addr = mb_correct_addr_and_bit(&fix, addr);
> - max += fix;
> + tmpmax = max + fix;
> start += fix;
>
> - return ext4_find_next_bit(addr, max, start) - fix;
> + ret = ext4_find_next_bit(addr, tmpmax, start) - fix;
> + if (ret > max)
> + return max;
> + return ret;
> }
>
> static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max)
> @@ -3633,8 +3639,6 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
> if (bit >= end)
> break;
> next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
> - if (next > end)
> - next = end;
> start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit +
> le32_to_cpu(sbi->s_es->s_first_data_block);
> mb_debug(" free preallocated %u/%u in group %u\n",
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2008-07-10 0:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-08 16:44 [PATCH] ext4: Fix mb_find_next_bit not to return larger than max Aneesh Kumar K.V
2008-07-10 0:27 ` Mingming Cao [this message]
2008-07-10 4:42 ` Aneesh Kumar K.V
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1215649643.6978.16.camel@mingming-laptop \
--to=cmm@us.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=linux-ext4@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox