From patchwork Tue Sep 3 03:30:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yukaixiong X-Patchwork-Id: 13787955 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 79CB0CD3427 for ; Tue, 3 Sep 2024 03:31:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B01A68D012C; Mon, 2 Sep 2024 23:31:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3E3F8D0119; Mon, 2 Sep 2024 23:31:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B30E8D012C; Mon, 2 Sep 2024 23:31:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 688BD8D0119 for ; Mon, 2 Sep 2024 23:31:21 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2ABEF1A0185 for ; Tue, 3 Sep 2024 03:31:21 +0000 (UTC) X-FDA: 82522001562.18.B5AC1CB Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf04.hostedemail.com (Postfix) with ESMTP id BDF8440005 for ; Tue, 3 Sep 2024 03:31:18 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.190 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=1725334186; 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=iPwFQaf7WCoscfpZNLzYQ6t8U+8MAHfLgeNyODJjFyg=; b=RP/FLCMvegul/ufQpartCNc9nXZe8S/az9zfbEmaerrqBg2MVwf7NBqUNNEhlUaja76ZQG Xj9v2i2bmjNVcDB8u0J0k7KL5Az+s/uDPTk/7CmYfBh391DC2BStmRz2JQKJ/dUNXra55n 1MhET+4NvQg99r2/b6E0T5yUV/lDAC8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725334186; a=rsa-sha256; cv=none; b=gnZxXvH2uW9/nAL7sDx6xhs3P7S2TmtSbcXvXekdc6VfBCOPt8OH9Ftr/LJhnKihHPI4y7 7ossEkyPhulfLRIu7sANhDysNtbc5q6tPSmyQUl73ju3jgO97XhBWmlgoR6iC4zDqo7GHi Is2eUdPzUu/KdbTjxlfDI9lFLxOb4nE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WyWHc1xTJz20mjS; Tue, 3 Sep 2024 11:26:20 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id DA1AD180019; Tue, 3 Sep 2024 11:31:15 +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; Tue, 3 Sep 2024 11:31:13 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 -next 06/15] mm: mmap: move sysctl into its own file Date: Tue, 3 Sep 2024 11:30:02 +0800 Message-ID: <20240903033011.2870608-7-yukaixiong@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240903033011.2870608-1-yukaixiong@huawei.com> References: <20240903033011.2870608-1-yukaixiong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemh100016.china.huawei.com (7.202.181.102) X-Rspamd-Queue-Id: BDF8440005 X-Stat-Signature: phrnsyedz1owpbm94hwa4d7ja9zkec7x X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725334278-627421 X-HE-Meta: U2FsdGVkX1+DQMqVXKS1i3s7o3WWimy2ojyLgw4cYBw747c1H0iRVu71+FdjT4OsgXkrNA3BzsAR+YPbQpxzvauEPrWI1BH6njKbjF27s67hK/60CFj3svAjsDYNb1yT04Q8T32Cedt+pUQiIE3kbAG/VBI/aIJ7Uz2zwTaZSQWKjCK//5T2jmOFHgfKZ8uxOrFRKmytK8ZlGQqGC2PnF4Geq8XQd/ZknybVPYJOJKwfvbtjwxltp/0rdInogNLhkG9k0UqEobVWuT2viVaF5qoAYQdR4Am+6cYMvRaElb5cvdazEaH/+MDFn9mRi7T4/LxYt3zrMvqM4pzSC2mdfWGj0ItxGELL18MPSFugWyMF/XjoUGBwKd61gMTF1SCXX2p+nrVM657fA8DOgX/RQ0L2rDtETKuKBgCskK5XD7v8Aa2F6Vd3VG/YvgEJZFEsYxnZvu9ke1PRyumTrXf7dLNIFWWcA16QqDlmKn4FCDstOpf3zjaRsucSiqeiGNtJLDxhPIH6+F/wnfKE6RfJCQaHTVvZFcwunq/16zSXo+BFWBZxdIL6CurvOxeU0NI3Zbop5Mw6JV4qp3jJekW7ZBovcpIZ5ecS68kZxa77AH4ZImvVkvtDMWW0l2c0enZnWikNL+TE91snyN9h4jJ55d72oEw/Z4SSVyUYTlwBMPwH7wW7pjBEg6TZJ8vb5eoC1XAlpLhjz97b4mSnmKnu2oXLntB8uEagdadm8P2/IhU/CBUEaXfCI7Nn1kWArBLmCvMhzZBO6/yKp4tsCShVq5gVSgFlRiDGxWLyZ+jfXXVCuXgOiUi5i6fhUgkpzkEA4fbqRMXVf8QrhPgUR6Xy+Sej2ef2j7pi+snRKfmozy4KYLBmesbqEjQuYdGQRJYAwguESZgdn5m1aMnRX+fbv0Tfm7Kw4egvb+fCYz71HIs7CDHCgqj/CqEKRnBSFsnWnZoGmz3TQlTqfIlFIK1 vmdwGxhM h4TeKZZ6hGkSWMKtqjTE2DiB5ve6AE6nbIAyX2Choh65HdgjjJyS4rYuD7V9MkRM69Y+w4NZWvPzwi993p67UOXFrZ0loYznZ/jQkJ+uNkeBe/dOXtF3x3jt3M2VaYXfY3g8mRfrcXBjuj+a4CSbdZc4ONH8vqsVAaGQQbBZrih2r3Jc= 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 its own file, 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 --- 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 c018f5a5bffd..e3d888aa1e25 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2120,6 +2120,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 */ @@ -2129,6 +2180,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 } /*