From patchwork Wed Dec 8 17:18:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12664923 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 BC877C433EF for ; Wed, 8 Dec 2021 17:23:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21D7B6B0081; Wed, 8 Dec 2021 12:18:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CC396B0082; Wed, 8 Dec 2021 12:18:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01F426B0083; Wed, 8 Dec 2021 12:18:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id E39E76B0081 for ; Wed, 8 Dec 2021 12:18:37 -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 26F2F88CD3 for ; Wed, 8 Dec 2021 17:18:27 +0000 (UTC) X-FDA: 78895285854.17.4E6AFDF Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120085.outbound.protection.outlook.com [40.107.12.85]) by imf01.hostedemail.com (Postfix) with ESMTP id 8A1BC40002 for ; Wed, 8 Dec 2021 17:18:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eiZE8ftOBXxsSnxDh+qS2PcHhjoXQopdzZnblcNLb9uKi5sQtvMffCsXmRUMSg/hTM3fKRrEQutm9HPZWc5xpBOHpbeiwxT2tY37qOs+C57S59xsSHr1NmrCzX/pM1k0zExlxhzRh8iCFG2ZYTroGOR2/WhwNgRjxXEBhs2BPtLTxUGSWpi7XD56AP+RH8AcTGqHzGCKWoS3BgwAyNskNhYsah7EdXhzmvZmyPVRtC/Dm7SshOIAp9fczUqc2VX/iWJR00rAzVRk9t1TQSYsCaoHt1RfyowNcYpA3nN7ypO0xKYFSzuvFHi5PxA4GulsbcJQZtSnzzGUUEd3HfyF0w== 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=mwyareCaN3ZlSh2+BwwdNQ1qMDia3Q7S45Cfyrw+tSI=; b=YF1ow86oKAgDqt+Jgs/jZ5/KaiB7AMFEyMPMQpsHLdwcwQzYx/fxL4LCfkI2xsljcEiagserEGjd+vSAaBVadFD1ERVDjrZnhxYq8s04D6dZjXCEG7xgywzMFXo5s9TIH0Y3y1wbHTsbO8WqxFyF8PuUSHsB0vpFfvlsC3cZTQnb2w2+VZMt1VqxRpDtnmmSYVZL0qDtJ83NcUMF/I2OTfMEAz/NlLAAJOHt3f6UCddMln4kcQwxt0Gret7akPFlCs7M0HSPjjVtLohafVAXMd/MUFlhNr7fIbd5PCmT2U4EndlMS9sMMOjEuRyut76Ee/DPD4vAaH6ucmM48+Gdzw== 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 MRXP264MB0823.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:16::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Wed, 8 Dec 2021 17:18:23 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::fc67:d895:7965:663f]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::fc67:d895:7965:663f%2]) with mapi id 15.20.4755.022; Wed, 8 Dec 2021 17:18:23 +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" Subject: [PATCH v4 10/10] powerpc/mm: Properly randomise mmap with slices Thread-Topic: [PATCH v4 10/10] powerpc/mm: Properly randomise mmap with slices Thread-Index: AQHX7Fea0peO1pudxEe4GqD87shvlw== Date: Wed, 8 Dec 2021 17:18:23 +0000 Message-ID: <4249d95311ec93b0a9d421ca56d69612fb1e5811.1638976229.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: 25e52a4a-c6a3-4185-e955-08d9ba6ebd39 x-ms-traffictypediagnostic: MRXP264MB0823:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lzZX7QebEXDdh9sbFiSLsMtViHHRZyuzmmraxPn14LX7E5/nwrCbd8mJ8PGk9p87L1P99dGLnZ1ksPCzqXSp/6Be2576RjnuQibka4fkV4FNFcSDbB0MU4PRj0hBGmMM2FpoUaytnYqjB7kRljJ3KOaZ5FeFgWSvfV6v7VJ6fG20QGVBziPgtKcyjQNR8JC8lf+eoolBiVmLoAZGTYYsoILhjLU3XifBKKBXxmtsR0qmgV+ta5A9rG2IL8Xqa2BQthbgQgsn1OZwNUGiMHCkmfSZlp0ExRS4mYn7A20ve+yRlS8WV5B9S3i+l4OsQzG/RE4WsBqP43afoNdG3Yt8ZiZfYsCkMNNyEG1dFSbAZxKJVjzmtjNY3S8CgCPcp4Tgc0M/kyOYUV8tugI+oulVfaIOoccdSPn+v3+u7QzLEr2m/3spFDopAak6/fp69Xl638KjlVaIpbPROfDKhsotoJHgLrzUR9M37jfkkp4GG7jYmhtr54Xuc6gqUagCNnQ7iYdc3uDq+amjJtPLHfw0D0nDgtgOA6yORm/imzYePiW64zxnq2EQFQY9JarGBQlRyIumujirAuc0TYVeFvYp8N2m0K0hUhiSUP5FYEI033fMWZPduY3R9WsnKRatTl4SrvvLCp2EEx4olQaI9/N3WTRuahDVn65tKl9WSD09gcuwwbLX7UYchkAEpr1Bv+kkvxK8F8ywmWzXKWp+KG1XvA== 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)(4326008)(316002)(83380400001)(6486002)(2906002)(36756003)(26005)(110136005)(64756008)(91956017)(66946007)(8676002)(54906003)(86362001)(44832011)(76116006)(6506007)(66476007)(66556008)(6512007)(5660300002)(508600001)(38100700002)(2616005)(66446008)(71200400001)(122000001)(186003)(8936002)(38070700005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?j56JBr4ekIZvDjBGiD8vnEL?= =?iso-8859-1?q?wDxOgQ8KAn43eVuzSzeimAxdDIaiMWHiVSmTWXs6kvr5Hp851I7ff8wq7Guu?= =?iso-8859-1?q?+H99+yTPOzv+iW3WqpZb89tpnaEyGexpwru+9sm1k0bR00qCpRx8IeQwk+nz?= =?iso-8859-1?q?4gXI3NbHhOHQe3YPGbnoihmiD/ml2fYiTsWmQCDYeuFCFvhffTxtP2tYbKq4?= =?iso-8859-1?q?PfaM3c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9jhALtmnn1b9GZhJYnWWwwqitHD?= =?iso-8859-1?q?frFlpALfVfGpAMkRdT8E8uXRUyKO8Ioa21YoVPgypzvQbJzwIYj7YWxAo6yT?= =?iso-8859-1?q?wNh9SP8HwZ7GGKgG+YvkwCxoUQCXJGUuiSTfTKxBwRWRGOfsYxBuJKYXOK0U?= =?iso-8859-1?q?zQTCcv0+1z5zMjTixq02GtFn0SE0QtqbIxZU/tGnAgpYzNp43zYR3lnhdMyF?= =?iso-8859-1?q?YuWW5G1dXal2mVzfn7k4HC1z+svwDgEMgn+lV2Uv4yWoXiWJ2Y5iZ9OeeXOf?= =?iso-8859-1?q?wR/JNe41cn2qsrKhvb90A3ddEsorjILCwde+6RmG75XyPYmk5VE2aPcDYrC2?= =?iso-8859-1?q?LHrZ2N1o1Y3WlcCoDe96S20CT1Ctk0FmEkRDEct38bZKqFVY3zDzaiZMZ5Mi?= =?iso-8859-1?q?Xmkp8Yy0hhwPHR/MlnJlFy1pNacyJhyQY6/7hKaIRDy6KLi3HG7DMaUm5wUe?= =?iso-8859-1?q?AsR6jLv9YdZkT9nJ+3m9KC3SgrhydJqECDwdQINyGv4Q7h1k3eCgnafZXgQx?= =?iso-8859-1?q?1Pc2PRFFk+lXZ2YI6OezH962Xgt73VK2dAL6en5QvOnqfjE7NFufxOnIqxZu?= =?iso-8859-1?q?T18sB2PA6dSepiWEohAgdSBY8DmILTSrGiTjkdOx898TQ5/OguTnrDdq2Q2d?= =?iso-8859-1?q?ZSOs=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: 25e52a4a-c6a3-4185-e955-08d9ba6ebd39 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Dec 2021 17:18:23.3045 (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: xrmZbvib/nPauh6MNCf5h/i6IV6TryjEpzQV2pNldufeprO/+fb686MLlSvw6xDNNo/artxugnM6xp+jzPsFcTgf9xzkcnDNbHZ+BKkLUis= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MRXP264MB0823 X-Stat-Signature: e5k6dmti6wzyeu7pqip6t3s44rodbckn Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf01.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.85 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 8A1BC40002 X-HE-Tag: 1638983906-888131 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: Now that powerpc switched to default topdown mmap layout, mm->mmap_base is properly randomised. However slice_find_area_bottomup() doesn't use mm->mmap_base but uses the fixed TASK_UNMAPPED_BASE instead. slice_find_area_bottomup() being used as a fallback to slice_find_area_topdown(), it can't use mm->mmap_base directly. Instead of always using TASK_UNMAPPED_BASE as base address, leave it to the caller. When called from slice_find_area_topdown() TASK_UNMAPPED_BASE is used. Otherwise mm->mmap_base is used. Signed-off-by: Christophe Leroy --- arch/powerpc/mm/book3s64/slice.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index 03681042b807..c0b58afb9a47 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -276,20 +276,18 @@ static bool slice_scan_available(unsigned long addr, } static unsigned long slice_find_area_bottomup(struct mm_struct *mm, - unsigned long len, + unsigned long addr, unsigned long len, const struct slice_mask *available, int psize, unsigned long high_limit) { int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); - unsigned long addr, found, next_end; + unsigned long found, next_end; struct vm_unmapped_area_info info; info.flags = 0; info.length = len; info.align_mask = PAGE_MASK & ((1ul << pshift) - 1); info.align_offset = 0; - - addr = TASK_UNMAPPED_BASE; /* * Check till the allow max value for this mmap request */ @@ -322,12 +320,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm, } static unsigned long slice_find_area_topdown(struct mm_struct *mm, - unsigned long len, + unsigned long addr, unsigned long len, const struct slice_mask *available, int psize, unsigned long high_limit) { int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); - unsigned long addr, found, prev; + unsigned long found, prev; struct vm_unmapped_area_info info; unsigned long min_addr = max(PAGE_SIZE, mmap_min_addr); @@ -335,8 +333,6 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, info.length = len; info.align_mask = PAGE_MASK & ((1ul << pshift) - 1); info.align_offset = 0; - - addr = mm->mmap_base; /* * If we are trying to allocate above DEFAULT_MAP_WINDOW * Add the different to the mmap_base. @@ -377,7 +373,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, * can happen with large stack limits and large mmap() * allocations. */ - return slice_find_area_bottomup(mm, len, available, psize, high_limit); + return slice_find_area_bottomup(mm, TASK_UNMAPPED_BASE, len, available, psize, high_limit); } @@ -386,9 +382,9 @@ static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len, int topdown, unsigned long high_limit) { if (topdown) - return slice_find_area_topdown(mm, len, mask, psize, high_limit); + return slice_find_area_topdown(mm, mm->mmap_base, len, mask, psize, high_limit); else - return slice_find_area_bottomup(mm, len, mask, psize, high_limit); + return slice_find_area_bottomup(mm, mm->mmap_base, len, mask, psize, high_limit); } static inline void slice_copy_mask(struct slice_mask *dst,