From patchwork Wed Aug 29 12:45:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10580281 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 D2BB7174A for ; Wed, 29 Aug 2018 12:46:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C34372B031 for ; Wed, 29 Aug 2018 12:46:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7D442B037; Wed, 29 Aug 2018 12:46:16 +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,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1FBBD2AFB5 for ; Wed, 29 Aug 2018 12:46:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=KWzyckf2Rcbay4cjgpQjq1sagR/XNbTtn9lZSd9jgmY=; b=guZAQCtenFQC8Mr8Dd4u+tvxhZ 9sNPItTwcwb73ciRQ3/0SFeTRR1LPe1TVZrLuLgt1FN9dRifw3CprSLxADLCcUI26zBsUVRK8look hVD0qPyxAX4bostfn9VT5rysmgGzVj9EZFGKh/7c2a8to4ifa/5ywEPes3hJnrAXUuL19RlkOOAxz IL07eQrrV4grBFHpVl0iXN7KRqxELa7ayRBCiMpov532k+WhF5bSqDRFKdu0riRFvI+XI2sFU7bBL VmARfHte5j5Bi3oXe9oK98qGDtCuss3xkGK7VpqUlViD2FSRIkeRRSePHmAdCJTPlrmII/5BNXmeK mKNtRUkA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fuzrJ-00059F-LX; Wed, 29 Aug 2018 12:46:05 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fuzrF-00056s-TA for linux-arm-kernel@lists.infradead.org; Wed, 29 Aug 2018 12:46:03 +0000 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 89B861684; Wed, 29 Aug 2018 05:45:55 -0700 (PDT) Received: from capper-debian.arm.com (unknown [10.37.12.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 77ABA3F5BC; Wed, 29 Aug 2018 05:45:54 -0700 (PDT) From: Steve Capper To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/5] arm64: mmap: Allow for "high" 52-bit VA allocations Date: Wed, 29 Aug 2018 13:45:42 +0100 Message-Id: <20180829124543.25314-5-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180829124543.25314-1-steve.capper@arm.com> References: <20180829124543.25314-1-steve.capper@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180829_054602_062272_5D399DBF X-CRM114-Status: GOOD ( 14.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch alters arch_get_unmapped_area and arch_get_unmapped_area_topdown such that mmap calls with an addr parameter that lie above 48-bit VAs will receive a VA that lies within the 52-bit VA space on systems that support it. Signed-off-by: Steve Capper --- arch/arm64/mm/mmap.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index b516e0bfdb71..827414b69866 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -81,6 +81,15 @@ static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) extern unsigned long mmap_min_addr; +static unsigned long get_end_address(unsigned long addr) +{ + if (IS_ENABLED(CONFIG_ARM64_TRY_52BIT_VA) && + (addr > DEFAULT_MAP_WINDOW)) + return TASK_SIZE; + else + return DEFAULT_MAP_WINDOW; +} + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) @@ -88,8 +97,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; + unsigned long end = get_end_address(addr); - if (len > TASK_SIZE - mmap_min_addr) + if (len > end - mmap_min_addr) return -ENOMEM; if (flags & MAP_FIXED) @@ -98,7 +108,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 (end - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vm_start_gap(vma)) && (!prev || addr >= vm_end_gap(prev))) return addr; @@ -107,7 +117,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 = end; info.align_mask = 0; return vm_unmapped_area(&info); } @@ -121,9 +131,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; + unsigned long end = get_end_address(addr); /* requested length too big for entire address space */ - if (len > TASK_SIZE - mmap_min_addr) + if (len > end - mmap_min_addr) return -ENOMEM; if (flags & MAP_FIXED) @@ -133,7 +144,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 (end - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vm_start_gap(vma)) && (!prev || addr >= vm_end_gap(prev))) return addr; @@ -143,6 +154,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit = max(PAGE_SIZE, mmap_min_addr); info.high_limit = mm->mmap_base; + if (IS_ENABLED(CONFIG_ARM64_TRY_52BIT_VA) && (addr > DEFAULT_MAP_WINDOW)) + info.high_limit += TASK_SIZE - DEFAULT_MAP_WINDOW; + info.align_mask = 0; addr = vm_unmapped_area(&info); @@ -156,7 +170,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 = end; addr = vm_unmapped_area(&info); }