hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/release-management/issues/ID3TGE -------------------------------- Initialize the zcopy driver module framework Signed-off-by: Liu Mingrui <liumingrui@huawei.com> --- MAINTAINERS | 5 ++ drivers/Kconfig | 2 + drivers/Makefile | 3 ++ drivers/zcopy/Kconfig | 32 ++++++++++++ drivers/zcopy/Makefile | 2 + drivers/zcopy/zcopy.c | 108 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 152 insertions(+) create mode 100644 drivers/zcopy/Kconfig create mode 100644 drivers/zcopy/Makefile create mode 100644 drivers/zcopy/zcopy.c diff --git a/MAINTAINERS b/MAINTAINERS index 927e9f6aa9ce..32cc0f80a7d0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -24150,6 +24150,11 @@ M: Yibo Dong <dong100@mucse.com> S: Maintained F: drivers/net/ethernet/mucse/ +ZCOPY DRIVER +M: Mingrui Liu <liumingrui@huawei.com> +S: Maintained +F: drivers/zcopy/ + THE REST M: Linus Torvalds <torvalds@linux-foundation.org> L: linux-kernel@vger.kernel.org diff --git a/drivers/Kconfig b/drivers/Kconfig index 35521e3200fa..2b48e9abd144 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -256,4 +256,6 @@ source "drivers/coda/Kconfig" source "drivers/arm/Kconfig" +source "drivers/zcopy/Kconfig" + endmenu diff --git a/drivers/Makefile b/drivers/Makefile index f8e58f0ca2d1..56e2145e7ed6 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -209,3 +209,6 @@ obj-$(CONFIG_ROH) += roh/ obj-$(CONFIG_HISI_VIRTCCA_CODA) += coda/ obj-$(CONFIG_ARM_SPE_MEM_SAMPLING) += arm/mm_monitor/ + +# PAGE_ATTACH zero-copy communication between processes +obj-$(CONFIG_PAGEATTACH) += zcopy/ diff --git a/drivers/zcopy/Kconfig b/drivers/zcopy/Kconfig new file mode 100644 index 000000000000..653c0a016e5c --- /dev/null +++ b/drivers/zcopy/Kconfig @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: GPL-2.0-only +config PAGEATTACH + tristate "PAGEATTACH: A zero-copy data transfer mechanism for HPC" + depends on MMU && ARM64 + help + This option enables the PAGEATTACH mechanism, a zero-copy data transfer + solution optimized for High Performance Computing (HPC) workloads. It + allows direct sharing of physical memory pages between distinct processes + by mapping source pages to a target address space, eliminating redundant + data copying and improving large data transfer efficiency. + + Key features: + - Supports zero-copy communication between intra-node processes. + - Handles both PTE-level small pages and PMD-level huge pages (2MB). + - Preserves the read/write permissions of the source page in the target address space. + + Important constraints and requirements: + 1. Callers must ensure the source address is already mapped to physical pages, + while the destination address is unused (no existing mappings). + 2. No internal locking is implemented in the PageAttach interface; userspace + must manage memory mapping and release order to avoid race conditions. + 3. Source and destination must be different processes (not threads of the same process). + 4. Only user-space addresses are supported; kernel addresses cannot be mapped. + 5. Both source and destination processes must remain alive during the mapping operation. + 6. PUD-level huge pages are not supported in current implementation. + 7. The start address and size of both source and destination must be 2MB-aligned. + 8. Callers are responsible for ensuring safe access to mapped pages after attachment, + as permissions are inherited from the source. + + This mechanism is intended for HPC applications requiring high-speed inter-process + data sharing. If your use case does not meet the above constraints or you are unsure, + disable this option by saying N. diff --git a/drivers/zcopy/Makefile b/drivers/zcopy/Makefile new file mode 100644 index 000000000000..60a6909da314 --- /dev/null +++ b/drivers/zcopy/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_PAGEATTACH) += zcopy.o \ No newline at end of file diff --git a/drivers/zcopy/zcopy.c b/drivers/zcopy/zcopy.c new file mode 100644 index 000000000000..4e8657e07831 --- /dev/null +++ b/drivers/zcopy/zcopy.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (C) 2025. Huawei Technologies Co., Ltd */ + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/ioctl.h> +#include <linux/fs.h> +#include <linux/cdev.h> +#include <linux/uaccess.h> + +struct zcopy_cdev { + struct cdev chrdev; + dev_t dev; + int major; + struct class *dev_class; + struct device *dev_device; +}; + +static struct zcopy_cdev z_cdev; + +static long zcopy_ioctl(struct file *file, unsigned int type, unsigned long ptr) +{ + return 0; +} + +static const struct file_operations zcopy_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = zcopy_ioctl, +}; + +static int register_device_zcopy(void) +{ + int ret; + + ret = alloc_chrdev_region(&z_cdev.dev, 0, 1, "zcopy"); + if (ret < 0) { + pr_err("alloc chrdev failed\n"); + goto err_out; + } + + z_cdev.major = MAJOR(z_cdev.dev); + + cdev_init(&z_cdev.chrdev, &zcopy_fops); + ret = cdev_add(&z_cdev.chrdev, z_cdev.dev, 1); + if (ret < 0) { + pr_err("add char device failed\n"); + goto err_unregister_chrdev; + } + + z_cdev.dev_class = class_create("zcopy"); + if (IS_ERR(z_cdev.dev_class)) { + pr_err("class create error\n"); + ret = PTR_ERR(z_cdev.dev_class); + goto err_cdev_del; + } + + z_cdev.dev_device = device_create(z_cdev.dev_class, NULL, + MKDEV(z_cdev.major, 0), NULL, "zdax"); + if (IS_ERR(z_cdev.dev_device)) { + pr_err("device create error\n"); + ret = PTR_ERR(z_cdev.dev_device); + goto err_class_destroy; + } + + return 0; + +err_class_destroy: + class_destroy(z_cdev.dev_class); +err_cdev_del: + cdev_del(&z_cdev.chrdev); +err_unregister_chrdev: + unregister_chrdev_region(z_cdev.dev, 1); +err_out: + return ret; +} + +static void unregister_device_zcopy(void) +{ + device_destroy(z_cdev.dev_class, MKDEV(z_cdev.major, 0)); + class_destroy(z_cdev.dev_class); + cdev_del(&z_cdev.chrdev); + unregister_chrdev_region(z_cdev.dev, 1); +} + +static int __init zcopy_init(void) +{ + int ret; + + ret = register_device_zcopy(); + if (ret) { + pr_err("register_device_zcopy failed\n"); + return -1; + } + + return 0; +} + +static void __exit zcopy_exit(void) +{ + unregister_device_zcopy(); +} + +module_init(zcopy_init); +module_exit(zcopy_exit); + +MODULE_AUTHOR("liumingrui <liumingrui@huawei.com>"); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("PAGEATTACH: A zero-copy data transfer mechanism"); -- 2.25.1