From patchwork Fri Jan 21 08:42:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12719505 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 0B5A3C433F5 for ; Fri, 21 Jan 2022 08:42:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 668686B0098; Fri, 21 Jan 2022 03:42:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 619036B0099; Fri, 21 Jan 2022 03:42:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B9E16B009A; Fri, 21 Jan 2022 03:42:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id 366CA6B0098 for ; Fri, 21 Jan 2022 03:42:36 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EE7988F147 for ; Fri, 21 Jan 2022 08:42:35 +0000 (UTC) X-FDA: 79053653070.15.F79BB8E Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120059.outbound.protection.outlook.com [40.107.12.59]) by imf18.hostedemail.com (Postfix) with ESMTP id 4F9641C0007 for ; Fri, 21 Jan 2022 08:42:35 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e+Kyvz1CW6FHjb5CKxfXYIFXDKyuQ9xh5bK48M45PncUSVJRFVFBgpN/MelvWCY6K5k+2R9jpZHYniIvTkRzFf66l38uJBgyl2bhFkdSTE+zma9fVW8/4zO3GLOdEnMDsdp5Rc27IJpqQcrD/Ut8N4kx5S1UlFxjpkAFG80wQpJjFIHFg/RNkMsql7uYgEFQvCmH2irKsHBtq9/c49zvUyrpaKkEDtqAmiwxjKHt8DqQTz1ccEymZ9kjMPEEF3be15LOW3n9LQywNDDGGSLOcKtH8W/uqerii/0DKmfo7tivOqZ4mj0Mgoo1f3Q69rGOYF5mldJhFmVAbGhCB+eYWw== 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=1R9HXl3qYoGwoSieVkCnAD5XaAJlrCyaK/qBHE9jM9o=; b=NGowRYhyNpcTMfMK3cnTDqVwjaJDziyTZRDiQLhcY8v04eFKPbEIu9E0vMTzKwwmb8oWC8UdYteCHRnzNUrgIniYaD4bXkoeAe/fw2SfyiWl+C6pR4Lu6qgUHGqvpFGy2jRklC8AlnoMLirNKk8Nqsqv83d7J597ofxjrx0QcoC20WGD43NpD4YdcwcG1ZKL6LcA0mOVK4ywe+pB/oF15wdFpFG/Qp+Qj7cob+Q/nkdyB+p6I5VRTYfmltuNlkc9QQnLBAD5Rl2tyZ3LGSD8h0gkLFo8X+evHqYQZfpQmXmfRIDtYseW+I4/0tMaHEdT9Sy2hZ6IZloOWepxaZKahw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR0P264MB0201.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Fri, 21 Jan 2022 08:42:33 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.008; Fri, 21 Jan 2022 08:42:33 +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 v7 09/14] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Thread-Topic: [PATCH v7 09/14] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Thread-Index: AQHYDqLVm5veIrfhK0GUQ6geY45hSw== Date: Fri, 21 Jan 2022 08:42:33 +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: 19fad9a6-63e4-47fa-1fe4-08d9dcb9f806 x-ms-traffictypediagnostic: PR0P264MB0201: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: kS0v/eP8lnKJxpNHH05Z3vXZLeNmHaltx4fNWVRvAnvgZNkXEBrefXqiXWUvFyJhMu7c2CDCyriykSCsSpNBBbm5qn5dKWx6x71EddjxQL9Lt/9BUb0mMqOJbPybx5xds4IBv5yJ+FJwAXXpcuHtLoSnbgSh+vN8ga7gXSAUKUYjKU2LjlWvrIgMGKHK8ZJQ9enwZrXwKv7ldlGKUisLG1cYuXAnx0GW7gE2rkb76kcGDXnv9uMRFF7Ds0jp1lE99tgV9UzkjP7U0G4IEhMfCE9qLOtsRm0zcxiLbqS7T1kZX1oRfsmkiK4sSz79Gu2VMGUQMBxJDVd8I120xKgBKjdqeFVeHuMi4ev6HIAXllOMcVFhZ5ulNx6aN8nKQNRhJy3WrbVLF439p6W3N6sXu0Azm3G+j+iy/s8rcvxEwScCWjfK2/oYdMBty9X+kb9RgTaNsytxOwwS7lUbqIu0xc8DT7z0AsECHQP/H4H+eAfc3w9lDu4Pu2BNjKeGm7kDSyy1ro2YL2EJw77uFY6VjVIDDw8cUmBl2BfOLyj8mrjablKDwHKiO2bKLVtrS7vMCFUTn3q3ts47aSrzDOWIowMD0bEJ7sovAOUKU6kT+oQ5fUILdn/yHYIdzJ3CSWcBo4115I1HEJp3AxTpNv+uoW1FUyHoJ2pLcOjTLUE9ggvDBKouNFXdKSjFXUPCkuueq9mJJM+fxAF6XJXWid3i97xrTclfNl2OLWP+b5B0hvw= 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)(76116006)(91956017)(36756003)(66476007)(2906002)(5660300002)(66946007)(8676002)(6512007)(122000001)(71200400001)(8936002)(83380400001)(66446008)(64756008)(4326008)(66556008)(86362001)(26005)(508600001)(6486002)(54906003)(2616005)(44832011)(38070700005)(6506007)(186003)(38100700002)(7416002)(110136005)(316002)(41533002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?ia+kquVdA8s2z6JirQGURGl?= =?iso-8859-1?q?s6h3XGqet30Chvjw+FGdDpGF90fms556Myk7PUWSe0B0UXIb5tIm4uKJDUmI?= =?iso-8859-1?q?wzHJcfKDFPok8c/y/QXEBl1ovE7fWQnGK8rh+uXq0YSRVeTsUOVuy5oaoAqX?= =?iso-8859-1?q?kgIOjg31gAJ8FSdbBH67cLOEJDR12mFTBs0Mcm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859-1?q?LvRoavfLr/Aue+bB5nofbxZf03x6zdEhcu+v8EZ8IY9z9m5GOPZuQt8kmWuw?= =?iso-8859-1?q?dhp7oaeZUAX7lp8TbpEGLtcq6MIYqojDcNKChv7VfBCt3q1XL2rRwZxkBDc4?= =?iso-8859-1?q?yii76r8A5vUY5Di92dJ2BaI5+ySIJ7NqC9maW0xommA9Bd7fh5n9t3g2A+B+?= =?iso-8859-1?q?Yv62oBip3FG3PN0JI2xmOiKy8qBlcdx02uyhINLaPpBvaUb5Q0GQK+t5VdAd?= =?iso-8859-1?q?tR5RT3RCL7v63hMu40elRYY9Bg74k7jyfM795QWVB7eYQz914sF9v+fmdRcG?= =?iso-8859-1?q?9Udv2omaK3/Lzm94zggXoBJTA49aeRBJAhZAbPEgzM9xrHUaVStZt/KdWq2p?= =?iso-8859-1?q?r93h/OJxOKqnivmeq3O61heAjZl+9wngPUJyNHvnjo6JFH+XJ5g7CQPJN8KJ?= =?iso-8859-1?q?Teyy/Eqx/P1umJnnniUF01HUawXr5eLR3vCYfidESlxgQRYbZw/BSmcsJ0sS?= =?iso-8859-1?q?B0CoHfZOIscDySF6GtSNRXZkt1Hi9DyHOUybLlkQQcspjq/BbIUU0BKkVlUc?= =?iso-8859-1?q?g6jyWbawL+j4zU6Dh4qixSxomxXwPIOv4PFaQrQoRlyj8iIp7G0ix5xQ/F8J?= =?iso-8859-1?q?S2qH2WVZggM7c0q14rCrZzuKToCi4Y6HoKZw43kio2wYESgZmBp4VikcK6zD?= =?iso-8859-1?q?l7M4=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: 19fad9a6-63e4-47fa-1fe4-08d9dcb9f806 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jan 2022 08:42:33.6909 (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: 8Umo8CPIWc9oXF7wzgCLBSs3WLFBuP12r+u8GN7cM+Vdgf51XSkF09jm/4WuE5evnr1pCjVkPc9kHi2HgZylwS1KKbok+sIP7QxWsWgELjE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR0P264MB0201 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4F9641C0007 X-Stat-Signature: 6u84ahh7f9unj9itx14ggq75h65juaun Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.59 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1642754555-12675 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 38fdf8041d12..5a709951c901 100644 --- a/arch/powerpc/include/asm/task_size_64.h +++ b/arch/powerpc/include/asm/task_size_64.h @@ -72,4 +72,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: