From patchwork Thu Oct 10 15:22:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yukaixiong X-Patchwork-Id: 13830197 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 3AE15CF11F8 for ; Thu, 10 Oct 2024 14:11:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAC0D6B0095; Thu, 10 Oct 2024 10:11:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5CA56B0096; Thu, 10 Oct 2024 10:11:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D53D6B0098; Thu, 10 Oct 2024 10:11:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 834BC6B0095 for ; Thu, 10 Oct 2024 10:11:56 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 549631A05F4 for ; Thu, 10 Oct 2024 14:11:50 +0000 (UTC) X-FDA: 82657881432.22.832D80B Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf18.hostedemail.com (Postfix) with ESMTP id 5AF221C0021 for ; Thu, 10 Oct 2024 14:11:52 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728569444; a=rsa-sha256; cv=none; b=VocZ4yKakUi1U9K6dpErQApalJ1fbf8jNQwm28NyqhqgIgVj2nBSVBZDvuAPeI2xnMZEO7 ta72g2KBeNE98F9K5iTMDChK+uPmSqHIE7PAk/px2UO5wc/HTmp9mFNEUQHv9Jl3nNX69w tliixr938qziI2qFpg0jDbP9PaB/emo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728569444; 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=s2ros0uLr2eOPAZap4eBocjo7MYyEJpnKahV/mA/ubk=; b=NsD0jw6BCKLxAH5EuBKN4rHxe2Ex1X8798QCdMxKBwtZArdk1hxjqwJskVQ5yfsl2bcsSK mssdr3PlAE1GqE4KTTyiVjudL7EmH8dKEyumHL+Obim68Cfeul2X0k/gZJCLILT9yTTKhy EY/J8C9Ul8Bzts6yxhe/lo1BdEZoIjg= Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4XPWqK1kbpz1T8N3; Thu, 10 Oct 2024 22:10:05 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id 09BCF1401E9; Thu, 10 Oct 2024 22:11:50 +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; Thu, 10 Oct 2024 22:11:46 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Date: Thu, 10 Oct 2024 23:22:06 +0800 Message-ID: <20241010152215.3025842-7-yukaixiong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241010152215.3025842-1-yukaixiong@huawei.com> References: <20241010152215.3025842-1-yukaixiong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemh100016.china.huawei.com (7.202.181.102) X-Stat-Signature: s1phw5ssibs77aarnz9qbqy5cx7ogsk5 X-Rspamd-Queue-Id: 5AF221C0021 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1728569512-891353 X-HE-Meta: U2FsdGVkX19/IscJXlMjqWBLBMsXnwKVe2amlIHrgKu59Ou90ctuip1MtdQw8w7cotp/3Ta7mc+Kz0QVSSDshcSwTAbYOXHEV9yJE5T6eCVkstBdDu1DeDwMhUHdFHu2quWpecvQLuxkyxMbbU0tzNsFQ7J3u+KfONTymAivOHfrXdpzQEJRuQp2NFKsYGF5rcUkE2xXW0iG0mHF8gVsFYb3tLu6BayMKokxooxr6FGNKH525lT8CwIQSZraWv+AyWfjlVcgCSFHDvFPSrlsWtVu2DgTLlMjbOS8yrzAr2pqmojom5OVxmjf8Y5MeKiWHUAaY7wti2OslDpxTrknexlYhV62ErgsgaE2Eu2rGfntiIdi0cMTqDBCmEGwQhD6T6qEiyvYIh97N82uu183Aqq6+GAxqXD6qBE87OBieU2O/DYOHgnhJCXFCUdelsNBUNkw9Iep+p02x+k2DxkrJymvTqIH3zYzXYCfoAwmXRny9YX5kYsydtqIeGx0n2VrJf3kprcbcRSwCuJ6NNToO7oRePsCv2Egv/HskcnnGwugPzzWt+zz4T7rf/9uWAhgVW5Bf0D/n4yUKPE6yipo8gm21Mh9ftvTWxHiXpdEJcl4BS0HFsTRGBsi8N9OF1q8KUC4kMPhs/aUQ60k+/VjHSiz4TUDLG41IliVyzj7zygASAjORAH8hIzgT9Q46kQfhhK2SY40IRguUWzSA5yKfw2fX+OISvvcAn0j+RX/MSyD/sVhP/B3D+yrz08oBnpli9OSMQ/XSz9k3heNzG08xCdNeskR3N9UnMnvhnJLaLIn1Kz1rQeQOtgjPly3i5PXecJoLNEhga2PkU03GQXzB0c1Z4Ur6rr6T5MVPM4qM9e1HKXZOLQ6ifXQpCXyCKwuOQdk4qrsgTNNc21HD212YA7NeJH8QqrblrtEsBLoVW4b71uo+ETUQewcqs2eeR9R3Bul3BhoGnon911feot DyXDUIXK DHIq809o+b9qy0VHWD9FEJWOjD2lMKB5yXi1BHUuT3MLG63QwTaqlPgelavKKjdF9l10XBl85TepI4z9gpTIMQxvGcJkMlqbQke+cx7dR+EWT+xxbaYueQSt4Tysx5ZRid3DRrzO8uKkk4KkZam3Ccp21G10GdvEKAfw2 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 --- 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 ad3ac6f6c808..41d4afc978e6 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 */ /* @@ -2047,16 +2041,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, @@ -2074,17 +2059,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", @@ -2110,28 +2084,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 4ef58ad80a33..6d584e67d045 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2176,6 +2176,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 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 */ @@ -2185,6 +2236,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 } /*