public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/3] btrfs: fix wrong start offset for delalloc space release during mmap write
Date: Wed, 14 May 2025 20:08:20 +0930	[thread overview]
Message-ID: <fc07ef6d-fbec-4708-a0ca-10259530298a@suse.com> (raw)
In-Reply-To: <79efbad28a262a6dbe07decd0f49b5a91a167c15.1747217722.git.fdmanana@suse.com>



在 2025/5/14 19:59, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
> 
> If we're doing a mmap write against a folio that has i_size somewhere in
> the middle and we have multiple sectors in the folio, we may have to
> release excess space previously reserved, for the range going from the
> rounded up (to sector size) i_size to the folio's end offset. We are
> calculating the right amount to release and passing it to
> btrfs_delalloc_release_space(), but we are passing the wrong start offset
> of that range - we're passing the folio's start offset instead of the
> end offset, plus 1, of the range for which we keep the reservation. This
> may result in releasing more space then we should and eventually trigger
> an underflow of the data space_info's bytes_may_use counter.
> 
> So fix this by passing the start offset as 'end + 1' instead of
> 'page_start' to btrfs_delalloc_release_space().
> 
> Fixes: d0b7da88f640 ("Btrfs: btrfs_page_mkwrite: Reserve space in sectorsized units")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Just curious how did you spot this, by pure eyeballing or you have some 
tool exposing this?

Thanks,
Qu> ---
>   fs/btrfs/file.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 660a73b6af90..32aad1b02b01 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1918,7 +1918,7 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
>   		if (reserved_space < fsize) {
>   			end = page_start + reserved_space - 1;
>   			btrfs_delalloc_release_space(BTRFS_I(inode),
> -					data_reserved, page_start,
> +					data_reserved, end + 1,
>   					fsize - reserved_space, true);
>   		}
>   	}


  reply	other threads:[~2025-05-14 10:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14 10:29 [PATCH 0/3] btrfs: fix a bug and cleanups in btrfs_page_mkwrite() fdmanana
2025-05-14 10:29 ` [PATCH 1/3] btrfs: fix wrong start offset for delalloc space release during mmap write fdmanana
2025-05-14 10:38   ` Qu Wenruo [this message]
2025-05-14 10:41     ` Filipe Manana
2025-05-14 10:29 ` [PATCH 2/3] btrfs: pass true to btrfs_delalloc_release_space() at btrfs_page_mkwrite() fdmanana
2025-05-14 10:40   ` Qu Wenruo
2025-05-14 10:29 ` [PATCH 3/3] btrfs: simplify early error checking in btrfs_page_mkwrite() fdmanana
2025-05-14 10:50   ` Qu Wenruo
2025-05-14 10:57     ` Filipe Manana
2025-05-14 11:35       ` Filipe Manana
2025-05-14 11:38 ` [PATCH v2 0/5] btrfs: fix a bug and cleanups " fdmanana
2025-05-14 11:38   ` [PATCH v2 1/5] btrfs: fix wrong start offset for delalloc space release during mmap write fdmanana
2025-05-14 11:38   ` [PATCH v2 2/5] btrfs: pass true to btrfs_delalloc_release_space() at btrfs_page_mkwrite() fdmanana
2025-05-14 11:38   ` [PATCH v2 3/5] btrfs: simplify early error checking in btrfs_page_mkwrite() fdmanana
2025-05-14 21:01     ` Qu Wenruo
2025-05-14 11:38   ` [PATCH v2 4/5] btrfs: don't return VM_FAULT_SIGBUS on failure to set delalloc for mmap write fdmanana
2025-05-14 21:01     ` Qu Wenruo
2025-05-14 11:38   ` [PATCH v2 5/5] btrfs: use a single variable to track return value at btrfs_page_mkwrite() fdmanana
2025-05-14 21:02     ` Qu Wenruo
2025-05-15 13:19   ` [PATCH v2 0/5] btrfs: fix a bug and cleanups in btrfs_page_mkwrite() David Sterba

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=fc07ef6d-fbec-4708-a0ca-10259530298a@suse.com \
    --to=wqu@suse.com \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /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