public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeya R <jeyr@codeaurora.org>
To: linux-arm-msm@vger.kernel.org, srinivas.kandagatla@linaro.org
Cc: Jeya R <jeyr@codeaurora.org>,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	fastrpc.upstream@qti.qualcomm.com, bkumar@qti.qualcomm.com,
	ekangupt@qti.qualcomm.com, jeyr@qti.qualcomm.com
Subject: [PATCH 3/3] misc: fastrpc: Handle mapping of invoke argument with attribute
Date: Tue, 30 Nov 2021 18:27:52 +0530	[thread overview]
Message-ID: <1638277072-6459-6-git-send-email-jeyr@codeaurora.org> (raw)
In-Reply-To: <1638277072-6459-1-git-send-email-jeyr@codeaurora.org>

Allow mapping of arguments for remote invocations with attribute.

Signed-off-by: Jeya R <jeyr@codeaurora.org>
---
 drivers/misc/fastrpc.c      | 25 ++++++++++++++++---------
 include/uapi/misc/fastrpc.h |  5 ++++-
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index a9adfa4d..f6a6e4d 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -172,6 +172,7 @@ struct fastrpc_map {
 	u64 size;
 	void *va;
 	u64 len;
+	u32 attr;
 	struct kref refcount;
 };
 
@@ -246,6 +247,10 @@ static void fastrpc_free_map(struct kref *ref)
 	map = container_of(ref, struct fastrpc_map, refcount);
 
 	if (map->table) {
+		if (map->attr & FASTRPC_SECUREMAP) {
+			/* Invoke qcom_scm API to assign memory access
+			 * back to HLOS
+			 */
 		dma_buf_unmap_attachment(map->attach, map->table,
 					 DMA_BIDIRECTIONAL);
 		dma_buf_detach(map->buf, map->attach);
@@ -622,7 +627,7 @@ static const struct dma_buf_ops fastrpc_dma_buf_ops = {
 };
 
 static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
-			      u64 len, struct fastrpc_map **ppmap)
+			      u64 len, u32 attr, struct fastrpc_map **ppmap)
 {
 	struct fastrpc_session_ctx *sess = fl->sctx;
 	struct fastrpc_map *map = NULL;
@@ -664,6 +669,14 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 	map->len = len;
 	kref_init(&map->refcount);
 
+	if (attr & FASTRPC_SECUREMAP) {
+		map->attr = attr;
+		/*
+		 * If subsystem VMIDs are defined in DTSI, then do
+		 * hyp_assign from HLOS to those VM(s).
+		*/
+	}
+
 	spin_lock(&fl->lock);
 	list_add_tail(&map->node, &fl->maps);
 	spin_unlock(&fl->lock);
@@ -746,16 +759,12 @@ static int fastrpc_create_maps(struct fastrpc_invoke_ctx *ctx)
 	int i, err;
 
 	for (i = 0; i < ctx->nscalars; ++i) {
-		/* Make sure reserved field is set to 0 */
-		if (ctx->args[i].reserved)
-			return -EINVAL;
-
 		if (ctx->args[i].fd == 0 || ctx->args[i].fd == -1 ||
 		    ctx->args[i].length == 0)
 			continue;
 
 		err = fastrpc_map_create(ctx->fl, ctx->args[i].fd,
-					 ctx->args[i].length, &ctx->maps[i]);
+					 ctx->args[i].length, ctx->args[i].attr, x->maps[i]);
 		if (err) {
 			dev_err(dev, "Error Creating map %d\n", err);
 			return -EINVAL;
@@ -1062,7 +1071,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
 	fl->pd = USER_PD;
 
 	if (init.filelen && init.filefd) {
-		err = fastrpc_map_create(fl, init.filefd, init.filelen, &map);
+		err = fastrpc_map_create(fl, init.filefd, init.filelen, 0, &map);
 		if (err)
 			goto err;
 	}
@@ -1171,7 +1180,6 @@ static int fastrpc_release_current_dsp_process(struct fastrpc_user *fl)
 	args[0].ptr = (u64)(uintptr_t) &tgid;
 	args[0].length = sizeof(tgid);
 	args[0].fd = -1;
-	args[0].reserved = 0;
 	sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_RELEASE, 1, 0);
 
 	return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE,
@@ -1307,7 +1315,6 @@ static int fastrpc_init_attach(struct fastrpc_user *fl, int pd)
 	args[0].ptr = (u64)(uintptr_t) &tgid;
 	args[0].length = sizeof(tgid);
 	args[0].fd = -1;
-	args[0].reserved = 0;
 	sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_ATTACH, 1, 0);
 	fl->pd = pd;
 
diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h
index 0a89f95..4dd4a9e 100644
--- a/include/uapi/misc/fastrpc.h
+++ b/include/uapi/misc/fastrpc.h
@@ -14,11 +14,14 @@
 #define FASTRPC_IOCTL_MUNMAP		_IOWR('R', 7, struct fastrpc_req_munmap)
 #define FASTRPC_IOCTL_INIT_ATTACH_SNS	_IO('R', 8)
 
+/* Fastrpc attribute for memory protection of buffers */
+#define FASTRPC_SECUREMAP (1)
+
 struct fastrpc_invoke_args {
 	__u64 ptr;
 	__u64 length;
 	__s32 fd;
-	__u32 reserved;
+	__u32 attr;
 };
 
 struct fastrpc_invoke {
-- 
2.7.4


  parent reply	other threads:[~2021-11-30 12:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30 12:57 [PATCH 0/3] Add vmid property and mapping attribute Jeya R
2021-11-30 12:57 ` [PATCH 1/3] dt-bindings: misc: add fastrpc domain vmid property Jeya R
2021-11-30 13:17   ` Srinivas Kandagatla
2021-11-30 12:57 ` [PATCH 1/2] misc: fastrpc: Add fdlist implementation Jeya R
2021-11-30 20:20   ` kernel test robot
2021-11-30 23:52   ` kernel test robot
2021-11-30 12:57 ` [PATCH 2/2] misc: fastrpc: Add dma handle implementation Jeya R
2021-11-30 22:44   ` kernel test robot
2021-12-01  0:22   ` kernel test robot
2021-11-30 12:57 ` [PATCH 2/3] misc: fastrpc: Read virtual machine IDs during probe Jeya R
2021-11-30 12:57 ` Jeya R [this message]
2021-11-30 18:18   ` [PATCH 3/3] misc: fastrpc: Handle mapping of invoke argument with attribute kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1638277072-6459-6-git-send-email-jeyr@codeaurora.org \
    --to=jeyr@codeaurora.org \
    --cc=bkumar@qti.qualcomm.com \
    --cc=ekangupt@qti.qualcomm.com \
    --cc=fastrpc.upstream@qti.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeyr@qti.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox