Skip to contentSkip to conversation

kvmctl code refactoring part 1

PATCH New Jerone Young 6 participants 21 messages Oct 29, 2007 – Oct 30, 2007 6 messages not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvmctl code refactoring part 1

These patches are the beginning of the refactoring of the current kvmctl. To begin the main focus is to refcator the x86 code to allow other architectures to easily add support to kvmctl.

These will all be small for easy review and criticism. So please fire away :-)

Jerone Young <jyoung5-r/[email protected]>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#1 lore raw

PATCH 1/1 Move x86 kvmcallback structure to kvmctl-x86.h header

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618330 18000
# Node ID 3bf072e498768885ab96b7ccb668b61c96db0e83
# Parent a6f7c585fe76f9563fd061cfe3e772532ab27952
Move x86 kvmcallback structure to kvmctl-x86.h header.

This patch moves the kvmcallback structure that is currently in kvmctl.h into an arch specific header.

new file mode 100644

user/kvmctl-x86.h new file +54 -0
new file mode 100644
@@ -0,0 +1,54 @@
+#ifndef KVMCTL_X86_H
+#define KVMCTL_X86_H
+
+/*!
+ * \brief KVM callbacks structure
+ *
+ * This structure holds pointers to various functions that KVM will call
+ * when it encounters something that cannot be virtualized, such as
+ * accessing hardware devices via MMIO or regular IO.
+ */
+struct kvm_callbacks {
+	/// For 8bit IO reads from the guest (Usually when executing 'inb')
+    int (*inb)(void *opaque, uint16_t addr, uint8_t *data);
+	/// For 16bit IO reads from the guest (Usually when executing 'inw')
+    int (*inw)(void *opaque, uint16_t addr, uint16_t *data);
+	/// For 32bit IO reads from the guest (Usually when executing 'inl')
+    int (*inl)(void *opaque, uint16_t addr, uint32_t *data);
+	/// For 8bit IO writes from the guest (Usually when executing 'outb')
+    int (*outb)(void *opaque, uint16_t addr, uint8_t data);
+	/// For 16bit IO writes from the guest (Usually when executing 'outw')
+    int (*outw)(void *opaque, uint16_t addr, uint16_t data);
+	/// For 32bit IO writes from the guest (Usually when executing 'outl')
+    int (*outl)(void *opaque, uint16_t addr, uint32_t data);
+	/// For 8bit memory reads from unmapped memory (For MMIO devices)
+    int (*readb)(void *opaque, uint64_t addr, uint8_t *data);
+	/// For 16bit memory reads from unmapped memory (For MMIO devices)
+    int (*readw)(void *opaque, uint64_t addr, uint16_t *data);
+	/// For 32bit memory reads from unmapped memory (For MMIO devices)
+    int (*readl)(void *opaque, uint64_t addr, uint32_t *data);
+	/// For 64bit memory reads from unmapped memory (For MMIO devices)
+    int (*readq)(void *opaque, uint64_t addr, uint64_t *data);
+	/// For 8bit memory writes to unmapped memory (For MMIO devices)
+    int (*writeb)(void *opaque, uint64_t addr, uint8_t data);
+	/// For 16bit memory writes to unmapped memory (For MMIO devices)
+    int (*writew)(void *opaque, uint64_t addr, uint16_t data);
+	/// For 32bit memory writes to unmapped memory (For MMIO devices)
+    int (*writel)(void *opaque, uint64_t addr, uint32_t data);
+	/// For 64bit memory writes to unmapped memory (For MMIO devices)
+    int (*writeq)(void *opaque, uint64_t addr, uint64_t data);
+    int (*debug)(void *opaque, int vcpu);
+	/*!
+	 * \brief Called when the VCPU issues an 'hlt' instruction.
+	 *
+	 * Typically, you should yeild here to prevent 100% CPU utilization
+	 * on the host CPU.
+	 */
+    int (*halt)(void *opaque, int vcpu);
+    int (*shutdown)(void *opaque, int vcpu);
+    int (*io_window)(void *opaque);
+    int (*try_push_interrupts)(void *opaque);
+    void (*post_kvm_run)(void *opaque, int vcpu);
+    int (*pre_kvm_run)(void *opaque, int vcpu);
+};
+#endif
user/kvmctl.h +4 -50

60 lines not on this page · raw message

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#22 lore raw

PATCH 1/1 Move kvm_context structure to kvmctl.h header

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618330 18000
# Node ID 8bf5e4e6a4c9d2dab89062a0ab24a2ae5d144a02
# Parent 3bf072e498768885ab96b7ccb668b61c96db0e83
Move kvm_context structure to kvmctl.h header

This patch moves the kvm_context sturcture declaration to the kvmctl.h header. This way other files are able to identify variables associated with the structure. Also moved are definitions MAX_VCPU & KVM_MAX_NUM_MEM_REGIONS to the kvmctl-x86.h since these are arch specific.

user/kvmctl-x86.h +3 -0
@@ -1,5 +1,8 @@
 #ifndef KVMCTL_X86_H
 #define KVMCTL_X86_H
+
+#define KVM_MAX_NUM_MEM_REGIONS 8u
+#define MAX_VCPUS 4
 
 /*!
  * \brief KVM callbacks structure
user/kvmctl.c +0 -28
@@ -44,36 +44,8 @@ static int kvm_abi = EXPECTED_KVM_API_VE
 
 /* FIXME: share this number with kvm */
 /* FIXME: or dynamically alloc/realloc regions */
-#define KVM_MAX_NUM_MEM_REGIONS 8u
 int free_slots[KVM_MAX_NUM_MEM_REGIONS];
 unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS];
-#define MAX_VCPUS 4
-
-/**
- * \brief The KVM context
- *
- * The verbose KVM context
- */
-struct kvm_context {
-	/// Filedescriptor to /dev/kvm
-	int fd;
-	int vm_fd;
-	int vcpu_fd[MAX_VCPUS];
-	struct kvm_run *run[MAX_VCPUS];
-	/// Callbacks that KVM uses to emulate various unvirtualizable functionality
-	struct kvm_callbacks *callbacks;
-	void *opaque;
-	/// A pointer to the memory used as the physical memory for the guest
-	void *physical_memory;
-	/// is dirty pages logging enabled for all regions or not
-	int dirty_pages_log_all;
-	/// memory regions parameters
-	struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS];
-	/// do not create in-kernel irqchip if set
-	int no_irqchip_creation;
-	/// in-kernel irqchip status
-	int irqchip_in_kernel;
-};
 
 static void init_slots()
 {
user/kvmctl.h +30 -0
@@ -31,6 +31,36 @@ typedef struct kvm_context *kvm_context_
 #if defined(__x86_64__) || defined(__i386__)
 #include "kvmctl-x86.h"
 #endif
+
+
+/**
+ * \brief The KVM context
+ *
+ * The verbose KVM context
+ */
+
+struct kvm_context {
+	/// Filedescriptor to /dev/kvm
+	int fd;
+	int vm_fd;
+	int vcpu_fd[MAX_VCPUS];
+	struct kvm_run *run[MAX_VCPUS];
+	/// Callbacks that KVM uses to emulate various unvirtualizable functionality
+	struct kvm_callbacks *callbacks;
+	void *opaque;
+	/// A pointer to the memory used as the physical memory for the guest
+	void *physical_memory;
+	/// is dirty pages logging enabled for all regions or not
+	int dirty_pages_log_all;
+	/// memory regions parameters
+	struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS];
+	/// do not create in-kernel irqchip if set
+	int no_irqchip_creation;
+	/// in-kernel irqchip status
+	int irqchip_in_kernel;
+};
+
+
 
 /*!
  * \brief Create new KVM context

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#26 lore raw

PATCH 1/1 Move x86 specific properties of kvm_init to own file

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618393 18000
# Node ID 64de4ce84d745217a7001dd5ba8c871aa9ad533a
# Parent 8bf5e4e6a4c9d2dab89062a0ab24a2ae5d144a02
Move x86 specific properties of kvm_init to own file.

This patch breaks out x86 specific properties for kvm_init initialization into it's own function, into a architecture specific file.

user/config-x86-common.mak +2 -2
@@ -2,9 +2,9 @@
 
 all: kvmctl libkvm.a test_cases
 
-kvmctl_objs=kvmctl.o main.o
+kvmctl_objs=kvmctl-x86.o kvmctl.o main.o
 
-libkvm_objs=kvmctl.o
+libkvm_objs=kvmctl-x86.o kvmctl.o
 
 balloon_ctl: balloon_ctl.o
 
user/kvmctl-x86.c new file +9 -0
new file mode 100644
@@ -0,0 +1,9 @@
+#include "kvmctl.h"
+#include <string.h>
+
+void arch_kvm_init(kvm_context_t kvm)
+{
+	kvm->dirty_pages_log_all = 0;
+	kvm->no_irqchip_creation = 0;
+	memset(&kvm->mem_regions, 0, sizeof(kvm->mem_regions));
+}
user/kvmctl-x86.h +7 -0
@@ -54,4 +54,11 @@ struct kvm_callbacks {
     void (*post_kvm_run)(void *opaque, int vcpu);
     int (*pre_kvm_run)(void *opaque, int vcpu);
 };
+
+/*
+ * \brief  Arch specific initialization for KVM context
+ */  
+void arch_kvm_init(kvm_context_t kvm);
+
+
 #endif
user/kvmctl.c +3 -4
@@ -231,10 +231,9 @@ kvm_context_t kvm_init(struct kvm_callba
 	kvm->vm_fd = -1;
 	kvm->callbacks = callbacks;
 	kvm->opaque = opaque;
-	kvm->dirty_pages_log_all = 0;
-	kvm->no_irqchip_creation = 0;
-	memset(&kvm->mem_regions, 0, sizeof(kvm->mem_regions));
-
+
+	arch_kvm_init(kvm);
+	
 	return kvm;
  out_close:
 	close(fd);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#2 lore raw

Re: [PATCH 1 of 3] Move x86 kvmcallback structure tokvmctl-x86.h header

In reply to Jerone Young
Quoted 29 lines · Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618330 18000
# Node ID 3bf072e498768885ab96b7ccb668b61c96db0e83
# Parent a6f7c585fe76f9563fd061cfe3e772532ab27952
Move x86 kvmcallback structure to kvmctl-x86.h header.

This patch moves the kvmcallback structure that is currently in kvmctl.h into an arch specific header.

new file mode 100644

user/kvmctl-x86.h new file +7 -0
new file mode 100644
@@ -0,0 +1,54 @@
+#ifndef KVMCTL_X86_H
+#define KVMCTL_X86_H
+
+/*!
+ * \brief KVM callbacks structure
+ *
+ * This structure holds pointers to various functions that KVM will

call + * when it encounters something that cannot be virtualized, such as + * accessing hardware devices via MMIO or regular IO.
+ */

user/kvmctl-x86.h

Quoted 2 lines
user/kvmctl-x86.h new file +2 -0
+struct kvm_callbacks {
+	/// For 8bit IO reads from the guest (Usually when executing

'inb')

user/kvmctl-x86.h

Quoted 2 lines
user/kvmctl-x86.h new file +2 -0
+    int (*inb)(void *opaque, uint16_t addr, uint8_t *data);
+	/// For 16bit IO reads from the guest (Usually when executing

'inw')

Quoted 1 line

+ int (*inw)(void *opaque, uint16_t addr, uint16_t *data);

I don't know the privious story about this thread, but now I can't understand the move. Why do we move all the structure to arch-specific ? For IA64 side, almostly we can reuse them directly, and just see some special fields as arch-specific. So, I think, we should keep common fields in kvmctl.h.

Quoted 5 lines

/*!
* \brief Create new KVM context

------------------------------------------------------------------------
-

Quoted 8 lines

This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >>
http://get.splunk.com/ _______________________________________________ kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#23 lore raw

Re: [PATCH 2 of 3] Move kvm_context structure to kvmctl.hheader

In reply to Jerone Young
Quoted 7 lines · Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618330 18000
# Node ID 8bf5e4e6a4c9d2dab89062a0ab24a2ae5d144a02
# Parent 3bf072e498768885ab96b7ccb668b61c96db0e83
Move kvm_context structure to kvmctl.h header

Quoted 5 lines

This patch moves the kvm_context sturcture declaration to the kvmctl.h header. This way other files are able to identify variables associated with the structure. Also moved are definitions MAX_VCPU & KVM_MAX_NUM_MEM_REGIONS to the kvmctl-x86.h since these are arch specific.

Just see these two definitions here, I remembered kernel space also defines two similar macros for the purpose . How to sync with them
direclty? Define them in linux/kvm.h instead of defining them twice ?

Quoted 14 lines

- */

user/kvmctl.c +0 -7
-struct kvm_context {
-	/// Filedescriptor to /dev/kvm
-	int fd;
-	int vm_fd;
-	int vcpu_fd[MAX_VCPUS];
-	struct kvm_run *run[MAX_VCPUS];
-	/// Callbacks that KVM uses to emulate various unvirtualizable

functionality

user/kvmctl.c +0 -3
-	struct kvm_callbacks *callbacks;
-	void *opaque;
-	/// A pointer to the memory used as the physical memory for the

guest

user/kvmctl.c static int kvm_abi = EXPECTED_KVM_API_VE · line 76

Quoted 10 lines
user/kvmctl.c +0 -10
-	void *physical_memory;
-	/// is dirty pages logging enabled for all regions or not
-	int dirty_pages_log_all;
-	/// memory regions parameters
-	struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS];
-	/// do not create in-kernel irqchip if set
-	int no_irqchip_creation;
-	/// in-kernel irqchip status
-	int irqchip_in_kernel;
-};

Maybe we should put them in kvmctl.h, and just move some arch-specific fields to kvmctl-x86.h.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#4 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure tokvmctl-x86.h header

In reply to a message not in the archive
Quoted 36 lines · Xiantao
Quoted 29 lines · Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618330 18000
# Node ID 3bf072e498768885ab96b7ccb668b61c96db0e83
# Parent a6f7c585fe76f9563fd061cfe3e772532ab27952
Move x86 kvmcallback structure to kvmctl-x86.h header.

This patch moves the kvmcallback structure that is currently in kvmctl.h into an arch specific header.

new file mode 100644

user/kvmctl-x86.h new file +7 -0
new file mode 100644
@@ -0,0 +1,54 @@
+#ifndef KVMCTL_X86_H
+#define KVMCTL_X86_H
+
+/*!
+ * \brief KVM callbacks structure
+ *
+ * This structure holds pointers to various functions that KVM will

call + * when it encounters something that cannot be virtualized, such as + * accessing hardware devices via MMIO or regular IO.
+ */

user/kvmctl-x86.h

Quoted 2 lines
user/kvmctl-x86.h new file +2 -0
+struct kvm_callbacks {
+	/// For 8bit IO reads from the guest (Usually when executing

'inb')

user/kvmctl-x86.h

Quoted 2 lines
user/kvmctl-x86.h new file +2 -0
+    int (*inb)(void *opaque, uint16_t addr, uint8_t *data);
+	/// For 16bit IO reads from the guest (Usually when executing

'inw')

Quoted 7 lines
Quoted 1 line

+ int (*inw)(void *opaque, uint16_t addr, uint16_t *data);

I don't know the privious story about this thread, but now I can't understand the move. Why do we move all the structure to arch-specific ? For IA64 side, almostly we can reuse them directly, and just see some special fields as arch-specific. So, I think, we should keep common fields in kvmctl.h.

Are you suggesting that kvm_callbacks should be the union of all callbacks used on all architectures, and for any given architecture only a subset are actually used?

Signature · 9 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
#24 lore raw

Re: [PATCH 2 of 3] Move kvm_context structure to kvmctl.h header

In reply to Jerone Young
Quoted 7 lines · Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618330 18000
# Node ID 8bf5e4e6a4c9d2dab89062a0ab24a2ae5d144a02
# Parent 3bf072e498768885ab96b7ccb668b61c96db0e83
Move kvm_context structure to kvmctl.h header

Quoted 5 lines

This patch moves the kvm_context sturcture declaration to the kvmctl.h header. This way other files are able to identify variables associated with the structure. Also moved are definitions MAX_VCPU & KVM_MAX_NUM_MEM_REGIONS to the kvmctl-x86.h since these are arch specific.

I think just moving the declaration of kvm_context to an x86 specific file is the wrong direction to take.

I think a better first step would be to split up the architecture specific portions of kvm_context into an architecture specific structure and then have the common kvm_context be a part of the architecture specific structure (just like is done in the kernel code).

Regards,

Anthony Liguori

Quoted 96 lines
user/kvmctl-x86.h +3 -0
@@ -1,5 +1,8 @@
 #ifndef KVMCTL_X86_H
 #define KVMCTL_X86_H
+
+#define KVM_MAX_NUM_MEM_REGIONS 8u
+#define MAX_VCPUS 4
 
 /*!
  * \brief KVM callbacks structure
user/kvmctl.c +0 -28
@@ -44,36 +44,8 @@ static int kvm_abi = EXPECTED_KVM_API_VE
 
 /* FIXME: share this number with kvm */
 /* FIXME: or dynamically alloc/realloc regions */
-#define KVM_MAX_NUM_MEM_REGIONS 8u
 int free_slots[KVM_MAX_NUM_MEM_REGIONS];
 unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS];
-#define MAX_VCPUS 4
-
-/**
- * \brief The KVM context
- *
- * The verbose KVM context
- */
-struct kvm_context {
-	/// Filedescriptor to /dev/kvm
-	int fd;
-	int vm_fd;
-	int vcpu_fd[MAX_VCPUS];
-	struct kvm_run *run[MAX_VCPUS];
-	/// Callbacks that KVM uses to emulate various unvirtualizable functionality
-	struct kvm_callbacks *callbacks;
-	void *opaque;
-	/// A pointer to the memory used as the physical memory for the guest
-	void *physical_memory;
-	/// is dirty pages logging enabled for all regions or not
-	int dirty_pages_log_all;
-	/// memory regions parameters
-	struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS];
-	/// do not create in-kernel irqchip if set
-	int no_irqchip_creation;
-	/// in-kernel irqchip status
-	int irqchip_in_kernel;
-};
 
 static void init_slots()
 {
user/kvmctl.h +30 -1
@@ -31,6 +31,36 @@ typedef struct kvm_context *kvm_context_
 #if defined(__x86_64__) || defined(__i386__)
 #include "kvmctl-x86.h"
 #endif
+
+
+/**
+ * \brief The KVM context
+ *
+ * The verbose KVM context
+ */
+
+struct kvm_context {
+	/// Filedescriptor to /dev/kvm
+	int fd;
+	int vm_fd;
+	int vcpu_fd[MAX_VCPUS];
+	struct kvm_run *run[MAX_VCPUS];
+	/// Callbacks that KVM uses to emulate various unvirtualizable functionality
+	struct kvm_callbacks *callbacks;
+	void *opaque;
+	/// A pointer to the memory used as the physical memory for the guest
+	void *physical_memory;
+	/// is dirty pages logging enabled for all regions or not
+	int dirty_pages_log_all;
+	/// memory regions parameters
+	struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS];
+	/// do not create in-kernel irqchip if set
+	int no_irqchip_creation;
+	/// in-kernel irqchip status
+	int irqchip_in_kernel;
+};
+
+
 
 /*!
  * \brief Create new KVM context
 
-------------------------------------------------------------------------
Quoted 10 lines

This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#14 lore raw

Re: [PATCH 1 of 3] Move x86 kvmcallback structure to kvmctl-x86.h header

In reply to Jerone Young
Quoted 107 lines · Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618330 18000
# Node ID 3bf072e498768885ab96b7ccb668b61c96db0e83
# Parent a6f7c585fe76f9563fd061cfe3e772532ab27952
Move x86 kvmcallback structure to kvmctl-x86.h header.

This patch moves the kvmcallback structure that is currently in kvmctl.h into an arch specific header.

new file mode 100644

user/kvmctl-x86.h new file +54 -0
new file mode 100644
@@ -0,0 +1,54 @@
+#ifndef KVMCTL_X86_H
+#define KVMCTL_X86_H
+
+/*!
+ * \brief KVM callbacks structure
+ *
+ * This structure holds pointers to various functions that KVM will call
+ * when it encounters something that cannot be virtualized, such as
+ * accessing hardware devices via MMIO or regular IO.
+ */
+struct kvm_callbacks {
+	/// For 8bit IO reads from the guest (Usually when executing 'inb')
+    int (*inb)(void *opaque, uint16_t addr, uint8_t *data);
+	/// For 16bit IO reads from the guest (Usually when executing 'inw')
+    int (*inw)(void *opaque, uint16_t addr, uint16_t *data);
+	/// For 32bit IO reads from the guest (Usually when executing 'inl')
+    int (*inl)(void *opaque, uint16_t addr, uint32_t *data);
+	/// For 8bit IO writes from the guest (Usually when executing 'outb')
+    int (*outb)(void *opaque, uint16_t addr, uint8_t data);
+	/// For 16bit IO writes from the guest (Usually when executing 'outw')
+    int (*outw)(void *opaque, uint16_t addr, uint16_t data);
+	/// For 32bit IO writes from the guest (Usually when executing 'outl')
+    int (*outl)(void *opaque, uint16_t addr, uint32_t data);
+	/// For 8bit memory reads from unmapped memory (For MMIO devices)
+    int (*readb)(void *opaque, uint64_t addr, uint8_t *data);
+	/// For 16bit memory reads from unmapped memory (For MMIO devices)
+    int (*readw)(void *opaque, uint64_t addr, uint16_t *data);
+	/// For 32bit memory reads from unmapped memory (For MMIO devices)
+    int (*readl)(void *opaque, uint64_t addr, uint32_t *data);
+	/// For 64bit memory reads from unmapped memory (For MMIO devices)
+    int (*readq)(void *opaque, uint64_t addr, uint64_t *data);
+	/// For 8bit memory writes to unmapped memory (For MMIO devices)
+    int (*writeb)(void *opaque, uint64_t addr, uint8_t data);
+	/// For 16bit memory writes to unmapped memory (For MMIO devices)
+    int (*writew)(void *opaque, uint64_t addr, uint16_t data);
+	/// For 32bit memory writes to unmapped memory (For MMIO devices)
+    int (*writel)(void *opaque, uint64_t addr, uint32_t data);
+	/// For 64bit memory writes to unmapped memory (For MMIO devices)
+    int (*writeq)(void *opaque, uint64_t addr, uint64_t data);
+    int (*debug)(void *opaque, int vcpu);
+	/*!
+	 * \brief Called when the VCPU issues an 'hlt' instruction.
+	 *
+	 * Typically, you should yeild here to prevent 100% CPU utilization
+	 * on the host CPU.
+	 */
+    int (*halt)(void *opaque, int vcpu);
+    int (*shutdown)(void *opaque, int vcpu);
+    int (*io_window)(void *opaque);
+    int (*try_push_interrupts)(void *opaque);
+    void (*post_kvm_run)(void *opaque, int vcpu);
+    int (*pre_kvm_run)(void *opaque, int vcpu);
+};
+#endif
user/kvmctl.h +0 -27
@@ -27,56 +27,10 @@ struct kvm_context;
 
 typedef struct kvm_context *kvm_context_t;
 
-/*!
- * \brief KVM callbacks structure
- *
- * This structure holds pointers to various functions that KVM will call
- * when it encounters something that cannot be virtualized, such as
- * accessing hardware devices via MMIO or regular IO.
- */
-struct kvm_callbacks {
-	/// For 8bit IO reads from the guest (Usually when executing 'inb')
-    int (*inb)(void *opaque, uint16_t addr, uint8_t *data);
-	/// For 16bit IO reads from the guest (Usually when executing 'inw')
-    int (*inw)(void *opaque, uint16_t addr, uint16_t *data);
-	/// For 32bit IO reads from the guest (Usually when executing 'inl')
-    int (*inl)(void *opaque, uint16_t addr, uint32_t *data);
-	/// For 8bit IO writes from the guest (Usually when executing 'outb')
-    int (*outb)(void *opaque, uint16_t addr, uint8_t data);
-	/// For 16bit IO writes from the guest (Usually when executing 'outw')
-    int (*outw)(void *opaque, uint16_t addr, uint16_t data);
-	/// For 32bit IO writes from the guest (Usually when executing 'outl')
-    int (*outl)(void *opaque, uint16_t addr, uint32_t data);
-	/// For 8bit memory reads from unmapped memory (For MMIO devices)
-    int (*readb)(void *opaque, uint64_t addr, uint8_t *data);
-	/// For 16bit memory reads from unmapped memory (For MMIO devices)
-    int (*readw)(void *opaque, uint64_t addr, uint16_t *data);
-	/// For 32bit memory reads from unmapped memory (For MMIO devices)
-    int (*readl)(void *opaque, uint64_t addr, uint32_t *data);
-	/// For 64bit memory reads from unmapped memory (For MMIO devices)

user/kvmctl.h struct kvm_context; · line 30

Quoted 10 lines
user/kvmctl.h +0 -9
-    int (*readq)(void *opaque, uint64_t addr, uint64_t *data);
-	/// For 8bit memory writes to unmapped memory (For MMIO devices)
-    int (*writeb)(void *opaque, uint64_t addr, uint8_t data);
-	/// For 16bit memory writes to unmapped memory (For MMIO devices)
-    int (*writew)(void *opaque, uint64_t addr, uint16_t data);
-	/// For 32bit memory writes to unmapped memory (For MMIO devices)
-    int (*writel)(void *opaque, uint64_t addr, uint32_t data);
-	/// For 64bit memory writes to unmapped memory (For MMIO devices)
-    int (*writeq)(void *opaque, uint64_t addr, uint64_t data);
 

With a little refactoring, this can be made into something sharable for all architectures. I'd recommend converting to something like:

int (*io_write)(void *opaque, int as, uint64_t addr, uint64_t data, int size);

Where as is a #define representing the address space (on x86, there is the PIO and MMIO address spaces, on PPC, there is just MMIO).

Since the ioctl() interface has a single handler for all pio operations/mmio operations, I think this is more natural too.

Regards,

Anthony Liguori

Quoted 22 lines
user/kvmctl.h +4 -14
-    int (*debug)(void *opaque, int vcpu);
-	/*!
-	 * \brief Called when the VCPU issues an 'hlt' instruction.
-	 *
-	 * Typically, you should yeild here to prevent 100% CPU utilization
-	 * on the host CPU.
-	 */
-    int (*halt)(void *opaque, int vcpu);
-    int (*shutdown)(void *opaque, int vcpu);
-    int (*io_window)(void *opaque);
-    int (*try_push_interrupts)(void *opaque);
-    void (*post_kvm_run)(void *opaque, int vcpu);
-    int (*pre_kvm_run)(void *opaque, int vcpu);
-};
+/* Add info from arch specific header */
+#if defined(__x86_64__) || defined(__i386__)
+#include "kvmctl-x86.h"
+#endif
 
 /*!

* \brief Create new KVM context

Quoted 11 lines

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#5 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure tokvmctl-x86.h header

In reply to Hollis Blanchard
Quoted 11 lines · Hollis Blanchard
Quoted 6 lines

I don't know the privious story about this thread, but now I can't understand the move. Why do we move all the structure to arch-specific ? For IA64 side, almostly we can reuse them directly, and just see some special fields as arch-specific. So, I think, we should keep common fields in kvmctl.h.

Are you suggesting that kvm_callbacks should be the union of all callbacks used on all architectures, and for any given architecture only a subset are actually used?

I think two separate callback structures would make more sense.

Quite a few of the callbacks should have common implementations. For instance, all of the io callbacks and the io_window callback should be the same. I would expect most architectures have a concept of a "halt" so that should probably be the same too. That pretty much covers the majority of the callbacks structure :-)

Regards,

Anthony Liguori

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#11 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86kvmcallback structure tokvmctl-x86.h header

In reply to Hollis Blanchard
Quoted 15 lines
Quoted 14 lines
Quoted 8 lines

call + * when it encounters something that cannot be virtualized, such as + * accessing hardware devices via MMIO or regular IO. + */

(quoted diff) +2 -0
+struct kvm_callbacks {
+	/// For 8bit IO reads from the guest (Usually when executing

'inb') + int (*inb)(void *opaque, uint16_t addr, uint8_t *data);

(quoted diff) +1 -0
+	/// For 16bit IO reads from the guest (Usually when executing

'inw') + int (*inw)(void *opaque, uint16_t addr, uint16_t *data);

I don't know the privious story about this thread, but now I can't understand the move. Why do we move all the structure to arch-specific ? For IA64 side, almostly we can reuse them directly, and just see some special fields as arch-specific. So, I think, we should keep common fields in kvmctl.h.

Quoted 3 lines

Are you suggesting that kvm_callbacks should be the union of all callbacks used on all architectures, and for any given architecture only a subset are actually used?

No, not a union. I think we should keep some common fields for all archs. At least, io_callbacks should be same for all archs. So, we need to split them into two parts, one common and the other one is arch-specific. Maybe we should add an filed, such as arch to hold arch-specific fields, instead of moving them all to kvmctl-x86.h

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#7 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure tokvmctl-x86.h header

In reply to a message not in the archive
Quoted 13 lines · Anthony Liguori
Quoted 11 lines · Hollis Blanchard
Quoted 6 lines

I don't know the privious story about this thread, but now I can't understand the move. Why do we move all the structure to arch-specific ? For IA64 side, almostly we can reuse them directly, and just see some special fields as arch-specific. So, I think, we should keep common fields in kvmctl.h.

Are you suggesting that kvm_callbacks should be the union of all callbacks used on all architectures, and for any given architecture only a subset are actually used?

Quoted 7 lines

I think two separate callback structures would make more sense.

Quite a few of the callbacks should have common implementations. For instance, all of the io callbacks and the io_window callback should be the same. I would expect most architectures have a concept of a "halt" so that should probably be the same too. That pretty much covers the majority of the callbacks structure :-)

Agree.

Quoted 3 lines

Regards,

Anthony Liguori

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#13 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86kvmcallback structure tokvmctl-x86.h header

In reply to a message not in the archive
Quoted 14 lines · Xiantao
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

call + * when it encounters something that cannot be virtualized, such as + * accessing hardware devices via MMIO or regular IO. + */

(quoted diff) +2 -0
+struct kvm_callbacks {
+	/// For 8bit IO reads from the guest (Usually when executing

'inb') + int (*inb)(void *opaque, uint16_t addr, uint8_t *data);

(quoted diff) +1 -0
+	/// For 16bit IO reads from the guest (Usually when executing

'inw') + int (*inw)(void *opaque, uint16_t addr, uint16_t *data);

I don't know the privious story about this thread, but now I can't understand the move. Why do we move all the structure to arch-specific ? For IA64 side, almostly we can reuse them directly, and just see some special fields as arch-specific. So, I think, we should keep common fields in kvmctl.h.

Quoted 6 lines
Quoted 3 lines

Are you suggesting that kvm_callbacks should be the union of all callbacks used on all architectures, and for any given architecture only a subset are actually used?

No, not a union. I think we should keep some common fields for all archs. At least, io_callbacks should be same for all archs.

Really? The *PIO* callbacks are the same? (PowerPC doesn't do PIO at all, and I'm almost positive that S390 doesn't either.)

Quoted 3 lines

So, we need to split them into two parts, one common and the other one is arch-specific. Maybe we should add an filed, such as arch to hold arch-specific fields, instead of moving them all to kvmctl-x86.h

Arch-specific code must handle the kernel->user returns anyways, so having a common/arch-specific data structure split buys us nothing. The reason we will have that split in the general KVM code (e.g. ioctl handling) is that there is common *code*, and so it needs to work with common data structures. That is not the case here.

If your arch has PIO, you're welcome to create PIO callbacks, and you can even share the implementation of those callbacks by building a shared pio.c. This can and should be done with completely arch-specific callback structures.

Signature · 9 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
#9 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure tokvmctl-x86.h header

In reply to a message not in the archive
Quoted 16 lines · Xiantao
Quoted 15 lines · Anthony Liguori
Quoted 11 lines · Hollis Blanchard
Quoted 6 lines

I don't know the privious story about this thread, but now I can't understand the move. Why do we move all the structure to arch-specific ? For IA64 side, almostly we can reuse them directly, and just see some special fields as arch-specific. So, I think, we should keep common fields in kvmctl.h.

Are you suggesting that kvm_callbacks should be the union of all callbacks used on all architectures, and for any given architecture only a subset are actually used?

I think two separate callback structures would make more sense.

Quoted 7 lines
Quoted 5 lines

Quite a few of the callbacks should have common implementations. For instance, all of the io callbacks and the io_window callback should be the same. I would expect most architectures have a concept of a "halt" so that should probably be the same too. That pretty much covers the majority of the callbacks structure :-)

Agree.

OK, are you changing your position then? Anthony is saying there should be multiple callback data structure definitions, but that the *implementations* of some of those callbacks should be shared. For example:

ia64.h:

        struct kvm_callbacks {
                ...
                .inb = pio_inb,
        };

x86.h:

        struct kvm_callbacks {
                ...
                .inb = pio_inb,
        };

pio.c (built only for ia64 and x86):

        int pio_inb(port) {
                ...
        }
Signature · 9 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
#16 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure to kvmctl-x86.h header

In reply to a message not in the archive
Quoted 6 lines · Anthony Liguori

int (*io_write)(void *opaque, int as, uint64_t addr, uint64_t data, int size);

Where as is a #define representing the address space (on x86, there is the PIO and MMIO address spaces, on PPC, there is just MMIO).

So the implementation would look something like this:

int io_write(void *opaque, int as, uint64_t addr, uint64_t data, int

size) {
        io_handler_t cb;
        
        switch (as) {
        case MMIO:
                cb = io_table_lookup(&mmio_table, ...)
                break;
#ifdef HAS_PIO
        case PIO:
                cb = io_table_lookup(&pio_table, ...)
                break;
#endif
#ifdef HAS_DCR
        case DCR:
                cb = io_table_lookup(&dcr_table, ...)
                break;
#endif
        default:
                cb = NULL;
        }
        
        if (cb)
                return cb(...);
        
        printk("error");
        return -EINVAL;
}

Sounds fine to me.

Signature · 9 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
#17 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure to kvmctl-x86.h header

Quoted 40 lines · Hollis Blanchard
Quoted 6 lines · Anthony Liguori

int (*io_write)(void *opaque, int as, uint64_t addr, uint64_t data, int size);

Where as is a #define representing the address space (on x86, there is the PIO and MMIO address spaces, on PPC, there is just MMIO).

So the implementation would look something like this:

int io_write(void *opaque, int as, uint64_t addr, uint64_t data, int

size) {
        io_handler_t cb;
        
        switch (as) {
        case MMIO:
                cb = io_table_lookup(&mmio_table, ...)
                break;
#ifdef HAS_PIO
        case PIO:
                cb = io_table_lookup(&pio_table, ...)
                break;
#endif
#ifdef HAS_DCR
        case DCR:
                cb = io_table_lookup(&dcr_table, ...)
                break;
#endif
        default:
                cb = NULL;
        }
        
        if (cb)
                return cb(...);
        
        printk("error");
        return -EINVAL;
}
Quoted 2 lines

Sounds fine to me.

You could certainly get even more clever and have the arch backend register the appropriate tables based on the as type but that's merely an implementation detail. The key observation, that I believe is correct, is that all architectures have one or more IO "address spaces" that have at max a 64-bit address space and support at max 64-bit input/output operations. Once that assumption is made, almost all IO code becomes common.

Regards,

Anthony Liguori

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#10 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure tokvmctl-x86.h header

In reply to Hollis Blanchard
Quoted 46 lines · Hollis Blanchard
Quoted 18 lines · Xiantao
Quoted 16 lines · Anthony Liguori
Quoted 7 lines · Hollis Blanchard
Quoted 7 lines

I don't know the privious story about this thread, but now I can't understand the move. Why do we move all the structure to arch-specific ? For IA64 side, almostly we can reuse them directly, and just see some special fields as arch-specific. So, I think, we should keep common fields in kvmctl.h.

Quoted 5 lines

Are you suggesting that kvm_callbacks should be the union of all callbacks used on all architectures, and for any given architecture only a subset are actually used?

I think two separate callback structures would make more sense.

Quoted 8 lines
Quoted 6 lines

Quite a few of the callbacks should have common implementations. For instance, all of the io callbacks and the io_window callback should be the same. I would expect most architectures have a concept of a "halt" so that should probably be the same too. That pretty much covers the majority of the callbacks structure :-)

Agree.

OK, are you changing your position then? Anthony is saying there should be multiple callback data structure definitions, but that the *implementations* of some of those callbacks should be shared. For example:

ia64.h:

        struct kvm_callbacks {
                ...
                .inb = pio_inb,
        };

x86.h:

        struct kvm_callbacks {
                ...
                .inb = pio_inb,
        };
Quoted 5 lines

pio.c (built only for ia64 and x86):

        int pio_inb(port) {
                ...
        }

I was actually advocating splitting the kvm_callbacks structure into two separate structures, one being architecture specific. But I don't think it's *that* important.

Regards,

Anthony Liguori

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#19 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure to kvmctl-x86.h header

In reply to a message not in the archive
Quoted 8 lines · Anthony Liguori

You could certainly get even more clever and have the arch backend register the appropriate tables based on the as type but that's merely an implementation detail. The key observation, that I believe is correct, is that all architectures have one or more IO "address spaces" that have at max a 64-bit address space and support at max 64-bit input/output operations. Once that assumption is made, almost all IO code becomes common.

Just FYI, some PowerPC have "load/store quad", which are 128-bit memory accesses. For that matter, I suppose one could do IO loads into Altivec registers (which are also 128 bits), though that sounds like an extreme case. I wonder if the same is true for x86 vector registers.

Also, can't x86 "rep" instructions go beyond 64 bits? I guess that must be handled in the arch-specific caller of io_write(), which would call it multiple times.

Signature · 9 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
#25 lore raw

Re: [PATCH 2 of 3] Move kvm_context structure to kvmctl.h header

In reply to Jerone Young
Quoted 11 lines · Jerone Young

# HG changeset patch
# User Jerone Young <jyoung5-r/[email protected]> # Date 1193618330 18000
# Node ID 8bf5e4e6a4c9d2dab89062a0ab24a2ae5d144a02
# Parent 3bf072e498768885ab96b7ccb668b61c96db0e83
Move kvm_context structure to kvmctl.h header

This patch moves the kvm_context sturcture declaration to the kvmctl.h header. This way other files are able to identify variables associated with the structure. Also moved are definitions MAX_VCPU & KVM_MAX_NUM_MEM_REGIONS to the kvmctl-x86.h since these are arch specific.

this KVM_MAX_NUM_MEM_REGIONS should have never be defined from kvmctl.h, (nothing wrong with what you did)
but i think this define should move to include/linux/kvm.h so userspace and kernel share this number

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#20 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure to kvmctl-x86.h header

In reply to Hollis Blanchard
Quoted 11 lines · Hollis Blanchard
Quoted 8 lines · Anthony Liguori

You could certainly get even more clever and have the arch backend register the appropriate tables based on the as type but that's merely an implementation detail. The key observation, that I believe is correct, is that all architectures have one or more IO "address spaces" that have at max a 64-bit address space and support at max 64-bit input/output operations. Once that assumption is made, almost all IO code becomes common.

Quoted 2 lines

Just FYI, some PowerPC have "load/store quad", which are 128-bit memory accesses.

Can you do MMIO with these instructions though? I'm not really sure what would happen on x86 if you did MMIO with a 128-bit instruction.

Regards,

Anthony Liguori

Quoted 9 lines

For that matter, I suppose one could do IO loads into Altivec
registers (which are also 128 bits), though that sounds like an extreme case. I wonder if the same is true for x86 vector registers.

Also, can't x86 "rep" instructions go beyond 64 bits? I guess that must be handled in the arch-specific caller of io_write(), which would call it multiple times.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#21 lore raw

Re: [kvm-ppc-devel] [PATCH 1 of 3] Move x86 kvmcallback structure to kvmctl-x86.h header

In reply to Hollis Blanchard
Quoted 4 lines · Hollis Blanchard

Also, can't x86 "rep" instructions go beyond 64 bits? I guess that must be handled in the arch-specific caller of io_write(), which would call it multiple times.

'rep' has special support in the ABI (it's N accesses of M bits, not an NxM bit access).

Signature · 8 lines
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/