All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] misc: fastrpc: copy to user only for non-DMA-BUF heap buffers
@ 2021-09-23  8:37 Jeya R
  2021-09-23  8:49 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Jeya R @ 2021-09-23  8:37 UTC (permalink / raw)
  To: linux-arm-msm, srinivas.kandagatla
  Cc: Jeya R, gregkh, linux-kernel, fastrpc.upstream

fastrpc_put_args is copying all the output buffers to user. For large
number of output context buffers, this might cause performance
degradation. Copying is not needed for DMA-BUF heap buffers.

Signed-off-by: Jeya R <jeyr@codeaurora.org>
---
 drivers/misc/fastrpc.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index beda610..536eabf 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -890,15 +890,17 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
 	inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
 
 	for (i = inbufs; i < ctx->nbufs; ++i) {
-		void *src = (void *)(uintptr_t)rpra[i].pv;
-		void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
-		u64 len = rpra[i].len;
+		if (!ctx->maps[i]) {
+			void *src = (void *)(uintptr_t)rpra[i].pv;
+			void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
+			u64 len = rpra[i].len;
 
-		if (!kernel) {
-			if (copy_to_user((void __user *)dst, src, len))
-				return -EFAULT;
-		} else {
-			memcpy(dst, src, len);
+			if (!kernel) {
+				if (copy_to_user((void __user *)dst, src, len))
+					return -EFAULT;
+			} else {
+				memcpy(dst, src, len);
+			}
 		}
 	}
 
-- 
2.7.4


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

* Re: [PATCH] misc: fastrpc: copy to user only for non-DMA-BUF heap buffers
  2021-09-23  8:37 [PATCH] misc: fastrpc: copy to user only for non-DMA-BUF heap buffers Jeya R
@ 2021-09-23  8:49 ` Greg KH
  2021-09-23 10:24   ` jeyr
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2021-09-23  8:49 UTC (permalink / raw)
  To: Jeya R; +Cc: linux-arm-msm, srinivas.kandagatla, linux-kernel, fastrpc.upstream

On Thu, Sep 23, 2021 at 02:07:52PM +0530, Jeya R wrote:
> fastrpc_put_args is copying all the output buffers to user. For large
> number of output context buffers, this might cause performance
> degradation. Copying is not needed for DMA-BUF heap buffers.

What does "performance degradation" really mean?

> 
> Signed-off-by: Jeya R <jeyr@codeaurora.org>
> ---
>  drivers/misc/fastrpc.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index beda610..536eabf 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -890,15 +890,17 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
>  	inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
>  
>  	for (i = inbufs; i < ctx->nbufs; ++i) {
> -		void *src = (void *)(uintptr_t)rpra[i].pv;
> -		void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
> -		u64 len = rpra[i].len;
> +		if (!ctx->maps[i]) {
> +			void *src = (void *)(uintptr_t)rpra[i].pv;
> +			void *dst = (void *)(uintptr_t)ctx->args[i].ptr;

uintptr_t is not a kernel variable type.  Please use the real kernel
type for this as you are touching these lines.

> +			u64 len = rpra[i].len;
>  
> -		if (!kernel) {
> -			if (copy_to_user((void __user *)dst, src, len))
> -				return -EFAULT;
> -		} else {
> -			memcpy(dst, src, len);
> +			if (!kernel) {
> +				if (copy_to_user((void __user *)dst, src, len))
> +					return -EFAULT;
> +			} else {
> +				memcpy(dst, src, len);
> +			}

So you were copying buffers that didn't need to be copied?  So you are
now doing less work?  Or is this fixing a bug where you were copying
things that you should not have been copying?

What commit does this fix?  Does this need to go to the stable kernel
trees?

thanks,

greg k-h

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

* Re: [PATCH] misc: fastrpc: copy to user only for non-DMA-BUF heap buffers
  2021-09-23  8:49 ` Greg KH
@ 2021-09-23 10:24   ` jeyr
  2021-09-23 17:43     ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: jeyr @ 2021-09-23 10:24 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-arm-msm, srinivas.kandagatla, linux-kernel, fastrpc.upstream

On 2021-09-23 14:19, Greg KH wrote:
> On Thu, Sep 23, 2021 at 02:07:52PM +0530, Jeya R wrote:
>> fastrpc_put_args is copying all the output buffers to user. For large
>> number of output context buffers, this might cause performance
>> degradation. Copying is not needed for DMA-BUF heap buffers.
> 
> What does "performance degradation" really mean?

Unnecessary copying for large number of buffers would cause some
additional time which would get added to overall fastrpc call cost.

> 
>> 
>> Signed-off-by: Jeya R <jeyr@codeaurora.org>
>> ---
>>  drivers/misc/fastrpc.c | 18 ++++++++++--------
>>  1 file changed, 10 insertions(+), 8 deletions(-)
>> 
>> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
>> index beda610..536eabf 100644
>> --- a/drivers/misc/fastrpc.c
>> +++ b/drivers/misc/fastrpc.c
>> @@ -890,15 +890,17 @@ static int fastrpc_put_args(struct 
>> fastrpc_invoke_ctx *ctx,
>>  	inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
>> 
>>  	for (i = inbufs; i < ctx->nbufs; ++i) {
>> -		void *src = (void *)(uintptr_t)rpra[i].pv;
>> -		void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
>> -		u64 len = rpra[i].len;
>> +		if (!ctx->maps[i]) {
>> +			void *src = (void *)(uintptr_t)rpra[i].pv;
>> +			void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
> 
> uintptr_t is not a kernel variable type.  Please use the real kernel
> type for this as you are touching these lines.
> 

Sure, thanks for pointing this. Will update this in the next patch.

>> +			u64 len = rpra[i].len;
>> 
>> -		if (!kernel) {
>> -			if (copy_to_user((void __user *)dst, src, len))
>> -				return -EFAULT;
>> -		} else {
>> -			memcpy(dst, src, len);
>> +			if (!kernel) {
>> +				if (copy_to_user((void __user *)dst, src, len))
>> +					return -EFAULT;
>> +			} else {
>> +				memcpy(dst, src, len);
>> +			}
> 
> So you were copying buffers that didn't need to be copied?  So you are
> now doing less work?  Or is this fixing a bug where you were copying
> things that you should not have been copying?
> 
> What commit does this fix?  Does this need to go to the stable kernel
> trees?
> 

Yes, not all buffer needs to be copied. This change would avoid 
unnecessary
copying of buffers. Not adding fix tag as it's not exactly fixing any 
bug.
This should go to stable kernel trees.

Thanks

> thanks,
> 
> greg k-h

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

* Re: [PATCH] misc: fastrpc: copy to user only for non-DMA-BUF heap buffers
  2021-09-23 10:24   ` jeyr
@ 2021-09-23 17:43     ` Greg KH
  2021-09-24  6:25       ` jeyr
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2021-09-23 17:43 UTC (permalink / raw)
  To: jeyr; +Cc: linux-arm-msm, srinivas.kandagatla, linux-kernel, fastrpc.upstream

On Thu, Sep 23, 2021 at 03:54:15PM +0530, jeyr@codeaurora.org wrote:
> On 2021-09-23 14:19, Greg KH wrote:
> > On Thu, Sep 23, 2021 at 02:07:52PM +0530, Jeya R wrote:
> > > fastrpc_put_args is copying all the output buffers to user. For large
> > > number of output context buffers, this might cause performance
> > > degradation. Copying is not needed for DMA-BUF heap buffers.
> > 
> > What does "performance degradation" really mean?
> 
> Unnecessary copying for large number of buffers would cause some
> additional time which would get added to overall fastrpc call cost.
> 
> > 
> > > 
> > > Signed-off-by: Jeya R <jeyr@codeaurora.org>
> > > ---
> > >  drivers/misc/fastrpc.c | 18 ++++++++++--------
> > >  1 file changed, 10 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> > > index beda610..536eabf 100644
> > > --- a/drivers/misc/fastrpc.c
> > > +++ b/drivers/misc/fastrpc.c
> > > @@ -890,15 +890,17 @@ static int fastrpc_put_args(struct
> > > fastrpc_invoke_ctx *ctx,
> > >  	inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
> > > 
> > >  	for (i = inbufs; i < ctx->nbufs; ++i) {
> > > -		void *src = (void *)(uintptr_t)rpra[i].pv;
> > > -		void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
> > > -		u64 len = rpra[i].len;
> > > +		if (!ctx->maps[i]) {
> > > +			void *src = (void *)(uintptr_t)rpra[i].pv;
> > > +			void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
> > 
> > uintptr_t is not a kernel variable type.  Please use the real kernel
> > type for this as you are touching these lines.
> > 
> 
> Sure, thanks for pointing this. Will update this in the next patch.
> 
> > > +			u64 len = rpra[i].len;
> > > 
> > > -		if (!kernel) {
> > > -			if (copy_to_user((void __user *)dst, src, len))
> > > -				return -EFAULT;
> > > -		} else {
> > > -			memcpy(dst, src, len);
> > > +			if (!kernel) {
> > > +				if (copy_to_user((void __user *)dst, src, len))
> > > +					return -EFAULT;
> > > +			} else {
> > > +				memcpy(dst, src, len);
> > > +			}
> > 
> > So you were copying buffers that didn't need to be copied?  So you are
> > now doing less work?  Or is this fixing a bug where you were copying
> > things that you should not have been copying?
> > 
> > What commit does this fix?  Does this need to go to the stable kernel
> > trees?
> > 
> 
> Yes, not all buffer needs to be copied. This change would avoid unnecessary
> copying of buffers. Not adding fix tag as it's not exactly fixing any bug.
> This should go to stable kernel trees.

If it's not fixing a bug, why should it go into the stable trees?

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

* Re: [PATCH] misc: fastrpc: copy to user only for non-DMA-BUF heap buffers
  2021-09-23 17:43     ` Greg KH
@ 2021-09-24  6:25       ` jeyr
  2021-09-24  6:55         ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: jeyr @ 2021-09-24  6:25 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-arm-msm, srinivas.kandagatla, linux-kernel, fastrpc.upstream

On 2021-09-23 23:13, Greg KH wrote:
> On Thu, Sep 23, 2021 at 03:54:15PM +0530, jeyr@codeaurora.org wrote:
>> On 2021-09-23 14:19, Greg KH wrote:
>> > On Thu, Sep 23, 2021 at 02:07:52PM +0530, Jeya R wrote:
>> > > fastrpc_put_args is copying all the output buffers to user. For large
>> > > number of output context buffers, this might cause performance
>> > > degradation. Copying is not needed for DMA-BUF heap buffers.
>> >
>> > What does "performance degradation" really mean?
>> 
>> Unnecessary copying for large number of buffers would cause some
>> additional time which would get added to overall fastrpc call cost.
>> 
>> >
>> > >
>> > > Signed-off-by: Jeya R <jeyr@codeaurora.org>
>> > > ---
>> > >  drivers/misc/fastrpc.c | 18 ++++++++++--------
>> > >  1 file changed, 10 insertions(+), 8 deletions(-)
>> > >
>> > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
>> > > index beda610..536eabf 100644
>> > > --- a/drivers/misc/fastrpc.c
>> > > +++ b/drivers/misc/fastrpc.c
>> > > @@ -890,15 +890,17 @@ static int fastrpc_put_args(struct
>> > > fastrpc_invoke_ctx *ctx,
>> > >  	inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
>> > >
>> > >  	for (i = inbufs; i < ctx->nbufs; ++i) {
>> > > -		void *src = (void *)(uintptr_t)rpra[i].pv;
>> > > -		void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
>> > > -		u64 len = rpra[i].len;
>> > > +		if (!ctx->maps[i]) {
>> > > +			void *src = (void *)(uintptr_t)rpra[i].pv;
>> > > +			void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
>> >
>> > uintptr_t is not a kernel variable type.  Please use the real kernel
>> > type for this as you are touching these lines.
>> >
>> 
>> Sure, thanks for pointing this. Will update this in the next patch.
>> 
>> > > +			u64 len = rpra[i].len;
>> > >
>> > > -		if (!kernel) {
>> > > -			if (copy_to_user((void __user *)dst, src, len))
>> > > -				return -EFAULT;
>> > > -		} else {
>> > > -			memcpy(dst, src, len);
>> > > +			if (!kernel) {
>> > > +				if (copy_to_user((void __user *)dst, src, len))
>> > > +					return -EFAULT;
>> > > +			} else {
>> > > +				memcpy(dst, src, len);
>> > > +			}
>> >
>> > So you were copying buffers that didn't need to be copied?  So you are
>> > now doing less work?  Or is this fixing a bug where you were copying
>> > things that you should not have been copying?
>> >
>> > What commit does this fix?  Does this need to go to the stable kernel
>> > trees?
>> >
>> 
>> Yes, not all buffer needs to be copied. This change would avoid 
>> unnecessary
>> copying of buffers. Not adding fix tag as it's not exactly fixing any 
>> bug.
>> This should go to stable kernel trees.
> 
> If it's not fixing a bug, why should it go into the stable trees?

This is not a bug fix, it can be considered as an enhancement and it can 
go in
to new release.

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

* Re: [PATCH] misc: fastrpc: copy to user only for non-DMA-BUF heap buffers
  2021-09-24  6:25       ` jeyr
@ 2021-09-24  6:55         ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2021-09-24  6:55 UTC (permalink / raw)
  To: jeyr; +Cc: linux-arm-msm, srinivas.kandagatla, linux-kernel, fastrpc.upstream

On Fri, Sep 24, 2021 at 11:55:32AM +0530, jeyr@codeaurora.org wrote:
> On 2021-09-23 23:13, Greg KH wrote:
> > On Thu, Sep 23, 2021 at 03:54:15PM +0530, jeyr@codeaurora.org wrote:
> > > On 2021-09-23 14:19, Greg KH wrote:
> > > > On Thu, Sep 23, 2021 at 02:07:52PM +0530, Jeya R wrote:
> > > > > fastrpc_put_args is copying all the output buffers to user. For large
> > > > > number of output context buffers, this might cause performance
> > > > > degradation. Copying is not needed for DMA-BUF heap buffers.
> > > >
> > > > What does "performance degradation" really mean?
> > > 
> > > Unnecessary copying for large number of buffers would cause some
> > > additional time which would get added to overall fastrpc call cost.
> > > 
> > > >
> > > > >
> > > > > Signed-off-by: Jeya R <jeyr@codeaurora.org>
> > > > > ---
> > > > >  drivers/misc/fastrpc.c | 18 ++++++++++--------
> > > > >  1 file changed, 10 insertions(+), 8 deletions(-)
> > > > >
> > > > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> > > > > index beda610..536eabf 100644
> > > > > --- a/drivers/misc/fastrpc.c
> > > > > +++ b/drivers/misc/fastrpc.c
> > > > > @@ -890,15 +890,17 @@ static int fastrpc_put_args(struct
> > > > > fastrpc_invoke_ctx *ctx,
> > > > >  	inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
> > > > >
> > > > >  	for (i = inbufs; i < ctx->nbufs; ++i) {
> > > > > -		void *src = (void *)(uintptr_t)rpra[i].pv;
> > > > > -		void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
> > > > > -		u64 len = rpra[i].len;
> > > > > +		if (!ctx->maps[i]) {
> > > > > +			void *src = (void *)(uintptr_t)rpra[i].pv;
> > > > > +			void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
> > > >
> > > > uintptr_t is not a kernel variable type.  Please use the real kernel
> > > > type for this as you are touching these lines.
> > > >
> > > 
> > > Sure, thanks for pointing this. Will update this in the next patch.
> > > 
> > > > > +			u64 len = rpra[i].len;
> > > > >
> > > > > -		if (!kernel) {
> > > > > -			if (copy_to_user((void __user *)dst, src, len))
> > > > > -				return -EFAULT;
> > > > > -		} else {
> > > > > -			memcpy(dst, src, len);
> > > > > +			if (!kernel) {
> > > > > +				if (copy_to_user((void __user *)dst, src, len))
> > > > > +					return -EFAULT;
> > > > > +			} else {
> > > > > +				memcpy(dst, src, len);
> > > > > +			}
> > > >
> > > > So you were copying buffers that didn't need to be copied?  So you are
> > > > now doing less work?  Or is this fixing a bug where you were copying
> > > > things that you should not have been copying?
> > > >
> > > > What commit does this fix?  Does this need to go to the stable kernel
> > > > trees?
> > > >
> > > 
> > > Yes, not all buffer needs to be copied. This change would avoid
> > > unnecessary
> > > copying of buffers. Not adding fix tag as it's not exactly fixing
> > > any bug.
> > > This should go to stable kernel trees.
> > 
> > If it's not fixing a bug, why should it go into the stable trees?
> 
> This is not a bug fix, it can be considered as an enhancement and it can go
> in
> to new release.

Ok, please update and send a v2 with the needed changes.

thanks,

greg k-h

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

end of thread, other threads:[~2021-09-24  6:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23  8:37 [PATCH] misc: fastrpc: copy to user only for non-DMA-BUF heap buffers Jeya R
2021-09-23  8:49 ` Greg KH
2021-09-23 10:24   ` jeyr
2021-09-23 17:43     ` Greg KH
2021-09-24  6:25       ` jeyr
2021-09-24  6:55         ` Greg KH

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.