diff mbox series

[01/31] ntsync: Introduce the ntsync driver and character device.

Message ID 20240214233645.9273-2-zfigura@codeweavers.com (mailing list archive)
State New
Headers show
Series NT synchronization primitive driver | expand

Commit Message

Elizabeth Figura Feb. 14, 2024, 11:36 p.m. UTC
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>
---
 drivers/misc/Kconfig  |  9 ++++++++
 drivers/misc/Makefile |  1 +
 drivers/misc/ntsync.c | 52 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 drivers/misc/ntsync.c

Comments

Randy Dunlap Feb. 15, 2024, 1:57 a.m. UTC | #1
Hi,

On 2/14/24 15:36, Elizabeth Figura wrote:
> 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>
> ---
>  drivers/misc/Kconfig  |  9 ++++++++
>  drivers/misc/Makefile |  1 +
>  drivers/misc/ntsync.c | 52 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 62 insertions(+)
>  create mode 100644 drivers/misc/ntsync.c
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 4fb291f0bf7c..bdd8a71bd853 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -504,6 +504,15 @@ config OPEN_DICE
>  	  measured boot flow. Userspace can use CDIs for remote attestation
>  	  and sealing.
>  
> +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.

It looks like the "If unsure" line belongs to the OPEN_DICE kconfig entry
above here. If you want one for NTSYNC, please add one.

>  
>  config VCPU_STALL_DETECTOR


> diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c
> new file mode 100644
> index 000000000000..e4969ef90722
> --- /dev/null
> +++ b/drivers/misc/ntsync.c
> @@ -0,0 +1,52 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * ntsync.c - Kernel driver for NT synchronization primitives
> + *
> + * Copyright (C) 2024 Elizabeth Figura

It would be nice to have your email address above...

> + */
> +

> +
> +MODULE_AUTHOR("Elizabeth Figura");

but at least please add it in MODULE_AUTHOR(). Yes it's optional, but
roughly 7900 of 10400 entries do include it (according to my rough
grepping).

Yes, I know that it's in MAINTAINERS.

> +MODULE_DESCRIPTION("Kernel driver for NT synchronization primitives");
> +MODULE_LICENSE("GPL");

thanks.
Elizabeth Figura Feb. 15, 2024, 7:04 p.m. UTC | #2
On Wednesday, 14 February 2024 19:57:23 CST Randy Dunlap wrote:
> Hi,
> 
> On 2/14/24 15:36, Elizabeth Figura wrote:
> > 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>
> > ---
> >  drivers/misc/Kconfig  |  9 ++++++++
> >  drivers/misc/Makefile |  1 +
> >  drivers/misc/ntsync.c | 52 +++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 62 insertions(+)
> >  create mode 100644 drivers/misc/ntsync.c
> > 
> > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > index 4fb291f0bf7c..bdd8a71bd853 100644
> > --- a/drivers/misc/Kconfig
> > +++ b/drivers/misc/Kconfig
> > @@ -504,6 +504,15 @@ config OPEN_DICE
> >  	  measured boot flow. Userspace can use CDIs for remote attestation
> >  	  and sealing.
> >  
> > +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.
> 
> It looks like the "If unsure" line belongs to the OPEN_DICE kconfig entry
> above here. If you want one for NTSYNC, please add one.

Oops, looks like that was a bad rebase :-(

> 
> >  
> >  config VCPU_STALL_DETECTOR
> 
> 
> > diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c
> > new file mode 100644
> > index 000000000000..e4969ef90722
> > --- /dev/null
> > +++ b/drivers/misc/ntsync.c
> > @@ -0,0 +1,52 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * ntsync.c - Kernel driver for NT synchronization primitives
> > + *
> > + * Copyright (C) 2024 Elizabeth Figura
> 
> It would be nice to have your email address above...
> 
> > + */
> > +
> 
> > +
> > +MODULE_AUTHOR("Elizabeth Figura");
> 
> but at least please add it in MODULE_AUTHOR(). Yes it's optional, but
> roughly 7900 of 10400 entries do include it (according to my rough
> grepping).
> 
> Yes, I know that it's in MAINTAINERS.

Will add, thanks. As you guessed I did just pick an arbitrary module to copy.
diff mbox series

Patch

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4fb291f0bf7c..bdd8a71bd853 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -504,6 +504,15 @@  config OPEN_DICE
 	  measured boot flow. Userspace can use CDIs for remote attestation
 	  and sealing.
 
+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
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index ea6ea5bbbc9c..153a3f4837e8 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -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
index 000000000000..e4969ef90722
--- /dev/null
+++ b/drivers/misc/ntsync.c
@@ -0,0 +1,52 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ntsync.c - Kernel driver for NT synchronization primitives
+ *
+ * Copyright (C) 2024 Elizabeth Figura
+ */
+
+#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");
+MODULE_DESCRIPTION("Kernel driver for NT synchronization primitives");
+MODULE_LICENSE("GPL");