From patchwork Wed Oct 17 16:34:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10645899 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 82C29157A for ; Wed, 17 Oct 2018 16:35:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 715BB28478 for ; Wed, 17 Oct 2018 16:35:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 650AC286FC; Wed, 17 Oct 2018 16:35:27 +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 DA3A428478 for ; Wed, 17 Oct 2018 16:35:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD5FC6B0269; Wed, 17 Oct 2018 12:35:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A83DF6B026A; Wed, 17 Oct 2018 12:35:25 -0400 (EDT) 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 973E46B026B; Wed, 17 Oct 2018 12:35:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by kanga.kvack.org (Postfix) with ESMTP id 6CA7C6B0269 for ; Wed, 17 Oct 2018 12:35:25 -0400 (EDT) Received: by mail-oi1-f198.google.com with SMTP id u205-v6so2039130oie.5 for ; Wed, 17 Oct 2018 09:35:25 -0700 (PDT) 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=he7mJPA42CmiW0otUgvDEJIlYTU7T3zkFrzC6QrbR8A=; b=RQ1+iAUuV3YHlB+yGJP3T+Nu5KTInRvzBit+y9IjIfwUP6DaIVVahz4g0f44aVanAe P3qj7wOvwdLDaECwAoA2g6iVt+i0VuS3rRdJXZaJ3df30dcxNBZ7NwDpt5gAostBWA3A MkVaxkef76hRMzurN3CRbUEGOWMQBoRHd/wtJGkb+se39zmLXyPhAgiixuSp2eR/DojU tS422svXE7qV90OQZb8NyyLZDTGW4kadQXH3nonrRINWIdw2uqqoCv0t/DC2NMGQDn+L sdRQCCJg92PkvFBzuR+z8Okk2KNYSjtNWFk1Gj+EDxbX8VH6I+63hnxHFq5/IBqqJ6ig Ty6g== 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: ABuFfoiEqbcbRgQoEQPFsqQsKh+nH4+NfRiBAEef5Y+yFJLrsoNuK3i1 hOHeRcPfrDR5Q1gfT8XHmsQN2p50fYRr2VDtVSyWU7x5kyeDGopgEgElYfxoWC1JivzCKo91xVh 9BZc6i6/kZaeJhK0233DdSj4wQ92IlK7drQ0/yHiFFdjtBYDocW9gmmr3QpFjgM7cqg== X-Received: by 2002:a9d:faa:: with SMTP id d39mr17579812otd.277.1539794125183; Wed, 17 Oct 2018 09:35:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV61+/Y4lWCnc6t585DSCtD3v0JZphlSyXXaNYJoWzplH+yaQb5sNI7XbYqNAMunupu6zrYIb X-Received: by 2002:a9d:faa:: with SMTP id d39mr17579772otd.277.1539794124357; Wed, 17 Oct 2018 09:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539794124; cv=none; d=google.com; s=arc-20160816; b=NeFozbYv3EK9jFS42of5OWAlB0uDziQgH++y18cz7OG4NGMusIyUTlrTKfwDKHRnRC 7QWcVRTiA4+lyc8v7eoBvZkM42/vSWvxgsfZZiws0JCCzskbFGmsTjylFfOm4uMoA0dx UHfQ6vhxz1e/HQxL/hqbMJzZ9xPZXFZQA5YR1r9NjiA8IvPfU5diVJNItKQIGeMQi6im PPceqRETLxJip17pbaLiLODDruTolUbDKzH7MBTLNJAtjpNVjToKMkx/jB8TgBUl6aIH fgQ+1drqJ4Q1Ok6KRJzWuSkUm+N8x0DY0rw2FbgQkkiRpXIPDI+JqPQQsKA8/lEc97jn +V+Q== 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=he7mJPA42CmiW0otUgvDEJIlYTU7T3zkFrzC6QrbR8A=; b=vl838N4wQMV84DlNexLVRf490QVQ/1h+PR/vo7zlSL2BM8UAyVn/NKuFKrEYYj+QGN +KEbvJEoQZRsxUZ0TztZ66wrQ1UrMX6puJA9TCEe8BC0UO3Ctkbp9ZNebuafPYirss5N NtZve5gxXDPcDshKdlsoG5KmycTPJmJSmKiuejFWL4fm6uIXsDZltOUmP1ID8U5R0n+X 5JYpZhCWXuot9kjbBsnizEyihcmq0aBifMfZKJOfgUxlP/x++QLphAm4XQft5ZlGbk0I X/prgwKX1OVSdifS2MTvn0QwRoaDpd5b08PA/p2p0JwBZe14sRILTr6LsWjvdz2P88GK Vuqg== 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 (usa-sjc-mx-foss1.foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id q185-v6si8023443oia.57.2018.10.17.09.35.24 for ; Wed, 17 Oct 2018 09:35:24 -0700 (PDT) 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 A4839EBD; Wed, 17 Oct 2018 09:35:23 -0700 (PDT) Received: from capper-debian.emea.arm.com (unknown [10.32.102.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 674D13F71A; Wed, 17 Oct 2018 09:35:22 -0700 (PDT) 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 V2 1/4] mm: mmap: Allow for "high" userspace addresses Date: Wed, 17 Oct 2018 17:34:56 +0100 Message-Id: <20181017163459.20175-2-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181017163459.20175-1-steve.capper@arm.com> References: <20181017163459.20175-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). Rather than duplicate the arch_get_unmapped_* stock implementations, 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 --- Changed in V2, these alterations are made to mm/mmap.c rather than copied over to arch/arm64 and modified there. --- mm/mmap.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 5f2b2b184c60..396b8ae12783 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2042,6 +2042,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. * @@ -2061,8 +2070,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) @@ -2071,7 +2081,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; @@ -2080,7 +2090,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); } @@ -2100,9 +2110,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) @@ -2112,7 +2123,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; @@ -2121,7 +2132,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); @@ -2135,7 +2146,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); }