From patchwork Sat Sep 15 00:37:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 146737 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1279274ljw; Fri, 14 Sep 2018 17:37:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYqSua5DgsOvYohCPHqD9urAKnsxym1NAh9WthyMIwcbGvGBrYHPvz3x2WKv5HdW7kncD2t X-Received: by 2002:a17:902:76c5:: with SMTP id j5-v6mr14385271plt.140.1536971871323; Fri, 14 Sep 2018 17:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536971871; cv=none; d=google.com; s=arc-20160816; b=e+oX+K5Ix3zoeJ3176GpIffdM7iFlu6+xZzfIKXPYEhWpz1Ev3wCALl7Ccs/ZeiG5f pRySsobvIvGvNlMuNqX1ayll2UBpWO0CYKy2POpfpLI7zj9yPqdTcowMH1d+PUF0lydH 1rbJ3QQxeCYIU7fNOwWa3hX/EGl+QTumL1SZnFiQg60UZQkaADroAcVtzuAi+OEEVQSi 0EHi6HDW3Eh8qMWIYZk0GRxdsKNffr+RQY0iD0NcjR8jilMuU0MQBpRGSRjS6h0Ek2EW JXI/BMXSc68muDay9EkE3/Xp4xk4G5gRZ4W9VD/OeP5gVZo9hgt8HJpUXm1q5ud6VaE0 1hdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=wLEYCzC9XufBzVfjjUNucSdiCcLogJD4kaqjN567E+s=; b=sOrDKd7c/s23aMMrKlUdXV0hdzABnsS7TfVVvgZcehtWcXzKMkSUiovJ8sy2yKPnZV GkNt8O+SX17yKHvwZsyMZmxdmjElLn+vfMqUr28/sv2oipwmvmzVtCo3fK90ymFkZqex NT88d5ujzv/gvTmSxR0pQNA5RolC6rn/5HY8FqVpT/G3biIfZPtmI+sZWlc9mG7d0CiA MdG7rSc/of2FTIsxNk7ocRRIF+rbDo14XVkMIp+FE2ZDE8mHUkOGh7mvdgE2RebfTAI/ FYxKi29YCH+xoZUqzVgStbYXiPQSy8TytG4nXcEOXY3Z+f1a2rv+V2icFrTz9keZ5hnI bj+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=GImp8Plq; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3-v6si8408047pga.137.2018.09.14.17.37.51; Fri, 14 Sep 2018 17:37:51 -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=@ti.com header.s=ti-com-17Q1 header.b=GImp8Plq; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727225AbeIOFyc (ORCPT + 32 others); Sat, 15 Sep 2018 01:54:32 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:37496 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726610AbeIOFyT (ORCPT ); Sat, 15 Sep 2018 01:54:19 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id w8F0bSGX030650; Fri, 14 Sep 2018 19:37:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1536971848; bh=wLEYCzC9XufBzVfjjUNucSdiCcLogJD4kaqjN567E+s=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=GImp8Plq9X0wJlxcM7EmsAIuMPRjI0lcXNCaDb/ZM/iCpEyF4oDP4SiP8RcUBECcF Si8H9yyuP6OZdFi0Tq66D9EL3HrHXKz3h9F7Nq9qMW/a6KQVNT7qkWcicgd1iaIJUS G2MFnLydd1iT/0dXbwp1Dkk3R7MSjGpKOQCFP/Ns= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w8F0bSPf023617; Fri, 14 Sep 2018 19:37:28 -0500 Received: from DLEE104.ent.ti.com (157.170.170.34) 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.1466.3; Fri, 14 Sep 2018 19:37:28 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 14 Sep 2018 19:37:28 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w8F0bSx9018266; Fri, 14 Sep 2018 19:37:28 -0500 Received: from localhost (irmo.dhcp.ti.com [128.247.58.153]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id w8F0bRx13351; Fri, 14 Sep 2018 19:37:27 -0500 (CDT) From: Suman Anna To: Bjorn Andersson CC: Ohad Ben-Cohen , Loic Pallardy , Arnaud Pouliquen , , , Suman Anna Subject: [PATCH 4/5] remoteproc: Introduce deny_sysfs_ops flag Date: Fri, 14 Sep 2018 19:37:24 -0500 Message-ID: <20180915003725.17549-5-s-anna@ti.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180915003725.17549-1-s-anna@ti.com> References: <20180915003725.17549-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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'. 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 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 --- drivers/remoteproc/remoteproc_sysfs.c | 8 ++++++++ include/linux/remoteproc.h | 2 ++ 2 files changed, 10 insertions(+) -- 2.18.0 diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index ce93f4d710f3..b2d8c11b89d0 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -36,6 +36,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); @@ -102,6 +106,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 75f9ca05b865..d21252b4f758 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -440,6 +440,7 @@ struct rproc_dump_segment { * @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU * @auto_boot: flag to indicate if remote processor should be auto-started + * @deny_sysfs_ops: flag to not permit sysfs operations on state and firmware * @dump_segments: list of segments in the firmware */ struct rproc { @@ -472,6 +473,7 @@ struct rproc { size_t table_sz; bool has_iommu; bool auto_boot; + bool deny_sysfs_ops; struct list_head dump_segments; };