Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'kvm-3.10-2' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull kvm fixes from Gleb Natapov:
"Most of the fixes are in the emulator since now we emulate more than
we did before for correctness sake we see more bugs there, but there
is also an OOPS fixed and corruption of xcr0 register."

* tag 'kvm-3.10-2' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
KVM: emulator: emulate SALC
KVM: emulator: emulate XLAT
KVM: emulator: emulate AAM
KVM: VMX: fix halt emulation while emulating invalid guest sate
KVM: Fix kvm_irqfd_init initialization
KVM: x86: fix maintenance of guest/host xcr0 state

+80 -26
+41 -1
arch/x86/kvm/emulate.c
··· 60 60 #define OpGS 25ull /* GS */ 61 61 #define OpMem8 26ull /* 8-bit zero extended memory operand */ 62 62 #define OpImm64 27ull /* Sign extended 16/32/64-bit immediate */ 63 + #define OpXLat 28ull /* memory at BX/EBX/RBX + zero-extended AL */ 63 64 64 65 #define OpBits 5 /* Width of operand field */ 65 66 #define OpMask ((1ull << OpBits) - 1) ··· 100 99 #define SrcImmUByte (OpImmUByte << SrcShift) 101 100 #define SrcImmU (OpImmU << SrcShift) 102 101 #define SrcSI (OpSI << SrcShift) 102 + #define SrcXLat (OpXLat << SrcShift) 103 103 #define SrcImmFAddr (OpImmFAddr << SrcShift) 104 104 #define SrcMemFAddr (OpMemFAddr << SrcShift) 105 105 #define SrcAcc (OpAcc << SrcShift) ··· 533 531 FOP_SETCC(setnl) 534 532 FOP_SETCC(setle) 535 533 FOP_SETCC(setnle) 534 + FOP_END; 535 + 536 + FOP_START(salc) "pushf; sbb %al, %al; popf \n\t" FOP_RET 536 537 FOP_END; 537 538 538 539 #define __emulate_1op_rax_rdx(ctxt, _op, _suffix, _ex) \ ··· 3001 2996 return X86EMUL_CONTINUE; 3002 2997 } 3003 2998 2999 + static int em_aam(struct x86_emulate_ctxt *ctxt) 3000 + { 3001 + u8 al, ah; 3002 + 3003 + if (ctxt->src.val == 0) 3004 + return emulate_de(ctxt); 3005 + 3006 + al = ctxt->dst.val & 0xff; 3007 + ah = al / ctxt->src.val; 3008 + al %= ctxt->src.val; 3009 + 3010 + ctxt->dst.val = (ctxt->dst.val & 0xffff0000) | al | (ah << 8); 3011 + 3012 + /* Set PF, ZF, SF */ 3013 + ctxt->src.type = OP_IMM; 3014 + ctxt->src.val = 0; 3015 + ctxt->src.bytes = 1; 3016 + fastop(ctxt, em_or); 3017 + 3018 + return X86EMUL_CONTINUE; 3019 + } 3020 + 3004 3021 static int em_aad(struct x86_emulate_ctxt *ctxt) 3005 3022 { 3006 3023 u8 al = ctxt->dst.val & 0xff; ··· 3963 3936 /* 0xD0 - 0xD7 */ 3964 3937 G(Src2One | ByteOp, group2), G(Src2One, group2), 3965 3938 G(Src2CL | ByteOp, group2), G(Src2CL, group2), 3966 - N, I(DstAcc | SrcImmByte | No64, em_aad), N, N, 3939 + I(DstAcc | SrcImmUByte | No64, em_aam), 3940 + I(DstAcc | SrcImmUByte | No64, em_aad), 3941 + F(DstAcc | ByteOp | No64, em_salc), 3942 + I(DstAcc | SrcXLat | ByteOp, em_mov), 3967 3943 /* 0xD8 - 0xDF */ 3968 3944 N, E(0, &escape_d9), N, E(0, &escape_db), N, E(0, &escape_dd), N, N, 3969 3945 /* 0xE0 - 0xE7 */ ··· 4227 4197 op->addr.mem.seg = seg_override(ctxt); 4228 4198 op->val = 0; 4229 4199 op->count = 1; 4200 + break; 4201 + case OpXLat: 4202 + op->type = OP_MEM; 4203 + op->bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes; 4204 + op->addr.mem.ea = 4205 + register_address(ctxt, 4206 + reg_read(ctxt, VCPU_REGS_RBX) + 4207 + (reg_read(ctxt, VCPU_REGS_RAX) & 0xff)); 4208 + op->addr.mem.seg = seg_override(ctxt); 4209 + op->val = 0; 4230 4210 break; 4231 4211 case OpImmFAddr: 4232 4212 op->type = OP_IMM;
+6
arch/x86/kvm/vmx.c
··· 5434 5434 return 0; 5435 5435 } 5436 5436 5437 + if (vcpu->arch.halt_request) { 5438 + vcpu->arch.halt_request = 0; 5439 + ret = kvm_emulate_halt(vcpu); 5440 + goto out; 5441 + } 5442 + 5437 5443 if (signal_pending(current)) 5438 5444 goto out; 5439 5445 if (need_resched())
+20 -20
arch/x86/kvm/x86.c
··· 555 555 } 556 556 EXPORT_SYMBOL_GPL(kvm_lmsw); 557 557 558 + static void kvm_load_guest_xcr0(struct kvm_vcpu *vcpu) 559 + { 560 + if (kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE) && 561 + !vcpu->guest_xcr0_loaded) { 562 + /* kvm_set_xcr() also depends on this */ 563 + xsetbv(XCR_XFEATURE_ENABLED_MASK, vcpu->arch.xcr0); 564 + vcpu->guest_xcr0_loaded = 1; 565 + } 566 + } 567 + 568 + static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu) 569 + { 570 + if (vcpu->guest_xcr0_loaded) { 571 + if (vcpu->arch.xcr0 != host_xcr0) 572 + xsetbv(XCR_XFEATURE_ENABLED_MASK, host_xcr0); 573 + vcpu->guest_xcr0_loaded = 0; 574 + } 575 + } 576 + 558 577 int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) 559 578 { 560 579 u64 xcr0; ··· 590 571 return 1; 591 572 if (xcr0 & ~host_xcr0) 592 573 return 1; 574 + kvm_put_guest_xcr0(vcpu); 593 575 vcpu->arch.xcr0 = xcr0; 594 - vcpu->guest_xcr0_loaded = 0; 595 576 return 0; 596 577 } 597 578 ··· 5630 5611 false); 5631 5612 kvm_x86_ops->set_irq(vcpu); 5632 5613 } 5633 - } 5634 - } 5635 - 5636 - static void kvm_load_guest_xcr0(struct kvm_vcpu *vcpu) 5637 - { 5638 - if (kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE) && 5639 - !vcpu->guest_xcr0_loaded) { 5640 - /* kvm_set_xcr() also depends on this */ 5641 - xsetbv(XCR_XFEATURE_ENABLED_MASK, vcpu->arch.xcr0); 5642 - vcpu->guest_xcr0_loaded = 1; 5643 - } 5644 - } 5645 - 5646 - static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu) 5647 - { 5648 - if (vcpu->guest_xcr0_loaded) { 5649 - if (vcpu->arch.xcr0 != host_xcr0) 5650 - xsetbv(XCR_XFEATURE_ENABLED_MASK, host_xcr0); 5651 - vcpu->guest_xcr0_loaded = 0; 5652 5614 } 5653 5615 } 5654 5616
+13 -5
virt/kvm/kvm_main.c
··· 3105 3105 int r; 3106 3106 int cpu; 3107 3107 3108 - r = kvm_irqfd_init(); 3109 - if (r) 3110 - goto out_irqfd; 3111 3108 r = kvm_arch_init(opaque); 3112 3109 if (r) 3113 3110 goto out_fail; 3111 + 3112 + /* 3113 + * kvm_arch_init makes sure there's at most one caller 3114 + * for architectures that support multiple implementations, 3115 + * like intel and amd on x86. 3116 + * kvm_arch_init must be called before kvm_irqfd_init to avoid creating 3117 + * conflicts in case kvm is already setup for another implementation. 3118 + */ 3119 + r = kvm_irqfd_init(); 3120 + if (r) 3121 + goto out_irqfd; 3114 3122 3115 3123 if (!zalloc_cpumask_var(&cpus_hardware_enabled, GFP_KERNEL)) { 3116 3124 r = -ENOMEM; ··· 3194 3186 out_free_0a: 3195 3187 free_cpumask_var(cpus_hardware_enabled); 3196 3188 out_free_0: 3197 - kvm_arch_exit(); 3198 - out_fail: 3199 3189 kvm_irqfd_exit(); 3200 3190 out_irqfd: 3191 + kvm_arch_exit(); 3192 + out_fail: 3201 3193 return r; 3202 3194 } 3203 3195 EXPORT_SYMBOL_GPL(kvm_init);