misc: fastrpc: copy to user only for non-DMA-BUF heap buffers
PATCH 1/1 misc: fastrpc: copy to user only for non-DMA-BUF heap buffers
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.
--- drivers/misc/fastrpc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/misc/fastrpc.c +10 -8
@@ -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); + } } }
Signature · 1 line
2.7.4
Greg KH
maintainerQuoted 3 lines · Jeya R
fastrpc_put_argsis 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?
Quoted 11 lines
Signed-off-by Jeya R <[email protected]>--- drivers/misc/fastrpc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)drivers/misc/fastrpc.c +0
-0
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 895
Quoted 9 lines
drivers/misc/fastrpc.c +3
-3@@ -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.
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 903
Quoted 13 lines
drivers/misc/fastrpc.c +7
-5+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
Quoted 6 lines · Greg KH
Quoted 3 lines · Jeya R
fastrpc_put_argsis 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.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Jeya R <[email protected]>--- drivers/misc/fastrpc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)drivers/misc/fastrpc.c +0
-0@@ -890,15 +890,17 @@ static int fastrpc_put_args(structfastrpc_invoke_ctx *ctx, inbufs =REMOTE_SCALARS_INBUFS (ctx->sc);
Quoted 11 lines
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 895
Quoted 7 lines
drivers/misc/fastrpc.c +3
-3for (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_tis 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.
Quoted 18 lines
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 903
Quoted 13 lines
drivers/misc/fastrpc.c +7
-5+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?
Quoted 3 lines
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
Quoted 3 lines
thanks,
greg k-h
Greg KH
maintainerQuoted 58 lines · On Thu, Sep 23, 2021 at 03:54:15PM +0530, [email protected] wrote:
Quoted 6 lines · Greg KH
Quoted 3 lines · Jeya R
fastrpc_put_argsis 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.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Jeya R <[email protected]>--- drivers/misc/fastrpc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)drivers/misc/fastrpc.c +0
-0@@ -890,15 +890,17 @@ static int fastrpc_put_args(structfastrpc_invoke_ctx *ctx, inbufs =REMOTE_SCALARS_INBUFS (ctx->sc);Quoted 11 lines
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 895
Quoted 7 lines
drivers/misc/fastrpc.c +3
-3for (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_tis 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.
Quoted 18 lines
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 903
Quoted 13 lines
drivers/misc/fastrpc.c +7
-5+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?
Quoted 7 lines
Quoted 3 lines
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?
Quoted 63 lines · Greg KH
Quoted 62 lines · On Thu, Sep 23, 2021 at 03:54:15PM +0530, [email protected] wrote:
Quoted 6 lines · Greg KH
Quoted 3 lines · Jeya R
fastrpc_put_argsis 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.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Jeya R <[email protected]>--- drivers/misc/fastrpc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)drivers/misc/fastrpc.c +0
-0@@ -890,15 +890,17 @@ static int fastrpc_put_args(structfastrpc_invoke_ctx *ctx, inbufs =REMOTE_SCALARS_INBUFS (ctx->sc);Quoted 11 lines
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 895
Quoted 7 lines
drivers/misc/fastrpc.c +3
-3for (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_tis 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.
Quoted 21 lines
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 903
Quoted 13 lines
drivers/misc/fastrpc.c +7
-5+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?
Quoted 5 lines
Quoted 3 lines
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.
Greg KH
maintainerQuoted 70 lines · On Fri, Sep 24, 2021 at 11:55:32AM +0530, [email protected] wrote:
Quoted 69 lines · Greg KH
Quoted 67 lines · On Thu, Sep 23, 2021 at 03:54:15PM +0530, [email protected] wrote:
Quoted 6 lines · Greg KH
Quoted 3 lines · Jeya R
fastrpc_put_argsis 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.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Jeya R <[email protected]>--- drivers/misc/fastrpc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)drivers/misc/fastrpc.c +0
-0@@ -890,15 +890,17 @@ static int fastrpc_put_args(structfastrpc_invoke_ctx *ctx, inbufs =REMOTE_SCALARS_INBUFS (ctx->sc);Quoted 11 lines
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 895
Quoted 7 lines
drivers/misc/fastrpc.c +3
-3for (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_tis 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.
Quoted 18 lines
drivers/misc/fastrpc.c static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, · line 903
Quoted 13 lines
drivers/misc/fastrpc.c +7
-5+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?
Quoted 3 lines
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.
Quoted 5 lines
Quoted 1 line
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