Trivial: /dev/kvm interface is no longer experimental.
PATCH 1/10 Trivial: /dev/kvm interface is no longer experimental.
KVM interface is no longer experimental.
include/linux/kvm.h +1 -2
@@ -4,8 +4,7 @@/* * Userspace interface for /dev/kvm - kernel based virtual machine * -* Note: this interface is considered experimental and may change without -* notice. +* Note: you must update KVM_API_VERSION if you change this interface. */ #include <asm/types.h>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184677946.10380.4.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PATCH 2/10 Trivial: Remove KVM_IRQ_BITMAP macro
Creating one's own BITMAP macro seems suboptimal: if we use manual arithmetic in the one place exposed to userspace, we can use standard macros elsewhere.
The - 7 + 8 calc is overkill: can NR_IRQ_WORDS ever really change?
drivers/kvm/kvm.h +1 -2
@@ -342,8 +342,7 @@ struct kvm_vcpu {int guest_mode;unsigned long requests;unsigned long irq_summary;/* bit vector: 1 per word in irq_pending */ -#define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long) -unsigned long irq_pending[NR_IRQ_WORDS ]; +DECLARE_BITMAP (irq_pending,KVM_NR_INTERRUPTS );unsigned long regs[NR_VCPU_REGS ];/* for rsp: vcpu_load_rsp_rip() */ unsigned long rip;/* needs vcpu_load_rsp_rip() */
drivers/kvm/kvm_main.c +1 -1
@@ -2122,7 +2122,7 @@ static int kvm_vcpu_ioctl_set_sregs(strumemcpy (vcpu->irq_pending, sregs->interrupt_bitmap,sizeof vcpu->irq_pending); vcpu->irq_summary =0 ; -for (i =0 ; i <NR_IRQ_WORDS ; ++i) +for (i =0 ; i <ARRAY_SIZE (vcpu->irq_pending); ++i)if (vcpu->irq_pending[i])__set_bit (i, &vcpu->irq_summary);
include/linux/kvm.h +2 -8
@@ -12,14 +12,8 @@#define KVM_API_VERSION 12 -/* -* Architectural interrupt line count, and the size of the bitmap needed -* to hold them. -*/ +/* Architectural interrupt line count. */ #define KVM_NR_INTERRUPTS 256 -#define KVM_IRQ_BITMAP_SIZE_BYTES ((KVM_NR_INTERRUPTS + 7) / 8) -#define KVM_IRQ_BITMAP_SIZE (type) (KVM_IRQ_BITMAP_SIZE_BYTES / sizeof(type)) -/* for KVM_CREATE_MEMORY_REGION */ struct kvm_memory_region {
@@ -163,7 +157,7 @@ struct kvm_sregs {__u64 cr0, cr2, cr3, cr4, cr8;__u64 efer;__u64 apic_base; -__u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE (__u64)]; +__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS +7 ) /8 ]; };struct kvm_msr_entry {
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184678060.10380.7.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PATCH 3/10 Trivial: Remove unused struct cpu_user_regs declaration
drivers/kvm/x86_emulate.h +0 -2
@@ -112,8 +112,6 @@ struct x86_emulate_ops { }; -struct cpu_user_regs ; -struct x86_emulate_ctxt {/* Register state before/after emulation. */ struct kvm_vcpu *vcpu;
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184678129.10380.10.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PATCH 4/10 Trivial: Make decode_register() static
I have shied away from touching x86_emulate.c (it could definitely use some love, but it is forked from the Xen code, and it would be more productive to cross-merge fixes).
drivers/kvm/x86_emulate.c +7 -2
@@ -443,8 +443,13 @@ struct operand { (((reg) + _inc) & ((1UL << (ad_bytes <<3 )) -1 )); \ }while (0 ) -void *decode_register(u8 modrm_reg, unsigned long *regs, - int highbyte_regs) +/* +* Given the 'reg' portion of a ModRM byte, and a register block, return a +* pointer into the block that addresses the relevant register. +* @highbyte_regs specifies whether to decode AH,CH,DH,BH. +*/ +static void *decode_register(u8 modrm_reg, unsigned long *regs, +int highbyte_regs) {void *p;
drivers/kvm/x86_emulate.h +0 -8
@@ -152,12 +152,4 @@ int x86_emulate_memop(struct x86_emulateint x86_emulate_memop (struct x86_emulate_ctxt *ctxt,struct x86_emulate_ops *ops); -/* -* Given the 'reg' portion of a ModRM byte, and a register block, return a -* pointer into the block that addresses the relevant register. -* @highbyte_regs specifies whether to decode AH,CH,DH,BH. -*/ -void *decode_register (u8 modrm_reg,unsigned long *regs, -int highbyte_regs); -#endif /* __X86_EMULATE_H__ */
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184678171.10380.12.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PATCH 5/10 Trivial: Comment spelling may escape grep
Speling error in comment.
drivers/kvm/x86_emulate.c +1 -1
@@ -6,7 +6,7 @@* Copyright (c) 2005 Keir Fraser * * Linux coding style, mod r/m decoder, segment base fixes, real-mode -* privieged instructions: +* privileged instructions: * * Copyright (C) 2006 Qumranet *
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184678216.10380.14.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PATCH 6/10 Trivial: Avoid hardware_disable predeclaration
Don't pre-declare hardware_disable: shuffle the reboot hook down.
drivers/kvm/kvm_main.c +19 -21
@@ -53,8 +53,6 @@ static cpumask_t cpus_hardware_enabled;static cpumask_t cpus_hardware_enabled;struct kvm_arch_ops *kvm_arch_ops; - -static void hardware_disable (void *ignored);#define STAT_OFFSET (x) offsetof(struct kvm_vcpu, stat.x)
@@ -2930,25 +2928,6 @@ static struct miscdevice kvm_dev = { &kvm_chardev_ops, }; -static int kvm_reboot (struct notifier_block *notifier,unsigned long val, -void *v) -{ -if (val ==SYS_RESTART ) { -/* -* Some (well, at least mine) BIOSes hang on reboot if -* in vmx root mode. -*/ -printk (KERN_INFO "kvm: exiting hardware virtualization\n" ); -on_each_cpu (hardware_disable,NULL ,0 ,1 ); - } -return NOTIFY_OK ; -} - -static struct notifier_block kvm_reboot_notifier = { - .notifier_call = kvm_reboot, - .priority =0 , -}; -/* * Make sure that a cpu that is being hot-unplugged does not have any vcpus * cached on it.
@@ -3027,6 +3006,25 @@ static int kvm_cpu_hotplug(struct notifireturn NOTIFY_OK ; } +static int kvm_reboot (struct notifier_block *notifier,unsigned long val, +void *v) +{ +if (val ==SYS_RESTART ) { +/* +* Some (well, at least mine) BIOSes hang on reboot if +* in vmx root mode. +*/ +printk (KERN_INFO "kvm: exiting hardware virtualization\n" ); +on_each_cpu (hardware_disable,NULL ,0 ,1 ); + } +return NOTIFY_OK ; +} + +static struct notifier_block kvm_reboot_notifier = { + .notifier_call = kvm_reboot, + .priority =0 , +}; +void kvm_io_bus_init (struct kvm_io_bus *bus) {memset (bus,0 ,sizeof (*bus));
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184678275.10380.16.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PATCH 7/10 Trivial: Use standard CR0 flags macros from asm/cpu-features.h
The kernel now has asm/cpu-features.h: use those macros instead of inventing our own.
Also spell out definition of CR0_RESEVED_BITS (no code change) and fix typo.
drivers/kvm/kvm.h +5 -14
@@ -19,15 +19,6 @@#include <linux/kvm.h> #include <linux/kvm_para.h> -#define CR0_PE_MASK (1ULL << 0) -#define CR0_MP_MASK (1ULL << 1) -#define CR0_TS_MASK (1ULL << 3) -#define CR0_NE_MASK (1ULL << 5) -#define CR0_WP_MASK (1ULL << 16) -#define CR0_NW_MASK (1ULL << 29) -#define CR0_CD_MASK (1ULL << 30) -#define CR0_PG_MASK (1ULL << 31) -#define CR3_WPT_MASK (1ULL << 3)#define CR3_PCD_MASK (1ULL << 4)
@@ -42,11 +33,11 @@#define CR4_VMXE_MASK (1ULL << 13)#define KVM_GUEST_CR0_MASK \ - (CR0_PG_MASK | CR0_PE_MASK | CR0_WP_MASK | CR0_NE_MASK \ - | CR0_NW_MASK | CR0_CD_MASK) + (X86_CR0_PG | X86_CR0_PE | X86_CR0_WP | X86_CR0_NE \ + | X86_CR0_NW | X86_CR0_CD)#define KVM_VM_CR0_ALWAYS_ON \ - (CR0_PG_MASK | CR0_PE_MASK | CR0_WP_MASK | CR0_NE_MASK | CR0_TS_MASK \ - | CR0_MP_MASK) + (X86_CR0_PG | X86_CR0_PE | X86_CR0_WP | X86_CR0_NE | X86_CR0_TS \ + | X86_CR0_MP)#define KVM_GUEST_CR4_MASK \ (CR4_PSE_MASK | CR4_PAE_MASK | CR4_PGE_MASK | CR4_VMXE_MASK | CR4_VME_MASK)#define KVM_PMODE_VM_CR4_ALWAYS_ON (CR4_VMXE_MASK | CR4_PAE_MASK)
@@ -660,7 +651,7 @@ static inline int is_pse(struct kvm_vcpustatic inline int is_paging (struct kvm_vcpu *vcpu) { -return vcpu->cr0 &CR0_PG_MASK ; +return vcpu->cr0 &X86_CR0_PG ; }static inline int memslot_id (struct kvm *kvm,struct kvm_memory_slot *slot)
drivers/kvm/kvm_main.c +9 -6
@@ -82,7 +82,10 @@ static struct dentry *debugfs_dir;#define MAX_IO_MSRS 256 -#define CR0_RESEVED_BITS 0xffffffff1ffaffc0ULL +#define CR0_RESERVED_BITS \ + (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \ + | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \ + | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))#define LMSW_GUEST_MASK 0x0eULL#define CR4_RESEVED_BITS (~((1ULL << 11) - 1))#define CR8_RESEVED_BITS (~0x0fULL)
@@ -483,27 +486,27 @@ out:void set_cr0 (struct kvm_vcpu *vcpu,unsigned long cr0) { -if (cr0 &CR0_RESEVED_BITS ) { +if (cr0 &CR0_RESERVED_BITS ) {printk (KERN_DEBUG "set_cr0: 0x%lx #GP, reserved bits 0x%lx\n" , cr0, vcpu->cr0);inject_gp (vcpu);return ; } -if ((cr0 &CR0_NW_MASK ) && !(cr0 &CR0_CD_MASK )) { +if ((cr0 &X86_CR0_NW ) && !(cr0 &X86_CR0_CD )) {printk (KERN_DEBUG "set_cr0: #GP, CD == 0 && NW == 1\n" );inject_gp (vcpu);return ; } -if ((cr0 &CR0_PG_MASK ) && !(cr0 &CR0_PE_MASK )) { +if ((cr0 &X86_CR0_PG ) && !(cr0 &X86_CR0_PE )) {printk (KERN_DEBUG "set_cr0: #GP, set PG flag " "and a clear PE flag\n" );inject_gp (vcpu);return ; } -if (!is_paging (vcpu) && (cr0 &CR0_PG_MASK )) { +if (!is_paging (vcpu) && (cr0 &X86_CR0_PG )) {#ifdef CONFIG_X86_64 if ((vcpu->shadow_efer &EFER_LME )) {int cs_db, cs_l;
@@ -1190,7 +1193,7 @@ int emulate_clts(struct kvm_vcpu *vcpu) {unsigned long cr0; - cr0 = vcpu->cr0 & ~CR0_TS_MASK ; + cr0 = vcpu->cr0 & ~X86_CR0_TS ; kvm_arch_ops->set_cr0 (vcpu, cr0);return X86EMUL_CONTINUE ; }
drivers/kvm/mmu.c +1 -1
@@ -159,7 +159,7 @@ static struct kmem_cache *mmu_page_headestatic int is_write_protection (struct kvm_vcpu *vcpu) { -return vcpu->cr0 &CR0_WP_MASK ; +return vcpu->cr0 &X86_CR0_WP ; }static int is_cpuid_PSE36 (void )
drivers/kvm/svm.c +10 -10
@@ -99,7 +99,7 @@ static unsigned get_addr_size(struct kvmstruct vmcb_save_area *sa = &vcpu->svm->vmcb->save;u16 cs_attrib; -if (!(sa->cr0 &CR0_PE_MASK ) || (sa->rflags &X86_EFLAGS_VM )) +if (!(sa->cr0 &X86_CR0_PE ) || (sa->rflags &X86_EFLAGS_VM ))return 2 ; cs_attrib = sa->cs.attrib;
@@ -563,7 +563,7 @@ static void init_vmcb(struct vmcb *vmcb)* cr0 val on cpu init should be 0x60000010, we enable cpu * cache by default. the orderly way is to enable cache in bios. */ - save->cr0 =0x00000010 |CR0_PG_MASK |CR0_WP_MASK ; + save->cr0 =0x00000010 |X86_CR0_PG |X86_CR0_WP ; save->cr4 =CR4_PAE_MASK ;/* rdx = ?? */ }
@@ -756,25 +756,25 @@ static void svm_set_cr0(struct kvm_vcpu {#ifdef CONFIG_X86_64 if (vcpu->shadow_efer &KVM_EFER_LME ) { -if (!is_paging (vcpu) && (cr0 &CR0_PG_MASK )) { +if (!is_paging (vcpu) && (cr0 &X86_CR0_PG )) { vcpu->shadow_efer |=KVM_EFER_LMA ; vcpu->svm->vmcb->save.efer |=KVM_EFER_LMA |KVM_EFER_LME ; } -if (is_paging (vcpu) && !(cr0 &CR0_PG_MASK ) ) { +if (is_paging (vcpu) && !(cr0 &X86_CR0_PG ) ) { vcpu->shadow_efer &= ~KVM_EFER_LMA ; vcpu->svm->vmcb->save.efer &= ~(KVM_EFER_LMA |KVM_EFER_LME ); } }#endif -if ((vcpu->cr0 &CR0_TS_MASK ) && !(cr0 &CR0_TS_MASK )) { +if ((vcpu->cr0 &X86_CR0_TS ) && !(cr0 &X86_CR0_TS )) { vcpu->svm->vmcb->control.intercept_exceptions &= ~(1 <<NM_VECTOR ); vcpu->fpu_active =1 ; } vcpu->cr0 = cr0; - cr0 |=CR0_PG_MASK |CR0_WP_MASK ; - cr0 &= ~(CR0_CD_MASK |CR0_NW_MASK ); + cr0 |=X86_CR0_PG |X86_CR0_WP ; + cr0 &= ~(X86_CR0_CD |X86_CR0_NW ); vcpu->svm->vmcb->save.cr0 = cr0; }
@@ -945,8 +945,8 @@ static int nm_interception(struct kvm_vcstatic int nm_interception (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) { vcpu->svm->vmcb->control.intercept_exceptions &= ~(1 <<NM_VECTOR ); -if (!(vcpu->cr0 &CR0_TS_MASK )) - vcpu->svm->vmcb->save.cr0 &= ~CR0_TS_MASK ; +if (!(vcpu->cr0 &X86_CR0_TS )) + vcpu->svm->vmcb->save.cr0 &= ~X86_CR0_TS ; vcpu->fpu_active =1 ;return 1 ;
@@ -1702,7 +1702,7 @@ static void svm_set_cr3(struct kvm_vcpuif (vcpu->fpu_active) { vcpu->svm->vmcb->control.intercept_exceptions |= (1 <<NM_VECTOR ); - vcpu->svm->vmcb->save.cr0 |=CR0_TS_MASK ; + vcpu->svm->vmcb->save.cr0 |=X86_CR0_TS ; vcpu->fpu_active =0 ; } }
drivers/kvm/vmx.c +11 -11
@@ -436,9 +436,9 @@ static void vmx_fpu_activate(struct kvm_if (vcpu->fpu_active)return ; vcpu->fpu_active =1 ; -vmcs_clear_bits (GUEST_CR0 ,CR0_TS_MASK ); -if (vcpu->cr0 &CR0_TS_MASK ) -vmcs_set_bits (GUEST_CR0 ,CR0_TS_MASK ); +vmcs_clear_bits (GUEST_CR0 ,X86_CR0_TS ); +if (vcpu->cr0 &X86_CR0_TS ) +vmcs_set_bits (GUEST_CR0 ,X86_CR0_TS );update_exception_bitmap (vcpu); }
@@ -447,7 +447,7 @@ static void vmx_fpu_deactivate(struct kvif (!vcpu->fpu_active)return ; vcpu->fpu_active =0 ; -vmcs_set_bits (GUEST_CR0 ,CR0_TS_MASK ); +vmcs_set_bits (GUEST_CR0 ,X86_CR0_TS );update_exception_bitmap (vcpu); }
@@ -1002,17 +1002,17 @@ static void vmx_set_cr0(struct kvm_vcpu {vmx_fpu_deactivate (vcpu); -if (vcpu->rmode.active && (cr0 &CR0_PE_MASK )) +if (vcpu->rmode.active && (cr0 &X86_CR0_PE ))enter_pmode (vcpu); -if (!vcpu->rmode.active && !(cr0 &CR0_PE_MASK )) +if (!vcpu->rmode.active && !(cr0 &X86_CR0_PE ))enter_rmode (vcpu);#ifdef CONFIG_X86_64 if (vcpu->shadow_efer &EFER_LME ) { -if (!is_paging (vcpu) && (cr0 &CR0_PG_MASK )) +if (!is_paging (vcpu) && (cr0 &X86_CR0_PG ))enter_lmode (vcpu); -if (is_paging (vcpu) && !(cr0 &CR0_PG_MASK )) +if (is_paging (vcpu) && !(cr0 &X86_CR0_PG ))exit_lmode (vcpu); }#endif
@@ -1022,14 +1022,14 @@ static void vmx_set_cr0(struct kvm_vcpu (cr0 & ~KVM_GUEST_CR0_MASK) | KVM_VM_CR0_ALWAYS_ON); vcpu->cr0 = cr0; -if (!(cr0 &CR0_TS_MASK ) || !(cr0 &CR0_PE_MASK )) +if (!(cr0 &X86_CR0_TS ) || !(cr0 &X86_CR0_PE ))vmx_fpu_activate (vcpu); }static void vmx_set_cr3 (struct kvm_vcpu *vcpu,unsigned long cr3) {vmcs_writel (GUEST_CR3 , cr3); -if (vcpu->cr0 &CR0_PE_MASK ) +if (vcpu->cr0 &X86_CR0_PE )vmx_fpu_deactivate (vcpu); }
@@ -1778,7 +1778,7 @@ static int handle_cr(struct kvm_vcpu *vccase 2 :/* clts */ vcpu_load_rsp_rip (vcpu);vmx_fpu_deactivate (vcpu); - vcpu->cr0 &= ~CR0_TS_MASK ; + vcpu->cr0 &= ~X86_CR0_TS ;vmcs_writel (CR0_READ_SHADOW , vcpu->cr0);vmx_fpu_activate (vcpu);skip_emulated_instruction (vcpu);
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184678348.10380.19.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PATCH 8/10 Use standard CR3 flags, tighten checking
The kernel now has asm/cpu-features.h: use those macros instead of inventing our own.
Also spell out definition of CR3_RESEVED_BITS, fix spelling and tighten it for the non-PAE case.
drivers/kvm/kvm.h +3 -6
@@ -19,12 +19,9 @@#include <linux/kvm.h> #include <linux/kvm_para.h> -#define CR3_WPT_MASK (1ULL << 3) -#define CR3_PCD_MASK (1ULL << 4) - -#define CR3_RESEVED_BITS 0x07ULL -#define CR3_L_MODE_RESEVED_BITS (~((1ULL << 40) - 1) | 0x0fe7ULL) -#define CR3_FLAGS_MASK ((1ULL << 5) - 1) +#define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1) +#define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD)) +#define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS|0xFFFFFF0000000000ULL)#define CR4_VME_MASK (1ULL << 0)#define CR4_PSE_MASK (1ULL << 4)
drivers/kvm/kvm_main.c +21 -12
@@ -588,23 +588,32 @@ void set_cr3(struct kvm_vcpu *vcpu, unsivoid set_cr3 (struct kvm_vcpu *vcpu,unsigned long cr3) {if (is_long_mode (vcpu)) { -if (cr3 &CR3_L_MODE_RESEVED_BITS ) { +if (cr3 &CR3_L_MODE_RESERVED_BITS ) {printk (KERN_DEBUG "set_cr3: #GP, reserved bits\n" );inject_gp (vcpu);return ; } }else { -if (cr3 &CR3_RESEVED_BITS ) { -printk (KERN_DEBUG "set_cr3: #GP, reserved bits\n" ); -inject_gp (vcpu); -return ; - } -if (is_paging (vcpu) &&is_pae (vcpu) && - !load_pdptrs (vcpu, cr3)) { -printk (KERN_DEBUG "set_cr3: #GP, pdptrs " -"reserved bits\n" ); -inject_gp (vcpu); -return ; +if (is_pae (vcpu)) { +if (cr3 &CR3_PAE_RESERVED_BITS ) { +printk (KERN_DEBUG +"set_cr3: #GP, reserved bits\n" ); +inject_gp (vcpu); +return ; + } +if (is_paging (vcpu) && !load_pdptrs (vcpu, cr3)) { +printk (KERN_DEBUG "set_cr3: #GP, pdptrs " +"reserved bits\n" ); +inject_gp (vcpu); +return ; + } + }else { +if (cr3 &CR3_NONPAE_RESERVED_BITS ) { +printk (KERN_DEBUG +"set_cr3: #GP, reserved bits\n" ); +inject_gp (vcpu); +return ; + } } }
drivers/kvm/paging_tmpl.h +1 -1
@@ -99,7 +99,7 @@ static int FNAME(walk_addr)(struct guest walker->table =kmap_atomic (pfn_to_page (hpa >>PAGE_SHIFT ),KM_USER0 );ASSERT ((!is_long_mode (vcpu) &&is_pae (vcpu)) || - (vcpu->cr3 & ~(PAGE_MASK |CR3_FLAGS_MASK )) ==0 ); + (vcpu->cr3 &CR3_NONPAE_RESERVED_BITS ) ==0 ); walker->inherited_ar =PT_USER_MASK |PT_WRITABLE_MASK ;
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184679175.10380.25.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PATCH 9/10 Use standard CR4 flags, tighten checking
On this machine (Intel), writing to the CR4 bits 0x00000800 and 0x00001000 cause a GPF. The Intel manual is a little unclear, but AFIACT they're reserved, too.
Also fix spelling of CR4_RESEVED_BITS.
drivers/kvm/kvm.h +5 -11
@@ -23,12 +23,6 @@#define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD))#define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS|0xFFFFFF0000000000ULL) -#define CR4_VME_MASK (1ULL << 0) -#define CR4_PSE_MASK (1ULL << 4) -#define CR4_PAE_MASK (1ULL << 5) -#define CR4_PGE_MASK (1ULL << 7) -#define CR4_VMXE_MASK (1ULL << 13) -#define KVM_GUEST_CR0_MASK \ (X86_CR0_PG | X86_CR0_PE | X86_CR0_WP | X86_CR0_NE \ | X86_CR0_NW | X86_CR0_CD)
@@ -36,9 +30,9 @@ (X86_CR0_PG |X86_CR0_PE |X86_CR0_WP |X86_CR0_NE |X86_CR0_TS \ | X86_CR0_MP)#define KVM_GUEST_CR4_MASK \ - (CR4_PSE_MASK | CR4_PAE_MASK | CR4_PGE_MASK | CR4_VMXE_MASK | CR4_VME_MASK) -#define KVM_PMODE_VM_CR4_ALWAYS_ON (CR4_VMXE_MASK | CR4_PAE_MASK) -#define KVM_RMODE_VM_CR4_ALWAYS_ON (CR4_VMXE_MASK | CR4_PAE_MASK | CR4_VME_MASK) + (X86_CR4_VME | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE | X86_CR4_VMXE) +#define KVM_PMODE_VM_CR4_ALWAYS_ON (X86_CR4_PAE | X86_CR4_VMXE) +#define KVM_RMODE_VM_CR4_ALWAYS_ON (X86_CR4_VME | X86_CR4_PAE | X86_CR4_VMXE)#define INVALID_PAGE (~(hpa_t)0)#define UNMAPPED_GVA (~(gpa_t)0)
@@ -638,12 +632,12 @@ static inline int is_long_mode(struct kvstatic inline int is_pae (struct kvm_vcpu *vcpu) { -return vcpu->cr4 &CR4_PAE_MASK ; +return vcpu->cr4 &X86_CR4_PAE ; }static inline int is_pse (struct kvm_vcpu *vcpu) { -return vcpu->cr4 &CR4_PSE_MASK ; +return vcpu->cr4 &X86_CR4_PSE ; }static inline int is_paging (struct kvm_vcpu *vcpu)
drivers/kvm/kvm_main.c +10 -6
@@ -86,8 +86,12 @@ static struct dentry *debugfs_dir; (~(unsigned long )(X86_CR0_PE |X86_CR0_MP |X86_CR0_EM |X86_CR0_TS \ |X86_CR0_ET |X86_CR0_NE |X86_CR0_WP |X86_CR0_AM \ | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG)) -#define LMSW_GUEST_MASK 0x0eULL -#define CR4_RESEVED_BITS (~((1ULL << 11) - 1)) +#define CR4_RESERVED_BITS \ + (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\ + | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \ + | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR \ + | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE)) +#define CR8_RESEVED_BITS (~0x0fULL)#define EFER_RESERVED_BITS 0xfffffffffffff2fe
@@ -554,26 +558,26 @@ EXPORT_SYMBOL_GPL(lmsw);void set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4) { -if (cr4 &CR4_RESEVED_BITS ) { +if (cr4 &CR4_RESERVED_BITS ) {printk (KERN_DEBUG "set_cr4: #GP, reserved bits\n" );inject_gp (vcpu);return ; }if (is_long_mode (vcpu)) { -if (!(cr4 &CR4_PAE_MASK )) { +if (!(cr4 &X86_CR4_PAE )) {printk (KERN_DEBUG "set_cr4: #GP, clearing PAE while " "in long mode\n" );inject_gp (vcpu);return ; } - }else if (is_paging (vcpu) && !is_pae (vcpu) && (cr4 &CR4_PAE_MASK ) + }else if (is_paging (vcpu) && !is_pae (vcpu) && (cr4 &X86_CR4_PAE ) && !load_pdptrs (vcpu, vcpu->cr3)) {printk (KERN_DEBUG "set_cr4: #GP, pdptrs reserved bits\n" );inject_gp (vcpu); } -if (cr4 &CR4_VMXE_MASK ) { +if (cr4 &X86_CR4_VMXE ) {printk (KERN_DEBUG "set_cr4: #GP, setting VMXE\n" );inject_gp (vcpu);return ;
drivers/kvm/svm.c +3 -4
@@ -38,7 +38,6 @@ MODULE_LICENSE("GPL");#define DR7_GD_MASK (1 << 13)#define DR6_BD_MASK (1 << 13) -#define CR4_DE_MASK (1UL << 3)#define SEG_TYPE_LDT 2#define SEG_TYPE_BUSY_TSS16 3
@@ -564,7 +563,7 @@ static void init_vmcb(struct vmcb *vmcb)* cache by default. the orderly way is to enable cache in bios. */ save->cr0 =0x00000010 |X86_CR0_PG |X86_CR0_WP ; - save->cr4 =CR4_PAE_MASK ; + save->cr4 =X86_CR4_PAE ;/* rdx = ?? */ }
@@ -781,7 +780,7 @@ static void svm_set_cr4(struct kvm_vcpustatic void svm_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4) { vcpu->cr4 = cr4; - vcpu->svm->vmcb->save.cr4 = cr4 |CR4_PAE_MASK ; + vcpu->svm->vmcb->save.cr4 = cr4 |X86_CR4_PAE ; } static void svm_set_segment(struct kvm_vcpu *vcpu,
@@ -877,7 +876,7 @@ static void svm_set_dr(struct kvm_vcpu * vcpu->svm->db_regs[dr] = value;return ; case 4 ... 5: -if (vcpu->cr4 &CR4_DE_MASK ) { +if (vcpu->cr4 &X86_CR4_DE ) { *exception =UD_VECTOR ;return ; }
drivers/kvm/vmx.c +4 -4
@@ -764,7 +764,7 @@ static void hardware_enable(void *garbagif ((old &5 ) !=5 )/* enable and lock */ wrmsrl (MSR_IA32_FEATURE_CONTROL , old |5 ); -write_cr4 (read_cr4 () |CR4_VMXE );/* FIXME: not cpu hotplug safe */ +write_cr4 (read_cr4 () |X86_CR4_VMXE );/* FIXME: not cpu hotplug safe */ asm volatile (ASM_VMX_VMXON_RAX : : "a"(&phys_addr), "m"(phys_addr) : "memory", "cc"); }
@@ -879,8 +879,8 @@ static void enter_pmode(struct kvm_vcpu flags |= (vcpu->rmode.save_iopl <<IOPL_SHIFT );vmcs_writel (GUEST_RFLAGS , flags); -vmcs_writel (GUEST_CR4 , (vmcs_readl (GUEST_CR4 ) & ~CR4_VME_MASK ) | - (vmcs_readl (CR4_READ_SHADOW ) &CR4_VME_MASK )); +vmcs_writel (GUEST_CR4 , (vmcs_readl (GUEST_CR4 ) & ~X86_CR4_VME ) | + (vmcs_readl (CR4_READ_SHADOW ) &X86_CR4_VME ));update_exception_bitmap (vcpu);
@@ -937,7 +937,7 @@ static void enter_rmode(struct kvm_vcpu flags |=IOPL_MASK |X86_EFLAGS_VM ;vmcs_writel (GUEST_RFLAGS , flags); -vmcs_writel (GUEST_CR4 ,vmcs_readl (GUEST_CR4 ) |CR4_VME_MASK ); +vmcs_writel (GUEST_CR4 ,vmcs_readl (GUEST_CR4 ) |X86_CR4_VME );update_exception_bitmap (vcpu);vmcs_write16 (GUEST_SS_SELECTOR ,vmcs_readl (GUEST_SS_BASE ) >>4 );
drivers/kvm/vmx.h +0 -2
@@ -285,8 +285,6 @@ enum vmcs_field {#define AR_RESERVD_MASK 0xfffe0f00 -#define CR4_VMXE 0x2000 -#define MSR_IA32_VMX_BASIC 0x480#define MSR_IA32_FEATURE_CONTROL 0x03a#define MSR_IA32_VMX_PINBASED_CTLS 0x481
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 10/10 Use standard CR8 flags, and fix TPR definition
Intel manual (and KVM definition) say it's TPR is 4 bits wide. Also fix CR8_RESEVED_BITS typo.
drivers/kvm/kvm_main.c +2 -2
@@ -92,7 +92,7 @@ static struct dentry *debugfs_dir; | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR \ | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE)) -#define CR8_RESEVED_BITS (~0x0fULL) +#define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)#define EFER_RESERVED_BITS 0xfffffffffffff2fe#ifdef CONFIG_X86_64
@@ -633,7 +633,7 @@ EXPORT_SYMBOL_GPL(set_cr3);void set_cr8 (struct kvm_vcpu *vcpu,unsigned long cr8) { -if ( cr8 &CR8_RESEVED_BITS ) { +if (cr8 &CR8_RESERVED_BITS ) {printk (KERN_DEBUG "set_cr8: #GP, reserved bits 0x%lx\n" , cr8);inject_gp (vcpu);return ;
include/asm-i386/processor-flags.h +1 -1
@@ -63,7 +63,7 @@/* * x86-64 Task Priority Register, CR8 */ -#define X86_CR8_TPR 0x00000007/* task priority register */ +#define X86_CR8_TPR 0x0000000F/* task priority register */ /* * AMD and Transmeta use MSRs for configuration; see <asm/msr-index.h>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Re: [PATCH 10/10] Use standard CR8 flags, and fix TPR definition
Quoted 11 lines · Rusty Russell
Intel manual (and KVM definition) say it's TPR is 4 bits wide. Also fix
CR8_RESEVED_BITStypo.Signed-off-by Rusty Russell <[email protected]>diff -r
6ef0b4c0d6f7include/asm-i386/processor-flags.h
include/asm-i386/processor-flags.h line 69
Quoted 8 lines
include/asm-i386/processor-flags.h +1
-1@@ -63,7 +63,7 @@/* * x86-64 Task Priority Register, CR8 */ -#define X86_CR8_TPR 0x00000007/* task priority register */ +#define X86_CR8_TPR 0x0000000F/* task priority register */ /* * AMD and Transmeta use MSRs for configuration; see <asm/msr-index.h>
X86_CR8_TPR is not used in the kernel. But is this meant to be a mask, or something else?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 10/10] Use standard CR8 flags, and fix TPR definition
Quoted 4 lines · Avi Kivity
X86_CR8_TPRis not used in the kernel. But is this meant to be a mask, or something else?
Yes, a mask.
And no, it's not used, except for KVM...
-hpa
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Re: [PATCH 10/10] Use standard CR8 flags, and fix TPR definition
In reply to Rusty RussellQuoted 4 lines · Rusty Russell
Intel manual (and KVM definition) say it's TPR is 4 bits wide. Also fix
CR8_RESEVED_BITStypo.Signed-off-by Rusty Russell <rusty-8n+1lVoiYb80n/[email protected]>
Indeed it is.
-hpa
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Re: [PATCH 10/10] Use standard CR8 flags, and fix TPR definition
Quoted 5 lines · H. Peter Anvin
Quoted 3 lines · Rusty Russell
Intel manual (and KVM definition) say it's TPR is 4 bits wide. Also fix
CR8_RESEVED_BITStypo.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Rusty Russell <rusty-8n+1lVoiYb80n/[email protected]>Indeed it is.
Acked-by H. Peter Anvin <[email protected]>
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184679256.10380.27.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
Avi Kivity
AppliedRe: [PATCH 9/10] Use standard CR4 flags, tighten checking
Quoted 7 lines · Rusty Russell
On this machine (Intel), writing to the CR4 bits
0x00000800and0x00001000cause a GPF. The Intel manual is a little unclear, but AFIACT they're reserved, too.Also fix spelling of
CR4_RESEVED_BITS.
Applied, thanks.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Avi Kivity
AppliedRe: [PATCH 8/10] Use standard CR3 flags, tighten checking
In reply to a message not in the archiveQuoted 6 lines · Rusty Russell
The kernel now has
asm/cpu-features.h: use those macros instead of inventing our own.Also spell out definition of
CR3_RESEVED_BITS, fix spelling and tighten it for the non-PAE case.
Applied, thanks. Watch out for trailing whitespace!
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Re: [PATCH 7/10] Trivial: Use standard CR0 flags macros from asm/cpu-features.h
In reply to a message not in the archiveQuoted 5 lines · Rusty Russell
The kernel now has
asm/cpu-features.h: use those macros instead of inventing our own.Also spell out definition of
CR0_RESEVED_BITS(no code change) and fix typo.
Long overdue. Applied, thanks.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Avi Kivity
AppliedRe: [PATCH 6/10] Trivial: Avoid hardware_disable predeclaration
In reply to a message not in the archiveQuoted 2 lines · Rusty Russell
Don't pre-declare
hardware_disable: shuffle the reboot hook down.
Applied, thanks.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Re: [PATCH 5/10] Trivial: Comment spelling may escape grep
In reply to a message not in the archiveQuoted 3 lines · Rusty Russell
Speling error in comment.
Aplied, thanks.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Avi Kivity
AppliedRe: [PATCH 4/10] Trivial: Make decode_register() static
In reply to a message not in the archiveQuoted 5 lines · Rusty Russell
I have shied away from touching
x86_emulate.c(it could definitely use some love, but it is forked from the Xen code, and it would be more productive to cross-merge fixes).
Applied, thanks.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Avi Kivity
AppliedRe: [PATCH 3/10] Trivial: Remove unused struct cpu_user_regs declaration
In reply to a message not in the archiveQuoted 8 lines · Rusty Russell
Signed-off-by Rusty Russell <rusty-8n+1lVoiYb80n/[email protected]>diff -r
725f52d66cc0drivers/kvm/x86_emulate.h
drivers/kvm/x86_emulate.h struct x86_emulate_ops { · line 117
Quoted 8 lines
drivers/kvm/x86_emulate.h +0
-2@@ -112,8 +112,6 @@ struct x86_emulate_ops { }; -struct cpu_user_regs ; -struct x86_emulate_ctxt {/* Register state before/after emulation. */ struct kvm_vcpu *vcpu;
Applied, thanks.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Re: [PATCH 2/10] Trivial: Remove KVM_IRQ_BITMAP macro
In reply to a message not in the archiveQuoted 6 lines · Rusty Russell
Creating one's own BITMAP macro seems suboptimal: if we use manual arithmetic in the one place exposed to userspace, we can use standard macros elsewhere.
The - 7 + 8 calc is overkill: can
NR_IRQ_WORDSever really change?
Looks like it can:
include/linux/kvm.h struct kvm_sregs { · line 163
Quoted 12 lines
/* for
KVM_CREATE_MEMORY_REGION*/
structkvm_memory_region{include/linux/kvm.h +1
-1@@ -163,7 +157,7 @@ struct kvm_sregs {__u64 cr0, cr2, cr3, cr4, cr8;__u64 efer;__u64 apic_base; -__u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE (__u64)]; +__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS +7 ) /8 ]; };
The size is in bytes, but the element type is __u64.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 469CC367.1000107-atKUWr5tajBWk0Htik3J/[email protected]
Re: [PATCH 2/10] Trivial: Remove KVM_IRQ_BITMAP macro
Quoted 9 lines · Avi Kivity
Quoted 6 lines · Rusty Russell
Creating one's own BITMAP macro seems suboptimal: if we use manual arithmetic in the one place exposed to userspace, we can use standard macros elsewhere.
The - 7 + 8 calc is overkill: can
NR_IRQ_WORDSever really change?Looks like it can:
Sure, but the number 256 is part of the x86 architecture. A paravirt guest could choose to have more interrupts, but is there really a point?
Quoted 5 lines
Quoted 5 lines
/* for
KVM_CREATE_MEMORY_REGION*/
structkvm_memory_region{(quoted diff) +0
-0@@ -163,7 +157,7 @@ struct kvm_sregs { __u64 cr0, cr2, cr3, cr4, cr8; __u64 efer;
Quoted 8 lines
Review struct kvm_sregs { · line 163
Quoted 6 lines
(quoted diff) +1
-1__u64 apic_base; - __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)]; + __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 7) / 8]; };The size is in bytes, but the element type is
__u64.
Doh, fixed here:
==
Use standard BITMAP macros, open-code userspace-exposed header.
Creating one's own BITMAP macro seems suboptimal: if we use manual arithmetic in the one place exposed to userspace, we can use standard macros elsewhere.
drivers/kvm/kvm.h +1 -2
@@ -342,8 +342,7 @@ struct kvm_vcpu {int guest_mode;unsigned long requests;unsigned long irq_summary;/* bit vector: 1 per word in irq_pending */ -#define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long) -unsigned long irq_pending[NR_IRQ_WORDS ]; +DECLARE_BITMAP (irq_pending,KVM_NR_INTERRUPTS );unsigned long regs[NR_VCPU_REGS ];/* for rsp: vcpu_load_rsp_rip() */ unsigned long rip;/* needs vcpu_load_rsp_rip() */
drivers/kvm/kvm_main.c +1 -1
@@ -2122,7 +2122,7 @@ static int kvm_vcpu_ioctl_set_sregs(strumemcpy (vcpu->irq_pending, sregs->interrupt_bitmap,sizeof vcpu->irq_pending); vcpu->irq_summary =0 ; -for (i =0 ; i <NR_IRQ_WORDS ; ++i) +for (i =0 ; i <ARRAY_SIZE (vcpu->irq_pending); ++i)if (vcpu->irq_pending[i])__set_bit (i, &vcpu->irq_summary);
include/linux/kvm.h +2 -8
@@ -12,14 +12,8 @@#define KVM_API_VERSION 12 -/* -* Architectural interrupt line count, and the size of the bitmap needed -* to hold them. -*/ +/* Architectural interrupt line count. */ #define KVM_NR_INTERRUPTS 256 -#define KVM_IRQ_BITMAP_SIZE_BYTES ((KVM_NR_INTERRUPTS + 7) / 8) -#define KVM_IRQ_BITMAP_SIZE (type) (KVM_IRQ_BITMAP_SIZE_BYTES / sizeof(type)) -/* for KVM_CREATE_MEMORY_REGION */ struct kvm_memory_region {
@@ -163,7 +157,7 @@ struct kvm_sregs {__u64 cr0, cr2, cr3, cr4, cr8;__u64 efer;__u64 apic_base; -__u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE (__u64)]; +__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS +63 ) /64 ]; };struct kvm_msr_entry {
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184727958.10380.54.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
Avi Kivity
AppliedRe: [PATCH 2/10] Trivial: Remove KVM_IRQ_BITMAP macro
Quoted 8 lines · Rusty Russell
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Rusty Russell
Creating one's own BITMAP macro seems suboptimal: if we use manual arithmetic in the one place exposed to userspace, we can use standard macros elsewhere.
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
The - 7 + 8 calc is overkill: can
NR_IRQ_WORDSever really change?Looks like it can:
Sure, but the number 256 is part of the x86 architecture. A paravirt guest could choose to have more interrupts, but is there really a point?
I meant that you yourself, Rusty Russell, extended it to 2048 with your arithmetic. Sorry for being unclear.
Quoted 9 lines
Doh, fixed here:
==
Use standard BITMAP macros, open-code userspace-exposed header.Creating one's own BITMAP macro seems suboptimal: if we use manual arithmetic in the one place exposed to userspace, we can use standard macros elsewhere.
Applied, thanks.
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Quoted 11 lines · Rusty Russell
KVM interface is no longer experimental.
Signed-off-by Rusty Russell <rusty-8n+1lVoiYb80n/[email protected]>diff -r
4e57f5c6d4a9include/linux/kvm.h
include/linux/kvm.h line 10
Quoted 9 lines
include/linux/kvm.h +1
-2@@ -4,8 +4,7 @@/* * Userspace interface for /dev/kvm - kernel based virtual machine * -* Note: this interface is considered experimental and may change without -* notice. +* Note: you must update KVM_API_VERSION if you change this interface. */ #include <asm/types.h>
Applied, thanks. What about CONFIG_EXPERIMENTAL?
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Quoted 8 lines · Rusty Russell
KVM interface is no longer experimental.
Signed-off-by Rusty Russell <rusty-8n+1lVoiYb80n/[email protected]>diff -r
4e57f5c6d4a9include/linux/kvm.h
include/linux/kvm.h Tue Jul 17 13:09:54 2007 +1000 line 8
Quoted 7 lines
include/linux/kvm.h Tue Jul 17 13:09:54 2007 +1000 renamed from include/linux/kvm.h Tue Jul 17 13:04:58 2007 +1000 +1
-2@@ -4,8 +4,7 @@ /* * Userspace interface for /dev/kvm - kernel based virtual machine * - * Note: this interface is considered experimental and may change without - * notice. + * Note: you must update KVM_API_VERSION if you change this interface. */
I don't like the idea of making this interface official. If this is the point where we think it's perfect, it should become a set of real system calls instead.
At that point, incompatible API changes are simply not acceptable any more, and the bar should be raised as high as possible. With a system call, you basically have to allocate a new syscall number if you need to add another parameter or similar, and yuo need to keep the behaviour of the old number for eternity.
The equivalent of the current set of ioctls comes down to roughtly this set of syscalls:
int kvm_create_vm(void);
int kvm_get_msr_index_list(int fd, sttuct kvm_msr_list); size_t kvm_get_vcpu_mmap_size(int fd);
int kvm_set_memory_region(int fd, unsigned slot, unsigned flags,
__u64 guest_phys_addr, __u64 size);
int kvm_create_vcpu(int fd);
int kvm_get_dirty_log(int fd, unsigned slot, void *dirty_bitmap); int kvm_get_memory_alias(int fd, struct kvm_memory_region *region); int kvm_run(int fd);
int kvm_get_regs(int fd, struct kvm_regs *regs);
int kvm_set_regs(int fd, const struct kvm_regs *regs);
int kvm_get_sregs(int fd, struct kvm_sregs *sregs);
int kvm_set_sregs(int fd, const struct kvm_sregs *sregs); int kvm_translate(int fd, __u64 linear_address, __u64 *physical_address,
__u8 *valid, __u8 *writeable, __u8 *usemode);
int kvm_interrupt(int fd, __u32 irq);
int kvm_debug_guest(...);
int kvm_get_msrs(...);
int kvm_set_msrs(...);
int kvm_set_cpuid(...);
int kvm_set_signal_mask(...);
int kvm_get_fpu(...);
int kvm_set_fpu(...);
That's a lot of system calls! The only ioctl calls that can immediately go away are KVM_GET_API_VERSION and KVM_CHECK_EXTENSION, if the API is fixed.
Before moving to the final syscall interface, I'd wait for the memory model to have moved to using a region of the host process address instead of a separate address range. As I understood Carsten, that's what was discussed in Ottawa anyway. It can probably remove a few of the existing ioctl calls.
Some more can be saved by changing the interface for the kvm_get/set_* calls. One way I can see this done at the syscall level is to replace kvm_get_regs() with
regsfd = openat(vcpu, "regs", O_RDWR);
(void)read(regsfs, ®s, sizeof (regs);
Some of the others can also be done with files like this, e.g. writing to an "interrupt" file. Of course, you would keep the file descriptors open for the life time of the guest.
Arnd <><
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Rusty Russell
KVM interface is no longer experimental.
Signed-off-by Rusty Russell <rusty-8n+1lVoiYb80n/[email protected]>
Quoted 15 lines
include/linux/kvm.h Tue Jul 17 13:09:54 2007 +1000 line 8
Quoted 11 lines
diff -r
4e57f5c6d4a9include/linux/kvm.hinclude/linux/kvm.h Tue Jul 17 13:09:54 2007 +1000 renamed from include/linux/kvm.h Tue Jul 17 13:04:58 2007 +1000 +1
-2@@ -4,8 +4,7 @@ /* * Userspace interface for /dev/kvm - kernel based virtual machine * - * Note: this interface is considered experimental and may change without - * notice. + * Note: you must update KVM_API_VERSION if you change this interface. */I don't like the idea of making this interface official. If this is the point where we think it's perfect, it should become a set of real system calls instead.
I don't either, but I thought Avi had announced interface stability. That doesn't preclude a new API, but it does mean that the old one must be supported...
Rusty.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 1184716197.10380.45.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
Quoted 25 lines · Rusty Russell
Quoted 6 lines · Arnd Bergmann
Quoted 4 lines · Rusty Russell
KVM interface is no longer experimental.
Signed-off-by Rusty Russell <rusty-8n+1lVoiYb80n/[email protected]>Quoted 16 lines
include/linux/kvm.h Tue Jul 17 13:09:54 2007 +1000 line 9
Quoted 12 lines
diff -r
4e57f5c6d4a9include/linux/kvm.hinclude/linux/kvm.h Tue Jul 17 13:09:54 2007 +1000 renamed from include/linux/kvm.h Tue Jul 17 13:04:58 2007 +1000 +1
-2@@ -4,8 +4,7 @@ /* * Userspace interface for /dev/kvm - kernel based virtual machine * - * Note: this interface is considered experimental and may change without - * notice. + * Note: you must update KVM_API_VERSION if you change this interface. */I don't like the idea of making this interface official. If this is the point where we think it's perfect, it should become a set of real system calls instead.
Quoted 4 lines
I don't either, but I thought Avi had announced interface stability. That doesn't preclude a new API, but it does mean that the old one must be supported...
This interface is official as there is userspace deployed that uses it that we are committed not to break.
In case we do switch to a syscall based interface, this is a positive
thing: it allows us to make the syscall interface unofficial as long as we like, and when we are finally satisfied we can deprecate the old interface.
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
Quoted 27 lines · Arnd Bergmann
The equivalent of the current set of ioctls comes down to roughtly this set of syscalls:
int
kvm_create_vm(void);
intkvm_get_msr_index_list(int fd, sttuct kvm_msr_list);size_tkvm_get_vcpu_mmap_size(int fd);
int kvm_set_memory_region(int fd, unsigned slot, unsigned flags,__u64 guest_phys_addr, __u64 size);int
kvm_create_vcpu(int fd);
intkvm_get_dirty_log(int fd, unsigned slot, void *dirty_bitmap); intkvm_get_memory_alias(int fd, struct kvm_memory_region *region); intkvm_run(int fd);
intkvm_get_regs(int fd, struct kvm_regs *regs);
intkvm_set_regs(int fd, const struct kvm_regs *regs);
intkvm_get_sregs(int fd, struct kvm_sregs *sregs);
intkvm_set_sregs(int fd, const struct kvm_sregs *sregs); int kvm_translate(int fd,__u64linear_address,__u64*physical_address,__u8 *valid, __u8 *writeable, __u8 *usemode);int
kvm_interrupt(int fd, __u32 irq);
intkvm_debug_guest(...);
intkvm_get_msrs(...);
intkvm_set_msrs(...);
intkvm_set_cpuid(...);
intkvm_set_signal_mask(...);
intkvm_get_fpu(...);
intkvm_set_fpu(...);
Quoted 4 lines
That's a lot of system calls! The only ioctl calls that can immediately go away are
KVM_GET_API_VERSIONandKVM_CHECK_EXTENSION, if the API is fixed.
Many can be merged (set_fpu, set_regs, set_sregs). We will need CHECK_EXTENSION as long as we are unable to predict the future (well, for syscalls that are intended to be invoked on initialization only we can use ENOSYS).
Quoted 6 lines
Before moving to the final syscall interface, I'd wait for the memory model to have moved to using a region of the host process address instead of a separate address range. As I understood Carsten, that's what was discussed in Ottawa anyway. It can probably remove a few of the existing ioctl calls.
We will also wait until we get most ports working, so we get a chance to test it in real life.
Quoted 11 lines
Some more can be saved by changing the interface for the kvm_get/set_* calls. One way I can see this done at the syscall level is to replace
kvm_get_regs()withregsfd =
openat(vcpu, "regs", O_RDWR);
(void)read(regsfs, ®s, sizeof (regs);Some of the others can also be done with files like this, e.g. writing to an "interrupt" file. Of course, you would keep the file descriptors open for the life time of the guest.
Once we're back to using fds, we might as well use ioctls. If anything, an ioctl has an explicit mention of the structure it manipulates in its definition. I don't care that it came in last in the last 15 annual kernel beauty contests.
For me, the difference between syscalls and ioctls is whether the vcpu is bound to a task (and the vm bound to the mm) rather than whether the names are spelled in lowercase or uppercase.
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
A message that is not in the archive (sent off-list or not yet received): 469DDDEB.9070009-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 9 lines · Avi Kivity
Once we're back to using fds, we might as well use ioctls. If anything, an ioctl has an explicit mention of the structure it manipulates in its definition. I don't care that it came in last in the last 15 annual kernel beauty contests.
For me, the difference between syscalls and ioctls is whether the vcpu is bound to a task (and the vm bound to the mm) rather than whether the names are spelled in lowercase or uppercase.
Ok, good point. If we go to syscalls, it absolutely makes sense to do the automatic mm_struct<->guest and thread<->vcpu association and not pass any file descriptors around, while as long as we're using ioctl, having the fds point to the objects is logical.
My point regarding the move to system calls instead of ioctl was more about emphasizing kvm as a core kernel functionality, not a device driver, the same way that we don't have /dev/fork or /dev/epoll but use system calls for those.
Arnd <><
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/