[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a2fusr6l4j5kxxkxgyeoxbsvuux7jbzsuwehii57benll26n7m@46mclv4gfgyh>
Date: Thu, 30 Jan 2025 16:37:21 +1100
From: Alistair Popple <apopple@...dia.com>
To: David Hildenbrand <david@...hat.com>
Cc: linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
dri-devel@...ts.freedesktop.org, linux-mm@...ck.org, nouveau@...ts.freedesktop.org,
Andrew Morton <akpm@...ux-foundation.org>, Jérôme Glisse <jglisse@...hat.com>,
Jonathan Corbet <corbet@....net>, Alex Shi <alexs@...nel.org>, Yanteng Si <si.yanteng@...ux.dev>,
Karol Herbst <kherbst@...hat.com>, Lyude Paul <lyude@...hat.com>,
Danilo Krummrich <dakr@...nel.org>, David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>, "Liam R. Howlett" <Liam.Howlett@...cle.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, Vlastimil Babka <vbabka@...e.cz>, Jann Horn <jannh@...gle.com>,
Pasha Tatashin <pasha.tatashin@...een.com>, Peter Xu <peterx@...hat.com>, Jason Gunthorpe <jgg@...dia.com>
Subject: Re: [PATCH v1 3/4] mm/memory: pass folio and pte to
restore_exclusive_pte()
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@...dia.com>
> Signed-off-by: David Hildenbrand <david@...hat.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
>
Powered by blists - more mailing lists