KVM Updates for 2.6.28 merge window (part 3 of 3)
cover KVM Updates for 2.6.28 merge window (part 3 of 3)
Here is the third and last batch of the KVM updates for the 2.6.28 merge window.
Linux 2.6.28 KVM will introduce support for pci device assignment and will improve overall emulation accuracy.
Amit Shah (1):
KVM: Device Assignment: Free device structures if IRQ allocation
fails
Avi Kivity (3):
KVM: Add statistics for guest irq injections
KVM: x86 emulator: fix jmp r/m64 instruction
MAINTAINERS: Update Avi Kivity's email address
Ben-Ami Yassour (1):
KVM: Device Assignment with VT-d
Guillaume Thouvenin (3):
KVM: x86 emulator: Add DstAcc operand type
KVM: x86 emulator: Add cmp al, imm and cmp ax, imm instructions
(ocodes 3c, 3d)
KVM: x86 emulator: Use DstAcc for 'and'
Harvey Harrison (1):
KVM: x86.c make kvm_load_realmode_segment static
Hollis Blanchard (1):
KVM: ppc: kvmppc_44x_shadow_release() does not require mmap_sem to be
locked
Jan Kiszka (1):
KVM: VMX: Cleanup stalled INTR_INFO read
Joerg Roedel (1):
add MAINTAINERS entry for the KVM AMD module
Kay, Allen M (1):
VT-d: Changes to support KVM
Marcelo Tosatti (4):
KVM: x86: do not execute halted vcpus
KVM: x86: unhalt vcpu0 on reset
KVM: opencode gfn_to_page in kvm_vm_fault
KVM: switch to get_user_pages_fast
Mohammed Gamal (3):
KVM: x86 emulator: Add std and cld instructions (opcodes 0xfc-0xfd)
KVM: x86 emulator: Add in/out instructions (opcodes 0xe4-0xe7,
0xec-0xef)
KVM: x86 emulator: Add call near absolute instruction (opcode 0xff/2)
Sheng Yang (4):
KVM: MMU: Modify kvm_shadow_walk.entry to accept u64 addr
x86: Move VMX MSRs to msr-index.h
KVM: VMX: Rename IA32_FEATURE_CONTROL bits
x86: Move FEATURE_CONTROL bits to msr-index.h
Xiantao Zhang (1):
KVM: ia64: Implement kvm_arch_vcpu_ioctl_{set,get}_mpstate
MAINTAINERS | 9 +-
arch/ia64/kvm/kvm-ia64.c | 37 ++++-
arch/powerpc/kvm/44x_tlb.c | 8 -
arch/x86/kvm/Makefile | 3 +
arch/x86/kvm/i8254.c | 5 +-
arch/x86/kvm/lapic.c | 16 +--
arch/x86/kvm/mmu.c | 33 ++---
arch/x86/kvm/paging_tmpl.h | 12 +-
arch/x86/kvm/svm.c | 1 +
arch/x86/kvm/vmx.c | 26 ++--
arch/x86/kvm/vmx.h | 18 --
arch/x86/kvm/vtd.c | 198 ++++++++++++++++++++++++
arch/x86/kvm/x86.c | 215 +++++++++++++++-----------
arch/x86/kvm/x86_emulate.c | 132 +++++++++++-----
drivers/pci/dmar.c | 4 +-
drivers/pci/intel-iommu.c | 116 +++++++++++++-
drivers/pci/iova.c | 2 +-
include/asm-x86/kvm_host.h | 24 +---
include/asm-x86/msr-index.h | 19 +++
{drivers/pci => include/linux}/intel-iommu.h | 11 ++
{drivers/pci => include/linux}/iova.h | 0
include/linux/kvm.h | 3 +
include/linux/kvm_host.h | 53 +++++++
virt/kvm/kvm_main.c | 48 ++++--
24 files changed, 726 insertions(+), 267 deletions(-)
create mode 100644 arch/x86/kvm/vtd.c
rename {drivers/pci => include/linux}/intel-iommu.h (94%)
rename {drivers/pci => include/linux}/iova.h (100%)PATCH 1/25 KVM: x86 emulator: Add std and cld instructions (opcodes 0xfc-0xfd)
From: Mohammed Gamal <[email protected]>
This adds the std and cld instructions to the emulator.
Encountered while running the BIOS with invalid guest state emulation enabled.
--- arch/x86/kvm/x86_emulate.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
arch/x86/kvm/x86_emulate.c +9 -1
@@ -187,7 +187,7 @@ static u16 opcode_table[256] = { ImplicitOps, ImplicitOps, Group | Group3_Byte, Group | Group3,/* 0xF8 - 0xFF */ ImplicitOps,0 , ImplicitOps, ImplicitOps, - 0, 0, Group | Group4, Group | Group5, + ImplicitOps, ImplicitOps, Group | Group4, Group | Group5, }; static u16 twobyte_table[256] = {
@@ -1762,6 +1762,14 @@ special_insn: ctxt->eflags |=X86_EFLAGS_IF ; c->dst.type =OP_NONE ;/* Disable writeback. */ break ; +case 0xfc :/* cld */ + ctxt->eflags &= ~EFLG_DF ; + c->dst.type =OP_NONE ;/* Disable writeback. */ +break ; +case 0xfd :/* std */ + ctxt->eflags |=EFLG_DF ; + c->dst.type =OP_NONE ;/* Disable writeback. */ +break ; case 0xfe ... 0xff: /* Grp4/Grp5 */ rc =emulate_grp45 (ctxt, ops);if (rc !=0 )
Signature · 1 line
1.6.0.1
PATCH 2/25 KVM: ia64: Implement kvm_arch_vcpu_ioctl_{set,get}_mpstate
In reply to Avi KivityFrom: Xiantao Zhang <[email protected]>
Two ioctl arch functions are added to set vcpu's smp state.
--- arch/ia64/kvm/kvm-ia64.c | 37 +++++++++++++++++++++++++++++++++++-- 1 files changed, 35 insertions(+), 2 deletions(-)
arch/ia64/kvm/kvm-ia64.c +35 -2
@@ -179,6 +179,7 @@ int kvm_dev_ioctl_check_extension(long ext)switch (ext) {case KVM_CAP_IRQCHIP :case KVM_CAP_USER_MEMORY : +case KVM_CAP_MP_STATE : r =1 ;break ;
@@ -1789,11 +1790,43 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) { -return -EINVAL ; +vcpu_load (vcpu); + mp_state->mp_state = vcpu->arch.mp_state; +vcpu_put (vcpu); +return 0 ; +} + +static int vcpu_reset (struct kvm_vcpu *vcpu) +{ +int r; +long psr; +local_irq_save (psr); + r =kvm_insert_vmm_mapping (vcpu); +if (r) + goto fail; + + vcpu->arch.launched =0 ; +kvm_arch_vcpu_uninit (vcpu); + r =kvm_arch_vcpu_init (vcpu); +if (r) + goto fail; + +kvm_purge_vmm_mapping (vcpu); + r =0 ; +fail: +local_irq_restore (psr); +return r; }int kvm_arch_vcpu_ioctl_set_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) { -return -EINVAL ; +int r =0 ; + +vcpu_load (vcpu); + vcpu->arch.mp_state = mp_state->mp_state; +if (vcpu->arch.mp_state ==KVM_MP_STATE_UNINITIALIZED ) + r =vcpu_reset (vcpu); +vcpu_put (vcpu); +return r; }
Signature · 1 line
1.6.0.1
PATCH 3/25 KVM: MMU: Modify kvm_shadow_walk.entry to accept u64 addr
In reply to Avi KivityFrom: Sheng Yang <[email protected]>
EPT is 4 level by default in 32pae(48 bits), but the addr parameter of kvm_shadow_walk->entry() only accept unsigned long as virtual address, which is 32bit in 32pae. This result in SHADOW_PT_INDEX() overflow when try to fetch level 4 index.
Fix it by extend kvm_shadow_walk->entry() to accept 64bit addr in parameter.
--- arch/x86/kvm/mmu.c | 10 +++++----- arch/x86/kvm/paging_tmpl.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-)
arch/x86/kvm/mmu.c +5 -5
@@ -144,7 +144,7 @@ struct kvm_rmap_desc {struct kvm_shadow_walk {int (*entry)(struct kvm_shadow_walk *walk,struct kvm_vcpu *vcpu, -gva_t addr,u64 *spte,int level); +u64 addr,u64 *spte,int level); };static struct kmem_cache *pte_chain_cache;
@@ -941,7 +941,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, }static int walk_shadow (struct kvm_shadow_walk *walker, -struct kvm_vcpu *vcpu,gva_t addr) +struct kvm_vcpu *vcpu,u64 addr) {hpa_t shadow_addr;int level;
@@ -1270,7 +1270,7 @@ struct direct_shadow_walk {static int direct_map_entry (struct kvm_shadow_walk *_walk,struct kvm_vcpu *vcpu, -gva_t addr,u64 *sptep,int level) +u64 addr,u64 *sptep,int level) {struct direct_shadow_walk *walk = container_of(_walk, struct direct_shadow_walk, walker);
@@ -1289,7 +1289,7 @@ static int direct_map_entry(struct kvm_shadow_walk *_walk,if (*sptep == shadow_trap_nonpresent_pte) { pseudo_gfn = (addr &PT64_DIR_BASE_ADDR_MASK ) >>PAGE_SHIFT ; - sp =kvm_mmu_get_page (vcpu, pseudo_gfn, addr, level -1 , + sp =kvm_mmu_get_page (vcpu, pseudo_gfn, (gva_t )addr, level -1 ,1 ,ACC_ALL , sptep);if (!sp) {pgprintk ("nonpaging_map: ENOMEM\n" );
@@ -1317,7 +1317,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write, .pt_write = 0, }; - r =walk_shadow (&walker.walker, vcpu, (gva_t )gfn <<PAGE_SHIFT ); + r =walk_shadow (&walker.walker, vcpu, gfn <<PAGE_SHIFT );if (r <0 )return r;return walker.pt_write;
arch/x86/kvm/paging_tmpl.h +2 -2
@@ -286,7 +286,7 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page,* Fetch a shadow pte for a specific level in the paging hierarchy. */ static int FNAME (shadow_walk_entry )(struct kvm_shadow_walk *_sw, -struct kvm_vcpu *vcpu,gva_t addr, +struct kvm_vcpu *vcpu,u64 addr,u64 *sptep,int level) { struct shadow_walker *sw =
@@ -326,7 +326,7 @@ static int FNAME(shadow_walk_entry)(struct kvm_shadow_walk *_sw, metaphysical =0 ; table_gfn = gw->table_gfn[level -2 ]; } - shadow_page =kvm_mmu_get_page (vcpu, table_gfn, addr, level-1 , + shadow_page =kvm_mmu_get_page (vcpu, table_gfn, (gva_t )addr, level-1 , metaphysical, access, sptep);if (!metaphysical) { r = kvm_read_guest_atomic(vcpu->kvm, gw->pte_gpa[level - 2],
Signature · 1 line
1.6.0.1
PATCH 4/25 KVM: Add statistics for guest irq injections
In reply to Avi KivityFrom: Avi Kivity <[email protected]>
These can help show whether a guest is making progress or not.
--- arch/x86/kvm/svm.c | 1 + arch/x86/kvm/vmx.c | 1 + arch/x86/kvm/x86.c | 1 + include/asm-x86/kvm_host.h | 1 + 4 files changed, 4 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +1 -0
@@ -1519,6 +1519,7 @@ static inline void svm_inject_irq(struct vcpu_svm *svm, int irq)KVMTRACE_1D (INJ_VIRQ , &svm->vcpu, (u32 )irq, handler); + ++svm->vcpu.stat.irq_injections; control = &svm->vmcb->control; control->int_vector = irq; control->int_ctl &= ~V_INTR_PRIO_MASK ;
arch/x86/kvm/vmx.c +1 -0
@@ -2341,6 +2341,7 @@ static void vmx_inject_irq(struct kvm_vcpu *vcpu, int irq)KVMTRACE_1D (INJ_VIRQ , vcpu, (u32 )irq, handler); + ++vcpu->stat.irq_injections;if (vcpu->arch.rmode.active) { vmx->rmode.irq.pending = true; vmx->rmode.irq.vector = irq;
arch/x86/kvm/x86.c +1 -0
@@ -92,6 +92,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { { "fpu_reload", VCPU_STAT(fpu_reload) }, { "insn_emulation", VCPU_STAT(insn_emulation) }, { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) }, + { "irq_injections", VCPU_STAT(irq_injections) }, { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) }, { "mmu_pte_write", VM_STAT(mmu_pte_write) }, { "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
include/asm-x86/kvm_host.h +1 -0
@@ -413,6 +413,7 @@ struct kvm_vcpu_stat {u32 insn_emulation;u32 insn_emulation_fail;u32 hypercalls; +u32 irq_injections; };struct descriptor_table {
Signature · 1 line
1.6.0.1
PATCH 5/25 KVM: x86 emulator: Add in/out instructions (opcodes 0xe4-0xe7, 0xec-0xef)
In reply to Avi KivityFrom: Mohammed Gamal <[email protected]>
The patch adds in/out instructions to the x86 emulator.
The instruction was encountered while running the BIOS while using the invalid guest state emulation patch.
--- arch/x86/kvm/x86_emulate.c | 35 +++++++++++++++++++++++++++++++++-- 1 files changed, 33 insertions(+), 2 deletions(-)
arch/x86/kvm/x86_emulate.c +33 -2
@@ -177,11 +177,14 @@ static u16 opcode_table[256] = {/* 0xD8 - 0xDF */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* 0xE0 - 0xE7 */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , +0 ,0 ,0 ,0 , + SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, + SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps,/* 0xE8 - 0xEF */ ImplicitOps | Stack, SrcImm | ImplicitOps, ImplicitOps, SrcImmByte | ImplicitOps, -0 ,0 ,0 ,0 , + SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, + SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps,/* 0xF0 - 0xF7 */ 0 ,0 ,0 ,0 , ImplicitOps, ImplicitOps, Group | Group3_Byte, Group | Group3,
@@ -1259,6 +1262,8 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)u64 msr_data;unsigned long saved_eip =0 ;struct decode_cache *c = &ctxt->decode; +unsigned int port; +int io_dir_in;int rc =0 ;/* Shadow copy of register state. Committed on successful emulation.
@@ -1687,6 +1692,16 @@ special_insn: c->src.val = c->regs[VCPU_REGS_RCX ];emulate_grp2 (ctxt);break ; +case 0xe4 :/* inb */ +case 0xe5 :/* in */ + port =insn_fetch (u8,1 , c->eip); + io_dir_in =1 ; + goto do_io; +case 0xe6 :/* outb */ +case 0xe7 :/* out */ + port =insn_fetch (u8,1 , c->eip); + io_dir_in =0 ; + goto do_io;case 0xe8 :/* call (near) */ {long int rel;switch (c->op_bytes) {
@@ -1737,6 +1752,22 @@ special_insn:jmp_rel (c, c->src.val); c->dst.type =OP_NONE ;/* Disable writeback. */ break ; +case 0xec :/* in al,dx */ +case 0xed :/* in (e/r)ax,dx */ + port = c->regs[VCPU_REGS_RDX ]; + io_dir_in =1 ; + goto do_io; +case 0xee :/* out al,dx */ +case 0xef :/* out (e/r)ax,dx */ + port = c->regs[VCPU_REGS_RDX ]; + io_dir_in =0 ; + do_io:if (kvm_emulate_pio (ctxt->vcpu,NULL , io_dir_in, + (c->d & ByteOp) ?1 : c->op_bytes, + port) !=0 ) { + c->eip = saved_eip; + goto cannot_emulate; + } +return 0 ;case 0xf4 :/* hlt */ ctxt->vcpu->arch.halt_request =1 ;break ;
Signature · 1 line
1.6.0.1
PATCH 6/25 KVM: x86: do not execute halted vcpus
In reply to Avi KivityFrom: Marcelo Tosatti <[email protected]>
Offline or uninitialized vcpu's can be executed if requested to perform userspace work.
Follow Avi's suggestion to handle halted vcpu's in the main loop, simplifying kvm_emulate_halt(). Introduce a new vcpu->requests bit to indicate events that promote state from halted to running.
Also standardize vcpu wake sites.
--- arch/x86/kvm/i8254.c | 5 +- arch/x86/kvm/lapic.c | 16 ++------ arch/x86/kvm/x86.c | 100 +++++++++++++++++++++++++--------------------- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 10 ++-- 5 files changed, 67 insertions(+), 65 deletions(-)
arch/x86/kvm/i8254.c +2 -3
@@ -200,10 +200,9 @@ static int __pit_timer_fn(struct kvm_kpit_state *ps)if (!atomic_inc_and_test (&pt->pending))set_bit (KVM_REQ_PENDING_TIMER , &vcpu0->requests); -if (vcpu0 &&waitqueue_active (&vcpu0->wq)) { - vcpu0->arch.mp_state =KVM_MP_STATE_RUNNABLE ; + +if (vcpu0 &&waitqueue_active (&vcpu0->wq))wake_up_interruptible (&vcpu0->wq); - } pt->timer.expires =ktime_add_ns (pt->timer.expires, pt->period); pt->scheduled =ktime_to_ns (pt->timer.expires);
arch/x86/kvm/lapic.c +4 -12
@@ -339,13 +339,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, }else apic_clear_vector (vector, apic->regs +APIC_TMR ); -if (vcpu->arch.mp_state ==KVM_MP_STATE_RUNNABLE ) -kvm_vcpu_kick (vcpu); -else if (vcpu->arch.mp_state ==KVM_MP_STATE_HALTED ) { - vcpu->arch.mp_state =KVM_MP_STATE_RUNNABLE ; -if (waitqueue_active (&vcpu->wq)) -wake_up_interruptible (&vcpu->wq); - } +kvm_vcpu_kick (vcpu); result = (orig_irr ==0 );break ;
@@ -384,8 +378,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,if (vcpu->arch.mp_state ==KVM_MP_STATE_INIT_RECEIVED ) { vcpu->arch.sipi_vector = vector; vcpu->arch.mp_state =KVM_MP_STATE_SIPI_RECEIVED ; -if (waitqueue_active (&vcpu->wq)) -wake_up_interruptible (&vcpu->wq); +kvm_vcpu_kick (vcpu); }break ;
@@ -950,10 +943,9 @@ static int __apic_timer_fn(struct kvm_lapic *apic)if (!atomic_inc_and_test (&apic->timer.pending))set_bit (KVM_REQ_PENDING_TIMER , &apic->vcpu->requests); -if (waitqueue_active (q)) { - apic->vcpu->arch.mp_state =KVM_MP_STATE_RUNNABLE ; +if (waitqueue_active (q))wake_up_interruptible (q); - } +if (apic_lvtt_period (apic)) { result =1 ; apic->timer.dev.expires = ktime_add_ns(
arch/x86/kvm/x86.c +55 -45
144 lines not on this page · raw message
include/linux/kvm_host.h +1 -0
@@ -34,6 +34,7 @@#define KVM_REQ_MMU_RELOAD 3#define KVM_REQ_TRIPLE_FAULT 4#define KVM_REQ_PENDING_TIMER 5 +#define KVM_REQ_UNHALT 6struct kvm_vcpu ;extern struct kmem_cache *kvm_vcpu_cache;
virt/kvm/kvm_main.c +5 -5
@@ -980,12 +980,12 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)for (;;) {prepare_to_wait (&vcpu->wq, &wait,TASK_INTERRUPTIBLE ); -if (kvm_cpu_has_interrupt (vcpu)) -break ; -if (kvm_cpu_has_pending_timer (vcpu)) -break ; -if (kvm_arch_vcpu_runnable (vcpu)) +if (kvm_cpu_has_interrupt (vcpu) || +kvm_cpu_has_pending_timer (vcpu) || +kvm_arch_vcpu_runnable (vcpu)) { +set_bit (KVM_REQ_UNHALT , &vcpu->requests);break ; + }if (signal_pending (current))break ;
Signature · 1 line
1.6.0.1
PATCH 7/25 KVM: x86 emulator: Add call near absolute instruction (opcode 0xff/2)
In reply to Avi KivityFrom: Mohammed Gamal <[email protected]>
Add call near absolute instruction.
--- arch/x86/kvm/x86_emulate.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
arch/x86/kvm/x86_emulate.c +10 -1
@@ -286,7 +286,8 @@ static u16 group_table[] = { ByteOp | DstMem | SrcNone | ModRM, ByteOp | DstMem | SrcNone | ModRM, 0, 0, 0, 0, 0, 0, [Group5*8 ] = - DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM,0 ,0 , + DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM, + SrcMem | ModRM | Stack,0 , SrcMem | ModRM, 0, SrcMem | ModRM | Stack, 0, [Group7*8 ] = 0, 0, ModRM | SrcMem, ModRM | SrcMem,
@@ -1162,6 +1163,14 @@ static inline int emulate_grp45(struct x86_emulate_ctxt *ctxt,case 1 :/* dec */ emulate_1op ("dec" , c->dst, ctxt->eflags);break ; +case 2 :/* call near abs */ { +long int old_eip; + old_eip = c->eip; + c->eip = c->src.val; + c->src.val = old_eip; +emulate_push (ctxt); +break ; + }case 4 :/* jmp abs */ c->eip = c->src.val;break ;
Signature · 1 line
1.6.0.1
PATCH 8/25 KVM: x86: unhalt vcpu0 on reset
In reply to Avi KivityFrom: Marcelo Tosatti <[email protected]>
Since "KVM: x86: do not execute halted vcpus", HLT by vcpu0 before system reset by the IO thread will hang the guest.
Mark vcpu as runnable in such case.
--- arch/x86/kvm/x86.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +6 -0
@@ -3959,6 +3959,12 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,kvm_set_segment (vcpu, &sregs->tr,VCPU_SREG_TR );kvm_set_segment (vcpu, &sregs->ldt,VCPU_SREG_LDTR ); +/* Older userspace won't unhalt the vcpu on reset. */ +if (vcpu->vcpu_id ==0 &&kvm_rip_read (vcpu) ==0xfff0 && + sregs->cs.selector ==0xf000 && sregs->cs.base ==0xffff0000 && + !(vcpu->arch.cr0 &X86_CR0_PE )) + vcpu->arch.mp_state =KVM_MP_STATE_RUNNABLE ; +vcpu_put (vcpu);return 0 ;
Signature · 1 line
1.6.0.1
PATCH 9/25 KVM: ppc: kvmppc_44x_shadow_release() does not require mmap_sem to be locked
In reply to Avi KivityFrom: Hollis Blanchard <[email protected]>
And it gets in the way of get_user_pages_fast().
--- arch/powerpc/kvm/44x_tlb.c | 8 +------- 1 files changed, 1 insertions(+), 7 deletions(-)
arch/powerpc/kvm/44x_tlb.c +1 -7
@@ -110,7 +110,6 @@ static int kvmppc_44x_tlbe_is_writable(struct tlbe *tlbe)return tlbe->word2 & (PPC44x_TLB_SW|PPC44x_TLB_UW); } -/* Must be called with mmap_sem locked for writing. */ static void kvmppc_44x_shadow_release (struct kvm_vcpu *vcpu,unsigned int index) {
@@ -150,17 +149,16 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gfn_t gfn, u64 asid,/* Get reference to new page. */ down_read (¤t->mm->mmap_sem); new_page =gfn_to_page (vcpu->kvm, gfn); +up_read (¤t->mm->mmap_sem);if (is_error_page (new_page)) {printk (KERN_ERR "Couldn't get guest page for gfn %lx!\n" , gfn);kvm_release_page_clean (new_page); -up_read (¤t->mm->mmap_sem);return ; } hpaddr =page_to_phys (new_page);/* Drop reference to old page. */ kvmppc_44x_shadow_release (vcpu, victim); -up_read (¤t->mm->mmap_sem); vcpu->arch.shadow_pages[victim] = new_page;
@@ -194,7 +192,6 @@ void kvmppc_mmu_invalidate(struct kvm_vcpu *vcpu, gva_t eaddr,int i;/* XXX Replace loop with fancy data structures. */ -down_write (¤t->mm->mmap_sem);for (i =0 ; i <= tlb_44x_hwater; i++) {struct tlbe *stlbe = &vcpu->arch.shadow_tlb[i];unsigned int tid;
@@ -219,7 +216,6 @@ void kvmppc_mmu_invalidate(struct kvm_vcpu *vcpu, gva_t eaddr, stlbe->tid, stlbe->word0, stlbe->word1, stlbe->word2, handler); } -up_write (¤t->mm->mmap_sem); }/* Invalidate all mappings on the privilege switch after PID has been changed.
@@ -231,7 +227,6 @@ void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode)if (vcpu->arch.swap_pid) {/* XXX Replace loop with fancy data structures. */ -down_write (¤t->mm->mmap_sem);for (i =0 ; i <= tlb_44x_hwater; i++) {struct tlbe *stlbe = &vcpu->arch.shadow_tlb[i];
@@ -243,7 +238,6 @@ void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode) stlbe->tid, stlbe->word0, stlbe->word1, stlbe->word2, handler); } -up_write (¤t->mm->mmap_sem); vcpu->arch.swap_pid =0 ; }
Signature · 1 line
1.6.0.1
PATCH 10/25 KVM: VMX: Cleanup stalled INTR_INFO read
In reply to Avi KivityFrom: Jan Kiszka <[email protected]>
Commit 1c0f4f5011829dac96347b5f84ba37c2252e1e08 left a useless access of VM_ENTRY_INTR_INFO_FIELD in vmx_intr_assist behind. Clean this up.
--- arch/x86/kvm/vmx.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx.c +0 -3
@@ -3135,11 +3135,8 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx)static void vmx_intr_assist (struct kvm_vcpu *vcpu) { -u32 intr_info_field; -update_tpr_threshold (vcpu); - intr_info_field =vmcs_read32 (VM_ENTRY_INTR_INFO_FIELD );if (cpu_has_virtual_nmis ()) {if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) {if (vmx_nmi_enabled (vcpu)) {
Signature · 1 line
1.6.0.1
PATCH 11/25 KVM: x86 emulator: fix jmp r/m64 instruction
In reply to Avi KivityFrom: Avi Kivity <[email protected]>
jmp r/m64 doesn't require the rex.w prefix to indicate the operand size is 64 bits. Set the Stack attribute (even though it doesn't involve the stack, really) to indicate this.
--- arch/x86/kvm/x86_emulate.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86_emulate.c +1 -1
@@ -288,7 +288,7 @@ static u16 group_table[] = { [Group5*8 ] = DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM, SrcMem | ModRM | Stack,0 , - SrcMem | ModRM, 0, SrcMem | ModRM | Stack, 0, + SrcMem | ModRM | Stack, 0, SrcMem | ModRM | Stack, 0, [Group7*8 ] =0 ,0 , ModRM | SrcMem, ModRM | SrcMem, SrcNone | ModRM | DstMem | Mov, 0,
Signature · 1 line
1.6.0.1
PATCH 12/25 add MAINTAINERS entry for the KVM AMD module
In reply to Avi KivityFrom: Joerg Roedel <[email protected]>
--- MAINTAINERS | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
MAINTAINERS +7 -0
@@ -2416,6 +2416,13 @@ L: [email protected] W: http://kvm.qumranet.com S: Supported +KERNEL VIRTUAL MACHINE (KVM) FOR AMD-V +P: Joerg Roedel +M: [email protected] +L: [email protected] +W: http://kvm.qumranet.com +S: Supported + KERNEL VIRTUAL MACHINE (KVM) FOR POWERPC P: Hollis Blanchard M: [email protected]
Signature · 1 line
1.6.0.1
PATCH 13/25 x86: Move VMX MSRs to msr-index.h
In reply to Avi KivityFrom: Sheng Yang <[email protected]>
They are hardware specific MSRs, and we would use them in virtualization feature detection later.
--- arch/x86/kvm/vmx.h | 15 --------------- include/asm-x86/msr-index.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 15 deletions(-)
arch/x86/kvm/vmx.h +0 -15
@@ -331,21 +331,6 @@ enum vmcs_field {#define AR_RESERVD_MASK 0xfffe0f00 -#define MSR_IA32_VMX_BASIC 0x480 -#define MSR_IA32_VMX_PINBASED_CTLS 0x481 -#define MSR_IA32_VMX_PROCBASED_CTLS 0x482 -#define MSR_IA32_VMX_EXIT_CTLS 0x483 -#define MSR_IA32_VMX_ENTRY_CTLS 0x484 -#define MSR_IA32_VMX_MISC 0x485 -#define MSR_IA32_VMX_CR0_FIXED0 0x486 -#define MSR_IA32_VMX_CR0_FIXED1 0x487 -#define MSR_IA32_VMX_CR4_FIXED0 0x488 -#define MSR_IA32_VMX_CR4_FIXED1 0x489 -#define MSR_IA32_VMX_VMCS_ENUM 0x48a -#define MSR_IA32_VMX_PROCBASED_CTLS2 0x48b -#define MSR_IA32_VMX_EPT_VPID_CAP 0x48c - -#define MSR_IA32_FEATURE_CONTROL 0x3a#define IA32_FEATURE_CONTROL_LOCKED_BIT 0x1#define IA32_FEATURE_CONTROL_VMXON_ENABLED_BIT 0x4
include/asm-x86/msr-index.h +16 -0
@@ -176,6 +176,7 @@#define MSR_IA32_TSC 0x00000010#define MSR_IA32_PLATFORM_ID 0x00000017#define MSR_IA32_EBL_CR_POWERON 0x0000002a +#define MSR_IA32_FEATURE_CONTROL 0x0000003a#define MSR_IA32_APICBASE 0x0000001b#define MSR_IA32_APICBASE_BSP (1<<8)
@@ -310,4 +311,19 @@/* Geode defined MSRs */ #define MSR_GEODE_BUSCONT_CONF0 0x00001900 +/* Intel VT MSRs */ +#define MSR_IA32_VMX_BASIC 0x00000480 +#define MSR_IA32_VMX_PINBASED_CTLS 0x00000481 +#define MSR_IA32_VMX_PROCBASED_CTLS 0x00000482 +#define MSR_IA32_VMX_EXIT_CTLS 0x00000483 +#define MSR_IA32_VMX_ENTRY_CTLS 0x00000484 +#define MSR_IA32_VMX_MISC 0x00000485 +#define MSR_IA32_VMX_CR0_FIXED0 0x00000486 +#define MSR_IA32_VMX_CR0_FIXED1 0x00000487 +#define MSR_IA32_VMX_CR4_FIXED0 0x00000488 +#define MSR_IA32_VMX_CR4_FIXED1 0x00000489 +#define MSR_IA32_VMX_VMCS_ENUM 0x0000048a +#define MSR_IA32_VMX_PROCBASED_CTLS2 0x0000048b +#define MSR_IA32_VMX_EPT_VPID_CAP 0x0000048c +#endif /* __ASM_MSR_INDEX_H */
Signature · 1 line
1.6.0.1
PATCH 14/25 KVM: VMX: Rename IA32_FEATURE_CONTROL bits
In reply to Avi KivityFrom: Sheng Yang <[email protected]>
--- arch/x86/kvm/vmx.c | 18 +++++++++--------- arch/x86/kvm/vmx.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-)
arch/x86/kvm/vmx.c +9 -9
@@ -1041,9 +1041,9 @@ static __init int vmx_disabled_by_bios(void)u64 msr;rdmsrl (MSR_IA32_FEATURE_CONTROL , msr); -return (msr & (IA32_FEATURE_CONTROL_LOCKED_BIT | -IA32_FEATURE_CONTROL_VMXON_ENABLED_BIT )) - ==IA32_FEATURE_CONTROL_LOCKED_BIT ; +return (msr & (FEATURE_CONTROL_LOCKED | +FEATURE_CONTROL_VMXON_ENABLED )) + ==FEATURE_CONTROL_LOCKED ;/* locked but not enabled */ }
@@ -1055,14 +1055,14 @@ static void hardware_enable(void *garbage)INIT_LIST_HEAD (&per_cpu (vcpus_on_cpu, cpu));rdmsrl (MSR_IA32_FEATURE_CONTROL , old); -if ((old & (IA32_FEATURE_CONTROL_LOCKED_BIT | -IA32_FEATURE_CONTROL_VMXON_ENABLED_BIT )) - != (IA32_FEATURE_CONTROL_LOCKED_BIT | -IA32_FEATURE_CONTROL_VMXON_ENABLED_BIT )) +if ((old & (FEATURE_CONTROL_LOCKED | +FEATURE_CONTROL_VMXON_ENABLED )) + != (FEATURE_CONTROL_LOCKED | +FEATURE_CONTROL_VMXON_ENABLED ))/* enable and lock */ wrmsrl (MSR_IA32_FEATURE_CONTROL , old | -IA32_FEATURE_CONTROL_LOCKED_BIT | -IA32_FEATURE_CONTROL_VMXON_ENABLED_BIT ); +FEATURE_CONTROL_LOCKED | +FEATURE_CONTROL_VMXON_ENABLED );write_cr4 (read_cr4 () |X86_CR4_VMXE );/* FIXME: not cpu hotplug safe */ asmvolatile (ASM_VMX_VMXON_RAX : : "a"(&phys_addr), "m"(phys_addr)
arch/x86/kvm/vmx.h +2 -2
@@ -331,8 +331,8 @@ enum vmcs_field {#define AR_RESERVD_MASK 0xfffe0f00 -#define IA32_FEATURE_CONTROL_LOCKED_BIT 0x1 -#define IA32_FEATURE_CONTROL_VMXON_ENABLED_BIT 0x4 +#define FEATURE_CONTROL_LOCKED (1<<0) +#define FEATURE_CONTROL_VMXON_ENABLED (1<<2)#define APIC_ACCESS_PAGE_PRIVATE_MEMSLOT 9#define IDENTITY_PAGETABLE_PRIVATE_MEMSLOT 10
Signature · 1 line
1.6.0.1
PATCH 15/25 x86: Move FEATURE_CONTROL bits to msr-index.h
In reply to Avi KivityFrom: Sheng Yang <[email protected]>
For MSR_IA32_FEATURE_CONTROL is already there.
--- arch/x86/kvm/vmx.h | 3 --- include/asm-x86/msr-index.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx.h +0 -3
@@ -331,9 +331,6 @@ enum vmcs_field {#define AR_RESERVD_MASK 0xfffe0f00 -#define FEATURE_CONTROL_LOCKED (1<<0) -#define FEATURE_CONTROL_VMXON_ENABLED (1<<2) -#define APIC_ACCESS_PAGE_PRIVATE_MEMSLOT 9#define IDENTITY_PAGETABLE_PRIVATE_MEMSLOT 10
include/asm-x86/msr-index.h +3 -0
@@ -178,6 +178,9 @@#define MSR_IA32_EBL_CR_POWERON 0x0000002a#define MSR_IA32_FEATURE_CONTROL 0x0000003a +#define FEATURE_CONTROL_LOCKED (1<<0) +#define FEATURE_CONTROL_VMXON_ENABLED (1<<2) +#define MSR_IA32_APICBASE 0x0000001b#define MSR_IA32_APICBASE_BSP (1<<8)#define MSR_IA32_APICBASE_ENABLE (1<<11)
Signature · 1 line
1.6.0.1
PATCH 16/25 KVM: x86 emulator: Add DstAcc operand type
In reply to Avi KivityFrom: Guillaume Thouvenin <[email protected]>
Add DstAcc operand type. That means that there are 4 bits now for DstMask.
"In the good old days cpus would have only one register that was able to
fully participate in arithmetic operations, typically called A for Accumulator. The x86 retains this tradition by having special, shorter encodings for the A register (like the cmp opcode), and even some instructions that only operate on A (like mul).
SrcAcc and DstAcc would accommodate these instructions by decoding A into the corresponding 'struct operand'."
-- Avi Kivity
--- arch/x86/kvm/x86_emulate.c | 50 +++++++++++++++++++++++++++++-------------- 1 files changed, 34 insertions(+), 16 deletions(-)
arch/x86/kvm/x86_emulate.c +34 -16
@@ -47,25 +47,26 @@#define ImplicitOps (1<<1)/* Implicit in opcode. No generic decode. */ #define DstReg (2<<1)/* Register operand. */ #define DstMem (3<<1)/* Memory operand. */ -#define DstMask (3<<1) +#define DstAcc (4<<1)/* Destination Accumulator */ +#define DstMask (7<<1)/* Source operand type. */ -#define SrcNone (0<<3)/* No source operand. */ -#define SrcImplicit (0<<3)/* Source operand is implicit in the opcode. */ -#define SrcReg (1<<3)/* Register operand. */ -#define SrcMem (2<<3)/* Memory operand. */ -#define SrcMem16 (3<<3)/* Memory operand (16-bit). */ -#define SrcMem32 (4<<3)/* Memory operand (32-bit). */ -#define SrcImm (5<<3)/* Immediate operand. */ -#define SrcImmByte (6<<3)/* 8-bit sign-extended immediate operand. */ -#define SrcMask (7<<3) +#define SrcNone (0<<4)/* No source operand. */ +#define SrcImplicit (0<<4)/* Source operand is implicit in the opcode. */ +#define SrcReg (1<<4)/* Register operand. */ +#define SrcMem (2<<4)/* Memory operand. */ +#define SrcMem16 (3<<4)/* Memory operand (16-bit). */ +#define SrcMem32 (4<<4)/* Memory operand (32-bit). */ +#define SrcImm (5<<4)/* Immediate operand. */ +#define SrcImmByte (6<<4)/* 8-bit sign-extended immediate operand. */ +#define SrcMask (7<<4)/* Generic ModRM decode. */ -#define ModRM (1<<6) +#define ModRM (1<<7)/* Destination is only written; never read. */ -#define Mov (1<<7) -#define BitOp (1<<8) -#define MemAbs (1<<9)/* Memory operand is absolute displacement */ -#define String (1<<10)/* String instruction (rep capable) */ -#define Stack (1<<11)/* Stack instruction (push/pop) */ +#define Mov (1<<8) +#define BitOp (1<<9) +#define MemAbs (1<<10)/* Memory operand is absolute displacement */ +#define String (1<<12)/* String instruction (rep capable) */ +#define Stack (1<<13)/* Stack instruction (push/pop) */ #define Group (1<<14)/* Bits 3:5 of modrm byte extend opcode */ #define GroupDual (1<<15)/* Alternate decoding of mod == 3 */ #define GroupMask 0xff/* Group number stored in bits 0:7 */
@@ -1060,6 +1061,23 @@ done_prefixes: } c->dst.type =OP_MEM ;break ; +case DstAcc: + c->dst.type =OP_REG ; + c->dst.bytes = c->op_bytes; + c->dst.ptr = &c->regs[VCPU_REGS_RAX ]; +switch (c->op_bytes) { +case 1 : + c->dst.val = *(u8 *)c->dst.ptr; +break ; +case 2 : + c->dst.val = *(u16 *)c->dst.ptr; +break ; +case 4 : + c->dst.val = *(u32 *)c->dst.ptr; +break ; + } + c->dst.orig_val = c->dst.val; +break ; }if (c->rip_relative)
Signature · 1 line
1.6.0.1
PATCH 17/25 KVM: x86 emulator: Add cmp al, imm and cmp ax, imm instructions (ocodes 3c, 3d)
In reply to Avi KivityFrom: Guillaume Thouvenin <[email protected]>
Add decode entries for these opcodes; execution is already implemented.
--- arch/x86/kvm/x86_emulate.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kvm/x86_emulate.c +2 -1
@@ -108,7 +108,8 @@ static u16 opcode_table[256] = {/* 0x38 - 0x3F */ ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM, -0 ,0 ,0 ,0 , + ByteOp | DstAcc | SrcImm, DstAcc | SrcImm, +0 ,0 ,/* 0x40 - 0x47 */ DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, /* 0x48 - 0x4F */
Signature · 1 line
1.6.0.1
PATCH 18/25 KVM: x86 emulator: Use DstAcc for 'and'
In reply to Avi KivityFrom: Guillaume Thouvenin <[email protected]>
For instruction 'and al,imm' we use DstAcc instead of doing the emulation directly into the instruction's opcode.
--- arch/x86/kvm/x86_emulate.c | 21 ++------------------- 1 files changed, 2 insertions(+), 19 deletions(-)
arch/x86/kvm/x86_emulate.c +2 -19
@@ -96,7 +96,7 @@ static u16 opcode_table[256] = {/* 0x20 - 0x27 */ ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM, - SrcImmByte, SrcImm,0 ,0 , + DstAcc | SrcImmByte, DstAcc | SrcImm,0 ,0 ,/* 0x28 - 0x2F */ ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
@@ -1392,27 +1392,10 @@ special_insn: sbb:/* sbb */ emulate_2op_SrcV ("sbb" , c->src, c->dst, ctxt->eflags);break ; - case 0x20 ... 0x23: + case 0x20 ... 0x25: and:/* and */ emulate_2op_SrcV ("and" , c->src, c->dst, ctxt->eflags);break ; -case 0x24 :/* and al imm8 */ - c->dst.type =OP_REG ; - c->dst.ptr = &c->regs[VCPU_REGS_RAX ]; - c->dst.val = *(u8 *)c->dst.ptr; - c->dst.bytes =1 ; - c->dst.orig_val = c->dst.val; - goto and; -case 0x25 :/* and ax imm16, or eax imm32 */ - c->dst.type =OP_REG ; - c->dst.bytes = c->op_bytes; - c->dst.ptr = &c->regs[VCPU_REGS_RAX ]; -if (c->op_bytes ==2 ) - c->dst.val = *(u16 *)c->dst.ptr; -else - c->dst.val = *(u32 *)c->dst.ptr; - c->dst.orig_val = c->dst.val; - goto and; case 0x28 ... 0x2d: sub:/* sub */ emulate_2op_SrcV ("sub" , c->src, c->dst, ctxt->eflags);
Signature · 1 line
1.6.0.1
PATCH 19/25 VT-d: Changes to support KVM
In reply to Avi KivityFrom: Kay, Allen M <[email protected]>
This patch extends the VT-d driver to support KVM
[Ben: fixed memory pinning]
---
drivers/pci/dmar.c | 4 +-
drivers/pci/intel-iommu.c | 116 +++++++++++++++++++++++++-
drivers/pci/iova.c | 2 +-
{drivers/pci => include/linux}/intel-iommu.h | 11 +++
{drivers/pci => include/linux}/iova.h | 0
5 files changed, 126 insertions(+), 7 deletions(-)
rename {drivers/pci => include/linux}/intel-iommu.h (94%)
rename {drivers/pci => include/linux}/iova.h (100%)drivers/pci/dmar.c +2 -2
@@ -26,8 +26,8 @@#include <linux/pci.h> #include <linux/dmar.h> -#include "iova.h" -#include "intel-iommu.h" +#include <linux/iova.h> +#include <linux/intel-iommu.h> #undef PREFIX#define PREFIX "DMAR:"
drivers/pci/intel-iommu.c +112 -4
137 lines not on this page · raw message
drivers/pci/iova.c +1 -1
@@ -7,7 +7,7 @@* Author: Anil S Keshavamurthy <[email protected]> */ -#include "iova.h" +#include <linux/iova.h> void init_iova_domain (struct iova_domain *iovad,unsigned long pfn_32bit)
include/linux/intel-iommu.h renamed from drivers/pci/intel-iommu.h +11 -0
@@ -341,4 +341,15 @@ static inline void iommu_prepare_gfx_mapping(void) }#endif /* !CONFIG_DMAR_GFX_WA */ +void intel_iommu_domain_exit (struct dmar_domain *domain); +struct dmar_domain *intel_iommu_domain_alloc (struct pci_dev *pdev); +int intel_iommu_context_mapping (struct dmar_domain *domain, +struct pci_dev *pdev); +int intel_iommu_page_mapping (struct dmar_domain *domain,dma_addr_t iova, +u64 hpa,size_t size,int prot); +void intel_iommu_detach_dev (struct dmar_domain *domain,u8 bus,u8 devfn); +struct dmar_domain *intel_iommu_find_domain (struct pci_dev *pdev); +int intel_iommu_found (void ); +u64 intel_iommu_iova_to_pfn (struct dmar_domain *domain,u64 iova); +#endif
include/linux/iova.h renamed from drivers/pci/iova.h +0 -0
Signature · 1 line
1.6.0.1
PATCH 20/25 KVM: Device Assignment with VT-d
In reply to Avi KivityFrom: Ben-Ami Yassour <[email protected]>
Based on a patch by: Kay, Allen M <[email protected]>
This patch enables PCI device assignment based on VT-d support. When a device is assigned to the guest, the guest memory is pinned and the mapping is updated in the VT-d IOMMU.
[Amit: Expose KVM_CAP_IOMMU so we can check if an IOMMU is present and also control enable/disable from userspace]
--- arch/x86/kvm/Makefile | 3 + arch/x86/kvm/vtd.c | 198 ++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kvm/x86.c | 14 +++ include/asm-x86/kvm_host.h | 23 +----- include/linux/kvm.h | 3 + include/linux/kvm_host.h | 52 ++++++++++++ virt/kvm/kvm_main.c | 9 ++- 7 files changed, 281 insertions(+), 21 deletions(-) create mode 100644 arch/x86/kvm/vtd.c
arch/x86/kvm/Makefile +3 -0
@@ -12,6 +12,9 @@ EXTRA_CFLAGS += -Ivirt/kvm -Iarch/x86/kvm kvm-objs := $(common-objs) x86.o mmu.o x86_emulate.o i8259.o irq.o lapic.o \ i8254.o +ifeq ($(CONFIG_DMAR),y) +kvm-objs += vtd.o +endif obj-$(CONFIG_KVM) += kvm.o kvm-intel-objs = vmx.o obj-$(CONFIG_KVM_INTEL) += kvm-intel.o
arch/x86/kvm/vtd.c new file +198 -0
198 lines not on this page · raw message
arch/x86/kvm/x86.c +14 -0
@@ -35,6 +35,7 @@#include <linux/module.h> #include <linux/mman.h> #include <linux/highmem.h> +#include <linux/intel-iommu.h> #include <asm/uaccess.h> #include <asm/msr.h>
@@ -277,9 +278,18 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,list_add (&match->list, &kvm->arch.assigned_dev_head); +if (assigned_dev->flags &KVM_DEV_ASSIGN_ENABLE_IOMMU ) { + r =kvm_iommu_map_guest (kvm, match); +if (r) + goto out_list_del; + } + out:mutex_unlock (&kvm->lock);return r; +out_list_del: +list_del (&match->list); +pci_release_regions (dev); out_disable:pci_disable_device (dev); out_put:
@@ -1147,6 +1157,9 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_PV_MMU : r = !tdp_enabled;break ; +case KVM_CAP_IOMMU : + r =intel_iommu_found (); +break ;default : r =0 ;break ;
@@ -4282,6 +4295,7 @@ static void kvm_free_vcpus(struct kvm *kvm)void kvm_arch_destroy_vm (struct kvm *kvm) { +kvm_iommu_unmap_guest (kvm);kvm_free_assigned_devices (kvm);kvm_free_pit (kvm);kfree (kvm->arch.vpic);
include/asm-x86/kvm_host.h +3 -20
@@ -331,26 +331,6 @@ struct kvm_mem_alias {gfn_t target_gfn; }; -struct kvm_irq_ack_notifier { -struct hlist_node link; -unsigned gsi; -void (*irq_acked)(struct kvm_irq_ack_notifier *kian); -}; - -struct kvm_assigned_dev_kernel { -struct kvm_irq_ack_notifier ack_notifier; -struct work_struct interrupt_work; -struct list_head list; -int assigned_dev_id; -int host_busnr; -int host_devfn; -int host_irq; -int guest_irq; -int irq_requested; -struct pci_dev *dev; -struct kvm *kvm; -}; -struct kvm_arch {int naliases;struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS ];
@@ -364,6 +344,7 @@ struct kvm_arch{*/ struct list_head active_mmu_pages;struct list_head assigned_dev_head; +struct dmar_domain *intel_iommu_domain;struct kvm_pic *vpic;struct kvm_ioapic *vioapic;struct kvm_pit *vpit;
@@ -514,6 +495,8 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,int kvm_pv_mmu_op (struct kvm_vcpu *vcpu,unsigned long bytes,gpa_t addr,unsigned long *ret); +int is_mmio_pfn (pfn_t pfn); +extern bool tdp_enabled;enum emulation_result {
include/linux/kvm.h +3 -0
@@ -384,6 +384,7 @@ struct kvm_trace_rec {#define KVM_CAP_COALESCED_MMIO 15#define KVM_CAP_SYNC_MMU 16/* Changes to host mmap are reflected in guest */ #define KVM_CAP_DEVICE_ASSIGNMENT 17 +#define KVM_CAP_IOMMU 18/* * ioctls for VM fds
@@ -495,4 +496,6 @@ struct kvm_assigned_irq { __u32 flags; }; +#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) +#endif
include/linux/kvm_host.h +52 -0
64 lines not on this page · raw message
virt/kvm/kvm_main.c +8 -1
@@ -41,6 +41,7 @@#include <linux/pagemap.h> #include <linux/mman.h> #include <linux/swap.h> +#include <linux/intel-iommu.h> #include <asm/processor.h> #include <asm/io.h>
@@ -76,7 +77,7 @@ static inline int valid_vcpu(int n)return likely (n >=0 && n <KVM_MAX_VCPUS ); } -static inline int is_mmio_pfn (pfn_t pfn) +inline int is_mmio_pfn (pfn_t pfn) {if (pfn_valid (pfn))return PageReserved (pfn_to_page (pfn));
@@ -578,6 +579,12 @@ int __kvm_set_memory_region(struct kvm *kvm, }kvm_free_physmem_slot (&old, &new); + +/* map the pages in iommu page table */ + r =kvm_iommu_map_pages (kvm, base_gfn, npages); +if (r) + goto out; +return 0 ; out_free:
Signature · 1 line
1.6.0.1
PATCH 21/25 KVM: Device Assignment: Free device structures if IRQ allocation fails
In reply to Avi KivityFrom: Amit Shah <[email protected]>
When an IRQ allocation fails, we free up the device structures and disable the device so that we can unregister the device in the userspace and not expose it to the guest at all.
--- arch/x86/kvm/x86.c | 86 +++++++++++++++++++++++++++------------------------- 1 files changed, 45 insertions(+), 41 deletions(-)
arch/x86/kvm/x86.c +45 -41
@@ -166,6 +166,43 @@ static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)enable_irq (dev->host_irq); } +static void kvm_free_assigned_device (struct kvm *kvm, +struct kvm_assigned_dev_kernel + *assigned_dev) +{ +if (irqchip_in_kernel (kvm) && assigned_dev->irq_requested) +free_irq (assigned_dev->host_irq, (void *)assigned_dev); + +kvm_unregister_irq_ack_notifier (kvm, &assigned_dev->ack_notifier); + +if (cancel_work_sync (&assigned_dev->interrupt_work)) +/* We had pending work. That means we will have to take +* care of kvm_put_kvm. +*/ +kvm_put_kvm (kvm); + +pci_release_regions (assigned_dev->dev); +pci_disable_device (assigned_dev->dev); +pci_dev_put (assigned_dev->dev); + +list_del (&assigned_dev->list); +kfree (assigned_dev); +} + +static void kvm_free_all_assigned_devices (struct kvm *kvm) +{ +struct list_head *ptr, *ptr2; +struct kvm_assigned_dev_kernel *assigned_dev; + +list_for_each_safe (ptr, ptr2, &kvm->arch.assigned_dev_head) { + assigned_dev =list_entry (ptr, + struct kvm_assigned_dev_kernel, + list); + +kvm_free_assigned_device (kvm, assigned_dev); + } +} +static int kvm_vm_ioctl_assign_irq (struct kvm *kvm,struct kvm_assigned_irq *assigned_irq)
@@ -194,8 +231,8 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm,if (irqchip_in_kernel (kvm)) {if (!capable (CAP_SYS_RAWIO )) { -return -EPERM ; - goto out; + r = -EPERM ; + goto out_release; }if (assigned_irq->host_irq)
@@ -214,17 +251,18 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm,*/ if (request_irq (match->host_irq, kvm_assigned_dev_intr,0 ,"kvm_assigned_device" , (void *)match)) { -printk (KERN_INFO "%s: couldn't allocate irq for pv " -"device\n" , __func__); r = -EIO ; - goto out; + goto out_release; } } match->irq_requested = true; -out:mutex_unlock (&kvm->lock);return r; +out_release: +mutex_unlock (&kvm->lock); +kvm_free_assigned_device (kvm, match); +return r; } static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
@@ -300,40 +338,6 @@ out_free:return r; } -static void kvm_free_assigned_devices (struct kvm *kvm) -{ -struct list_head *ptr, *ptr2; -struct kvm_assigned_dev_kernel *assigned_dev; - -list_for_each_safe (ptr, ptr2, &kvm->arch.assigned_dev_head) { - assigned_dev =list_entry (ptr, - struct kvm_assigned_dev_kernel, - list); - -if (irqchip_in_kernel (kvm) && assigned_dev->irq_requested) { -free_irq (assigned_dev->host_irq, - (void *)assigned_dev); - -kvm_unregister_irq_ack_notifier (kvm, - &assigned_dev-> - ack_notifier); - } - -if (cancel_work_sync (&assigned_dev->interrupt_work)) -/* We had pending work. That means we will have to take -* care of kvm_put_kvm. -*/ -kvm_put_kvm (kvm); - -pci_release_regions (assigned_dev->dev); -pci_disable_device (assigned_dev->dev); -pci_dev_put (assigned_dev->dev); - -list_del (&assigned_dev->list); -kfree (assigned_dev); - } -} -unsigned long segment_base (u16 selector) {struct descriptor_table gdt;
@@ -4296,7 +4300,7 @@ static void kvm_free_vcpus(struct kvm *kvm)void kvm_arch_destroy_vm (struct kvm *kvm) {kvm_iommu_unmap_guest (kvm); -kvm_free_assigned_devices (kvm); +kvm_free_all_assigned_devices (kvm);kvm_free_pit (kvm);kfree (kvm->arch.vpic);kfree (kvm->arch.vioapic);
Signature · 1 line
1.6.0.1
PATCH 22/25 KVM: opencode gfn_to_page in kvm_vm_fault
In reply to Avi KivityFrom: Marcelo Tosatti <[email protected]>
kvm_vm_fault is invoked with mmap_sem held in read mode. Since gfn_to_page will be converted to get_user_pages_fast, which requires this lock NOT to be held, switch to opencoded get_user_pages.
--- virt/kvm/kvm_main.c | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-)
virt/kvm/kvm_main.c +12 -7
@@ -1394,17 +1394,22 @@ out:static int kvm_vm_fault (struct vm_area_struct *vma,struct vm_fault *vmf) { +struct page *page[1 ]; +unsigned long addr; +int npages; +gfn_t gfn = vmf->pgoff;struct kvm *kvm = vma->vm_file->private_data; -struct page *page; -if (!kvm_is_visible_gfn (kvm, vmf->pgoff)) + addr =gfn_to_hva (kvm, gfn); +if (kvm_is_error_hva (addr))return VM_FAULT_SIGBUS ; - page =gfn_to_page (kvm, vmf->pgoff); -if (is_error_page (page)) { -kvm_release_page_clean (page); + + npages =get_user_pages (current, current->mm, addr,1 ,1 ,0 , page, +NULL ); +if (unlikely (npages !=1 ))return VM_FAULT_SIGBUS ; - } - vmf->page = page; + + vmf->page = page[0 ];return 0 ; }
Signature · 1 line
1.6.0.1
PATCH 23/25 KVM: switch to get_user_pages_fast
In reply to Avi KivityFrom: Marcelo Tosatti <[email protected]>
Convert gfn_to_pfn to use get_user_pages_fast, which can do lockless pagetable lookups on x86. Kernel compilation on 4-way guest is 3.7% faster on VMX.
--- arch/powerpc/kvm/44x_tlb.c | 2 -- arch/x86/kvm/mmu.c | 23 +++++++++-------------- arch/x86/kvm/paging_tmpl.h | 8 +------- arch/x86/kvm/vmx.c | 4 ---- arch/x86/kvm/x86.c | 6 ------ virt/kvm/kvm_main.c | 10 +++++----- 6 files changed, 15 insertions(+), 38 deletions(-)
arch/powerpc/kvm/44x_tlb.c +0 -2
@@ -147,9 +147,7 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gfn_t gfn, u64 asid, stlbe = &vcpu->arch.shadow_tlb[victim];/* Get reference to new page. */ -down_read (¤t->mm->mmap_sem); new_page =gfn_to_page (vcpu->kvm, gfn); -up_read (¤t->mm->mmap_sem);if (is_error_page (new_page)) {printk (KERN_ERR "Couldn't get guest page for gfn %lx!\n" , gfn);kvm_release_page_clean (new_page);
arch/x86/kvm/mmu.c +9 -14
@@ -405,16 +405,19 @@ static int host_largepage_backed(struct kvm *kvm, gfn_t gfn) {struct vm_area_struct *vma;unsigned long addr; +int ret =0 ; addr =gfn_to_hva (kvm, gfn);if (kvm_is_error_hva (addr)) -return 0 ; +return ret; +down_read (¤t->mm->mmap_sem); vma =find_vma (current->mm, addr);if (vma &&is_vm_hugetlb_page (vma)) -return 1 ; + ret =1 ; +up_read (¤t->mm->mmap_sem); -return 0 ; +return ret; }static int is_largepage_backed (struct kvm_vcpu *vcpu,gfn_t large_gfn)
@@ -1140,9 +1143,7 @@ struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva)if (gpa ==UNMAPPED_GVA )return NULL ; -down_read (¤t->mm->mmap_sem); page =gfn_to_page (vcpu->kvm, gpa >>PAGE_SHIFT ); -up_read (¤t->mm->mmap_sem);return page; }
@@ -1330,16 +1331,14 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)pfn_t pfn;unsigned long mmu_seq; -down_read (¤t->mm->mmap_sem);if (is_largepage_backed (vcpu, gfn & ~(KVM_PAGES_PER_HPAGE -1 ))) { gfn &= ~(KVM_PAGES_PER_HPAGE -1 ); largepage =1 ; } mmu_seq = vcpu->kvm->mmu_notifier_seq; -/* implicit mb(), we'll read before PT lock is unlocked */ +smp_rmb (); pfn =gfn_to_pfn (vcpu->kvm, gfn); -up_read (¤t->mm->mmap_sem);/* mmio */ if (is_error_pfn (pfn)) {
@@ -1488,15 +1487,13 @@ static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa,if (r)return r; -down_read (¤t->mm->mmap_sem);if (is_largepage_backed (vcpu, gfn & ~(KVM_PAGES_PER_HPAGE -1 ))) { gfn &= ~(KVM_PAGES_PER_HPAGE -1 ); largepage =1 ; } mmu_seq = vcpu->kvm->mmu_notifier_seq; -/* implicit mb(), we'll read before PT lock is unlocked */ +smp_rmb (); pfn =gfn_to_pfn (vcpu->kvm, gfn); -up_read (¤t->mm->mmap_sem);if (is_error_pfn (pfn)) {kvm_release_pfn_clean (pfn);return 1 ;
@@ -1809,15 +1806,13 @@ static void mmu_guess_page_from_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,return ; gfn = (gpte &PT64_BASE_ADDR_MASK ) >>PAGE_SHIFT ; -down_read (¤t->mm->mmap_sem);if (is_large_pte (gpte) &&is_largepage_backed (vcpu, gfn)) { gfn &= ~(KVM_PAGES_PER_HPAGE -1 ); vcpu->arch.update_pte.largepage =1 ; } vcpu->arch.update_pte.mmu_seq = vcpu->kvm->mmu_notifier_seq; -/* implicit mb(), we'll read before PT lock is unlocked */ +smp_rmb (); pfn =gfn_to_pfn (vcpu->kvm, gfn); -up_read (¤t->mm->mmap_sem);if (is_error_pfn (pfn)) {kvm_release_pfn_clean (pfn);
arch/x86/kvm/paging_tmpl.h +1 -7
@@ -102,14 +102,10 @@ static bool FNAME(cmpxchg_gpte)(struct kvm *kvm,pt_element_t *table;struct page *page; -down_read (¤t->mm->mmap_sem); page =gfn_to_page (kvm, table_gfn); -up_read (¤t->mm->mmap_sem); table =kmap_atomic (page,KM_USER0 ); - ret =CMPXCHG (&table[index], orig_pte, new_pte); -kunmap_atomic (table,KM_USER0 );kvm_release_page_dirty (page);
@@ -418,7 +414,6 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,return 0 ; } -down_read (¤t->mm->mmap_sem);if (walker.level ==PT_DIRECTORY_LEVEL ) {gfn_t large_gfn; large_gfn = walker.gfn & ~(KVM_PAGES_PER_HPAGE -1 );
@@ -428,9 +423,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, } } mmu_seq = vcpu->kvm->mmu_notifier_seq; -/* implicit mb(), we'll read before PT lock is unlocked */ +smp_rmb (); pfn =gfn_to_pfn (vcpu->kvm, walker.gfn); -up_read (¤t->mm->mmap_sem);/* mmio */ if (is_error_pfn (pfn)) {
arch/x86/kvm/vmx.c +0 -4
@@ -2010,9 +2010,7 @@ static int alloc_apic_access_page(struct kvm *kvm)if (r) goto out; -down_read (¤t->mm->mmap_sem); kvm->arch.apic_access_page =gfn_to_page (kvm,0xfee00 ); -up_read (¤t->mm->mmap_sem); out:up_write (&kvm->slots_lock);return r;
@@ -2034,10 +2032,8 @@ static int alloc_identity_pagetable(struct kvm *kvm)if (r) goto out; -down_read (¤t->mm->mmap_sem); kvm->arch.ept_identity_pagetable =gfn_to_page (kvm,VMX_EPT_IDENTITY_PAGETABLE_ADDR >>PAGE_SHIFT ); -up_read (¤t->mm->mmap_sem); out:up_write (&kvm->slots_lock);return r;
arch/x86/kvm/x86.c +0 -6
@@ -946,10 +946,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)/* ...but clean it before doing the actual write */ vcpu->arch.time_offset = data & ~(PAGE_MASK |1 ); -down_read (¤t->mm->mmap_sem); vcpu->arch.time_page =gfn_to_page (vcpu->kvm, data >>PAGE_SHIFT ); -up_read (¤t->mm->mmap_sem);if (is_error_page (vcpu->arch.time_page)) {kvm_release_page_clean (vcpu->arch.time_page);
@@ -2322,9 +2320,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr, val = *(u64 *)new; -down_read (¤t->mm->mmap_sem); page =gfn_to_page (vcpu->kvm, gpa >>PAGE_SHIFT ); -up_read (¤t->mm->mmap_sem); kaddr =kmap_atomic (page,KM_USER0 );set_64bit ((u64 *)(kaddr +offset_in_page (gpa)), val);
@@ -3089,9 +3085,7 @@ static void vapic_enter(struct kvm_vcpu *vcpu)if (!apic || !apic->vapic_addr)return ; -down_read (¤t->mm->mmap_sem); page =gfn_to_page (vcpu->kvm, apic->vapic_addr >>PAGE_SHIFT ); -up_read (¤t->mm->mmap_sem); vcpu->arch.apic->vapic_page = page; }
virt/kvm/kvm_main.c +5 -5
@@ -723,9 +723,6 @@ unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn) }EXPORT_SYMBOL_GPL (gfn_to_hva); -/* -* Requires current->mm->mmap_sem to be held -*/ pfn_t gfn_to_pfn (struct kvm *kvm,gfn_t gfn) {struct page *page[1 ];
@@ -741,20 +738,23 @@ pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn)return page_to_pfn (bad_page); } - npages =get_user_pages (current, current->mm, addr,1 ,1 ,0 , page, -NULL ); + npages =get_user_pages_fast (addr,1 ,1 , page);if (unlikely (npages !=1 )) {struct vm_area_struct *vma; +down_read (¤t->mm->mmap_sem); vma =find_vma (current->mm, addr); +if (vma ==NULL || addr < vma->vm_start || !(vma->vm_flags &VM_PFNMAP )) { +up_read (¤t->mm->mmap_sem);get_page (bad_page);return page_to_pfn (bad_page); } pfn = ((addr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; +up_read (¤t->mm->mmap_sem);BUG_ON (!is_mmio_pfn (pfn)); }else pfn =page_to_pfn (page[0 ]);
Signature · 1 line
1.6.0.1
PATCH 24/25 KVM: x86.c make kvm_load_realmode_segment static
In reply to Avi KivityFrom: Harvey Harrison <[email protected]>
Noticed by sparse:arch/x86/kvm/x86.c:3591:5: warning: symbol 'kvm_load_realmode_segment' was not declared. Should it be static?
--- arch/x86/kvm/x86.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +1 -1
@@ -3611,7 +3611,7 @@ static int load_segment_descriptor_to_kvm_desct(struct kvm_vcpu *vcpu,return 0 ; } -int kvm_load_realmode_segment (struct kvm_vcpu *vcpu,u16 selector,int seg) +static int kvm_load_realmode_segment (struct kvm_vcpu *vcpu,u16 selector,int seg) {struct kvm_segment segvar = { .base = selector <<4 ,
Signature · 1 line
1.6.0.1
PATCH 25/25 MAINTAINERS: Update Avi Kivity's email address
In reply to Avi Kivity--- MAINTAINERS | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
MAINTAINERS +1 -1
@@ -2411,7 +2411,7 @@ S: Supported KERNEL VIRTUAL MACHINE (KVM) P: Avi Kivity -M: [email protected] +M: [email protected] L: [email protected] W: http://kvm.qumranet.com S: Supported
Signature · 1 line
1.6.0.1