From patchwork Sat Jan 11 07:07:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaixiong Yu X-Patchwork-Id: 13935837 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 D30E4E7719C for ; Sat, 11 Jan 2025 07:12:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D62C6B00A0; Sat, 11 Jan 2025 02:12:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6869B6B00A2; Sat, 11 Jan 2025 02:12:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48AA96B00A1; Sat, 11 Jan 2025 02:12:46 -0500 (EST) 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 256116B009F for ; Sat, 11 Jan 2025 02:12:46 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D4F5CAE383 for ; Sat, 11 Jan 2025 07:12:45 +0000 (UTC) X-FDA: 82994303490.30.08320DD Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf25.hostedemail.com (Postfix) with ESMTP id 6A634A0005 for ; Sat, 11 Jan 2025 07:12:43 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.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=1736579564; 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=8Ga+OQZ44mla62P4etydcq/fwz+iOpWaKbgGbyuFD9w=; b=RNMvsc/7YXkRC0rFIY0trdVz0otgZ0JXXNP+xg8YKll6EurpYJIqQfXpbzRuMJCBLSGPEi TClb8GTfjuWT4Y00zHafwTrcPRNdX11qXTYjV8jXDOzSm8oy7p6akKX2gimVSiF17pEIU4 Sp0b7clgO+TVwwR5EGO//49jcywgD7I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736579564; a=rsa-sha256; cv=none; b=CtvzkwmJS6xLCDX8Fl0X73z5S6tS9VC6PVfF5R8+aJgSO/epg5FRibevBb0B8nwuGIXwoS sRMAGwT66XcCbvwJDK9fAVDwpfdPACucxce9SbRdEJKNcvd1vrO9TYpg+AFssWBCI+HmT8 kXDF6DdJJp0orEPRQ+soiUNCNdMgDVY= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4YVV4Q1yR4z11Nrw; Sat, 11 Jan 2025 15:08:54 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id 03F68180064; Sat, 11 Jan 2025 15:12:40 +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, 11 Jan 2025 15:12:36 +0800 From: Kaixiong Yu To: , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 -next 06/16] mm: mmap: move sysctl to mm/mmap.c Date: Sat, 11 Jan 2025 15:07:41 +0800 Message-ID: <20250111070751.2588654-7-yukaixiong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250111070751.2588654-1-yukaixiong@huawei.com> References: <20250111070751.2588654-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: rrdizp1788q4ucgcb5toc76azmqkg73b X-Rspamd-Queue-Id: 6A634A0005 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736579563-710527 X-HE-Meta: U2FsdGVkX19iYapar/HctM7SBjzBjIMczLN0ASTvaN0aC2LyM6whCOj76ripXoABMbHZ/8sOn31xj4qxE06fTDNbNoTOcf/XThJMcE3uNSFML77AiulHoPGZBVS372cHrVSiBzeSJwTyo4cqGoUNCiLgXWoNvlTTYfUERL2jponVEdp3UHzTtoyHs0HVK1UgjpM9G0yvbTGK0lp1l9Flg3MSKs9NBZnJ/x0jMyU002ocQ6bwbBDFVB38p9UhbXq7FZwYijvCg6lk7jNyqsis8ZkrxHoYofjg8u71Gg9XrJtg7ofbfrcXhHVp86aKpNboGfUv8rrzmPgYVFGMF6oOzrcpvVcIfHXtvGS8qIARynF3YykwPCXIYDjaCP4780+XUUEQ31aiEC22P/ZnZE/p5y19OtynIyEUkSfEjnLH9tuABiXv2FEnb8PuyLGNz4/OZKi5Lbqm/rkAYLPRlCBVktWkGlf6hCjeeIfSKar+l+0siVI4zjJG+pf0QX6jBh7UMFmqvEtcZN0hfRycQgOL/hmwu6vuz68mZgkul3b7rDRP0gVT6Ypun0BhqAjfXorJkQ622qGS7VIfHauVWbZQ2Dt0YH406tM9jx+mmjzIScjZL+5JQ++UcPGF+S1C+z0of8UQUnnctC0XFFjTkG0zPw2LGrQeF4wsRt4dxfTt6FYVgTZ77aCMI8MYY4cVY2f/8uz/VaqeAa0Cfzt/UJ+JLtajmREr2DVogGcUPs+56h3T9D3tNLqXHuvh93a4AI4m/u9qlxHp763kWNyBeMbth5z3JoWwQ7vF62Ve2At5/V76eICyMcJu0BQwy7EiL3Tu3WvD3RB6DU6oJQgI4KjcWyZg01pBET++2DQnJDoGVeJX5RfHAs3XtPBEBug0t+tWLIGm28tGHB2OmVeaMcscg94207poP3TF4VQ+C4ksT651vzDeP0FoqqWtwBBHdU3/v2Yy9oU6BMjQ5NLCS+7 giTpxWAe lK7WvnDHTPRyNABUTNJKmSjGVcemE3JKlrFrRf5n6RMf0YoYwhI7EwujgeB+NqLh1qr4SkPTbNHNUBejKW6uljRobTUcSkV1IOGxpy5GdYwY+Nnvlyli0g7MHsdUtaCUzWusHTAsGU25ace2P0u/2jJJ83qxeLRhjp0L+nfFgu69AhFQevO433eereJzReGdkgCU8 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 Reviewed-by: Lorenzo Stoakes --- v5: - add Reviewed-by: Lorenzo Stoakes 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 7aa36216ecc0..9b9d7ded839e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1544,6 +1544,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 */ @@ -1553,6 +1604,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 } /*