From patchwork Fri Sep 16 15:41:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 12978671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D4C6ECAAA1 for ; Fri, 16 Sep 2022 15:41:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229784AbiIPPlj (ORCPT ); Fri, 16 Sep 2022 11:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbiIPPlf (ORCPT ); Fri, 16 Sep 2022 11:41:35 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 305CFB07C7 for ; Fri, 16 Sep 2022 08:41:27 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id kr11so4205479ejc.8 for ; Fri, 16 Sep 2022 08:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=i1s44syzFEYnr0eNDyLT85KmbD8ohRjyNiKZIDjm3/o=; b=c3HQ5Ugb/LUNiXlZYL/qejNXQ2xsNsnG7rPz7B1k67AOWbTZUztIVb+j3O0A1ZMzgN YBXD4/9PK23WtMmlELuGmXD2+3UMXu+Kzif2qcxQbq7Ka/xvIH3McYljYTAjxSsXyT6n rQAq4pGEZEVHasSGwI1zjTFOIlD8TuZ3RYD9PViGC72085vqoMuBoltunJpOWXn/l4eP qD9OAz1FsD7frLp5dNHbvkwv7/ab8M8hWMVNNvJyJXa2WwAXC4ZAaqLziOxD6bLHgXvk OMQeiZjRzg47gQdoi9g9excYhVXFD4g34/xENJSPudlS4aRDeH5xVumgrtCQTz5XUMh8 ufYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=i1s44syzFEYnr0eNDyLT85KmbD8ohRjyNiKZIDjm3/o=; b=y+elKoM8a/SUWPpeASyQ9FUbAymANDm3ngJvDqLqF+qUWEIfKV67BGj1xKolhXl9kd BZ//F71ep13JyemWWcuVHJ/69nEH0iHzcW8e4TlQsKHgPi6cL9OUUuKzzQJ76wc+/zGB GTeyMLRJ35mq6CPAWo2q6nw84c0ArfWTDbNnhBFqoG2RfbRSmMnxitLeM7VN/iD4Fdv7 vSREoT2nZhJAS3hmw+w4RP367zxyivyGLT1cn9vrJnhlO4M3YUv3Na795CPxGX3pK8vb 19Dr/3B/meTh3oxtHnVruMs62B2R7hRAPhMZ9qKALposZkDODJVbGk0TXQHnXlaKUZ2I eeWg== X-Gm-Message-State: ACrzQf23SFOh+zQkckXKum3jOiMUZelIRBm9FM0rwL5KvjL/hvA8OQJn /0vKHb5Y1hBeFh2+qS6vYIhx8A== X-Google-Smtp-Source: AMsMyM7I7AU8B33k9c3fSGSpbC1fQvriVGAIFnwscUKk4paQ8FqKb/I9zZXG3YG23nVptTglV/Qung== X-Received: by 2002:a17:907:c15:b0:775:df03:3f06 with SMTP id ga21-20020a1709070c1500b00775df033f06mr3887524ejc.89.1663342886049; Fri, 16 Sep 2022 08:41:26 -0700 (PDT) Received: from hackbox.lan ([94.52.112.99]) by smtp.gmail.com with ESMTPSA id e10-20020a1709062c0a00b0073d638a7a89sm10567707ejh.99.2022.09.16.08.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 08:41:25 -0700 (PDT) From: Abel Vesa To: Srinivas Kandagatla , Amol Maheshwari , Ekansh Gupta , Bharath Kumar , Himateja Reddy , Anirudh Raghavendra Cc: Arnd Bergmann , Greg Kroah-Hartman , linux-arm-msm@vger.kernel.org, Linux Kernel Mailing List Subject: [PATCH v4 7/9] misc: fastrpc: Safekeep mmaps on interrupted invoke Date: Fri, 16 Sep 2022 18:41:00 +0300 Message-Id: <20220916154102.1768088-8-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916154102.1768088-1-abel.vesa@linaro.org> References: <20220916154102.1768088-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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 --- drivers/misc/fastrpc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index b123b6783920..971d4fc697fa 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,7 @@ 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 +1184,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); @@ -2281,6 +2290,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; @@ -2305,6 +2315,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; @@ -2319,6 +2330,11 @@ 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); + fastrpc_buf_free(buf); + } + if (cctx->remote_heap) fastrpc_buf_free(cctx->remote_heap);