From patchwork Wed Dec 15 06:45:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12677583 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 3D780C433EF for ; Wed, 15 Dec 2021 06:50:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A58506B0082; Wed, 15 Dec 2021 01:45:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A07AC6B0083; Wed, 15 Dec 2021 01:45:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 881A16B0085; Wed, 15 Dec 2021 01:45:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 786B66B0082 for ; Wed, 15 Dec 2021 01:45:30 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 277DF181AC9CC for ; Wed, 15 Dec 2021 06:45:20 +0000 (UTC) X-FDA: 78919092000.10.6A2ACB4 Received: from FRA01-MR2-obe.outbound.protection.outlook.com (mail-eopbgr90073.outbound.protection.outlook.com [40.107.9.73]) by imf25.hostedemail.com (Postfix) with ESMTP id 81915A0015 for ; Wed, 15 Dec 2021 06:45:15 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e2o4ckaurMbW74O74keXiO5Q5ngRRUqhxRjP/hEYL/hrsM4ipKXfQqpShReA+rQ/SK7RHPoJ0m25wOx8nGUdidsCG+scqnlCLe63FqUn3BMVs7t/gnmWzqXuPAo9xthv0VW/zubuRWqvYKStWhu/BUk0bDaFpZpcR1hKyw776zw2WtAiA6XRmROu9aNmX6nvn3WqJiZto97Yy2jOlHlwoi8R9lGMYrn7CLnyGHL2H4zFEpt8hU9k62qfXwD8JwtbBdow9sV8p6wLNOaWQx+0+FVFknmJ11juu6Xjup2GOhwgRrWYAejgP9+VrezfLnyyZuHGJDQl6L9cDi4q05IQVQ== 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=aOPlIfLv9B1QrXE92w0DRqSm9EvE4h7iahy364wlTRA=; b=kDTDvsprhHKu4YgeXO8ajrnY6ov/rMJyUWfs1c5IpiV1jkVsGfyoaLyDWjrh2eA7BWZpy4nbb7Xx8KssjJ6HY3F/cSBWs1t3n3xJ90IHECk/W/8+So/PESNh9ChTwp8DU3rraPhxUEk7r+6x87H9F4Nq4sKQZ2rKPsyoTZYSpwwlYPzRJM1d9Xq1LGDtcmKmg2TUk8Y7vfJiLEUdkgmRJkJA1mV5m9mFv0hLTOUmLBQPmf7GbM9FcOumqrfTWZA27+3XvzxlWyA//kykDGA2Hyb7F/Jcvx/sor6AqgNIEblmv5EWsDAB7Z+98fb/ABoc1hhlTGK9SKMfuPvB9WPcIw== 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 MR1P264MB2147.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:11::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.16; Wed, 15 Dec 2021 06:45:13 +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.4778.018; Wed, 15 Dec 2021 06:45:13 +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 v5 07/11] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Thread-Topic: [PATCH v5 07/11] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Thread-Index: AQHX8X9P18+NgiQ6yEyIrb9PAUSKDA== Date: Wed, 15 Dec 2021 06:45:12 +0000 Message-ID: <686895764befff16e9dbc2989e8f8eb2284b38d6.1639550392.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: 9967f536-27a8-45f6-4e4c-08d9bf96721c x-ms-traffictypediagnostic: MR1P264MB2147: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: 6u4XPbBzX8aUCgKc9PVkAvqwA9yW+BYVCMNZ0ZJAnjmhpFffDra7oGo1i4/g9nF34c5azhXiyZbnSEPBqxqmGD+uXLcikmXtSFrPV7VlwGajY4hhZ72kN58/U6O0cwqWmVtRfVan9pI/Zg+y0ae3ocvUMb2G1ejmwTqNqPJ3aGeAg5SCYrVqJb146glAOrxwBeorESWUSOKTRB7TS9UbmwBgU5JIsDfFCXMOOHJEaflhS9n/CZEwLrJj8q6+e7uhaLZaOaRurZeyBYhPMYjnlCSCDVz5/RrfmquCwHhhTs/pIuD8yxanBcMinTRuNTm2rUnWLjTTl8cmZ/xk8DdisoMrolnnZAE7XF7zdYHs+JkyjgcnRkSO5KXGbekl0piqVkvnh8ZMrLZJiny6vO0MBp1wvjeFocwUH89ynkqkeFCIhlyIOJbib7po9avvLpUD3Y9pQJbJO9DThDI/rS54qYU4BesKFiCQR4WG3zMtQknG+IUkkmPvXevTOCxgyegFZNLxmVBvhjiZd9npsqzlR6IU25Co+xDRIrn46kAOkFt4BKO9Ldz0JBG4fzcjWqmUFxSyvvqmrbAZO+6hqrtA5aAMe2JtSHn+OlBLc9AArs2NBc3cX27DrUxyvFlBt8MB+Taau0Ab17nm1ZQ38WStuiABpqmSqRcgFBe7uti9UxkNuCQL4QvWpM7fUjp4CNfGBNmwRjEEPs0NRziL83VzuyLM1+VtVZjpE9t1kSd5r+Y= 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)(110136005)(36756003)(6486002)(2906002)(86362001)(5660300002)(508600001)(26005)(186003)(38100700002)(8936002)(44832011)(54906003)(316002)(66556008)(66446008)(66476007)(64756008)(6506007)(76116006)(91956017)(8676002)(66946007)(4326008)(2616005)(122000001)(83380400001)(6512007)(71200400001)(38070700005)(7416002)(41533002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?DA0cfbH0+ItJxq8aub4etUk?= =?iso-8859-1?q?jJiMT/05mSVg4Y0AZ8kTqn9BlrRK7B53emHgb0qUIxid9SlJ6L8UdrcagbrC?= =?iso-8859-1?q?3AZxHCFM5iTBejUaqyiNEMuNdOv4kVW1qP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K?= =?iso-8859-1?q?KaVRKeNFAXTo/XtuYr2STPWmX6KHS8/NsDFhIh1evGa1VxQx8kXlQ7tc/OK/?= =?iso-8859-1?q?T4AC8+8cmWLTrqGsuvID2y/F8p2LIGG0uO74i3N2UoTzofWJsSEM05dqQD3x?= =?iso-8859-1?q?FyjjUrERJYzFRilP38N0y59HdreOSLsuTj6kXdLD5CZZ1Eznuc8ps8QJE1+h?= =?iso-8859-1?q?YM19TBnwExU3Q44LdS2omZRXVb2kJUUy1CKU8oejyPkoZVrESefucPdyRq9p?= =?iso-8859-1?q?z+1gd7hVRtDhBeThfbQGgks680mlh512/eaKPqV+M0l8a38MwKk7SNRP3RJ6?= =?iso-8859-1?q?9C2kcTSaLM97fFUcPAQg0zB6riF4Ljr5qiLhGdjBhLSMzi5J1nO5Apc3YYk0?= =?iso-8859-1?q?p2Gst2vWcpZgKgyk9aNlB1hMrYw6LrwXD0e8iFDruVR4JIa7nkzUH6iiTuyD?= =?iso-8859-1?q?ap+y96MSPryNBiecBs84WeHX0UwjWPNvkXiKGopXAMUFtohK+WJrjuwsX45/?= =?iso-8859-1?q?16aqOn2wLLiCtBGQCyaLGP61qW+LUSjevcGO1YbxuaDiJ9OdN1baBxn8BMxE?= =?iso-8859-1?q?3fXRS1Y4XXrWbQQy7KOy+RGuaoIN4xAg68pezZz+ecrIP0sLCr+eG1dNXb4J?= =?iso-8859-1?q?gjIdc/6MdyB3sX4qYuo7cA+CTykkIIbgWfPaEQD78OhbgyXtp6r9rUMkdXpN?= =?iso-8859-1?q?U/TYq0XRiJ7lzWjMA6020yIUS64os51WeIk/HMru8WHVMK/ojQlLawrF8OJA?= =?iso-8859-1?q?dG/s=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: 9967f536-27a8-45f6-4e4c-08d9bf96721c X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2021 06:45:12.8689 (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: R4ELGewbwqWRZ8H9s3QtHbVdVl1zrK2nEUfpejx7i+279dNxE3p5ytjzZ2jFaD58RvGEY0ZJlGTFuIJcKYXPPPU1rXfUUKQ+0TsmOUb+gKE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MR1P264MB2147 Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf25.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.9.73 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 81915A0015 X-Stat-Signature: a6ngxqs7yi1f48r19h77gyiecrtme9di X-HE-Tag: 1639550715-343495 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 Reported-by: kernel test robot --- 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..bdc87cde670c 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: