From patchwork Tue Sep 3 23:22:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 562F2CD37A7 for ; Tue, 3 Sep 2024 23:24:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC7D08D01F7; Tue, 3 Sep 2024 19:24:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D72668D01E4; Tue, 3 Sep 2024 19:24:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC1E8D01F7; Tue, 3 Sep 2024 19:24:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9EEB98D01E4 for ; Tue, 3 Sep 2024 19:24:04 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3BEEF1609DE for ; Tue, 3 Sep 2024 23:24:04 +0000 (UTC) X-FDA: 82525007208.26.A6C7DDA Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf05.hostedemail.com (Postfix) with ESMTP id 22E1B100002 for ; Tue, 3 Sep 2024 23:24:01 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QbGQwxdq; spf=pass (imf05.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725405767; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rZM9CKTeyNtS6qKT8tvvNx4uJ3f/kEX/Cc1h11gS1T4=; b=r6WQ7oRYZzvgv0k+2iGePnd7+rVjEblkELAwFLqkZGroUBXP7YP5Ivsf0gt7zvqWaF5/St etyjPbQzhGFqf3xFaPQ4iKsRCo72Yii4fra5CcH63TXG0URUBZcOY1A2YxdjlkrvnsuO6w K8+g67fw3RhsfnBOi+lb7KDwKY+Ymsk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QbGQwxdq; spf=pass (imf05.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405767; a=rsa-sha256; cv=none; b=xiS9VVvLRFTAC8/il6G94s9PUpddxq+dNiqxEs4DqSxQ302ZQ2Tvr9Wzb1hUs/uBaEQVvQ rcvALPQrSxa7F4fIY0NwbMQ3prcm/qu304npk4Oop1VoTeDAs+oJmdygHMrff2PpNG0sJL hr/wOlompQNNVeFoqLrnXVbnM6F8yc4= Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 483LBWCG020127; Tue, 3 Sep 2024 23:23:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=r ZM9CKTeyNtS6qKT8tvvNx4uJ3f/kEX/Cc1h11gS1T4=; b=QbGQwxdqeRDyZrwon 08Bcoq7jANjXxA5hglaPpRK1L9MX6d0tZ/JpTyZM3oKAsy8PZlwxxwg/4k6dvs12 4OEPr+BCpgq6TIMiF45Llr7ayM0NsUT15SwvIXVeLmKMnrx+1FCCiHegmZCsPSbo d8M95EWG6fuaredoa85flOrMYpC2g85hNbpQefv8oLjRPImJapNjxG9Yr+JpzuwR eI6wMBv76u12YDJY3p23Ygg1TN//uTCtXvI38uTGSvLAS8hTUZFYzTDAfxfHLW/2 pdiFKeE7Et85Q0w1WIfzF0WEBHZmcMwkHm0rC1Tu4DAqjyoRzllU8KQiG9YylynR rGhkw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41duyj27h9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:47 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483MjvRq001729; Tue, 3 Sep 2024 23:23:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnkg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:45 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfO040456; Tue, 3 Sep 2024 23:23:45 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-10; Tue, 03 Sep 2024 23:23:44 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 09/10] mm: create __do_mmap() to take an mm_struct * arg Date: Tue, 3 Sep 2024 16:22:40 -0700 Message-ID: <20240903232241.43995-10-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=735 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-GUID: tUoy6uZR4wBNfmtmw451fh63ni68XiFs X-Proofpoint-ORIG-GUID: tUoy6uZR4wBNfmtmw451fh63ni68XiFs X-Stat-Signature: 75tedfj7j3m9e455r3b8ejgjz7y6yibt X-Rspam-User: X-Rspamd-Queue-Id: 22E1B100002 X-Rspamd-Server: rspam02 X-HE-Tag: 1725405841-268990 X-HE-Meta: U2FsdG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YOZxw1KbCF/tD0E7IgSZXLAMmncGRkVCaOYb2eWWVUFwbgDcXSo6wYc3GWIADuQHS9+ZX6RqonsNsniHFKiG7HJtTY7KJeT3IDUZvUFjn9PKr5i3ggkkJ8pfrCw+hBGKIQZxnGwKJpWrBZmGNaCzVvK+IOx6NP9t66GO4kf8DTgU001EsqYOuUf+NwVK3Tisyuw7 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: List-Subscribe: List-Unsubscribe: In preparation for mapping objects into an mshare region, create __do_mmap() to allow mapping into a specified mm. There are no functional changes otherwise. Signed-off-by: Anthony Yznaga --- include/linux/mm.h | 18 +++++++++++++++++- mm/mmap.c | 12 +++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3aa0b3322284..a9afbda73cb0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3409,11 +3409,27 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, extern unsigned long mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, - struct list_head *uf); + struct list_head *uf, struct mm_struct *mm); +#ifdef CONFIG_MMU +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, + struct list_head *uf, struct mm_struct *mm); +static inline 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, + struct list_head *uf) +{ + return __do_mmap(file, addr, len, prot, flags, vm_flags, pgoff, + populate, uf, current->mm); +} +#else 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, struct list_head *uf); +#endif + extern int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool unlock); diff --git a/mm/mmap.c b/mm/mmap.c index d0dfc85b209b..4112f18e7302 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1250,15 +1250,14 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, } /* - * The caller must write-lock current->mm->mmap_lock. + * The caller must write-lock mm->mmap_lock. */ -unsigned long do_mmap(struct file *file, unsigned long addr, +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, - struct list_head *uf) + struct list_head *uf, struct mm_struct *mm) { - struct mm_struct *mm = current->mm; int pkey = 0; *populate = 0; @@ -1465,7 +1464,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, vm_flags |= VM_NORESERVE; } - addr = mmap_region(file, addr, len, vm_flags, pgoff, uf); + addr = mmap_region(file, addr, len, vm_flags, pgoff, uf, mm); if (!IS_ERR_VALUE(addr) && ((vm_flags & VM_LOCKED) || (flags & (MAP_POPULATE | MAP_NONBLOCK)) == MAP_POPULATE)) @@ -2848,9 +2847,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, unsigned long mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, - struct list_head *uf) + struct list_head *uf, struct mm_struct *mm) { - struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; struct vm_area_struct *next, *prev, *merge; pgoff_t pglen = len >> PAGE_SHIFT;