linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Axel Rasmussen <axelrasmussen@google.com>
Cc: Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Dan Carpenter <dan.carpenter@linaro.org>,
	Peter Xu <peterx@redhat.com>,
	 linux-mm@kvack.org
Subject: Re: [PATCH mm-unstable fix] mm: userfaultfd: add new UFFDIO_POISON ioctl: fix
Date: Thu, 13 Jul 2023 19:40:30 -0700 (PDT)	[thread overview]
Message-ID: <517aeee1-b4cd-c3fc-3236-e2a33c115af5@google.com> (raw)
In-Reply-To: <CAJHvVchEJokKZxYaiW8m3O_waW2NnuSmtx+dP8O9NStt3U0_hQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2635 bytes --]

On Wed, 12 Jul 2023, Axel Rasmussen wrote:
> On Tue, Jul 11, 2023 at 6:27 PM Hugh Dickins <hughd@google.com> wrote:
> >
> > Smatch has observed that pte_offset_map_lock() is now allowed to fail,
> > and then ptl should not be unlocked.  Use -EAGAIN here like elsewhere.
> >
> > Signed-off-by: Hugh Dickins <hughd@google.com>
> 
> Looks correct to me, thanks Hugh! If it's useful, feel free to take:
> 
> Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>

Thanks, that will have helped Andrew (but would vanish into the merge
with your original when it moves from mm-unstable to mm-stable).

> 
> > ---
> > Axel, Peter: this seems right as a fix to the patch in mm-unstable;
> > but in preparing this, I noticed mfill_atomic()'s code before calling
> > mfill_atomic_pte(), and think that my original choice of -EFAULT was
> > therefore better than -EAGAIN for all of these; and that mfill_atomic()'s
> > BUG_ONs there would be better deleted (and is its BUG_ON(folio) safe??).
> > Something one of us should address, after this fixup is in akpm's tree.
> 
> Agreed, dealing with the BUG_ONs is something I have been meaning to
> do as checkpatch bothers me about it frequently.
> 
> What this code is trying to do is to enforce the contract that: if
> mfill_atomic_pte failed, then it must have released *folio and set it
> to NULL. But, you're exactly right that if we had such a bug, it would
> mean we leaked one page in an unusual error case - not great, but not
> worth crashing the kernel either.
> 
> For UFFDIO_POISON this doesn't really apply because it doesn't
> allocate or get a reference to a page in any case.
> 
> For other cases like UFFDIO_COPY where it does matter, I think it's
> fine as is regardless of the error code returned (as long as it's not
> -ENOENT :) ). mfill_atomic_pte_copy() is sure to set `*foliop = NULL`
> before it attempts this lock (in mfill_atomic_install_pte). So -EAGAIN
> or -EFAULT should work equally well at least from that perspective. I
> somewhat prefer -EAGAIN, but maybe I'm missing something.

Right, when I said -EFAULT better than -EAGAIN, I was only basing that
on -EFAULT being the code which was already used for pmd_trans_huge()
in the check above mfill_atomic()'s call to mfill_atomic_pte().

I don't disagree with you, and Peter too preferred -EAGAIN: it's just
better if they all use the same code (or maybe mfill_atomic()'s first
check for pmd_trans_huge() can be deleted along with the BUG_ONs - but
I have not checked through the cases, there may be very good reason to
keep that preliminary check there).

Hugh

  reply	other threads:[~2023-07-14  2:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-12  1:27 Hugh Dickins
2023-07-12 18:16 ` Axel Rasmussen
2023-07-14  2:40   ` Hugh Dickins [this message]
2023-07-19 21:53     ` Peter Xu

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=517aeee1-b4cd-c3fc-3236-e2a33c115af5@google.com \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@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