linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "Vishal Moola (Oracle)" <vishal.moola@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org,
	Hugh Dickins <hughd@google.com>, Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH 3/5] userfualtfd: Replace lru_cache functions with folio_add functions
Date: Tue, 1 Nov 2022 18:31:26 +0000	[thread overview]
Message-ID: <Y2Fl/pZyLSw/ddZY@casper.infradead.org> (raw)
In-Reply-To: <20221101175326.13265-4-vishal.moola@gmail.com>

On Tue, Nov 01, 2022 at 10:53:24AM -0700, Vishal Moola (Oracle) wrote:
> Replaces lru_cache_add() and lru_cache_add_inactive_or_unevictable()
> with folio_add_lru() and folio_add_lru_vma(). This is in preparation for
> the removal of lru_cache_add().

Ummmmm.  Reviewing this patch reveals a bug (not introduced by your
patch).  Look:

mfill_atomic_install_pte:
        bool page_in_cache = page->mapping;

mcontinue_atomic_pte:
        ret = shmem_get_folio(inode, pgoff, &folio, SGP_NOALLOC);
...
        page = folio_file_page(folio, pgoff);
        ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr,
                                       page, false, wp_copy);

That says pretty plainly that mfill_atomic_install_pte() can be passed
a tail page from shmem, and if it is ...

        if (page_in_cache) {
...
        } else {
                page_add_new_anon_rmap(page, dst_vma, dst_addr);
                lru_cache_add_inactive_or_unevictable(page, dst_vma);
        }

it'll get put on the rmap as an anon page!

> Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
> ---
>  mm/userfaultfd.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index e24e8a47ce8a..2560973b00d8 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -66,6 +66,7 @@ int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd,
>  	bool vm_shared = dst_vma->vm_flags & VM_SHARED;
>  	bool page_in_cache = page->mapping;
>  	spinlock_t *ptl;
> +	struct folio *folio;
>  	struct inode *inode;
>  	pgoff_t offset, max_off;
>  
> @@ -113,14 +114,15 @@ int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd,
>  	if (!pte_none_mostly(*dst_pte))
>  		goto out_unlock;
>  
> +	folio = page_folio(page);
>  	if (page_in_cache) {
>  		/* Usually, cache pages are already added to LRU */
>  		if (newly_allocated)
> -			lru_cache_add(page);
> +			folio_add_lru(folio);
>  		page_add_file_rmap(page, dst_vma, false);
>  	} else {
>  		page_add_new_anon_rmap(page, dst_vma, dst_addr);
> -		lru_cache_add_inactive_or_unevictable(page, dst_vma);
> +		folio_add_lru_vma(folio, dst_vma);
>  	}
>  
>  	/*
> -- 
> 2.38.1
> 
> 


  reply	other threads:[~2022-11-01 18:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01 17:53 [PATCH 0/5] Removing the lru_cache_add() wrapper Vishal Moola (Oracle)
2022-11-01 17:53 ` [PATCH 1/5] filemap: Convert replace_page_cache_page() to replace_page_cache_folio() Vishal Moola (Oracle)
2022-11-01 18:20   ` Matthew Wilcox
2022-11-01 17:53 ` [PATCH 2/5] fuse: Convert fuse_try_move_page() to use folios Vishal Moola (Oracle)
2022-11-01 18:24   ` Matthew Wilcox
2022-11-10 18:36     ` Vishal Moola
2022-11-14 13:25       ` Miklos Szeredi
2022-11-01 17:53 ` [PATCH 3/5] userfualtfd: Replace lru_cache functions with folio_add functions Vishal Moola (Oracle)
2022-11-01 18:31   ` Matthew Wilcox [this message]
2022-11-02 19:02     ` Peter Xu
2022-11-02 19:21       ` Matthew Wilcox
2022-11-02 20:44         ` Peter Xu
2022-11-03 17:34           ` Axel Rasmussen
2022-11-03 17:56             ` Peter Xu
2022-11-02 20:47       ` Andrew Morton
2022-11-01 17:53 ` [PATCH 4/5] khugepage: Replace lru_cache_add() with folio_add_lru() Vishal Moola (Oracle)
2022-11-01 18:32   ` Matthew Wilcox
2022-11-01 17:53 ` [PATCH 5/5] folio-compat: Remove lru_cache_add() Vishal Moola (Oracle)
2022-11-01 18:33   ` Matthew Wilcox
2022-11-29 19:25 ` [PATCH 0/5] Removing the lru_cache_add() wrapper Vishal Moola

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=Y2Fl/pZyLSw/ddZY@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=vishal.moola@gmail.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;
as well as URLs for NNTP newsgroup(s).