From patchwork Tue Sep 3 23:22:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789495 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 665ABCD37B1 for ; Tue, 3 Sep 2024 23:23:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3A308D01EF; Tue, 3 Sep 2024 19:23:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE8398D01E4; Tue, 3 Sep 2024 19:23:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BED648D01EF; Tue, 3 Sep 2024 19:23:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9EA708D01E4 for ; Tue, 3 Sep 2024 19:23:35 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 58241A9040 for ; Tue, 3 Sep 2024 23:23:35 +0000 (UTC) X-FDA: 82525005990.27.524EF03 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf29.hostedemail.com (Postfix) with ESMTP id 3F16B12000A for ; Tue, 3 Sep 2024 23:23:33 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=UBaIiA4Z; spf=pass (imf29.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=1725405687; 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=D4FeNiFjoW7280RGlNaW295fu5x23k8wulvm/byXbLI=; b=1jIZL0VdVVTE7hFTkewCzn5Xh07AmcJmiazOsWky/7q9JWImjNc6V5Hhv79wBzefqo29b1 C8DwP+zi8NGbpBacueyfani1dciT9gCgG0hGrNVCQIBeGspx9Ron6RKDU7qQWRC0lJnw7w U6NZUGFPuTDP6b7CDc0kb6MOwFo0aWQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=UBaIiA4Z; spf=pass (imf29.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=1725405687; a=rsa-sha256; cv=none; b=hvmuDZR2HOez4TB5skQNy3kSNpcBD1w9BEUGzUz3JgBSfxuendEOR4ATTGUqLyrW4kyF5f uwKZwrpHH/BmuOFtxXnSmL2DPBnNiY/Q//liOQs4+vourpbPMA2o1gXim0UYBusYrACkAA C2lpVTKLCrBzDCvVEQl+vQxtdLyDXYM= 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 483LBjOJ023355; Tue, 3 Sep 2024 23:23:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=D 4FeNiFjoW7280RGlNaW295fu5x23k8wulvm/byXbLI=; b=UBaIiA4ZeuUrN9Zzm ITOCcX3GYzkJGDkAIXVty2hKiZT1pRHW7dJmm4nXq6fwFaJ61HioM+feWiWSj9Mp uv+F37VLQW5mT/1rMmf+mKwfO6x7+Dn4OpxBJBEHgeqIXtbcAwZW/rRWeHBntNaf l8Sbkxigh8ILYyEzZsQGYQWJHNKVadTewbpiHHMgu172T4qNxObVNkEtk1kyBdE9 H33PtNZFqRYbRliM/J+RwnyTcNJODKDoQv1BXMJYseilKi13IjG1NVwvpj3+fW7f PpX+VqAL5egKerN7nZwIqgEYbhhCbHr9fMalceQp2IlhJl//2xDZwcup8P71Ov7b vBZZA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dr0jtfte-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:18 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483M7tw3001738; Tue, 3 Sep 2024 23:23:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmn7q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:17 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkf8040456; Tue, 3 Sep 2024 23:23:16 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-2; Tue, 03 Sep 2024 23:23:15 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 01/10] mm: Add msharefs filesystem Date: Tue, 3 Sep 2024 16:22:32 -0700 Message-ID: <20240903232241.43995-2-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=876 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-GUID: AbPuJa1pBRboO3bqigacEes6kB0erZoG X-Proofpoint-ORIG-GUID: AbPuJa1pBRboO3bqigacEes6kB0erZoG X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3F16B12000A X-Stat-Signature: oyeb89i7ksn9arr54bf13wmqnti85xkr X-Rspam-User: X-HE-Tag: 1725405813-659108 X-HE-Meta: U2FsdGVkX1+fSXezYE+sX/zekcvSENV+RMeE1RyfcFo9NNCVVoQ6WrGKm3LVMoUYekSXLXCGXYAZqeWWWvVDETMJtNUxUH34XWKhiBoedF5d7tOmEf2IWOmtGUUNwJD542Yy2kHXeaqNgzme8RdSNha15C1XUffGDpg+/pPIB6Jdqf6cMFk/z2laXl0KUACYXatSC+5D2TdJegc9qevjP2bDSttO5SQXi6EFsGVDVVjGFeiZpU2U5Ue1UT9Gb7CZ0w0RitflOijI8gdQwSb6VueE72ZNHkLHnoI40yN5QmWlpnWf66cYA6D8RW0pe0tss7CFP/bDH6BnxsfPgHalWW+X4MZy9mw3PQ2FfZ1ipQCAzz7zwtWK+/5Xw0e0G1ZzveZ6IIeDl4E+ZrwsuOPaGmbcU39lX+eynhfBfiD00EjZFtoTQyW+tN5am/b7CyOwrr10KeQmITmu5F0q7Vk+ERTHBrtXlTufCkgMgmUuNKUnbzbIUqvfdPgoTyBkFcu121sJ5gUep9b8P4E3QhlceRl0AYi2UXwYYnJd7MKjzKvTfSkdpsSgphAi9cqc17d1v2+pHQyFOzBmGDH0SJiDhEu0F0/vGG/Kj+HDnS+iS51nw7esYnZRFN6u+JW51mNA/ma4n/v1dFP2dTip1Y34vt4xy0/tkODu2/aJxaja+fKxF2tii93IaZz6aUT86xGORqMbZFnswesZ5z9Ceg7fW5kcUxDkBYuXG6utHxBwXiutkf8Rqozi0iPWA2pi81DBdLXU1II9ypDdFf0+5j2NcNRpXyxw+famyDUSGREAV2sglZ1nYn0s1j8LtFxFgoYbqPc0GtaiUJpkSPUN7XR/gt90dk8CPmEfEPpRbrCKwlLsxp5Tg8bsr4yvETtZ6RwyAPklM230SBeJEMZxyy8K0aGhArvcZ4x1cM1UMEMWOYSSMhVyLjE7Gg2aaxRZp5zhCxNmoZptDXRVCjcDjiI grFRSW8r k5fjGtuCAgtN3935NVyuWJ9kD3x49O60CjGRFYw/TypsYbAv4CUedSWeNf1w1t8BdAtn/V2Q53x9CbtIyezKmIIsrx2TqQAK/OK/ckPe9Hr/VV7DLg9+T1DEAhZqzjdNv5Ec5ht9aBC5IMHpmjz2DP1lSNFCXIcmnsi4wkNPaEPwl7OT4W2aLk2m2Eu4mpYQ03+EMrJ4lJKUnqiLQUnYwOPj4T1P58Yolrw7ZhkZdeVfGlksftwh0hsy0b/XA2gVTBOBrTYmMgGXlOX4mgY+V4xUBVTIduNOjEOugNdTxxTIj15I= 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. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- Documentation/filesystems/msharefs.rst | 107 +++++++++++++++++++++++++ include/uapi/linux/magic.h | 1 + mm/Makefile | 2 +- mm/mshare.c | 97 ++++++++++++++++++++++ 4 files changed, 206 insertions(+), 1 deletion(-) 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..727cda663b0b --- /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. + +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/Makefile b/mm/Makefile index d2915f8c9dc0..956137de9e1f 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -45,7 +45,7 @@ mmu-$(CONFIG_MMU) += process_vm_access.o endif ifdef CONFIG_64BIT -mmu-$(CONFIG_MMU) += mseal.o +mmu-$(CONFIG_MMU) += mseal.o mshare.o endif obj-y := filemap.o mempool.o oom_kill.o fadvise.o \ diff --git a/mm/mshare.c b/mm/mshare.c new file mode 100644 index 000000000000..d5d8e2530e5a --- /dev/null +++ b/mm/mshare.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Enable cooperating processes to share page table between + * them to reduce the extra memory consumed by multiple copies + * of page tables. + * + * This code adds an in-memory filesystem - msharefs. + * msharefs is used to manage page table sharing + * + * + * Copyright (C) 2024 Oracle Corp. All rights reserved. + * Author: Khalid Aziz + * + */ + +#include +#include +#include + +static const struct file_operations msharefs_file_operations = { + .open = simple_open, + .llseek = no_llseek, +}; + +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 Tue Sep 3 23:22:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789496 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 889C2CD37B5 for ; Tue, 3 Sep 2024 23:23:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 119498D01F0; Tue, 3 Sep 2024 19:23:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C97E8D01E4; Tue, 3 Sep 2024 19:23:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E83FE8D01F0; Tue, 3 Sep 2024 19:23:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C866F8D01E4 for ; Tue, 3 Sep 2024 19:23:37 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7C3101C441F for ; Tue, 3 Sep 2024 23:23:37 +0000 (UTC) X-FDA: 82525006074.17.934054B Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf21.hostedemail.com (Postfix) with ESMTP id 8D9CD1C0007 for ; Tue, 3 Sep 2024 23:23:35 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=O5D6NE1h; 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=1725405720; 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=+NwCsMY5ut7geDTvEdbHpELHUG2vwXaB0hfwIYvPX5k=; b=VdztY0hdWfqrVIKuqi+8B92UHvRiiCC04NaSi4CGIy1PnMIQqBTsHIV9F4OiHx1MXTizE5 7MOdFYpVZGtoL/WAqD+StTeLWxzNrvk3U0YMXEIiFl5rqqhdUU+F4+vnTnLarKf9yvwZ+d 8THjKFeDVTN0/s5LK00xvvcCfC11s+I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405720; a=rsa-sha256; cv=none; b=p54IiLEFw1NZllz7d5qxI2oYKPk4IHB09gab2j6GRqc2G+pvmOVMMpW+OmFsE4crzHsYOM aMor7n70Rw5k0ngpfc1RNFtnbTrYUPXXdDHSL46b3NhgO0SkG1fHwzbY2VXuPneKguEbvs /BC16T+ARa3Rvpae0fmVDPyXOjm33aM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=O5D6NE1h; 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 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 483LBdVa002918; Tue, 3 Sep 2024 23:23:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=+ NwCsMY5ut7geDTvEdbHpELHUG2vwXaB0hfwIYvPX5k=; b=O5D6NE1hAI1ca/5Ka oNy0zYRbgBGl2kvJhbEFSE2t+s+VAqS5Itxo/2SwVNf8M9ByxtnzA+NG7rJnm7hu dKHsrAsHwjW5c2ZzAcCr44IVNtX6avwvIpqrGhuhAjkxpoE5yljmk5LKlsUApeAX wC5xQOYUl/diPl48xpZELiIr1vlTBrX86VEVJUCzmbh93L8PMabujNaI6SjRUzHe ga2a6MNm0f21zOLZ/IQvffXdguxhARqZAr2N0T8rkqMypo3qQgYzEPHVjYo4eS8I Ae+/0tBxEmbRXW7mc8M2Ycu3SODKyrTFuyTlmxcTUp/GgnTkzwG//pRma2IqyHFf Hbsxg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dvu7a3u3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:21 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483L0q9W001754; Tue, 3 Sep 2024 23:23:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmn96-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:20 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfA040456; Tue, 3 Sep 2024 23:23:19 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-3; Tue, 03 Sep 2024 23:23: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, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 02/10] mm/mshare: pre-populate msharefs with information file Date: Tue, 3 Sep 2024 16:22:33 -0700 Message-ID: <20240903232241.43995-3-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-ORIG-GUID: GfvRugAIhgIXGKZZXnPMCuCQwggq_Rr6 X-Proofpoint-GUID: GfvRugAIhgIXGKZZXnPMCuCQwggq_Rr6 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8D9CD1C0007 X-Stat-Signature: 68zqhzjmmqx46c6jn9x5ejrcr5fehz36 X-HE-Tag: 1725405815-106604 X-HE-Meta: U2FsdGVkX18e+qG4tTXsTDV4KyL71UsOo6PAgqJcgYLG1GPwzixJndgbLIrhxiMmLV4g5DNO3gBOkZy8Tir6lkNkf+W0Rm0jEPVQPDM3rA3sC/IsgjTzgS2m9W3sdU1kfWtPJ+KjzH7W7JxsJAWcMAWFjxm17lxw6zVkV5gju61alNM71M63JLAZJaBJsHnyftGjAGbHnI11zKZeQakWot6Yyjq6uiqC0c9QV2kZCP6EW3WFQKwDM9qQAv1zBM80WuIU8yz4Y2dWQ+dgDy47fJTgSDGVLiDkVCduYUDAlTzQtHKcIV8taM4B3UYmqkzrFFWvc7+8H0SOuqtlBs9mCLd08zxyQfaT1wY+Vp/AEyRAyvKmduA3SHJtY2zboBnCLC6KHcPiS3PBwWF8ZZFHHPt7ixnThdgnLKXtMQY/KaFrRx2W3+K8GmC9cSPZSVFABmd58+BcpjtXBir+2ewNSp/UsrqGFqlfs8ipssx6X5pY10u0kCtMn9V6bpItsravUFVSKXZ6UkMvnOEuxockX1ReT6ew+Bfe6xjvCABoAUrxJDOmWvcthSSWWDeWC5CNmUd6+UIyRaL91Voi9oUFGNGelLWJ1VSa+V7fz78C9YqR87zJF9hhXJTW81/+V+GXTJxXeMi5p8zbNg9DleNZMgDF66tTkGP579Y0ocMJPCFdKH+09s3NLoMK+h1DLZ7PPmXt2va3bRKVjGmZP95cu8ktW3eUo2ysJSkYGGrtnUB/TqJiJiQrF94WbHnrL90MP3hrnO4A/KfvSpinygR75mCSo4WUbniAap+nnWn9bm+OXDD77NQLqBvQXwZ9urmVhDb+8JNeHJyLGKq0ev40CkvTLH2vfhrkePK7LJ7XSMTU9t2k4mkKdBNCF4edUSs2un5ZH67L2KsPu71IdJf6IPPzS981shqD/q8Miv/O7jf5SD3HIqwEc3HRFfa8UNvw6cHWWCKXC9YWykTKkXo oLolnp1Q ikpapLbKl8zgeoGjdyus2GllDExdJkCeyPK8Q/3nhwzOg86esuhpk+/wtUfJqsRjH+ruWisiPU/Jc10/z2n5Efkvg3N2cBwmUT5K4UQr3wSiEuh+lPCiTzWhO3LIVS16WDXUGsD/DyXZbUUhFv96fM7csBp5FuBDUEWXZ5M6rg6HKuTs7araSgHgX9yT1ox/a7axV1i9E3179hyDaOURFqobjPKI8yeckqTA+wdVgzMxyUu8eVaVl0AQSLxFrDzeAbSl0LZREoxiKWEE= 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 feature to share page tables need to know the size and alignment requirement for shared regions. Pre-populate msharefs with a file, mshare_info, that provides this information. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/mm/mshare.c b/mm/mshare.c index d5d8e2530e5a..6562000545e1 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -17,19 +17,73 @@ #include #include +struct msharefs_info { + struct dentry *info_dentry; +}; + static const struct file_operations msharefs_file_operations = { .open = simple_open, .llseek = no_llseek, }; +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", PGDIR_SIZE); + return simple_read_from_buffer(buf, nbytes, ppos, s, strlen(s)); +} + +static const struct file_operations mshare_info_ops = { + .read = mshare_info_read, + .llseek = noop_llseek, +}; + static const struct super_operations mshare_s_ops = { .statfs = simple_statfs, }; +static int +msharefs_create_mshare_info(struct super_block *sb) +{ + struct msharefs_info *info = sb->s_fs_info; + struct dentry *root = sb->s_root; + struct dentry *dentry; + struct inode *inode; + int ret; + + ret = -ENOMEM; + inode = new_inode(sb); + if (!inode) + goto out; + + inode->i_ino = 2; + simple_inode_init_ts(inode); + inode_init_owner(&nop_mnt_idmap, inode, NULL, S_IFREG | 0444); + inode->i_fop = &mshare_info_ops; + + dentry = d_alloc_name(root, "mshare_info"); + if (!dentry) + goto out; + + info->info_dentry = dentry; + d_add(dentry, inode); + + return 0; +out: + iput(inode); + + return ret; +} + static int msharefs_fill_super(struct super_block *sb, struct fs_context *fc) { + struct msharefs_info *info; struct inode *inode; + int ret; sb->s_blocksize = PAGE_SIZE; sb->s_blocksize_bits = PAGE_SHIFT; @@ -37,6 +91,12 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_op = &mshare_s_ops; sb->s_time_gran = 1; + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + sb->s_fs_info = info; + inode = new_inode(sb); if (!inode) return -ENOMEM; @@ -52,7 +112,9 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc) if (!sb->s_root) return -ENOMEM; - return 0; + ret = msharefs_create_mshare_info(sb); + + return ret; } static int @@ -72,10 +134,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 Tue Sep 3 23:22:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789497 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 1E268CD37B1 for ; Tue, 3 Sep 2024 23:23:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92F4E8D01F1; Tue, 3 Sep 2024 19:23:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DFE58D01E4; Tue, 3 Sep 2024 19:23:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 730FF8D01F1; Tue, 3 Sep 2024 19:23:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4AAA58D01E4 for ; Tue, 3 Sep 2024 19:23:43 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9E008A9230 for ; Tue, 3 Sep 2024 23:23:42 +0000 (UTC) X-FDA: 82525006284.06.1ECFF6A Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf02.hostedemail.com (Postfix) with ESMTP id 7D0E08000E for ; Tue, 3 Sep 2024 23:23:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=JWnQoH6O; spf=pass (imf02.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725405745; 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=6B0tKbUVx2G5pw+r7fZGx9eSPo2EK+YI2lXoEXcda9U=; b=bKY/4DZW3tgiv0L8gAHpisZbUc4wpW7j8qZZrFY27M7ef722bJNrIqmw7snlFqfxIBMJEM G2XOKUKEqlyXZdlyp4xK3a1G7MZN5QVTrWVyanKlMp4ovTVn2Actkx6eb7jma2c+x06iJt dJOAoZB/iIpGwtOVVCsFhiEyRoSqq9Q= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=JWnQoH6O; spf=pass (imf02.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405745; a=rsa-sha256; cv=none; b=Bf86jvqUBfwMY9DWa33uoz/WNdHcv+EtsiHreoWds01fXQTFwaFObjB3rFJqmu7NDTdo5D oE4YNkzjGBJRn5eUxRRz/mGsiLqDwod8RnDfa064tvD0hYgt2n5NGy1dSoDlzuMKPiazmP SRpZtivKC3U53uAFgs4N3pCv1nehG5E= 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 483LBX5G019218; Tue, 3 Sep 2024 23:23:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=6 B0tKbUVx2G5pw+r7fZGx9eSPo2EK+YI2lXoEXcda9U=; b=JWnQoH6OkoRsK/s6Y pYOu63ObV4XAiFYZHrkfMbGHjP4QhBQGg+TwphKXfWvY2Z8qDsMyd9a1Jprv7IMu 8QdGSPdH6BPbLRBQNRorn7egiix4VMt88WdNf5uTfdDWdJ+T0orhKeqIPV/Ef8vk rcl9DsghKzUObYBJFv6YMrba7G1L6Vz67A1sPXps7pQ0F4WOZuPk53C4RWkyQi9S iPLGth4Q49ly5FIicWwRDuldjaT9lkRygrHyUOBa9HybefSgesYdwsVrDWN7GC6F VcaJ8Mhtr9wkZZl6NIWrp3cKvjLHANz5oEbA9ClYXCKd+Sj3lYTcAGdTITuF+F5u 8d5oQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dw51t434-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:25 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483NAKBu001869; Tue, 3 Sep 2024 23:23:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:24 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfC040456; Tue, 3 Sep 2024 23:23:23 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-4; Tue, 03 Sep 2024 23:23:23 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 03/10] mm/mshare: make msharefs writable and support directories Date: Tue, 3 Sep 2024 16:22:34 -0700 Message-ID: <20240903232241.43995-4-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=670 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-ORIG-GUID: dkXLeEH9FYZojdDG1RlpfQIloPnwy2Wb X-Proofpoint-GUID: dkXLeEH9FYZojdDG1RlpfQIloPnwy2Wb X-Stat-Signature: h7o5o73dfrxh51r3einnija97bdo71am X-Rspam-User: X-Rspamd-Queue-Id: 7D0E08000E X-Rspamd-Server: rspam02 X-HE-Tag: 1725405820-121058 X-HE-Meta: U2FsdGVkX1/xo+iY1R/rYURtM1dQSB4SpF9ZlH9PzT8HMkDgJ1cAkIPAA+eZNvtCOiemNkEvjrvr4iB4oqk7iOKF5YSbmtvQ4C6GapTnqUZNCe7Z7qOVNE1NLJnJ7BbK397D1qHNuKbKwce6XZO3KWpyY7AVN2jIbKVRZmeF66i2vYNbT9etdqsKG/CmP3b7rJMl9nhmEpnVdZ0v6XBp2rG3lZ9xB0jm0oSvNqh5dUbBiqnZo4NSmZg7uauFilCZ11pP72+mdICdeVUi2Q54WOOghtqLfxgt3rI7spL6YdLrwleztYaR2S3TtNZE12/O0T72zxH9cNF6ewK/xdIBZ+0msYMl/sZpg+owGo4dNw2DrQDRCEmtR8T06rmwwK2MKzf2NIR6Jwl/6GKQMIIfyGpKh6zZPu5xBn5AKi4QWyM+o2F6hpnJcFJ0j3zbeckPDCHfB5DVxfJfzAFCSTdV+5DC1vdq2XmQkVKth6g4jAxou/MRR9XH1igAv/+9BVKedhJ3mh0OiHBXd+kb8KWnYMf5aU5196MWgN+gOxpiqdQK2hnSltcqT4nfPQJ194WwEelVIocE2BTbeYMJtocQrEQjHfRm/Pg/T/44iIoxVdkK/fbKttE8d1GmPUwq3nT6YtWYXkA9JfzRKEFVicSUGhNthbrrNcvBg0jHBoPOYZgHcVQZ+ttrWqCs8uFIX5R/lSidyJ8uCQ6sYqJ9n7z2b2+o55H0ybKIIezvljplOO1gVJmy7cL3jQrBB9mYMcjVy2yLZMToCk+tZrLIQk8ypB4RfrVfXg2LrABg0nN2klBH7tQACqeAYwwze1tfbAlP6JLpjcIZSjk0ONzJhlycm4OAzkdGaNttMWFmCfEqO/3v+G90tLCveAsy7FJKeZufUnFgLJ1AYffI50zsvQhj5hOZsxqDxZz0RpdiI6qE7ZJAUX9nfSDbU3HgpT+iOmdTi4ReZPPY631Ec6ZO3zV e4BKhTPT Tv9T4J1o2HbzveC6QjovZiEpJh8Pmv6KpD9Hs7vHSsJp3z9K39utK7B332gc0cXBn4XOVOH8CTHJVCK7caOGMcpy0PmyzIdhkOjVgvUuhrhsxcTjDyiVyUlB7H3b0hAvQP+lDiELeu5tD6WfVayJ7PgVmNUtSn7axLEAEQ64NtgE5298BkHUks6aLARcxEsooDgbNm4TJM9OCVYjeKfksXeOS3eq3o413xs/JvEGvKRAx+OyR8UWuSHui5vdAe47fwY9dzGcUTSFHVQ0= 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 6562000545e1..f718b8934cdf 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -21,11 +21,126 @@ struct msharefs_info { struct dentry *info_dentry; }; +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, .llseek = no_llseek, }; +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; +} + +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) @@ -104,7 +219,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 Tue Sep 3 23:22:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F8D2CD37A7 for ; Tue, 3 Sep 2024 23:23:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9D8D8D01F2; Tue, 3 Sep 2024 19:23:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CAEC08D01E4; Tue, 3 Sep 2024 19:23:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B523B8D01F2; Tue, 3 Sep 2024 19:23:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8B9FD8D01E4 for ; Tue, 3 Sep 2024 19:23:45 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4867040A6F for ; Tue, 3 Sep 2024 23:23:45 +0000 (UTC) X-FDA: 82525006410.04.C6BCE35 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf18.hostedemail.com (Postfix) with ESMTP id 29C7A1C0012 for ; Tue, 3 Sep 2024 23:23:42 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=gAQPAJoT; spf=pass (imf18.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725405729; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uuOxq7Oxho81S6TXP89tPlj4pEnJ7xSzH4D/ZNOwSLQ=; b=Fk1RGWtf//0dp7HocG/AEpSsdY5tHWfKh/Mygc1Giky4hhC+vV1mqSkLGWxp0Hv8LTDmx6 tM2f4sFcQMxuML9cHFpjcms7V7YieLKm/63hWghusvOPU0vkSxsEEsjZO+oCQ+u4dSuhYQ V/0tnm7stx/pqxu4eLG2wcmblo8/1qY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405729; a=rsa-sha256; cv=none; b=2lGHIcVjqnGIZTxgDr6a1M78O4Rv+TfwYtbH5IMp93UiRj8feuzmJCChwkRfyDQ7PUS59d hk9yrGow1V6+GKsSWxn4R5RUaAEe3qteBOrjzwOP1FvMZd2pcYtfOxcxMWhg8XxoPfOQZ7 udmnCFZnu3wqjI15oxpBIln19kDvRaM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=gAQPAJoT; spf=pass (imf18.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 483LBjM9011995; Tue, 3 Sep 2024 23:23:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=u uOxq7Oxho81S6TXP89tPlj4pEnJ7xSzH4D/ZNOwSLQ=; b=gAQPAJoTvI/FNK6eL sKJI7eQCB3J2OSzXrt3K+5f6N6xK/6rCTaImSwTOseMCrUUee9Kjl+4s/LcimnfB 6jzUvyH6envjvVyEPq9wbYurqjKBjUX+jWk4ssZuJbYSu5v2a/CB3YZZH2AzNi5G rTdMnWmTm/E2WSbyVmq1dQmIeqUUhc3Sh0Lo/t1DC1dsrO35TOtS3OF9YJcP597D sFL2ZioyPqpRjKJ69NNfNWCb3l+F91NAWvRZWUtmga9WacuTSECGHCRouIvT0yxi cXleAiC4b9Iip0kjFIygGETHbRayBo9Ci+b1MGO6Iy+6z4eo0RDmK/widO8FjWmx C/m3A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41duw7t6wk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:29 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483L2KtP001690; Tue, 3 Sep 2024 23:23:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnbr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:27 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfE040456; Tue, 3 Sep 2024 23:23:26 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-5; Tue, 03 Sep 2024 23:23:26 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 04/10] mm/mshare: allocate an mm_struct for msharefs files Date: Tue, 3 Sep 2024 16:22:35 -0700 Message-ID: <20240903232241.43995-5-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=750 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-GUID: YI5SiYhe_q46H_6h3lbAj2EayvwuuRUi X-Proofpoint-ORIG-GUID: YI5SiYhe_q46H_6h3lbAj2EayvwuuRUi X-Rspamd-Queue-Id: 29C7A1C0012 X-Stat-Signature: xuzpdjhnukwnpckjqiu4d1rcb38i7j99 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725405822-544891 X-HE-Meta: U2FsdGVkX19yODAjiR8ts0ykW46o4JAZK5zflCqj4Vk2nViqEuxnnMmZeVcwwR5s/kxnnxNrCmtFbclvXp7byQw9/tcAkKsl26Df6DD+icXUBYMH8Kdau1I5hivhVQJyWM5seLUGE6OuUsXxD2wBP/ePlDcfHke4ELOzR6jr+a2cpN1L3iVzEQYztclAc3Z0s/UhYzjdWsoEFirF+W+sWTzfzgPSmXV66glTx+v2wcjiaCsG+W12u1Hwd9hcTq8gCcFICp6orXMQPHxKWhJzk0CdzlxOorhfSC7UzxQam/TLG+9Jz75lweDie0COndkD0Qo4xWtLyV6nrFefhe7i2fwpMyrDXuCav5r4EAmS1bCpU6R1Qf5Hu/KJDyV2yjW2syfti2chQcYQmJWehKbH9BYkTwkCQ7uPlKh5vvL4QyPGiZcfI6366rNNtU0qUGdZ94EX0N4KoQoQQuC6UyQ9h+lHK6rlOiVxU5e/zON3sqCJN/awlZ6pxxWgpRpQZk0Vzf7+dPmI8WXQg3DafagTseMBHFKLYSx6rURbYiS3Ae5GUjDStfLQPpRGgdOC/Xj0+Ev2/irdgS0XZWQdtc44XnQ2w8ryEbHSdKIE/oTImMZO2vm5wVzm4W7mFvkf4CoB6qUpZkU44P2OmZZm89eaSE7Rz0k+w7ZuUs9AgcI9q2lUBN8sACLQd/Nr8Md2syW1NusDv/96qJgPZ16FBbeDkt4LexkCgFmOl5BqZ95BkaziAI4jh6ZmOMD9pwo4GSetoxa36A7Yez/DYAlOdbkBS5KZxEqlklSSxmSM5BfnnejhaVb3PEhGjDeIFVvPqW9WryEWznvnubd7qdf9L2dwGgPzn6b0QIl3KP35djv8wSJbVMKS40e3CzylTju4sCA31oS/F5k1bbNgdOKpnXi1ECxgN6Fl/c8X8U0Qc2gMgrg3LBizQUotSNUQAhMOL+GcWiYWnPB4OyHvY6xBOi3 tvlCRN2D LqI+XIml9YzN5C95fsaYMTY0wUH0lvgFTZur5Qww7qyE2qFWicpeXkg0aFFJHnENikf9I1dY+Kj36dehzbWJDE83NRc1tPMwvj5UHcve8G7pEYLqvCsYgSBhSWk6TIbDGi3AUuEziXtQ6PPapapoYYGjytmlSoJ35mkLvELVkI7JHeTt+7b+5xtc8wgyTOXHq15/B8Xk2umTOoUakpY2TuIdFAkKZw8IAhrH96LrM7sDcSw+wrOufyd9W1gezhdXx06ib7tXuQYlIVdkZ+e4T3T91+p0w/wc7erOUVeQDUouoQeob/Nr1Q87Gqw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When a new file is created under msharefs, allocate a new mm_struct to be associated with it for the lifetime of the file. The mm_struct will hold the VMAs and pagetables for the mshare region the file represents. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index f718b8934cdf..a37849e724e1 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -17,6 +17,10 @@ #include #include +struct mshare_data { + struct mm_struct *mm; +}; + struct msharefs_info { struct dentry *info_dentry; }; @@ -29,11 +33,51 @@ static const struct file_operations msharefs_file_operations = { .llseek = no_llseek, }; +static int +msharefs_fill_mm(struct inode *inode) +{ + struct mm_struct *mm; + struct mshare_data *m_data = NULL; + int ret = 0; + + mm = mm_alloc(); + if (!mm) { + ret = -ENOMEM; + goto err_free; + } + + mm->mmap_base = mm->task_size = 0; + + m_data = kzalloc(sizeof(*m_data), GFP_KERNEL); + if (!m_data) { + ret = -ENOMEM; + goto err_free; + } + m_data->mm = mm; + inode->i_private = m_data; + + return 0; + +err_free: + if (mm) + mmput(mm); + kfree(m_data); + return ret; +} + +static void +msharefs_delmm(struct mshare_data *m_data) +{ + mmput(m_data->mm); + kfree(m_data); +} + static struct inode *msharefs_get_inode(struct mnt_idmap *idmap, struct super_block *sb, const struct inode *dir, umode_t mode) { struct inode *inode = new_inode(sb); + int ret; if (!inode) return ERR_PTR(-ENOMEM); @@ -46,6 +90,11 @@ static struct inode case S_IFREG: inode->i_op = &msharefs_file_inode_ops; inode->i_fop = &msharefs_file_operations; + ret = msharefs_fill_mm(inode); + if (ret) { + discard_new_inode(inode); + inode = ERR_PTR(ret); + } break; case S_IFDIR: inode->i_op = &msharefs_dir_inode_ops; @@ -141,6 +190,16 @@ static const struct inode_operations msharefs_dir_inode_ops = { .rename = msharefs_rename, }; +static void +mshare_evict_inode(struct inode *inode) +{ + struct mshare_data *m_data = inode->i_private; + + if (m_data) + msharefs_delmm(m_data); + clear_inode(inode); +} + static ssize_t mshare_info_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) @@ -158,6 +217,7 @@ static const struct file_operations mshare_info_ops = { static const struct super_operations mshare_s_ops = { .statfs = simple_statfs, + .evict_inode = mshare_evict_inode, }; static int From patchwork Tue Sep 3 23:22:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789499 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 29A6DCD37A7 for ; Tue, 3 Sep 2024 23:23:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69A678D01F3; Tue, 3 Sep 2024 19:23:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D53E8D01E4; Tue, 3 Sep 2024 19:23:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44CFB8D01F3; Tue, 3 Sep 2024 19:23:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1A9E58D01E4 for ; Tue, 3 Sep 2024 19:23:47 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C6EDC140B65 for ; Tue, 3 Sep 2024 23:23:46 +0000 (UTC) X-FDA: 82525006452.10.A4472B2 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf15.hostedemail.com (Postfix) with ESMTP id CEA11A0012 for ; Tue, 3 Sep 2024 23:23:44 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Gyq+srtC; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf15.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=1725405754; a=rsa-sha256; cv=none; b=hM+eiCNQCz/oidIn5vRK90a7TashbNIqPNBpP6dJCZbp1dzO3T7L9xHcy6qF1+Vs/UR9tO zlNVIp3W1ThdT4PG5AO3X4/f2ybrssfK712Ry31Sac6xRaDpuvjZKSieVcGljg/yYbOcVb iZ7a34AsiQThVuRDp3Co9s3ZpZTBxOs= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Gyq+srtC; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf15.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=1725405754; 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=qEfvffDSVfz+Cs+eDRWcr3G6GuHXhaLNpWU2hJkHeiQ=; b=SmU9RICh7vJTISH4456sZp3yqHG7HezVpOrScCwyAIahja5/0EgPbiVr5GTWTvWrRNXtvP 5cDlMzCll3VfJwfbQSHZVx25ete8p2klSdTeO8BigBk9JSG9vPOOedg3xxOlv57RaPyJcb C5+CstV90zA73s8bqpXhLIbUzC+W7js= 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 483LBUmx028866; Tue, 3 Sep 2024 23:23:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=q EfvffDSVfz+Cs+eDRWcr3G6GuHXhaLNpWU2hJkHeiQ=; b=Gyq+srtC+arStnlah Us7IAI2/G+LfgIpGjAK8YYVBmyqXbNrPdVSsYfi6KxSst/w//YW85yCDlvqKbgGk a6XQFyfiHiUNspyERhIq2oXw4HCL3XZHfk4aOIufJCxJGWByFbOk3X6X1SFy532i Zb7jAjs8YD0gSHcgJW4ZM0Ik85p1/fEBy/Fvs3oDrkTDIeKROz3Jl3UD1cr3h+Eb fStki0YNMIkS6Io0UYpRQpWQJ+EGHP1BXHscMnPRUmdAMFd08E18023W1JMJALfG 1wo93GM8jya6z7nlhHpLcq5Bki7UAK/mLwf0PVFSNpkYCduT7PR9p86CvMO4LDxl GuGkQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dwndj1ax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:32 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483L2mjO001723; Tue, 3 Sep 2024 23:23:31 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmndr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:31 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfG040456; Tue, 3 Sep 2024 23:23:30 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-6; Tue, 03 Sep 2024 23:23:30 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 05/10] mm/mshare: Add ioctl support Date: Tue, 3 Sep 2024 16:22:36 -0700 Message-ID: <20240903232241.43995-6-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-GUID: F6ATNHHZ8mdBkmlzSGVUWfQGjEu59pOv X-Proofpoint-ORIG-GUID: F6ATNHHZ8mdBkmlzSGVUWfQGjEu59pOv X-Rspamd-Queue-Id: CEA11A0012 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dnew7mfbcrw9ogdgxc98cfujycaedwhi X-HE-Tag: 1725405824-3744 X-HE-Meta: U2FsdGVkX1/GmurfKAolDnD+WEXIyWDa9x/38TGzfAxCGR0vcJY0biIBaR9CW+tbF2hvhmv3yZLDuZQikUb/UZLcLawQ+5lG2xSDajEUAv+TydO5M++CERuMfhLgqFkkBY9xf6nq2yUWE7fpPtk3pf4Ge0qXR5y3j+wOHFXgiyPKvfLgVu8bAuq0aybTLeDRBJ866u/UGTDNHH6Zl7ZP9nq5uR/Ccf4SuD6g0RKOKxwQD06QJP5SA1n51FQEHc/Tqxx39wJ5pCUgXZoQ3C120DfQwnM5UuxLsC/HL3hglEDHih5xnVDXRg9EA9o6ObZMKqTDFT9fEiX6laG23g8jZJFQIusl6x+1h/Dn+yxFDNJ4c7QCpjmG+tAJu0/7ClOJxjrbHWJ5HOvRjN5wNsV/1EHwzyxQLAuVBgW786mPFj6LdXKVwHLJLTNNymX5Yxp1fGMOa/PDFY3L4fRLW/9qP7Z06M51lF3WVCQ5wRJ6C5NEzUciQWrr0/Xn88pNkVWCTvc/Plc1PQgXNB6VVLBC1THrA85ikDLfMGJ+RMhutBlumHQM7TOl9Zk6SyrobAWHlHxBpDZx87u5n8oU6iyi9xq+vSR6Be2Deva9GNo7cMGjAlrlO6QpmzVwaXZ00eFTK1KuyoSvhdBr8Y9S/lnQ7CxMue9a1z5SS9iyJI/j9TkqcbnddzdDQtBwFUF3vsRsudtT0WSAvQnCOxMs349sAcKFvYasjh3c4044jKOFclxuftHykVsgGs9jvwOylxhxoItVr2HNrAz+INKCfV62H+KTpiGW1s+RqMuDcgPz0eGl7WZk6DnFMyEo65no3eDWjM5mBtRpmYXT1rDXsfgYWs4bc1tBdpbYOXye9zyax5xoOTZc1LvKwG20Mijz+ft7P4QfsuulUY/6slfm9moH8/jGn9tHchCwGKg06kC4OmcUATEQNyZJayjJdguFaeYW79Z3kHRp7jPIGD2uKzN 0wSyrF+I jg/vLvOl73qFQvxCDCdXA/zzktHSi7cOzUYBZoNFMMrmI0VarqwwhHS0CEb0/QoM5SNH8NNk/5wq2m1egoaeyKTD7oka4NziSYtY0/JGbUU2uXT5u5PAVC5GxXmqP85xu7dK6d0xomKBRbN7PsUdaocZvuEQ+Rf85bhgROdweAFPCIgu4+wcQzzWD3kaPB+FEAmbjQER5mMg9o8rcfbmyHSN7fYu2VuceD+oHqBMTPqeXLwQgk+BaTDNfSEN0QdIZ/UJUmKZIL0G4XOvkn5Cd5QCkBQSjF5DeFrZlTJYxjNUZUuzIpmgNkNB2m3MU9CC7758n40Z/FUkPz+3flfU2VUck4oTPf1apWAZqWUR9VcVLRDAQOHcmsRW8oPZ+ojfvesZ0RV4W3tATEiRDkKxtI9nV6NoqGmakk5n+ 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 | 72 +++++++++++++++++++ 3 files changed, 102 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 e91c0376ee59..d2fa6b117f66 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -301,6 +301,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 a37849e724e1..af46eb76d2bc 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -10,15 +10,20 @@ * * Copyright (C) 2024 Oracle Corp. All rights reserved. * Author: Khalid Aziz + * Author: Matthew Wilcox * */ #include #include +#include #include +#include struct mshare_data { struct mm_struct *mm; + spinlock_t m_lock; + struct mshare_info minfo; }; struct msharefs_info { @@ -28,8 +33,74 @@ struct msharefs_info { static const struct inode_operations msharefs_dir_inode_ops; static const struct inode_operations msharefs_file_inode_ops; +static long +msharefs_set_size(struct mm_struct *mm, struct mshare_data *m_data, + struct mshare_info *minfo) +{ + unsigned long end = minfo->start + minfo->size; + + /* + * Validate alignment for start address, and size + */ + if ((minfo->start | end) & (PGDIR_SIZE - 1)) { + spin_unlock(&m_data->m_lock); + return -EINVAL; + } + + mm->mmap_base = minfo->start; + mm->task_size = minfo->size; + if (!mm->task_size) + mm->task_size--; + + m_data->minfo.start = mm->mmap_base; + m_data->minfo.size = 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 *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.start != 0) { + spin_unlock(&m_data->m_lock); + return -EINVAL; + } + + return msharefs_set_size(mm, m_data, &minfo); + + default: + return -ENOTTY; + } +} + static const struct file_operations msharefs_file_operations = { .open = simple_open, + .unlocked_ioctl = msharefs_ioctl, .llseek = no_llseek, }; @@ -54,6 +125,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 Tue Sep 3 23:22:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789500 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 D2076CD37B1 for ; Tue, 3 Sep 2024 23:23:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 622768D01F4; Tue, 3 Sep 2024 19:23:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D1FC8D01E4; Tue, 3 Sep 2024 19:23:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 474D48D01F4; Tue, 3 Sep 2024 19:23:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 25F4D8D01E4 for ; Tue, 3 Sep 2024 19:23:53 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A0283C08FF for ; Tue, 3 Sep 2024 23:23:52 +0000 (UTC) X-FDA: 82525006704.22.2B5058F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf28.hostedemail.com (Postfix) with ESMTP id 74722C0002 for ; Tue, 3 Sep 2024 23:23:50 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Lgqq6CIz; spf=pass (imf28.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=1725405755; 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=IZQX5Rr0ub/XJMfRdfY262glhjZWupIHzaraDs2Ywu8=; b=eySIjwgR8Rx66LE2ID5SK8OKEOaB0DE3Jqr+a/C4OI37W6XzEKQBrO9tZYxUEnvyV4cUGj u3rEdah/GBMB2zpDkq64KtyuLl4k8FMMlgJHUpWa1M/xoHYaFFDZpDBtjdfhW58QLSVD7Z RaCK+0wW3l0czp69OnyFHh7wHac39ag= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Lgqq6CIz; spf=pass (imf28.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=1725405755; a=rsa-sha256; cv=none; b=52AtqbIq08N68DN9vruIC0aLG5/yuErzu8mrRAj2jwPdHHswnJKYyzP1BO/cod2upBnGkH NxiKGnCHrbUr86L9MeNG1JECKZbKZnhiN8lpn4ElRu4v3s48JXCxd6qDQwmhWyXTA07pPU BqCYBzPDPTxeGGEfYiURw7NdpxLj//Q= 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 483LBXtV019214; Tue, 3 Sep 2024 23:23:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=I ZQX5Rr0ub/XJMfRdfY262glhjZWupIHzaraDs2Ywu8=; b=Lgqq6CIzpuQX3U9X6 iDa58SGs4E0AAapCVCBdEQV877eZHX/dUHEHyK6LTiS6pGCk5JUG8g43WwdiC9jJ ZrKgW8RSINLnh7hb74L3mn/6X7muQGneLkQSOvvOnXiVKWY5ACbPi1G5jZF/GYtY 6tWLZdVZ9UleXIrnz9Q8Ho4mtzdsmuB6jSwuFYHJZ6KmSD4BZYVfAy+KXYlDUBmR i/iHccgvQVxuoJQshtVXcBUs3OktK3mu3Wv5ja0oR1UjkbM1G1H+uBz2iAsfYWE4 ktReTIrdKQ/MpcGjsU5QimzV0roVztQ0ppHy13/qvSRm1rCYpdhxzoUEfLcszL1E fhY/Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dw51t439-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:36 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483MmNpe001958; Tue, 3 Sep 2024 23:23:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnf8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:35 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfI040456; Tue, 3 Sep 2024 23:23:34 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-7; Tue, 03 Sep 2024 23:23:33 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 06/10] mm/mshare: Add vm flag for shared PTEs Date: Tue, 3 Sep 2024 16:22:37 -0700 Message-ID: <20240903232241.43995-7-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=679 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-ORIG-GUID: atzil67mt7N0tlp4YnnhsIyhWgXr7t7D X-Proofpoint-GUID: atzil67mt7N0tlp4YnnhsIyhWgXr7t7D X-Stat-Signature: z13z74b4fs9ghdtcqkrqn7hkt37ambc5 X-Rspam-User: X-Rspamd-Queue-Id: 74722C0002 X-Rspamd-Server: rspam02 X-HE-Tag: 1725405830-150626 X-HE-Meta: U2FsdGVkX183Uuw2fJvqPEc95M1R25ocW4ZgAQtyGLSnDalh5cmrEUtNifBnLEHXj6/rS7hLl3tUmqkXPCx7mOtRG+Ss+pHWb2aLexb5H+Jie5n0a/VugRbPZxQI2+rBayXM/xU2NJof5CYKicJ/NIpVilunf14HLyC3Iijz8XQ4jLBIEu50NsIs5pzZAzQ0R0WfucqKvbsOOEeO1z2ieMWRqFji+fC2LKHWg4qIVyZ8EccIs7+zNMF8E2/zu0EQvNG0PiE7hLLDBHVZklJOYKCaHrtHcn+NOVPlLzqrkcokwDq+o/uPCGX5sugT0US/zy4WmCI/bkFGz9ZIgLBdOPzuY1kOsth/DQtxkZmLCs5N6oYGEUyEnjSzIFEoX+tGy17z7Q5ZApLc2KhrI3HYr2/vqFlfLi7hLNZdBppk8r8OEc2z9r7YGsHyQdTme7oGuenCARQ+S2JRX/vXo6LvsoAYLC6Nh4GmrQQPQdp6ZGMS89idicDB8DnWtsFRNMEnBowmv03qBWljv79VHx+iu61JGDiW6jXLG/QyA0jHoX6neexrnJQ2kFmL4XFrPSlu/VCJaJwAe72KHIAuoVfWSQVQ0tc83Bca1dKor8GpRfjnkAgitt/nqfllTOy/V/OzxdF5EKCD933rv1jQ2Hs3oio8q2g0MYJc95rvMPQBOueBMgamXcjeAxCMFQJTXVxnN9V2Ml4CcotWh9IqauvWk5qgwbEOeyITzj3SaBShh5FZp1MAawOFELnrOEXCIKdet6pMlzetnD79/wqPc10YX9EolAEUMxpYugfO1+LtZCjHpU8/6i1xIAxoQh/m6hALvwbcBgw/PHjAkvXC8gJrNOwoXI1tIIUOcgIUXuBiXlEThOIDWMXf4IB9XXTEpeDRX2m3fe6eri2PtiuItGnYi9eDdFce3bshMBn14J4AW0GxqwIUFDpoOIVQgRFCTt3CKGbzSLk86bW3BJU4mxu ebXDYygq 9HzL79URNB/OcHxJiM0v/ISW+yV0M3jZQ4XB0ZVcUiKg5UMnODjRjDTUbUthlMsIBbk3I9btSAU7aqpOqBsXTIgDZZ0kFz8w98ulK5oUUabg4GTFRf16knAouq5THTW+hcqK2qnJSJsSrHBKs7QxSjtECe1WNzfnlWBelWm/MvP02OxBMUkbJ4xjEQxx89UfCwtDYOJWJdMVRz7O4W1XbU1uqVitrTArc2gmocYN3kswKdZF/3mqQCYchOVz6GLkOaugjm4Kx+kdgzDiScgfrKYY0y+MRFUizcoogiDb4G812L35IbFLoERsvDVw9vuzm6jwrhsyloPEoSps= 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 bit to vm_flags to indicate a vma shares PTEs with others. Add a function to determine if a vma shares PTEs by checking this flag. This is to be used to find the shared page table entries on page fault for vmas sharing PTEs. Signed-off-by: Khalid Aziz Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Anthony Yznaga --- include/linux/mm.h | 7 +++++++ include/trace/events/mmflags.h | 3 +++ mm/internal.h | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 6549d0979b28..3aa0b3322284 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -413,6 +413,13 @@ extern unsigned int kobjsize(const void *objp); #define VM_DROPPABLE VM_NONE #endif +#ifdef CONFIG_64BIT +#define VM_SHARED_PT_BIT 41 +#define VM_SHARED_PT BIT(VM_SHARED_PT_BIT) +#else +#define VM_SHARED_PT VM_NONE +#endif + #ifdef CONFIG_64BIT /* VM is sealed, in vm_flags */ #define VM_SEALED _BITUL(63) diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index b63d211bd141..e1ae1e60d086 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -167,8 +167,10 @@ IF_HAVE_PG_ARCH_X(arch_3) #ifdef CONFIG_64BIT # define IF_HAVE_VM_DROPPABLE(flag, name) {flag, name}, +# define IF_HAVE_VM_SHARED_PT(flag, name) {flag, name}, #else # define IF_HAVE_VM_DROPPABLE(flag, name) +# define IF_HAVE_VM_SHARED_PT(flag, name) #endif #define __def_vmaflag_names \ @@ -204,6 +206,7 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \ {VM_HUGEPAGE, "hugepage" }, \ {VM_NOHUGEPAGE, "nohugepage" }, \ IF_HAVE_VM_DROPPABLE(VM_DROPPABLE, "droppable" ) \ +IF_HAVE_VM_SHARED_PT(VM_SHARED_PT, "sharedpt" ) \ {VM_MERGEABLE, "mergeable" } \ #define show_vma_flags(flags) \ diff --git a/mm/internal.h b/mm/internal.h index b4d86436565b..8005d5956b6e 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1578,4 +1578,9 @@ void unlink_file_vma_batch_init(struct unlink_vma_file_batch *); void unlink_file_vma_batch_add(struct unlink_vma_file_batch *, struct vm_area_struct *); void unlink_file_vma_batch_final(struct unlink_vma_file_batch *); +static inline bool vma_is_shared(const struct vm_area_struct *vma) +{ + return VM_SHARED_PT && (vma->vm_flags & VM_SHARED_PT); +} + #endif /* __MM_INTERNAL_H */ From patchwork Tue Sep 3 23:22:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B4FECD37A7 for ; Tue, 3 Sep 2024 23:23:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4010A8D01F5; Tue, 3 Sep 2024 19:23:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AEE88D01E4; Tue, 3 Sep 2024 19:23:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24FA88D01F5; Tue, 3 Sep 2024 19:23:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E6F228D01E4 for ; Tue, 3 Sep 2024 19:23:53 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 99ECE409EB for ; Tue, 3 Sep 2024 23:23:53 +0000 (UTC) X-FDA: 82525006746.06.0598BC1 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf13.hostedemail.com (Postfix) with ESMTP id A7D4A2000A for ; Tue, 3 Sep 2024 23:23:51 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=IhLIDQ9S; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf13.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405761; a=rsa-sha256; cv=none; b=p39WmyHGSRSl0TjTsBty+0Xb/Xk32OhXyBvFxdgiLlS1CGysXVlIzvwxpKLRpZDkmtEVcn NnHYSxfarat8BdEVe+xeA03YrgAilEy2bxtvRKsvY2ZcwcEiOr5JXM/+MlQi20sduxbGmY Xdbwd4Q6MEKmHfMqItzet6X388pZ/Hs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=IhLIDQ9S; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf13.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725405761; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BkNLLtEIT6PO4SxMovJKnjkv2fPS2KtWiGRrJ9D3V3g=; b=vCxQ6DRI8XTREXzKE7RdI3VqW91doj6OTMWrW5WVj3kTsatD53A5lUaT3lyhduLns0Hhmc kY9Xbmk+g/ZpWKZzhK2OZ1W6ziq/UKIQv5oNZPhU9Hfrd5SuJ7KZurR11sDy3l0WmGUk1N 03osmTV57PzEphe8W96x30tawBNqo1w= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 483LBaYt016174; Tue, 3 Sep 2024 23:23:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=B kNLLtEIT6PO4SxMovJKnjkv2fPS2KtWiGRrJ9D3V3g=; b=IhLIDQ9Sqp40vvnUI 34TprUtmbQDB5n4DVDKooD0xIxnA9ArOd8ofsa0o76qCbt28HkwlJP0uB5UoAFC7 0m8eVUkmeIcNKyr1gq7razbo9AzQRAf8cJab1G3VsDIu5Jxw+bzd4+Or4rORVC42 2W+FRNK6aXQ5SIQjSHZbnh0AgApvLeuLnqfpwcybtrN24+ENl0PYyHL7oATWBZYp qwanrtCEgssoDDyQeWKpv0IeHachScW6caIdbFOknj9ypQUd+I58BAUp0x5f+iSY QsvxdrWujnIVHevkLnyPYhp05xrtAC7HTNxKN5eUhG6faUsjDsOxNv1+tt9mfSoB sUexw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dvsaa54m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:39 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483L5Jdg001689; Tue, 3 Sep 2024 23:23:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmngn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:38 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfK040456; Tue, 3 Sep 2024 23:23:37 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-8; Tue, 03 Sep 2024 23:23:37 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 07/10] mm/mshare: Add mmap support Date: Tue, 3 Sep 2024 16:22:38 -0700 Message-ID: <20240903232241.43995-8-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-ORIG-GUID: OvJ_mqh9ucxXTl96GlPjzLJ-nynAvIDN X-Proofpoint-GUID: OvJ_mqh9ucxXTl96GlPjzLJ-nynAvIDN X-Rspamd-Queue-Id: A7D4A2000A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dbt7c9cr8mgn6kqw5cumw6f9owmuigw3 X-HE-Tag: 1725405831-696018 X-HE-Meta: U2FsdGVkX1/KaoKm32x/grUi431hCJ90iRgxWCvREPFISGYTHCumLKmZSipaOrgavvU546yepxWYEAtFryCboqZyCDZM/gTNrNKQSYcWFQApGbhpc41iOP7nfb8qQxOkHW8ZZD2ckSW/XMEfMmxB4LBTw6N1NZcO3KQ1Ax5ysSTDD6zodtoCqaCRyLaFixgmopC437kdI7r4V9DeFEnvMHzWrJefmcNcTCxB8jViluMsC8GgnGe3/RinpIFv/ITfDm6suvOP9fazRodi0STKNyKj8QcqvK8+uyd4MG4WbH6AmAWpn9fJ9Mmc7CazzvvNWjZrwLkjia5ZCdj1GI+WjJ63Mmp+XQzGtzqvcGABOHuN9j6NTJw4LHMeW8pZkmP9zJx9adaCWYcrtHUVT+7NCgZrIwIOupe6CFd6OtEyqirQs6Kyj4FogK1mLzUHzdJrq6t3n1grWzeNTYnkPLefJ126ogeWffVL1HjMLzyAxszsAWINvRh6pDL+OllltUO7ZO/rHOiPn1iD4ZUSCV+OyO1FdSM0pM/ITt5vkO209LPnfu4SAdyW3Pv7wMbwG223lqw3Z9CbIdwVHfreNAPfTL96wwaAWbiHG4Q9dUW3QyS6JP8IjUILk3fu4Wn6Q5k+yqoH/8YkbHf0ZRbS1MZ8zQuAjPvTQ6RXkA/EA8n1IXFG19TqKPmbPr4FAQD15kUh6oAEqCWBAl+RH4ApYeh9N2BlbY5V/nKG+id0c0FHf3gGyScA2wBKMoNOQqF2A37G9jAF0hBR1sM4g/kpvsbQJ8fDoMAwubAl6qfeUI3SRdMeO6OcEhPitpgl+wXpMtFZoNXo6DvdTMWKTNbNwTcrp1CT8BwngAOAZkdC5uvUjAnLYfGqq6+x3Tn+Pku8fwudSHPTVc+N5xeH9LGFWfmQ3/rHSL9BxAdSksPitDfTSIgpMngplnS23W8iKRwEvFB26CBnVpnmbtvfY0bnr+g 6RXJdDAh OA3Pefkugp7CSoFxpySGbdDzHDT+qMqbZvSL1ul9P72SAJeTR2+mKLcLtMBDXiVm3UqVV0ryiX2Upi8HtiA1NB4xG0L5ToBBBCBWulM7b/be3PbVrxcCPiNezEOA4r6tsfpiQunRUm5lVgl2mLyrFGTtI2CIO98nf1zxoO8A1ABC8pCfvkP9R5blniXmDQmQYgyru/kgVjASQTifO5u8fv5XKfzS17UnQPU+qqG2D4mteiNBj5uMNS89k1FsMW9e5uTLixdhqZnOWU/g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Khalid Aziz Add support for mapping an mshare region into a process after the region has been established in msharefs. For now, disallow partial unmaps of the region by disallowing splitting of an mshare VMA. The functionality for mapping an object into an mshare region will added in later patches. Signed-off-by: Khalid Aziz Signed-off-by: Anthony Yznaga --- mm/mshare.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index af46eb76d2bc..f3f6ed9c3761 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -33,6 +33,63 @@ struct msharefs_info { static const struct inode_operations msharefs_dir_inode_ops; static const struct inode_operations msharefs_file_inode_ops; +/* + * Disallow partial unmaps of an mshare region for now. Unmapping at + * boundaries aligned to the level page tables are shared at could + * be allowed in the future. + */ +static int mshare_vm_op_split(struct vm_area_struct *vma, unsigned long addr) +{ + return -EINVAL; +} + +static const struct vm_operations_struct msharefs_vm_ops = { + .may_split = mshare_vm_op_split, +}; + +/* + * msharefs_mmap() - mmap an mshare region + */ +static int +msharefs_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct mshare_data *m_data = file->private_data; + unsigned long mshare_start, mshare_end; + int err = -EINVAL; + + spin_lock(&m_data->m_lock); + mshare_start = m_data->minfo.start; + mshare_end = mshare_start + m_data->minfo.size; + spin_unlock(&m_data->m_lock); + + /* + * Make sure start and end of this mshare region has + * been established already + */ + if (mshare_start == 0) + goto err_out; + + /* + * Verify alignment and size multiple + */ + if ((vma->vm_start | vma->vm_end) & (PGDIR_SIZE - 1)) + goto err_out; + + /* + * Verify this mapping does not extend outside of mshare region + */ + if (vma->vm_start < mshare_start || vma->vm_end > mshare_end) + goto err_out; + + err = 0; + vma->vm_private_data = m_data; + vm_flags_set(vma, VM_SHARED_PT); + vma->vm_ops = &msharefs_vm_ops; + +err_out: + return err; +} + static long msharefs_set_size(struct mm_struct *mm, struct mshare_data *m_data, struct mshare_info *minfo) @@ -100,6 +157,7 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) static const struct file_operations msharefs_file_operations = { .open = simple_open, + .mmap = msharefs_mmap, .unlocked_ioctl = msharefs_ioctl, .llseek = no_llseek, }; From patchwork Tue Sep 3 23:22:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789502 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 A0239CD37A7 for ; Tue, 3 Sep 2024 23:23:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29FBE8D01F6; Tue, 3 Sep 2024 19:23:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 250508D01E4; Tue, 3 Sep 2024 19:23:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 053748D01F6; Tue, 3 Sep 2024 19:23:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D4FAF8D01E4 for ; Tue, 3 Sep 2024 19:23:58 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9054EA6D54 for ; Tue, 3 Sep 2024 23:23:58 +0000 (UTC) X-FDA: 82525006956.04.8F85853 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf11.hostedemail.com (Postfix) with ESMTP id 9AFA540014 for ; Tue, 3 Sep 2024 23:23:56 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=h6VunbqX; spf=pass (imf11.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=1725405741; 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=Zopa4j/YG9ypfcYjVylIZK6eOHt2AhaFVb3bFR+h2R0=; b=StY7mOFGHJlG26u8Oog1PAM+m0g+vu1TejkzIt5XSR8hLQiNDNQmm+nl25VOonwxGh078N qTOrmHNZOkIlRSlrDEe6A/tZ0GtmhyttTpBWJCLeMksAgOjF7PxBfmGxgrqNoU/JvAHhJ7 a32wnPFO3BMDcPHQ3SGh2lKdRbuc67s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725405741; a=rsa-sha256; cv=none; b=tbDJUJgppu3m9miMJTZIoU1bWQWSKGatIf+EHTv280WNzOKJMLxPZr0KImzjLaI9Vy6+O1 /3mhy119tcMOZSmzENwrz7ADg/IfxRHIlQwDKMz7lVA8HsumnzS6Jj6MdfRqbuOjhXlARh 0WDL5HPQP0nCaqgiFtZ9Z+HW1W3wV4E= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=h6VunbqX; spf=pass (imf11.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 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 483LBUsR028873; Tue, 3 Sep 2024 23:23:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=Z opa4j/YG9ypfcYjVylIZK6eOHt2AhaFVb3bFR+h2R0=; b=h6VunbqXq7Bp5fy3K vROsz7xaF1ga6xe+IdCk7NIersH2TEIx+n55RSTobgnwZRnBc4AGbLXewz0DqcgG d7xXJncUcGErVEQSlSKaWTfjB4UEagI8SVJBFHWj556KQ+vzogJ0ds1t2hiVGDW6 edUxjOwoHctJhlDga2SctYImPafF5uRhpyhPekQD8zIr8dSufRBa3HszJ+a5lV/5 jmFZSX3O+4RngMR7EoBwGuNLLkNtnPfGaid2Q0nsA1hn2vDQhOOUDKO+IMvZ9HAf oUZLmkpxxySAsp5y2SKpX92oeSOmHwN2RFI83NypOSf7vsyrv2OA6zC83mh5n3A3 IopEA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dwndj1b4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:43 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483LOnF5001684; Tue, 3 Sep 2024 23:23:42 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:42 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfM040456; Tue, 3 Sep 2024 23:23:41 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-9; Tue, 03 Sep 2024 23:23:41 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 08/10] mm/mshare: Add basic page table sharing support Date: Tue, 3 Sep 2024 16:22:39 -0700 Message-ID: <20240903232241.43995-9-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-GUID: qZisTCCz9aXLQkiiG6O8unjhEMrL-EHe X-Proofpoint-ORIG-GUID: qZisTCCz9aXLQkiiG6O8unjhEMrL-EHe X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9AFA540014 X-Stat-Signature: ssg5ywpii45kb1bjo1eput639efkn33j X-HE-Tag: 1725405836-826467 X-HE-Meta: U2FsdGVkX1/FzGBgQbDgk383cZnclt9+dedE/DonFw1yf1/ExduZ5pzyJxG2aqyRhXNrdr1y0EH+iSg7d/n/x0btvcnBBbA6MjLNgudV827sAjvnFKqd3jLM+yZnUOLX3q/UzisjxccZN3bVfiV34IrVZiR0ODK58aK8qfSeTLSxHfadvheLK/BwtynO6FigalPhAXR+PoShZM9RPPHHm1P2R6CPRRMp5gWRjF6lXqLtuO/5Sw8+YfJ/D13O1Np7WRpefjYwu+Je07tKkGqHNFcg6pHM+n1S+r5QrvNnv4GZ0ijs/MX+G3hy0mWo8/LZRNfsZFv66XmkzN0o32KO34nPFnmmnjRFiexCeledT3SNDcqhUr0L3jSG+hKEi6IrdG14bUcHbhB9AZr54MjiuHaqqict3XmB9iLw3vuemFrDJKo3CAU5ZaaoaU4UgMd4nKOiQu+4Q4Z2Bw+pFdakeiJaglv2g+OVmm4lnObGSv/e0NJugm2gzziuvNoB+xtNuV+1GZD+vxFmdwUXz0qhrwl8T9Vn2Hg1Ys0CseJMUrlgcCqNdLyX8abPD7XhSB0mV+gsYEh80yriAhLddsC6QiEJmA4U5QUiJUjfGNNtOviitbA1uPOyGjw1Vo0gS/cU1zf9Ox69WCDUD0KQs5sPIuesPHEygxZtSqgbr6shOzhCr1vxnFEVXYh3ItR1FXthEg6v8PpF4zF9pYbsxnuFDrPrgXNyujVnYKLSgzRnxcOJrKAJwf2fYesbY02NbtyZRB4frvNtcEk73p9vV36g1j236K1gauaMWOysOKzkDOPGZJsYZ5H8CvuOb2fTJ3na5Ozr+rbni2LVRreEYzAicS/YxcCyWhhPLiZgA4Zevs0+Gs1LH38+QLIobZNRsjN9sVQ8WagwCdRPGrZt7FPDlMSjFB8gAgyhuHuEsn11EbVSwLL4n1se2YBLg8ZMn7lnex1xK3C1x+a1WNEkE55 DxiR8Hb/ cByYfV0Nl53AAWzDrjjfVmY/jlfZfkxCPOqh2l/wzbP+YafQ2mr/3s5INrvYeRDjhzG/4iGTlJotKaSoyftTug1XTqNFK6Pv04JyDwoA/+vV+d9d9vbGiyLUB8UYGgS9Mp2jrpXbLN2kp8S1QKie9j2yp7nbIdrCPna7DxboUjEiEhArCSwBqy3qYMFmx2wyE1REWcECD5F35dwMrWsSdQQwBzqxBLR0KVZD8AiOBKPkofXh9/fOV4usBPnUmzfuoxwv49reYLI9ZDU4vcARB+bhfx/V9SGlwZzVres4ue0qmPfymiwRY1CXdClu3srwu8xMpntupw/mUg+4= 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 handling page faults in an mshare region by redirecting the faults to operate on the mshare mm_struct and vmas contained in it and to link the page tables of the faulting process with the shared page tables in the mshare mm. Modify the unmap path to ensure that page tables in mshare regions are kept intact when a process exits. Note that they are also kept intact and not unlinked from a process when an mshare region is explicitly unmapped which is bug to be addressed. Signed-off-by: Khalid Aziz Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Anthony Yznaga --- mm/internal.h | 1 + mm/memory.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++--- mm/mshare.c | 38 +++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 8005d5956b6e..8ac224d96806 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1578,6 +1578,7 @@ void unlink_file_vma_batch_init(struct unlink_vma_file_batch *); void unlink_file_vma_batch_add(struct unlink_vma_file_batch *, struct vm_area_struct *); void unlink_file_vma_batch_final(struct unlink_vma_file_batch *); +extern vm_fault_t find_shared_vma(struct vm_area_struct **vma, unsigned long *addrp); static inline bool vma_is_shared(const struct vm_area_struct *vma) { return VM_SHARED_PT && (vma->vm_flags & VM_SHARED_PT); diff --git a/mm/memory.c b/mm/memory.c index 3c01d68065be..f526aef71a61 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -387,11 +387,15 @@ void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas, vma_start_write(vma); unlink_anon_vmas(vma); + /* + * There is no page table to be freed for vmas that + * are mapped in mshare regions + */ if (is_vm_hugetlb_page(vma)) { unlink_file_vma(vma); hugetlb_free_pgd_range(tlb, addr, vma->vm_end, floor, next ? next->vm_start : ceiling); - } else { + } else if (!vma_is_shared(vma)) { unlink_file_vma_batch_init(&vb); unlink_file_vma_batch_add(&vb, vma); @@ -399,7 +403,8 @@ void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas, * Optimization: gather nearby vmas into one call down */ while (next && next->vm_start <= vma->vm_end + PMD_SIZE - && !is_vm_hugetlb_page(next)) { + && !is_vm_hugetlb_page(next) + && !vma_is_shared(next)) { vma = next; next = mas_find(mas, ceiling - 1); if (unlikely(xa_is_zero(next))) @@ -412,7 +417,9 @@ void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas, unlink_file_vma_batch_final(&vb); free_pgd_range(tlb, addr, vma->vm_end, floor, next ? next->vm_start : ceiling); - } + } else + unlink_file_vma(vma); + vma = next; } while (vma); } @@ -1797,6 +1804,13 @@ void unmap_page_range(struct mmu_gather *tlb, pgd_t *pgd; unsigned long next; + /* + * No need to unmap vmas that share page table through + * mshare region + */ + if (vma_is_shared(vma)) + return; + BUG_ON(addr >= end); tlb_start_vma(tlb, vma); pgd = pgd_offset(vma->vm_mm, addr); @@ -5801,6 +5815,7 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, struct mm_struct *mm = vma->vm_mm; vm_fault_t ret; bool is_droppable; + bool shared = false; __set_current_state(TASK_RUNNING); @@ -5808,6 +5823,21 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, if (ret) goto out; + if (unlikely(vma_is_shared(vma))) { + /* XXX mshare does not support per-VMA locks yet so fallback to mm lock */ + if (flags & FAULT_FLAG_VMA_LOCK) { + vma_end_read(vma); + return VM_FAULT_RETRY; + } + + ret = find_shared_vma(&vma, &address); + if (ret) + return ret; + if (!vma) + return VM_FAULT_SIGSEGV; + shared = true; + } + if (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE, flags & FAULT_FLAG_INSTRUCTION, flags & FAULT_FLAG_REMOTE)) { @@ -5843,6 +5873,32 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, if (is_droppable) ret &= ~VM_FAULT_OOM; + /* + * Release the read lock on the shared mm of a shared VMA unless + * unless the lock has already been released. + * The mmap lock will already have been released if __handle_mm_fault + * returns VM_FAULT_COMPLETED or if it returns VM_FAULT_RETRY and + * the flags FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_RETRY_NOWAIT are + * _not_ both set. + * If the lock was released earlier, release the lock on the task's + * mm now to keep lock state consistent. + */ + if (shared) { + int release_mmlock = 1; + + if ((ret & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)) == 0) { + mmap_read_unlock(vma->vm_mm); + release_mmlock = 0; + } else if ((flags & FAULT_FLAG_ALLOW_RETRY) && + (flags & FAULT_FLAG_RETRY_NOWAIT)) { + mmap_read_unlock(vma->vm_mm); + release_mmlock = 0; + } + + if (release_mmlock) + mmap_read_unlock(mm); + } + if (flags & FAULT_FLAG_USER) { mem_cgroup_exit_user_fault(); /* diff --git a/mm/mshare.c b/mm/mshare.c index f3f6ed9c3761..8f47c8d6e6a4 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -19,6 +19,7 @@ #include #include #include +#include "internal.h" struct mshare_data { struct mm_struct *mm; @@ -33,6 +34,43 @@ struct msharefs_info { static const struct inode_operations msharefs_dir_inode_ops; static const struct inode_operations msharefs_file_inode_ops; +/* 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; + pgd_t *pgd, *guest_pgd; + + mmap_read_lock(host_mm); + host_addr = *addrp - guest->vm_start + host_mm->mmap_base; + pgd = pgd_offset(host_mm, host_addr); + guest_pgd = pgd_offset(guest->vm_mm, *addrp); + if (!pgd_same(*guest_pgd, *pgd)) { + set_pgd(guest_pgd, *pgd); + 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; +} + /* * Disallow partial unmaps of an mshare region for now. Unmapping at * boundaries aligned to the level page tables are shared at could From patchwork Tue Sep 3 23:22:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789503 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 562F2CD37A7 for ; Tue, 3 Sep 2024 23:24:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC7D08D01F7; Tue, 3 Sep 2024 19:24:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D72668D01E4; Tue, 3 Sep 2024 19:24:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC1E8D01F7; Tue, 3 Sep 2024 19:24:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9EEB98D01E4 for ; Tue, 3 Sep 2024 19:24:04 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3BEEF1609DE for ; Tue, 3 Sep 2024 23:24:04 +0000 (UTC) X-FDA: 82525007208.26.A6C7DDA Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf05.hostedemail.com (Postfix) with ESMTP id 22E1B100002 for ; Tue, 3 Sep 2024 23:24:01 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QbGQwxdq; spf=pass (imf05.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=1725405767; 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=rZM9CKTeyNtS6qKT8tvvNx4uJ3f/kEX/Cc1h11gS1T4=; b=r6WQ7oRYZzvgv0k+2iGePnd7+rVjEblkELAwFLqkZGroUBXP7YP5Ivsf0gt7zvqWaF5/St etyjPbQzhGFqf3xFaPQ4iKsRCo72Yii4fra5CcH63TXG0URUBZcOY1A2YxdjlkrvnsuO6w K8+g67fw3RhsfnBOi+lb7KDwKY+Ymsk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QbGQwxdq; spf=pass (imf05.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=1725405767; a=rsa-sha256; cv=none; b=xiS9VVvLRFTAC8/il6G94s9PUpddxq+dNiqxEs4DqSxQ302ZQ2Tvr9Wzb1hUs/uBaEQVvQ rcvALPQrSxa7F4fIY0NwbMQ3prcm/qu304npk4Oop1VoTeDAs+oJmdygHMrff2PpNG0sJL hr/wOlompQNNVeFoqLrnXVbnM6F8yc4= 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 483LBWCG020127; Tue, 3 Sep 2024 23:23:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=r ZM9CKTeyNtS6qKT8tvvNx4uJ3f/kEX/Cc1h11gS1T4=; b=QbGQwxdqeRDyZrwon 08Bcoq7jANjXxA5hglaPpRK1L9MX6d0tZ/JpTyZM3oKAsy8PZlwxxwg/4k6dvs12 4OEPr+BCpgq6TIMiF45Llr7ayM0NsUT15SwvIXVeLmKMnrx+1FCCiHegmZCsPSbo d8M95EWG6fuaredoa85flOrMYpC2g85hNbpQefv8oLjRPImJapNjxG9Yr+JpzuwR eI6wMBv76u12YDJY3p23Ygg1TN//uTCtXvI38uTGSvLAS8hTUZFYzTDAfxfHLW/2 pdiFKeE7Et85Q0w1WIfzF0WEBHZmcMwkHm0rC1Tu4DAqjyoRzllU8KQiG9YylynR rGhkw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41duyj27h9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:47 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483MjvRq001729; Tue, 3 Sep 2024 23:23:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnkg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:45 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfO040456; Tue, 3 Sep 2024 23:23:45 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-10; Tue, 03 Sep 2024 23:23:44 +0000 From: Anthony Yznaga To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, khalid@kernel.org Cc: anthony.yznaga@oracle.com, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 09/10] mm: create __do_mmap() to take an mm_struct * arg Date: Tue, 3 Sep 2024 16:22:40 -0700 Message-ID: <20240903232241.43995-10-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=735 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-GUID: tUoy6uZR4wBNfmtmw451fh63ni68XiFs X-Proofpoint-ORIG-GUID: tUoy6uZR4wBNfmtmw451fh63ni68XiFs X-Stat-Signature: 75tedfj7j3m9e455r3b8ejgjz7y6yibt X-Rspam-User: X-Rspamd-Queue-Id: 22E1B100002 X-Rspamd-Server: rspam02 X-HE-Tag: 1725405841-268990 X-HE-Meta: U2FsdGVkX1/ssYgQaeyv2xah1hQlXl3o9litRcM0Fc/6y+tVVncgSzcqzaBHf3w2nSnBmNOkCimzgljy11OU++JQ9eZLXiTMctbnOT4uSHjiC+a5kURqh4CuZDKHsAwj1DBAs6cI29UzKkZcCGwkFw/0enb6blDMQSoaA7dWP8zOYIGEqnXlOSymaykMTWXMbf8uPz8lVaGtvt2ilsApZ43/SFISrChapZ6c2DGFo0uCxAugBDbrFgMVIzb9OU+MekfvndsUUO7IHDoNB7zmD0MjFJjOh6hK5wnFct6HkV19MrqMrK+gZpk+GCBpYMVr4bsCeWFFqgMMPXDqu/Ro9OgQUZFHBTtVLbGPu8yGkSOk9kwdeCEo1QNAvhOKHkLtmeW4BOEsWn8Qs7H5oXPGZhIJoRLscz6qQodxr2lHwPH0QoMReQbMFuBxhYVKNbhbrnpNHE0d8wFcHIGX+Sswux50cBlKF9YaINm8kTQ/vptN94Zro3rg6KSKXA9aZNJQMKHbjrbS3tAJBfOwjiCHCAhUKzFRkq1HUsQ5PE00NsWxOD0jovbhzLMC+6vuZYcuaKghTKhOMEt/ug4k7RDUna2PGs1Ku0KlElNsbg+1t8gw/72wruw02ObKw6anFIAbdWsSoW3OXmbwrFtf0wLrg9UJxHjVeb4WSqCaTQiG5tAN8WXxWv3CkPUg9AXaRlHZk+AtmdcPCGj+Z5RCtvMpo5Ra3TayuE1yleoUQAMXduYnYSbVI7fT5gMnBABmHYuDMlmehGiwt/lvfrnPCEdaqmbSMA8pitZEHO0b4h4YhEoawClrxz+o/XwZQ5fKBMUAn7OuR7g1UVPnKzseobJ89x+SoEhhlF+Qowa436gyA0hBE7ZA43Un7ZCTe6jttHPb8BpzXrqYZFoK9hJYi0o0mza6taMJLE4bF1PCIGZM17RCbdLT859GXRqpJ78sNtOVOvMPIrSqZxgWoltEQit 2BDNlg8R 99h+aQ6OgbBDZDGG7q+3cWsEiepoGfARHrRdveOtKeGp/nYB9lB2XQL3onp6sH7vYatinvDzPwDznrgUGgNF4n5HMgUgeGDj7YOZxw1KbCF/tD0E7IgSZXLAMmncGRkVCaOYb2eWWVUFwbgDcXSo6wYc3GWIADuQHS9+ZX6RqonsNsniHFKiG7HJtTY7KJeT3IDUZvUFjn9PKr5i3ggkkJ8pfrCw+hBGKIQZxnGwKJpWrBZmGNaCzVvK+IOx6NP9t66GO4kf8DTgU001EsqYOuUf+NwVK3Tisyuw7 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 | 18 +++++++++++++++++- mm/mmap.c | 12 +++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3aa0b3322284..a9afbda73cb0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3409,11 +3409,27 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, extern 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); +#ifdef CONFIG_MMU +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, 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 d0dfc85b209b..4112f18e7302 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1250,15 +1250,14 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, } /* - * The caller must write-lock current->mm->mmap_lock. + * The caller must write-lock mm->mmap_lock. */ -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; @@ -1465,7 +1464,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)) @@ -2848,9 +2847,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, 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; struct vm_area_struct *next, *prev, *merge; pgoff_t pglen = len >> PAGE_SHIFT; From patchwork Tue Sep 3 23:22:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13789504 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 A2D4FCD37B1 for ; Tue, 3 Sep 2024 23:24:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EADAF8D01F8; Tue, 3 Sep 2024 19:24:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E35A68D01E4; Tue, 3 Sep 2024 19:24:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD8AD8D01F8; Tue, 3 Sep 2024 19:24:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AD14F8D01E4 for ; Tue, 3 Sep 2024 19:24:05 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 654EAC06DA for ; Tue, 3 Sep 2024 23:24:05 +0000 (UTC) X-FDA: 82525007250.28.41E357F Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf01.hostedemail.com (Postfix) with ESMTP id 6241240004 for ; Tue, 3 Sep 2024 23:24:03 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=EejzamMD; spf=pass (imf01.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=1725405717; 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=VK2/rT5IIEmxprXEAU2yy+HHJnHBBZfWU/+zXLoCJkA=; b=EG/6shM9hQS+joPs9i08KDEFgSBUbIsNhWklX3Rq7LUmSrpRlx4npOfwCQu8836bM+UQFO KNvelB4mU7XEL3dVFphx+i3GIQaShuzYp3olDeMjSwvmBsxO4fqRLpLyW1zwiVCqiIktec fMPtGRXV9KLTEWvOWBmYBRrT2Qyk88o= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=EejzamMD; spf=pass (imf01.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=1725405717; a=rsa-sha256; cv=none; b=KeNMSS/VXvO07gaQTo24i3J0gxfks1FpT2NYUPfSHOyBQvm39fg373IYUWQkGFMdJTBix7 SYoFTe9DNT7y8t9UyavuPU4DM0/BxHTKBn+3IpbqxeKgfvpiN0RXLlnuGmOSz6iRRMkASR UdBHbnKNVvbcvSmTW/ANgzvUN+XImLU= 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 483LBTND022739; Tue, 3 Sep 2024 23:23:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=V K2/rT5IIEmxprXEAU2yy+HHJnHBBZfWU/+zXLoCJkA=; b=EejzamMDBK7bPK5bb 0qt0mQjn5qkF+bv+ii/+f+UA/hfcsO4FDUSATiJLfN5sAhb7njBr6XKEg26G43N/ Un0lt+S0CoRg1U2RIXQEp2EBtenc6w8MFGkXGalrrGGgX+F6rBhwPpmnzH1Z5DYr V8mNpL9sRagOGCX1auCuiIUgINwjowoouwBVLdEAAKjCXCelimkJHpMK/Z5SQDTQ TyJViwri2XDZLuPG2Fdm15FlIXv2tB/d/mu3VV4Gd2UIeLec5OK9m409R1dId+Nt iN6SRiC/qf/BhY5+gFW4u/jdhJJw6ekLNzFbxSu0DGBJSoD86IlNKtM/wexRBsJl r0XFQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dk84jug1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:50 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483KsE5R001736; Tue, 3 Sep 2024 23:23:49 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmfmnn0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 23:23:49 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483NMkfQ040456; Tue, 3 Sep 2024 23:23:48 GMT Received: from localhost.us.oracle.com (dhcp-10-159-133-114.vpn.oracle.com [10.159.133.114]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmfmmwr-11; Tue, 03 Sep 2024 23:23: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, andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [RFC PATCH v3 10/10] mshare: add MSHAREFS_CREATE_MAPPING Date: Tue, 3 Sep 2024 16:22:41 -0700 Message-ID: <20240903232241.43995-11-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903232241.43995-1-anthony.yznaga@oracle.com> References: <20240903232241.43995-1-anthony.yznaga@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_11,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=792 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030187 X-Proofpoint-GUID: o4IuCMD6qVU1RpEdvToueyKdV1ZsTS0a X-Proofpoint-ORIG-GUID: o4IuCMD6qVU1RpEdvToueyKdV1ZsTS0a X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6241240004 X-Stat-Signature: 3hwewmdihxs8whqxggp5yebwwrf9pjbg X-Rspam-User: X-HE-Tag: 1725405843-734418 X-HE-Meta: U2FsdGVkX1/9h1ABie9oM/RUepan07WFTIa6XvYcxt+60HybUr2otZpld2ZCvJQjtPvpYs+tLzXBZ4y3YUbT26nLvFbycMe2oZWQ7nkIhfL0idILhjMeV/5asCPXVT4fgAFAot7Q1XnlbiZOA35AqyAms5Cd15WCb66rt193jcWXpegwPNoyTMq7IBXTHMj8CZiE2uYSQ1xDfHwV98xlPSrNj4KbiVQRdN+OUmld3UTHQHkK6kMoWFVOjQ3D6tZIVEQA38EA5cRo08yzeEDmDReowAYmj4J0XH32i3jrBXW92qNHg7QMlOAuAYLx2MHIzarldsO81XO8UJgEsw8YidrA3vMJHfVSSbKyCgRTtcFK0ZC/Zt4CZ/xQoNioBkyI9QOj06+F3bJ/iSxVUDFlFdgR24iBmnVg2Ccr02AGp3HXNzzA6OGkXzRSPGme6SxZruHYX5IF0e4nAEx+KB6UmsbcdfvLg/JhAvGWOsVIpXhnAn0l+bQr2ZhqvYxEzS2YfxgUXAN4kqzfa5kIEKyTmEYhHYagrHALpVL556ZBm8vrwsnZ80UMKtnV1pX0nYsFZjwJg14GrA8jTcdwy2P/hs/10mhoJo1matIeSkLKYOObysLVkvXfEPcK7291ZQe4r7D7ZJ0v6XHBrMPvd9KFD3aW61vv1CnkCjWNWJak14L6XgXabS95ysdshc5dNe7qxyYzDqb/PWdzE+xjxk2JlGi2i4oxALJGO3pJyfqGw1QOFi2FFgL+nykYHUnTOJF0hk72HdYf92jpfmSTGLD03cHRbKtyP1bSr4X9vqeL2M3ZQ/1I7roG13CJP2/C8GiFMxn8uyFpmcKbdU9+tYDIfvXRyoGpOSJhFNx7Z2f9QmaenktSCv9xrqw6eEdpjqdpg+dgU5f/hZbEt1w9HuBlaDYLfSNtKOYLLLKp/qEV/V2fZzrOI9T/EtqCbTQqNfqZNsV3L9AOK/8HYHO1ezB TLIExKr6 TrQOt4peLPQRhs+Iluk+jBDvQCV9q+f8TkqV/p1beDRKC4Up1Yr+1YMevz1OTjE0QDXumIBFa5xOo1Vw+g7huuq3M2u7zHBHMTZyOXYYI5ffG/45P/PLNp+h7B3T3ygjAFNDpky9JgTraFMV6+Z4hwwx+9pfod4CGAkAoVSDR+K8J9BRI+ZhL2h4QDDjcu7wp4r5oPiTmjL9CQLcFly7uDsLy2vfLvczrqJ6/iprATQCUjqujKuILE2AYwNz6izBeIPv54osbdcuJagv/XJd1SZAoo1s5EGPHGmdYZWulg8iMYto= 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() although only shared anonymous memory with some restrictions is supported initially. Signed-off-by: Anthony Yznaga --- include/uapi/linux/msharefs.h | 9 +++++ mm/mshare.c | 71 +++++++++++++++++++++++++++++++++++ 2 files changed, 80 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 8f47c8d6e6a4..7b89bf7f5ffc 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -154,12 +155,65 @@ msharefs_set_size(struct mm_struct *mm, struct mshare_data *m_data, return 0; } +static long +msharefs_create_mapping(struct mm_struct *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; + + /* + * XXX Keep things simple initially and only allow the mapping of + * anonymous shared memory at fixed addresses without unmapping. + */ + if ((flags & (MAP_SHARED | MAP_FIXED)) != (MAP_SHARED | MAP_FIXED)) + goto out; + + if (fd != -1) + goto out; + + flags |= MAP_FIXED_NOREPLACE; + vm_flags = VM_NOHUGEPAGE; + + if (mmap_write_lock_killable(mm)) { + err = -EINTR; + goto out; + } + + err = 0; + mapped_addr = __do_mmap(NULL, addr, size, prot, flags, vm_flags, + 0, &populate, NULL, mm); + + if (IS_ERR_VALUE(mapped_addr)) + err = (long)mapped_addr; + + mmap_write_unlock(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 *mm = m_data->mm; struct mshare_info minfo; + struct mshare_create mcreate; switch (cmd) { case MSHAREFS_GET_SIZE: @@ -188,6 +242,23 @@ msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return msharefs_set_size(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.start == 0) { + spin_unlock(&m_data->m_lock); + return -EINVAL; + } + spin_unlock(&m_data->m_lock); + + return msharefs_create_mapping(mm, m_data, &mcreate); + default: return -ENOTTY; }