linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ben Gardon <bgardon@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
	"David Rientjes" <rientjes@google.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Michal Hocko" <mhocko@suse.com>,
	"Jérôme Glisse" <jglisse@redhat.com>,
	"Andrea Arcangeli" <aarcange@redhat.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Dimitri Sivanich" <dimitri.sivanich@hpe.com>
Subject: Re: [PATCH] mm/oom_kill: Ensure MMU notifier range_end() is paired with range_start()
Date: Wed, 10 Mar 2021 14:08:31 -0800	[thread overview]
Message-ID: <CANgfPd-GskR6cBEsE_77f6B5zyXLLOLdkh6sF7Hw1UZtH5up4g@mail.gmail.com> (raw)
In-Reply-To: <20210310213117.1444147-1-seanjc@google.com>

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

On Wed, Mar 10, 2021 at 1:31 PM Sean Christopherson <seanjc@google.com>
wrote:

> Invoke the MMU notifier's .invalidate_range_end() callbacks even if one
> of the .invalidate_range_start() callbacks failed.  If there are multiple
> notifiers, the notifier that did not fail may have performed actions in
> its ...start() that it expects to unwind via ...end().  Per the
> mmu_notifier_ops documentation, ...start() and ...end() must be paired.
>
> The only in-kernel usage that is fatally broken is the SGI UV GRU driver,
> which effectively blocks and sleeps fault handlers during ...start(), and
> unblocks/wakes the handlers during ...end().  But, the only users that
> can fail ...start() are the i915 and Nouveau drivers, which are unlikely
> to collide with the SGI driver.
>
> KVM is the only other user of ...end(), and while KVM also blocks fault
> handlers in ...start(), the fault handlers do not sleep and originate in
> killable ioctl() calls.  So while it's possible for the i915 and Nouveau
> drivers to collide with KVM, the bug is benign for KVM since the process
> is dying and KVM's guest is about to be terminated.
>
> So, as of today, the bug is likely benign.  But, that may not always be
> true, e.g. there is a potential use case for blocking memslot updates in
> KVM while an invalidation is in-progress, and failure to unblock would
> result in said updates being blocked indefinitely and hanging.
>
> Found by inspection.  Verified by adding a second notifier in KVM that
> periodically returns -EAGAIN on non-blockable ranges, triggering OOM,
> and observing that KVM exits with an elevated notifier count.
>
> Fixes: 93065ac753e4 ("mm, oom: distinguish blockable mode for mmu
> notifiers")
> Cc: stable@vger.kernel.org
> Cc: David Rientjes <rientjes@google.com>
> Cc: Ben Gardon <bgardon@google.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: "Jérôme Glisse" <jglisse@redhat.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Dimitri Sivanich <dimitri.sivanich@hpe.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>

Reviewed-by: Ben Gardon <bgardon@google.com>

Thanks for catching and fixing this.


> ---
>  mm/oom_kill.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index bc65ba4f5192..acc3ba8b2ed7 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -546,12 +546,10 @@ bool __oom_reap_task_mm(struct mm_struct *mm)
>                                                 vma, mm, vma->vm_start,
>                                                 vma->vm_end);
>                         tlb_gather_mmu(&tlb, mm);
> -                       if
> (mmu_notifier_invalidate_range_start_nonblock(&range)) {
> -                               tlb_finish_mmu(&tlb);
> +                       if
> (!mmu_notifier_invalidate_range_start_nonblock(&range))
> +                               unmap_page_range(&tlb, vma, range.start,
> range.end, NULL);
> +                       else
>                                 ret = false;
> -                               continue;
> -                       }
> -                       unmap_page_range(&tlb, vma, range.start,
> range.end, NULL);
>                         mmu_notifier_invalidate_range_end(&range);
>                         tlb_finish_mmu(&tlb);
>                 }
> --
> 2.30.1.766.gb4fecdf3b7-goog
>
>

[-- Attachment #2: Type: text/html, Size: 5226 bytes --]

  reply	other threads:[~2021-03-10 22:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10 21:31 Sean Christopherson
2021-03-10 22:08 ` Ben Gardon [this message]
2021-03-11  0:06 ` Andrew Morton
2021-03-11  0:28 ` Jason Gunthorpe
2021-03-11  1:20   ` Sean Christopherson
2021-03-11  1:50     ` Jason Gunthorpe
2021-03-11  7:22       ` Sean Christopherson
2021-03-11 16:20   ` Michal Hocko

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=CANgfPd-GskR6cBEsE_77f6B5zyXLLOLdkh6sF7Hw1UZtH5up4g@mail.gmail.com \
    --to=bgardon@google.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dimitri.sivanich@hpe.com \
    --cc=hannes@cmpxchg.org \
    --cc=jgg@ziepe.ca \
    --cc=jglisse@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=rientjes@google.com \
    --cc=seanjc@google.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