From: Linus Torvalds <torvalds@linux-foundation.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
Dan Carpenter <dan.carpenter@linaro.org>,
syzbot+48011b86c8ea329af1b9@syzkaller.appspotmail.com,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH] filemap: Handle error return from __filemap_get_folio()
Date: Sat, 6 May 2023 09:35:33 -0700 [thread overview]
Message-ID: <CAHk-=winai-5i6E1oMk7hXPfbP+SCssk5+TOLCJ3koaDrn7Bzg@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=winrN4jsysShx0kWKVzmSMu7Pp3nz_6+aps9CP+v-qHWQ@mail.gmail.com>
On Sat, May 6, 2023 at 9:09 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> Thanks, applied directly.
Actually, I take that back.
I applied it, and then I looked at the context some more, and decided
that I hated it.
It's not that the patch itself was wrong, but the whole original
if (folio)
folio_put(folio);
was wrong in that context, and shouldn't have been done that way.
Converting the conditional to use !IS_ERR() fixes a conversion error,
but doesn't fix the original problem with the code.
The only path that triggered that "we have no folio" was wrong to jump
to that "should I drop this folio" code sequence in the first place.
So the fix is to not use "out_retry" at all for the IS_ERR(folio) case.
Yes, yes, compilers can do jump threading, and in a perfect world
might realize that there are two consecutive tests for IS_ERR(folio)
and just do this kind of conversion automatically.
But the fact that compilers *might* fix out our code to do the right
thing doesn't mean that the code shouldn't have been written to just
have the proper error handling nesting in the first place.
And yes, the simplest fix for the "wrong test" would be to just add a
new "out_nofolio" error case after "out_retry", and use that.
However, even that seems wrong, because the return value for that path
is the wrong one.
So the "goto out_retry" was actually *doubly* wrong.
If the __filemap_get_folio(FGP_CREAT) failed, then we should not
return VM_FAULT_RETRY at all. We should return VM_FAULT_OOM, like it
does for the no-fpin case.
So the whole
if (IS_ERR(folio)) {
if (fpin)
goto out_retry;
sequence seems to be completely wrong in several ways. It shouldn't go
to "out_retry" at all, because this is simply not a "retry" case.
And that in turn means that "out_retry" shouldn't be testing folio at
all (whether for IS_ERR() _or_ for NULL).
So i really think the proper fix is this (whitespace-damaged) patch instead:
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3291,7 +3291,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
vmf->gfp_mask);
if (IS_ERR(folio)) {
- if (fpin)
- goto out_retry;
filemap_invalidate_unlock_shared(mapping);
+ if (fpin)
+ fput(fpin);
return VM_FAULT_OOM;
}
@@ -3379,6 +3379,5 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
* page.
*/
- if (folio)
- folio_put(folio);
+ folio_put(folio);
if (mapping_locked)
filemap_invalidate_unlock_shared(mapping);
which fixes both problems by simply avoiding a bogus 'goto' entirely.
Hmm?
Linus
next prev parent reply other threads:[~2023-05-06 16:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-06 16:04 Matthew Wilcox (Oracle)
2023-05-06 16:09 ` Linus Torvalds
2023-05-06 16:35 ` Linus Torvalds [this message]
2023-05-06 17:04 ` Linus Torvalds
2023-05-06 17:10 ` Linus Torvalds
2023-05-06 17:34 ` Linus Torvalds
2023-05-06 17:41 ` Andrew Morton
2023-05-08 13:56 ` Dan Carpenter
2023-05-09 7:43 ` Dan Carpenter
2023-05-09 17:37 ` Linus Torvalds
2023-05-09 20:49 ` Christoph Hellwig
2023-05-11 9:44 ` Dan Carpenter
2023-05-09 19:19 ` Johannes Weiner
2023-05-10 20:27 ` Peter Xu
2023-05-10 21:33 ` Linus Torvalds
2023-05-10 21:44 ` Linus Torvalds
2023-05-11 4:45 ` Peter Xu
2023-05-12 0:14 ` Peter Xu
2023-05-12 3:28 ` [PATCH 1/3] mm: handle_mm_fault_one() kernel test robot
2023-05-12 3:52 ` kernel test robot
2023-05-12 3:52 ` kernel test robot
2023-05-12 4:49 ` kernel test robot
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='CAHk-=winai-5i6E1oMk7hXPfbP+SCssk5+TOLCJ3koaDrn7Bzg@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@linaro.org \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=syzbot+48011b86c8ea329af1b9@syzkaller.appspotmail.com \
--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