From patchwork Mon Mar 13 22:14:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Till Smejkal X-Patchwork-Id: 738520 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vhydp0N6Vz9s78 for ; Tue, 14 Mar 2017 13:01:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mia0fUKW"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=googlemail.com header.i=@googlemail.com header.b="jCXgItCC"; dkim-atps=neutral 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=QmY9lAJoEa+bAackFTmTQ5hI9bUXDR+or4NhFXQz1mw=; b=mia0fUKWQiiu4meJpe//Vjkf8C KpCBOyZsXUZC/6ZmUMvU/MRAbJ3V5vyg/jgB6v3f9OzkcpqAFAUblRpIgQrQ9ZiNF5YcSrE9B3AoO YpR3uYPQGwc4jhbFKJI1ti+ADeafprMt8mB+HB4VejENVBgm/Zpk8m5CGKo/9M19vbMHtC3rkWyJv LqhtYnuEuzSYbQjqmabKXZ3CQpkmA6PKKIEK+VwFlTx0qSDfAmpSEi4WelDQbmcg+wlzRGEPCzRWJ 6SWzi11Uq01hbTqV8i/T/lHpY6LLOhgH6nxV13HwmguXKuu3AO2OEPi2moPs1dENiazju83I/Zlhz tlvAnglQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cnbmG-00069f-2m; Tue, 14 Mar 2017 02:01:32 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cnYEn-0001dX-97; Mon, 13 Mar 2017 22:14:49 +0000 Received: by mail-wm0-x244.google.com with SMTP id n11so12117029wma.0; Mon, 13 Mar 2017 15:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S0upfSdZufs1E8OQBrpOcxd5FLskulElvUhgO1Wl3wU=; b=jCXgItCCNfcmySMt1lzfCoLn7OmnJyWkm3cFsRYC2K8Ij9+56VoOhMDBHnNudHZFb+ FM31o9mmQYMtWqyjd5aF2lz1B83kwkUc57uo2NqTlMRN2gmxZKyT1AX8wmomL8DHu+gQ wKLtXB4/StVo+nbdmgFrVt5lLwHCdEDFtPxLbZu5km46xqrUGcpp2cGVDxWEXbnQ7/1V DihZ8qpJw8yC4a6ixN4YTJYq5p4Ifc2uhLSMcgW5+xL5FIkwn8I8oeCHwyNntS1CWqtH rZqPvsyyF4ZTAgdVhzqFWfbSuc5uNI9/FSsIUsbc0l4fnDTjlTywa3JrI9SwT9jdTeXc DWtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S0upfSdZufs1E8OQBrpOcxd5FLskulElvUhgO1Wl3wU=; b=nG+F/h5yGpKY0SsMQPX6woJIDUFxa2dMa8Ekl6GieG/+dqAIZan9xytA7eevlX0Ruo sU72nCjKfjY42GzxpOxMHqvc8uhlntmlNODaMB6Suzs85RyBYdocb4W8Ipq44xkKc5WK A+ByaXyicewa/PU5sDgfHcKsrjGEQqhOzi+65Y0AgE1kcVzlP0yqQJJaNU2NJFMIXVhW SwLwt8O9iU4lBhaDmXsHQldc8hLMt/wVUautKLzlGgnx7Wo9GrDFSbjxnf2p4OSK7Gsb FZEzxaJ1oP60barFVVEtsCLDYHgQzEjaHK7h3X8TGKrNHOIcV4fN1wu3vZ7wt49/iqSy sm5g== X-Gm-Message-State: AFeK/H2tQZET/m3Q1dQWwe3BD9fkIebreEJQjl1jVGY2UFNykMw+7oDDh6mrcJBMUNr6Nw== X-Received: by 10.28.203.204 with SMTP id b195mr12636968wmg.51.1489443266680; Mon, 13 Mar 2017 15:14:26 -0700 (PDT) Received: from localhost (login1.zih.tu-dresden.de. [141.76.16.140]) by smtp.googlemail.com with ESMTPSA id k8sm26453956wre.19.2017.03.13.15.14.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Mar 2017 15:14:26 -0700 (PDT) From: Till Smejkal X-Google-Original-From: Till Smejkal To: Richard Henderson , Ivan Kokshaysky , Matt Turner , Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Steven Miao , Richard Kuo , Tony Luck , Fenghua Yu , James Hogan , Ralf Baechle , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Martin Schwidefsky , Heiko Carstens , Yoshinori Sato , Rich Felker , "David S. Miller" , Chris Metcalf , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Andy Lutomirski , Chris Zankel , Max Filippov , Arnd Bergmann , Greg Kroah-Hartman , Laurent Pinchart , Mauro Carvalho Chehab , Pawel Osciak , Marek Szyprowski , Kyungmin Park , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Cyrille Pitchen , Felipe Balbi , Alexander Viro , Benjamin LaHaise , Nadia Yvette Chambers , Jeff Layton , "J. Bruce Fields" , Peter Zijlstra , Hugh Dickins , Arnaldo Carvalho de Melo , Alexander Shishkin , Jaroslav Kysela , Takashi Iwai Subject: [RFC PATCH 02/13] mm: Add mm_struct argument to 'do_mmap' and 'do_mmap_pgoff' Date: Mon, 13 Mar 2017 15:14:04 -0700 Message-Id: <20170313221415.9375-3-till.smejkal@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170313221415.9375-1-till.smejkal@gmail.com> References: <20170313221415.9375-1-till.smejkal@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170313_151445_704498_D1389779 X-CRM114-Status: GOOD ( 17.02 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:244 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (till.smejkal[at]googlemail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Mailman-Approved-At: Mon, 13 Mar 2017 19:01:29 -0700 X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mips@linux-mips.org, alsa-devel@alsa-project.org, linux-ia64@vger.kernel.org, linux-aio@kvack.org, linux-mm@kvack.org, linux-mtd@lists.infradead.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-media@vger.kernel.org, linux-xtensa@linux-xtensa.org, adi-buildroot-devel@lists.sourceforge.net, linux-metag@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-parisc@vger.kernel.org, linux-api@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-fsdevel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add to the 'do_mmap' and 'do_mmap_pgoff' functions the mm_struct they should operate on as additional argument. Before, both functions simply used the memory map of the current task. However, with the introduction of first class virtual address spaces, these functions also need to be usable for other memory maps than just the one of the current process. Hence, explicitly define during the function call which memory map to use. Signed-off-by: Till Smejkal --- arch/x86/mm/mpx.c | 4 ++-- fs/aio.c | 4 ++-- include/linux/mm.h | 11 ++++++----- ipc/shm.c | 3 ++- mm/mmap.c | 16 ++++++++-------- mm/nommu.c | 7 ++++--- mm/util.c | 2 +- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/arch/x86/mm/mpx.c b/arch/x86/mm/mpx.c index af59f808742f..99c664a97c35 100644 --- a/arch/x86/mm/mpx.c +++ b/arch/x86/mm/mpx.c @@ -50,8 +50,8 @@ static unsigned long mpx_mmap(unsigned long len) return -EINVAL; down_write(&mm->mmap_sem); - addr = do_mmap(NULL, 0, len, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, VM_MPX, 0, &populate); + addr = do_mmap(mm, NULL, 0, len, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, VM_MPX, 0, &populate); up_write(&mm->mmap_sem); if (populate) mm_populate(addr, populate); diff --git a/fs/aio.c b/fs/aio.c index 873b4ca82ccb..df9bba5a2aff 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -510,8 +510,8 @@ static int aio_setup_ring(struct kioctx *ctx) return -EINTR; } - ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size, - PROT_READ | PROT_WRITE, + ctx->mmap_base = do_mmap_pgoff(current->mm, ctx->aio_ring_file, 0, + ctx->mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, 0, &unused); up_write(&mm->mmap_sem); if (IS_ERR((void *)ctx->mmap_base)) { diff --git a/include/linux/mm.h b/include/linux/mm.h index fa483d2ff3eb..fb11be77545f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2019,17 +2019,18 @@ extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned lo extern unsigned long mmap_region(struct mm_struct *mm, struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff); -extern unsigned long do_mmap(struct file *file, unsigned long addr, - unsigned long len, unsigned long prot, unsigned long flags, - vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate); +extern unsigned long do_mmap(struct mm_struct *mm, struct file *file, + unsigned long addr, unsigned long len, unsigned long prot, + unsigned long flags, vm_flags_t vm_flags, unsigned long pgoff, + unsigned long *populate); extern int do_munmap(struct mm_struct *, unsigned long, size_t); static inline unsigned long -do_mmap_pgoff(struct file *file, unsigned long addr, +do_mmap_pgoff(struct mm_struct *mm, struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long pgoff, unsigned long *populate) { - return do_mmap(file, addr, len, prot, flags, 0, pgoff, populate); + return do_mmap(mm, file, addr, len, prot, flags, 0, pgoff, populate); } #ifdef CONFIG_MMU diff --git a/ipc/shm.c b/ipc/shm.c index 81203e8ba013..64c21fb32ca9 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1222,7 +1222,8 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr, goto invalid; } - addr = do_mmap_pgoff(file, addr, size, prot, flags, 0, &populate); + addr = do_mmap_pgoff(mm, file, addr, size, prot, flags, 0, + &populate); *raddr = addr; err = 0; if (IS_ERR_VALUE(addr)) diff --git a/mm/mmap.c b/mm/mmap.c index 5ac276ac9807..70028bf7b58d 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1299,14 +1299,14 @@ static inline int mlock_future_check(struct mm_struct *mm, } /* - * The caller must hold down_write(¤t->mm->mmap_sem). + * The caller must hold down_write(&mm->mmap_sem). */ -unsigned long do_mmap(struct file *file, unsigned long addr, - unsigned long len, unsigned long prot, - unsigned long flags, vm_flags_t vm_flags, - unsigned long pgoff, unsigned long *populate) +unsigned long do_mmap(struct mm_struct *mm, struct file *file, + unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + vm_flags_t vm_flags, unsigned long pgoff, + unsigned long *populate) { - struct mm_struct *mm = current->mm; int pkey = 0; *populate = 0; @@ -2779,8 +2779,8 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, } file = get_file(vma->vm_file); - ret = do_mmap_pgoff(vma->vm_file, start, size, - prot, flags, pgoff, &populate); + ret = do_mmap_pgoff(mm, vma->vm_file, start, size, + prot, flags, pgoff, &populate); fput(file); out: up_write(&mm->mmap_sem); diff --git a/mm/nommu.c b/mm/nommu.c index 24f9f5f39145..54825d29f50b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1198,7 +1198,8 @@ static int do_mmap_private(struct vm_area_struct *vma, /* * handle mapping creation for uClinux */ -unsigned long do_mmap(struct file *file, +unsigned long do_mmap(struct mm_struct *mm, + struct file *file, unsigned long addr, unsigned long len, unsigned long prot, @@ -1375,10 +1376,10 @@ unsigned long do_mmap(struct file *file, /* okay... we have a mapping; now we have to register it */ result = vma->vm_start; - current->mm->total_vm += len >> PAGE_SHIFT; + mm->total_vm += len >> PAGE_SHIFT; share: - add_vma_to_mm(current->mm, vma); + add_vma_to_mm(mm, vma); /* we flush the region from the icache only when the first executable * mapping of it is made */ diff --git a/mm/util.c b/mm/util.c index 3cb2164f4099..46d05eef9a6b 100644 --- a/mm/util.c +++ b/mm/util.c @@ -302,7 +302,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, if (!ret) { if (down_write_killable(&mm->mmap_sem)) return -EINTR; - ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff, + ret = do_mmap_pgoff(mm, file, addr, len, prot, flag, pgoff, &populate); up_write(&mm->mmap_sem); if (populate)