[v3] misc: fastrpc: Pass proper scm arguments for static process init

Message ID 1690952549-31819-1-git-send-email-quic_ekangupt@quicinc.com
State New
Headers
Series [v3] misc: fastrpc: Pass proper scm arguments for static process init |

Commit Message

Ekansh Gupta Aug. 2, 2023, 5:02 a.m. UTC
  Memory is allocated for dynamic loading when audio daemon is trying
to attach to audioPD on DSP side. This memory is allocated from
reserved CMA memory region and needs ownership assignment to
new VMID in order to use it from audioPD.

In the current implementation, arguments are not correctly passed
to the scm call which might result in failure of dynamic loading
on audioPD. Added changes to pass correct arguments during daemon
attach request.

Fixes: 	0871561055e6 ("misc: fastrpc: Add support for audiopd")
Cc: stable <stable@kernel.org>
Tested-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
---
Changes in v2:
  - Removed redundant code
Changes in v3:
  - Reuse channel context perms for source perms

 drivers/misc/fastrpc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
  

Comments

Srinivas Kandagatla Aug. 2, 2023, 1:37 p.m. UTC | #1
On 02/08/2023 06:02, Ekansh Gupta wrote:
> Memory is allocated for dynamic loading when audio daemon is trying
> to attach to audioPD on DSP side. This memory is allocated from
> reserved CMA memory region and needs ownership assignment to
> new VMID in order to use it from audioPD.
> 
> In the current implementation, arguments are not correctly passed
> to the scm call which might result in failure of dynamic loading
> on audioPD. Added changes to pass correct arguments during daemon
> attach request.
> 
> Fixes: 	0871561055e6 ("misc: fastrpc: Add support for audiopd")
> Cc: stable <stable@kernel.org>
> Tested-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
> Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
> ---
> Changes in v2:
>    - Removed redundant code
> Changes in v3:
>    - Reuse channel context perms for source perms
> 
>   drivers/misc/fastrpc.c | 16 ++++++++++------
>   1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 30d4d04..5a1268f 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -1280,8 +1280,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
>   		if (fl->cctx->vmcount) {
>   			err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys,
>   							(u64)fl->cctx->remote_heap->size,
> -							&fl->cctx->perms,
> -							fl->cctx->vmperms, fl->cctx->vmcount);
> +							&fl->cctx->perms, fl->cctx->vmperms, fl->cctx->vmcount);

this change does not look correct,  Looks totally like converting 
multiple lines to a single line.

--srini

>   			if (err) {
>   				dev_err(fl->sctx->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d",
>   					fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err);
> @@ -1322,13 +1321,18 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
>   	return 0;
>   err_invoke:
>   	if (fl->cctx->vmcount) {
> -		struct qcom_scm_vmperm perm;
> +		u64 src_perms = 0;
> +		struct qcom_scm_vmperm dst_perms;
> +		u32 i;
>   
> -		perm.vmid = QCOM_SCM_VMID_HLOS;
> -		perm.perm = QCOM_SCM_PERM_RWX;
> +		for (i = 0; i < fl->cctx->vmcount; i++)
> +			src_perms |= BIT(fl->cctx->vmperms[i].vmid);
> +
> +		dst_perms.vmid = QCOM_SCM_VMID_HLOS;
> +		dst_perms.perm = QCOM_SCM_PERM_RWX;
>   		err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys,
>   						(u64)fl->cctx->remote_heap->size,
> -						&fl->cctx->perms, &perm, 1);
> +						&src_perms, &dst_perms, 1);
>   		if (err)
>   			dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d",
>   				fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err);
  
Ekansh Gupta Aug. 2, 2023, 1:47 p.m. UTC | #2
On 8/2/2023 7:07 PM, Srinivas Kandagatla wrote:
> 
> 
> On 02/08/2023 06:02, Ekansh Gupta wrote:
>> Memory is allocated for dynamic loading when audio daemon is trying
>> to attach to audioPD on DSP side. This memory is allocated from
>> reserved CMA memory region and needs ownership assignment to
>> new VMID in order to use it from audioPD.
>>
>> In the current implementation, arguments are not correctly passed
>> to the scm call which might result in failure of dynamic loading
>> on audioPD. Added changes to pass correct arguments during daemon
>> attach request.
>>
>> Fixes:     0871561055e6 ("misc: fastrpc: Add support for audiopd")
>> Cc: stable <stable@kernel.org>
>> Tested-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
>> Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
>> ---
>> Changes in v2:
>>    - Removed redundant code
>> Changes in v3:
>>    - Reuse channel context perms for source perms
>>
>>   drivers/misc/fastrpc.c | 16 ++++++++++------
>>   1 file changed, 10 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
>> index 30d4d04..5a1268f 100644
>> --- a/drivers/misc/fastrpc.c
>> +++ b/drivers/misc/fastrpc.c
>> @@ -1280,8 +1280,7 @@ static int 
>> fastrpc_init_create_static_process(struct fastrpc_user *fl,
>>           if (fl->cctx->vmcount) {
>>               err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys,
>>                               (u64)fl->cctx->remote_heap->size,
>> -                            &fl->cctx->perms,
>> -                            fl->cctx->vmperms, fl->cctx->vmcount);
>> +                            &fl->cctx->perms, fl->cctx->vmperms, 
>> fl->cctx->vmcount);
> 
> this change does not look correct,  Looks totally like converting 
> multiple lines to a single line.
Thanks for pointing this out, I might have missed keeping the correct 
formatting while reverting the change. I will update this in next patch.
> 
> --srini
> 
>>               if (err) {
>>                   dev_err(fl->sctx->dev, "Failed to assign memory with 
>> phys 0x%llx size 0x%llx err %d",
>>                       fl->cctx->remote_heap->phys, 
>> fl->cctx->remote_heap->size, err);
>> @@ -1322,13 +1321,18 @@ static int 
>> fastrpc_init_create_static_process(struct fastrpc_user *fl,
>>       return 0;
>>   err_invoke:
>>       if (fl->cctx->vmcount) {
>> -        struct qcom_scm_vmperm perm;
>> +        u64 src_perms = 0;
>> +        struct qcom_scm_vmperm dst_perms;
>> +        u32 i;
>> -        perm.vmid = QCOM_SCM_VMID_HLOS;
>> -        perm.perm = QCOM_SCM_PERM_RWX;
>> +        for (i = 0; i < fl->cctx->vmcount; i++)
>> +            src_perms |= BIT(fl->cctx->vmperms[i].vmid);
>> +
>> +        dst_perms.vmid = QCOM_SCM_VMID_HLOS;
>> +        dst_perms.perm = QCOM_SCM_PERM_RWX;
>>           err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys,
>>                           (u64)fl->cctx->remote_heap->size,
>> -                        &fl->cctx->perms, &perm, 1);
>> +                        &src_perms, &dst_perms, 1);
>>           if (err)
>>               dev_err(fl->sctx->dev, "Failed to assign memory phys 
>> 0x%llx size 0x%llx err %d",
>>                   fl->cctx->remote_heap->phys, 
>> fl->cctx->remote_heap->size, err);
  

Patch

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 30d4d04..5a1268f 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1280,8 +1280,7 @@  static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
 		if (fl->cctx->vmcount) {
 			err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys,
 							(u64)fl->cctx->remote_heap->size,
-							&fl->cctx->perms,
-							fl->cctx->vmperms, fl->cctx->vmcount);
+							&fl->cctx->perms, fl->cctx->vmperms, fl->cctx->vmcount);
 			if (err) {
 				dev_err(fl->sctx->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d",
 					fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err);
@@ -1322,13 +1321,18 @@  static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
 	return 0;
 err_invoke:
 	if (fl->cctx->vmcount) {
-		struct qcom_scm_vmperm perm;
+		u64 src_perms = 0;
+		struct qcom_scm_vmperm dst_perms;
+		u32 i;
 
-		perm.vmid = QCOM_SCM_VMID_HLOS;
-		perm.perm = QCOM_SCM_PERM_RWX;
+		for (i = 0; i < fl->cctx->vmcount; i++)
+			src_perms |= BIT(fl->cctx->vmperms[i].vmid);
+
+		dst_perms.vmid = QCOM_SCM_VMID_HLOS;
+		dst_perms.perm = QCOM_SCM_PERM_RWX;
 		err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys,
 						(u64)fl->cctx->remote_heap->size,
-						&fl->cctx->perms, &perm, 1);
+						&src_perms, &dst_perms, 1);
 		if (err)
 			dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d",
 				fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err);