misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()
Subsystems (3)
cover misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()
Hi,
There are also a couple of tiny cleanup patches, just to fix up a few minor issues that I spotted while converting from get_user_pages_fast() to pin_user_pages_fast().
Note that I have only compile-tested these patches, although that does also include cross-compiling for a few other arches. Any run-time testing would be greatly appreciated!
John Hubbard (3):
misc: xilinx-sdfec: improve get_user_pages_fast() error handling
misc: xilinx-sdfec: cleanup return value in xsdfec_table_write()
misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()
drivers/misc/xilinx_sdfec.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
base-commit: 9cb1fd0efd195590b828b9b865421ad345a4a145
Signature · 7 lines
2.26.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/3 misc: xilinx-sdfec: improve get_user_pages_fast() error handling
This fixes the case of get_user_pages_fast() returning a -errno. The result needs to be stored in a signed integer. And for safe signed/unsigned comparisons, it's best to keep everything signed. And get_user_pages_fast() also expects a signed value for number of pages to pin.
Therefore, change most relevant variables, from u32 to int. Leave "n" unsigned, for convenience in checking for overflow. And provide a WARN_ON_ONCE() and early return, if overflow occurs.
Also, as long as we're tidying up: rename the page array from page, to pages, in order to match the conventions used in most other call sites.
--- drivers/misc/xilinx_sdfec.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/misc/xilinx_sdfec.c +17 -10
@@ -602,10 +602,10 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset, const u32 depth) {u32 reg =0 ; -u32 res; -u32 n, i; +int res, i, nr_pages; +u32 n;u32 *addr =NULL ; -struct page *page[MAX_NUM_PAGES ]; +struct page *pages[MAX_NUM_PAGES ];/* * Writes that go beyond the length of
@@ -622,15 +622,22 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset,if ((len *XSDFEC_REG_WIDTH_JUMP ) %PAGE_SIZE ) n +=1 ; - res =get_user_pages_fast ((unsigned long )src_ptr, n,0 , page); -if (res < n) { -for (i =0 ; i < res; i++) -put_page (page[i]); +if (WARN_ON_ONCE (n >INT_MAX )) +return -EINVAL ; + + nr_pages = n; + + res =get_user_pages_fast ((unsigned long )src_ptr, nr_pages,0 , pages); +if (res < nr_pages) { +if (res >0 ) { +for (i =0 ; i < res; i++) +put_page (pages[i]); + }return -EINVAL ; } - for (i = 0; i < n; i++) { - addr = kmap(page[i]); + for (i = 0; i < nr_pages; i++) { + addr = kmap(pages[i]); do { xsdfec_regwrite(xsdfec, base_addr + ((offset + reg) *
@@ -639,7 +646,7 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset, reg++; }while ((reg < len) && ((reg *XSDFEC_REG_WIDTH_JUMP ) %PAGE_SIZE )); -put_page (page[i]); +put_page (pages[i]); }return reg; }
Signature · 1 line
2.26.2
PATCH 2/3 misc: xilinx-sdfec: cleanup return value in xsdfec_table_write()
In reply to John HubbardReturn 0 for success, rather than the value of an incrementing "reg" index. The reg value was never actually used, so this simplifies the caller slightly.
--- drivers/misc/xilinx_sdfec.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/misc/xilinx_sdfec.c +1 -3
@@ -648,7 +648,7 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset, ((reg * XSDFEC_REG_WIDTH_JUMP) % PAGE_SIZE));put_page (pages[i]); } -return reg; +return 0 ; }static int xsdfec_add_ldpc (struct xsdfec_dev *xsdfec,void __user *arg)
@@ -727,8 +727,6 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg) ret =xsdfec_table_write (xsdfec,4 * ldpc->qc_off, ldpc->qc_table, ldpc->nqc,XSDFEC_LDPC_QC_TABLE_ADDR_BASE ,XSDFEC_QC_TABLE_DEPTH ); -if (ret >0 ) - ret =0 ; err_out:kfree (ldpc);return ret;
Signature · 1 line
2.26.2
PATCH 3/3 misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()
In reply to John HubbardThis code was using get_user_pages*(), in approximately a "Case 1" scenario (Direct IO), using the categorization from [1]. That means that it's time to convert the get_user_pages*() + put_page() calls to pin_user_pages*() + unpin_user_pages() calls.
There is some helpful background in [2]: basically, this is a small part of fixing a long-standing disconnect between pinning pages, and file systems' use of those pages.
[1] Documentation/core-api/pin_user_pages.rst
[2] "Explicit pinning of user-space pages":
https://lwn.net/Articles/807108/
--- drivers/misc/xilinx_sdfec.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/misc/xilinx_sdfec.c +5 -6
@@ -627,12 +627,11 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset, nr_pages = n; - res =get_user_pages_fast ((unsigned long )src_ptr, nr_pages,0 , pages); + res =pin_user_pages_fast ((unsigned long )src_ptr, nr_pages,0 , pages);if (res < nr_pages) { -if (res >0 ) { -for (i =0 ; i < res; i++) -put_page (pages[i]); - } +if (res >0 ) +unpin_user_pages (pages, res); +return -EINVAL ; }
@@ -646,7 +645,7 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset, reg++; }while ((reg < len) && ((reg *XSDFEC_REG_WIDTH_JUMP ) %PAGE_SIZE )); -put_page (pages[i]); +unpin_user_page (pages[i]); }return 0 ; }
Signature · 1 line
2.26.2
Hi John,
Thank you for the suggestion, please find my comment below:
Quoted 26 lines
-----Original Message-----
From: John Hubbard <[email protected]>
Sent: Wednesday 27 May 2020 02:26
To: LKML <[email protected]>
Cc: Souptick Joarder <[email protected]>; John Hubbard <[email protected]>; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>; Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>; [email protected]
Subject: [PATCH 0/3] misc: xilinx-sdfec: convertget_user_pages()-->pin_user_pages()Hi,
There are also a couple of tiny cleanup patches, just to fix up a few minor issues that I spotted while converting from
get_user_pages_fast()topin_user_pages_fast().Note that I have only compile-tested these patches, although that does also include cross-compiling for a few other arches. Any run-time testing would be greatly appreciated!
Cc Derek Kiernan <[email protected]>Cc Dragan Cvetic <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Michal Simek <[email protected]>
Quoted 4 lines
John Hubbard (3):
misc: xilinx-sdfec: improveget_user_pages_fast()error handling
misc: xilinx-sdfec: cleanup return value inxsdfec_table_write()
misc: xilinx-sdfec: convertget_user_pages()-->pin_user_pages()
Reviewed-by:
Technically there is no problem in this patch, but as you said this should be tested. Currently due to Covid-19 I'm not able to access the HW and I cannot validate this suggestion.
Quoted 8 lines
drivers/misc/xilinx_sdfec.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)base-commit:
9cb1fd0efd195590b828b9b865421ad345a4a145--
2.26.2
Quoted 36 lines · Dragan Cvetic
Hi John,
Thank you for the suggestion, please find my comment below:
Quoted 26 lines
-----Original Message-----
From: John Hubbard <[email protected]>
Sent: Wednesday 27 May 2020 02:26
To: LKML <[email protected]>
Cc: Souptick Joarder <[email protected]>; John Hubbard <[email protected]>; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>; Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>; [email protected]
Subject: [PATCH 0/3] misc: xilinx-sdfec: convertget_user_pages()-->pin_user_pages()Hi,
There are also a couple of tiny cleanup patches, just to fix up a few minor issues that I spotted while converting from
get_user_pages_fast()topin_user_pages_fast().Note that I have only compile-tested these patches, although that does also include cross-compiling for a few other arches. Any run-time testing would be greatly appreciated!
Cc Derek Kiernan <[email protected]>Cc Dragan Cvetic <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Michal Simek <[email protected]>Quoted 4 lines
John Hubbard (3):
misc: xilinx-sdfec: improveget_user_pages_fast()error handling
misc: xilinx-sdfec: cleanup return value inxsdfec_table_write()
misc: xilinx-sdfec: convertget_user_pages()-->pin_user_pages()
Quoted 4 lines
Reviewed-by:
Technically there is no problem in this patch, but as you said this should be tested. Currently due to Covid-19 I'm not able to access the HW and I cannot validate this suggestion.
Hi Dragan,
Thanks for the review, and for *wanting* to do the testing, even though you can't right now. :)
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 9 lines
Quoted 8 lines
drivers/misc/xilinx_sdfec.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)base-commit:
9cb1fd0efd195590b828b9b865421ad345a4a145--
2.26.2