From patchwork Fri Jan 24 23:54:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950025 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 CC689C0218B for ; Fri, 24 Jan 2025 23:55:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 604462800AE; Fri, 24 Jan 2025 18:55:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E04C2800B2; Fri, 24 Jan 2025 18:55:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A75C2800B0; Fri, 24 Jan 2025 18:55:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DED1E2800B0 for ; Fri, 24 Jan 2025 18:55:35 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8BBE0C19F5 for ; Fri, 24 Jan 2025 23:55:35 +0000 (UTC) X-FDA: 83044005030.17.0CEEBF2 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf18.hostedemail.com (Postfix) with ESMTP id 97A0C1C000B for ; Fri, 24 Jan 2025 23:55:33 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="QY/j1Qke"; spf=pass (imf18.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=1737762933; 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=NhoD2UyohCxfveoHgDD+cR1/Lz5zOg29Zxa7SdPOnus=; b=VldAtTpIBehPyKfQonkCH5h0qNxP6vY/mx//0NjFgwnB6Gt7BkUu/DaUMa2ZFilIKlEWs8 4sn8w1+jx1xbs5VL9zvy9KrADMzKG0pdEbkO1laZmVHyBPL/hyQJmeoo/tBKvzwzvunktN b9OJv5ySQcHJ9eSED5rFjWAeMR1lKTE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="QY/j1Qke"; spf=pass (imf18.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=1737762933; a=rsa-sha256; cv=none; b=MVR8WS1llZ+qN6oi4bbd9y5thIMY/gUtGATA9sct5qcPaZM8DT0eozeiIKCrOdlp2BTQ/x vlzY2xRLDMQYljkps6/xPgA164cznWuAQ7F8U6OJdOOYIlLPvoEHXnWcRZfYzrBVji69Wf KeINpTZ34dzvNyPf57sWzs6fc9oBYbc= 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 50OIV8E3018170; Fri, 24 Jan 2025 23:55:19 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=NhoD2 UyohCxfveoHgDD+cR1/Lz5zOg29Zxa7SdPOnus=; b=QY/j1QkegXiviWjeo98nh F0qYOSLXLhPu8lHvxPBkZWcdoJTdL2kQQ5KKhw+r7FvhKfeT89mU/GBPMUJZNV3J PLsm+Z+tUfUcTvEMYs/I9TZQg/kCUageWG+NC9Ow86/c7xqZ6XfG7HIwmrRcphEF +HN9Liqi6GKNxKo2ChglsrDyGdD6jGWhUk28dqmv7mwWG6OZYzVbfs0c30TFBalR OpDG5IKFMnf11Dpt5fmN2XHOxGC1WWE47hJZcGx69mrCkjQIGSQGxoJ1wXQjKiWq zw7sr5SS7cLQITieF9uBlt92uCVh0tlWN+AiCW9hSbdu9Fwbafc5QECw6zdjIMir A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b96am96g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:18 +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 50ON3eWg036495; Fri, 24 Jan 2025 23:55:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4a7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:17 +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 50ONsxPo018051; Fri, 24 Jan 2025 23:55:16 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-5; Fri, 24 Jan 2025 23:55:16 +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 04/20] mm/mshare: allocate an mm_struct for msharefs files Date: Fri, 24 Jan 2025 15:54:38 -0800 Message-ID: <20250124235454.84587-5-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=829 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: Zg9k0kA44bw59zVgGS2FFhExNRlmmq9n X-Proofpoint-ORIG-GUID: Zg9k0kA44bw59zVgGS2FFhExNRlmmq9n X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 97A0C1C000B X-Stat-Signature: n8nprycn3ek1qupsf9645m9tfnci6xeu X-Rspam-User: X-HE-Tag: 1737762933-674495 X-HE-Meta: U2FsdGVkX1/lP491xjcjG7gGspN0HpNb4AKZwfo1UdvUF1+GgqWMwJOmGsInsYQKzk3E2JPxRaAURyoLZXMW1L/0oxoB4TAC/rlsJha/b4/PpwgZjKg58qKpWazlhR9fjk0gqq8WlU6DDGA78AIWTXUzQZmi14Uet6ju3WNiv0hCnRKWeSkIERX+oBOFkmVqRzTp4cXSho86TB4miEmPmmWZeVgxNayrkX8b/jweoqzQj5s8EQ1SNpNb/6jG4SKmRIRUETtzEdwtPahdZESqzD7o4sDH9N8pshAUZWqBazWDAo/84DEUTuf7eJzXss1KZZtXHesgeHhaXWf14dPDQEnOOl2teIV9t2UbInJCTGMhm+ahUAoa4KQgqaqRHIc74CFkBHfJ+wRdzlj3R1c3VH1PyeqKvlsSYR0AE8maC7sLwP8mfNxlSyEWfyHidFQ5k4FyogLq/v4tAO4eL8Iopi1PjZCcDH11x099214Cu2LNXDx2PRR9PLy7demRtazYy2jS1BBCqsCvPhXDyPdavVp6v6qVDHLiHzPd/tj2UiJ0u8eCTa6lmUDsGcFVYLc+0eIoqHKBMcvkE8Q1GdXNzVBd1MkgHJVlWSfra64mirpkEPk1Rgpq/xByTbWnQeylyeS0jlC7dyR/+4mPLqM91NE830LVLiOTJtdvu8gkDSBkNubN/Ko3XUpUN7wMU6RTHEvuStlWcuKajS9pBNuDyDDPBxDvka4J4KRy8Uw5bUwNSYveimjeOsmMnkyULPaEvf2JIIgatr/4C3CMTqjOXYMz9oXDk0OnBrSFDxzpueudw68pfTJKbsu+qAONRDD3pFeKmMhjBy7lgNMwn05tdObVVILHCxgOlmsJzj6S2UOMYCXYf/TKJClZZlA7yAHKJVZGZYCwJVGZPYuxZrwqxoiByHBCFHvwSoi45SrHHL1TXZCTG2p22LAdwcHFj78QAhhVsXIQMLKPKJsC0B3 2/2iaGBr 4aqvJJeRBh6a8SrgXQA+hDTeHZiXLKfQXztM3W+3H5cG4r3Vzz3S9mDIoBVWw4DnHprTguAo9bUy87bQCQEE6zJOjqmUCkxPk2VSmi3q3sfWT3pDB0WbZc8QNCV+PO9GLUPqn6IzAVxoluRgEpipxAwVrv76bpPm0ceCVWQdaxIJxejFGH59AwMvL327q9qwSMRhRIIPDL+B4E4nzP02rR9cpQZvVJh+jGBTF7xxD9hZNJAZJNq7y4vTRZHi70bbBsAwjIlBph+XySZV3onSQN39rXsIJVvMMj/WHQUORwysvR3Zik44N40y7rQ== 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 b755346da827..060292fb6a00 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -19,6 +19,10 @@ const unsigned long mshare_align = P4D_SIZE; +struct mshare_data { + struct mm_struct *mm; +}; + static const struct inode_operations msharefs_dir_inode_ops; static const struct inode_operations msharefs_file_inode_ops; @@ -26,11 +30,51 @@ static const struct file_operations msharefs_file_operations = { .open = simple_open, }; +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); @@ -43,6 +87,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; @@ -142,6 +191,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) @@ -159,6 +218,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