From patchwork Sat Nov 21 03:01:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 11923131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04C1CC2D0E4 for ; Sat, 21 Nov 2020 03:02:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8AE64223FD for ; Sat, 21 Nov 2020 03:02:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="JVJ8Z9pH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727214AbgKUDCK (ORCPT ); Fri, 20 Nov 2020 22:02:10 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:50544 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbgKUDCI (ORCPT ); Fri, 20 Nov 2020 22:02:08 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0AL323gJ047229; Fri, 20 Nov 2020 21:02:03 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1605927723; bh=ZGbBvHAaW9TuS/ALC0dm1MvfWI+JMpJVqQhQoSxmGh0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=JVJ8Z9pHncmDkOGoIEtqNUZ+gAnmT/rmkFizb/ZFAAqfLM+K7ROm9DHh54TT6bCVM gO71B/FJF4dMCy24XUtrw6MG3yLQHcFHuWxxYjigpSx+MixgA+nDdnp4/oETMTyJ+4 szMvqVvbfMDEAGAvpdGCUzfmnzKxBJy8DeSrzO24= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0AL322NW021583 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 20 Nov 2020 21:02:03 -0600 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Fri, 20 Nov 2020 21:02:03 -0600 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Fri, 20 Nov 2020 21:02:02 -0600 Received: from fllv0103.dal.design.ti.com (fllv0103.dal.design.ti.com [10.247.120.73]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0AL322nG006924; Fri, 20 Nov 2020 21:02:02 -0600 Received: from localhost ([10.250.68.46]) by fllv0103.dal.design.ti.com (8.14.7/8.14.7) with ESMTP id 0AL321Q8038584; Fri, 20 Nov 2020 21:02:01 -0600 From: Suman Anna To: Bjorn Andersson , Mathieu Poirier CC: Arnaud Pouliquen , Loic Pallardy , Grzegorz Jaszczyk , Tony Lindgren , , , , Suman Anna Subject: [PATCH v2 1/3] remoteproc: Fix unbalanced boot with sysfs for no auto-boot rprocs Date: Fri, 20 Nov 2020 21:01:54 -0600 Message-ID: <20201121030156.22857-2-s-anna@ti.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201121030156.22857-1-s-anna@ti.com> References: <20201121030156.22857-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The remoteproc core performs automatic boot and shutdown of a remote processor during rproc_add() and rproc_del() for remote processors supporting 'auto-boot'. The remoteproc devices not using 'auto-boot' require either a remoteproc client driver or a userspace client to use the sysfs 'state' variable to perform the boot and shutdown. The in-kernel client drivers hold the corresponding remoteproc driver module's reference count when they acquire a rproc handle through the rproc_get_by_phandle() API, but there is no such support for userspace applications performing the boot through sysfs interface. The shutdown of a remoteproc upon removing a remoteproc platform driver is automatic only with 'auto-boot' and this can cause a remoteproc with no auto-boot to stay powered on and never freed up if booted using the sysfs interface without a matching stop, and when the remoteproc driver module is removed or unbound from the device. This will result in a memory leak as well as the corresponding remoteproc ida being never deallocated. Fix this by holding a module reference count for the remoteproc's driver during a sysfs 'start' and releasing it during the sysfs 'stop' operation. Signed-off-by: Suman Anna Acked-by: Arnaud Pouliquen --- v2: rebased version, no changes v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20180915003725.17549-2-s-anna@ti.com/ drivers/remoteproc/remoteproc_sysfs.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index d1cf7bf277c4..bd2950a246c9 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -3,6 +3,7 @@ * Remote Processor Framework */ +#include #include #include @@ -228,14 +229,27 @@ static ssize_t state_store(struct device *dev, if (rproc->state == RPROC_RUNNING) return -EBUSY; + /* + * prevent underlying implementation from being removed + * when remoteproc does not support auto-boot + */ + if (!rproc->auto_boot && + !try_module_get(dev->parent->driver->owner)) + return -EINVAL; + ret = rproc_boot(rproc); - if (ret) + if (ret) { dev_err(&rproc->dev, "Boot failed: %d\n", ret); + if (!rproc->auto_boot) + module_put(dev->parent->driver->owner); + } } else if (sysfs_streq(buf, "stop")) { if (rproc->state != RPROC_RUNNING) return -EINVAL; rproc_shutdown(rproc); + if (!rproc->auto_boot) + module_put(dev->parent->driver->owner); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; From patchwork Sat Nov 21 03:01:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 11923137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98197C64E75 for ; Sat, 21 Nov 2020 03:02:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C7A4223FD for ; Sat, 21 Nov 2020 03:02:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Lqj+7k29" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727344AbgKUDCO (ORCPT ); Fri, 20 Nov 2020 22:02:14 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:50548 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727244AbgKUDCL (ORCPT ); Fri, 20 Nov 2020 22:02:11 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0AL323Ii047239; Fri, 20 Nov 2020 21:02:03 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1605927723; bh=HMdSdR7V2x6ONvh3fs4KsUST5GUzlhQZ7uiFijupU2c=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Lqj+7k291l4uOnCc3kVwF8kQYBHb0BW5o8eF8kGAj9iRLYLA9cz/1vUohnuLBztDk +tviOeX/3dnyBSKwLsqhK6rmttpuzlfodLBoQdPnCM6UKKYlhCGssWYgYqfldg4y3S MEoKytFEBXH64ai8JApLvpaTOXndTo9ORGocMOs4= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0AL323oP021875 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 20 Nov 2020 21:02:03 -0600 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Fri, 20 Nov 2020 21:02:02 -0600 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Fri, 20 Nov 2020 21:02:03 -0600 Received: from fllv0103.dal.design.ti.com (fllv0103.dal.design.ti.com [10.247.120.73]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0AL322tm006992; Fri, 20 Nov 2020 21:02:02 -0600 Received: from localhost ([10.250.68.46]) by fllv0103.dal.design.ti.com (8.14.7/8.14.7) with ESMTP id 0AL322mX038651; Fri, 20 Nov 2020 21:02:02 -0600 From: Suman Anna To: Bjorn Andersson , Mathieu Poirier CC: Arnaud Pouliquen , Loic Pallardy , Grzegorz Jaszczyk , Tony Lindgren , , , , Suman Anna Subject: [PATCH v2 2/3] remoteproc: Introduce deny_sysfs_ops flag Date: Fri, 20 Nov 2020 21:01:55 -0600 Message-ID: <20201121030156.22857-3-s-anna@ti.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201121030156.22857-1-s-anna@ti.com> References: <20201121030156.22857-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The remoteproc framework provides sysfs interfaces for changing the firmware name and for starting/stopping a remote processor through the sysfs files 'state' and 'firmware'. The 'recovery' sysfs file can also be used similarly to control the error recovery state machine of a remoteproc. These interfaces are currently allowed irrespective of how the remoteprocs were booted (like remoteproc self auto-boot, remoteproc client-driven boot etc). These interfaces can adversely affect a remoteproc and its clients especially when a remoteproc is being controlled by a remoteproc client driver(s). Also, not all remoteproc drivers may want to support the sysfs interfaces by default. Add support to deny the sysfs state/firmware/recovery change by introducing a state flag 'deny_sysfs_ops' that the individual remoteproc drivers can set based on their usage needs. The default behavior is to allow the sysfs operations as before. Signed-off-by: Suman Anna --- v2: revised to account for the 'recovery' sysfs file as well, patch description updated accordingly v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20180915003725.17549-5-s-anna@ti.com/ drivers/remoteproc/remoteproc_sysfs.c | 12 ++++++++++++ include/linux/remoteproc.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index bd2950a246c9..3fd18a71c188 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -49,6 +49,10 @@ static ssize_t recovery_store(struct device *dev, { struct rproc *rproc = to_rproc(dev); + /* restrict sysfs operations if not allowed by remoteproc drivers */ + if (rproc->deny_sysfs_ops) + return -EPERM; + if (sysfs_streq(buf, "enabled")) { /* change the flag and begin the recovery process if needed */ rproc->recovery_disabled = false; @@ -158,6 +162,10 @@ static ssize_t firmware_store(struct device *dev, char *p; int err, len = count; + /* restrict sysfs operations if not allowed by remoteproc drivers */ + if (rproc->deny_sysfs_ops) + return -EPERM; + err = mutex_lock_interruptible(&rproc->lock); if (err) { dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, err); @@ -225,6 +233,10 @@ static ssize_t state_store(struct device *dev, struct rproc *rproc = to_rproc(dev); int ret = 0; + /* restrict sysfs operations if not allowed by remoteproc drivers */ + if (rproc->deny_sysfs_ops) + return -EPERM; + if (sysfs_streq(buf, "start")) { if (rproc->state == RPROC_RUNNING) return -EBUSY; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 3fa3ba6498e8..dbc3767f7d0e 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -508,6 +508,7 @@ struct rproc_dump_segment { * @has_iommu: flag to indicate if remote processor is behind an MMU * @auto_boot: flag to indicate if remote processor should be auto-started * @autonomous: true if an external entity has booted the remote processor + * @deny_sysfs_ops: flag to not permit sysfs operations on state, firmware and recovery * @dump_segments: list of segments in the firmware * @nb_vdev: number of vdev currently handled by rproc * @char_dev: character device of the rproc @@ -545,6 +546,7 @@ struct rproc { bool has_iommu; bool auto_boot; bool autonomous; + bool deny_sysfs_ops; struct list_head dump_segments; int nb_vdev; u8 elf_class; From patchwork Sat Nov 21 03:01:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 11923133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E06CC2D0E4 for ; Sat, 21 Nov 2020 03:02:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14336223FD for ; Sat, 21 Nov 2020 03:02:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="In7mXjrR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727221AbgKUDCK (ORCPT ); Fri, 20 Nov 2020 22:02:10 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:50546 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726799AbgKUDCJ (ORCPT ); Fri, 20 Nov 2020 22:02:09 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0AL324QI047246; Fri, 20 Nov 2020 21:02:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1605927724; bh=TC5ddzu7mwkthSoG4t+tXmM7BmxrpIfppkjKhSj731Y=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=In7mXjrRgbQ0nlWt1Qi2QKcSTGAQS0qMrWirRO6hjhvaVehJVg1ySaev+kyo+SZG3 YYggSHAUx0qlr2ZUQxvJGhuKjAS/jqIUtrDFXFxYOcSQ5O9L9d0tp6DrXVdeCiyI7M YnEybjK+GCU7CqnpNH6Bj6QsHt02buSW7Ju04Axk= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0AL324sA112239 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 20 Nov 2020 21:02:04 -0600 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Fri, 20 Nov 2020 21:02:03 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Fri, 20 Nov 2020 21:02:03 -0600 Received: from fllv0103.dal.design.ti.com (fllv0103.dal.design.ti.com [10.247.120.73]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0AL323go102487; Fri, 20 Nov 2020 21:02:03 -0600 Received: from localhost ([10.250.68.46]) by fllv0103.dal.design.ti.com (8.14.7/8.14.7) with ESMTP id 0AL322Bj038719; Fri, 20 Nov 2020 21:02:02 -0600 From: Suman Anna To: Bjorn Andersson , Mathieu Poirier CC: Arnaud Pouliquen , Loic Pallardy , Grzegorz Jaszczyk , Tony Lindgren , , , , Suman Anna Subject: [PATCH v2 3/3] remoteproc: wkup_m3: Set deny_sysfs_ops flag Date: Fri, 20 Nov 2020 21:01:56 -0600 Message-ID: <20201121030156.22857-4-s-anna@ti.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201121030156.22857-1-s-anna@ti.com> References: <20201121030156.22857-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The Wakeup M3 remote processor is controlled by the wkup_m3_ipc client driver, so set the newly introduced 'deny_sysfs_ops' flag to not allow any overriding of the remoteproc firmware or state from userspace. Signed-off-by: Suman Anna Reviewed-by: Bjorn Andersson --- v2: rebased version, no code changes, patch title adjusted slightly v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20180915003725.17549-6-s-anna@ti.com/ drivers/remoteproc/wkup_m3_rproc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/remoteproc/wkup_m3_rproc.c b/drivers/remoteproc/wkup_m3_rproc.c index b9349d684258..d92d7f32ba8d 100644 --- a/drivers/remoteproc/wkup_m3_rproc.c +++ b/drivers/remoteproc/wkup_m3_rproc.c @@ -160,6 +160,7 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev) } rproc->auto_boot = false; + rproc->deny_sysfs_ops = true; wkupm3 = rproc->priv; wkupm3->rproc = rproc;