From patchwork Fri Dec 17 10:27:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12684217 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 6CE4AC433F5 for ; Fri, 17 Dec 2021 10:32:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA5C46B0081; Fri, 17 Dec 2021 05:28:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D7C056B0082; Fri, 17 Dec 2021 05:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1DE76B0083; Fri, 17 Dec 2021 05:28:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id B45526B0081 for ; Fri, 17 Dec 2021 05:28:07 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 759ED89078 for ; Fri, 17 Dec 2021 10:27:57 +0000 (UTC) X-FDA: 78926910594.06.9437A84 Received: from FRA01-MR2-obe.outbound.protection.outlook.com (mail-eopbgr90054.outbound.protection.outlook.com [40.107.9.54]) by imf11.hostedemail.com (Postfix) with ESMTP id DF12340017 for ; Fri, 17 Dec 2021 10:27:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XvJ0eHgsX3LejI2BRmnYXYO3+496znch4BFMYqqKCf+RGGxUfh0UT0XBaKwUTPGIz1/HisoEdZ15bF7IbjnWCceqhwzpmgVeDS05GruQaCwnhhkTlFvvwo07Ch7IQpTLkxuCi36ekUrGd46ttKhP2Ub3gDNTklLcKLyu/deKlQoQUbHxVXpt1j6CYYObHQPXebVQd8LuK1BKEIo8sRxGKkTqTDGrPPRlxxXyD7VHFtaIoNp1aigZuolui2mJwhtHnaptr2glbdykbRa46/w8VHytKOb2Ywi3nDsUJaqN785+iPPu2zA6VHdei1z2XL1evLjFnvG4UE1UjYE7rJDd+w== 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=1/H5LlacuEM5f+URl9CL6CXXwKhBdc5iypoM/HPJGE8=; b=PY2XRcP2KwdniQDEpz56RQ52VEJzwBBe8enfKj3R9y9dGw5hVrbfI1+HNKNCndJIInYe71KznHQpX35qR6HdHO/OQX6jpioKQCuA0qbJycWe1OaE8opQqB/8eXpqIgSdqI/5xM5viCYVkXCwdwF9mJqmNuHr3xf7HphWeKRr4K9B1QVC3UuBEbg4szjDuNyEnsri1mOk9Xc06j2VtIxiI9LA0dXU4NoUzDOWrlA0036p1GMSNpRDkS4uL76xNVCxWPjeJfpzO4pjIvlqBO2aPD8n6rpjaoQcCEG3vS4a68LOYdEtColsI8Rb8pfoeoN8kaMGL5sMca/x4vyM5NuStg== 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 MR2P264MB0194.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:b::16) 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:27:55 +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:27:55 +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 09/14] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Thread-Topic: [PATCH v6 09/14] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Thread-Index: AQHX8zDA7wQ3g07WgkWIeuZ4wqz97A== Date: Fri, 17 Dec 2021 10:27:55 +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: cca97c2f-3997-4bad-4b71-08d9c147e365 x-ms-traffictypediagnostic: MR2P264MB0194: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: NeCtnT0CGOj3qAuqQHSmbiKSzOpq/jT+H/dPbc9W9UYTbSMc4u1WL949WfcXR87I9crDwNSuiSe1wQLxEKzZ6zPVg3Wl6SUA7zQ0dtRtI0F/Ac01LdLZP84w+bkPGmn4sDylB3IUn49OHuveZDV8yLIx8ljOc3U64e4BnOxmGIAZ090u8q7wZH+d2wP/NHE7ptcA9lqwttnfEAYpshxcxzGcruYMmNC9bCVVF5+2DWnETdbFKmx6eBiNSiJYxVLJH6OTRj+syrnSwbybKG4rbFqlLWYOszKA3ga3rwSd4H2jSMcTyypHiAByoZiQCCOwyVE3R/1rHGTdZZVyMg0HNGc7ImfTFq3F8mRZPRusHvYFBX0t1aVsRcl3Wam5WB6JeYSRzOUNrfDmyh7yRuKiG/Dwz8NOaj+ThUZ0hVv3ShAKIaf12PoPyMSu1VvCKGpulz2dytvILDWSYFYHcfPmzWme+hpP92jfnTTwPShi4l3xOFcS7rrrQCR0cK4B5XjTvjmhfX4cRzPnAlXNWPCLKH+Ny2OseCcgXfx89stpDEjv/nzF2G9DbCZzjj9cG0Pi7AA4wMD1ogmoKvEVP69WuGPVnBwSbu98d1/97n1mOdOrN/+onKQaFIDceRMibctmAvIyX4yYR09JXedBdVuInwsuz1NHDaMCvhEEKLNnYWIl4RWuZ0zxyGyXSirUCGKbiZyRnw87vB93IUizSPUM8Rjy4aJvIuMvEWZ1KuYQcwA= 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)(122000001)(2906002)(66476007)(66556008)(7416002)(36756003)(316002)(38100700002)(186003)(44832011)(6506007)(66946007)(91956017)(6486002)(26005)(508600001)(4326008)(76116006)(2616005)(8676002)(8936002)(66446008)(71200400001)(83380400001)(110136005)(64756008)(38070700005)(6512007)(54906003)(5660300002)(86362001)(41533002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?vE/VB+s/cuHaVigQjZGUIjB?= =?iso-8859-1?q?LRSC4GK9p54HVKHaVv09PK8XIHzzH6JJVGaWevFFdt4ln5rQlTU8+IuijXKl?= =?iso-8859-1?q?GqUQ9JNrzP7TxQr7M3g5KASSgr9syklfopoaFKbLn2MZESlB0yXi8bOJmd7k?= =?iso-8859-1?q?hKEENHUjfmdy3RxDysk3l3UDRnK7DhCfptzoO+aSHTn8kIeqoGnNfdacxKGR?= =?iso-8859-1?q?19IKgJpXcHPjH0/u6Mb1v/pDbtTBHHtvthv7PN2RtbQMEB3e23eFGAqEgJCa?= =?iso-8859-1?q?mAbJH9a1b2Qia977uSSjh44c8OBVosujEnbuhfF6ot3xrJwmciZpr2f7mETP?= =?iso-8859-1?q?m+GslT4Byaq334pVo6qYolldX8Z7MCMfwlO6RQWk/xutsHiI29iLZr5Nu3ng?= =?iso-8859-1?q?DT9awR1PN9S/dyS668tjoSPKJD2ERI8t15R88oyPlsi8JxQT+QWMl3pwLUoX?= =?iso-8859-1?q?oBUIm9Bau0NsgpQecWWid9auUj+SJjqkW1La2LUX7aROkmcnDHWVNwq6RkhX?= =?iso-8859-1?q?XdjH/g92sZgT3Yc2VvExABIctioOzqL+lg0U8and1pULn7cgPtoO9yxX3QBQ?= =?iso-8859-1?q?SVQndfejU8p7NB+g95xkgEQnPw0ya0Caiau2N66Ce0qLe5qCAMwxE8IaWbrt?= =?iso-8859-1?q?Zfl8gqi0ttlfgu5VLLvYucEjujxr+WZSZ/+BCp1dSqcFtv5wsafji86fsX82?= =?iso-8859-1?q?AvGURxPn/0BxSvJVcEO0zjpqk9jvFILIEslT5MwW+ykLjA77TCeAv0ChjllK?= =?iso-8859-1?q?UzYjYjio7nCG7FgqX7T5undAiScS0tOCVvC/h9yy9a5RXPtjjhp5r+KYgbn5?= =?iso-8859-1?q?nRsb8NCqBx4fbjqOkDTgKwnKekR84QzeOxVrDr1VH3LHll2bxGapE+3R7+WD?= =?iso-8859-1?q?Z0QRpRRCC1EurzP7tBS0ud5WcRjF7rd9uh+0c+cL/18NwlxGlsNlN5qyms3m?= =?iso-8859-1?q?Hf/zC59q/baLpfztrnfdpUL4bxxpfQj4mIMhF6Ap0b/Nh2KdIeax9o7b7Yrd?= =?iso-8859-1?q?1sS+qGM19ks0Nnffoj22mlvw/OSUyj4GjcLNt6LoRfQxdsRuytUm2AfWmYU4?= =?iso-8859-1?q?xjb1NQPKhMiyGB97sZglukd7DR60zy0wBj4fZZvLK+I13cZ7pCmwKSygdEKt?= =?iso-8859-1?q?0vTKmQxxLbc33x2LCHWvSVdf2GvlkPjRUFu8m2rgkzVq4JgO4ozOhRIfg3m8?= =?iso-8859-1?q?1RiFB9f3XqYZMZXQzmytF7H2AH1ZwnyBBF6mgfA6uzWrCsKeg347D9YpGD6Z?= =?iso-8859-1?q?METlMlgbEQ42D8AphOKQXC7ellMXKqTe2m3BDmX23O19SIL0CTqq3U/xNUA4?= =?iso-8859-1?q?45YrQMDpn3oIfMKDWXlzHnY7nUrrURT2/Z7JPA1qEIFrpLBoSadGG5U8VAJv?= =?iso-8859-1?q?FHH18vdewpAOZAaQvlkyLTVFzjHE7XBh66OWKJe3VzeOrF9HOTSjPyJQWm0g?= =?iso-8859-1?q?9h8SiyFOrgHIkXzfGbpNpaStGe1eJVEL4mAndnRKjFP5Le5OaxNDauu7+Z3s?= =?iso-8859-1?q?qMPLSxcWekHedHd1qbox4Qx+d3thx//1sG2gT5Hlo+bCnYwBpO167Bi0TUEq?= =?iso-8859-1?q?emfL/DdMtob3wNgY5FkXYzcxvZ1fymlCwEZj6uskUHgMZGxqzD9ESOwfCtVR?= =?iso-8859-1?q?q8clFK036Hke3H4w7B14EKD40wxoopeRXGS/b3CSXqKHgVU9l1ozxrU2b/py?= =?iso-8859-1?q?AIDFh2wY7qsWsvQiJMF30YfYKP8T0n3gh+MoLsGBz7NFCNSIntLbty4H7jVg?= =?iso-8859-1?q?U270=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: cca97c2f-3997-4bad-4b71-08d9c147e365 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Dec 2021 10:27:55.0447 (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: 5jyt6VKyqtPWpXc0+9osnGMJ5XoxIQmCDMvFrPaCVDfHd0bZcVEXQ25FU4TogD9qRVYOPaj0RTeKTXK5r5MQfYGp913xEHMWShENuL3hOyk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MR2P264MB0194 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: DF12340017 X-Stat-Signature: bjuo1qxgbjk1teem6fggdb4h3qfqhtcw Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.9.54 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none X-HE-Tag: 1639736874-50081 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: Use the generic version of arch_get_unmapped_area() which is now available at all time instead of its copy radix__arch_get_unmapped_area() To allow that for PPC64, add arch_get_mmap_base() and arch_get_mmap_end() macros. Instead of setting mm->get_unmapped_area() to either arch_get_unmapped_area() or generic_get_unmapped_area(), always set it to arch_get_unmapped_area() and call generic_get_unmapped_area() from there when radix is enabled. Do the same with radix__arch_get_unmapped_area_topdown() Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/task_size_64.h | 8 ++ arch/powerpc/mm/mmap.c | 127 ++---------------------- 2 files changed, 14 insertions(+), 121 deletions(-) diff --git a/arch/powerpc/include/asm/task_size_64.h b/arch/powerpc/include/asm/task_size_64.h index c993482237ed..0544764b32c3 100644 --- a/arch/powerpc/include/asm/task_size_64.h +++ b/arch/powerpc/include/asm/task_size_64.h @@ -76,4 +76,12 @@ #define STACK_TOP_MAX TASK_SIZE_USER64 #define STACK_TOP (is_32bit_task() ? STACK_TOP_USER32 : STACK_TOP_USER64) +#define arch_get_mmap_base(addr, base) \ + (((addr) > DEFAULT_MAP_WINDOW) ? (base) + TASK_SIZE - DEFAULT_MAP_WINDOW : (base)) + +#define arch_get_mmap_end(addr, len, flags) \ + (((addr) > DEFAULT_MAP_WINDOW) || \ + (((flags) & MAP_FIXED) && ((addr) + (len) > DEFAULT_MAP_WINDOW)) ? TASK_SIZE : \ + DEFAULT_MAP_WINDOW) + #endif /* _ASM_POWERPC_TASK_SIZE_64_H */ diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c index 9b0d6e395bc0..46781d0103d1 100644 --- a/arch/powerpc/mm/mmap.c +++ b/arch/powerpc/mm/mmap.c @@ -81,115 +81,15 @@ static inline unsigned long mmap_base(unsigned long rnd, } #ifdef HAVE_ARCH_UNMAPPED_AREA -#ifdef CONFIG_PPC_RADIX_MMU -/* - * Same function as generic code used only for radix, because we don't need to overload - * the generic one. But we will have to duplicate, because hash select - * HAVE_ARCH_UNMAPPED_AREA - */ -static unsigned long -radix__arch_get_unmapped_area(struct file *filp, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - int fixed = (flags & MAP_FIXED); - unsigned long high_limit; - struct vm_unmapped_area_info info; - - high_limit = DEFAULT_MAP_WINDOW; - if (addr >= high_limit || (fixed && (addr + len > high_limit))) - high_limit = TASK_SIZE; - - if (len > high_limit) - return -ENOMEM; - - if (fixed) { - if (addr > high_limit - len) - return -ENOMEM; - return addr; - } - - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma(mm, addr); - if (high_limit - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } - - info.flags = 0; - info.length = len; - info.low_limit = mm->mmap_base; - info.high_limit = high_limit; - info.align_mask = 0; - - return vm_unmapped_area(&info); -} - -static unsigned long -radix__arch_get_unmapped_area_topdown(struct file *filp, - const unsigned long addr0, - const unsigned long len, - const unsigned long pgoff, - const unsigned long flags) -{ - struct vm_area_struct *vma; - struct mm_struct *mm = current->mm; - unsigned long addr = addr0; - int fixed = (flags & MAP_FIXED); - unsigned long high_limit; - struct vm_unmapped_area_info info; - - high_limit = DEFAULT_MAP_WINDOW; - if (addr >= high_limit || (fixed && (addr + len > high_limit))) - high_limit = TASK_SIZE; - - if (len > high_limit) - return -ENOMEM; - - if (fixed) { - if (addr > high_limit - len) - return -ENOMEM; - return addr; - } - - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma(mm, addr); - if (high_limit - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } - - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = max(PAGE_SIZE, mmap_min_addr); - info.high_limit = mm->mmap_base + (high_limit - DEFAULT_MAP_WINDOW); - info.align_mask = 0; - - addr = vm_unmapped_area(&info); - if (!(addr & ~PAGE_MASK)) - return addr; - VM_BUG_ON(addr != -ENOMEM); - - /* - * A failed mmap() very likely causes application failure, - * so fall back to the bottom-up function here. This scenario - * can happen with large stack limits and large mmap() - * allocations. - */ - return radix__arch_get_unmapped_area(filp, addr0, len, pgoff, flags); -} -#endif - unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { + if (radix_enabled()) + return generic_get_unmapped_area(filp, addr, len, pgoff, flags); + #ifdef CONFIG_PPC_64S_HASH_MMU return slice_get_unmapped_area(addr, len, flags, mm_ctx_user_psize(¤t->mm->context), 0); @@ -204,6 +104,9 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, const unsigned long pgoff, const unsigned long flags) { + if (radix_enabled()) + return generic_get_unmapped_area_topdown(filp, addr0, len, pgoff, flags); + #ifdef CONFIG_PPC_64S_HASH_MMU return slice_get_unmapped_area(addr0, len, flags, mm_ctx_user_psize(¤t->mm->context), 1); @@ -213,21 +116,6 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, } #endif /* HAVE_ARCH_UNMAPPED_AREA */ -static void radix__arch_pick_mmap_layout(struct mm_struct *mm, - unsigned long random_factor, - struct rlimit *rlim_stack) -{ -#ifdef CONFIG_PPC_RADIX_MMU - if (mmap_is_legacy(rlim_stack)) { - mm->mmap_base = TASK_UNMAPPED_BASE; - mm->get_unmapped_area = radix__arch_get_unmapped_area; - } else { - mm->mmap_base = mmap_base(random_factor, rlim_stack); - mm->get_unmapped_area = radix__arch_get_unmapped_area_topdown; - } -#endif -} - /* * This function, called very early during the creation of a new * process VM image, sets up which VM layout function to use: @@ -239,9 +127,6 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) if (current->flags & PF_RANDOMIZE) random_factor = arch_mmap_rnd(); - if (radix_enabled()) - return radix__arch_pick_mmap_layout(mm, random_factor, - rlim_stack); /* * Fall back to the standard layout if the personality * bit is set, or if the expected stack growth is unlimited: