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/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/zcopy/Kconfig | 34 ++++++++++++ drivers/misc/zcopy/Makefile | 2 + drivers/misc/zcopy/zcopy.c | 100 ++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+) create mode 100644 drivers/misc/zcopy/Kconfig create mode 100644 drivers/misc/zcopy/Makefile create mode 100644 drivers/misc/zcopy/zcopy.c diff --git a/MAINTAINERS b/MAINTAINERS index 927e9f6aa9ce..f66131aba5a3 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/misc/zcopy/ + THE REST M: Linus Torvalds <torvalds@linux-foundation.org> L: linux-kernel@vger.kernel.org diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index b5184ce9d86e..795061be6412 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -597,4 +597,5 @@ source "drivers/misc/cardreader/Kconfig" source "drivers/misc/uacce/Kconfig" source "drivers/misc/pvpanic/Kconfig" source "drivers/misc/mchp_pci1xxxx/Kconfig" +source "drivers/misc/zcopy/Kconfig" endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 16fe31fbf7d4..8f8419ea28c4 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -69,3 +69,4 @@ obj-$(CONFIG_TMR_MANAGER) += xilinx_tmr_manager.o obj-$(CONFIG_TMR_INJECT) += xilinx_tmr_inject.o obj-$(CONFIG_TPS6594_ESM) += tps6594-esm.o obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o +obj-$(CONFIG_PAGEATTACH) += zcopy/ diff --git a/drivers/misc/zcopy/Kconfig b/drivers/misc/zcopy/Kconfig new file mode 100644 index 000000000000..014fbef3bd79 --- /dev/null +++ b/drivers/misc/zcopy/Kconfig @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0-only +config PAGEATTACH + tristate "PAGEATTACH: A zero-copy data transfer mechanism between processes" + depends on MMU && ARM64 + help + This option enables the PAGEATTACH mechanism, a zero-copy data transfer + solution optimized for High Performance Computing 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. + - 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). If exists + old mappings, the return value is -EAGAIN. For this case, caller should free + the old dst_addr, and alloc a new one to try again. + 2. No internal locking is implemented in the PageAttach interface; Callers + 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 PMD-size-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 like 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/misc/zcopy/Makefile b/drivers/misc/zcopy/Makefile new file mode 100644 index 000000000000..60a6909da314 --- /dev/null +++ b/drivers/misc/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/misc/zcopy/zcopy.c b/drivers/misc/zcopy/zcopy.c new file mode 100644 index 000000000000..acbe3efc99a3 --- /dev/null +++ b/drivers/misc/zcopy/zcopy.c @@ -0,0 +1,100 @@ +// 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) + 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) + goto err_unregister_chrdev; + + z_cdev.dev_class = class_create("zcopy"); + if (IS_ERR(z_cdev.dev_class)) { + 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)) { + 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) + return ret; + + 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