All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: andreas.tanz@kvt.de
Cc: kvm@vger.kernel.org
Subject: Re: KVM on Via Nano (Isaiah) CPUs? <Virus checked>
Date: Thu, 19 Mar 2009 19:20:00 +0200	[thread overview]
Message-ID: <49C27EC0.1090108@redhat.com> (raw)
In-Reply-To: <200903191805.05622.andreas.tanz@kvt.de>

Andreas Tanz wrote:
> Am 19.03.2009 schrieb Avi Kivity:
>   
>> This bit is broken.  The original code:
>>
>>     if (vcpu->arch.rmode.active &&
>>         handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK,
>>                                 error_code)) {
>>
>> Only executes handle_rmode_exception() if rmode.active is true.  Your 
>> code executes it unconditionally.
>>
>> You can write it as
>>
>>     if (vcpu->arch.rmode.active &&
>>         (retval = handle_rmode_exception(vcpu, intr_info & 
>> INTR_INFO_VECTOR_MASK,
>>                                 error_code))) {
>>
>>
>> Please check for other cases as well.  As it happens, the guest crashed 
>> immediately after entering protected mode (so rmode.active became false, 
>> triggering the bug).
>>
>>     
>
> ooooooops - stupid mistake :-I
> that was it...
>
> vmx.c now looks as this : 
> ....
> 2637 static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
> 2638 {
> 2639         struct vcpu_vmx *vmx = to_vmx(vcpu);
> 2640         u32 intr_info, ex_no, error_code;
> 2641         unsigned long cr2, rip, dr6;
> 2642         u32 vect_info;
> 2643         enum emulation_result er;
> 2644
> 2645         vect_info = vmx->idt_vectoring_info;
> 2646         intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
> 2647
> 2648         printk(KERN_ERR "vmx->handle_exception 00 : giving some infos\n");
> 2649         printk(KERN_ERR "vmx->handle_exception 01 : vect_info: 0x%x\n",vect_info);
> 2650         printk(KERN_ERR "vmx->handle_exception 02 : intr_info: 0x%x, is_page_fault()==%i\n",intr_info,is_page_fault(intr_info));
> 2651
> 2652         if ((vect_info & VECTORING_INFO_VALID_MASK) &&
> 2653                                                 !is_page_fault(intr_info))
> 2654                 printk(KERN_ERR "%s: unexpected, vectoring info 0x%x "
> 2655                        "intr info 0x%x\n", __func__, vect_info, intr_info);
> 2656
> 2657         printk(KERN_ERR "vmx->handle_exception 03 : irq_chip_in_kernel()==%i\n",irqchip_in_kernel(vcpu->kvm));
> 2658         printk(KERN_ERR "vmx->handle_exception 04 : is_external_interrupt()==%i\n",is_external_interrupt(vect_info));
> 2659         if (!irqchip_in_kernel(vcpu->kvm) && is_external_interrupt(vect_info)) {
> 2660                 int irq = vect_info & VECTORING_INFO_VECTOR_MASK;
> 2661                 printk(KERN_ERR "vmx->handle_exception 05 : irq: 0x%x\n",irq);
> 2662                 set_bit(irq, vcpu->arch.irq_pending);
> 2663                 set_bit(irq / BITS_PER_LONG, &vcpu->arch.irq_summary);
> 2664         }
> 2665
> 2666         if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR){
> 2667                 printk(KERN_ERR "vmx->handle_exception 06 : already handled by vmx_vcpu_run()\n");
> 2668                 return 1;  /* already handled by vmx_vcpu_run() */
> 2669         }
> 2670
> 2671         if (is_no_device(intr_info)) {
> 2672                 printk(KERN_ERR "vmx->handle_exception 07 : is_no_device(intr_info)\n");
> 2673                 vmx_fpu_activate(vcpu);
> 2674                 return 1;
> 2675         }
> 2676
> 2677         if (is_invalid_opcode(intr_info)) {
> 2678                 printk(KERN_ERR "vmx->handle_exception 08 : is_invalid_opcode(intr_info)\n");
> 2679                 er = emulate_instruction(vcpu, kvm_run, 0, 0, EMULTYPE_TRAP_UD);
> 2680                 if (er != EMULATE_DONE) {
> 2681                         printk(KERN_ERR "vmx->handle_exception 09 : emulation not done. enqueueing exception\n");
> 2682                         kvm_queue_exception(vcpu, UD_VECTOR);
> 2683                 }
> 2684                 return 1;
> 2685         }
> 2686
> 2687         error_code = 0;
> 2688         rip = kvm_rip_read(vcpu);
> 2689         printk(KERN_ERR "vmx->handle_exception 0a : kvm_rip_read(vcpu) returned 0x%lx\n",rip);
> 2690         if (intr_info & INTR_INFO_DELIVER_CODE_MASK)
> 2691                 error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE);
> 2692         if (is_page_fault(intr_info)) {
> 2693                 printk(KERN_ERR "vmx->handle_exception 0b : is_page_fault(intr_info) returned 0x%x\n",is_page_fault(intr_info));
> 2694                 /* EPT won't cause page fault directly */
> 2695                 if (vm_need_ept())
> 2696                         BUG();
> 2697                 cr2 = vmcs_readl(EXIT_QUALIFICATION);
> 2698                 printk(KERN_ERR "vmx->handle_exception 0c : vmcs_readl(EXIT_QUALIFICATION) returned 0x%lx\n",cr2);
> 2699                 KVMTRACE_3D(PAGE_FAULT, vcpu, error_code, (u32)cr2,
> 2700                             (u32)((u64)cr2 >> 32), handler);
> 2701                 if (vcpu->arch.interrupt.pending || vcpu->arch.exception.pending){
> 2702                         printk(KERN_ERR "vmx->handle_exception 0d : interrupt.pending or exception.pending\n");
> 2703                         kvm_mmu_unprotect_page_virt(vcpu, cr2);
> 2704                 }
> 2705                 int retval = kvm_mmu_page_fault(vcpu, cr2, error_code);
> 2706                 printk(KERN_ERR "vmx->handle_exception 0e : kvm_mmu_page_fault(vcpu, cr2, error_code) returned 0x%x\n",retval);
> 2707                 //return kvm_mmu_page_fault(vcpu, cr2, error_code);
> 2708                 return retval;
> 2709         }
> 2710
> 2711         printk(KERN_ERR "vmx->handle_exception 0f : vcpu->arch.rmode.active: 0x%x\n",vcpu->arch.rmode.active);
> 2712         int debug_handle_rmode_exception = 0;
> 2713         if (vcpu->arch.rmode.active && (debug_handle_rmode_exception = handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK, error_code))) {
> 2714                 printk(KERN_ERR "vmx->handle_exception 10 : handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK, error_code) returned 0x%x\n",debug_handle_rmode_exception);
> 2715                 if (vcpu->arch.halt_request) {
> 2716                         printk(KERN_ERR "vmx->handle_exception 11 : vcpu->arch.halt_request: 0x%x, resetting to 0\n",vcpu->arch.halt_request);
> 2717                         vcpu->arch.halt_request = 0;
> 2718                         int retval = kvm_emulate_halt(vcpu);
> 2719                         printk(KERN_ERR "vmx->handle_exception 12 : kvm_emulate_halt(vcpu) returned 0x%x\n",retval);
> 2720                         // return kvm_emulate_halt(vcpu);
> 2721                         return retval;
> 2722                 }
> 2723                 return 1;
> 2724         }
> 2725
> 2726         ex_no = intr_info & INTR_INFO_VECTOR_MASK;
> 2727         switch (ex_no) {
> 2728         case DB_VECTOR:
> 2729                 dr6 = vmcs_readl(EXIT_QUALIFICATION);
> 2730                 printk(KERN_ERR "vmx->handle_exception 13 : ex_no==DB_VECTOR==0x%x, vmcs_readl(EXIT_QUALIFICATION) returned 0x%lx\n",ex_no,dr6);
> 2731                 if (!(vcpu->guest_debug &
> 2732                       (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) {
> 2733                         vcpu->arch.dr6 = dr6 | DR6_FIXED_1;
> 2734                         printk(KERN_ERR "vmx->handle_exception 14 : enqueuing exception\n");
> 2735                         kvm_queue_exception(vcpu, DB_VECTOR);
> 2736                         return 1;
> 2737                 }
> 2738                 kvm_run->debug.arch.dr6 = dr6 | DR6_FIXED_1;
> 2739                 kvm_run->debug.arch.dr7 = vmcs_readl(GUEST_DR7);
> 2740                 /* fall through */
> 2741         case BP_VECTOR:
> 2742                 if(ex_no == BP_VECTOR)printk(KERN_ERR "vmx->handle_exception 15 : ex_no==BP_VECTOR==0x%x\n",ex_no);
> 2743                 kvm_run->exit_reason = KVM_EXIT_DEBUG;
> 2744                 unsigned long debug_vmcs_readl = vmcs_readl(GUEST_CS_BASE);
> 2745                 printk(KERN_ERR "vmx->handle_exception 16 : vmcs_readl(GUEST_CS_BASE) returned 0x%lx\n",debug_vmcs_readl);
> 2746                 kvm_run->debug.arch.pc = debug_vmcs_readl + rip;
> 2747                 kvm_run->debug.arch.exception = ex_no;
> 2748                 break;
> 2749         default:
> 2750                 printk(KERN_ERR "vmx->handle_exception 17 : unknown ex_no: 0x%x, error_code: 0x%x\n",ex_no,error_code);
> 2751                 kvm_run->exit_reason = KVM_EXIT_EXCEPTION;
> 2752                 kvm_run->ex.exception = ex_no;
> 2753                 kvm_run->ex.error_code = error_code;
> 2754                 break;
> 2755         }
> 2756         printk(KERN_ERR "vmx->handle_exception 18 : reached end of handle_exception - returning 0\n");
> 2757         return 0;
> 2758 }
>
> ....
>
>
> # dmesg :
> .....
> [101324.097856] vmx->handle_exception 00 : giving some infos
> [101324.097861] vmx->handle_exception 01 : vect_info: 0x0
> [101324.097865] vmx->handle_exception 02 : intr_info: 0x80000b0d, is_page_fault()==0
> [101324.097871] vmx->handle_exception 03 : irq_chip_in_kernel()==1
> [101324.097876] vmx->handle_exception 04 : is_external_interrupt()==0
> [101324.097881] vmx->handle_exception 0a : kvm_rip_read(vcpu) returned 0x3154
> [101324.097886] vmx->handle_exception 0f : vcpu->arch.rmode.active: 0x1
> [101324.097891] vmx->handle_exception 10 : handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK, error_code) returned 0x1
> [101324.097898] returning from kvm_handle_exit, cause 3, retval = 1, exit_reason = 0
> [101324.097912] vmx->handle_exception 00 : giving some infos
> [101324.097917] vmx->handle_exception 01 : vect_info: 0x0
> [101324.097922] vmx->handle_exception 02 : intr_info: 0x80000b0d, is_page_fault()==0
> [101324.097927] vmx->handle_exception 03 : irq_chip_in_kernel()==1
> [101324.097932] vmx->handle_exception 04 : is_external_interrupt()==0
> [101324.097937] vmx->handle_exception 0a : kvm_rip_read(vcpu) returned 0x3154
> [101324.097942] vmx->handle_exception 0f : vcpu->arch.rmode.active: 0x1
> [101324.097947] vmx->handle_exception 10 : handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK, error_code) returned 0x1
> [101324.097955] returning from kvm_handle_exit, cause 3, retval = 1, exit_reason = 0
> [101324.097968] vmx->handle_exception 00 : giving some infos
> [101324.097973] vmx->handle_exception 01 : vect_info: 0x0
> [101324.097978] vmx->handle_exception 02 : intr_info: 0x80000b0d, is_page_fault()==0
> [101324.097983] vmx->handle_exception 03 : irq_chip_in_kernel()==1
> [101324.097988] vmx->handle_exception 04 : is_external_interrupt()==0
> [101324.097993] vmx->handle_exception 0a : kvm_rip_read(vcpu) returned 0x3154
> [101324.097998] vmx->handle_exception 0f : vcpu->arch.rmode.active: 0x1
> [101324.098039] vmx->handle_exception 10 : handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK, error_code) returned 0x1
> [101324.098050] returning from kvm_handle_exit, cause 3, retval = 1, exit_reason = 0
> .... until kvm get's killed
>   

The code in question is:

    3152:       fb                      sti   
    3153:       55                      push   %bp

*** fault here ***

    3154:       89 e5                   mov    %sp,%bp
    3156:       8b 7e 2a                mov    0x2a(%bp),%di
    3159:       8b 46 28                mov    0x28(%bp),%ax
    315c:       8b 4e 08                mov    0x8(%bp),%cx
    315f:       81 ff 00 f8             cmp    $0xf800,%di

So it looks like we tried to inject the IDE interrupt (that's the first 
point where it is possible to inject interrupts), but via fails to 
inject the interrupt for some reason.

I'll need to think how to debug this further.

-- 
error compiling committee.c: too many arguments to function


  reply	other threads:[~2009-03-19 17:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200903180902.29139.andreas.tanz@kvt.de>
     [not found] ` <200903181810.48603.andreas.tanz@kvt.de>
     [not found]   ` <49C20DEE.9040302@redhat.com>
2009-03-19 10:55     ` KVM on Via Nano (Isaiah) CPUs? <Virus checked> Andreas Tanz
2009-03-19 12:25       ` Avi Kivity
2009-03-19 15:10         ` Andreas Tanz
2009-03-19 15:19           ` Avi Kivity
2009-03-19 15:34             ` Andreas Tanz
2009-03-19 15:48               ` Avi Kivity
2009-03-19 17:05                 ` Andreas Tanz
2009-03-19 17:20                   ` Avi Kivity [this message]
2009-03-20 12:37                     ` Andreas Tanz
2009-03-22  8:53                       ` Avi Kivity
2009-03-22  9:03                     ` Avi Kivity
2009-03-23 13:39                       ` Andreas Tanz
2009-03-23 14:08                         ` Avi Kivity
2009-03-23 17:33                           ` Andreas Tanz
2009-03-23 18:41                             ` Avi Kivity
2009-03-23 20:36                               ` Avi Kivity
2009-03-25  9:45                                 ` Andreas Tanz
2009-03-23 18:50                             ` [PATCH] mm/memory.c:unmap_vmas(): fix NULL * deref john cooper
2009-05-08 19:16 KVM on Via Nano (Isaiah) CPUs? Craig Metz
2009-05-09  9:32 ` Avi Kivity
2009-05-12  6:48   ` KVM on Via Nano (Isaiah) CPUs? <Virus checked> Andreas Tanz
2009-05-12  6:50     ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49C27EC0.1090108@redhat.com \
    --to=avi@redhat.com \
    --cc=andreas.tanz@kvt.de \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.