From patchwork Sat Dec 28 14:57:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yukaixiong X-Patchwork-Id: 13922368 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 A841BE77188 for ; Sat, 28 Dec 2024 15:02:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FEAC6B0098; Sat, 28 Dec 2024 10:02:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AE9F6B0099; Sat, 28 Dec 2024 10:02:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 152B16B009A; Sat, 28 Dec 2024 10:02:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E6EA16B0098 for ; Sat, 28 Dec 2024 10:02:10 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6CDDAC17E9 for ; Sat, 28 Dec 2024 15:02:10 +0000 (UTC) X-FDA: 82944681960.12.977442F Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf10.hostedemail.com (Postfix) with ESMTP id 4675CC000E for ; Sat, 28 Dec 2024 15:01:47 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735398087; a=rsa-sha256; cv=none; b=lyR7q73HSbEGoGgPL4wu3f5thTmJ25hlK+AMxu3N34Y8z+RZjrr13Kp6sT1fM11RMyp2wy etyk1tcmqUiKRbDHDR0popTFqUgwOuiR7rhmyMyFRH4zujQUMGyEosPpoHWgS3X6ur6xCQ HJf+sUKGOGMNgTUZob+GGDWcSBcqwg0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.187 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=1735398087; 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=W7U2JFM1MskeTJAEypYZ7UlQ1Vqy2nunksQsMGfyiHMsZFC0/4vkpW1yJMzgVd+Df9WTf+ ZPf0DZ9JOQSz0T5Wxloq27UDHYjw6tUpnJDUB1ZENLb4QYx8ze8V7WoiD01AixPcSCZ+Kx hU8/WsRLr5D7NaQQ/hkPm+95iIq/XsQ= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4YL58p4BSlz11Nds; Sat, 28 Dec 2024 22:58:34 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id A55541400D1; Sat, 28 Dec 2024 23:02:02 +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; Sat, 28 Dec 2024 23:01:59 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Date: Sat, 28 Dec 2024 22:57:37 +0800 Message-ID: <20241228145746.2783627-7-yukaixiong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241228145746.2783627-1-yukaixiong@huawei.com> References: <20241228145746.2783627-1-yukaixiong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemh100016.china.huawei.com (7.202.181.102) X-Stat-Signature: 7bu34tkbugkqbhadg9ue9tbkckgiuk13 X-Rspam-User: X-Rspamd-Queue-Id: 4675CC000E X-Rspamd-Server: rspam08 X-HE-Tag: 1735398107-717468 X-HE-Meta: U2FsdGVkX19XGFapq8vWZZJc2H6pyQTYZqGMRzfdmezxW8wnJ/awKxhqNpnQ+vWLaskGPNwYsYuDKH9J/23txfh8yJYF1t+qKArqycL64CC4IYJUOQtVQV3i5SVV/4ht+O+OsIDYfxwKD1kKovvu+BFtzMXwOuTYB8f+aysy/NvicPIhut4ZalYN+yNYCyIED54tv8+QQ+ko5NpsaqUYtnZOZiLFENOZN7oZuT5EcCh9CV+XMwcc1rI8/MGwclJWcoOGZqiP7NUxQRqAQ3dYOiK5GWENeDkSOKl+Yp9EfvoeWqpP2W/rwNzwZwHrOKC2kTsj3suAYx/JI9qZSAPLo+4nq+sfHBB8eCAI/c8jM9w4LRPM2fwKt2HGKIdnIPqjdHuoj1ixin03lGgU2iVPVjPTG6hBeq1H3UZNFo2bTM8+uHyeE0cRePJx0p7U5xnTk3/ataUnE+YXYVhEylCltXH1gTk1BrzYRCQXabrQEi7Vv/NOwyjmRhyBT0TmFuUDW2UnJ0RfFV0WX3G1ypIzG4OQ14hjovuu8ZUmYmas1OGCbIyeAWW7SNDV24Mmm1S3022VFj4QJEIiuvnvF6/YSW6I2gCyeyta+OynnC1q70MKOUVS+YR3oE4ucE5m5B+HurUbIxdEz7wrFs6Eml3sdovRPYztqZN+TcyHjPHXew+k9MAkEP6osMMsTQhOzOsuIpPnokX7Mhwx2impD1lbwtwFqNdVxFjUBq1rI6oTmmQ9OMKBTdjGeBqE8z6FR2JBTkOVyRb3Q41N6b7aAcEqHeIe4jIY04W5v9aLELC0wPAanUGThatAGcJxDuTRpIAmscpowRTId5j3Sw/AMlipGekU9mcvJhcgMpg3pKV8iB8qNrFDmay/IrPPSrd7XKYZ4RdzWDr3qrDplbY8rgxc95QpptXVOhSHtGzl7QsNDo79R0/09m9isFVueMTiVueLc5FkeuELCUOlqzAEcVm d47nDAuI AM0Fo1R040vyKxqmhg44IUUoZErI820lSHBbh0Ob8AHGgq/wNkqVYtNtyNIqVgmDo+yBd5xPp7YJxzFsupBDFKUva078lMrRub4VUvVd/9rsGJvaiTWUa1heXytXYUGtW8MhD31mj0pNWzQ/BDu5KGi5TqTxWLB5QRpfw9Ut8u3RcaCNO6R9UBUAw5LkYsMTDC3ZdSmhhLubKs0xyQNC9NRZ6ZRiBlzdrcRunDaad4NHJzSGRhQkGMv79R+q/F5WKy7twxOLqCbqUl7gfPtAv8yy6a7TEARq2azVtVdKcM63wFXOYqnms5KBwpjytOXRfByOf 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 } /*