From patchwork Mon Jan 24 09:22:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12721802 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 38FE8C433EF for ; Mon, 24 Jan 2022 09:22:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A21836B0083; Mon, 24 Jan 2022 04:22:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D11E6B0085; Mon, 24 Jan 2022 04:22:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 899586B0087; Mon, 24 Jan 2022 04:22:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 7D30D6B0083 for ; Mon, 24 Jan 2022 04:22:20 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 394C6181C1927 for ; Mon, 24 Jan 2022 09:22:20 +0000 (UTC) X-FDA: 79064639640.22.F841ED0 Received: from FRA01-MR2-obe.outbound.protection.outlook.com (mail-eopbgr90073.outbound.protection.outlook.com [40.107.9.73]) by imf20.hostedemail.com (Postfix) with ESMTP id 7B9641C0017 for ; Mon, 24 Jan 2022 09:22:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fpbYaHdqniR4nPJ6vkxtFXMbmcQWuQbYIoz5FpxRoEss/4Km1zZlPV8p3ry7JkNjD6B43oSvj0jTErz0VQX0o23DC/SrbBlN975UHRUAXAGFNMGgCjII+d40TFRJTB4Bw3Q0epJLHwztZeJQq6XlG24YBlkdO/DnT8aP0GBS7niadkQZ41tn7/7fLbvE6HlapmiYZ+5V9XYPJDwB8TL9aYBV3WVlF0TFpjyd+jIa4Dj9rXxRjqJLhd/MgIie66M6mkffVGIaMPLOCoqRd1Lt/7RJfXMM/4q0bqJIkilkR68UHyip8+pPxsyox0G91CJBDC9UrCyMkOGo2ISoGERmdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=d8RJ3jC6E9arBGQfSQkBiXWHNDOnWeX/ePWzBPoQFCk=; b=Tqa3DlJML6Se5hBWBlytlLpMvBlaHuKCtwZTEvGWIKqrj/9wHEPc/mi6Or3PCFAs2L2wNzPweDQMld7OptOiIRH1YoKsRCUb5yt4uvoESHcWuR1dyICJm24rAWNw8Tae9UECkB8upVdB3S89UXCdspr1LbVawqt7w38pZCQSBpMRufpAjU/GFoUs92ZKIvM7GDY7A18amQSZ1HhzqhsBvsseZaYDJaLkMFZreDhob0Z0s4zcZni8B9Co5pfc15OUGQZitlHC8inUYmJvjuAFIbOg8IwM7uDocSOpPYB0v6lyOZUgz7hWPJSjMbClmwhkyqcwkUwQKRn6udKk+0IXnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR0P264MB0235.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:3::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.13; Mon, 24 Jan 2022 09:22:15 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 09:22:15 +0000 From: Christophe Leroy To: Luis Chamberlain , Jessica Yu CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kgdb-bugreport@lists.sourceforge.net" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" Subject: [PATCH 1/7] modules: Refactor within_module_core() and within_module_init() Thread-Topic: [PATCH 1/7] modules: Refactor within_module_core() and within_module_init() Thread-Index: AQHYEQPgKgdjFmN/j0GzHm/ZB6XnTA== Date: Mon, 24 Jan 2022 09:22:15 +0000 Message-ID: References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a477f472-47bb-4d73-d4d9-08d9df1b031c x-ms-traffictypediagnostic: PR0P264MB0235:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1388; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Yi3CwSSuGGlA3ba+4AkSnSjZVn/PqFNanVh4jhm9A5moBuaO4A4piu5tqAL28rXffKw1MNes43ipv0PpzLm7I1bpzkLwvbIg335Om05vW4DCyCttsCDWiM/Mn4QGWigJCSA9OqcftB6gCe4hLO1POTZNUSJ3lQOLmUl44E3TJTltkGUdvxOMxLCIXw2Ti54ZDb54OB2zqXl1lnIj7X6ph2jkBppYHQMfMLEwuXDbNj9vam0rUAA7gdKt7Crv3h7izQ7z5bYPci4+b6ZxBxhoaW1iimaQwZL+OULpxLxbGOimygzyLl3A9Nq/6iIHs5erY2AIaQ1GYC/INqxiyWqoBqVLLgYiem7Q8gOYzobq/OaiL+mNcL7+1JM0d+s42CsyPVnaWVk1bHpcFceUNDj5kt5e2gJG2VKJU4A7QTWZKBuuPPv//zgIRSdUP7P3dza7CnK+mCEvND6NNhFaexO4q+nYvw4a7Yba1DODZl+axTj1hgOb7wPKyYZIVBpn4UfpkutU/j3B/InmRPxJW5W6YgqEo+qLrUFhL3Jw23hdyU1AxdvQvm9VkX51TVBJFrxChDsXyCxvFT2P24eV6Ku3ahv2h44pQ1GMjwhfqn8FcSqegPS4nBEE/Oo55LAt0nOwFM6d1RRMoVHonPOcNBQ4v43DRXEptCFGjm3OhfsPx+WuiwK9EAT4wjVjGoJlLUU4C0RL+jrmxcj+lk1W5c9RSw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(8936002)(6512007)(86362001)(66946007)(2906002)(4326008)(6506007)(66446008)(8676002)(64756008)(71200400001)(44832011)(36756003)(26005)(122000001)(66556008)(508600001)(186003)(66476007)(76116006)(38070700005)(91956017)(54906003)(5660300002)(110136005)(83380400001)(2616005)(6486002)(316002)(38100700002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?Cnz75I49SQedHiMgpuEyn/N?= =?iso-8859-1?q?mgV01t0blBoDNA97YLN4IWg5xEbk5JOk0sbm6IlAkTWzfZAywTfHUc5WqPqs?= =?iso-8859-1?q?/O1VyaG8A+mpVHAF1cYAj0ifQq45W/aWED1JyprOwC7RCuro3eD1+o2WFyuY?= =?iso-8859-1?q?WlalIgG0FD19B4knCn1aB93l0boyA4fhlPv2ohSDEJqZNCvu1ZWk7vPRE1BC?= =?iso-8859-1?q?Ec07w3AXvNQaDWDf6x3qvPZTmjw1n8NJBXwV13zU1s3F1jGvbYpWK2oVNyr1?= =?iso-8859-1?q?85Zvh40v+vUmdfIQ5wdcUKwUt15QAZiT21Jm5Gu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8859-1?q?P4Ygbt4PKaiATWw6faBk1GPdFoTzptTvZlFRbLmWVJO/+vZqyZhmKp39VDxy?= =?iso-8859-1?q?AulG0C389R55k+qN0/lJ6mkh6rBMk2U91URxv00TUZ7Z13IS5x0RP86alQVD?= =?iso-8859-1?q?ywAIrJG94I8dbVLWK/ijUeqG6ENnKNJOm3CqROv7+vPNnzqvTJOHcWh4hrLZ?= =?iso-8859-1?q?f5Oj+bl6EQAIOFxWvLFpKAJa7zhijYb4lV6HD1DidGmwciDPNlnu8pew3E6+?= =?iso-8859-1?q?KFnL8OPKerJA0zu7A/C63CJ3xEFSRgE8R8MEAPZciLi8GI4++Zj5OjYAO0pq?= =?iso-8859-1?q?88ghXYJTS62JXzSPIHuYOjAOCxCbTBVh+84s5xpEgeMPbptD538Jn+MwDeJa?= =?iso-8859-1?q?OVzcMvUxsicSqTRL6/2v2xWJ90n1mCliFbGZxm53EJ2PnSGzCjBWYvW4ObcK?= =?iso-8859-1?q?rgGJlKEMSpJMR8Nf6qo89yUQORAoiF0selKwwKRt7HSTeDqyKJT1vlGMk+ur?= =?iso-8859-1?q?yE25AfBIum34dKJ1uoW0qIg+Gu8DGskmdlaQe7+4yKMoGxah5N7kRrr0Dx2c?= =?iso-8859-1?q?06Ws=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: a477f472-47bb-4d73-d4d9-08d9df1b031c X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2022 09:22:15.8499 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Qc0+ghyqbVfzqEDJTSTQUbOZIUQdd+1Cem/vdEaISQjSDxFkk2+j1tpE2fXvEE6m0GvWqt83UQclVbM8s+OiDTpWTPymzhENKvQ68JvhBps= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR0P264MB0235 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7B9641C0017 X-Stat-Signature: gha1egecexca68tgbou389grx15x4qp4 Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.9.73 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1643016139-83598 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: within_module_core() and within_module_init() are doing the exact same test, one on core_layout, the second on init_layout. In preparation of increasing the complexity of that verification, refactor it into a single function called within_module_layout(). Signed-off-by: Christophe Leroy --- include/linux/module.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index c9f1200b2312..33b4db8f5ca5 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -565,18 +565,27 @@ bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr); bool is_module_percpu_address(unsigned long addr); bool is_module_text_address(unsigned long addr); +static inline bool within_range(unsigned long addr, void *base, unsigned int size) +{ + return addr >= (unsigned long)base && addr < (unsigned long)base + size; +} + +static inline bool within_module_layout(unsigned long addr, + const struct module_layout *layout) +{ + return within_range(addr, layout->base, layout->size); +} + static inline bool within_module_core(unsigned long addr, const struct module *mod) { - return (unsigned long)mod->core_layout.base <= addr && - addr < (unsigned long)mod->core_layout.base + mod->core_layout.size; + return within_module_layout(addr, &mod->core_layout); } static inline bool within_module_init(unsigned long addr, const struct module *mod) { - return (unsigned long)mod->init_layout.base <= addr && - addr < (unsigned long)mod->init_layout.base + mod->init_layout.size; + return within_module_layout(addr, &mod->init_layout); } static inline bool within_module(unsigned long addr, const struct module *mod) From patchwork Mon Jan 24 09:22:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12721803 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 E9845C433F5 for ; Mon, 24 Jan 2022 09:22:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2820F6B0085; Mon, 24 Jan 2022 04:22:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 20AC46B0087; Mon, 24 Jan 2022 04:22:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 082496B0088; Mon, 24 Jan 2022 04:22:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id E87A46B0085 for ; Mon, 24 Jan 2022 04:22:20 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AC8338248D52 for ; Mon, 24 Jan 2022 09:22:20 +0000 (UTC) X-FDA: 79064639640.10.8733925 Received: from FRA01-MR2-obe.outbound.protection.outlook.com (mail-eopbgr90073.outbound.protection.outlook.com [40.107.9.73]) by imf20.hostedemail.com (Postfix) with ESMTP id 1C8EE1C003B for ; Mon, 24 Jan 2022 09:22:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DkfdG7ScK2vgeI+nYwpg2VXiBDMgmEacARdkET6VhloWM2RhAja5zx/el0Z8/nlQRwOlR6bexTXzfWAGIdVfM8KdjRKUwJgyf2WoBowGx88yQing16Ct72EkmK25x5uOGKnGDk1YxlzH/C6RrnRFDFfQfAcqYNIhmUQ0mMcZ47DxH3MRr+qTfO32AqAjthDr5sM6Y92iVyLqpVDC5tlQagM3ISFwM5l2N8kDhXjWQb7FrJLxEaUWBZrnyp1gMuujkbfUlutDud2fJgBjZfjO6B7SmJrqG5PRotXLQqZKcdUZUzXOVYsuNhnXAbmAGCJm67mlUD1SemEtwvB1nDse8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O+CeV327RTVvdEcxdN1wQBsa3h5QC1tyTLvFztvuQB8=; b=b0oD3cIW+VQBFXmjkye7BGgssW8TdFYSeylFylmpQ7RdKsaSl2jN/mbHafAq7nyQ3QnDJYMK0r7wJPAiX4iRbuMwMBuvTP4ykRGNJq6Ilaov1IEzJ6xmQkpFkVFKe0QHglNIDzCwpMX9yQ6ZCwAK1/HGKiUz190xKAp2lFp+B8o7V1zfCTxvZje41tyUre1bP8VjJOTSXLJOA5Y3kn1vb3AOmxgIi/7htTuhwuqluPEwOAKGR8ZQ6f9PFyOTIvLq4x5GtFS/J735UAgYc5wVehFhfiS+dXCKMuArj4SweKzYK6WFgXMHBzBylaavNyoj5O6qHot4FyFZt5RZfd6zSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR0P264MB0235.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:3::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.13; Mon, 24 Jan 2022 09:22:19 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 09:22:19 +0000 From: Christophe Leroy To: Luis Chamberlain , Jessica Yu CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kgdb-bugreport@lists.sourceforge.net" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" Subject: [PATCH 2/7] modules: Add within_module_text() macro Thread-Topic: [PATCH 2/7] modules: Add within_module_text() macro Thread-Index: AQHYEQPiNEhZhVr+ok+URNEzXjzsfg== Date: Mon, 24 Jan 2022 09:22:19 +0000 Message-ID: <0cd6fff65c1038286f62c4207c0d2e90b78c5cd4.1643015752.git.christophe.leroy@csgroup.eu> References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9f5f4eda-6347-4440-531f-08d9df1b051b x-ms-traffictypediagnostic: PR0P264MB0235:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:227; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: PuYgn0K0sn7sTo45g+IdGEvG1NMGl4M5yPkv/hVPMv986AeGGR0QLaa/Jp8K4kuBvbrgEeoxMxa1PGpk7vrea8q3ID9vxjdTcPY1i0gIS/ZKHMHh89Vux7r6Y0+vqE6jVvD7YiYFwHeWSe1vIOy6NNLpsS3vgx5fGNjCuqE9P6f9z+VGe1mMZY59o2soL9xjaLD0r41Xk7/fZfrc8p8NYoG2K6yKImLHuZOcz9oQ1QLlr4xI94vMOEo1ShyMswcqk7VT4YR2u3ORKNbDnK2ljeK8GPWU2a+60qTKFAHJC65O4TrRRmzIE9RIvKKjjS2v4AmCaGWYayLp8OeKSQCrSik9piGP8rctkG2AkPjnCyUUQZPMACxBA3spng1g2vzS5a15M7STRXLI0Tsrlx8+kARB28V3URQ567iNCsnnL1fL+XOUNRpN6YEDWzfin3LFC+BUE3+e5bmEuYGyvMzlvxRI6/h4Emh6weKEwAQ08Ms1WiKbiHCuSLEjtnWLfEzkQBE2MZgfrU2pkRCdXS7GONXyYHgZFrIHD3JrkgXNqkkjP/Zd0xEuW0cMOvttnWGxvtLB5yvYxuu7Ap4tiBUb58F3Ocq3/9lTB7O75AftZbgWx3pXnuGOEPpzwGSu/K3Yk8Sl+1yicrZdCRpMi537j4R4Y3BuYjO+JJVu2jv7J6NmWSdFHIrSRTDxr/LCeGIhUoQzhZ5HMRKqwG7FaVaruA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(8936002)(6512007)(86362001)(66946007)(2906002)(4326008)(6506007)(66446008)(8676002)(64756008)(71200400001)(44832011)(36756003)(26005)(122000001)(66556008)(508600001)(186003)(66476007)(76116006)(38070700005)(91956017)(54906003)(5660300002)(110136005)(83380400001)(2616005)(6486002)(316002)(38100700002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?1PK7+Cy/9MCi2GmBFGfs17s?= =?iso-8859-1?q?PHfGi7KoA3Z6F2uyNGi+YWTMGSVNvzbq7G1jFQLPFYOpswGT+O6d+P6NtYpd?= =?iso-8859-1?q?/4k2WviWnMUxTuLDVj/v1RRu4/JeicX14RFXNqw0h58+5trMhwJb3X8wiF7T?= =?iso-8859-1?q?1UYR+FL+IC+8YfWQXLbLcrjDXHiKdAbED7m/KAY2n5FG2924p9KkeOvgHlr8?= =?iso-8859-1?q?TiUY6Zs7POKOOKz+E3A0b2fMvl4sVkB+yekEz/a1/kJCRdF7m8HV32ODrkcJ?= =?iso-8859-1?q?veRhONQEta5ly3QevBxsldj5kch9LirxHKWTb7HZdGov6PGqwyxIc4XwnaN8?= =?iso-8859-1?q?r635RNb9LMryTVAHUlGAOfsCYBfnOqHHwJkK27A94uYE25s6R9bsbE3ubDrO?= =?iso-8859-1?q?vWwk+I3FSqxtW/SHnuzQUUDuctZF/BaI72h4nury4hH5ANvZErxwTexlicP1?= =?iso-8859-1?q?nV0Sox6Vzc3twwYhMBjwZyc1y6ly4N4FQ3Z41C8s9NjKDalzZSrrGZfPuLfL?= =?iso-8859-1?q?IBfdVZRme8jDbfsyAQ38vg2hFv7QfTAqFMv8gax55G0oGaxrd0DhXPQ+uuNC?= =?iso-8859-1?q?1KEOkG7EiowGa1MxseISbNzrFeBxHbTilLOHXSCfI0YXd+V7bXy0Jpya8zcn?= =?iso-8859-1?q?kR2R/FBYPQlxTgQeXmIO0W1c6pf1ogVazICK5PLGiXJMyat+Nc8z/8kGbY9K?= =?iso-8859-1?q?isfuqMvzEA0NbnzPcmFCzFVJNMvuc3yhOI/mlu8paO/P0be8XW+FBzqGkjpF?= =?iso-8859-1?q?z8IldR2+mTVF51VRWzCGGU/iNkaCNdc2jYgbJkoXrARaUKLLD/9oCSNdsl/p?= =?iso-8859-1?q?z54GoLxrH5WixF7+jDY6qxofT8WxGIzZKQOXRP+fkkGWfCV+eWGxRbQtq4y4?= =?iso-8859-1?q?7xB/hSoWXHxWxh4mPOslTqMXiQYv7uBnzMe5rglluDEnxiXWdoWJyp1DTUHk?= =?iso-8859-1?q?N4RlpBP4WWxy+On1SPsy2fGt3UfenILn2ZvSwkw/XfCSK+SHKBv3/buIyBPj?= =?iso-8859-1?q?nZGTsPt0VmSbsqwHIEzz3/RYOg7uCz9Ejz3lc/2xFaXHTNfcDNyTkhSv441z?= =?iso-8859-1?q?bwdgiWK6xe7hUsOjAE9iFoF7pDhNcznh/6edg3NNtJKponiMtWUvgAEAhnPy?= =?iso-8859-1?q?IAdyC1Wgi67ZWLpBGEwKkN7IFb6hCdB7JRZcrd+C1YLROb/lYBc5EGJKiyF2?= =?iso-8859-1?q?K4Ji/PDhXJqNrcmDawJxRnzt6xUZ9npok+o1pQSU/lADBxaL7ymSyKNmpA9M?= =?iso-8859-1?q?pM98pVqj6EFLdis6Xm28J0DDrBJhiNl+/dy91tB8pHOKihEMOHQB0DzQOr5T?= =?iso-8859-1?q?r+uBRzBN7gRSI0Fq77YNs5lvY3U1dfw4sVTBrQudWNBUQnC8log1z8eyrkH3?= =?iso-8859-1?q?FubYyEn9hgrG64iZKp3iZyOmcDICkoYhvGeax9PyQbJmjsmKifx1Sp91/53f?= =?iso-8859-1?q?iVt1+uDoGrSUUCMYbDc4vZaW1/34Fr2jeHhU29JyVT4U7cV7BqG072aje3u+?= =?iso-8859-1?q?PautkgInKEIRRvVHDFfl625aIr/cgN8svMHSjyQDViHnJPIl7gTRKNJM6dJw?= =?iso-8859-1?q?4iMKh3rJ30q5U/b0lYf1ejTfg2ZNrwDWNVhFIRyzE2i0Rm7dvPDgi1iLCkTP?= =?iso-8859-1?q?5Xq42Z4uBdu8Xt9U7vu+SA/ryGDmZ1qDXSJPcstO0IEpZrLKh+CEfje62Bi0?= =?iso-8859-1?q?mhpjBCo1FXD+5Rnhr5jcE+AZyiBZjM4SZP4oUdBAR93eaBz/EtWEtUmQR3OE?= =?iso-8859-1?q?uwB4=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 9f5f4eda-6347-4440-531f-08d9df1b051b X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2022 09:22:19.1642 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: le6uaqCbUcrkeXcMDeo4ArJzqgd9kk4SnQ3m1i0I2D2IfJZMPhz1QsSnwNy29xpR48fiyjdbG27ry8LTQE2UowdS58BlVcyUV5HghejseRE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR0P264MB0235 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1C8EE1C003B X-Stat-Signature: 9cjyzoakbbj64513a8tbtxog955bwr8d Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.9.73 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1643016139-286792 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: Add a macro to check whether an address is within module's text. Signed-off-by: Christophe Leroy --- include/linux/module.h | 13 +++++++++++++ kernel/module.c | 17 +++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 33b4db8f5ca5..fc7adb110a81 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -570,6 +570,19 @@ static inline bool within_range(unsigned long addr, void *base, unsigned int siz return addr >= (unsigned long)base && addr < (unsigned long)base + size; } +static inline bool within_module_layout_text(unsigned long addr, + const struct module_layout *layout) +{ + return within_range(addr, layout->base, layout->text_size); +} + +static inline bool within_module_text(unsigned long addr, + const struct module *mod) +{ + return within_module_layout_text(addr, &mod->core_layout) || + within_module_layout_text(addr, &mod->init_layout); +} + static inline bool within_module_layout(unsigned long addr, const struct module_layout *layout) { diff --git a/kernel/module.c b/kernel/module.c index 84a9141a5e15..201d27643c84 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -4224,11 +4224,6 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) return load_module(&info, uargs, flags); } -static inline int within(unsigned long addr, void *start, unsigned long size) -{ - return ((void *)addr >= start && (void *)addr < start + size); -} - #ifdef CONFIG_KALLSYMS /* * This ignores the intensely annoying "mapping symbols" found @@ -4765,13 +4760,11 @@ bool is_module_text_address(unsigned long addr) struct module *__module_text_address(unsigned long addr) { struct module *mod = __module_address(addr); - if (mod) { - /* Make sure it's within the text section. */ - if (!within(addr, mod->init_layout.base, mod->init_layout.text_size) - && !within(addr, mod->core_layout.base, mod->core_layout.text_size)) - mod = NULL; - } - return mod; + + if (mod && within_module_text(addr, mod)) + return mod; + + return NULL; } /* Don't grab lock, we're oopsing. */ From patchwork Mon Jan 24 09:22:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12721804 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 9E922C433F5 for ; Mon, 24 Jan 2022 09:22:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 391FE6B0087; Mon, 24 Jan 2022 04:22:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3411F6B0088; Mon, 24 Jan 2022 04:22:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 209836B0089; Mon, 24 Jan 2022 04:22:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id 1440D6B0087 for ; Mon, 24 Jan 2022 04:22:26 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D17C4181C9650 for ; Mon, 24 Jan 2022 09:22:25 +0000 (UTC) X-FDA: 79064639850.27.4B43A5E Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120052.outbound.protection.outlook.com [40.107.12.52]) by imf01.hostedemail.com (Postfix) with ESMTP id CCBBD4004C for ; Mon, 24 Jan 2022 09:22:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DSt+E/XURznZulAGhlMbiovc4yen7GRZN0F++FGe/XtZoow0OioJ9D2FrdHaftvImjCoavIwwUDHCxui2BbsbqSS5hyPglPMyaJJVAytNTStk+eZ+DpjqpkXJVeZfijNKYsSdzeGolIvJfPjy6E7sqXSwYp/BLzGGWDISq4C1OUgXZyxMyEUMUsrZS3wfspDCTDUEUQik+Kz+Hi+hMpbio8pdP7r3JrWGo8reHFSvAIJTSzjZEzqFJkb6sW/3suDNgMOYn1EeC40hPHTSnFKM3pUIgi5Z648u3iYee/v0MUjMI5L9Xzg+7H59nQQ1XMBPTcjDsVkk1o9tqOqsfOr5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rhTJ7QX3WkRpDwshxUt7QYbimHh3etVoyWuIW07lriA=; b=OCd9qBACfC9U1S7+GsND4RxyQ+S5Ck7cNGBKVJMvk2QDhqhMrXSguYsQPodaF0IxF7ObqouSxAS5UCHYiDCmjDjxZRRM7EDMjZ/ufPD8Mg4FD9FydpovcYSUrX3W2EnPG3QnHnByFVQGQi/2nOCQKvht7W1lPcwdnNfmYtWQhYLzksYQ5TZMr+cFua27Iwao0DA1ma4Gril1DL+kNsZepCeUkHpBpitheQB3WJ1eDXClSt1CS8cCG2fCJ/O48lCrYg36xjuAYzylAb15JLw7AznGDL1gU8nKkCDAj4mxp+2kaTIOOq0TeWwXNZtlPsBO3Dnxenk48eWDwVMpr3Mo5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR1P264MB1742.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1b5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Mon, 24 Jan 2022 09:22:22 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 09:22:22 +0000 From: Christophe Leroy To: Luis Chamberlain , Jessica Yu CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kgdb-bugreport@lists.sourceforge.net" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" Subject: [PATCH 3/7] modules: Always have struct mod_tree_root Thread-Topic: [PATCH 3/7] modules: Always have struct mod_tree_root Thread-Index: AQHYEQPkvRMP8VjwPkuoB6YwBo0YaA== Date: Mon, 24 Jan 2022 09:22:22 +0000 Message-ID: References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7d1175ff-49d7-48cc-c83c-08d9df1b0708 x-ms-traffictypediagnostic: PR1P264MB1742:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: DIPfQT1k+ttsTMuUBVvjkFOfIdb1xK68aJ8gPAkc+MYW4J9vEiDiGHMU0SJfv5TReNI0CEbOoraJ4bBdoOSlrd7yl+hjmydTTCo6i0FfnK81HTNT7Hgkq/nbFAfxj9rtFyk27arz5PU2xLfbYRcpJ4xCG1t9laKFcYatOdflc0Dgq5qmhBO47xFBhxyPDqmAs9eaP9b4L10OZ86A8X1y9YbaTBDiw78ITmZr6X4WN7e+CRaxXjNSKDp9FrRnYqvgLXCl6KyyqGBHsCoU6eYMTfqLOp1I4kAVVaOrkRr/zIwAFUN19ODu7sLH1FAP+dLheGdMswuduLyPohDSIrda7SQ7tD33lkbagnYBmyC1i/GVb9pk/RhylJKan2+te166Ij3UX+OhcAkNoUjcv1YZSr6P+uZMQlf/NGhnxEA2/dHOjm4xkaupRpthb0vwgjkAvkl+GrVCXMAgfmIE4EbEJmXUfWH3PhjqrjluTS47r78jwbO8mEKybm0MW+h2kUjSoCBG+K86WkSZfgdcZaOfMinh10R4R7mVSdHJ3EIHh+Tovz5vzkUMRmDw7DoICL4s0YsxZ2YKgGoHqEcXLR4ZPCXKlRQtvOBxHSftFH91Pk9wSlfSGUFUcYlI4O0e3Y3Tt7nxfbV/B192TRPlbGJ4ydRLNRFLf+oFo07OB4Ee1UdqjuuDBmHMEwya/OVzeGCrLhKU9jfTQ6TxG5AftP6dCg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(66556008)(66476007)(91956017)(316002)(6486002)(54906003)(110136005)(6512007)(508600001)(64756008)(2616005)(86362001)(8676002)(186003)(26005)(5660300002)(66446008)(83380400001)(2906002)(76116006)(38100700002)(122000001)(44832011)(71200400001)(38070700005)(6506007)(66946007)(4326008)(36756003)(8936002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?LRM3IeTpUDio9XbXSKJPUY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XDlmwTQE3bQ24ZA54TrCs5RZeIkMi9mPBQrvFHTvYeimvSj48E?= =?iso-8859-1?q?V5VesMfIOBKxPs/Q5clFxgiOMl3cg6eCG5qLOtQWQXNfow+3l48PFzS+QDaP?= =?iso-8859-1?q?atyeg70cCn2HxZq/JCJzTh4B5HmCsqWRPgTxi8a3BJiiqTRu496pwlso5N93?= =?iso-8859-1?q?raFs2/2DtJsC12IL8wyWxWFXk/1U5f+nYwAx5FeCiXjyn032cPSSFntxavP5?= =?iso-8859-1?q?qcbE7+BwRum1Qd+BWr6LlMoBhQ30EpgivEe2Y4p+ZCoWVyua8o5RURC13Ua7?= =?iso-8859-1?q?PjbD+JgifQ4CoE4Xt6FiS+PjyuRnujBoFhlO2uqUk8A/U2+3rLKXuq/y1dd/?= =?iso-8859-1?q?qFViGbl92ynU5kgdtDRiYbyemQEsssBQnJcPttjbAyvMZXxYmJRBJ7D2g48q?= =?iso-8859-1?q?Ysou94RzO2tpKsDJ5yBb0zuHda2TnF4glPrlBAFNOYmuvsuszrBBgdQ9RVhE?= =?iso-8859-1?q?8SGBNA+/gxT77Sj7G1lwZI5je/U3Clzkwl2HmtFj6GeY31Uy9CrIv8NtJFXB?= =?iso-8859-1?q?7/dAHFXejK9f9iQeuMvaHXjTRk4EeqN4YJMzn6XpDPVHZ2PS1qJVkQKCMsEX?= =?iso-8859-1?q?7ZWuIE51WK7LORXbf9gRnsahvKYwwSj7xbYgwYCTo7vcNeb2OLrRIlUqIK+2?= =?iso-8859-1?q?QQKmBfvraSosd/ozWCaVmxkVmLySLXOIgQLQTC3b3iQPoWoBvGr2SUA41pGV?= =?iso-8859-1?q?BvFc+J+A2XBLtNnYUWXoJm8qwciY3UL/62mzEdQi+q9PG1U5K4j7ipb9FUEa?= =?iso-8859-1?q?8wb+PZlozZjr/fXrdkWhJYMWvVZBH6Wok9c21LrHAVLuLax0cUchiyQmltxw?= =?iso-8859-1?q?tkPU=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 7d1175ff-49d7-48cc-c83c-08d9df1b0708 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2022 09:22:22.3669 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Jefnacka/hwUuHNJjIqB5m/kSJPzYXLhDkz8++8H8OMm9bDekn0iP1fzJeCm6jRR+Y8OAeev+RakZKFHVgwifl2eICu26El5bjpIQDLpdy0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR1P264MB1742 X-Stat-Signature: 6pstgptd1nh5neucm39cjkhywwrtq51p Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf01.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.52 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: CCBBD4004C X-HE-Tag: 1643016144-454962 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: In order to separate text and data, we need to setup two rb trees. This also means that struct mod_tree_root is required even without MODULES_TREE_LOOKUP. Also remove module_addr_min and module_addr_max as there will be one min and one max for each tree. Signed-off-by: Christophe Leroy --- kernel/module.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 201d27643c84..346bc2e7a150 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -85,7 +85,7 @@ * Mutex protects: * 1) List of modules (also safely readable with preempt_disable), * 2) module_use links, - * 3) module_addr_min/module_addr_max. + * 3) mod_tree.addr_min/mod_tree.addr_max. * (delete and add uses RCU list operations). */ static DEFINE_MUTEX(module_mutex); @@ -96,6 +96,16 @@ static void do_free_init(struct work_struct *w); static DECLARE_WORK(init_free_wq, do_free_init); static LLIST_HEAD(init_free_list); +static struct mod_tree_root { +#ifdef CONFIG_MODULES_TREE_LOOKUP + struct latch_tree_root root; +#endif + unsigned long addr_min; + unsigned long addr_max; +} mod_tree __cacheline_aligned = { + .addr_min = -1UL, +}; + #ifdef CONFIG_MODULES_TREE_LOOKUP /* @@ -149,17 +159,6 @@ static const struct latch_tree_ops mod_tree_ops = { .comp = mod_tree_comp, }; -static struct mod_tree_root { - struct latch_tree_root root; - unsigned long addr_min; - unsigned long addr_max; -} mod_tree __cacheline_aligned = { - .addr_min = -1UL, -}; - -#define module_addr_min mod_tree.addr_min -#define module_addr_max mod_tree.addr_max - static noinline void __mod_tree_insert(struct mod_tree_node *node) { latch_tree_insert(&node->node, &mod_tree.root, &mod_tree_ops); @@ -209,8 +208,6 @@ static struct module *mod_find(unsigned long addr) #else /* MODULES_TREE_LOOKUP */ -static unsigned long module_addr_min = -1UL, module_addr_max = 0; - static void mod_tree_insert(struct module *mod) { } static void mod_tree_remove_init(struct module *mod) { } static void mod_tree_remove(struct module *mod) { } @@ -239,10 +236,10 @@ static void __mod_update_bounds(void *base, unsigned int size) unsigned long min = (unsigned long)base; unsigned long max = min + size; - if (min < module_addr_min) - module_addr_min = min; - if (max > module_addr_max) - module_addr_max = max; + if (min < mod_tree.addr_min) + mod_tree.addr_min = min; + if (max > mod_tree.addr_max) + mod_tree.addr_max = max; } static void mod_update_bounds(struct module *mod) @@ -4526,14 +4523,14 @@ static void cfi_init(struct module *mod) mod->exit = *exit; #endif - cfi_module_add(mod, module_addr_min); + cfi_module_add(mod, mod_tree.addr_min); #endif } static void cfi_cleanup(struct module *mod) { #ifdef CONFIG_CFI_CLANG - cfi_module_remove(mod, module_addr_min); + cfi_module_remove(mod, mod_tree.addr_min); #endif } @@ -4717,7 +4714,7 @@ struct module *__module_address(unsigned long addr) { struct module *mod; - if (addr < module_addr_min || addr > module_addr_max) + if (addr < mod_tree.addr_min || addr > mod_tree.addr_max) return NULL; module_assert_mutex_or_preempt(); From patchwork Mon Jan 24 09:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12721805 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 6A624C433EF for ; Mon, 24 Jan 2022 09:22:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 036906B0088; Mon, 24 Jan 2022 04:22:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F03D26B0089; Mon, 24 Jan 2022 04:22:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2E266B008A; Mon, 24 Jan 2022 04:22:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0167.hostedemail.com [216.40.44.167]) by kanga.kvack.org (Postfix) with ESMTP id C60FA6B0088 for ; Mon, 24 Jan 2022 04:22:27 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8A7908248D52 for ; Mon, 24 Jan 2022 09:22:27 +0000 (UTC) X-FDA: 79064639934.05.5E10174 Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120042.outbound.protection.outlook.com [40.107.12.42]) by imf23.hostedemail.com (Postfix) with ESMTP id 050D914000E for ; Mon, 24 Jan 2022 09:22:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kVZ8ojzhT8ZyaUdD3eTp2OrppvIDJ43bYLykyL3sAIyFzCHKl3WTl0o3q5OU/qRv1by+7z5mIYeK6h/om5szE8Yvlhp5oUbFe6H4H1iHdXXHdwZJEwPTCIbnoaU1Lbe1mnGOVuhZkBlfvKs3VXMbCU3BUlc0TT4ZVR+g+GYan08rxiulsvBu+svWaPzRy7alrJROC2Zyj8UhCMAXE3DfUa/f/CpwhivoqP9/3VeioJiFam6H2G1S2vbplHh0OEF/zjDSJtFX8xFn/3lfEGgzKUQ6mrXWOl4vMstIo9+4YLu1PkOQIqe9qILfbry4sqgzEbD5SLrJi3B5p66PUSk8iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4vYHN3GX5aVxixYLF0RC1M6EWpoRCEfxGB8h8Addwkk=; b=RBRegFexI30dgrrX88hyFWh7Qi8jxtLMlpNC23pBeWD+6ZCy4/CfLzlIdSrR8ulpnqfI7vd6BJtHFffeglNKSq68ycd7TTj8bR8drxHQnOTW3HhBxNFdDzneyqkJRU75Eh+DFVAysNXKi4xqb8MQElAbqZkjsK3jN44kn7mPGvO7fwpK4w2/0uyDMLCci1ltfOU0/ZyuZUVFXQTyGYhadtMCdI9TpP8CW82XVyQIAehJfyNV2kNaRYdC/dYXGXtffcRp49mo6kh6H8pYTATPqgoR6kKPIn6Ch6e1rh/cqql2apsJ79CfVwtdMIMgBvlHmpv7YStRdZacAJXXTENX2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR1P264MB1742.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1b5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Mon, 24 Jan 2022 09:22:25 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 09:22:25 +0000 From: Christophe Leroy To: Luis Chamberlain , Jessica Yu CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kgdb-bugreport@lists.sourceforge.net" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" Subject: [PATCH 4/7] modules: Prepare for handling several RB trees Thread-Topic: [PATCH 4/7] modules: Prepare for handling several RB trees Thread-Index: AQHYEQPmKXwkfhrzcEa1kF7tzAaVuQ== Date: Mon, 24 Jan 2022 09:22:25 +0000 Message-ID: References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5088db47-4151-481c-fab0-08d9df1b08bf x-ms-traffictypediagnostic: PR1P264MB1742:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dFhZUmIazp9Jrwd2v6gwR2tVK15LQ8eSsuEH6hVsrjy/jUwndFiBPj2Q4rzmO6ZeDA3vUXFhoTzacHD97jQ4AvgtkhU/9kyONp14IF8zT2UMixzrSsMriaJLgEPUPkMk/pZvWstUSScA/UTeDCSD+GCGWs/dZI3iQQehG5T4t8z8AagXpt8FeB4cnLsA9XYeyrj4L+B5p6j+h0T5Ib9exuong2VmZhvTDc80KtckYW0IPSWLjzyYYIaz2HL/+iOacRyLlZm0MfjSldFH/9rwQ+R52LNNTDGiuefb4GUNLuAvnWEn79Vcnp9kBmqkIO43eq+XLL9ovJVHqN75gBR2Unus7E0NnIkI6pRn2yaoL9wM5c1r6Q2CFz1/HdvSvsBBFH4ghXIXeAQtEXpGvjzevEy6ZMva3Ie0joJ76E5yu3r/hx/Y3GrEbwdO7mIo5FlXAMGyRxLQmj0xgjhFSTLjzNl/j4iZiVknLhnnDtOO8fqXc2e+Pc50VFMkF0GHpCfFi58bxZEcBErwDiNleisDyz/hpsCQj6wCKFOZiiYLk7RT0SmedMjy6cAwmDYw11B/7TgRgOtN/VxJfeqe6Xjs71cdNPylZAcotqznyozzxzJfYsni8eGoEv8TnYxzCNDeakKzk7F77qZRUZq7V0jSs72tFfTTQchoFLRyT1QVty0n5rWWRRGhedBW7uUNhWtrqo4JmX5mrCOF9hon1KLhnA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(66556008)(66476007)(91956017)(316002)(6486002)(54906003)(110136005)(6512007)(508600001)(64756008)(2616005)(86362001)(8676002)(186003)(26005)(5660300002)(66446008)(83380400001)(2906002)(76116006)(38100700002)(122000001)(44832011)(71200400001)(38070700005)(6506007)(66946007)(4326008)(36756003)(8936002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?7zqyxdmFF8DLDS3ZjG5YQdR?= =?iso-8859-1?q?hquLnp/LdU68jo24RjQkINQz7gGiVPfsG3hoHZXEgaucLeNYCN+NwWFl9IkQ?= =?iso-8859-1?q?l54G/lx7gpSFtef5KxPi7EW1ClRtBAq07hmI/TYvUvhsvXRODU6JP/V60Jwn?= =?iso-8859-1?q?gN/Y5f+4rmLEQHpMx+FPa/bjxWXoOW1CJPVAGsnRGy+oCZlIkyDVWzLj9f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1uxH7FW/85RvndqTwyv+xjU6nRftmoSx7j09VCygQ6yawzRus2Dk?= =?iso-8859-1?q?HaHK8x+loelbhE7UXNlBmbzi2Jv8tq1li+g7MuSkJ1ecDHQVqF1oZbVhT2xy?= =?iso-8859-1?q?iLQgRMXiSeQ6x/Isdy5w+l0KJ/09zRAOHcEXoDHPsOshSStlxUPtEmu0z6UY?= =?iso-8859-1?q?Vtuijv/P0vXbEpAL4qbjvAiiKqb06TD3C3RwglHXQfTBNDRNWMRgnOgBw058?= =?iso-8859-1?q?r1jvW0AdAsPIF94As7BYbPa3IwEwn6R8jU8l8CaKWYouT+XlyPJpBTaZqOqW?= =?iso-8859-1?q?5nJmati5sUDjeflK5WrSpb9WZygjaE5jyRlIhule3aMJL6o2ZjwKVC0i7XF0?= =?iso-8859-1?q?b3exWNYeDboNto13NtJsv+qJv8GLlQ/sdUioDWctfIIJjgs2dyKjaWjyaIwp?= =?iso-8859-1?q?CoENg+G6E2HIEr0ZZb8/hjD2035fUh6V9lkMaTvwdKHv3kpVW8y2OoNiJGSg?= =?iso-8859-1?q?lg+rfqexTdQ7iJiTefUmJStFcYJHQjnMSgn7llZ6WOO6djjiuaeFnEU7tpvL?= =?iso-8859-1?q?VJwr5wDVYAbA2fEoDqw0izWAhkhMpha3ObankcZYrgNltramBtz1y8bBvnHk?= =?iso-8859-1?q?ID2enbPb79bp2NjvJcA248Ty1cIqc3s/13Qb94IaF94N8SXRYXYHRok9u1zh?= =?iso-8859-1?q?UnVA=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 5088db47-4151-481c-fab0-08d9df1b08bf X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2022 09:22:25.2765 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: kASDSAnqtDinizX+Ln70QKZDBkZYiI1Iuw9yYRPi5EeSW1b3tN3CcCXqmVxOgyzWJsJNo8g0D6MzCyh2bfJI+jUj1b8eZH8L8rc3eOm9YRM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR1P264MB1742 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 050D914000E X-Stat-Signature: c88srsks1s78a8n3y6uaejph5s8591ih Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.42 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1643016146-198001 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: In order to separate text and data, we need to setup two rb trees. So modify functions to give the tree as a parameter. Signed-off-by: Christophe Leroy --- kernel/module.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 346bc2e7a150..051fecef416b 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -159,14 +159,14 @@ static const struct latch_tree_ops mod_tree_ops = { .comp = mod_tree_comp, }; -static noinline void __mod_tree_insert(struct mod_tree_node *node) +static noinline void __mod_tree_insert(struct mod_tree_node *node, struct mod_tree_root *tree) { - latch_tree_insert(&node->node, &mod_tree.root, &mod_tree_ops); + latch_tree_insert(&node->node, &tree->root, &mod_tree_ops); } -static void __mod_tree_remove(struct mod_tree_node *node) +static void __mod_tree_remove(struct mod_tree_node *node, struct mod_tree_root *tree) { - latch_tree_erase(&node->node, &mod_tree.root, &mod_tree_ops); + latch_tree_erase(&node->node, &tree->root, &mod_tree_ops); } /* @@ -178,28 +178,28 @@ static void mod_tree_insert(struct module *mod) mod->core_layout.mtn.mod = mod; mod->init_layout.mtn.mod = mod; - __mod_tree_insert(&mod->core_layout.mtn); + __mod_tree_insert(&mod->core_layout.mtn, &mod_tree); if (mod->init_layout.size) - __mod_tree_insert(&mod->init_layout.mtn); + __mod_tree_insert(&mod->init_layout.mtn, &mod_tree); } static void mod_tree_remove_init(struct module *mod) { if (mod->init_layout.size) - __mod_tree_remove(&mod->init_layout.mtn); + __mod_tree_remove(&mod->init_layout.mtn, &mod_tree); } static void mod_tree_remove(struct module *mod) { - __mod_tree_remove(&mod->core_layout.mtn); + __mod_tree_remove(&mod->core_layout.mtn, &mod_tree); mod_tree_remove_init(mod); } -static struct module *mod_find(unsigned long addr) +static struct module *mod_find(unsigned long addr, struct mod_tree_root *tree) { struct latch_tree_node *ltn; - ltn = latch_tree_find((void *)addr, &mod_tree.root, &mod_tree_ops); + ltn = latch_tree_find((void *)addr, &tree->root, &mod_tree_ops); if (!ltn) return NULL; @@ -212,7 +212,7 @@ static void mod_tree_insert(struct module *mod) { } static void mod_tree_remove_init(struct module *mod) { } static void mod_tree_remove(struct module *mod) { } -static struct module *mod_find(unsigned long addr) +static struct module *mod_find(unsigned long addr, struct mod_tree_root *tree) { struct module *mod; @@ -231,22 +231,22 @@ static struct module *mod_find(unsigned long addr) * Bounds of module text, for speeding up __module_address. * Protected by module_mutex. */ -static void __mod_update_bounds(void *base, unsigned int size) +static void __mod_update_bounds(void *base, unsigned int size, struct mod_tree_root *tree) { unsigned long min = (unsigned long)base; unsigned long max = min + size; - if (min < mod_tree.addr_min) - mod_tree.addr_min = min; - if (max > mod_tree.addr_max) - mod_tree.addr_max = max; + if (min < tree->addr_min) + tree->addr_min = min; + if (max > tree->addr_max) + tree->addr_max = max; } static void mod_update_bounds(struct module *mod) { - __mod_update_bounds(mod->core_layout.base, mod->core_layout.size); + __mod_update_bounds(mod->core_layout.base, mod->core_layout.size, &mod_tree); if (mod->init_layout.size) - __mod_update_bounds(mod->init_layout.base, mod->init_layout.size); + __mod_update_bounds(mod->init_layout.base, mod->init_layout.size, &mod_tree); } #ifdef CONFIG_KGDB_KDB @@ -4719,7 +4719,7 @@ struct module *__module_address(unsigned long addr) module_assert_mutex_or_preempt(); - mod = mod_find(addr); + mod = mod_find(addr, &mod_tree); if (mod) { BUG_ON(!within_module(addr, mod)); if (mod->state == MODULE_STATE_UNFORMED) From patchwork Mon Jan 24 09:22:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12721806 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 1A446C433F5 for ; Mon, 24 Jan 2022 09:22:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A96566B008A; Mon, 24 Jan 2022 04:22:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A46966B008C; Mon, 24 Jan 2022 04:22:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90E8E6B0092; Mon, 24 Jan 2022 04:22:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id 825126B008A for ; Mon, 24 Jan 2022 04:22:32 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4953A903C2 for ; Mon, 24 Jan 2022 09:22:32 +0000 (UTC) X-FDA: 79064640144.27.64BF6CE Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120088.outbound.protection.outlook.com [40.107.12.88]) by imf19.hostedemail.com (Postfix) with ESMTP id 0BD8A1A0081 for ; Mon, 24 Jan 2022 09:22:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nP+3znfRf4xXXT4JXr/3CDuySIqgepl+vWeXQ2+8cUmTAjmjVk9i0vBMo+LPqz43zIq5Qhn0NSfw8OPbbgP0f4ARqL9mOyrPQEhHRvHUr5uqBlz1pPHEwa6U4X9nhmHi7nYW0kV4UfAIyqKfLPhrkW8zSpTNRhl/ZPqigBovoccdjX2yUnUYGVqigTplc177DMVo6ViSWhh4JTz7c5ZN8GZqfFCFLVtcL11I7NoEgLTzOLOo2QkwN1FgjCmWvi+A6atM23MRHNDBOEee+9+jzeXoF3QIYAzDZShx8MdYUgwLS2TCSRhFeWv5wizkRKO80ZFjV5ugVurl/JPJzSkgnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VTbVcR3jMufVBb5PW3NS2+4N3Hmnb6cMpE+GvX/CZYQ=; b=liyfcfw1rHZ231WXgSNKw/Yx1yTmIOp+p9JFcRZFSkcZ0nx2Dx0KWoX7x4GLKPQFBRaOxXbHqn4dvvKyWOBom8nixwg7UqITVi5taxBE4YLW54HsO5lMidejulmVVtK15HCCpTPf6QlvETGEhVyEkpEKd4f/InUYlGeaH0BO/1QEb5Xu0uPkaO7TLpTgAiQiFHuWCPA7gL4By6XnZiovRn+GuPLQ/RMUvRUgTvGmVwrzlRCMy9Mr0V33TaXb+c4tOBRD+ZeC1fnpzrX727O6u+lTA9kt0ZtMz6eZV9KgmqfRx/nxIxMFwAh3EHx5ysHyymObTDhMMZ5hJJIhbchZvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR1P264MB1742.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1b5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Mon, 24 Jan 2022 09:22:28 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 09:22:28 +0000 From: Christophe Leroy To: Luis Chamberlain , Jessica Yu CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kgdb-bugreport@lists.sourceforge.net" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" Subject: [PATCH 5/7] modules: Introduce data_layout Thread-Topic: [PATCH 5/7] modules: Introduce data_layout Thread-Index: AQHYEQPob8ByTEMNTUeq+xS9tS+mrg== Date: Mon, 24 Jan 2022 09:22:28 +0000 Message-ID: References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5ec41163-8959-4fa5-1fe2-08d9df1b0acc x-ms-traffictypediagnostic: PR1P264MB1742:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2150; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6RKTGnA0v6EjSwltQTYc/lJpZlhVKNmVB0FGSLOO9cb46Y24Magbb+W7CNX8N7I48vIot/Ru1230UnsSoXUKzmHPC1hLNmgcg+P/IcEvzsYRHIE4LHh301FaBGc1sph1HcIKgd+1B0AN+FV1xsHXAE6qKNP3BtN/c/yKxTQo6jF9EZVwovvbU8aQBXr59dYc5prgdJqnnwKbaEcq3Sq6fYZ25JTxzVa1lYmNVwgu4Z8eH/hg+V0ZiW/LlLnQymjHil8BZnm/zHl2zFtezsQP8f2IBO8JOV1wiWgz+fG3wTOvgIp6Q8CNOCQSqp8wWZmJnsnq+uUOtdspCNqEHVC1c4YBZmyDRIulsGAXUaiImYH0iKdrIUfuL7vqTNZvdFfpQVITMEKiWtJvIpVnSa8P40+fKI8RQNtzVpd5a7qPWl+NNOjviDX9gHder1FvHoHuCVCkyAUB+JGaSxJVqgPY9vG9vndkjBu9mQY+D7tz8rCethof38mWLB3ppJJZtngDdcvvCN/CWnkfwC5KJEuthbIjIuWiF7MMsbqw6Cd/BlZOSjvfRy5Gf7gvbXorf6oI+NLvRM8kIWjno4v1rIcNgw+eUR3DdyKiXpyOxiTzRvrDE3cE0FPwcLgT9lsv2fPBkYvGp8qkXzzUYBvyg5Zs+5RH9e92aMziPT/+XH6yEE6oUfp0wPZHmAz1UWWv7qsoH+aH+ROJHev182ezC28PBw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(66556008)(66476007)(91956017)(316002)(6486002)(54906003)(110136005)(6512007)(508600001)(64756008)(2616005)(86362001)(8676002)(186003)(26005)(5660300002)(66446008)(83380400001)(2906002)(76116006)(38100700002)(122000001)(44832011)(71200400001)(38070700005)(6506007)(66946007)(4326008)(36756003)(8936002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?WWp3zRPzOikt3xarTNdczOA?= =?iso-8859-1?q?wGoUvpywJjA+cDj2Y8MpUxMbB73RDFIeJpXTpREwLvczrJfe3WGZlE7tfcIM?= =?iso-8859-1?q?NubdUbe5CS1zi1Sptr7zY0Yz2aOr5gOfJQE/FDxFecg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?q?ngqNb5NGvqDAvoQH2GFtb10t0G4bxgRD/KyXOSrzBQAd5+BOBI0Vels9IcYE?= =?iso-8859-1?q?U2dst7lUY7GDJyX+SIahsXqAxKet64WzkkfiYyYA/OfW5OzobvPxGg5fQLzJ?= =?iso-8859-1?q?LOJNPvDVIi3dV+k247euXaFaP53WlLobv1it2gaJPzq2M1s6FQeiczVW1yCt?= =?iso-8859-1?q?xxn1JBGreRVzZ+C+jS/+4foleJn4qQxAvpyFyOKZhO4KBDhIObk5A+EwRn35?= =?iso-8859-1?q?C+VvZY49HewRVs9ubTT3TLm5Y9Yz1ow1wyHbeYMajF7+Ztm5y/UUOC2Y4PlA?= =?iso-8859-1?q?kRvsN9jRAyf0wJDisVScdrsvGDOOyvSFoIn+ZwtsatTb/7myk5TduY9oUtpu?= =?iso-8859-1?q?Mcuj+6ZquvgbWRIa//6zsQwC5E7rIFgY4PEv8UUaFB0WX4snx4vOtTbytI+p?= =?iso-8859-1?q?mCITQXPKE7ugRoUpr0W6Z9YvCMb9oG8b/iQ0ULWXFRiPPKO7p8YhCcxnd1yQ?= =?iso-8859-1?q?FY7kQ0P2WcieDDuQPik7QR/nTazHlrKXMRTH1D4GliW7VRc+poROpEY0USt1?= =?iso-8859-1?q?vxD+VWqM9zyQQJPPzUEIsGVoVYbZH1LLFKjIhPHsvm2YujvB8lLVornYjibh?= =?iso-8859-1?q?BUrzb7cWxfXYettLrYW1QKU+G7rUQlISBF9qEZB7B1FFXlQID5f9VPZIQ9nW?= =?iso-8859-1?q?xWFCMAOOacoiVyOEY+Cq3uKUuq47S220VFCi/4cM1mC9L1PknZg7pFWHyFAr?= =?iso-8859-1?q?hgTY=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 5ec41163-8959-4fa5-1fe2-08d9df1b0acc X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2022 09:22:28.6803 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: a8fiTlyMoImxU/5NzIKQdBij9UfX+3HY7nXRiD2V1PjBX8QPviJG0/bnTeXLAyDzBbIMJjrjl284K3dxQxcF+9whqdruaoo0Wk+Pp1qPfDc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR1P264MB1742 Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.88 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0BD8A1A0081 X-Stat-Signature: w78tkugbosact13ww5m1nhizowz3erhj X-HE-Tag: 1643016150-98075 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: In order to allow separation of data from text, add another layout, called data_layout. For architectures requesting separation of text and data, only text will go in core_layout and data will go in data_layout. For architectures which keep text and data together, make data_layout an alias of core_layout, that way data_layout can be used for all data manipulations, regardless of whether data is in core_layout or data_layout. Signed-off-by: Christophe Leroy --- kernel/module.c | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 051fecef416b..de1a9de6a544 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -81,6 +81,8 @@ /* If this is set, the section belongs in the init part of the module */ #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) +#define data_layout core_layout + /* * Mutex protects: * 1) List of modules (also safely readable with preempt_disable), @@ -2012,19 +2014,20 @@ static void module_enable_ro(const struct module *mod, bool after_init) set_vm_flush_reset_perms(mod->init_layout.base); frob_text(&mod->core_layout, set_memory_ro); - frob_rodata(&mod->core_layout, set_memory_ro); + frob_rodata(&mod->data_layout, set_memory_ro); + frob_text(&mod->init_layout, set_memory_ro); frob_rodata(&mod->init_layout, set_memory_ro); if (after_init) - frob_ro_after_init(&mod->core_layout, set_memory_ro); + frob_ro_after_init(&mod->data_layout, set_memory_ro); } static void module_enable_nx(const struct module *mod) { - frob_rodata(&mod->core_layout, set_memory_nx); - frob_ro_after_init(&mod->core_layout, set_memory_nx); - frob_writable_data(&mod->core_layout, set_memory_nx); + frob_rodata(&mod->data_layout, set_memory_nx); + frob_ro_after_init(&mod->data_layout, set_memory_nx); + frob_writable_data(&mod->data_layout, set_memory_nx); frob_rodata(&mod->init_layout, set_memory_nx); frob_writable_data(&mod->init_layout, set_memory_nx); } @@ -2202,7 +2205,7 @@ static void free_module(struct module *mod) percpu_modfree(mod); /* Free lock-classes; relies on the preceding sync_rcu(). */ - lockdep_free_key_range(mod->core_layout.base, mod->core_layout.size); + lockdep_free_key_range(mod->data_layout.base, mod->data_layout.size); /* Finally, free the core (containing the module structure) */ module_memfree(mod->core_layout.base); @@ -2449,7 +2452,10 @@ static void layout_sections(struct module *mod, struct load_info *info) || s->sh_entsize != ~0UL || module_init_layout_section(sname)) continue; - s->sh_entsize = get_offset(mod, &mod->core_layout.size, s, i); + if (m) + s->sh_entsize = get_offset(mod, &mod->data_layout.size, s, i); + else + s->sh_entsize = get_offset(mod, &mod->core_layout.size, s, i); pr_debug("\t%s\n", sname); } switch (m) { @@ -2458,15 +2464,15 @@ static void layout_sections(struct module *mod, struct load_info *info) mod->core_layout.text_size = mod->core_layout.size; break; case 1: /* RO: text and ro-data */ - mod->core_layout.size = debug_align(mod->core_layout.size); - mod->core_layout.ro_size = mod->core_layout.size; + mod->data_layout.size = debug_align(mod->data_layout.size); + mod->data_layout.ro_size = mod->data_layout.size; break; case 2: /* RO after init */ - mod->core_layout.size = debug_align(mod->core_layout.size); - mod->core_layout.ro_after_init_size = mod->core_layout.size; + mod->data_layout.size = debug_align(mod->data_layout.size); + mod->data_layout.ro_after_init_size = mod->data_layout.size; break; case 4: /* whole core */ - mod->core_layout.size = debug_align(mod->core_layout.size); + mod->data_layout.size = debug_align(mod->data_layout.size); break; } } @@ -2719,12 +2725,12 @@ static void layout_symtab(struct module *mod, struct load_info *info) } /* Append room for core symbols at end of core part. */ - info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1); - info->stroffs = mod->core_layout.size = info->symoffs + ndst * sizeof(Elf_Sym); - mod->core_layout.size += strtab_size; - info->core_typeoffs = mod->core_layout.size; - mod->core_layout.size += ndst * sizeof(char); - mod->core_layout.size = debug_align(mod->core_layout.size); + info->symoffs = ALIGN(mod->data_layout.size, symsect->sh_addralign ?: 1); + info->stroffs = mod->data_layout.size = info->symoffs + ndst * sizeof(Elf_Sym); + mod->data_layout.size += strtab_size; + info->core_typeoffs = mod->data_layout.size; + mod->data_layout.size += ndst * sizeof(char); + mod->data_layout.size = debug_align(mod->data_layout.size); /* Put string table section at end of init part of module. */ strsect->sh_flags |= SHF_ALLOC; @@ -2768,9 +2774,9 @@ static void add_kallsyms(struct module *mod, const struct load_info *info) * Now populate the cut down core kallsyms for after init * and set types up while we still have access to sections. */ - mod->core_kallsyms.symtab = dst = mod->core_layout.base + info->symoffs; - mod->core_kallsyms.strtab = s = mod->core_layout.base + info->stroffs; - mod->core_kallsyms.typetab = mod->core_layout.base + info->core_typeoffs; + mod->core_kallsyms.symtab = dst = mod->data_layout.base + info->symoffs; + mod->core_kallsyms.strtab = s = mod->data_layout.base + info->stroffs; + mod->core_kallsyms.typetab = mod->data_layout.base + info->core_typeoffs; src = mod->kallsyms->symtab; for (ndst = i = 0; i < mod->kallsyms->num_symtab; i++) { mod->kallsyms->typetab[i] = elf_type(src + i, info); @@ -3462,6 +3468,8 @@ static int move_module(struct module *mod, struct load_info *info) if (shdr->sh_entsize & INIT_OFFSET_MASK) dest = mod->init_layout.base + (shdr->sh_entsize & ~INIT_OFFSET_MASK); + else if (!(shdr->sh_flags & SHF_EXECINSTR)) + dest = mod->data_layout.base + shdr->sh_entsize; else dest = mod->core_layout.base + shdr->sh_entsize; @@ -4167,7 +4175,7 @@ static int load_module(struct load_info *info, const char __user *uargs, mutex_unlock(&module_mutex); free_module: /* Free lock-classes; relies on the preceding sync_rcu() */ - lockdep_free_key_range(mod->core_layout.base, mod->core_layout.size); + lockdep_free_key_range(mod->data_layout.base, mod->data_layout.size); module_deallocate(mod, info); free_copy: From patchwork Mon Jan 24 09:22:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12721807 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 ECD18C433F5 for ; Mon, 24 Jan 2022 09:22:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89ADC6B0092; Mon, 24 Jan 2022 04:22:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 84AA76B0093; Mon, 24 Jan 2022 04:22:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 711B46B0095; Mon, 24 Jan 2022 04:22:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 63B4F6B0092 for ; Mon, 24 Jan 2022 04:22:37 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2F59D91AD6 for ; Mon, 24 Jan 2022 09:22:37 +0000 (UTC) X-FDA: 79064640354.07.A80A901 Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120047.outbound.protection.outlook.com [40.107.12.47]) by imf16.hostedemail.com (Postfix) with ESMTP id 84B99180031 for ; Mon, 24 Jan 2022 09:22:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RiOiPtN/Jr8FN7L9/6KPPIQSIc8OsJt8AvUhafxyLYZ4/V7dQh0pFHSSNxXq9HU80JZJbu/D5dYECuSF887Yq8q5jF/QLsRTCeGGAy5MASPj3WAzvQTTGjh5jLl2a8bts4bJwBdqZzZuxRPNbkgBDAlS8Uy8S3mwaU3NRaRsY8TzkSG1eQoFHZ0oi/uCyQ2uiVoxd/XrcBy7FeInu6wi44PU8+h5AlMAnNgjsasXZieRrZDg6WKcsS2uwJ2zLAJIRYk9haU5m6aqMFviURn/xjlSH8JnMiVOFFWD7bQqWlvi3In442EKh8F01Jbszn3oy7ABMaKYtFn559nPHNWSHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bMsW8FpagZt8kJgfuuAdQRpHDbv+vxyvyU1u52FdqhI=; b=UUHbXrQkaGd0QdxpwmIo1DVNyX+TfN3vHEryx6EneS7IzoaPnILg9BTRq74bX6VsX3dUX2ugMDZ943cb0Ncm/np93eqsnU8Jd0OpDgiR/51PRk+TQYuGpZxhVej0JvzFpVdcPLkFXzJ5fwR+rmzhDptx6Gq/Tyf0P/tUQKQOykxszvDZN+qCnJ0s3Qd/Qf6Xd+wv/vI5DOTyENRxufHiLpbqFc8wpHd7gHsJeY6daHajkE3RK7gDiNJqAeCmAf/eKiqaaRfDadUXUOYPqLIWZNUcl6ESEbPj+d/CcR9uOUvDCRklj3HihkpU6vIFSoUySHvqFOMY9B0tnwrgAK2alw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR1P264MB1742.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1b5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Mon, 24 Jan 2022 09:22:34 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 09:22:34 +0000 From: Christophe Leroy To: Luis Chamberlain , Jessica Yu CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kgdb-bugreport@lists.sourceforge.net" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" , Jason Wessel , Daniel Thompson , Douglas Anderson Subject: [PATCH 6/7] modules: Add CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC Thread-Topic: [PATCH 6/7] modules: Add CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC Thread-Index: AQHYEQPri54wm9k2kUic7oR3m4zr7g== Date: Mon, 24 Jan 2022 09:22:34 +0000 Message-ID: <848d857871f457f4df37e80fad468d615b237c24.1643015752.git.christophe.leroy@csgroup.eu> References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 32be9bc4-dd58-40cd-0e7a-08d9df1b0e37 x-ms-traffictypediagnostic: PR1P264MB1742:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3383; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5UfPIhTMFJiMu+SEES3I0o+vtzG8ygg/QNlsNYjMGuHEnk+esOimqFrVjlYZnfgsDh7pXTij8kKKB4n/fySur1AawLLbG9Vu5zgzE74s5BlapOZ3ln04Ii21Ky7pRN23OWBM1IFilXgIN6FG/gZ/jG2P+831w+GHleltYWoAyZkKqaiGSplvbjRd4sFA/lkNA6esJNwdpBMPb3JjMSPFOBFNO9RUKh1DfMN89ViC0NQjinpmOYIL01VVbl4ljMEu0zcok5c6NTbPHxKX7NTMQvgVIew2nV/+W6JaI0Ompuo8YGmNzusi1qILh00ySUnKpYLRTbsHkbKqXSbEqrgGx8+EvOBzCzBMsOHZin0tQ2JlYrbhf9MqphmTxiEDehRdpqN3UaleZK6GX43YYi0nmdGfITof1Blzu/e9ZMWrhTf29PdFabRCOXeD3+7XY7pmBrZxD/W7Q8g9molaNjkBUlsZW5l15D5TTgAd2HzQlc+VohuI90lwIXA52+aG6V2HtkqX3eYZLTQ3lw2ZhhRNR6rp4U5PZabJy8U5qltSmcEMackA6uIpo+TWGjXgzChfqvex9hNP2cKcn1qOrW3PPe4XiSKsE4We9ONfG6yWdT3bzIZoAe5u1T2COD1rTw5EvELUi2vldvuiC/HHq9LK5Sb5QZ5w42LZQxeXQHmgH3+sgw8SnR66Fi9Y8SOdCUl4/uRJ4H31sa3Unmb75e6kqg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(66556008)(7416002)(66476007)(91956017)(316002)(6486002)(54906003)(110136005)(6512007)(508600001)(64756008)(2616005)(86362001)(8676002)(186003)(26005)(5660300002)(66446008)(83380400001)(2906002)(76116006)(38100700002)(122000001)(44832011)(71200400001)(38070700005)(6506007)(66946007)(4326008)(36756003)(8936002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?TZGymvdsy+SsDpfKfbX0FqH?= =?iso-8859-1?q?5wqabpfFrGebYu4rVIXfiQcZTkEvGd0PXj3StIoFHjtOTiWlI37xGq2wlCEk?= =?iso-8859-1?q?v3mtiGq8VF/RxQPZNzrTD6O7GIqL2pLboaOqmLVG3vEOnv0WPZnhldJN9JOm?= =?iso-8859-1?q?qnTMQyaPzK0HjhmeEhu0p9Demx3GFdh2Iv003Mlp3JydlgbCKwnLM20yimzN?= =?iso-8859-1?q?d3+e2Yw8b1BqGGDyLA1EGxP+3GSA8Zn8C4SAvXez1A9fV51CkviGwjs36/tC?= =?iso-8859-1?q?o/snMZfClgGTQbx0nJ7HixHZn1Ikyxwtj5XHDSwsR0zujXYuYoUwNQ/RKzS+?= =?iso-8859-1?q?aoaY9xEq+SK1StUy3VbftFMe9Z2e0XlFMBoH2w4JQkeryO0cXpIY7pvs3qhw?= =?iso-8859-1?q?Oz3pmIL/2pv7L0cGKv5vySbDHbDEAzsCpyTvjwyIJLwskA6Ru20pB+5Ofspt?= =?iso-8859-1?q?t5Ob9cvuF95avuJ6N442W169Hy9YzYhSjVtyCiBjQy5+YT/37G6pD5ESIWxO?= =?iso-8859-1?q?uEWHtr5p5tngQY2V8VHUkw+v7km+0TuaULb2wen8FxshIVkeqzjTTHa4cvV3?= =?iso-8859-1?q?XR+gjWK7BaXNDxZOyPpiOtZf8K7dH7njjVSUzQQ2nl9g2J0JHvq/R7rfKGd4?= =?iso-8859-1?q?5IMNneOkxUaDwsTuQBWboHJ0PS3U5tQyQMKXarBB5VRXXQzav3mDOuC6RI2+?= =?iso-8859-1?q?LcaRqff3FQ3AdcswjIo3cEvoj8VcYVg7o8a9Q5BRvI1wMDsObFSu6V6q5Z3X?= =?iso-8859-1?q?JTq607qYFtxrtkO9kXhhE9e5thEp3SAmKKWo/AyG4SOWVe/0fMrljyY/GO13?= =?iso-8859-1?q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UP9eWvduYFIuJk9arPjSjQYQIxDCwEwJlYop6BjXBhWH?= =?iso-8859-1?q?PBOA=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 32be9bc4-dd58-40cd-0e7a-08d9df1b0e37 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2022 09:22:34.4142 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: DsjACjUCXRe+Nt7RLX3D5mfDzV3WVewrGhpvRjd6RkNfLT3jnEQR1aRIgC+4zbSfqcTxfNTCv3XC2yaQkCU0Z3NMeWrVGeAlXAoQK+W+BDM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR1P264MB1742 Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.47 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-Stat-Signature: j53q6xwhkpe3kzm4huym6mxkf1msmgzr X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 84B99180031 X-HE-Tag: 1643016156-150283 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: Add CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC to allow architectures to request having modules data in vmalloc area instead of module area. This is required on powerpc book3s/32 in order to set data non executable, because it is not possible to set executability on page basis, this is done per 256 Mbytes segments. The module area has exec right, vmalloc area has noexec. This can also be useful on other powerpc/32 in order to maximize the chance of code being close enough to kernel core to avoid branch trampolines. Signed-off-by: Christophe Leroy Cc: Jason Wessel Cc: Daniel Thompson Cc: Douglas Anderson --- arch/Kconfig | 6 +++ include/linux/module.h | 8 ++++ kernel/debug/kdb/kdb_main.c | 10 ++++- kernel/module.c | 73 ++++++++++++++++++++++++++++++++++++- 4 files changed, 93 insertions(+), 4 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 847fde3d22cd..ed6a5ab8796d 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -883,6 +883,12 @@ config MODULES_USE_ELF_REL Modules only use ELF REL relocations. Modules with ELF RELA relocations will give an error. +config ARCH_WANTS_MODULES_DATA_IN_VMALLOC + bool + help + For architectures like powerpc/32 which have constraints on module + allocation and need to allocate module data outside of module area. + config HAVE_IRQ_EXIT_ON_IRQ_STACK bool help diff --git a/include/linux/module.h b/include/linux/module.h index fc7adb110a81..3d908bb7ed08 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -421,6 +421,9 @@ struct module { /* Core layout: rbtree is accessed frequently, so keep together. */ struct module_layout core_layout __module_layout_align; struct module_layout init_layout; +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + struct module_layout data_layout; +#endif /* Arch-specific module values */ struct mod_arch_specific arch; @@ -592,7 +595,12 @@ static inline bool within_module_layout(unsigned long addr, static inline bool within_module_core(unsigned long addr, const struct module *mod) { +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + return within_module_layout(addr, &mod->core_layout) || + within_module_layout(addr, &mod->data_layout); +#else return within_module_layout(addr, &mod->core_layout); +#endif } static inline bool within_module_init(unsigned long addr, diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 0852a537dad4..b09e92f2c78d 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -2022,8 +2022,11 @@ static int kdb_lsmod(int argc, const char **argv) if (mod->state == MODULE_STATE_UNFORMED) continue; - kdb_printf("%-20s%8u 0x%px ", mod->name, - mod->core_layout.size, (void *)mod); + kdb_printf("%-20s%8u", mod->name, mod->core_layout.size); +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + kdb_printf("/%8u 0x%px ", mod->data_layout.size); +#endif + kdb_printf(" 0x%px ", (void *)mod); #ifdef CONFIG_MODULE_UNLOAD kdb_printf("%4d ", module_refcount(mod)); #endif @@ -2034,6 +2037,9 @@ static int kdb_lsmod(int argc, const char **argv) else kdb_printf(" (Live)"); kdb_printf(" 0x%px", mod->core_layout.base); +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + kdb_printf("/0x%px", mod->data_layout.base); +#endif #ifdef CONFIG_MODULE_UNLOAD { diff --git a/kernel/module.c b/kernel/module.c index de1a9de6a544..53486a65750e 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -81,7 +81,9 @@ /* If this is set, the section belongs in the init part of the module */ #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) +#ifndef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC #define data_layout core_layout +#endif /* * Mutex protects: @@ -108,6 +110,12 @@ static struct mod_tree_root { .addr_min = -1UL, }; +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC +static struct mod_tree_root mod_data_tree __cacheline_aligned = { + .addr_min = -1UL, +}; +#endif + #ifdef CONFIG_MODULES_TREE_LOOKUP /* @@ -183,6 +191,11 @@ static void mod_tree_insert(struct module *mod) __mod_tree_insert(&mod->core_layout.mtn, &mod_tree); if (mod->init_layout.size) __mod_tree_insert(&mod->init_layout.mtn, &mod_tree); + +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + mod->data_layout.mtn.mod = mod; + __mod_tree_insert(&mod->data_layout.mtn, &mod_data_tree); +#endif } static void mod_tree_remove_init(struct module *mod) @@ -195,6 +208,9 @@ static void mod_tree_remove(struct module *mod) { __mod_tree_remove(&mod->core_layout.mtn, &mod_tree); mod_tree_remove_init(mod); +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + __mod_tree_remove(&mod->core_layout.mtn, &mod_data_tree); +#endif } static struct module *mod_find(unsigned long addr, struct mod_tree_root *tree) @@ -249,6 +265,9 @@ static void mod_update_bounds(struct module *mod) __mod_update_bounds(mod->core_layout.base, mod->core_layout.size, &mod_tree); if (mod->init_layout.size) __mod_update_bounds(mod->init_layout.base, mod->init_layout.size, &mod_tree); +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + __mod_update_bounds(mod->data_layout.base, mod->data_layout.size, &mod_data_tree); +#endif } #ifdef CONFIG_KGDB_KDB @@ -1179,6 +1198,17 @@ static ssize_t show_coresize(struct module_attribute *mattr, static struct module_attribute modinfo_coresize = __ATTR(coresize, 0444, show_coresize, NULL); +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC +static ssize_t show_datasize(struct module_attribute *mattr, + struct module_kobject *mk, char *buffer) +{ + return sprintf(buffer, "%u\n", mk->mod->data_layout.size); +} + +static struct module_attribute modinfo_datasize = + __ATTR(datasize, 0444, show_datasize, NULL); +#endif + static ssize_t show_initsize(struct module_attribute *mattr, struct module_kobject *mk, char *buffer) { @@ -1207,6 +1237,9 @@ static struct module_attribute *modinfo_attrs[] = { &modinfo_srcversion, &modinfo_initstate, &modinfo_coresize, +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + &modinfo_datasize, +#endif &modinfo_initsize, &modinfo_taint, #ifdef CONFIG_MODULE_UNLOAD @@ -2209,6 +2242,9 @@ static void free_module(struct module *mod) /* Finally, free the core (containing the module structure) */ module_memfree(mod->core_layout.base); +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + vfree(mod->data_layout.base); +#endif } void *__symbol_get(const char *symbol) @@ -3456,6 +3492,24 @@ static int move_module(struct module *mod, struct load_info *info) } else mod->init_layout.base = NULL; +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + /* Do the allocs. */ + ptr = vmalloc(mod->data_layout.size); + /* + * The pointer to this block is stored in the module structure + * which is inside the block. Just mark it as not being a + * leak. + */ + kmemleak_not_leak(ptr); + if (!ptr) { + module_memfree(mod->core_layout.base); + module_memfree(mod->init_layout.base); + return -ENOMEM; + } + + memset(ptr, 0, mod->data_layout.size); + mod->data_layout.base = ptr; +#endif /* Transfer each section which specifies SHF_ALLOC */ pr_debug("final section addresses:\n"); for (i = 0; i < info->hdr->e_shnum; i++) { @@ -3631,6 +3685,9 @@ static void module_deallocate(struct module *mod, struct load_info *info) module_arch_freeing_init(mod); module_memfree(mod->init_layout.base); module_memfree(mod->core_layout.base); +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + vfree(mod->data_layout.base); +#endif } int __weak module_finalize(const Elf_Ehdr *hdr, @@ -4597,8 +4654,13 @@ static int m_show(struct seq_file *m, void *p) if (mod->state == MODULE_STATE_UNFORMED) return 0; +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + seq_printf(m, "%s %u", mod->name, + mod->init_layout.size + mod->core_layout.size + mod->data_layout.size); +#else seq_printf(m, "%s %u", mod->name, mod->init_layout.size + mod->core_layout.size); +#endif print_unload_info(m, mod); /* Informative for users. */ @@ -4721,13 +4783,20 @@ bool is_module_address(unsigned long addr) struct module *__module_address(unsigned long addr) { struct module *mod; + struct mod_tree_root *tree; - if (addr < mod_tree.addr_min || addr > mod_tree.addr_max) + if (addr >= mod_tree.addr_min && addr <= mod_tree.addr_max) + tree = &mod_tree; +#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC + else if (addr >= mod_data_tree.addr_min && addr <= mod_data_tree.addr_max) + tree = &mod_data_tree; +#endif + else return NULL; module_assert_mutex_or_preempt(); - mod = mod_find(addr, &mod_tree); + mod = mod_find(addr, tree); if (mod) { BUG_ON(!within_module(addr, mod)); if (mod->state == MODULE_STATE_UNFORMED) From patchwork Mon Jan 24 09:22:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12721808 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 AF206C433FE for ; Mon, 24 Jan 2022 09:22:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47C986B0095; Mon, 24 Jan 2022 04:22:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42B316B0096; Mon, 24 Jan 2022 04:22:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CD186B0098; Mon, 24 Jan 2022 04:22:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 1EBD86B0095 for ; Mon, 24 Jan 2022 04:22:41 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4997F918C9 for ; Mon, 24 Jan 2022 09:22:40 +0000 (UTC) X-FDA: 79064640480.04.39E92B7 Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120057.outbound.protection.outlook.com [40.107.12.57]) by imf14.hostedemail.com (Postfix) with ESMTP id A0010100025 for ; Mon, 24 Jan 2022 09:22:39 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RZvPCiowM6RklnpLKurfUmRyj/3v/oVq7u15JqkzyNQAYBJvc/ujagae9SmNnHVx18ZsEtu62yztIb/CcreuX+i5a0drjGHtPVsvmAEjPdi8ooT53oVnWuffhu8bH99Wxu/p5+Klu+7SLIUK6yH+eDA6Rgm5eHMlCfv5YNBjbomEa9TlcyecTPiXhe9+u/IgQqtq+55NvsqirWjmtm2+2mCGN2p06cX9M/Nsgvo6GTW2iYZ/6RsqbHzrxv6LN46qAaL6zJs6WgzN/TVWclURYUq45Sv20NjDQ4XT4mZwoEobogJEubxMD1hDTIoqaL+As6aF1oQirSt0XFuQur1Yjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z8ARt3PLVJ2vGaO0xkEt2cByxv0ww6gnOJLBp5FiZNw=; b=B8rxeU2rxmlmqIQBePLr0nE+VqG0OG3YDUqAXY8ACehY06w/s+KHokMPmwehucKKLAgPXcjifrZihtU7pfMSKWOj6hN2FGASA5Uxn7WBrb2VZxRZAopwFEX85dZnECK8q+aXe+uNBnktcxy95t+CJZddmWYHWUvJYjntnVzH515rw6Eut8+7PUxxWzA/hl5Y8jJajiF7AA4x4EbZRJL1jUBI93hMt9YPxkZ1caUTPhBZ5mjHe6b+9acwJut7ThkME17V9RPOPft/IICzIeNVLJrVRrOfVR3maWEMGcCB7JKdBeREdoy02Hh7G5m1qrBDhnhwQcuir9hFbJn+rcSa0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR1P264MB1742.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1b5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Mon, 24 Jan 2022 09:22:38 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 09:22:38 +0000 From: Christophe Leroy To: Luis Chamberlain , Jessica Yu CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kgdb-bugreport@lists.sourceforge.net" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras Subject: [PATCH 7/7] powerpc: Select ARCH_WANTS_MODULES_DATA_IN_VMALLOC on book3s/32 and 8xx Thread-Topic: [PATCH 7/7] powerpc: Select ARCH_WANTS_MODULES_DATA_IN_VMALLOC on book3s/32 and 8xx Thread-Index: AQHYEQPtzPfcZbAkPk+3M/R7ScopBg== Date: Mon, 24 Jan 2022 09:22:38 +0000 Message-ID: References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 951a93e4-71c8-410a-c590-08d9df1b1071 x-ms-traffictypediagnostic: PR1P264MB1742:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1XG+OFX+DNek76q0RmoVN2k5+bFN69HGG8d8edjH52fr+z18S5PgYrUM9aM60HXLYEmmOfopPWqQ672nTKyAI/nDnm1UZt50vPrObfCgOpU7aMI5M11CHsucnBSrqFnhIKMS00oB8dirag129/ij+tyhQ5OU6KS7mSzuCuaqG6rIzxPCPe6H/xmN9q6C24HyOwohzh3qmqw9yIEhuR2e1hNDgSa0jK+1LFvriFofOOuaCkimFCsEfz21FyG3vNEvn3mkJZ5PPxE1HGokSC8dwYN0Q7pty60/zB+S4fXokWap1XCSN2rtU+gvc2kgRy+MkKOIrIRDFtV9GD7nbMlUE/dFx75PLCgV7spaijGkAALTAKdSm1hRBsVckHl4QtUCM+wCHqHR9uJNb+rQ8a4XLxvJsUtRtf6wQ6AvK0zsiK0wx5OuZVqTDW7BAWswJe+UgZokGePImHfvHwdpcs0PRRoVvHANwLKx1jtTk8oh1In3ovZ25EnMkvGhSf4lS7fZF+5uCA3pTFRv7mvZkp6y3Olf6gY4nZm0afEk2prw9BdekiJ2b52P8zBkYC7INeqny+9f8xLGD9pA+iiZfMOscpq/MMj1J6zgWqk8P7/xxVtzbej1o1BpZ7KdO9TxvJ1i4/+b1udq0qSCFNZ7Cg5jd2d83t+CJVryZ/mz6e8Bo8/lxC7lBWSPbqk6P695f1QmtAQZqKvfEHSsWzHQJDmj6GU+vag5uuRyH5rrbkW6sGM= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(66556008)(7416002)(66476007)(91956017)(316002)(6486002)(54906003)(110136005)(6512007)(508600001)(64756008)(2616005)(86362001)(8676002)(186003)(26005)(5660300002)(66446008)(83380400001)(2906002)(76116006)(38100700002)(122000001)(44832011)(71200400001)(38070700005)(6506007)(66946007)(4326008)(36756003)(8936002)(32563001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?szicDs3f8vXOo1JDPRq5MSH?= =?iso-8859-1?q?uh2A2foLMymUFO25+7PHtEc+tp1QpzMgtAelUCuVslqItxXN0v6DwxZeMzVT?= =?iso-8859-1?q?VJ1FLOvf4tqD3k6FX1/+TH3g8QrgbPPxeECRG0+9v/gWmSTwa+jPhaBGAI6l?= =?iso-8859-1?q?96UsDOOaXrFN6NHl6amRC4qPKy7lrPVi9H9gVHjN5bDSzM4xr62fTMC4dMSO?= =?iso-8859-1?q?VvUObKrlpz1DN7rC02SpOz7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4z5pbvhFXm/ZAeS?= =?iso-8859-1?q?o8XFmRcLILrhActohC8uAr1SW9QYzReX9lvlSpgYBMo2E9OADkz5oy9DDkoU?= =?iso-8859-1?q?GmXM0VqQou+KDtEU6iV9hYGX1+dOKOTi1QZq6BIYsXZFFJo4DI6/L62IBV5A?= =?iso-8859-1?q?djWRmgNcNZSwYWS+b6Zutyk51z5h2zNuUd+uCS2xJyKBlpM+CDd4THCZLorH?= =?iso-8859-1?q?Cz+/q+lyO21PBCxnFkQLXkYjpa8STBd37PssBS2dfyvrSx/pqgiwV106zITu?= =?iso-8859-1?q?92LsCv7TDCA3MUHorMkGwKLhbWVRGO8ISRzL/CEF/l8j3SyTQUU6rlSy4JYO?= =?iso-8859-1?q?EZmV/Q6E16m81ZVK5KxPCljuvJi1FHBxc8dF8QcAvln/p0C1WgcNHBghMoHn?= =?iso-8859-1?q?3JyOaSY/f1XylQBYKwThFDizSNgFvNaFm/NyVE5lVKqu1VJVq64QG/52qLz+?= =?iso-8859-1?q?vUjPKzfsGQSU/AH0/JnYEfCXwNJsYPLRsxxy8RBL/ywB921QdRsYxbbe3DFW?= =?iso-8859-1?q?C0/4dbfTBzfTe3WuSixxhysW/kpYLBqMS10dj+H1tMPV9OFdcKS8d/Hpg+Rt?= =?iso-8859-1?q?ZrsGmIKrxTtSte4yxCDNzCMcAKKMqJWnO9BIIebZyxd00m0V7qYVI1hl7E/1?= =?iso-8859-1?q?Uo6o=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 951a93e4-71c8-410a-c590-08d9df1b1071 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2022 09:22:38.2013 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: BC6hWK1UsZeHvMIgQaAMnlrQ9NxGrCRqxd7qYldE3euGCt9xO2uBtTJEjm+ikdtXblt6yFmMVoHGpKB+JEVRjcrKnlU1+dj9W6gD1TH8Uh8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR1P264MB1742 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: A0010100025 X-Stat-Signature: d6hnr7rramq8bypjdicgpz953afzhoba Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.57 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-Rspam-User: nil X-HE-Tag: 1643016159-221344 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: book3s/32 and 8xx have a separate area for allocating modules, defined by MODULES_VADDR / MODULES_END. On book3s/32, it is not possible to protect against execution on a page basis. A full 256M segment is either Exec or NoExec. The module area is in an Exec segment while vmalloc area is in a NoExec segment. In order to protect module data against execution, select ARCH_WANTS_MODULES_DATA_IN_VMALLOC. For the 8xx (and possibly other 32 bits platform in the future), there is no such constraint on Exec/NoExec protection, however there is a critical distance between kernel functions and callers that needs to remain below 32Mbytes in order to avoid costly trampolines. By allocating data outside of module area, we increase the chance for module text to remain within acceptable distance from kernel core text. So select ARCH_WANTS_MODULES_DATA_IN_VMALLOC for 8xx as well. Signed-off-by: Christophe Leroy Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Reported-by: kernel test robot --- arch/powerpc/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 0631c9241af3..0360d6438359 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -161,6 +161,7 @@ config PPC select ARCH_WANT_IPC_PARSE_VERSION select ARCH_WANT_IRQS_OFF_ACTIVATE_MM select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANTS_MODULES_DATA_IN_VMALLOC if PPC_BOOK3S_32 || PPC_8xx select ARCH_WEAK_RELEASE_ACQUIRE select BINFMT_ELF select BUILDTIME_TABLE_SORT