2022-11-24 18:32:45

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH 00/11] misc: fastrpc: patches for 6.2

Hi Greg,

Here are some fastrpc patches which add new feature to handle Audio
Protection Domain. Along with it there is one locking update on dma-buf
and an update to bindings.

Could you please queue them up for 6.2.

Thanks,
Srini


Abel Vesa (10):
dt-bindings: misc: qcom,fastrpc: increase allowed iommus entries
misc: fastrpc: Rename audio protection domain to root
misc: fastrpc: Add reserved mem support
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

Dmitry Osipenko (1):
misc: fastrpc: Assert held reservation lock for dma-buf mmapping

.../bindings/misc/qcom,fastrpc.yaml | 2 +-
drivers/misc/fastrpc.c | 263 +++++++++++++++---
include/uapi/misc/fastrpc.h | 7 +
3 files changed, 239 insertions(+), 33 deletions(-)

--
2.25.1


2022-11-24 18:34:21

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH 01/11] misc: fastrpc: Assert held reservation lock for dma-buf mmapping

From: Dmitry Osipenko <[email protected]>

When userspace mmaps dma-buf's fd, the dma-buf reservation lock must be
held. Add locking sanity check to the dma-buf mmaping callback to ensure
that the locking assumption won't regress in the future.

Suggested-by: Daniel Vetter <[email protected]>
Signed-off-by: Dmitry Osipenko <[email protected]>
Signed-off-by: Srinivas Kandagatla <[email protected]>
---
drivers/misc/fastrpc.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 80811e852d8f..c6b9ddaa698b 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -6,6 +6,7 @@
#include <linux/device.h>
#include <linux/dma-buf.h>
#include <linux/dma-mapping.h>
+#include <linux/dma-resv.h>
#include <linux/idr.h>
#include <linux/list.h>
#include <linux/miscdevice.h>
@@ -692,6 +693,8 @@ static int fastrpc_mmap(struct dma_buf *dmabuf,
struct fastrpc_buf *buf = dmabuf->priv;
size_t size = vma->vm_end - vma->vm_start;

+ dma_resv_assert_held(dmabuf->resv);
+
return dma_mmap_coherent(buf->dev, vma, buf->virt,
FASTRPC_PHYS(buf->phys), size);
}
--
2.25.1

2022-11-24 18:59:10

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH 05/11] misc: fastrpc: Add fastrpc_remote_heap_alloc

From: Abel Vesa <[email protected]>

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

Signed-off-by: Abel Vesa <[email protected]>
Co-developed-by: Srinivas Kandagatla <[email protected]>
Signed-off-by: Srinivas Kandagatla <[email protected]>
---
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 86d11ffadf29..0ddad976a4d2 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -380,7 +380,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;
@@ -408,14 +408,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.25.1

2022-11-24 19:00:43

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH 10/11] misc: fastrpc: Add mmap request assigning for static PD pool

From: Abel Vesa <[email protected]>

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.

Signed-off-by: Abel Vesa <[email protected]>
Co-developed-by: Srinivas Kandagatla <[email protected]>
Signed-off-by: Srinivas Kandagatla <[email protected]>
---
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 3cf76a240b7a..d3147e4313cc 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1845,8 +1845,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;
}

@@ -1892,6 +1893,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.25.1