Skip to contentSkip to conversation

add POWER Virtual Management Channel driver

PATCH In review Steven Royer 3 participants 7 messages Feb 16, 2016 – Feb 18, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add POWER Virtual Management Channel driver

From: Steven Royer <[email protected]>

The ibmvmc driver is a device driver for the POWER Virtual Management Channel virtual adapter on the PowerVM platform. It is used to communicate with the hypervisor for virtualization management. It provides both request/response and asynchronous message support through the /dev/ibmvmc node.

---
This is used by the PowerVM NovaLink project. You can see development history on github:
https://github.com/powervm/ibmvmc

 Documentation/ioctl/ioctl-number.txt |    1 +
 MAINTAINERS                          |    5 +
 arch/powerpc/include/asm/hvcall.h    |    3 +-
 drivers/misc/Kconfig                 |    9 +
 drivers/misc/Makefile                |    1 +
 drivers/misc/ibmvmc.c                | 1882 ++++++++++++++++++++++++++++++++++
 drivers/misc/ibmvmc.h                |  203 ++++
 7 files changed, 2103 insertions(+), 1 deletion(-)
 create mode 100644 drivers/misc/ibmvmc.c
 create mode 100644 drivers/misc/ibmvmc.h
Documentation/ioctl/ioctl-number.txt +1 -0
index 91261a3..d5f5f4f 100644
@@ -324,6 +324,7 @@ Code  Seq#(hex)	Include File		Comments
 0xCA	80-8F	uapi/scsi/cxlflash_ioctl.h
 0xCB	00-1F	CBM serial IEC bus	in development:
 					<mailto:[email protected]>
+0xCC	00-0F	drivers/misc/ibmvmc.h	pseries VMC driver
 0xCD	01	linux/reiserfs_fs.h
 0xCF	02	fs/cifs/ioctl.c
 0xDB	00-0F	drivers/char/mwave/mwavepub.h
MAINTAINERS +5 -0
index cc2f753..c39dca2 100644
@@ -5353,6 +5353,11 @@ L:	[email protected]
 S:	Supported
 F:	drivers/net/ethernet/ibm/ibmvnic.*
 
+IBM Power Virtual Management Channel Driver
+M:	Steven Royer <[email protected]>
+S:	Supported
+F:	drivers/misc/ibmvmc.*
+
 IBM Power Virtual SCSI Device Drivers
 M:	Tyrel Datwyler <[email protected]>
 L:	[email protected]
arch/powerpc/include/asm/hvcall.h +2 -1
index e3b54dd..1ee6f2b 100644
@@ -274,7 +274,8 @@
 #define H_COP			0x304
 #define H_GET_MPP_X		0x314
 #define H_SET_MODE		0x31C
-#define MAX_HCALL_OPCODE	H_SET_MODE
+#define H_REQUEST_VMC		0x360
+#define MAX_HCALL_OPCODE	H_REQUEST_VMC
 
 /* H_VIOCTL functions */
 #define H_GET_VIOA_DUMP_SIZE	0x01
drivers/misc/Kconfig +9 -0
index 054fc10..f8d9113 100644
@@ -526,6 +526,15 @@ config VEXPRESS_SYSCFG
 	  bus. System Configuration interface is one of the possible means
 	  of generating transactions on this bus.
 
+config IBMVMC
+	tristate "IBM Virtual Management Channel support"
+	depends on PPC_PSERIES
+	help
+	  This is the IBM POWER Virtual Management Channel
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ibmvmc.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index 537d7f3..08336b3 100644
@@ -56,3 +56,4 @@ obj-$(CONFIG_GENWQE)		+= genwqe/
 obj-$(CONFIG_ECHO)		+= echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)		+= cxl/
+obj-$(CONFIG_IBMVMC)		+= ibmvmc.o
drivers/misc/ibmvmc.c new file +1882 -0

1,882 lines not on this page · raw message

drivers/misc/ibmvmc.h new file +203 -0

203 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw
Quoted 7 lines · Steven Royer

From: Steven Royer <[email protected]>

The ibmvmc driver is a device driver for the POWER Virtual Management Channel virtual adapter on the PowerVM platform. It is used to communicate with the hypervisor for virtualization management. It provides both request/response and asynchronous message support through the /dev/ibmvmc node.

What is the protocol for that device node?

Where is the documentation here? Why does this have to be a character device? Why can't it fit in with other drivers of this type?

Quoted 96 lines

---
This is used by the PowerVM NovaLink project. You can see development history on github:
https://github.com/powervm/ibmvmc

 Documentation/ioctl/ioctl-number.txt |    1 +
 MAINTAINERS                          |    5 +
 arch/powerpc/include/asm/hvcall.h    |    3 +-
 drivers/misc/Kconfig                 |    9 +
 drivers/misc/Makefile                |    1 +
 drivers/misc/ibmvmc.c                | 1882 ++++++++++++++++++++++++++++++++++
 drivers/misc/ibmvmc.h                |  203 ++++
 7 files changed, 2103 insertions(+), 1 deletion(-)
 create mode 100644 drivers/misc/ibmvmc.c
 create mode 100644 drivers/misc/ibmvmc.h
Documentation/ioctl/ioctl-number.txt +1 -0
index 91261a3..d5f5f4f 100644
@@ -324,6 +324,7 @@ Code  Seq#(hex)	Include File		Comments
 0xCA	80-8F	uapi/scsi/cxlflash_ioctl.h
 0xCB	00-1F	CBM serial IEC bus	in development:
 					<mailto:[email protected]>
+0xCC	00-0F	drivers/misc/ibmvmc.h	pseries VMC driver
 0xCD	01	linux/reiserfs_fs.h
 0xCF	02	fs/cifs/ioctl.c
 0xDB	00-0F	drivers/char/mwave/mwavepub.h
MAINTAINERS +5 -0
index cc2f753..c39dca2 100644
@@ -5353,6 +5353,11 @@ L:	[email protected]
 S:	Supported
 F:	drivers/net/ethernet/ibm/ibmvnic.*
 
+IBM Power Virtual Management Channel Driver
+M:	Steven Royer <[email protected]>
+S:	Supported
+F:	drivers/misc/ibmvmc.*
+
 IBM Power Virtual SCSI Device Drivers
 M:	Tyrel Datwyler <[email protected]>
 L:	[email protected]
arch/powerpc/include/asm/hvcall.h +2 -1
index e3b54dd..1ee6f2b 100644
@@ -274,7 +274,8 @@
 #define H_COP			0x304
 #define H_GET_MPP_X		0x314
 #define H_SET_MODE		0x31C
-#define MAX_HCALL_OPCODE	H_SET_MODE
+#define H_REQUEST_VMC		0x360
+#define MAX_HCALL_OPCODE	H_REQUEST_VMC
 
 /* H_VIOCTL functions */
 #define H_GET_VIOA_DUMP_SIZE	0x01
drivers/misc/Kconfig +9 -0
index 054fc10..f8d9113 100644
@@ -526,6 +526,15 @@ config VEXPRESS_SYSCFG
 	  bus. System Configuration interface is one of the possible means
 	  of generating transactions on this bus.
 
+config IBMVMC
+	tristate "IBM Virtual Management Channel support"
+	depends on PPC_PSERIES
+	help
+	  This is the IBM POWER Virtual Management Channel
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ibmvmc.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index 537d7f3..08336b3 100644
@@ -56,3 +56,4 @@ obj-$(CONFIG_GENWQE)		+= genwqe/
 obj-$(CONFIG_ECHO)		+= echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)		+= cxl/
+obj-$(CONFIG_IBMVMC)		+= ibmvmc.o
drivers/misc/ibmvmc.c new file +2 -0
new file mode 100644
index 0000000..fb943b7
@@ -0,0 +1,1882 @@
+/*
+ * IBM Power Systems Virtual Management Channel Support.

drivers/misc/ibmvmc.c line 12

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+ *
+ * Copyright (c) 2004, 2016 IBM Corp.
+ *   Dave Engebretsen [email protected]
+ *   Steven Royer [email protected]
+ *   Adam Reznechek [email protected]
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.

I have to ask, but do you really mean "or any later version"?

Quoted 17 lines
drivers/misc/ibmvmc.c new file +17 -0
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/major.h>
+#include <linux/string.h>
+#include <linux/fcntl.h>
+#include <linux/slab.h>
+#include <linux/poll.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>

drivers/misc/ibmvmc.c line 39

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+#include <linux/spinlock.h>
+#include <linux/percpu.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
+#include <linux/device.h>
+
+#include <asm/byteorder.h>
+#include <asm/irq.h>
+#include <asm/vio.h>

Why are these asm files needed?

drivers/misc/ibmvmc.c line 41

Quoted 2 lines
drivers/misc/ibmvmc.c new file +2 -0
+
+#include "ibmvmc.h"

Why do you have a .h file for a single-file driver? That shouldn't be needed at all, unless you have an odd user api, and if so, it better be documented...

Quoted 17 lines
drivers/misc/ibmvmc.c new file +17 -0
+
+#define IBMVMC_DRIVER_VERSION "1.0"
+
+MODULE_DESCRIPTION("IBM VMC");
+MODULE_AUTHOR("Steven Royer <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(IBMVMC_DRIVER_VERSION);
+
+
+/*
+ * Static global variables
+ */
+static DECLARE_WAIT_QUEUE_HEAD(ibmvmc_read_wait);
+
+static const char ibmvmc_driver_name[] = "ibmvmc";
+static const char ibmvmc_workq_name[] = "ibmvmc";
+

drivers/misc/ibmvmc.c line 68

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+static struct ibmvmc_struct ibmvmc;
+static struct ibmvmc_hmc hmcs[MAX_HMCS];
+static struct crq_server_adapter ibmvmc_adapter;
+static dev_t ibmvmc_chrdev;
+
+static int ibmvmc_max_buf_pool_size = DEFAULT_BUF_POOL_SIZE;
+static int ibmvmc_max_hmcs = DEFAULT_HMCS;
+static int ibmvmc_max_mtu = DEFAULT_MTU;
+static struct class *ibmvmc_class;
+struct device *ibmvmc_dev;

Those are huge flags to me, why would you ever have a static pointer to a device? You should never deal with a "raw" struct device, unless something is really odd...

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+
+/* Module parameters */
+module_param_named(buf_pool_size, ibmvmc_max_buf_pool_size,
+		   int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(buf_pool_size, "Buffer pool size");
+module_param_named(max_hmcs, ibmvmc_max_hmcs, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(max_hmcs, "Max HMCs");
+module_param_named(max_mtu, ibmvmc_max_mtu, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(max_mtu, "Max MTU");
+

drivers/misc/ibmvmc.c line 88

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+
+static inline long h_copy_rdma(s64 length, u64 sliobn, u64 slioba,
+	u64 dliobn, u64 dlioba)
+{
+	long rc = 0;
+
+	/* Ensure all writes to source memory are visible before hcall */
+	mb();
+	pr_debug("ibmvmc: h_copy_rdma(0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx\n",
+			length, sliobn, slioba, dliobn, dlioba);

It's a driver, use dev_dbg() please.

Quoted 7 lines
drivers/misc/ibmvmc.c new file +7 -0
+	rc = plpar_hcall_norets(H_COPY_RDMA, length, sliobn, slioba,
+			dliobn, dlioba);
+	pr_debug("ibmvmc: h_copy_rdma rc = 0x%lx\n", rc);
+
+	return rc;
+}
+

drivers/misc/ibmvmc.c line 105

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+static inline void h_free_crq(uint32_t unit_address)
+{
+	long rc = 0;
+
+	do {
+		if (H_IS_LONG_BUSY(rc))
+			msleep(get_longbusy_msecs(rc));
+
+		rc = plpar_hcall_norets(H_FREE_CRQ, unit_address);
+	} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));

endless loop? Not good.

Quoted 14 lines
drivers/misc/ibmvmc.c new file +14 -0
+}
+
+/**
+ * h_request_vmc: - request a hypervisor virtual management channel device
+ * @vmc_index: drc index of the vmc device created
+ *
+ * Requests the hypervisor create a new virtual management channel device,
+ * allowing this partition to send hypervisor virtualization control commands.
+ *
+ */
+static inline long h_request_vmc(u32 *vmc_index)
+{
+	long rc = 0;
+	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];

drivers/misc/ibmvmc.c line 129

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+
+	do {
+		if (H_IS_LONG_BUSY(rc))
+			msleep(get_longbusy_msecs(rc));
+
+		/* Call to request the VMC device from phyp */
+		rc = plpar_hcall(H_REQUEST_VMC, retbuf);
+		pr_debug("ibmvmc: h_request_vmc rc = 0x%lx\n", rc);
+		*vmc_index = retbuf[0];
+	} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));

Another endless loop? Your hardware must never fail :)

Quoted 12 lines
drivers/misc/ibmvmc.c new file +12 -0
+
+	return rc;
+}
+
+/* routines for managing a command/response queue */
+/**
+ * ibmvmc_handle_event: - Interrupt handler for crq events
+ * @irq:        number of irq to handle, not used
+ * @dev_instance: crq_server_adapter that received interrupt
+ *
+ * Disables interrupts and schedules ibmvmc_task
+ * Always returns IRQ_HANDLED

drivers/misc/ibmvmc.c line 151

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+ */
+static irqreturn_t ibmvmc_handle_event(int irq, void *dev_instance)
+{
+	struct crq_server_adapter *adapter =
+		(struct crq_server_adapter *)dev_instance;
+
+	vio_disable_interrupts(to_vio_dev(adapter->dev));
+	queue_work(adapter->work_queue, &adapter->work);
+
+	return IRQ_HANDLED;

No shared interrupt handling?

drivers/misc/ibmvmc.c line 1802

Quoted 9 lines
drivers/misc/ibmvmc.c new file +9 -0
+}
+
+	/* Dynamically allocate ibmvmc major number */
+	if (alloc_chrdev_region(&ibmvmc_chrdev, 0, VMC_NUM_MINORS,
+		ibmvmc_driver_name)) {
+		pr_err("ibmvmc: unable to allocate a dev_t\n");
+		rc = -EIO;
+		goto alloc_chrdev_failed;
+	}

A whole major number for one minor? Use the misc class instead please.

And finally, you only have a self-sign-off here, which is fine for trivial stuff, but I want to see that other people actually believe this code is correct and they agree with it. Get others to review it first before making the community (i.e. me) do their work for them. IBM has a whole bunch of people that do this as part of their job, don't ignore them...

bah.

greg k-h

#2 lore raw
Quoted 10 lines · Greg Kroah-Hartman
Quoted 7 lines · Steven Royer

From: Steven Royer <[email protected]>

The ibmvmc driver is a device driver for the POWER Virtual Management Channel virtual adapter on the PowerVM platform. It is used to communicate with the hypervisor for virtualization management. It provides both request/response and asynchronous message support through the /dev/ibmvmc node.

What is the protocol for that device node?

The protocol is not currently published. I am pushing on getting it published, but that process will take time. If you have a PowerVM system with NovaLink, it would not be hard to reverse engineer it... If you don't have a PowerVM system, then this driver isn't interesting anyway...

Quoted 3 lines

Where is the documentation here? Why does this have to be a character device? Why can't it fit in with other drivers of this type?

This is a character device for historical reasons. The short version is that this driver is a clean-room rewrite of an AIX driver which made it a character device. The user space application was ported from AIX to Linux and it is convenient to have the AIX and Linux drivers match behavior where possible.

Quoted 102 lines
Quoted 102 lines

---
This is used by the PowerVM NovaLink project. You can see development history on github:
https://github.com/powervm/ibmvmc

 Documentation/ioctl/ioctl-number.txt |    1 +
 MAINTAINERS                          |    5 +
 arch/powerpc/include/asm/hvcall.h    |    3 +-
 drivers/misc/Kconfig                 |    9 +
 drivers/misc/Makefile                |    1 +
 drivers/misc/ibmvmc.c                | 1882 
++++++++++++++++++++++++++++++++++
 drivers/misc/ibmvmc.h                |  203 ++++
 7 files changed, 2103 insertions(+), 1 deletion(-)
 create mode 100644 drivers/misc/ibmvmc.c
 create mode 100644 drivers/misc/ibmvmc.h
Documentation/ioctl/ioctl-number.txt +1 -0
index 91261a3..d5f5f4f 100644
@@ -324,6 +324,7 @@ Code  Seq#(hex)	Include File		Comments
 0xCA	80-8F	uapi/scsi/cxlflash_ioctl.h
 0xCB	00-1F	CBM serial IEC bus	in development:
 					<mailto:[email protected]>
+0xCC	00-0F	drivers/misc/ibmvmc.h	pseries VMC driver
 0xCD	01	linux/reiserfs_fs.h
 0xCF	02	fs/cifs/ioctl.c
 0xDB	00-0F	drivers/char/mwave/mwavepub.h
MAINTAINERS +5 -0
index cc2f753..c39dca2 100644
@@ -5353,6 +5353,11 @@ L:	[email protected]
 S:	Supported
 F:	drivers/net/ethernet/ibm/ibmvnic.*
 
+IBM Power Virtual Management Channel Driver
+M:	Steven Royer <[email protected]>
+S:	Supported
+F:	drivers/misc/ibmvmc.*
+
 IBM Power Virtual SCSI Device Drivers
 M:	Tyrel Datwyler <[email protected]>
 L:	[email protected]
arch/powerpc/include/asm/hvcall.h +2 -1
index e3b54dd..1ee6f2b 100644
@@ -274,7 +274,8 @@
 #define H_COP			0x304
 #define H_GET_MPP_X		0x314
 #define H_SET_MODE		0x31C
-#define MAX_HCALL_OPCODE	H_SET_MODE
+#define H_REQUEST_VMC		0x360
+#define MAX_HCALL_OPCODE	H_REQUEST_VMC
 
 /* H_VIOCTL functions */
 #define H_GET_VIOA_DUMP_SIZE	0x01
drivers/misc/Kconfig +9 -0
index 054fc10..f8d9113 100644
@@ -526,6 +526,15 @@ config VEXPRESS_SYSCFG
 	  bus. System Configuration interface is one of the possible means
 	  of generating transactions on this bus.
 
+config IBMVMC
+	tristate "IBM Virtual Management Channel support"
+	depends on PPC_PSERIES
+	help
+	  This is the IBM POWER Virtual Management Channel
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ibmvmc.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index 537d7f3..08336b3 100644
@@ -56,3 +56,4 @@ obj-$(CONFIG_GENWQE)		+= genwqe/
 obj-$(CONFIG_ECHO)		+= echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)		+= cxl/
+obj-$(CONFIG_IBMVMC)		+= ibmvmc.o
drivers/misc/ibmvmc.c new file +6 -0
new file mode 100644
index 0000000..fb943b7
@@ -0,0 +1,1882 @@
+/*
+ * IBM Power Systems Virtual Management Channel Support.
+ *
+ * Copyright (c) 2004, 2016 IBM Corp.
+ *   Dave Engebretsen [email protected]
+ *   Steven Royer [email protected]
Quoted 8 lines

drivers/misc/ibmvmc.c line 12

Quoted 6 lines
drivers/misc/ibmvmc.c new file +6 -0
+ *   Adam Reznechek [email protected]
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.

I have to ask, but do you really mean "or any later version"?

This actually matches closely to other similar PowerVM virtual device drivers, like ibmvscsi or ibmveth.

Quoted 22 lines
Quoted 22 lines
drivers/misc/ibmvmc.c new file +21 -0
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/major.h>
+#include <linux/string.h>
+#include <linux/fcntl.h>
+#include <linux/slab.h>
+#include <linux/poll.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>
+#include <linux/spinlock.h>
+#include <linux/percpu.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
Quoted 8 lines

drivers/misc/ibmvmc.c line 39

Quoted 6 lines
drivers/misc/ibmvmc.c new file +6 -0
+#include <linux/io.h>
+#include <linux/device.h>
+
+#include <asm/byteorder.h>
+#include <asm/irq.h>
+#include <asm/vio.h>

Why are these asm files needed?

I did that research once before and I think I need them, but I don't recall the details now. I'll revisit.

Quoted 7 lines

drivers/misc/ibmvmc.c line 41

Quoted 3 lines
drivers/misc/ibmvmc.c new file +2 -0
+
+#include "ibmvmc.h"

Why do you have a .h file for a single-file driver? That shouldn't be needed at all, unless you have an odd user api, and if so, it better be documented...

I did this to match other PowerVM drivers, like ibmveth. I'm not particularly attached to this model and am willing to change if you prefer.

Quoted 24 lines
Quoted 24 lines
drivers/misc/ibmvmc.c new file +23 -0
+
+#define IBMVMC_DRIVER_VERSION "1.0"
+
+MODULE_DESCRIPTION("IBM VMC");
+MODULE_AUTHOR("Steven Royer <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(IBMVMC_DRIVER_VERSION);
+
+
+/*
+ * Static global variables
+ */
+static DECLARE_WAIT_QUEUE_HEAD(ibmvmc_read_wait);
+
+static const char ibmvmc_driver_name[] = "ibmvmc";
+static const char ibmvmc_workq_name[] = "ibmvmc";
+
+static struct ibmvmc_struct ibmvmc;
+static struct ibmvmc_hmc hmcs[MAX_HMCS];
+static struct crq_server_adapter ibmvmc_adapter;
+static dev_t ibmvmc_chrdev;
+
+static int ibmvmc_max_buf_pool_size = DEFAULT_BUF_POOL_SIZE;
Quoted 8 lines

drivers/misc/ibmvmc.c line 68

Quoted 4 lines
drivers/misc/ibmvmc.c new file +4 -0
+static int ibmvmc_max_hmcs = DEFAULT_HMCS;
+static int ibmvmc_max_mtu = DEFAULT_MTU;
+static struct class *ibmvmc_class;
+struct device *ibmvmc_dev;

Those are huge flags to me, why would you ever have a static pointer to a device? You should never deal with a "raw" struct device, unless something is really odd...

Agree. I'll fix this.

Quoted 17 lines
Quoted 17 lines
drivers/misc/ibmvmc.c new file +6 -0
+
+/* Module parameters */
+module_param_named(buf_pool_size, ibmvmc_max_buf_pool_size,
+		   int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(buf_pool_size, "Buffer pool size");
+module_param_named(max_hmcs, ibmvmc_max_hmcs, int, S_IRUGO | 

S_IWUSR);

drivers/misc/ibmvmc.c new file +9 -0
+MODULE_PARM_DESC(max_hmcs, "Max HMCs");
+module_param_named(max_mtu, ibmvmc_max_mtu, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(max_mtu, "Max MTU");
+
+
+static inline long h_copy_rdma(s64 length, u64 sliobn, u64 slioba,
+	u64 dliobn, u64 dlioba)
+{
+	long rc = 0;
Quoted 8 lines

drivers/misc/ibmvmc.c line 88

Quoted 6 lines
drivers/misc/ibmvmc.c new file +4 -0
+
+	/* Ensure all writes to source memory are visible before hcall */
+	mb();
+	pr_debug("ibmvmc: h_copy_rdma(0x%llx, 0x%llx, 0x%llx, 0x%llx, 

0x%llx\n",

drivers/misc/ibmvmc.c new file +1 -0
+			length, sliobn, slioba, dliobn, dlioba);

It's a driver, use dev_dbg() please.

Agree.

Quoted 12 lines
Quoted 12 lines
drivers/misc/ibmvmc.c new file +11 -0
+	rc = plpar_hcall_norets(H_COPY_RDMA, length, sliobn, slioba,
+			dliobn, dlioba);
+	pr_debug("ibmvmc: h_copy_rdma rc = 0x%lx\n", rc);
+
+	return rc;
+}
+
+static inline void h_free_crq(uint32_t unit_address)
+{
+	long rc = 0;
+
Quoted 8 lines

drivers/misc/ibmvmc.c line 105

Quoted 6 lines
drivers/misc/ibmvmc.c new file +6 -0
+	do {
+		if (H_IS_LONG_BUSY(rc))
+			msleep(get_longbusy_msecs(rc));
+
+		rc = plpar_hcall_norets(H_FREE_CRQ, unit_address);
+	} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));

endless loop? Not good.

This is actually required on PowerVM. This is a purely virtual device. If you look at other PowerVM drivers, you'll see more or less identical code. i.e., ibmvscsi.

Quoted 47 lines
Quoted 18 lines
drivers/misc/ibmvmc.c new file +4 -0
+}
+
+/**
+ * h_request_vmc: - request a hypervisor virtual management channel 

device
+ * @vmc_index: drc index of the vmc device created
+ *
+ * Requests the hypervisor create a new virtual management channel device,
+ * allowing this partition to send hypervisor virtualization control commands.
+ *
+ */

drivers/misc/ibmvmc.c new file +4 -0
+static inline long h_request_vmc(u32 *vmc_index)
+{
+	long rc = 0;
+	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];

drivers/misc/ibmvmc.c line 129

Quoted 10 lines
drivers/misc/ibmvmc.c new file +10 -0
+
+	do {
+		if (H_IS_LONG_BUSY(rc))
+			msleep(get_longbusy_msecs(rc));
+
+		/* Call to request the VMC device from phyp */
+		rc = plpar_hcall(H_REQUEST_VMC, retbuf);
+		pr_debug("ibmvmc: h_request_vmc rc = 0x%lx\n", rc);
+		*vmc_index = retbuf[0];
+	} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));

Another endless loop? Your hardware must never fail :)

Quoted 16 lines
drivers/misc/ibmvmc.c new file +16 -0
+
+	return rc;
+}
+
+/* routines for managing a command/response queue */
+/**
+ * ibmvmc_handle_event: - Interrupt handler for crq events
+ * @irq:        number of irq to handle, not used
+ * @dev_instance: crq_server_adapter that received interrupt
+ *
+ * Disables interrupts and schedules ibmvmc_task
+ * Always returns IRQ_HANDLED
+ */
+static irqreturn_t ibmvmc_handle_event(int irq, void *dev_instance)
+{
+	struct crq_server_adapter *adapter =
Quoted 8 lines

drivers/misc/ibmvmc.c line 151

Quoted 6 lines
drivers/misc/ibmvmc.c new file +6 -0
+		(struct crq_server_adapter *)dev_instance;
+
+	vio_disable_interrupts(to_vio_dev(adapter->dev));
+	queue_work(adapter->work_queue, &adapter->work);
+
+	return IRQ_HANDLED;

No shared interrupt handling?

I'll do some investigation here, but again, this matches almost exactly how other similar PowerVM drivers work (ibmvscsi).

Quoted 12 lines

drivers/misc/ibmvmc.c line 1802

Quoted 10 lines
drivers/misc/ibmvmc.c new file +9 -0
+}
+
+	/* Dynamically allocate ibmvmc major number */
+	if (alloc_chrdev_region(&ibmvmc_chrdev, 0, VMC_NUM_MINORS,
+		ibmvmc_driver_name)) {
+		pr_err("ibmvmc: unable to allocate a dev_t\n");
+		rc = -EIO;
+		goto alloc_chrdev_failed;
+	}

A whole major number for one minor? Use the misc class instead please.

Agree.

Quoted 7 lines

And finally, you only have a self-sign-off here, which is fine for trivial stuff, but I want to see that other people actually believe this code is correct and they agree with it. Get others to review it first before making the community (i.e. me) do their work for them. IBM has a whole bunch of people that do this as part of their job, don't ignore them...

Sorry, this was my fault. It was reviewed at IBM but I neglected to include the sign-off statements. Thanks for taking the time to review this.

Quoted 4 lines

bah.

greg k-h

#3 lore raw
Quoted 10 lines · Steven Royer
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Steven Royer

From: Steven Royer <[email protected]>

The ibmvmc driver is a device driver for the POWER Virtual Management Channel virtual adapter on the PowerVM platform. It is used to communicate with the hypervisor for virtualization management. It provides both request/response and asynchronous message support through the /dev/ibmvmc node.

Quoted 5 lines
Quoted 1 line

What is the protocol for that device node?

The protocol is not currently published. I am pushing on getting it published, but that process will take time. If you have a PowerVM system with NovaLink, it would not be hard to reverse engineer it... If you don't have a PowerVM system, then this driver isn't interesting anyway...

You can't just expect us to review this code without at least having a clue as to how it is supposed to work?

Quoted 7 lines
Quoted 2 lines

Where is the documentation here? Why does this have to be a character device? Why can't it fit in with other drivers of this type?

This is a character device for historical reasons. The short version is that this driver is a clean-room rewrite of an AIX driver which made it a character device. The user space application was ported from AIX to Linux and it is convenient to have the AIX and Linux drivers match behavior where possible.

Note that we don't let random userspace applications dictate kernel api decisions, please make the best choice for this interface without being influenced by AIX.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

+/*
+ * IBM Power Systems Virtual Management Channel Support.
+ *
+ * Copyright (c) 2004, 2016 IBM Corp.

+ *   Dave Engebretsen [email protected]
+ *   Steven Royer [email protected]
+ *   Adam Reznechek [email protected]

+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.

Quoted 3 lines
Quoted 1 line

I have to ask, but do you really mean "or any later version"?

This actually matches closely to other similar PowerVM virtual device drivers, like ibmvscsi or ibmveth.

That did not answer the question, picking a license in a cargo-cult manner is not a wise decision :(

#4 lore raw
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Steven Royer
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Steven Royer

From: Steven Royer <[email protected]>

The ibmvmc driver is a device driver for the POWER Virtual Management Channel virtual adapter on the PowerVM platform. It is used to communicate with the hypervisor for virtualization management. It provides both request/response and asynchronous message support through the /dev/ibmvmc node.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What is the protocol for that device node?

The protocol is not currently published. I am pushing on getting it published, but that process will take time. If you have a PowerVM system with NovaLink, it would not be hard to reverse engineer it... If you don't have a PowerVM system, then this driver isn't interesting anyway...

You can't just expect us to review this code without at least having a clue as to how it is supposed to work?

There are two layers to the protocol. The first layer is the only layer that the driver actually cares about. The second layer is just a payload that is between the application and the hypervisor and can change independently from the kernel/driver (this is what is transported over the /dev/ibmvmc node). The first layer technically is published in the PAPR (appendix G), but it is not trivial for most people to access online. I'll put together some documentation that describes that first layer of the protocol in my next revision of the patch. In many respects, the interface between driver and hypervisor is similar to ibmvscsi. Both are CRQ based devices. ibmvmc is actually a little closer to the old ibmvstgt driver since it is a CRQ server device.

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

Where is the documentation here? Why does this have to be a character device? Why can't it fit in with other drivers of this type?

This is a character device for historical reasons. The short version is that this driver is a clean-room rewrite of an AIX driver which made it a character device. The user space application was ported from AIX to Linux and it is convenient to have the AIX and Linux drivers match behavior where possible.

Quoted 3 lines

Note that we don't let random userspace applications dictate kernel api decisions, please make the best choice for this interface without being influenced by AIX.

That is fair. I actually started down the path of using a block interface early on, and I ran into some complications that made it seem less desirable than character. Specifically the interface has variable length messages from 32 bytes to 4kb (mostly closer to 32 bytes than 4kb per message) and I was worried about overhead of dealing with all the zeros in the majority of the messages. I've never made a block interface before and it's entirely possible (likely) I missed something obvious. I'll revisit before I post the next revision.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

+/*
+ * IBM Power Systems Virtual Management Channel Support.
+ *
+ * Copyright (c) 2004, 2016 IBM Corp.

+ *   Dave Engebretsen [email protected]
+ *   Steven Royer [email protected]
+ *   Adam Reznechek [email protected]

+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I have to ask, but do you really mean "or any later version"?

This actually matches closely to other similar PowerVM virtual device drivers, like ibmvscsi or ibmveth.

That did not answer the question, picking a license in a cargo-cult manner is not a wise decision :(

This is boilerplate for IBM provided PowerVM drivers. So yes, I did mean this.

#5 lore raw
Quoted 12 lines · Steven Royer
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Steven Royer
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Steven Royer

From: Steven Royer <[email protected]>

The ibmvmc driver is a device driver for the POWER Virtual Management Channel virtual adapter on the PowerVM platform. It is used to communicate with the hypervisor for virtualization management. It provides both request/response and asynchronous message support through the /dev/ibmvmc node.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

What is the protocol for that device node?

The protocol is not currently published. I am pushing on getting it published, but that process will take time. If you have a PowerVM system
with NovaLink, it would not be hard to reverse engineer it... If you don't
have a PowerVM system, then this driver isn't interesting anyway...

Stephen - if you need some help pushing for it to be published, let me know, there's a few internal things I could help push.

Quoted 8 lines
Quoted 2 lines

You can't just expect us to review this code without at least having a clue as to how it is supposed to work?

There are two layers to the protocol. The first layer is the only layer that the driver actually cares about. The second layer is just a payload that is between the application and the hypervisor and can change independently from the kernel/driver (this is what is transported over the /dev/ibmvmc node). The first layer technically is published in the PAPR (appendix G), but it is not trivial for most people to access

https://members.openpowerfoundation.org/document/dl/469 is LoPAPR which has been published through OpenPower Foundation and anyone can access, although Appendix G there is on EEH. Although VMC (Virtual Management Channel) is mentioned in that document the details aren't there... so it's possible that this is only in some other PAPR version :/ and... looking in internal places, it is. *sigh*

With my OpenPower Foundation hat on, I'll say that it's a work-in-progress getting all this documentation in order.

The questions of if it's a sensible hypervisor to partition interface and if it's a sensible userspace API are open for debate :)

Would we implement this way of communicating between a KVM guest and the host linux system? If not, then it's probably not a generally good idea. That being said, it seems to be what already exists in PowerVM

Signature · 2 lines
Stewart Smith
OPAL Architect, IBM.
#6 lore raw
Quoted 21 lines · Stewart Smith
Quoted 12 lines · Steven Royer
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Steven Royer
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Steven Royer

From: Steven Royer <[email protected]>

The ibmvmc driver is a device driver for the POWER Virtual Management Channel virtual adapter on the PowerVM platform. It is used to communicate with the hypervisor for virtualization management. It provides both request/response and asynchronous message support through the /dev/ibmvmc node.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

What is the protocol for that device node?

The protocol is not currently published. I am pushing on getting it published, but that process will take time. If you have a PowerVM system
with NovaLink, it would not be hard to reverse engineer it... If you don't
have a PowerVM system, then this driver isn't interesting anyway...

Quoted 2 lines

Stephen - if you need some help pushing for it to be published, let me know, there's a few internal things I could help push.

Thanks

Quoted 20 lines
Quoted 9 lines
Quoted 3 lines

You can't just expect us to review this code without at least having a clue as to how it is supposed to work?

There are two layers to the protocol. The first layer is the only layer that the driver actually cares about. The second layer is just a payload that is between the application and the hypervisor and can change independently from the kernel/driver (this is what is transported over the /dev/ibmvmc node). The first layer technically is published in the PAPR (appendix G), but it is not trivial for most people to access

https://members.openpowerfoundation.org/document/dl/469 is LoPAPR which has been published through OpenPower Foundation and anyone can access, although Appendix G there is on EEH. Although VMC (Virtual Management Channel) is mentioned in that document the details aren't there... so it's possible that this is only in some other PAPR version :/ and... looking in internal places, it is. *sigh*

With my OpenPower Foundation hat on, I'll say that it's a work-in-progress getting all this documentation in order.

Quoted 6 lines

The questions of if it's a sensible hypervisor to partition interface and if it's a sensible userspace API are open for debate :)

Would we implement this way of communicating between a KVM guest and the host linux system? If not, then it's probably not a generally good idea. That being said, it seems to be what already exists in PowerVM

There is no "host" OS on PowerVM. The ibmvmc device makes it possible to emulate that behavior by picking one of the LPARs to be privileged. So this isn't really similar to a KVM guest talking to the KVM host. It's more like this Linux OS becomes the host. ibmvmc is the pipe that enables virtualization management software (i.e., OpenStack via NovaLink) to manage PowerVM: create/destroy/modify guests, etc... The why's and how's of NovaLink are described simply here: https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Power%20Systems/page/Introducing%20PowerVM%20NovaLink