* [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()
@ 2020-05-27 1:26 John Hubbard
2020-05-27 1:26 ` [PATCH 1/3] misc: xilinx-sdfec: improve get_user_pages_fast() error handling John Hubbard
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: John Hubbard @ 2020-05-27 1:26 UTC (permalink / raw)
To: LKML
Cc: Souptick Joarder, John Hubbard, Derek Kiernan, Dragan Cvetic,
Arnd Bergmann, Greg Kroah-Hartman, Michal Simek,
linux-arm-kernel
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!
Cc: Derek Kiernan <derek.kiernan@xilinx.com>
Cc: Dragan Cvetic <dragan.cvetic@xilinx.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: linux-arm-kernel@lists.infradead.org
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
--
2.26.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] misc: xilinx-sdfec: improve get_user_pages_fast() error handling
2020-05-27 1:26 [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages() John Hubbard
@ 2020-05-27 1:26 ` John Hubbard
2020-05-27 1:26 ` [PATCH 2/3] misc: xilinx-sdfec: cleanup return value in xsdfec_table_write() John Hubbard
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: John Hubbard @ 2020-05-27 1:26 UTC (permalink / raw)
To: LKML
Cc: Souptick Joarder, John Hubbard, Derek Kiernan, Dragan Cvetic,
Arnd Bergmann, Greg Kroah-Hartman, Michal Simek,
linux-arm-kernel
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.
Fixes: 20ec628e8007e ("misc: xilinx_sdfec: Add ability to configure LDPC")
Cc: Derek Kiernan <derek.kiernan@xilinx.com>
Cc: Dragan Cvetic <dragan.cvetic@xilinx.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
drivers/misc/xilinx_sdfec.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
index 71bbaa56bdb5..e2766aad9e14 100644
--- a/drivers/misc/xilinx_sdfec.c
+++ b/drivers/misc/xilinx_sdfec.c
@@ -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;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] misc: xilinx-sdfec: cleanup return value in xsdfec_table_write()
2020-05-27 1:26 [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages() John Hubbard
2020-05-27 1:26 ` [PATCH 1/3] misc: xilinx-sdfec: improve get_user_pages_fast() error handling John Hubbard
@ 2020-05-27 1:26 ` John Hubbard
2020-05-27 1:26 ` [PATCH 3/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages() John Hubbard
2020-05-29 8:29 ` [PATCH 0/3] " Dragan Cvetic
3 siblings, 0 replies; 6+ messages in thread
From: John Hubbard @ 2020-05-27 1:26 UTC (permalink / raw)
To: LKML
Cc: Souptick Joarder, John Hubbard, Derek Kiernan, Dragan Cvetic,
Arnd Bergmann, Greg Kroah-Hartman, Michal Simek,
linux-arm-kernel
Return 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.
Cc: Derek Kiernan <derek.kiernan@xilinx.com>
Cc: Dragan Cvetic <dragan.cvetic@xilinx.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
drivers/misc/xilinx_sdfec.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
index e2766aad9e14..7e2ee3e547f2 100644
--- a/drivers/misc/xilinx_sdfec.c
+++ b/drivers/misc/xilinx_sdfec.c
@@ -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;
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()
2020-05-27 1:26 [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages() John Hubbard
2020-05-27 1:26 ` [PATCH 1/3] misc: xilinx-sdfec: improve get_user_pages_fast() error handling John Hubbard
2020-05-27 1:26 ` [PATCH 2/3] misc: xilinx-sdfec: cleanup return value in xsdfec_table_write() John Hubbard
@ 2020-05-27 1:26 ` John Hubbard
2020-05-29 8:29 ` [PATCH 0/3] " Dragan Cvetic
3 siblings, 0 replies; 6+ messages in thread
From: John Hubbard @ 2020-05-27 1:26 UTC (permalink / raw)
To: LKML
Cc: Souptick Joarder, John Hubbard, Derek Kiernan, Dragan Cvetic,
Arnd Bergmann, Greg Kroah-Hartman, Michal Simek,
linux-arm-kernel
This 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/
Cc: Derek Kiernan <derek.kiernan@xilinx.com>
Cc: Dragan Cvetic <dragan.cvetic@xilinx.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
drivers/misc/xilinx_sdfec.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
index 7e2ee3e547f2..cda3559025d5 100644
--- a/drivers/misc/xilinx_sdfec.c
+++ b/drivers/misc/xilinx_sdfec.c
@@ -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;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* RE: [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()
2020-05-27 1:26 [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages() John Hubbard
` (2 preceding siblings ...)
2020-05-27 1:26 ` [PATCH 3/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages() John Hubbard
@ 2020-05-29 8:29 ` Dragan Cvetic
2020-05-29 19:15 ` John Hubbard
3 siblings, 1 reply; 6+ messages in thread
From: Dragan Cvetic @ 2020-05-29 8:29 UTC (permalink / raw)
To: John Hubbard, LKML
Cc: Souptick Joarder, Derek Kiernan, Arnd Bergmann,
Greg Kroah-Hartman, Michal Simek, linux-arm-kernel
Hi John,
Thank you for the suggestion, please find my comment below:
> -----Original Message-----
> From: John Hubbard <jhubbard@nvidia.com>
> Sent: Wednesday 27 May 2020 02:26
> To: LKML <linux-kernel@vger.kernel.org>
> Cc: Souptick Joarder <jrdr.linux@gmail.com>; John Hubbard <jhubbard@nvidia.com>; Derek Kiernan <dkiernan@xilinx.com>; Dragan
> Cvetic <draganc@xilinx.com>; Arnd Bergmann <arnd@arndb.de>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Michal Simek
> <michals@xilinx.com>; linux-arm-kernel@lists.infradead.org
> Subject: [PATCH 0/3] 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!
>
> Cc: Derek Kiernan <derek.kiernan@xilinx.com>
> Cc: Dragan Cvetic <dragan.cvetic@xilinx.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Michal Simek <michal.simek@xilinx.com>
> Cc: linux-arm-kernel@lists.infradead.org
>
> 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()
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.
>
> drivers/misc/xilinx_sdfec.c | 30 +++++++++++++++++-------------
> 1 file changed, 17 insertions(+), 13 deletions(-)
>
>
> base-commit: 9cb1fd0efd195590b828b9b865421ad345a4a145
> --
> 2.26.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()
2020-05-29 8:29 ` [PATCH 0/3] " Dragan Cvetic
@ 2020-05-29 19:15 ` John Hubbard
0 siblings, 0 replies; 6+ messages in thread
From: John Hubbard @ 2020-05-29 19:15 UTC (permalink / raw)
To: Dragan Cvetic, LKML
Cc: Souptick Joarder, Derek Kiernan, Arnd Bergmann,
Greg Kroah-Hartman, Michal Simek, linux-arm-kernel
On 2020-05-29 01:29, Dragan Cvetic wrote:
> Hi John,
>
> Thank you for the suggestion, please find my comment below:
>
>> -----Original Message-----
>> From: John Hubbard <jhubbard@nvidia.com>
>> Sent: Wednesday 27 May 2020 02:26
>> To: LKML <linux-kernel@vger.kernel.org>
>> Cc: Souptick Joarder <jrdr.linux@gmail.com>; John Hubbard <jhubbard@nvidia.com>; Derek Kiernan <dkiernan@xilinx.com>; Dragan
>> Cvetic <draganc@xilinx.com>; Arnd Bergmann <arnd@arndb.de>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Michal Simek
>> <michals@xilinx.com>; linux-arm-kernel@lists.infradead.org
>> Subject: [PATCH 0/3] 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!
>>
>> Cc: Derek Kiernan <derek.kiernan@xilinx.com>
>> Cc: Dragan Cvetic <dragan.cvetic@xilinx.com>
>> Cc: Arnd Bergmann <arnd@arndb.de>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: Michal Simek <michal.simek@xilinx.com>
>> Cc: linux-arm-kernel@lists.infradead.org
>>
>> 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()
>
>
> 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,
--
John Hubbard
NVIDIA
>>
>> drivers/misc/xilinx_sdfec.c | 30 +++++++++++++++++-------------
>> 1 file changed, 17 insertions(+), 13 deletions(-)
>>
>>
>> base-commit: 9cb1fd0efd195590b828b9b865421ad345a4a145
>> --
>> 2.26.2
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-05-29 19:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 1:26 [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages() John Hubbard
2020-05-27 1:26 ` [PATCH 1/3] misc: xilinx-sdfec: improve get_user_pages_fast() error handling John Hubbard
2020-05-27 1:26 ` [PATCH 2/3] misc: xilinx-sdfec: cleanup return value in xsdfec_table_write() John Hubbard
2020-05-27 1:26 ` [PATCH 3/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages() John Hubbard
2020-05-29 8:29 ` [PATCH 0/3] " Dragan Cvetic
2020-05-29 19:15 ` John Hubbard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).