From patchwork Wed Dec 8 17:18:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12664913 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 5A97CC433F5 for ; Wed, 8 Dec 2021 17:20:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 902C36B0078; Wed, 8 Dec 2021 12:18:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88FEA6B007E; Wed, 8 Dec 2021 12:18:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AD896B007D; Wed, 8 Dec 2021 12:18:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 5B33D6B0078 for ; Wed, 8 Dec 2021 12:18:34 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1889E1803A13D for ; Wed, 8 Dec 2021 17:18:24 +0000 (UTC) X-FDA: 78895285728.03.02C80AA 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 7443740005 for ; Wed, 8 Dec 2021 17:18:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FBXuS5p95SYWI+/ybJFzZxtF2TTOyqPXNzj1wtnjNXrinjlm3b1nu6FRDQalOUdG/8bUMK05Twbkwj17AlWsWKu0qnwou8zwfvItOLgMdaR6v1FzTJ02roCk1U4EM3Vee83d7gpxWqhCKN4tvwak4MjHohivcpYljtGqX/OBXl14vsaf+xVP0sge3PLO0gK13O+GgiyrLgtw9dFp4m8mej1t53MOEo6X2RuURwTUW86T3gopX4uH7it2zdbrqFyXViM8+cCt3Nep292HNEIgg4sv/eRnRsrEhnPRYrUp+JaQ1ss2JVCMzRzqHlBRwvPDt/cpm+Ws9X9oRW2wDEuD2w== 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=yUFkKM+3rEOBA7h8OB54KFRMuecm1HZK/3fT5Q8Cr/c=; b=LbOjdyTI05Ix3Bh+xaWCMCmOnywtjmXTQhQ6R/zFFI13lFqJi2s9/uJUjOZQuOd8SBxUS03zkxKPvhn2mEsqWQPnpCIMKACTHxRwuPcLmEmU8ZACY80UPi7VQ2mtuLu2wm0dsLm5jQQVinluop9aayruo+eSqwMVIZWBfSolfhHKOH94qxwlp9g43vA4eZ6qxQ06GXZaTLShA4lPWtLpGx8aPRBCpGRkyxDKEG4lvdNQSwSmI2bamVDplKepJxM/rm4SNPKu6tdMSgOrTiAlA7Gq0McMJSVgfWohKT3lGcj9e4cQ1Z1TprUuDa8zumnd4hrlXfMTuULwouKVj+rZjw== 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:20 +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:20 +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 06/10] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Thread-Topic: [PATCH v4 06/10] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Thread-Index: AQHX7FeZYbkFB7BK6kOFRdVEM/XL8A== Date: Wed, 8 Dec 2021 17:18:20 +0000 Message-ID: <8f54a8d097c402d808147b2044365ebfda2862dd.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: ba27659e-75f9-488f-1f4e-08d9ba6ebbb7 x-ms-traffictypediagnostic: MRXP264MB0823:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4GkEdRthWLQrvEIz46IXLQOO83EFFFpxUf3jJJOPxz9LCtan3D7ONo7IuM4eumUS1L+n8IQUVnYw3KHrqKiBrSKXHpfZrvwI1rtTaN0rapDScUhxn+3Q3pjPgIvUZV5s80ZFpDH/GVX9k3G+zHN3orQyZy5W7jWJm75/i268cJl8hXOTQ0XqrQipNKhQ73Ty9Ly620d9fhSwB3SKIZ7u4hHOUKnBc0puSUu1g88Pp5OsJczswMIKptIsQeH0/KqMet4vudN+G4OHpY3VqiaksfL++F0rBYuR6z5UzSGimk4ZpxRPySrBebNveenhQbBw1IsprWw81RIF9aGvwqcoU933KqJaSCPldDBtOzWjAbfmlfFLDhZO8AWWeDtU/5YgYuCk54bWJToRlSO2mEEwXYO2jiMo+ybGnWYt3OEVnCNqn6tQJrIknqvEqvmLLE/MamWLlokM8rcHvwZ1xsiFeRsbpqGx1XpVgr4hVhx7KvuJDUWuIvQc4Qyd2r5ifL7gcpMxygUJjTWo2DxVCDdf3TqyVpLzf1mik69cge8b0CtySPo+p2PL+yhgEWdwRC9JcrBx4fGnaODwlXutfKjM1nnMwnWl8icIdkjF07Vu6osPQejYMisMumqLpEoekAZZ6+ViDSQzGnuuTxmeIr5GglQxrnuDw9La1NL+cq8Ddtp3fhMUo3U2ckBl75ogMogkReEZP4bVwky79dUTdb4l4cpsTk7yvu7Rs92zKP0+GCg= 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)(41533002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?xS3CNFaMBV3+aDDehC47sr2?= =?iso-8859-1?q?U5dQBZ4E6/TIb81JXOTMYWchrqtaCHhT+haKQIndRE6ckw9pF83BK1VZxcLW?= =?iso-8859-1?q?MvxX9IMASpBzMEJ4B06SL7iLKv+FPMeYiygvHxJLdJum05Rj9k0Hhc3Pil5l?= =?iso-8859-1?q?7aqyPeJxzZLEMJjYvC6udjbQ+dpZsMuJbN06B8vf0JkhuSbYtKWs+m1y9lH8?= =?iso-8859-1?q?8RA0xvOAzNih242j1vw8sAlskeBfj3RacbjhEk8TaS5q/34P9sqCK3crX/gb?= =?iso-8859-1?q?L5MbaojoNV7cGV+zT8YX3RFXBCNLPgPjz1IAmni5XukUolKxLaatNi7QdB/7?= =?iso-8859-1?q?fGRB4PEJYmeD4jAPjU7HFSZdH2f7Zq3kzE8R0q+D/m3e4fk7oqgltNVjTqzx?= =?iso-8859-1?q?HFyywHAM968sUiecNxudpeJsMdDiUWHxCavbaZbtE5sbGAqx8JIfMpfL3/0e?= =?iso-8859-1?q?L3yJcCfMLq1s4wUXCk6gGums9FzgbA3edYLQDmDsxjuU345HyLEJbq5jd78g?= =?iso-8859-1?q?5XgIGotSJY/PScTpTq7tD6Tylv2WjqO+gcFnSdsFwb2RFRog+A1mPIzOyfo2?= =?iso-8859-1?q?4dN+FXwRtHlPxEB/p4AvhHuTyGhSEJsX1LxYFA6tnrPN0eyswG6dKrI6bQeu?= =?iso-8859-1?q?sE32BvvBUcdJf1thrytildnJQmWeUGfsSNjGnL7SWBdNQH/VSeSK4pvAkhe4?= =?iso-8859-1?q?dtnizicEKI7FiGlwO8J5P7q0ZUImVk2GBqUndi/pU/widFAyxP5UE3U99HOR?= =?iso-8859-1?q?At8utkYcnEIcAIphcjJQsUMs00/oZFKKkc4rtp8mTE/QbIDRle9Ymdxaj96a?= =?iso-8859-1?q?jFoU460udeAwHElAxmFy/2AUOV6ozHPEBq3sKWGDpI/4AR6bdUXsI1Nv6rdB?= =?iso-8859-1?q?q0WInWffW2cB/FeTa/BLrX+82lXDC/6C6Pgw5xnyawL1jCByAWqeX8uv11D7?= =?iso-8859-1?q?5m843xtSlE/NB9b7AX+c916ccU/keg3JUh6nFsT7tdmKW5yj2P4Mm+vHQZB1?= =?iso-8859-1?q?h2y5DQkDPdcxYC20nC55loO+BcpkK3OE/NwWjD1VKV05NKAhEq8Q/cD14twU?= =?iso-8859-1?q?eyv5vxjVGCkHwunoAwdTtiGq5yrEUIazl6GAOlRSNiQswdU0SVUoASKfcP5t?= =?iso-8859-1?q?XN9xp6mCaLDb/IYdSoUxaXb5oINRGyMAQwF/6G+KftPqgWrFq9QZmsZQ9Xmr?= =?iso-8859-1?q?/ptx+cpIq48cDFithx9euD7TrIMH4mV3ACZBS25w86wdYQvgA6/A0H9He31n?= =?iso-8859-1?q?GkhmfDO38S4ssQRZONxbn0cMxOhULWgnDGp2d4OICyrDW56xfk55qxUhJptu?= =?iso-8859-1?q?lWF97fGt8EcvJgc+d6ar8OFY3e5FqOM/CwSeihj2wKXeLcILRN5xRDmDzOwV?= =?iso-8859-1?q?3oC1VzkYifSzzEHVJvQuZywGiDNzA473Lm9GyhrFEyWcBl59QsAov3yisFgE?= =?iso-8859-1?q?iX5oysfY2w+XJ1lf6EdhPoAsgDOoqD1ZZZKeGfLVrbe/IIA2WH6l4lUAoyV6?= =?iso-8859-1?q?LzUx/z6pTacHSTLwEXon4UhRtTsqAmdEnibpYGBp58jhmDaZK7xc/1adk+Pa?= =?iso-8859-1?q?Ct9/kEhagtVTVbLGrn2Ci0FcIiFreTIkziH7MGRsQIEpnz90BGHgT9lWXxmE?= =?iso-8859-1?q?bkmmtrKg/LaYiBvn3VYX0nc4PMQjVH1IBNuOU3SiBBBmbKsdC7NhadyE0pRn?= =?iso-8859-1?q?TTNAipFBNHFsTzrmfyIPkZXkZGSoUE6tswdgfQS3IGUBanX7U7hozheDBbp8?= =?iso-8859-1?q?GuNs=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: ba27659e-75f9-488f-1f4e-08d9ba6ebbb7 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Dec 2021 17:18:20.6701 (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: uC3CSVXdWPrP9w843rQwrFCYsIXsami6Sk9waNXJJ9FwR42dSVCcrEeS7RxPOxxDe31Hg1ei8igwZ526OkM16YOVUybTeengBRdjengieis= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MRXP264MB0823 X-Stat-Signature: 761zngbuk9fhy8yoboyqz7osrygfeesk 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: 7443740005 X-HE-Tag: 1638983903-701329 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() 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/mm/mmap.c | 127 ++--------------------------------------- 1 file changed, 6 insertions(+), 121 deletions(-) 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: