From patchwork Fri Jan 24 23:54:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950028 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 C8097C02181 for ; Fri, 24 Jan 2025 23:55:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBABB2800B4; Fri, 24 Jan 2025 18:55:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E67B52800B0; Fri, 24 Jan 2025 18:55:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C29D22800B4; Fri, 24 Jan 2025 18:55:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9C0012800B0 for ; Fri, 24 Jan 2025 18:55:45 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4FB40C19FC for ; Fri, 24 Jan 2025 23:55:45 +0000 (UTC) X-FDA: 83044005450.09.8D3CB99 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf16.hostedemail.com (Postfix) with ESMTP id 5170C18000E for ; Fri, 24 Jan 2025 23:55:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=nbz8o9rG; spf=pass (imf16.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.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=1737762943; 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=WMU6LWuuz0sPUG0ZZmDbq73rQ3vuBHP+1rFTOp/x2RM=; b=dDSTj3ixLhSoRtFfWEj3xikvntN5zKsqP44RhsP4B/2nvSEiU/x1aif1IBeWzYg8uefE4c Jayi0vqzgMS/7C2jUEkBo12tKx1dey5kVJf6wSEWL1bqY/vkPkySNsM4+RLGeXSxcGPoNZ zzfZ24KonvMcGQ2QLhtRrbj9tln5ecE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=nbz8o9rG; spf=pass (imf16.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.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=1737762943; a=rsa-sha256; cv=none; b=lh8W4DAEV5nJRHWvcN+QnkPWXGPt5GP/844ZmEXLm1Ad5qbhUnHwYiORjqni0kmZ7jp8qv hVRdE1Gh61hN+4RdPvR4PZPgV2NjbawIKkWsOavyG76EgHbvn2bYaNtgmge+xB/aTHJ8HW bB02RiJK2Li38p9twT2lBjcyEWHLGoQ= Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50OIEkFN002187; Fri, 24 Jan 2025 23:55:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=WMU6L Wuuz0sPUG0ZZmDbq73rQ3vuBHP+1rFTOp/x2RM=; b=nbz8o9rGukImzGsDob9en 39eAIUc2+JsNnnyy1oLFl6BBl0xeOR1PcFdBkSlAA4rzc0+GhaIcJPfVnGLg/+JN Wfmcvc0WXR2fVzZRDhwPHkpPwWKxXt3mhdvCMlfd7qSDhFqmAd5qfiBojuf9+t2/ DnaUiWy3tMqp6/snf+Ooy2j3r6VSq8PQXW3LSAW9zYbTyxssN8BYDgy/WOBkWkeP Ys9AtYq4Nt3ZvDSXjD3H9k72fimLgFlPwjb5zTCe+C7nENNJvedZOE8MQ3qtKRwJ jaZdedCDLHtrPy3KxnVgcpiJ24btlclTgnD1e5hJxh1R4eHwhj+7FCVDEbEnwsn3 Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awufwwhg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:30 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMPchG036590; Fri, 24 Jan 2025 23:55:29 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4ac7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:29 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPu018051; Fri, 24 Jan 2025 23:55:28 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-8; Fri, 24 Jan 2025 23:55:27 +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, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, 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: [PATCH 07/20] mm/mshare: Add mmap support Date: Fri, 24 Jan 2025 15:54:41 -0800 Message-ID: <20250124235454.84587-8-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=765 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: kbiUWFz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fHd+2jFrc3Mr1p/VuwOop/9M9PHtK5WUI4ahQx+KkdJNKESDPCaY56GPe364PzjSGdmdXW0+GNztSLDLozNLV9NK0P5 NRG2ivSY 4HbiOIDrKEDgX5Lan9Aee041yvedfY9BTdj9C6Kz9vfVwkLnZB3K14MShaw59TMqZnZIRyCaWVgpS6vn1u2CLJ8gvVCs/fAKBlF5hqNx87ca1WkTN0XllWdzWs0+2jROPBQF80e7rkehIOQecST14ZE/YXp+DFMfkvR6MFXY3d37BmJPtuelWtPNzQZEKPsh7kD9hDf46rQSTVMZdIkj3o/+V8NPG6Q4RgOXFF7FHRIhyZqPE9j012GFKiKTQGAo8PQv6 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: From: Khalid Aziz Add support for mapping an mshare region into a process after the region has been established in msharefs. Disallow operations that could split the resulting msharefs vma such as partial unmaps and protection changes. Fault handling, mapping, unmapping, and protection changes for objects mapped into an mshare region will be done using the shared vmas created for them in the host mm. This functionality will be added in later patches. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index 056cb5a82547..529a90fe1602 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,74 @@ struct mshare_data { struct mshare_info minfo; }; +static int mshare_vm_op_split(struct vm_area_struct *vma, unsigned long addr) +{ + return -EINVAL; +} + +static int mshare_vm_op_mprotect(struct vm_area_struct *vma, unsigned long start, + unsigned long end, unsigned long newflags) +{ + return -EINVAL; +} + +static const struct vm_operations_struct msharefs_vm_ops = { + .may_split = mshare_vm_op_split, + .mprotect = mshare_vm_op_mprotect, +}; + +/* + * msharefs_mmap() - mmap an mshare region + */ +static int +msharefs_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct mshare_data *m_data = file->private_data; + + vma->vm_private_data = m_data; + vm_flags_set(vma, VM_MSHARE | VM_DONTEXPAND); + vma->vm_ops = &msharefs_vm_ops; + + return 0; +} + +static unsigned long +msharefs_get_unmapped_area(struct file *file, unsigned long addr, + unsigned long len, unsigned long pgoff, unsigned long flags) +{ + struct mshare_data *m_data = file->private_data; + struct mm_struct *mm = current->mm; + unsigned long mshare_start, mshare_size; + const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); + + mmap_assert_write_locked(mm); + + if ((flags & MAP_TYPE) == MAP_PRIVATE) + return -EINVAL; + + spin_lock(&m_data->m_lock); + mshare_start = m_data->minfo.start; + mshare_size = m_data->minfo.size; + spin_unlock(&m_data->m_lock); + + if ((mshare_size == 0) || (len != mshare_size)) + return -EINVAL; + + if (len > mmap_end - mmap_min_addr) + return -ENOMEM; + + if (addr && (addr != mshare_start)) + return -EINVAL; + + if (flags & MAP_FIXED) + return addr; + + if (find_vma_intersection(mm, mshare_start, mshare_start + mshare_size)) + return -EEXIST; + + return mshare_start; +} + static long msharefs_set_size(struct mm_struct *host_mm, struct mshare_data *m_data, struct mshare_info *minfo) @@ -94,6 +163,8 @@ static const struct inode_operations msharefs_file_inode_ops; static const struct file_operations msharefs_file_operations = { .open = simple_open, + .mmap = msharefs_mmap, + .get_unmapped_area = msharefs_get_unmapped_area, .unlocked_ioctl = msharefs_ioctl, };