From patchwork Fri Jan 24 23:54:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950021 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 3D2B6C02181 for ; Fri, 24 Jan 2025 23:55:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 519152800AD; Fri, 24 Jan 2025 18:55:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CA2A2800A8; Fri, 24 Jan 2025 18:55:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36A002800AD; Fri, 24 Jan 2025 18:55:34 -0500 (EST) 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 1838A2800A8 for ; Fri, 24 Jan 2025 18:55:34 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 680B7C1532 for ; Fri, 24 Jan 2025 23:55:33 +0000 (UTC) X-FDA: 83044004946.20.7836837 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf25.hostedemail.com (Postfix) with ESMTP id 1D744A0002 for ; Fri, 24 Jan 2025 23:55:30 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=MxaiLSyw; 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; 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=1737762931; 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=SBsij5SflBt2Meq/0t4PQFvud6q4J6+i2o2Phuq8JSQ=; b=uV4M5+p3r2GzALguMuc3jSgu5CwbV/pzl2QPLcuOsMi653D6LkCgNREW7xN2kigI3lgWHn UJHsuVPVpOmKpkSin3eErEJqvW2kV2SRmQN/Y11az3dnxhi/p6iJCfIp71BnLDXNcf/q/K RixTnX+dBqyn/+rLUFVgoQ7wfYnEDJA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=MxaiLSyw; 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; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762931; a=rsa-sha256; cv=none; b=K3ECm8LWaAkhbH0ZszFTb1PvtW2HNSF9pKZgnbbPJ/6N6rowjXzb8pQk+3GX/IVaoSbXv/ kP/1Fv5hnprCcbChfMjqAS3iiIFu6xS4c+lUg1EPKZoey6+Pjbl65mWFaqxuSIO29x/tUf faESI+GyjaJMkmgsRmGUQ/wlR8KiXN0= 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 50OIJo4r001375; Fri, 24 Jan 2025 23:55:06 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=SBsij 5SflBt2Meq/0t4PQFvud6q4J6+i2o2Phuq8JSQ=; b=MxaiLSywB8uB8wmqgMOmK yl8K0Aklj279cAA7G4xPcodpnwSRWYGHQOHf2DOpQym6+foRxx8LjV2Ka+hBsOID wz/yQUVE2ZaekBfUZm+dXTq0fwV6+vmgZ0s4W2NhDX9NMl8lD3Yf5hQ6Q7yRo5lY uB9MHV3wuG+pWVfvAm2LlhlCqYAugk4pv/pHWz3LwOPVIss0pYx49iubxWfXyAQN aBTBKPoW/rxgHA26oxVTbXk4H9FzDJV1+qkU8XlBoGAenQTWpXa3S2aXGdfQgdOO pyFF2LgodTDNlH5Beu6mZ/FBTfrHCThLeH6AwK+oT/UHmlU8NQJNZ1IUmzHD4F26 A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awyh5rk1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:06 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMD09R036431; Fri, 24 Jan 2025 23:55:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4a2t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:05 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPi018051; Fri, 24 Jan 2025 23:55:04 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-2; Fri, 24 Jan 2025 23:55:04 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 01/20] mm: Add msharefs filesystem Date: Fri, 24 Jan 2025 15:54:35 -0800 Message-ID: <20250124235454.84587-2-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: H3g567xUR2NiiHY65FwJbZPol2W-orgQ X-Proofpoint-GUID: H3g567xUR2NiiHY65FwJbZPol2W-orgQ X-Rspamd-Queue-Id: 1D744A0002 X-Stat-Signature: 9efkne5shm497i8kj5hq4eufn11db3wc X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737762930-555433 X-HE-Meta: U2FsdGVkX1/lVonI9zBhNkP9bboqR4/ZeqetMIeolph5i6UknPnAegFsnhsbuOKUETy6tIzSH2OEwyF48+HCDdvXzackhhh6nf7EQRj+66I1BZAP3ykdHtqWwnRfoZNIxwNum0slVCz/JTVr/530yNbBkfhzzbuv7sGt5Q6Qf6Sqva2jnBqdpiCkabUNYBDPNanSW+JmnjAoqNsDZeuioDqB6j1suqVMR2aDA3PkQRV0B0axUc1kqWM2YY/fLktZmEFqm/bWnw7gbmS3hhT6WQxfgwlhKdqx8Q2nNmf2OZ4tbk77+AEYbAlaa0m3OZv8Me6kOOpIXscxrIO50AlptPCL8cuivg4ugDa14SKNMxOGNBrU/QKN98pN6hiFWGsUAP4vQo1xt5bTmst4e0Lzrh9iy7HK3wsmoXPJ9xXSs8p86GhkpaMzD+O26yz2d0zyO8+Ix5m5ZqrlThAtmnl4vOGzPeU+XzZfCYQCSo9Awepr1vPZRAe7fperUjzDWqrKVJJtCdi87HaPfjOVAUyKowiFp54fz9MYg/tzUtlukpy7GyUHQbX+hHvfNhV2ovIlxQEEfXxesImu/rZ/DvtE5Z2A5Lr/A7TGVTTK6NJ11q1sAJ+4QUcbw04N/HL7TBsb3w+dMaaKrn0An89zz5Ma+Y+SlT1KwE+NgnGVofE+OaiCJy2z+3/Wt5IuMh4lIIXEFudaNgoykx21BO0lqYx8RpJW8ICQwy9E8XO4DAEXezkqwtW65ZXiSfTKwJSZn2qvISgkQs8lS7DmpVNuotkjneF42M8mi1tlpKdfOudJMfsZngJamQefXSc9tkEVE1zHMxQLCCdr1m9vpU+S945U3bjFDMZ/yzC7AveWsbCyU8zud2jCLZhAhZV4G8kprC2kh6/VLOUoSAST4JW2+ZxFDy3IK5khCAlIzgRciOJOVVpaeqeTYqxXS3qNbZYfABNJl4MohcpqWPL+E/9sdKX VrxBf6oy Bs8V9tPCJ24FPpe2XnNsZnKVs1SiJivEyJPTGK1Zm9nGkaqG4FL/seGqcKAfq/xHnt3qCIMQyjLBtBW19A1E/i/zFItRDU9EYdsfy/2N2Q6wWRjbd9SWz8lE2IARmbzywVd1SqiO7A/FvyX+lvsIE44sYzBy6WNznTUquF604bPFpHgn0gWgyXwI7xcbaQ2QKxsZ+m0bf6SEaS2IUjPWI5hBjbVhJ9BwPBpaj4+blA/AqZ34AxjKavDM7JutI0jaF22G/ithR+A1SsyqrrsugIVNrjA== 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 ram-based filesystem that contains page table sharing information and files that enables processes to share page tables. This patch adds the basic filesystem that can be mounted and a CONFIG_MSHARE option for compiling support in a kernel. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- Documentation/filesystems/msharefs.rst | 107 +++++++++++++++++++++++++ include/uapi/linux/magic.h | 1 + mm/Kconfig | 9 +++ mm/Makefile | 4 + mm/mshare.c | 96 ++++++++++++++++++++++ 5 files changed, 217 insertions(+) create mode 100644 Documentation/filesystems/msharefs.rst create mode 100644 mm/mshare.c diff --git a/Documentation/filesystems/msharefs.rst b/Documentation/filesystems/msharefs.rst new file mode 100644 index 000000000000..c3c7168aa18f --- /dev/null +++ b/Documentation/filesystems/msharefs.rst @@ -0,0 +1,107 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================================================== +msharefs - a filesystem to support shared page tables +===================================================== + +msharefs is a ram-based 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. ioctls are used to initialize or retrieve the start address +and size of a shared region and to map objects in the shared +region. It is important to note that an msharefs file is a control +file for the shared region and does not contain the contents +of the region itself. + +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: + +.. code-block:: c + + fd = open("/sys/fs/mshare/shareme", + O_RDWR|O_CREAT|O_EXCL, 0600); + +b. Establish the starting address and size of the region: + +.. code-block:: c + + struct mshare_info minfo; + + minfo.start = TB(2); + minfo.size = BUFFER_SIZE; + ioctl(fd, MSHAREFS_SET_SIZE, &minfo); + +c. Map some memory in the region: + +.. code-block:: c + + struct mshare_create mcreate; + + mcreate.addr = TB(2); + mcreate.size = BUFFER_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: + +.. code-block:: c + + mmap((void *)TB(2), 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 file on msharefs, for example: + +.. code-block:: c + + fd = open("/sys/fs/mshare/shareme", O_RDWR); + +b. Get information about mshare'd region from the file: + +.. code-block:: c + + struct mshare_info minfo; + + ioctl(fd, MSHAREFS_GET_SIZE, &minfo); + +c. Map the mshare'd region into the process: + +.. code-block:: c + + mmap(minfo.start, minfo.size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + +5. To delete the mshare region: + +.. code-block:: c + + 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 1b501db06417..ba3dbe31f86a 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1358,6 +1358,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 850386a67b3e..68bc967863f9 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..49d32e0c20d2 --- /dev/null +++ b/mm/mshare.c @@ -0,0 +1,96 @@ +// 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_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 Jan 24 23:54:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950022 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 ACB10C0218C for ; Fri, 24 Jan 2025 23:55:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1F2B2800AF; Fri, 24 Jan 2025 18:55:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA7F72800A8; Fri, 24 Jan 2025 18:55:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A47C52800AE; Fri, 24 Jan 2025 18:55:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 860C02800A8 for ; Fri, 24 Jan 2025 18:55:34 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 25EBF819A4 for ; Fri, 24 Jan 2025 23:55:34 +0000 (UTC) X-FDA: 83044004988.25.95872D0 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf06.hostedemail.com (Postfix) with ESMTP id E69A618000B for ; Fri, 24 Jan 2025 23:55:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HLHVaWZH; 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=1737762932; 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=In3/QU715xLhM8W3K3qF4Q+QnYxI0SeFwCtvEoqrM48=; b=6glIp9UYf433+qGx8dZ517ssRxD2VpNvTZgVvqCJwcAhJxKPhFtA9yzSw8z957/9A9zbtd i6pyVWV4WFesfZzaHwnn7P3AvyaXyJXHo+YYzoY8fy5KUMHdbLZQJ7AdA3/2PiIZLCfUTo 1b7ajnOM4RqcwM2549UNPS+pVyCXOT0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HLHVaWZH; 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=1737762932; a=rsa-sha256; cv=none; b=mFEZDKdv4FXnsG0kaGOniHTsVjQGEQP+2qzH3bcQilf6ffrup6GH6X46Stm/7Rkw8QFVu4 B9WyuYYwTvaSRfUkRGF4in66EcmMZDKHL5FrMB2paZfgRXhUA3LW84cgqXAEhRn5Bh9763 0GUzFJ0e+63u4NyWL/u3Hb9i7OqtQCk= 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 50OI9Khf021995; Fri, 24 Jan 2025 23:55:11 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=In3/Q U715xLhM8W3K3qF4Q+QnYxI0SeFwCtvEoqrM48=; b=HLHVaWZH0xw0fUWfpJLKK Yj4Z6fAZf9KRr4nhNheCUsucOkOPRtT9rUPzrmzkRBCKuu1sVUtXUNSLOfpV8vnO mzsnDq8PVtK0+cPlMv21opwInIiL9RXaIcA8qUMCwfBtDkTa+Cw2l6Hgjb4lxtL1 8wHiwShDXIcH5fbohFiO6wkw3j7XMRY3aV3hfxkKGc80voJOUS8yjDJwnl2tCx7o 8XHCVk4ukhdWd+KUJuxLfcCnVRXk6LKglh3ldQ9aFYOEdZD7NYB639sjv6SFJPNt p1Xgj7uGT9HaVf/GhAYRM9w1lsOsYc35T/QPV1hWYjMmqw/v5CETdhBxzWFAVgZV Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awpx5vpr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:11 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMl7J0036434; Fri, 24 Jan 2025 23:55:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4a4w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:10 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPk018051; Fri, 24 Jan 2025 23:55:09 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-3; Fri, 24 Jan 2025 23:55:08 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 02/20] mm/mshare: pre-populate msharefs with information file Date: Fri, 24 Jan 2025 15:54:36 -0800 Message-ID: <20250124235454.84587-3-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: HTWbFrhMb8YrF3VvR_cxKBeK5wrE_S0U X-Proofpoint-GUID: HTWbFrhMb8YrF3VvR_cxKBeK5wrE_S0U X-Rspamd-Queue-Id: E69A618000B X-Stat-Signature: tpetihhe4y1f75xmy7skp9kdznfw3tda X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737762931-892003 X-HE-Meta: U2FsdGVkX18CNmPxV42P1QkFw3pgTRVdPC8AGxgnXWToJKoFvBMOS++ohBnQcwv986pJtQ7qNxQ+4Do7U2DRH7q5zG4bPcMAYkwHmd+Ji03U7NvWNKOo/Zm7C9LrPufOebi1QPtxjSs86nglRo4im33/fhOPla5RnDN/2DGdKDI/Hrfqtjdl1ejP3l15qoZ0+CLnKzzgzGHPYB2/b7MDIAoZhYO+nAZyYs1EdpL/WQgkKg5liTelBuF1+NL9xW+BriILskzaeuAPGHBlmcSgRSgHvJdvUAyF22MxQtCHkfeVv8ZKqQyVgNn+/TAFcIoNTPRuOFmJ82zhzBS+F9QWyrGdvAmR/Z7GRJE70Wb8dFkjiTTjzLYoG+F0BCIFxgUvwr/iKYae3y3ErE2Mu0hMVW2RVjt5RK3nDLM7nsbR+WFIlk2i1M6gYTkYwAC+ZxLtbgF506koPb5aoMysu3jhLF744lijVxeOhUySeohikrVT4WwfrdlPXF9bv+H+HqkgMUXi7uP6CNMJoqbge7XwFoCBJ+XUZcOiPb9daDQFtwN9nCs2rwralob0qWN4W2ppolQV+xLlmZS0tBHs8QUtYmgBG3hqZdEvJASJey6GvmKL89LUQRRaMmDvAKyVSkZAZV7o7lEk1OJ4d0fQ/QzgqZrFafCDf0Abh/kZOcLBBEgj2fkC/4+7ychryL8C+Ww5hr5ql2RzwzjhfqwNMobYspkGKgRNAV5BZzljHvXWWx6CxW8BbxY0nanUhxw93CpXtrtxXFSPVfvN8jQvb0ut5+TDcm9tFdVs2pz984qaRFtOLRNdYUPZUVtmxldxvGFIEMfGQDyW6ha7y9ZEATmN7xfbYMdUo3chZy+mpQ7LR7NaghokoVLLlRFxKFi/2U2scVO8B7hb+BCmGb400n3O0Humia0Ps06n4jBBF8sNxsNgFMg22VRH5mvZQG5G3k15bcLtI7znWef4bdhCfBc M3rzNsPi CXTqVNRpPPeifHGCL7XWbzTg3wkLQ62tR1U4MmijffsHkByR4qo5JesbgxSSFZuriVOyxJ3IpiwUqcl4KrSUFQue2B9gDUFTwIR2Xzkq8TBoWwUj7lBtRlRtgjwGqCAxuIFLlTu6lMt6FTY3SwLtYIy+fnLecc6e4wxlDXNDHse64VMspBIBC9Y/5pIu9KZab5h8WeFCKL5uv5nPH8Oq743Evt3UyogDGqunQp5KL8MKNgGkvB0Pxc9K0aiHDdR8Puwsa 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 49d32e0c20d2..6d3760d1af8e 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; @@ -36,6 +92,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; @@ -51,7 +113,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 @@ -71,10 +135,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 Jan 24 23:54:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950023 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 24355C02181 for ; Fri, 24 Jan 2025 23:55:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FC4A2800A8; Fri, 24 Jan 2025 18:55:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ABA32800AE; Fri, 24 Jan 2025 18:55:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB5792800A8; Fri, 24 Jan 2025 18:55:34 -0500 (EST) 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 BF1B12800AE for ; Fri, 24 Jan 2025 18:55:34 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 67C06121961 for ; Fri, 24 Jan 2025 23:55:34 +0000 (UTC) X-FDA: 83044004988.06.4806661 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 488621A0006 for ; Fri, 24 Jan 2025 23:55:32 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=afhvDSIm; spf=pass (imf19.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=1737762932; 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=nqagYyeBhaL2RlbKKTLc6lxU3rvGauZsyUuzovUQ98I=; b=t5ixm01GC2TCaEMgxZYbaqpz/GQo6Byp/55n7qwMZQXtQzaktADfbb6lp+tjr0c5cxFROu SNT75/HAznDFMspM+s0zhpMFDMWVtK0PJO4s2QaaLNBV36dK6MTSUeNAMvqx94r6IIwmsF d2KUGCUoHFvjRFH8G4BEX7H3Mkf8RWI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762932; a=rsa-sha256; cv=none; b=bZidU5HZlpJSVmdtvd2qfHGWZvjjoOQvmRz5IQ6EalzFe4ex1tg4a0f+Hf3h9m/tjvCCo7 X1U7p8ulnud1A+y4xwVjMKRpQL3N54pIXUymOPP2/0YzVh8RBhrU4af6C+mRzgeTPiG4iu cIWn2ioYOPu/vp6H0q45AQEfolM9I0Y= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=afhvDSIm; spf=pass (imf19.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 50OIRdZF000609; Fri, 24 Jan 2025 23:55:15 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=nqagY yeBhaL2RlbKKTLc6lxU3rvGauZsyUuzovUQ98I=; b=afhvDSImLqAMVCsYQmNcG ariAxBqtOlnnMHGzw4+P9TuWi+BLYUBCKMY/F/pj5x5FO7305VUzzvylCnuwmP4B hhYHZynes5p/hwSoIKvX5ccNh78E9B6di+gQeN+eIe16U3Df3EiBZIxNruSiHRU1 SJ50wwpE0RCkh3J6hYADyKFwjnQbcBOZwctnm2XyerXnxLsMg1bRN4OGjrNW+imS 2mYM2mcM+4MR+bLIYKhWG2LvVwU9fbAiSjcoxgT8/1PTvpcKSwoyu2z+mjgfJzs6 mVUJ4aXylk0CMjxwTAbeXUPl4y5yw2BzkPNJ2p8eCfMQMM1C7R1iqiPhQIjQHyEG w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b06j5j3u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:14 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OLP7ek036648; Fri, 24 Jan 2025 23:55:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4a6c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:14 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPm018051; Fri, 24 Jan 2025 23:55:13 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-4; Fri, 24 Jan 2025 23:55:12 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 03/20] mm/mshare: make msharefs writable and support directories Date: Fri, 24 Jan 2025 15:54:37 -0800 Message-ID: <20250124235454.84587-4-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=781 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: q87c7Eu1K_1GSRczZ328BcrLzGhppaPX X-Proofpoint-GUID: q87c7Eu1K_1GSRczZ328BcrLzGhppaPX X-Stat-Signature: ingqy84bs8ajippf7qawfjax7xpo9yan X-Rspam-User: X-Rspamd-Queue-Id: 488621A0006 X-Rspamd-Server: rspam03 X-HE-Tag: 1737762932-947245 X-HE-Meta: U2FsdGVkX18/2toI/gbM7WtemuspGUBJYGMshq0g/TOw4p1EMaDVFb0XVykMHTQSPdVcbwtGwW8vSxDCMwK2OcyH4wN9pHVV+wK8zFQnzvs1C47l5VidcDqKX5ECvUj5iZt809gcr2IrRkdTuKxt2fk4ILFRQRDV22c2djj8Kr2huuJb0KOSU/8sFQN52OwbdIDs+SVtYMG3MQiZ3e7heLpYFREW1OcxAByRKw495btJ64Z98C35hpIH8cz0SeAUKF14vcJK2aC7nkm/vOuJZtdeTdWpOOrPANKQsVipBaNq9/Ki1WCs/a2382SfAUE2HsGDmrwKmH8T301R/7OOpRc2V+6MDFwdBRAJ0q1XcExqRZdLRUF5iCCMoYBbK8ZCHwSUtFh0jGyWTnEKknHp4PPMFFbCKI22NhtsPjzKHqR4zHPrEp+yu9jirRAfGhZuzlfhkNTzDkJrzXtQX7NOVDnVKEK72Lkgy9vAx06QfsX4aZB83RuTgHILY57DfDi+Kg8lb2YRv/eGZvyNcna+g+ZCy1kMnLdo7Ebr13R0KEoGBnIVGNG7KIvueMKFpN/eqANlX1TLwzoq1e67QKYU37O0s2cgQ2r6DJu/fHOrVqQe/R5Lflb66vbCrVVx1WP27R0CYsN7t0BcqMBYqWP4YwEfepOF0bJrIQ98UHmnoOcmBQOm6DBD/D4Jy0mOEOh5fsawC+jZk0k9EiN3fuyyCrHNi2QPBK6lENufwrlD7XK9hw8cW6TYCj02h7gQk9KyAvTry1wasISXtVuMAjA1TEgzLihQVs6ryGEAA7CLBtZikAz+VqNqt22yqDiroyaE4fTpdxxuoA3DB/CHLBghRCVgSjhz5SAlbOscnjZ5gzQn4FJF9SubVp3z9wmqAptMVM5mnh+6lK3v2dX5qXPKoljaJQk1wiK2fWU/2zbqbzO/29cjon1EiDkfTLDBI00erIi+y7Z5/41dC8AG2Ku iz2Q/kui tWbryqTKFiMOTR3tRu2cl2s8DjVy+P2mEu1bboEsihBwMbJ/KTV2etGwfkvj17Jf+RA9AVYcoQvGnKQ+Itn8yndsUckn6Vw8R3IkoTCJEX/q+4xChSfbkIgmZ6BkIUvXMz3UaE8Sj9/db4+KzKaU/z5NEqtE/3wg3AGkcpG2VAMc6xBQ9W2XFKziVrfpiCEgpi7Nql1hMHYWhSNhzzvZinJLWQFtgho4T9ZoppeOCjtVaKWbYjMGdicAv8oqxFPbBmhWT 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 Make msharefs filesystem writable and allow creating directories to support better access control to mshare'd regions defined in msharefs. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/mm/mshare.c b/mm/mshare.c index 6d3760d1af8e..b755346da827 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -19,14 +19,129 @@ const unsigned long mshare_align = P4D_SIZE; +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, }; +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); + + if (!inode) + return ERR_PTR(-ENOMEM); + + inode->i_ino = get_next_ino(); + inode_init_owner(&nop_mnt_idmap, inode, dir, mode); + simple_inode_init_ts(inode); + + switch (mode & S_IFMT) { + case S_IFREG: + inode->i_op = &msharefs_file_inode_ops; + inode->i_fop = &msharefs_file_operations; + break; + case S_IFDIR: + inode->i_op = &msharefs_dir_inode_ops; + inode->i_fop = &simple_dir_operations; + inc_nlink(inode); + break; + default: + discard_new_inode(inode); + return ERR_PTR(-EINVAL); + } + + return inode; +} + +static int +msharefs_mknod(struct mnt_idmap *idmap, struct inode *dir, + struct dentry *dentry, umode_t mode) +{ + struct inode *inode; + + inode = msharefs_get_inode(idmap, dir->i_sb, dir, mode); + if (IS_ERR(inode)) + return PTR_ERR(inode); + + d_instantiate(dentry, inode); + dget(dentry); + inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); + + return 0; +} + +static int +msharefs_create(struct mnt_idmap *idmap, struct inode *dir, + struct dentry *dentry, umode_t mode, bool excl) +{ + return msharefs_mknod(idmap, dir, dentry, mode | S_IFREG); +} + +static int +msharefs_mkdir(struct mnt_idmap *idmap, struct inode *dir, + struct dentry *dentry, umode_t mode) +{ + int ret = msharefs_mknod(idmap, dir, dentry, mode | S_IFDIR); + + if (!ret) + inc_nlink(dir); + return ret; +} + struct msharefs_info { struct dentry *info_dentry; }; +static inline bool +is_msharefs_info_file(const struct dentry *dentry) +{ + struct msharefs_info *info = dentry->d_sb->s_fs_info; + + return info->info_dentry == dentry; +} + +static int +msharefs_rename(struct mnt_idmap *idmap, + struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) +{ + if (is_msharefs_info_file(old_dentry) || + is_msharefs_info_file(new_dentry)) + return -EPERM; + + return simple_rename(idmap, old_dir, old_dentry, new_dir, + new_dentry, flags); +} + +static int +msharefs_unlink(struct inode *dir, struct dentry *dentry) +{ + if (is_msharefs_info_file(dentry)) + return -EPERM; + + return simple_unlink(dir, dentry); +} + +static const struct inode_operations msharefs_file_inode_ops = { + .setattr = simple_setattr, + .getattr = simple_getattr, +}; + +static const struct inode_operations msharefs_dir_inode_ops = { + .create = msharefs_create, + .lookup = simple_lookup, + .link = simple_link, + .unlink = msharefs_unlink, + .mkdir = msharefs_mkdir, + .rmdir = simple_rmdir, + .rename = msharefs_rename, +}; + static ssize_t mshare_info_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) @@ -105,7 +220,7 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc) inode->i_ino = 1; inode->i_mode = S_IFDIR | 0777; simple_inode_init_ts(inode); - inode->i_op = &simple_dir_inode_operations; + inode->i_op = &msharefs_dir_inode_ops; inode->i_fop = &simple_dir_operations; set_nlink(inode, 2); From patchwork Fri Jan 24 23:54:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC689C0218B for ; Fri, 24 Jan 2025 23:55:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 604462800AE; Fri, 24 Jan 2025 18:55:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E04C2800B2; Fri, 24 Jan 2025 18:55:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A75C2800B0; Fri, 24 Jan 2025 18:55:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DED1E2800B0 for ; Fri, 24 Jan 2025 18:55:35 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8BBE0C19F5 for ; Fri, 24 Jan 2025 23:55:35 +0000 (UTC) X-FDA: 83044005030.17.0CEEBF2 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf18.hostedemail.com (Postfix) with ESMTP id 97A0C1C000B for ; Fri, 24 Jan 2025 23:55:33 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="QY/j1Qke"; spf=pass (imf18.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737762933; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NhoD2UyohCxfveoHgDD+cR1/Lz5zOg29Zxa7SdPOnus=; b=VldAtTpIBehPyKfQonkCH5h0qNxP6vY/mx//0NjFgwnB6Gt7BkUu/DaUMa2ZFilIKlEWs8 4sn8w1+jx1xbs5VL9zvy9KrADMzKG0pdEbkO1laZmVHyBPL/hyQJmeoo/tBKvzwzvunktN b9OJv5ySQcHJ9eSED5rFjWAeMR1lKTE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="QY/j1Qke"; spf=pass (imf18.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762933; a=rsa-sha256; cv=none; b=MVR8WS1llZ+qN6oi4bbd9y5thIMY/gUtGATA9sct5qcPaZM8DT0eozeiIKCrOdlp2BTQ/x vlzY2xRLDMQYljkps6/xPgA164cznWuAQ7F8U6OJdOOYIlLPvoEHXnWcRZfYzrBVji69Wf KeINpTZ34dzvNyPf57sWzs6fc9oBYbc= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50OIV8E3018170; Fri, 24 Jan 2025 23:55:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=NhoD2 UyohCxfveoHgDD+cR1/Lz5zOg29Zxa7SdPOnus=; b=QY/j1QkegXiviWjeo98nh F0qYOSLXLhPu8lHvxPBkZWcdoJTdL2kQQ5KKhw+r7FvhKfeT89mU/GBPMUJZNV3J PLsm+Z+tUfUcTvEMYs/I9TZQg/kCUageWG+NC9Ow86/c7xqZ6XfG7HIwmrRcphEF +HN9Liqi6GKNxKo2ChglsrDyGdD6jGWhUk28dqmv7mwWG6OZYzVbfs0c30TFBalR OpDG5IKFMnf11Dpt5fmN2XHOxGC1WWE47hJZcGx69mrCkjQIGSQGxoJ1wXQjKiWq zw7sr5SS7cLQITieF9uBlt92uCVh0tlWN+AiCW9hSbdu9Fwbafc5QECw6zdjIMir A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b96am96g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:18 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50ON3eWg036495; Fri, 24 Jan 2025 23:55:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4a7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:17 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPo018051; Fri, 24 Jan 2025 23:55:16 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-5; Fri, 24 Jan 2025 23:55:16 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 04/20] mm/mshare: allocate an mm_struct for msharefs files Date: Fri, 24 Jan 2025 15:54:38 -0800 Message-ID: <20250124235454.84587-5-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=829 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: Zg9k0kA44bw59zVgGS2FFhExNRlmmq9n X-Proofpoint-ORIG-GUID: Zg9k0kA44bw59zVgGS2FFhExNRlmmq9n X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 97A0C1C000B X-Stat-Signature: n8nprycn3ek1qupsf9645m9tfnci6xeu X-Rspam-User: X-HE-Tag: 1737762933-674495 X-HE-Meta: U2FsdGVkX1/lP491xjcjG7gGspN0HpNb4AKZwfo1UdvUF1+GgqWMwJOmGsInsYQKzk3E2JPxRaAURyoLZXMW1L/0oxoB4TAC/rlsJha/b4/PpwgZjKg58qKpWazlhR9fjk0gqq8WlU6DDGA78AIWTXUzQZmi14Uet6ju3WNiv0hCnRKWeSkIERX+oBOFkmVqRzTp4cXSho86TB4miEmPmmWZeVgxNayrkX8b/jweoqzQj5s8EQ1SNpNb/6jG4SKmRIRUETtzEdwtPahdZESqzD7o4sDH9N8pshAUZWqBazWDAo/84DEUTuf7eJzXss1KZZtXHesgeHhaXWf14dPDQEnOOl2teIV9t2UbInJCTGMhm+ahUAoa4KQgqaqRHIc74CFkBHfJ+wRdzlj3R1c3VH1PyeqKvlsSYR0AE8maC7sLwP8mfNxlSyEWfyHidFQ5k4FyogLq/v4tAO4eL8Iopi1PjZCcDH11x099214Cu2LNXDx2PRR9PLy7demRtazYy2jS1BBCqsCvPhXDyPdavVp6v6qVDHLiHzPd/tj2UiJ0u8eCTa6lmUDsGcFVYLc+0eIoqHKBMcvkE8Q1GdXNzVBd1MkgHJVlWSfra64mirpkEPk1Rgpq/xByTbWnQeylyeS0jlC7dyR/+4mPLqM91NE830LVLiOTJtdvu8gkDSBkNubN/Ko3XUpUN7wMU6RTHEvuStlWcuKajS9pBNuDyDDPBxDvka4J4KRy8Uw5bUwNSYveimjeOsmMnkyULPaEvf2JIIgatr/4C3CMTqjOXYMz9oXDk0OnBrSFDxzpueudw68pfTJKbsu+qAONRDD3pFeKmMhjBy7lgNMwn05tdObVVILHCxgOlmsJzj6S2UOMYCXYf/TKJClZZlA7yAHKJVZGZYCwJVGZPYuxZrwqxoiByHBCFHvwSoi45SrHHL1TXZCTG2p22LAdwcHFj78QAhhVsXIQMLKPKJsC0B3 2/2iaGBr 4aqvJJeRBh6a8SrgXQA+hDTeHZiXLKfQXztM3W+3H5cG4r3Vzz3S9mDIoBVWw4DnHprTguAo9bUy87bQCQEE6zJOjqmUCkxPk2VSmi3q3sfWT3pDB0WbZc8QNCV+PO9GLUPqn6IzAVxoluRgEpipxAwVrv76bpPm0ceCVWQdaxIJxejFGH59AwMvL327q9qwSMRhRIIPDL+B4E4nzP02rR9cpQZvVJh+jGBTF7xxD9hZNJAZJNq7y4vTRZHi70bbBsAwjIlBph+XySZV3onSQN39rXsIJVvMMj/WHQUORwysvR3Zik44N40y7rQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When a new file is created under msharefs, allocate a new mm_struct to be associated with it for the lifetime of the file. The mm_struct will hold the VMAs and pagetables for the mshare region the file represents. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index b755346da827..060292fb6a00 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -19,6 +19,10 @@ const unsigned long mshare_align = P4D_SIZE; +struct mshare_data { + struct mm_struct *mm; +}; + static const struct inode_operations msharefs_dir_inode_ops; static const struct inode_operations msharefs_file_inode_ops; @@ -26,11 +30,51 @@ static const struct file_operations msharefs_file_operations = { .open = simple_open, }; +static int +msharefs_fill_mm(struct inode *inode) +{ + struct mm_struct *mm; + struct mshare_data *m_data = NULL; + int ret = 0; + + mm = mm_alloc(); + if (!mm) { + ret = -ENOMEM; + goto err_free; + } + + mm->mmap_base = mm->task_size = 0; + + m_data = kzalloc(sizeof(*m_data), GFP_KERNEL); + if (!m_data) { + ret = -ENOMEM; + goto err_free; + } + m_data->mm = mm; + inode->i_private = m_data; + + return 0; + +err_free: + if (mm) + mmput(mm); + kfree(m_data); + return ret; +} + +static void +msharefs_delmm(struct mshare_data *m_data) +{ + mmput(m_data->mm); + kfree(m_data); +} + static struct inode *msharefs_get_inode(struct mnt_idmap *idmap, struct super_block *sb, const struct inode *dir, umode_t mode) { struct inode *inode = new_inode(sb); + int ret; if (!inode) return ERR_PTR(-ENOMEM); @@ -43,6 +87,11 @@ static struct inode case S_IFREG: inode->i_op = &msharefs_file_inode_ops; inode->i_fop = &msharefs_file_operations; + ret = msharefs_fill_mm(inode); + if (ret) { + discard_new_inode(inode); + inode = ERR_PTR(ret); + } break; case S_IFDIR: inode->i_op = &msharefs_dir_inode_ops; @@ -142,6 +191,16 @@ static const struct inode_operations msharefs_dir_inode_ops = { .rename = msharefs_rename, }; +static void +mshare_evict_inode(struct inode *inode) +{ + struct mshare_data *m_data = inode->i_private; + + if (m_data) + msharefs_delmm(m_data); + clear_inode(inode); +} + static ssize_t mshare_info_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) @@ -159,6 +218,7 @@ static const struct file_operations mshare_info_ops = { static const struct super_operations mshare_s_ops = { .statfs = simple_statfs, + .evict_inode = mshare_evict_inode, }; static int From patchwork Fri Jan 24 23:54:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950027 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 1638DC02181 for ; Fri, 24 Jan 2025 23:55:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51D0A2800B3; Fri, 24 Jan 2025 18:55:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42DCD2800B0; Fri, 24 Jan 2025 18:55:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F7272800B3; Fri, 24 Jan 2025 18:55:42 -0500 (EST) 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 1059C2800B0 for ; Fri, 24 Jan 2025 18:55:42 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 84342161884 for ; Fri, 24 Jan 2025 23:55:41 +0000 (UTC) X-FDA: 83044005282.07.B18588D Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 9263140002 for ; Fri, 24 Jan 2025 23:55:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=U17qv4kg; spf=pass (imf27.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=1737762939; 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=YR94nq9P1Qyhdr85jFXsDeNLWyF6Jz4qdsVA+7ycWG8=; b=d5CgpXD/nX+oHZ0V38zgVx2OMuCEyOeZMzhTpWVHMiOFFlTFdibZ34cNJ3YoiLYT+1wSY9 P3F+xE/nvTCD3eq8PrNgBx9z16osTiXqQmbBIs5EaXwHl5BrZ/Yle+hxI1MDeEu2WuSL4H szb48l/5m9vZbIcly94a2HDTOYmr4Y8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=U17qv4kg; spf=pass (imf27.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=1737762939; a=rsa-sha256; cv=none; b=faB2CgAfCDVrzvC/lM79KHR1WsZJvNk+ARz1nj3eTUt4N7iaAoya3K1XPRYix2JbhfewsQ ezB+BpWDzFSB6brAY1xMH+fwoPWsRWFkzWt1g6lCeSoUTI+DEGNUOPsBbAzX/PTe7tvBl9 r31iMzFSRQ1nCJW7/hWjOvXMpiQUheQ= 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 50OINfWM031123; Fri, 24 Jan 2025 23:55:22 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=YR94n q9P1Qyhdr85jFXsDeNLWyF6Jz4qdsVA+7ycWG8=; b=U17qv4kgLrflB4RHAeog7 4wlpmeoJpaSoQ3N6swcZcCacC+QK6zUVbGVxCJmnF7CR/w80FJ7sR+odgKJ3UuIi OtXw3u5uE7nk55riixTIRmxB1uecSItgWbCILUpnr38OgT7yMveyfZgnrtM3Mwc5 R4hrlqSpm3uGwIGQujCqMhibGcC6BLSM7MvvyvSMWBxnn4qJF4zPCQNI5ZbLscNt +fjr0vMc5f5X+fkUYSZjrH2NoU3EDMtHPKSjXjV4COMwxKAV42siTVIk3coAlQZM 9Cr4ZMVkNtfJ+Z0mriz976U2A8GWiJ/ceDvqqwJGKc2kAhsj0MAfAxxUNcjwFLZZ g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4485nsmvmr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:22 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMmRjc036584; Fri, 24 Jan 2025 23:55:21 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4a92-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:21 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPq018051; Fri, 24 Jan 2025 23:55:20 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-6; Fri, 24 Jan 2025 23:55:19 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 05/20] mm/mshare: Add ioctl support Date: Fri, 24 Jan 2025 15:54:39 -0800 Message-ID: <20250124235454.84587-6-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: Z20-vg57O9zfZiKygPd_gm_amo1x_1Ej X-Proofpoint-ORIG-GUID: Z20-vg57O9zfZiKygPd_gm_amo1x_1Ej X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9263140002 X-Stat-Signature: ao4t3ad3idgtk9qep7dxehd4ypb6f78m X-Rspam-User: X-HE-Tag: 1737762939-522018 X-HE-Meta: U2FsdGVkX1+//Js7YYfcRl3vBs2RglFw6ZWp7DAXbYzJC8QzCF3QL/fcw//4RyqYg7khXFHCnDwkowLEvlxWKT0fQ7Xon3F/9srOJwbFY0VKloq07Feq7A9zRc3xPhE3ulJCrI7S9lu3Qmuvfvhvu38hkxRH+luhj4Erxk9u7RwEYhQ2GuyxlPd0iLXVv/KIHLZ64xT0js5dqy7f7hQ/ZtFADPXfDUoPzRz7DldrG3v9kOEp3kDymio17lA3QA+5YUbp191rbsCVoina2vsGOq1DQ7n8jBmjrr5z1DUelwxY6XbrUSapISl+9zSRfXdpX5pPNobs7Dz9g/VB2GGhu9N9zQ6Zw3a6NikCWaPoklatgGgA5Nr9Rhwrr1qh8PrhU8KNPz30R9cpwCL3gyST5QXDpI6bC+O43PMZRhSVMlyDMFjEgHtZhUIFaoeduuTRXwYjfUbrxloyV3ka6/5oHsSgxMgxurpCd4c5EHh5JvkFSCUY2NJDjVNWvDPvBJJTSHrEvOyKE+tsdEGBSMYB0R5xGnlMYK+nbC2xbvJaxKn7BojeMYCbOBd3VSTrqhgqo4YRYE6U/SJEFW6evGOFB9UW6hTkx81md+IH06yxDP0T6mljJHKW2mHjKO81h3OHO9Dmm7u6SNLLvTcsMhVfb500T93Gtq5wYM3QIIFcUJ9XUXAblTsKZYjAwxb6ImS0yLkpsm+XvEH2RKhiwJxy58daW7RJKgFy8MW3Av1aRKY52Gjf1lW6V8e4VhcG8N4VCHYm+Qom3jv+RzTaedH3aizRMAcsskBikRkYPOsU4K6yYtRiuKYVi5+8EwJ28Mmab+lcSndL+J2Y7O5a0/tIpz2NGo4ReBMEAsRfQgNd95sNO8Il4xTLT2x2jx0bUKrqs9dPRTzZe9YtWITaAl2PWK7GBvsVQMUUHgFYF02VtipwDsYxoyGLPzI2n6Phge2h3xPDscYfvorAd0sqfO9 eATP0vKa gRrkVahKmBrY83JLv3rcgkyWybThaKyP7AVoma88Zx70jm1GOUuyutgeNKfbzCBKXJIYBLyZ7jT1JqBUltyDwLNcBttpZdDolYUt/dvtOhFCkevjrafY5292pG8YMepR7niByG5xY6RChHQ5fKTzdT5WEesxw/oGHjhrn6t2Q40ravx+hZXAzdxrD7bLyRqGRF7EzxhHyP8uwo0Z3lNi7r0DV5/g7VPCpPXe98aQXfTfCpWb8jKRnYkaTbVcJMZUtkyuxewVoWNeA8LBw89YF47GPyPNol7wIJo8UyMOooSsYLgAkAHkoEcsOJSgSq11/0wU7YYj03SfRjMYSrGV/p+NLojWJSKajh+w5B3CMzYtC01k3GhyfD5PzqNwcC7mDIw+stz0/Pz0sSmhImZAMl1fS4g== 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 the first two ioctls to get and set the start address and size of an mshare region. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- .../userspace-api/ioctl/ioctl-number.rst | 1 + include/uapi/linux/msharefs.h | 29 ++++++++ mm/mshare.c | 68 +++++++++++++++++++ 3 files changed, 98 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 243f1f1b554a..aa22b5412e4d 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -303,6 +303,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..c7b509c7e093 --- /dev/null +++ b/include/uapi/linux/msharefs.h @@ -0,0 +1,29 @@ +/* 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_GET_SIZE _IOR('x', 0, struct mshare_info) +#define MSHAREFS_SET_SIZE _IOW('x', 1, struct mshare_info) + +struct mshare_info { + __u64 start; + __u64 size; +}; + +#endif diff --git a/mm/mshare.c b/mm/mshare.c index 060292fb6a00..056cb5a82547 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -10,24 +10,91 @@ * * Copyright (C) 2024 Oracle Corp. All rights reserved. * Author: Khalid Aziz + * Author: Matthew Wilcox * */ #include #include +#include #include +#include const unsigned long mshare_align = P4D_SIZE; struct mshare_data { struct mm_struct *mm; + spinlock_t m_lock; + struct mshare_info minfo; }; +static long +msharefs_set_size(struct mm_struct *host_mm, struct mshare_data *m_data, + struct mshare_info *minfo) +{ + /* + * Validate alignment for start address and size + */ + if (!minfo->size || ((minfo->start | minfo->size) & (mshare_align - 1))) { + spin_unlock(&m_data->m_lock); + return -EINVAL; + } + + host_mm->mmap_base = minfo->start; + host_mm->task_size = minfo->size; + + m_data->minfo.start = host_mm->mmap_base; + m_data->minfo.size = host_mm->task_size; + spin_unlock(&m_data->m_lock); + + return 0; +} + +static long +msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct mshare_data *m_data = filp->private_data; + struct mm_struct *host_mm = m_data->mm; + struct mshare_info minfo; + + switch (cmd) { + case MSHAREFS_GET_SIZE: + spin_lock(&m_data->m_lock); + minfo = m_data->minfo; + spin_unlock(&m_data->m_lock); + + if (copy_to_user((void __user *)arg, &minfo, sizeof(minfo))) + return -EFAULT; + + return 0; + + case MSHAREFS_SET_SIZE: + if (copy_from_user(&minfo, (struct mshare_info __user *)arg, + sizeof(minfo))) + return -EFAULT; + + /* + * If this mshare region has been set up once already, bail out + */ + spin_lock(&m_data->m_lock); + if (m_data->minfo.size != 0) { + spin_unlock(&m_data->m_lock); + return -EINVAL; + } + + return msharefs_set_size(host_mm, m_data, &minfo); + + default: + return -ENOTTY; + } +} + 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, + .unlocked_ioctl = msharefs_ioctl, }; static int @@ -51,6 +118,7 @@ msharefs_fill_mm(struct inode *inode) goto err_free; } m_data->mm = mm; + spin_lock_init(&m_data->m_lock); inode->i_private = m_data; return 0; From patchwork Fri Jan 24 23:54:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950026 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 7869AC02181 for ; Fri, 24 Jan 2025 23:55:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0AFF2800B2; Fri, 24 Jan 2025 18:55:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB90A2800B0; Fri, 24 Jan 2025 18:55:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B36572800B2; Fri, 24 Jan 2025 18:55:41 -0500 (EST) 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 85F2C2800B0 for ; Fri, 24 Jan 2025 18:55:41 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3E3D0B22B1 for ; Fri, 24 Jan 2025 23:55:41 +0000 (UTC) X-FDA: 83044005282.29.1E4615F Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf04.hostedemail.com (Postfix) with ESMTP id 435FA4000B for ; Fri, 24 Jan 2025 23:55:39 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=XLe18pnp; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf04.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=1737762939; a=rsa-sha256; cv=none; b=mJeUVIojo1frk8G3gi2yk2VWDad2gZauEGhzOqRFZ3vUiWdAgGGVT8dftXZGzhIxJcveVZ c3/9TYl31bnYnmCpUvyjBnb2akjCsuI4hnulqgJTZU7Xjq1j1pdDKVnchlir4bz1NavtMq v6pBecUmf+06Cu6BPb8Y3aZinjVkTQE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=XLe18pnp; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf04.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=1737762939; 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=Gmt7QB3NcOmNhQjBszQbUI804S0rjvRagMuhEI7yvaU=; b=uHY0dlAgpHI5z3Mf9QHtpriZpaKQ0ZfkPNANVGai+cemtgHHbrWJcuQbd42afnY/OS0v2O e7raY6C5tctNUuVPzMmzW9SLiUYd+PyftjpxuL369k0aXU85jhK2D2egagRAj+4W7Qyq40 UdexN8Tw8Xy6qZAm9FnTDzH1+p5qQNg= 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 50OIeKEZ031124; Fri, 24 Jan 2025 23:55:27 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=Gmt7Q B3NcOmNhQjBszQbUI804S0rjvRagMuhEI7yvaU=; b=XLe18pnpG/WvE0w7WwOXY y5bIblHn+FdWnW185Ykktr4sL6Xalmuzdvdq/qHYMpRSdi04j7yf3G2gLCAOwqeB fG2s3UJ9KB1t74mh62AMLQTe2v8989/wdSHUdojO0jsNTy50uFy027OHPa8QotEv R6Ri1dWaU2E006hYgPKoVSgJf67h/+Jhr1rH5KxT103ZQfoSo0rl3bJ/zsRQI4vh atf7VHTBh+aTE1GNhGUW3jDHJC2/4vgvLBi6Yp3S5ZgtPNJowCSCOF/ZfQknDTFq jC414yxxNtO9fER2M5ALcVKQZveFIoMWPpoENC9GIW3eYktUka4GcR5EX0S0/qs2 Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4485nsmvms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:26 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMEpto036739; Fri, 24 Jan 2025 23:55:25 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4aav-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:25 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPs018051; Fri, 24 Jan 2025 23:55:24 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-7; Fri, 24 Jan 2025 23:55:24 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 06/20] mm/mshare: Add a vma flag to indicate an mshare region Date: Fri, 24 Jan 2025 15:54:40 -0800 Message-ID: <20250124235454.84587-7-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=724 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: fAnTHbbqevGjh-8GbPtHZ8_gFx9Uqmua X-Proofpoint-ORIG-GUID: fAnTHbbqevGjh-8GbPtHZ8_gFx9Uqmua X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 435FA4000B X-Stat-Signature: ipsdh6p5at35h6jejyz75kr3886ombo9 X-Rspam-User: X-HE-Tag: 1737762939-913270 X-HE-Meta: U2FsdGVkX199N4zsATf/vy+o84Vk6/vb4tKFPh9Q6VG60Is3rRbBmewoFkAqo41pMEjeZpFLU+ciS12RzdLfy13zKS10KTXPEWjRMLmDIIMmTtqEveIEfCGrbUpTW4sKTZzxX4gT0D8szJBZvMW4rMdyJhVmlhJUYMqxpSJdmZsvPGiXdf/pPg/adaZUTxWCSfYgILFwnghq7idsX7Yc66/fhxPjkP+a+mPllOlAfEQ2ZNyhsSknkhBU2y9Gy9fjTKep3lJE60qM7Snoujkj24gwlX9mvgLleWW8PEkkGDLGHn4pilOat3MCRNrC9oWwV9lyvNFvmxGnZHiysSpIBzEBq45uCYeL4w4CqL47WztbzPwp8Nova14lB8opt2jZ2mAq+6q2TqMLXwK1M7Iz6oeAx/u8YOrQmjPeOD4Yd32tWn7Q+yg4n5QYbl+yRSiROMXg4EDIGsLjT1KGE7KGNdu7aleTVxuq5qY4aJIWBrwUnGLDkW0swv9taReizzNUJFoSH45X9ozXfW8Wu4HnMm9i4URMywb6snsJD3vQA5iKv3XbDAvsjg+VAx6QFaGmIlmv/8OAXsXILfXBmRjyHqmBA/N3n4+qPUo5TL/kBg+dYjBU3ylf7hX1iItCe3QaGlXBEdwPR2IkZgfInZOYyB8+TUqWGa7bed3uo77mPT85J3+/AVEtL2q0FfIXus8TtcwvIgaMydE5CPEEH42h+b1SQD9MgizTUpoh6QfMvBr8rXGsQBY3SdNvT+BC9vrUAvju2wI7P/+Kmvw8vBKiSMpde/IiGf9TWrV0h5yDuviq4gVnkhArywMNK4P6CofBoX/g+/sBgoonDsSKJJRdQlywfOeRmlUzGXeXS4Cqq9YYKtTmo35TQWPWx3pv3WbVPvydvUrCUSzSwo04frFMCRm0AvQSTBE4kQusPn4r7qJ33nvOglKAs9fRzKQQ6xrnq9JV9NQcsJrs8AOfiLv H/9A/mkV CnDx1YMlkeJUe5bhzG0He4UMEScnwjqrTIqsSxE/o/lshbXFvjStJtgzws3aNkFmxa2AdJjGG0by1xAjBH18tx0wa+l6suOEN0oPzdoMkNgbrR0JvlXE1/08sffppGRcSq2n/avOoGhQFxd7YcDcIPekZRUlx7guy83hcMFBhTGcs8psy0VN+nqdZgxG4VABUTAOT7H748Ogm1/gWYyyQaFJH28TDBTzAKzSyO3Y5mQt1T6F1UjLlYQ5nuczTLNIHGSt3dhtl4I3h74zkclk+vP/p1MSVGH86pN9n3rQh8JFq4RHw1YMonG2AGxo39wRbRQSO 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 8483e09aeb2c..bca7aee40f4d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -440,6 +440,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) @@ -1092,6 +1099,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 3bc8656c8359..0c7d50ab56cd 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -160,6 +160,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" }, \ @@ -193,6 +199,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 Jan 24 23:54:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8097C02181 for ; Fri, 24 Jan 2025 23:55:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBABB2800B4; Fri, 24 Jan 2025 18:55:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E67B52800B0; Fri, 24 Jan 2025 18:55:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C29D22800B4; Fri, 24 Jan 2025 18:55:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9C0012800B0 for ; Fri, 24 Jan 2025 18:55:45 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4FB40C19FC for ; Fri, 24 Jan 2025 23:55:45 +0000 (UTC) X-FDA: 83044005450.09.8D3CB99 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf16.hostedemail.com (Postfix) with ESMTP id 5170C18000E for ; Fri, 24 Jan 2025 23:55:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=nbz8o9rG; spf=pass (imf16.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737762943; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WMU6LWuuz0sPUG0ZZmDbq73rQ3vuBHP+1rFTOp/x2RM=; b=dDSTj3ixLhSoRtFfWEj3xikvntN5zKsqP44RhsP4B/2nvSEiU/x1aif1IBeWzYg8uefE4c Jayi0vqzgMS/7C2jUEkBo12tKx1dey5kVJf6wSEWL1bqY/vkPkySNsM4+RLGeXSxcGPoNZ zzfZ24KonvMcGQ2QLhtRrbj9tln5ecE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=nbz8o9rG; spf=pass (imf16.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762943; a=rsa-sha256; cv=none; b=lh8W4DAEV5nJRHWvcN+QnkPWXGPt5GP/844ZmEXLm1Ad5qbhUnHwYiORjqni0kmZ7jp8qv hVRdE1Gh61hN+4RdPvR4PZPgV2NjbawIKkWsOavyG76EgHbvn2bYaNtgmge+xB/aTHJ8HW bB02RiJK2Li38p9twT2lBjcyEWHLGoQ= Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50OIEkFN002187; Fri, 24 Jan 2025 23:55:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=WMU6L Wuuz0sPUG0ZZmDbq73rQ3vuBHP+1rFTOp/x2RM=; b=nbz8o9rGukImzGsDob9en 39eAIUc2+JsNnnyy1oLFl6BBl0xeOR1PcFdBkSlAA4rzc0+GhaIcJPfVnGLg/+JN Wfmcvc0WXR2fVzZRDhwPHkpPwWKxXt3mhdvCMlfd7qSDhFqmAd5qfiBojuf9+t2/ DnaUiWy3tMqp6/snf+Ooy2j3r6VSq8PQXW3LSAW9zYbTyxssN8BYDgy/WOBkWkeP Ys9AtYq4Nt3ZvDSXjD3H9k72fimLgFlPwjb5zTCe+C7nENNJvedZOE8MQ3qtKRwJ jaZdedCDLHtrPy3KxnVgcpiJ24btlclTgnD1e5hJxh1R4eHwhj+7FCVDEbEnwsn3 Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awufwwhg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:30 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMPchG036590; Fri, 24 Jan 2025 23:55:29 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4ac7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:29 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPu018051; Fri, 24 Jan 2025 23:55:28 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-8; Fri, 24 Jan 2025 23:55:27 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 07/20] mm/mshare: Add mmap support Date: Fri, 24 Jan 2025 15:54:41 -0800 Message-ID: <20250124235454.84587-8-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=765 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: kbiUWFzTnM-XfItFGqup7QCxCSWShv0i X-Proofpoint-GUID: kbiUWFzTnM-XfItFGqup7QCxCSWShv0i X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 5170C18000E X-Stat-Signature: 49xhn6uaqn5pk6ndin54wx533hcop8o7 X-Rspam-User: X-HE-Tag: 1737762943-571129 X-HE-Meta: U2FsdGVkX1/tRpQQL/k7EDydoU/fwMDpcEQ4UDjnOwX9f8Dm2dGVlxgEIL54eD+pYoqblr+5afTHMtPT8sDQdVjyESy8H+EYuh2gjCspGergVbqJoWYBuJQJznsdBt5ZZyo+rmoNdZZ1gjxrX76UhxY3cpjQK7XrIyuSp4mUKsl4U48t+m4QKlW+OLAAmOFYCLwcGGQi7Qzn7E7u+f5ozIbg9U9cZIROYZ4/7G668h/p1JT7lxIzLhTFTqwUR4o59qIlQl77QS0ndQBUWfFOMEBoZ0OzTf9oW4VE7UFGn83nwsoGHBhNLyFUk62PlVdlfKNkz83nwMQzhVh7jdMTpDNCT2uyFcN0Vr4MrKrD4TIJZEY84/+nG/Qlz3FixCGiI6R7nUkb1TMlySaO3Twa6TP0VsyNenuKJr/ojW929x9CmoUQ/wvVi4a99ONrE1p5QYNMUByliRGHxSehHDY+kAbmR9SXlZtq93BwA7mmJmoFzfptGU9XcXmeJPw/BaTjCmpu1yhQTIh85kLnITn3O2rZNLR+8nfd85Pf7p7pDVG8THeH0QUf4Vc+3cg/zO3dhP/QuXklj4IesHMHU9p8YXRoNHEzMynF0mwDg9RaQuDUMunwZy5uXH65wvZPo5wqU6ukwN6E+lFi+WCD/m4/NAQ6WywqGE6AGJfAYLmU8mUhpxoOiDz4yOC4O/uQ8POi6wgmLYmH1H/a8QPjpOSJSG2KrreEuUA9doq8JnPYXwU/WiwTRnTazwCql0z4aJ9pRitA94JUxTXdyVHQhC/Xw2dnIof2tw8zwUosDPqks9ma+y8zS1Uvr1Zpzfdcg71XkSH8LQCqNdjGlPddcbfliqkoA142V8TIbalRS/zcbBNIxPPIJklYGOK4fHd+2jFrc3Mr1p/VuwOop/9M9PHtK5WUI4ahQx+KkdJNKESDPCaY56GPe364PzjSGdmdXW0+GNztSLDLozNLV9NK0P5 NRG2ivSY 4HbiOIDrKEDgX5Lan9Aee041yvedfY9BTdj9C6Kz9vfVwkLnZB3K14MShaw59TMqZnZIRyCaWVgpS6vn1u2CLJ8gvVCs/fAKBlF5hqNx87ca1WkTN0XllWdzWs0+2jROPBQF80e7rkehIOQecST14ZE/YXp+DFMfkvR6MFXY3d37BmJPtuelWtPNzQZEKPsh7kD9hDf46rQSTVMZdIkj3o/+V8NPG6Q4RgOXFF7FHRIhyZqPE9j012GFKiKTQGAo8PQv6 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Khalid Aziz Add support for mapping an mshare region into a process after the region has been established in msharefs. Disallow operations that could split the resulting msharefs vma such as partial unmaps and protection changes. Fault handling, mapping, unmapping, and protection changes for objects mapped into an mshare region will be done using the shared vmas created for them in the host mm. This functionality will be added in later patches. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index 056cb5a82547..529a90fe1602 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,74 @@ struct mshare_data { struct mshare_info minfo; }; +static int mshare_vm_op_split(struct vm_area_struct *vma, unsigned long addr) +{ + return -EINVAL; +} + +static int mshare_vm_op_mprotect(struct vm_area_struct *vma, unsigned long start, + unsigned long end, unsigned long newflags) +{ + return -EINVAL; +} + +static const struct vm_operations_struct msharefs_vm_ops = { + .may_split = mshare_vm_op_split, + .mprotect = mshare_vm_op_mprotect, +}; + +/* + * msharefs_mmap() - mmap an mshare region + */ +static int +msharefs_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct mshare_data *m_data = file->private_data; + + vma->vm_private_data = m_data; + vm_flags_set(vma, VM_MSHARE | VM_DONTEXPAND); + vma->vm_ops = &msharefs_vm_ops; + + return 0; +} + +static unsigned long +msharefs_get_unmapped_area(struct file *file, unsigned long addr, + unsigned long len, unsigned long pgoff, unsigned long flags) +{ + struct mshare_data *m_data = file->private_data; + struct mm_struct *mm = current->mm; + unsigned long mshare_start, mshare_size; + const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); + + mmap_assert_write_locked(mm); + + if ((flags & MAP_TYPE) == MAP_PRIVATE) + return -EINVAL; + + spin_lock(&m_data->m_lock); + mshare_start = m_data->minfo.start; + mshare_size = m_data->minfo.size; + spin_unlock(&m_data->m_lock); + + if ((mshare_size == 0) || (len != mshare_size)) + return -EINVAL; + + if (len > mmap_end - mmap_min_addr) + return -ENOMEM; + + if (addr && (addr != mshare_start)) + return -EINVAL; + + if (flags & MAP_FIXED) + return addr; + + if (find_vma_intersection(mm, mshare_start, mshare_start + mshare_size)) + return -EEXIST; + + return mshare_start; +} + static long msharefs_set_size(struct mm_struct *host_mm, struct mshare_data *m_data, struct mshare_info *minfo) @@ -94,6 +163,8 @@ static const struct inode_operations msharefs_file_inode_ops; static const struct file_operations msharefs_file_operations = { .open = simple_open, + .mmap = msharefs_mmap, + .get_unmapped_area = msharefs_get_unmapped_area, .unlocked_ioctl = msharefs_ioctl, }; From patchwork Fri Jan 24 23:54:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950029 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 9D28FC0218B for ; Fri, 24 Jan 2025 23:55:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73D102800B5; Fri, 24 Jan 2025 18:55:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EF362800B0; Fri, 24 Jan 2025 18:55:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F3E52800B5; Fri, 24 Jan 2025 18:55:47 -0500 (EST) 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 3076A2800B0 for ; Fri, 24 Jan 2025 18:55:47 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E7E44C19F5 for ; Fri, 24 Jan 2025 23:55:46 +0000 (UTC) X-FDA: 83044005492.07.872F3B7 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf22.hostedemail.com (Postfix) with ESMTP id F1C7AC0006 for ; Fri, 24 Jan 2025 23:55:44 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=dkhH1ABN; 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; 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=1737762945; 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=rU9rPudGLwBZN+ul8ATDIQZHL+5JLK1AK68Xl6t+yJk=; b=STSQR1WQd2L8J596Np0UDVqCo0CYczl0XLQFTfeLxQ5mRsFVFXCmwl9vPC2ifQNnnReCzV a+IkDZ3wcgDiRU4sMlhxTD22GZGyfs7z9oCVeU2mo6qoeSIPGRjEzTUPspTXD2O+LUx/5Q d7nBvtT4S03Gz+1asOIbHcaAfEUsQl4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=dkhH1ABN; 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; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762945; a=rsa-sha256; cv=none; b=W5grUOxVDNU8Eo0Rk6+UWHVcDNQZupJU1tfUYPWjq/Wuug2dgLAF7YhGTplBILPMjdTaPY KTsJ3lxiJ4YR2NHq4UigktLW7mztGx6yA7kbNGdzLW3cz80UhUesyaCiUsT0YuqgnVJRYm +azq9qZkQJMvEzUEWxqEqWFymN66eok= 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 50OIHwxb022439; Fri, 24 Jan 2025 23:55:33 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=rU9rP udGLwBZN+ul8ATDIQZHL+5JLK1AK68Xl6t+yJk=; b=dkhH1ABNUHDgkMbcNjOVe HLOlO3zpfZ6/zcXgH1MWSMApJp53Zwemc5AMBv8VgZ8H72pMejt0H3iho7yOmvzF H9xMiQUdAlws7OQLQt3lEzupvIdFAz9lcZVHNY52vnuTO1jN4+4NOIRkaG0aXtrA L01uc+qtH7o9rswF60olv2Vbr/OTaxT5KAyuoPLHYUCrd1ijEpIlZlcF0e0FXYcT iEBP96177UVbNmeouIy0f2vKY7Z3tP7ni1ruGvCXQ6tLrF4NkSSbvbYlOZXQNQuo FddCVtbP+byHiQ2Hg2u0Y9K411peP9nCUuiZ90jxeGRg+PLZXMcNjZr1ChereVuS g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4485qm4y4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:33 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMEElh036463; Fri, 24 Jan 2025 23:55:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4acw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:32 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxPw018051; Fri, 24 Jan 2025 23:55:31 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-9; Fri, 24 Jan 2025 23:55:31 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 08/20] mm/mshare: flush all TLBs when updating PTEs in an mshare range Date: Fri, 24 Jan 2025 15:54:42 -0800 Message-ID: <20250124235454.84587-9-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: G0_gkNzHGYYH-z86dDhJuuCCuwBORxu- X-Proofpoint-ORIG-GUID: G0_gkNzHGYYH-z86dDhJuuCCuwBORxu- X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: F1C7AC0006 X-Stat-Signature: 5donmjkehiyiicpyajz37nj4u6qpxwqa X-HE-Tag: 1737762944-7108 X-HE-Meta: U2FsdGVkX1/+CZ+JTpvWAw8Car+89tD6FNyAzscEZmIMb8O58IXtjZojPZLQKQgCuaQHe1PsNnGDXK1XiuLu2tP9BVe9t4qMT+WXwmmf6eBIU9hLJluSIL1wyH12s3AP5h84yHW5Hy95Req92vlg8V383LAI5mSbFx/tJosxUCPJ6UODDoDAlD7s/gtu9vb4225boAS7B4/n3MfpMOPy/WrNgdSvOBD93iF4lGcJsPExgwUGN6dlc3fxeGBbrul163czZfOyrWZ9rt0iCLZwPbjHLyx0g40s1eJsLC5+r1q0io6lCO7mo+wyQu9xNWJssNry3/CWUfYzrE7vxv0zna4jVoHe9WUK34EybkLlanqDHk1YcPRflmRNDdTTgfNvr3v3Riy9HDTPdtahiIMuroervNeTTzTtN4+h6W2RO5QVgtVVln3Gmwp0ctNVCVcIB4Vd3wb70gd1ZXOkpSZwxSFQqvUiNRENwtTkEugfJTyNrlbcSRLnYqhWmHxqU0/qDI6snoaCynA/djsxF7vuvu4cZKuRuNzB5N6p9TLNkMgY7jtKPtaTjgAiRRkZ3A3neW+eeoY8YBqDnGQFMZB0EG4/FSGtp8oaDTp0KxeCviXTUoDIGcGiU/PLuw5o6xby1r65qPuIAbaKe9EcqiewDifZIZGBJeBt+m4bCOFgcUIhYmctDk0j/+4j6dz0EC26Q0K1gZYFhSPYbBqHqck8EbfxUtmU9KosKKpB/EhhlVmBPSNnqGmRwAlE6xkhreopWai6zDpjQPvN1AxkqwRFygrNUtfirp8Ypcv/MSdJbIsOheXvKnle3bwp480gxNCrKVFt6ZuULykHe2+g6uCtPePvqj6wQSduqKQ1r+vgU7O/vzifzhcYW+DuBoiagjCEcU7NsWsREhrM4TbW9XfyUfRcTGPLfL4StsJR8X+r3oEkZawN1Y8ehSWv8KrNontWAmJElOl9SqGGf3XfvJc YFval9tT 9/TouoNY3m5+AKymJ2rAKaQz8T4vrr3gVe39x1I5bzGMTDlDzdIsGoy3O7Ctu3PaFt3UnA1x+xvrr4Ckt/u1ZYJcmSrVXEl93hZldCkPtLdWW4Eho0QiSfxYunBMPGH7FYpk+emZ4zFwTkyGKx51qtUueGFiAUUenimDAG98DcO+Wq+S/edINjk2uvabYwiVZkBMSFDCmBanDl8m7zW0iO/MWvGnN56+XV4P8TESfGMGT+gKhEEtu8AuYdLzuaV9iM7LjGRvpKXVx+Ho= 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 529a90fe1602..8dca4199dd01 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -17,9 +17,11 @@ #include #include #include +#include #include #include #include +#include const unsigned long mshare_align = P4D_SIZE; @@ -27,6 +29,17 @@ struct mshare_data { struct mm_struct *mm; spinlock_t m_lock; struct mshare_info minfo; + 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) @@ -191,6 +204,10 @@ msharefs_fill_mm(struct inode *inode) m_data->mm = mm; spin_lock_init(&m_data->m_lock); 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 Jan 24 23:54: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: 13950030 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 61AD1C02181 for ; Fri, 24 Jan 2025 23:55:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBC222800B6; Fri, 24 Jan 2025 18:55:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6D492800B0; Fri, 24 Jan 2025 18:55:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABFFE2800B6; Fri, 24 Jan 2025 18:55:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8877A2800B0 for ; Fri, 24 Jan 2025 18:55:50 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 38D6A141692 for ; Fri, 24 Jan 2025 23:55:50 +0000 (UTC) X-FDA: 83044005660.18.C746E1F Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf20.hostedemail.com (Postfix) with ESMTP id 143E01C0016 for ; Fri, 24 Jan 2025 23:55:47 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ein04UV3; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf20.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=1737762948; a=rsa-sha256; cv=none; b=aW+pJuD2DfMNge8Si37iuq0BPTWMb2d4lPVm76VK8pzQQdZWPGGFTdLo69rwQnmRK/3lNl EbX4Qrxqq74WA3PHe4kq64zf8FjYdMT7gOBfe5nIRNlNCBAEG54px11y4od57u8bOBuqa3 r3iHoUCk+xUtk7F4nwzOZ4wiMQ1sJnI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ein04UV3; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf20.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=1737762948; 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=ZcO5NeJEjDQdCDY/fuqAGnADUV80X4TyMt4r7D6ggW4=; b=OSd4Wojg9TK5SijCW7Lj1UbkdEkRARrLExSrFCYgZL2jTZDOZCSehzJkwkUCf25LAc/dBT EZOBz7a830A6Z39Z6o2rOFaKl3lw0nWN+L8SqGG25jqY3v8ql2Hv0/EdYtyyZuopfWHIIl i8t+DFm/LWVBkUGY+kF/il351XktVlc= 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 50OIGFs8002260; Fri, 24 Jan 2025 23:55: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=ZcO5N eJEjDQdCDY/fuqAGnADUV80X4TyMt4r7D6ggW4=; b=ein04UV3awDrUwjxe3S2F MV9y3gYFGT9/MmyXGDXQb/BrB4uwuWGc4p+o69qDmO4VbJa80nrnfelxKQ0j20S6 DLl0AF/0hXWyLfa/sqN6uW5ekxmZ5JVfq3CNVgsTyu7UnodQaM8GBZR3YRcxOQoe BKUSS40IOOJhkFcsGTpMTXRMr9tc9v1iEpBT2RNUqT1hEbiEX5dF9CXP35nIF053 hgACxW5JUNXzK+NZd/ubylr/8d2N+Ra8/1T0WMsz81NyTR+P1len+ibflq/QY0Lf R2oXk8MelD8F9VONynGg7P60sbsQv9iplPAtzA5S2se/DYERWIE6fN0vKy0dvWDq g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awufwwhj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:36 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OLJ9Zl036493; Fri, 24 Jan 2025 23:55:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4adr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:35 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQ0018051; Fri, 24 Jan 2025 23:55:34 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-10; Fri, 24 Jan 2025 23:55:34 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 09/20] sched/numa: do not scan msharefs vmas Date: Fri, 24 Jan 2025 15:54:43 -0800 Message-ID: <20250124235454.84587-10-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=932 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: RLJBBpgx7vozRd6-hI4ZYSvtQXLVXi04 X-Proofpoint-GUID: RLJBBpgx7vozRd6-hI4ZYSvtQXLVXi04 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 143E01C0016 X-Stat-Signature: ny5sw31areppaepct7h8c97in9n8oxsm X-Rspam-User: X-HE-Tag: 1737762947-666584 X-HE-Meta: U2FsdGVkX1+qRVzJwRQvnk5SCHB8J/5hI5OiXTSVuXBmRfHd+7BIW8pbx85eIOMdC1OO5eZS14iL1Y1gSMC+NWsTZorAvHYPfOewhO6FFV02dyDLaDHQpxWwpaYHFORKcNZB1AqLxqGTBLPXyB+QJacRda58E82NC7OuBq0P8/3B86oKLujgiuHXd/6WG9EKl3v8IfSCHPAfIfk+9LW8CP3HT5gySYkabOMKfLb4CJ0sUGtKUXf3VPy0rjvROGTiX/tEU/qh8i2QwXKR7+S3HN1GTy6WLNEUjQNpSmg7w7tLjwgfxWn0r7PvthrGdpCk57v++fYtxTvaTxGIBnX+rJvpBAnPWe3c56CKTJux8SaG3cD7+Ur2UL8rI3aXvro8zr/zqbo/qf2RAqGLSpRJDKhpe88A0JITeDoMArcDdYllfhlpxcPEs7Uioj/htO6RjDQcIhGygyJY2cq1zYNAj0Z/3GlcBZ6fEEhC6VlAsvPrbcdE8FFN4UGiZNyOIQ8EIruAmN3GF3wevSYDOtxiUbybGdKMH/7pSag9j1hN/1c68Y/iVxzEUDbzzy3cvPg1+HNJPyQvgdtSMBBoXkVFIykv/ZpjkiBXIfuoZiFg5h/Z+4tmSDYpSyifz6H8CDZeHvb0SqRammtpSKWrkOaxRCK7iZz4FWlqWE5GYVCMndyDvbW1RdfNLvnLKPEW5Ozw319coDFbkh01vpak5CvImSCJPVcaBLoQp9JOdE8njZAIPbFaw/2SJT6jU4ehJ3oVZlTupvj8hl8aNsmjdeQRGHdMc397AtMzSgYaPhvy3OWodwQhoSy7dTZJnaS0/uJ+WrnyxgFGIm+a6zTwVneiFYb+qs13v7IDmhskgxSmh6UvMUue1+SWU2FHgbZ0hMXLamUYpxaSeLsipjMY/4JA0OKw6jC9Itgx4d8r5ZCmCHnieYN78/X7r8knbs92sOCoKXXL1DzhDN+4Pgj84ZE DE58hY4/ vLm+acQdw2Rws2VmEPyioEud2Qw5AWfo/N/nMSJtDC2hAW9V3u0ewYWJTXlhbgnlVYIVnRTzdeB3xx7MuVJAvIBiyTPVgkXisMDAwzNsUB5AUISpp7X4AjOa1yNAOtgghNNq0dGMLe5dxI4AKUDsHWj9oVA65O/JFlwD+JcyIUd8pgcH3BmZCBIjTlsktUxFlzwrr8NEcn39AC6N7vP0RhlI2UcL+Wb5z3O4s4Ag7HOHNb5A= 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 changes to the shared page table but with TLB flushes 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 3e9ca38512de..e9aa1e35f40e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3374,7 +3374,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 Jan 24 23:54: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: 13950031 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 1F604C02181 for ; Fri, 24 Jan 2025 23:56:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 987592800B7; Fri, 24 Jan 2025 18:55:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9371B2800B0; Fri, 24 Jan 2025 18:55:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FF452800B7; Fri, 24 Jan 2025 18:55:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 60DEF2800B0 for ; Fri, 24 Jan 2025 18:55:54 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 225B6161A2F for ; Fri, 24 Jan 2025 23:55:54 +0000 (UTC) X-FDA: 83044005828.29.42C036E Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 28B1D40008 for ; Fri, 24 Jan 2025 23:55:52 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=UXJrjoNs; spf=pass (imf27.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=1737762952; 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=/eSghHqoT5c0J4YzgWIiRZ+XGq6p2xYWtpvcjE+ANB4=; b=Z5tYnr3JBbpmY8s58JpeqwJczgsjJuVf5CwISXZ9UgSwLIIgL/oZz2J0mk17fFWspkwyTn POu0stdVgLEuYJvRLXX79lri0G46qmBFJPFkYh/RHhI/FFMsiQOvPOg+nYh4cmOEFCVZZb VHAxza1eYxCnEwrReF/9bBtxiDNAnnU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=UXJrjoNs; spf=pass (imf27.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=1737762952; a=rsa-sha256; cv=none; b=OynyAj2YAg5001uYEq9MJYY+ioEWeqkYnUoHEhgSoDOPtplPLmrXvDIQM+Lg+9kW7ZhSGP 3QhLjD8svMBqLtgmD0NipDLHLvFa2g08uo6T1+Q/ihgNm5Sj92Dja1NheyRYZl6dpHL5+K 5qEp1xjSeyUQYAdQHGZBsrxXi3A5UzY= 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 50OIvxBh022712; Fri, 24 Jan 2025 23:55:41 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=/eSgh HqoT5c0J4YzgWIiRZ+XGq6p2xYWtpvcjE+ANB4=; b=UXJrjoNsfNb4WKRHZ5xkw OEpw+EPE0TRIcETStVh274mVMU/ko8F9hL67gSxzr76IzNOQKPesaZEDIek7KNQo lTIOIiv8DRhEIC8wock9il8CVWN62KiAPGD112LB69JF6EcmZpHbQQyF4QZ7sbt1 rn3+NWx5FKLfy01BnPhLbUWAxq+AEdhO/sy850W6MLIBaCiVRDw2UNyvhIAR4ofG xbShQ0LMrZ4goJ6FKuRIenPA1Cszgvlb0tYwJtkOIhLiGfy5IkaK5OkK7mVGAx66 2lHmeqb8SHErOXUSAJy4e7cWQmBAGpn2IiZyZ7FthV6IG7ozjw+QWPoUmFjH8KS5 Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4485qm4y4e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:40 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OLP7er036648; Fri, 24 Jan 2025 23:55:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4aer-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:39 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQ2018051; Fri, 24 Jan 2025 23:55:38 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-11; Fri, 24 Jan 2025 23:55:38 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 10/20] mm: add mmap_read_lock_killable_nested() Date: Fri, 24 Jan 2025 15:54:44 -0800 Message-ID: <20250124235454.84587-11-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=825 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: VWyly9zRQiKlVwOlv3-7fatJDdYAY01l X-Proofpoint-ORIG-GUID: VWyly9zRQiKlVwOlv3-7fatJDdYAY01l X-Rspamd-Queue-Id: 28B1D40008 X-Stat-Signature: 1ey88k1s5zmnrsxk54r7o99paxsct1sm X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737762951-102975 X-HE-Meta: U2FsdGVkX1+bBmqsSVitumISI+HszwTFVATYb9fXKZ7MKL1CaGb+fiCrwzZ3iBxvJcUQm+3fh8Z803QzbrqtmBYlkezv39cujIlQEMON8DTUkbo5yLyoEZ3m3xJE7uadUvm2yDv3dvjIqH7FbdfG3/CnBm57kQMGCRxvyqyvzCPrhcPl2XgrFcZWzAMnSz0SmF1lSscSXF9U4CIipufHuW8VdVenqlMCie1PRolllmms57DwxGcMuQcocR/Hd7aMvzXCwM7ID0n1sF3VXYqLMzFPOU8A4mXMYOUwV8kCoHxWwN8eHjqiix6yHxjf0Sk8O8wr2sjE2Mt/Sc+25RCBl5wJTTTUIrJ90dzd8Iu+KrSdjJt92JD9tfZjl+RkQOw78Dx20sQ7rop8Izt+tpKtp/txiFVftiitsMoeN30msGhjsrgbq6GQVrRANqG3OLKzKiV7eJeMgMWr1GV9NhGXVfdwLSedNHQtyN5+PPp0zvIU0PLxHjhkKROK2S9JxNvGCkYoMeiOCW8ZVRcUjCvVk0ZNu1zZMNAv76tKC0yNdd7m+VfcI3AcULS1jH67ZYpxIhl25ppkN45uw51HUtCOC3JSQj4uTdYZZHYyJSLZgEIZFKnocbX7Iyz1n3aYabXA4xukqCFaM2OS4VsK6P+HyeGm0z+H0Yms0dmQn3MQTCqb/DBx8X+02BlOAM8xxfsyMxcYTTCn0jl7K5WSavv2sS7Pq/zcYuTZ1w6Jp00YskpHV+g3cgnXD+DWf6KpLUrt61yB8IFiDcbAJeMX4zrnbsTQTgGUZlvpwBjHPiSOi3gSbfjGjaFhQjLUUIQ1mBZfE1QAG5tg23IRpoYXBpNBNroJcRixEMb5683M6/zyOEoPZrjLIzxvtiHZEGYWqPP/r0TmJifDv0UI+39t4mB1mGAsnfGZg3MDKxr0MdmigYhaZjE7LJsYcKzuOzbVOz4CcnsJawXukmoygXhE+sO QJQjQC6c kRieWgyrecP+sFpgo5IWNusRyFa90B2DqeFRsVtN+aaogf0upNVc5EP/NSFknUFJxN9k5yIG7eAUOwronHgIif1jgoN/xGjMu44Fj3scpf6x/JRKF+5/Wo0hx+mL5HXmLXnBzjVns86Ril8zlG1FxZW8CmIHDsm6wsDQdvowU0ivqGLJ4id/r4/5vIpVDqyxHvKeJZbqeAbaPGCo73H0j+2dqi9Nl3yMlfJS7XpIzoYY44x9tLtihAaT8oyrNQO8Wk7mZXNsQXj7X2SVjkSSrjGwvlgCNao9DGxXR 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 will be used to support mshare functionality where the read lock on an mshare host mm is taken while holding the lock on a process mm. Signed-off-by: Anthony Yznaga --- include/linux/mmap_lock.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 45a21faa3ff6..4671b4435d2a 100644 --- a/include/linux/mmap_lock.h +++ b/include/linux/mmap_lock.h @@ -191,6 +191,13 @@ static inline void mmap_read_lock(struct mm_struct *mm) __mmap_lock_trace_acquire_returned(mm, false, true); } +static inline void mmap_read_lock_nested(struct mm_struct *mm, int subclass) +{ + __mmap_lock_trace_start_locking(mm, false); + down_read_nested(&mm->mmap_lock, subclass); + __mmap_lock_trace_acquire_returned(mm, false, true); +} + static inline int mmap_read_lock_killable(struct mm_struct *mm) { int ret; From patchwork Fri Jan 24 23:54:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950032 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 0169AC02181 for ; Fri, 24 Jan 2025 23:56:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D7BD2800B8; Fri, 24 Jan 2025 18:55:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 085DA2800B0; Fri, 24 Jan 2025 18:55:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7E562800B8; Fri, 24 Jan 2025 18:55:58 -0500 (EST) 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 B92582800B0 for ; Fri, 24 Jan 2025 18:55:58 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7572DA1A02 for ; Fri, 24 Jan 2025 23:55:58 +0000 (UTC) X-FDA: 83044005996.18.CF1DAEE Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf06.hostedemail.com (Postfix) with ESMTP id 3F7BF180008 for ; Fri, 24 Jan 2025 23:55:56 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QeFtJJdY; 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=1737762956; 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=OSIj2mJijhCNko8dcXyJfuTUdjY7NtJAOi00OHXcvao=; b=vaK5q1doCkbEvEP+/jPQxj+KTEpsuEji6Po3rcDA1FLvDpsbV9qeeKI8fJ87Xm/W+yS6zu TNJrSFlWGSBk2FeL5Q3totA3N8owLw/Z3Fo1a7IB+UcLSOItQxDQDKLgjwIMQgt2UvSKhd PtnbTUzt9v2vTqGgWNKHsDG86szaXLM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QeFtJJdY; 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=1737762956; a=rsa-sha256; cv=none; b=AzWE4Uf+FE17JtpPu/6FZK61cPJgB0PjS6AedzZ3RJrzfsnCFFiyOURq4zcFsKZQ/pHIRm MDlhK2MrbiFzJUY3HS50VqFZbDJlA2IFAewlRDYJgIUw+3NylNsGlmuXCtPTB1WN3uK5bQ +v/me8n0ZIg6RVwyy6JboeopBAZOzCE= 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 50OIExIp022002; Fri, 24 Jan 2025 23:55: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=OSIj2 mJijhCNko8dcXyJfuTUdjY7NtJAOi00OHXcvao=; b=QeFtJJdYB0wtvXXNjl/QM MPDJrbyYUVLf9oTAT9Q1GPOvNcwMRB/wQjVpDMKhajG22HNnFiLBqaUY4k9lk+Ch p+HSZLNHXxr6eUHaE1S7kk8q9oFnK7c0bR3w9v/pxvPddRrPLiJ8EFvdkZ+MksWF kkNtUZMettwjyChukyChxUmO4z5Z6wpnm0a7epnj4d56SjuEL1ws3QX/AiXktMNC kWNWqqyzD5/dcni/8xsWCkA+gvfBNoHQTEyIJWLR4DRHSIgRunNbVBi2Zx0tqZ+x ony2WUw8mZyEiA/55WfKntKeHX9zSZgPpASTVJgawqgXcW31dZtBBWMWuOFY2Ra+ A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awpx5vpy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:43 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OM0FXi036437; Fri, 24 Jan 2025 23:55:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4af9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:43 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQ4018051; Fri, 24 Jan 2025 23:55:42 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-12; Fri, 24 Jan 2025 23:55: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, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 11/20] mm: add and use unmap_page_range vm_ops hook Date: Fri, 24 Jan 2025 15:54:45 -0800 Message-ID: <20250124235454.84587-12-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: MwcrHgPHqQLpE3U3E5SYpIbs-4Wi_R5L X-Proofpoint-GUID: MwcrHgPHqQLpE3U3E5SYpIbs-4Wi_R5L X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3F7BF180008 X-Stat-Signature: 6xsm6s7cuupus9kxuzeo6begdr4uaeiu X-Rspam-User: X-HE-Tag: 1737762956-449340 X-HE-Meta: U2FsdGVkX19QWapvkHFZlS43C5M7p3M1KsSQVXLxdfIbwNyVs4dQ5Px705Z2kIMg7BCLxdE8zxWwTXhFm7mH4tC1n47QwwyWHFTS7ZFex+q1GGdYzz5QvM/jENv+sX5iCXgPA60DlWLPbmkSCQVwXfXez0uojpfElFgfkjsd4MEOq4kmteuzVH4bx5q/LTDOEgKqGzLgUZZ5XjrhmRXZVFn/m3PV44j14zXQpnsZ9XYx5XO/6aQzktmOzH1lMnBFnPnk3kRy8jsSHr/jX5+U4ZUNAhuNiFJ/PlnwyV9CFIonYOQdJAkZEyv79QjF2Ri85kMVpMrk/T3SvwR4afKCm+o+x7wmKg9DYkW1zFhZJJ1A0heuwsy/3H88aVQwoZWqP7PcNVmvzgymwzRD96jfYLkT0XLVVuxXGg9adjr9JXHD9Y4cAM/jO1Ar909cUttlGG2wgyf86jxsb7pVmuWzc2kWYq+EHg7B7DKgP+EutP95bMWtPS+afSXYFIezov6Sv3FaXZcvQhzom88ICDGZvoD6vhXlSlzeW0KkpE7OEdHePCEcDsMJFd/EMLPNEmL9OmSYs6lYei3uyudSqhtqIBbqWowD0qcVerBbFLduMrj9Kuj/Wx0h5hTxv6emVk2hv6M8ZGs5YnndkO5pchvGdEmbN7DFLDwaGINcw6ZJp3BNjZeYVhbeHjx9jBNxGC5Eo/JGZcAh1y3DugiabQIlgtujKizSZQn47WQulUqwfrlsbaHN0d3Fz7U3tGzjk644FoH70/6O9GZp4Tq+wywp4VQHy+2xhSXDz1vBbAADVPnViqLjw14059npKAUOs2Q75PA2xvEWp7YbiuBVsE/47bVpj4+o6LG5AOqjBkevw2+EU41drIhiAwYBKLf7juZGjmTUec8Y88lQtqCGpe9+gPQGZejkDMFCL5giD648TSbS5NFjUc60ARmFPS9Y2+NGSnq8iypWDA4cZh2f1B/ qVCnYc67 r8g7BXjx/6nz3+pOTNQxE7CPIaW3/r+rSbrvzhpFIYc2HUMq3FpBJuTHdc+FCrhYrWrkCBe1ouobaSG6PlfAFV9ZMYLdUC0VsFY56gvZbCFIknEipwYNUs43lTG8OMpSrRK7BIptG7nYpk66vEopVz21qnDXoeJeTOXpyqRZqYcsXncl/FNUpbQjM+m5Rx6c1DKqH8zMNMwVFBRYCCL9bWppn85LC02hbmVq1+DIScBb9RWdQDQ1SCgFA52G0/ejfBNhfMV4ytSGOlpTvwv+mOonQAepHhXlVdKuD 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 bca7aee40f4d..1314af11596d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -39,6 +39,7 @@ struct anon_vma_chain; struct user_struct; struct pt_regs; struct folio_batch; +struct zap_details; extern int sysctl_page_lock_unfairness; @@ -687,8 +688,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 87761b042ed0..ac3ef62a3dc4 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5147,6 +5147,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. @@ -5160,6 +5184,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 2a20e3810534..20bafbb10ea7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1875,7 +1875,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) @@ -1895,6 +1895,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, @@ -1916,28 +1926,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 Jan 24 23:54: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: 13950033 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 30D4BC02181 for ; Fri, 24 Jan 2025 23:56:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89CC32800B9; Fri, 24 Jan 2025 18:56:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 84F502800B0; Fri, 24 Jan 2025 18:56:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67A7D2800B9; Fri, 24 Jan 2025 18:56:03 -0500 (EST) 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 486E42800B0 for ; Fri, 24 Jan 2025 18:56:03 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BE3224B92B for ; Fri, 24 Jan 2025 23:56:02 +0000 (UTC) X-FDA: 83044006164.24.324E562 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf15.hostedemail.com (Postfix) with ESMTP id 9E831A0004 for ; Fri, 24 Jan 2025 23:56:00 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Mm1LIh12; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf15.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=1737762960; a=rsa-sha256; cv=none; b=YwkCjo9hZBf4/vC73u9wDTWu4424EAy9MxH88pk/9LTig/z+kAFVbeE1s800N1/fizGGjk p49PwgJufxOfpLSR3uW2Eus/PnLxVdTxY2dxEDl5nDYlGx0IuYuMpl8F5s/lj0yTx2iq2j avT5tocZNSva2TwyBSOn2NfvsEScvo8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Mm1LIh12; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf15.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=1737762960; 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=brN5YFFSbK9qb6sU8kyqnzGs0ZV4dIdkz0Y2OGeQQDI=; b=MlfXsY7ZIGPvLTPDFNpcN3VMCuPwoJHNlMGYVCqeD+YRKZuaZGj0kWgAUWb8q4MVVvrg7L GGem87oU+E9n4nH8Cy0ZL3PSnqbPIkXMR1m+knoWLH0bwkPaFjXaBvXY7bJs29UfmF5aPA OdjW6Xob9C1ycfrckDfESI6SOEmr0VY= 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 50OIbuNm019103; Fri, 24 Jan 2025 23:55: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=brN5Y FFSbK9qb6sU8kyqnzGs0ZV4dIdkz0Y2OGeQQDI=; b=Mm1LIh125wbmWKLr3jwj4 R7menthV7n7TpEZr/0aypVito0pT68YHzWA2WWLbgm9qulCEOARfgF22jhK4ghzu JuFx9Tq5FDeJqPnFnV+tQfW55CPAHFNEg5nuyZD0XTE2kdsyH4gNFjFfdHuOH9ze 7sYTwIl4yAYK1WjO1snF2PKEEohEso8ZJ2pTjai5F6/SXKLeGDoRNdftR0fnjKV5 iuzXnAnoHPloNzwNDPGr1PwAmV+vfmrRujHz5+hIW2/YF2IwYvAYEi2v6xh5aP3e NHyYjMFdt6qYoyOw47Z5bbiE65oHmOmMD1L48ApCP5PIAkliRqBYxIaESjoAgv/q A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4485qaw404-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:47 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OLoFNG036500; Fri, 24 Jan 2025 23:55:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4ag8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:46 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQ6018051; Fri, 24 Jan 2025 23:55:45 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-13; Fri, 24 Jan 2025 23:55: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, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 12/20] mm/mshare: prepare for page table sharing support Date: Fri, 24 Jan 2025 15:54:46 -0800 Message-ID: <20250124235454.84587-13-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: np-h1M02s4XSflXejt2j3zPrBIjWPfJo X-Proofpoint-ORIG-GUID: np-h1M02s4XSflXejt2j3zPrBIjWPfJo X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 9E831A0004 X-Stat-Signature: 1fd6bx7ehywg3nmmze8wxaumk3b1zi9x X-HE-Tag: 1737762960-376298 X-HE-Meta: U2FsdGVkX1+M2i+vpJWjXNVtODISuna+hoh1LBW2VBDdjJ0dkCPMvktJHYQi5cAPedftTuzfNSI00M5eY0HbUXAb7ZiISUpt6gOI8fWumX28m2ay+zdxZVOMcs+rnOVKKFtVVb68SzfeePddhs/Hbq30Rb+Z97BQSJbrKBzTkhhH7wRuggbhocqHfhVDHZyULUgS2GRHNfP4E4KmQ/92VLfCJXEAhwccYlda3BCcL035nzWi+ktt0OWBA5NM9x1lVN5Yv3JNg8PKlhSfKI205qudfEEl++b51qSIg8eDEVxYmVAELFMX4Ic7YfWSbJdrUO7PuDsnLbZp/YJKPnM/JnRf54QmMLNrFAQahr2vmIFYSrRe8jgUhPcuBng3OcgkjjzM5U5QrCPSsIN9PqBRtoNnJhgR4sNht572dcqbVMLXzhyYeay2qFLPpeS4lPEWbciIrZtJuoXnB8y0SwMMrKceYvPxCkkOUdBhw1Iag0JpRDykL7m69ZiYpsvJESuKu2f3F8NBMpVgx5JoyoIXDQfLU8KaJaHJYqDSPpX2p7JWtHacHhsCuWtFvDYuF3SO/3GRlNmyG4M4y5nnO/wnoR4h3UqQJiK1VmzWD8jjHHM5BXKfltjXXuupBADwTJ2MRF+A6G5GrpULO15C953V4kY6AOQKYJEoQGQ7/iFTBmiRtlzjQbkV+iBn1sFkF3p/ZrWm0u4n2VCy5alvLecRE//y4wBVNH7HacsGT7YfWZDVfhB+28govJwQAQgVQB9SHkVrvRAOFeeYG2R5CfBYCZ4tUuJbwNRr2sydo05XZnsppdWB8DzevTsnN2Bzg5joIsaxSMsQInB3Qe41cjSvsETsBRNEFqtdeF8HI05YLE7n93uSzOBO79Lc7Qy0NoHXHxoUa7weSealXzu9KI+HZUwHBjgCEs8o3od/0wgRI8MoB3MfL4wjNACdO7g8wRXG5OyrSTFQrZAjzr2ajk0 /E7cmYP0 /uTqqcBzaS/Gwl6LU/DwWvixbYZiO1yg4B6iWU6X25QCN3ucU3Ho1yEXKBxP6xrQc6cycPGHGwMVswVyuSmYns8cSRbT4gUCDhI66ccgCeRUjMdL2T3zpRUfKfs2U8rvze48//qAW17r87+LbkKvqrydbHYUEqpZd+FEYMadHikNCtKKu1b6X5mL/we34l/qxxZDlu6D343pORdCuz2bA4Fk32qckWi6vFgkjZ+5Di5ISbGnSbfg+OzVmnyUfUO0bIHBi7AH5pC77vz/0TtkwPO6sBDbdODZqyrY1ioviDBj9edJfJe7yxK3ORTXrAUdSKBLZ 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 | 38 ++++++++++++++++++++++------ mm/mshare.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 8 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1314af11596d..9889c4757f45 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1110,11 +1110,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 20bafbb10ea7..9374bb184a5f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -263,7 +263,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; @@ -275,7 +276,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; @@ -297,9 +301,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; @@ -355,10 +360,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) @@ -395,9 +407,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))) @@ -408,9 +423,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); } @@ -6148,6 +6165,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 8dca4199dd01..9ada1544aeb1 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -42,6 +42,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; @@ -53,9 +103,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 Jan 24 23:54: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: 13950034 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 B5C26C02181 for ; Fri, 24 Jan 2025 23:56:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BFC32800BA; Fri, 24 Jan 2025 18:56:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16F812800B0; Fri, 24 Jan 2025 18:56:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F05C72800BA; Fri, 24 Jan 2025 18:56:04 -0500 (EST) 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 D0A562800B0 for ; Fri, 24 Jan 2025 18:56:04 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8A5364B92C for ; Fri, 24 Jan 2025 23:56:04 +0000 (UTC) X-FDA: 83044006248.25.8AD9424 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf21.hostedemail.com (Postfix) with ESMTP id 954A41C0012 for ; Fri, 24 Jan 2025 23:56:02 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=XeEkIkrW; 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; 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=1737762962; 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=nCdkv5pMD/BW8EJZHRB98QYPFY1ik8038tE9HN9GQDQ=; b=HBdj1OnpYNC9RdYkBF5HpHLtOL1GLETD2mUTgJ2HtpQXI3p9wPtktk8+dlynPQYmH4fwJp QtRzmeUO1CBTPVje60BiJ7yLAR0+oEgKAMzjsvjWzP4NbAZOlLWgxYoHQUggAMrZ0nPptJ UrrhQNFkVCeNltQO2Np1qRpqZIF+aG4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=XeEkIkrW; 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; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762962; a=rsa-sha256; cv=none; b=hG4+gp1Xro+7ebVY4eEnQAyCgHh1nz071EFJbMWcWa6tc+6cMd3ytO92/5HxAiHWXqf224 C/DtFWtEz9nRM+AqhmR+FKH0DifVSb2avDc6mrq3YgofZHbPcmzbRp1rcUtRDELjd/XYdo 9+gJcNEEqiWnmjVrWRCMK/ufTI5e/io= 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 50OIeKEb031124; Fri, 24 Jan 2025 23:55:51 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=nCdkv 5pMD/BW8EJZHRB98QYPFY1ik8038tE9HN9GQDQ=; b=XeEkIkrWDwXm5HtebbhBD p3lABo0GMrvK4ZvGeh56K+Ji9vVwuOJ6CfP9WQgDNnIg/fylBvrEnda76gj1hlaH djlWZy7JPMD3YWvJ07uS/u2FQf/WNtgihIgs+ahOJw7m476tTNkDwMXzkkvgVlMb WaAhY1K9BmKIjf9cBYWQCBii9KnDOWEQ86r5Jgcb+DoKoPYGmvQzlxO/2s1/HjSE 2X8wi2WkZkemqVoSzjBSlGdAQCPFca5ePjZctgTNBHixFaMq6YMIwXCF0STwxFVX 1V8aXMFIhRqshW3vli+id7PjxsJ0s6TGm5KFe5oka0l703yelWNl+uHD03Bpstfy Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4485nsmvn0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:50 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMD09a036431; Fri, 24 Jan 2025 23:55:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4ahx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:49 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQ8018051; Fri, 24 Jan 2025 23:55:48 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-14; Fri, 24 Jan 2025 23:55:48 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 13/20] x86/mm: enable page table sharing Date: Fri, 24 Jan 2025 15:54:47 -0800 Message-ID: <20250124235454.84587-14-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: m7wXHyW69pLXZ8gl0E-xcyVHCx0Mq1Za X-Proofpoint-ORIG-GUID: m7wXHyW69pLXZ8gl0E-xcyVHCx0Mq1Za X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 954A41C0012 X-Stat-Signature: 9acmpjot6pip3pywaa4miw33kmu73ouy X-Rspam-User: X-HE-Tag: 1737762962-583143 X-HE-Meta: U2FsdGVkX18a3e3SgiVw/iyzWFec9KlNlGHekbbdGgLlOQcMfJqGz42ZgRqVMoIp0OHiG1CU71+5q78WC1SYCutonbC/r3c8HBkiEY4YtPHFrp2WVkdPwCRboGeQjPbY3JihCJ2UYe5azvv2JvcOUxfjhTHgwXTZzEXhopplDPZWCxcYSPIMuR7rKHRiN5kAIrKYrZRdhM9pETOp96lOUOp+G+hieITECMiq/3RMjBzYNSCu9D2A7AorVz5AXy8nXVIWXaPoO0TSu+YnJr49eXRLP809qG36ngVdbhHqATH7/B903M8NC9I9NMQ5m/kDZwKgDQ6jO9TNc4Xt6KveQqxbRhUPUEc2vV/wwBsrbaQQYjI2wDjbbUS7ygQfg/5Q6kBBLgi50XazwSh9e7dhd3FF/IOZqQXV+CKyJPl4gzgIzvnVJ+C/9zZhPSA3tgdk6fmGkscSuWr7Wdx2NmBBvIHPNgxRhyqQUZ3z5RCWIAbJb6AYVLRVJWayShAaKLpfQ9LE3HwVNNGjdQPWU9Ei/irNBRnpA0bAnso6v0CpTN3haM53aRs/VPi+Kd/rb7X9KyFySuT9Zlex7yiOCOMFNlkzcPTwn6rVgsyBcqhhtgD4aTVOX9uAIU8CStIxgKyIF97Y9rc6+ibYUnTQ0vOqO8z5+7DWx8hl9Mek4HcQClBhCy9wrD5R35Y0yBwa+1itTFWVEBL4iNL4UcXp3yc0C0UfWhWt9BivzG973YG//JHQheNvN7F8/T0vF3aqe25YYIPxz8qu6cQyEe/uSGa8WfmVW6zTABCa8/SN8S34K/waaFwcpBkK80HIx4dSW8lqdWfe7ZlJhMS6E3EK8NAP375GfoHpeJjphrhGoW5sjtAssuQ4iqjaKTd5FzjCJh0toK5aVJ1SDpthu1/UcddWlbBdBVu8lOeIMnBPMOHQlMIxD9Iq2/85q5bniJ+uobSxcoCtPhU4uk54mNTGsWh KSgcG4W8 X6Iei3kSU+hLut1TWGKrQjtiNRF60FrVTWF3m30BxITQkCGpC4LXtbETrsLe858tEZuFKwD6g7vV/Dbsu6SH2Yqfn+dSmq2EPO3d4QjyQyvKJDl7ml/YK4p05VceaITbsvV/mz4Bp1zpPQxwzRpXLF+dvoamUiqbi8FTFjyaQ+HsjiTd/zFFucCkNXpIegTokToQEPnWDDzzBMuYIf3UQNobWUf3q65yEAlyDF0RXOvY0DgE= 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 6682b2a53e34..32474cdcb882 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1640,6 +1640,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 2e1a3e4386de..453a39098dfa 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -120,6 +120,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 e6c469b323cc..4b55ade61a01 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1217,6 +1217,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; @@ -1330,6 +1332,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); @@ -1358,17 +1366,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; } @@ -1386,7 +1415,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)) { /* @@ -1414,6 +1447,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 ba3dbe31f86a..4fc056bb5643 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1360,7 +1360,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 Jan 24 23:54: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: 13950035 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 3C305C02181 for ; Fri, 24 Jan 2025 23:56:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D6212800BB; Fri, 24 Jan 2025 18:56:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 041C62800B0; Fri, 24 Jan 2025 18:56:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE2892800BB; Fri, 24 Jan 2025 18:56:08 -0500 (EST) 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 AF2D32800B0 for ; Fri, 24 Jan 2025 18:56:08 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 69BA0141958 for ; Fri, 24 Jan 2025 23:56:08 +0000 (UTC) X-FDA: 83044006416.13.4F9C740 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf03.hostedemail.com (Postfix) with ESMTP id 3C7742000A for ; Fri, 24 Jan 2025 23:56:05 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=fUnoSigK; spf=pass (imf03.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=1737762966; 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=yJXvnYoxkm1NK3qwW6jmL1jgVFm2IaD/yhkctg4U92M=; b=0wITEJDM3TrfbE12fNAl86B4w5Z248o4Z3lH3RQMIR3OWNpel7jqmAH9xgTVp18x4l/++a lPcbhuDs0gXOYqJiofcM6w0jFK45E1GtYxBEUa+J3MBGjQjvbLrm1WfRgfJP2b4e9znXqo rqgsBI7HWiEtoEdrpoSzgwb/wfgIbEM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=fUnoSigK; spf=pass (imf03.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=1737762966; a=rsa-sha256; cv=none; b=sYAL3Hwod3SkQEt1XatIrAt/RwIlsaBwF3reL4tLdxDHnDCu7A8H/wefykrRC07Qim79J0 Sq6mOIvvNK694PxH+x/kPtJAKDLLkFHzB52LrK7OGFI7U6fGqCMwBJ6Hk/GowbRs+Qd5+G LjqoC3ZNE1a1isEIZXK0rLlXUmirsJU= 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 50OI8hMZ022258; Fri, 24 Jan 2025 23:55:54 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=yJXvn Yoxkm1NK3qwW6jmL1jgVFm2IaD/yhkctg4U92M=; b=fUnoSigK9HLwd6NsS95Dr GyOpPYzCA/4kAye89j7nfUI1NddpqygTwjTKIAx8WdCkHtrXLbtzP35MIHAsmrUW YVajTmDtXQjTlPNn92R8YLpqiHdUn002WI1acMbJkbOE6cMhRzIe1TEbnETKclZv PO8InVxSqjARDaOLg0THwBHKBh7H5l7Xp4Mhgk1Fml5N0jH9z71iYiikv6v2wV/f gSumYFsJlOo8v1MNe/KVyxtq253t9KB/+8zgIauIoMpKEGsrxO4wJMhdS9HhNoxx qdHFU0fU68u6E+2F/P0wK00JlGdSUsPJJNY44LDZVvFxwFLeMFT0nDibDEg32Rfu w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awpx5vq1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:53 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OLKNdP036521; Fri, 24 Jan 2025 23:55:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4ajv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:53 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQA018051; Fri, 24 Jan 2025 23:55:52 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-15; Fri, 24 Jan 2025 23:55: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, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 14/20] mm: create __do_mmap() to take an mm_struct * arg Date: Fri, 24 Jan 2025 15:54:48 -0800 Message-ID: <20250124235454.84587-15-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=915 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: Oa18II2kZqrAU3hlh8jjOS5UYIop2-kj X-Proofpoint-GUID: Oa18II2kZqrAU3hlh8jjOS5UYIop2-kj X-Rspamd-Queue-Id: 3C7742000A X-Stat-Signature: t3n79exzybdahun1ig1rgzuntw6gaq3u X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737762965-326250 X-HE-Meta: U2FsdGVkX18I+e4LxUL+Fv02qZjCfT6dn9bUJI5W3y2OXMw0rO84tQ+ShDmThDcgTOhYDtcQtZ25QwwfZIiccsqF6zaNTtXeEHcRDJDSeKjv8KFr1luYFX7/Q33eqIuBUCLH7F650C+2UNW5Bfw50WxDAvkFsLQfv59a+/ucFLgH52PqYMSvvOFtrwOjeenGw9wP+GHyj5knKubjE6o1IAuTF8F3JHUXCuGsMt4lHrBgbMJGXHnRwmq49RcykMa+k4yBqyR+N2GKMns8CeWL03tEMShRILM1lC2gQH8NwElYoVL0lYc2VoRzPK0fj5qnw3V/SmEReUYrI5xRhYPHP7CsMQAMviE+7pfULcB8FEg2ArURR8yJTBTqTf2urWppcSAYnm3GgMH43iGCw33r10adMfBFESZQr7AKWryXiq0WtXfrw0IGD77nDQgMxjlR+RG8oZMvs2sp7kjBSBz0WTPlcZGFCCygeA6zffhZYS6AfLur692eDeQzLkh2Qoe+M8SKXQo796zeZ1OI61MDrJCoQ/2hRfteDp2B+aL6pr5IxZEg21z1Ix0t10x2Czc52BigNU0/IMQX2nbDd/5ADTw9STLHbMvEJoBZM1gypuytM8wV+d2c/UzV8hTTl9GIi8QBIXS3iHGcn9IqqcgAGLIDkNqLzslesLw0vejBFH/Ymx0Y+NVmkOyiRfpOWKNYCHbLDaBTEqIlGBf/W2PLeO2TJuoCX31RniSOQIOcTbTFPrLasr9o7tjD5BZR3p3n3qX0GDFYM3Xpu2jv6Riajh+gyhWYkV2ZbXfCcRGKLchI101qOcRU7oeozt5WUSlu8ngSD/EUcGYRUqe+kQVl+eCtBLgLJUau4dUhO5u6h9CaXPLQCd2a7EDJ/FiduUdtmeg/ATd1v2Mhnp842U8eGgqwk8vxAhfH34yWpDDl3vyWQOl93FaNZ4+PhzbhG9B0zqDyBYoTt7oNmulk1f3 PpWNO0Vb wV03OWqsOMfwWejGvv57WlUlOUWK/eKeOKIekNy4Y884dfrQdAW1ZQ9SImDWIPExnhQVnrJr7YxjpsoNGNqP5WanQ/LaWdXYT1qpjWOTvN0abxRXh0hUydGDc29nDtAVquGrxwTnR1/tUWtsRzGtyTLBrsMAQsqMbBUyC73o1HxVZbCAd3Fx6ooREqqnO5wkY3Pi28hfYNJfjqkp/ZV3qQlxd58FzalrHOhG7MIe4igShrDicLnAPD4ZiyDayx6MuC3qS1aTaExJ7mrESFDqNgOe5fXNcK8ddsSpP 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 | 7 +++---- mm/vma.c | 15 +++++++-------- mm/vma.h | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9889c4757f45..80429d1a6ae4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3398,10 +3398,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 cda01071c7b1..2d327b148bfc 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -334,13 +334,12 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, * 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 +557,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 af1d549b179c..28942701e301 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -2433,9 +2433,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); @@ -2485,13 +2484,13 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr, /** * mmap_region() - Actually perform the userland mapping of a VMA into - * current->mm with known, aligned and overflow-checked @addr and @len, and + * mm with known, aligned and overflow-checked @addr and @len, and * correctly determined VMA flags @vm_flags and page offset @pgoff. * * This is an internal memory management function, and should not be used * directly. * - * The caller must write-lock current->mm->mmap_lock. + * The caller must write-lock mm->mmap_lock. * * @file: If a file-backed mapping, a pointer to the struct file describing the * file to be mapped, otherwise NULL. @@ -2508,12 +2507,12 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr, */ 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)) @@ -2532,13 +2531,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 a2e8710b8c47..e704f56577f3 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -243,7 +243,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 Jan 24 23:54: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: 13950036 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 12056C0218B for ; Fri, 24 Jan 2025 23:56:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D5BE2800BC; Fri, 24 Jan 2025 18:56:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 085862800B0; Fri, 24 Jan 2025 18:56:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E403A2800BC; Fri, 24 Jan 2025 18:56:10 -0500 (EST) 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 BF6E42800B0 for ; Fri, 24 Jan 2025 18:56:10 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8677FB22B1 for ; Fri, 24 Jan 2025 23:56:10 +0000 (UTC) X-FDA: 83044006500.28.17AAA6A Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf29.hostedemail.com (Postfix) with ESMTP id 97A4F120003 for ; Fri, 24 Jan 2025 23:56:08 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QXXOQ6N2; spf=pass (imf29.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=1737762968; 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=W2H0ctTufvhNvnXZJs2k6LGmiWdy4rqMSHVr4raXjx0=; b=Go1r7VpjqBVfLdqCp64Xv9BJg59x3SSLLAfYppDqF5ciE7VDoBhTS2LuI7CcJk4eTlAmG2 AjLJVK3WM9+YELA7L52UM2iXLA57mreZKZA3k2XU9GUZh6vKpqIJgVeaVdijulKqp1/0UR FGjNK+E6SaZD3PeBCcxGIXcUdeDhp94= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QXXOQ6N2; spf=pass (imf29.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=1737762968; a=rsa-sha256; cv=none; b=B9dmi2FvcguA3OePpRm/bhidOl5T/xNhtvooq08/i03R9Deus7Ri5kqELwgYYoSJx3dmED MpZL2PQLYKgNO0gXPcIJazWUzSCzhxF+rhP6kUXl1v4BWhYXAuFQ0+0uSYYCZljOFG6eOI iheQSRItPL7sPweOX46vTW42NpYB8zM= 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 50OIioeL018166; Fri, 24 Jan 2025 23:55: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=W2H0c tTufvhNvnXZJs2k6LGmiWdy4rqMSHVr4raXjx0=; b=QXXOQ6N23uk7G9VbZbPAF f/QqSAc5iOsT9xCDTdmT6oyWhAgniQUG3Z7HmFAfZ0bDBwKBIvV+YT7Vjcn2YUsw 4BXCgx2yNsC2NOEOkIHJOoc4cywTGNGprHkX2qJmp3Xx+WG/52Czo16Ed3Ov5QhM 7/Iq8gqTqAgrLzC/67EBmTQU8e0ckWYvZEkC9eoZSGIttbuEitMyfH3mwJVOB5cq nCTIcpd5kRDYGcIOT0w0nMvOGTNdnhFcaiRQEsEqsDLWzbY7hJ3r5tDcUZkZM2sm w/OjPwtIAYWhM4xN3xfWaR0SlPwYAKwlvDlxi/32YuE+r3YbcTLRLr2NJor30AJL g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b96am96t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:57 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50ONC16b036516; Fri, 24 Jan 2025 23:55:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4akt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:56 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQC018051; Fri, 24 Jan 2025 23:55:55 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-16; Fri, 24 Jan 2025 23:55: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, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 15/20] mm: pass the mm in vma_munmap_struct Date: Fri, 24 Jan 2025 15:54:49 -0800 Message-ID: <20250124235454.84587-16-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: 3Bsi0dEb_NSrsadh2i7dfRhctL6iq62g X-Proofpoint-ORIG-GUID: 3Bsi0dEb_NSrsadh2i7dfRhctL6iq62g X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 97A4F120003 X-Stat-Signature: kf3wj4gjdqgj95t1oj18wc9t41natn8y X-Rspam-User: X-HE-Tag: 1737762968-742861 X-HE-Meta: U2FsdGVkX1+TE2g89M9i/whtRiNHAAwxT75ltOUrkc7NbB1azRu/29RYdPT91Izw8WFE7MGMu0RHm8z28VfCfT3xIw4fFsON6NQO+n7ez06tFL18bCbb0IqtlD7YaPtQmXStlqwf1RQbROScsw/amdyBrxsQ8H9MN0dLQng+ITzvqqkXKPEFolW1Rdp9R+x1z0ZrQxDv5XVP+NDcyQEHR7dzqq8VTRKcveLmna9wy2nCRbqATVI9f3spjlPqo95ScUMsktS05nzm8h7nHERBMcxkPZqG5C7XZ79N9ct2OsWDEbDPLRsmzT16h0UlJe9DopJDvdZOtK2EmFbZC6eMY2UE2z/5AAUgp//VUxFj+7G8OVIUf0uSlJPDIAIUip3O4ACX1QpFkVGhAZyMcasYR6yGBZFmbQ9NoRIwptAeD6Y1/jnQz0ACSHkH9UtnV3AiTW++2kbRDgYspxoNMucTAxj6IHbUdU7uNcFUm6ZvdKRp7WfGzeAgg9hvrCA0Q+Inzw2KUCC5twTiuqK7lS3oO/F7VEs0ItMkiKlasEMBjKHRDojXKb3QnY8cXbTezhSTvgt/3RiDhxE+XHo6FRFkclhXcpwFsDARBjxiOgekpFEvg6DnPSgo2LD7yUR7SxOuX8jDc2PSGa9VuQpOm86VVbDNH8e6IvXlUdm9mem6HMDAzxSzcjaEe3iobQnOV4fBJT8pLUc/NW5N+68HhSwmswbjtBlHbtPDso/n5QL+ud/0NUjs68/vN9Kc9cxsk71No33C+7yxiJExMeTqqwqf4+On5Np6HzBmeQDlI43qamCUAdu8V/ElnoCJda9aP7BD/ZG572jVwo0ItwpnoTN7WbWAnYSw0nPmhdcuFqL+Y96jfQj7N/x393xLtHz+19kRufk6DvF890wSg3k6ceD5gkpbKf9SsMxH3WuWxQvv9mc6OO7lSM6agSO+nugBs13gEB8Agpj+uBQUMxB8Cge QFECfQ6m EgZsVUbv6WAk/0kh3oxsGl4IiL08abJ5zMQO363BzblAjQJ3X3Gghn/Zf4AJYTHZudqjdxBDL6ka0ZO4gQv9aJkzqprqbDEDp0mlhO1pElKPoawkL6U29vZBLMuRnBKWYPInfZRxKotpJXyOJUvkOASU/ocSl3YrzB8sZ5le3xGqx9HZTaO/vfqnfDTnm+wSc8v+tRUBJ8I0EXYORIrHx7hH7kIEzoqbUwgEqBJYDDAJ3N7bJ5taR8gwIRO+sUgwL/wFl0EKkuArZC6eZMhGJv7LXVA== 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 28942701e301..60a37a9eb15e 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1174,7 +1174,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) @@ -1382,13 +1382,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) { @@ -1432,7 +1434,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; @@ -2229,7 +2231,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 e704f56577f3..03d69321312d 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 Jan 24 23:54: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: 13950037 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 98E5FC0218B for ; Fri, 24 Jan 2025 23:56:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 720E72800BD; Fri, 24 Jan 2025 18:56:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A0962800B0; Fri, 24 Jan 2025 18:56:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47E202800BD; Fri, 24 Jan 2025 18:56:15 -0500 (EST) 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 296052800B0 for ; Fri, 24 Jan 2025 18:56:15 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D63C8A1679 for ; Fri, 24 Jan 2025 23:56:14 +0000 (UTC) X-FDA: 83044006668.21.D4D1D26 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf25.hostedemail.com (Postfix) with ESMTP id B566BA0010 for ; Fri, 24 Jan 2025 23:56:12 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="a2Fn/my0"; 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; 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=1737762973; 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=fcIGcV/98l8ZSjQDmXrF3affeH5gAuXvROyoFcfZEuw=; b=uZ5anrQ+xneXc2ajUWZ8FoydgdOAcMXxi7h69wytk8Ao/+I1ITvCXOjlsqerzrR/wnEwUg yjYTHWT7FjhhPu/a48exIQqWepFxGshOOhAnu5WClBBv4nvJALkxAuM7CwsOx236sh5o9W USgr3A77IMA3w1Ey8fx/WEob7EkD7WM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="a2Fn/my0"; 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; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762973; a=rsa-sha256; cv=none; b=kQdjrloNcCoqER2BTMxbtMkfKuXJkH6i/dt23EZ5qs9ojsOgsKUOzyHIfCYhBULkt/Tio+ 8OUcTpDjNfS+8RkQAVHT80Y3uMAzGumz3CeQSYkhQPlV+Goyr0S9fQJVuPwdAxq0+Xgh0F JbNDZ9pe81BWXlLixsSjZiZ6VV15eGw= 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 50OIi39S019133; Fri, 24 Jan 2025 23:56:00 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=fcIGc V/98l8ZSjQDmXrF3affeH5gAuXvROyoFcfZEuw=; b=a2Fn/my0YFitA1HTu3rMs vVjepHWSc4mtb1D4lZwU2+HUiFmyAfRG+b2J9B7sTQIhkhHv+5so55NFpuw+9QB6 5IlnBjtBB1nScTizxp8+HvWpPPlV8Xk7iu5bC2OppEWguINRcXS8x0rTEEduQ8zY 6DphIs0lyq7VA2SY/CjUxmOmQR2yda66f9hy9vTq5C4r9eoCY48aAV/BQhk/YKEf gXDR570rmgzu1e/LVmfqRVSIMF9lquv00jDKnJAiVDdsXsi3N1RZMtOdsZjGiBDt gYZ8Dcz/6PLRmaL0lP7CNShlYBppS11nC8cJec/kCQ23yo/t+0IRNU8t1fN4NuzE w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4485qaw408-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:00 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMD09b036431; Fri, 24 Jan 2025 23:55:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4ama-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:55:59 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQE018051; Fri, 24 Jan 2025 23:55:58 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-17; Fri, 24 Jan 2025 23:55:58 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 16/20] mshare: add MSHAREFS_CREATE_MAPPING Date: Fri, 24 Jan 2025 15:54:50 -0800 Message-ID: <20250124235454.84587-17-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-GUID: 5QNgZKQltQ9yn3rK-ZEnWzGSYsobWy1O X-Proofpoint-ORIG-GUID: 5QNgZKQltQ9yn3rK-ZEnWzGSYsobWy1O X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B566BA0010 X-Stat-Signature: mrg9hfj8tfo39m4pkbfmt8oz4m7cg7qs X-HE-Tag: 1737762972-488842 X-HE-Meta: U2FsdGVkX1/LcRtF7fpI1sfPLeGbkUSp4xhzCnftZOYe3GxZo0NtpJ/Ph+o0QsuiSnfhI2qzI2HrAoQ8BhdH6Y/f0AtbtoJIklxjax5xFTFOB2JpNDIShVRkcwQIRFvJB0eAX91iicDkltin4lr2SdTgLCJ5tIZt80cYzeMfFCect7RiOgxpjuF3FMv0x4L6HYcje1kM5KemchG25xaE8xevUKITdbK00MJWPfU32pZU7X9ICmftDyvw6ctF3u8/1xvZ23h9Sp0CoWZqpy1aRjt1DqkiXiCQ2EGeaPbtkHTBe6UdwjY0c9o5tJ4lYtLeX79vTM73l6vSUpHUMt+p/VnIUV+wzzGoAGUfFq4+stC4whus/EylKgTFJB6FF4N8JtPOWFgYJLKOUScqCvk1Q22zrRxrIPSnFkc5dTw/1qz03Dq8Xa+KvM5Ad+rMRdbANqBvCHfzuI8qrxsbl9Gzrts70oJcj96GcgQvaYhbcxhr+3LjUmOeitUhLQcGs7SLtMw1rWzuQgcqAl37RtZ48BgmwsE84B5Xn2IYBZ9l9DGnXX+BKIC2BrbPTSB/ZiLVpQYH6HOxWvR7WGJQoadQjdOpic43sZPOEvPsEK5hzd+6w0uJWNSpicTf30kSOrmeMpdwsKVp+tAjmQJKul1b7HalAp+clVrFfP6L5Fd2W3v9BOnW2x4Aid3Mv0vvJrCb0hG90yOGBXGWMT43BPnufyh8x47TAOqRxb0hOhQIT3GK/KnCAS0N7J4/8NLvhla7jCYH5aARUrZixOGy2FvYRdDbsNjPB/fpq0RkRbiRTZsYiVcCY+yy55F9vcxGyLcKyVOku2UWvi+rJxr5HlYlM0N9TA/hjtmczHKzSEgmaNWuLVLRp16pMRrRqHc2Guw8SzoHsWWescvisAVll5O0TKkdAXgjLlTVd7ruu6oMGON/mAKBKCzUwO2UftmUKSfvnui75dAmCvn8u3sMTfJ YtvMnue2 af+l5UXKTePVN3oBOMiUy2iLh+XMTNqqp2d1N55Kx9wwcSQGFsDcr3YH6DWeaNVE/ygPV6S0qf9Y//1ZvKDAul/zHqe8M4sYqXZZA6b+XZcytXhW/BJS87ImCHEcYKnNT6xMsLrpferq/ABmRVJudqF2B0QN7PlR5i2Brp9F4QtLXV5u11cyO+wiQYGibrdRLtTH9/aONQeFFqmoPyh+BGSM4tHT+E3ZZLZ1XygIQx2lzXRHUwW9YgdcL5LVsthuTTHU9pvE8+GN73UrAoERCleDKkw== 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 an ioctl for mapping objects within an mshare region. The arguments are the same as mmap(). Only shared anonymous memory mapped with MAP_FIXED is supported initially. Signed-off-by: Anthony Yznaga --- include/uapi/linux/msharefs.h | 9 +++++ mm/mshare.c | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/include/uapi/linux/msharefs.h b/include/uapi/linux/msharefs.h index c7b509c7e093..fea0afdf000d 100644 --- a/include/uapi/linux/msharefs.h +++ b/include/uapi/linux/msharefs.h @@ -20,10 +20,19 @@ */ #define MSHAREFS_GET_SIZE _IOR('x', 0, struct mshare_info) #define MSHAREFS_SET_SIZE _IOW('x', 1, struct mshare_info) +#define MSHAREFS_CREATE_MAPPING _IOW('x', 2, struct mshare_create) struct mshare_info { __u64 start; __u64 size; }; +struct mshare_create { + __u64 addr; + __u64 size; + __u64 offset; + __u32 prot; + __u32 flags; + __u32 fd; +}; #endif diff --git a/mm/mshare.c b/mm/mshare.c index 9ada1544aeb1..d70f10210b46 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -194,12 +194,60 @@ msharefs_set_size(struct mm_struct *host_mm, struct mshare_data *m_data, return 0; } +static long +msharefs_create_mapping(struct mm_struct *host_mm, struct mshare_data *m_data, + struct mshare_create *mcreate) +{ + unsigned long mshare_start, mshare_end; + unsigned long mapped_addr; + unsigned long populate = 0; + unsigned long addr = mcreate->addr; + unsigned long size = mcreate->size; + unsigned int fd = mcreate->fd; + int prot = mcreate->prot; + int flags = mcreate->flags; + vm_flags_t vm_flags; + int err = -EINVAL; + + mshare_start = m_data->minfo.start; + mshare_end = mshare_start + m_data->minfo.size; + + 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)) { + err = -EINTR; + goto out; + } + + err = 0; + mapped_addr = __do_mmap(NULL, addr, size, prot, flags, vm_flags, + 0, &populate, NULL, host_mm); + + if (IS_ERR_VALUE(mapped_addr)) + err = (long)mapped_addr; + + mmap_write_unlock(host_mm); +out: + return err; +} + static long msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct mshare_data *m_data = filp->private_data; struct mm_struct *host_mm = m_data->mm; struct mshare_info minfo; + struct mshare_create mcreate; switch (cmd) { case MSHAREFS_GET_SIZE: @@ -228,6 +276,23 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return msharefs_set_size(host_mm, m_data, &minfo); + case MSHAREFS_CREATE_MAPPING: + if (copy_from_user(&mcreate, (struct mshare_create __user *)arg, + sizeof(mcreate))) + return -EFAULT; + + /* + * validate mshare region + */ + spin_lock(&m_data->m_lock); + if (m_data->minfo.size == 0) { + spin_unlock(&m_data->m_lock); + return -EINVAL; + } + spin_unlock(&m_data->m_lock); + + return msharefs_create_mapping(host_mm, m_data, &mcreate); + default: return -ENOTTY; } From patchwork Fri Jan 24 23:54: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: 13950038 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 20C58C02181 for ; Fri, 24 Jan 2025 23:56:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 172F62800BE; Fri, 24 Jan 2025 18:56:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1237D2800B0; Fri, 24 Jan 2025 18:56:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDE532800BE; Fri, 24 Jan 2025 18:56:17 -0500 (EST) 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 C4B372800B0 for ; Fri, 24 Jan 2025 18:56:17 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7F7D5C1532 for ; Fri, 24 Jan 2025 23:56:17 +0000 (UTC) X-FDA: 83044006794.19.8FD615F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf17.hostedemail.com (Postfix) with ESMTP id 538EC4000D for ; Fri, 24 Jan 2025 23:56:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HreZ+IIN; spf=pass (imf17.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=1737762975; 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=X0po0sWopN9sdAxoG7FE/M7ahK8VIPD0eThxsGOy3dw=; b=tY/LF3798Ta2WQYcVbXgv4YTm8AAReS9HZQ5hel6rIoidPn07/PxKJuQkIEWDnFPFVfgfc juwxTm9BZ6uzE+sMcMw1+i3hHB/QIxjv5l5f9TmBZsOQLIjn2Vv4kJhHnNdA9c3zWDyGSH zNxV0P6o8i6ZyXClSVrV4mku5GWC1bA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737762975; a=rsa-sha256; cv=none; b=V3yCCqyMydQTN/ey0YASNnKaaOZTN3Dc7g42bEzCrnxIwYMUs8rO5aV3rgAbK8TR86FFpA kdvHrcMdivj6Rec06/hZKcR+gjG/G2RkxUeKIjpoMGWk3tf15AliBuoBEBN5EoTyWplVJQ UCiW+J2l1lgoGPajME35ccAWqIKjWQw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HreZ+IIN; spf=pass (imf17.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 50OIBX66001521; Fri, 24 Jan 2025 23:56:03 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=X0po0 sWopN9sdAxoG7FE/M7ahK8VIPD0eThxsGOy3dw=; b=HreZ+IINxUUt+Ox8BrN6k 6Z+qo+dQKjtgOpUCTcmokqyKC8EDmnBK2Cf+RCng15P/GkxFg0YXJdOy4fwxNpBY Dg33t34z09UTLSboAUdg1aUmGbgXxjuHDSoaCEy3SrV/28oxHKjTvHW3OIS8Zx5D DGKtvBeW6Ae3gzmirx1E1l76v6cYlLcpkQyY2Q9SyYL+msDRSVRrRQaHj9J2imvK 5KRtFLNDEJ2pS4aQtFeUrnedt0uyCLN7NtseR0U2zF2H23db2kvhKkEO7XVws/uZ ATY/rdXNTX7N0L3xJlOQh/jjZUdGVZNw2s8m51crRzx6N9pzGPxZCreQtHBzT8EX Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b06j5j48-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:03 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMMu6P036606; Fri, 24 Jan 2025 23:56:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4an8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:02 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQG018051; Fri, 24 Jan 2025 23:56:01 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-18; Fri, 24 Jan 2025 23:56:01 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 17/20] mshare: add MSHAREFS_UNMAP Date: Fri, 24 Jan 2025 15:54:51 -0800 Message-ID: <20250124235454.84587-18-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=914 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: rYZnMe-DfE5Cl4XSqOR0IwdWDQ6875RN X-Proofpoint-GUID: rYZnMe-DfE5Cl4XSqOR0IwdWDQ6875RN X-Rspamd-Queue-Id: 538EC4000D X-Stat-Signature: u3o8xarbzie6iz4rsri1y1pt6moktbiw X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1737762975-271152 X-HE-Meta: U2FsdGVkX18dn/NCDUpbPfxl1myX8Zy6gImYcMDZVf3FR0nLsMf0NA0LPX4jka2bpfUPst8QT3uXsT6cAyNBcP6IhL+HXRFtalp0Jn8SVKbztPnTzh18cVtXAlQvwpXHg0JXKsOhEUd9FtbN/MSoTcIPs5khE+zFaMtfeNlQEtMBUKTIwwsne/zlaLytkkSenke1uixm0TWHJGVoZDV0pejY77AMVEhFRuBDZR5KItm1xc1QlxJH2Qg+Zdko9MV/qkYJNiapUEOgaXB31t5bMdSYN+6Lg98rg5qDNk1zPcSOSXEbR3Ji79L0XUYIIAY9lSYov8qiV1HMrtBEyRoOfqI1+E5horvntVFJkFYYnsErenoNT7oLmNVD/Ux/N2Bx3yxKxP0UtzLnDOl2D8W50VcX+vSAGEjpceQ6jfv0XCJGkqqsBrOrfZDEVnjywYKXQiCR1PMT2L0sb8auMmy6k26rIweysw+7mPRvrJXiUdsYsl/kxdpKdJDhKZ8OcuvNeIZSodAJzIF6R3aFF1JLrYXJM8mnsIjwSMsp+VfCg82hcSV8ja+V3Ic1+w6pIByp/Y9cv5wom16Azj/CPbKlbKO9W/1KNhcEzp1uE3x7JqReNq1PPVZuBNmZXH2sOKVeOV0lOZ8/hUYYiTacdSx031HX3+lUjyLTmCsoLKQT4ETjlMxDAlEspxRkY0vH0S2RTzyZFSGlkDFRqIjBHqEGrcXOcRN23gbykN2aKlTmYxd7KB3OdCEFoyFQp2NG7HmLauUQYlYannxBVTzG+GcUZtteBdXqFZpfmQWnTxPwvqIcfKtFih+dJW73eVyWAYm2JKLWu3/hRg6T7r/OEAd5G6ScCL760cjw6uua5F/qEw8PyKe4g5d8TkewwYn8/MhCloy4p14qfCHrTL7VF/jc48samogXh/fs6I8ovvmWKJs3YoYK1Q0KP1Lr6mhGn1/ZW86TDB4H+O4H0iRN1Rq BHVgL1KN 5lcTDCPa34y8Aow/SHrjrOovekP40jYlYCHxZspcWglw6KqxzG8y1GTHafmqE6fqYhG86Ytp1V4kqE2H2GHdO98cbaKKyyMHl8bOEkJK+rNUkqmJebJiW1S9XQaxXPK4zWtmSC8h5whRQ8W9UPlVt7vY7+iuBFfdX1CLAjckRFAZpKVLeT6EV7/AbsQ1WR1JEjZ/wWwik5hm73jj9YR7cuNrUr1HsKD8qB//vE4uV2eHSkcn6sUox1rHKRx8zTGqBjgfYJdvZDAI5DUwsbKJ0OcZcqg== 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 an ioctl for unmapping objects in an mshare region. Signed-off-by: Anthony Yznaga --- include/uapi/linux/msharefs.h | 7 ++++++ mm/mshare.c | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/uapi/linux/msharefs.h b/include/uapi/linux/msharefs.h index fea0afdf000d..f7af1f2b5ee7 100644 --- a/include/uapi/linux/msharefs.h +++ b/include/uapi/linux/msharefs.h @@ -21,6 +21,7 @@ #define MSHAREFS_GET_SIZE _IOR('x', 0, struct mshare_info) #define MSHAREFS_SET_SIZE _IOW('x', 1, struct mshare_info) #define MSHAREFS_CREATE_MAPPING _IOW('x', 2, struct mshare_create) +#define MSHAREFS_UNMAP _IOW('x', 3, struct mshare_unmap) struct mshare_info { __u64 start; @@ -35,4 +36,10 @@ struct mshare_create { __u32 flags; __u32 fd; }; + +struct mshare_unmap { + __u64 addr; + __u64 size; +}; + #endif diff --git a/mm/mshare.c b/mm/mshare.c index d70f10210b46..8f53b8132895 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -241,6 +241,32 @@ msharefs_create_mapping(struct mm_struct *host_mm, struct mshare_data *m_data, return err; } +static long +msharefs_unmap(struct mm_struct *host_mm, struct mshare_data *m_data, + struct mshare_unmap *m_unmap) +{ + unsigned long mshare_start, mshare_end; + unsigned long addr = m_unmap->addr; + unsigned long size = m_unmap->size; + int err; + + mshare_start = m_data->minfo.start; + mshare_end = mshare_start + m_data->minfo.size; + + if ((addr < mshare_start) || (addr >= mshare_end) || + (addr + size > mshare_end)) + return -EINVAL; + + if (mmap_write_lock_killable(host_mm)) + return -EINTR; + + err = do_munmap(host_mm, addr, size, NULL); + + mmap_write_unlock(host_mm); + + return err; +} + static long msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { @@ -248,6 +274,7 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) struct mm_struct *host_mm = m_data->mm; struct mshare_info minfo; struct mshare_create mcreate; + struct mshare_unmap m_unmap; switch (cmd) { case MSHAREFS_GET_SIZE: @@ -293,6 +320,23 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return msharefs_create_mapping(host_mm, m_data, &mcreate); + case MSHAREFS_UNMAP: + if (copy_from_user(&m_unmap, (struct mshare_unmap __user *)arg, + sizeof(m_unmap))) + return -EFAULT; + + /* + * validate mshare region + */ + spin_lock(&m_data->m_lock); + if (m_data->minfo.size == 0) { + spin_unlock(&m_data->m_lock); + return -EINVAL; + } + spin_unlock(&m_data->m_lock); + + return msharefs_unmap(host_mm, m_data, &m_unmap); + default: return -ENOTTY; } From patchwork Fri Jan 24 23:54:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13950040 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 5E239C02181 for ; Fri, 24 Jan 2025 23:56:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCF292800C0; Fri, 24 Jan 2025 18:56:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D7DFD2800B0; Fri, 24 Jan 2025 18:56:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF7BE2800C0; Fri, 24 Jan 2025 18:56:42 -0500 (EST) 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 9CD262800B0 for ; Fri, 24 Jan 2025 18:56:42 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5D6F0C19CC for ; Fri, 24 Jan 2025 23:56:42 +0000 (UTC) X-FDA: 83044007844.12.98BF574 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf16.hostedemail.com (Postfix) with ESMTP id 3FF6D180009 for ; Fri, 24 Jan 2025 23:56:40 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=NBNz1vpN; spf=pass (imf16.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=1737763000; 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=8uftArRhojvCPMIRnGj1x1yBh7nth+rSToT9QfbKQbE=; b=IaaIVet9Ok213tVpEcOL6OSP2TVQPc/fyXSZF7y1waIOUuftTe0+ETulvLJmfgOQVlSiH2 cii5PHDBivmfB2WW0fiEiM81uJGmyPV3rXyqqNn9K999ZyK64qwQrfnQ1koS54KGaE2bHu OWzd9fB84X4iVVd3y13LKRlsnZigdRw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=NBNz1vpN; spf=pass (imf16.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=1737763000; a=rsa-sha256; cv=none; b=umXZjH9VCqnlM4yL+N8SeOKKiAszbTnOVyjULjIvVEjvm3bhusE3iVMXRPDrPk6htghSAs jrQ4EdZ2HcPfkQYA5+NhnNb4JAfZGVG0QGOmRXmB1E9zImRv/CEKtOqMezk/8JkqyviYWl TQYFiPF43l9Qjd97C42j4s10maNk4sY= 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 50OIXg65000799; Fri, 24 Jan 2025 23:56:07 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=8uftA rRhojvCPMIRnGj1x1yBh7nth+rSToT9QfbKQbE=; b=NBNz1vpNVG2DdlahpKAac mHO3DpyehCcOesPJsPnk36jiCZRFlXyz9Y8PTUI7Hnr4gFTFjbSxnZ8oKQoK/e3D YShuehhAQHh4kFuqiX6xE1Dt2E881mSqfHP3bmUwYsgQSJlS2PjaQJNVyT9/WOZS QqpVHaIbVebMBSuDVaH9otVoCtmhY/9pMaDlI/MuoyXFDkG/AksQjFluDgd4yr3H 8+3PIMBHFEW/B1nL1bh/H1xpLlGX5rDCDlAlZV6E6aC8MIJStkhyOxHe+pAt6ki5 1a1OSflAkFUO3oEeHVB/HBKm+9KteLBZVAsvfXVp3WGJZD8idzzQ1RJdlD0LU/Ak A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awyh5rkj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:07 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OLoFNH036500; Fri, 24 Jan 2025 23:56:06 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4ap1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:06 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQI018051; Fri, 24 Jan 2025 23:56:05 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-19; Fri, 24 Jan 2025 23:56:05 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 18/20] mm/mshare: provide a way to identify an mm as an mshare host mm Date: Fri, 24 Jan 2025 15:54:52 -0800 Message-ID: <20250124235454.84587-19-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=924 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: seWEfcu2KQdw5VizmqhNebvh3voJaHP1 X-Proofpoint-GUID: seWEfcu2KQdw5VizmqhNebvh3voJaHP1 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3FF6D180009 X-Stat-Signature: obnao6zwtozie5tq78g3taesjpai3qgd X-Rspam-User: X-HE-Tag: 1737763000-717328 X-HE-Meta: U2FsdGVkX1++XYQ9G6GFyonbJQEZp3r7JVJTruag0n1RMtVpviGe4mtHmt+pFtYBVikMEzLyOiMRPpURf5YfQepXCpZu8zmAfotqdRpuLQWO9pJ+g8LecOmyBP4Y2lLH9xBV1ts0IidxWkOgO6e5FVkmYnbbDQm77PX1GBYSAbh8ajn5W6gqnWjpYXoq5nGZ0aWcQ4KLiQnEk5+OKv/6oueyVFUbyOU3G12qiPAgqaolYM3e25oZ0c4EV3zi1kRr1SwfuDolNC1gV7cXIb297V94dnLS+WMQsPs1TBo1YMXxwJ2ip25DBvgeZXps2mv55RQV4hGDfmipSYw1Xh0fg4ap3lOLsQgEfXQjvrnPkFmTnZVHD96+Gy9GgQEhldf+joRsSCQznMCEbTyxK7Y0T6P/2Vt6wb6A+La/2McnY2NbZww+D0jU7QSzeIpFTemMq/lJZgPYrhUln41P327z+SdAyPwNXbS3JXNKuLL0YDoiqZ6s3sZTs6sQhT7XIqHsUW2DmA8Bllg9DjD/a9/Xv+5ebLbNXkE4mhaLyWhYxcVRnlyyeU/4aku/31aTl5Odfujbn+07Ij6hPhvwqI9eibouxCTPfhL/XN0pssvAkdcGzUl7Ss5uH3cy++8oLpeN7Qu6y8GnNlO0h/PFVz5usPlF6iqU+SsQ3mJJe9rDPLXKBEbVhnJoY60cdr50wPNvHxdGhYUrxmraXxGT7MiieQ0uOY/dBZcmTg+wszt+TaRNepNslj5C1hXQ3XSXsqw7PNa9pzJ3Kj/P1ny25160UrQH48Zk+PHTFpBmWMeLQ81iXjkEPV4SNwXJpfYtkGwI35F3+PHUwKAigDDEzER9ggCbRMSnRPVPo1M92td/L7az5mNh3F7EukeHwpqca1IPhg8fUc7TkEH6dH/ho+aHKaB5xLur5mf8j2KYAhZVqsi2l4E+Y1XDMQY86c7jEHrLnQ2O+XreAULnskCo8py cTRq4qzZ nEhYJO/n3GNZzUZOxSFUVbxjlajjtiuw+gvtJegeQjV3L8EMVsNNZ8beymdg7TDM8ohJFfK2Tsfayt2MI+rwyHhdmxFG/h9zIfPJyCGHvsYEvJsja1KQcu7XRlbu41IJ2b43GKH/IwLnUax2XxcP6lpcxaOMxIHvbJO4OLiFChsIi8LFuACJDJiYInXN4ofk/OXUvCrGgS4WqeSbc9FF9q9LLrz1v42EtwWapivwoXz0ReUIk0eNdARmULeWXv1RGi5tGnneV/hRhgY4= 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 5f1b2dc788e2..dfbeb50e4c9b 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1642,6 +1642,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 8f53b8132895..4c3f6c2410d6 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -365,6 +365,7 @@ msharefs_fill_mm(struct inode *inode) goto err_free; } + set_bit(MMF_MSHARE, &mm->flags); mm->mmap_base = mm->task_size = 0; m_data = kzalloc(sizeof(*m_data), GFP_KERNEL); From patchwork Fri Jan 24 23:54: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: 13950041 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 45153C02181 for ; Fri, 24 Jan 2025 23:57:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE72C2800C1; Fri, 24 Jan 2025 18:57:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6DD62800B0; Fri, 24 Jan 2025 18:57:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC0532800C1; Fri, 24 Jan 2025 18:57:48 -0500 (EST) 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 8739A2800B0 for ; Fri, 24 Jan 2025 18:57:48 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 36507B110F for ; Fri, 24 Jan 2025 23:57:48 +0000 (UTC) X-FDA: 83044010616.19.4D7A38F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf04.hostedemail.com (Postfix) with ESMTP id EE2D840008 for ; Fri, 24 Jan 2025 23:57:45 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=B3fjZHZb; spf=pass (imf04.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=1737763066; 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=SM5Ww7fWlIZajv0rUMSJsMcTKUFDtvzpjq2xibJD7zc=; b=bc9HTNjvcmEddqTBiiufg09HxvgdMYu9MQQz2IHnrlciBofMKtVbNgAs+N0WGC5BF/QCeC Je8PeUiZ2mhChYTULeWjp6nYWNiK7bvAX1QUA4NZvE1xqEJKngiFr0jhwqBwCGiB6rwseb w7rl6GDvBKz28PqiJan3rssSyArqoIQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737763066; a=rsa-sha256; cv=none; b=N9rB0ubYXIeQNcYA0uB2b5VkKhswpgOm/fdmUIdUa06gluL8aJAaO6nonXenW1JY+2yB8o XMahlGogTXEgDzKR0jp3gBPplyHuGQpVkTYR862DzgFjVIT1nXS2sWNq5dWYRbnQZVRRqz cLTqoIs9zi4O5C7LJnE9Q0zhHJ+fcCU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=B3fjZHZb; spf=pass (imf04.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50OIBhnG000613; Fri, 24 Jan 2025 23:56: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=SM5Ww 7fWlIZajv0rUMSJsMcTKUFDtvzpjq2xibJD7zc=; b=B3fjZHZbj/1OatG3T8blh RsVs7af8iubXIbp5pCA/LmBolWeub9ZWDjgfFw/eUeRi9kdXt4spr34dzUUkjVYH 8YFGdxJ4Z5/RpbERJYmTWBrzS9ds8FNE2A0kyKEfgzObXPdQl7S+wid3oS7YndzN RZR9201pZ9PZfSijDDQmyNa/mBgI2y7nL9PF9mqYFcwu3MYFtqG6NtUY/EBfUsRO 9kYqDw1UwZamvlgb0Lzhzui1+zNUkKTJbSnBNmyZJxKmd7jmxIsBEVT1go/vz6CP ybAZTHMbWjqjXO8Y8QBEbLr+RzKlZtiw3vGENMpoLhyb+Mkvr3LTEbk1ar79lSPf Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44awyh5rkm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:10 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMPchS036590; Fri, 24 Jan 2025 23:56:09 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4aq7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:09 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQK018051; Fri, 24 Jan 2025 23:56:08 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-20; Fri, 24 Jan 2025 23:56:08 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 19/20] mm/mshare: get memcg from current->mm instead of mshare mm Date: Fri, 24 Jan 2025 15:54:53 -0800 Message-ID: <20250124235454.84587-20-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=912 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: mhtNEYRHB3aSsRiiq5ZgkAR2eaM2NkII X-Proofpoint-GUID: mhtNEYRHB3aSsRiiq5ZgkAR2eaM2NkII X-Rspamd-Queue-Id: EE2D840008 X-Stat-Signature: gia46f4mhrii3ta6k8ajyp153rt6gkk7 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1737763065-644189 X-HE-Meta: U2FsdGVkX19mTuZTvXoU4YuSNmbgg4F5my1YBWU8CRWDiXajTSWcJ7jgxTMYQSHj7pXVqbSeFI9fiuzoiRjikcAUiFYvYKYXeIARSmvGouyUs4tJXE3NGVpxl8AM5G3FZT0rihuITkIZczWl2CfXnLXw43eesX7+iAkdPTKh7m7+kl8+cu9h8AFfTles2kJ97Sr2s/Y0BJdoiATCqhEGkAxJJLHlRXRzg1PD6OgX1WHLIIvCmDMsV/CrW8W8ru1vY8UaNuNXn19xp5UnsK8NDxA9LYduUhaVSFKKv02Q4wGAlroZ2vhUQz85PmIY97q4SJw3jKLcMFaEekPAGggCZz9aMGO9SotHcJe5pnQv1cv9UIWpdWywErPa6c/pGjcJ/+6KuqAb93XEs5J3FmS6wYUt6jkfK4Pmtn0kkmMWj7mcun+/lV/eAC86Xmokw6SWsT/Vhwmu4jocPBFIdtVCnQw+bCSd0ZEpQWWzYbD/r23hcaWV1W5YvS6m/2iBtR2LKl/vW8lq8QzH24pYxPhVtlXQctHgxMEM3muzPN/T1mWuYZHw/6bzWKZ5DoYlLONOITxg8B1MdnYyPoquH/vjpYROSLiFeB8ru3NydL2i2uKSqWaJgd2RAWSnFLhCk/fxDJPm6KSjsd3iKua+LTtjit4OMLJWKVxOQp1hIM6n2PkcvfIIeeqRiO3Hnm2+IUdPL0nEfel4qJCOBIy73GFUC0vwBqXeg4ZrVp5LB1kjdXPCiKQDp8WHGNhDGrSDNO31EHlH76yd8zsXmmWIYcx6dKcV1a5SoEJWzCXvqqI848fMDJA1eIkydpRLqhJnhg5/tjTuIYVum83VIfkIuSQIdhwsVKJ4852M4TybGTHqY5r6DZwpaLZtELqp5OZENwA3aVAV/9ZeAhh4HZByx762Gck4rwLzOfeAW7OlbtIgL/O+9cPzKWzzEJDO8b2WBCbUpiXq3jCrrcMhgDWpEsj PzZp5VLh v77jdetfz32rZABY4Z28bZ2gyBbS1bI29mKfV1uKW1nel+tL1vh7RXIyjA7n323KvSTsMmyvciZsctDohHWuIo8yNS1l5UOHVgjb4csP1uWImWtFzhHR1AlaXNDJMdSpnMqCInPXVK+tTwL/15dSDca2JYzeezA7tqpv797kk53m8a6luMuKBfev48Zs+2xddnWaX2oBFFOnhY45wNTxb6oJY5YPTGOnBsSm4mMzZmcEB9cU= 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 6e74b8254d9b..e458ca80e833 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -987,6 +987,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 46f8b372d212..ba6267615ee6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -938,7 +938,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 4c3f6c2410d6..5cc416cfd78c 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -381,6 +381,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 Jan 24 23:54: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: 13950039 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 A244CC02181 for ; Fri, 24 Jan 2025 23:56:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F9B02800BF; Fri, 24 Jan 2025 18:56:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A8612800B0; Fri, 24 Jan 2025 18:56:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 148D22800BF; Fri, 24 Jan 2025 18:56:29 -0500 (EST) 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 E189A2800B0 for ; Fri, 24 Jan 2025 18:56:28 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9C300A1679 for ; Fri, 24 Jan 2025 23:56:28 +0000 (UTC) X-FDA: 83044007256.05.30DA842 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf03.hostedemail.com (Postfix) with ESMTP id 761B62000B for ; Fri, 24 Jan 2025 23:56:26 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=TKAFsMxw; spf=pass (imf03.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=1737762986; 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=W/gkk8s5Xxm+HTDJna5mPHZqxpMgtw4DEDxvy6ObgxU=; b=qLx9YPkUXVl5SrU4wCUKlQVrd+cDc7qLY8wxjYe+wP0PziDlV9F44xOPbAKyzFD4kjKj2J SE2wYRI0+iAC5tzpi+l7v3w4Dd/Bo3oLOHt1hGGUy0HhTVfwPSjqik4AOIBFH98YRs5qgj Kea9ATj53wWbPxXlYP2+lb5LXqtfQuM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=TKAFsMxw; spf=pass (imf03.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=1737762986; a=rsa-sha256; cv=none; b=3rmVEvxFdH7o5FOn8ADJdvkUWlqmstqlYESHxaglbdSZZ5fYIgpK3Il7DvKlj05aV3XmoE DIH3vDj45305JdsZi8kc13CZao5v6W2SrRn58bcZiUaVHQ9l/Hu/m/pdG4C6+PV61YJZ98 B8TDXK2dqivbpJCB9tDVx5mOy+vXII8= 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 50OIDTDv002066; Fri, 24 Jan 2025 23:56:14 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=W/gkk 8s5Xxm+HTDJna5mPHZqxpMgtw4DEDxvy6ObgxU=; b=TKAFsMxw1dXtdtOqEkfGV AVdqkRY2RaTdu3ZmNNPD24QQMG/BLy7lFLPKQesBM2vgbBHmiE9tOyS6uYXZD9a8 igkuBfXhy7Q+VQB0Bm8CIozCZ7QQEBlmnDjvf+UaytMwnp0OMnxpxlBDMaVKYQmq P9D0laJVFb14OHi14s8rtz/KnzjNr/Fh6nc8gkVLCGAATk+D/arv9PRIvMfr7kHG 6/lLtbfBmh/jzKaJR+mgTQutGpbydQuuNkiX+EmfQy6FHGubtdh8EJOxsuwy9JOT yAsDLorshtbQQvpBZtJ7Z37vUlSH8xD+TAbBo5nI9nKMmO7mYH7lUg8XO5iRsEmU A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b06j5j4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:13 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50OMEEls036463; Fri, 24 Jan 2025 23:56:13 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44917u4aqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2025 23:56:13 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 50ONsxQM018051; Fri, 24 Jan 2025 23:56:12 GMT Received: from localhost.us.oracle.com (dhcp-10-65-130-174.vpn.oracle.com [10.65.130.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 44917u49ww-21; Fri, 24 Jan 2025 23:56:11 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, jthoughton@google.com, corbet@lwn.net, dave.hansen@intel.com, kirill@shutemov.name, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, mingo@redhat.com, peterz@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, tglx@linutronix.de, cgroups@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH 20/20] mm/mshare: associate a mem cgroup with an mshare file Date: Fri, 24 Jan 2025 15:54:54 -0800 Message-ID: <20250124235454.84587-21-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250124235454.84587-1-anthony.yznaga@oracle.com> References: <20250124235454.84587-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-24_10,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501240162 X-Proofpoint-ORIG-GUID: Z6OzEU8bsVr0C8NMG9E5ROuvsfbs4fjT X-Proofpoint-GUID: Z6OzEU8bsVr0C8NMG9E5ROuvsfbs4fjT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 761B62000B X-Stat-Signature: rkn75yrc3yhzp9x4rf7d44dpbak5w6cg X-Rspam-User: X-HE-Tag: 1737762986-446462 X-HE-Meta: U2FsdGVkX189I/RjQqYNLJQljAvoC2Zh0+Gz61Z0JiChylGRR9PtadMeJiVoiGT1Ht8x5l1q17+SpwnCnJoWM0AVrk2r/YAHb3ZtPkI3Q5ybRoCdQ0AOVrPA/MKSnbnRBj14eH5gm2gY9uBA76DzUqj6NGqZlsYorr/zCko32Payie1CksN0tJLkIq/nmsozBl9UcE+08tphjcJJ+RsvFWWfHmMRdoncD98FBPT4WftALwBcItaX9TF7CoEwncjmlCDK7imTAO6bZOOwAViXgaOqJhUtvmogC0qzVCrSKRnvnDFoDJBBXHdwvGA0FrqnOt4nXVZjvhOlnwT6h2DnTyXNKDJD+MJExzCGOIUHwt0lpfPPLzF0RAHnVi9iKfnG0zh95l2i9qSHC4tbsN2IrJJfBo/mIumFdRXEgqBaHGtyrJ/NjkurG1xYsqHJbVvUdAeK6WnQDBA6pq9E88azBuaTj48msxbCCjWFfsJzslrDHpYotoeF6eCJc/JyJXVJ86tgiOdJGy6vSICM7dXWHQV8KQgv4BPTXOPiOceR+9WuhsH4yJEnRGI//l8s6kb19Xff5TTUXpYTB07quo3U18UFrcyuVCqdOQqZSbMGtmLJMJY2dcT8IAwotWgkoxzKmP8FVcDov7xpTjV5vEAQ2Vf6LXLArexIo6CEU8GdtiI+PGsIDZA3OAwSeH2fRl1YvJIv5PRdh3J7XbvZHy44uMfvzeRi3de7pE+IOFTmthdUC6nkodmZmBhaTRXHu5SbhxnP12l123TUhKGgCIGIheLRbw2JVEoJR/I5mOzJ459rObmNjczJ/MfQRQHJWSEVjAMjqqD+IStgHPOQ/vydQhT5Lcl93vJhk1SgWwK+edGXfnL9AYVphMLDSsTD+QPuPsfxg2ATPUUa641mOsiWwgKGU48Y151l87JJmNis0fRSdT45UFsup2e9pvGjPNoGvyGXAe1Nuqlf6BJRlhQ 2n/UZWvR kuQHJsPgBINk/4jGUxr+ZkNm8dNWBomA7VuML3HgC0f7gN0Trtul95u+7a82v6+gnWiCMB2ooMFBJemKQaip/sY75KNF7W8zPTsNIQaj030q4h7hyRAwShIAVtjkZ1b4YXF+6IdxwrCaAzOWHoy4FTXosGBGQ4EA1w5MTdgVbP5myW4PWzn85Vg8mt8zFWfapdAeGi0y77KOHhXFx4tHG0648f7Q22ZVkOTdF81qlZBtCdg8= 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 4b55ade61a01..1b50417f68ad 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -21,6 +21,7 @@ #include #include /* find_and_lock_vma() */ #include +#include #include /* boot_cpu_has, ... */ #include /* dotraplinkage, ... */ @@ -1219,6 +1220,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; @@ -1375,6 +1378,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) { @@ -1402,6 +1407,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 @@ -1417,6 +1425,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 80429d1a6ae4..eaa304d22a9d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1110,12 +1110,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 5cc416cfd78c..a56e56c90aaa 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -30,8 +31,22 @@ struct mshare_data { spinlock_t m_lock; struct mshare_info minfo; 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) { @@ -358,6 +373,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) { @@ -383,6 +401,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; @@ -396,6 +425,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); }