From patchwork Tue Sep 3 23:22:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789501 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 1B4FECD37A7 for ; Tue, 3 Sep 2024 23:23:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4010A8D01F5; Tue, 3 Sep 2024 19:23:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AEE88D01E4; Tue, 3 Sep 2024 19:23:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24FA88D01F5; Tue, 3 Sep 2024 19:23:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E6F228D01E4 for ; Tue, 3 Sep 2024 19:23:53 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 99ECE409EB for ; Tue, 3 Sep 2024 23:23:53 +0000 (UTC) X-FDA: 82525006746.06.0598BC1 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf13.hostedemail.com (Postfix) with ESMTP id A7D4A2000A for ; Tue, 3 Sep 2024 23:23:51 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=IhLIDQ9S; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf13.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405761; a=rsa-sha256; cv=none; b=p39WmyHGSRSl0TjTsBty+0Xb/Xk32OhXyBvFxdgiLlS1CGysXVlIzvwxpKLRpZDkmtEVcn NnHYSxfarat8BdEVe+xeA03YrgAilEy2bxtvRKsvY2ZcwcEiOr5JXM/+MlQi20sduxbGmY Xdbwd4Q6MEKmHfMqItzet6X388pZ/Hs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=IhLIDQ9S; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf13.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725405761; 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=BkNLLtEIT6PO4SxMovJKnjkv2fPS2KtWiGRrJ9D3V3g=; b=vCxQ6DRI8XTREXzKE7RdI3VqW91doj6OTMWrW5WVj3kTsatD53A5lUaT3lyhduLns0Hhmc kY9Xbmk+g/ZpWKZzhK2OZ1W6ziq/UKIQv5oNZPhU9Hfrd5SuJ7KZurR11sDy3l0WmGUk1N 03osmTV57PzEphe8W96x30tawBNqo1w= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 483LBaYt016174; Tue, 3 Sep 2024 23:23:39 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=B kNLLtEIT6PO4SxMovJKnjkv2fPS2KtWiGRrJ9D3V3g=; b=IhLIDQ9Sqp40vvnUI 34TprUtmbQDB5n4DVDKooD0xIxnA9ArOd8ofsa0o76qCbt28HkwlJP0uB5UoAFC7 0m8eVUkmeIcNKyr1gq7razbo9AzQRAf8cJab1G3VsDIu5Jxw+bzd4+Or4rORVC42 2W+FRNK6aXQ5SIQjSHZbnh0AgApvLeuLnqfpwcybtrN24+ENl0PYyHL7oATWBZYp qwanrtCEgssoDDyQeWKpv0IeHachScW6caIdbFOknj9ypQUd+I58BAUp0x5f+iSY QsvxdrWujnIVHevkLnyPYhp05xrtAC7HTNxKN5eUhG6faUsjDsOxNv1+tt9mfSoB sUexw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dvsaa54m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:39 +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 483L5Jdg001689; Tue, 3 Sep 2024 23:23:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmngn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:38 +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 483NMkfK040456; Tue, 3 Sep 2024 23:23:37 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-8; Tue, 03 Sep 2024 23:23:37 +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 07/10] mm/mshare: Add mmap support Date: Tue, 3 Sep 2024 16:22:38 -0700 Message-ID: <20240903232241.43995-8-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=999 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-ORIG-GUID: OvJ_mqh9ucxXTl96GlPjzLJ-nynAvIDN X-Proofpoint-GUID: OvJ_mqh9ucxXTl96GlPjzLJ-nynAvIDN X-Rspamd-Queue-Id: A7D4A2000A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dbt7c9cr8mgn6kqw5cumw6f9owmuigw3 X-HE-Tag: 1725405831-696018 X-HE-Meta: U2FsdGVkX1/K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BCBWulM7b/be3PbVrxcCPiNezEOA4r6tsfpiQunRUm5lVgl2mLyrFGTtI2CIO98nf1zxoO8A1ABC8pCfvkP9R5blniXmDQmQYgyru/kgVjASQTifO5u8fv5XKfzS17UnQPU+qqG2D4mteiNBj5uMNS89k1FsMW9e5uTLixdhqZnOWU/g= 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. For now, disallow partial unmaps of the region by disallowing splitting of an mshare VMA. The functionality for mapping an object into an mshare region will added in later patches. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index af46eb76d2bc..f3f6ed9c3761 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -33,6 +33,63 @@ struct msharefs_info { static const struct inode_operations msharefs_dir_inode_ops; static const struct inode_operations msharefs_file_inode_ops; +/* + * Disallow partial unmaps of an mshare region for now. Unmapping at + * boundaries aligned to the level page tables are shared at could + * be allowed in the future. + */ +static int mshare_vm_op_split(struct vm_area_struct *vma, unsigned long addr) +{ + return -EINVAL; +} + +static const struct vm_operations_struct msharefs_vm_ops = { + .may_split = mshare_vm_op_split, +}; + +/* + * 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; + unsigned long mshare_start, mshare_end; + int err = -EINVAL; + + spin_lock(&m_data->m_lock); + mshare_start = m_data->minfo.start; + mshare_end = mshare_start + m_data->minfo.size; + spin_unlock(&m_data->m_lock); + + /* + * Make sure start and end of this mshare region has + * been established already + */ + if (mshare_start == 0) + goto err_out; + + /* + * Verify alignment and size multiple + */ + if ((vma->vm_start | vma->vm_end) & (PGDIR_SIZE - 1)) + goto err_out; + + /* + * Verify this mapping does not extend outside of mshare region + */ + if (vma->vm_start < mshare_start || vma->vm_end > mshare_end) + goto err_out; + + err = 0; + vma->vm_private_data = m_data; + vm_flags_set(vma, VM_SHARED_PT); + vma->vm_ops = &msharefs_vm_ops; + +err_out: + return err; +} + static long msharefs_set_size(struct mm_struct *mm, struct mshare_data *m_data, struct mshare_info *minfo) @@ -100,6 +157,7 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) static const struct file_operations msharefs_file_operations = { .open = simple_open, + .mmap = msharefs_mmap, .unlocked_ioctl = msharefs_ioctl, .llseek = no_llseek, };