From patchwork Fri Jan 21 08:42:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12719510 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 50DFDC433EF for ; Fri, 21 Jan 2022 08:42:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0A1F6B00A7; Fri, 21 Jan 2022 03:42:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB93D6B00A8; Fri, 21 Jan 2022 03:42:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5A4E6B00A9; Fri, 21 Jan 2022 03:42:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id B65D56B00A7 for ; Fri, 21 Jan 2022 03:42:51 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 827F695272 for ; Fri, 21 Jan 2022 08:42:51 +0000 (UTC) X-FDA: 79053653742.17.91A733D Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120080.outbound.protection.outlook.com [40.107.12.80]) by imf06.hostedemail.com (Postfix) with ESMTP id CD94B180002 for ; Fri, 21 Jan 2022 08:42:50 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bPTj455QNB+EVyVm224htK0Vc2P12e48zgbKtv4PdyeoO0GBzfQoghgjAWMi3+w2gBI6j/mBCwmdTRbWEfSp8Aksmu9rfQjNjD92UijI8Re0MQRFXNhQ+KHav/3k6vsPnW/gACSDSCmx90mKhJl0yFByets0hP1pBMGK3fHg2dhDSdnbvJqsTBi9EhrCnD2/Cx/Q0/h7/D9P/g5dh9UJQrQjtKGyuaCZPksaJ6G2kVXTzNqWQQONn7S/EmU0IRojW7NH7tPr7FT1vGsAO5LbIQMUzyTq4z913OyjIzEMdgbvyy0Q2IQbWSQz7eX5KQb57Pvzs35Djt8noitZ2lSITg== 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=a9SuhqlOy06KBe0gYPpfKhVvBqJHRnDfSe40VkrHRks=; b=JaRA4mK0b4JTJ+RL40l4c0DISgxxmA94q+kSdMszPjb9j05rqTGIBJI3pRH4GztJFv7wWnPUKXTXtJR/3yFXUQRUybBvFSbSqdjRa7d60orM8E3At1q8CXBxhUvcmonulDnOpUY/nT6UWKYib0/Fz5nCEA/hP12Ufz3PXx5blRKIRb/34NaiFq+mmCDZ1rjsSApGYra2tNKna/Bf4INJKrn3A38vVhelY+DSgKT57yymv/FPm7D3PsYWFPPIyy+Ku8j5UkrNwWG2kU+DdTXB0nqDDrM+nEc2+ogH5ZZRtIHS//+1vcVSitLXFfsIIQpHLmMyjkJkuytsyPa2y0iutg== 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 MR2P264MB0196.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Fri, 21 Jan 2022 08:42:48 +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.008; Fri, 21 Jan 2022 08:42:48 +0000 From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "alex@ghiti.fr" CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-mm@kvack.org" , "akpm@linux-foundation.org" , "catalin.marinas@arm.com" , "will@kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: [PATCH v7 14/14] powerpc: Simplify and move arch_randomize_brk() Thread-Topic: [PATCH v7 14/14] powerpc: Simplify and move arch_randomize_brk() Thread-Index: AQHYDqLenb0tMTWDJ02+PYwHQDqHvA== Date: Fri, 21 Jan 2022 08:42:48 +0000 Message-ID: <49dc4982c458867c66f022d11f16ad34e656cd85.1642752946.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: dd402a8c-678b-4878-e2bc-08d9dcba00fe x-ms-traffictypediagnostic: MR2P264MB0196:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: O/9ozK6umGY0tJIszwAYxTiJgjiKCCBynk+LGK8Alwp7mRZqQcpO4thYpJrXS2PbHPzy7WZ8bYon9Hw16Z04wKmlS76/KYhmVpLKyLSf/nKPXCPTOXCXhyTb0iMjXZrPYayai921tbzRBMOzjsT35BWQPlbuYO7gP6wui/xDUUxIymOdYJFX8v06a3N3HefbLKcFNacpwlwrcGRFDpTzoS89bEtY3zT3qUMM43zSUC0cr0cc0/X75aKCi5XI8OTGoqaKSRrfpqh9jABKeWXjXre2E1NULvyKNuVAgGj5eC2fjNss6Ubs/MSCgYT45b8UuNz1NLKIb/aWjcebI5TCyDiQyf3dHnM+JnHtopLjFYIE5FBwelqCE7W/kAxpyGHUWgfDuiRzJoOrp8cxq5TsUb1BJzP0XNlRoJMp1pPuIX0P3wKMj6dHC25Lpuz+5JOSd5y6rOdlwFcu39Rqxlfmw2G+NAwI4i+HA7Bxo1TKKzTS2ROTtx+BoYBhynFpUOPCYUuSmf3/Pt4KyIWs7EfD5Wmoe6KuYXcQan40bN+FpQ7gaIasEl9gh2atD1GtNnbWRYV0mJtKwm9ieJpcausxrdnS971DFBJ3uVZpTFy0McLrkAVevqu8DMby8KYHQLv4oYjsmB2kjA8aCU8oYZpouqiu8++vVfRojNjj+hqlhJaPYg4oDZPeKNca+8y2xU5jXqUYXnDHmqMrpSig5YVlzA== 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)(2616005)(6486002)(186003)(44832011)(26005)(7416002)(6512007)(6506007)(2906002)(8676002)(71200400001)(8936002)(508600001)(86362001)(4326008)(5660300002)(316002)(66446008)(64756008)(66556008)(91956017)(110136005)(54906003)(38070700005)(76116006)(66476007)(122000001)(38100700002)(66946007)(36756003)(83380400001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?r7C3FOW/zL6zHNmBEFUepPu?= =?iso-8859-1?q?mHD4c3g20NOC6K8hWLK+Lw4GbOBOaMOJcowytDzsvEoQgOib2l7vIMYj/XSV?= =?iso-8859-1?q?Y9WE5b/Migd7qnMX4r2plnRW3pdUmnBmHNOyY0m/qigUwdLoW1YeJAx2QIYO?= =?iso-8859-1?q?W5m0spYx2vOrHSDPFED/p1hqoQR2BScPlnrKcWLO/7rugcST/QxpsaLOwXed?= =?iso-8859-1?q?q0H6zsw+UA4JhrOKCUVcymjqmMaG4SK242Ur9KoZWRyglT+sJu8dUE8ZyM5O?= =?iso-8859-1?q?ZyYD7vFFquRKmMj374XaieTxH/CTyaKA4xOLLSvAI7p+PAC8DcTvbdDipxu2?= =?iso-8859-1?q?VJ6twi3mGGQvJuXN9XopQstJg5r/gw8zk2ANKf+LxCVz/9L/lSN3JJ985le4?= =?iso-8859-1?q?HtghPj34XsJXIr7Niws8JEBix8ggNPAyBSXU4z2rRHKLw30z8+CeJYHcjt3U?= =?iso-8859-1?q?c04KzwgFfmaUkU93OfSp5KlWGOP5tHabw2GviGr8AdVwHL82f8dSMQl0NBgY?= =?iso-8859-1?q?gehfSs9xbBuXkBBXeDXtmJKno5t0Zo5H5NmWXI49WIYpkXcQOKnG26nOM7F9?= =?iso-8859-1?q?uzbpGAMEeDkDtSI8eBNZiFL5+r661pUNm8sgrM3D0EAG+BpYVFCqNUdKzD4T?= =?iso-8859-1?q?fzKC/4CPL9FMBwEz0xxsh2OZKH1SHo9uBdoEankWtDqyzyYDLrLiC9bfesO5?= =?iso-8859-1?q?hPlkqvZcft7bb8SKwKjyAeZrB+oBKuds6SMdhFGknATntv5C+zfsfwH7b1Z3?= =?iso-8859-1?q?+qVJQoUBZsRtDLCkZ5JUcqpbnHTvjkysjDOFwu/wqpcbdSqhbrpzZz1pZyd5?= =?iso-8859-1?q?jPV4hXizsnfoOjvBTSirn6dsalUGnoj22/yFTTZmZMd9ONonYlaNuODUD1um?= =?iso-8859-1?q?p+qQ32K8G098kEiNQs2Q1KSVTHkXXgprPC2nMhlLQx9C9cMoIFgSeW1v3A/2?= =?iso-8859-1?q?q5tubp2QaYA1QiftstxYLsXpCGTw5TcJcpZph4qgT+/mXN8aHEiLr8JLyVXr?= =?iso-8859-1?q?3OInZN2s/7+qe85wGOS6i3E7Qo9MMhaptW5S84sy2TaTsNmaNo+HiLL9QBjv?= =?iso-8859-1?q?fc87IzR2B076LdVVXeFPmKOsaANQfyQvNhUYkOYHYMF0X8DuXkfMMnhi8bjT?= =?iso-8859-1?q?5AfoWehs8fZ0dKW5Mq09IjkJ5QpZP90bj7TdkqxV2r2dAYxmPPdesDgoVkpp?= =?iso-8859-1?q?V2QMRNbfHOIYBX+Fu+jWk+HReSszDLcZFHZbd7G8+4a9tEcEax5VxJdYHUau?= =?iso-8859-1?q?gghbABAjGpRCN1skYNHGQ0UnaJCEhStOCnbY+yO2AUiXP7h9k78NqOaH4pHh?= =?iso-8859-1?q?T5SVLAK43Db6JkMEvEzmnRTTF9doujXLEAWTNP5HOeziMcqtWhaOk4+ocy8O?= =?iso-8859-1?q?fh4b1VbRbpdFB+zbag/zIGGp4jD7jZQH1NvW94ktRscYjJMEfimzeHPZS6aZ?= =?iso-8859-1?q?OshKxEMJh7Y7wMVJhqwX1phf5hMLb9a1/7ynezPeeWJjDtSvtfJFzvcdvyCU?= =?iso-8859-1?q?4f65Gepa/iQqh1DuexkBrGIfz5kO5Osd38+1G7QWGfnrEaNiCbbwOpzGS0c8?= =?iso-8859-1?q?dWvFxcmBy46Vxb42X9frvviGXXEYS9oZedlyXfAarn9NTeAx/d01zu/82uAs?= =?iso-8859-1?q?mzv6aTsqA++G7JA9qjPIolM4W85Wb55els/unj3igh9vYp/odAtxZLghB2yp?= =?iso-8859-1?q?i2ZbsZa3dCOlMP5rMf8xfpU1M7fQGsEMnnL7vivcniJ0KaElhWDhRPzmeF0H?= =?iso-8859-1?q?FSdY=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: dd402a8c-678b-4878-e2bc-08d9dcba00fe X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jan 2022 08:42:48.8055 (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: KdQOI9rbEU1DV/T6+acUVGQZdYJarLJnno5XF4Nh6zIe3ir42Do9dVTOoQVIgmr9JE7BkH5VKAYQzZ0eAyl4msu/TG8791Q0vbVXf6uwn5U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MR2P264MB0196 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: CD94B180002 X-Stat-Signature: ybo8shdrajg3mw8aprga94r6nc59mt8e Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf06.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.80 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1642754570-876187 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: arch_randomize_brk() is only needed for hash on book3s/64, for other platforms the one provided by the default mmap layout is good enough. Move it to hash_utils.c and use randomize_page() like the generic one. And properly opt out the radix case instead of making an assumption on mmu_highuser_ssize. Also change to a 32M range like most other architectures instead of 8M. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/process.c | 41 --------------------------- arch/powerpc/mm/book3s64/hash_utils.c | 19 +++++++++++++ 2 files changed, 19 insertions(+), 41 deletions(-) diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 984813a4d5dc..e7f809bdd433 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -34,10 +34,8 @@ #include #include #include -#include #include #include -#include #include #include @@ -2313,42 +2311,3 @@ unsigned long arch_align_stack(unsigned long sp) sp -= get_random_int() & ~PAGE_MASK; return sp & ~0xf; } - -static inline unsigned long brk_rnd(void) -{ - unsigned long rnd = 0; - - /* 8MB for 32bit, 1GB for 64bit */ - if (is_32bit_task()) - rnd = (get_random_long() % (1UL<<(23-PAGE_SHIFT))); - else - rnd = (get_random_long() % (1UL<<(30-PAGE_SHIFT))); - - return rnd << PAGE_SHIFT; -} - -unsigned long arch_randomize_brk(struct mm_struct *mm) -{ - unsigned long base = mm->brk; - unsigned long ret; - -#ifdef CONFIG_PPC_BOOK3S_64 - /* - * If we are using 1TB segments and we are allowed to randomise - * the heap, we can put it above 1TB so it is backed by a 1TB - * segment. Otherwise the heap will be in the bottom 1TB - * which always uses 256MB segments and this may result in a - * performance penalty. - */ - if (!radix_enabled() && !is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T)) - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T); -#endif - - ret = PAGE_ALIGN(base + brk_rnd()); - - if (ret < mm->brk) - return mm->brk; - - return ret; -} - diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index 154a5a860959..d28003132a51 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include #include @@ -2171,3 +2173,20 @@ void __init print_system_hash_info(void) if (htab_hash_mask) pr_info("htab_hash_mask = 0x%lx\n", htab_hash_mask); } + +unsigned long arch_randomize_brk(struct mm_struct *mm) +{ + /* + * If we are using 1TB segments and we are allowed to randomise + * the heap, we can put it above 1TB so it is backed by a 1TB + * segment. Otherwise the heap will be in the bottom 1TB + * which always uses 256MB segments and this may result in a + * performance penalty. + */ + if (is_32bit_task()) + return randomize_page(mm->brk, SZ_32M); + else if (!radix_enabled() && mmu_highuser_ssize == MMU_SEGSIZE_1T) + return randomize_page(max_t(unsigned long, mm->brk, SZ_1T), SZ_1G); + else + return randomize_page(mm->brk, SZ_1G); +}