linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/10] misc: fastrpc: Add audiopd support
@ 2022-09-09 13:39 Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 01/10] misc: fastrpc: Rename audio protection domain to root Abel Vesa
                   ` (12 more replies)
  0 siblings, 13 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

This patchset adds audiopd support to fastrpc.

The v2 of this patchset is here:
https://lore.kernel.org/all/20220902154900.3404524-1-abel.vesa@linaro.org/

Abel Vesa (10):
  misc: fastrpc: Rename audio protection domain to root
  misc: fastrpc: Add reserved mem support
  dt-bindings: misc: fastrpc: Document memory-region property
  misc: fastrpc: Add fastrpc_remote_heap_alloc
  misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
  misc: fastrpc: Rework fastrpc_req_munmap
  misc: fastrpc: Add support for audiopd
  misc: fastrpc: Safekeep mmaps on interrupted invoke
  misc: fastrpc: Add mmap request assigning for static PD pool
  misc: fastrpc: Add dma_mask to fastrpc_channel_ctx

 .../bindings/misc/qcom,fastrpc.yaml           |   5 +
 drivers/misc/fastrpc.c                        | 260 +++++++++++++++---
 include/uapi/misc/fastrpc.h                   |   7 +
 3 files changed, 240 insertions(+), 32 deletions(-)

-- 
2.34.1


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

* [PATCH v3 01/10] misc: fastrpc: Rename audio protection domain to root
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 02/10] misc: fastrpc: Add reserved mem support Abel Vesa
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

The AUDIO_PD will be done via static pd, so the proper name here is
actually ROOT_PD.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/misc/fastrpc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 58654d394d17..8bcbc560d4a7 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -83,7 +83,7 @@
 #define FASTRPC_RMID_INIT_MEM_UNMAP    11
 
 /* Protection Domain(PD) ids */
-#define AUDIO_PD	(0) /* also GUEST_OS PD? */
+#define ROOT_PD		(0)
 #define USER_PD		(1)
 #define SENSORS_PD	(2)
 
@@ -1889,7 +1889,7 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd,
 		err = fastrpc_invoke(fl, argp);
 		break;
 	case FASTRPC_IOCTL_INIT_ATTACH:
-		err = fastrpc_init_attach(fl, AUDIO_PD);
+		err = fastrpc_init_attach(fl, ROOT_PD);
 		break;
 	case FASTRPC_IOCTL_INIT_ATTACH_SNS:
 		err = fastrpc_init_attach(fl, SENSORS_PD);
-- 
2.34.1


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

* [PATCH v3 02/10] misc: fastrpc: Add reserved mem support
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 01/10] misc: fastrpc: Rename audio protection domain to root Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 03/10] dt-bindings: misc: fastrpc: Document memory-region property Abel Vesa
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

The reserved mem support is needed for CMA heap support, which will be
used by AUDIOPD.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/misc/fastrpc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 8bcbc560d4a7..9afc3528dab4 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 #include <linux/qcom_scm.h>
 #include <uapi/misc/fastrpc.h>
+#include <linux/of_reserved_mem.h>
 
 #define ADSP_DOMAIN_ID (0)
 #define MDSP_DOMAIN_ID (1)
@@ -2064,6 +2065,9 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
 		return -EINVAL;
 	}
 
+	if (of_reserved_mem_device_init_by_idx(rdev, rdev->of_node, 0))
+		dev_info(rdev, "no reserved DMA memory for FASTRPC\n");
+
 	vmcount = of_property_read_variable_u32_array(rdev->of_node,
 				"qcom,vmids", &vmids[0], 0, FASTRPC_MAX_VMIDS);
 	if (vmcount < 0)
-- 
2.34.1


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

* [PATCH v3 03/10] dt-bindings: misc: fastrpc: Document memory-region property
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 01/10] misc: fastrpc: Rename audio protection domain to root Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 02/10] misc: fastrpc: Add reserved mem support Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-09 14:44   ` Krzysztof Kozlowski
  2022-09-12 17:10   ` Rob Herring
  2022-09-09 13:39 ` [PATCH v3 04/10] misc: fastrpc: Add fastrpc_remote_heap_alloc Abel Vesa
                   ` (9 subsequent siblings)
  12 siblings, 2 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

Add memory-region property to the list of optional properties, specify
the value type and a definition. This property is used to specify the
memory region which should be used for remote heap CMA.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---

Changes since v2:
 * addressed Krzysztof's comment by specifying what's the use of the
   memory region

 Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml b/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
index f25924d33fa9..62c8a553b120 100644
--- a/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
+++ b/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
@@ -27,6 +27,11 @@ properties:
       - sdsp
       - cdsp
 
+  memory-region:
+    maxItems: 1
+    description:
+      Phandle to a node describing memory to be used for remote heap CMA.
+
   qcom,glink-channels:
     description:
       A list of channels tied to this function, used for matching
-- 
2.34.1


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

* [PATCH v3 04/10] misc: fastrpc: Add fastrpc_remote_heap_alloc
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (2 preceding siblings ...)
  2022-09-09 13:39 ` [PATCH v3 03/10] dt-bindings: misc: fastrpc: Document memory-region property Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 05/10] misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail Abel Vesa
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

Split fastrpc_buf_alloc in such a way it allows allocation of remote
heap too and add fastrpc_remote_heap_alloc to do so.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/misc/fastrpc.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 9afc3528dab4..d421e3e473d6 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -379,7 +379,7 @@ static void fastrpc_buf_free(struct fastrpc_buf *buf)
 	kfree(buf);
 }
 
-static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
+static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
 			     u64 size, struct fastrpc_buf **obuf)
 {
 	struct fastrpc_buf *buf;
@@ -407,14 +407,37 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
 		return -ENOMEM;
 	}
 
+	*obuf = buf;
+
+	return 0;
+}
+
+static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
+			     u64 size, struct fastrpc_buf **obuf)
+{
+	int ret;
+	struct fastrpc_buf *buf;
+
+	ret = __fastrpc_buf_alloc(fl, dev, size, obuf);
+	if (ret)
+		return ret;
+
+	buf = *obuf;
+
 	if (fl->sctx && fl->sctx->sid)
 		buf->phys += ((u64)fl->sctx->sid << 32);
 
-	*obuf = buf;
-
 	return 0;
 }
 
+static int fastrpc_remote_heap_alloc(struct fastrpc_user *fl, struct device *dev,
+				     u64 size, struct fastrpc_buf **obuf)
+{
+	struct device *rdev = &fl->cctx->rpdev->dev;
+
+	return  __fastrpc_buf_alloc(fl, rdev, size, obuf);
+}
+
 static void fastrpc_channel_ctx_free(struct kref *ref)
 {
 	struct fastrpc_channel_ctx *cctx;
-- 
2.34.1


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

* [PATCH v3 05/10] misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (3 preceding siblings ...)
  2022-09-09 13:39 ` [PATCH v3 04/10] misc: fastrpc: Add fastrpc_remote_heap_alloc Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 06/10] misc: fastrpc: Rework fastrpc_req_munmap Abel Vesa
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

Move the kref_init right after the allocation so that we can use
fastrpc_map_put on any following error case.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---

Changes since v2:
 * added Srinivas's R-b tag

 drivers/misc/fastrpc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index d421e3e473d6..8bc9cf5305c4 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -745,6 +745,8 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 		return -ENOMEM;
 
 	INIT_LIST_HEAD(&map->node);
+	kref_init(&map->refcount);
+
 	map->fl = fl;
 	map->fd = fd;
 	map->buf = dma_buf_get(fd);
@@ -771,7 +773,6 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 	map->size = len;
 	map->va = sg_virt(map->table->sgl);
 	map->len = len;
-	kref_init(&map->refcount);
 
 	if (attr & FASTRPC_ATTR_SECUREMAP) {
 		/*
@@ -801,7 +802,7 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 attach_err:
 	dma_buf_put(map->buf);
 get_err:
-	kfree(map);
+	fastrpc_map_put(map);
 
 	return err;
 }
-- 
2.34.1


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

* [PATCH v3 06/10] misc: fastrpc: Rework fastrpc_req_munmap
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (4 preceding siblings ...)
  2022-09-09 13:39 ` [PATCH v3 05/10] misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 07/10] misc: fastrpc: Add support for audiopd Abel Vesa
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

Move the lookup of the munmap request to the fastrpc_req_munmap and pass
on only the buf to the lower level fastrpc_req_munmap_impl. That way
we can use the lower level fastrpc_req_munmap_impl on error path in
fastrpc_req_mmap to free the buf without searching for the munmap
request it belongs to.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/misc/fastrpc.c | 47 +++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 8bc9cf5305c4..1f6d63bf637d 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1630,30 +1630,14 @@ static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp)
 	return 0;
 }
 
-static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
-				   struct fastrpc_req_munmap *req)
+static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *buf)
 {
 	struct fastrpc_invoke_args args[1] = { [0] = { 0 } };
-	struct fastrpc_buf *buf = NULL, *iter, *b;
 	struct fastrpc_munmap_req_msg req_msg;
 	struct device *dev = fl->sctx->dev;
 	int err;
 	u32 sc;
 
-	spin_lock(&fl->lock);
-	list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
-		if ((iter->raddr == req->vaddrout) && (iter->size == req->size)) {
-			buf = iter;
-			break;
-		}
-	}
-	spin_unlock(&fl->lock);
-
-	if (!buf) {
-		dev_err(dev, "mmap not in list\n");
-		return -EINVAL;
-	}
-
 	req_msg.pgid = fl->tgid;
 	req_msg.size = buf->size;
 	req_msg.vaddr = buf->raddr;
@@ -1679,12 +1663,29 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
 
 static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
 {
+	struct fastrpc_buf *buf = NULL, *iter, *b;
 	struct fastrpc_req_munmap req;
+	struct device *dev = fl->sctx->dev;
 
 	if (copy_from_user(&req, argp, sizeof(req)))
 		return -EFAULT;
 
-	return fastrpc_req_munmap_impl(fl, &req);
+	spin_lock(&fl->lock);
+	list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
+		if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) {
+			buf = iter;
+			break;
+		}
+	}
+	spin_unlock(&fl->lock);
+
+	if (!buf) {
+		dev_err(dev, "mmap\t\tpt 0x%09llx [len 0x%08llx] not in list\n",
+			req.vaddrout, req.size);
+		return -EINVAL;
+	}
+
+	return fastrpc_req_munmap_impl(fl, buf);
 }
 
 static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
@@ -1693,7 +1694,6 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 	struct fastrpc_buf *buf = NULL;
 	struct fastrpc_mmap_req_msg req_msg;
 	struct fastrpc_mmap_rsp_msg rsp_msg;
-	struct fastrpc_req_munmap req_unmap;
 	struct fastrpc_phy_page pages;
 	struct fastrpc_req_mmap req;
 	struct device *dev = fl->sctx->dev;
@@ -1755,11 +1755,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 	spin_unlock(&fl->lock);
 
 	if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
-		/* unmap the memory and release the buffer */
-		req_unmap.vaddrout = buf->raddr;
-		req_unmap.size = buf->size;
-		fastrpc_req_munmap_impl(fl, &req_unmap);
-		return -EFAULT;
+		err = -EFAULT;
+		goto err_assign;
 	}
 
 	dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n",
@@ -1767,6 +1764,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 
 	return 0;
 
+err_assign:
+	fastrpc_req_munmap_impl(fl, buf);
 err_invoke:
 	fastrpc_buf_free(buf);
 
-- 
2.34.1


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

* [PATCH v3 07/10] misc: fastrpc: Add support for audiopd
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (5 preceding siblings ...)
  2022-09-09 13:39 ` [PATCH v3 06/10] misc: fastrpc: Rework fastrpc_req_munmap Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke Abel Vesa
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

In order to be able to start the adsp listener for audiopd using adsprpcd,
we need to add the corresponding ioctl for creating a static process.
On that ioctl call we need to allocate the heap. Allocating the heap needs
to be happening only once and needs to be kept between different device
open calls, so attach it to the channel context to make sure that remains
until the RPMSG driver is removed. Then, if there are any VMIDs associated
with the static ADSP process, do a call to SCM to assign it.
And then, send all the necessary info related to heap to the DSP.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---

Changes since v2:
 * dropped blank line and unnecessary debug message, as Srinivas
   suggested
 * added mem assign rollback on invoke failure, as Srinivas suggested
 * changed the IOCTL number to 9, as Ekansh suggested (offline)

 drivers/misc/fastrpc.c      | 135 ++++++++++++++++++++++++++++++++++++
 include/uapi/misc/fastrpc.h |   7 ++
 2 files changed, 142 insertions(+)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 1f6d63bf637d..6b2a552dbdba 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -37,8 +37,20 @@
 #define FASTRPC_DSP_UTILITIES_HANDLE	2
 #define FASTRPC_CTXID_MASK (0xFF0)
 #define INIT_FILELEN_MAX (2 * 1024 * 1024)
+#define INIT_FILE_NAMELEN_MAX (128)
 #define FASTRPC_DEVICE_NAME	"fastrpc"
+
+/* Add memory to static PD pool, protection thru XPU */
+#define ADSP_MMAP_HEAP_ADDR  4
+/* MAP static DMA buffer on DSP User PD */
+#define ADSP_MMAP_DMA_BUFFER  6
+/* Add memory to static PD pool protection thru hypervisor */
+#define ADSP_MMAP_REMOTE_HEAP_ADDR  8
+/* Add memory to userPD pool, for user heap */
 #define ADSP_MMAP_ADD_PAGES 0x1000
+/* Add memory to userPD pool, for LLC heap */
+#define ADSP_MMAP_ADD_PAGES_LLC 0x3000,
+
 #define DSP_UNSUPPORTED_API (0x80000414)
 /* MAX NUMBER of DSP ATTRIBUTES SUPPORTED */
 #define FASTRPC_MAX_DSP_ATTRIBUTES (256)
@@ -72,6 +84,7 @@
 		FASTRPC_BUILD_SCALARS(0, method, in, out, 0, 0)
 
 #define FASTRPC_CREATE_PROCESS_NARGS	6
+#define FASTRPC_CREATE_STATIC_PROCESS_NARGS	3
 /* Remote Method id table */
 #define FASTRPC_RMID_INIT_ATTACH	0
 #define FASTRPC_RMID_INIT_RELEASE	1
@@ -261,6 +274,7 @@ struct fastrpc_channel_ctx {
 	u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES];
 	struct fastrpc_device *secure_fdevice;
 	struct fastrpc_device *fdevice;
+	struct fastrpc_buf *remote_heap;
 	bool secure;
 	bool unsigned_support;
 };
@@ -1167,6 +1181,7 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl,  u32 kernel,
 		spin_unlock(&fl->lock);
 		fastrpc_context_put(ctx);
 	}
+
 	if (err)
 		dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err);
 
@@ -1191,6 +1206,120 @@ static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_reques
 	return false;
 }
 
+static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
+					      char __user *argp)
+{
+	struct fastrpc_init_create_static init;
+	struct fastrpc_invoke_args *args;
+	struct fastrpc_phy_page pages[1];
+	char *name;
+	int err;
+	struct {
+		int pgid;
+		u32 namelen;
+		u32 pageslen;
+	} inbuf;
+	u32 sc;
+
+	args = kcalloc(FASTRPC_CREATE_STATIC_PROCESS_NARGS, sizeof(*args), GFP_KERNEL);
+	if (!args)
+		return -ENOMEM;
+
+	if (copy_from_user(&init, argp, sizeof(init))) {
+		err = -EFAULT;
+		goto err;
+	}
+
+	if (init.namelen > INIT_FILE_NAMELEN_MAX) {
+		err = -EINVAL;
+		goto err;
+	}
+
+	name = kzalloc(init.namelen, GFP_KERNEL);
+	if (!name) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	if (copy_from_user(name, (void __user *)(uintptr_t)init.name, init.namelen)) {
+		err = -EFAULT;
+		goto err_name;
+	}
+
+	if (!fl->cctx->remote_heap) {
+		err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen,
+						&fl->cctx->remote_heap);
+		if (err)
+			goto err_name;
+
+		/* Map if we have any heap VMIDs associated with this ADSP Static Process. */
+		if (fl->cctx->vmcount) {
+			unsigned int perms = BIT(QCOM_SCM_VMID_HLOS);
+
+			err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys,
+							(u64)fl->cctx->remote_heap->size, &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);
+				goto err_map;
+			}
+		}
+	}
+
+	inbuf.pgid = fl->tgid;
+	inbuf.namelen = init.namelen;
+	inbuf.pageslen = 0;
+	fl->pd = USER_PD;
+
+	args[0].ptr = (u64)(uintptr_t)&inbuf;
+	args[0].length = sizeof(inbuf);
+	args[0].fd = -1;
+
+	args[1].ptr = (u64)(uintptr_t)name;
+	args[1].length = inbuf.namelen;
+	args[1].fd = -1;
+
+	pages[0].addr = fl->cctx->remote_heap->phys;
+	pages[0].size = fl->cctx->remote_heap->size;
+
+	args[2].ptr = (u64)(uintptr_t) pages;
+	args[2].length = sizeof(*pages);
+	args[2].fd = -1;
+
+	sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE_STATIC, 3, 0);
+
+	err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE,
+				      sc, args);
+	if (err)
+		goto err_invoke;
+
+	kfree(args);
+
+	return 0;
+err_invoke:
+	if (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(fl->cctx->remote_heap->phys,
+						(u64)fl->cctx->remote_heap->size,
+						&(fl->cctx->vmperms[0].vmid), &perm, 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);
+	}
+err_map:
+	fastrpc_buf_free(fl->cctx->remote_heap);
+err_name:
+	kfree(name);
+err:
+	kfree(args);
+
+	return err;
+}
+
 static int fastrpc_init_create_process(struct fastrpc_user *fl,
 					char __user *argp)
 {
@@ -1918,6 +2047,9 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd,
 	case FASTRPC_IOCTL_INIT_ATTACH_SNS:
 		err = fastrpc_init_attach(fl, SENSORS_PD);
 		break;
+	case FASTRPC_IOCTL_INIT_CREATE_STATIC:
+		err = fastrpc_init_create_static_process(fl, argp);
+		break;
 	case FASTRPC_IOCTL_INIT_CREATE:
 		err = fastrpc_init_create_process(fl, argp);
 		break;
@@ -2183,6 +2315,9 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
 	if (cctx->secure_fdevice)
 		misc_deregister(&cctx->secure_fdevice->miscdev);
 
+	if (cctx->remote_heap)
+		fastrpc_buf_free(cctx->remote_heap);
+
 	of_platform_depopulate(&rpdev->dev);
 
 	cctx->rpdev = NULL;
diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h
index 5e29f2cfa42d..f33d914d8f46 100644
--- a/include/uapi/misc/fastrpc.h
+++ b/include/uapi/misc/fastrpc.h
@@ -13,6 +13,7 @@
 #define FASTRPC_IOCTL_MMAP		_IOWR('R', 6, struct fastrpc_req_mmap)
 #define FASTRPC_IOCTL_MUNMAP		_IOWR('R', 7, struct fastrpc_req_munmap)
 #define FASTRPC_IOCTL_INIT_ATTACH_SNS	_IO('R', 8)
+#define FASTRPC_IOCTL_INIT_CREATE_STATIC _IOWR('R', 9, struct fastrpc_init_create_static)
 #define FASTRPC_IOCTL_MEM_MAP		_IOWR('R', 10, struct fastrpc_mem_map)
 #define FASTRPC_IOCTL_MEM_UNMAP		_IOWR('R', 11, struct fastrpc_mem_unmap)
 #define FASTRPC_IOCTL_GET_DSP_INFO	_IOWR('R', 13, struct fastrpc_ioctl_capability)
@@ -87,6 +88,12 @@ struct fastrpc_init_create {
 	__u64 file;	/* pointer to elf file */
 };
 
+struct fastrpc_init_create_static {
+	__u32 namelen;	/* length of pd process name */
+	__u32 memlen;
+	__u64 name;	/* pd process name */
+};
+
 struct fastrpc_alloc_dma_buf {
 	__s32 fd;	/* fd */
 	__u32 flags;	/* flags to map with */
-- 
2.34.1


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

* [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (6 preceding siblings ...)
  2022-09-09 13:39 ` [PATCH v3 07/10] misc: fastrpc: Add support for audiopd Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-16 12:58   ` Srinivas Kandagatla
  2022-09-09 13:39 ` [PATCH v3 09/10] misc: fastrpc: Add mmap request assigning for static PD pool Abel Vesa
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

If the userspace daemon is killed in the middle of an invoke (e.g.
audiopd listerner invoke), we need to skip the unmapping on device
release, otherwise the DSP will crash. So lets safekeep all the maps
only if there is in invoke interrupted, by attaching them to the channel
context (which is resident until RPMSG driver is removed), and free them
on RPMSG driver remove.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/misc/fastrpc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 6b2a552dbdba..bc1e8f003d7a 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -275,6 +275,7 @@ struct fastrpc_channel_ctx {
 	struct fastrpc_device *secure_fdevice;
 	struct fastrpc_device *fdevice;
 	struct fastrpc_buf *remote_heap;
+	struct list_head invoke_interrupted_mmaps;
 	bool secure;
 	bool unsigned_support;
 };
@@ -1119,6 +1120,8 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl,  u32 kernel,
 				   struct fastrpc_invoke_args *args)
 {
 	struct fastrpc_invoke_ctx *ctx = NULL;
+	struct fastrpc_buf *buf, *b;
+
 	int err = 0;
 
 	if (!fl->sctx)
@@ -1182,6 +1185,13 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl,  u32 kernel,
 		fastrpc_context_put(ctx);
 	}
 
+	if (err == -ERESTARTSYS) {
+		list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
+			list_del(&buf->node);
+			list_add_tail(&buf->node, &fl->cctx->invoke_interrupted_mmaps);
+		}
+	}
+
 	if (err)
 		dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err);
 
@@ -2277,6 +2287,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
 	dev_set_drvdata(&rpdev->dev, data);
 	dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32));
 	INIT_LIST_HEAD(&data->users);
+	INIT_LIST_HEAD(&data->invoke_interrupted_mmaps);
 	spin_lock_init(&data->lock);
 	idr_init(&data->ctx_idr);
 	data->domain_id = domain_id;
@@ -2301,6 +2312,7 @@ static void fastrpc_notify_users(struct fastrpc_user *user)
 static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
 {
 	struct fastrpc_channel_ctx *cctx = dev_get_drvdata(&rpdev->dev);
+	struct fastrpc_buf *buf, *b;
 	struct fastrpc_user *user;
 	unsigned long flags;
 
@@ -2315,6 +2327,9 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
 	if (cctx->secure_fdevice)
 		misc_deregister(&cctx->secure_fdevice->miscdev);
 
+	list_for_each_entry_safe(buf, b, &cctx->invoke_interrupted_mmaps, node)
+		list_del(&buf->node);
+
 	if (cctx->remote_heap)
 		fastrpc_buf_free(cctx->remote_heap);
 
-- 
2.34.1


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

* [PATCH v3 09/10] misc: fastrpc: Add mmap request assigning for static PD pool
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (7 preceding siblings ...)
  2022-09-09 13:39 ` [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-09 13:39 ` [PATCH v3 10/10] misc: fastrpc: Add dma_mask to fastrpc_channel_ctx Abel Vesa
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

If the mmap request is to add pages and thre are VMIDs associated with
that context, do a call to SCM to reassign that memory. Do not do this
for remote heap allocation, that is done on init create static process
only.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/misc/fastrpc.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index bc1e8f003d7a..b9d9bfad93f6 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1842,8 +1842,9 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 	if (copy_from_user(&req, argp, sizeof(req)))
 		return -EFAULT;
 
-	if (req.flags != ADSP_MMAP_ADD_PAGES) {
+	if (req.flags != ADSP_MMAP_ADD_PAGES && req.flags != ADSP_MMAP_REMOTE_HEAP_ADDR) {
 		dev_err(dev, "flag not supported 0x%x\n", req.flags);
+
 		return -EINVAL;
 	}
 
@@ -1889,6 +1890,22 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 	/* let the client know the address to use */
 	req.vaddrout = rsp_msg.vaddr;
 
+	/* 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;
+		int err = 0;
+
+		perm.vmid = QCOM_SCM_VMID_HLOS;
+		perm.perm = QCOM_SCM_PERM_RWX;
+		err = qcom_scm_assign_mem(buf->phys, buf->size,
+			&(fl->cctx->vmperms[0].vmid), &perm, 1);
+		if (err) {
+			dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d",
+					buf->phys, buf->size, err);
+			goto err_assign;
+		}
+	}
+
 	spin_lock(&fl->lock);
 	list_add_tail(&buf->node, &fl->mmaps);
 	spin_unlock(&fl->lock);
-- 
2.34.1


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

* [PATCH v3 10/10] misc: fastrpc: Add dma_mask to fastrpc_channel_ctx
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (8 preceding siblings ...)
  2022-09-09 13:39 ` [PATCH v3 09/10] misc: fastrpc: Add mmap request assigning for static PD pool Abel Vesa
@ 2022-09-09 13:39 ` Abel Vesa
  2022-09-12 17:08 ` [PATCH v3 00/10] misc: fastrpc: Add audiopd support Rob Herring
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-09 13:39 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

dma_set_mask_and_coherent only updates the mask to which the device
dma_mask pointer points to. Add a dma_mask to the channel ctx and set
the device dma_mask to point to that, otherwise the dma_set_mask will
return an error and the dma_set_coherent_mask will be skipped too.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/misc/fastrpc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index b9d9bfad93f6..31fb1e9e3e47 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -278,6 +278,7 @@ struct fastrpc_channel_ctx {
 	struct list_head invoke_interrupted_mmaps;
 	bool secure;
 	bool unsigned_support;
+	u64 dma_mask;
 };
 
 struct fastrpc_device {
@@ -2302,6 +2303,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
 	kref_init(&data->refcount);
 
 	dev_set_drvdata(&rpdev->dev, data);
+	rdev->dma_mask = &data->dma_mask;
 	dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32));
 	INIT_LIST_HEAD(&data->users);
 	INIT_LIST_HEAD(&data->invoke_interrupted_mmaps);
-- 
2.34.1


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

* Re: [PATCH v3 03/10] dt-bindings: misc: fastrpc: Document memory-region property
  2022-09-09 13:39 ` [PATCH v3 03/10] dt-bindings: misc: fastrpc: Document memory-region property Abel Vesa
@ 2022-09-09 14:44   ` Krzysztof Kozlowski
  2022-09-12 17:10   ` Rob Herring
  1 sibling, 0 replies; 20+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-09 14:44 UTC (permalink / raw)
  To: Abel Vesa, Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Ekansh Gupta,
	Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

On 09/09/2022 15:39, Abel Vesa wrote:
> Add memory-region property to the list of optional properties, specify
> the value type and a definition. This property is used to specify the
> memory region which should be used for remote heap CMA.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>


Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


Best regards,
Krzysztof

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

* Re: [PATCH v3 00/10] misc: fastrpc: Add audiopd support
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (9 preceding siblings ...)
  2022-09-09 13:39 ` [PATCH v3 10/10] misc: fastrpc: Add dma_mask to fastrpc_channel_ctx Abel Vesa
@ 2022-09-12 17:08 ` Rob Herring
  2022-09-13  8:53   ` Abel Vesa
  2022-09-16 12:56 ` Srinivas Kandagatla
  2022-11-24 11:07 ` Srinivas Kandagatla
  12 siblings, 1 reply; 20+ messages in thread
From: Rob Herring @ 2022-09-12 17:08 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra,
	Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

On Fri, Sep 09, 2022 at 04:39:28PM +0300, Abel Vesa wrote:
> This patchset adds audiopd support to fastrpc.
> 
> The v2 of this patchset is here:
> https://lore.kernel.org/all/20220902154900.3404524-1-abel.vesa@linaro.org/
> 
> Abel Vesa (10):
>   misc: fastrpc: Rename audio protection domain to root
>   misc: fastrpc: Add reserved mem support
>   dt-bindings: misc: fastrpc: Document memory-region property
>   misc: fastrpc: Add fastrpc_remote_heap_alloc
>   misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
>   misc: fastrpc: Rework fastrpc_req_munmap
>   misc: fastrpc: Add support for audiopd
>   misc: fastrpc: Safekeep mmaps on interrupted invoke
>   misc: fastrpc: Add mmap request assigning for static PD pool
>   misc: fastrpc: Add dma_mask to fastrpc_channel_ctx

How do you expect this series to be merged? Please spell it out to the 
maintainers. If you don't, Greg is just going to tell you the series 
doesn't apply (because qcom,fastrpc.yaml only exists in my tree), drop 
it, and move on to the next thing in his queue.

Anyways, I've applied the binding patch. Who knew fastrpc was going to 
be so popular this cycle...

Rob

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

* Re: [PATCH v3 03/10] dt-bindings: misc: fastrpc: Document memory-region property
  2022-09-09 13:39 ` [PATCH v3 03/10] dt-bindings: misc: fastrpc: Document memory-region property Abel Vesa
  2022-09-09 14:44   ` Krzysztof Kozlowski
@ 2022-09-12 17:10   ` Rob Herring
  1 sibling, 0 replies; 20+ messages in thread
From: Rob Herring @ 2022-09-12 17:10 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Bharath Kumar, Greg Kroah-Hartman, linux-arm-msm,
	Srinivas Kandagatla, Anirudh Raghavendra, Amol Maheshwari,
	Andy Gross, Bjorn Andersson, Arnd Bergmann,
	Linux Kernel Mailing List, devicetree, Konrad Dybcio,
	Himateja Reddy, Ekansh Gupta, Krzysztof Kozlowski

On Fri, 09 Sep 2022 16:39:31 +0300, Abel Vesa wrote:
> Add memory-region property to the list of optional properties, specify
> the value type and a definition. This property is used to specify the
> memory region which should be used for remote heap CMA.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
> 
> Changes since v2:
>  * addressed Krzysztof's comment by specifying what's the use of the
>    memory region
> 
>  Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml | 5 +++++
>  1 file changed, 5 insertions(+)
> 

Applied, thanks!

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

* Re: [PATCH v3 00/10] misc: fastrpc: Add audiopd support
  2022-09-12 17:08 ` [PATCH v3 00/10] misc: fastrpc: Add audiopd support Rob Herring
@ 2022-09-13  8:53   ` Abel Vesa
  0 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-13  8:53 UTC (permalink / raw)
  To: Rob Herring
  Cc: Srinivas Kandagatla, Amol Maheshwari, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Krzysztof Kozlowski,
	Ekansh Gupta, Bharath Kumar, Himateja Reddy, Anirudh Raghavendra,
	Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

On 22-09-12 12:08:27, Rob Herring wrote:
> On Fri, Sep 09, 2022 at 04:39:28PM +0300, Abel Vesa wrote:
> > This patchset adds audiopd support to fastrpc.
> > 
> > The v2 of this patchset is here:
> > https://lore.kernel.org/all/20220902154900.3404524-1-abel.vesa@linaro.org/
> > 
> > Abel Vesa (10):
> >   misc: fastrpc: Rename audio protection domain to root
> >   misc: fastrpc: Add reserved mem support
> >   dt-bindings: misc: fastrpc: Document memory-region property
> >   misc: fastrpc: Add fastrpc_remote_heap_alloc
> >   misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
> >   misc: fastrpc: Rework fastrpc_req_munmap
> >   misc: fastrpc: Add support for audiopd
> >   misc: fastrpc: Safekeep mmaps on interrupted invoke
> >   misc: fastrpc: Add mmap request assigning for static PD pool
> >   misc: fastrpc: Add dma_mask to fastrpc_channel_ctx
> 
> How do you expect this series to be merged? Please spell it out to the 
> maintainers. If you don't, Greg is just going to tell you the series 
> doesn't apply (because qcom,fastrpc.yaml only exists in my tree), drop 
> it, and move on to the next thing in his queue.

Yeah, you are right. I should've mentioned that dt-bindings patch goes through
your tree while all the others go through Greg's tree. Sorry about that.

Greg, if you want I can resend this patchset without the dt-bindings, now
that it was applied by Rob to his tree.

> 
> Anyways, I've applied the binding patch. Who knew fastrpc was going to 
> be so popular this cycle...

Thanks for applying the binding patch.

> 
> Rob

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

* Re: [PATCH v3 00/10] misc: fastrpc: Add audiopd support
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (10 preceding siblings ...)
  2022-09-12 17:08 ` [PATCH v3 00/10] misc: fastrpc: Add audiopd support Rob Herring
@ 2022-09-16 12:56 ` Srinivas Kandagatla
  2022-11-24 11:07 ` Srinivas Kandagatla
  12 siblings, 0 replies; 20+ messages in thread
From: Srinivas Kandagatla @ 2022-09-16 12:56 UTC (permalink / raw)
  To: Abel Vesa, Amol Maheshwari, Andy Gross, Bjorn Andersson,
	Konrad Dybcio, Rob Herring, Krzysztof Kozlowski, Ekansh Gupta,
	Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree



On 09/09/2022 14:39, Abel Vesa wrote:
> This patchset adds audiopd support to fastrpc.
> 
> The v2 of this patchset is here:
> https://lore.kernel.org/all/20220902154900.3404524-1-abel.vesa@linaro.org/
> 
> Abel Vesa (10):
>    misc: fastrpc: Rename audio protection domain to root
>    misc: fastrpc: Add reserved mem support
>    dt-bindings: misc: fastrpc: Document memory-region property
>    misc: fastrpc: Add fastrpc_remote_heap_alloc
>    misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
>    misc: fastrpc: Rework fastrpc_req_munmap
>    misc: fastrpc: Add support for audiopd
>    misc: fastrpc: Safekeep mmaps on interrupted invoke
>    misc: fastrpc: Add mmap request assigning for static PD pool
>    misc: fastrpc: Add dma_mask to fastrpc_channel_ctx
> 

thanks Abel for picking this up...

Tested this series on SM8450 with ECNS.

Tested-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>


--srini
>   .../bindings/misc/qcom,fastrpc.yaml           |   5 +
>   drivers/misc/fastrpc.c                        | 260 +++++++++++++++---
>   include/uapi/misc/fastrpc.h                   |   7 +
>   3 files changed, 240 insertions(+), 32 deletions(-)
> 

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

* Re: [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke
  2022-09-09 13:39 ` [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke Abel Vesa
@ 2022-09-16 12:58   ` Srinivas Kandagatla
  2022-09-16 14:38     ` Abel Vesa
  0 siblings, 1 reply; 20+ messages in thread
From: Srinivas Kandagatla @ 2022-09-16 12:58 UTC (permalink / raw)
  To: Abel Vesa, Amol Maheshwari, Andy Gross, Bjorn Andersson,
	Konrad Dybcio, Rob Herring, Krzysztof Kozlowski, Ekansh Gupta,
	Bharath Kumar, Himateja Reddy, Anirudh Raghavendra
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree



On 09/09/2022 14:39, Abel Vesa wrote:
> If the userspace daemon is killed in the middle of an invoke (e.g.
> audiopd listerner invoke), we need to skip the unmapping on device
> release, otherwise the DSP will crash. So lets safekeep all the maps
> only if there is in invoke interrupted, by attaching them to the channel
> context (which is resident until RPMSG driver is removed), and free them
> on RPMSG driver remove.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>   drivers/misc/fastrpc.c | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 6b2a552dbdba..bc1e8f003d7a 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -275,6 +275,7 @@ struct fastrpc_channel_ctx {
>   	struct fastrpc_device *secure_fdevice;
>   	struct fastrpc_device *fdevice;
>   	struct fastrpc_buf *remote_heap;
> +	struct list_head invoke_interrupted_mmaps;
>   	bool secure;
>   	bool unsigned_support;
>   };
> @@ -1119,6 +1120,8 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl,  u32 kernel,
>   				   struct fastrpc_invoke_args *args)
>   {
>   	struct fastrpc_invoke_ctx *ctx = NULL;
> +	struct fastrpc_buf *buf, *b;
> +
>   	int err = 0;
>   
>   	if (!fl->sctx)
> @@ -1182,6 +1185,13 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl,  u32 kernel,
>   		fastrpc_context_put(ctx);
>   	}
>   
> +	if (err == -ERESTARTSYS) {
> +		list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
> +			list_del(&buf->node);
> +			list_add_tail(&buf->node, &fl->cctx->invoke_interrupted_mmaps);
> +		}
> +	}
> +
>   	if (err)
>   		dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err);
>   
> @@ -2277,6 +2287,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
>   	dev_set_drvdata(&rpdev->dev, data);
>   	dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32));
>   	INIT_LIST_HEAD(&data->users);
> +	INIT_LIST_HEAD(&data->invoke_interrupted_mmaps);
>   	spin_lock_init(&data->lock);
>   	idr_init(&data->ctx_idr);
>   	data->domain_id = domain_id;
> @@ -2301,6 +2312,7 @@ static void fastrpc_notify_users(struct fastrpc_user *user)
>   static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
>   {
>   	struct fastrpc_channel_ctx *cctx = dev_get_drvdata(&rpdev->dev);
> +	struct fastrpc_buf *buf, *b;
>   	struct fastrpc_user *user;
>   	unsigned long flags;
>   
> @@ -2315,6 +2327,9 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
>   	if (cctx->secure_fdevice)
>   		misc_deregister(&cctx->secure_fdevice->miscdev);
>   
> +	list_for_each_entry_safe(buf, b, &cctx->invoke_interrupted_mmaps, node)
> +		list_del(&buf->node);
> +
When would you free these?
looks like we are leaking even after dsp is down..
Should we not do fastrpc_buf_free() here?



--srini

>   	if (cctx->remote_heap)
>   		fastrpc_buf_free(cctx->remote_heap);
>   

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

* Re: [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke
  2022-09-16 12:58   ` Srinivas Kandagatla
@ 2022-09-16 14:38     ` Abel Vesa
  0 siblings, 0 replies; 20+ messages in thread
From: Abel Vesa @ 2022-09-16 14:38 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Amol Maheshwari, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Rob Herring, Krzysztof Kozlowski, Ekansh Gupta, Bharath Kumar,
	Himateja Reddy, Anirudh Raghavendra, Arnd Bergmann,
	Greg Kroah-Hartman, linux-arm-msm, Linux Kernel Mailing List,
	devicetree

On 22-09-16 13:58:35, Srinivas Kandagatla wrote:
> 
> 
> On 09/09/2022 14:39, Abel Vesa wrote:
> > If the userspace daemon is killed in the middle of an invoke (e.g.
> > audiopd listerner invoke), we need to skip the unmapping on device
> > release, otherwise the DSP will crash. So lets safekeep all the maps
> > only if there is in invoke interrupted, by attaching them to the channel
> > context (which is resident until RPMSG driver is removed), and free them
> > on RPMSG driver remove.
> > 
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > ---
> >   drivers/misc/fastrpc.c | 15 +++++++++++++++
> >   1 file changed, 15 insertions(+)
> > 
> > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> > index 6b2a552dbdba..bc1e8f003d7a 100644
> > --- a/drivers/misc/fastrpc.c
> > +++ b/drivers/misc/fastrpc.c
> > @@ -275,6 +275,7 @@ struct fastrpc_channel_ctx {
> >   	struct fastrpc_device *secure_fdevice;
> >   	struct fastrpc_device *fdevice;
> >   	struct fastrpc_buf *remote_heap;
> > +	struct list_head invoke_interrupted_mmaps;
> >   	bool secure;
> >   	bool unsigned_support;
> >   };
> > @@ -1119,6 +1120,8 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl,  u32 kernel,
> >   				   struct fastrpc_invoke_args *args)
> >   {
> >   	struct fastrpc_invoke_ctx *ctx = NULL;
> > +	struct fastrpc_buf *buf, *b;
> > +
> >   	int err = 0;
> >   	if (!fl->sctx)
> > @@ -1182,6 +1185,13 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl,  u32 kernel,
> >   		fastrpc_context_put(ctx);
> >   	}
> > +	if (err == -ERESTARTSYS) {
> > +		list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
> > +			list_del(&buf->node);
> > +			list_add_tail(&buf->node, &fl->cctx->invoke_interrupted_mmaps);
> > +		}
> > +	}
> > +
> >   	if (err)
> >   		dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err);
> > @@ -2277,6 +2287,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
> >   	dev_set_drvdata(&rpdev->dev, data);
> >   	dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32));
> >   	INIT_LIST_HEAD(&data->users);
> > +	INIT_LIST_HEAD(&data->invoke_interrupted_mmaps);
> >   	spin_lock_init(&data->lock);
> >   	idr_init(&data->ctx_idr);
> >   	data->domain_id = domain_id;
> > @@ -2301,6 +2312,7 @@ static void fastrpc_notify_users(struct fastrpc_user *user)
> >   static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
> >   {
> >   	struct fastrpc_channel_ctx *cctx = dev_get_drvdata(&rpdev->dev);
> > +	struct fastrpc_buf *buf, *b;
> >   	struct fastrpc_user *user;
> >   	unsigned long flags;
> > @@ -2315,6 +2327,9 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
> >   	if (cctx->secure_fdevice)
> >   		misc_deregister(&cctx->secure_fdevice->miscdev);
> > +	list_for_each_entry_safe(buf, b, &cctx->invoke_interrupted_mmaps, node)
> > +		list_del(&buf->node);
> > +
> When would you free these?
> looks like we are leaking even after dsp is down..
> Should we not do fastrpc_buf_free() here?

Yes, we should. I forgot to add it.

Will send a new version.

Thanks.

> 
> 
> 
> --srini
> 
> >   	if (cctx->remote_heap)
> >   		fastrpc_buf_free(cctx->remote_heap);

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

* Re: [PATCH v3 00/10] misc: fastrpc: Add audiopd support
  2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
                   ` (11 preceding siblings ...)
  2022-09-16 12:56 ` Srinivas Kandagatla
@ 2022-11-24 11:07 ` Srinivas Kandagatla
  2022-11-24 16:46   ` Greg KH
  12 siblings, 1 reply; 20+ messages in thread
From: Srinivas Kandagatla @ 2022-11-24 11:07 UTC (permalink / raw)
  To: Abel Vesa, Amol Maheshwari, Andy Gross, Bjorn Andersson,
	Konrad Dybcio, Rob Herring, Krzysztof Kozlowski, Ekansh Gupta,
	Bharath Kumar, Himateja Reddy, Anirudh Raghavendra, Greg KH
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	Linux Kernel Mailing List, devicetree

Hi Greg,

On 09/09/2022 14:39, Abel Vesa wrote:
> This patchset adds audiopd support to fastrpc.
> 
> The v2 of this patchset is here:
> https://lore.kernel.org/all/20220902154900.3404524-1-abel.vesa@linaro.org/
> 
> Abel Vesa (10):
>    misc: fastrpc: Rename audio protection domain to root
>    misc: fastrpc: Add reserved mem support
>    dt-bindings: misc: fastrpc: Document memory-region property
>    misc: fastrpc: Add fastrpc_remote_heap_alloc
>    misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
>    misc: fastrpc: Rework fastrpc_req_munmap
>    misc: fastrpc: Add support for audiopd
>    misc: fastrpc: Safekeep mmaps on interrupted invoke
>    misc: fastrpc: Add mmap request assigning for static PD pool
>    misc: fastrpc: Add dma_mask to fastrpc_channel_ctx
> 

Do you think you could pick these fastrpc patches as it is or should I 
collect these patches with other fastrpc patches on the list and send them?

As there are few more of fastrpc patches that could go in 6.2.

thanks,
Srini



>   .../bindings/misc/qcom,fastrpc.yaml           |   5 +
>   drivers/misc/fastrpc.c                        | 260 +++++++++++++++---
>   include/uapi/misc/fastrpc.h                   |   7 +
>   3 files changed, 240 insertions(+), 32 deletions(-)
> 

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

* Re: [PATCH v3 00/10] misc: fastrpc: Add audiopd support
  2022-11-24 11:07 ` Srinivas Kandagatla
@ 2022-11-24 16:46   ` Greg KH
  0 siblings, 0 replies; 20+ messages in thread
From: Greg KH @ 2022-11-24 16:46 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Abel Vesa, Amol Maheshwari, Andy Gross, Bjorn Andersson,
	Konrad Dybcio, Rob Herring, Krzysztof Kozlowski, Ekansh Gupta,
	Bharath Kumar, Himateja Reddy, Anirudh Raghavendra,
	Arnd Bergmann, linux-arm-msm, Linux Kernel Mailing List,
	devicetree

On Thu, Nov 24, 2022 at 11:07:55AM +0000, Srinivas Kandagatla wrote:
> Hi Greg,
> 
> On 09/09/2022 14:39, Abel Vesa wrote:
> > This patchset adds audiopd support to fastrpc.
> > 
> > The v2 of this patchset is here:
> > https://lore.kernel.org/all/20220902154900.3404524-1-abel.vesa@linaro.org/
> > 
> > Abel Vesa (10):
> >    misc: fastrpc: Rename audio protection domain to root
> >    misc: fastrpc: Add reserved mem support
> >    dt-bindings: misc: fastrpc: Document memory-region property
> >    misc: fastrpc: Add fastrpc_remote_heap_alloc
> >    misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
> >    misc: fastrpc: Rework fastrpc_req_munmap
> >    misc: fastrpc: Add support for audiopd
> >    misc: fastrpc: Safekeep mmaps on interrupted invoke
> >    misc: fastrpc: Add mmap request assigning for static PD pool
> >    misc: fastrpc: Add dma_mask to fastrpc_channel_ctx
> > 
> 
> Do you think you could pick these fastrpc patches as it is or should I
> collect these patches with other fastrpc patches on the list and send them?
> 
> As there are few more of fastrpc patches that could go in 6.2.

Pleasae collect them all up and send them on to me.

thanks,

greg k-h

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

end of thread, other threads:[~2022-11-24 16:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 13:39 [PATCH v3 00/10] misc: fastrpc: Add audiopd support Abel Vesa
2022-09-09 13:39 ` [PATCH v3 01/10] misc: fastrpc: Rename audio protection domain to root Abel Vesa
2022-09-09 13:39 ` [PATCH v3 02/10] misc: fastrpc: Add reserved mem support Abel Vesa
2022-09-09 13:39 ` [PATCH v3 03/10] dt-bindings: misc: fastrpc: Document memory-region property Abel Vesa
2022-09-09 14:44   ` Krzysztof Kozlowski
2022-09-12 17:10   ` Rob Herring
2022-09-09 13:39 ` [PATCH v3 04/10] misc: fastrpc: Add fastrpc_remote_heap_alloc Abel Vesa
2022-09-09 13:39 ` [PATCH v3 05/10] misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail Abel Vesa
2022-09-09 13:39 ` [PATCH v3 06/10] misc: fastrpc: Rework fastrpc_req_munmap Abel Vesa
2022-09-09 13:39 ` [PATCH v3 07/10] misc: fastrpc: Add support for audiopd Abel Vesa
2022-09-09 13:39 ` [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke Abel Vesa
2022-09-16 12:58   ` Srinivas Kandagatla
2022-09-16 14:38     ` Abel Vesa
2022-09-09 13:39 ` [PATCH v3 09/10] misc: fastrpc: Add mmap request assigning for static PD pool Abel Vesa
2022-09-09 13:39 ` [PATCH v3 10/10] misc: fastrpc: Add dma_mask to fastrpc_channel_ctx Abel Vesa
2022-09-12 17:08 ` [PATCH v3 00/10] misc: fastrpc: Add audiopd support Rob Herring
2022-09-13  8:53   ` Abel Vesa
2022-09-16 12:56 ` Srinivas Kandagatla
2022-11-24 11:07 ` Srinivas Kandagatla
2022-11-24 16:46   ` Greg KH

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