From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 151D8C43331 for ; Tue, 24 Mar 2020 16:50:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE71420774 for ; Tue, 24 Mar 2020 16:50:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE71420774 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 66A246B0005; Tue, 24 Mar 2020 12:50:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F54D6B0006; Tue, 24 Mar 2020 12:50:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E2896B0007; Tue, 24 Mar 2020 12:50:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id 30BAC6B0005 for ; Tue, 24 Mar 2020 12:50:53 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 02D7618027A67 for ; Tue, 24 Mar 2020 16:50:53 +0000 (UTC) X-FDA: 76630845186.08.tin71_5ef305e2ab45b X-HE-Tag: tin71_5ef305e2ab45b X-Filterd-Recvd-Size: 5008 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Mar 2020 16:50:52 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 67515ABCF; Tue, 24 Mar 2020 16:50:50 +0000 (UTC) Subject: Re: [RFC] kernel/sysctl: support setting sysctl parameters from kernel command line To: Kees Cook Cc: Luis Chamberlain , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org, Ivan Teterevkov , Michal Hocko , David Rientjes , Matthew Wilcox , "Eric W . Biederman" References: <20200317132105.24555-1-vbabka@suse.cz> <202003171421.5DCADF51@keescook> From: Vlastimil Babka Message-ID: Date: Tue, 24 Mar 2020 17:50:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <202003171421.5DCADF51@keescook> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/17/20 10:29 PM, Kees Cook wrote: > On Tue, Mar 17, 2020 at 02:21:05PM +0100, Vlastimil Babka wrote: >> A recently proposed patch to add vm_swappiness command line parameter in >> addition to existing sysctl [1] made me wonder why we don't have a general >> support for passing sysctl parameters via command line. Googling found only >> somebody else wondering the same [2], but I haven't found any prior discussion >> with reasons why not to do this. > > I'd like to see stuff like this (as you say, you've found some > redundancies here which could be cleaned up a bit). I think the reason > it hasn't happened before is that the answers have mostly revolved > around "just set it in your initramfs". :P > >> [...] >> Hence, this patch adds a new parse_args() pass that looks for parameters >> prefixed by 'sysctl.' and searches for them in the sysctl ctl_tables. When >> found, the respective proc handler is invoked. The search is just a naive >> linear one, to avoid using the whole procfs layer. It should be acceptable, >> as the cost depends on number of sysctl. parameters passed. > > I think this needs reconsidering: this RFC only searches 1 level deep, > but sysctls are a tree. For example: Yes, that was an oversight, easily fixed. > kernel.yama.ptrace_scope > mm.transparent_hugepage.enabled Hm, transparent_hugepage is in sysfs (/sys/kernel/mm), but not sysctl, at least in my case the sysctl tool doesn't list it. Yours does? Yay for consistency. > net.ipv4.conf.default.rp_filter > ...etc > > If this goes in, it'll need to do full traversal. Right. >> The main limitation of avoiding the procfs layer is however that sysctls >> dynamically registered by register_sysctl_table() or register_sysctl_paths() >> cannot be set by this method. > > Correct. And I like what you've done in the code: announce any unhandled > sysctls. > >> The processing is hooked right before the init process is loaded, as some >> handlers might be more complicated than simple setters and might need some >> subsystems to be initialized. At the moment the init process can be started and >> eventually execute a process writing to /proc/sys/ then it should be also fine >> to do that from the kernel. > > I agree about placement. > >> >> [1] https://lore.kernel.org/linux-doc/BL0PR02MB560167492CA4094C91589930E9FC0@BL0PR02MB5601.namprd02.prod.outlook.com/ >> [2] https://unix.stackexchange.com/questions/558802/how-to-set-sysctl-using-kernel-command-line-parameter >> >> Signed-off-by: Vlastimil Babka >> --- >> Hi, >> >> this is an early RFC so I can get feedback whether to pursue this idea further, >> before trying the more complicated stuff with dynamically registered sysctls. >> For those I have some unanswered questions: >> - Support them at all? > > Maybe? It seems excessive for the initial version. OK >> - Do so by an internal procfs mount again, that was removed by 61a47c1ad3a4 ? >> Or try to keep it simple. > > I think you can walk the registered sysctl structures themselves, yes? I should be able to, yeah. >> - If sysctls are dynamically registered at module load, process the command >> line sysctl arguments again? - this would be rather complicated I guess. > > If it does get supported, perhaps saving them somewhere for > register_sysctl_table() to walk when it gets called? > > I like the idea if just for having to build less boiler plate for > supporting things that I've had to plumb to both boot_params and sysctl. > :) Thanks, I will pursue the idea further then :) Vlastimil