Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp895854pxb; Tue, 1 Feb 2022 12:40:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUjGWggDAqeeuyIoW7da0CvPcNmBKzE5zzVNlxvZmfOkZVMfAJTMVkbmOde6lLqKJMXVau X-Received: by 2002:a05:6a00:b96:: with SMTP id g22mr5236095pfj.31.1643748017859; Tue, 01 Feb 2022 12:40:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643748017; cv=none; d=google.com; s=arc-20160816; b=lmEN3Kzx6jmSRLdxlmKelkxdszogoWxLNKdNjspg4mWIg0wgRyoxH2VoGCn1pFHZQD P5DrYOj/blanvtiEpwLm5ppOS8jbWVgsrDPannF3l+BlEt+tQ2Ej4MvLSetG4yIBOvqf dlHvm5pwSnnZqufSQNHqQHy1zal1E7euc7QTjW8kafllRFBOLpqLrPSXwT0G8Hz7CqI1 2h+r+3Mi2cNnF/t5+qBHd6Mp+0b6zyk8l0bBXV9kYhxh047Ldx459ul/Dc0Kozam2sVW um4meG1Y7o+sI0OdDLRxHN6hHX5i7T8ufSFlNDbPme775g89XYBM8Km1i7uFGkg2xOAc ZbPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=tnE0wyNxKHyZ8k775+KkUncgCdQA0PjnSA4/A1ZW6ec=; b=yLh0TNLOQJ4w9px7jlHdle3xAz5n8oqfpA6Vi9Bzvmn0wxU1mceE2t5hT4FmEw40r+ PLI6PP3DRQtjtj6V7wp1dqUkTNJF1UOIm1CKI3EiuCoJQ1DTtYyYWpXautGPQvuaZwaw pCWs8AAbtP60+Xj071RLeWbLlIF+Q8ZUjGLswrN7csqvryQcRHA9qtGm+xuXSixjmmzK s4v5JJONm+nfPlRfP3wGDzMIWZBIAOq7pd9YtwFLkZlKP4rr5XTWw/mbVfw7ktred8a0 k+VJoUhfwCXGvtnki7sTXYUIHqSzhpmU1hYXcpFhkT+Nn9JF0S13HNZKEJE4h3Yd4+7G mAOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OgFVT7pc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h184si4634814pge.254.2022.02.01.12.40.06; Tue, 01 Feb 2022 12:40:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OgFVT7pc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379271AbiAaOMW (ORCPT + 99 others); Mon, 31 Jan 2022 09:12:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379262AbiAaOMR (ORCPT ); Mon, 31 Jan 2022 09:12:17 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C3BC06173B; Mon, 31 Jan 2022 06:12:17 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id e9so12366307pgb.3; Mon, 31 Jan 2022 06:12:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tnE0wyNxKHyZ8k775+KkUncgCdQA0PjnSA4/A1ZW6ec=; b=OgFVT7pc9LR34GJPj68Tu0P0fwiOPndqLk8x/rqxdHzZkpdNVDRhjTMpzRbVjPLBpH SnxXrqexOnecBmouCk/oCqCbBhhrXDHfwoFbF9hYBhmSBnp4GWI7zFtrPU5Q2UMAsNFH XLyE84mza2IsyF+JiBElRSAv27ta26OPapKt/3g7RDvT+HBDloWr7MW6r1ITJtUh+fIx /x1V3VNR1Dzh5Y7K5kt0Fmb4VOBaZjqh2xJKIs9h8zGikpt6EJKMqxlLzCaE2WHiOwOe qCIv1TkVBgPvoyO6bs7X9eA1ONaGTEqAxW3J2utrsc97DShmr8i+N1w3icc5hobWVQO0 7EmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tnE0wyNxKHyZ8k775+KkUncgCdQA0PjnSA4/A1ZW6ec=; b=4JRXKghZU4pltvjo6or/xr9B5zX78jehbU/TFYrZKzL4nwAoe7TJsVIyzjlFoLmOcr qvD+7J7EJhrwXr/NQXOEAXgD/vxKsxr4AWhxHcxlkpX4krAwjNNvIy3UJ6jmNYtYJeeh 329tLbkJpmW99asZMkaMSmWNCD49jJRKoOZ9F1MaJ6x545k1vGqp7wN2CPndUn1v2vIV cGdNhcGWYmH6LxwQKv7ewGZF707klU/HGhQWPocOB8XwGAHZRHfXoCOo1yBxchgvLGMd Dkv2xac7P7fsb0ZrZwd/y+FcYOIducNWsJWQwhMKCcE70lTBAKE8GrgzkAeQVtmR8zoi 702Q== X-Gm-Message-State: AOAM532NTBS62EAnXpzo1eGBkzrFPVcx+M8aDuDLMaZI1A9SA310fUqx LkrXUR3EB717Spdm68Yz9XalYz2TdM4= X-Received: by 2002:a63:1002:: with SMTP id f2mr16848056pgl.388.1643638336672; Mon, 31 Jan 2022 06:12:16 -0800 (PST) Received: from localhost.localdomain ([124.253.246.115]) by smtp.googlemail.com with ESMTPSA id g12sm18101682pfm.119.2022.01.31.06.12.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Jan 2022 06:12:16 -0800 (PST) From: Puranjay Mohan X-Google-Original-From: Puranjay Mohan To: kishon@ti.com, vigneshr@ti.com, s-anna@ti.com, bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Puranjay Mohan Subject: [PATCH 1/2] remoteproc: Introduce deny_sysfs_ops flag Date: Mon, 31 Jan 2022 19:41:51 +0530 Message-Id: <1643638312-3912-2-git-send-email-p-mohan@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1643638312-3912-1-git-send-email-p-mohan@ti.com> References: <1643638312-3912-1-git-send-email-p-mohan@ti.com> 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'. 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. Implement attribute_group->is_visible() to hide the sysfs state/firmware/recovery entries when deny_sysfs_ops flag is set. Signed-off-by: Puranjay Mohan --- drivers/remoteproc/remoteproc_sysfs.c | 18 +++++++++++++++++- include/linux/remoteproc.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index ea8b89f97d7b..4a41abdd1f7b 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -230,6 +230,21 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(name); +static umode_t rproc_is_visible(struct kobject *kobj, struct attribute *attr, + int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct rproc *rproc = to_rproc(dev); + umode_t mode = attr->mode; + + if (rproc->deny_sysfs_ops && (attr == &dev_attr_recovery.attr || + attr == &dev_attr_firmware.attr || + attr == &dev_attr_state.attr)) + mode = 0; + + return mode; +} + static struct attribute *rproc_attrs[] = { &dev_attr_coredump.attr, &dev_attr_recovery.attr, @@ -240,7 +255,8 @@ static struct attribute *rproc_attrs[] = { }; static const struct attribute_group rproc_devgroup = { - .attrs = rproc_attrs + .attrs = rproc_attrs, + .is_visible = rproc_is_visible, }; static const struct attribute_group *rproc_devgroups[] = { diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index e0600e1e5c17..3849c66ce38f 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -523,6 +523,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, firmware and recovery * @dump_segments: list of segments in the firmware * @nb_vdev: number of vdev currently handled by rproc * @elf_class: firmware ELF class @@ -562,6 +563,7 @@ struct rproc { size_t table_sz; bool has_iommu; bool auto_boot; + bool deny_sysfs_ops; struct list_head dump_segments; int nb_vdev; u8 elf_class; -- 2.24.3