From patchwork Fri Apr 4 02:18:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037987 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 204CFC3601B for ; Fri, 4 Apr 2025 02:19:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E0216B0007; Thu, 3 Apr 2025 22:19:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 617066B000E; Thu, 3 Apr 2025 22:19:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3327D6B000A; Thu, 3 Apr 2025 22:19:29 -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 020646B0006 for ; Thu, 3 Apr 2025 22:19:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 203B259544 for ; Fri, 4 Apr 2025 02:19:30 +0000 (UTC) X-FDA: 83294754900.17.2A041D5 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf23.hostedemail.com (Postfix) with ESMTP id DC43C14000B for ; Fri, 4 Apr 2025 02:19:27 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ZfgPtYYp; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf23.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.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=1743733168; 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=s3Be4h3gS8mZLGO0ggl9ZrqQVZS1VM6QgX8fGTsPeZ0=; b=phOkHXFc40qHtowc52TfCt6Rfk4oULqAI0TFKXQarZgrCZpOBrqG9xvAT6yrQCMh1ALtsJ RZrOoLJ+GOWc+WVSgKrTZ60IbvG0MVR59g7NpMV04wgore82BB6eSK+VgFSKW9BTfiSJLG 3IhPdWddXo3gdpMCW8g5vWa+XcTlidg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ZfgPtYYp; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf23.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733168; a=rsa-sha256; cv=none; b=q+C/p/NDQueg0tlvt8LJAfodPvLZxYBU1SGQgS2C3chYVGv6y8WMAlZfiwzqyTiWdcDua/ DJ3TbmS/0bGMEZn9ALpRbb272LB4I3JDd9v5KCC2sbhXm70wZRi4sRz32wjCBn+TQTurTx wZkC/XhHMaNQux0ez1+FeLRLYERtRt0= Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341N2KW003850; Fri, 4 Apr 2025 02:19:10 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=s3Be4 h3gS8mZLGO0ggl9ZrqQVZS1VM6QgX8fGTsPeZ0=; b=ZfgPtYYpoylzoJBqsSQeN LUYLNPEY9WvV+15bBaK2cB95PXsUxqWAXwZmbBT/XnmmN/N5zvfkQQ//334Y4a6w 5B0GtTjwvqIizjHEbdwyhiMvk4+uHdw90DHrzc/jOOv/3m7rxJ8yrpo2loCL1xFK PqtQcQz/DhjIMuYJsR6M3LRxQam9nSH6drJw9VyZl2WuXTU1QzkYKBrrpKsp3SPm MHVQYHHxUBNEA0vKQCsEG8gRKyChBbmmWhyw+YDQyU53+D3Cf0jea5XhXTPEgHzg lrBNzCH+KF50lCO1XMHs4dx5a1UkrdPqt/YXt0IIMFCxowfsem9GCj5Te+4aimnM g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p7sax3x5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:09 +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 5340fjJl017569; Fri, 4 Apr 2025 02:19:08 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspj8d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:08 +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 5342H8gc030074; Fri, 4 Apr 2025 02:19:07 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-2; Fri, 04 Apr 2025 02:19:07 +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: [PATCH v2 01/20] mm: Add msharefs filesystem Date: Thu, 3 Apr 2025 19:18:43 -0700 Message-ID: <20250404021902.48863-2-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: idsw14QBE2ePZgxGjKQz5K2iLCV9N4Lh X-Proofpoint-ORIG-GUID: idsw14QBE2ePZgxGjKQz5K2iLCV9N4Lh X-Rspamd-Server: rspam01 X-Stat-Signature: bibumnqhaqbx1fpp3md83xscjbr885u5 X-Rspam-User: X-Rspamd-Queue-Id: DC43C14000B X-HE-Tag: 1743733167-606833 X-HE-Meta: U2FsdGVkX19wibl9ipd+Q+FWASWv6q1GtFUDqmh5n4wXXXLeZE+uN4ccLGpivONHrb4XeTbGWmIPGUYZI4IydpGku+SxFjOuS0U0f1CKQTil1mFLxB+8B5TRDgu/ki5p9Li9sK9n1SzoTwwjwRJ/nMYzaxwhSuGeJKgc7/8AgloYq4sm6PIFudE9OXM5SzhPaEIUhf0dSc9bOkES/a7BhL41kEgtkRbXbRNbj2RlszdMnUZ1UCacR3eNatWDuQvaJRSvTYMg+OnL721suJOHYDPG9XujDIEYylN0rrE2wtaKz9ecaC9QTr+m/goPg7LnlFj3xnXm9KSeK1cwhC2DCnhf/oeHr+60w3xso+HQfQXqTb+VvPBEFIUW8IK49A/weWHubfASijzR0jwCJbIQa6HjtSI7ODZk6B7qzu6wTAQdZnGuY+pS6JqzsQuFgCzpJs6sY3n4QYjJK9p4gH5Zm660GLW78DWu9vIb+v6PrvQNeU9+bcH4RXEMKYv2wcIBKVRJ3xdx0HSbRD++Q9wivlvSBzpECL7a7QXLibKMPPKLc6yz2jrn36KMUejK/haqsMBdvilUT8yzPxnF1eMI15VYBbSlUjfs3gw/ddO5vB2yaDcpJ8wfwsfmS4ub6cZZZ2YyI9/8SVpbKICW0Vc3HYvAuKIVuC6DCaQtmhjCKLjP/0kBB69dMSFtlSQpkTIk1ni850WLjUjddq8zx6mdM2Y1MXr9XxrJzG3a9/w1VlG+u+Bx8OmId/GvYCxYX6WhK72ALz3QHc0sI+8oZz5RDpLnp6OvXmxh0Wpi2Mqh5wzOlb7edcA/YfWUpXQo7b4xARzpgNk8NVG13gdUsKa9UtcqNHtFDOLiAVbM+cLAPqvLl/kDayf31kT00wK20/0v35CHuWI13MydWDrppDvshaE0P3zZ/InPFGzVuF2WhHUeaUbJhr3A+q1c+LpAsR9mOPjXUlfQGTsU9K/uodX QatzdoQt lOZiU2m0g/XHU3lkRfTBJJZqsbduSrc+CLiI+QhdhuH6Wp6q/vXcI2iyR3VUJdgXuzQJHMJYT7sUoenHXk5ppXEgDnBkbnhkIHjWpMS1tzHgdjWLJdZpj7o8J4AMb+5vTsnDwW6EsyFa2Bt0cLjwDQd86txr8abZOVthnyjgS5VOzIrnoYxcynjPzBK2VIw3KWevc3I1k5/a1F26ZyMomeMmwB+yD80FFX3bisHVu/7zGdr43kFIfJwPbhzKuoNxbLkS+ml0VtLgQFDxvmzxBlCRHpiGheGRtqxF1 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 a pseudo filesystem that contains files and page table sharing information that enables processes to share page table entries. This patch adds the basic filesystem that can be mounted, a CONFIG_MSHARE option to enable the feature, and documentation. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- Documentation/filesystems/index.rst | 1 + Documentation/filesystems/msharefs.rst | 96 +++++++++++++++++++++++++ include/uapi/linux/magic.h | 1 + mm/Kconfig | 9 +++ mm/Makefile | 4 ++ mm/mshare.c | 97 ++++++++++++++++++++++++++ 6 files changed, 208 insertions(+) create mode 100644 Documentation/filesystems/msharefs.rst create mode 100644 mm/mshare.c diff --git a/Documentation/filesystems/index.rst b/Documentation/filesystems/index.rst index a9cf8e950b15..573d7a05dbca 100644 --- a/Documentation/filesystems/index.rst +++ b/Documentation/filesystems/index.rst @@ -101,6 +101,7 @@ Documentation for filesystem implementations. fuse-io-uring inotify isofs + msharefs nilfs2 nfs/index ntfs3 diff --git a/Documentation/filesystems/msharefs.rst b/Documentation/filesystems/msharefs.rst new file mode 100644 index 000000000000..3e5b7d531821 --- /dev/null +++ b/Documentation/filesystems/msharefs.rst @@ -0,0 +1,96 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================================================== +Msharefs - A filesystem to support shared page tables +===================================================== + +What is msharefs? +----------------- + +msharefs is a pseudo filesystem that allows multiple processes to +share page table entries for shared pages. To enable support for +msharefs the kernel must be compiled with CONFIG_MSHARE set. + +msharefs is typically mounted like this:: + + mount -t msharefs none /sys/fs/mshare + +A file created on msharefs creates a new shared region where all +processes mapping that region will map it using shared page table +entries. Once the size of the region has been established via +ftruncate() or fallocate(), the region can be mapped into processes +and ioctls used to map and unmap objects within it. Note that an +msharefs file is a control file and accessing mapped objects within +a shared region through read or write of the file is not permitted. + +How to use mshare +----------------- + +Here are the basic steps for using mshare: + + 1. Mount msharefs on /sys/fs/mshare:: + + mount -t msharefs msharefs /sys/fs/mshare + + 2. mshare regions have alignment and size requirements. Start + address for the region must be aligned to an address boundary and + be a multiple of fixed size. This alignment and size requirement + can be obtained by reading the file ``/sys/fs/mshare/mshare_info`` + which returns a number in text format. mshare regions must be + aligned to this boundary and be a multiple of this size. + + 3. For the process creating an mshare region: + + a. Create a file on /sys/fs/mshare, for example:: + + fd = open("/sys/fs/mshare/shareme", + O_RDWR|O_CREAT|O_EXCL, 0600); + + b. Establish the size of the region:: + + fallocate(fd, 0, 0, BUF_SIZE); + + or:: + + ftruncate(fd, BUF_SIZE); + + c. Map some memory in the region:: + + struct mshare_create mcreate; + + mcreate.region_offset = 0; + mcreate.size = BUF_SIZE; + mcreate.offset = 0; + mcreate.prot = PROT_READ | PROT_WRITE; + mcreate.flags = MAP_ANONYMOUS | MAP_SHARED | MAP_FIXED; + mcreate.fd = -1; + + ioctl(fd, MSHAREFS_CREATE_MAPPING, &mcreate); + + d. Map the mshare region into the process:: + + mmap(NULL, BUF_SIZE, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + e. Write and read to mshared region normally. + + + 4. For processes attaching an mshare region: + + a. Open the msharefs file, for example:: + + fd = open("/sys/fs/mshare/shareme", O_RDWR); + + b. Get the size of the mshare region from the file:: + + fstat(fd, &sb); + mshare_size = sb.st_size; + + c. Map the mshare region into the process:: + + mmap(NULL, mshare_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + 5. To delete the mshare region:: + + unlink("/sys/fs/mshare/shareme"); diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h index bb575f3ab45e..e53dd6063cba 100644 --- a/include/uapi/linux/magic.h +++ b/include/uapi/linux/magic.h @@ -103,5 +103,6 @@ #define DEVMEM_MAGIC 0x454d444d /* "DMEM" */ #define SECRETMEM_MAGIC 0x5345434d /* "SECM" */ #define PID_FS_MAGIC 0x50494446 /* "PIDF" */ +#define MSHARE_MAGIC 0x4d534852 /* "MSHR" */ #endif /* __LINUX_MAGIC_H__ */ diff --git a/mm/Kconfig b/mm/Kconfig index d3fb3762887b..e6c90db83d01 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1342,6 +1342,15 @@ config PT_RECLAIM Note: now only empty user PTE page table pages will be reclaimed. +config MSHARE + bool "Mshare" + depends on MMU + help + Enable msharefs: A ram-based filesystem that allows multiple + processes to share page table entries for shared pages. A file + created on msharefs represents a shared region where all processes + mapping that region will map objects within it with shared PTEs. + Ioctls are used to configure and map objects into the shared region. source "mm/damon/Kconfig" diff --git a/mm/Makefile b/mm/Makefile index e7f6bbf8ae5f..b32aad62589b 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -48,6 +48,10 @@ ifdef CONFIG_64BIT mmu-$(CONFIG_MMU) += mseal.o endif +ifdef CONFIG_MSHARE +mmu-$(CONFIG_MMU) += mshare.o +endif + obj-y := filemap.o mempool.o oom_kill.o fadvise.o \ maccess.o page-writeback.o folio-compat.o \ readahead.o swap.o truncate.o vmscan.o shrinker.o \ diff --git a/mm/mshare.c b/mm/mshare.c new file mode 100644 index 000000000000..f703af49ec81 --- /dev/null +++ b/mm/mshare.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Enable cooperating processes to share page table between + * them to reduce the extra memory consumed by multiple copies + * of page tables. + * + * This code adds an in-memory filesystem - msharefs. + * msharefs is used to manage page table sharing + * + * + * Copyright (C) 2024 Oracle Corp. All rights reserved. + * Author: Khalid Aziz + * + */ + +#include +#include +#include + +static const struct file_operations msharefs_file_operations = { + .open = simple_open, +}; + +static const struct super_operations mshare_s_ops = { + .statfs = simple_statfs, +}; + +static int +msharefs_fill_super(struct super_block *sb, struct fs_context *fc) +{ + struct inode *inode; + + sb->s_blocksize = PAGE_SIZE; + sb->s_blocksize_bits = PAGE_SHIFT; + sb->s_maxbytes = MAX_LFS_FILESIZE; + sb->s_magic = MSHARE_MAGIC; + sb->s_op = &mshare_s_ops; + sb->s_time_gran = 1; + + inode = new_inode(sb); + if (!inode) + return -ENOMEM; + + inode->i_ino = 1; + inode->i_mode = S_IFDIR | 0777; + simple_inode_init_ts(inode); + inode->i_op = &simple_dir_inode_operations; + inode->i_fop = &simple_dir_operations; + set_nlink(inode, 2); + + sb->s_root = d_make_root(inode); + if (!sb->s_root) + return -ENOMEM; + + return 0; +} + +static int +msharefs_get_tree(struct fs_context *fc) +{ + return get_tree_nodev(fc, msharefs_fill_super); +} + +static const struct fs_context_operations msharefs_context_ops = { + .get_tree = msharefs_get_tree, +}; + +static int +mshare_init_fs_context(struct fs_context *fc) +{ + fc->ops = &msharefs_context_ops; + return 0; +} + +static struct file_system_type mshare_fs = { + .name = "msharefs", + .init_fs_context = mshare_init_fs_context, + .kill_sb = kill_litter_super, +}; + +static int __init +mshare_init(void) +{ + int ret; + + ret = sysfs_create_mount_point(fs_kobj, "mshare"); + if (ret) + return ret; + + ret = register_filesystem(&mshare_fs); + if (ret) + sysfs_remove_mount_point(fs_kobj, "mshare"); + + return ret; +} + +core_initcall(mshare_init); From patchwork Fri Apr 4 02:18:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037986 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 EAC14C3600C for ; Fri, 4 Apr 2025 02:19:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41E9D6B0006; Thu, 3 Apr 2025 22:19:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A8066B0007; Thu, 3 Apr 2025 22:19:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 247C96B000D; Thu, 3 Apr 2025 22:19:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 02C9B6B0007 for ; Thu, 3 Apr 2025 22:19:28 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 28A4AAD2E9 for ; Fri, 4 Apr 2025 02:19:30 +0000 (UTC) X-FDA: 83294754900.14.3B209FD Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf09.hostedemail.com (Postfix) with ESMTP id 0DCA014000C for ; Fri, 4 Apr 2025 02:19:27 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="I5gkmJ/1"; spf=pass (imf09.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=1743733168; 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=ycdDJTgDlYIEQjukDNkKC68His+LWjtA3oN+O4pSL40=; b=mJqQCZvx0F5Iq8NrgpDK8XEMmFMaMr9nc4hRzJullucOWCahZHYPy6n18EJbJmRFbW67AN fULmlmTWxkRn29lYLSniEOsxopnNg0dKHMYTnWRekmBz5qa5VGFq0mDp5eaU4Ic/cenfUZ eInpId2RexJeq1KTx8J2q6kVtdzkBsg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733168; a=rsa-sha256; cv=none; b=wGS/vG9kpk07hk7Ip5f0VK1+Q3Y3QCYcmA9AL9v7nwSk/CdTddH85AX7yJEURWVa0nbp+m M18yUg51tl9E5gEDW4rZiENqWZCdXxiUFae1xfvPl9KTAPM7dsr2mIJKMA0Fq0u2zk6c/V 3EGoW/O+8eXls5BMFzdC15eKzQlWDIE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="I5gkmJ/1"; spf=pass (imf09.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 (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341N50Q018277; Fri, 4 Apr 2025 02:19:12 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=ycdDJ TgDlYIEQjukDNkKC68His+LWjtA3oN+O4pSL40=; b=I5gkmJ/1vSaakrJl85e7J aXiS6+GmZw0MrmqmdkJzCCOfcsydJu9q/8uk9+deDz3OCI1OwWfBZ8LXkWspArw+ b+uxgndtCdcyt9D+Ue8dgwCnrHBl0fTSKwGi8nt97lCjcz8Ov+GIueB8ZKvGTz4X 9xA/Wm7pQK6iXJEWy42H/ryZNuH/Nwbc2AaPqxt/aNFcON8vaAspnNmQqLLo/ew4 erfq2uJnYJj/eKicpq0sTOcz/i2UeG9/nkk/kwKL3FdT/4S3c7hV6nDF6QD2AxrC ByApYYqoDOeJdOLsJfs6tYPj1dBALQv/xNwXi/zoThky56B5YYGApUi886XVycrd g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p9dtp4mx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:12 +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 5340e3TA017325; Fri, 4 Apr 2025 02:19:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspj97-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:10 +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 5342H8ge030074; Fri, 4 Apr 2025 02:19:10 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-3; Fri, 04 Apr 2025 02:19:10 +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: [PATCH v2 02/20] mm/mshare: pre-populate msharefs with information file Date: Thu, 3 Apr 2025 19:18:44 -0700 Message-ID: <20250404021902.48863-3-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: 5EX2FvNmxhkCoLSUIS8A4xTErMV4vc5S X-Proofpoint-GUID: 5EX2FvNmxhkCoLSUIS8A4xTErMV4vc5S X-Stat-Signature: qo69awpaqcbrsuiwp41d59ripyoh4qtx X-Rspam-User: X-Rspamd-Queue-Id: 0DCA014000C X-Rspamd-Server: rspam08 X-HE-Tag: 1743733167-422427 X-HE-Meta: U2FsdGVkX1/8tjwLrNvh9SXZfOr2lEsjANgKxAEHmNS2/0YrB6ARrYjXWcpbqPRdFpVoeGWa/R22i7EaudhUN3QIrrKrb8EX7mMZzpIFKdYFmaUi6xPGuiQAxo1u2BMn8/DrDFAbn02VNEehy+ciefQueEk5fioOSsTzT6OXBuwSyxnSC/aRjNPwlJYl/TAc3HzTsp2NiK++JO99ZKZhAv4z4NYI3erMhTDaq7pDDtq8yBft6f2qkrb4XoT6T0ZNqSTAkyOYbkELn8qePN8SmP4eTRVQ93GVfI6nPimNe7O2dx3/rxAvGb3ijrWIXDVPG1/1guU4WY3Vs2mzH2l4Emp7d63XlG6K2ZknJIrNP6yHkR1KbcPMWm+7QvxwZEl2tJMSd6pt3e5RNHf+whm1NjBu4R8UBGZDOnVNpuwRYxwcFvcinmA3hiviP4RLC6lhQLWo54ghksLQVgOUNfySxlj06VTToC02vdLoI5HW6YI2QYk3zqUNwpPX5RD+A04rcMzDZPUAme3aEsqyOUgXLViIfkQtUYEtqYsjmyDIyaTSmhJh9mKuyuMfmdUiIeeqtFZ7oMkqA00We1p/YQIs+aUn1n/6nTajs0RNk8cId+Ehje2Kc9Wxu2r+AgWyR3RDekHviXHLpd0KM7OCZnr+SWvORBvm+agprrhaLYnkon1dldtCE1NuEFJgVWubPNFkOiSND6kr0UMKN+785m4Anqdhicd4Yigh9bARP/JLFqyXUOHtSMh2IrgoCYBpvC9I6NEzPM6TxNcxQejLL1ByKM1MpOCuxnDv/D/B5Ki5OYzFwHks8rVgHr0niu7h7MArShpof7ip7XZGPZBbxj5MjUrTqixm2yLArsdPGS8f+WFzs7xLO5Funl5ZP9CAEqrJ27hkd63BB8+Ky/azDM937T/tGryjeLTC5mEH3f++Z+E7rRXkTLAekJDPTuULW2yHCmFZQyAQKJ3027/qNOm 16L8kv6f 5mRZGMH4bDb0LixhfyvrRnw8QBuSgEouGUwfJ3e/tHHe2fPbPE9NCCkTbh6/gyDVySH+FNy7G0ZcGoWIkqjJPZBTv5qTJa46m9F2UAgdFSiZGc9BmAI46utRPl+ymq9DyXTlE8jddcwBZlLcLEez1CUDXIlZAvLHnl+TtzXIpauesVO1OqJPTgmjwxmXv8rSkfxH38vifruwYXg+UDvFAInsLMu7AqSwXTldABxuyGTOITiK9Rs7rSo26WiBbiIHKTIhJzK2VQHrt7T0= 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 Users of mshare need to know the size and alignment requirement for shared regions. Pre-populate msharefs with a file, mshare_info, that provides this information. For now, pagetable sharing is hardcoded to be at the PUD level. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/mm/mshare.c b/mm/mshare.c index f703af49ec81..d666471bc94b 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -17,18 +17,74 @@ #include #include +const unsigned long mshare_align = P4D_SIZE; + static const struct file_operations msharefs_file_operations = { .open = simple_open, }; +struct msharefs_info { + struct dentry *info_dentry; +}; + +static ssize_t +mshare_info_read(struct file *file, char __user *buf, size_t nbytes, + loff_t *ppos) +{ + char s[80]; + + sprintf(s, "%ld\n", mshare_align); + return simple_read_from_buffer(buf, nbytes, ppos, s, strlen(s)); +} + +static const struct file_operations mshare_info_ops = { + .read = mshare_info_read, + .llseek = noop_llseek, +}; + static const struct super_operations mshare_s_ops = { .statfs = simple_statfs, }; +static int +msharefs_create_mshare_info(struct super_block *sb) +{ + struct msharefs_info *info = sb->s_fs_info; + struct dentry *root = sb->s_root; + struct dentry *dentry; + struct inode *inode; + int ret; + + ret = -ENOMEM; + inode = new_inode(sb); + if (!inode) + goto out; + + inode->i_ino = 2; + simple_inode_init_ts(inode); + inode_init_owner(&nop_mnt_idmap, inode, NULL, S_IFREG | 0444); + inode->i_fop = &mshare_info_ops; + + dentry = d_alloc_name(root, "mshare_info"); + if (!dentry) + goto out; + + info->info_dentry = dentry; + d_add(dentry, inode); + + return 0; +out: + iput(inode); + + return ret; +} + static int msharefs_fill_super(struct super_block *sb, struct fs_context *fc) { + struct msharefs_info *info; struct inode *inode; + int ret; sb->s_blocksize = PAGE_SIZE; sb->s_blocksize_bits = PAGE_SHIFT; @@ -37,6 +93,12 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_op = &mshare_s_ops; sb->s_time_gran = 1; + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + sb->s_fs_info = info; + inode = new_inode(sb); if (!inode) return -ENOMEM; @@ -52,7 +114,9 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc) if (!sb->s_root) return -ENOMEM; - return 0; + ret = msharefs_create_mshare_info(sb); + + return ret; } static int @@ -72,10 +136,19 @@ mshare_init_fs_context(struct fs_context *fc) return 0; } +static void +msharefs_kill_super(struct super_block *sb) +{ + struct msharefs_info *info = sb->s_fs_info; + + kfree(info); + kill_litter_super(sb); +} + static struct file_system_type mshare_fs = { .name = "msharefs", .init_fs_context = mshare_init_fs_context, - .kill_sb = kill_litter_super, + .kill_sb = msharefs_kill_super, }; static int __init From patchwork Fri Apr 4 02:18:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037989 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 00DB2C3601B for ; Fri, 4 Apr 2025 02:19:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A5846B000E; Thu, 3 Apr 2025 22:19:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92EF46B0011; Thu, 3 Apr 2025 22:19:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D0B5280005; Thu, 3 Apr 2025 22:19:31 -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 54FB76B000E for ; Thu, 3 Apr 2025 22:19:31 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CB101121D0B for ; Fri, 4 Apr 2025 02:19:32 +0000 (UTC) X-FDA: 83294754984.06.6F0BF0A Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf02.hostedemail.com (Postfix) with ESMTP id B43848000F for ; Fri, 4 Apr 2025 02:19:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=kUgz0VAG; spf=pass (imf02.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=1743733170; 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=Jiiycqv5NaezAa4akWRM0oZtFs3Zbqyk8RRdDi/cYQE=; b=a9ZKExUaLiW8VmKSbM43zRNGoYjEFJNUsD9+4EMPA9+0dRdc0Qe9P2Rb+wlcNr3QFJp29p 7T2nysZXgihdKE2XuN/8Ryao/+PkbPlUMzztMdtmY7NzYv5YsRQ82xTcJK+HHffrHVuab1 RZ6W5dYesibx1pDLKLbDRPj/sfdWePE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=kUgz0VAG; spf=pass (imf02.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=1743733170; a=rsa-sha256; cv=none; b=lTTWeo5asEdzHFD3l33Bf9WEewyeMvzGnEQWQPXDao2iJtQfzzts8vU4YeKs03AQ6BoSZ8 c5R10zeJgo0VMQlgSwDwvfrMdmRYO7fMWq9e63dGiSPnHCgt4DhSxeX67lsM0z52nS0bk+ pD2gTQKgN0+dlpoiiYl/KRY3YzamHAs= Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341N2KX003850; Fri, 4 Apr 2025 02:19:18 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=Jiiyc qv5NaezAa4akWRM0oZtFs3Zbqyk8RRdDi/cYQE=; b=kUgz0VAGp7FWZz6OmUrqy d+XaVJHy5AOwRFGI6rP0IJRxEDEeP0BoWlWgkk7E/GTiIwTsFHGDB9m6BeT7VG9D pP1P4xpGi12py8FYsC3+icBQDMAHXqbyfqF7hqsFU0aeBdSUAJKqT9KMymyJNR45 nYZc3p6C8gbCvApjUgzKtCHiBDadyVGtg+w5Rmu/utTlym9bo59BMlPbdoOPoBfn +GtODKf8Rv0W2Y5ZmdkDov86aRwKi3J7y5oeZLFNWVhDS/0banOGbUgz4J5jp0Nh tex9KMV4t0kFsngj7gmSwVV70fJTDwUMIn0neOG4jQLZ7bPQ9inpOhPK0B1qOHHI A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p7sax3x8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:17 +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 5340fRNi017354; Fri, 4 Apr 2025 02:19:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjaf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:16 +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 5342H8gi030074; Fri, 4 Apr 2025 02:19:15 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-5; Fri, 04 Apr 2025 02:19:15 +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: [PATCH v2 04/20] mm/mshare: allocate an mm_struct for msharefs files Date: Thu, 3 Apr 2025 19:18:46 -0700 Message-ID: <20250404021902.48863-5-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: XffFeJm3vpyUA90a03acjGYQrghcbXqg X-Proofpoint-ORIG-GUID: XffFeJm3vpyUA90a03acjGYQrghcbXqg X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B43848000F X-Stat-Signature: ik38f4zbg3qu1rcrobdthcnffhqdyo7y X-HE-Tag: 1743733170-233358 X-HE-Meta: U2FsdGVkX19mX5vBp+JssAlWu6tupSPxuOdugBN2E8jecme3vRO2wvVrdh7mJqgkCsS+f1bjqFe9sRTLR+ynyQMDPvyMqZ/AUkJS8eqBUtFhaZcIfmDaBGLamMLaJ4Wzeif43GbKpHFN1ABnOqYb4VUKTmKU/TRVN20wisTaYilZqnhOgk7IwNhFX7WMMXoRTyrmySE5jAHl40LXpNvGQwmzmkEvaiJ9zwuyVxbt3jJp8nFWnkNSwwGnH2N64LU65iuzbyhiV2urhT1x1gvRwO1OU6Z3nMQKeHU3mo2Ddga9lIHu5mgfOU23j5jMP0+QYiiLhvFNTBIgRakqpJfMFsEJzDoi8APQ7Yh6JjohvRBWhaCKc3CaXdJBFVYz0Ls/27P5gIFrP8hGTKV3uJsVhQ3TczOCXS6iqee4qU2d16/vGSc5b6vjzhx5oEoUhT4XCF/Zncgf3e5JjPBvd4HHctFIhQv8gxIsltemUFKvLrnyOQdaWrCncway/2Z2I6KBh2dzMUEkDzFVttSkNly4M2uAf1V/WpebpfABFAvT7UKrZKmiHXHXSC33SzBH+6bXJ1ExJ3yKAT9JZsFaRbXzPUjY5QO+bkNf8zQORrWfDnnwx0kG8cm6nf349t9DpWtvV5td89aWWnL7/zvH1DakcjKSGRrgnw0L2mQu36UfM0LP+3mVmBF9j/DxVtraWGZOIM/9pSnHObiqmmqzQBD7OdgqVRdtHQvwD5JHhzrZyPDHNFwWBtOEnQr68fqWHJ+Syb0/fPAftA1F6q0BzM14eS8BSDnY6iwS+aDpy5HXelDYEwWK3Yol98Gc/BrpRtN14kgbosn2HcIdcpJQlpl28DfpQW4l2SMcwxtJHiQ2YZ6ETS7fKXW/yX2lG8CqpYdFBm3l0z1vHjtZ7UVFj/DcVj5LB+aupPw3GuHi6XfYnUhvQMyDlasgYRiIy4VarVKoq3xpw2qWOQF4pVQC4kA Us0JHEqP epB3l92alQIG0Um0nMWm+deQ3Rxz8IEEDi7tHTQX9nTQbHylcX8X5N3D6awsZhvqwrdQXJ39wfdiaI35zioDiHucqJXTHOD5ebmLyqSgrAeaSkorr1veO/SAucpjdHYxDgA3IVtvSxeesEwvQBkrxjeGKpVLMdzoExG8FJ6SKH/gad4oaFJK2O0kbd5xWJME0bdKg5ZAPt/DqdxO4sKiqI8FmvaawT54TEK/HZNv5D0nmMshjWQ2E1lCPQ1e/sXCaKt2x7E43cjfJZPIgmsMNz1zDpjvlUXg5HDpJObWcjLLNYEIZPz+t1FPzAw== 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 5d9e25da0244..551d12cb9fdb 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; @@ -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 From patchwork Fri Apr 4 02:18:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14038129 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 24B69C3601A for ; Fri, 4 Apr 2025 04:27:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A91F7280003; Fri, 4 Apr 2025 00:27:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A17D8280001; Fri, 4 Apr 2025 00:27:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B73C280003; Fri, 4 Apr 2025 00:27:17 -0400 (EDT) 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 6A6F1280001 for ; Fri, 4 Apr 2025 00:27:17 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 93348121F32 for ; Fri, 4 Apr 2025 04:27:17 +0000 (UTC) X-FDA: 83295076914.01.F82BBB1 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 4C91840005 for ; Fri, 4 Apr 2025 04:27:15 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=cxSCOxsf; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf27.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743740835; a=rsa-sha256; cv=none; b=yJBGEFaoDCm4gINVSHURsdjhsECbSPZEITTyDeKoBXW3aP1IVinvjYqR5PwOFiP7iHN384 mqgBh9RKkgwnVmqt+LpMtI4taDCCbHpo+A/5Je7ALIuVxVFHjDMUS5IEdb50gOAyXcE5He 3uZBtPQ4ddZsY2APR3wh+APc0vhEKBQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=cxSCOxsf; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf27.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.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=1743740835; 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=MGRNlHjm2NzE/Ygwoev9rb9WkAWCS/ZSx8jSVZ/ywzM=; b=n4I+1WbVwdRMRvh8tIu4LHXr6fsfyTyXrNPYYPuNFEZLblnAXDuRvIroKFe1zb/jjIJN6G +4SWGWMM7cHJCRM3JBY1EW7S/6xMqPAAMuJFzb9hkmBarJB0gd5Ycef5fJWdKjY87eQypY iD0rXYSQERly7Et07qqVQDxMQTWEBzE= 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 5341ND7v027856; Fri, 4 Apr 2025 02:19:20 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=MGRNl Hjm2NzE/Ygwoev9rb9WkAWCS/ZSx8jSVZ/ywzM=; b=cxSCOxsfTYCu7dCZHdjUY 1auFj+JrZqQERrU9rOlhlRZU/iIhe8/AqDt51WtcOo77HHNblyzS+79uDMIaLvCw 2tb0h05n+851Wz/3Ff4fj4SOYs0qEbOecahI5Wt7rpNRLcX2mOLN2Kxx3Qsgm48o 88LuB+/eDQ3gSNKPhL4AO4exixU3DQEg/Bf26j3nBKmUm/yN9TEGMA7wKueDpRW8 Anp1GRHYpP3w0oH+c67RS8aeXIhX0ijRUn/J1jaU/CeBbzj36KfcC7DUX0E3cPyk 7GW+iRxZ70ZwWKDzCg5guf6TK+KHz+PsrbfnxJRH9M3PWDhqKBn9fAbZnlGIxN// A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p7f0p1nr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:20 +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 5340Ztw7017309; Fri, 4 Apr 2025 02:19:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjb5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:18 +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 5342H8gk030074; Fri, 4 Apr 2025 02:19:18 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-6; Fri, 04 Apr 2025 02:19:17 +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: [PATCH v2 05/20] mm/mshare: add ways to set the size of an mshare region Date: Thu, 3 Apr 2025 19:18:47 -0700 Message-ID: <20250404021902.48863-6-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: 9H4YH3MygLBCUPRBRZGsso8O3POOnB6W X-Proofpoint-GUID: 9H4YH3MygLBCUPRBRZGsso8O3POOnB6W X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4C91840005 X-Stat-Signature: 7rfjdt9tkqj1m6o75i88jc9eenaxprds X-Rspam-User: X-HE-Tag: 1743740835-319346 X-HE-Meta: U2FsdGVkX1/NBoSY8SGNQp+nbV4/rRzfi1JOZ9HE7mYkwgFeo2s+MJb4IcisQQENhAmdZaFtvUSuACMFx+atqJYPQOQSViFW6z6XE1QgkvDtz9DF1MQu4q+EJ3/bZZSgJefpV7lflBFLsueeMQC9ZV3xukW4vF8Yr2V015OffN1ToiflrgOS7whz4U8r2DIoIXRNZvx4H80NCDZwX2WN/kA3kWkqndyfqu2vQkZNSZHPoS69C1+f5DNvf32ojazLErpgCUjO+NRO9Su0sAtCSeDrGEmr2SP4o/5Wx3jpCPGhBYK0hx38XoODoi/QjOfYtJlz47bn0sSwOS5vylv3T+M6KCDYIIT2kzZDGTJsZsND0/+NXXY6qYwNn56y7bD7uzMlecdcW8DPzAM5Tv8Br5bHbqnzYCU488hn5usA9JEXFzZWTcWJISTKmelhctHk6YEFbKt4NoovZ/R/xQRHtGYvdPjCOQn3l/f9XWcYdYs9BcUx/8aiys1z7og5JSnLuEYhF7m24yFTtm75duYtxnkxr77oTXMb8vFFKRyt0B6QPVnXXXjFvd/Nkg+W7m1CVUYH0aLt/KTdKO1poZ6fXqAH/+G0dA95RoXyU0CaMZNkWrLywNwE7taAMmBFSjdnI1pAwN//RaEid7/KeI+QzdG7/euyjQqDm4a7p8Zeqm6DVhfgl6JwJ6rx1OOXw7AcELwLcSi/LROOJkxEz3EeOtmZryvsVH6oxOUmczxtRvJnTwqcXbLCYqCSUgNWoO+2DHO4qesYGMsNKjzoGd9ZAxIl5/9Do96LC1LUFMTYvnHcaQs3wKtLRnAFQdM2jgoJllazML28eqASRIjXG+TryoV0UTXWoVsiyzRbIUnWcGQ37KvROY5ZV32HOGsAjurUpHcJLPuCKu5c1CcvlCtaLtyVJMc86ZbpcDv3nTyUhSrtSj1qnhBi9DYfQ/O1ycVwRp6jQt3Noefr5z/lfdq GML6azl9 Xo187IfYcNq056YrvgjKJf7LKnl9mSFJLLvDjPd8IZnyoFqDhqcEXlJZJFI2nAclw983chpPuBkvP7LNQhHgSx1Lnfk/7qistk7Sl8gfkUEZcb2nje9J1xVl+jVnr6smQDR6S+nEKBWP8n8Nw/3DQisNPZgQ/0dk+4Q+9bTA6WuD45f57FHCQlOrgNANi6vu1kIzFL/jIP1JmxSsr20PvT7oSceM85jUXBRIYhUJggnTohRwIoTgdfPjC7S+Ay7UD743VOb3XNY7n2qWxqC5nLo3DPY+1beH0rrNDZ7CIhCW8F025LXXXunlKiQ== 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: Add file and inode operations to allow the size of an mshare region to be set fallocate() or ftruncate(). Signed-off-by: Anthony Yznaga --- mm/mshare.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/mm/mshare.c b/mm/mshare.c index 551d12cb9fdb..5eed18bc3b51 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -16,18 +16,72 @@ #include #include #include +#include const unsigned long mshare_align = P4D_SIZE; +#define MSHARE_INITIALIZED 0x1 + struct mshare_data { struct mm_struct *mm; + unsigned long size; + unsigned long flags; }; +static int msharefs_set_size(struct mshare_data *m_data, unsigned long size) +{ + int error = -EINVAL; + + if (test_bit(MSHARE_INITIALIZED, &m_data->flags)) + goto out; + + if (m_data->size || (size & (mshare_align - 1))) + goto out; + + m_data->mm->task_size = m_data->size = size; + + set_bit(MSHARE_INITIALIZED, &m_data->flags); + error = 0; +out: + return error; +} + +static long msharefs_fallocate(struct file *file, int mode, loff_t offset, + loff_t len) +{ + struct inode *inode = file_inode(file); + struct mshare_data *m_data = inode->i_private; + int error; + + if (mode != FALLOC_FL_ALLOCATE_RANGE) + return -EOPNOTSUPP; + + if (offset) + return -EINVAL; + + inode_lock(inode); + + error = inode_newsize_ok(inode, len); + if (error) + goto out; + + error = msharefs_set_size(m_data, len); + if (error) + goto out; + + i_size_write(inode, len); +out: + inode_unlock(inode); + + return error; +} + static const struct inode_operations msharefs_dir_inode_ops; static const struct inode_operations msharefs_file_inode_ops; static const struct file_operations msharefs_file_operations = { .open = simple_open, + .fallocate = msharefs_fallocate, }; static int @@ -123,6 +177,32 @@ msharefs_mknod(struct mnt_idmap *idmap, struct inode *dir, return 0; } +static int msharefs_setattr(struct mnt_idmap *idmap, + struct dentry *dentry, struct iattr *attr) +{ + struct inode *inode = d_inode(dentry); + struct mshare_data *m_data = inode->i_private; + unsigned int ia_valid = attr->ia_valid; + int error; + + error = setattr_prepare(idmap, dentry, attr); + if (error) + return error; + + if (ia_valid & ATTR_SIZE) { + loff_t newsize = attr->ia_size; + + error = msharefs_set_size(m_data, newsize); + if (error) + return error; + + i_size_write(inode, newsize); + } + + setattr_copy(idmap, inode, attr); + return 0; +} + static int msharefs_create(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) @@ -177,7 +257,7 @@ msharefs_unlink(struct inode *dir, struct dentry *dentry) } static const struct inode_operations msharefs_file_inode_ops = { - .setattr = simple_setattr, + .setattr = msharefs_setattr, }; static const struct inode_operations msharefs_dir_inode_ops = { From patchwork Fri Apr 4 02:18:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037991 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 55E88C3600C for ; Fri, 4 Apr 2025 02:19:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BB8A280007; Thu, 3 Apr 2025 22:19:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44507280005; Thu, 3 Apr 2025 22:19:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26CF5280007; Thu, 3 Apr 2025 22:19:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 000E5280005 for ; Thu, 3 Apr 2025 22:19:42 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6BAF1141930 for ; Fri, 4 Apr 2025 02:19:44 +0000 (UTC) X-FDA: 83294755488.20.08AF21F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf13.hostedemail.com (Postfix) with ESMTP id 5074A2000A for ; Fri, 4 Apr 2025 02:19:42 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=kKlOLGk0; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf13.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.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=1743733182; 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=ERxbMbNvl+07Cj+9Wuvp+iaT7q1L4pPpVQOiYDgyC2I=; b=2xfgPYoDPP4FnscIbEZnooUf2QgtlRgsinpdknkZwSWvIXUDQ/F9pPBMH96P7qtszgaDQK XwamTRtIXg38W/mdYVE6v2twXfPmUYwKHy4H8AH3G0z5TEGoZjHO8w9HC+kwgE+alQbuto S+EViRidqJZbYoGrf97JExQMKOUxKOQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=kKlOLGk0; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf13.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733182; a=rsa-sha256; cv=none; b=35JiXjpymfb3gtO2OjMdMI0ZiRP8tTw05jhzsWgmSsS3tWptQKFYB+zl17lBDzmVzxQ0HJ f7mHayRCZkXr/ygXFQmjJ0rNZK5pdgSivqFPvZjzjOEjJOciqL3nMLrb7+I1g0AcSvS9QT HV4Ezl5SOEj8NUAlAamyJo98fVO09XI= Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341N2KY003850; Fri, 4 Apr 2025 02:19:23 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=ERxbM bNvl+07Cj+9Wuvp+iaT7q1L4pPpVQOiYDgyC2I=; b=kKlOLGk0hCq15sHQdr7YF FJ+gGpYRYlDa3QhxUreQtsXVZPwi78CKzQHO2+oky6un4GjA6Hzf1g98WotpaCjs Q4RAaeqWyovEO6QQFm1741D44rbTtCyUN13U86JQNrQet4tUPk6G5aGz5Ah3IXIp OZ5bDebKWoZ3aF/6iTUotD5VHa/Z+V3eUbi1F1p+NjKfrPFjg7UcakfFeZUqZSEw eElHzpO6pSIe0wPahnKOu98BSdHW7TcgGKCd7p4sikkQsrPiCirxIaIVh0kFGIi2 ghWQcWxRIJMIyckngwRUk9CdEnIt5eIk2k34P5my53MC8vqx+tSs3bNyJ6RrMxZj A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p7sax3xa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:22 +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 5340VAmN017338; Fri, 4 Apr 2025 02:19:21 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjbn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:21 +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 5342H8gm030074; Fri, 4 Apr 2025 02:19:20 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-7; Fri, 04 Apr 2025 02:19:20 +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: [PATCH v2 06/20] mm/mshare: Add a vma flag to indicate an mshare region Date: Thu, 3 Apr 2025 19:18:48 -0700 Message-ID: <20250404021902.48863-7-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: CqLOZCNIvjq0vvOwi8VweFI6kJqfrYBW X-Proofpoint-ORIG-GUID: CqLOZCNIvjq0vvOwi8VweFI6kJqfrYBW X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 5074A2000A X-Stat-Signature: 3qiqr5g7pq8sm69cc34x94h4pjsginuf X-Rspam-User: X-HE-Tag: 1743733182-819176 X-HE-Meta: U2FsdGVkX19ZnZF1ElI6VgqX8KbkjkSsiZNOlYKoOnPRuCJtqnZJIYNZRI/rtptYFFZOXKm5AJG1XahRdg5Ndu8TgJo4oYrithb19zsP4YwIfy4qLLRoOcOuIN88g6lw0DQz7EO+z1afVxQg+Mk5dgf9Rip5sqj7tIWTSdpgGnGmmJNURF/GUp4bs0R5Q9N+MBWYWljKcv1gNluE7inhGtOpKAVQhd1PMAaSU+z2MIsave1BLtN4TA+jt5AfuuGBh7IlG94z9TB/Kve3d3cvPIGR8LAVY/jHRDd3VVuqmu7tyCw9RVO+OupcK9rB027V6QH5aRrZok8wHgGn5oDhzu/Mk36TZDr1nMO7ahecMlClRIwiycXma6a2PNUbzL/FrYyUaAea5aV4lOXSig3ThzCA9tOWpwv4frQL1XewToun722Dw8GwYYGqlOHwcNviG4mAhZ5xZEkFbPOastj1nwEIeCqP8FgrKIm4/vPwi0/qEetx2Msq/3j8QUQuacOebEq6bMFdeoq9+/IDOEAWWvjjcauvb8SdjhqIpdwT0iBkf/L2FN2jlzh4K9uc4tYauMs1uCgYsjY5ZsGYQF+tRQuBcZKsPN3Hiy4HOQa+VfxzSWMgMThhEIFxQQDPUT6E7rkjIeI7BCdFl/Z8O5p5Gq9rTJ/epVsBOVDU9Hycqz1TpK3NuTEDUeuE85fSJcq87zV9kvm3j1leNQ7p3BRqidkyUXvM87miC8g+mrGzPfa3/6Gp550W+igE0rLIyakAD8zYHcHWFx+tIVbYfV5QVzmhp0a4QyEIknuIU4tQU9mJFWwyFUCsWPOzGCrIPcu9dh58IAaNVk15YdFVvMgOEg2Ce5ZlegffI+QIFvWSU4xbbdOuNCeJG7UNvBjSBC3R6oxvPE64KP5hwGAJ2eCGDzSLYyY4zEBvxugXq8cWHymJWGQ3DjgH6CDCh9bnypZfQqnxD3popvIpT59pVmR 2pZ6xFl+ nX+dHdleodp31EDoxZsBaRowN59qcQBvZBrab2d7dTSil9O7Gb0f/qqta7m+7d5htQLu/n1MgNYWX1vSl+9Hp1BQI1MgsRBCpCndwVDvnBF6lej3/ix5o2Im9U1MwIacs1QN3esw7CGGd4bXlVdNyoyVF1auXTzLM53yy1AvAJeu4IA8YiDGHY4kyHrARj0DbnsjKn372Akq8oLwcbAODsbAKYxsICvr8hmo0iHKl5NHSfKbVkckcHhJBil1UEIF9rr8N7qMMM0UpRyt9DgM32YQ3leklHbmZiQZBI9WKUXC67a5Zt+g/TSyhpGN4uI0LHn+7IvD+jx4SsPY= 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 An mshare region contains zero or more actual vmas that map objects in the mshare range with shared page tables. Signed-off-by: Khalid Aziz Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Anthony Yznaga --- include/linux/mm.h | 19 +++++++++++++++++++ include/trace/events/mmflags.h | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 778f5de6a12e..f2f9d15213ab 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -414,6 +414,13 @@ extern unsigned int kobjsize(const void *objp); #define VM_DROPPABLE VM_NONE #endif +#ifdef CONFIG_MSHARE +#define VM_MSHARE_BIT 41 +#define VM_MSHARE BIT(VM_MSHARE_BIT) +#else +#define VM_MSHARE VM_NONE +#endif + #ifdef CONFIG_64BIT /* VM is sealed, in vm_flags */ #define VM_SEALED _BITUL(63) @@ -1161,6 +1168,18 @@ static inline bool vma_is_anon_shmem(struct vm_area_struct *vma) { return false; int vma_is_stack_for_current(struct vm_area_struct *vma); +#ifdef CONFIG_MSHARE +static inline bool vma_is_mshare(const struct vm_area_struct *vma) +{ + return vma->vm_flags & VM_MSHARE; +} +#else +static inline bool vma_is_mshare(const struct vm_area_struct *vma) +{ + return false; +} +#endif + /* flush_tlb_range() takes a vma, not a mm, and can care about flags */ #define TLB_FLUSH_VMA(mm,flags) { .vm_mm = (mm), .vm_flags = (flags) } diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index 15aae955a10b..02ebd354ed55 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -202,6 +202,12 @@ IF_HAVE_PG_ARCH_3(arch_3) # define IF_HAVE_VM_DROPPABLE(flag, name) #endif +#ifdef CONFIG_MSHARE +# define IF_HAVE_VM_MSHARE(flag, name) {flag, name}, +#else +# define IF_HAVE_VM_MSHARE(flag, name) +#endif + #define __def_vmaflag_names \ {VM_READ, "read" }, \ {VM_WRITE, "write" }, \ @@ -235,6 +241,7 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \ {VM_HUGEPAGE, "hugepage" }, \ {VM_NOHUGEPAGE, "nohugepage" }, \ IF_HAVE_VM_DROPPABLE(VM_DROPPABLE, "droppable" ) \ +IF_HAVE_VM_MSHARE(VM_MSHARE, "mshare" ) \ {VM_MERGEABLE, "mergeable" } \ #define show_vma_flags(flags) \ From patchwork Fri Apr 4 02:18:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037990 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 9817BC3601A for ; Fri, 4 Apr 2025 02:19:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B7E8280006; Thu, 3 Apr 2025 22:19:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 466FE280005; Thu, 3 Apr 2025 22:19:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30595280006; Thu, 3 Apr 2025 22:19:42 -0400 (EDT) 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 130A3280005 for ; Thu, 3 Apr 2025 22:19:42 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5E75B1A1D4A for ; Fri, 4 Apr 2025 02:19:43 +0000 (UTC) X-FDA: 83294755446.28.E045C55 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf21.hostedemail.com (Postfix) with ESMTP id 61BF91C0007 for ; Fri, 4 Apr 2025 02:19:41 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=SFbf2O0a; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf21.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=1743733181; a=rsa-sha256; cv=none; b=tv181L+FpXo/9rIgadUZ8t+CPbmbyUjcnkT3JmBvfr/goPzSjOFrOXhNsUTNDRgUU4Bv32 gYnigVo68TDm5n7+g8BSmGydtuOs2qGEIvwm6548xwkSyG4d+48GLM0ZFZlnt0Vr1zzOBI ZrS9t68IMTdVkibXq68TXlBaHw6DSR8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=SFbf2O0a; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf21.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=1743733181; 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=G6bFI3MSbYckAqKa8DbmqZRRvXTFnR+psrnW0s3D10w=; b=m3qU/WGCTZ4eWqEFx/ARfalidPDbte+PPgHBkcDfVVkLPB2N9AEV+pyQtawYLItQOEpXcR agkqQOZK2h7nExjJN6nOu8Cge6UNe3TT2yb2EqSgnwRBU9JnuzoHZiXe62wTuAtAZ1B4GW o0e2oOZALg9b8qmV+lbHi1uFrte/9jU= 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 5341PCiw018034; Fri, 4 Apr 2025 02:19:24 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=G6bFI 3MSbYckAqKa8DbmqZRRvXTFnR+psrnW0s3D10w=; b=SFbf2O0apdBaReO3aXDX7 qKBUp06v+LfCXy0HNTBraJaIWnHOVxFbRMFWeDE+xWKivuPsWFd63fZ2vIRMhDod 2JI3SJ4oIX1MDPh1T251RJz02RdoXuK0L/BYn0eZm81zJXgI0bfs6qRH0tRwxoeG 1Xzx7Dol5K51BGUgsbm95Hob68Ab6UN6fz8jRdD+L7NQw709KMnaTddt/XR4TmN+ nFO8wvSdRyNl4xiN807TbZy+7jUxGlOUwKzC8oo9U23+2/N8iiOvvpOCiRHbZAxy JobYNget7etnDru2/7kUJPteFu0nv0/cyACbU3IRXFbD4gihYUyT92lgwhraJpqz Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p7n2efn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:24 +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 5340esOZ017552; Fri, 4 Apr 2025 02:19:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjbv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:23 +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 5342H8go030074; Fri, 4 Apr 2025 02:19:23 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-8; Fri, 04 Apr 2025 02:19:22 +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: [PATCH v2 07/20] mm/mshare: Add mmap support Date: Thu, 3 Apr 2025 19:18:49 -0700 Message-ID: <20250404021902.48863-8-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: qDuqjeXm7WJqgdoVZNMoI87iLLLG-uKZ X-Proofpoint-GUID: qDuqjeXm7WJqgdoVZNMoI87iLLLG-uKZ X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 61BF91C0007 X-Stat-Signature: zjcn7pn6cciumk6s3ehzs1h6ggan1gq5 X-HE-Tag: 1743733181-47010 X-HE-Meta: U2FsdGVkX19kDI+v9zbYjzQd1X0bXOThrRremN3gM8+TqIjjbfSBgxFFB2QmSC6O/MT3iRobAKUsXWCLQcz/Cii/3eXh2YGCLV+ZvQJlzkr+5ULQYp/kj43WWy1kfqDT1iP+DSaCglhWX5pxZMOP4w7ja7mA+3frklon61CbsTOuCrTLzvq41UQwG+7BgMJWMz+e1nvYMfP4/8yXilgqilBk14R/KXxxKijoulxejQ5fFZX0wToLi7ovxe7Ml72swzVFwU028umhQhUV3g9JBY9qUbHFgc8w58ZzoIZM3CYI3oDzEhUMdsm2OZrQRUNA05x0dK/+FGOnFeGFLccDaHlkY00aaq1/rnDm5QOMn8NBZNZgCY7uFVBprXsfnoCfHR4/fyvtmVUUjdNeMLwKCiQ96F8LpI0SHWrKlJuPNiLvgUrKASA9j118Z94Bn/C8joeg3pp2rl9HO7iRcNefEzMyiXOCWiW4I8qdXSD/QYWbfzY93+y+u8V38fLTXrFyo8UIFue8lXy4cftBNLeE8gQqQ1fJMOt6blCzMYWdyrEgS1zVN8zsbbmruYLpBPe+H+QRXElw/UYarAnQgPasypMG0smnDOZVBEEgk4dDOV4OUI0dtrkCrTQzAVAf3bIOSiiDw20IcFw7TQTNlL9NI4OSKtb/qk2WyXk9RC6nAz5PtD9QOGlEjfGDZhkrgXgmJAT5ux+4jo3ltAVXZwX3q6pe4mwNvPgMzfFql21l04RekgcNJ91tcXakhprd2oFtpcbu2h8qEoNzEhVLHwpuZVAXu71CDcr06Ad/Vrf+i8ODD8m3xab6QlB/JRkt57rIXQVVJ4dCVN7CDj4h8Re1naxwq+vcBA6SR7br9zTPqXeR63GRgjEI5uwQ0RC0t6yDpk6cuEInBvrS/AczNJ+SVmMC5mSgEJn0FYaxn0kGPoGnvGfAvtCn5EzpRPLbpKBD0bLNtpb95H9JzDYPiaR qoMxa2ke FILjNBv3KuzTfQWS1Q8Zz34ZmatoKdL4vOYJcMxY8G8wmauesKc+cvL0xrDMaGQ+RCvOFRCGEFjCH5l9gBj8YZh4Vwz8B3f9PTChXLCXEUDhwmmP3RLtAZaVIAjeuzZGisoWl33YKI7EvoC3UxyzloE+KDzzz7b3xcxkfQduRqs4ZAF92psAwwkZUgP/kDJIibLYJyiYdOh5GX+08EizxI0nEfO0HaI7KFTPUm6eNOMV+NX9eGmiE0dTBuV3qoegKxe8Fvx7gnNZpa4U= 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 | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/mm/mshare.c b/mm/mshare.c index 5eed18bc3b51..6bdbcfa8deea 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -15,19 +15,146 @@ #include #include +#include #include #include const unsigned long mshare_align = P4D_SIZE; +const unsigned long mshare_base = mshare_align; #define MSHARE_INITIALIZED 0x1 struct mshare_data { struct mm_struct *mm; + unsigned long start; unsigned long size; unsigned long flags; }; +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_bottomup(struct file *file, unsigned long addr, + unsigned long len, unsigned long pgoff, unsigned long flags) +{ + struct vm_unmapped_area_info info = {}; + + info.length = len; + info.low_limit = current->mm->mmap_base; + info.high_limit = arch_get_mmap_end(addr, len, flags); + info.align_mask = PAGE_MASK & (mshare_align - 1); + return vm_unmapped_area(&info); +} + +static unsigned long +msharefs_get_unmapped_area_topdown(struct file *file, unsigned long addr, + unsigned long len, unsigned long pgoff, unsigned long flags) +{ + struct vm_unmapped_area_info info = {}; + + info.flags = VM_UNMAPPED_AREA_TOPDOWN; + info.length = len; + info.low_limit = PAGE_SIZE; + info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base); + info.align_mask = PAGE_MASK & (mshare_align - 1); + addr = vm_unmapped_area(&info); + + /* + * A failed mmap() very likely causes application failure, + * so fall back to the bottom-up function here. This scenario + * can happen with large stack limits and large mmap() + * allocations. + */ + if (unlikely(offset_in_page(addr))) { + VM_BUG_ON(addr != -ENOMEM); + info.flags = 0; + info.low_limit = current->mm->mmap_base; + info.high_limit = arch_get_mmap_end(addr, len, flags); + addr = vm_unmapped_area(&info); + } + + return addr; +} + +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; + struct vm_area_struct *vma, *prev; + 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; + + if (!test_bit(MSHARE_INITIALIZED, &m_data->flags)) + return -EINVAL; + + mshare_start = m_data->start; + mshare_size = m_data->size; + + if (len != mshare_size) + return -EINVAL; + + if (len > mmap_end - mmap_min_addr) + return -ENOMEM; + + if (flags & MAP_FIXED) { + if (!IS_ALIGNED(addr, mshare_align)) + return -EINVAL; + return addr; + } + + if (addr) { + addr = ALIGN(addr, mshare_align); + vma = find_vma_prev(mm, addr, &prev); + if (mmap_end - len >= addr && addr >= mmap_min_addr && + (!vma || addr + len <= vm_start_gap(vma)) && + (!prev || addr >= vm_end_gap(prev))) + return addr; + } + + if (!test_bit(MMF_TOPDOWN, &mm->flags)) + return msharefs_get_unmapped_area_bottomup(file, addr, len, + pgoff, flags); + else + return msharefs_get_unmapped_area_topdown(file, addr, len, + pgoff, flags); +} + static int msharefs_set_size(struct mshare_data *m_data, unsigned long size) { int error = -EINVAL; @@ -81,6 +208,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, .fallocate = msharefs_fallocate, }; @@ -97,7 +226,8 @@ msharefs_fill_mm(struct inode *inode) goto err_free; } - mm->mmap_base = mm->task_size = 0; + mm->mmap_base = mshare_base; + mm->task_size = 0; m_data = kzalloc(sizeof(*m_data), GFP_KERNEL); if (!m_data) { @@ -105,6 +235,7 @@ msharefs_fill_mm(struct inode *inode) goto err_free; } m_data->mm = mm; + m_data->start = mshare_base; inode->i_private = m_data; return 0; From patchwork Fri Apr 4 02:18:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037992 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 BB978C3601B for ; Fri, 4 Apr 2025 02:19:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 116D8280009; Thu, 3 Apr 2025 22:19:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C2C0280005; Thu, 3 Apr 2025 22:19:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E81A0280008; Thu, 3 Apr 2025 22:19:43 -0400 (EDT) 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 B1365280005 for ; Thu, 3 Apr 2025 22:19:43 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3306CBB739 for ; Fri, 4 Apr 2025 02:19:45 +0000 (UTC) X-FDA: 83294755530.15.E16FCA9 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf06.hostedemail.com (Postfix) with ESMTP id 0BFA1180002 for ; Fri, 4 Apr 2025 02:19:42 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=EEveCq6A; spf=pass (imf06.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=1743733183; 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=P2XFHgeO4VsoVgQxIbbUAqjLop0i7SOFEtZvQx9+un4=; b=F7W8cj9zWZY2yL7fH9yjcX1McnpY8wFyuNGfwk+Jax0/HmqI2QrtRt9/vwJH+UIami+68k n6Ve+fwde80K/+b7pnR7NdVmTK9mPQ2OZ01CGULsNwcWtqYLhSWf/nZq9TS+nGZeFm5lhV zNsR90R+tNUPfiBdXjrey/qYoN0fMwE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=EEveCq6A; spf=pass (imf06.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=1743733183; a=rsa-sha256; cv=none; b=fjG2Y2ik9yIfOzzHXMonJEH0gzw1blpcB9l6ROaqLgzQuuErN67cNF/Q0MsREcq6syh2EJ kwlBAiXXDKwu+xZ1WhYZ0VUL/OGM4Wxap6AB/0H1sd3S2lqw6MRH4vJrxKTXqqnU9EH7z1 mtiGEpUfZZDBIW8l4EYTKLn2E4t16g8= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341N2YB018250; Fri, 4 Apr 2025 02:19:28 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=P2XFH geO4VsoVgQxIbbUAqjLop0i7SOFEtZvQx9+un4=; b=EEveCq6AMr+euQTlVS1HT YDUUD4VMHH7ZeJOrwBHdW1ZNljHVeLPDfiMlRcTMCD3h+Wq3cHHFSUTwHX6TsH7V ne6t8CIVI25Jx9uUQh1dQ1x5cV55hbzK1NnylKABXIXWwTFf21w+9/ej2OEDTScR sVpqS8Uri8pFmytEG1l9dw/VzxFqLk/tUgeHHAARRLs5uSZXH4OmTkYmQVJz1FTz bqXKxUjGrsTIfNYV2183lwK4TcTTGkG8lsIxPWPCyQxD/7TsRmeK0EFeJt3pnmhm Yzs5LFhxV/GDwHfUTgnBkOgddmapHWzHTEaYX+RNX6NtKjcS32bAnfqeENJbUqcJ g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p9dtp4n4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:27 +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 5340dfDs017355; Fri, 4 Apr 2025 02:19:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjc8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:26 +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 5342H8gq030074; Fri, 4 Apr 2025 02:19:25 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-9; Fri, 04 Apr 2025 02:19:25 +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: [PATCH v2 08/20] mm/mshare: flush all TLBs when updating PTEs in an mshare range Date: Thu, 3 Apr 2025 19:18:50 -0700 Message-ID: <20250404021902.48863-9-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: x_lMRsGn6qiH95awEN80uSxpY_3-EKKe X-Proofpoint-GUID: x_lMRsGn6qiH95awEN80uSxpY_3-EKKe X-Rspamd-Queue-Id: 0BFA1180002 X-Stat-Signature: t3rj1m9zczbjupzsyho9ooc3ib8ufqhj X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1743733182-111026 X-HE-Meta: U2FsdGVkX18wsJhhS0ch0u3UE7Q9o4zAy7RJQvsZNnNqgptScPe+1m1+cMq0dQ9oD0JN1fVh5EssibJgIZCMi1qFN95LO7CVxwSMYk9HPp6Zjlfh9FEYbRXqxE4PHg6xeCev7vB8jt9qmE5saNOEWODxi1lZVgMfr77dTQ06Ah8QNscWdqE0jNn8c+eyEkxXz/6U/8Yn20G24wGzzICip/gUhRvV0yiBgW/87dksyEfyA9466FPorQRApdkhMV4laOGvr0KJicA7zoR30rmAyTZykcGKWNfjYw04lwpdvBXAzZNkYtzZ7EF01I7cMqUhkZEN6+Bjjml+f5cw5Fj582mCLz37I1qfIqcvXRReV9W0gvDAX+KZqiwf0XznMpIbN89nX/id9SlEBFJwXUM4U5lOml5LtfweLINtk6oR5igES3V56vkbQ/dyY+fsOdi/BaEEpBxr/kQDYv2pDaoCn1QRNI1/hueWMIyXujGTvscD041HYttmW676wkm8EYJJwltVAy/qr67W15GFAqNsFn1gp+cL4epeI7bc4ZQ9a3Bp6tE3MVtUwCml5EnNQKF9tJLB5OINtANCkyRwAttW5xVG94Hp/s8zNqEePoA0lRkkkauqJtUbFTIBFSBIbVFGbnf+F9ZE/tzaj4BUDWp964jwIFFJIuVQbfWnT4eq4PRz6kxcP66P91kZdZZlCZL+CoCu3V9hvMGg4EuK9q72bMkxl5kZAmlVomOhQw8tib9/tva5W9GfX/AEZqBg8lHr+kKvmoYPVlpWemp1qIs2rFwbmh5dWsBRHQmVlghO+GFAxU/Bj4PuHXUQfj6XT/e0ut6V9zTfN39TMXwlKMGKFupih6lTMMdajSyAzxZf+WA0sRFpSaRI8mUqo4NjWaAsxPdrei9C63U9eciONFNcfS85h5KqOvDdmyvVgoEmWaRWZimUjo/VfrWCVYv3RPlpbCXsyzA4mjGAsxrdBav fSpKUdIw S3367bp3t+Vqw9wH4ED8fPvaIkTCBGGfApBxlXxa5dLI3azrk65At44tnG9wz9ZaT2+tXzKK9e4bVpcIKJ1H/mJUPrcmOtA7rM13YRv7xr0kfAxJiizI54spPLLjdkHsWKMaWiSX1brmMiCjiaQW0E7cSDuSNWG1E2JdcDf6kJC9S6Ma0qdzLM53PLcm/A577WgvjAdPOcWg9PK4EpQyONyZaIvjeASNTuu8SYUe2f8RYUf93hyWVyxYgVQG5pafL9h3Pk29B+U6KXR8pABVzz9ZQgQ== 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: Unlike the mm of a task, an mshare host mm is not updated on context switch. In particular this means that mm_cpumask is never updated which results in TLB flushes for updates to mshare PTEs only being done on the local CPU. To ensure entries are flushed for non-local TLBs, set up an mmu notifier on the mshare mm and use the .arch_invalidate_secondary_tlbs callback to flush all TLBs. arch_invalidate_secondary_tlbs guarantees that TLB entries will be flushed before pages are freed when unmapping pages in an mshare region. Signed-off-by: Anthony Yznaga --- mm/mshare.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index 6bdbcfa8deea..792d86c61042 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -16,8 +16,10 @@ #include #include #include +#include #include #include +#include const unsigned long mshare_align = P4D_SIZE; const unsigned long mshare_base = mshare_align; @@ -29,6 +31,17 @@ struct mshare_data { unsigned long start; unsigned long size; unsigned long flags; + struct mmu_notifier mn; +}; + +static void mshare_invalidate_tlbs(struct mmu_notifier *mn, struct mm_struct *mm, + unsigned long start, unsigned long end) +{ + flush_tlb_all(); +} + +static const struct mmu_notifier_ops mshare_mmu_ops = { + .arch_invalidate_secondary_tlbs = mshare_invalidate_tlbs, }; static int mshare_vm_op_split(struct vm_area_struct *vma, unsigned long addr) @@ -237,6 +250,10 @@ msharefs_fill_mm(struct inode *inode) m_data->mm = mm; m_data->start = mshare_base; inode->i_private = m_data; + m_data->mn.ops = &mshare_mmu_ops; + ret = mmu_notifier_register(&m_data->mn, mm); + if (ret) + goto err_free; return 0; From patchwork Fri Apr 4 02:18:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037993 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 35E0FC3601A for ; Fri, 4 Apr 2025 02:19:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E103A28000A; Thu, 3 Apr 2025 22:19:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBF2C280005; Thu, 3 Apr 2025 22:19:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C399328000A; Thu, 3 Apr 2025 22:19:45 -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 A1FD7280005 for ; Thu, 3 Apr 2025 22:19:45 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1F88781ACE for ; Fri, 4 Apr 2025 02:19:47 +0000 (UTC) X-FDA: 83294755614.01.DFE90AF Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf30.hostedemail.com (Postfix) with ESMTP id 032D280014 for ; Fri, 4 Apr 2025 02:19:44 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=oc9A+bH1; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf30.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733185; a=rsa-sha256; cv=none; b=7WajMd1Us4PStMaMbIuiQGBCViEkXEpv75HUJeLeqePvoDOSlfxA4vDhYcggLtnt2bqOmE amw926ayMWNcxqqXoI0+ETSgXQe7Gj4mKxazu4tmZtbu3Jk+ZV6IF1+ITKf25OCNsYR8hv KwOehZpdLT12raCFmlOTC0Kc+at4tkI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=oc9A+bH1; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf30.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.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=1743733185; 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=NIZj0NmRXwYI88V+aUcfHMTYJsx+jXY2ugUEXgva0Lw=; b=KCWxKcFTlZUzXVDNdK2J6vjibeRZiW4+nWcOaksP/pDSFX2CoPwoAwyWr2i70iWL9P23Fr 80F7Bk/JITXiNXxeq30bMHjzDiloHWx64zEuJPtrHJE8kCQqrx5ZLv78km9TvxO3m45+Ql uPXh6v0f0GLiqcQCgqYieqqPrUBQR00= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341NZt7019542; Fri, 4 Apr 2025 02:19: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=NIZj0 NmRXwYI88V+aUcfHMTYJsx+jXY2ugUEXgva0Lw=; b=oc9A+bH1+TNDIELUNtbN4 Lf4KhIRPl4fLuOM4pD8iz7i/gmjo4hE9zrIE+kEIIb5DfDgLhEyPoj7calY7428U Gj+gz33ZF5fK+ihgCiXzBQcywO7Za8HwH+JjptMt4yTRL7n3fxZqJmHD4ShwU0Wa DaljXnGZ2OWSbKCLEZwnevc9Ltt5F7+C/EBVSwajAbyTAJNC9njWcYLuXZV9NpWV 7TypwWrqGJodGrJR0thOfcxqt0s/2gnv/4lgJq8x4GmXrSy6+IX7REOnEGpqJIBl rywKuYdH3eC1rtQz+/4wqKh/1gcz8ZDuxY5piAOT/2jBOVuqDVe0e4VFrpaLbNKb g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p9dtp4n5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:30 +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 5340fGw8017328; Fri, 4 Apr 2025 02:19:28 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjcu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:28 +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 5342H8gs030074; Fri, 4 Apr 2025 02:19:28 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-10; Fri, 04 Apr 2025 02:19: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, 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: [PATCH v2 09/20] sched/numa: do not scan msharefs vmas Date: Thu, 3 Apr 2025 19:18:51 -0700 Message-ID: <20250404021902.48863-10-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: 9h4yNhwaRZZl92DAM61KrKfJObLin3fk X-Proofpoint-GUID: 9h4yNhwaRZZl92DAM61KrKfJObLin3fk X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 032D280014 X-Stat-Signature: 1u75jotndbptfpuobhpxit3nfx4fjiae X-HE-Tag: 1743733184-158058 X-HE-Meta: U2FsdGVkX19crgzVFdtV/x5CYCYEBuY6XQd8bmmJuMWJH7YgnJ4/urA+jDU0DcJmLFhkCKdNhmxM9TjVdPIctFkj8nJeY2bL1IdNa+ks/30QazecvBHIW7zrlv3/5z70dc2i2w+Qor7qg1JBM8oP9dZyoooSgUv5uO7zpMtYwTNdWUWuajKr1Wyj7p5CZBkkKNNPjJJ1dVAhjs4t0hJIFuFiyWFqo8XYTPFg/UaNhjIuKK6z17jp/TNnp/NHGZjHY/U5nmyjTIS3JC2rhIN0npFfDVP7onSASleztbBuOLKj7zTIKiB8JJSIQte8jfMJKFSbfjGukeQiX6ApVGFrEwFkZoFx8ijQRGAae9QtlFtXlXhxrW4X41Oyd1l7d2r4ZWlowGRfUOddcVOfZ0Zz08EMA0ZPrsLzy8jSRtwigyZ8xybrfEXir5KnSAI37zfOYRpPzaxvCOf2OPRheXNAlttcyDOpT7rdytamn5pphb5xvfU9aU47Ku9gvhY+1tbGBGdM6lMQjjB1abm8PQEDCGhF9iTNOrre1ijrpTniARaNtmEr8yR6GiOizYvieXWlzYlKn1+lmkWMGXlPqD/5M7p/EA0R/so0Eh20vP2duC9XoHE/mlgswwbGzYXL4f7C6wfpWUg0/xsrv3Xkc7+qgmfAqKwB2U5efAK+bJhADLtTEY/B12jRjF/UFGt7LBkXOoryXwChdeHBryeYh9lNYujEsWRc2JPYLnI7BnYsMt6+oIGAto+YTp89TUdwF0rmsmYlb3dUolozpzd5civH8n4nyZUkDE5mcMdsJzbOqJmLoohmq43FhLUh7vba4MIJeVIH/xwgKoEA4ysuXFCm0t9+R8wqd/VIAc8IDNh6VTqrvaZv1C++sYzMJAGIGBWifiY5GjhXNARd6Xi/hbkeqsc+1avDXjRcn31666IJ+POXQp8TsgkvXBxFiKweV+QCLJJP/Sdx3kxgp67hXJZ e8yPzGne 4OnYP5iK+3EFQt8wrbvGBknS9LpOisGTYTInb1bO+bUECiT3OOmp3WynzNW1076lQBbNI6vulnBOPCsDWST8hAQmzTu/HX2umkqq6XhOUo8AeUTw9Vofjbd+uKMB5SMjODz5vl6wxiVYK6lVaacYvoPgqKQK5HnAkkCgaP8bfnAjhbK5EY37qM1CX+kMw9Fy9TqBu6xm/QGRGHfMBQpxRn0lfd5xHWJMRJpAE2JRgqIq1tFTZDtlUlumSwQ== 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: Scanning an msharefs vma results in changes to the shared page table but with TLB flushes incorrectly only going to the process with the vma. Signed-off-by: Anthony Yznaga --- kernel/sched/fair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e43993a4e580..6e1649a28551 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3386,7 +3386,8 @@ static void task_numa_work(struct callback_head *work) for (; vma; vma = vma_next(&vmi)) { if (!vma_migratable(vma) || !vma_policy_mof(vma) || - is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_MIXEDMAP)) { + is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_MIXEDMAP) || + vma_is_mshare(vma)) { trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_UNSUITABLE); continue; } From patchwork Fri Apr 4 02:18:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14038024 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 DDBDCC3600C for ; Fri, 4 Apr 2025 03:02:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02D88280007; Thu, 3 Apr 2025 23:02:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1E4B280005; Thu, 3 Apr 2025 23:02:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE363280007; Thu, 3 Apr 2025 23:02:33 -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 C0820280005 for ; Thu, 3 Apr 2025 23:02:33 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4CEAAC1DBA for ; Fri, 4 Apr 2025 03:02:34 +0000 (UTC) X-FDA: 83294863428.03.CA9DB42 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf26.hostedemail.com (Postfix) with ESMTP id 1E79C140009 for ; Fri, 4 Apr 2025 03:02:31 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=m14CeTB2; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf26.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.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=1743735752; 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=qrrOKBJ/3jCKhjqRR4yfWGx2+uS9oDf6jT20lWJ3iuQ=; b=KT1vUayFWCWXHDZrQGEJDE2zjZu2x79jAvvY+c13lTLFo11MJaW112k8/wgnhW1GtPgZOG 8fCVVIwqg2hW3t41jAMisgHiXJux/3XeOIizdB/bib6D4OmKm2bszlN84LCIm60PsaulbZ CpzZjdrz4xZV52Q/hfZ/NyrQqyxw0x0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743735752; a=rsa-sha256; cv=none; b=ChxZiEa8ktjIaTwOAhVbQYeHb5HoMtFHRot1OkM8iImKjWbMuUqkWcZyKyXSZQFEhIwu7l 7BausIcuP5BRnKJC4NcAIA77RqrrG+VAC/iYVIIVK4DB18ueR0IjKYbRIEjD2N90FfBIu4 qCnah93O3tXajV451GF4T/AL8LwOBwA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=m14CeTB2; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf26.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com 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 5341O0ar030247; Fri, 4 Apr 2025 02:19:35 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=qrrOK BJ/3jCKhjqRR4yfWGx2+uS9oDf6jT20lWJ3iuQ=; b=m14CeTB2tu/LSvz0nrYD/ qagIzSxoh7Xc5bDEZd056ItzD0cuTb4GVd8WG8UbD38+n3OaT6ZLlMNRIQ7+HPZk viQHg2frxvNYW3iuscXzofYtV/8gb5Q25cqJqcYMdnLkHGyeJNReDSx0Ws/3IWou xnqJEHZfdMkSNPGnFVS+plxeUwrT3nQsZz5ix6XyOEQjdMccScT5dGEM1KAS1lu9 791hKsHciPkbIlYCt9+j6Ovt5Hv/DLnJ/+TnsHMlRiEe0h8H48OQFJWJLD84x+pl WGJt+FITXkazEqnq9p82z5pL1BiZwu/Ub1tL52jpIgVguKiNFlE55cR80+9o+z4f Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p7f0p1nx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:35 +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 5340hocF017504; Fri, 4 Apr 2025 02:19:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspje4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:33 +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 5342H8gw030074; Fri, 4 Apr 2025 02:19:33 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-12; Fri, 04 Apr 2025 02:19:32 +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: [PATCH v2 11/20] mm: add and use unmap_page_range vm_ops hook Date: Thu, 3 Apr 2025 19:18:53 -0700 Message-ID: <20250404021902.48863-12-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: D3avib5KfJw9o7txOeLIIqumVBlsAqWD X-Proofpoint-GUID: D3avib5KfJw9o7txOeLIIqumVBlsAqWD X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1E79C140009 X-Stat-Signature: 7biict7j8da9xct7hznoi96k81w1kmhi X-Rspam-User: X-HE-Tag: 1743735751-250998 X-HE-Meta: U2FsdGVkX1+16ViEcCqgipPi93AzIh2PoVAgat8MZwc0jBzIvcSLIrjinId+7Xien8Uo03U3o9SJvMULssU3FVy/9fwebr+gO5yd0Cd+9ua9+oIDlphjINSkq2W4VUIz/bnGhLL3xpm/Ys2pOvWHkx234FBPw4ranUiWUQSLm3mjRqMQP3UwEHCJ4LuT6XucYPbZBdAZ0I+CAGXP1CWXPdI7FqN/lNG2NV5iEqIDiGf1mrkx5AbeRKYUlGMocEPYMzwNgDheQxHdnJudX+iuoPr7G7wRlJEX/r7Tlwu5kdHtJpTa+8By6QTiHG+ne1FxGXK3/crDLh1Ci/TcSTUqVyQqGqdYCMaIaa5spD1VSqb6vW2o40bRxuNzonb2qEoQYQNic3FgvmGOnL6YuLeA7IWNOviD44A5u3++WhfmOFFZ2NDyVa8Kc9GI5LQL+mAaT3Opp+XedV/KbsXDFG21jj2wxhogcibeA5qDn1WuJOaNjgjb7FGqFZCleBe13APum/ciS1XsI95Ddbv4WRfJSInI7USZ3tFJ9KuClHDtHZmmjsSAR1FUNMCZVc9dn3IU6+BlMPL//sLDUntO16E+IlxhE7K447EdA8j77rFKJ1O9Dh/K6qGoKqVRY52/kYkgSfm6+749L5S/Btrcn4+XaItLuMkD0e0N0blwG/dbVzsC1bAbyYSd8EgklUYk7SGydRcjcJsJXyfPA6s8K44sAP6WUFXfWWTgBUlPld0csv5SDfKE9a+hQg6pJuFPuJlupyqpJZt6CjsMn4vV2OMPw5wxl0Y3sTqJ/KCfEyiux/hhj3/sRsPjV2/n2Eii3Wj4JZHrGeZ1w4LHczvcQT8x1ft12dKrj+3HCKxuJYOeHLZK6e6CZrGMToa6i7QapZW8QL1INkW+aW2rXghjsRqXx983vkwJwwDLV4GZjl6fjxkgCaELGPHSktW8n1JYEcdA3MSkTmiuz/Txm1D/kvq ASabsY3x UkbyoMHdw02OpG3W4vDAVquHyetrDZtzA27z2iT9pUlePX1yxX2LrqUf0HRhJDSihjCiJWTkW8lBkd4uLHOovvykIwfI1nbYmdL/awgYEWzrcFYMO25TG2+hkbOJNwl8QSAIO/UGim75quXrn9O8upSqb70cD8HBWSUpcnb/a5I2qYbtiuCmJRgEtPLek78dVQQ1MrfjtH0YMoew3esPCAYVfbcB/MD90XWzGvz1nUHWcYwzEclkB4ZpEot6ZOeLLmOq3aMiz41+dGGVDQiMLnXRGxQWCpc6qVxIU 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: Special handling is needed when unmapping a hugetlb vma and will be needed when unmapping an msharefs vma once support is added for handling faults in an mshare region. Signed-off-by: Anthony Yznaga --- include/linux/mm.h | 10 ++++++++++ ipc/shm.c | 17 +++++++++++++++++ mm/hugetlb.c | 25 +++++++++++++++++++++++++ mm/memory.c | 36 +++++++++++++----------------------- 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index f2f9d15213ab..d6cac2cca4da 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -40,6 +40,7 @@ struct anon_vma_chain; struct user_struct; struct pt_regs; struct folio_batch; +struct zap_details; void arch_mm_preinit(void); void mm_core_init(void); @@ -661,8 +662,17 @@ struct vm_operations_struct { */ struct page *(*find_special_page)(struct vm_area_struct *vma, unsigned long addr); + void (*unmap_page_range)(struct mmu_gather *tlb, + struct vm_area_struct *vma, + unsigned long addr, unsigned long end, + struct zap_details *details); }; +void __unmap_page_range(struct mmu_gather *tlb, + struct vm_area_struct *vma, + unsigned long addr, unsigned long end, + struct zap_details *details); + #ifdef CONFIG_NUMA_BALANCING static inline void vma_numab_state_init(struct vm_area_struct *vma) { diff --git a/ipc/shm.c b/ipc/shm.c index 99564c870084..cadd551e60b9 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -585,6 +585,22 @@ static struct mempolicy *shm_get_policy(struct vm_area_struct *vma, } #endif +static void shm_unmap_page_range(struct mmu_gather *tlb, + struct vm_area_struct *vma, + unsigned long addr, unsigned long end, + struct zap_details *details) +{ + struct file *file = vma->vm_file; + struct shm_file_data *sfd = shm_file_data(file); + + if (sfd->vm_ops->unmap_page_range) { + sfd->vm_ops->unmap_page_range(tlb, vma, addr, end, details); + return; + } + + __unmap_page_range(tlb, vma, addr, end, details); +} + static int shm_mmap(struct file *file, struct vm_area_struct *vma) { struct shm_file_data *sfd = shm_file_data(file); @@ -685,6 +701,7 @@ static const struct vm_operations_struct shm_vm_ops = { .set_policy = shm_set_policy, .get_policy = shm_get_policy, #endif + .unmap_page_range = shm_unmap_page_range, }; /** diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 39f92aad7bd1..e4a516f458a0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5426,6 +5426,30 @@ static vm_fault_t hugetlb_vm_op_fault(struct vm_fault *vmf) return 0; } +static void hugetlb_vm_op_unmap_page_range(struct mmu_gather *tlb, + struct vm_area_struct *vma, + unsigned long addr, unsigned long end, + struct zap_details *details) +{ + zap_flags_t zap_flags = details ? details->zap_flags : 0; + + /* + * It is undesirable to test vma->vm_file as it + * should be non-null for valid hugetlb area. + * However, vm_file will be NULL in the error + * cleanup path of mmap_region. When + * hugetlbfs ->mmap method fails, + * mmap_region() nullifies vma->vm_file + * before calling this function to clean up. + * Since no pte has actually been setup, it is + * safe to do nothing in this case. + */ + if (!vma->vm_file) + return; + + __unmap_hugepage_range(tlb, vma, addr, end, NULL, zap_flags); +} + /* * When a new function is introduced to vm_operations_struct and added * to hugetlb_vm_ops, please consider adding the function to shm_vm_ops. @@ -5439,6 +5463,7 @@ const struct vm_operations_struct hugetlb_vm_ops = { .close = hugetlb_vm_op_close, .may_split = hugetlb_vm_op_split, .pagesize = hugetlb_vm_op_pagesize, + .unmap_page_range = hugetlb_vm_op_unmap_page_range, }; static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page, diff --git a/mm/memory.c b/mm/memory.c index 6ea3551eb2df..db558fe43088 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1876,7 +1876,7 @@ static inline unsigned long zap_p4d_range(struct mmu_gather *tlb, return addr; } -void unmap_page_range(struct mmu_gather *tlb, +void __unmap_page_range(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long addr, unsigned long end, struct zap_details *details) @@ -1896,6 +1896,16 @@ void unmap_page_range(struct mmu_gather *tlb, tlb_end_vma(tlb, vma); } +void unmap_page_range(struct mmu_gather *tlb, + struct vm_area_struct *vma, + unsigned long addr, unsigned long end, + struct zap_details *details) +{ + if (vma->vm_ops && vma->vm_ops->unmap_page_range) + vma->vm_ops->unmap_page_range(tlb, vma, addr, end, details); + else + __unmap_page_range(tlb, vma, addr, end, details); +} static void unmap_single_vma(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long start_addr, @@ -1917,28 +1927,8 @@ static void unmap_single_vma(struct mmu_gather *tlb, if (unlikely(vma->vm_flags & VM_PFNMAP)) untrack_pfn(vma, 0, 0, mm_wr_locked); - if (start != end) { - if (unlikely(is_vm_hugetlb_page(vma))) { - /* - * It is undesirable to test vma->vm_file as it - * should be non-null for valid hugetlb area. - * However, vm_file will be NULL in the error - * cleanup path of mmap_region. When - * hugetlbfs ->mmap method fails, - * mmap_region() nullifies vma->vm_file - * before calling this function to clean up. - * Since no pte has actually been setup, it is - * safe to do nothing in this case. - */ - if (vma->vm_file) { - zap_flags_t zap_flags = details ? - details->zap_flags : 0; - __unmap_hugepage_range(tlb, vma, start, end, - NULL, zap_flags); - } - } else - unmap_page_range(tlb, vma, start, end, details); - } + if (start != end) + unmap_page_range(tlb, vma, start, end, details); } /** From patchwork Fri Apr 4 02:18:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037994 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 0A6FFC3600C for ; Fri, 4 Apr 2025 02:19:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B129E28000C; Thu, 3 Apr 2025 22:19:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9BB128000B; Thu, 3 Apr 2025 22:19:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8839E28000C; Thu, 3 Apr 2025 22:19:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 590A528000B for ; Thu, 3 Apr 2025 22:19:51 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D8D7FB7B3E for ; Fri, 4 Apr 2025 02:19:52 +0000 (UTC) X-FDA: 83294755824.29.1C0509D Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf08.hostedemail.com (Postfix) with ESMTP id EC789160009 for ; Fri, 4 Apr 2025 02:19:50 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=lKtTA5MD; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf08.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=1743733191; 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=qRdpIuCp/tE17I/IAkh9LjXKFn30Xjs2SfQmBLZeMus=; b=RXvhi2gZ2/g/LM0FvE42kRCJd5pLfM/jMxAeSIZSkJDHfNzmCEfZkpUpittsoEwRxSEz4n uqxKwiMrfVkHq9S1m4Axm+a5YRJ3Wz4w2wD5Jh2Urq2jg5ePI39yHhuKIQLy25P+0Sj2Rk V+GP8CdP/2/rVJMc1N96l57VnOnCnFM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733191; a=rsa-sha256; cv=none; b=5xr1WS1TnD8JRzgs/MVvOoV3L6jzyklgqr3WgvjRj05L3df3oYxdX+s6ffonUSdbMX3f6M 6uhrhNMeDcrQCfBamfDr4zcAZ3WQ/2IkfzrRye7iyOrLB19wGDEYTOpgkUjgDlxe2rkA+K VMkhOeqFekCDVCCV7V40Fh4XHP263j0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=lKtTA5MD; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf08.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341N1aZ021759; Fri, 4 Apr 2025 02:19:37 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=qRdpI uCp/tE17I/IAkh9LjXKFn30Xjs2SfQmBLZeMus=; b=lKtTA5MDFrSaUt+MSx01e 4QDNTa6p2Jo15R6RM9Kn6nQCmrtstm+F6bHSR5QZHvnj1c2q5UUOGpcN8yXmJnIO lQJLvfYmiJ1nAGpjMwHTLs/KxetWYtJwYzUYh74SKjzcStys5/811hw5IQmheIdM NBzjMFSz6xKU2SMTEnZqeOYRJw2mKWZelJ28nzV7WZZtwiJ5xgiYqTpg6yBQj/1J 7x0CHBH78MWhvnOGpJgQgNr3t2K+IwCJ3oxSyase3MOqm0FLnYGOBjfaDW4TTEUs Uq2B2/XkhmhUR4bSgKdcQPSaC+r9LuWFbVMIhwpuQ//cWDSNgq313MAlwe8lkUWO A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p8fsehex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:36 +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 5340b2tj017252; Fri, 4 Apr 2025 02:19:36 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjer-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:36 +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 5342H8h0030074; Fri, 4 Apr 2025 02:19:35 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-13; Fri, 04 Apr 2025 02:19:35 +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: [PATCH v2 12/20] mm/mshare: prepare for page table sharing support Date: Thu, 3 Apr 2025 19:18:54 -0700 Message-ID: <20250404021902.48863-13-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: kjqCYtOYSi4kyYmM1hlElVfdmwM9mYYd X-Proofpoint-GUID: kjqCYtOYSi4kyYmM1hlElVfdmwM9mYYd X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: EC789160009 X-Stat-Signature: beqie8qhsmks4gziebmugmu185dmn4xy X-Rspam-User: X-HE-Tag: 1743733190-383047 X-HE-Meta: U2FsdGVkX1+ZJkbuYQ9qXTaJy7prJO7j9at81usyrz3XAcWwvfCxiLeLYyFQDgof8kZ9vYB0S8SZLU3kCFEbKbJMxk88m1on7j6hTFeDds95UyovUCYxU2EV+fIh91aPztI1Xr3s29EA7t7Bm14pNyjXSZZsxJdo9dHPaltsSXcmsSWQ3b3fnSMgoTN+oJ40cmwPdfaoM3BhmpMu04PMpnxiUXwkM32O1n7BWaQSqdj+BBh+tQAoikM0YzXwYlRlLtcbpVpSCnPIE8TqJNhHPx2m9Tgn8vZdjev2IvOJ1I1ggc9Op4i7FDr/2gvH5XYljLBtq0qQr8Tf4y726GbfNoaaZlwArxm3qwdxnOAhXuS9EUSiZgKesI6sjTowuCMUtmRCHlcgfzuRfitAbCBMvGgbxwToVjutRy8TKYnZdFhAbqzSiZPTTTmroS/XyRP1QnFYK2stsyhKuYXlGXyGOXl/U/bhaAICbJKtRHy3MNv5StUWTEKohuEBSgYAt16SvdJ29FJ2Gfwwoye32MyjV0fY75rz5hQSGEOylfoJiHkb7oIMP2QrqaLM/7kShUshSHIGsrVdx/r8YbCrFRZunYQ5ODsnNjUSErXXislbT8qyQ1kc0hU10cGkhfg3H4prqaGkr+xTE14DUCTf3U75k96Qeei0HQLa4sXVx2Hu8v8uMR9OZtyVCmj71umH6Nib/knRYnnL8BnEkr8qJlb1WcBweZcssMe819Kw/ylmH8DWAhumwEH7Vz24gwrPByoy2ikhDmZ3I1ov0qeDg81H8K1RDTxjPyzArmbE4DFToXb5djoTAMmkLhtNgscBy82MwNXPgWlTAv5ybdIgTOZFtckxrlWdGRZ0U+3z/yjyqPPfUqIbbX8T4WoSmnTLZTbLtzMXARvKLS1yt3bPzSay4xy0lWisXU3d20xD0T/bh8d0uFWrCYlvtUY7KcooBH0JJYcObNmj9260j2tK8N9 TNcbCV+Y H/d3Zas99Y1wb/mfvsRkjOmMvWLTFQWhCO21CBfGXGdX3LOvXHTcndhZaB6ia+OvbAWlTimJWiOHm50+b0ZPqO5HQP5tQRnPC2keCv9I/tciTeqHwUHzvc+UdrihNkOeWCDHGBkg1Dg7zLeRThCT4ZK21K5PXXl3R2A4T+pE6Dgkf4e0Ce5yRKDZDgyGpcyAtmQ5kxXDxeW6bMEZcCgvcmUXZiplyIdjXtgK5kI8EnmeR4gAZ4Jdu/29Y8RSBLQrrvl54gA93F6tnOPYPmZlUkEc1PIQILzfQBcNtfsiEsgS2DVTb7yCMCx+zUW2m5xX1K3+LLpeyDi0k0to= 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 In preparation for enabling the handling of page faults in an mshare region provide a way to link an mshare shared page table to a process page table and otherwise find the actual vma in order to handle a page fault. Modify the unmap path to ensure that page tables in mshare regions are unlinked and kept intact when a process exits or an mshare region is explicitly unmapped. Signed-off-by: Khalid Aziz Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Anthony Yznaga --- include/linux/mm.h | 6 +++++ mm/memory.c | 45 +++++++++++++++++++++++++++------ mm/mshare.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 8 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index d6cac2cca4da..f06be2f20c20 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1179,11 +1179,17 @@ static inline bool vma_is_anon_shmem(struct vm_area_struct *vma) { return false; int vma_is_stack_for_current(struct vm_area_struct *vma); #ifdef CONFIG_MSHARE +vm_fault_t find_shared_vma(struct vm_area_struct **vma, unsigned long *addrp); static inline bool vma_is_mshare(const struct vm_area_struct *vma) { return vma->vm_flags & VM_MSHARE; } #else +static inline vm_fault_t find_shared_vma(struct vm_area_struct **vma, unsigned long *addrp) +{ + WARN_ON_ONCE(1); + return VM_FAULT_SIGBUS; +} static inline bool vma_is_mshare(const struct vm_area_struct *vma) { return false; diff --git a/mm/memory.c b/mm/memory.c index db558fe43088..68422b606819 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -247,7 +247,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, p4d_t *p4d, static inline void free_p4d_range(struct mmu_gather *tlb, pgd_t *pgd, unsigned long addr, unsigned long end, - unsigned long floor, unsigned long ceiling) + unsigned long floor, unsigned long ceiling, + bool shared_pud) { p4d_t *p4d; unsigned long next; @@ -259,7 +260,10 @@ static inline void free_p4d_range(struct mmu_gather *tlb, pgd_t *pgd, next = p4d_addr_end(addr, end); if (p4d_none_or_clear_bad(p4d)) continue; - free_pud_range(tlb, p4d, addr, next, floor, ceiling); + if (unlikely(shared_pud)) + p4d_clear(p4d); + else + free_pud_range(tlb, p4d, addr, next, floor, ceiling); } while (p4d++, addr = next, addr != end); start &= PGDIR_MASK; @@ -281,9 +285,10 @@ static inline void free_p4d_range(struct mmu_gather *tlb, pgd_t *pgd, /* * This function frees user-level page tables of a process. */ -void free_pgd_range(struct mmu_gather *tlb, +static void __free_pgd_range(struct mmu_gather *tlb, unsigned long addr, unsigned long end, - unsigned long floor, unsigned long ceiling) + unsigned long floor, unsigned long ceiling, + bool shared_pud) { pgd_t *pgd; unsigned long next; @@ -339,10 +344,17 @@ void free_pgd_range(struct mmu_gather *tlb, next = pgd_addr_end(addr, end); if (pgd_none_or_clear_bad(pgd)) continue; - free_p4d_range(tlb, pgd, addr, next, floor, ceiling); + free_p4d_range(tlb, pgd, addr, next, floor, ceiling, shared_pud); } while (pgd++, addr = next, addr != end); } +void free_pgd_range(struct mmu_gather *tlb, + unsigned long addr, unsigned long end, + unsigned long floor, unsigned long ceiling) +{ + __free_pgd_range(tlb, addr, end, floor, ceiling, false); +} + void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas, struct vm_area_struct *vma, unsigned long floor, unsigned long ceiling, bool mm_wr_locked) @@ -379,9 +391,12 @@ void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas, /* * Optimization: gather nearby vmas into one call down + * + * Do not free the shared page tables of an mshare region. */ while (next && next->vm_start <= vma->vm_end + PMD_SIZE - && !is_vm_hugetlb_page(next)) { + && !is_vm_hugetlb_page(next) + && !vma_is_mshare(next)) { vma = next; next = mas_find(mas, ceiling - 1); if (unlikely(xa_is_zero(next))) @@ -392,9 +407,11 @@ void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas, unlink_file_vma_batch_add(&vb, vma); } unlink_file_vma_batch_final(&vb); - free_pgd_range(tlb, addr, vma->vm_end, - floor, next ? next->vm_start : ceiling); + __free_pgd_range(tlb, addr, vma->vm_end, + floor, next ? next->vm_start : ceiling, + vma_is_mshare(vma)); } + vma = next; } while (vma); } @@ -1884,6 +1901,13 @@ void __unmap_page_range(struct mmu_gather *tlb, pgd_t *pgd; unsigned long next; + /* + * Do not unmap vmas that share page tables through an + * mshare region. + */ + if (vma_is_mshare(vma)) + return; + BUG_ON(addr >= end); tlb_start_vma(tlb, vma); pgd = pgd_offset(vma->vm_mm, addr); @@ -6275,6 +6299,11 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, if (ret) goto out; + if (unlikely(vma_is_mshare(vma))) { + WARN_ON_ONCE(1); + return VM_FAULT_SIGBUS; + } + if (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE, flags & FAULT_FLAG_INSTRUCTION, flags & FAULT_FLAG_REMOTE)) { diff --git a/mm/mshare.c b/mm/mshare.c index 792d86c61042..4ddaa0d41070 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -44,6 +44,56 @@ static const struct mmu_notifier_ops mshare_mmu_ops = { .arch_invalidate_secondary_tlbs = mshare_invalidate_tlbs, }; +static p4d_t *walk_to_p4d(struct mm_struct *mm, unsigned long addr) +{ + pgd_t *pgd; + p4d_t *p4d; + + pgd = pgd_offset(mm, addr); + p4d = p4d_alloc(mm, pgd, addr); + if (!p4d) + return NULL; + + return p4d; +} + +/* Returns holding the host mm's lock for read. Caller must release. */ +vm_fault_t +find_shared_vma(struct vm_area_struct **vmap, unsigned long *addrp) +{ + struct vm_area_struct *vma, *guest = *vmap; + struct mshare_data *m_data = guest->vm_private_data; + struct mm_struct *host_mm = m_data->mm; + unsigned long host_addr; + p4d_t *p4d, *guest_p4d; + + mmap_read_lock_nested(host_mm, SINGLE_DEPTH_NESTING); + host_addr = *addrp - guest->vm_start + host_mm->mmap_base; + p4d = walk_to_p4d(host_mm, host_addr); + guest_p4d = walk_to_p4d(guest->vm_mm, *addrp); + if (!p4d_same(*guest_p4d, *p4d)) { + set_p4d(guest_p4d, *p4d); + mmap_read_unlock(host_mm); + return VM_FAULT_NOPAGE; + } + + *addrp = host_addr; + vma = find_vma(host_mm, host_addr); + + /* XXX: expand stack? */ + if (vma && vma->vm_start > host_addr) + vma = NULL; + + *vmap = vma; + + /* + * release host mm lock unless a matching vma is found + */ + if (!vma) + mmap_read_unlock(host_mm); + return 0; +} + static int mshare_vm_op_split(struct vm_area_struct *vma, unsigned long addr) { return -EINVAL; @@ -55,9 +105,21 @@ static int mshare_vm_op_mprotect(struct vm_area_struct *vma, unsigned long start return -EINVAL; } +static void mshare_vm_op_unmap_page_range(struct mmu_gather *tlb, + struct vm_area_struct *vma, + unsigned long addr, unsigned long end, + struct zap_details *details) +{ + /* + * The msharefs vma is being unmapped. Do not unmap pages in the + * mshare region itself. + */ +} + static const struct vm_operations_struct msharefs_vm_ops = { .may_split = mshare_vm_op_split, .mprotect = mshare_vm_op_mprotect, + .unmap_page_range = mshare_vm_op_unmap_page_range, }; /* From patchwork Fri Apr 4 02:18:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037995 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 5DD33C3601A for ; Fri, 4 Apr 2025 02:19:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72BC628000D; Thu, 3 Apr 2025 22:19:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A79328000B; Thu, 3 Apr 2025 22:19:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D82028000D; Thu, 3 Apr 2025 22:19:53 -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 29FBB28000B for ; Thu, 3 Apr 2025 22:19:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B5C2481B18 for ; Fri, 4 Apr 2025 02:19:54 +0000 (UTC) X-FDA: 83294755908.01.1C2EE0B Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf25.hostedemail.com (Postfix) with ESMTP id 99BEFA0005 for ; Fri, 4 Apr 2025 02:19:52 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=P5P7gOnH; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf25.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.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=1743733192; 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=7cpVyKF4ZMd3LXxrpKacQ/zYRn5BM4QzMhn1LTBJNYE=; b=Pjg5auA4Uix+VYFaEnADo2UdOhCK+IhC2JhPBcT5yZ6d/arv0O4i8VxR8nnHlhIyB9GYl+ /UMJoVk/SxS6TE3V51xM0abiERnwCmw5ufRcWl0e5mB/Y+nbgMctJPIdpY9AThrs2S5IQ+ NsehTwIliE8QlkBMmgsW8Za4i/BH3ME= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=P5P7gOnH; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf25.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733192; a=rsa-sha256; cv=none; b=bt5U8qC6kepOiDy3toxAd+aibUEyNCnR8+txqGCnsz3gaOsjlkQ+R4+3m7gNm911k4/8/C ZRO8PME2PdvUuE7oPUbqH80upe+5vuYa/RQsQWDU9ttPP/Wj2tchSQznV5VNC/S5HjI1Sm ooUVbxt5gnqK1Tzn62Hn04w4w7aGOYQ= 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 5341NVEe020022; Fri, 4 Apr 2025 02:19:40 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=7cpVy KF4ZMd3LXxrpKacQ/zYRn5BM4QzMhn1LTBJNYE=; b=P5P7gOnHiFEynlnwbYemo LF6MKgmZlq3ZINoC9Oxv0XiVLmwVef2WLfkNqFptvdl2faULOJ4/8cglbTnyWTWG sX5DOqvXDPqwKsGonJiqksUjS1QpgFx53q3/EPpBmuPE4XzxIRecFyHerePfEFcY 5pT37h6Kf2Vg7SnIjYMbBMnlCGL8We33vWrSyLzwbfL1433bEmZuGCUQ23URynCO jrkGs9pps47BS7oj/hL4rlCPUd6igpxbyG9Tc3XQ5K1Gn6xRkbAu7tzU8c+A7fbd f3oOIgw7Gik9rSUHeMfpoxdnjoLVlvWRD2DeeYbfS0gOYR902+E1OY/KQSIV2WO9 Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p8r9ntk6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:40 +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 5340fxgu017356; Fri, 4 Apr 2025 02:19:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjf9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19: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 5342H8h2030074; Fri, 4 Apr 2025 02:19:38 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-14; Fri, 04 Apr 2025 02:19: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: [PATCH v2 13/20] x86/mm: enable page table sharing Date: Thu, 3 Apr 2025 19:18:55 -0700 Message-ID: <20250404021902.48863-14-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: i6lZP0jsec5VQkf8qGzbwTeR86wApoN6 X-Proofpoint-ORIG-GUID: i6lZP0jsec5VQkf8qGzbwTeR86wApoN6 X-Rspamd-Server: rspam01 X-Stat-Signature: g4siyyba8xie9z8dd4nusuq187ju1wca X-Rspam-User: X-Rspamd-Queue-Id: 99BEFA0005 X-HE-Tag: 1743733192-880059 X-HE-Meta: U2FsdGVkX18ENk1RkN7PnHWi4B0SzKwnV4RSWseAatOgi38hGPeghAAMz2RryDD7If2GN5Mn8elpVURUCzZw5sGl1LT4cnTTn4yVzPJwc1+72NXWL5P8cqBafiNZSb9cwr2XeH/sbiH/7Ac+bBQnvGW67KuENeTqDucRe/Ik4GZcL/60MPWycYkaBQBp1EscXTBy5Se3q/hk80tjMlWjuvN1+VK3zhQDIB/6m/OXLY/taWzwevL1Fem6KForSY2vNI2X8rxy9pue+L7eahCztivJaYg2aNFqHfzcwS4R7OwWiN+JqjEDwcgn3DyvZq6V2+sBQVkWVgsf/xMoJ/TF3iNqlA6wBY8i9XfXn+T94Uivh+sX8z23hPXRaLoxrvpdHDJqRWsNLFa/T8Px/9AWMkJCddQ7Kg7ilmk6c0Hfi9EOm5xbNDHTStsr4O1IdY1C3F3G9yhafj/IU+WCJXgaypiJ3UE1mSfG5eqNKNxTo9n3RDglSyH6IPqMBVKgu0ZfmsTgI3IEAcwicvQDyMros1bJQ0xxZsHrTypat9WjsT5a+FHfofPAgI6rm8TQ6NnFF7zLTbpyDty0DEreiiDivswJyPODyKboe8JVt91HAtwnHa2hRZ+5zBPrABTksJjmb2wnlNaTvRF5A9sxUc5dxfeIqqd5Sw4Rgg1sFRYmpgXe/A+ZvAxQ2lPl/Nh70TfEf+Y16Gfixw+aSfzfZTbgXo25dDJBkLGSGOyvfKOLrAejLFgx2kAQ80bLBDXPYnnKaVgMwRjf1mcRw7pDbYoMvkyoBCG6ageK/MQowNWTXKWiUb6djhdIeZGm0CkDlDaix8L7MuUOQhRUKAFU+J4lkPAOMF+DodjDrokOkCUiZfmKFdT63LlPINXC0UjIoul7SJxczg52eo7xMsdcfnt485Rg0xEkRdhoo+9vzjgPNu3WLOALGnVGPdBLvidRETYAI/1fJpXBAzu8jEsRtvZ nTETGCRz W1c4WudjxUv5TUmUlpX8zI7egZHIEF/ams3fAw6Kb4gGFxJdtUv97SiwXZyePxogzixfqNiGNwUGannPZ8/f2xn5eMpVDrXeHVM8xKUUfAlatQ+8nb1cww50YKSSJOumRNXP0Hf8TK8A4pDP3GSwaIKOPnqdJikcV9OhFnSovme6o8rfFFf6HuCxg75AczrFHCDMZhBB2be8CHwe8R7ULVSf+AxvitaNzMCx1zxRo03rMOwcJ57z0I7wSrQ== 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: Enable x86 support for handling page faults in an mshare region by redirecting page faults to operate on the mshare mm_struct and vmas contained in it. Some permissions checks are done using vma flags in architecture-specfic fault handling code so the actual vma needed to complete the handling is acquired before calling handle_mm_fault(). Because of this an ARCH_SUPPORTS_MSHARE config option is added. Signed-off-by: Anthony Yznaga --- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + arch/x86/mm/fault.c | 37 ++++++++++++++++++++++++++++++++++++- mm/Kconfig | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 9f6eb09ef12d..2e000fefe9b3 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1652,6 +1652,9 @@ config HAVE_ARCH_PFN_VALID config ARCH_SUPPORTS_DEBUG_PAGEALLOC bool +config ARCH_SUPPORTS_MSHARE + bool + config ARCH_SUPPORTS_PAGE_TABLE_CHECK bool diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1502fd0c3c06..1f1779decb44 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -125,6 +125,7 @@ config X86 select ARCH_SUPPORTS_ACPI select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_DEBUG_PAGEALLOC + select ARCH_SUPPORTS_MSHARE if X86_64 select ARCH_SUPPORTS_PAGE_TABLE_CHECK if X86_64 select ARCH_SUPPORTS_NUMA_BALANCING if X86_64 select ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP if NR_CPUS <= 4096 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 296d294142c8..49659d2f9316 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1216,6 +1216,8 @@ void do_user_addr_fault(struct pt_regs *regs, struct mm_struct *mm; vm_fault_t fault; unsigned int flags = FAULT_FLAG_DEFAULT; + bool is_shared_vma; + unsigned long addr; tsk = current; mm = tsk->mm; @@ -1329,6 +1331,12 @@ void do_user_addr_fault(struct pt_regs *regs, if (!vma) goto lock_mmap; + /* mshare does not support per-VMA locks yet */ + if (vma_is_mshare(vma)) { + vma_end_read(vma); + goto lock_mmap; + } + if (unlikely(access_error(error_code, vma))) { bad_area_access_error(regs, error_code, address, NULL, vma); count_vm_vma_lock_event(VMA_LOCK_SUCCESS); @@ -1357,17 +1365,38 @@ void do_user_addr_fault(struct pt_regs *regs, lock_mmap: retry: + addr = address; + is_shared_vma = false; vma = lock_mm_and_find_vma(mm, address, regs); if (unlikely(!vma)) { bad_area_nosemaphore(regs, error_code, address); return; } + if (unlikely(vma_is_mshare(vma))) { + fault = find_shared_vma(&vma, &addr); + + if (fault) { + mmap_read_unlock(mm); + goto done; + } + + if (!vma) { + mmap_read_unlock(mm); + bad_area_nosemaphore(regs, error_code, address); + return; + } + + is_shared_vma = true; + } + /* * Ok, we have a good vm_area for this memory access, so * we can handle it.. */ if (unlikely(access_error(error_code, vma))) { + if (unlikely(is_shared_vma)) + mmap_read_unlock(vma->vm_mm); bad_area_access_error(regs, error_code, address, mm, vma); return; } @@ -1385,7 +1414,11 @@ void do_user_addr_fault(struct pt_regs *regs, * userland). The return to userland is identified whenever * FAULT_FLAG_USER|FAULT_FLAG_KILLABLE are both set in flags. */ - fault = handle_mm_fault(vma, address, flags, regs); + fault = handle_mm_fault(vma, addr, flags, regs); + + if (unlikely(is_shared_vma) && ((fault & VM_FAULT_COMPLETED) || + (fault & VM_FAULT_RETRY) || fault_signal_pending(fault, regs))) + mmap_read_unlock(mm); if (fault_signal_pending(fault, regs)) { /* @@ -1413,6 +1446,8 @@ void do_user_addr_fault(struct pt_regs *regs, goto retry; } + if (unlikely(is_shared_vma)) + mmap_read_unlock(vma->vm_mm); mmap_read_unlock(mm); done: if (likely(!(fault & VM_FAULT_ERROR))) diff --git a/mm/Kconfig b/mm/Kconfig index e6c90db83d01..8a5a159457f2 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1344,7 +1344,7 @@ config PT_RECLAIM config MSHARE bool "Mshare" - depends on MMU + depends on MMU && ARCH_SUPPORTS_MSHARE help Enable msharefs: A ram-based filesystem that allows multiple processes to share page table entries for shared pages. A file From patchwork Fri Apr 4 02:18:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037996 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 B2AFFC3601B for ; Fri, 4 Apr 2025 02:19:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A55B028000E; Thu, 3 Apr 2025 22:19:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A04EB28000B; Thu, 3 Apr 2025 22:19:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 858A628000E; Thu, 3 Apr 2025 22:19:54 -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 6332128000B for ; Thu, 3 Apr 2025 22:19:54 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B46E6161C0F for ; Fri, 4 Apr 2025 02:19:55 +0000 (UTC) X-FDA: 83294755950.20.9471BA0 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf23.hostedemail.com (Postfix) with ESMTP id B8D0F140004 for ; Fri, 4 Apr 2025 02:19:53 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=n61RHZno; spf=pass (imf23.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=1743733193; 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=ryv0hp50CeHBUKVemJw6FHGxU5zvzxNYohzdpJ9sUII=; b=dVy1z+3gkSW8dcVvHjawvZKqa8G3ZFoCHspUya/VzUROUxah42//oaxxHgDvms+FrN3cCW pKfzHncEiFiNwan3mz3//dWp+xlwGPAlhGHK+NB0pyHKWgsLdNvaZyuesZkl7HftjyPaAE +rkLYVgSXbz1eoHjXHtiMv2Tqdq3Vck= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=n61RHZno; spf=pass (imf23.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=1743733193; a=rsa-sha256; cv=none; b=WTRUnwHl0053Wslk3FATZo4V3PDS6gUWJieLPQJeMoiVFq2UyE8raUg/LNwNSM7jReUW+G XBj6jDPyFhVki55RpPvJCJEFpdQrHB4jN/WxsqPuA0rjwc25HiDzcQY9C9FcgomvKF8d41 vCgB7ivBNyQXqy5CpNjpLGIIYDoxB8I= 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 5341OBoX001653; Fri, 4 Apr 2025 02:19:42 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=ryv0h p50CeHBUKVemJw6FHGxU5zvzxNYohzdpJ9sUII=; b=n61RHZnoKkN0JJfs3/Hlf h6IrWJsnEFlUd/b4B366oinRoZVtDrmHY6pJX+O1s6xwlt8kKurAEo87AkEjywet GCKGU4Oq2MpXtVGgo+BIE7n5ZED139vL7UjDN56/6Z1/oYWQ2ycqS6kmtQJY8L9W EjE4D4rqdQDRuaFIK1q2sjRo9scjpD7yi3lFVHgB1koE+oNDCWoorlaT/Tw4d2Im IegTCC+lyj5HsAdM6FCwJgSuv9+dfc8iF4W4HnW060ZO2uBoIziivg4X+9KlSh1z 4lALQIVlSBw+2Hzo/7vjiGgC5f4oSwZ+3QUrf7tgv2begUWCGjDQy/9bA5hVe4eA A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p8wcpnq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:41 +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 5340epsJ017365; Fri, 4 Apr 2025 02:19:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjg0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:41 +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 5342H8h4030074; Fri, 4 Apr 2025 02:19:40 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-15; Fri, 04 Apr 2025 02:19:40 +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: [PATCH v2 14/20] mm: create __do_mmap() to take an mm_struct * arg Date: Thu, 3 Apr 2025 19:18:56 -0700 Message-ID: <20250404021902.48863-15-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: 6acAiO5dqkv4w9rAuQqqhxtWfBXsThgQ X-Proofpoint-ORIG-GUID: 6acAiO5dqkv4w9rAuQqqhxtWfBXsThgQ X-Rspamd-Queue-Id: B8D0F140004 X-Rspamd-Server: rspam05 X-Rspam-User: X-Stat-Signature: sqjh6ok96q96thqtcczq4bs386k8fz6z X-HE-Tag: 1743733193-582004 X-HE-Meta: U2FsdGVkX18ywctg5fnHMA/evM0H18YDHrwCPA4sTaqdbjJn4O175S/qol+RrX8tMnXKiVW+GGCm5zFqaAm6Ik68GyRgfToYFT5xB8Ajs99I2wAIzJY9PNsVE81Z3f2t+qHuyxpu6W25YqgfXkVVWi7GcXzMfvusFzrLZ8qbYXruItm8l4ViNayObQBZ105eu8Lzd4I+/+8VqAkuyj/15r7OkR7dqZFDDUoARcljSxdHa3JFzxh/ytMXN+yHGLoCK+qqTzig4q+xIC3qKZ2eJA/aPPONKVcUwm7BVpLDlh8mUgRjOJ8YRakyjmIbrklk9C5beKctnjTLrb08tciI9LgSZsR+U6PQM7bwG4R4vLJnk44jVFYEfEyYBA03h5ZVJpPlq8QIdWvKs8GRtijB9hd/fw4Z2C0EbnOaJyMLgVL7GUIEKBWJNU8xTr7SpYAVxeDqP7yWnDMJFpKfmISFtJWeQoE03dgSMNHsG3Vo1UakS3jx4RaZmdxt0oqfYziHYKfBgAdFnpyjF7QsSnuSdmNwnzmcUAvAxIajgo1Q9HTTQR6CVhqut5OoyJ1GMyEr4trnW4C9Mk1bfjxDvtW51P8MLddDcBYPep+II7h0PYrLJbdvMwVtt6jHaM4rDHT3LGvR5PDr2Xd/4vTbl1xB81ARKUWET9aKuXW0gnPRd8/xySMDDSHE27Lk9ZTTQKz8Ke1rc95iIefAdxZRqxCgeTOauRf1yTsHJH/iua8GVjSMKMSLgfDlkhWK8otnIqWaXKL96Swi5ebXDjC/4Fd/ovrO0bbeUxhte/HpyrXbQ/5auFQmvCTuP91qe6ONEPiH46KrfgwL89cVkA4isUeWkq0OZzcKwmmS3blfJryyrYTaQGbUuGSPUabfqbAJoYiJQzz3/WgtI02W+41DkA8WgwDxxT8xeo7D068hTM//kOu7fOd7IylhTMDvoGO1jHcVuLTrFeruUOwanmPfXo+ yq9FZLoF BIY9BQVctSXK4qSF+0V7byBIY9TGSf23LfKqnTUd+DSA5HBq+bFDvShxvyY2hQ75ElsS5Tp5283v6yDNFcgggFu2UTg4bxO/hi8p4OUH31i7PnYmNkFfA2ffpBBfGQpSCg5JVsDqa2bPWRVJIpzCxIbbhUyTSCzlR182L8mpogMN3B/Ub5BInJjva4Cuah4uL2ET9JG+XAEdwoFwz/GO2SpVt7haK3gR/ULRt22tmGhonvnyba0mlvALWTFslmtXy6zwicnbCS5zPOSNDx6sq5MohMTxCoH6B4qS6 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 | 16 ++++++++++++++++ mm/mmap.c | 10 +++++----- mm/vma.c | 12 ++++++------ mm/vma.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index f06be2f20c20..9e64deae3d64 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3480,10 +3480,26 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, return __get_unmapped_area(file, addr, len, pgoff, flags, 0); } +#ifdef CONFIG_MMU +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 bd210aaf7ebd..0cc187a60a0f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -278,7 +278,7 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, } /** - * do_mmap() - Perform a userland memory mapping into the current process + * __do_mmap() - Perform a userland memory mapping into the current process * address space of length @len with protection bits @prot, mmap flags @flags * (from which VMA flags will be inferred), and any additional VMA flags to * apply @vm_flags. If this is a file-backed mapping then the file is specified @@ -330,17 +330,17 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, * @uf: An optional pointer to a list head to track userfaultfd unmap events * should unmapping events arise. If provided, it is up to the caller to manage * this. + * @mm: The mm_struct * * Returns: Either an error, or the address at which the requested mapping has * been performed. */ -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; @@ -558,7 +558,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)) diff --git a/mm/vma.c b/mm/vma.c index 5cdc5612bfc1..9069b42edab6 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -2452,9 +2452,8 @@ static void __mmap_complete(struct mmap_state *map, struct vm_area_struct *vma) static 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; int error; VMA_ITERATOR(vmi, mm, addr); @@ -2521,18 +2520,19 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr, * the virtual page offset in memory of the anonymous mapping. * @uf: Optionally, a pointer to a list head used for tracking userfaultfd unmap * events. + * @mm: The mm struct * * Returns: Either an error, or the address at which the requested mapping has * been performed. */ 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) { unsigned long ret; bool writable_file_mapping = false; - mmap_assert_write_locked(current->mm); + mmap_assert_write_locked(mm); /* Check to see if MDWE is applicable. */ if (map_deny_write_exec(vm_flags, vm_flags)) @@ -2551,13 +2551,13 @@ unsigned long mmap_region(struct file *file, unsigned long addr, writable_file_mapping = true; } - ret = __mmap_region(file, addr, len, vm_flags, pgoff, uf); + ret = __mmap_region(file, addr, len, vm_flags, pgoff, uf, mm); /* Clear our write mapping regardless of error. */ if (writable_file_mapping) mapping_unmap_writable(file->f_mapping); - validate_mm(current->mm); + validate_mm(mm); return ret; } diff --git a/mm/vma.h b/mm/vma.h index 7356ca5a22d3..a6db191e65cf 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -292,7 +292,7 @@ void mm_drop_all_locks(struct mm_struct *mm); 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); int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *brkvma, unsigned long addr, unsigned long request, unsigned long flags); From patchwork Fri Apr 4 02:18:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037997 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 E297FC3600C for ; Fri, 4 Apr 2025 02:20:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97A5F28000F; Thu, 3 Apr 2025 22:20:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9038028000B; Thu, 3 Apr 2025 22:20:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7306628000F; Thu, 3 Apr 2025 22:20:00 -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 4D48E28000B for ; Thu, 3 Apr 2025 22:20:00 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DB1F781B2D for ; Fri, 4 Apr 2025 02:20:01 +0000 (UTC) X-FDA: 83294756202.11.EEA7DFD Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf22.hostedemail.com (Postfix) with ESMTP id 1DC74C0004 for ; Fri, 4 Apr 2025 02:19:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=jjuzDj3q; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf22.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=1743733200; 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=K79b88UIyoJS+J3UJtmo5bx4rIGf4HjUwc2YR+jqvkc=; b=2+PcMUMjFgdimcQ4O/c2AbunvwdphcQEyxsHROrfbCdFl3KgsG4RlsE6FIKcqcXKi8XEKz lmgtmI/vTZfBrc/tB0+Yrhrtjzmv5OCXLMZSBx7fR2YfJd5Rzdn9ob2Hix7MwyBUYvldZ6 v0P9+Tnym/NRoGl02hLIKJyl49DOx+E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733200; a=rsa-sha256; cv=none; b=fBMgNo4fqez/4x5ITZry+AyWt2p2JYXC7jXDifT+oinvrrjhXlG3oxoa+kNrbz7B/0k9/J 7oXumZ3+Blc8koS2S8z/UoKcB4oeua3tgmefN93G4f+05LxsXDpCcw4veDazzDLhw3esAl 3mWJ3q+0noKhMzUag/yZyW8bKOcDmAY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=jjuzDj3q; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf22.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com 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 5341NVrf000752; Fri, 4 Apr 2025 02:19:44 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=K79b8 8UIyoJS+J3UJtmo5bx4rIGf4HjUwc2YR+jqvkc=; b=jjuzDj3qp82UuFSa0katb Z4ToABUz7mu2SzMP6UijRLaJJfhB0/O+5g/tMRQLUrB2dNA3/8ZFs5xYMKuvLMNj HVRrOfgC1Zu94cIkXMTDAh4cl6SeV9PG9TUd8uMtVXj8tCIqT1oAi+HSwyJPQpla eIDKkD9z3w+8H4Lev0pUX3tOVHFenoWpeI/BWWHO+U4pqSVb4w7TALvUEK90DPC7 PZRqkJo/RN/2fW+NI2Y2GQZd4d26GgP+fFVlYkD+881h6g8268dHG4oASKT8Ju5k pMFxyayFU7ZXg8oQWAc5Fhtn4w8nLWZ7YMjIlw3wv99A1g7xmQVZQfLVEg5ZrQKC A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p8wcpnq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:44 +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 5340g3PN017380; Fri, 4 Apr 2025 02:19:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjgk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:43 +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 5342H8h6030074; Fri, 4 Apr 2025 02:19:43 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-16; Fri, 04 Apr 2025 02:19:42 +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: [PATCH v2 15/20] mm: pass the mm in vma_munmap_struct Date: Thu, 3 Apr 2025 19:18:57 -0700 Message-ID: <20250404021902.48863-16-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: FD5x5FdaburlWteo41CRHnMs6Jy6iOM4 X-Proofpoint-ORIG-GUID: FD5x5FdaburlWteo41CRHnMs6Jy6iOM4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1DC74C0004 X-Stat-Signature: xn1yuj3csge7zpxa41uupjioo5kmfxrq X-Rspam-User: X-HE-Tag: 1743733199-180981 X-HE-Meta: U2FsdGVkX1+CWfGHkNo0gdOo7SMy8+JbaEZTOoeJcen5egqeJHaQrsgVX1LQrmX2I91/7KYkauyS6a3v7fO8/wAquSm5lHRFsuY8NTrev1zpTBqHI5DtCFaJaoUWjEDrviSXXnrs+IseOTgen9s3ZAnWBDczm6R0viKNZhsFBuQzCd2syGanUr/xoXLmyUpqqHmESqhNN8yTpr/ELzNZqhwwxe6dCHbpf7g47CySafLQKqGKIzBw4jo9aAyTE4RdYKxhS4dOJcLwB4c65myE/4eHiSy76gmdjY5fndh9VyG1JxXhD35dkmuRSZgZef7TR6HrxKJQHT6wvigwpXgKoWKrWHFMkcNHT0ZKhTxGbbV0PcqmVfBa34u7NaqIFcYkxk+ndfELB70Txsv0MRtG/eYX+t4pxjZ+qV/koRn/hMXfP8/7BeIq6rR2Xbg9l5SQENaJt0f27kB7vMMCNTuHP2+4qDoWXWmATQDMAwHcol895M0+CoPWjGYWtSoCDbo5oXK1XiZoWPyRe6vRJfpx3U95/gUqWvqBmfFiaLWtNSLDxfAMP7og3rYolS7DjW4Vuv6WJCqBowgQlllocydbsyXxxcsiVqttysLfWBfr1fW4j/050azKncM19gvettiJsnZilYrlSzN7fLeSVa4wof0xLvCWG/fhIzmAn3LKB7QRrAjhAYfWSXHweINAIpK92lm5VJHy3TdIeBsq1MeMhnCIwr2QPidZg0JI7I9XuaT+RFyDktiIPruCTkE3OvikIGHL22LzKdkil72zJKsyfxgGe1NXf7a+3GYAa3Rexjdw8PfnVoXWS3zyQNSlOt7cIoVyZ4bfHx/7tY44iTiO+ubhuBAXp2NHUqkbqnd0oJelirAneNPXUl3ijW/qazu5kIETgF2QBJqsr8JqDG00ksvZ1aZ6osWUvWXwJ+g7+V58kSkN3Kq4Wg0eSzmYFigu 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: Allow unmap to work with an mshare host mm. Signed-off-by: Anthony Yznaga --- mm/vma.c | 10 ++++++---- mm/vma.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 9069b42edab6..c56f773c06c0 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1188,7 +1188,7 @@ static void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, struct vm_area_struct *vma; struct mm_struct *mm; - mm = current->mm; + mm = vms->mm; mm->map_count -= vms->vma_count; mm->locked_vm -= vms->locked_vm; if (vms->unlock) @@ -1396,13 +1396,15 @@ static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, * @start: The aligned start address to munmap * @end: The aligned end address to munmap * @uf: The userfaultfd list_head + * @mm: The mm struct * @unlock: Unlock after the operation. Only unlocked on success */ static void init_vma_munmap(struct vma_munmap_struct *vms, struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long start, unsigned long end, struct list_head *uf, - bool unlock) + struct mm_struct *mm, bool unlock) { + vms->mm = mm; vms->vmi = vmi; vms->vma = vma; if (vma) { @@ -1446,7 +1448,7 @@ int do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, struct vma_munmap_struct vms; int error; - init_vma_munmap(&vms, vmi, vma, start, end, uf, unlock); + init_vma_munmap(&vms, vmi, vma, start, end, uf, mm, unlock); error = vms_gather_munmap_vmas(&vms, &mas_detach); if (error) goto gather_failed; @@ -2247,7 +2249,7 @@ static int __mmap_prepare(struct mmap_state *map, struct list_head *uf) /* Find the first overlapping VMA and initialise unmap state. */ vms->vma = vma_find(vmi, map->end); - init_vma_munmap(vms, vmi, vms->vma, map->addr, map->end, uf, + init_vma_munmap(vms, vmi, vms->vma, map->addr, map->end, uf, map->mm, /* unlock = */ false); /* OK, we have overlapping VMAs - prepare to unmap them. */ diff --git a/mm/vma.h b/mm/vma.h index a6db191e65cf..572a11274114 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -49,6 +49,7 @@ struct vma_munmap_struct { unsigned long exec_vm; unsigned long stack_vm; unsigned long data_vm; + struct mm_struct *mm; }; enum vma_merge_state { From patchwork Fri Apr 4 02:18:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037998 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 41203C3601A for ; Fri, 4 Apr 2025 02:20:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84542280010; Thu, 3 Apr 2025 22:20:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F2E328000B; Thu, 3 Apr 2025 22:20:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69468280010; Thu, 3 Apr 2025 22:20:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3FC6128000B for ; Thu, 3 Apr 2025 22:20:01 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CADA7161BDC for ; Fri, 4 Apr 2025 02:20:02 +0000 (UTC) X-FDA: 83294756244.05.15FD02F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf10.hostedemail.com (Postfix) with ESMTP id AAC94C0005 for ; Fri, 4 Apr 2025 02:20:00 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="nVX/7zKw"; spf=pass (imf10.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=1743733200; 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=Bl6JEql6MB9CDGJQFpauhei0hhqynyHJJWlm3XmR/I8=; b=226xaXaXnS9AQJhQvS7SRv62Kau8H+Jrnky7kiuJE7r27jvtvlYU8cIWcj/FvFqa/NfZ/m eMM73N7R21DAgYOkf8oYmT/+8zxMZY6ln/tGwL6eyjesVQkHMMv2R5ECSzBYUIxBBnVZsV PwWD++QEK9BD6KmNcbRJS1OZI8RusU8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="nVX/7zKw"; spf=pass (imf10.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=1743733200; a=rsa-sha256; cv=none; b=e7kMS1H6/VsVRW0/p9ysBqhvLHrYcYjlhOrAryb5P08VceA8L9D40HI0Zr/2DLUCWMPnxC Qs2rQ/cPkPod2i8XWJo1RCm+wM6h8slpS9Mn43CbvEtoJ1yGgX7GC+WQhoDkj8sQYDKeKC zZyKdpXaPjnTb7n63WjdJXMYc0UKRzE= 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 5341N6uL019296; Fri, 4 Apr 2025 02:19:48 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=Bl6JE ql6MB9CDGJQFpauhei0hhqynyHJJWlm3XmR/I8=; b=nVX/7zKwS3gvI5qsECKtH NDs4jsDPlOmEiOijuVxA7pDbWh0oA9B2JvEmGCr0PVxf8/XX+eB4Pkri3RebMNQa Z74UOgbSpazeIGDFw5Yl8aTiKz2Lb0Akk5JnGojhJ2ZNT9+kjz6Wq1bdZ5jr3z94 YDjCmXcWktK7zefv1mjhACAlIqskyaqbT0M03ydZbNJjoxQRi9nQz9EWBNMJYpeH 39adnsY7ZXuemdSz+ihLqXYWCY8cGte6S7eY68F2eCCdxfNGdnqR0aXrdmLWu7R7 MpXRALsgtYLWZmVKTssUkKVLKkWA8Qm2fulI2+F7oarjKxE6ialYmpq7svcFWdo7 w== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p8r9ntk8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19: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 5340Wvcw017307; Fri, 4 Apr 2025 02:19:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjh4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:46 +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 5342H8h8030074; Fri, 4 Apr 2025 02:19:45 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-17; Fri, 04 Apr 2025 02:19:45 +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: [PATCH v2 16/20] mm/mshare: Add an ioctl for mapping objects in an mshare region Date: Thu, 3 Apr 2025 19:18:58 -0700 Message-ID: <20250404021902.48863-17-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: x4FlRSVJiVrDyZtaVnRO1ABhBBdbOkij X-Proofpoint-ORIG-GUID: x4FlRSVJiVrDyZtaVnRO1ABhBBdbOkij X-Rspamd-Queue-Id: AAC94C0005 X-Rspamd-Server: rspam05 X-Rspam-User: X-Stat-Signature: aeniqkq66jj7ocrwxxdbqa75h3e1f5ga X-HE-Tag: 1743733200-858545 X-HE-Meta: U2FsdGVkX19VXCSBCcc1qZX1GM9InAsVKuMU7/IXDzBStddhSnDxn2cRgsFcV0RlyXzgE5D8XJi9tArIb+YKU0uBDc8khzKf5D9CMSeyXYmq7qQHbtLPDQOxdvM9l3rzxj/FBePSH2EMBOhASYcQ6L1eJiohSyrYIv9pNGIG6Gn6ORbtdsvusK3fPLk5a9Ez/O0xFPXomDv6ReJeqnAyxjjpboQZ0SbGmAiDFc18CXKlhpsFIFdrUeiOBV5Wi8kXTJiJm+H1MEaQ32OhTy9acfG0+7GbL7jwgrr4ZErXabN3oaeKexWy2GUgSSlANXvNP2WI9jinYs+g6UVPThPOUg8t8g6nfIx29L5xR6pFMPv7UfPkx545o8E9i+lDl5RjvrBAr3smxTwTtQFJWKCvNQXv2+L+XYBn1eB5F2vvOKioivjkyDUD/wWAEW9i1JDAi/pJDg7ZoTUVWDT1DJRSjNOA2qHvES748b7n9cyo1fsXAPpMuN7q6V1szPIepbgG+0H3HiWigdSb/Q+o1N/0boPzyOePb+ReYUZdYmhC3k/wlg1nofOAniZ7emgT1X7xiY5QgnO+beWkXwJONkfOPNnPYfR2HdqLZpiW6m70VqpSAWrgB8YPGW+nw3iG+ytVLqpP0z34OzzJ8zMmgnSTDOKelL38TN68WNsRWpFaByppgr/RPD+flVHT3nsReqKSgRcVPzNA0Q1PHtGVoWypl0D0vN/bttpdLsNcdV4lTAvpT4TnjQcmEyebquFNWMB1g7X+x6r6ZoqdH+pqjuZzzAGf2lu3PH9V6XhA3BfuwxE92b1PdYx5+kLz4Iy7RRm5V92TU+PrcEwQKSSQ2BQxlYzLH/yTI3g9oZj/JsXPnYWZBI/qrmZ+tG3JA/nSLWqMLAoegooKFH12f4Aoj1m6ZtVnWwrhhyq7bLrGu90Tr74zCWCeKy7H6tjAQ25a6oPMDRVTvkVLlCc6HrZhiap Z3pPvZTQ XG9I5APayJoIsnRcIV4/fFbebFK2+pQTJSfTDG4+PK5L/Q+/K5SHK3J9a/K+t+AvU7znv+YALgOJsI7Nnq9SagGfeqL/KXxNdgpPPIg2hc6L+xyYADVVxLBgF4n9uokLTpaE5fBtCjh4+BwI3KwandZ8w+Dj+3n5r/BraI5Z62X37XZfNkaIimBsm+Rk35YepwmqgUcCpRbP3kxF3auyeb5Vwb0GKHnMV/h6UTzm38IhNbrq+diag6s96Z2yfsbFkHPmBRLceln9M1hoTSQcV3xIR2NhV6YCU2BxT4MG8BBu1vvzkySGuuDTsk9NeCAy8xYmEKYhYFWHH4HJp6vnSMhxjqY7m8cCr/X2BHo6bp3o2+2o9avPBllh2vbLRqQcoSzXYYXFYUPkXtYONJiRZ6BvQ+DR6yQhms7Qf 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 Reserve a range of ioctls for msharefs and add an ioctl for mapping objects within an mshare region. The arguments are the same as mmap() except that the start of the mapping is specified as an offset into the mshare region instead of as an address. For now system-selected addresses are disallowed so MAP_FIXED must be specified. Only shared anonymous memory is supported initially. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- .../userspace-api/ioctl/ioctl-number.rst | 1 + include/uapi/linux/msharefs.h | 31 ++++++++ mm/mshare.c | 74 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 include/uapi/linux/msharefs.h diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst index 3d1cd7ad9d67..250dd58ebdba 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -306,6 +306,7 @@ Code Seq# Include File Comments 'v' 20-27 arch/powerpc/include/uapi/asm/vas-api.h VAS API 'v' C0-FF linux/meye.h conflict! 'w' all CERN SCI driver +'x' 00-1F linux/msharefs.h msharefs filesystem 'y' 00-1F packet based user level communications 'z' 00-3F CAN bus card conflict! diff --git a/include/uapi/linux/msharefs.h b/include/uapi/linux/msharefs.h new file mode 100644 index 000000000000..ad129beeef62 --- /dev/null +++ b/include/uapi/linux/msharefs.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * msharefs defines a memory region that is shared across processes. + * ioctl is used on files created under msharefs to set various + * attributes on these shared memory regions + * + * + * Copyright (C) 2024 Oracle Corp. All rights reserved. + * Author: Khalid Aziz + */ + +#ifndef _UAPI_LINUX_MSHAREFS_H +#define _UAPI_LINUX_MSHAREFS_H + +#include +#include + +/* + * msharefs specific ioctl commands + */ +#define MSHAREFS_CREATE_MAPPING _IOW('x', 0, struct mshare_create) + +struct mshare_create { + __u64 region_offset; + __u64 size; + __u64 offset; + __u32 prot; + __u32 flags; + __u32 fd; +}; +#endif diff --git a/mm/mshare.c b/mm/mshare.c index 4ddaa0d41070..be0aaa894963 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -10,6 +10,7 @@ * * Copyright (C) 2024 Oracle Corp. All rights reserved. * Author: Khalid Aziz + * Author: Matthew Wilcox * */ @@ -18,6 +19,7 @@ #include #include #include +#include #include #include @@ -230,6 +232,77 @@ msharefs_get_unmapped_area(struct file *file, unsigned long addr, pgoff, flags); } +static long +msharefs_create_mapping(struct mshare_data *m_data, struct mshare_create *mcreate) +{ + struct mm_struct *host_mm = m_data->mm; + unsigned long mshare_start, mshare_end; + unsigned long region_offset = mcreate->region_offset; + unsigned long size = mcreate->size; + unsigned int fd = mcreate->fd; + int flags = mcreate->flags; + int prot = mcreate->prot; + unsigned long populate = 0; + unsigned long mapped_addr; + unsigned long addr; + vm_flags_t vm_flags; + int error = -EINVAL; + + mshare_start = m_data->start; + mshare_end = mshare_start + m_data->size; + addr = mshare_start + region_offset; + + if ((addr < mshare_start) || (addr >= mshare_end) || + (addr + size > mshare_end)) + goto out; + + /* + * Only anonymous shared memory at fixed addresses is allowed for now. + */ + if ((flags & (MAP_SHARED | MAP_FIXED)) != (MAP_SHARED | MAP_FIXED)) + goto out; + if (fd != -1) + goto out; + + if (mmap_write_lock_killable(host_mm)) { + error = -EINTR; + goto out; + } + + error = 0; + mapped_addr = __do_mmap(NULL, addr, size, prot, flags, vm_flags, + 0, &populate, NULL, host_mm); + + if (IS_ERR_VALUE(mapped_addr)) + error = (long)mapped_addr; + + mmap_write_unlock(host_mm); +out: + return error; +} + +static long +msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct mshare_data *m_data = filp->private_data; + struct mshare_create mcreate; + + switch (cmd) { + case MSHAREFS_CREATE_MAPPING: + if (copy_from_user(&mcreate, (struct mshare_create __user *)arg, + sizeof(mcreate))) + return -EFAULT; + + if (!test_bit(MSHARE_INITIALIZED, &m_data->flags)) + return -EINVAL; + + return msharefs_create_mapping(m_data, &mcreate); + + default: + return -ENOTTY; + } +} + static int msharefs_set_size(struct mshare_data *m_data, unsigned long size) { int error = -EINVAL; @@ -285,6 +358,7 @@ 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, .fallocate = msharefs_fallocate, }; From patchwork Fri Apr 4 02:18:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14037999 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 C1CC9C3601B for ; Fri, 4 Apr 2025 02:20:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05A53280011; Thu, 3 Apr 2025 22:20:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00D3328000B; Thu, 3 Apr 2025 22:20:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2D0A280011; Thu, 3 Apr 2025 22:20:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B479C28000B for ; Thu, 3 Apr 2025 22:20:02 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 19695121C4B for ; Fri, 4 Apr 2025 02:20:04 +0000 (UTC) X-FDA: 83294756328.03.3860E17 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf14.hostedemail.com (Postfix) with ESMTP id 241EB100011 for ; Fri, 4 Apr 2025 02:20:02 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="g8/rtzC/"; spf=pass (imf14.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=1743733202; 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=qKETl3boxGSqY1XHPbVbmfYTJqsfiqERPIv13nBPjsk=; b=s4MQnIoC33m59570wcaTSo6Uui+8V/+Fvm48rtVuTAc6OqzPGm8obmoyREjyjDuCTIXRAH 5YE8acqBlxH/+0c+CP6OuHwCWHuFsfATBG22YP8O3XNN9MYx6dMux3v9TVeDwrii+NKY1D vtrth0Or3ph1N6Be5XTw2PbT4dAnj+E= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="g8/rtzC/"; spf=pass (imf14.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=1743733202; a=rsa-sha256; cv=none; b=h8t4GtXe2KawReH/BGMhXj80lBJ286I0FbUjL1U/SomT581DmTHZV48wFEFjPOLlesYfYL YsAvOWX5LI5vs/eL5zAhtLPEAZlEPklJs51GHj5VBpUsM6wrDDvZVk6tpRoIBavgtBu/j3 lm+3/arYpyOBbT/koOFaE+lm1jLHwts= Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341O7Gg024208; Fri, 4 Apr 2025 02:19:49 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=qKETl 3boxGSqY1XHPbVbmfYTJqsfiqERPIv13nBPjsk=; b=g8/rtzC/YcIbSBczu3C+P wkfNxw3vt28s1VNtVjUrMPbz6ydnxVpgi9ZqSQN+QIZ3OIF3weOFsoF90AmHF6QF je+LmZn+1Nf1sogguuAS/OmcHFex4zdh0qcYUGJByl1tRXBcw72PKC/U1/o+zAW3 QtmmRb/Fq9VmX+V1ynnqTyTBWWrIULyI+KuLLzV/DWeSjP9x9FWz6m1sXEG0h8x+ LaIrrWJ6indGXgjZzeHXmPYNl4Szbnf1Xv1Qhi2q+pG8sm8l03CItwdpbQSuwhaS 7yXWXOcoK0nmuDxVr6DeFrR4e8reRFHoOdwcszXYLdmLs0twU7HRagaQ+krmyOtU g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p8fsehf2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:49 +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 5340fRNl017354; Fri, 4 Apr 2025 02:19:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjhj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:48 +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 5342H8hA030074; Fri, 4 Apr 2025 02:19:48 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-18; Fri, 04 Apr 2025 02:19:47 +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: [PATCH v2 17/20] mm/mshare: Add an ioctl for unmapping objects in an mshare region Date: Thu, 3 Apr 2025 19:18:59 -0700 Message-ID: <20250404021902.48863-18-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: _v_EaYXFzgUP_UK3Jm0_mzqmEOIgUWb- X-Proofpoint-GUID: _v_EaYXFzgUP_UK3Jm0_mzqmEOIgUWb- X-Rspamd-Queue-Id: 241EB100011 X-Rspamd-Server: rspam05 X-Rspam-User: X-Stat-Signature: tbjhtyypb3jpy8i4ppruau9ukkfap9hi X-HE-Tag: 1743733202-582034 X-HE-Meta: U2FsdGVkX18xlVXcztyW/EW4e5zwpd1EIGx90qLH2qbaRiciGfEs4pw2U7drvHD2CD/wgGiqbWIm/D5t02c04zhkw64xr+M2KhBf8aIpuUlo73twFVWvaZWTR976ypoNdXiVIgD90IZrrQMQWyGolEMrcwYUEmHvmtQ3mgzP2sXf5rqLFULl9zxup3TAvdW83EhJzW8b2z/kaS57+Y77exvbh3e49VK/C5S+F7BFCAy95tppbgf9Qxi3XGnns1JMF93WZVTO7qH/zSH2F5WtxMpYJvhLxRa5OT1EWfI/yLjKQ6XTGj8y6EKGFKbCyewR/0DoJL8BOpZmnSQNsk6vbbIKgJmI+C9ynvZFYaM44XQl6H3GYVhz/1Oc/oxv9WyGvxV2gBvThybf87BGXRgsCLYZ4gxEyV+dwMAZmARkbwZWd1IpG5TL0kmURCIjwlnJFG4Rwd8lg/dqzq/YQNm0Db9UikBbBkftLHAkDBqmch66FPqTvmC7NM9lBw7BhDxIkuySTC/VILEwbu/LPfsfERPFoxqxjWQLXW8uEYopxGyiDa+L6JWk9FTs22Cs0Jn+8nFfxCQvBt0jxf4tm3q8rB4iSBpN1Rcft/ykUppYXogi/poI3+ss4ls3JomP2OPAnmfWHHTOjlUaHoD3nYHgbOq02H1v9Q86C9HXRCmca3WyJOGmJfNDnKT3SAxfml/XJQptUbGe6D7vQxPAK4yKI2Z3y0dUxins6RVpQSZHrkKRurJ0EMOCT8ngOCFgxWKTRsNMj02bPpi/RhwJNDnyXr0C39B7CPEICPl1R+EouxU5hkJNNOg/FSAkQwQ5AVfVwc2i3Ip427BLnOlint1Ox17ogUZXmTlAhwZZGR6bmD1egt+QaT0Ijk1ixmTYZ95h+8wf3jlbugIPgm+NImzY3od8qM1fxlOve9dCKpvJF8uPQkf9UUMbEpJDDpPWCfERwzDms/2uvqPlf+iT6sL nuHs97gV nuDh/XmYF7D3LbzQS335wAdDeLgdvNj8N94c+8z1dAJiLKeNh6ZesDob7lNGJ+XA8ig3fwumZWdzDdhMlOYO+tjy7+d6eHb/itlc+uhnHbenK6Cttz5m37dHtiDQT1Vp4r5SL/V6LQqPoL/V1//u5cEETkEhrlMq1EJq0TsDvAuA+q/k3wwXvolIKJMA1Z+Y6rZ8on7sJy57y08eYJpg8JFyjVc2iFC9ILjT0QvtJeDs/IFv9eQF7/UiVzQ== 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: The arguments are the same as munmap() except that the start of the mapping is specified as an offset into the mshare region instead of as an address. Signed-off-by: Anthony Yznaga --- include/uapi/linux/msharefs.h | 7 ++++++ mm/mshare.c | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/uapi/linux/msharefs.h b/include/uapi/linux/msharefs.h index ad129beeef62..fb0235d1e384 100644 --- a/include/uapi/linux/msharefs.h +++ b/include/uapi/linux/msharefs.h @@ -19,6 +19,7 @@ * msharefs specific ioctl commands */ #define MSHAREFS_CREATE_MAPPING _IOW('x', 0, struct mshare_create) +#define MSHAREFS_UNMAP _IOW('x', 1, struct mshare_unmap) struct mshare_create { __u64 region_offset; @@ -28,4 +29,10 @@ struct mshare_create { __u32 flags; __u32 fd; }; + +struct mshare_unmap { + __u64 region_offset; + __u64 size; +}; + #endif diff --git a/mm/mshare.c b/mm/mshare.c index be0aaa894963..a6106f6264cb 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -281,11 +281,41 @@ msharefs_create_mapping(struct mshare_data *m_data, struct mshare_create *mcreat return error; } +static long +msharefs_unmap(struct mshare_data *m_data, struct mshare_unmap *munmap) +{ + struct mm_struct *host_mm = m_data->mm; + unsigned long mshare_start, mshare_end, mshare_size; + unsigned long region_offset = munmap->region_offset; + unsigned long size = munmap->size; + unsigned long addr; + int error; + + mshare_start = m_data->start; + mshare_size = m_data->size; + mshare_end = mshare_start + mshare_size; + addr = mshare_start + region_offset; + + if ((size > mshare_size) || (region_offset >= mshare_size) || + (addr + size > mshare_end)) + return -EINVAL; + + if (mmap_write_lock_killable(host_mm)) + return -EINTR; + + error = do_munmap(host_mm, addr, size, NULL); + + mmap_write_unlock(host_mm); + + return error; +} + static long msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct mshare_data *m_data = filp->private_data; struct mshare_create mcreate; + struct mshare_unmap munmap; switch (cmd) { case MSHAREFS_CREATE_MAPPING: @@ -298,6 +328,16 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return msharefs_create_mapping(m_data, &mcreate); + case MSHAREFS_UNMAP: + if (copy_from_user(&munmap, (struct mshare_unmap __user *)arg, + sizeof(munmap))) + return -EFAULT; + + if (!test_bit(MSHARE_INITIALIZED, &m_data->flags)) + return -EINVAL; + + return msharefs_unmap(m_data, &munmap); + default: return -ENOTTY; } From patchwork Fri Apr 4 02:19:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14038000 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 34BC7C3601A for ; Fri, 4 Apr 2025 02:20:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20DFA280012; Thu, 3 Apr 2025 22:20:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 193AF28000B; Thu, 3 Apr 2025 22:20:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F028B280012; Thu, 3 Apr 2025 22:20:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CD80028000B for ; Thu, 3 Apr 2025 22:20:03 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6DC29121D5E for ; Fri, 4 Apr 2025 02:20:05 +0000 (UTC) X-FDA: 83294756370.07.84896AF Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf21.hostedemail.com (Postfix) with ESMTP id 8B7861C0007 for ; Fri, 4 Apr 2025 02:20:03 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=T0ycFXWg; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf21.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=1743733203; 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=XVOpBG1ATs5p2zVw52i4mZc77HmrRT8TPOxFoHoCrjM=; b=iRNDFn9giQ+Y3S2g1nK3PCe3jf37eKmQuumPfONatSXAUXaGLPOy8Mtxo/V8/r6k/eojsm /QeTDuv2hEeO6/6MECGyXNcABJUHOeWJ+wbdluWxJXZK/itEb+5W9AAIzlpoU/0DNsmaVG qua9tz9xoS/VNGFg+ZITh1W6c3uol2Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733203; a=rsa-sha256; cv=none; b=zCfAmvkVENHByV9meK11JwmTiaaDIGpStoW/2FjRDQubFf8qXBePrg3VB8k9n6p0HlhBP7 k3Y5SRH0gflQDOF5wf0waLBJssfTfKuvloK8buyfXt0cvUnXxY/cojVFdWXmh+BltTjp8P xUameMRQ3OtGvhRT8+wzZJC0jMNJ18Y= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=T0ycFXWg; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf21.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com 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 5341NUVY014912; Fri, 4 Apr 2025 02:19:52 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=XVOpB G1ATs5p2zVw52i4mZc77HmrRT8TPOxFoHoCrjM=; b=T0ycFXWglr4qG264tZ4Ua MFwJwR8/2kxZcnXFrVn/sI6L1fLnrrw6eDHlDynQx8dF+z+9m3rsgdVC0h22DwM6 H6uYS4hBH+KoVpdkgRS2AEL4jAE/3/vLNOLww79LUl1q+dk6FH5Clcw6YhckMZjy s5ISGg4LFT/eOAL1LikyzzKT0aGfd1vTIT7j+EZ3SXZYMitMd+u3CQpb+TE4HK9h ncIUxelY8nsWUTAo6lvZW1y6l2b+z510lALMrb8gEIXTg+7ACvBTeahW5IC+Yp5w ZcygkdkENPGmMv6QJx1fOtVv2F0yoWC5m8+mHaMr9DAJBCuBnHnnO7rDcfpHJFq+ g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p7n2efne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:51 +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 5340gpBJ017418; Fri, 4 Apr 2025 02:19:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjj7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:51 +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 5342H8hC030074; Fri, 4 Apr 2025 02:19:50 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-19; Fri, 04 Apr 2025 02:19:50 +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: [PATCH v2 18/20] mm/mshare: provide a way to identify an mm as an mshare host mm Date: Thu, 3 Apr 2025 19:19:00 -0700 Message-ID: <20250404021902.48863-19-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-ORIG-GUID: EgU8HPZBLjq7O2rxK59i4iWFx0NytBa0 X-Proofpoint-GUID: EgU8HPZBLjq7O2rxK59i4iWFx0NytBa0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8B7861C0007 X-Stat-Signature: higoz74gyguzh89go97r7x4jib4g6tsn X-Rspam-User: X-HE-Tag: 1743733203-443957 X-HE-Meta: U2FsdGVkX19u0tFirC9IOeq4nmZGoBoVCgAxFQ3/QrS19Ic4YW3oWkLIVpRZGLICYJQYhn+qRsMlp0W4mmmKxvVMN9W7jMcpv3ieLdFXIIYqLJ1XrfbSkijgOLi5v68bJoYTLkRVWa2lcKy96RNP4mutRobnYCCierlenygPy56TCvdIMBEtjsK16ecD3lZB7IaK+G1v12vRORY/QGFl+yFjKfmkcHxW3Gs3fFFSZSYZOmAJyfqwP8cI8O2khNNUVsiXQ6sYwCzARq02aeJ+6PJSkNbMlGUtA87D87WNvngE8YIgWPOHrrS1aN7okfXtvjKSucKd4Agq9OrUG3falqdtS/4qScnWJ7iqU1E0wdqRGNEjQLBwRaBgr9ojAaWK8Gbqg77GvjJKwshIrnTu47zbwmkyfB7Jemzi51ctsfbRaLi201KNI/ZtEA9lTIEFrfALqWba3GpntptZH6vG2ZjT7An5hr41Q02PeMIzwTswY8t1YdY7OcyAMmcFav+ouKWJFjYBw0tSQBI9ZEiXwLBKxDNaQvv2cEnEX2kCM34FRj6J7FdYiz+czvNMJ7QMLMV4C7lhbzTig4rI/FPyfll4kxFf0icwn4tBfZEE4BZcuXSZK9vy7D1hpTPaLCsWesPHYW7CW/INlsOG4hZPyS16VW7PWfyegpPTav7QSrZmDhX7JnXhDWy/GU/oBeF8+v3J2GQEnF39oQiHwZdl4MtdYTqsUijkwWpyeG38cE+VQkATftzuljVkCQlb4HnyfdkCkz0AL3a+J+ke66SPrXmR0lxiIEtxZe9l/ujtBckFW+gj/v7PnYQw1ZYQXEfi+U9iIRwI8klJyOoF8EYs2b/KhSfBlnExGlUSOxWolZ/BLHGPMEDoVGIRk5rdoApV/Rq3qEkoCjbWZeoPu9dcnKGnJgl8BF2kjBwrK/pGp8FNFwvlBBmKrHjT2oDEcGMI0peTQt/3uKB6yKEHD6B pRDliMuK 3n6T8USrF2wCYdyekQ+MXZR47arjW/iJ4gLqWfpzUrT7Fx8KQ0fEhVigE2+CMkQuG94TwLrkGtBrUOBd0/Chw6J8Z7nw71D9++87VTiryOe8kyVrGHA7pMw6zxYRMae8PadJ91HblHDCNSd69uSd3hlujB2h8wGD4z61i+hfvqa99hpL8j/6amFVYFpFvl33IW+Q8rxz1rAbmm+3Oy9FbNzCC9vXIRYoDUs0KGnA7iuTJBqIkNI5gk+8z9+WAobjENzYKciffnf03dKk= 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: Add new mm flag, MMF_MSHARE. Signed-off-by: Anthony Yznaga --- include/linux/mm_types.h | 2 ++ mm/mshare.c | 1 + 2 files changed, 3 insertions(+) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 56d07edd01f9..392605b23c62 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1741,6 +1741,8 @@ enum { #define MMF_TOPDOWN 31 /* mm searches top down by default */ #define MMF_TOPDOWN_MASK (1 << MMF_TOPDOWN) +#define MMF_MSHARE 32 /* mm is an mshare host mm */ + #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\ MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK |\ MMF_VM_MERGE_ANY_MASK | MMF_TOPDOWN_MASK) diff --git a/mm/mshare.c b/mm/mshare.c index a6106f6264cb..0a75bd3928fc 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -415,6 +415,7 @@ msharefs_fill_mm(struct inode *inode) goto err_free; } + set_bit(MMF_MSHARE, &mm->flags); mm->mmap_base = mshare_base; mm->task_size = 0; From patchwork Fri Apr 4 02:19:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14038001 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 4FACDC3600C for ; Fri, 4 Apr 2025 02:20:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 880D1280013; Thu, 3 Apr 2025 22:20:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8083928000B; Thu, 3 Apr 2025 22:20:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65A7D280013; Thu, 3 Apr 2025 22:20:09 -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 3E35B28000B for ; Thu, 3 Apr 2025 22:20:09 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CDBBB59694 for ; Fri, 4 Apr 2025 02:20:10 +0000 (UTC) X-FDA: 83294756580.30.7C7E426 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf24.hostedemail.com (Postfix) with ESMTP id A5A53180004 for ; Fri, 4 Apr 2025 02:20:08 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=J+Hv+G97; spf=pass (imf24.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=1743733208; 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=hihIyQehB7q3j7k+6F2JpGTXdpMmcUUzS5/DDX7tIkU=; b=3ySq2UsHFBwHhU9BfXQ22VFAMtLeVsiZGl4SfUhd36YMBsQbW+8EL3gSzqzjsa6CSXCTFN 2z9tH4bzhWFjqq6diMzL0/e0982VmGAytA2bznn8JwtAbIMDAdly3Je86o08aVWU2ZDxyd Hhb2Nko6D4akhWMuaSvNCS8pQdcOAlY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743733208; a=rsa-sha256; cv=none; b=MbN6nufHFjsS/7VSR0Xg2xFMDbbQxhxq7IPxN6dtEFr0XVeKGzhunEnDC1UF7XWLJmPb70 VSTyV+x9et6LkjOpRmmL9XM0yg57X0KNmpiUy5/IQjuWhfZ7jLvXl6UMb7e607lG0dPSTm l/EOF31soN4tr3UAM0faiTSJGDnKjbo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=J+Hv+G97; spf=pass (imf24.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 (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341NVI4004896; Fri, 4 Apr 2025 02:19:55 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=hihIy QehB7q3j7k+6F2JpGTXdpMmcUUzS5/DDX7tIkU=; b=J+Hv+G970s0UNw7Fk1O+I xyb+oyhmnpc0YLXuDBxUI4y887SHTjDoosdvUioBOI2UD3vL1iPyM4kEriPVsSNp O1DNYb66WnGlUUJbuhwUWCGnw5hFVCk7NmmNACCCuMQi8gsFpqfb7K0nsaZMrO+c mQyHqX0CLb5xbWuUowP5rBxaFxl6wt7r3CzYeHb1bHPAXl5Qxiy6CrERuLjBFlty FOsfk+Ueac1YYRGI7BG/DwYCi/7h8NtXLqD4RfoY67QlLjMwRqEgPd5SAmJVZSYt cza36SA4valOVbQ3YWNcdGnR5MfhrrmRJo92rigToLHyxAZ9f45wuer+uxd3iyDj Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p7sax3xn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:55 +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 5340f1pR017372; Fri, 4 Apr 2025 02:19:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:53 +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 5342H8hE030074; Fri, 4 Apr 2025 02:19:53 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-20; Fri, 04 Apr 2025 02:19:52 +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: [PATCH v2 19/20] mm/mshare: get memcg from current->mm instead of mshare mm Date: Thu, 3 Apr 2025 19:19:01 -0700 Message-ID: <20250404021902.48863-20-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: 9RFuy4xjdkKWNLG9OWrPNtaQOlvZ7H_s X-Proofpoint-ORIG-GUID: 9RFuy4xjdkKWNLG9OWrPNtaQOlvZ7H_s X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A5A53180004 X-Stat-Signature: dzzdkxe3yqhc18dbwaodjz9f5gs4i345 X-HE-Tag: 1743733208-921678 X-HE-Meta: U2FsdGVkX19eZhf0EekkLkNsdpVJf5Xv0xU2lzC8+Ux7SX64Mpfjm5bnMSz5b8j7m7Uz2DtgNuTFWsk705pOYmaGtTI+ZzJau2XkSBlxydU5ZFFBSklrq2YlYL46ILd5OuY9oBnqGbwYjtoAj6lpp2o4xuhSqQaSujGWdcw07kt9RMySMdLvGTUyIwuTgL0bbwijsW1sRPuh1rL0rTGaYEuRwkSmq/WqqVnKdYrhRmZqXeDsIwRk6SFi1Gq/JLknTWhLqcihQ/eSYmBv6OHTSTR/SUI9OOr/jsSecnNjPYXRcD8p46HKAly4TTc2YBsVlUzy88KsIUnAIR3Io4LJBPcdKDaDQ7q2XERVcp8Xg2elcyyspWk/KxHDmpWbAB7rbwAC0frOH2J7rvF0yTnqVQ7d+xY8LplaSzZq2ingU+0IwA4v3fNchgnHPp9I02sBufvSR22bdJQli7GAi8xQnP4krENnVVFuR0dYvC96pZo/O4SXkptoNpxrI2XxLF0HrHcrHFF8JkvRGC98jwgcsz8KfKFVFx9vAfqioaq0lRnDF0C08r1Hr5bx0nks3oZXOAkBgcc9+7kpG0Qts8je9DS2BWRyLS3BC5A9nDnExi1ApUtHK08rF1Uve7gIK/N1k0zVoV9B3eiw2AcmIasnQmaKmQjF4EG2qs+OSaSn2TrkEoiV/2+87e/xjT4tXtVaDi439oijSrykLArw7P8pxt0U6wFSsocJaSaLSq1N2G/EgR8Y8IhU4lpgXmQycHnGObPyNk9r5g0yrren4Ixqay4ft9924kalVezsZluQjBcQ7BLAe+DXVY4jcjbVlPCt0x4vP1zz8tyFq4GvLBgDQcB9PfYh0yMOsDyuvhlF6GtPlWRWEMSg3gW+L4S8QV0SY5V4MVxO0OQzyp4KEwcUzvKqvq01qs3SoCi5AFMCp1v1jE2zIBkUuIBhAMp3AHm+ivevowX7SgU0Ff9+McJ aGGzmoXj XouFvUxRsdHRk/FF+0yu+4g1dYuZs2zx+PMIJR29DRd+Foa6lD2fKESpQFOSVeb6wipEAnByAD6pg1dfs83dACilLV5+JovZcs9RUdVMcelCbmhgOdYw7NsLDtgEYyAo2TT9cR28rPYUQQT1nKF2DDjp1JSscwgXio17bTTjiha1NvomFGqUtcy4LxR6qL6jinMDPfrcAOFzuP2JKqjvkVQ5nMEb33y3jjrrvrVswtHo1YvrUj5MEIFC7Cg== 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: Because handle_mm_fault() may operate on a vma from an mshare host mm, the mm passed to cgroup functions count_memcg_event_mm() and get_mem_cgroup_from_mm() may be an mshare host mm. These functions find a memcg by dereferencing mm->owner which is set when an mm is allocated. Since the task that created an mshare file may exit before the file is deleted, use current->mm instead to find the memcg to update or charge to. This may not be the right solution but is hopefully a good starting point. If charging should always go to a single memcg associated with the mshare file, perhaps active_memcg could be used. Signed-off-by: Anthony Yznaga --- include/linux/memcontrol.h | 3 +++ mm/memcontrol.c | 3 ++- mm/mshare.c | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 53364526d877..0d7a8787c876 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -983,6 +983,9 @@ static inline void count_memcg_events_mm(struct mm_struct *mm, if (mem_cgroup_disabled()) return; + if (test_bit(MMF_MSHARE, &mm->flags)) + mm = current->mm; + rcu_read_lock(); memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); if (likely(memcg)) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c96c1f2b9cf5..42465e523caa 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -945,7 +945,8 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) mm = current->mm; if (unlikely(!mm)) return root_mem_cgroup; - } + } else if (test_bit(MMF_MSHARE, &mm->flags)) + mm = current->mm; rcu_read_lock(); do { diff --git a/mm/mshare.c b/mm/mshare.c index 0a75bd3928fc..276fb825cc9a 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -432,6 +432,9 @@ msharefs_fill_mm(struct inode *inode) if (ret) goto err_free; +#ifdef CONFIG_MEMCG + mm->owner = NULL; +#endif return 0; err_free: From patchwork Fri Apr 4 02:19:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 14038002 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 A0A4DC3601B for ; Fri, 4 Apr 2025 02:20:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5317280014; Thu, 3 Apr 2025 22:20:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C026F28000B; Thu, 3 Apr 2025 22:20:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A550B280014; Thu, 3 Apr 2025 22:20:10 -0400 (EDT) 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 8570028000B for ; Thu, 3 Apr 2025 22:20:10 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1A5B2161C3D for ; Fri, 4 Apr 2025 02:20:12 +0000 (UTC) X-FDA: 83294756664.16.660BF7B Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf23.hostedemail.com (Postfix) with ESMTP id 25E08140004 for ; Fri, 4 Apr 2025 02:20:10 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HIFU++hR; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf23.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=1743733210; a=rsa-sha256; cv=none; b=L/FyWp2BfSS1doreGY7RVcDrGspt3vvN6ViETc0kuolIPGdPD1P/oXRiTDt/A+SrDow45/ l6XPPbW/dRIcfqQXCnLKW89sFvvFqYXm94YX4F6slHEbsVnBShUH5FrQgUwOZRGw9TwISj Y6oGrkAtYJiB4M8HrkOYQyxGtxiH44c= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HIFU++hR; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf23.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=1743733210; 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=Ktr19sh/3ozrpHi17WBwpuZmpP/ujNYWxACqCHdmQzw=; b=3vrhBNtEjSl6Vfb6jInNhRqY2MuCv3axwJHsErDzswhqpYEyRkYbmlNWi/mvonMeqHts30 6CGtTHwlhwWsV7m47O3LvN3C5dDB2YsMzzrddit9SG7g3z+Lueml+HxZe8CkwgNPNX9azU VIpCy0YCZQS37q4iXIlGDItQaaRJXj4= Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5341NVOE008087; Fri, 4 Apr 2025 02:19:57 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=Ktr19 sh/3ozrpHi17WBwpuZmpP/ujNYWxACqCHdmQzw=; b=HIFU++hRb/Xbnty+H/4sa /c7uqUGMCT8WHv7K8qEEhwEnTnqO3rmkv4oGC1MrjPh+JzyumQoeE1uh62Lf9YKD PxUZqo0Cy1o48l9EiQ9j+4Ko/kwlfwJkLcoZsGPsTKbr6rsZ+gO+40IZrgAMQKWr ssftNQbJs5pk6WlNzEfwBG1qvIj3lPK08D6cgNxPyzLE107WaZLEKbTd8bdqZVNh psRtut/9atoCgF/c9lfZd137EHgKwiHwPRs9ceU7cVqj7cz56RtiYVGCDqqkRzzs ORW2VBPNDtVxk7FboZ2l6yjKgHVrXWb95jySIF8jJI1ODWSD2WDFfEBM1BB4cl3j A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45p79ceaj1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:56 +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 5340ZtwD017309; Fri, 4 Apr 2025 02:19:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45t2pspjk3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Apr 2025 02:19:56 +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 5342H8hG030074; Fri, 4 Apr 2025 02:19:55 GMT Received: from localhost.localdomain (ca-dev60.us.oracle.com [10.129.136.27]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 45t2pspj73-21; Fri, 04 Apr 2025 02:19:55 +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: [PATCH v2 20/20] mm/mshare: associate a mem cgroup with an mshare file Date: Thu, 3 Apr 2025 19:19:02 -0700 Message-ID: <20250404021902.48863-21-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250404021902.48863-1-anthony.yznaga@oracle.com> References: <20250404021902.48863-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-04_01,2025-04-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504040014 X-Proofpoint-GUID: 7vkFVKheDEa9Sb1cTcQnlOeo0S0Hrku- X-Proofpoint-ORIG-GUID: 7vkFVKheDEa9Sb1cTcQnlOeo0S0Hrku- X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 25E08140004 X-Stat-Signature: cm77nned9w3ma3thpo8foiu1x5rce5j5 X-Rspam-User: X-HE-Tag: 1743733210-89335 X-HE-Meta: U2FsdGVkX18b5YYPJU8orzXUBN8g3mDUuhLHnyx3QSpOwUkgQip+eTUR8Mr6W2t/kg8DR0dJMvWRgRWvqygkLKPWj9uhpsx5xoY5R6VP1Ib7PCLy37xI51CZg65seietUo2ndKKjo7wlrXDmfnn2jhPKvOc0dO3R9WeG9YSxy8wOHVkOD8eNC6aBQc3TvcudGHCHc9cKTtPK4DCGxKF/fPzorbYEWYZ4M/loyqLNa2daK6Kckxw/4KDXU8AIUVatJi/mJFsXhCWmGNikgcIednqXhfjrI+B77+wzhNVHziu8BjRCuVklOR8j5O2INkJd+kWl5PmD+d5NSObjUnreCc1bX2Jpw6y5vQBk27v73jkYouYBWKNkVF1vMO26kJv2ORppPtpZv1yuQ8d99VGtDiF1nn1Tu10xyW42/EShj+1+KPeJTUCT+IAODDVTElm7r9AZhj7sqCEB8iLopTjzt5IBos8VIiL1xZ6R6mDnJk6QK5NDRSf2MR9/VGHVmNUYvY34riQummMNa6+BwRTT8nrCvBUAqkhcYnXcHZPngA7v+t9b9x8+oAP0bt354xYMHmYTyXYANOf3YSX/T6SIv3Vv+R6ngoNRuRfG12jYQmSEuRQjG3BBx5mx3QPguaRvkzMdkpmP5bxbM/Kqk7z7hJDISZa4aLx333vYIkbEuT/UbfsxUUM0yv/DsPZM+YSWUDsdwtIoZQf+ZC/jZZNnkECnrVbsxp7MYr9oH8DB+2C6MHH2BLNF1zcQw182ctANf8tB54k+DnnBOUUQwjqlvRYwH8lyEKf8WbwQM9fDNXl8qsrsPq69rXV9tAwArB897lkOpmcTLyMlWO1bieYtUZmAorapSoyzXfN/4N/uo6CXDHJonhInyWmZVtuXZpqv+RApGBRuMVtMr8tMXsSYzBFfDzHYXlbgw+NDdwMKX8mpbw3ZH5bSGZdyP8n0r3a17iawPWKAJMO4qQ8ExbG ffN6Y3c8 hHqblteMMu/NNXTWZXfeLIZGa52Rwopu5gGHrhuPiWmD4QKULhKp8VkSM91y/rilcPVMGbXJNZ52B/1H8wFWZQy/+Su9dI/JrE0RQBhouKonlLpic7vJ63ZPIwvpzTCpc9AMO41pnv1jFmzi7bl1NdzhHfItyNS13P9a1GEKCKNE6ofD3W99K1BTwuHz5TwwDvBEVkgsV34pmWOzdnTVJ+wlq3TsWOQOJFfgfgIgCK24ohR26uYQ3htBlTw== 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: This patch shows one approach to associating a specific mem cgroup to an mshare file and was inspired by code in mem_cgroup_sk_alloc(). Essentially when a process creates an mshare region, a reference is taken on the mem cgroup that the process belongs to and a pointer to the memcg is saved. At fault time set_active_memcg() is used to temporarily enable charging of __GFP_ACCOUNT allocations to the saved memcg. This does consolidate pagetable charges to a single memcg, but there are issues to address such as how to handle the case where the memcg is deleted but becomes a hidden, zombie memcg because the mshare file has a reference to it. Signed-off-by: Anthony Yznaga --- arch/x86/mm/fault.c | 11 +++++++++++ include/linux/mm.h | 5 +++++ mm/mshare.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 49659d2f9316..f79186b76ffe 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -20,6 +20,7 @@ #include #include /* find_and_lock_vma() */ #include +#include #include /* boot_cpu_has, ... */ #include /* dotraplinkage, ... */ @@ -1218,6 +1219,8 @@ void do_user_addr_fault(struct pt_regs *regs, unsigned int flags = FAULT_FLAG_DEFAULT; bool is_shared_vma; unsigned long addr; + struct mem_cgroup *mshare_memcg; + struct mem_cgroup *memcg; tsk = current; mm = tsk->mm; @@ -1374,6 +1377,8 @@ void do_user_addr_fault(struct pt_regs *regs, } if (unlikely(vma_is_mshare(vma))) { + mshare_memcg = get_mshare_memcg(vma); + fault = find_shared_vma(&vma, &addr); if (fault) { @@ -1401,6 +1406,9 @@ void do_user_addr_fault(struct pt_regs *regs, return; } + if (is_shared_vma && mshare_memcg) + memcg = set_active_memcg(mshare_memcg); + /* * If for any reason at all we couldn't handle the fault, * make sure we exit gracefully rather than endlessly redo @@ -1416,6 +1424,9 @@ void do_user_addr_fault(struct pt_regs *regs, */ fault = handle_mm_fault(vma, addr, flags, regs); + if (is_shared_vma && mshare_memcg) + set_active_memcg(memcg); + if (unlikely(is_shared_vma) && ((fault & VM_FAULT_COMPLETED) || (fault & VM_FAULT_RETRY) || fault_signal_pending(fault, regs))) mmap_read_unlock(mm); diff --git a/include/linux/mm.h b/include/linux/mm.h index 9e64deae3d64..e848c29eafe4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1179,12 +1179,17 @@ static inline bool vma_is_anon_shmem(struct vm_area_struct *vma) { return false; int vma_is_stack_for_current(struct vm_area_struct *vma); #ifdef CONFIG_MSHARE +struct mem_cgroup *get_mshare_memcg(struct vm_area_struct *vma); vm_fault_t find_shared_vma(struct vm_area_struct **vma, unsigned long *addrp); static inline bool vma_is_mshare(const struct vm_area_struct *vma) { return vma->vm_flags & VM_MSHARE; } #else +static inline struct mem_cgroup *get_mshare_memcg(struct vm_area_struct *vma) +{ + return NULL; +} static inline vm_fault_t find_shared_vma(struct vm_area_struct **vma, unsigned long *addrp) { WARN_ON_ONCE(1); diff --git a/mm/mshare.c b/mm/mshare.c index 276fb825cc9a..509b1ae8ce72 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -34,8 +35,22 @@ struct mshare_data { unsigned long size; unsigned long flags; struct mmu_notifier mn; +#ifdef CONFIG_MEMCG + struct mem_cgroup *memcg; +#endif }; +struct mem_cgroup *get_mshare_memcg(struct vm_area_struct *vma) +{ + struct mshare_data *m_data = vma->vm_private_data; + +#ifdef CONFIG_MEMCG + return m_data->memcg; +#else + return NULL; +#endif +} + static void mshare_invalidate_tlbs(struct mmu_notifier *mn, struct mm_struct *mm, unsigned long start, unsigned long end) { @@ -408,6 +423,9 @@ msharefs_fill_mm(struct inode *inode) struct mm_struct *mm; struct mshare_data *m_data = NULL; int ret = 0; +#ifdef CONFIG_MEMCG + struct mem_cgroup *memcg; +#endif mm = mm_alloc(); if (!mm) { @@ -434,6 +452,17 @@ msharefs_fill_mm(struct inode *inode) #ifdef CONFIG_MEMCG mm->owner = NULL; + + rcu_read_lock(); + memcg = mem_cgroup_from_task(current); + if (mem_cgroup_is_root(memcg)) + goto out; + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + goto out; + if (css_tryget(&memcg->css)) + m_data->memcg = memcg; +out: + rcu_read_unlock(); #endif return 0; @@ -447,6 +476,10 @@ msharefs_fill_mm(struct inode *inode) static void msharefs_delmm(struct mshare_data *m_data) { +#ifdef CONFIG_MEMCG + if (m_data->memcg) + css_put(&m_data->memcg->css); +#endif mmput(m_data->mm); kfree(m_data); }