mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Revert "vfio/type1: Unpin zero pages"
@ 2024-02-29 22:35 Alex Williamson
  2024-03-01 10:53 ` David Hildenbrand
  2024-03-04  8:06 ` Tian, Kevin
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Williamson @ 2024-02-29 22:35 UTC (permalink / raw)
  To: alex.williamson; +Cc: david, kvm, linux-kernel

This reverts commit 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4.

This was a heinous workaround and it turns out it's been fixed in mm
twice since it was introduced.  Most recently, commit c8070b787519
("mm: Don't pin ZERO_PAGE in pin_user_pages()") would have prevented
running up the zeropage refcount, but even before that commit
84209e87c696 ("mm/gup: reliable R/O long-term pinning in COW mappings")
avoids the vfio use case from pinning the zeropage at all, instead
replacing it with exclusive anonymous pages.

Remove this now useless overhead.

Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/vfio/vfio_iommu_type1.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index b2854d7939ce..b5c15fe8f9fc 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -567,18 +567,6 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
 	ret = pin_user_pages_remote(mm, vaddr, npages, flags | FOLL_LONGTERM,
 				    pages, NULL);
 	if (ret > 0) {
-		int i;
-
-		/*
-		 * The zero page is always resident, we don't need to pin it
-		 * and it falls into our invalid/reserved test so we don't
-		 * unpin in put_pfn().  Unpin all zero pages in the batch here.
-		 */
-		for (i = 0 ; i < ret; i++) {
-			if (unlikely(is_zero_pfn(page_to_pfn(pages[i]))))
-				unpin_user_page(pages[i]);
-		}
-
 		*pfn = page_to_pfn(pages[0]);
 		goto done;
 	}
-- 
2.43.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Revert "vfio/type1: Unpin zero pages"
  2024-02-29 22:35 [PATCH] Revert "vfio/type1: Unpin zero pages" Alex Williamson
@ 2024-03-01 10:53 ` David Hildenbrand
  2024-03-04  8:06 ` Tian, Kevin
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2024-03-01 10:53 UTC (permalink / raw)
  To: Alex Williamson; +Cc: kvm, linux-kernel

On 29.02.24 23:35, Alex Williamson wrote:
> This reverts commit 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4.
> 
> This was a heinous workaround and it turns out it's been fixed in mm
> twice since it was introduced.  Most recently, commit c8070b787519
> ("mm: Don't pin ZERO_PAGE in pin_user_pages()") would have prevented
> running up the zeropage refcount, but even before that commit
> 84209e87c696 ("mm/gup: reliable R/O long-term pinning in COW mappings")
> avoids the vfio use case from pinning the zeropage at all, instead
> replacing it with exclusive anonymous pages.
> 
> Remove this now useless overhead.
> 
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>   drivers/vfio/vfio_iommu_type1.c | 12 ------------
>   1 file changed, 12 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index b2854d7939ce..b5c15fe8f9fc 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -567,18 +567,6 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
>   	ret = pin_user_pages_remote(mm, vaddr, npages, flags | FOLL_LONGTERM,
>   				    pages, NULL);
>   	if (ret > 0) {
> -		int i;
> -
> -		/*
> -		 * The zero page is always resident, we don't need to pin it
> -		 * and it falls into our invalid/reserved test so we don't
> -		 * unpin in put_pfn().  Unpin all zero pages in the batch here.
> -		 */
> -		for (i = 0 ; i < ret; i++) {
> -			if (unlikely(is_zero_pfn(page_to_pfn(pages[i]))))
> -				unpin_user_page(pages[i]);
> -		}
> -
>   		*pfn = page_to_pfn(pages[0]);
>   		goto done;
>   	}

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] Revert "vfio/type1: Unpin zero pages"
  2024-02-29 22:35 [PATCH] Revert "vfio/type1: Unpin zero pages" Alex Williamson
  2024-03-01 10:53 ` David Hildenbrand
@ 2024-03-04  8:06 ` Tian, Kevin
  1 sibling, 0 replies; 3+ messages in thread
From: Tian, Kevin @ 2024-03-04  8:06 UTC (permalink / raw)
  To: Alex Williamson; +Cc: david, kvm, linux-kernel

> From: Alex Williamson <alex.williamson@redhat.com>
> Sent: Friday, March 1, 2024 6:36 AM
> 
> This reverts commit 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4.
> 
> This was a heinous workaround and it turns out it's been fixed in mm
> twice since it was introduced.  Most recently, commit c8070b787519
> ("mm: Don't pin ZERO_PAGE in pin_user_pages()") would have prevented
> running up the zeropage refcount, but even before that commit
> 84209e87c696 ("mm/gup: reliable R/O long-term pinning in COW mappings")
> avoids the vfio use case from pinning the zeropage at all, instead
> replacing it with exclusive anonymous pages.
> 
> Remove this now useless overhead.
> 
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-04  8:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 22:35 [PATCH] Revert "vfio/type1: Unpin zero pages" Alex Williamson
2024-03-01 10:53 ` David Hildenbrand
2024-03-04  8:06 ` Tian, Kevin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®