All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
@ 2023-06-16 22:42 Peter Colberg
  2023-06-19 13:46 ` Greg KH
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Colberg @ 2023-06-16 22:42 UTC (permalink / raw)
  To: hao.wu, yilun.xu, gregkh, linux-fpga, linux-kernel
  Cc: aaron.j.grier, tianfei.zhang, russell.h.weight, matthew.gerlach,
	marpagan, lgoncalv, Peter Colberg, Andy Shevchenko

Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
macros to convert between physical addresses and page frame numbers.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Peter Colberg <peter.colberg@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/fpga/dfl-afu-dma-region.c | 7 ++++---
 drivers/fpga/dfl-afu-main.c       | 5 +++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c
index 02b60fde0430..e8d54cfbb301 100644
--- a/drivers/fpga/dfl-afu-dma-region.c
+++ b/drivers/fpga/dfl-afu-dma-region.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/dma-mapping.h>
+#include <linux/pfn.h>
 #include <linux/sched/signal.h>
 #include <linux/uaccess.h>
 #include <linux/mm.h>
@@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)
 static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
 			     struct dfl_afu_dma_region *region)
 {
-	int npages = region->length >> PAGE_SHIFT;
+	int npages = PFN_DOWN(region->length);
 	struct device *dev = &pdata->dev->dev;
 	int ret, pinned;
 
@@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
 static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
 				struct dfl_afu_dma_region *region)
 {
-	long npages = region->length >> PAGE_SHIFT;
+	long npages = PFN_DOWN(region->length);
 	struct device *dev = &pdata->dev->dev;
 
 	unpin_user_pages(region->pages, npages);
@@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
  */
 static bool afu_dma_check_continuous_pages(struct dfl_afu_dma_region *region)
 {
-	int npages = region->length >> PAGE_SHIFT;
+	int npages = PFN_DOWN(region->length);
 	int i;
 
 	for (i = 0; i < npages - 1; i++)
diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index 7f621e96d3b8..048c9b418c8b 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -16,6 +16,7 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/pfn.h>
 #include <linux/uaccess.h>
 #include <linux/fpga-dfl.h>
 
@@ -816,7 +817,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 
 	pdata = dev_get_platdata(&pdev->dev);
 
-	offset = vma->vm_pgoff << PAGE_SHIFT;
+	offset = PFN_PHYS(vma->vm_pgoff);
 	ret = afu_mmio_region_get_by_offset(pdata, offset, size, &region);
 	if (ret)
 		return ret;
@@ -837,7 +838,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	return remap_pfn_range(vma, vma->vm_start,
-			(region.phys + (offset - region.offset)) >> PAGE_SHIFT,
+			PFN_DOWN(region.phys + (offset - region.offset)),
 			size, vma->vm_page_prot);
 }
 
-- 
2.28.0


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

* Re: [PATCH] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
  2023-06-16 22:42 [PATCH] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros Peter Colberg
@ 2023-06-19 13:46 ` Greg KH
  2023-06-19 13:54   ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Greg KH @ 2023-06-19 13:46 UTC (permalink / raw)
  To: Peter Colberg
  Cc: hao.wu, yilun.xu, linux-fpga, linux-kernel, aaron.j.grier,
	tianfei.zhang, russell.h.weight, matthew.gerlach, marpagan,
	lgoncalv, Andy Shevchenko

On Fri, Jun 16, 2023 at 06:42:09PM -0400, Peter Colberg wrote:
> Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
> macros to convert between physical addresses and page frame numbers.

Is this a bugfix, or just a cleanup?

thanks,

greg k-h

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

* Re: [PATCH] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
  2023-06-19 13:46 ` Greg KH
@ 2023-06-19 13:54   ` Andy Shevchenko
  2023-06-19 14:05     ` Greg KH
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2023-06-19 13:54 UTC (permalink / raw)
  To: Greg KH
  Cc: Peter Colberg, hao.wu, yilun.xu, linux-fpga, linux-kernel,
	aaron.j.grier, tianfei.zhang, russell.h.weight, matthew.gerlach,
	marpagan, lgoncalv

On Mon, Jun 19, 2023 at 03:46:29PM +0200, Greg KH wrote:
> On Fri, Jun 16, 2023 at 06:42:09PM -0400, Peter Colberg wrote:
> > Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
> > macros to convert between physical addresses and page frame numbers.
> 
> Is this a bugfix, or just a cleanup?

Cleanup.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
  2023-06-19 13:54   ` Andy Shevchenko
@ 2023-06-19 14:05     ` Greg KH
  2023-06-19 19:56       ` [PATCH v2] " Peter Colberg
  0 siblings, 1 reply; 10+ messages in thread
From: Greg KH @ 2023-06-19 14:05 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Peter Colberg, hao.wu, yilun.xu, linux-fpga, linux-kernel,
	aaron.j.grier, tianfei.zhang, russell.h.weight, matthew.gerlach,
	marpagan, lgoncalv

On Mon, Jun 19, 2023 at 04:54:44PM +0300, Andy Shevchenko wrote:
> On Mon, Jun 19, 2023 at 03:46:29PM +0200, Greg KH wrote:
> > On Fri, Jun 16, 2023 at 06:42:09PM -0400, Peter Colberg wrote:
> > > Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
> > > macros to convert between physical addresses and page frame numbers.
> > 
> > Is this a bugfix, or just a cleanup?
> 
> Cleanup.

Great, can the text be worded to say that?  As is, it does not give any
hint either way.

thanks,

greg k-h

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

* [PATCH v2] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
  2023-06-19 14:05     ` Greg KH
@ 2023-06-19 19:56       ` Peter Colberg
  2023-06-27  6:26         ` Xu Yilun
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Colberg @ 2023-06-19 19:56 UTC (permalink / raw)
  To: hao.wu, yilun.xu, gregkh, linux-fpga, linux-kernel
  Cc: aaron.j.grier, tianfei.zhang, russell.h.weight, matthew.gerlach,
	marpagan, lgoncalv, Peter Colberg, Andy Shevchenko

Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
macros to convert between physical addresses and page frame numbers.

These changes are cosmetic only; no functional changes.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Peter Colberg <peter.colberg@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2:
- Comment in commit message that changes are cosmetic only
---
 drivers/fpga/dfl-afu-dma-region.c | 7 ++++---
 drivers/fpga/dfl-afu-main.c       | 5 +++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c
index 02b60fde0430..e8d54cfbb301 100644
--- a/drivers/fpga/dfl-afu-dma-region.c
+++ b/drivers/fpga/dfl-afu-dma-region.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/dma-mapping.h>
+#include <linux/pfn.h>
 #include <linux/sched/signal.h>
 #include <linux/uaccess.h>
 #include <linux/mm.h>
@@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)
 static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
 			     struct dfl_afu_dma_region *region)
 {
-	int npages = region->length >> PAGE_SHIFT;
+	int npages = PFN_DOWN(region->length);
 	struct device *dev = &pdata->dev->dev;
 	int ret, pinned;
 
@@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
 static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
 				struct dfl_afu_dma_region *region)
 {
-	long npages = region->length >> PAGE_SHIFT;
+	long npages = PFN_DOWN(region->length);
 	struct device *dev = &pdata->dev->dev;
 
 	unpin_user_pages(region->pages, npages);
@@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
  */
 static bool afu_dma_check_continuous_pages(struct dfl_afu_dma_region *region)
 {
-	int npages = region->length >> PAGE_SHIFT;
+	int npages = PFN_DOWN(region->length);
 	int i;
 
 	for (i = 0; i < npages - 1; i++)
diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index 7f621e96d3b8..048c9b418c8b 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -16,6 +16,7 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/pfn.h>
 #include <linux/uaccess.h>
 #include <linux/fpga-dfl.h>
 
@@ -816,7 +817,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 
 	pdata = dev_get_platdata(&pdev->dev);
 
-	offset = vma->vm_pgoff << PAGE_SHIFT;
+	offset = PFN_PHYS(vma->vm_pgoff);
 	ret = afu_mmio_region_get_by_offset(pdata, offset, size, &region);
 	if (ret)
 		return ret;
@@ -837,7 +838,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	return remap_pfn_range(vma, vma->vm_start,
-			(region.phys + (offset - region.offset)) >> PAGE_SHIFT,
+			PFN_DOWN(region.phys + (offset - region.offset)),
 			size, vma->vm_page_prot);
 }
 
-- 
2.28.0


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

* Re: [PATCH v2] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
  2023-06-19 19:56       ` [PATCH v2] " Peter Colberg
@ 2023-06-27  6:26         ` Xu Yilun
  2023-06-27 18:23           ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Xu Yilun @ 2023-06-27  6:26 UTC (permalink / raw)
  To: Peter Colberg
  Cc: hao.wu, gregkh, linux-fpga, linux-kernel, aaron.j.grier,
	tianfei.zhang, russell.h.weight, matthew.gerlach, marpagan,
	lgoncalv, Andy Shevchenko

On 2023-06-19 at 15:56:34 -0400, Peter Colberg wrote:
> Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
> macros to convert between physical addresses and page frame numbers.
> 
> These changes are cosmetic only; no functional changes.
> 
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Peter Colberg <peter.colberg@intel.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2:
> - Comment in commit message that changes are cosmetic only
> ---
>  drivers/fpga/dfl-afu-dma-region.c | 7 ++++---
>  drivers/fpga/dfl-afu-main.c       | 5 +++--
>  2 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c
> index 02b60fde0430..e8d54cfbb301 100644
> --- a/drivers/fpga/dfl-afu-dma-region.c
> +++ b/drivers/fpga/dfl-afu-dma-region.c
> @@ -10,6 +10,7 @@
>   */
>  
>  #include <linux/dma-mapping.h>
> +#include <linux/pfn.h>
>  #include <linux/sched/signal.h>
>  #include <linux/uaccess.h>
>  #include <linux/mm.h>
> @@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)
>  static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
>  			     struct dfl_afu_dma_region *region)
>  {
> -	int npages = region->length >> PAGE_SHIFT;
> +	int npages = PFN_DOWN(region->length);

I don't much prefer this change, it is not doing the phy addr to pfn
convertion. The macro name doesn't match what is doing here.

>  	struct device *dev = &pdata->dev->dev;
>  	int ret, pinned;
>  
> @@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
>  static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
>  				struct dfl_afu_dma_region *region)
>  {
> -	long npages = region->length >> PAGE_SHIFT;
> +	long npages = PFN_DOWN(region->length);

ditto

>  	struct device *dev = &pdata->dev->dev;
>  
>  	unpin_user_pages(region->pages, npages);
> @@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
>   */
>  static bool afu_dma_check_continuous_pages(struct dfl_afu_dma_region *region)
>  {
> -	int npages = region->length >> PAGE_SHIFT;
> +	int npages = PFN_DOWN(region->length);

ditto

>  	int i;
>  
>  	for (i = 0; i < npages - 1; i++)
> diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
> index 7f621e96d3b8..048c9b418c8b 100644
> --- a/drivers/fpga/dfl-afu-main.c
> +++ b/drivers/fpga/dfl-afu-main.c
> @@ -16,6 +16,7 @@
>  
>  #include <linux/kernel.h>
>  #include <linux/module.h>
> +#include <linux/pfn.h>
>  #include <linux/uaccess.h>
>  #include <linux/fpga-dfl.h>
>  
> @@ -816,7 +817,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
>  
>  	pdata = dev_get_platdata(&pdev->dev);
>  
> -	offset = vma->vm_pgoff << PAGE_SHIFT;
> +	offset = PFN_PHYS(vma->vm_pgoff);

ditto. The variables are offsets within file, not phys addr & pfn.

>  	ret = afu_mmio_region_get_by_offset(pdata, offset, size, &region);
>  	if (ret)
>  		return ret;
> @@ -837,7 +838,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
>  	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
>  
>  	return remap_pfn_range(vma, vma->vm_start,
> -			(region.phys + (offset - region.offset)) >> PAGE_SHIFT,
> +			PFN_DOWN(region.phys + (offset - region.offset)),
>  			size, vma->vm_page_prot);
>  }
>  
> -- 
> 2.28.0
> 

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

* Re: [PATCH v2] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
  2023-06-27  6:26         ` Xu Yilun
@ 2023-06-27 18:23           ` Andy Shevchenko
  2023-06-28  5:56             ` Xu Yilun
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2023-06-27 18:23 UTC (permalink / raw)
  To: Xu Yilun
  Cc: Peter Colberg, hao.wu, gregkh, linux-fpga, linux-kernel,
	aaron.j.grier, tianfei.zhang, russell.h.weight, matthew.gerlach,
	marpagan, lgoncalv

On Tue, Jun 27, 2023 at 02:26:27PM +0800, Xu Yilun wrote:
> On 2023-06-19 at 15:56:34 -0400, Peter Colberg wrote:

...

> > -	int npages = region->length >> PAGE_SHIFT;
> > +	int npages = PFN_DOWN(region->length);
> 
> I don't much prefer this change, it is not doing the phy addr to pfn
> convertion. The macro name doesn't match what is doing here.

This macro converts length to pages. And it's not about phy addr.

...

> > -	long npages = region->length >> PAGE_SHIFT;
> > +	long npages = PFN_DOWN(region->length);
> 
> ditto

Ditto.

...

> > -	int npages = region->length >> PAGE_SHIFT;
> > +	int npages = PFN_DOWN(region->length);
> 
> ditto

Ditto.

...

> > -	offset = vma->vm_pgoff << PAGE_SHIFT;
> > +	offset = PFN_PHYS(vma->vm_pgoff);
> 
> ditto. The variables are offsets within file, not phys addr & pfn.

Here I probably can agree.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
  2023-06-27 18:23           ` Andy Shevchenko
@ 2023-06-28  5:56             ` Xu Yilun
  2023-06-29  0:22               ` [PATCH v3] fpga: dfl: afu: use PFN_DOWN() helper macro Peter Colberg
  0 siblings, 1 reply; 10+ messages in thread
From: Xu Yilun @ 2023-06-28  5:56 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Peter Colberg, hao.wu, gregkh, linux-fpga, linux-kernel,
	aaron.j.grier, tianfei.zhang, russell.h.weight, matthew.gerlach,
	marpagan, lgoncalv

On 2023-06-27 at 21:23:03 +0300, Andy Shevchenko wrote:
> On Tue, Jun 27, 2023 at 02:26:27PM +0800, Xu Yilun wrote:
> > On 2023-06-19 at 15:56:34 -0400, Peter Colberg wrote:
> 
> ...
> 
> > > -	int npages = region->length >> PAGE_SHIFT;
> > > +	int npages = PFN_DOWN(region->length);
> > 
> > I don't much prefer this change, it is not doing the phy addr to pfn
> > convertion. The macro name doesn't match what is doing here.
> 
> This macro converts length to pages. And it's not about phy addr.

You are right.

> > > -	offset = vma->vm_pgoff << PAGE_SHIFT;
> > > +	offset = PFN_PHYS(vma->vm_pgoff);
> > 
> > ditto. The variables are offsets within file, not phys addr & pfn.
> 
> Here I probably can agree.

OK. Remove this one, and others LGTM.

Thanks,
Yilun

> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 

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

* [PATCH v3] fpga: dfl: afu: use PFN_DOWN() helper macro
  2023-06-28  5:56             ` Xu Yilun
@ 2023-06-29  0:22               ` Peter Colberg
  2023-07-10  6:35                 ` Xu Yilun
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Colberg @ 2023-06-29  0:22 UTC (permalink / raw)
  To: hao.wu, yilun.xu, gregkh, linux-fpga, linux-kernel
  Cc: aaron.j.grier, tianfei.zhang, russell.h.weight, matthew.gerlach,
	marpagan, lgoncalv, Peter Colberg, Andy Shevchenko

Replace right shifts by PAGE_SHIFT with PFN_DOWN() helper macro to convert
from physical addresses to page frame numbers.

These changes are cosmetic only; no functional changes.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Peter Colberg <peter.colberg@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v3:
- Revert afu_mmap(), which calculates file offsets, not physical pages
v2:
- Comment in commit message that changes are cosmetic only
---
 drivers/fpga/dfl-afu-dma-region.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c
index 02b60fde0430..e8d54cfbb301 100644
--- a/drivers/fpga/dfl-afu-dma-region.c
+++ b/drivers/fpga/dfl-afu-dma-region.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/dma-mapping.h>
+#include <linux/pfn.h>
 #include <linux/sched/signal.h>
 #include <linux/uaccess.h>
 #include <linux/mm.h>
@@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)
 static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
 			     struct dfl_afu_dma_region *region)
 {
-	int npages = region->length >> PAGE_SHIFT;
+	int npages = PFN_DOWN(region->length);
 	struct device *dev = &pdata->dev->dev;
 	int ret, pinned;
 
@@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
 static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
 				struct dfl_afu_dma_region *region)
 {
-	long npages = region->length >> PAGE_SHIFT;
+	long npages = PFN_DOWN(region->length);
 	struct device *dev = &pdata->dev->dev;
 
 	unpin_user_pages(region->pages, npages);
@@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
  */
 static bool afu_dma_check_continuous_pages(struct dfl_afu_dma_region *region)
 {
-	int npages = region->length >> PAGE_SHIFT;
+	int npages = PFN_DOWN(region->length);
 	int i;
 
 	for (i = 0; i < npages - 1; i++)
-- 
2.28.0


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

* Re: [PATCH v3] fpga: dfl: afu: use PFN_DOWN() helper macro
  2023-06-29  0:22               ` [PATCH v3] fpga: dfl: afu: use PFN_DOWN() helper macro Peter Colberg
@ 2023-07-10  6:35                 ` Xu Yilun
  0 siblings, 0 replies; 10+ messages in thread
From: Xu Yilun @ 2023-07-10  6:35 UTC (permalink / raw)
  To: Peter Colberg
  Cc: hao.wu, gregkh, linux-fpga, linux-kernel, aaron.j.grier,
	tianfei.zhang, russell.h.weight, matthew.gerlach, marpagan,
	lgoncalv, Andy Shevchenko

On 2023-06-28 at 20:22:55 -0400, Peter Colberg wrote:
> Replace right shifts by PAGE_SHIFT with PFN_DOWN() helper macro to convert
> from physical addresses to page frame numbers.
> 
> These changes are cosmetic only; no functional changes.
> 
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Peter Colberg <peter.colberg@intel.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v3:
> - Revert afu_mmap(), which calculates file offsets, not physical pages
> v2:
> - Comment in commit message that changes are cosmetic only
> ---
>  drivers/fpga/dfl-afu-dma-region.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c
> index 02b60fde0430..e8d54cfbb301 100644
> --- a/drivers/fpga/dfl-afu-dma-region.c
> +++ b/drivers/fpga/dfl-afu-dma-region.c
> @@ -10,6 +10,7 @@
>   */
>  
>  #include <linux/dma-mapping.h>
> +#include <linux/pfn.h>
>  #include <linux/sched/signal.h>
>  #include <linux/uaccess.h>
>  #include <linux/mm.h>
> @@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)
>  static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
>  			     struct dfl_afu_dma_region *region)
>  {
> -	int npages = region->length >> PAGE_SHIFT;
> +	int npages = PFN_DOWN(region->length);
>  	struct device *dev = &pdata->dev->dev;
>  	int ret, pinned;
>  
> @@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
>  static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
>  				struct dfl_afu_dma_region *region)
>  {
> -	long npages = region->length >> PAGE_SHIFT;
> +	long npages = PFN_DOWN(region->length);
>  	struct device *dev = &pdata->dev->dev;
>  
>  	unpin_user_pages(region->pages, npages);
> @@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,
>   */
>  static bool afu_dma_check_continuous_pages(struct dfl_afu_dma_region *region)
>  {
> -	int npages = region->length >> PAGE_SHIFT;
> +	int npages = PFN_DOWN(region->length);
>  	int i;
>  
>  	for (i = 0; i < npages - 1; i++)



@@ -837,7 +838,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);

        return remap_pfn_range(vma, vma->vm_start,
-                       (region.phys + (offset - region.offset)) >> PAGE_SHIFT,
+                       PFN_DOWN(region.phys + (offset - region.offset)),
                        size, vma->vm_page_prot);


Why is this change also dropped? Maybe use PHYS_PFN() instead?

Thanks,
Yilun

> -- 
> 2.28.0
> 

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

end of thread, other threads:[~2023-07-10  6:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 22:42 [PATCH] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros Peter Colberg
2023-06-19 13:46 ` Greg KH
2023-06-19 13:54   ` Andy Shevchenko
2023-06-19 14:05     ` Greg KH
2023-06-19 19:56       ` [PATCH v2] " Peter Colberg
2023-06-27  6:26         ` Xu Yilun
2023-06-27 18:23           ` Andy Shevchenko
2023-06-28  5:56             ` Xu Yilun
2023-06-29  0:22               ` [PATCH v3] fpga: dfl: afu: use PFN_DOWN() helper macro Peter Colberg
2023-07-10  6:35                 ` Xu Yilun

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.