From patchwork Mon Feb 5 12:01:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gowans, James" X-Patchwork-Id: 13545314 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 01962C48291 for ; Mon, 5 Feb 2024 12:02:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86C456B0082; Mon, 5 Feb 2024 07:02:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F4076B0083; Mon, 5 Feb 2024 07:02:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66E2B6B0085; Mon, 5 Feb 2024 07:02:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5337F6B0082 for ; Mon, 5 Feb 2024 07:02:32 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 21E62A1876 for ; Mon, 5 Feb 2024 12:02:32 +0000 (UTC) X-FDA: 81757612944.16.758EABA Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) by imf20.hostedemail.com (Postfix) with ESMTP id C76D01C0021 for ; Mon, 5 Feb 2024 12:02:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=b3mmLUM8; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf20.hostedemail.com: domain of "prvs=75897cb1d=jgowans@amazon.com" designates 207.171.188.206 as permitted sender) smtp.mailfrom="prvs=75897cb1d=jgowans@amazon.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707134549; 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=ulQJ3D4Me8ScxlcztMMDIgEvnR/mGPMynfspToLkF2M=; b=zwH8vBVPJ9c00JcLtYJttGY8sMz6+qogayUhjflvAFZ2tgpmrROTwUjyc0LRfbsjrYoc5V qQXcyJd7H6u6u50H+m2EI1JcmtKCLL1mcu0RhPsZJeo8caYoaufIK1OfgeNsw8ns9pR534 rox+GpktS7y22g5fB6XjQTTlvZJHHQ4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=b3mmLUM8; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf20.hostedemail.com: domain of "prvs=75897cb1d=jgowans@amazon.com" designates 207.171.188.206 as permitted sender) smtp.mailfrom="prvs=75897cb1d=jgowans@amazon.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707134549; a=rsa-sha256; cv=none; b=w+B9wCTRViKxarj8M7I1d7DMIA7wZtAyK8o1l2Lr+sV/udnZj7vGdkxKZ6nnsr7h6o9XoC 22BvKf3XWFmAqP0FfdKqzKsR3SCO0K8QEa9vMW2C5Xu+Ms0w3Lyemt8IH2dq47tspvIUpb vbPatnoFxzdAhWPV4gzbPqWHLS8XgAc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1707134549; x=1738670549; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ulQJ3D4Me8ScxlcztMMDIgEvnR/mGPMynfspToLkF2M=; b=b3mmLUM8uxUdbQnSkV2tBea6B5synisslurnQMLhT1Y48dqsPRoeoRTI 6zWc/GGxW9avbDPVCdKxH58P9Dr0k5iHKpkCzx+wqjbVJk03MVe6yB7e7 EYdCy2Rd/TN/Ur0HgkAZqbavOeRmsOHJuvj7iR+0Yjh9S/ByJIIE4Kmac g=; X-IronPort-AV: E=Sophos;i="6.05,245,1701129600"; d="scan'208";a="702145833" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 12:02:22 +0000 Received: from EX19MTAEUB002.ant.amazon.com [10.0.43.254:59802] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.28.192:2525] with esmtp (Farcaster) id c85ecf83-e3a4-4c42-963b-1a5c7099c0b7; Mon, 5 Feb 2024 12:02:20 +0000 (UTC) X-Farcaster-Flow-ID: c85ecf83-e3a4-4c42-963b-1a5c7099c0b7 Received: from EX19D014EUC004.ant.amazon.com (10.252.51.182) by EX19MTAEUB002.ant.amazon.com (10.252.51.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:02:20 +0000 Received: from dev-dsk-jgowans-1a-a3faec1f.eu-west-1.amazon.com (172.19.112.191) by EX19D014EUC004.ant.amazon.com (10.252.51.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:02:14 +0000 From: James Gowans To: CC: Eric Biederman , , "Joerg Roedel" , Will Deacon , , Alexander Viro , "Christian Brauner" , , Paolo Bonzini , Sean Christopherson , , Andrew Morton , , Alexander Graf , David Woodhouse , "Jan H . Schoenherr" , Usama Arif , Anthony Yznaga , Stanislav Kinsburskii , , , Subject: [RFC 01/18] pkernfs: Introduce filesystem skeleton Date: Mon, 5 Feb 2024 12:01:46 +0000 Message-ID: <20240205120203.60312-2-jgowans@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205120203.60312-1-jgowans@amazon.com> References: <20240205120203.60312-1-jgowans@amazon.com> MIME-Version: 1.0 X-Originating-IP: [172.19.112.191] X-ClientProxiedBy: EX19D045UWA002.ant.amazon.com (10.13.139.12) To EX19D014EUC004.ant.amazon.com (10.252.51.182) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C76D01C0021 X-Stat-Signature: p51m9uk9wf1zdqsrpczxpycqyayojnbj X-Rspam-User: X-HE-Tag: 1707134548-226095 X-HE-Meta: U2FsdGVkX1/KQpWGZCWsiV5LxH43T4M+KeVElH9tUMph2yoJ8Wp7jYs5TCBVK3voFb4PY56hu6C4uedS6wikycbyePcGM5Y45+iyi50sCpg4ve4bJVHKg/RzO0kubwKshNt6LNnr+7AeMpS/AUbz1J0nZ5Qq+MrEe16q3+S2wXulN6200E/J/fQ1MeQMq2BkGQIGpkYBjTquAADRAa2GZ7na2D0ZNAK1oCtvH4t27Ni+WqSBIMYgPyHAagcSwnDmnXPfboR4vP+sLSU4IA6/HuSxi3p5HpPXkmyF4LjKhdDjveZ/d5tzOdfQ89B4W9eAM+Taw36lvbG/uE7Md9HuN5BdiYsbMz02us+puu7TWONSetkx5ZkSwlRM1BwAsyQ13P9drXdQ+Vn9VMZKEoN047shND9u35EEUdunNNGpfDMGBgSX4DKF958goytsEoqHui2OQXRw37ThOflH2xGBVHy++26TAfGQn+zgd9ne6COY1KTT1IZ3Vm2Cxt2GBZUw2gl21odG6QbCfvna+cFYO6gLMb/kci3QxJClDuqzAin+fIwvO9lve6jEq7fdKkUkPNxslQq+YPGwXjk2cbBDZKS6qRT7GRdLv3cjcWqCrwMk/byhVOfKC52Mchp5CkN2my4l5tqoIiMz8S2OjtpfUfsT28v2KPE/qSsMFCaq5jAGDzrifUXXRgADOZyxXI3JfrO8Y4nPIdLeyis1c0yFutE/WgCw1SEjnQKk3Y6KKrk7kB9erWMwqR/jk3KfPwh6LKBoYo3WwU1pjfk7vHcCbwOHs0rGEBeilgyR5gYAFs1zptfeHyGKbnO8Z2HHYtPxQi+nblPRmXUlfXWlGeJO7BMsNXNIH5sHiIUxkUCc60CXIhZugWrim/inud+CthyYE8nVOI4FyySPQmXqjlvd/Jx+qusRaqSDpFuMpwfD/CDZHrN/+9fRlCcHS2SGb6iLWoaY3EmtZguwFVEqoaD zIL5WBx6 ApBD+f5eKbycCiQDw4RKSRwpwu9sBYpL2dcupd91pTuswtSX5QpCoWhO9AXDn6EMLkt3zLOLwtXl3S5BbRzVMiIeWTRd3JUveDh0x1XRinu/9nPlFT8+FYUjZiImR7lzBlctG933w0KjBtIO84FSIDhCVSxxePGOBpvUeqEPlURAycjboSPASGeIZ8x/mWH+UopH8JQnJd/NO8CJ16+j721ojNwyhPUaGY/rrZp8MTBNcZRdooeohrt1Uu1Lz+oOn532Y3GzeQloI20qemFckvjN0GNRaDTo6MSHdKNR5IPcgV4jOUrtGnIHHLbp1GGHjkhZAV8mVz3aLZhaNiNR2KKugDF7PQ1b+2qcsJW+jGoQ8/3C8vTIDkGsRuBiDmkYwpD3FLMNoS5+CHtdcyHeid3gpdsq+0XJ1W9ha9PSOrhjpRYfT2bthhfKGcjLR3y+Rr8FsEABPUJo0ze27icU7sfwrSSOmGYbX1ODUvwOsM/8xYjD0MxLS9PZ2ssEuc/xKIl3iuphr5qGPChHC7AhG6l3yCjFtfVXETWbgODEgo+2HKuIyBaLbqrA6Qg== 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 in-memory filesystem: pkernfs. Memory is donated to pkernfs by carving it out of the normal System RAM range with the memmap= cmdline parameter and then giving that same physical range to pkernfs with the pkernfs= cmdline parameter. A new filesystem is added; so far it doesn't do much except persist a super block at the start of the donated memory and allows itself to be mounted. --- fs/Kconfig | 1 + fs/Makefile | 3 ++ fs/pkernfs/Kconfig | 9 ++++ fs/pkernfs/Makefile | 6 +++ fs/pkernfs/pkernfs.c | 99 ++++++++++++++++++++++++++++++++++++++++++++ fs/pkernfs/pkernfs.h | 6 +++ 6 files changed, 124 insertions(+) create mode 100644 fs/pkernfs/Kconfig create mode 100644 fs/pkernfs/Makefile create mode 100644 fs/pkernfs/pkernfs.c create mode 100644 fs/pkernfs/pkernfs.h diff --git a/fs/Kconfig b/fs/Kconfig index aa7e03cc1941..33a9770ae657 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -331,6 +331,7 @@ source "fs/sysv/Kconfig" source "fs/ufs/Kconfig" source "fs/erofs/Kconfig" source "fs/vboxsf/Kconfig" +source "fs/pkernfs/Kconfig" endif # MISC_FILESYSTEMS diff --git a/fs/Makefile b/fs/Makefile index f9541f40be4e..1af35b494b5d 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -19,6 +19,9 @@ obj-y := open.o read_write.o file_table.o super.o \ obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o obj-$(CONFIG_PROC_FS) += proc_namespace.o + +obj-y += pkernfs/ + obj-$(CONFIG_LEGACY_DIRECT_IO) += direct-io.o obj-y += notify/ obj-$(CONFIG_EPOLL) += eventpoll.o diff --git a/fs/pkernfs/Kconfig b/fs/pkernfs/Kconfig new file mode 100644 index 000000000000..59621a1d9aef --- /dev/null +++ b/fs/pkernfs/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config PKERNFS_FS + bool "Persistent Kernel filesystem (pkernfs)" + help + An in-memory filesystem on top of reserved memory specified via + pkernfs= cmdline argument. Used for storing kernel state and + userspace memory which is preserved across kexec to support + live update. diff --git a/fs/pkernfs/Makefile b/fs/pkernfs/Makefile new file mode 100644 index 000000000000..17258cb77f58 --- /dev/null +++ b/fs/pkernfs/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for persistent kernel filesystem +# + +obj-$(CONFIG_PKERNFS_FS) += pkernfs.o diff --git a/fs/pkernfs/pkernfs.c b/fs/pkernfs/pkernfs.c new file mode 100644 index 000000000000..4c476ddc35b6 --- /dev/null +++ b/fs/pkernfs/pkernfs.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include "pkernfs.h" +#include +#include +#include +#include +#include + +static phys_addr_t pkernfs_base, pkernfs_size; +static void *pkernfs_mem; +static const struct super_operations pkernfs_super_ops = { }; + +static int pkernfs_fill_super(struct super_block *sb, struct fs_context *fc) +{ + struct inode *inode; + struct dentry *dentry; + struct pkernfs_sb *psb; + + pkernfs_mem = memremap(pkernfs_base, pkernfs_size, MEMREMAP_WB); + psb = (struct pkernfs_sb *) pkernfs_mem; + + if (psb->magic_number == PKERNFS_MAGIC_NUMBER) { + pr_info("pkernfs: Restoring from super block\n"); + } else { + pr_info("pkernfs: Clean super block; initialising\n"); + psb->magic_number = PKERNFS_MAGIC_NUMBER; + } + + sb->s_op = &pkernfs_super_ops; + + inode = new_inode(sb); + if (!inode) + return -ENOMEM; + + inode->i_ino = 1; + inode->i_mode = S_IFDIR; + inode->i_op = &simple_dir_inode_operations; + inode->i_fop = &simple_dir_operations; + inode->i_atime = inode->i_mtime = current_time(inode); + inode_set_ctime_current(inode); + /* directory inodes start off with i_nlink == 2 (for "." entry) */ + inc_nlink(inode); + + dentry = d_make_root(inode); + if (!dentry) + return -ENOMEM; + sb->s_root = dentry; + + return 0; +} + +static int pkernfs_get_tree(struct fs_context *fc) +{ + return get_tree_nodev(fc, pkernfs_fill_super); +} + +static const struct fs_context_operations pkernfs_context_ops = { + .get_tree = pkernfs_get_tree, +}; + +static int pkernfs_init_fs_context(struct fs_context *const fc) +{ + fc->ops = &pkernfs_context_ops; + return 0; +} + +static struct file_system_type pkernfs_fs_type = { + .owner = THIS_MODULE, + .name = "pkernfs", + .init_fs_context = pkernfs_init_fs_context, + .kill_sb = kill_litter_super, + .fs_flags = FS_USERNS_MOUNT, +}; + +static int __init pkernfs_init(void) +{ + int ret; + + ret = register_filesystem(&pkernfs_fs_type); + return ret; +} + +/** + * Format: pkernfs=: + * Just like: memmap=nn[KMG]!ss[KMG] + */ +static int __init parse_pkernfs_extents(char *p) +{ + pkernfs_size = memparse(p, &p); + p++; /* Skip over ! char */ + pkernfs_base = memparse(p, &p); + return 0; +} + +early_param("pkernfs", parse_pkernfs_extents); + +MODULE_ALIAS_FS("pkernfs"); +module_init(pkernfs_init); diff --git a/fs/pkernfs/pkernfs.h b/fs/pkernfs/pkernfs.h new file mode 100644 index 000000000000..bd1e2a6fd336 --- /dev/null +++ b/fs/pkernfs/pkernfs.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#define PKERNFS_MAGIC_NUMBER 0x706b65726e6673 +struct pkernfs_sb { + unsigned long magic_number; +};