From patchwork Wed Nov 14 13:39:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10682649 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 9E865139B for ; Wed, 14 Nov 2018 13:39:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ECE82B4AB for ; Wed, 14 Nov 2018 13:39:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82ABA2B4D7; Wed, 14 Nov 2018 13:39:46 +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 EF0B42B4AB for ; Wed, 14 Nov 2018 13:39:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A6126B0008; Wed, 14 Nov 2018 08:39:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 255C36B000D; Wed, 14 Nov 2018 08:39:44 -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 0F6EA6B000C; Wed, 14 Nov 2018 08:39:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id D79996B0008 for ; Wed, 14 Nov 2018 08:39:43 -0500 (EST) Received: by mail-oi1-f200.google.com with SMTP id h135-v6so9221459oic.2 for ; Wed, 14 Nov 2018 05:39:43 -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; bh=x96SNRincEsQHA31onatbkti/QWr/6e+l0/n3efdPs4=; b=N8wjPnzzOJfejKDGoPCEJMWHEPb0t68kYuJ1kdi1ZfE0eqBcyplpHIZCmqF2vIdGuM XxK0CubY+t7odX1NdQnlWu7S5PWwfH5uVZglEtCBtNfVDSsALcdbARzB+gB/zMXTLsPd +G2YK+VscVWae+LYjWJ0WgreldXcnycF7AbzM80lre6NZAPmPBgQblTJSNjzyBIvrKJt T20H8tTSQuqAXGGqVaRk1Yftr/rO863ZB5Jm241/tnSeFUPzeMdsjLZRCMzXD4qX/GVP 3dS5AABGv1O/MIqgviQwflegf4cztFZbOXB6G96y8wT/pyNtW55fwkdbbKt5Uz/p53H3 JxQA== 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: AGRZ1gJBt8MzOG5ZIJND4Geezq7T+Ui4egGbLnaQLLJH9Xi08Bj9x+Mr 9HsVvxr6hdnIdaDk/Rei5vj7r0odhibXe4LYMQSz/Iw6oi0FYJYQJx0HDN7usmAehVBkvm5ZwWj 2vYsmlteinYbnx2l+WeXcqCn5zcVvsbRIEcfipfrQzRkM6prv0Pa0ULOUPJK7yNzhpA== X-Received: by 2002:a9d:59d0:: with SMTP id u16mr1101713otg.265.1542202783547; Wed, 14 Nov 2018 05:39:43 -0800 (PST) X-Google-Smtp-Source: AJdET5c/8TqEfKRKwA907Ct2IAHUzbj6V4I/9BpRAarzU0JWqM0rB9dVEH6f/TzptprbPBGHa5Rj X-Received: by 2002:a9d:59d0:: with SMTP id u16mr1101651otg.265.1542202782273; Wed, 14 Nov 2018 05:39:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542202782; cv=none; d=google.com; s=arc-20160816; b=MTb9pbqdPUb04df4Vq7wc0xDXFAtTe8Ird9jGYcRHa51uvWPwwMwMxf2j1gE3Fi8QL 3hY/3APWnanVaAV7wbwLKjA4DMaqcWuvGX56irS41iAk+4p3n8RkCi8rbjDrW7c9anRe SzLjN+o61/Id+G3/CEC0tF1YyV5qcqc64DCRztgnWF5yJCzDXioVLT0soemHyOmJljpk OYsv/N5yz/e7b57LfOC53PPpwTtlim7S3vhhis++UjxN3rAGqPIvghKFnuW5ZQB8QSdk gyRbI6AeqfEvpp+apRVkXH/YAn5MwvQxPt8VCV+lu3aV016iHyO6PGVuB3mKLWSV4A8C Q+7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=x96SNRincEsQHA31onatbkti/QWr/6e+l0/n3efdPs4=; b=gX/EknMiowsQd/g2bJvimQ4Qt6zA3gQ7nrll4IDSS2K7Eol63vK+19YeJpO3peq1M4 uCPiQgirDpYP2wG12cQzTOaGilfRm0qhRr2+QZfKEAnbXowf64gBZxprORA5ac+sOrDU EcRun7MmDyL7khM80Pp6zNc2L7Mqw5U5ClGUTx4aOZnaNHCeqvO4LP5KC6deOvfPKVu0 HCXE5rUO4WZI6UAS4SlRyLUEgzwxM6htGQcIN7RRjaZ6RlsnvqvvQneBvOZt/VU5Rf7H 9JyWONirEn8u0G8FgG8MxoYZ1zfbEgEpghJ2QoPI2MDyTqDYuxU1B9XgTIWeWtCF6v8B rB5g== 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 e3si10688097otl.176.2018.11.14.05.39.41 for ; Wed, 14 Nov 2018 05:39:42 -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 7B3CE1596; Wed, 14 Nov 2018 05:39:41 -0800 (PST) Received: from capper-debian.arm.com (unknown [10.37.12.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 241053F718; Wed, 14 Nov 2018 05:39:39 -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 Subject: [PATCH V3 1/5] mm: mmap: Allow for "high" userspace addresses Date: Wed, 14 Nov 2018 13:39:16 +0000 Message-Id: <20181114133920.7134-2-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181114133920.7134-1-steve.capper@arm.com> References: <20181114133920.7134-1-steve.capper@arm.com> 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 --- 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); }