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: 159822 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7251033jad; Thu, 7 Mar 2019 02:13:29 -0800 (PST) X-Google-Smtp-Source: APXvYqwJ792ci0oabDcWG2pF4XspiJrfWqtvHVTR11At7qJZWncaYcxK7M8tS7l9ccF7rBrHLXAF X-Received: by 2002:a63:d54f:: with SMTP id v15mr10697154pgi.318.1551953609130; Thu, 07 Mar 2019 02:13:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551953609; cv=none; d=google.com; s=arc-20160816; b=TYFnhXveuJLKI7xwpUPIHbzKlM0hMUo5d/NJuy8qhYRGfqCnwixyugh9t2LVsBSgFR nSc8ZBhc0ZoC+u0hZ4pZNnJKGxBQy/o/eJQZ59mHx1uLVMKalG1H01TdoOdXvqQnkgFA 7eu+MlvHoVU9vZkscY7xhmL/LbNnJNecm2JNsaDUSebJ2y+uuMbAl9Wo462lp2CKxmMe hMB28hxMMaQ5iMwXMVjpXumfdG7Eaw/hPaq1MfKnrZILhi+8KBKh/GqpBHhribsRgLfN A47spvR51k4rl2RzZsBsNawb2sLNWZGYorS61MwwhpOhRrdoSNK3LcReRh2GgHPNOWJ8 AoZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o8BYMahdyLpS4J6ZFucCS3ofixQiIJoSCGVZibyHjj8=; b=gxdq+3Q2PHb49bU6uSLF57KmtUIqaJkSw6BPQkD7LIFwZUdE6S3yKSyE6xt72/bSep Rr70aMgWON3hAT8T+Reqv2/HV1LjrmJ0W2yXPOcuz9BLyyW7mvb0fyQB2nJB5kwWKkht IG1I0ZzQiG1K11d4hmLS5I/MlEWkqPI+PinnTnL16/kfQJleAuixC0Hl07CcZoXUZ30B UOj5z0uKqcaCnBXWjb04hqX4IvoIKyZoR3MQUpDh+UFXp6G8AWvHoPOfpLd93MBRvCFu HfGsHOI+Fzbg63N9XLoD6Zsn6ctzhmDZbfcECrWJZMevLAS1MxVAvUtpYhUwEAky+zbr dt6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mxibRsT7; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p25si3957312pff.77.2019.03.07.02.13.20; Thu, 07 Mar 2019 02:13:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mxibRsT7; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1726131AbfCGKNR (ORCPT + 15 others); 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-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 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(-) -- 2.21.0 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; }