From patchwork Tue Sep 3 23:22:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789498 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 5F8D2CD37A7 for ; Tue, 3 Sep 2024 23:23:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9D8D8D01F2; Tue, 3 Sep 2024 19:23:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CAEC08D01E4; Tue, 3 Sep 2024 19:23:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B523B8D01F2; Tue, 3 Sep 2024 19:23:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8B9FD8D01E4 for ; Tue, 3 Sep 2024 19:23:45 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4867040A6F for ; Tue, 3 Sep 2024 23:23:45 +0000 (UTC) X-FDA: 82525006410.04.C6BCE35 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf18.hostedemail.com (Postfix) with ESMTP id 29C7A1C0012 for ; Tue, 3 Sep 2024 23:23:42 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=gAQPAJoT; spf=pass (imf18.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=1725405729; 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=uuOxq7Oxho81S6TXP89tPlj4pEnJ7xSzH4D/ZNOwSLQ=; b=Fk1RGWtf//0dp7HocG/AEpSsdY5tHWfKh/Mygc1Giky4hhC+vV1mqSkLGWxp0Hv8LTDmx6 tM2f4sFcQMxuML9cHFpjcms7V7YieLKm/63hWghusvOPU0vkSxsEEsjZO+oCQ+u4dSuhYQ V/0tnm7stx/pqxu4eLG2wcmblo8/1qY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405729; a=rsa-sha256; cv=none; b=2lGHIcVjqnGIZTxgDr6a1M78O4Rv+TfwYtbH5IMp93UiRj8feuzmJCChwkRfyDQ7PUS59d hk9yrGow1V6+GKsSWxn4R5RUaAEe3qteBOrjzwOP1FvMZd2pcYtfOxcxMWhg8XxoPfOQZ7 udmnCFZnu3wqjI15oxpBIln19kDvRaM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=gAQPAJoT; spf=pass (imf18.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 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 483LBjM9011995; Tue, 3 Sep 2024 23:23:29 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=u uOxq7Oxho81S6TXP89tPlj4pEnJ7xSzH4D/ZNOwSLQ=; b=gAQPAJoTvI/FNK6eL sKJI7eQCB3J2OSzXrt3K+5f6N6xK/6rCTaImSwTOseMCrUUee9Kjl+4s/LcimnfB 6jzUvyH6envjvVyEPq9wbYurqjKBjUX+jWk4ssZuJbYSu5v2a/CB3YZZH2AzNi5G rTdMnWmTm/E2WSbyVmq1dQmIeqUUhc3Sh0Lo/t1DC1dsrO35TOtS3OF9YJcP597D sFL2ZioyPqpRjKJ69NNfNWCb3l+F91NAWvRZWUtmga9WacuTSECGHCRouIvT0yxi cXleAiC4b9Iip0kjFIygGETHbRayBo9Ci+b1MGO6Iy+6z4eo0RDmK/widO8FjWmx C/m3A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41duw7t6wk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:29 +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 483L2KtP001690; Tue, 3 Sep 2024 23:23:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnbr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:27 +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 483NMkfE040456; Tue, 3 Sep 2024 23:23:26 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-5; Tue, 03 Sep 2024 23:23:26 +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 04/10] mm/mshare: allocate an mm_struct for msharefs files Date: Tue, 3 Sep 2024 16:22:35 -0700 Message-ID: <20240903232241.43995-5-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=750 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: YI5SiYhe_q46H_6h3lbAj2EayvwuuRUi X-Proofpoint-ORIG-GUID: YI5SiYhe_q46H_6h3lbAj2EayvwuuRUi X-Rspamd-Queue-Id: 29C7A1C0012 X-Stat-Signature: xuzpdjhnukwnpckjqiu4d1rcb38i7j99 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725405822-544891 X-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JDE83NRc1tPMwvj5UHcve8G7pEYLqvCsYgSBhSWk6TIbDGi3AUuEziXtQ6PPapapoYYGjytmlSoJ35mkLvELVkI7JHeTt+7b+5xtc8wgyTOXHq15/B8Xk2umTOoUakpY2TuIdFAkKZw8IAhrH96LrM7sDcSw+wrOufyd9W1gezhdXx06ib7tXuQYlIVdkZ+e4T3T91+p0w/wc7erOUVeQDUouoQeob/Nr1Q87Gqw== 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: When a new file is created under msharefs, allocate a new mm_struct to be associated with it for the lifetime of the file. The mm_struct will hold the VMAs and pagetables for the mshare region the file represents. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index f718b8934cdf..a37849e724e1 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -17,6 +17,10 @@ #include #include +struct mshare_data { + struct mm_struct *mm; +}; + struct msharefs_info { struct dentry *info_dentry; }; @@ -29,11 +33,51 @@ static const struct file_operations msharefs_file_operations = { .llseek = no_llseek, }; +static int +msharefs_fill_mm(struct inode *inode) +{ + struct mm_struct *mm; + struct mshare_data *m_data = NULL; + int ret = 0; + + mm = mm_alloc(); + if (!mm) { + ret = -ENOMEM; + goto err_free; + } + + mm->mmap_base = mm->task_size = 0; + + m_data = kzalloc(sizeof(*m_data), GFP_KERNEL); + if (!m_data) { + ret = -ENOMEM; + goto err_free; + } + m_data->mm = mm; + inode->i_private = m_data; + + return 0; + +err_free: + if (mm) + mmput(mm); + kfree(m_data); + return ret; +} + +static void +msharefs_delmm(struct mshare_data *m_data) +{ + mmput(m_data->mm); + kfree(m_data); +} + static struct inode *msharefs_get_inode(struct mnt_idmap *idmap, struct super_block *sb, const struct inode *dir, umode_t mode) { struct inode *inode = new_inode(sb); + int ret; if (!inode) return ERR_PTR(-ENOMEM); @@ -46,6 +90,11 @@ static struct inode case S_IFREG: inode->i_op = &msharefs_file_inode_ops; inode->i_fop = &msharefs_file_operations; + ret = msharefs_fill_mm(inode); + if (ret) { + discard_new_inode(inode); + inode = ERR_PTR(ret); + } break; case S_IFDIR: inode->i_op = &msharefs_dir_inode_ops; @@ -141,6 +190,16 @@ static const struct inode_operations msharefs_dir_inode_ops = { .rename = msharefs_rename, }; +static void +mshare_evict_inode(struct inode *inode) +{ + struct mshare_data *m_data = inode->i_private; + + if (m_data) + msharefs_delmm(m_data); + clear_inode(inode); +} + static ssize_t mshare_info_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) @@ -158,6 +217,7 @@ static const struct file_operations mshare_info_ops = { static const struct super_operations mshare_s_ops = { .statfs = simple_statfs, + .evict_inode = mshare_evict_inode, }; static int