Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3191611ybz; Mon, 27 Apr 2020 11:35:55 -0700 (PDT) X-Google-Smtp-Source: APiQypL08qsMWurVQhRHRJX1wOcGEDC1fKp64ZErgV3moch5k4N0leWyGLSC1/Om7pNSfGijDfsp X-Received: by 2002:a50:9d83:: with SMTP id w3mr19860997ede.23.1588012555387; Mon, 27 Apr 2020 11:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588012555; cv=none; d=google.com; s=arc-20160816; b=0+NOhkNDBGbqTo6pKaIp+IDaLgXv/T8Jvq2xL53Llqtwq6XRespFVulbcz5U2/zNUm T9MaCR2zaA26+6VwQG9nU5mzOo8l/JxzStuQeawtslYZvizMcyp5wzAq4bHRUjPAbKri lpFVoQqwrSlaAON1tDmeMx42Jq9eWGq7iFTkoxuUVvwJKpZEVw2WxpacqyqenoIR3Hx+ HFVQ6Xjv1S+ZsW6itL6r+QCw4BLK4vmimpJhEfCXAEA8JWe2lT44rKxkI4hZ4gt4lInv EsNfLnKTlw5boHVtxYtaZlepZGSrofZOHlZIJcyVBtAT+OrJ7SVJPvCm94iV8sgzvkmK gd0g== 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=GdLWuYYhPuid3lvIyelw8X3c7qkkOm+0iIaUYbBAddc=; b=TP0HyqhXaE9d44set4pgd68txR1QYbSYuWnu7ZotyFUaQyTSHmCLQHveOqCUaAswUm lfLseF50WFQjo+2hlkAvQ5veaOLcH7xzN3p865FKvXLLpCIlncJRj3ZX017lbRup1SIz F66aAswkLuGjhJNCT4WQqzshaW/NMkAGOHRQiapaKek8bbLbLvBfhpnJpo8ZGVmKakPu pxBo+dCqbEfFLSwFYMWHVEQ5wzQPurwUlSDe7TPPjz+uH3cDVE6yvSmjWW3pRuY/iFkg 5XqOlPcLFWYrkB7o3qlhvZUY5NtXapMfGkmzbfUN9f18DtBh4gQtrtsws60HBryi16UC rylg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vTUbWzE5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lw9si220243ejb.175.2020.04.27.11.35.32; Mon, 27 Apr 2020 11:35:55 -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=vTUbWzE5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbgD0Sde (ORCPT + 99 others); Mon, 27 Apr 2020 14:33:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:47972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbgD0Sde (ORCPT ); Mon, 27 Apr 2020 14:33:34 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (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 C91E3205C9; Mon, 27 Apr 2020 18:33:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588012412; bh=Kvl1vZC9kDd1F7eq2SkykbjVcxFidxJg+IWcZRfXVAo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=vTUbWzE5YKsAhGIfXoRp6hDQedTaAGNp8/huMp2MGwjrnBnIXHcBAq0/WY8QdQVWP 3fwbk784z3Nv1x9AHPRORRmxK1OEK6hOa6dlldVISf/+5WX+j/LhXOW/uH1RlqCgSk CTNRshvUm2K2Rpl2z+NivnJNaxfo+daK65RoGEYo= Date: Mon, 27 Apr 2020 11:33:31 -0700 From: Andrew Morton To: Vlastimil Babka Cc: 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 , Michal Hocko Subject: Re: [PATCH v3 1/5] kernel/sysctl: support setting sysctl parameters from kernel command line Message-Id: <20200427113331.f0c1e8e7cee98644260448d3@linux-foundation.org> In-Reply-To: <20200427180433.7029-2-vbabka@suse.cz> References: <20200427180433.7029-1-vbabka@suse.cz> <20200427180433.7029-2-vbabka@suse.cz> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; 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 Mon, 27 Apr 2020 20:04:29 +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. > > ... > > + sysctl.*= [KNL] > + Set a sysctl parameter, right before loading the init > + process, as if the value was written to the respective > + /proc/sys/... file. Both '.' and '/' are recognized as > + separators. Unrecognized parameters and invalid values > + are reported in the kernel log. Sysctls registered > + later by a loaded module cannot be set this way. > + Example: sysctl.vm.swappiness=40 Why support "."? I think only supporting "/" is perfectly adequate and simplifies documentation. It aligns the command-line syntax with the rest of the sysctl documentation. I'm not seeing the need to provide two ways of doing the same thing?