From patchwork Tue Jan 10 11:45:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Chen X-Patchwork-Id: 41420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2698620wrt; Tue, 10 Jan 2023 03:50:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXs1wybHSnFIpa2mFel80uHPWhNdTwPQG69rL8WVKWeMRtiuYThU06Kfu0euIfbWwtHkr9lb X-Received: by 2002:a17:902:9b8f:b0:192:6d68:158 with SMTP id y15-20020a1709029b8f00b001926d680158mr63186650plp.15.1673351439149; Tue, 10 Jan 2023 03:50:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673351439; cv=pass; d=google.com; s=arc-20160816; b=Y4Dy+yYcqZxG2yD4yQ4vvjXqdZb2/crvs+pAvouULkEXuCE/RU4YGo5iL92bBtqEjO z78KTZY2PmtngDPiAl+E1X9w/9QQzGKOisGBuPoZjRiqkTwFFKE3UckTR31vkRiBeqpJ DvEn32OG3SCtv7O585WyaF80EJa1iAN6dWexbr2A+atKeVXhq1Io51cXKqxkvY8Z+SXz VfV8k9zeQDwvJ9BxYy/JIVaTC5/RwV6xSbMMu7q667D/FN4tgnrSaeYJ+RsbV4M+HN7f DSaVzUnnG0p0ut4BSYkXrrDfJZ0IylzJ3oOd96lt9qg5FlZE3ngV1otcjQ3Fh2ZAoP14 wktw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=RPawfXkHoPL7Y8+J9U9JKYo2P4bL8EODHWvhtbG7JUM=; b=ReuRtQFvpptxfhVDFmw1WJSEdsd4RIlFofij3ftLq7z9D8q0m3CB2kSGjjiVagiuwc CIFLos4HNRqcDJKmnZTZvE+Ri4S99oJ5i+CszcHK4uFIhvb6zoGaUBV2/5ZlubpK8G4e lFDtxbZf4rtfu0jo9WPzCb+bq5n+kaVouvWSI93IyKBZUyXxcEjO6GLE48UwL5rCQ1pJ 7pCinJ+X6gLYczkitht6RvzpKJ2Qj6luV+zi2ITO0L8bCKBwQhW7gClFB1P3ER3gR+Cf 6NDaAJSCdRySOOn4tSfVstTpI3742d4LKDTesp/WIKvZosqH2gyMeVWJ9rUrKRfvhXaC kzEw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.beauty header.s=zmail header.b=cMBmQMqp; arc=pass (i=1 spf=pass spfdomain=linux.beauty dkim=pass dkdomain=linux.beauty dmarc=pass fromdomain=linux.beauty>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a170902680800b00192c7f19784si10150343plk.546.2023.01.10.03.50.26; Tue, 10 Jan 2023 03:50:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.beauty header.s=zmail header.b=cMBmQMqp; arc=pass (i=1 spf=pass spfdomain=linux.beauty dkim=pass dkdomain=linux.beauty dmarc=pass fromdomain=linux.beauty>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232513AbjAJLqf (ORCPT + 99 others); Tue, 10 Jan 2023 06:46:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230406AbjAJLqb (ORCPT ); Tue, 10 Jan 2023 06:46:31 -0500 Received: from sender4-op-o14.zoho.com (sender4-op-o14.zoho.com [136.143.188.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0B3948CD1; Tue, 10 Jan 2023 03:46:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673351179; cv=none; d=zohomail.com; s=zohoarc; b=KzUVpDH4yAJRpJ8xxKrcI+ABzCtsWIvYAoBfYdqUdr/YMp/f3h85IauWXnvUxpShHj9kIewwWpnIChCUKGm+DQI+nTbQQ98Lune8Qz4IDoKgR3ZQ3neEQg5vGn+gOTUn3sqGcbCKfQPSKmwNrFuSXndoGADHwDir7m2ChGKUODM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673351179; h=Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=RPawfXkHoPL7Y8+J9U9JKYo2P4bL8EODHWvhtbG7JUM=; b=noo5uskees5bJsL53OoThxFJ7Aj5kyxkAaVZD/CDqhRwnVY1FZS50srIgWA9DBg/Sa/4QTmoIyTc+SDgGuaYhJLaVumrENjeNatf0WIHKRoFcJbtQDIqWJs75uhkMvay8kdn1BAngoFfUBKlP/rOU212mJaam8I8pv1Wy+1zW90= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1673351179; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=RPawfXkHoPL7Y8+J9U9JKYo2P4bL8EODHWvhtbG7JUM=; b=cMBmQMqpuLqyn71C4hiies8itTeQAPKfHZLKzwv4/wR3TvNFR45elQf7Yz2ggUal rFTSIinvxMCQhd3FYt7QUg+38wL2qePJYt3Zns7q7T5lYex3tHkJXmDBdXMx9yZNyH/ AeLfz+huOtWh/+9P1kcMLaGG1C6Njp3LOMiq5v8o= Received: from shbuild9.ambarella.net (116.246.37.178 [116.246.37.178]) by mx.zohomail.com with SMTPS id 1673351177408190.58179689203598; Tue, 10 Jan 2023 03:46:17 -0800 (PST) From: Li Chen To: Michael Turquette , Stephen Boyd Cc: Li Chen , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: create write_enable file to control clk rate write and other dangerous ops permission Date: Tue, 10 Jan 2023 19:45:39 +0800 Message-Id: <20230110114540.2975540-1-me@linux.beauty> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-ZohoMailClient: External X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754636158535908181?= X-GMAIL-MSGID: =?utf-8?q?1754636158535908181?= From: Li Chen It's common requirement for bsp debug/test to change clk rate from userspace. Currently, we must define CLKOCK_ALLOW_WRITE_DEBUGFS then re-compile kernel to allow this feature. Let's replace it with a "write_enable" file to allow enable it at runtime. Signed-off-by: Li Chen Change-Id: Ic4bf94c572c24f6979c2b7aea042fec654370220 --- drivers/clk/clk.c | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index e62552a75f08..668f691bf67a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -89,6 +89,7 @@ struct clk_core { struct hlist_node debug_node; #endif struct kref ref; + bool write_enable; }; #define CREATE_TRACE_POINTS @@ -3263,8 +3264,6 @@ static int clk_dump_show(struct seq_file *s, void *data) } DEFINE_SHOW_ATTRIBUTE(clk_dump); -#undef CLOCK_ALLOW_WRITE_DEBUGFS -#ifdef CLOCK_ALLOW_WRITE_DEBUGFS /* * This can be dangerous, therefore don't provide any real compile time * configuration option for this feature. @@ -3275,6 +3274,9 @@ static int clk_rate_set(void *data, u64 val) struct clk_core *core = data; int ret; + if (!core->write_enable) + return -EACCES; + clk_prepare_lock(); ret = clk_core_set_rate_nolock(core, val); clk_prepare_unlock(); @@ -3289,6 +3291,9 @@ static int clk_prepare_enable_set(void *data, u64 val) struct clk_core *core = data; int ret = 0; + if (!core->write_enable) + return -EACCES; + if (val) ret = clk_prepare_enable(core->hw->clk); else @@ -3301,6 +3306,9 @@ static int clk_prepare_enable_get(void *data, u64 *val) { struct clk_core *core = data; + if (!core->write_enable) + return -EACCES; + *val = core->enable_count && core->prepare_count; return 0; } @@ -3308,11 +3316,6 @@ static int clk_prepare_enable_get(void *data, u64 *val) DEFINE_DEBUGFS_ATTRIBUTE(clk_prepare_enable_fops, clk_prepare_enable_get, clk_prepare_enable_set, "%llu\n"); -#else -#define clk_rate_set NULL -#define clk_rate_mode 0444 -#endif - static int clk_rate_get(void *data, u64 *val) { struct clk_core *core = data; @@ -3426,7 +3429,6 @@ static int current_parent_show(struct seq_file *s, void *data) } DEFINE_SHOW_ATTRIBUTE(current_parent); -#ifdef CLOCK_ALLOW_WRITE_DEBUGFS static ssize_t current_parent_write(struct file *file, const char __user *ubuf, size_t count, loff_t *ppos) { @@ -3460,7 +3462,6 @@ static const struct file_operations current_parent_rw_fops = { .llseek = seq_lseek, .release = single_release, }; -#endif static int clk_duty_cycle_show(struct seq_file *s, void *data) { @@ -3524,7 +3525,6 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry) debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); debugfs_create_file("clk_duty_cycle", 0444, root, core, &clk_duty_cycle_fops); -#ifdef CLOCK_ALLOW_WRITE_DEBUGFS debugfs_create_file("clk_prepare_enable", 0644, root, core, &clk_prepare_enable_fops); @@ -3532,7 +3532,6 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry) debugfs_create_file("clk_parent", 0644, root, core, ¤t_parent_rw_fops); else -#endif if (core->num_parents > 0) debugfs_create_file("clk_parent", 0444, root, core, ¤t_parent_fops); @@ -3592,24 +3591,6 @@ static int __init clk_debug_init(void) { struct clk_core *core; -#ifdef CLOCK_ALLOW_WRITE_DEBUGFS - pr_warn("\n"); - pr_warn("********************************************************************\n"); - pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); - pr_warn("** **\n"); - pr_warn("** WRITEABLE clk DebugFS SUPPORT HAS BEEN ENABLED IN THIS KERNEL **\n"); - pr_warn("** **\n"); - pr_warn("** This means that this kernel is built to expose clk operations **\n"); - pr_warn("** such as parent or rate setting, enabling, disabling, etc. **\n"); - pr_warn("** to userspace, which may compromise security on your system. **\n"); - pr_warn("** **\n"); - pr_warn("** If you see this message and you are not debugging the **\n"); - pr_warn("** kernel, report this immediately to your vendor! **\n"); - pr_warn("** **\n"); - pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); - pr_warn("********************************************************************\n"); -#endif - rootdir = debugfs_create_dir("clk", NULL); debugfs_create_file("clk_summary", 0444, rootdir, &all_lists,