From patchwork Mon Dec 23 14:15:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaixiong Yu X-Patchwork-Id: 13918974 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 357D3E7718B for ; Mon, 23 Dec 2024 14:20:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFA3E6B00DD; Mon, 23 Dec 2024 09:20:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB1276B00DE; Mon, 23 Dec 2024 09:20:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A49436B00DF; Mon, 23 Dec 2024 09:20:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 846CF6B00DD for ; Mon, 23 Dec 2024 09:20:53 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3F973120E8C for ; Mon, 23 Dec 2024 14:20:53 +0000 (UTC) X-FDA: 82926433716.07.1070469 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf11.hostedemail.com (Postfix) with ESMTP id B430F4001F for ; Mon, 23 Dec 2024 14:20:15 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734963633; a=rsa-sha256; cv=none; b=oxq4zChWZ/JKr08JnhC/nEp7mec/l41Gf+ZT3z2ile3dGgcSg+k9re8nBNwNMr2AAg9Cq1 N8TpqjpOKz+t53S1o7T9Nos5eELH5rW7tf3DIGiCA0tX9PkCOHACpLmddQ0dka87B1zkQT S4qiDsDdZjmH+hx4j9iC+l4XpcItbaU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734963633; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KRRQWJMozcVAKYVMUwFg78+lDlVV7L8SHkPde0RbLo4=; b=fL8mPuZMTBzME0vG4Dj097OEKvs7uqNEfCzKxbKk+q50J5OzZAB5LO4h7ZVtsiyxCCOQCb +d2sAOqxpbKkbQI0y197rYLtHi2MFkkNrh7tkJlmIMSsQ+IVUQcAnbAAswd23AttO2yG7y kVrJe2QlJ52LpDBJcjpJP7vtR1R7+8M= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4YH0Yt4jcbz20mck; Mon, 23 Dec 2024 22:21:06 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id 292F31402E0; Mon, 23 Dec 2024 22:20:47 +0800 (CST) Received: from huawei.com (10.175.113.32) by kwepemh100016.china.huawei.com (7.202.181.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Dec 2024 22:20:43 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Date: Mon, 23 Dec 2024 22:15:41 +0800 Message-ID: <20241223141550.638616-23-yukaixiong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241223141550.638616-1-yukaixiong@huawei.com> References: <20241223141550.638616-1-yukaixiong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemh100016.china.huawei.com (7.202.181.102) X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B430F4001F X-Stat-Signature: kutyij4b6usuhg68dcyusa4t1j8u3au5 X-HE-Tag: 1734963615-773732 X-HE-Meta: U2FsdGVkX1+VwAsP+WJA78Ut+al7ypH7KBznhdXNBbPhHa8+/yb9U30sRLCCrctYIf13+16sRxkD8tKshg81MiCs5o1HdSv/7zZy2Ygpg1WWRpxtT4CgOq2MqgjiQ1meKBIyNzlL6FfbXWyoPxAfX+X7vDkmrHqbFNI3vvfHUl3KO0O7aYT0zggnURQHAmlT93t3Lh4oZh67unNpxJrVOPf92B4KSgkG96afb12D/F5ra4pHZKZypjnXKVaOAMkW2/WHvVcamvKLZTiQuNhGUzJ2Xj9sPJUUmxRlReIMUVs3P+unUHCQggp/AKAm0prGc2JhUMofrAF965ecFVhHsXb84xYz5eKgOlTecnbBhiuR9RRaRslbjC+Q/mUkxnqElWHZuLitJY4CaOR3TBbuEv4AWK1WsTEg5EHARgUTJXC5Qgsi3TUMW1Isty2cR0WUO0KqbYwYaEztA55aaq09AyRuVxXDScDFyBgFPO9Fc7+kICyliTHSIRBLA54ChBwyC+CoXdBRcn0dwXjCUyqwFlConRr9bAgNiEk3sG8/2ecwr3rkfA5N6hZjyhHF6PbyYyDx6LL2fH7WRWaMJcXa1hPm2stgl7/R6YKdPQ/V1s/ClNqQ/9LDdu6VMjnqZ4IjCi7fxyVXr9RvdgY4qte2flno0/6aVoaaq9FZ6ppXlrB2Vz4cHjAVMtTGfMZTwX5TVUTOfvpVFtxB5itFdRvxkp+ZX6FuZ2jjDOUnOlTc3SpW9Of9qFsevrmd4y+7VKgPNYTvdNl+5en0SLjjc1UIah7ttbjkBZag4WGet5qpzEwllGcFhnTh5VjuQd/croV/357LApcVjIHzxDmWZoFtKA2qREa5AghYEJ+t90HW8i4Y/CJsQCbJ8OfKMXXCWMAPQmKoHSp/R5XYTFY/3doS4C8/l+FT5T4ggMgfWBuQe8U5SkegKmLpUrpVPzTMFqYldDUdhury/RSbDbFaJdy OTfhAE6g bVguugMWUIu0Ux190krwSj3KhVD3bbBunRZZVmyVXH/pqz4Gzawpnd8O2VfakhW52yQqVJIim/xJzWSoy50PV/Rfszppu+ALFvW+YhGKbETanR1kDJpmFl6NieYefmiXz1tnR/6jGHDJIbqYWzK1so8e3iv+ZwnLqjP/z 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: List-Subscribe: List-Unsubscribe: This moves all mmap related sysctls to mm/mmap.c, as part of the kernel/sysctl.c cleaning, also move the variable declaration from kernel/sysctl.c into mm/mmap.c. Signed-off-by: Kaixiong Yu Reviewed-by: Kees Cook --- v4: - const qualify struct ctl_table mmap_table v3: - change the title v2: - fix sysctl_max_map_count undeclared issue in mm/nommu.c --- --- kernel/sysctl.c | 50 +-------------------------------------------- mm/mmap.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index aea3482106e0..9c245898f535 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -127,12 +127,6 @@ enum sysctl_writes_mode { static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT; #endif /* CONFIG_PROC_SYSCTL */ - -#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ - defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) -int sysctl_legacy_va_layout; -#endif - #endif /* CONFIG_SYSCTL */ /* @@ -2037,16 +2031,7 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ONE, .extra2 = SYSCTL_FOUR, }, -#ifdef CONFIG_MMU - { - .procname = "max_map_count", - .data = &sysctl_max_map_count, - .maxlen = sizeof(sysctl_max_map_count), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - }, -#else +#ifndef CONFIG_MMU { .procname = "nr_trim_pages", .data = &sysctl_nr_trim_pages, @@ -2064,17 +2049,6 @@ static struct ctl_table vm_table[] = { .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, }, -#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ - defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) - { - .procname = "legacy_va_layout", - .data = &sysctl_legacy_va_layout, - .maxlen = sizeof(sysctl_legacy_va_layout), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - }, -#endif #ifdef CONFIG_MMU { .procname = "mmap_min_addr", @@ -2100,28 +2074,6 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ZERO, }, #endif -#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS - { - .procname = "mmap_rnd_bits", - .data = &mmap_rnd_bits, - .maxlen = sizeof(mmap_rnd_bits), - .mode = 0600, - .proc_handler = proc_dointvec_minmax, - .extra1 = (void *)&mmap_rnd_bits_min, - .extra2 = (void *)&mmap_rnd_bits_max, - }, -#endif -#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS - { - .procname = "mmap_rnd_compat_bits", - .data = &mmap_rnd_compat_bits, - .maxlen = sizeof(mmap_rnd_compat_bits), - .mode = 0600, - .proc_handler = proc_dointvec_minmax, - .extra1 = (void *)&mmap_rnd_compat_bits_min, - .extra2 = (void *)&mmap_rnd_compat_bits_max, - }, -#endif }; int __init sysctl_init_bases(void) diff --git a/mm/mmap.c b/mm/mmap.c index aef835984b1c..cc579aafd7ba 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1603,6 +1603,57 @@ struct vm_area_struct *_install_special_mapping( &special_mapping_vmops); } +#ifdef CONFIG_SYSCTL +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ + defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) +int sysctl_legacy_va_layout; +#endif + +static const struct ctl_table mmap_table[] = { + { + .procname = "max_map_count", + .data = &sysctl_max_map_count, + .maxlen = sizeof(sysctl_max_map_count), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + }, +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ + defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) + { + .procname = "legacy_va_layout", + .data = &sysctl_legacy_va_layout, + .maxlen = sizeof(sysctl_legacy_va_layout), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + }, +#endif +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS + { + .procname = "mmap_rnd_bits", + .data = &mmap_rnd_bits, + .maxlen = sizeof(mmap_rnd_bits), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = (void *)&mmap_rnd_bits_min, + .extra2 = (void *)&mmap_rnd_bits_max, + }, +#endif +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS + { + .procname = "mmap_rnd_compat_bits", + .data = &mmap_rnd_compat_bits, + .maxlen = sizeof(mmap_rnd_compat_bits), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = (void *)&mmap_rnd_compat_bits_min, + .extra2 = (void *)&mmap_rnd_compat_bits_max, + }, +#endif +}; +#endif /* CONFIG_SYSCTL */ + /* * initialise the percpu counter for VM */ @@ -1612,6 +1663,9 @@ void __init mmap_init(void) ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL); VM_BUG_ON(ret); +#ifdef CONFIG_SYSCTL + register_sysctl_init("vm", mmap_table); +#endif } /*