From patchwork Mon Dec 23 14:15:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaixiong Yu X-Patchwork-Id: 13918959 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 CC62CE7718D for ; Mon, 23 Dec 2024 14:20:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 604926B00BD; Mon, 23 Dec 2024 09:20:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B55A6B00BE; Mon, 23 Dec 2024 09:20:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B8936B00BF; Mon, 23 Dec 2024 09:20:00 -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 186F36B00BD for ; Mon, 23 Dec 2024 09:20:00 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D00161C6B1C for ; Mon, 23 Dec 2024 14:19:59 +0000 (UTC) X-FDA: 82926431784.26.D84AD8F Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf20.hostedemail.com (Postfix) with ESMTP id B07661C0019 for ; Mon, 23 Dec 2024 14:19:17 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.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=1734963554; 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=uw6S3lEVjcOPbG89C8WDncq/a0FHYY7De2OqCDAR37c3/n4TX/z2fGMCot8etyoAZUva1U 3AogIenMYcAeuKtyxiIRk56EWlJqM4uDE4pBfOJObAz9CrMBF3moCq0KTD2lQEN96BSc5s wktEtRq1gPtv8vGVGHaKvC1CtxRecEo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734963554; a=rsa-sha256; cv=none; b=p5+uT8C6R947V+hdzhksGtCqVjupjaAXYboD/LdqfxnW8LT0y9ziinzqYGm3C8ALvHiakk phEHiBIZPTx5V6dz2Sm0sVxDZKspJR6+BZQq722pDJRSIMy/z1ZTyWF8LpIouMTwr/mSPh Vl8aZi6DwYNqAvaRPPvAU74SWSlkKzw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.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 4YH0TS0T9czhZZ4; Mon, 23 Dec 2024 22:17:16 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id BD245180087; Mon, 23 Dec 2024 22:19:53 +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:19:50 +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:25 +0800 Message-ID: <20241223141550.638616-7-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-Rspamd-Queue-Id: B07661C0019 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: kutyij4b6usuhg68dcyusa4t1j8u3au5 X-HE-Tag: 1734963557-841496 X-HE-Meta: U2FsdGVkX1+UNzWXhi5jJmmYcehe5QTxVtmuqAwmNvIfT+kNfLvdLzo02F6IDJPssJgoaEKBHkAd9W0E3CJUu8fbN7OmddCbLp0LPGTWNQAlvGtYcLyXmA6G3oQyVmxRO6Rlp7BAZYmaDx0jadL7PQZK+HYf3PsHt4bJ0fXZRc+y089rT667GIwnLVqzyOFVHZJGsT9gMbfDxMHP+D/lqABAZwGwoBF6A0NkSIMn5SLJv1czXT89T93Vgpgt7HQOE2qEOHJpbbwo6fDFHhtFdfsyvnmlbyf05XGwSMbb5Q1JS8XtmoAlGnYpQ04BAdLbT+1QGDheUrAgroNDckcxnTe92T5eFD2OjFey/JHO8yTnOUbw0wOSWVh65DyTHG1o5pdaKYaq06MEal2FNqi8RNod+8cVRhfz/WwA6GbyRpaaoThZby/A/rjrXQUMUmDRQgN4PT9bvH3lU77ShxVlwv4ibnzq9g4Q9UlZMpLBDcbcEVZ8XWpblkfgz3jlIm7w0sYtbQSrhwWA9RWC9QRej33tJEqHi4RFgOGnGXNQlPDVkRMAXUL8YBNJiBW8V6Q9Ya8+q0QrquRAA8G6/8iKTrhTQG8TftIU3EbdS3O1pa4iqHYGTB67fKOm8EHCB8mLpWA/UwMpyzggOtU4fxvTj4XPnE8JxFWhfcZY/KxLKLQe+kR2veiAK01AzyS0yFGeHZtA5teymSgAFYr6YLQkDKYt/a9N+ElEofI56h04bMpwYw7zc0WLfL93zaI6EZDv0/cmUNyWTjnS0VPraCchQNLSY7p1x3FEx2WwCzFEblYbk3xuGZZp/s9s9Gz9fwQ9savOrE2Ew8FEuOk/0dMAn7qSN1svBwmjmgEpDOiMZ50YY/2p3SeffsLKNtDX7Myu4Qj0x8qt5SIgnxDVBgXF5Y+nY56Q0jLFTSDBpxg0Nf2C7P9pSttjm+OYra4lqKoyYCg9nitf4PGKEO9PKh7 b0K6Thxc vqxRKJEqNKOO7JgInvuJ3vGde5BEZSt2gdPLoLTD1AHezRw/lYhE+hjCSyLUVrgAjvgCmvG0B+mPHtcXepzGu8kX9a2HE34L9ZS149WBZOO5Ll5ydEYa/24EznpXElmRYek4eh0OtOb5M2TmfGHydZFRG9TVmEQ4DrXGvLcJJOOpLIPk= 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 } /*