From: Abel Vesa <abel.vesa@linaro.org>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Amol Maheshwari <amahesh@qti.qualcomm.com>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@somainline.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	Ekansh Gupta <ekangupt@qti.qualcomm.com>,
	Bharath Kumar <bkumar@qti.qualcomm.com>,
	Himateja Reddy <hmreddy@quicinc.com>,
	Anirudh Raghavendra <araghave@quicinc.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-arm-msm@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	devicetree@vger.kernel.org
Subject: [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke
Date: Fri,  9 Sep 2022 16:39:36 +0300	[thread overview]
Message-ID: <20220909133938.3518520-9-abel.vesa@linaro.org> (raw)
In-Reply-To: <20220909133938.3518520-1-abel.vesa@linaro.org>
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
next prev parent reply	other threads:[~2022-09-09 13:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Abel Vesa [this message]
2022-09-16 12:58   ` [PATCH v3 08/10] misc: fastrpc: Safekeep mmaps on interrupted invoke 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
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=20220909133938.3518520-9-abel.vesa@linaro.org \
    --to=abel.vesa@linaro.org \
    --cc=agross@kernel.org \
    --cc=amahesh@qti.qualcomm.com \
    --cc=andersson@kernel.org \
    --cc=araghave@quicinc.com \
    --cc=arnd@arndb.de \
    --cc=bkumar@qti.qualcomm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=ekangupt@qti.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hmreddy@quicinc.com \
    --cc=konrad.dybcio@somainline.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@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;
as well as URLs for NNTP newsgroup(s).