From: Alistair Popple <apopple@nvidia.com>
To: David Hildenbrand <david@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-mm@kvack.org,
nouveau@lists.freedesktop.org,
"Andrew Morton" <akpm@linux-foundation.org>,
"Jérôme Glisse" <jglisse@redhat.com>,
"Jonathan Corbet" <corbet@lwn.net>, "Alex Shi" <alexs@kernel.org>,
"Yanteng Si" <si.yanteng@linux.dev>,
"Karol Herbst" <kherbst@redhat.com>,
"Lyude Paul" <lyude@redhat.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Jann Horn" <jannh@google.com>,
"Pasha Tatashin" <pasha.tatashin@soleen.com>,
"Peter Xu" <peterx@redhat.com>,
"Jason Gunthorpe" <jgg@nvidia.com>
Subject: Re: [PATCH v1 3/4] mm/memory: pass folio and pte to restore_exclusive_pte()
Date: Thu, 30 Jan 2025 16:37:21 +1100 [thread overview]
Message-ID: <a2fusr6l4j5kxxkxgyeoxbsvuux7jbzsuwehii57benll26n7m@46mclv4gfgyh> (raw)
In-Reply-To: <20250129115803.2084769-4-david@redhat.com>
On Wed, Jan 29, 2025 at 12:58:01PM +0100, David Hildenbrand wrote:
> Let's pass the folio and the pte to restore_exclusive_pte(), so we
> can avoid repeated page_folio() and ptep_get(). To do that,
> pass the pte to try_restore_exclusive_pte() and use a folio in there
> already.
>
> While at it, just avoid the "swp_entry_t entry" variable in
> try_restore_exclusive_pte() and add a folio-locked check to
> restore_exclusive_pte().
Seems reasonable.
Reviewed-by: Alistair Popple <apopple@nvidia.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> mm/memory.c | 29 ++++++++++++++---------------
> 1 file changed, 14 insertions(+), 15 deletions(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index cd689cd8a7c8..46956994aaff 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -719,14 +719,13 @@ struct folio *vm_normal_folio_pmd(struct vm_area_struct *vma,
> #endif
>
> static void restore_exclusive_pte(struct vm_area_struct *vma,
> - struct page *page, unsigned long address,
> - pte_t *ptep)
> + struct folio *folio, struct page *page, unsigned long address,
> + pte_t *ptep, pte_t orig_pte)
> {
> - struct folio *folio = page_folio(page);
> - pte_t orig_pte;
> pte_t pte;
>
> - orig_pte = ptep_get(ptep);
> + VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio);
> +
> pte = pte_mkold(mk_pte(page, READ_ONCE(vma->vm_page_prot)));
> if (pte_swp_soft_dirty(orig_pte))
> pte = pte_mksoft_dirty(pte);
> @@ -756,16 +755,15 @@ static void restore_exclusive_pte(struct vm_area_struct *vma,
> * Tries to restore an exclusive pte if the page lock can be acquired without
> * sleeping.
> */
> -static int
> -try_restore_exclusive_pte(pte_t *src_pte, struct vm_area_struct *vma,
> - unsigned long addr)
> +static int try_restore_exclusive_pte(struct vm_area_struct *vma,
> + unsigned long addr, pte_t *ptep, pte_t orig_pte)
> {
> - swp_entry_t entry = pte_to_swp_entry(ptep_get(src_pte));
> - struct page *page = pfn_swap_entry_to_page(entry);
> + struct page *page = pfn_swap_entry_to_page(pte_to_swp_entry(orig_pte));
> + struct folio *folio = page_folio(page);
>
> - if (trylock_page(page)) {
> - restore_exclusive_pte(vma, page, addr, src_pte);
> - unlock_page(page);
> + if (folio_trylock(folio)) {
> + restore_exclusive_pte(vma, folio, page, addr, ptep, orig_pte);
> + folio_unlock(folio);
> return 0;
> }
>
> @@ -871,7 +869,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
> * (ie. COW) mappings.
> */
> VM_BUG_ON(!is_cow_mapping(src_vma->vm_flags));
> - if (try_restore_exclusive_pte(src_pte, src_vma, addr))
> + if (try_restore_exclusive_pte(src_vma, addr, src_pte, orig_pte))
> return -EBUSY;
> return -ENOENT;
> } else if (is_pte_marker_entry(entry)) {
> @@ -3979,7 +3977,8 @@ static vm_fault_t remove_device_exclusive_entry(struct vm_fault *vmf)
> vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address,
> &vmf->ptl);
> if (likely(vmf->pte && pte_same(ptep_get(vmf->pte), vmf->orig_pte)))
> - restore_exclusive_pte(vma, vmf->page, vmf->address, vmf->pte);
> + restore_exclusive_pte(vma, folio, vmf->page, vmf->address,
> + vmf->pte, vmf->orig_pte);
>
> if (vmf->pte)
> pte_unmap_unlock(vmf->pte, vmf->ptl);
> --
> 2.48.1
>
next prev parent reply other threads:[~2025-01-30 5:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-29 11:57 [PATCH v1 0/4] mm: cleanups for device-exclusive entries (hmm) David Hildenbrand
2025-01-29 11:57 ` [PATCH v1 1/4] lib/test_hmm: make dmirror_atomic_map() consume a single page David Hildenbrand
2025-01-30 0:29 ` Alistair Popple
2025-01-29 11:58 ` [PATCH v1 2/4] mm/mmu_notifier: drop owner from MMU_NOTIFY_EXCLUSIVE David Hildenbrand
2025-01-30 5:34 ` Alistair Popple
2025-01-30 9:28 ` David Hildenbrand
2025-01-30 13:29 ` Simona Vetter
2025-01-30 15:26 ` David Hildenbrand
2025-01-29 11:58 ` [PATCH v1 3/4] mm/memory: pass folio and pte to restore_exclusive_pte() David Hildenbrand
2025-01-30 5:37 ` Alistair Popple [this message]
2025-01-29 11:58 ` [PATCH v1 4/4] mm/memory: document restore_exclusive_pte() David Hildenbrand
2025-01-30 0:27 ` Alistair Popple
2025-01-30 9:37 ` David Hildenbrand
2025-01-30 13:31 ` Simona Vetter
2025-01-30 15:29 ` David Hildenbrand
2025-01-31 0:14 ` Alistair Popple
2025-01-31 17:20 ` Simona Vetter
2025-01-30 10:43 ` Simona Vetter
2025-01-31 0:20 ` Alistair Popple
2025-01-31 9:15 ` David Hildenbrand
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=a2fusr6l4j5kxxkxgyeoxbsvuux7jbzsuwehii57benll26n7m@46mclv4gfgyh \
--to=apopple@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexs@kernel.org \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=david@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jannh@google.com \
--cc=jgg@nvidia.com \
--cc=jglisse@redhat.com \
--cc=kherbst@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=lyude@redhat.com \
--cc=nouveau@lists.freedesktop.org \
--cc=pasha.tatashin@soleen.com \
--cc=peterx@redhat.com \
--cc=si.yanteng@linux.dev \
--cc=simona@ffwll.ch \
--cc=vbabka@suse.cz \
/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