From patchwork Thu Feb 24 13:32:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meng Tang X-Patchwork-Id: 12758587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68767C433FE for ; Thu, 24 Feb 2022 13:32:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235024AbiBXNdM (ORCPT ); Thu, 24 Feb 2022 08:33:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235022AbiBXNdL (ORCPT ); Thu, 24 Feb 2022 08:33:11 -0500 X-Greylist: delayed 9568 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 24 Feb 2022 05:32:41 PST Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AB6216DAFB for ; Thu, 24 Feb 2022 05:32:41 -0800 (PST) X-QQ-mid: bizesmtp70t1645709547tpwkhq7i Received: from localhost.localdomain (unknown [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 24 Feb 2022 21:32:20 +0800 (CST) X-QQ-SSF: 01400000002000B0F000B00A0000000 X-QQ-FEAT: /38I06TeVDt/A9RUhVZYOINAD/wPpx9pW1Fb3qmhzq4x7Q2Ua+MBKouMh0Uzn mF7ioiAmnlUyMwrWJmNKv+nmVGoBWKsVxjGl5q6nYE8pE+TExWnUpBh5SlcD/UZFVCM8Isk bRvIkO+BkFI+Vo+R9MC3qN9npU/RvArveLimfqrBtfH1aUfXiI8dUS4EHHNz68oxLxEUFUJ j4VSg9QJkWUkJBIMdt8Y2FgEob+tjpdKZ0jxDzHys7ObyddxOeYpBCEG5EBa7OsZwYK7XSy 3wxpQ7bLzxjCGFutx+fQbnjEOV6rtr4OuEtPMNineyYAsgPwEn3u+IcmfHlX0l7XI4xJ46X Ev8c7UftVm2ZQSwKxnjYepAa9bYffdyMQ1gKLRZqw1Q1vTfZvQ= X-QQ-GoodBg: 2 From: Meng Tang To: mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com Cc: guoren@kernel.org, nickhu@andestech.com, green.hu@gmail.com, deanbo422@gmail.com, ebiggers@kernel.org, tytso@mit.edu, wad@chromium.org, john.johansen@canonical.com, jmorris@namei.org, serge@hallyn.com, linux-csky@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Meng Tang Subject: [PATCH v3 1/2] fs/proc: Optimize arrays defined by struct ctl_path Date: Thu, 24 Feb 2022 21:32:16 +0800 Message-Id: <20220224133217.1755-1-tangmeng@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign2 X-QQ-Bgrelay: 1 Precedence: bulk List-ID: Previously, arrays defined by struct ctl_path is terminated with an empty one. When we actually only register one ctl_path, we've gone from 8 bytes to 16 bytes. So, I use ARRAY_SIZE() as a boundary condition to optimize it. Since the original __register_sysctl_paths is only used in fs/proc/proc_sysctl.c, in order to not change the usage of register_sysctl_paths, delete __register_sysctl_paths from include/linux/sysctl.h, change it to __register_sysctl_paths_init in fs/proc/proc_sysctl.c, and modify it with static. The register_sysctl_paths becomes __register_sysctl_paths, and the macro definition is used in include/linux/sysctl.h to expand register_sysctl_paths(path, table) to __register_sysctl_paths(path, ARRAY_SIZE(path), table). Signed-off-by: Meng Tang --- fs/proc/proc_sysctl.c | 22 +++++++++++++--------- include/linux/sysctl.h | 9 ++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 9ecd5c87e8dd..721a8bec63d6 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1589,9 +1589,10 @@ static int register_leaf_sysctl_tables(const char *path, char *pos, } /** - * __register_sysctl_paths - register a sysctl table hierarchy + * __register_sysctl_paths_init - register a sysctl table hierarchy * @set: Sysctl tree to register on * @path: The path to the directory the sysctl table is in. + * @ctl_path_num: The numbers(ARRAY_SIZE(path)) of ctl_path * @table: the top-level table structure * * Register a sysctl table hierarchy. @table should be a filled in ctl_table @@ -1599,22 +1600,23 @@ static int register_leaf_sysctl_tables(const char *path, char *pos, * * See __register_sysctl_table for more details. */ -struct ctl_table_header *__register_sysctl_paths( +static struct ctl_table_header *__register_sysctl_paths_init( struct ctl_table_set *set, - const struct ctl_path *path, struct ctl_table *table) + const struct ctl_path *path, int ctl_path_num, struct ctl_table *table) { struct ctl_table *ctl_table_arg = table; int nr_subheaders = count_subheaders(table); struct ctl_table_header *header = NULL, **subheaders, **subheader; const struct ctl_path *component; char *new_path, *pos; + int i; pos = new_path = kmalloc(PATH_MAX, GFP_KERNEL); if (!new_path) return NULL; pos[0] = '\0'; - for (component = path; component->procname; component++) { + for (component = path, i = 0; component->procname && i < ctl_path_num; component++, i++) { pos = append_path(new_path, pos, component->procname); if (!pos) goto out; @@ -1663,20 +1665,22 @@ struct ctl_table_header *__register_sysctl_paths( /** * register_sysctl_paths - register a sysctl table hierarchy * @path: The path to the directory the sysctl table is in. + * @ctl_path_num: The numbers(ARRAY_SIZE(path)) of ctl_path * @table: the top-level table structure * * Register a sysctl table hierarchy. @table should be a filled in ctl_table * array. A completely 0 filled entry terminates the table. * - * See __register_sysctl_paths for more details. + * See __register_sysctl_paths_init for more details. */ -struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, +struct ctl_table_header *__register_sysctl_paths(const struct ctl_path *path, + int ctl_path_num, struct ctl_table *table) { - return __register_sysctl_paths(&sysctl_table_root.default_set, - path, table); + return __register_sysctl_paths_init(&sysctl_table_root.default_set, + path, ctl_path_num, table); } -EXPORT_SYMBOL(register_sysctl_paths); +EXPORT_SYMBOL(__register_sysctl_paths); /** * register_sysctl_table - register a sysctl table hierarchy diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 889c995d8a08..37958aeecfb5 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -219,13 +219,12 @@ extern void retire_sysctl_set(struct ctl_table_set *set); struct ctl_table_header *__register_sysctl_table( struct ctl_table_set *set, const char *path, struct ctl_table *table); -struct ctl_table_header *__register_sysctl_paths( - struct ctl_table_set *set, - const struct ctl_path *path, struct ctl_table *table); struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table); struct ctl_table_header *register_sysctl_table(struct ctl_table * table); -struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, - struct ctl_table *table); +#define register_sysctl_paths(path, table) \ + __register_sysctl_paths(path, ARRAY_SIZE(path), table) +extern struct ctl_table_header *__register_sysctl_paths(const struct ctl_path *path, + int ctl_path_num, struct ctl_table *table); void unregister_sysctl_table(struct ctl_table_header * table); From patchwork Thu Feb 24 13:32:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meng Tang X-Patchwork-Id: 12758588 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2817FC433EF for ; Thu, 24 Feb 2022 13:32:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234246AbiBXNdQ (ORCPT ); Thu, 24 Feb 2022 08:33:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235022AbiBXNdP (ORCPT ); Thu, 24 Feb 2022 08:33:15 -0500 Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3B023D1EC for ; Thu, 24 Feb 2022 05:32:44 -0800 (PST) X-QQ-mid: bizesmtp70t1645709553teogwjqm Received: from localhost.localdomain (unknown [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 24 Feb 2022 21:32:30 +0800 (CST) X-QQ-SSF: 01400000002000B0F000B00A0000000 X-QQ-FEAT: ZKIyA7viXp0gWhLqDVbbfYxfkb1rGrN8gS7cOdtlS7mVfvwrf5J+8/rKYvFC7 C/XTCCvT/2Awyd/hxgYSSFTj/R5yQIMkL3l1RyA43TAJIF2tJMBNBuUdhQ599kCIe5m1noz kUjxq2b8nrQ7DkWyQWIlT0qleP7kc1r1cSYDdHen1miSf+NvaRlggGCd+Kcj76Wi4JNQtXE OD/CMdjoN465+2nybrK3U+NRd+oCxrEJ8AOka9iCl2ZQYRGFZRMHM7wA0RMv7GMYk3VEpUj i9W801lL0B/6+bXVsryCWraTiCKfhuVS2lzwWA2vH+BEFDlPRc3JQSZMmpH6IP7isO/tisW RW+2H+fxRLm+R8eBUnHpkjKNUUEekqKxxkEN684X+7BXf5WGJcBmalzqaVaXw== X-QQ-GoodBg: 2 From: Meng Tang To: mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com Cc: guoren@kernel.org, nickhu@andestech.com, green.hu@gmail.com, deanbo422@gmail.com, ebiggers@kernel.org, tytso@mit.edu, wad@chromium.org, john.johansen@canonical.com, jmorris@namei.org, serge@hallyn.com, linux-csky@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Meng Tang Subject: [PATCH v3 2/2] fs/proc: Optimize arrays defined by struct ctl_path Date: Thu, 24 Feb 2022 21:32:17 +0800 Message-Id: <20220224133217.1755-2-tangmeng@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220224133217.1755-1-tangmeng@uniontech.com> References: <20220224133217.1755-1-tangmeng@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign6 X-QQ-Bgrelay: 1 Precedence: bulk List-ID: Previously, arrays defined by struct ctl_path is terminated with an empty one. When we actually only register one ctl_path, we've gone from 8 bytes to 16 bytes. The optimization has been implemented in the previous patch, here to remove unnecessary terminate ctl_path with an empty one. Signed-off-by: Meng Tang --- arch/csky/abiv1/alignment.c | 5 ++--- arch/nds32/mm/alignment.c | 5 ++--- fs/verity/signature.c | 3 +-- kernel/pid_namespace.c | 2 +- kernel/seccomp.c | 3 +-- security/apparmor/lsm.c | 3 +-- security/loadpin/loadpin.c | 3 +-- security/yama/yama_lsm.c | 3 +-- 8 files changed, 10 insertions(+), 17 deletions(-) diff --git a/arch/csky/abiv1/alignment.c b/arch/csky/abiv1/alignment.c index 2df115d0e210..5c2936b29d29 100644 --- a/arch/csky/abiv1/alignment.c +++ b/arch/csky/abiv1/alignment.c @@ -340,9 +340,8 @@ static struct ctl_table sysctl_table[2] = { {} }; -static struct ctl_path sysctl_path[2] = { - {.procname = "csky"}, - {} +static struct ctl_path sysctl_path[1] = { + {.procname = "csky"} }; static int __init csky_alignment_init(void) diff --git a/arch/nds32/mm/alignment.c b/arch/nds32/mm/alignment.c index 1eb7ded6992b..5e79c01b91d6 100644 --- a/arch/nds32/mm/alignment.c +++ b/arch/nds32/mm/alignment.c @@ -560,9 +560,8 @@ static struct ctl_table nds32_sysctl_table[2] = { {} }; -static struct ctl_path nds32_path[2] = { - {.procname = "nds32"}, - {} +static struct ctl_path nds32_path[1] = { + {.procname = "nds32"} }; /* diff --git a/fs/verity/signature.c b/fs/verity/signature.c index 143a530a8008..6cdad230c438 100644 --- a/fs/verity/signature.c +++ b/fs/verity/signature.c @@ -92,8 +92,7 @@ static struct ctl_table_header *fsverity_sysctl_header; static const struct ctl_path fsverity_sysctl_path[] = { { .procname = "fs", }, - { .procname = "verity", }, - { } + { .procname = "verity", } }; static struct ctl_table fsverity_sysctl_table[] = { diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index a46a3723bc66..f4f6db65bf81 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -294,7 +294,7 @@ static struct ctl_table pid_ns_ctl_table[] = { }, { } }; -static struct ctl_path kern_path[] = { { .procname = "kernel", }, { } }; +static struct ctl_path kern_path[] = { { .procname = "kernel", } }; #endif /* CONFIG_CHECKPOINT_RESTORE */ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index db10e73d06e0..03f88d0b79f1 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -2333,8 +2333,7 @@ static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write, static struct ctl_path seccomp_sysctl_path[] = { { .procname = "kernel", }, - { .procname = "seccomp", }, - { } + { .procname = "seccomp", } }; static struct ctl_table seccomp_sysctl_table[] = { diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 4f0eecb67dde..e35c3b29742d 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1729,8 +1729,7 @@ static int apparmor_dointvec(struct ctl_table *table, int write, } static struct ctl_path apparmor_sysctl_path[] = { - { .procname = "kernel", }, - { } + { .procname = "kernel", } }; static struct ctl_table apparmor_sysctl_table[] = { diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c index b12f7d986b1e..0471b177d2e1 100644 --- a/security/loadpin/loadpin.c +++ b/security/loadpin/loadpin.c @@ -48,8 +48,7 @@ static DEFINE_SPINLOCK(pinned_root_spinlock); static struct ctl_path loadpin_sysctl_path[] = { { .procname = "kernel", }, - { .procname = "loadpin", }, - { } + { .procname = "loadpin", } }; static struct ctl_table loadpin_sysctl_table[] = { diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c index 06e226166aab..b42b61e801b1 100644 --- a/security/yama/yama_lsm.c +++ b/security/yama/yama_lsm.c @@ -449,8 +449,7 @@ static int max_scope = YAMA_SCOPE_NO_ATTACH; static struct ctl_path yama_sysctl_path[] = { { .procname = "kernel", }, - { .procname = "yama", }, - { } + { .procname = "yama", } }; static struct ctl_table yama_sysctl_table[] = {