2008-02-13 14:39:13

by Zdenek Kabelac

[permalink] [raw]
Subject: Qemu & KVM bug

Hi

I get this bug in my log whenever I start qemu-kvm - I do not use kqemu
module - so it's with plain kernel modules.
If more details are needed - just ask.
(Cpu; C2D)

Bye

Zdenek



BUG: sleeping function called from invalid context at kernel/rwsem.c:48
in_atomic():1, irqs_disabled():0
INFO: lockdep is turned off.
Pid: 26600, comm: qemu-kvm Not tainted 2.6.25-rc1 #29

Call Trace:
[<ffffffff81064873>] ? __debug_show_held_locks+0x23/0x30
[<ffffffff81036765>] __might_sleep+0xe5/0x110
[<ffffffff812f21b0>] down_write+0x20/0x70
[<ffffffff88271a3c>] :kvm_intel:vmx_create_vcpu+0x48c/0x61c
[<ffffffff810b5d92>] ? fd_install+0x52/0x60
[<ffffffff8824edce>] :kvm:kvm_arch_vcpu_create+0xe/0x10
[<ffffffff8824dca2>] :kvm:kvm_vm_ioctl+0x122/0x220
[<ffffffff8824c770>] ? :kvm:kvm_dev_ioctl+0x80/0x1c0
[<ffffffff810c67b1>] vfs_ioctl+0x31/0xa0
[<ffffffff810c6aa3>] do_vfs_ioctl+0x283/0x2f0
[<ffffffff810c6ba9>] sys_ioctl+0x99/0xa0
[<ffffffff8100c8ae>] tracesys+0xdc/0xe1

SIPI to vcpu 1 vector 0x10
Ignoring de-assert INIT to vcpu 1
SIPI to vcpu 1 vector 0x06
SIPI to vcpu 1 vector 0x06
kvm: emulating exchange as write


2008-02-13 15:27:09

by Jiri Kosina

[permalink] [raw]
Subject: Re: Qemu & KVM bug

On Wed, 13 Feb 2008, Zdenek Kabelac wrote:

> I get this bug in my log whenever I start qemu-kvm - I do not use kqemu
> module - so it's with plain kernel modules. If more details are needed -
> just ask. (Cpu; C2D)
> BUG: sleeping function called from invalid context at kernel/rwsem.c:48
> in_atomic():1, irqs_disabled():0
> INFO: lockdep is turned off.
> Pid: 26600, comm: qemu-kvm Not tainted 2.6.25-rc1 #29

This has been obviously caused by Marcelo's (added to CC) commit
10589a4699b, which added down_write(mmap_sem) to alloc_apic_access_page(),
which is called with preempt disabled from vmx_create_vcpu().

--
Jiri Kosina
SUSE Labs

2008-02-13 16:06:59

by Marcelo Tosatti

[permalink] [raw]
Subject: Re: Qemu & KVM bug

On Wed, Feb 13, 2008 at 04:24:53PM +0100, Jiri Kosina wrote:
> On Wed, 13 Feb 2008, Zdenek Kabelac wrote:
>
> > I get this bug in my log whenever I start qemu-kvm - I do not use kqemu
> > module - so it's with plain kernel modules. If more details are needed -
> > just ask. (Cpu; C2D)
> > BUG: sleeping function called from invalid context at kernel/rwsem.c:48
> > in_atomic():1, irqs_disabled():0
> > INFO: lockdep is turned off.
> > Pid: 26600, comm: qemu-kvm Not tainted 2.6.25-rc1 #29
>
> This has been obviously caused by Marcelo's (added to CC) commit
> 10589a4699b, which added down_write(mmap_sem) to alloc_apic_access_page(),
> which is called with preempt disabled from vmx_create_vcpu().

alloc_apic_access_page() called mutex_lock, so the warning would trigger
before that change.

I think it's fine to allocate the APIC page after put_cpu(), since no vcpu
state is required.

Avi?


--- linux-2.6.orig/arch/x86/kvm/vmx.c
+++ linux-2.6/arch/x86/kvm/vmx.c
@@ -1601,9 +1601,6 @@ static int vmx_vcpu_setup(struct vcpu_vm
vmcs_writel(CR0_GUEST_HOST_MASK, ~0UL);
vmcs_writel(CR4_GUEST_HOST_MASK, KVM_GUEST_CR4_MASK);

- if (vm_need_virtualize_apic_accesses(vmx->vcpu.kvm))
- if (alloc_apic_access_page(vmx->vcpu.kvm) != 0)
- return -ENOMEM;

return 0;
}
@@ -2533,6 +2530,9 @@ static struct kvm_vcpu *vmx_create_vcpu(
put_cpu();
if (err)
goto free_vmcs;
+ if (vm_need_virtualize_apic_accesses(kvm))
+ if (alloc_apic_access_page(kvm) != 0)
+ goto free_vmcs;

return &vmx->vcpu;

2008-02-13 16:38:31

by Zdenek Kabelac

[permalink] [raw]
Subject: Re: Qemu & KVM bug

2008/2/13, Marcelo Tosatti <[email protected]>:
> On Wed, Feb 13, 2008 at 04:24:53PM +0100, Jiri Kosina wrote:
> > On Wed, 13 Feb 2008, Zdenek Kabelac wrote:
> >
> > > I get this bug in my log whenever I start qemu-kvm - I do not use kqemu
> > > module - so it's with plain kernel modules. If more details are needed -
> > > just ask. (Cpu; C2D)
> > > BUG: sleeping function called from invalid context at kernel/rwsem.c:48
> > > in_atomic():1, irqs_disabled():0
> > > INFO: lockdep is turned off.
> > > Pid: 26600, comm: qemu-kvm Not tainted 2.6.25-rc1 #29
> >
> > This has been obviously caused by Marcelo's (added to CC) commit
> > 10589a4699b, which added down_write(mmap_sem) to alloc_apic_access_page(),
> > which is called with preempt disabled from vmx_create_vcpu().
>
> alloc_apic_access_page() called mutex_lock, so the warning would trigger
> before that change.
>
> I think it's fine to allocate the APIC page after put_cpu(), since no vcpu
> state is required.
>
> Avi?
>
>
> --- linux-2.6.orig/arch/x86/kvm/vmx.c
> +++ linux-2.6/arch/x86/kvm/vmx.c
> @@ -1601,9 +1601,6 @@ static int vmx_vcpu_setup(struct vcpu_vm

Hi

I've checked the patch myself - and looks like there is no BUG message
now - nice
thanks.

Zdenek

2008-02-13 16:58:42

by Avi Kivity

[permalink] [raw]
Subject: Re: Qemu & KVM bug

Marcelo Tosatti wrote:
> On Wed, Feb 13, 2008 at 04:24:53PM +0100, Jiri Kosina wrote:
>
>> On Wed, 13 Feb 2008, Zdenek Kabelac wrote:
>>
>>
>>> I get this bug in my log whenever I start qemu-kvm - I do not use kqemu
>>> module - so it's with plain kernel modules. If more details are needed -
>>> just ask. (Cpu; C2D)
>>> BUG: sleeping function called from invalid context at kernel/rwsem.c:48
>>> in_atomic():1, irqs_disabled():0
>>> INFO: lockdep is turned off.
>>> Pid: 26600, comm: qemu-kvm Not tainted 2.6.25-rc1 #29
>>>
>> This has been obviously caused by Marcelo's (added to CC) commit
>> 10589a4699b, which added down_write(mmap_sem) to alloc_apic_access_page(),
>> which is called with preempt disabled from vmx_create_vcpu().
>>
>
> alloc_apic_access_page() called mutex_lock, so the warning would trigger
> before that change.
>
> I think it's fine to allocate the APIC page after put_cpu(), since no vcpu
> state is required.
>
>


Looks right, but wants a changelog and signoff, of course.

--
Any sufficiently difficult bug is indistinguishable from a feature.