KVM: Late fixes for the 2.6.23 merge window
A trio of issues were discovered and fixed while bringing up smp guests:
- An nx huge page table shadow could alias a real mode shadow page table, causing the real mode page to be treated as not executable. For certain newer Linux kernels, this caused kvm to spin on the smp trampoline.
This is not an smp issue per se, but only triggered in that scenario.
- The memory slot and memory alias manipulation functions were not handled properly in guest smp. This causes hangs starting X. With the patch applied, Linux can boot into graphical mode.
- Windows apparently uses rdmsr and wrmsr on its trampoline, so we need to add these instructions to the x86 emulator.
With these three patches atop the previously submitted patchset, guest smp is fully operational. Kernel build on 2-way smp is 40% faster than on a up guest. Expect significant performance improvements from in-kernel apic and from further tuning.
Please review -- comments welcome.
-------------------------------------------------------------------------
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 1/3 KVM: MMU: Store nx bit for large page shadows
We need to distinguish between large page shadows which have the nx bit set and those which don't. The problem shows up when booting a newer smp Linux kernel, where the trampoline page (which is in real mode, which uses the same shadow pages as large pages) is using the same mapping as a kernel data page, which is mapped using nx, causing kvm to spin on that page.
--- drivers/kvm/kvm.h | 4 ++-- drivers/kvm/paging_tmpl.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/kvm/kvm.h +2 -2
@@ -121,7 +121,7 @@ struct kvm_pte_chain {* bits 4:7 - page table level for this shadow (1-4) * bits 8:9 - page table quadrant for 2-level guests * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode) -* bits 17:18 - "access" - the user and writable bits of a huge page pde +* bits 17:19 - "access" - the user, writable, and nx bits of a huge page pde */ union kvm_mmu_page_role {unsigned word;
@@ -131,7 +131,7 @@ union kvm_mmu_page_role { unsigned quadrant : 2; unsigned pad_for_nice_hex_output : 6; unsigned metaphysical : 1; - unsigned hugepage_access : 2; + unsigned hugepage_access : 3; }; };
drivers/kvm/paging_tmpl.h +2 -0
@@ -366,6 +366,8 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, metaphysical =1 ; hugepage_access = *guest_ent; hugepage_access &=PT_USER_MASK |PT_WRITABLE_MASK ; +if (*guest_ent &PT64_NX_MASK ) + hugepage_access |= (1 <<2 ); hugepage_access >>=PT_WRITABLE_SHIFT ; table_gfn = (*guest_ent &PT_BASE_ADDR_MASK ) >>PAGE_SHIFT ;
Signature · 8 lines
1.5.2.4 ------------------------------------------------------------------------- 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 2/3 KVM: Fix memory slot management functions for guest smp
In reply to Avi KivityThe memory slot management functions were oriented against vcpu 0, where they should be kvm-wide. This causes hangs starting X on guest smp.
Fix by making the functions (and resultant tail in the mmu) non-vcpu-specific. Unfortunately this reduces the efficiency of the mmu object cache a bit. We may have to revisit this later.
--- drivers/kvm/kvm.h | 4 +- drivers/kvm/kvm_main.c | 68 ++++--------------------------- drivers/kvm/mmu.c | 103 +++++++++++++++++++----------------------------- 3 files changed, 52 insertions(+), 123 deletions(-)
drivers/kvm/kvm.h +2 -2
@@ -535,8 +535,8 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu);int kvm_mmu_setup (struct kvm_vcpu *vcpu);int kvm_mmu_reset_context (struct kvm_vcpu *vcpu); -void kvm_mmu_slot_remove_write_access (struct kvm_vcpu *vcpu,int slot); -void kvm_mmu_zap_all (struct kvm_vcpu *vcpu); +void kvm_mmu_slot_remove_write_access (struct kvm *kvm,int slot); +void kvm_mmu_zap_all (struct kvm *kvm);hpa_t gpa_to_hpa (struct kvm_vcpu *vcpu,gpa_t gpa);#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
drivers/kvm/kvm_main.c +9 -59
107 lines not on this page · raw message
drivers/kvm/mmu.c +41 -62
268 lines not on this page · raw message
Signature · 8 lines
1.5.2.4 ------------------------------------------------------------------------- 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 3/3 KVM: x86 emulator: implement rdmsr and wrmsr
In reply to Avi KivityAllow real-mode emulation of rdmsr and wrmsr. This allows smp Windows to boot, presumably for its sipi trampoline.
--- drivers/kvm/kvm.h | 2 ++ drivers/kvm/kvm_main.c | 8 ++++---- drivers/kvm/x86_emulate.c | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-)
drivers/kvm/kvm.h +2 -0
@@ -569,6 +569,8 @@ void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,unsigned long realmode_get_cr (struct kvm_vcpu *vcpu,int cr);void realmode_set_cr (struct kvm_vcpu *vcpu,int cr,unsigned long value,unsigned long *rflags); +int kvm_get_msr (struct kvm_vcpu *vcpu,u32 msr_index,u64 *data); +int kvm_set_msr (struct kvm_vcpu *vcpu,u32 msr_index,u64 data);struct x86_emulate_ctxt ;
drivers/kvm/kvm_main.c +4 -4
@@ -1517,7 +1517,7 @@ EXPORT_SYMBOL_GPL(kvm_get_msr_common);* Returns 0 on success, non-0 otherwise. * Assumes vcpu_load() was already called. */ -static int get_msr (struct kvm_vcpu *vcpu,u32 msr_index,u64 *pdata) +int kvm_get_msr (struct kvm_vcpu *vcpu,u32 msr_index,u64 *pdata) {return kvm_arch_ops->get_msr (vcpu, msr_index, pdata); }
@@ -1595,7 +1595,7 @@ EXPORT_SYMBOL_GPL(kvm_set_msr_common);* Returns 0 on success, non-0 otherwise. * Assumes vcpu_load() was already called. */ -static int set_msr (struct kvm_vcpu *vcpu,u32 msr_index,u64 data) +int kvm_set_msr (struct kvm_vcpu *vcpu,u32 msr_index,u64 data) {return kvm_arch_ops->set_msr (vcpu, msr_index, data); }
@@ -2133,7 +2133,7 @@ static __init void kvm_init_msr_list(void)*/ static int do_set_msr (struct kvm_vcpu *vcpu,unsigned index,u64 *data) { -return set_msr (vcpu, index, *data); +return kvm_set_msr (vcpu, index, *data); }/*
@@ -2617,7 +2617,7 @@ static long kvm_vcpu_ioctl(struct file *filp,break ; }case KVM_GET_MSRS : - r =msr_io (vcpu, argp, get_msr,1 ); + r =msr_io (vcpu, argp, kvm_get_msr,1 );break ;case KVM_SET_MSRS : r =msr_io (vcpu, argp, do_set_msr,0 );
drivers/kvm/x86_emulate.c +25 -1
@@ -163,7 +163,7 @@ static u16 twobyte_table[256] = { ModRM | ImplicitOps, ModRM, ModRM | ImplicitOps, ModRM,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* 0x30 - 0x3F */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , + ImplicitOps,0 , ImplicitOps,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* 0x40 - 0x47 */ DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
@@ -486,6 +486,7 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)unsigned long modrm_ea;int use_modrm_ea, index_reg =0 , base_reg =0 , scale, rip_relative =0 ;int no_wb =0 ; +u64 msr_data;/* Shadow copy of register state. Committed on successful emulation. */ unsigned long _regs[NR_VCPU_REGS ];
@@ -1344,6 +1345,29 @@ twobyte_special_insn: goto cannot_emulate;realmode_set_cr (ctxt->vcpu, modrm_reg, modrm_val, &_eflags);break ; +case 0x30 : +/* wrmsr */ + msr_data = (u32 )_regs[VCPU_REGS_RAX ] + | ((u64 )_regs[VCPU_REGS_RDX ] <<32 ); + rc =kvm_set_msr (ctxt->vcpu, _regs[VCPU_REGS_RCX ], msr_data); +if (rc) { + kvm_arch_ops->inject_gp (ctxt->vcpu,0 ); + _eip = ctxt->vcpu->rip; + } + rc =X86EMUL_CONTINUE ; +break ; +case 0x32 : +/* rdmsr */ + rc =kvm_get_msr (ctxt->vcpu, _regs[VCPU_REGS_RCX ], &msr_data); +if (rc) { + kvm_arch_ops->inject_gp (ctxt->vcpu,0 ); + _eip = ctxt->vcpu->rip; + }else { + _regs[VCPU_REGS_RAX ] = (u32 )msr_data; + _regs[VCPU_REGS_RDX ] = msr_data >>32 ; + } + rc =X86EMUL_CONTINUE ; +break ;case 0xc7 :/* Grp9 (cmpxchg8b) */ {u64 old, new;
Signature · 8 lines
1.5.2.4 ------------------------------------------------------------------------- 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/