All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mike Snitzer" <snitzer@kernel.org>,
	"Matthew Wilcox" <willy@infradead.org>, "Jan Kara" <jack@suse.cz>,
	linux-mm@kvack.org, "Christian Brauner" <brauner@kernel.org>
Cc: "Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Anna Schumaker" <anna@kernel.org>
Subject: Re: [PATCH v12 2/7] mm: take a folio off WB_DONTCACHE_DIRTY only if it was counted there
Date: Fri, 13 Nov 2026 19:09:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-213508@kernel.org> (raw)
In-Reply-To: <20261112190911.84702-3-snitzer@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm: unsigned negation in filemap_clear_dropbehind() corrupts
  counter on 32-bit
--

commit 08b68ff1ed201d0ae5bce5df36b625f50a1bfa1f
Author: Mike Snitzer <snitzer@kernel.org>

mm: take a folio off WB_DONTCACHE_DIRTY only if it was counted there

This commit updates filemap_clear_dropbehind() to hold the folio lock and
i_pages lock before clearing the dropbehind flag and decrementing
WB_DONTCACHE_DIRTY when both PG_dirty and PAGECACHE_TAG_DIRTY are set.

> diff --git a/mm/filemap.c b/mm/filemap.c
> index 437113addbddf..98ce955404127 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1956,22 +1956,36 @@ void *filemap_get_entry(struct address_space *mapping, pgoff_t index)
>  	return folio;
>  }
>  
> -/* Clear the dropbehind flag of a folio that a cached lookup found. */
> +/*
> + * Clear the dropbehind flag of a folio that a cached lookup found, and take
> + * the folio off WB_DONTCACHE_DIRTY if it is counted there.  With the folio
> + * locked and the i_pages lock held, the folio is counted if both PG_dirty and
> + * the dirty tag are set.  A folio that another task has locked keeps the flag.
> + */
>  static void filemap_clear_dropbehind(struct address_space *mapping,
> -				     struct folio *folio)
> +				     struct folio *folio, bool locked)
>  {
> -	if (!folio_test_clear_dropbehind(folio))
> -		return;
> -	if (folio_test_dirty(folio) && mapping_can_writeback(mapping)) {
> -		struct inode *inode = mapping->host;
> -		struct bdi_writeback *wb;
> -		struct wb_lock_cookie cookie = {};
> -		long nr = folio_nr_pages(folio);
> +	unsigned long flags;
>  
> -		wb = unlocked_inode_to_wb_begin(inode, &cookie);
> -		wb_stat_mod(wb, WB_DONTCACHE_DIRTY, -nr);
> -		unlocked_inode_to_wb_end(inode, &cookie);
> +	if (!locked) {
> +		if (!folio_trylock(folio))
> +			return;
> +		if (unlikely(folio->mapping != mapping))
> +			goto out;
> +	}
> +	if (!mapping_can_writeback(mapping)) {
> +		folio_clear_dropbehind(folio);
> +		goto out;
>  	}
> +	xa_lock_irqsave(&mapping->i_pages, flags);
> +	if (folio_test_clear_dropbehind(folio) && folio_test_dirty(folio) &&
> +	    xa_get_mark(&mapping->i_pages, folio->index, PAGECACHE_TAG_DIRTY))
> +		wb_stat_mod(inode_to_wb(mapping->host), WB_DONTCACHE_DIRTY,
> +			    -folio_nr_pages(folio));

[Severity: Medium]
Does passing -folio_nr_pages(folio) to wb_stat_mod() corrupt the
WB_DONTCACHE_DIRTY counter on 32-bit architectures?

folio_nr_pages() returns unsigned long, whereas wb_stat_mod() takes s64.
On 32-bit platforms, negating a 32-bit unsigned long produces 2^32 - nr,
which is then zero-extended to s64, adding a large positive value instead
of subtracting nr pages.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261112190911.84702-1-snitzer@kernel.org?part=2


  reply	other threads:[~2026-11-13 19:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 19:09 [PATCH v12 0/7] mm, iomap, NFSD: stop DONTCACHE writes reading back shared pages Mike Snitzer
2026-11-12 19:09 ` [PATCH v12 1/7] mm: move clearing the dropbehind flag of a found folio into a helper Mike Snitzer
2026-11-12 19:09 ` [PATCH v12 2/7] mm: take a folio off WB_DONTCACHE_DIRTY only if it was counted there Mike Snitzer
2026-11-13 19:09   ` sashiko-bot [this message]
2026-11-12 19:09 ` [PATCH v12 3/7] mm: expose WB_DONTCACHE_DIRTY in bdi debugfs stats Mike Snitzer
2026-11-12 19:09 ` [PATCH v12 4/7] mm: add folio_mark_dropbehind() to mark a folio dropbehind and account it Mike Snitzer
2026-11-12 19:09 ` [PATCH v12 5/7] mm, iomap: keep a partially covered page until a DONTCACHE write completes it Mike Snitzer
2026-11-12 19:09 ` [PATCH v12 6/7] mm, iomap: let a DONTCACHE writer complete its shared pages itself Mike Snitzer
2026-11-12 19:09 ` [PATCH v12 7/7] NFSD: drop a shared boundary page only once both WRITEs have written it Mike Snitzer

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=sashiko-outbox-213508@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=anna@kernel.org \
    --cc=brauner@kernel.org \
    --cc=cel@kernel.org \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=snitzer@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.