ntsync: Introduce the ntsync driver and character device.
authorElizabeth Figura <zfigura@codeweavers.com>
Fri, 29 Mar 2024 00:05:52 +0000 (19:05 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 Apr 2024 13:34:36 +0000 (15:34 +0200)
ntsync uses a misc device as the simplest and least intrusive uAPI interface.

Each file description on the device represents an isolated NT instance, intended
to correspond to a single NT virtual machine.

Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com>
Link: https://lore.kernel.org/r/20240329000621.148791-2-zfigura@codeweavers.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/ntsync.c [new file with mode: 0644]

index 4fb291f0bf7c89863868c1fc066de3c443ebf377..801ed229ed7dc176346f9056f639388ad8db0071 100644 (file)
@@ -506,6 +506,17 @@ config OPEN_DICE
 
          If unsure, say N.
 
+config NTSYNC
+       tristate "NT synchronization primitive emulation"
+       help
+         This module provides kernel support for emulation of Windows NT
+         synchronization primitives. It is not a hardware driver.
+
+         To compile this driver as a module, choose M here: the
+         module will be called ntsync.
+
+         If unsure, say N.
+
 config VCPU_STALL_DETECTOR
        tristate "Guest vCPU stall detector"
        depends on OF && HAS_IOMEM
index ea6ea5bbbc9c62c4620ba59a65b3e7d776019f39..153a3f4837e8caab8f865fe96cc7ebf0ac33716f 100644 (file)
@@ -59,6 +59,7 @@ obj-$(CONFIG_PVPANIC)         += pvpanic/
 obj-$(CONFIG_UACCE)            += uacce/
 obj-$(CONFIG_XILINX_SDFEC)     += xilinx_sdfec.o
 obj-$(CONFIG_HISI_HIKEY_USB)   += hisi_hikey_usb.o
+obj-$(CONFIG_NTSYNC)           += ntsync.o
 obj-$(CONFIG_HI6421V600_IRQ)   += hi6421v600-irq.o
 obj-$(CONFIG_OPEN_DICE)                += open-dice.o
 obj-$(CONFIG_GP_PCI1XXXX)      += mchp_pci1xxxx/
diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c
new file mode 100644 (file)
index 0000000..bd76e65
--- /dev/null
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ntsync.c - Kernel driver for NT synchronization primitives
+ *
+ * Copyright (C) 2024 Elizabeth Figura <zfigura@codeweavers.com>
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+
+#define NTSYNC_NAME    "ntsync"
+
+static int ntsync_char_open(struct inode *inode, struct file *file)
+{
+       return nonseekable_open(inode, file);
+}
+
+static int ntsync_char_release(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static long ntsync_char_ioctl(struct file *file, unsigned int cmd,
+                             unsigned long parm)
+{
+       switch (cmd) {
+       default:
+               return -ENOIOCTLCMD;
+       }
+}
+
+static const struct file_operations ntsync_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ntsync_char_open,
+       .release        = ntsync_char_release,
+       .unlocked_ioctl = ntsync_char_ioctl,
+       .compat_ioctl   = compat_ptr_ioctl,
+       .llseek         = no_llseek,
+};
+
+static struct miscdevice ntsync_misc = {
+       .minor          = MISC_DYNAMIC_MINOR,
+       .name           = NTSYNC_NAME,
+       .fops           = &ntsync_fops,
+};
+
+module_misc_device(ntsync_misc);
+
+MODULE_AUTHOR("Elizabeth Figura <zfigura@codeweavers.com>");
+MODULE_DESCRIPTION("Kernel driver for NT synchronization primitives");
+MODULE_LICENSE("GPL");