Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1974262rwn; Fri, 9 Sep 2022 06:55:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR4GHWwGWtnSjujRqIHX4seuMhqt8GxbGwjOP96Hay19WjlnInhk7jZutsvDKLPW1sptPFAQ X-Received: by 2002:a05:6a00:c96:b0:537:1537:988f with SMTP id a22-20020a056a000c9600b005371537988fmr14788046pfv.2.1662731728547; Fri, 09 Sep 2022 06:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662731728; cv=none; d=google.com; s=arc-20160816; b=lgMEMO3Am+MfjhRiOVTrOqF7lcQPxVcSghKn6gzpaSPAY2TRa3BVZxBKGC2Nh1n5jM wU71lF0pdEf6PKLT9LQAFTFNwBmFluFMmvxIXzamhPbiUAWV33VB6vikpf2s5xT0JCiM ZynndRYiBABO60CGeGfehPb2IKuUqvQ0pEJ482MwNZwTwpZaEptLLaTQXhb0FpONhy3O uQFiYTRTzLgAyiayO4LYyAK7wQgRY6SrgBrAV7pOu1qkLG/ME5dMSnZXAJ0aiuPXk25W DBjcZoxPUTM0675JTJENkFsIOhiE5AVg5PlZ5h2J8Z2E+z46Jax5RFSyrCNvgAiCoKfP VW/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TgMhe1L8Z5pQw5Ws1qnT8lOmOJIjYgKzz95gp2a8iEk=; b=SkuR/bro87fsG2bGsLqbWe4CiL6K4vz+wRrrX0h/aeJ+EiGV9JHrgaH3BIS75hk+5f RZgqmcgfLXrOl33691rxtRND7XG2A2FBDrkkev/i41d7cHe/ZIlmYUCnBqarVi21u6yU LxbOc4iz4ANBg9QGtEZQcNAhgOGoRcWy7hVWc45VgC2vjor8eCyvHgr/9msZyUC0mBrl 24aJzcyVxW4c9SxuEnphKMSITX3a28ZcZWTOMMuHKFLfQ0opxKkmJt1uY4htOmo+7P8O u94m0C92DV4GjvJFNpePoNSCZuca5M9awM3ONxzJjhWytc/3/+zV3icB4BlCVNUNa+aY rcGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bnmqBLRD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x194-20020a6331cb000000b0043456a4e3e5si496268pgx.864.2022.09.09.06.55.15; Fri, 09 Sep 2022 06:55:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bnmqBLRD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbiIINmK (ORCPT + 99 others); Fri, 9 Sep 2022 09:42:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbiIINlE (ORCPT ); Fri, 9 Sep 2022 09:41:04 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C890BCC17 for ; Fri, 9 Sep 2022 06:40:51 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id bq9so2817302wrb.4 for ; Fri, 09 Sep 2022 06:40:51 -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=TgMhe1L8Z5pQw5Ws1qnT8lOmOJIjYgKzz95gp2a8iEk=; b=bnmqBLRDNQn2Mb58Y6ESTUJYa+iA9fmvtbOVYzMwUov6f9xlJGwKJPPlZfCPsyT4Wy hah4ALy4eL3j6G2OY6Bm/RIKVWrSki8lnpP3RUJ50qp6TJm0lfb+bUtgudc/6Yp3CgEa qW87ToXBDcDROP8Xd9cchbH1Jc/m1z+08VVUwho/+TOqeWsQW+zDOBhjVYnwaIAYTYPz DulSjwl6wlxd1QMOWbGUw+PN016p2XSCcHNEl+VJ944mej7qyknBcJpVzytmTZpSWNho IWiSIxniokTgh/bQDMOLA3ljnl9O52CbQlMFNAdUBzuiFAcZ/VjwEZFmYjPr90aqdBP3 Z9+g== 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=TgMhe1L8Z5pQw5Ws1qnT8lOmOJIjYgKzz95gp2a8iEk=; b=a11Gl7lAKn9etCbPWgWGWUtXUkCTIhezw7pGA+7ozMBdJMu1biG71e3o+iOWbl7b6X 5DUtpfaXAr0uofdIyFKOiDx5rfwV7GjNdkb69I8UwmOaJidu0HBfinm0s32qTK8KJm+0 Dvw6sEgDZzTeKeVBjBH2iOyUGsEn8UsrTta7ThszZnzy9CvcfsIimrz8dTRkwK8uPR8s 6V3V4UHMmUTUySWj55AICttLfFBeg85wKVxkzcjgQGtFR9KJBygNXOu2TL7FH4efi5eB 5QPX5E6wFw4W4ZfzYCRUgJPgLo/v5D8/B1Wy6Cab6jA+LTAfvW+1xKTf0zN1pFurb/aW Q7Pw== X-Gm-Message-State: ACgBeo2VhipBzg/82mNxd3+Cg7RnER4p9/iwSwErsVXYtgP0ymSi7/j1 1+rC/xeL7omJ3YGht5dEIQYipw== X-Received: by 2002:a5d:458e:0:b0:228:cd6e:dc56 with SMTP id p14-20020a5d458e000000b00228cd6edc56mr8365812wrq.614.1662730850778; Fri, 09 Sep 2022 06:40:50 -0700 (PDT) Received: from hackbox.lan ([94.52.112.99]) by smtp.gmail.com with ESMTPSA id q20-20020a1cf314000000b003a604a29a34sm660622wmq.35.2022.09.09.06.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 06:40:50 -0700 (PDT) From: Abel Vesa 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@vger.kernel.org, Linux Kernel Mailing List , 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 Message-Id: <20220909133938.3518520-9-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220909133938.3518520-1-abel.vesa@linaro.org> References: <20220909133938.3518520-1-abel.vesa@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 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