From patchwork Thu Mar 7 10:12:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10842607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02ABD17E4 for ; Thu, 7 Mar 2019 10:13:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E22D12E183 for ; Thu, 7 Mar 2019 10:13:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D41542E374; Thu, 7 Mar 2019 10:13:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 755632E183 for ; Thu, 7 Mar 2019 10:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726131AbfCGKNR (ORCPT ); Thu, 7 Mar 2019 05:13:17 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44960 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbfCGKNR (ORCPT ); Thu, 7 Mar 2019 05:13:17 -0500 Received: by mail-wr1-f68.google.com with SMTP id w2so16700933wrt.11 for ; Thu, 07 Mar 2019 02:13:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o8BYMahdyLpS4J6ZFucCS3ofixQiIJoSCGVZibyHjj8=; b=mxibRsT7eF/cC6Ed0qLikadqu+huQ+J+lx0QPSPyd/w64x2ow9v2ZMCyJEe3tLVLZu XrypsmopYuOcwmFYpNQG4Ko6Hnx38/In8wp3BR0swJiyHteZFPZ9LdZAwgiQ2Ob7Az9i +1zavAurpgt+LUClF0wRabX7coBlUMXGPvRgZhxH037v0gGmVLMFy83eg8z3Cx3EvwDP yPUpMHD6PMwAzmTjIFZDgmbIjny1BkR0pEtnjFqxrmR4JdykRxZqdJMnD0YM+rzmAyYp ePKMlYlUAl9xR+Uq6DCMvhYtXCSWP4Bl1AOkkuXEXLJHSAfH7kgk5bVN0KbTelZQI6im OR1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o8BYMahdyLpS4J6ZFucCS3ofixQiIJoSCGVZibyHjj8=; b=tPCnLw+xSnoQyfiTvboI0X8iSP2VkNsoAjELt5YnALVc67sVFxLw8lBuGp8qOZ/LLU 7E6dM7rHXElp13VThxvB46+DnFROYj7KHr+wP/YxTQRm9HD4h3gNHNILR9u3PGgjFK+t 4eWaYn5xETXyKEQXU4/UAeGIb904oawhWzZ4y9fW2JhwDEnbcnl5dtcawfMYvCxQ4927 MLzzJb/ZseE4Kfip5fg5qwCLdvBmeGfOLwAp2zYrNLDvOJlQBI2kwZPbRphPly4tcq6z mD+SAxj9ivHqOdDVg7jOj0ugxhCpq23OVp+KpT1KfgfV7PusLEztUU2cBTHJpc2T7HfF kziw== X-Gm-Message-State: APjAAAU+VR4g4HaCAp1Od7dty6q9JGlkjwWxd/R38rQy5XshLXzkjS74 5ZuoRi3XfRXctw836u5MWmoF0w== X-Google-Smtp-Source: APXvYqyQGvCBC3IQlw6zZ0nfAJimJ03uAVNbdTiF9EneF5Qyse1FflLLFj+sBuBjHF6Fi9rUA2FTIg== X-Received: by 2002:adf:f792:: with SMTP id q18mr5995764wrp.324.1551953595673; Thu, 07 Mar 2019 02:13:15 -0800 (PST) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id n9sm3529767wmi.33.2019.03.07.02.13.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Mar 2019 02:13:15 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org, arnd@arndb.de Cc: linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org, bkumar@qti.qualcomm.com, linux-arm-msm@vger.kernel.org, ktadakam@qti.qualcomm.com, Thierry Escande , Srinivas Kandagatla Subject: [PATCH 1/8] misc: fastrpc: Avoid free of DMA buffer in interrupt context Date: Thu, 7 Mar 2019 10:12:22 +0000 Message-Id: <20190307101229.7856-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190307101229.7856-1-srinivas.kandagatla@linaro.org> References: <20190307101229.7856-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Escande When the remote DSP invocation is interrupted by the user, the associated DMA buffer can be freed in interrupt context causing a kernel BUG. This patch adds a worker thread associated to the fastrpc context. It is scheduled in the rpmsg callback to decrease its refcount out of the interrupt context. Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context Invoke method") Signed-off-by: Thierry Escande Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 89aec17738ef..82e7217ae87a 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -149,6 +149,7 @@ struct fastrpc_invoke_ctx { struct kref refcount; struct list_head node; /* list of ctxs */ struct completion work; + struct work_struct put_work; struct fastrpc_msg msg; struct fastrpc_user *fl; struct fastrpc_remote_arg *rpra; @@ -311,6 +312,14 @@ static void fastrpc_context_put(struct fastrpc_invoke_ctx *ctx) kref_put(&ctx->refcount, fastrpc_context_free); } +static void fastrpc_context_put_wq(struct work_struct *work) +{ + struct fastrpc_invoke_ctx *ctx = + container_of(work, struct fastrpc_invoke_ctx, put_work); + + fastrpc_context_put(ctx); +} + static struct fastrpc_invoke_ctx *fastrpc_context_alloc( struct fastrpc_user *user, u32 kernel, u32 sc, struct fastrpc_invoke_args *args) @@ -345,6 +354,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( ctx->tgid = user->tgid; ctx->cctx = cctx; init_completion(&ctx->work); + INIT_WORK(&ctx->put_work, fastrpc_context_put_wq); spin_lock(&user->lock); list_add_tail(&ctx->node, &user->pending); @@ -1349,7 +1359,13 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, ctx->retval = rsp->retval; complete(&ctx->work); - fastrpc_context_put(ctx); + + /* + * The DMA buffer associated with the context cannot be freed in + * interrupt context so schedule it through a worker thread to + * avoid a kernel BUG. + */ + schedule_work(&ctx->put_work); return 0; }