From: Xiaoming Ni <nixiaoming@huawei.com>
To: Joe Perches <joe@perches.com>,
Andrew Morton <akpm@linux-foundation.org>,
Julia Lawall <Julia.Lawall@inria.fr>, <cocci@inria.fr>
Cc: <linux-kernel@vger.kernel.org>, <mcgrof@kernel.org>,
<viro@zeniv.linux.org.uk>, <ebiederm@xmission.com>,
<keescook@chromium.org>, <jlayton@kernel.org>,
<bfields@fieldses.org>, <yzaikin@google.com>,
<wangle6@huawei.com>
Subject: Re: [PATCH] sysctl: Add a group of macro functions to initcall the sysctl table of each feature
Date: Tue, 7 Dec 2021 14:25:14 +0800 [thread overview]
Message-ID: <ce96717e-3f18-bf9e-90e2-a482be33a488@huawei.com> (raw)
In-Reply-To: <80e800b505adf8a26b2ed9898d03516263a830a7.camel@perches.com>
On 2021/12/7 9:50, Joe Perches wrote:
> On Mon, 2021-12-06 at 17:38 -0800, Andrew Morton wrote:
>> On Tue, 7 Dec 2021 09:13:20 +0800 Xiaoming Ni <nixiaoming@huawei.com> wrote:
>>
>>> To avoid duplicated code, add a set of macro functions to initialize the
>>> sysctl table for each feature.
>>>
>>> The system initialization process is as follows:
>>>
>>> start_kernel () {
>>> ...
>>> /* init proc and sysctl base,
>>> * proc_root_init()-->proc_sys_init()-->sysctl_init_bases()
>>> */
>>> proc_root_init(); /* init proc and sysctl base */
>>> ...
>>> arch_call_rest_init();
>>> }
>>>
>>> arch_call_rest_init()-->rest_init()-->kernel_init()
>>> kernel_init() {
>>> ...
>>> kernel_init_freeable(); /* do all initcalls */
>>> ...
>>> do_sysctl_args(); /* Process the sysctl parameter: sysctl.*= */
>>> }
>>>
>>> kernel_init_freeable()--->do_basic_setup()-->do_initcalls()
>>> do_initcalls() {
>>> for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) {
>>> do_initcall_level
>>> }
>>>
>>> The sysctl interface of each subfeature should be registered after
>>> sysctl_init_bases() and before do_sysctl_args(). It seems that the sysctl
>>> interface does not depend on initcall_levels. To prevent the sysctl
>>> interface from being initialized before the feature itself. The
>>> lowest-level late_initcall() is used as the common sysctl interface
>>> registration level.
>>
>> I'm not normally a fan of wrapping commonly-used code sequences into
>> magical macros, but this one does seem to make sense.
>>
>> I wonder if it is possible to cook up a checkpatch rule to tell people
>> to henceforth use the magic macros rather than to open-code things in
>> the old way. Sounds hard.
>
> Almost impossible for checkpatch.
> Likely easier in coccinelle.
>
Maybe we can add a rudimentary check to the checkpatch.
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b01c36a15d9d..26e953ae4cc5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7212,6 +7212,12 @@ sub process {
"Deprecated use of '$deprecated_api',
prefer '$new_api' instead\n" . $herecurr);
}
+# check register_sysctl_init
+ if ($prevline =~ /{/ && $rawline =~
/\sregister_sysctl_init\(\"(kernel|fs|vm|debug|dev)\",\s+(.*)\)\;/) {
+ WARN("DEPRECATED_API",
+ "Deprecated use of
'register_sysctl_init(\"$1\", $2);', prefer '$1_sysctl_initcall($2);'
instead\n".$herecurr);
+ }
+
# check for various structs that are normally const (ops, kgdb,
device_tree)
# and avoid what seem like struct definitions 'struct foo {'
if (defined($const_structs) &&
Thanks
Xiaoming Ni
next prev parent reply other threads:[~2021-12-07 6:25 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-07 1:13 Xiaoming Ni
2021-12-07 1:38 ` Andrew Morton
2021-12-07 1:50 ` Joe Perches
2021-12-07 6:25 ` Xiaoming Ni [this message]
2021-12-07 6:30 ` Julia Lawall
2021-12-07 3:09 ` Xiaoming Ni
2021-12-07 20:18 ` Luis Chamberlain
2021-12-07 21:08 ` Eric W. Biederman
2021-12-07 22:39 ` Luis Chamberlain
2021-12-08 2:10 ` Xiaoming Ni
2021-12-08 2:44 ` Luis Chamberlain
2021-12-08 12:34 ` Xiaoming Ni
2021-12-08 20:05 ` Luis Chamberlain
2021-12-10 8:58 ` [PATCH v2] " Xiaoming Ni
2021-12-10 17:20 ` Luis Chamberlain
2021-12-12 9:58 ` Xiaoming Ni
2021-12-13 3:31 ` [PATCH v3] " Xiaoming Ni
2021-12-19 21:32 ` Luis Chamberlain
2021-12-13 16:04 ` [PATCH] " Eric W. Biederman
2021-12-13 21:29 ` Luis Chamberlain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ce96717e-3f18-bf9e-90e2-a482be33a488@huawei.com \
--to=nixiaoming@huawei.com \
--cc=Julia.Lawall@inria.fr \
--cc=akpm@linux-foundation.org \
--cc=bfields@fieldses.org \
--cc=cocci@inria.fr \
--cc=ebiederm@xmission.com \
--cc=jlayton@kernel.org \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=wangle6@huawei.com \
--cc=yzaikin@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®