From patchwork Wed Jun 29 22:53:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12900744 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 07EBFC43334 for ; Wed, 29 Jun 2022 22:55:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 211576B007D; Wed, 29 Jun 2022 18:55:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DD078E0002; Wed, 29 Jun 2022 18:55:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAA4A8E0001; Wed, 29 Jun 2022 18:55:02 -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 A4AAE6B007E for ; Wed, 29 Jun 2022 18:55:02 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 77DD33210D for ; Wed, 29 Jun 2022 22:55:02 +0000 (UTC) X-FDA: 79632780444.29.396678C Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf29.hostedemail.com (Postfix) with ESMTP id D963012003E for ; Wed, 29 Jun 2022 22:55:01 +0000 (UTC) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25TM4ain000903; Wed, 29 Jun 2022 22:54:28 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 : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=w05FYHNlKNrWph18aS5RLxPDQ90bMPDdwIo7huXc+tk=; b=ICDvyNIiYYntUWkd3FULW3fwML0R8tgjmyJYREDpRhHOAPoF2jVipNvGeMBh3FJwOdWn csGdXCp/xitEQecxBOpIBO96E9D6l1MyH3JIeQcVMV/vHi7lvW1/Iz6rD9cqXSrkmFIu rr7y2GkI5BxfA8E5dH/cneHVY9rc0ycPVR/7yjqz7qAEoKjlz4c/CVrkyLlTzNUpkuXy 1xbQZcbnHcqcMeAWd8t8Oda1bqcbCDMk13gAhDLS1QuNPop/flgPksigkjluYhAgVgOI /ef+HnVDlLroE31salhXTKu6+GhfCd4BP+8XPyEK8db02VPAfyX0iV0rFHs0X6Cmap6N pw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gwry0jnk9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jun 2022 22:54:27 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25TMeS2v031827; Wed, 29 Jun 2022 22:54:19 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2174.outbound.protection.outlook.com [104.47.55.174]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gwrt3h9rp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jun 2022 22:54:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EWpL9iTGpVXwMVZLNEWdxiJkfmlwO3Aqv6lkI6JK/zvXmIkjK/5aReCTg2StcLGemPZrpr74uyxy21wR+thO2sFNkAgvJBPg+vHJPKXXwXFg4EY+mA6Zgj1qGiqTrTmqqa0zBfaxKIh79VzZ25ro2r0NQwpYwjdpjlPiD5zhycpXH1Z1sEvwbz59OJRywq24DR++mNnZ3EmxW2Cc5v1lXA+g1DtdsPhOMvo6KcdCknyDr8RjRjbAu2UgJwPPuJxkci12IDAicVjB10rJv/GYqDiLyhd0lQK7SA5YPMWhgJf9Klp/RiSOpPOVqMWWVdY3v1sDYEHZc7L01BOUz954UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=w05FYHNlKNrWph18aS5RLxPDQ90bMPDdwIo7huXc+tk=; b=AXuLY4BxwSvxt1vrT2QLpuu+MLKSd8rsZ0Fet+98lWOGkYUXwMKoEfFPoNSRkcCcHnn6djCaowwjc6ZwhqQ2uVzUFrIx3TjrWGUF+ziy2bmBi0cs8Cwa7BZyL99aOgw6mLlf/U2Q2/Th2roW3X9g35ouS1pinbOsgQkub7oJL8h2Y3as153exWeSeUVpbtM76tC/UbfwtYZOVTS07gf6dt3s7LbPTkNM0ZffEZphaWxE5pNmHGtf9ueCacoAcRIiF8PPIP58XfmTYg1LQ9TK9qDNlJDDebzEtR/OFy09+lpK3ril6ijh807pGb8lcJpLqDzU5OMN3TtSfR1nuO8ENA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w05FYHNlKNrWph18aS5RLxPDQ90bMPDdwIo7huXc+tk=; b=qL7sX2FnZEd9Vj1t3bqXVO3ghN+G4GbjYqu4r1y7Fvms9HicY7TsS2KD5Ze4SZIlnhZqkTQtuLnfcULxN2dIlssLJSz8TKq6yCszbxZ7FV2TUUfhQB4huomvaR/BCfigcckQKM4pdisyT4EUtI50xwVMrJ2bMHrCZxrtZxMVv5Y= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by DM5PR10MB1834.namprd10.prod.outlook.com (2603:10b6:3:10b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Wed, 29 Jun 2022 22:54:18 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::28d2:e82b:afa1:bbc2]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::28d2:e82b:afa1:bbc2%3]) with mapi id 15.20.5373.018; Wed, 29 Jun 2022 22:54:17 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v2 1/9] mm: Add msharefs filesystem Date: Wed, 29 Jun 2022 16:53:52 -0600 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SN7P222CA0021.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::6) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ae2a4b2-e0f2-4184-8652-08da5a224be5 X-MS-TrafficTypeDiagnostic: DM5PR10MB1834:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VxfIi/GrdJHnGL5Tdd9eQA6PNu0MHMk+Cl9HcA1H9MY0YJOoeZkQHJM1XJU/+VP+snIKaH7sH5NI8cZk4nfZB1c34ryLY1DRWzjV4Y0d/jQMr8aTqoorHaw5zFuv99RO1r4+iCugEiV1g/4wwCLwyFqQzGvGrLf6c5ybZQEyyOZEE0E0ok/cW5lNA3Z9c2mzd2GoazKOKvRmUUgjJ6G8RC8zvrcOy3OC55SmCY+o0OR5yAQXWFWGDamRJiQjYr6aPsHIot2YjN/Bfu2W/821Bcw3F3fDwuqhPUQHSO83cvbTXQGLHu1eBmrJzNQsnpsr4Rp1MIuZBCfFWEDfxUt1ivlNFzxRcJpKrLfGyGC8rdsPQZ6nZNC2M6OYAS45YGmcsRAbAdaKIMIrU/EEV9jbwSpDT1qiT5B7SwYbwPKpuNkdO+5luTV+8diRvbXiG5dJQg7odAJDk7RulkvWBetwNrxZ2TPDlCqppDb48w7by8QXkWDWZ1/a6VCf8EkinQAC9hrpNtV9+JryZesWfOa26u+Mfu52KIxjIPO1pST0+qGck2PeNP6WwuzivNhFTnF7ALjX4rI8iiKZafKxhTi1uEozsoSDbS04SKg/jyN9iP7uC/WU4nEHE1J9Nq4yjxmo0hHGSYgHFmDcYktNRvJiNytBTXvmiv523aXKSnrHPWZTUrsQAjHbpxDJ4xMuGZpMs8bIR/E1gLG9PSO8qVtNUHQhir2cpFQHSuvItNY+2yM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(376002)(346002)(136003)(39860400002)(366004)(396003)(6666004)(52116002)(41300700001)(186003)(6506007)(8676002)(66556008)(2616005)(6512007)(66476007)(38100700002)(83380400001)(44832011)(7416002)(8936002)(316002)(36756003)(2906002)(86362001)(66946007)(6486002)(5660300002)(478600001)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XsklGQ1jNXpnPtWr9IIVIHKgLe8vjWVSaB6AnB+hl6BeRrTtwMo3x6z14/70ck/MTLXCsMqLuowarkgTd963Bj/3+DuhcLHxYyWDab+CkIbHydG8PxOQkLTCfBoWmEONmqgy8Byiv6etm1Do1lq0iGK5qdBHQh/bFnulT2ohxZMsh2sqPWzQlbdQISQ/zdvlcT7gQiy/J0xMC1xBWsPF+QgzJxukRrauKm1TeSepmazdTkukEgGezLs4qWzF2MfDmoMVFG5DEVV6fkYgcKeOpGCLUYyLahgrZ3QLgYTChdovFhEHetzJ/ztTKQiL796y5oLmuC9LD5Tjd+KtteD1OkCM9/2LLDq1gCt67HncmZtI+DHT751NvFV/PPR+6a9xDZEQ6Zgr9fwy2bTIZA4sA/2r+ujRQJYYAuqwZP78RlmYAd13VrKfK8+B6Ujiloj92QqgwhsJCEqc9xZ+88nbWxgCRhOOL4EzRg7gepDgCwSdkBjPqeOcrCTR19B/t5B72eZVSjnuDFr/2UiB/cynYN8b4eg2Lh9eWsnGyI/3Bi2OPjPON/EsLrT81FJZzYQk4zgGj9wByot7nxclxbaB0kDGwraUvJlLCTzSeQ9dIzXxQkOK1kYANSeqbJ042goY0WE4IAwBod8RBsI4S9uauOSlc0vU4qkgqV9q+ew/sgw2xrOKxgLEdYUdDhWvd+jeHPhbbl+ISqg+VXGKXXKekHwHIXtGybgSKT/j5oTPdyyxPRe2Etw8Tu6TSOwWtxbn4xQ4ArIk8C7NXapAxNwlu988iBqWwduFk66bEaMQVDO3RcWI+9qsMeNLMMNSk19rKAA8i5anmOae/ZJGipfwOcn38gzQrM431qYGkpLrVh0H7/+43+Y2szSxUzJb5UAgph6MnUVm2RYRk0o2/DmAoQPQnYl2WbLvKwBbqcuwgCAk1Lvhye7qEys/djSz01TYNPTS0GfI+M1sdvqhPMpp673/oGehBWY9e8kT9BX+WMLHyjpr8PyrBAZh2JOtrvld4FaTifCijASgCgvNNKOLtPivwSvk6Kpqsz/wuIKbJoEqauiZQYaccfr5g5rQqnilBkG6AqQGq6zDEFoDb7kWkNhnpI9izaGpXvBkz9UQ+14sPSxOVBJnUqR6ZKYGRVGAPGQHnvgstQx047NZdHs6iSSeIfmK0tBaQ9GK/eqKNytLLS4jgqKZelfrm32PclHxdREWuKhcU1HznyAFvTIDM3dK73GZ6J7eDVRLq+80+3Z9tuNmPntDVrD72NCJMNbKUHRk/DAlHI0ajfaNkkdaERLx65hcrYBtkGtuyFYCqGrLdheRj4VMUbmvHLEtkrj2cR4L2wBxgF6LLPm50BmIgVrplvFwgBDCsIdUemaQMNWzuTOlOob5Z16QZrPkqs/OxHjAwp2Vz3IbTSFEhtrL73cTr1M5QnnXNY6wJGxxR9pt2IFsVAnQhfKWApVD/6U9w5v/T5QIHIaFgbmQOvxO6iJZQI5oXOqm/4B/b9YvJ+CUdDpVmmWjYuIr/diwFEXVDUtqwGTvpkFTv3pPXIBJVPMpdaG5nSie+wCL035Fbu6v5PW1DSRrT3f3ruL/+avf67iIqhJZbiU5vWCW33oCxBqzeIPpWGO+oerH5H5WGx/o0pfveBmNSMHATtKKMH6j X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ae2a4b2-e0f2-4184-8652-08da5a224be5 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2022 22:54:17.7567 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JWM58AzVeAoYEqqjkWEuLcfIu8AgbOtsDxTK4QvHDgINi/Fak1FnIudqrMPQrjgqrXuqFDJM/2PlqvJ2nr8lvQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1834 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-29_22:2022-06-28,2022-06-29 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206290078 X-Proofpoint-GUID: U_44Uyr39N6VLmhZKqP5bc78xPmdhb6r X-Proofpoint-ORIG-GUID: U_44Uyr39N6VLmhZKqP5bc78xPmdhb6r ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656543302; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w05FYHNlKNrWph18aS5RLxPDQ90bMPDdwIo7huXc+tk=; b=IdjZ29crAD3lmkgSEyiDblkJ1vUiFP4YXUJP1KtaDnPvtEsCH91uTV4qXBupRrC5G+oWMw aEHeExvs7uWSTvE6+pSWcQWwA+R+AfgNX5RbRbnIir+E4C9C+5wjvD/yEAJz/2ksWH+HYp HgKXW3lI796nAvImImv9yn0sUOpH1dg= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=ICDvyNIi; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=qL7sX2Fn; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf29.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=khalid.aziz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1656543302; a=rsa-sha256; cv=pass; b=qQyKkwbd4LBDrSHUxXUDroqDQYaon8Vxc54QwaUWYdTis2pPAdFWJeTLhL3q6GGJ1RvF2X AwVW7VPmlZ8RDRfyvVTwcO40FtUldqvY8cxLKyuq27a0krR2sdtDLhK80uIuCwkXkY3X7G 2IrwqP/I6qxr9lSxffjLX+ozmXEMtQM= X-Rspamd-Queue-Id: D963012003E Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=ICDvyNIi; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=qL7sX2Fn; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf29.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=khalid.aziz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: grcyi1jkwkbxzz56w17pf4fohx6m8xdt X-HE-Tag: 1656543301-776963 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: 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 --- Documentation/filesystems/msharefs.rst | 19 +++++ include/uapi/linux/magic.h | 1 + mm/Makefile | 2 +- mm/mshare.c | 103 +++++++++++++++++++++++++ 4 files changed, 124 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..fd161f67045d --- /dev/null +++ b/Documentation/filesystems/msharefs.rst @@ -0,0 +1,19 @@ +.. 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 + +When a process calls mshare syscall with a name for the shared address +range, a file with the same name is created under msharefs with that +name. This file can be opened by another process, if permissions +allow, to query the addresses shared under this range. These files are +removed by mshare_unlink syscall and can not be deleted directly. +Hence these files are created as immutable files. diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h index f724129c0425..2a57a6ec6f3e 100644 --- a/include/uapi/linux/magic.h +++ b/include/uapi/linux/magic.h @@ -105,5 +105,6 @@ #define Z3FOLD_MAGIC 0x33 #define PPC_CMM_MAGIC 0xc7571590 #define SECRETMEM_MAGIC 0x5345434d /* "SECM" */ +#define MSHARE_MAGIC 0x4d534852 /* "MSHR" */ #endif /* __LINUX_MAGIC_H__ */ diff --git a/mm/Makefile b/mm/Makefile index 6f9ffa968a1a..51a2ab9080d9 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -37,7 +37,7 @@ CFLAGS_init-mm.o += $(call cc-disable-warning, override-init) CFLAGS_init-mm.o += $(call cc-disable-warning, initializer-overrides) mmu-y := nommu.o -mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o \ +mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o mshare.o \ mlock.o mmap.o mmu_gather.o mprotect.o mremap.o \ msync.o page_vma_mapped.o pagewalk.o \ pgtable-generic.o rmap.o vmalloc.o diff --git a/mm/mshare.c b/mm/mshare.c new file mode 100644 index 000000000000..c8fab3869bab --- /dev/null +++ b/mm/mshare.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Enable copperating 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) 2022 Oracle Corp. All rights reserved. + * Author: Khalid Aziz + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static struct super_block *msharefs_sb; + +static const struct file_operations msharefs_file_operations = { + .open = simple_open, + .llseek = no_llseek, +}; + +static int +msharefs_d_hash(const struct dentry *dentry, struct qstr *qstr) +{ + unsigned long hash = init_name_hash(dentry); + const unsigned char *s = qstr->name; + unsigned int len = qstr->len; + + while (len--) + hash = partial_name_hash(*s++, hash); + qstr->hash = end_name_hash(hash); + return 0; +} + +static const struct dentry_operations msharefs_d_ops = { + .d_hash = msharefs_d_hash, +}; + +static int +msharefs_fill_super(struct super_block *sb, struct fs_context *fc) +{ + static const struct tree_descr empty_descr = {""}; + int err; + + sb->s_d_op = &msharefs_d_ops; + err = simple_fill_super(sb, MSHARE_MAGIC, &empty_descr); + if (err) + return err; + + msharefs_sb = sb; + return 0; +} + +static int +msharefs_get_tree(struct fs_context *fc) +{ + return get_tree_single(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 +mshare_init(void) +{ + int ret = 0; + + 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; +} + +fs_initcall(mshare_init);