From patchwork Wed Dec 5 16:41:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10714599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0DE6109C for ; Wed, 5 Dec 2018 16:42:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B03CC2DB97 for ; Wed, 5 Dec 2018 16:42:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE3812DE32; Wed, 5 Dec 2018 16:42:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19D5A2DE43 for ; Wed, 5 Dec 2018 16:42:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A34A6B754D; Wed, 5 Dec 2018 11:42:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 953026B754E; Wed, 5 Dec 2018 11:42:07 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81AB36B754F; Wed, 5 Dec 2018 11:42:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by kanga.kvack.org (Postfix) with ESMTP id 5B4736B754D for ; Wed, 5 Dec 2018 11:42:07 -0500 (EST) Received: by mail-ot1-f71.google.com with SMTP id s3so9706227otb.0 for ; Wed, 05 Dec 2018 08:42:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Ssm9tJWHFrtRksDx3U9R+7F2PdGwOmZQj+FU4qI3efA=; b=c93mZEuq8RprUqVGDvyCpmoafaemQs2WDOB5LWs2Z2DjPCj7gr+hFoArtTNgBbTz7b RM/Br1TD+HWRC42EzxEVg2uXR/3Sw2lq2pw2eIyCD961EF1VCbJnFed5Lj0hViAeDfmI wJ/V5f8wM9792zv8V62p9v0PB8ZxjVFhpPmdORxJMZ0lmnNUKVa6gnPY/ijQGA9nyvE5 hIV1Kaj6mIoyi3MEV96mw6VxBiCWPxPXna5kcbJhZwgmEr7xWqWIpDIJChLrQD+j/TcU UP6L63Ft0qSxJczqIVxF28ecLBRwsEtPuYz6yTSbRxW0hcXJMTUDSqAw4THQinBIUKGX LoeA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com X-Gm-Message-State: AA+aEWZHeoxAc1F32wHSX+xTtq9g4n5KG+L5AA7p3iAU+DABYCQMpFsC LcOG+tluygqP2OytF3sdy884K7Itcq4qu641jAIwkxYl1eW3tGvWpnt03tHqz2b2FlvdSAeIOIK 3I1NKJwMFRyi1Z38OC9b/Kssr97dyz2SMOa8Mhbxo53ntdeUEoStmfCEauqS35tefcg== X-Received: by 2002:a9d:aa9:: with SMTP id 38mr13885515otq.255.1544028127057; Wed, 05 Dec 2018 08:42:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/VZ826fJh8fjrPdg21ughKJccS0Zbz+cahRPl1/fNy6ygQCWjXpoPUB3xGcNUKFZcoJUk9h X-Received: by 2002:a9d:aa9:: with SMTP id 38mr13885460otq.255.1544028125709; Wed, 05 Dec 2018 08:42:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544028125; cv=none; d=google.com; s=arc-20160816; b=BRBW92uaykdLDO5ZncfTTHt8mRbdJR3M4liFoqt7SXNr9XZcBcuR4xdM7AN/hb2KRk bydgEwt/08nNLNq69BEb2T6JNXE1432xTnmyEWqv60aG2C1uw+D8YNpJ+oo0lQd7CUwA PpVD8+Vs7/dlrgbeNiqB4kvAtiFmdUsauLs29yWVTldNXlaXzAdN6IVLrHrm3aYtixWO zG5AeP/gqGK+HMfIOcJ6zOAEaNqhP3mXFE6Eilk/YBsnRB3zu1fU2nmoXjiVLzOW2xlt vHqNgT+IvCYL5YiUQbTCb1OYg50J/Ky0oNZiRKzkmutI82PXgUWrZrt9dkJHVafMHtJl vCUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Ssm9tJWHFrtRksDx3U9R+7F2PdGwOmZQj+FU4qI3efA=; b=G5zTeqkd8h+iwtf/h5671qm6xE5mreebm9J9J216E5824oESdIC/i0an8DXeiFJdEv 92QdA7wnUl3VATol/8dH8+AbAiTeGx2WcU0ByUxMHEtw3znwbF8J5NMYVZ2jcjFYBXcF edz4QpAegTbFfp4a7zSl25o3nMOclLltGAOpR6gqD5GKFSbVp12VDkmuqc/TNqWwM3hx CO/Ric//xhEvQMESHmHgh3JUtN1SMXsQd5jAl+lTq71hUBKQC0tISuSoQiU+/+XnLjCm x2SjLIjXtle6NP1Yd4GCDplVH0sw/+KxBnLzDtVoMHjxCS+e9ukrU/45ICbAK7YTeD8v PZcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id j62si9055126oia.268.2018.12.05.08.42.05 for ; Wed, 05 Dec 2018 08:42:05 -0800 (PST) Received-SPF: pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 19F5315AD; Wed, 5 Dec 2018 08:42:00 -0800 (PST) Received: from capper-debian.emea.arm.com (C02R32KKFVH8.manchester.arm.com [10.32.102.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A2EE03F5AF; Wed, 5 Dec 2018 08:41:58 -0800 (PST) From: Steve Capper To: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, jcm@redhat.com, Steve Capper , Andrew Morton Subject: [PATCH V4 1/6] mm: mmap: Allow for "high" userspace addresses Date: Wed, 5 Dec 2018 16:41:40 +0000 Message-Id: <20181205164145.24568-2-steve.capper@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181205164145.24568-1-steve.capper@arm.com> References: <20181205164145.24568-1-steve.capper@arm.com> MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP 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 arch_get_unmapped_* functions. However, on arm64 we use the generic versions of these functions. Rather than duplicate the generic arch_get_unmapped_* implementations for arm64, this patch instead introduces two architectural helper macros and applies them to arch_get_unmapped_*: arch_get_mmap_end(addr) - get mmap upper limit depending on addr hint arch_get_mmap_base(addr, base) - get mmap_base depending on addr hint 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. Signed-off-by: Steve Capper Reviewed-by: Catalin Marinas Cc: Andrew Morton --- Changed in V4, added Catalin's reviewed by Changed in V3, commit log cleared up, explanation given for why core code change over just architectural change --- mm/mmap.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 6c04292e16a7..7bb64381e77c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2066,6 +2066,15 @@ unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) return gap_end; } + +#ifndef arch_get_mmap_end +#define arch_get_mmap_end(addr) (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. * @@ -2085,8 +2094,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, struct mm_struct *mm = current->mm; struct vm_area_struct *vma, *prev; struct vm_unmapped_area_info info; + const unsigned long mmap_end = arch_get_mmap_end(addr); - if (len > TASK_SIZE - mmap_min_addr) + if (len > mmap_end - mmap_min_addr) return -ENOMEM; if (flags & MAP_FIXED) @@ -2095,7 +2105,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, if (addr) { addr = PAGE_ALIGN(addr); vma = find_vma_prev(mm, addr, &prev); - if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && + if (mmap_end - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vm_start_gap(vma)) && (!prev || addr >= vm_end_gap(prev))) return addr; @@ -2104,7 +2114,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, info.flags = 0; info.length = len; info.low_limit = mm->mmap_base; - info.high_limit = TASK_SIZE; + info.high_limit = mmap_end; info.align_mask = 0; return vm_unmapped_area(&info); } @@ -2124,9 +2134,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, struct mm_struct *mm = current->mm; unsigned long addr = addr0; struct vm_unmapped_area_info info; + const unsigned long mmap_end = arch_get_mmap_end(addr); /* requested length too big for entire address space */ - if (len > TASK_SIZE - mmap_min_addr) + if (len > mmap_end - mmap_min_addr) return -ENOMEM; if (flags & MAP_FIXED) @@ -2136,7 +2147,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, if (addr) { addr = PAGE_ALIGN(addr); vma = find_vma_prev(mm, addr, &prev); - if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && + if (mmap_end - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vm_start_gap(vma)) && (!prev || addr >= vm_end_gap(prev))) return addr; @@ -2145,7 +2156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; info.low_limit = max(PAGE_SIZE, mmap_min_addr); - info.high_limit = mm->mmap_base; + info.high_limit = arch_get_mmap_base(addr, mm->mmap_base); info.align_mask = 0; addr = vm_unmapped_area(&info); @@ -2159,7 +2170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, VM_BUG_ON(addr != -ENOMEM); info.flags = 0; info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = TASK_SIZE; + info.high_limit = mmap_end; addr = vm_unmapped_area(&info); }