mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] misc: fastrpc: fixes for v6.5
@ 2023-08-11 11:56 Srinivas Kandagatla
  2023-08-11 11:56 ` [PATCH 1/3] misc: fastrpc: Fix remote heap allocation request Srinivas Kandagatla
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2023-08-11 11:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Srinivas Kandagatla

Hi Greg,

Here are some fixes in fastrpc driver mostly around audio process domain
and secure memory allocation.

Can you please apply them for v6.5

thanks,
Srini

Ekansh Gupta (3):
  misc: fastrpc: Fix remote heap allocation request
  misc: fastrpc: Fix incorrect DMA mapping unmap request
  misc: fastrpc: Pass proper scm arguments for static process init

 drivers/misc/fastrpc.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

-- 
2.25.1


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

* [PATCH 1/3] misc: fastrpc: Fix remote heap allocation request
  2023-08-11 11:56 [PATCH 0/3] misc: fastrpc: fixes for v6.5 Srinivas Kandagatla
@ 2023-08-11 11:56 ` Srinivas Kandagatla
  2023-08-11 11:56 ` [PATCH 2/3] misc: fastrpc: Fix incorrect DMA mapping unmap request Srinivas Kandagatla
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2023-08-11 11:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Ekansh Gupta, stable, Srinivas Kandagatla

From: Ekansh Gupta <quic_ekangupt@quicinc.com>

Remote heap is used by DSP audioPD on need basis. This memory is
allocated from reserved CMA memory region and is then shared with
audioPD to use it for it's functionality.

Current implementation of remote heap is not allocating the memory
from CMA region, instead it is allocating the memory from SMMU
context bank. The arguments passed to scm call for the reassignment
of ownership is also not correct. Added changes to allocate CMA
memory and have a proper ownership reassignment.

Fixes: 532ad70c6d44 ("misc: fastrpc: Add mmap request assigning for static PD pool")
Cc: stable <stable@kernel.org>
Tested-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/misc/fastrpc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 9666d28037e1..2faabbd12755 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1866,7 +1866,11 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 		return -EINVAL;
 	}
 
-	err = fastrpc_buf_alloc(fl, fl->sctx->dev, req.size, &buf);
+	if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR)
+		err = fastrpc_remote_heap_alloc(fl, dev, req.size, &buf);
+	else
+		err = fastrpc_buf_alloc(fl, dev, req.size, &buf);
+
 	if (err) {
 		dev_err(dev, "failed to allocate buffer\n");
 		return err;
@@ -1905,12 +1909,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 
 	/* Add memory to static PD pool, protection thru hypervisor */
 	if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR && fl->cctx->vmcount) {
-		struct qcom_scm_vmperm perm;
-
-		perm.vmid = QCOM_SCM_VMID_HLOS;
-		perm.perm = QCOM_SCM_PERM_RWX;
-		err = qcom_scm_assign_mem(buf->phys, buf->size,
-			&fl->cctx->perms, &perm, 1);
+		err = qcom_scm_assign_mem(buf->phys, (u64)buf->size,
+			&fl->cctx->perms, fl->cctx->vmperms, fl->cctx->vmcount);
 		if (err) {
 			dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d",
 					buf->phys, buf->size, err);
-- 
2.25.1


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

* [PATCH 2/3] misc: fastrpc: Fix incorrect DMA mapping unmap request
  2023-08-11 11:56 [PATCH 0/3] misc: fastrpc: fixes for v6.5 Srinivas Kandagatla
  2023-08-11 11:56 ` [PATCH 1/3] misc: fastrpc: Fix remote heap allocation request Srinivas Kandagatla
@ 2023-08-11 11:56 ` Srinivas Kandagatla
  2023-08-11 11:56 ` [PATCH 3/3] misc: fastrpc: Pass proper scm arguments for static process init Srinivas Kandagatla
  2023-08-22 14:00 ` [PATCH 0/3] misc: fastrpc: fixes for v6.5 Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2023-08-11 11:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Ekansh Gupta, stable, Srinivas Kandagatla

From: Ekansh Gupta <quic_ekangupt@quicinc.com>

Scatterlist table is obtained during map create request and the same
table is used for DMA mapping unmap. In case there is any failure
while getting the sg_table, ERR_PTR is returned instead of sg_table.

When the map is getting freed, there is only a non-NULL check of
sg_table which will also be true in case failure was returned instead
of sg_table. This would result in improper unmap request. Add proper
check before setting map table to avoid bad unmap request.

Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context Invoke method")
Cc: stable <stable@kernel.org>
Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/misc/fastrpc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 2faabbd12755..8183c55283fb 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -756,6 +756,7 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 {
 	struct fastrpc_session_ctx *sess = fl->sctx;
 	struct fastrpc_map *map = NULL;
+	struct sg_table *table;
 	int err = 0;
 
 	if (!fastrpc_map_lookup(fl, fd, ppmap, true))
@@ -783,11 +784,12 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 		goto attach_err;
 	}
 
-	map->table = dma_buf_map_attachment_unlocked(map->attach, DMA_BIDIRECTIONAL);
-	if (IS_ERR(map->table)) {
-		err = PTR_ERR(map->table);
+	table = dma_buf_map_attachment_unlocked(map->attach, DMA_BIDIRECTIONAL);
+	if (IS_ERR(table)) {
+		err = PTR_ERR(table);
 		goto map_err;
 	}
+	map->table = table;
 
 	if (attr & FASTRPC_ATTR_SECUREMAP) {
 		map->phys = sg_phys(map->table->sgl);
-- 
2.25.1


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

* [PATCH 3/3] misc: fastrpc: Pass proper scm arguments for static process init
  2023-08-11 11:56 [PATCH 0/3] misc: fastrpc: fixes for v6.5 Srinivas Kandagatla
  2023-08-11 11:56 ` [PATCH 1/3] misc: fastrpc: Fix remote heap allocation request Srinivas Kandagatla
  2023-08-11 11:56 ` [PATCH 2/3] misc: fastrpc: Fix incorrect DMA mapping unmap request Srinivas Kandagatla
@ 2023-08-11 11:56 ` Srinivas Kandagatla
  2023-08-22 14:00 ` [PATCH 0/3] misc: fastrpc: fixes for v6.5 Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2023-08-11 11:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Ekansh Gupta, stable, Srinivas Kandagatla

From: Ekansh Gupta <quic_ekangupt@quicinc.com>

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>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/misc/fastrpc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 8183c55283fb..42c4f603ec81 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1324,13 +1324,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);
-- 
2.25.1


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

* Re: [PATCH 0/3] misc: fastrpc: fixes for v6.5
  2023-08-11 11:56 [PATCH 0/3] misc: fastrpc: fixes for v6.5 Srinivas Kandagatla
                   ` (2 preceding siblings ...)
  2023-08-11 11:56 ` [PATCH 3/3] misc: fastrpc: Pass proper scm arguments for static process init Srinivas Kandagatla
@ 2023-08-22 14:00 ` Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2023-08-22 14:00 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-kernel

On Fri, Aug 11, 2023 at 12:56:40PM +0100, Srinivas Kandagatla wrote:
> Hi Greg,
> 
> Here are some fixes in fastrpc driver mostly around audio process domain
> and secure memory allocation.
> 
> Can you please apply them for v6.5
> 
> thanks,
> Srini
> 
> Ekansh Gupta (3):
>   misc: fastrpc: Fix remote heap allocation request
>   misc: fastrpc: Fix incorrect DMA mapping unmap request
>   misc: fastrpc: Pass proper scm arguments for static process init
> 
>  drivers/misc/fastrpc.c | 35 +++++++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 14 deletions(-)
> 
> -- 
> 2.25.1
> 

Ick, sorry, it's too late for 6.5, I'll queue these up for 6.6-rc1 and
then they can be backported into 6.5.1

thanks,

greg k-h

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

end of thread, other threads:[~2023-08-22 14:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-11 11:56 [PATCH 0/3] misc: fastrpc: fixes for v6.5 Srinivas Kandagatla
2023-08-11 11:56 ` [PATCH 1/3] misc: fastrpc: Fix remote heap allocation request Srinivas Kandagatla
2023-08-11 11:56 ` [PATCH 2/3] misc: fastrpc: Fix incorrect DMA mapping unmap request Srinivas Kandagatla
2023-08-11 11:56 ` [PATCH 3/3] misc: fastrpc: Pass proper scm arguments for static process init Srinivas Kandagatla
2023-08-22 14:00 ` [PATCH 0/3] misc: fastrpc: fixes for v6.5 Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®