Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp639873ybz; Wed, 15 Apr 2020 15:43:48 -0700 (PDT) X-Google-Smtp-Source: APiQypIM0QhxksNbl4nvV7dqjK1vSOH92m+FlV/Rt+hwgO2g3KKhG3BsUhdouOmNZ6HPmsIV6RlB X-Received: by 2002:a17:906:7d7:: with SMTP id m23mr6879512ejc.154.1586990628532; Wed, 15 Apr 2020 15:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586990628; cv=none; d=google.com; s=arc-20160816; b=TUVmaeYqz6P7IBZpNaCy3rlBo/VtyfuPfdSxfQ/kWvgh4zOtNwcO3NJv5IFk3aNyfQ zVkQf18Hxr2RnVNk4OS9OV0JBrf3tzuVUY5b566pDw1nGyp9iPEy26GsbJvAqmnYf3hd /lhfN4dPcVuWomBZ8evEAXHNmscxKwTgw/9xEikMJ8otCBfVzu+YQjKTlPltf+rhpMmw RZWoRQh/qmd76CovLHOogmIbAlTN3c1kv3M1RP9aukTF7bwrKMTvyuDQRLv0MmotJSFU 1Nz2FpWbqtlaoxSlJtmCGrMdCtsk+GJG4fMKYHGV0105p+HKv6gbRVJWMvytLCy2fTwS Tw7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9b05Bwo0pWdog6KDsicJZyU5LSQcE6nXU/EDpVvC3Tk=; b=CWd1GZ+NnyyAnQ3sSVZFywoedivhm8i1KuG/7/SUiAc8SoMKrnzJI96LomjvVCrvOu m3oHE9IR2tICynNcJFRbAQ4QzkHk83yW4ZX1q/EG7mXyMeEQZJEAf32lt7gDWE2GvMCN HTiY+8Pg6ZyYaFxrJFc0GtlcxbXicOh8l/7fRBhcfcrX+ydfKmG5XEvpC1WxlITmeubX N3OROPkG8Q/rB39XyuWt5Kqwxu6b03DsxtzvZKs++xG3RbdkOquFhOuuik1VrlhHjcif OS9/c7GpkZiDlXTW4m/F//ThbOK1IzWrcm9ugfmdkgUnacq+ihuA3+TxoOSr5Kwd/LbY jphg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=whw9AE1F; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si6981027edu.188.2020.04.15.15.43.25; Wed, 15 Apr 2020 15:43:48 -0700 (PDT) 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=@kernel.org header.s=default header.b=whw9AE1F; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393830AbgDOJEG (ORCPT + 99 others); Wed, 15 Apr 2020 05:04:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:55104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390645AbgDOJEC (ORCPT ); Wed, 15 Apr 2020 05:04:02 -0400 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 98A0120775; Wed, 15 Apr 2020 09:03:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586941441; bh=6Uf+FHmo8nvRfSiHPdrZgA/7AJpQX7o1hOkc3xcNH5Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=whw9AE1FcCYHqiqYow7YdaN0KuUEpYhHQmobiTs2rs34TaCZrbGc+BCL5rwKSJJQx 0xvzItctDZoQc90DshDkCR1jfedSWYbvNDvDOXWDHI/NCRnEGyvssM+5XtRsfRFd0f vwpw6v/8zFe88LhTTbrQmJb0U2YE2DJfJzVCSEwU= Date: Wed, 15 Apr 2020 18:03:55 +0900 From: Masami Hiramatsu To: Vlastimil Babka Cc: Andrew Morton , Luis Chamberlain , Kees Cook , 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" , "Guilherme G . Piccoli" , Alexey Dobriyan , Thomas Gleixner , Greg Kroah-Hartman , Christian Brauner , Masami Hiramatsu Subject: Re: [PATCH v2 1/3] kernel/sysctl: support setting sysctl parameters from kernel command line Message-Id: <20200415180355.00bc828ea726c421638db871@kernel.org> In-Reply-To: <20200414113222.16959-2-vbabka@suse.cz> References: <20200414113222.16959-1-vbabka@suse.cz> <20200414113222.16959-2-vbabka@suse.cz> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 14 Apr 2020 13:32:20 +0200 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. > > Settings the vm_swappiness issue aside (the underlying issue might be solved in > a different way), quick search of kernel-parameters.txt shows there are already > some that exist as both sysctl and kernel parameter - hung_task_panic, > nmi_watchdog, numa_zonelist_order, traceoff_on_warning. A general mechanism > would remove the need to add more of those one-offs and might be handy in > situations where configuration by e.g. /etc/sysctl.d/ is impractical. > > Hence, this patch adds a new parse_args() pass that looks for parameters > prefixed by 'sysctl.' and tries to interpret them as writes to the > corresponding sys/ files using an temporary in-kernel procfs mount. This > mechanism was suggested by Eric W. Biederman [3], as it handles all dynamically > registered sysctl tables, even though we don't handle modular sysctls. Errors > due to e.g. invalid parameter name or value are reported in the kernel log. > > 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. > > Sysctls registered later on module load time are not set by this mechanism - > it's expected that in such scenarios, setting sysctl values from userspace is > practical enough. > > [1] https://lore.kernel.org/r/BL0PR02MB560167492CA4094C91589930E9FC0@BL0PR02MB5601.namprd02.prod.outlook.com/ > [2] https://unix.stackexchange.com/questions/558802/how-to-set-sysctl-using-kernel-command-line-parameter > [3] https://lore.kernel.org/r/87bloj2skm.fsf@x220.int.ebiederm.org/ > > Signed-off-by: Vlastimil Babka > Reviewed-by: Luis Chamberlain [...] > diff --git a/init/main.c b/init/main.c > index a48617f2e5e5..7b43118215d6 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -1372,6 +1372,8 @@ static int __ref kernel_init(void *unused) > > rcu_end_inkernel_boot(); > > + do_sysctl_args(); > + Ah, I see. Since the sysctl is designed to be called after all __init calls were done, it shouldn't use bootconfig directly because bootconfig is full of __init call. OK, anyway we can use "kernel.sysctl" prefixed bootconfig for these. Reviewed-by: Masami Hiramatsu Thank you, -- Masami Hiramatsu