From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: dsterba@suse.cz, Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org, Filipe Manana <fdmanana@suse.com>
Subject: Re: [PATCH v4] btrfs: trim: fix underflow in trim length to prevent access beyond device boundary
Date: Wed, 12 Aug 2020 14:33:33 +0800 [thread overview]
Message-ID: <2fd35a06-ba26-173d-1b72-e41243b78068@gmx.com> (raw)
In-Reply-To: <20200812061016.GT2026@twin.jikos.cz>
On 2020/8/12 下午2:10, David Sterba wrote:
> On Tue, Aug 11, 2020 at 03:42:31PM +0800, Qu Wenruo wrote:
>>>> CHUNK_TRIMMED and CHUNK_ALLOCATED.
>>>>
>>>> Thus what we're doing is to clear all utilized bits.
>>>
>>> Which is true for now, adding a new bit would change that.
>>
>> Yep, that's also why I had the comment here.
>
> The comment is not enough to make the code future proof, as we really
> want do clear all bits in the range beyond device->total_size and that
> works only if we specify them all (clear_state_bit).
>
> Either we can define a bitmask of all the bits next to their definition
> (slightly more error prone if we forget to add that manually), or pass a
> all ones to the clear_extent_bit. Though this is a bit uncommon, with a
> comment I'd prefer this option.
OK, I'd go that (u64)-1 as clear_bits direction, with updated comment.
Thanks,
Qu
>
>>>>> But I still have doubts about just clearing the range, why are there any
>>>>> device->alloc_state entries at all after device is shrunk?
>>>>
>>>> Because the alloc_state is mostly only utilized by trim facility, thus
>>>> existing functions won't bother clearing/setting it.
>>>>
>>>> In this particular case, previous fstrim run would set the CHUNK_TRIMMED
>>>> bit for all unallocated range (except the super reserve).
>>>> Then shrink doesn't clear the exceed range, and cause problem.
>>>
>>> So the unallocated range on a device is also represented in the
>>> alloc_state tree?
>>
>> If the unallocated range has been trimmed, then it has an state, with
>> CHUNK_TRIMMED bit set.
>
> To clarify my previous doubts: I was talking about the slack space (ie.
> space beyond device->total_size up to block device size), 'unallocated'
> is ambiguous and confusing here.
>
> The missing bit about clearing the whole range lies inside
> clear_state_bit that deletes all state tracking once all bits are
> dropped.
>
next prev parent reply other threads:[~2020-08-12 6:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-31 11:29 [PATCH v4] btrfs: trim: fix underflow in trim length to prevent access beyond device boundary Qu Wenruo
2020-07-31 14:08 ` David Sterba
2020-07-31 23:35 ` Qu Wenruo
2020-08-11 7:22 ` David Sterba
2020-08-11 7:42 ` Qu Wenruo
2020-08-12 6:10 ` David Sterba
2020-08-12 6:33 ` Qu Wenruo [this message]
2020-08-12 6:37 ` David Sterba
2020-08-11 8:41 ` Nikolay Borisov
2020-08-11 8:46 ` Qu Wenruo
2020-08-11 10:24 ` Filipe Manana
2020-08-12 6:14 ` David Sterba
2020-08-12 6:43 ` [PATCH v5] " David Sterba
2020-08-12 6:57 ` Qu Wenruo
2020-08-12 11:14 ` Qu Wenruo
2020-08-12 11:24 ` Nikolay Borisov
2020-08-12 11:26 ` Qu Wenruo
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=2fd35a06-ba26-173d-1b72-e41243b78068@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=dsterba@suse.cz \
--cc=fdmanana@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/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