linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-fsdevel@vger.kernel.org,
	fuse-devel <fuse-devel@lists.sourceforge.net>,
	linux-mm <linux-mm@kvack.org>, miklos <mszeredi@redhat.com>,
	"Gabriel Krisman Bertazi" <krisman@collabora.com>,
	"André Almeida" <andrealmeid@collabora.com>
Subject: Re: [fuse-devel] fuse: trying to steal weird page
Date: Mon, 18 May 2020 08:26:01 -0700	[thread overview]
Message-ID: <20200518152601.GU16070@bombadil.infradead.org> (raw)
In-Reply-To: <CAJfpegtKQ85K2iJUvm-A+cTD1TKsa1AVTDnwbeky4hyf+SJfgQ@mail.gmail.com>

On Mon, May 18, 2020 at 04:58:05PM +0200, Miklos Szeredi wrote:
> On Mon, May 18, 2020 at 4:48 PM Matthew Wilcox <willy@infradead.org> wrote:
> >
> > On Mon, May 18, 2020 at 02:45:02PM +0200, Miklos Szeredi wrote:
> 
> > > page_cache_pipe_buf_steal() calls remove_mapping() which calls
> > > page_ref_unfreeze(page, 1).  That sets the refcount to 1, right?
> > >
> > > What am I missing?
> >
> > find_get_entry() calling page_cache_get_speculative().
> >
> > In a previous allocation, this page belonged to the page cache.  Then it
> > was freed, but another thread is in the middle of a page cache lookup and
> > has already loaded the pointer.  It is now delayed by a few clock ticks.
> >
> > Now the page is allocated to FUSE, which calls page_ref_unfreeze().
> > And then the refcount gets bumped to 2 by page_cache_get_speculative().
> > find_get_entry() calls xas_reload() and discovers this page is no longer
> > at that index, so it calls put_page(), but in that narrow window, FUSE
> > checks the refcount and finds it's not 1.
> 
> What if that page_cache_get_speculative() happens just before
> page_ref_unfreeze()?  The speculative reference would be lost and on
> put_page() the page would be freed, even though fuse is still holding
> the pointer.

static inline void page_ref_unfreeze(struct page *page, int count)
{
        VM_BUG_ON_PAGE(page_count(page) != 0, page);
        VM_BUG_ON(count == 0);

        atomic_set_release(&page->_refcount, count);

static inline int __page_cache_add_speculative(struct page *page, int count)
{
        if (unlikely(!page_ref_add_unless(page, count, 0))) {
                return 0;



  reply	other threads:[~2020-05-18 15:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-02 19:09 fuse: trying to steal weird page Nikolaus Rath
2020-05-02 19:52 ` Nikolaus Rath
2020-05-03  3:26   ` Matthew Wilcox
2020-05-03  8:43     ` [fuse-devel] " Nikolaus Rath
2020-05-03 10:27       ` Matthew Wilcox
2020-05-03 18:28         ` Gabriel Krisman Bertazi
2020-05-03 20:06           ` Matthew Wilcox
2020-05-03 20:25           ` Nikolaus Rath
2020-05-06 13:57             ` Vlastimil Babka
2020-05-03 21:34         ` Hugh Dickins
2020-05-18 12:45         ` Miklos Szeredi
2020-05-18 14:48           ` Matthew Wilcox
2020-05-18 14:58             ` Miklos Szeredi
2020-05-18 15:26               ` Matthew Wilcox [this message]
     [not found] <87o998m0a7.fsf@vostro.rath.org>
     [not found] ` <CAJfpegtQic0v+9G7ODXEzgUPAGOz+3Ay28uxqbafZGMJdqL-zQ@mail.gmail.com>
     [not found]   ` <87ef9omb5f.fsf@vostro.rath.org>
     [not found]     ` <CAJfpegu_qxcaQToDpSmcW_ncLb_mBX6f75RTEn6zbsihqcg=Rw@mail.gmail.com>
     [not found]       ` <87ef9nighv.fsf@thinkpad.rath.org>
     [not found]         ` <CAJfpegtiXDgSBWN8MRubpAdJFxy95X21nO_yycCZhpvKLVePRA@mail.gmail.com>
     [not found]           ` <87zhs7fbkg.fsf@thinkpad.rath.org>
     [not found]             ` <8736ovcn9q.fsf@vostro.rath.org>
     [not found]               ` <CAJfpegvjntcpwDYf3z_3Z1D5Aq=isB3ByP3_QSoG6zx-sxB84w@mail.gmail.com>
     [not found]                 ` <877ee4vgr4.fsf@vostro.rath.org>
     [not found]                   ` <878sy3h7gr.fsf@vostro.rath.org>
     [not found]                     ` <CAJfpeguCJnGrzCtHREq9d5uV-=g9JBmrX_c===giZB7FxWCcgw@mail.gmail.com>
     [not found]                       ` <CAJfpegu-QU-A0HORYjcrx3fM5FKGUop0x6k10A526ZV=p0CEuw@mail.gmail.com>
2019-02-26 20:35                         ` Nikolaus Rath
2019-02-26 20:56                           ` Miklos Szeredi
2019-03-01 20:40                             ` Nikolaus Rath
2019-03-18 11:27                               ` Miklos Szeredi

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=20200518152601.GU16070@bombadil.infradead.org \
    --to=willy@infradead.org \
    --cc=andrealmeid@collabora.com \
    --cc=fuse-devel@lists.sourceforge.net \
    --cc=krisman@collabora.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=miklos@szeredi.hu \
    --cc=mszeredi@redhat.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).