linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org, Hugh Dickins <hughd@google.com>,
	 Baolin Wang <baolin.wang@linux.alibaba.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH 10/10] mm: Use folio_next_pos()
Date: Tue, 11 Nov 2025 10:59:46 +0100	[thread overview]
Message-ID: <20251111-droht-oasen-449486f7248f@brauner> (raw)
In-Reply-To: <aQ7ObHvd8FXb8Taz@casper.infradead.org>

On Sat, Nov 08, 2025 at 05:00:28AM +0000, Matthew Wilcox wrote:
> On Fri, Oct 24, 2025 at 06:08:18PM +0100, Matthew Wilcox (Oracle) wrote:
> > +++ b/mm/truncate.c
> > @@ -387,7 +387,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
> >  	same_folio = (lstart >> PAGE_SHIFT) == (lend >> PAGE_SHIFT);
> >  	folio = __filemap_get_folio(mapping, lstart >> PAGE_SHIFT, FGP_LOCK, 0);
> >  	if (!IS_ERR(folio)) {
> > -		same_folio = lend < folio_pos(folio) + folio_size(folio);
> > +		same_folio = lend < folio_next_pos(folio);
> 
> This causes an intermittent failure with XFS.  Two reports here:
> https://lore.kernel.org/linux-xfs/aQohjfEFmU8lef6M@casper.infradead.org/
> 
> This is a fun one.  The "fix" I'm running with right now is:
> 
> -               same_folio = lend < folio_next_pos(folio);
> +               same_folio = lend < (u64)folio_next_pos(folio);
> 
> folio_pos() and folio_next_pos() return an loff_t.  folio_size() returns
> a size_t.  So folio_pos() + folio_size() is unsigned (by the usual C
> promotion rules).  Before this patch, this was an unsigned comparison
> against lend, and with the patch it's now a signed comparison.  Since
> lend can be -1 (to mean 'end of file'), same_folio will now be 'true'
> when it used to be 'false'.
> 
> Funnily, on 32-bit systems, size_t is u32 and loff_t is s64, so their
> addition is also s64.  That means this has been wrong on 32-bit systems
> for ... a while.  And nobody noticed, so I guess nobody's testing 32-bit
> all that hard.

death by slow degradation...

> Anyway, what's the *right* way to fix this?  Cast to (unsigned long

Naively, I would think it should be an unsigned comparison for u64.

> long)?  There's an ssize_t, but I really want the opposite, a uloff_t.

Fwiw, I don't think anything is stopping us from defining uloff_t in the
kernel if it's helpful.

> (now i'm going to go back through all the other patches in this series
> and see if I've made the same mistake anywhere else)


      reply	other threads:[~2025-11-11  9:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251024170822.1427218-1-willy@infradead.org>
2025-10-24 17:08 ` [PATCH 10/10] mm: Use folio_next_pos() Matthew Wilcox (Oracle)
2025-10-27  7:54   ` Christoph Hellwig
2025-10-27 15:43   ` David Hildenbrand
2025-11-08  5:00   ` Matthew Wilcox
2025-11-11  9:59     ` Christian Brauner [this message]

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=20251111-droht-oasen-449486f7248f@brauner \
    --to=brauner@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=hughd@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).