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; } From patchwork Thu Mar 7 10:12:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 159824 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7251174jad; Thu, 7 Mar 2019 02:13:37 -0800 (PST) X-Google-Smtp-Source: APXvYqzXsYrFn3aiNZkhSjuc5JGMp56tz2NQssVIZLggN9w4eNcPYlL/+FMlqmXiK8eAep9XW49K X-Received: by 2002:a63:35ce:: with SMTP id c197mr10626749pga.281.1551953617732; Thu, 07 Mar 2019 02:13:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551953617; cv=none; d=google.com; s=arc-20160816; b=p9kDpySdcFg95DNDxtk3q+ukd3oJ9VOLsfyu4bxUGdBpOc9qPOD/mOX3mkUoFVrWRL vUOJkTGHfpP0xoSi5Hyreq/cvfJIfaYLDK5c2EA7Hh25GXnUxXC9fJ1Yyf6VTKK1pP++ UM09OziUd+ipIHZF/0xl7KDmRi3BEZgBu70CUsKt8JLuZUi+bOpcP/e4q5L7tEQIEMWE ZnliZ1FNQY1XAKPJqo41gunrhmSx5bzCnYVCY6ddEd7XRNHHkVJakrvd2ob8VmKPUwQC GTLmjGJs3Gz7iZlv82z5dM1jcqGvWxZo1OiiZvtRZ5yNcQscAAii397wx2CzOIPpuXDE XCgA== 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=tIvmnq/sBI2toQzFNBq1UWBjHh7Rzax6iQto5A1QPn4=; b=vOJAPZyq0+W+BUUnnG0VMnnERWC0pv/auLapkGFyvDSlNpLSIOWuTGdncV8od/SkUq szP7ToOzyTfF2azNW367Zyf6pM8+P4s9ypqCgFzuuXe4YbHeUVDOTrlqfPO34WOgCAdj Rrnu9CNzjiwr+XV7MYApHdI/iZRXuxB9eeyQ/daNVpbNemG5HfiDwQcqubJOVlAvXeje aAVpB6sJTqixGofGlZTed1rVwJ79fBzQsC/5koxG5q+T1n/2qViaeu/sQtuND9kDVAcK hLMwgdmkp60KaiHg+w28aVWoTl1L6S7VuP5Bb7sNGsYj/uV5355TUttkCS0dOhVFffDo Zcrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jwm/QQvV"; 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.29; Thu, 07 Mar 2019 02:13:37 -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="jwm/QQvV"; 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 S1726452AbfCGKNV (ORCPT + 15 others); Thu, 7 Mar 2019 05:13:21 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35901 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726423AbfCGKNU (ORCPT ); Thu, 7 Mar 2019 05:13:20 -0500 Received: by mail-wr1-f65.google.com with SMTP id o17so16728484wrw.3 for ; Thu, 07 Mar 2019 02:13:19 -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=tIvmnq/sBI2toQzFNBq1UWBjHh7Rzax6iQto5A1QPn4=; b=jwm/QQvVT820lCl/gDoXVSyfY49C96sNHRAx6goCkxIRuQjhbxGY2YzDjLN/Phxihs pDGD0+vlMvxsVVnqPvV0oQfLnTgAt36yCGbbRJm59/802ESMlGNwaEHwiGRyTUVPd9dN VGNu3Y0xoGzaDTqXeuSQFpmY+okIlsdT/8KKWjqH0GhNtg8DclT/umfe7k4RV2mXJw2k r+5RNAYi1CtNhPJXyQg3BLyHyiyVABjpQJ/9W86jfQNBn00k7zpQzQf9Pcv9bANIXLkX Qx0tH9023PoEG9eUMZXYCNyVeKcafnbeItRGu00II2U231wYij/5rW7RMdzmqaMMgDS/ 31Sg== 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=tIvmnq/sBI2toQzFNBq1UWBjHh7Rzax6iQto5A1QPn4=; b=XqvN/xAYKlaGZvE1KGuXUNm1w9cpAV7aT6o544bog4SYraJJHNMvDZrI6KaYl4iBNC sXsI1Q6DrYA0fsU3PE51YewqiI4ao7qU3dQzFc2aYIezTXoiWyrYI/io5fON+IBraz8Q O43+Moa5gr61nxSLyqPH8bc/lQLF2h2mPDPovq+1bnfCi/JdYFiifA46Of5xWhKplbs7 txlmGrU14KUeUlVQnwMvt90n54trUkO/Uh/SO1L8U38Hdmc66EMOC9vsYpnXGLgBsmpU RlF8UjQ0jzmckPo1uxiA7DhIzHohjrMCZyLkL4B1H27C52C6FAs8XieAtagQP/SMStD8 LHaw== X-Gm-Message-State: APjAAAWR3LvZI3VbovrAxfgxlinVfw/0msq1SOvhKzwgtb+qzBD/X0uk MmpscxwKaApH+Rw2edIpbfN4uA== X-Received: by 2002:adf:e949:: with SMTP id m9mr6640281wrn.1.1551953598190; Thu, 07 Mar 2019 02:13:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Mar 2019 02:13:17 -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, Srinivas Kandagatla Subject: [PATCH 3/8] misc: fastrpc: make sure memory read and writes are visible Date: Thu, 7 Mar 2019 10:12:24 +0000 Message-Id: <20190307101229.7856-4-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 dma_alloc_coherent buffers could have writes queued in store buffers so commit them before sending buffer to DSP using correct dma barriers. Same with vice-versa. Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context Invoke method") Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.21.0 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 8fbcc607a77e..753d62ceb1fb 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -792,6 +792,9 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, if (err) goto bail; } + + /* make sure that all CPU memory writes are seen by DSP */ + dma_wmb(); /* Send invoke buffer to remote dsp */ err = fastrpc_invoke_send(fl->sctx, ctx, kernel, handle); if (err) @@ -808,6 +811,8 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, goto bail; if (ctx->nscalars) { + /* make sure that all memory writes by DSP are seen by CPU */ + dma_rmb(); /* populate all the output buffers with results */ err = fastrpc_put_args(ctx, kernel); if (err)