From patchwork Fri Dec 17 10:28:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12684227 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 08057C433EF for ; Fri, 17 Dec 2021 10:35:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 800836B0088; Fri, 17 Dec 2021 05:28:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 761396B0089; Fri, 17 Dec 2021 05:28:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58D8B6B008A; Fri, 17 Dec 2021 05:28:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0042.hostedemail.com [216.40.44.42]) by kanga.kvack.org (Postfix) with ESMTP id 466286B0088 for ; Fri, 17 Dec 2021 05:28:35 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0292E8908A for ; Fri, 17 Dec 2021 10:28:25 +0000 (UTC) X-FDA: 78926911770.31.70F0A97 Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120077.outbound.protection.outlook.com [40.107.12.77]) by imf14.hostedemail.com (Postfix) with ESMTP id 2A6FD100010 for ; Fri, 17 Dec 2021 10:28:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C+3N/LfyhqJU6PpPVS6vXk44k6zr+dcan+r4pGDooZMzBiWk1oOj9BkQNpJjpsxxTf3cTXSfAxGYS1qpnEOCUFNQ9LvdX2g4JmgcuA7XvnzgnlHtREe8a0X57yyAnCTaGZb7dzOhehZQwYy4Ch0kn88RYpDKmqdSGtcXM91lSFl8m9MPzL0rnqbvBksEfWlNriM279ojZsMZ4qsiOc91HHRWgV2o5aWWIg2ub0B4C4orU7h2cbCDY4UXNclyePA4aZRED5QDQKH5v8A1c9AGO3lIE+aH84oUnUPI+29el5EscIBGnLzhsXXjGENeYsfnzqt1X/SucFfK9HSGS4jBtQ== 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=7GCE25qRm2CGxDvHUrHXVel7PPUjK1mixNc0dChnkIs=; b=l3Vfvv4ifluULQPW8L1DQhRBQhsAybsmqdIuj9Zf8gyFa1t5udIvX3AtCsJOsOqyDTPBap4w+Fp8NhYWIDFo0rgkYz8hb+QRhls2x+GfuJVJPjY9XtiiWxG34DPWGemRe8lebSOahs7dzxYBhO3mlii5DIVGBYuBxUKhge0ZTRri0LzLL+PGrkxz7bhEjwlbjOsjHSJmORtBav4yuWRrz+T6ZKZLWmC6G1W3nUtrDTchQNz8VZUgGQqxzOF9kgdiPNyfdQFf4vSmxOj2x/yUjI4JXl9BCZHwP601mVWKzbm7uAkv/7U44pmYqdDaeBEeY4/CepYRPYRenppIc7IJrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=csgroup.eu; dmarc=pass action=none header.from=csgroup.eu; dkim=pass header.d=csgroup.eu; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by MR2P264MB0146.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.14; Fri, 17 Dec 2021 10:28:22 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::f0ef:856d:b0de:e85d]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::f0ef:856d:b0de:e85d%5]) with mapi id 15.20.4801.016; Fri, 17 Dec 2021 10:28:22 +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 v6 14/14] powerpc: Simplify and move arch_randomize_brk() Thread-Topic: [PATCH v6 14/14] powerpc: Simplify and move arch_randomize_brk() Thread-Index: AQHX8zDRiLqEcN60akW2b/fzMqW42Q== Date: Fri, 17 Dec 2021 10:28:22 +0000 Message-ID: <9ccc69fa94297835dde68b30759be7280333c8b8.1639736449.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: 0267c4cb-a780-428d-1fc4-08d9c147f3a5 x-ms-traffictypediagnostic: MR2P264MB0146: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: zSiIrs0adWpAvkdtXDhQHJarAfcVImcnWBb2+znDoEwTEHhFQtLGgO9OP966kcU2IxvspRpYFqpPtNkpX8jOE33HoqioMipVxFVVPJ2ckw62KVOwLTsunjsVaJFcQt3N98uOSr8Pfa9ZSsXT/ibN3gEubwX3LCW7SB9BNwbzuwCXUS5ssatjBEe55NdGyhyokHfkb0Mfk/Ox6gP0pthYgi7ZoRsWQIRkLPWTmLNzKF7R0Muq2uSWrDvKg4mcvvNZlIaovAbjMJsIZNz2xnen4LtxHObmWawthLAgMgjTMGzmz4k8GgwLw29xOVCBbtHgM5EKXg5PfKCZkmFIHAlvc4+MDZnWAAb9WQO5sz3gByJwfDgnEsbUc6UTpm5ykZI4HDeimmXg32+BkxpaH17VB511Ikp4jzxFLNepRXasJ2B/mAyGsQa9X1+c2/MTU4GicSPb8kjen0ymFQ9LVV6nFrbAoarff9zNy5L7iOyKzgv7Ev+wz+PgRQiE771C//yGk3+nHUcBSr4Ery0UMpdIksdo8+RBBYv45hJZQbNkk1YI/uZfwv2yRJoq3blGhVbyC3YbPr45jP1EfttdbFoXcpvHVmCbZwyynRBTmWglokVVSFJj8sL5d4DG6ilfExxY+yweanatKI1gZJQzoP+o9WsDwPhvFwKVrEypNXWqD7mU6TtRNUp2FzZH+ghxnjfpBe54ijLIymn+0soe2/rs5Q== 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)(186003)(91956017)(71200400001)(86362001)(83380400001)(66476007)(66556008)(66446008)(2906002)(64756008)(38070700005)(7416002)(44832011)(6506007)(76116006)(4326008)(36756003)(26005)(2616005)(5660300002)(122000001)(8936002)(38100700002)(508600001)(6486002)(54906003)(110136005)(66946007)(8676002)(316002)(6512007);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?CNCfu/O+ewrU+mOLOSA/Eh1?= =?iso-8859-1?q?QYu9DwABvzZRPWxuDOzHy2Ur4IoPxiKxJZXslRyHg7s/mT1gGwjoFps3y5uC?= =?iso-8859-1?q?FxE1iWmUTfJjDFkAWVRDw90DbkWHCVAFetvMs+qCsIUPhrvTxN9pNeDD4V0W?= =?iso-8859-1?q?wnPtXOTrBFF6+4FIuvAKOQiTO+iHoJ8mt9RbJMOaNzxubaTbdGx/fdFkBgqA?= =?iso-8859-1?q?0Ah2YBt+n7xxNHNFqg+lO+74bvtgLH6VeXpqtkgXtoF96TXtQdH8jsSJFaqW?= =?iso-8859-1?q?zUIDYd28BnpXTJ7oj+dYJZ+B3R9JHKWxO9hUgjhCcqE+tgZ20sq6rJlYYncl?= =?iso-8859-1?q?IzwrJzPOsyByptoQ5qWlFmWrszDJYC5vEk7rXdGblyHAjQFiLQIzd+W+tmWS?= =?iso-8859-1?q?9BhS3QR61vgHuRFjMhkD/ed0AvizCVU8/lRp4SuTmBLF8yEBkzL2wreyU/Uz?= =?iso-8859-1?q?CZ5TVcNKtngk2ebdGEUB8/dHPtHniMO261sxB/py5nZD3daev4aLkYAhs7w7?= =?iso-8859-1?q?8faPzFb7R2Gr0p1G7IjkRp17J6ygz3nhsp4hNQM+3TtP4uecmxiYbvDhoiry?= =?iso-8859-1?q?4NL565t+h/Kxn/61UVp0gCrTXCUJwRu47mRasZVrdsoO3PGaWWrVwPcuF4+E?= =?iso-8859-1?q?APTi/CgpX0SwX+BKXfJleotVOiC6O/awU2F8n//ojSH7X99XIW18XVmgaIQX?= =?iso-8859-1?q?2ElcK7LmSJW1W0pxer6aLPyXgcdcH6/N7Ixr+LLXa31jZKvNaHzYO4jQLQWP?= =?iso-8859-1?q?jBsuTTiCTu3G87h69ujBI3YBF6T1WYz8punmI9p9SnYlGlUq9vbfKTOdlSTY?= =?iso-8859-1?q?KDdwdj4eDF4LqdW5aDDKHCmgVOWwxz3OjgnHZJhQNmDbAenbyUIFhuHK3Rf9?= =?iso-8859-1?q?v6QYJVxOENUH7XeuHtOqrt7kpPRqnTdz3NK+9U4BNthMzQntpXOKfwWPt77k?= =?iso-8859-1?q?wZrL+2Tr+4aGOviUHlc18H35M+e5SQ8F/H6aCb9EfNwZcHS9h60d5lHX9hd6?= =?iso-8859-1?q?LqIteOIOrvZHogL8EtvY2zz1ajnHOR1UwQvQcADgws4R5xgsrymHSBOlSI11?= =?iso-8859-1?q?/1fRSkhFlNule0tnOoow8iV7XtMizO/TTxo3Yfpf/RQMcmisR3vQu6sk9Qxw?= =?iso-8859-1?q?0Uks0fOmtqb3I3aZN3F6xaCq2A+aqD/2O7Ecxg8ZVT+GrKDJbxp/V/WDBYb9?= =?iso-8859-1?q?bPE0AE0sDBZELTs82+ZOfTRbabdEf6D7fkAtOMwIRft3RAiwj/l6Abwvghls?= =?iso-8859-1?q?0c4iyZ2Bs2Oz8epzQtPDbtSdEmzKH/PNEjS/Cv0NgGIUjptLhF4E+0P/VthP?= =?iso-8859-1?q?TW1zOk62HwUUyz4qTS1yAc+n+eZsmYMMUzYKpc5udgdFCt0tNOssw6x9ft6F?= =?iso-8859-1?q?D9h+XZ9PEkFul0t3tbdiS+ZRi+H+ncG7dkxP+JOO2DhQ0A+0HDhKQd5OmLpC?= =?iso-8859-1?q?tPtwb3TNTJY3fM0oi1fzxjds4OTAu+1nGntptvDKkp/mLdWcojUFDfavKH1m?= =?iso-8859-1?q?fPpwqoAruGw1ssEYPM79zu/8IWPm9OH0+YTT6sgiecMuffdq9j6HyrkbqFr5?= =?iso-8859-1?q?UJ6wpRoHrKMscbyjO0F3zWWBOUN2/DFNciyiTjIywMgOXMlZw203zN1ni0Rj?= =?iso-8859-1?q?kIRZRlFbb8pxPYI2ZdRwTgSF410vW9r59wK0lJGReLbl1kcxTTqKaaanteT0?= =?iso-8859-1?q?yVgF//3BVemzGj/+KmnPb5yGTlB+1u0VAsbJ3ttL/R2pDf/MEa5oMXWrb6xk?= =?iso-8859-1?q?OuBI=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: 0267c4cb-a780-428d-1fc4-08d9c147f3a5 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Dec 2021 10:28:22.3690 (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: reEgNqq1CcknQMMtvcfORQNBZA7fKEm3+PAlFdRVVFlgdk1lumeUtlSvehS2gceHqlaAty5nyP7fhhTBZaNSBMT/4FQv/T+KnxfLi+FDrFQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MR2P264MB0146 X-Rspamd-Queue-Id: 2A6FD100010 X-Stat-Signature: sgxdh7u3365fnuays4g3rz4krfge3zdb Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.77 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-Rspamd-Server: rspam02 X-HE-Tag: 1639736903-819283 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 7ecadf5e6bf9..68a5468b0f19 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); +}