From patchwork Fri Dec 17 10:27:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12684207 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 D6A0FC433F5 for ; Fri, 17 Dec 2021 10:29:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BF156B0078; Fri, 17 Dec 2021 05:27:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16F3B6B007B; Fri, 17 Dec 2021 05:27:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2B186B007D; Fri, 17 Dec 2021 05:27:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id E58C56B0078 for ; Fri, 17 Dec 2021 05:27:40 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A8E0482499B9 for ; Fri, 17 Dec 2021 10:27:30 +0000 (UTC) X-FDA: 78926909460.22.864219E Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120050.outbound.protection.outlook.com [40.107.12.50]) by imf23.hostedemail.com (Postfix) with ESMTP id 55BAC14000E for ; Fri, 17 Dec 2021 10:27:25 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iB89JXApPwuwCFDgBvf/poPk3XsHOPuJmLHy4v3THlnicUX1+qJP+ioQONgSdwuAhEzgY6efLy7DpNMGu5R1miLbB/nmkV57tci4bsU7tk4NSaXMMmSHT8LipBN/oyxzopiDaPnfVGJVwcNA5yL9nIkZMdz/OizhAXEOKht+SnqpBOP4wLEuFsuSMXMSN98LI9aVwOBYxm1A0WaPW7aa8sq8/iWARp5K33s5MvP9PEkGat9Kt9JA0RL5ABb90FDU3oNUZZKNIACKXmt80JYUTf0DAOsGpTXfKOTP7R1RdUDai4xGyrXfkw86/mK43KYKrhzI9MivKWMtetG1GLoaJQ== 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=zGuchkW6gN8DyiSjcCAMN3uQCynPaUaD4ighWhH83D8=; b=C4ypQdFeDDhd3tJJCGb2Byx0l4zNja9recLA221xkLXU4J08RLBynCfZwewChZ8/hIRJhSr5bN80eZoSpe0I1yhqAuWmhbuWavTlvQ4WUQq2s852l7cADH0WFVyW8F5K5ChAWh2FiMX3xqXX5VN2bi7WoEAdppTDybyyGLkbGTqSms4BvmEAAjnat9Q1fnyRMkxAizaxrfL5hlEI2P2700t6d1X2Xi482Lvw3a1NGe0AI+tGBQTzZKiLX440depQxb4FeJ/hh72lFGi+2Uf2hB6VuIIuCPRaLJoEJke/hrfHVL3Q0gkNfoFYqd8xSM2KGGQ1tRgi+6Bs1xAhShqL+Q== 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 MR1P264MB1650.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:4::11) 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:28 +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:28 +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" , Steve Capper , Will Deacon Subject: [PATCH v6 04/14] mm, hugetlbfs: Allow for "high" userspace addresses Thread-Topic: [PATCH v6 04/14] mm, hugetlbfs: Allow for "high" userspace addresses Thread-Index: AQHX8zCw1U4oSg0lTUqR0a0vDc8DCQ== Date: Fri, 17 Dec 2021 10:27:28 +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: a78978f1-f292-4da2-fb1c-08d9c147d369 x-ms-traffictypediagnostic: MR1P264MB1650:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4714; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /+kmlVvERmbbsL6d+X62OmM18OEW7mlhR5Gs0qIFUdqX+duVpsLyap/pLCNlaLPdq6+WapP1mpOFhQjzNJa0ZtqLj8m3IiBkIHrpL1fm6nRzClFkmNoi3oCEpqpHTwL85siyj7So4TIAp3f6KOHdmKg+6yjVo1/P/VrOVznT+yvVnJb6nZrYEsq6Wf0+pofBgUaBvEd3jrYyq8jc8mj+jbRedPMAAFagtxtqEgQRKHjNQX6GityqGdZETU1H0L9mduxJHc28SLi13e8LXKRoFutMolRzDrzapd6DlVFCKe+ufKG2r6Eu6CF5Cb4PjwEBU29I/9OkpYezd2YbUD2GYNpf2u3Oy6Ltxh1+XhoRUoMDCNpDTkLdmIMKLn0JxhQ2+YB/YLGO7At8jnCooUx3pK9/J1FLhuTx+kIDYnhCsA8fFZ9C7si6dgpHN/OxHkJWWaYsDj5V1fhL+xpUjcuckzk/UUBuhcJeUPPveqMnpEVSNN5y7Bq7IVNSaBSz7HrTWX6XQnd0upxjs9tEUBJN2aPAJZyh3jrNchkjfDJAByLDfa+AKYJ0UvkF7ngPQJOaXCaYZ7GCh7PqU9zq68b2S8elRYvRZOXWmdMz9YhiImJDP8LEbKp+0Ap7XNbSgpqdp3K3UVkm4Qes/y6E6rVzb6jmXS8QsE7IpSm8VHFk+dUDPL0Q0Y2IaYm40vsR0NTdPCMMo8fKFlTcbWiH6WN3Nw== 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)(8936002)(2906002)(6486002)(6512007)(8676002)(83380400001)(122000001)(36756003)(6506007)(186003)(86362001)(26005)(38070700005)(44832011)(76116006)(66476007)(64756008)(66556008)(5660300002)(38100700002)(66446008)(2616005)(91956017)(66946007)(4326008)(508600001)(316002)(71200400001)(54906003)(7416002)(110136005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?OT1OVswMaI4vEOeEsTTFAbp?= =?iso-8859-1?q?vijDWfVCm6MjHbMf87WGhmwpC4R6sXImDk5SuOeHbV062Rt8GueHTmUczHSI?= =?iso-8859-1?q?05G2pcCMpyQQNeEB0uhsGPQVwST9iUS1ew59A9dDQobbQIV8RsTHKfDWcgFj?= =?iso-8859-1?q?2X6Sni/eFiGBCRRMHFpC0RdJmPn76iiSF/pmMe3j0GCLuzxnZ27yFf5Rn8Ux?= =?iso-8859-1?q?xU6yGAf2WfdJ6PpQ8H07XNqIAZjwuhTO83x287/56vFoE6nY7+QiDnLUHcJG?= =?iso-8859-1?q?u+8grVrNp6h+I4SH1LYb7NrBzPMdoJR32HLUERna0UOm/4hoXxulRNdUv3cV?= =?iso-8859-1?q?XWslvira+9S6hqb9h2WwR0xoh0AFp/wUAHIcXmsU1fyU1fo+z61ifDIufttE?= =?iso-8859-1?q?kTnyibw2My1gDHBS1Jo/734nkTG8OGEvX0ao7Fr4dT6faLupwyCBOM4E31MT?= =?iso-8859-1?q?Rv/ZZqhwfZonNiX+gcLhWrR6TTCoCPMkKvoP33Oz/gyv8nJfiRZxVrnBQ+SH?= =?iso-8859-1?q?f2vq0O70fR77QfERCrmQSWa8fDhu4nE9iYppRni2JABckddtOkHXlRN79QQB?= =?iso-8859-1?q?5MeqKn5zamLCDb5GUT9j/gO3Krn/Iu6lM62NUH/DDxe/WYI2RE02/vxiLey+?= =?iso-8859-1?q?8LmXjjlIylj1IEdoyxFIiZDmv8051xtZALFpA/jlJ+h6KGKAABlOgDnYS09S?= =?iso-8859-1?q?TMETZpHSxzWaXtvPerIkXuk96dEFcOHnecOn+vbqAMiYlGPFcvKM0xNz5LSG?= =?iso-8859-1?q?WszU2XrsUvBt9DVZXLDEhJHdnbqUmSfaXdKTydBeDgmAtOQDEVq/kkwmg/i/?= =?iso-8859-1?q?kbQxxd9JJLUlbWngrWjbjLNx91f1ZjM3143v2pfMNPrq1Ta9w5q7dbYUjSn2?= =?iso-8859-1?q?cDDiQdJtw2cjHfJizeuQpQFD1L/HY92NhERRuTxQlOYCz7Mjhu2NjxP6OoNp?= =?iso-8859-1?q?qqJSUSu+NULFkSOOZhRLyy5PKFsfTzwzpwaxB/qgIzRB47y0lcIemJtwbhDh?= =?iso-8859-1?q?nYdxeNicqYVEUrcK5odeXmSVCavr6xQOGiP4oAaAfeK876M4RFtTikxNQLNs?= =?iso-8859-1?q?0BVgqSKYxb3WkJmzpRmtv+2ps2ZLWy65jhLamJUXbX63Gwh/WGeXxmgeOFjA?= =?iso-8859-1?q?wfv7xvbqU+l+wbyM8J9wBb+I46weC9sVvDZH61Xipsd78RBTJudvTWzLhg1c?= =?iso-8859-1?q?4082xohqjmHkazMKyjaATfnRyafQhJsniZMrr+9h3FJZiSZf0jXfNGJSpOuy?= =?iso-8859-1?q?EVO5+iw0A6ubzYZZmneKL+U2R5r/nwL8sT9b5QSOUe1PzDEafJuc1Ke9pxxm?= =?iso-8859-1?q?YzLeQCoktdqUIKvAY9FKzrdztZEgjUSZVliap/ER3cJbThyXc7Zxam868IIG?= =?iso-8859-1?q?Gp0V6g7rd5iAG8kcA32g8jgvomiqvlsxARN+tgILTk1pL1Pv+iunsIk2K6U6?= =?iso-8859-1?q?+zm9zsHs9QyvduFKtLCNHTqyKDQARu7BN3nBfjH0vzu3deeOK3aq8H0mLwIQ?= =?iso-8859-1?q?8Pwt62aaW9/FhNgBwWiYAjN41SZOPx7U72xIpTyN91RL3SHkYAoDL4Qsf80R?= =?iso-8859-1?q?HiPVnRkTubkH72Tu43LhpCBrmqJhim6ScZQSz3fGhuThVwlCV0ntFumRzKLD?= =?iso-8859-1?q?2AJRMx4TnULy1NOrpLnWq+dtVmC5FHLr4fZIYekTySFUK01G2WpPTMCHSNF4?= =?iso-8859-1?q?kpyVD2srn+jlF5omRLDOyjjGxnY4EIgxCQQnyh6VMtn6LW6OCnlw2nlkmBoN?= =?iso-8859-1?q?IQh4=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: a78978f1-f292-4da2-fb1c-08d9c147d369 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Dec 2021 10:27:28.2944 (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: s3WIFI/tuDHH+/EAa8AyKUz+El75Yb4VJfHu8icu90uRrU1PSb6itzvlyoxtT/tK6KwIrsu0lh92DBo2bSg+LxJ+UFs2teNCrHRx9crF+2M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MR1P264MB1650 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 55BAC14000E X-Stat-Signature: fiwtd8zf96oewmmtegb4s48mkfnf5c17 Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.50 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1639736845-192909 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: This is a complement of f6795053dac8 ("mm: mmap: Allow for "high" userspace addresses") for hugetlb. This patch adds support for "high" userspace addresses that are optionally supported on the system and have to be requested via a hint mechanism ("high" addr parameter to mmap). Architectures such as powerpc and x86 achieve this by making changes to their architectural versions of hugetlb_get_unmapped_area() function. However, arm64 uses the generic version of that function. So take into account arch_get_mmap_base() and arch_get_mmap_end() in hugetlb_get_unmapped_area(). To allow that, move those two macros out of mm/mmap.c into include/linux/sched/mm.h If these macros are not defined in architectural code then they default to (TASK_SIZE) and (base) so should not introduce any behavioural changes to architectures that do not define them. For the time being, only ARM64 is affected by this change. Signed-off-by: Christophe Leroy Cc: Steve Capper Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Catalin Marinas --- fs/hugetlbfs/inode.c | 9 +++++---- include/linux/sched/mm.h | 8 ++++++++ mm/mmap.c | 8 -------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index c7cde4e5924d..a8d3b0899b60 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -205,7 +205,7 @@ hugetlb_get_unmapped_area_bottomup(struct file *file, unsigned long addr, info.flags = 0; info.length = len; info.low_limit = current->mm->mmap_base; - info.high_limit = TASK_SIZE; + info.high_limit = arch_get_mmap_end(addr, len, flags); info.align_mask = PAGE_MASK & ~huge_page_mask(h); info.align_offset = 0; return vm_unmapped_area(&info); @@ -221,7 +221,7 @@ hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr, info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; info.low_limit = max(PAGE_SIZE, mmap_min_addr); - info.high_limit = current->mm->mmap_base; + info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base); info.align_mask = PAGE_MASK & ~huge_page_mask(h); info.align_offset = 0; addr = vm_unmapped_area(&info); @@ -236,7 +236,7 @@ hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr, VM_BUG_ON(addr != -ENOMEM); info.flags = 0; info.low_limit = current->mm->mmap_base; - info.high_limit = TASK_SIZE; + info.high_limit = arch_get_mmap_end(addr, len, flags); addr = vm_unmapped_area(&info); } @@ -251,6 +251,7 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, struct mm_struct *mm = current->mm; struct vm_area_struct *vma; struct hstate *h = hstate_file(file); + const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); if (len & ~huge_page_mask(h)) return -EINVAL; @@ -266,7 +267,7 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, if (addr) { addr = ALIGN(addr, huge_page_size(h)); vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && + if (mmap_end - len >= addr && (!vma || addr + len <= vm_start_gap(vma))) return addr; } diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 2584f7c13f69..cc9d80bd36d5 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -135,6 +135,14 @@ static inline void mm_update_next_owner(struct mm_struct *mm) #endif /* CONFIG_MEMCG */ #ifdef CONFIG_MMU +#ifndef arch_get_mmap_end +#define arch_get_mmap_end(addr, len, flags) (TASK_SIZE) +#endif + +#ifndef arch_get_mmap_base +#define arch_get_mmap_base(addr, base) (base) +#endif + extern void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack); extern unsigned long diff --git a/mm/mmap.c b/mm/mmap.c index ad48f7af7511..c773b5ad9a11 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2112,14 +2112,6 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) return addr; } -#ifndef arch_get_mmap_end -#define arch_get_mmap_end(addr, len, flags) (TASK_SIZE) -#endif - -#ifndef arch_get_mmap_base -#define arch_get_mmap_base(addr, base) (base) -#endif - /* Get an address range which is currently unmapped. * For shmat() with addr=0. *