linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: rts5208: Convert kmap() to kmap_local_page()
@ 2022-03-28 11:24 Fabio M. De Francesco
  2022-03-28 15:41 ` Ira Weiny
  0 siblings, 1 reply; 4+ messages in thread
From: Fabio M. De Francesco @ 2022-03-28 11:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Benjamin Philip, Bart Van Assche,
	Martin K. Petersen, Charlie Sands, Mitali Borkar, Colin Ian King,
	linux-staging, linux-kernel, ira.weiny
  Cc: Fabio M. De Francesco

The use of kmap() is being deprecated and kmap_local_page() is faster.
Use kmap_local_page() in place of kmap().

Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 drivers/staging/rts5208/rtsx_transport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
index 805dc18fac0a..de690d7ee5e3 100644
--- a/drivers/staging/rts5208/rtsx_transport.c
+++ b/drivers/staging/rts5208/rtsx_transport.c
@@ -92,13 +92,13 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
 			while (sglen > 0) {
 				unsigned int plen = min(sglen, (unsigned int)
 						PAGE_SIZE - poff);
-				unsigned char *ptr = kmap(page);
+				unsigned char *ptr = kmap_local_page(page);
 
 				if (dir == TO_XFER_BUF)
 					memcpy(ptr + poff, buffer + cnt, plen);
 				else
 					memcpy(buffer + cnt, ptr + poff, plen);
-				kunmap(page);
+				kunmap_local(ptr);
 
 				/* Start at the beginning of the next page */
 				poff = 0;
-- 
2.34.1


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

* Re: [PATCH] staging: rts5208: Convert kmap() to kmap_local_page()
  2022-03-28 11:24 [PATCH] staging: rts5208: Convert kmap() to kmap_local_page() Fabio M. De Francesco
@ 2022-03-28 15:41 ` Ira Weiny
  2022-03-28 16:11   ` Ira Weiny
  2022-03-28 17:21   ` Fabio M. De Francesco
  0 siblings, 2 replies; 4+ messages in thread
From: Ira Weiny @ 2022-03-28 15:41 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Greg Kroah-Hartman, Benjamin Philip, Bart Van Assche,
	Martin K. Petersen, Charlie Sands, Mitali Borkar, Colin Ian King,
	linux-staging, linux-kernel

On Mon, Mar 28, 2022 at 01:24:40PM +0200, Fabio M. De Francesco wrote:
> The use of kmap() is being deprecated and kmap_local_page() is faster.
> Use kmap_local_page() in place of kmap().

Thanks for the patch!  I have just a couple of comments.

kmap_local_page() is not necessarily faster than kmap() but it is more correct
in this case.  You should mention why.

Also to help with kmap_local_page() there are a number of helpers implemented
in highmem.h for things like memcpy, memmove, etc.

Check out memcpy_page() for this use case.

Thank you!
Ira

> 
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
>  drivers/staging/rts5208/rtsx_transport.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
> index 805dc18fac0a..de690d7ee5e3 100644
> --- a/drivers/staging/rts5208/rtsx_transport.c
> +++ b/drivers/staging/rts5208/rtsx_transport.c
> @@ -92,13 +92,13 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
>  			while (sglen > 0) {
>  				unsigned int plen = min(sglen, (unsigned int)
>  						PAGE_SIZE - poff);
> -				unsigned char *ptr = kmap(page);
> +				unsigned char *ptr = kmap_local_page(page);
>  
>  				if (dir == TO_XFER_BUF)
>  					memcpy(ptr + poff, buffer + cnt, plen);
>  				else
>  					memcpy(buffer + cnt, ptr + poff, plen);
> -				kunmap(page);
> +				kunmap_local(ptr);
>  
>  				/* Start at the beginning of the next page */
>  				poff = 0;
> -- 
> 2.34.1
> 

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

* Re: [PATCH] staging: rts5208: Convert kmap() to kmap_local_page()
  2022-03-28 15:41 ` Ira Weiny
@ 2022-03-28 16:11   ` Ira Weiny
  2022-03-28 17:21   ` Fabio M. De Francesco
  1 sibling, 0 replies; 4+ messages in thread
From: Ira Weiny @ 2022-03-28 16:11 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Greg Kroah-Hartman, Benjamin Philip, Bart Van Assche,
	Martin K. Petersen, Charlie Sands, Mitali Borkar, Colin Ian King,
	linux-staging, linux-kernel, iweiny, ira.weiny

On Mon, Mar 28, 2022 at 08:41:53AM -0700, Ira Weiny wrote:
> On Mon, Mar 28, 2022 at 01:24:40PM +0200, Fabio M. De Francesco wrote:
> > The use of kmap() is being deprecated and kmap_local_page() is faster.
> > Use kmap_local_page() in place of kmap().
> 
> Thanks for the patch!  I have just a couple of comments.
> 
> kmap_local_page() is not necessarily faster than kmap() but it is more correct
> in this case.  You should mention why.
> 
> Also to help with kmap_local_page() there are a number of helpers implemented
> in highmem.h for things like memcpy, memmove, etc.
> 
> Check out memcpy_page() for this use case.
> 
> Thank you!
> Ira
> 

Also I believe this is work toward the Outreachy program.  If so be sure to
follow the guidelines on this page:

https://kernelnewbies.org/Outreachyfirstpatch

In particular, it does not look like you cc'ed the Outreachy list.

Thanks!
Ira

> > 
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> >  drivers/staging/rts5208/rtsx_transport.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
> > index 805dc18fac0a..de690d7ee5e3 100644
> > --- a/drivers/staging/rts5208/rtsx_transport.c
> > +++ b/drivers/staging/rts5208/rtsx_transport.c
> > @@ -92,13 +92,13 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
> >  			while (sglen > 0) {
> >  				unsigned int plen = min(sglen, (unsigned int)
> >  						PAGE_SIZE - poff);
> > -				unsigned char *ptr = kmap(page);
> > +				unsigned char *ptr = kmap_local_page(page);
> >  
> >  				if (dir == TO_XFER_BUF)
> >  					memcpy(ptr + poff, buffer + cnt, plen);
> >  				else
> >  					memcpy(buffer + cnt, ptr + poff, plen);
> > -				kunmap(page);
> > +				kunmap_local(ptr);
> >  
> >  				/* Start at the beginning of the next page */
> >  				poff = 0;
> > -- 
> > 2.34.1
> > 

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

* Re: [PATCH] staging: rts5208: Convert kmap() to kmap_local_page()
  2022-03-28 15:41 ` Ira Weiny
  2022-03-28 16:11   ` Ira Weiny
@ 2022-03-28 17:21   ` Fabio M. De Francesco
  1 sibling, 0 replies; 4+ messages in thread
From: Fabio M. De Francesco @ 2022-03-28 17:21 UTC (permalink / raw)
  To: Ira Weiny
  Cc: Greg Kroah-Hartman, Benjamin Philip, Bart Van Assche,
	Martin K. Petersen, Charlie Sands, Mitali Borkar, Colin Ian King,
	linux-staging, linux-kernel

On luned? 28 marzo 2022 17:41:53 CEST Ira Weiny wrote:
> On Mon, Mar 28, 2022 at 01:24:40PM +0200, Fabio M. De Francesco wrote:
> > The use of kmap() is being deprecated and kmap_local_page() is faster.
> > Use kmap_local_page() in place of kmap().
> 
> Thanks for the patch!  

Thanks for your review!

> I have just a couple of comments.
> 
> kmap_local_page() is not necessarily faster than kmap() but it is more correct
> in this case.  You should mention why.

Sure, my mistake. Thomas G. was talking about kmap_atomic() when he wrote that
it is "faster". It does not apply to kmap_local_page(). 

What could justify the use of kmap_local_page() is that "The mapping is per 
thread, CPU local and not globally visible.". Therefore this code is the right 
context where to use kmap_local_page() in place of kmap().

At this moment I think that I might change my commit message and write something
like the above.

However, I'll research more information during the next days. In the meantime 
I'm also going to take a look at the differences in implementation.

> Also to help with kmap_local_page() there are a number of helpers implemented
> in highmem.h for things like memcpy, memmove, etc.
> 
> Check out memcpy_page() for this use case.

Aren't memcpy_to_page() and memcpy_from_page() better suited for the two 
different branches of the "if" statement?

Thank you,

Fabio M. De Francesco

> 
> Thank you!
> Ira
> 
> > 
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> >  drivers/staging/rts5208/rtsx_transport.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
> > index 805dc18fac0a..de690d7ee5e3 100644
> > --- a/drivers/staging/rts5208/rtsx_transport.c
> > +++ b/drivers/staging/rts5208/rtsx_transport.c
> > @@ -92,13 +92,13 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
> >  			while (sglen > 0) {
> >  				unsigned int plen = min(sglen, (unsigned int)
> >  						PAGE_SIZE - poff);
> > -				unsigned char *ptr = kmap(page);
> > +				unsigned char *ptr = kmap_local_page(page);
> >  
> >  				if (dir == TO_XFER_BUF)
> >  					memcpy(ptr + poff, buffer + cnt, plen);
> >  				else
> >  					memcpy(buffer + cnt, ptr + poff, plen);
> > -				kunmap(page);
> > +				kunmap_local(ptr);
> >  
> >  				/* Start at the beginning of the next page */
> >  				poff = 0;
> > -- 
> > 2.34.1
> > 
> 





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

end of thread, other threads:[~2022-03-28 17:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-28 11:24 [PATCH] staging: rts5208: Convert kmap() to kmap_local_page() Fabio M. De Francesco
2022-03-28 15:41 ` Ira Weiny
2022-03-28 16:11   ` Ira Weiny
2022-03-28 17:21   ` Fabio M. De Francesco

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).