All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Alistair Popple <apopple@nvidia.com>
Cc: stable@vger.kernel.org, Ralph Campbell <rcampbell@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>,
	David Hildenbrand <david@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 6.2.y] mm: take a page reference when removing device exclusive entries
Date: Wed, 12 Apr 2023 09:59:26 +0200	[thread overview]
Message-ID: <2023041216-catalyze-query-7282@gregkh> (raw)
In-Reply-To: <20230412011831.152625-1-apopple@nvidia.com>

On Wed, Apr 12, 2023 at 11:18:31AM +1000, Alistair Popple wrote:
> Device exclusive page table entries are used to prevent CPU access to a
> page whilst it is being accessed from a device.  Typically this is used to
> implement atomic operations when the underlying bus does not support
> atomic access.  When a CPU thread encounters a device exclusive entry it
> locks the page and restores the original entry after calling mmu notifiers
> to signal drivers that exclusive access is no longer available.
> 
> The device exclusive entry holds a reference to the page making it safe to
> access the struct page whilst the entry is present.  However the fault
> handling code does not hold the PTL when taking the page lock.  This means
> if there are multiple threads faulting concurrently on the device
> exclusive entry one will remove the entry whilst others will wait on the
> page lock without holding a reference.
> 
> This can lead to threads locking or waiting on a folio with a zero
> refcount.  Whilst mmap_lock prevents the pages getting freed via munmap()
> they may still be freed by a migration.  This leads to warnings such as
> PAGE_FLAGS_CHECK_AT_FREE due to the page being locked when the refcount
> drops to zero.
> 
> Fix this by trying to take a reference on the folio before locking it.
> The code already checks the PTE under the PTL and aborts if the entry is
> no longer there.  It is also possible the folio has been unmapped, freed
> and re-allocated allowing a reference to be taken on an unrelated folio.
> This case is also detected by the PTE check and the folio is unlocked
> without further changes.
> 
> Link: https://lkml.kernel.org/r/20230330012519.804116-1-apopple@nvidia.com
> Fixes: b756a3b5e7ea ("mm: device exclusive memory access")
> Signed-off-by: Alistair Popple <apopple@nvidia.com>
> Reviewed-by: Ralph Campbell <rcampbell@nvidia.com>
> Reviewed-by: John Hubbard <jhubbard@nvidia.com>
> Acked-by: David Hildenbrand <david@redhat.com>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Christoph Hellwig <hch@infradead.org>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> (cherry picked from commit 7c7b962938ddda6a9cd095de557ee5250706ea88)
> ---
>  mm/memory.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)

All backports now queued up, thanks.

greg k-h

      reply	other threads:[~2023-04-12  7:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11 13:45 FAILED: patch "[PATCH] mm: take a page reference when removing device exclusive" failed to apply to 6.2-stable tree gregkh
2023-04-12  1:18 ` [PATCH 6.2.y] mm: take a page reference when removing device exclusive entries Alistair Popple
2023-04-12  7:59   ` Greg KH [this message]

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=2023041216-catalyze-query-7282@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=david@redhat.com \
    --cc=hch@infradead.org \
    --cc=jhubbard@nvidia.com \
    --cc=rcampbell@nvidia.com \
    --cc=stable@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.