2020-05-27 04:37:21

by John Hubbard

[permalink] [raw]
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 <[email protected]>
Cc: Dragan Cvetic <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: [email protected]

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


2020-05-27 10:00:52

by John Hubbard

[permalink] [raw]
Subject: [PATCH 3/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()

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 <[email protected]>
Cc: Dragan Cvetic <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: [email protected]
Signed-off-by: John Hubbard <[email protected]>
---
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

2020-05-27 10:16:36

by John Hubbard

[permalink] [raw]
Subject: [PATCH 2/3] misc: xilinx-sdfec: cleanup return value in xsdfec_table_write()

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 <[email protected]>
Cc: Dragan Cvetic <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: [email protected]
Signed-off-by: John Hubbard <[email protected]>
---
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

2020-05-29 08:31:22

by Dragan Cvetic

[permalink] [raw]
Subject: RE: [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()

Hi John,

Thank you for the suggestion, please find my comment below:

> -----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: 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 <[email protected]>
> Cc: Dragan Cvetic <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Michal Simek <[email protected]>
> Cc: [email protected]
>
> 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

2020-05-29 19:20:22

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 0/3] misc: xilinx-sdfec: convert get_user_pages() --> pin_user_pages()

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 <[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: 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 <[email protected]>
>> Cc: Dragan Cvetic <[email protected]>
>> Cc: Arnd Bergmann <[email protected]>
>> Cc: Greg Kroah-Hartman <[email protected]>
>> Cc: Michal Simek <[email protected]>
>> Cc: [email protected]
>>
>> 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
>