linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nuno Das Neves <nunodasneves@linux.microsoft.com>
To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: virtualization@lists.linux-foundation.org,
	mikelley@microsoft.com, viremana@linux.microsoft.com,
	sunilmut@microsoft.com, wei.liu@kernel.org, vkuznets@redhat.com,
	ligrassi@microsoft.com, kys@microsoft.com,
	sthemmin@microsoft.com, anbelski@linux.microsoft.com
Subject: [PATCH 03/19] drivers/hv: minimal mshv module (/dev/mshv/)
Date: Thu,  5 Aug 2021 14:23:45 -0700	[thread overview]
Message-ID: <1628198641-791-4-git-send-email-nunodasneves@linux.microsoft.com> (raw)
In-Reply-To: <1628198641-791-1-git-send-email-nunodasneves@linux.microsoft.com>

Introduce a barebones module file for the mshv API.
Introduce CONFIG_HYPERV_VMM_API for controlling compilation of mshv.

Co-developed-by: Lillian Grassin-Drake <ligrassi@microsoft.com>
Signed-off-by: Lillian Grassin-Drake <ligrassi@microsoft.com>
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
 arch/x86/hyperv/Makefile |  1 +
 drivers/hv/Kconfig       | 18 ++++++++++
 drivers/hv/Makefile      |  3 ++
 drivers/hv/mshv_main.c   | 77 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+)
 create mode 100644 drivers/hv/mshv_main.c

diff --git a/arch/x86/hyperv/Makefile b/arch/x86/hyperv/Makefile
index 48e2c51464e8..4b5a8a96ba01 100644
--- a/arch/x86/hyperv/Makefile
+++ b/arch/x86/hyperv/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_X86_64)	+= hv_apic.o hv_proc.o
 ifdef CONFIG_X86_64
 obj-$(CONFIG_PARAVIRT_SPINLOCKS)	+= hv_spinlock.o
 endif
+
diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
index 66c794d92391..0fc3fcce3cf7 100644
--- a/drivers/hv/Kconfig
+++ b/drivers/hv/Kconfig
@@ -27,4 +27,22 @@ config HYPERV_BALLOON
 	help
 	  Select this option to enable Hyper-V Balloon driver.
 
+config HYPERV_VMM_API
+	tristate "Microsoft Hypervisor root partition interfaces: /dev/mshv"
+	depends on HYPERV
+	help
+	  Provides access to interfaces for managing guest virtual machines
+	  running under the Microsoft Hypervisor.
+
+	  These interfaces will only work when Linux is running as root
+	  partition on the Microsoft Hypervisor.
+
+	  The interfaces are provided via a device named /dev/mshv.
+
+	  To compile this as a module, choose M here.
+	  The module is named mshv.
+
+	  If unsure, say N.
+
+
 endmenu
diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
index 94daf8240c95..c943fbeb70e7 100644
--- a/drivers/hv/Makefile
+++ b/drivers/hv/Makefile
@@ -2,6 +2,7 @@
 obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
 obj-$(CONFIG_HYPERV_UTILS)	+= hv_utils.o
 obj-$(CONFIG_HYPERV_BALLOON)	+= hv_balloon.o
+obj-$(CONFIG_HYPERV_ROOT_API)   += mshv.o
 
 CFLAGS_hv_trace.o = -I$(src)
 CFLAGS_hv_balloon.o = -I$(src)
@@ -11,3 +12,5 @@ hv_vmbus-y := vmbus_drv.o \
 		 channel_mgmt.o ring_buffer.o hv_trace.o
 hv_vmbus-$(CONFIG_HYPERV_TESTING)	+= hv_debugfs.o
 hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o
+
+mshv-y                          += mshv_main.o
diff --git a/drivers/hv/mshv_main.c b/drivers/hv/mshv_main.c
new file mode 100644
index 000000000000..e44adf91f660
--- /dev/null
+++ b/drivers/hv/mshv_main.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2020, Microsoft Corporation.
+ *
+ * Authors:
+ *   Nuno Das Neves <nudasnev@microsoft.com>
+ *   Lillian Grassin-Drake <ligrassi@microsoft.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+
+MODULE_AUTHOR("Microsoft");
+MODULE_LICENSE("GPL");
+
+static int mshv_dev_open(struct inode *inode, struct file *filp);
+static int mshv_dev_release(struct inode *inode, struct file *filp);
+static long mshv_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg);
+
+static const struct file_operations mshv_dev_fops = {
+	.owner = THIS_MODULE,
+	.open = mshv_dev_open,
+	.release = mshv_dev_release,
+	.unlocked_ioctl = mshv_dev_ioctl,
+	.llseek = noop_llseek,
+};
+
+static struct miscdevice mshv_dev = {
+	.minor = MISC_DYNAMIC_MINOR,
+	.name = "mshv",
+	.fops = &mshv_dev_fops,
+	.mode = 0600,
+};
+
+static long
+mshv_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
+{
+	return -ENOTTY;
+}
+
+static int
+mshv_dev_open(struct inode *inode, struct file *filp)
+{
+	return 0;
+}
+
+static int
+mshv_dev_release(struct inode *inode, struct file *filp)
+{
+	return 0;
+}
+
+static int
+__init mshv_init(void)
+{
+	int ret;
+
+	if (!hv_is_hyperv_initialized())
+		return -ENODEV;
+
+	ret = misc_register(&mshv_dev);
+	if (ret)
+		pr_err("%s: misc device register failed\n", __func__);
+
+	return ret;
+}
+
+static void
+__exit mshv_exit(void)
+{
+	misc_deregister(&mshv_dev);
+}
+
+module_init(mshv_init);
+module_exit(mshv_exit);
-- 
2.23.4


  parent reply	other threads:[~2021-08-05 21:24 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-05 21:23 [PATCH v2 00/19] Microsoft Hypervisor root partition ioctl interface Nuno Das Neves
2021-08-05 21:23 ` [PATCH 01/19] x86/hyperv: convert hyperv statuses to linux error codes Nuno Das Neves
2021-08-05 21:23 ` [PATCH 02/19] x86/hyperv: convert hyperv statuses to strings Nuno Das Neves
2021-08-05 21:23 ` Nuno Das Neves [this message]
2021-08-05 21:23 ` [PATCH 04/19] drivers/hv: check extension ioctl Nuno Das Neves
2021-08-05 21:23 ` [PATCH 05/19] drivers/hv: create partition ioctl Nuno Das Neves
2021-08-05 21:23 ` [PATCH 06/19] drivers/hv: create, initialize, finalize, delete partition hypercalls Nuno Das Neves
2021-08-05 21:23 ` [PATCH 07/19] drivers/hv: withdraw memory hypercall Nuno Das Neves
2021-08-05 21:23 ` [PATCH 08/19] drivers/hv: map and unmap guest memory Nuno Das Neves
2021-08-05 21:23 ` [PATCH 09/19] drivers/hv: create vcpu ioctl Nuno Das Neves
2021-08-05 21:23 ` [PATCH 10/19] drivers/hv: get and set vcpu registers ioctls Nuno Das Neves
2021-08-06 20:08   ` kernel test robot
2021-08-05 21:23 ` [PATCH 11/19] drivers/hv: set up synic pages for intercept messages Nuno Das Neves
2021-08-06  2:50   ` kernel test robot
2021-08-07  2:17   ` kernel test robot
2021-08-05 21:23 ` [PATCH 12/19] drivers/hv: run vp ioctl and isr Nuno Das Neves
2021-08-05 21:23 ` [PATCH 13/19] drivers/hv: install intercept ioctl Nuno Das Neves
2021-08-05 21:23 ` [PATCH 14/19] drivers/hv: assert interrupt ioctl Nuno Das Neves
2021-08-05 21:23 ` [PATCH 15/19] drivers/hv: get and set vp state ioctls Nuno Das Neves
2021-08-05 21:23 ` [PATCH 16/19] drivers/hv: mmap vp register page Nuno Das Neves
2021-08-05 21:23 ` [PATCH 17/19] drivers/hv: get and set partition property ioctls Nuno Das Neves
2021-08-05 21:24 ` [PATCH 18/19] drivers/hv: Add enlightenment bits to create partition ioctl Nuno Das Neves
2021-08-05 21:24 ` [PATCH 19/19] drivers/hv: Translate GVA to GPA Nuno Das Neves
  -- strict thread matches above, loose matches on Subject: below --
2021-05-28 22:43 [PATCH 00/19] Microsoft Hypervisor root partition ioctl interface Nuno Das Neves
2021-05-28 22:43 ` [PATCH 03/19] drivers/hv: minimal mshv module (/dev/mshv/) Nuno Das Neves
2021-05-29  0:01   ` Randy Dunlap
2021-06-01 19:45     ` Nuno Das Neves
2021-06-03  1:28   ` Sunil Muthuswamy
2021-06-23 22:05     ` Nuno Das Neves
2021-06-27 12:00   ` Wei Liu
2021-07-06 15:41     ` Nuno Das Neves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1628198641-791-4-git-send-email-nunodasneves@linux.microsoft.com \
    --to=nunodasneves@linux.microsoft.com \
    --cc=anbelski@linux.microsoft.com \
    --cc=kys@microsoft.com \
    --cc=ligrassi@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=sthemmin@microsoft.com \
    --cc=sunilmut@microsoft.com \
    --cc=viremana@linux.microsoft.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=vkuznets@redhat.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).