diff mbox series

drm: Remove PageReserved manipulation from drm_pci_alloc

Message ID 20200202161009.3969641-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series drm: Remove PageReserved manipulation from drm_pci_alloc | expand

Commit Message

Chris Wilson Feb. 2, 2020, 4:10 p.m. UTC
drm_pci_alloc/drm_pci_free are very thin wrappers around the core dma
facilities, and we have no special reason within the drm layer to behave
differently. In particular, since

commit de09d31dd38a50fdce106c15abd68432eebbd014
Author: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Date:   Fri Jan 15 16:51:42 2016 -0800

    page-flags: define PG_reserved behavior on compound pages

    As far as I can see there's no users of PG_reserved on compound pages.
    Let's use PF_NO_COMPOUND here.

it has been illegal to combine GFP_COMP with SetPageReserved, so lets
stop doing both and leave the dma layer to its own devices.

Reported-by: Taketo Kabe
Closes: https://gitlab.freedesktop.org/drm/intel/issues/1027
Fixes: de09d31dd38a ("page-flags: define PG_reserved behavior on compound pages")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: <stable@vger.kernel.org> # v4.5+
---
 drivers/gpu/drm/drm_pci.c | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)

Comments

Daniel Vetter Feb. 2, 2020, 4:43 p.m. UTC | #1
On Sun, Feb 02, 2020 at 04:10:09PM +0000, Chris Wilson wrote:
> drm_pci_alloc/drm_pci_free are very thin wrappers around the core dma
> facilities, and we have no special reason within the drm layer to behave
> differently. In particular, since
> 
> commit de09d31dd38a50fdce106c15abd68432eebbd014
> Author: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Date:   Fri Jan 15 16:51:42 2016 -0800
> 
>     page-flags: define PG_reserved behavior on compound pages
> 
>     As far as I can see there's no users of PG_reserved on compound pages.
>     Let's use PF_NO_COMPOUND here.
> 
> it has been illegal to combine GFP_COMP with SetPageReserved, so lets
> stop doing both and leave the dma layer to its own devices.
> 
> Reported-by: Taketo Kabe
> Closes: https://gitlab.freedesktop.org/drm/intel/issues/1027
> Fixes: de09d31dd38a ("page-flags: define PG_reserved behavior on compound pages")
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: <stable@vger.kernel.org> # v4.5+

Given that after your i915 patch only mga and r128 still use this I think
deleting code is the best action here.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> ---
>  drivers/gpu/drm/drm_pci.c | 23 ++---------------------
>  1 file changed, 2 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
> index f2e43d341980..d16dac4325f9 100644
> --- a/drivers/gpu/drm/drm_pci.c
> +++ b/drivers/gpu/drm/drm_pci.c
> @@ -51,8 +51,6 @@
>  drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t align)
>  {
>  	drm_dma_handle_t *dmah;
> -	unsigned long addr;
> -	size_t sz;
>  
>  	/* pci_alloc_consistent only guarantees alignment to the smallest
>  	 * PAGE_SIZE order which is greater than or equal to the requested size.
> @@ -68,20 +66,13 @@ drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t ali
>  	dmah->size = size;
>  	dmah->vaddr = dma_alloc_coherent(&dev->pdev->dev, size,
>  					 &dmah->busaddr,
> -					 GFP_KERNEL | __GFP_COMP);
> +					 GFP_KERNEL);
>  
>  	if (dmah->vaddr == NULL) {
>  		kfree(dmah);
>  		return NULL;
>  	}
>  
> -	/* XXX - Is virt_to_page() legal for consistent mem? */
> -	/* Reserve */
> -	for (addr = (unsigned long)dmah->vaddr, sz = size;
> -	     sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
> -		SetPageReserved(virt_to_page((void *)addr));
> -	}
> -
>  	return dmah;
>  }
>  
> @@ -94,19 +85,9 @@ EXPORT_SYMBOL(drm_pci_alloc);
>   */
>  void __drm_legacy_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
>  {
> -	unsigned long addr;
> -	size_t sz;
> -
> -	if (dmah->vaddr) {
> -		/* XXX - Is virt_to_page() legal for consistent mem? */
> -		/* Unreserve */
> -		for (addr = (unsigned long)dmah->vaddr, sz = dmah->size;
> -		     sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
> -			ClearPageReserved(virt_to_page((void *)addr));
> -		}
> +	if (dmah->vaddr)
>  		dma_free_coherent(&dev->pdev->dev, dmah->size, dmah->vaddr,
>  				  dmah->busaddr);
> -	}
>  }
>  
>  /**
> -- 
> 2.25.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Chris Wilson Feb. 2, 2020, 5:06 p.m. UTC | #2
Quoting Daniel Vetter (2020-02-02 16:43:06)
> On Sun, Feb 02, 2020 at 04:10:09PM +0000, Chris Wilson wrote:
> > drm_pci_alloc/drm_pci_free are very thin wrappers around the core dma
> > facilities, and we have no special reason within the drm layer to behave
> > differently. In particular, since
> > 
> > commit de09d31dd38a50fdce106c15abd68432eebbd014
> > Author: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > Date:   Fri Jan 15 16:51:42 2016 -0800
> > 
> >     page-flags: define PG_reserved behavior on compound pages
> > 
> >     As far as I can see there's no users of PG_reserved on compound pages.
> >     Let's use PF_NO_COMPOUND here.
> > 
> > it has been illegal to combine GFP_COMP with SetPageReserved, so lets
> > stop doing both and leave the dma layer to its own devices.
> > 
> > Reported-by: Taketo Kabe
> > Closes: https://gitlab.freedesktop.org/drm/intel/issues/1027
> > Fixes: de09d31dd38a ("page-flags: define PG_reserved behavior on compound pages")
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: <stable@vger.kernel.org> # v4.5+
> 
> Given that after your i915 patch only mga and r128 still use this I think
> deleting code is the best action here.

drm_bufs.c has a little sting in its tail with the inclusion of the
drm_dma_handle struct in its seglist. Certainly after removing r128 we
can remove the EXPORT_SYMBOL and make it internal.
-Chris
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index f2e43d341980..d16dac4325f9 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -51,8 +51,6 @@ 
 drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t align)
 {
 	drm_dma_handle_t *dmah;
-	unsigned long addr;
-	size_t sz;
 
 	/* pci_alloc_consistent only guarantees alignment to the smallest
 	 * PAGE_SIZE order which is greater than or equal to the requested size.
@@ -68,20 +66,13 @@  drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t ali
 	dmah->size = size;
 	dmah->vaddr = dma_alloc_coherent(&dev->pdev->dev, size,
 					 &dmah->busaddr,
-					 GFP_KERNEL | __GFP_COMP);
+					 GFP_KERNEL);
 
 	if (dmah->vaddr == NULL) {
 		kfree(dmah);
 		return NULL;
 	}
 
-	/* XXX - Is virt_to_page() legal for consistent mem? */
-	/* Reserve */
-	for (addr = (unsigned long)dmah->vaddr, sz = size;
-	     sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
-		SetPageReserved(virt_to_page((void *)addr));
-	}
-
 	return dmah;
 }
 
@@ -94,19 +85,9 @@  EXPORT_SYMBOL(drm_pci_alloc);
  */
 void __drm_legacy_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
 {
-	unsigned long addr;
-	size_t sz;
-
-	if (dmah->vaddr) {
-		/* XXX - Is virt_to_page() legal for consistent mem? */
-		/* Unreserve */
-		for (addr = (unsigned long)dmah->vaddr, sz = dmah->size;
-		     sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
-			ClearPageReserved(virt_to_page((void *)addr));
-		}
+	if (dmah->vaddr)
 		dma_free_coherent(&dev->pdev->dev, dmah->size, dmah->vaddr,
 				  dmah->busaddr);
-	}
 }
 
 /**