From patchwork Thu May 5 13:29:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 67208 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp752278qge; Thu, 5 May 2016 06:32:53 -0700 (PDT) X-Received: by 10.66.49.230 with SMTP id x6mr20626101pan.100.1462455173312; Thu, 05 May 2016 06:32:53 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fo1si11456383pad.118.2016.05.05.06.32.53; Thu, 05 May 2016 06:32:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757384AbcEENcv (ORCPT + 29 others); Thu, 5 May 2016 09:32:51 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:35233 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756412AbcEENbn (ORCPT ); Thu, 5 May 2016 09:31:43 -0400 Received: by mail-wm0-f43.google.com with SMTP id e201so20712726wme.0 for ; Thu, 05 May 2016 06:31:42 -0700 (PDT) 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; bh=DulChJXG5IMQ6PqkZhCoOc5LeMx5iXxiuA+oaAVI8ZI=; b=QVgDeFmPD/ByPq3vTflEnLK6rQo/hRlLOTCKbEQoXOv7w97e8HqOFiq1lFZXkEGgnC ZBsi8Ii+/k6B2+huNudkumUdl9BeDURjsrNVC2uBdSgca7LhK53gf1qnQD6/N8Rq1Jvc gb2Pm4LwQuD7bBAo0FDEOb+ZDlhXuLo5DVa0s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DulChJXG5IMQ6PqkZhCoOc5LeMx5iXxiuA+oaAVI8ZI=; b=fafRRBdCmrjq3t+rFLkuXiX6JZRPXuNVPRGmrMFP2wf89/h/1i6pxxgeg4niraYM0K 7EtC3vdAQYvys4tWDR/3oloJe5j7bEOmy4WfcTz3mtDmJCTii1SAZ9yPDuF9IEc45BIK 5JUir3mEnoghe/Qk3kien+bp0q6wqrN6EoNkD/zl7XQ08rX5jtc5iaUU+wE9CjNLUOlf H9xD5Fmm7YlCbrg9rwJSI+GV4HD/uECC4R6mrGnXzI1mJpS/YHEtGk+g/tCQlHuuGIQW xi/fkW8yclteoEQpZYCR58ROdlJ29xLHlj9hNFARx2CfAQSf3H/nbXhk7YASWkpyiVlf v9hg== X-Gm-Message-State: AOPr4FVAk8llAHZpeJovwk0+LKuqe98JxtrWjBE8mCOK38Y8v3VyCniCgGhNdkBuD3bozk49 X-Received: by 10.28.152.212 with SMTP id a203mr3523089wme.95.1462455101739; Thu, 05 May 2016 06:31:41 -0700 (PDT) Received: from localhost.localdomain (host81-129-173-198.range81-129.btcentralplus.com. [81.129.173.198]) by smtp.gmail.com with ESMTPSA id lf9sm9776868wjc.44.2016.05.05.06.31.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 May 2016 06:31:41 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, maxime.coquelin@st.com, ohad@wizery.com, bjorn.andersson@linaro.org, linux-remoteproc@vger.kernel.org, Lee Jones , Fabrice Gasnier Subject: [PATCH 1/5] remoteproc: core: Task sync during rproc_fw_boot() Date: Thu, 5 May 2016 14:29:39 +0100 Message-Id: <1462454983-13168-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1462454983-13168-1-git-send-email-lee.jones@linaro.org> References: <1462454983-13168-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By default, rproc_fw_boot() needs to wait for rproc to be configured, but a race may occur when using rpmsg/virtio. In this case, it can be called locally in a safe manor. This patch represents two usecases: - External call (via exported rproc_boot()), which waits - Internal call can use 'nowait' version of rproc_boot() Signed-off-by: Fabrice Gasnier Signed-off-by: Lee Jones --- drivers/remoteproc/remoteproc_core.c | 29 +++++++++++++++++++++++++++-- drivers/remoteproc/remoteproc_internal.h | 1 + drivers/remoteproc/remoteproc_virtio.c | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) -- 2.8.0 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ee44df5..7db2818 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1033,8 +1033,9 @@ static void rproc_crash_handler_work(struct work_struct *work) } /** - * rproc_boot() - boot a remote processor + * __rproc_boot() - boot a remote processor * @rproc: handle of a remote processor + * @wait: wait for rproc registration completion * * Boot a remote processor (i.e. load its firmware, power it on, ...). * @@ -1043,7 +1044,7 @@ static void rproc_crash_handler_work(struct work_struct *work) * * Returns 0 on success, and an appropriate error value otherwise. */ -int rproc_boot(struct rproc *rproc) +static int __rproc_boot(struct rproc *rproc, bool wait) { const struct firmware *firmware_p; struct device *dev; @@ -1091,6 +1092,10 @@ int rproc_boot(struct rproc *rproc) goto downref_rproc; } + /* if rproc virtio is not yet configured, wait */ + if (wait) + wait_for_completion(&rproc->firmware_loading_complete); + ret = rproc_fw_boot(rproc, firmware_p); release_firmware(firmware_p); @@ -1104,9 +1109,29 @@ unlock_mutex: mutex_unlock(&rproc->lock); return ret; } + +/** + * rproc_boot() - boot a remote processor + * @rproc: handle of a remote processor + */ +int rproc_boot(struct rproc *rproc) +{ + return __rproc_boot(rproc, true); +} EXPORT_SYMBOL(rproc_boot); /** + * rproc_boot_nowait() - boot a remote processor + * @rproc: handle of a remote processor + * + * Same as rproc_boot() but don't wait for rproc registration completion + */ +int rproc_boot_nowait(struct rproc *rproc) +{ + return __rproc_boot(rproc, false); +} + +/** * rproc_shutdown() - power off the remote processor * @rproc: the remote processor * diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 8041b95..57e1de5 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -48,6 +48,7 @@ struct rproc_fw_ops { /* from remoteproc_core.c */ void rproc_release(struct kref *kref); irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); +int rproc_boot_nowait(struct rproc *rproc); /* from remoteproc_virtio.c */ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id); diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index ff30684..106d9e4 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -175,7 +175,7 @@ static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs, } /* now that the vqs are all set, boot the remote processor */ - ret = rproc_boot(rproc); + ret = rproc_boot_nowait(rproc); if (ret) { dev_err(&rproc->dev, "rproc_boot() failed %d\n", ret); goto error;