From patchwork Thu Dec 6 22:50:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10717147 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 24FE01759 for ; Thu, 6 Dec 2018 22:51:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1601D2EDAE for ; Thu, 6 Dec 2018 22:51:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13FBE2F034; Thu, 6 Dec 2018 22:51:02 +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 7B0892EDAE for ; Thu, 6 Dec 2018 22:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 543086B7CAA; Thu, 6 Dec 2018 17:51:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F1626B7CB0; Thu, 6 Dec 2018 17:51:00 -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 3930D6B7CB4; Thu, 6 Dec 2018 17:51:00 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by kanga.kvack.org (Postfix) with ESMTP id 0BFF86B7CAA for ; Thu, 6 Dec 2018 17:51:00 -0500 (EST) Received: by mail-ot1-f72.google.com with SMTP id w24so903490otk.22 for ; Thu, 06 Dec 2018 14:51:00 -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=Ebe2HbBTEkV6saSoL6QuE5CcRfNWKD6N4iGYrFYyxckt942fKio4yDpOx881ahggZc MGBpwVeFkxMJlYtJXl+pg7ajgTgdEYhpG6fcAcPnppTI43TXChpmh60cc3kgmyt36Hw1 D9B0nasiNgjsqCcUMYtP4tRkEoyBZVGhgrnqeVrZPHSmkT2RNZDbX/71adQwkAGZ81P+ yOnOTCHulaztrZwF9MC43941HtxIaNZ84QlkzDaR3PbiN/W/V+1MLXHNeGzy1z61e1/z gWLfdc+8loxLFu6kAS5w7jpAgFHaA8c0DWL9HIw81xyuKUi24pN1AEEq3ORa2W69I53D jtpA== 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+aEWY0uFcJVzzKDo/gbjcTnqz7517U7BHNqaJSVM7QdSIUmjJTuhZ+ vjVMGNS8g+td7wyEAWhSbGFzojxphuD6r7y0lmmyPajXcqXoNlRObcKNt4j3nK+Z62dILoxiKVF ty1oIG6u+3tCpOw7zwl2fNWbJRBJLBHdnfsOu5r3vC+Vb9q9YhhyWgD353sqCbifCPQ== X-Received: by 2002:aca:3209:: with SMTP id y9mr1746987oiy.198.1544136659777; Thu, 06 Dec 2018 14:50:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/VqKVriWDL5pBg+DqhTETePvMKduk8RE3hEtQHeU8jRTF22/gHK1dAmXyyEvCVzYF0T0BZA X-Received: by 2002:aca:3209:: with SMTP id y9mr1746952oiy.198.1544136658562; Thu, 06 Dec 2018 14:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544136658; cv=none; d=google.com; s=arc-20160816; b=C9cDqtYCeD2bH4p0m/5B0okTmokSm+g7HtdyPlgw9O6hD1bgKddHNm3lcDFopWXZ3c Uv36GFF6gnll2V3OpHnz0s1D0PVhhLaBIDjrlLrQ5ja9HhvBbIIXpYT68ACb8kAp98Ob rStOCe5G1IGlZRNS6g4rUgnN/BhruRfLSfv1tswKw68Xv5Mpwb3Tsk741zbCeINDNine Ucz0ZV88ddjQMnvCa0KlYfkFjI4SzrncmxjxN2aCepmOrXxC0rDOenPJe1Daxqo62vkg JlhhWBCZOwWNSAPnhZAnkBgakKsz/203Gle3Gwg05jORLqXSLcEIIapv438w9x53aDXg PaCQ== 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=0d6DTwVh4i8VEWW+LlXgaEbAAdE9KmCS8fQzRea5wQEFz0For/tmBia6SeHSwg8Ois 6o4okrROFpIlfG5ERq2NgSUOJkub5s+/cHkArh32ODL/N8VrQ604w+bchrN36to59sLh sKk4kdSDPwYWrSrcNUwvGpS0yBFwuaWJlYxeqRgpbJ2LW3E5r/9J+O8M5YQLMgjb0eAz aeRLndfcm/l4mnFW4rGadjykU0+xBZD6AfeTot0rj+UngY+82ZEE9jRp/6fsVumKQFqS 5IMLJT9P8Z9mRmt6S7KoJ4WzkE5JleN3Q2QxxJrhpQM8pv2QsP2GPUsKPsL2mZQ3otJL EmGQ== 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 l14si640637oie.139.2018.12.06.14.50.58 for ; Thu, 06 Dec 2018 14:50:58 -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 DBB3015AB; Thu, 6 Dec 2018 14:50:57 -0800 (PST) Received: from capper-debian.arm.com (unknown [10.37.12.92]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2B5193F5AF; Thu, 6 Dec 2018 14:50:56 -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, suzuki.poulose@arm.com, jcm@redhat.com, Steve Capper , Andrew Morton Subject: [PATCH V5 1/7] mm: mmap: Allow for "high" userspace addresses Date: Thu, 6 Dec 2018 22:50:36 +0000 Message-Id: <20181206225042.11548-2-steve.capper@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206225042.11548-1-steve.capper@arm.com> References: <20181206225042.11548-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 Acked-by: 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); }