KVM Updates for the 2.6.30 merge window (3/3)
cover KVM Updates for the 2.6.30 merge window (3/3)
Third and last batch containing the KVM updates for the next merge window. Depending on schedule, some of the patches in the 'master' branch may end up here as well.
Alexander Graf (2):
x86: Add EFER descriptions for FFXSR
KVM: Add FFXSR support
Amit Shah (2):
KVM: VMX: Update necessary state when guest enters long mode
KVM: is_long_mode() should check for EFER.LMA
Andre Przywara (1):
KVM: SVM: set accessed bit for VMCB segment selectors
Christian Borntraeger (3):
KVM: s390: Fix printk on SIGP set arch
KVM: s390: Fix problem state check for b2 intercepts
KVM: s390: Fix SIGP set prefix ioctl
Gerd Hoffmann (1):
KVM: Fix kvmclock on !constant_tsc boxes
Gleb Natapov (2):
KVM: Report IRQ injection status to userspace.
KVM: Report IRQ injection status for MSI delivered interrupts
Hannes Eder (2):
KVM: fix sparse warnings: context imbalance
KVM: fix sparse warnings: Should it be static?
Jan Kiszka (1):
KVM: Drop unused evaluations from string pio handlers
Jes Sorensen (1):
KVM: ia64: dynamic nr online cpus
Joerg Roedel (4):
KVM: MMU: handle compound pages in kvm_is_mmio_pfn
KVM: MMU: remove redundant check in mmu_set_spte
KVM: MMU: remove assertion in kvm_mmu_alloc_page
KVM: MMU: Fix another largepage memory leak
Liu Yu (1):
KVM: ppc: Add emulation of E500 register mmucsr0
Marcelo Tosatti (1):
KVM: make irq ack notifications aware of routing table
Sheng Yang (2):
KVM: Use irq routing API for MSI
KVM: VMX: Use kvm_mmu_page_fault() handle EPT violation mmio
Weidong Han (2):
KVM: define KVM_CAP_DEVICE_DEASSIGNMENT
KVM: fix kvm_vm_ioctl_deassign_device
Xiantao Zhang (5):
KVM: ia64: vTLB change for enabling windows 2008 boot
KVM: ia64: Add the support for translating PAL Call's pointer args
KVM: ia64: Implement some pal calls needed for windows 2008
ia64: Move the macro definitions related to MSI to one header file.
KVM: ia64: Fix the build errors due to lack of macros related to MSI.
arch/ia64/include/asm/kvm_host.h | 10 ++- arch/ia64/include/asm/msidef.h | 42 +++++++++++ arch/ia64/kernel/msi_ia64.c | 55 ++------------ arch/ia64/kvm/irq.h | 2 + arch/ia64/kvm/kvm-ia64.c | 24 +++++-- arch/ia64/kvm/kvm_fw.c | 151 +++++++++++++++++++++++++++++++++++++- arch/ia64/kvm/process.c | 56 ++++++++++++-- arch/ia64/kvm/vcpu.c | 5 +- arch/ia64/kvm/vcpu.h | 4 +- arch/ia64/kvm/vtlb.c | 39 ++++------ arch/powerpc/kvm/e500_emulate.c | 8 ++ arch/powerpc/kvm/e500_tlb.c | 16 ++++ arch/powerpc/kvm/e500_tlb.h | 1 + arch/s390/kvm/intercept.c | 2 +- arch/s390/kvm/interrupt.c | 7 ++- arch/s390/kvm/kvm-s390.h | 2 +- arch/s390/kvm/priv.c | 18 ++++- arch/s390/kvm/sigp.c | 2 - arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/include/asm/msr-index.h | 2 + arch/x86/kvm/i8259.c | 25 +++++-- arch/x86/kvm/irq.h | 2 + arch/x86/kvm/mmu.c | 20 ++--- arch/x86/kvm/mmu.h | 2 +- arch/x86/kvm/paging_tmpl.h | 2 +- arch/x86/kvm/svm.c | 48 ++++++++---- arch/x86/kvm/vmx.c | 88 +++++++---------------- arch/x86/kvm/x86.c | 136 ++++++++++++++++++++++++++++++---- include/linux/kvm.h | 21 +++++- include/linux/kvm_host.h | 9 +- virt/kvm/ioapic.c | 33 +++++--- virt/kvm/ioapic.h | 2 +- virt/kvm/irq_comm.c | 131 +++++++++++++++++++++++++++------ virt/kvm/kvm_main.c | 78 +++----------------- 34 files changed, 724 insertions(+), 321 deletions(-) create mode 100644 arch/ia64/include/asm/msidef.h
PATCH 1/30 KVM: ia64: vTLB change for enabling windows 2008 boot
From: Xiantao Zhang <[email protected]>
Simply the logic of hash vTLB, and export kvm_gpa_to_mpa.
--- arch/ia64/kvm/vcpu.h | 4 ++-- arch/ia64/kvm/vtlb.c | 39 +++++++++++++++++---------------------- 2 files changed, 19 insertions(+), 24 deletions(-)
arch/ia64/kvm/vcpu.h +2 -2
@@ -703,7 +703,7 @@ extern u64 guest_vhpt_lookup(u64 iha, u64 *pte);extern void thash_purge_entries (struct kvm_vcpu *v,u64 va,u64 ps);extern void thash_purge_entries_remote (struct kvm_vcpu *v,u64 va,u64 ps);extern u64 translate_phy_pte (u64 *pte,u64 itir,u64 va); -extern int thash_purge_and_insert (struct kvm_vcpu *v,u64 pte, +extern void thash_purge_and_insert (struct kvm_vcpu *v,u64 pte,u64 itir,u64 ifa,int type);extern void thash_purge_all (struct kvm_vcpu *v); extern struct thash_data *vtlb_lookup(struct kvm_vcpu *v,
@@ -738,7 +738,7 @@ void kvm_init_vhpt(struct kvm_vcpu *v);void thash_init (struct thash_cb *hcb,u64 sz);void panic_vm (struct kvm_vcpu *v,const char *fmt, ...); - +u64 kvm_gpa_to_mpa (u64 gpa);extern u64 ia64_call_vsa (u64 proc,u64 arg1,u64 arg2,u64 arg3,u64 arg4,u64 arg5,u64 arg6,u64 arg7);
arch/ia64/kvm/vtlb.c +17 -22
@@ -164,11 +164,11 @@ static void vhpt_insert(u64 pte, u64 itir, u64 ifa, u64 gpte)unsigned long ps, gpaddr; ps =itir_ps (itir); + rr.val =ia64_get_rr (ifa); - gpaddr = ((gpte & _PAGE_PPN_MASK) >> ps << ps) | - (ifa & ((1UL << ps) -1 )); + gpaddr = ((gpte & _PAGE_PPN_MASK) >> ps << ps) | + (ifa & ((1UL << ps) -1 )); - rr.val =ia64_get_rr (ifa); head = (struct thash_data *)ia64_thash (ifa); head->etag =INVALID_TI_TAG ;ia64_mf ();
@@ -412,16 +412,14 @@ u64 translate_phy_pte(u64 *pte, u64 itir, u64 va)/* * Purge overlap TCs and then insert the new entry to emulate itc ops. -* Notes: Only TC entry can purge and insert. -* 1 indicates this is MMIO +* Notes: Only TC entry can purge and insert. */ -int thash_purge_and_insert (struct kvm_vcpu *v,u64 pte,u64 itir, +void thash_purge_and_insert (struct kvm_vcpu *v,u64 pte,u64 itir,u64 ifa,int type) {u64 ps;u64 phy_pte, io_mask, index;union ia64_rr vrr, mrr; -int ret =0 ; ps =itir_ps (itir); vrr.val =vcpu_get_rr (v, ifa);
@@ -441,25 +439,19 @@ int thash_purge_and_insert(struct kvm_vcpu *v, u64 pte, u64 itir, phy_pte &= ~_PAGE_MA_MASK; } -if (pte &VTLB_PTE_IO ) - ret =1 ; -vtlb_purge (v, ifa, ps);vhpt_purge (v, ifa, ps); -if (ps == mrr.ps) { -if (!(pte&VTLB_PTE_IO )) { -vhpt_insert (phy_pte, itir, ifa, pte); - }else { -vtlb_insert (v, pte, itir, ifa); -vcpu_quick_region_set (VMX (v, tc_regions), ifa); - } - }else if (ps > mrr.ps) { +if ((ps != mrr.ps) || (pte &VTLB_PTE_IO )) {vtlb_insert (v, pte, itir, ifa);vcpu_quick_region_set (VMX (v, tc_regions), ifa); -if (!(pte&VTLB_PTE_IO )) -vhpt_insert (phy_pte, itir, ifa, pte); - }else { + } +if (pte &VTLB_PTE_IO ) +return ; + +if (ps >= mrr.ps) +vhpt_insert (phy_pte, itir, ifa, pte); +else {u64 psr; phy_pte &= ~PAGE_FLAGS_RV_MASK ; psr =ia64_clear_ic ();
@@ -469,7 +461,6 @@ int thash_purge_and_insert(struct kvm_vcpu *v, u64 pte, u64 itir,if (!(pte&VTLB_PTE_IO ))mark_pages_dirty (v, pte, ps); -return ret; }/*
@@ -570,6 +561,10 @@ void thash_init(struct thash_cb *hcb, u64 sz)u64 kvm_get_mpt_entry (u64 gpfn) {u64 *base = (u64 *)KVM_P2M_BASE ; + +if (gpfn >= (KVM_P2M_SIZE >>3 )) +panic_vm (current_vcpu,"Invalid gpfn =%lx\n" , gpfn); +return *(base + gpfn); }
Signature · 1 line
1.6.0.6
PATCH 2/30 KVM: ia64: Add the support for translating PAL Call's pointer args
In reply to Avi KivityFrom: Xiantao Zhang <[email protected]>
Add the support to translate PAL Call's pointer args.
--- arch/ia64/kvm/process.c | 48 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 45 insertions(+), 3 deletions(-)
arch/ia64/kvm/process.c +45 -3
@@ -550,18 +550,60 @@ void reflect_interruption(u64 ifa, u64 isr, u64 iim,inject_guest_interruption (vcpu, vector); } +static unsigned long kvm_trans_pal_call_args (struct kvm_vcpu *vcpu, +unsigned long arg) +{ +struct thash_data *data; +unsigned long gpa, poff; + +if (!is_physical_mode (vcpu)) { +/* Depends on caller to provide the DTR or DTC mapping.*/ + data =vtlb_lookup (vcpu, arg,D_TLB ); +if (data) + gpa = data->page_flags & _PAGE_PPN_MASK; +else { + data =vhpt_lookup (arg); +if (!data) +return 0 ; + gpa = data->gpaddr & _PAGE_PPN_MASK; + } + + poff = arg & (PSIZE (data->ps) -1 ); + arg =PAGEALIGN (gpa, data->ps) | poff; + } + arg =kvm_gpa_to_mpa (arg <<1 >>1 ); + +return (unsigned long )__va (arg); +} +static void set_pal_call_data (struct kvm_vcpu *vcpu) {struct exit_ctl_data *p = &vcpu->arch.exit_data; +unsigned long gr28 =vcpu_get_gr (vcpu,28 ); +unsigned long gr29 =vcpu_get_gr (vcpu,29 ); +unsigned long gr30 =vcpu_get_gr (vcpu,30 );/*FIXME:For static and stacked convention, firmware * has put the parameters in gr28-gr31 before * break to vmm !!*/ - p->u.pal_data.gr28 =vcpu_get_gr (vcpu,28 ); - p->u.pal_data.gr29 =vcpu_get_gr (vcpu,29 ); - p->u.pal_data.gr30 =vcpu_get_gr (vcpu,30 ); +switch (gr28) { +case PAL_PERF_MON_INFO : +case PAL_HALT_INFO : + p->u.pal_data.gr29 =kvm_trans_pal_call_args (vcpu, gr29); + p->u.pal_data.gr30 =vcpu_get_gr (vcpu,30 ); +break ; +case PAL_BRAND_INFO : + p->u.pal_data.gr29 = gr29;; + p->u.pal_data.gr30 =kvm_trans_pal_call_args (vcpu, gr30); +break ; +default : + p->u.pal_data.gr29 = gr29;; + p->u.pal_data.gr30 =vcpu_get_gr (vcpu,30 ); + } + p->u.pal_data.gr28 = gr28; p->u.pal_data.gr31 =vcpu_get_gr (vcpu,31 ); + p->exit_reason =EXIT_REASON_PAL_CALL ; }
Signature · 1 line
1.6.0.6
PATCH 3/30 KVM: ia64: Implement some pal calls needed for windows 2008
In reply to Avi KivityFrom: Xiantao Zhang <[email protected]>
For windows 2008, it needs more pal calls to implement for booting. In addition, also changes the name of set_{sal, pal}_call_result to get_{sal,pal}_call_result for readability.
--- arch/ia64/kvm/kvm_fw.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++- arch/ia64/kvm/process.c | 8 +- 2 files changed, 152 insertions(+), 7 deletions(-)
arch/ia64/kvm/kvm_fw.c +148 -3
@@ -227,6 +227,18 @@ static struct ia64_pal_retval pal_proc_get_features(struct kvm_vcpu *vcpu)return result; } +static struct ia64_pal_retval pal_register_info (struct kvm_vcpu *vcpu) +{ + +struct ia64_pal_retval result = {0 ,0 ,0 ,0 }; +long in0, in1, in2, in3; + +kvm_get_pal_call_data (vcpu, &in0, &in1, &in2, &in3); + result.status =ia64_pal_register_info (in1, &result.v1, &result.v2); + +return result; +} +static struct ia64_pal_retval pal_cache_info (struct kvm_vcpu *vcpu) {
@@ -268,8 +280,12 @@ static struct ia64_pal_retval pal_vm_summary(struct kvm_vcpu *vcpu)static struct ia64_pal_retval pal_vm_info (struct kvm_vcpu *vcpu) {struct ia64_pal_retval result; +unsigned long in0, in1, in2, in3; -INIT_PAL_STATUS_UNIMPLEMENTED (result); +kvm_get_pal_call_data (vcpu, &in0, &in1, &in2, &in3); + + result.status =ia64_pal_vm_info (in1, in2, + (pal_tc_info_u_t *)&result.v1, &result.v2);return result; }
@@ -292,6 +308,108 @@ static void prepare_for_halt(struct kvm_vcpu *vcpu) vcpu->arch.timer_fired =0 ; } +static struct ia64_pal_retval pal_perf_mon_info (struct kvm_vcpu *vcpu) +{ +long status; +unsigned long in0, in1, in2, in3, r9; +unsigned long pm_buffer[16 ]; + +kvm_get_pal_call_data (vcpu, &in0, &in1, &in2, &in3); + status =ia64_pal_perf_mon_info (pm_buffer, + (pal_perf_mon_info_u_t *) &r9); +if (status !=0 ) { +printk (KERN_DEBUG "PAL_PERF_MON_INFO fails ret=%ld\n" , status); + }else { +if (in1) +memcpy ((void *)in1, pm_buffer,sizeof (pm_buffer)); +else { + status =PAL_STATUS_EINVAL ; +printk (KERN_WARNING "Invalid parameters " +"for PAL call:0x%lx!\n" , in0); + } + } +return (struct ia64_pal_retval ){status, r9,0 ,0 }; +} + +static struct ia64_pal_retval pal_halt_info (struct kvm_vcpu *vcpu) +{ +unsigned long in0, in1, in2, in3; +long status; +unsigned long res =1000UL | (1000UL <<16 ) | (10UL <<32 ) + | (1UL <<61 ) | (1UL <<60 ); + +kvm_get_pal_call_data (vcpu, &in0, &in1, &in2, &in3); +if (in1) { +memcpy ((void *)in1, &res,sizeof (res)); + status =0 ; + }else { + status =PAL_STATUS_EINVAL ; +printk (KERN_WARNING "Invalid parameters " +"for PAL call:0x%lx!\n" , in0); + } + +return (struct ia64_pal_retval ){status,0 ,0 ,0 }; +} + +static struct ia64_pal_retval pal_mem_attrib (struct kvm_vcpu *vcpu) +{ +unsigned long r9; +long status; + + status =ia64_pal_mem_attrib (&r9); + +return (struct ia64_pal_retval ){status, r9,0 ,0 }; +} + +static void remote_pal_prefetch_visibility (void *v) +{ +s64 trans_type = (s64 )v; +ia64_pal_prefetch_visibility (trans_type); +} + +static struct ia64_pal_retval pal_prefetch_visibility (struct kvm_vcpu *vcpu) +{ +struct ia64_pal_retval result = {0 ,0 ,0 ,0 }; +unsigned long in0, in1, in2, in3; +kvm_get_pal_call_data (vcpu, &in0, &in1, &in2, &in3); + result.status =ia64_pal_prefetch_visibility (in1); +if (result.status ==0 ) { +/* Must be performed on all remote processors +in the coherence domain. */ +smp_call_function (remote_pal_prefetch_visibility, + (void *)in1,1 ); +/* Unnecessary on remote processor for other vcpus!*/ + result.status =1 ; + } +return result; +} + +static void remote_pal_mc_drain (void *v) +{ +ia64_pal_mc_drain (); +} + +static struct ia64_pal_retval pal_get_brand_info (struct kvm_vcpu *vcpu) +{ +struct ia64_pal_retval result = {0 ,0 ,0 ,0 }; +unsigned long in0, in1, in2, in3; + +kvm_get_pal_call_data (vcpu, &in0, &in1, &in2, &in3); + +if (in1 ==0 && in2) { +char brand_info[128 ]; + result.status =ia64_pal_get_brand_info (brand_info); +if (result.status ==PAL_STATUS_SUCCESS ) +memcpy ((void *)in2, brand_info,128 ); + }else { + result.status =PAL_STATUS_REQUIRES_MEMORY ; +printk (KERN_WARNING "Invalid parameters for " +"PAL call:0x%lx!\n" , in0); + } + +return result; +} +int kvm_pal_emul (struct kvm_vcpu *vcpu,struct kvm_run *run) {
@@ -300,14 +418,22 @@ int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *run)int ret =1 ; gr28 =kvm_get_pal_call_index (vcpu); -/*printk("pal_call index:%lx\n",gr28);*/ switch (gr28) {case PAL_CACHE_FLUSH : result =pal_cache_flush (vcpu);break ; +case PAL_MEM_ATTRIB : + result =pal_mem_attrib (vcpu); +break ;case PAL_CACHE_SUMMARY : result =pal_cache_summary (vcpu);break ; +case PAL_PERF_MON_INFO : + result =pal_perf_mon_info (vcpu); +break ; +case PAL_HALT_INFO : + result =pal_halt_info (vcpu); +break ;case PAL_HALT_LIGHT : {INIT_PAL_STATUS_SUCCESS (result);
@@ -317,6 +443,16 @@ int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *run) }break ; +case PAL_PREFETCH_VISIBILITY : + result =pal_prefetch_visibility (vcpu); +break ; +case PAL_MC_DRAIN : + result.status =ia64_pal_mc_drain (); +/* FIXME: All vcpus likely call PAL_MC_DRAIN. +That causes the congestion. */ +smp_call_function (remote_pal_mc_drain,NULL ,1 ); +break ; +case PAL_FREQ_RATIOS : result =pal_freq_ratios (vcpu);break ;
@@ -346,6 +482,9 @@ int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *run)INIT_PAL_STATUS_SUCCESS (result); result.v1 = (1L <<32 ) |1L ;break ; +case PAL_REGISTER_INFO : + result =pal_register_info (vcpu); +break ;case PAL_VM_PAGE_SIZE : result.status =ia64_pal_vm_page_size (&result.v0, &result.v1);
@@ -365,12 +504,18 @@ int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *run) result.status =ia64_pal_version ( (pal_version_u_t *)&result.v0, (pal_version_u_t *)&result.v1); -break ;case PAL_FIXED_ADDR : result.status =PAL_STATUS_SUCCESS ; result.v0 = vcpu->vcpu_id;break ; +case PAL_BRAND_INFO : + result =pal_get_brand_info (vcpu); +break ; +case PAL_GET_PSTATE : +case PAL_CACHE_SHARED_INFO : +INIT_PAL_STATUS_UNIMPLEMENTED (result); +break ;default :INIT_PAL_STATUS_UNIMPLEMENTED (result); printk(KERN_WARNING"kvm: Unsupported pal call,"
arch/ia64/kvm/process.c +4 -4
@@ -607,7 +607,7 @@ static void set_pal_call_data(struct kvm_vcpu *vcpu) p->exit_reason =EXIT_REASON_PAL_CALL ; } -static void set_pal_call_result (struct kvm_vcpu *vcpu) +static void get_pal_call_result (struct kvm_vcpu *vcpu) {struct exit_ctl_data *p = &vcpu->arch.exit_data;
@@ -635,7 +635,7 @@ static void set_sal_call_data(struct kvm_vcpu *vcpu) p->exit_reason =EXIT_REASON_SAL_CALL ; } -static void set_sal_call_result (struct kvm_vcpu *vcpu) +static void get_sal_call_result (struct kvm_vcpu *vcpu) {struct exit_ctl_data *p = &vcpu->arch.exit_data;
@@ -658,13 +658,13 @@ void kvm_ia64_handle_break(unsigned long ifa, struct kvm_pt_regs *regs,if (iim ==DOMN_PAL_REQUEST ) {set_pal_call_data (v);vmm_transition (v); -set_pal_call_result (v); +get_pal_call_result (v);vcpu_increment_iip (v);return ; }else if (iim ==DOMN_SAL_REQUEST ) {set_sal_call_data (v);vmm_transition (v); -set_sal_call_result (v); +get_sal_call_result (v);vcpu_increment_iip (v);return ; }
Signature · 1 line
1.6.0.6
PATCH 4/30 KVM: s390: Fix printk on SIGP set arch
In reply to Avi KivityFrom: Christian Borntraeger <[email protected]>
KVM on s390 does not support the ESA/390 architecture. We refuse to change the architecture mode and print a warning. This patch removes the printk for several reasons:
o A malicious guest can flood host dmesg
o The old message had no newline
o there is no connection between the message and the failing guest
This patch simply removes the printk. We already set the condition code to 3 - the guest knows that something went wrong.
--- arch/s390/kvm/sigp.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
arch/s390/kvm/sigp.c +0 -2
@@ -153,8 +153,6 @@ static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 parameter)switch (parameter &0xff ) {case 0 : -printk (KERN_WARNING "kvm: request to switch to ESA/390 mode" -" not supported" ); rc =3 ;/* not operational */ break ;case 1 :
Signature · 1 line
1.6.0.6
PATCH 5/30 KVM: s390: Fix problem state check for b2 intercepts
In reply to Avi KivityFrom: Christian Borntraeger <[email protected]>
The kernel handles some priviledged instruction exits. While I was unable to trigger such an exit from guest userspace, the code should check for supervisor state before emulating a priviledged instruction.
I also renamed kvm_s390_handle_priv to kvm_s390_handle_b2. After all there are non priviledged b2 instructions like stck (store clock).
--- arch/s390/kvm/intercept.c | 2 +- arch/s390/kvm/kvm-s390.h | 2 +- arch/s390/kvm/priv.c | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-)
arch/s390/kvm/intercept.c +1 -1
@@ -103,7 +103,7 @@ static int handle_lctl(struct kvm_vcpu *vcpu)static intercept_handler_t instruction_handlers[256 ] = { [0x83 ] = kvm_s390_handle_diag, [0xae ] = kvm_s390_handle_sigp, - [0xb2 ] = kvm_s390_handle_priv, + [0xb2 ] = kvm_s390_handle_b2, [0xb7 ] = handle_lctl, [0xeb ] = handle_lctlg, };
arch/s390/kvm/kvm-s390.h +1 -1
@@ -50,7 +50,7 @@ int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,int kvm_s390_inject_program_int (struct kvm_vcpu *vcpu,u16 code);/* implemented in priv.c */ -int kvm_s390_handle_priv (struct kvm_vcpu *vcpu); +int kvm_s390_handle_b2 (struct kvm_vcpu *vcpu);/* implemented in sigp.c */ int kvm_s390_handle_sigp (struct kvm_vcpu *vcpu);
arch/s390/kvm/priv.c +15 -3
@@ -304,12 +304,24 @@ static intercept_handler_t priv_handlers[256] = { [0xb1] = handle_stfl, }; -int kvm_s390_handle_priv (struct kvm_vcpu *vcpu) +int kvm_s390_handle_b2 (struct kvm_vcpu *vcpu) {intercept_handler_t handler; +/* +* a lot of B2 instructions are priviledged. We first check for +* the priviledges ones, that we can handle in the kernel. If the +* kernel can handle this instruction, we check for the problem +* state bit and (a) handle the instruction or (b) send a code 2 +* program check. +* Anything else goes to userspace.*/ handler = priv_handlers[vcpu->arch.sie_block->ipa &0x00ff ]; -if (handler) -return handler (vcpu); +if (handler) { +if (vcpu->arch.sie_block->gpsw.mask &PSW_MASK_PSTATE ) +return kvm_s390_inject_program_int (vcpu, +PGM_PRIVILEGED_OPERATION ); +else +return handler (vcpu); + }return -ENOTSUPP ; }
Signature · 1 line
1.6.0.6
PATCH 6/30 KVM: s390: Fix SIGP set prefix ioctl
In reply to Avi KivityFrom: Christian Borntraeger <[email protected]>
This patch fixes the SET PREFIX interrupt if triggered by userspace. Until now, it was not necessary, but life migration will need it. In addition, it helped me creating SMP support for my kvm_crashme tool (lets kvm execute random guest memory content).
--- arch/s390/kvm/interrupt.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/s390/kvm/interrupt.c +6 -1
@@ -555,9 +555,14 @@ int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,VCPU_EVENT (vcpu,3 ,"inject: program check %d (from user)" , s390int->parm);break ; +case KVM_S390_SIGP_SET_PREFIX : + inti->prefix.address = s390int->parm; + inti->type = s390int->type; +VCPU_EVENT (vcpu,3 ,"inject: set prefix to %x (from user)" , + s390int->parm); +break ;case KVM_S390_SIGP_STOP :case KVM_S390_RESTART : -case KVM_S390_SIGP_SET_PREFIX :case KVM_S390_INT_EMERGENCY :VCPU_EVENT (vcpu,3 ,"inject: type %x" , s390int->type); inti->type = s390int->type;
Signature · 1 line
1.6.0.6
PATCH 7/30 KVM: ia64: dynamic nr online cpus
In reply to Avi KivityFrom: Jes Sorensen <[email protected]>
Account for number of online cpus and use that in loops iterating over the list of vpus instead of scanning the full array unconditionally. This patch is a building block to facilitate allowing to bump up the size of MAX_VCPUS significantly.
--- arch/ia64/include/asm/kvm_host.h | 10 ++++++---- arch/ia64/kvm/kvm-ia64.c | 12 ++++++++---- arch/ia64/kvm/vcpu.c | 5 ++++- 3 files changed, 18 insertions(+), 9 deletions(-)
arch/ia64/include/asm/kvm_host.h +6 -4
@@ -157,10 +157,10 @@ struct kvm_vm_data {struct kvm_vcpu_data vcpu_data[KVM_MAX_VCPUS ]; }; -#define VCPU_BASE (n) KVM_VM_DATA_BASE + \ - offsetof(struct kvm_vm_data, vcpu_data[n]) -#define VM_BASE KVM_VM_DATA_BASE + \ - offsetof(struct kvm_vm_data, kvm_vm_struct) +#define VCPU_BASE (n) (KVM_VM_DATA_BASE + \ + offsetof(struct kvm_vm_data, vcpu_data[n])) +#define KVM_VM_BASE (KVM_VM_DATA_BASE + \ + offsetof(struct kvm_vm_data, kvm_vm_struct))#define KVM_MEM_DIRTY_LOG_BASE KVM_VM_DATA_BASE + \ offsetof(struct kvm_vm_data, kvm_mem_dirty_log)
@@ -464,6 +464,8 @@ struct kvm_arch {unsigned long metaphysical_rr4;unsigned long vmm_init_rr; +int online_vcpus; +struct kvm_ioapic *vioapic;struct kvm_vm_stat stat;struct kvm_sal_data rdv_sal_data;
arch/ia64/kvm/kvm-ia64.c +8 -4
@@ -314,7 +314,7 @@ static struct kvm_vcpu *lid_to_vcpu(struct kvm *kvm, unsigned long id,union ia64_lid lid;int i; -for (i =0 ; i <KVM_MAX_VCPUS ; i++) { +for (i =0 ; i < kvm->arch.online_vcpus; i++) {if (kvm->vcpus[i]) { lid.val =VCPU_LID (kvm->vcpus[i]);if (lid.id == id && lid.eid == eid)
@@ -388,7 +388,7 @@ static int handle_global_purge(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) call_data.ptc_g_data = p->u.ptc_g_data; -for (i =0 ; i <KVM_MAX_VCPUS ; i++) { +for (i =0 ; i < kvm->arch.online_vcpus; i++) {if (!kvm->vcpus[i] || kvm->vcpus[i]->arch.mp_state ==KVM_MP_STATE_UNINITIALIZED || vcpu == kvm->vcpus[i])
@@ -788,6 +788,8 @@ struct kvm *kvm_arch_create_vm(void)return ERR_PTR (-ENOMEM );kvm_init_vm (kvm); + kvm->arch.online_vcpus =0 ; +return kvm; }
@@ -1154,7 +1156,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)/*Initialize itc offset for vcpus*/ itc_offset =0UL -ia64_getreg (_IA64_REG_AR_ITC); -for (i =0 ; i <KVM_MAX_VCPUS ; i++) { +for (i =0 ; i < kvm->arch.online_vcpus; i++) { v = (struct kvm_vcpu *)((char *)vcpu +sizeof (struct kvm_vcpu_data ) * i); v->arch.itc_offset = itc_offset;
@@ -1288,6 +1290,8 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, goto fail; } + kvm->arch.online_vcpus++; +return vcpu; fail:return ERR_PTR (r);
@@ -1828,7 +1832,7 @@ struct kvm_vcpu *kvm_get_lowest_prio_vcpu(struct kvm *kvm, u8 vector,struct kvm_vcpu *lvcpu = kvm->vcpus[0 ];int i; -for (i =1 ; i <KVM_MAX_VCPUS ; i++) { +for (i =1 ; i < kvm->arch.online_vcpus; i++) {if (!kvm->vcpus[i])continue ;if (lvcpu->arch.xtp > kvm->vcpus[i]->arch.xtp)
arch/ia64/kvm/vcpu.c +4 -1
@@ -807,12 +807,15 @@ static inline void vcpu_set_itm(struct kvm_vcpu *vcpu, u64 val);static void vcpu_set_itc (struct kvm_vcpu *vcpu,u64 val) {struct kvm_vcpu *v; +struct kvm *kvm;int i;long itc_offset = val -ia64_getreg (_IA64_REG_AR_ITC);unsigned long vitv =VCPU (vcpu, itv); + kvm = (struct kvm *)KVM_VM_BASE ; +if (vcpu->vcpu_id ==0 ) { -for (i =0 ; i <KVM_MAX_VCPUS ; i++) { +for (i =0 ; i < kvm->arch.online_vcpus; i++) { v = (struct kvm_vcpu *)((char *)vcpu +sizeof (struct kvm_vcpu_data ) * i);VMX (v, itc_offset) = itc_offset;
Signature · 1 line
1.6.0.6
PATCH 8/30 KVM: make irq ack notifications aware of routing table
In reply to Avi KivityFrom: Marcelo Tosatti <[email protected]>
IRQ ack notifications assume an identity mapping between pin->gsi, which might not be the case with, for example, HPET.
Translate before acking.
--- arch/x86/kvm/i8259.c | 5 +++-- arch/x86/kvm/irq.h | 2 ++ include/linux/kvm_host.h | 2 +- virt/kvm/ioapic.c | 10 +++++----- virt/kvm/irq_comm.c | 13 ++++++++++--- 5 files changed, 21 insertions(+), 11 deletions(-)
arch/x86/kvm/i8259.c +3 -2
@@ -49,7 +49,8 @@ static void pic_unlock(struct kvm_pic *s)spin_unlock (&s->lock);while (acks) { -kvm_notify_acked_irq (kvm,__ffs (acks)); +kvm_notify_acked_irq (kvm,SELECT_PIC (__ffs (acks)), +__ffs (acks)); acks &= acks -1 ; }
@@ -232,7 +233,7 @@ int kvm_pic_read_irq(struct kvm *kvm) }pic_update_irq (s);pic_unlock (s); -kvm_notify_acked_irq (kvm, irq); +kvm_notify_acked_irq (kvm,SELECT_PIC (irq), irq);return intno; }
arch/x86/kvm/irq.h +2 -0
@@ -32,6 +32,8 @@#include "lapic.h" #define PIC_NUM_PINS 16 +#define SELECT_PIC (irq) \ + ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE)struct kvm ;struct kvm_vcpu ;
include/linux/kvm_host.h +1 -1
@@ -352,7 +352,7 @@ void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,void kvm_fire_mask_notifiers (struct kvm *kvm,int irq,bool mask);void kvm_set_irq (struct kvm *kvm,int irq_source_id,int irq,int level); -void kvm_notify_acked_irq (struct kvm *kvm,unsigned gsi); +void kvm_notify_acked_irq (struct kvm *kvm,unsigned irqchip,unsigned pin);void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian);void kvm_unregister_irq_ack_notifier (struct kvm_irq_ack_notifier *kian);
virt/kvm/ioapic.c +5 -5
@@ -293,20 +293,20 @@ void kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level) } } -static void __kvm_ioapic_update_eoi (struct kvm_ioapic *ioapic,int gsi, +static void __kvm_ioapic_update_eoi (struct kvm_ioapic *ioapic,int pin,int trigger_mode) {union ioapic_redir_entry *ent; - ent = &ioapic->redirtbl[gsi]; + ent = &ioapic->redirtbl[pin]; -kvm_notify_acked_irq (ioapic->kvm, gsi); +kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , pin);if (trigger_mode ==IOAPIC_LEVEL_TRIG ) {ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG ); ent->fields.remote_irr =0 ; -if (!ent->fields.mask && (ioapic->irr & (1 << gsi))) -ioapic_service (ioapic, gsi); +if (!ent->fields.mask && (ioapic->irr & (1 << pin))) +ioapic_service (ioapic, pin); } }
virt/kvm/irq_comm.c +10 -3
@@ -59,10 +59,19 @@ void kvm_set_irq(struct kvm *kvm, int irq_source_id, int irq, int level) e->set (e, kvm, !!(*irq_state)); } -void kvm_notify_acked_irq (struct kvm *kvm,unsigned gsi) +void kvm_notify_acked_irq (struct kvm *kvm,unsigned irqchip,unsigned pin) { +struct kvm_kernel_irq_routing_entry *e;struct kvm_irq_ack_notifier *kian;struct hlist_node *n; +unsigned gsi = pin; + +list_for_each_entry (e, &kvm->irq_routing, link) +if (e->irqchip.irqchip == irqchip && + e->irqchip.pin == pin) { + gsi = e->gsi; +break ; + }hlist_for_each_entry (kian, n, &kvm->arch.irq_ack_notifier_list, link)if (kian->gsi == gsi)
@@ -237,8 +246,6 @@ out:#define ROUTING_ENTRY1 (irq) IOAPIC_ROUTING_ENTRY(irq)#ifdef CONFIG_X86 -#define SELECT_PIC (irq) \ - ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE)# define PIC_ROUTING_ENTRY (irq) \ { .gsi = irq, .type = KVM_IRQ_ROUTING_IRQCHIP, \ .u.irqchip.irqchip = SELECT_PIC(irq), .u.irqchip.pin = (irq) % 8 }
Signature · 1 line
1.6.0.6
PATCH 9/30 x86: Add EFER descriptions for FFXSR
In reply to Avi KivityFrom: Alexander Graf <[email protected]>
AMD k10 includes support for the FFXSR feature, which leaves out XMM registers on FXSAVE/FXSAVE when the EFER_FFXSR bit is set in EFER.
The CPUID feature bit exists already, but the EFER bit is missing currently, so this patch adds it to the list of known EFER bits.
--- arch/x86/include/asm/msr-index.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/include/asm/msr-index.h +2 -0
@@ -19,12 +19,14 @@#define _EFER_LMA 10/* Long mode active (read-only) */ #define _EFER_NX 11/* No execute enable */ #define _EFER_SVME 12/* Enable virtualization */ +#define _EFER_FFXSR 14/* Enable Fast FXSAVE/FXRSTOR */ #define EFER_SCE (1<<_EFER_SCE)#define EFER_LME (1<<_EFER_LME)#define EFER_LMA (1<<_EFER_LMA)#define EFER_NX (1<<_EFER_NX)#define EFER_SVME (1<<_EFER_SVME) +#define EFER_FFXSR (1<<_EFER_FFXSR)/* Intel MSRs. Some also available on other CPUs */ #define MSR_IA32_PERFCTR0 0x000000c1
Signature · 1 line
1.6.0.6
PATCH 10/30 KVM: Add FFXSR support
In reply to Avi KivityFrom: Alexander Graf <[email protected]>
AMD K10 CPUs implement the FFXSR feature that gets enabled using EFER. Let's check if the virtual CPU description includes that CPUID feature bit and allow enabling it then.
This is required for Windows Server 2008 in Hyper-V mode.
v2 adds CPUID capability exposure
--- arch/x86/kvm/svm.c | 3 +++ arch/x86/kvm/x86.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +3 -0
@@ -417,6 +417,9 @@ static __init int svm_hardware_setup(void)if (boot_cpu_has (X86_FEATURE_NX ))kvm_enable_efer_bits (EFER_NX ); +if (boot_cpu_has (X86_FEATURE_FXSR_OPT )) +kvm_enable_efer_bits (EFER_FFXSR ); +if (nested) {printk (KERN_INFO "kvm: Nested Virtualization enabled\n" );kvm_enable_efer_bits (EFER_SVME );
arch/x86/kvm/x86.c +12 -0
@@ -490,6 +490,17 @@ static void set_efer(struct kvm_vcpu *vcpu, u64 efer)return ; } +if (efer &EFER_FFXSR ) { +struct kvm_cpuid_entry2 *feat; + + feat =kvm_find_cpuid_entry (vcpu,0x80000001 ,0 ); +if (!feat || !(feat->edx &bit (X86_FEATURE_FXSR_OPT ))) { +printk (KERN_DEBUG "set_efer: #GP, enable FFXSR w/o CPUID capability\n" ); +kvm_inject_gp (vcpu,0 ); +return ; + } + } +if (efer &EFER_SVME ) {struct kvm_cpuid_entry2 *feat;
@@ -1240,6 +1251,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,#ifdef CONFIG_X86_64 bit (X86_FEATURE_LM ) | #endif +bit (X86_FEATURE_FXSR_OPT ) |bit (X86_FEATURE_MMXEXT ) |bit (X86_FEATURE_3DNOWEXT ) |bit (X86_FEATURE_3DNOW );
Signature · 1 line
1.6.0.6
PATCH 11/30 KVM: Drop unused evaluations from string pio handlers
In reply to Avi KivityFrom: Jan Kiszka <[email protected]>
Looks like neither the direction nor the rep prefix are used anymore. Drop related evaluations from SVM's and VMX's I/O exit handlers.
--- arch/x86/kvm/svm.c | 4 +--- arch/x86/kvm/vmx.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +1 -3
@@ -1194,7 +1194,7 @@ static int shutdown_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)static int io_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) {u32 io_info = svm->vmcb->control.exit_info_1;/* address size bug? */ -int size, down, in, string, rep; +int size, in, string;unsigned port; ++svm->vcpu.stat.io_exits;
@@ -1213,8 +1213,6 @@ static int io_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) in = (io_info &SVM_IOIO_TYPE_MASK ) !=0 ; port = io_info >>16 ; size = (io_info &SVM_IOIO_SIZE_MASK ) >>SVM_IOIO_SIZE_SHIFT ; - rep = (io_info &SVM_IOIO_REP_MASK ) !=0 ; - down = (svm->vmcb->save.rflags &X86_EFLAGS_DF ) !=0 ;skip_emulated_instruction (&svm->vcpu);return kvm_emulate_pio (&svm->vcpu, kvm_run, in, size, port);
arch/x86/kvm/vmx.c +1 -3
@@ -2698,7 +2698,7 @@ static int handle_triple_fault(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)static int handle_io (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) {unsigned long exit_qualification; -int size, down, in, string, rep; +int size, in, string;unsigned port; ++vcpu->stat.io_exits;
@@ -2714,8 +2714,6 @@ static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) size = (exit_qualification &7 ) +1 ; in = (exit_qualification &8 ) !=0 ; - down = (vmcs_readl (GUEST_RFLAGS ) &X86_EFLAGS_DF ) !=0 ; - rep = (exit_qualification &32 ) !=0 ; port = exit_qualification >>16 ;skip_emulated_instruction (vcpu);
Signature · 1 line
1.6.0.6
PATCH 12/30 KVM: Use irq routing API for MSI
In reply to Avi KivityFrom: Sheng Yang <[email protected]>
Merge MSI userspace interface with IRQ routing table. Notice the API have been changed, and using IRQ routing table would be the only interface kvm-userspace supported.
--- include/linux/kvm.h | 9 +++++ include/linux/kvm_host.h | 2 +- virt/kvm/irq_comm.c | 78 +++++++++++++++++++++++++++++++++++++++++---- virt/kvm/kvm_main.c | 70 +++-------------------------------------- 4 files changed, 86 insertions(+), 73 deletions(-)
include/linux/kvm.h +9 -0
@@ -410,8 +410,16 @@ struct kvm_irq_routing_irqchip {__u32 pin; }; +struct kvm_irq_routing_msi { +__u32 address_lo; +__u32 address_hi; +__u32 data; +__u32 pad; +}; +/* gsi routing entry types */ #define KVM_IRQ_ROUTING_IRQCHIP 1 +#define KVM_IRQ_ROUTING_MSI 2struct kvm_irq_routing_entry {__u32 gsi;
@@ -420,6 +428,7 @@ struct kvm_irq_routing_entry {__u32 pad;union {struct kvm_irq_routing_irqchip irqchip; +struct kvm_irq_routing_msi msi;__u32 pad[8 ]; } u; };
include/linux/kvm_host.h +1 -1
@@ -116,6 +116,7 @@ struct kvm_kernel_irq_routing_entry {unsigned irqchip;unsigned pin; } irqchip; +struct msi_msg msi; };struct list_head link; };
@@ -327,7 +328,6 @@ struct kvm_assigned_dev_kernel {int host_irq;bool host_irq_disabled;int guest_irq; -struct msi_msg guest_msi;#define KVM_ASSIGNED_DEV_GUEST_INTX (1 << 0)#define KVM_ASSIGNED_DEV_GUEST_MSI (1 << 1)#define KVM_ASSIGNED_DEV_HOST_INTX (1 << 8)
virt/kvm/irq_comm.c +71 -7
107 lines not on this page · raw message
virt/kvm/kvm_main.c +5 -65
102 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 13/30 KVM: VMX: Use kvm_mmu_page_fault() handle EPT violation mmio
In reply to Avi KivityFrom: Sheng Yang <[email protected]>
Removed duplicated code.
--- arch/x86/kvm/vmx.c | 30 +----------------------------- 1 files changed, 1 insertions(+), 29 deletions(-)
arch/x86/kvm/vmx.c +1 -29
@@ -3058,11 +3058,8 @@ static int handle_task_switch(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)static int handle_ept_violation (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) {u64 exit_qualification; -enum emulation_result er;gpa_t gpa; -unsigned long hva;int gla_validity; -int r; exit_qualification =vmcs_read64 (EXIT_QUALIFICATION );
@@ -3085,32 +3082,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) } gpa =vmcs_read64 (GUEST_PHYSICAL_ADDRESS ); - hva =gfn_to_hva (vcpu->kvm, gpa >>PAGE_SHIFT ); -if (!kvm_is_error_hva (hva)) { - r =kvm_mmu_page_fault (vcpu, gpa &PAGE_MASK ,0 ); -if (r <0 ) { -printk (KERN_ERR "EPT: Not enough memory!\n" ); -return -ENOMEM ; - } -return 1 ; - }else { -/* must be MMIO */ - er =emulate_instruction (vcpu, kvm_run,0 ,0 ,0 ); - -if (er ==EMULATE_FAIL ) { -printk (KERN_ERR -"EPT: Fail to handle EPT violation vmexit!er is %d\n" , - er); -printk (KERN_ERR "EPT: GPA: 0x%lx, GVA: 0x%lx\n" , - (long unsigned int )vmcs_read64 (GUEST_PHYSICAL_ADDRESS ), - (long unsigned int )vmcs_read64 (GUEST_LINEAR_ADDRESS )); -printk (KERN_ERR "EPT: Exit qualification is 0x%lx\n" , - (long unsigned int )exit_qualification); -return -ENOTSUPP ; - }else if (er ==EMULATE_DO_MMIO ) -return 0 ; - } -return 1 ; +return kvm_mmu_page_fault (vcpu, gpa &PAGE_MASK ,0 ); }static int handle_nmi_window (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run)
Signature · 1 line
1.6.0.6
PATCH 14/30 KVM: Fix kvmclock on !constant_tsc boxes
In reply to Avi KivityFrom: Gerd Hoffmann <[email protected]>
kvmclock currently falls apart on machines without constant tsc. This patch fixes it. Changes:
* keep tsc frequency in a per-cpu variable.
* handle kvmclock update using a new request flag, thus checking whenever we need an update each time we enter guest context.
* use a cpufreq notifier to track frequency changes and force kvmclock updates.
* send ipis to kick cpu out of guest context if needed to make sure the guest doesn't see stale values.
--- arch/x86/kvm/x86.c | 103 ++++++++++++++++++++++++++++++++++++++++++---- include/linux/kvm_host.h | 1 + 2 files changed, 95 insertions(+), 9 deletions(-)
arch/x86/kvm/x86.c +94 -9
@@ -36,6 +36,7 @@#include <linux/highmem.h> #include <linux/iommu.h> #include <linux/intel-iommu.h> +#include <linux/cpufreq.h> #include <asm/uaccess.h> #include <asm/msr.h>
@@ -617,6 +618,8 @@ static void kvm_set_time_scale(uint32_t tsc_khz, struct pvclock_vcpu_time_info * hv_clock->tsc_to_system_mul); } +static DEFINE_PER_CPU(unsigned long, cpu_tsc_khz); +static void kvm_write_guest_time (struct kvm_vcpu *v) {struct timespec ts;
@@ -627,9 +630,9 @@ static void kvm_write_guest_time(struct kvm_vcpu *v)if ((!vcpu->time_page))return ; -if (unlikely (vcpu->hv_clock_tsc_khz != tsc_khz)) { -kvm_set_time_scale (tsc_khz, &vcpu->hv_clock); - vcpu->hv_clock_tsc_khz = tsc_khz; +if (unlikely (vcpu->hv_clock_tsc_khz !=__get_cpu_var (cpu_tsc_khz))) { +kvm_set_time_scale (__get_cpu_var (cpu_tsc_khz), &vcpu->hv_clock); + vcpu->hv_clock_tsc_khz =__get_cpu_var (cpu_tsc_khz); }/* Keep irq disabled to prevent changes to the clock */
@@ -660,6 +663,16 @@ static void kvm_write_guest_time(struct kvm_vcpu *v)mark_page_dirty (v->kvm, vcpu->time >>PAGE_SHIFT ); } +static int kvm_request_guest_time_update (struct kvm_vcpu *v) +{ +struct kvm_vcpu_arch *vcpu = &v->arch; + +if (!vcpu->time_page) +return 0 ; +set_bit (KVM_REQ_KVMCLOCK_UPDATE , &v->requests); +return 1 ; +} +static bool msr_mtrr_valid (unsigned msr) {switch (msr) {
@@ -790,7 +803,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) vcpu->arch.time_page =NULL ; } -kvm_write_guest_time (vcpu); +kvm_request_guest_time_update (vcpu);break ; }default :
@@ -1000,6 +1013,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_MMU_SHADOW_CACHE_CONTROL :case KVM_CAP_SET_TSS_ADDR :case KVM_CAP_EXT_CPUID : +case KVM_CAP_CLOCKSOURCE :case KVM_CAP_PIT :case KVM_CAP_NOP_IO_DELAY :case KVM_CAP_MP_STATE :
@@ -1025,9 +1039,6 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_IOMMU : r =iommu_found ();break ; -case KVM_CAP_CLOCKSOURCE : - r =boot_cpu_has (X86_FEATURE_CONSTANT_TSC ); -break ;default : r =0 ;break ;
@@ -1098,7 +1109,7 @@ out:void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu) { kvm_x86_ops->vcpu_load (vcpu, cpu); -kvm_write_guest_time (vcpu); +kvm_request_guest_time_update (vcpu); }void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu)
@@ -2642,9 +2653,72 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, }EXPORT_SYMBOL_GPL (kvm_emulate_pio_string); +static void bounce_off (void *info) +{ +/* nothing */ +} + +static unsigned int ref_freq; +static unsigned long tsc_khz_ref; + +static int kvmclock_cpufreq_notifier (struct notifier_block *nb,unsigned long val, +void *data) +{ +struct cpufreq_freqs *freq = data; +struct kvm *kvm; +struct kvm_vcpu *vcpu; +int i, send_ipi =0 ; + +if (!ref_freq) + ref_freq = freq->old; + +if (val ==CPUFREQ_PRECHANGE && freq->old > freq->new) +return 0 ; +if (val ==CPUFREQ_POSTCHANGE && freq->old < freq->new) +return 0 ; +per_cpu (cpu_tsc_khz, freq->cpu) =cpufreq_scale (tsc_khz_ref, ref_freq, freq->new); + +spin_lock (&kvm_lock); +list_for_each_entry (kvm, &vm_list, vm_list) { +for (i =0 ; i <KVM_MAX_VCPUS ; ++i) { + vcpu = kvm->vcpus[i]; +if (!vcpu) +continue ; +if (vcpu->cpu != freq->cpu) +continue ; +if (!kvm_request_guest_time_update (vcpu)) +continue ; +if (vcpu->cpu !=smp_processor_id ()) + send_ipi++; + } + } +spin_unlock (&kvm_lock); + +if (freq->old < freq->new && send_ipi) { +/* +* We upscale the frequency. Must make the guest +* doesn't see old kvmclock values while running with +* the new frequency, otherwise we risk the guest sees +* time go backwards. +* +* In case we update the frequency for another cpu +* (which might be in guest context) send an interrupt +* to kick the cpu out of guest context. Next time +* guest context is entered kvmclock will be updated, +* so the guest will not see stale values. +*/ +smp_call_function_single (freq->cpu, bounce_off,NULL ,1 ); + } +return 0 ; +} + +static struct notifier_block kvmclock_cpufreq_notifier_block = { + .notifier_call = kvmclock_cpufreq_notifier +}; +int kvm_arch_init (void *opaque) { -int r; +int r, cpu;struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;if (kvm_x86_ops) {
@@ -2675,6 +2749,15 @@ int kvm_arch_init(void *opaque)kvm_mmu_set_base_ptes (PT_PRESENT_MASK );kvm_mmu_set_mask_ptes (PT_USER_MASK ,PT_ACCESSED_MASK ,PT_DIRTY_MASK ,PT64_NX_MASK ,0 ,0 ); + +for_each_possible_cpu (cpu) +per_cpu (cpu_tsc_khz, cpu) = tsc_khz; +if (!boot_cpu_has (X86_FEATURE_CONSTANT_TSC )) { + tsc_khz_ref = tsc_khz; +cpufreq_register_notifier (&kvmclock_cpufreq_notifier_block, +CPUFREQ_TRANSITION_NOTIFIER ); + } +return 0 ; out:
@@ -3010,6 +3093,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)if (vcpu->requests) {if (test_and_clear_bit (KVM_REQ_MIGRATE_TIMER , &vcpu->requests))__kvm_migrate_timers (vcpu); +if (test_and_clear_bit (KVM_REQ_KVMCLOCK_UPDATE , &vcpu->requests)) +kvm_write_guest_time (vcpu);if (test_and_clear_bit (KVM_REQ_MMU_SYNC , &vcpu->requests))kvm_mmu_sync_roots (vcpu);if (test_and_clear_bit (KVM_REQ_TLB_FLUSH , &vcpu->requests))
include/linux/kvm_host.h +1 -0
@@ -37,6 +37,7 @@#define KVM_REQ_PENDING_TIMER 5#define KVM_REQ_UNHALT 6#define KVM_REQ_MMU_SYNC 7 +#define KVM_REQ_KVMCLOCK_UPDATE 8#define KVM_USERSPACE_IRQ_SOURCE_ID 0
Signature · 1 line
1.6.0.6
PATCH 15/30 KVM: MMU: handle compound pages in kvm_is_mmio_pfn
In reply to Avi KivityFrom: Joerg Roedel <[email protected]>
The function kvm_is_mmio_pfn is called before put_page is called on a page by KVM. This is a problem when when this function is called on some struct page which is part of a compund page. It does not test the reserved flag of the compound page but of the struct page within the compount page. This is a problem when KVM works with hugepages allocated at boot time. These pages have the reserved bit set in all tail pages. Only the flag in the compount head is cleared. KVM would not put such a page which results in a memory leak.
--- virt/kvm/kvm_main.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
virt/kvm/kvm_main.c +4 -2
@@ -535,8 +535,10 @@ static inline int valid_vcpu(int n)inline int kvm_is_mmio_pfn (pfn_t pfn) { -if (pfn_valid (pfn)) -return PageReserved (pfn_to_page (pfn)); +if (pfn_valid (pfn)) { +struct page *page =compound_head (pfn_to_page (pfn)); +return PageReserved (page); + }return true; }
Signature · 1 line
1.6.0.6
PATCH 16/30 KVM: MMU: remove redundant check in mmu_set_spte
In reply to Avi KivityFrom: Joerg Roedel <[email protected]>
The following code flow is unnecessary:
if (largepage) was_rmapped = is_large_pte(*shadow_pte); else was_rmapped = 1;
The is_large_pte() function will always evaluate to one here because the (largepage && !is_large_pte) case is already handled in the first if-clause. So we can remove this check and set was_rmapped to one always here.
--- arch/x86/kvm/mmu.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/kvm/mmu.c +2 -6
@@ -1791,12 +1791,8 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,pgprintk ("hfn old %lx new %lx\n" ,spte_to_pfn (*shadow_pte), pfn);rmap_remove (vcpu->kvm, shadow_pte); - }else { -if (largepage) - was_rmapped =is_large_pte (*shadow_pte); -else - was_rmapped =1 ; - } + }else + was_rmapped =1 ; }if (set_spte (vcpu, shadow_pte, pte_access, user_fault, write_fault, dirty, largepage, global, gfn, pfn, speculative, true)) {
Signature · 1 line
1.6.0.6
PATCH 17/30 KVM: MMU: remove assertion in kvm_mmu_alloc_page
In reply to Avi KivityFrom: Joerg Roedel <[email protected]>
The assertion no longer makes sense since we don't clear page tables on allocation; instead we clear them during prefetch.
--- arch/x86/kvm/mmu.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
arch/x86/kvm/mmu.c +0 -1
@@ -802,7 +802,6 @@ static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu,set_page_private (virt_to_page (sp->spt), (unsigned long )sp);list_add (&sp->link, &vcpu->kvm->arch.active_mmu_pages);INIT_LIST_HEAD (&sp->oos_link); -ASSERT (is_empty_shadow_page (sp->spt));bitmap_zero (sp->slot_bitmap,KVM_MEMORY_SLOTS +KVM_PRIVATE_MEM_SLOTS ); sp->multimapped =0 ; sp->parent_pte = parent_pte;
Signature · 1 line
1.6.0.6
PATCH 18/30 KVM: Report IRQ injection status to userspace.
In reply to Avi KivityFrom: Gleb Natapov <[email protected]>
IRQ injection status is either -1 (if there was no CPU found that should except the interrupt because IRQ was masked or ioapic was misconfigured or ...) or >= 0 in that case the number indicates to how many CPUs interrupt was injected. If the value is 0 it means that the interrupt was coalesced and probably should be reinjected.
--- arch/ia64/kvm/kvm-ia64.c | 12 +++++++++- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/i8259.c | 18 ++++++++++++---- arch/x86/kvm/x86.c | 13 ++++++++++- include/linux/kvm.h | 7 +++++- include/linux/kvm_host.h | 4 +- virt/kvm/ioapic.c | 23 +++++++++++++++------ virt/kvm/ioapic.h | 2 +- virt/kvm/irq_comm.c | 41 ++++++++++++++++++++++++++------------ 9 files changed, 88 insertions(+), 34 deletions(-)
arch/ia64/kvm/kvm-ia64.c +10 -2
@@ -182,7 +182,7 @@ int kvm_dev_ioctl_check_extension(long ext)switch (ext) {case KVM_CAP_IRQCHIP :case KVM_CAP_MP_STATE : - +case KVM_CAP_IRQ_INJECT_STATUS : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
@@ -927,6 +927,7 @@ long kvm_arch_vm_ioctl(struct file *filp, goto out; }break ; +case KVM_IRQ_LINE_STATUS :case KVM_IRQ_LINE : {struct kvm_irq_level irq_event;
@@ -934,10 +935,17 @@ long kvm_arch_vm_ioctl(struct file *filp,if (copy_from_user (&irq_event, argp,sizeof irq_event)) goto out;if (irqchip_in_kernel (kvm)) { +__s32 status;mutex_lock (&kvm->lock); -kvm_set_irq (kvm,KVM_USERSPACE_IRQ_SOURCE_ID , + status =kvm_set_irq (kvm,KVM_USERSPACE_IRQ_SOURCE_ID , irq_event.irq, irq_event.level);mutex_unlock (&kvm->lock); +if (ioctl ==KVM_IRQ_LINE_STATUS ) { + irq_event.status = status; +if (copy_to_user (argp, &irq_event, +sizeof irq_event)) + goto out; + } r =0 ; }break ;
arch/x86/include/asm/kvm_host.h +1 -1
@@ -616,7 +616,7 @@ void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);void kvm_inject_page_fault (struct kvm_vcpu *vcpu,unsigned long cr2,u32 error_code); -void kvm_pic_set_irq (void *opaque,int irq,int level); +int kvm_pic_set_irq (void *opaque,int irq,int level);void kvm_inject_nmi (struct kvm_vcpu *vcpu);
arch/x86/kvm/i8259.c +13 -5
@@ -77,12 +77,13 @@ void kvm_pic_clear_isr_ack(struct kvm *kvm)/* * set irq level. If an edge is detected, then the IRR is set to 1 */ -static inline void pic_set_irq1 (struct kvm_kpic_state *s,int irq,int level) +static inline int pic_set_irq1 (struct kvm_kpic_state *s,int irq,int level) { -int mask; +int mask, ret =1 ; mask =1 << irq;if (s->elcr & mask)/* level triggered */ if (level) { + ret = !(s->irr & mask); s->irr |= mask; s->last_irr |= mask; }else {
@@ -91,11 +92,15 @@ static inline void pic_set_irq1(struct kvm_kpic_state *s, int irq, int level) }else /* edge triggered */ if (level) { -if ((s->last_irr & mask) ==0 ) +if ((s->last_irr & mask) ==0 ) { + ret = !(s->irr & mask); s->irr |= mask; + } s->last_irr |= mask; }else s->last_irr &= ~mask; + +return (s->imr & mask) ?-1 : ret; }/*
@@ -172,16 +177,19 @@ void kvm_pic_update_irq(struct kvm_pic *s)pic_unlock (s); } -void kvm_pic_set_irq (void *opaque,int irq,int level) +int kvm_pic_set_irq (void *opaque,int irq,int level) {struct kvm_pic *s = opaque; +int ret =-1 ;pic_lock (s);if (irq >=0 && irq <PIC_NUM_PINS ) { -pic_set_irq1 (&s->pics[irq >>3 ], irq &7 , level); + ret =pic_set_irq1 (&s->pics[irq >>3 ], irq &7 , level);pic_update_irq (s); }pic_unlock (s); + +return ret; }/*
arch/x86/kvm/x86.c +11 -2
@@ -1019,6 +1019,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_MP_STATE :case KVM_CAP_SYNC_MMU :case KVM_CAP_REINJECT_CONTROL : +case KVM_CAP_IRQ_INJECT_STATUS : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
@@ -1877,6 +1878,7 @@ long kvm_arch_vm_ioctl(struct file *filp, create_pit_unlock:mutex_unlock (&kvm->lock);break ; +case KVM_IRQ_LINE_STATUS :case KVM_IRQ_LINE : {struct kvm_irq_level irq_event;
@@ -1884,10 +1886,17 @@ long kvm_arch_vm_ioctl(struct file *filp,if (copy_from_user (&irq_event, argp,sizeof irq_event)) goto out;if (irqchip_in_kernel (kvm)) { +__s32 status;mutex_lock (&kvm->lock); -kvm_set_irq (kvm,KVM_USERSPACE_IRQ_SOURCE_ID , - irq_event.irq, irq_event.level); + status =kvm_set_irq (kvm,KVM_USERSPACE_IRQ_SOURCE_ID , + irq_event.irq, irq_event.level);mutex_unlock (&kvm->lock); +if (ioctl ==KVM_IRQ_LINE_STATUS ) { + irq_event.status = status; +if (copy_to_user (argp, &irq_event, +sizeof irq_event)) + goto out; + } r =0 ; }break ;
include/linux/kvm.h +6 -1
@@ -48,7 +48,10 @@ struct kvm_irq_level {* For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47.. * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23.. */ -__u32 irq; +union { +__u32 irq; +__s32 status; + };__u32 level; };
@@ -402,6 +405,7 @@ struct kvm_trace_rec {#ifdef __KVM_HAVE_IOAPIC#define KVM_CAP_IRQ_ROUTING 25#endif +#define KVM_CAP_IRQ_INJECT_STATUS 26#ifdef KVM_CAP_IRQ_ROUTING
@@ -465,6 +469,7 @@ struct kvm_irq_routing {#define KVM_CREATE_PIT _IO(KVMIO, 0x64)#define KVM_GET_PIT _IOWR(KVMIO, 0x65, struct kvm_pit_state)#define KVM_SET_PIT _IOR(KVMIO, 0x66, struct kvm_pit_state) +#define KVM_IRQ_LINE_STATUS _IOWR(KVMIO, 0x67, struct kvm_irq_level)#define KVM_REGISTER_COALESCED_MMIO \ _IOW(KVMIO, 0x67, struct kvm_coalesced_mmio_zone)#define KVM_UNREGISTER_COALESCED_MMIO \
include/linux/kvm_host.h +2 -2
@@ -110,7 +110,7 @@ struct kvm_memory_slot { struct kvm_kernel_irq_routing_entry { u32 gsi; - void (*set)(struct kvm_kernel_irq_routing_entry *e, + int (*set)(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, int level); union { struct {
@@ -352,7 +352,7 @@ void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq, struct kvm_irq_mask_notifier *kimn);void kvm_fire_mask_notifiers (struct kvm *kvm,int irq,bool mask); -void kvm_set_irq (struct kvm *kvm,int irq_source_id,int irq,int level); +int kvm_set_irq (struct kvm *kvm,int irq_source_id,int irq,int level);void kvm_notify_acked_irq (struct kvm *kvm,unsigned irqchip,unsigned pin);void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian);
virt/kvm/ioapic.c +16 -7
@@ -83,19 +83,22 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic,return result; } -static void ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union ioapic_redir_entry *pent; +int injected =-1 ; pent = &ioapic->redirtbl[idx];if (!pent->fields.mask) { -int injected =ioapic_deliver (ioapic, idx); + injected =ioapic_deliver (ioapic, idx);if (injected && pent->fields.trig_mode ==IOAPIC_LEVEL_TRIG ) pent->fields.remote_irr =1 ; }if (!pent->fields.trig_mode) ioapic->irr &= ~(1 << idx); + +return injected; }static void ioapic_write_indirect (struct kvm_ioapic *ioapic,u32 val)
@@ -207,7 +210,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq)u8 trig_mode = ioapic->redirtbl[irq].fields.trig_mode;u32 deliver_bitmask;struct kvm_vcpu *vcpu; -int vcpu_id, r =0 ; +int vcpu_id, r =-1 ; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",
@@ -247,7 +250,9 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) deliver_bitmask &= ~(1 << vcpu_id); vcpu = ioapic->kvm->vcpus[vcpu_id];if (vcpu) { - r =ioapic_inj_irq (ioapic, vcpu, vector, +if (r <0 ) + r =0 ; + r +=ioapic_inj_irq (ioapic, vcpu, vector, trig_mode, delivery_mode); } }
@@ -258,8 +263,10 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq)continue ; deliver_bitmask &= ~(1 << vcpu_id); vcpu = ioapic->kvm->vcpus[vcpu_id]; -if (vcpu) +if (vcpu) {ioapic_inj_nmi (vcpu); + r =1 ; + }else ioapic_debug ("NMI to vcpu %d failed\n" , vcpu->vcpu_id);
@@ -273,11 +280,12 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq)return r; } -void kvm_ioapic_set_irq (struct kvm_ioapic *ioapic,int irq,int level) +int kvm_ioapic_set_irq (struct kvm_ioapic *ioapic,int irq,int level) {u32 old_irr = ioapic->irr;u32 mask =1 << irq;union ioapic_redir_entry entry; +int ret =1 ;if (irq >=0 && irq <IOAPIC_NUM_PINS ) { entry = ioapic->redirtbl[irq];
@@ -288,9 +296,10 @@ void kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level) ioapic->irr |= mask;if ((!entry.fields.trig_mode && old_irr != ioapic->irr) || !entry.fields.remote_irr) -ioapic_service (ioapic, irq); + ret =ioapic_service (ioapic, irq); } } +return ret; } static void __kvm_ioapic_update_eoi(struct kvm_ioapic *ioapic, int pin,
virt/kvm/ioapic.h +1 -1
@@ -83,7 +83,7 @@ struct kvm_vcpu *kvm_get_lowest_prio_vcpu(struct kvm *kvm, u8 vector, unsigned long bitmap);void kvm_ioapic_update_eoi (struct kvm *kvm,int vector,int trigger_mode);int kvm_ioapic_init (struct kvm *kvm); -void kvm_ioapic_set_irq (struct kvm_ioapic *ioapic,int irq,int level); +int kvm_ioapic_set_irq (struct kvm_ioapic *ioapic,int irq,int level);void kvm_ioapic_reset (struct kvm_ioapic *ioapic);u32 kvm_ioapic_get_delivery_bitmask (struct kvm_ioapic *ioapic,u8 dest,u8 dest_mode);
virt/kvm/irq_comm.c +28 -13
78 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 19/30 KVM: SVM: set accessed bit for VMCB segment selectors
In reply to Avi KivityFrom: Andre Przywara <[email protected]>
In the segment descriptor _cache_ the accessed bit is always set (although it can be cleared in the descriptor itself). Since Intel checks for this condition on a VMENTRY, set this bit in the AMD path to enable cross vendor migration.
--- arch/x86/kvm/svm.c | 41 +++++++++++++++++++++++++++++------------ 1 files changed, 29 insertions(+), 12 deletions(-)
arch/x86/kvm/svm.c +29 -12
@@ -796,20 +796,37 @@ static void svm_get_segment(struct kvm_vcpu *vcpu, var->db = (s->attrib >>SVM_SELECTOR_DB_SHIFT ) &1 ; var->g = (s->attrib >>SVM_SELECTOR_G_SHIFT ) &1 ; -/* -* SVM always stores 0 for the 'G' bit in the CS selector in -* the VMCB on a VMEXIT. This hurts cross-vendor migration: -* Intel's VMENTRY has a check on the 'G' bit. -*/ -if (seg ==VCPU_SREG_CS ) +switch (seg) { +case VCPU_SREG_CS : +/* +* SVM always stores 0 for the 'G' bit in the CS selector in +* the VMCB on a VMEXIT. This hurts cross-vendor migration: +* Intel's VMENTRY has a check on the 'G' bit. +*/ var->g = s->limit >0xfffff ; - -/* -* Work around a bug where the busy flag in the tr selector -* isn't exposed -*/ -if (seg ==VCPU_SREG_TR ) +break ; +case VCPU_SREG_TR : +/* +* Work around a bug where the busy flag in the tr selector +* isn't exposed +*/ var->type |=0x2 ; +break ; +case VCPU_SREG_DS : +case VCPU_SREG_ES : +case VCPU_SREG_FS : +case VCPU_SREG_GS : +/* +* The accessed bit must always be set in the segment +* descriptor cache, although it can be cleared in the +* descriptor, the cached bit always remains at 1. Since +* Intel has a check on this, set it here to support +* cross-vendor migration. +*/ +if (!var->unusable) + var->type |=0x1 ; +break ; + } var->unusable = !var->present; }
Signature · 1 line
1.6.0.6
PATCH 20/30 KVM: MMU: Fix another largepage memory leak
In reply to Avi KivityFrom: Joerg Roedel <[email protected]>
In the paging_fetch function rmap_remove is called after setting a large pte to non-present. This causes rmap_remove to not drop the reference to the large page. The result is a memory leak of that page.
--- arch/x86/kvm/paging_tmpl.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/paging_tmpl.h +1 -1
@@ -306,9 +306,9 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,continue ;if (is_large_pte (*sptep)) { +rmap_remove (vcpu->kvm, sptep);set_shadow_pte (sptep, shadow_trap_nonpresent_pte);kvm_flush_remote_tlbs (vcpu->kvm); -rmap_remove (vcpu->kvm, sptep); } if (level == PT_DIRECTORY_LEVEL
Signature · 1 line
1.6.0.6
PATCH 21/30 KVM: Report IRQ injection status for MSI delivered interrupts
In reply to Avi KivityFrom: Gleb Natapov <[email protected]>
Return number of CPUs interrupt was successfully injected into or -1 if none.
--- virt/kvm/irq_comm.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
virt/kvm/irq_comm.c +8 -5
@@ -48,7 +48,7 @@ static int kvm_set_ioapic_irq(struct kvm_kernel_irq_routing_entry *e,static int kvm_set_msi (struct kvm_kernel_irq_routing_entry *e,struct kvm *kvm,int level) { -int vcpu_id; +int vcpu_id, r =-1 ;struct kvm_vcpu *vcpu;struct kvm_ioapic *ioapic =ioapic_irqchip (kvm);int dest_id = (e->msi.address_lo &MSI_ADDR_DEST_ID_MASK )
@@ -73,7 +73,7 @@ static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, vcpu =kvm_get_lowest_prio_vcpu (ioapic->kvm, vector, deliver_bitmask);if (vcpu !=NULL ) -kvm_apic_set_irq (vcpu, vector, trig_mode); + r =kvm_apic_set_irq (vcpu, vector, trig_mode);else printk (KERN_INFO "kvm: null lowest priority vcpu!\n" );break ;
@@ -83,14 +83,17 @@ static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,continue ; deliver_bitmask &= ~(1 << vcpu_id); vcpu = ioapic->kvm->vcpus[vcpu_id]; -if (vcpu) -kvm_apic_set_irq (vcpu, vector, trig_mode); +if (vcpu) { +if (r <0 ) + r =0 ; + r +=kvm_apic_set_irq (vcpu, vector, trig_mode); + } }break ;default :break ; } -return 1 ; +return r; }/* This should be called with the kvm->lock mutex held
Signature · 1 line
1.6.0.6
PATCH 22/30 KVM: ppc: Add emulation of E500 register mmucsr0
In reply to Avi KivityFrom: Liu Yu <[email protected]>
Latest kernel flushes TLB via mmucsr0.
--- arch/powerpc/kvm/e500_emulate.c | 8 ++++++++ arch/powerpc/kvm/e500_tlb.c | 16 ++++++++++++++++ arch/powerpc/kvm/e500_tlb.h | 1 + 3 files changed, 25 insertions(+), 0 deletions(-)
arch/powerpc/kvm/e500_emulate.c +8 -0
@@ -105,6 +105,11 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)case SPRN_HID1 : vcpu_e500->hid1 = vcpu->arch.gpr[rs];break ; +case SPRN_MMUCSR0 : + emulated =kvmppc_e500_emul_mt_mmucsr0 (vcpu_e500, + vcpu->arch.gpr[rs]); +break ; +/* extra exceptions */ case SPRN_IVOR32 : vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL ] = vcpu->arch.gpr[rs];
@@ -172,6 +177,9 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)case SPRN_HID1 : vcpu->arch.gpr[rt] = vcpu_e500->hid1;break ; +case SPRN_MMUCSR0 : + vcpu->arch.gpr[rt] =0 ;break ; +/* extra exceptions */ case SPRN_IVOR32 : vcpu->arch.gpr[rt] = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL ];
arch/powerpc/kvm/e500_tlb.c +16 -0
@@ -391,6 +391,22 @@ static int kvmppc_e500_gtlbe_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,return 0 ; } +int kvmppc_e500_emul_mt_mmucsr0 (struct kvmppc_vcpu_e500 *vcpu_e500,ulong value) +{ +int esel; + +if (value &MMUCSR0_TLB0FI ) +for (esel =0 ; esel < vcpu_e500->guest_tlb_size[0 ]; esel++) +kvmppc_e500_gtlbe_invalidate (vcpu_e500,0 , esel); +if (value &MMUCSR0_TLB1FI ) +for (esel =0 ; esel < vcpu_e500->guest_tlb_size[1 ]; esel++) +kvmppc_e500_gtlbe_invalidate (vcpu_e500,1 , esel); + +_tlbil_all (); + +return EMULATE_DONE ; +} +int kvmppc_e500_emul_tlbivax (struct kvm_vcpu *vcpu,int ra,int rb) {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);
arch/powerpc/kvm/e500_tlb.h +1 -0
@@ -44,6 +44,7 @@ | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK)extern void kvmppc_dump_tlbs (struct kvm_vcpu *); +extern int kvmppc_e500_emul_mt_mmucsr0 (struct kvmppc_vcpu_e500 *,ulong );extern int kvmppc_e500_emul_tlbwe (struct kvm_vcpu *);extern int kvmppc_e500_emul_tlbre (struct kvm_vcpu *);extern int kvmppc_e500_emul_tlbivax (struct kvm_vcpu *,int ,int );
Signature · 1 line
1.6.0.6
PATCH 23/30 KVM: define KVM_CAP_DEVICE_DEASSIGNMENT
In reply to Avi KivityFrom: Weidong Han <[email protected]>
define KVM_CAP_DEVICE_DEASSIGNMENT and KVM_DEASSIGN_PCI_DEVICE for device deassignment.
the ioctl has been already implemented in the
commit: 0a920356748df4fb06e86c21c23d2ed6d31d37ad
--- include/linux/kvm.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
include/linux/kvm.h +5 -0
@@ -406,6 +406,9 @@ struct kvm_trace_rec {#define KVM_CAP_IRQ_ROUTING 25#endif #define KVM_CAP_IRQ_INJECT_STATUS 26 +#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT +#define KVM_CAP_DEVICE_DEASSIGNMENT 27 +#endif #ifdef KVM_CAP_IRQ_ROUTING
@@ -480,6 +483,8 @@ struct kvm_irq_routing {#define KVM_ASSIGN_IRQ _IOR(KVMIO, 0x70, \ struct kvm_assigned_irq)#define KVM_REINJECT_CONTROL _IO(KVMIO, 0x71) +#define KVM_DEASSIGN_PCI_DEVICE _IOR(KVMIO, 0x72, \ + struct kvm_assigned_pci_dev)/* * ioctls for vcpu fds
Signature · 1 line
1.6.0.6
PATCH 24/30 KVM: fix kvm_vm_ioctl_deassign_device
In reply to Avi KivityFrom: Weidong Han <[email protected]>
only need to set assigned_dev_id for deassignment, use match->flags to judge and deassign it.
--- virt/kvm/kvm_main.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
virt/kvm/kvm_main.c +1 -1
@@ -517,7 +517,7 @@ static int kvm_vm_ioctl_deassign_device(struct kvm *kvm, goto out; } -if (assigned_dev->flags &KVM_DEV_ASSIGN_ENABLE_IOMMU ) +if (match->flags &KVM_DEV_ASSIGN_ENABLE_IOMMU )kvm_deassign_device (kvm, match);kvm_free_assigned_device (kvm, match);
Signature · 1 line
1.6.0.6
PATCH 25/30 ia64: Move the macro definitions related to MSI to one header file.
In reply to Avi KivityFrom: Xiantao Zhang <[email protected]>
For kvm's MSI support, it needs these macros defined in ia64_msi.c, and to avoid duplicate them, move them to one header file and share with kvm.
--- arch/ia64/include/asm/msidef.h | 42 ++++++++++++++++++++++++++++++ arch/ia64/kernel/msi_ia64.c | 55 ++++++--------------------------------- 2 files changed, 51 insertions(+), 46 deletions(-) create mode 100644 arch/ia64/include/asm/msidef.h
arch/ia64/include/asm/msidef.h new file +42 -0
@@ -0,0 +1,42 @@ +#ifndef _IA64_MSI_DEF_H +#define _IA64_MSI_DEF_H + +/* +* Shifts for APIC-based data +*/ + +#define MSI_DATA_VECTOR_SHIFT 0 +#define MSI_DATA_VECTOR (v) (((u8)v) << MSI_DATA_VECTOR_SHIFT) +#define MSI_DATA_VECTOR_MASK 0xffffff00 + +#define MSI_DATA_DELIVERY_MODE_SHIFT 8 +#define MSI_DATA_DELIVERY_FIXED (0 << MSI_DATA_DELIVERY_MODE_SHIFT) +#define MSI_DATA_DELIVERY_LOWPRI (1 << MSI_DATA_DELIVERY_MODE_SHIFT) + +#define MSI_DATA_LEVEL_SHIFT 14 +#define MSI_DATA_LEVEL_DEASSERT (0 << MSI_DATA_LEVEL_SHIFT) +#define MSI_DATA_LEVEL_ASSERT (1 << MSI_DATA_LEVEL_SHIFT) + +#define MSI_DATA_TRIGGER_SHIFT 15 +#define MSI_DATA_TRIGGER_EDGE (0 << MSI_DATA_TRIGGER_SHIFT) +#define MSI_DATA_TRIGGER_LEVEL (1 << MSI_DATA_TRIGGER_SHIFT) + +/* +* Shift/mask fields for APIC-based bus address +*/ + +#define MSI_ADDR_DEST_ID_SHIFT 4 +#define MSI_ADDR_HEADER 0xfee00000 + +#define MSI_ADDR_DEST_ID_MASK 0xfff0000f +#define MSI_ADDR_DEST_ID_CPU (cpu) ((cpu) << MSI_ADDR_DEST_ID_SHIFT) + +#define MSI_ADDR_DEST_MODE_SHIFT 2 +#define MSI_ADDR_DEST_MODE_PHYS (0 << MSI_ADDR_DEST_MODE_SHIFT) +#define MSI_ADDR_DEST_MODE_LOGIC (1 << MSI_ADDR_DEST_MODE_SHIFT) + +#define MSI_ADDR_REDIRECTION_SHIFT 3 +#define MSI_ADDR_REDIRECTION_CPU (0 << MSI_ADDR_REDIRECTION_SHIFT) +#define MSI_ADDR_REDIRECTION_LOWPRI (1 << MSI_ADDR_REDIRECTION_SHIFT) + +#endif /* _IA64_MSI_DEF_H */
arch/ia64/kernel/msi_ia64.c +9 -46
87 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 26/30 KVM: ia64: Fix the build errors due to lack of macros related to MSI.
In reply to Avi KivityFrom: Xiantao Zhang <[email protected]>
Include the newly introduced msidef.h to solve the build issues.
--- arch/ia64/kvm/irq.h | 2 ++ virt/kvm/irq_comm.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/ia64/kvm/irq.h +2 -0
@@ -23,6 +23,8 @@#ifndef __IRQ_H#define __IRQ_H +#include "lapic.h" +static inline int irqchip_in_kernel (struct kvm *kvm) {return 1 ;
virt/kvm/irq_comm.c +0 -2
@@ -21,9 +21,7 @@#include <linux/kvm_host.h> -#ifdef CONFIG_X86 #include <asm/msidef.h> -#endif #include "irq.h"
Signature · 1 line
1.6.0.6
PATCH 27/30 KVM: VMX: Update necessary state when guest enters long mode
In reply to Avi KivityFrom: Amit Shah <[email protected]>
setup_msrs() should be called when entering long mode to save the shadow state for the 64-bit guest state.
Using vmx_set_efer() in enter_lmode() removes some duplicated code and also ensures we call setup_msrs(). We can safely pass the value of shadow_efer to vmx_set_efer() as no other bits in the efer change while enabling long mode (guest first sets EFER.LME, then sets CR0.PG which causes a vmexit where we activate long mode).
With this fix, is_long_mode() can check for EFER.LMA set instead of EFER.LME and 5e23049e86dd298b72e206b420513dbc3a240cd9 can be reverted.
--- arch/x86/kvm/vmx.c | 54 +++++++++++++++++++++++---------------------------- 1 files changed, 24 insertions(+), 30 deletions(-)
arch/x86/kvm/vmx.c +24 -30
@@ -1430,6 +1430,29 @@ continue_rmode:init_rmode (vcpu->kvm); } +static void vmx_set_efer (struct kvm_vcpu *vcpu,u64 efer) +{ +struct vcpu_vmx *vmx =to_vmx (vcpu); +struct kvm_msr_entry *msr =find_msr_entry (vmx,MSR_EFER ); + + vcpu->arch.shadow_efer = efer; +if (!msr) +return ; +if (efer &EFER_LMA ) { +vmcs_write32 (VM_ENTRY_CONTROLS , +vmcs_read32 (VM_ENTRY_CONTROLS ) | +VM_ENTRY_IA32E_MODE ); + msr->data = efer; + }else { +vmcs_write32 (VM_ENTRY_CONTROLS , +vmcs_read32 (VM_ENTRY_CONTROLS ) & + ~VM_ENTRY_IA32E_MODE ); + + msr->data = efer & ~EFER_LME ; + } +setup_msrs (vmx); +} +#ifdef CONFIG_X86_64 static void enter_lmode (struct kvm_vcpu *vcpu)
@@ -1444,13 +1467,8 @@ static void enter_lmode(struct kvm_vcpu *vcpu) (guest_tr_ar & ~AR_TYPE_MASK ) | AR_TYPE_BUSY_64_TSS); } - vcpu->arch.shadow_efer |=EFER_LMA ; - -find_msr_entry (to_vmx (vcpu),MSR_EFER )->data |=EFER_LMA |EFER_LME ; -vmcs_write32 (VM_ENTRY_CONTROLS , -vmcs_read32 (VM_ENTRY_CONTROLS ) - |VM_ENTRY_IA32E_MODE ); +vmx_set_efer (vcpu, vcpu->arch.shadow_efer); }static void exit_lmode (struct kvm_vcpu *vcpu)
@@ -1609,30 +1627,6 @@ static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)vmcs_writel (GUEST_CR4 , hw_cr4); } -static void vmx_set_efer (struct kvm_vcpu *vcpu,u64 efer) -{ -struct vcpu_vmx *vmx =to_vmx (vcpu); -struct kvm_msr_entry *msr =find_msr_entry (vmx,MSR_EFER ); - - vcpu->arch.shadow_efer = efer; -if (!msr) -return ; -if (efer &EFER_LMA ) { -vmcs_write32 (VM_ENTRY_CONTROLS , -vmcs_read32 (VM_ENTRY_CONTROLS ) | -VM_ENTRY_IA32E_MODE ); - msr->data = efer; - - }else { -vmcs_write32 (VM_ENTRY_CONTROLS , -vmcs_read32 (VM_ENTRY_CONTROLS ) & - ~VM_ENTRY_IA32E_MODE ); - - msr->data = efer & ~EFER_LME ; - } -setup_msrs (vmx); -} -static u64 vmx_get_segment_base (struct kvm_vcpu *vcpu,int seg) {struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
Signature · 1 line
1.6.0.6
PATCH 28/30 KVM: is_long_mode() should check for EFER.LMA
In reply to Avi KivityFrom: Amit Shah <[email protected]>
is_long_mode currently checks the LongModeEnable bit in EFER instead of the LongModeActive bit. This is wrong, but we survived this till now since it wasn't triggered. This breaks guests that go from long mode to compatibility mode.
This is noticed on a solaris guest and fixes bug #1842160
--- arch/x86/kvm/mmu.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/mmu.h +1 -1
@@ -54,7 +54,7 @@ static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)static inline int is_long_mode (struct kvm_vcpu *vcpu) {#ifdef CONFIG_X86_64 -return vcpu->arch.shadow_efer &EFER_LME ; +return vcpu->arch.shadow_efer &EFER_LMA ;#else return 0 ;#endif
Signature · 1 line
1.6.0.6
PATCH 29/30 KVM: fix sparse warnings: context imbalance
In reply to Avi KivityFrom: Hannes Eder <[email protected]>
Impact: Attribute function with __acquires(...) resp. __releases(...).
Fix this sparse warnings:
arch/x86/kvm/i8259.c:34:13: warning: context imbalance in 'pic_lock' - wrong count at exit arch/x86/kvm/i8259.c:39:13: warning: context imbalance in 'pic_unlock' - unexpected unlock
--- arch/x86/kvm/i8259.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kvm/i8259.c +2 -0
@@ -32,11 +32,13 @@#include <linux/kvm_host.h> static void pic_lock (struct kvm_pic *s) + __acquires(&s->lock) {spin_lock (&s->lock); }static void pic_unlock (struct kvm_pic *s) + __releases(&s->lock) {struct kvm *kvm = s->kvm;unsigned acks = s->pending_acks;
Signature · 1 line
1.6.0.6
PATCH 30/30 KVM: fix sparse warnings: Should it be static?
In reply to Avi KivityFrom: Hannes Eder <[email protected]>
Impact: Make symbols static.
Fix this sparse warnings:
arch/x86/kvm/mmu.c:992:5: warning: symbol 'mmu_pages_add' was not declared. Should it be static? arch/x86/kvm/mmu.c:1124:5: warning: symbol 'mmu_pages_next' was not declared. Should it be static? arch/x86/kvm/mmu.c:1144:6: warning: symbol 'mmu_pages_clear_parents' was not declared. Should it be static? arch/x86/kvm/x86.c:2037:5: warning: symbol 'kvm_read_guest_virt' was not declared. Should it be static? arch/x86/kvm/x86.c:2067:5: warning: symbol 'kvm_write_guest_virt' was not declared. Should it be static? virt/kvm/irq_comm.c:220:5: warning: symbol 'setup_routing_entry' was not declared. Should it be static?
--- arch/x86/kvm/mmu.c | 11 ++++++----- arch/x86/kvm/x86.c | 8 ++++---- virt/kvm/irq_comm.c | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-)
arch/x86/kvm/mmu.c +6 -5
@@ -989,8 +989,8 @@ struct kvm_mmu_pages { idx <512 ; \ idx = find_next_bit(bitmap, 512, idx+1)) -int mmu_pages_add (struct kvm_mmu_pages *pvec,struct kvm_mmu_page *sp, -int idx) +static int mmu_pages_add (struct kvm_mmu_pages *pvec,struct kvm_mmu_page *sp, +int idx) {int i;
@@ -1121,8 +1121,9 @@ struct mmu_page_path { i < pvec.nr && ({ sp = pvec.page[i].sp;1 ;}); \ i = mmu_pages_next(&pvec, &parents, i)) -int mmu_pages_next (struct kvm_mmu_pages *pvec,struct mmu_page_path *parents, -int i) +static int mmu_pages_next (struct kvm_mmu_pages *pvec, +struct mmu_page_path *parents, +int i) {int n;
@@ -1141,7 +1142,7 @@ int mmu_pages_next(struct kvm_mmu_pages *pvec, struct mmu_page_path *parents,return n; } -void mmu_pages_clear_parents (struct mmu_page_path *parents) +static void mmu_pages_clear_parents (struct mmu_page_path *parents) {struct kvm_mmu_page *sp;unsigned int level =0 ;
arch/x86/kvm/x86.c +4 -4
@@ -2043,8 +2043,8 @@ static struct kvm_io_device *vcpu_find_mmio_dev(struct kvm_vcpu *vcpu,return dev; } -int kvm_read_guest_virt (gva_t addr,void *val,unsigned int bytes, -struct kvm_vcpu *vcpu) +static int kvm_read_guest_virt (gva_t addr,void *val,unsigned int bytes, +struct kvm_vcpu *vcpu) {void *data = val;int r =X86EMUL_CONTINUE ;
@@ -2073,8 +2073,8 @@ out:return r; } -int kvm_write_guest_virt (gva_t addr,void *val,unsigned int bytes, -struct kvm_vcpu *vcpu) +static int kvm_write_guest_virt (gva_t addr,void *val,unsigned int bytes, +struct kvm_vcpu *vcpu) {void *data = val;int r =X86EMUL_CONTINUE ;
virt/kvm/irq_comm.c +2 -2
@@ -233,8 +233,8 @@ void kvm_free_irq_routing(struct kvm *kvm)__kvm_free_irq_routing (&kvm->irq_routing); } -int setup_routing_entry (struct kvm_kernel_irq_routing_entry *e, -const struct kvm_irq_routing_entry *ue) +static int setup_routing_entry (struct kvm_kernel_irq_routing_entry *e, +const struct kvm_irq_routing_entry *ue) {int r = -EINVAL ;int delta;
Signature · 1 line
1.6.0.6