From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Kirill A. Shutemov" Subject: Re: BUG: sleeping function called from invalid context at mm/slub.c:793 Date: Tue, 11 Jan 2011 13:13:45 +0200 Message-ID: <20110111111345.GA23544@shutemov.name> References: <20110110105433.GA17881@shutemov.name> <20110110193117.GA20027@shutemov.name> <4D2C279D.5050309@redhat.com> <4D2C3115.9030301@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Christoph Lameter , Marcelo Tosatti , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Pekka Enberg To: Avi Kivity Return-path: Content-Disposition: inline In-Reply-To: <4D2C3115.9030301@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Tue, Jan 11, 2011 at 12:29:41PM +0200, Avi Kivity wrote: > On 01/11/2011 11:49 AM, Avi Kivity wrote: > > On 01/10/2011 09:31 PM, Kirill A. Shutemov wrote: > >> On Mon, Jan 10, 2011 at 10:52:05AM -0600, Christoph Lameter wrote: > >> > > >> > On Mon, 10 Jan 2011, Kirill A. Shutemov wrote: > >> > > >> > > Every time I run qemu with KVM enabled I get this in dmesg: > >> > > > >> > > [ 182.878328] BUG: sleeping function called from invalid > >> context at mm/slub.c:793 > >> > > [ 182.878339] in_atomic(): 1, irqs_disabled(): 0, pid: 4992, > >> name: qemu > >> > > [ 182.878355] Pid: 4992, comm: qemu Not tainted 2.6.37+ #31 > >> > > [ 182.878361] Call Trace: > >> > > [ 182.878381] [] ? __might_sleep+0xd0/0xd7 > >> > > [ 182.878394] [] ? > >> slab_pre_alloc_hook.clone.39+0x23/0x27 > >> > > [ 182.878404] [] ? kmem_cache_alloc+0x22/0xc8 > >> > > [ 182.878414] [] ? init_fpu+0x44/0x7b > >> > > >> > fpu_alloc() does call kmem_cache_alloc with GFP_KERNEL although we > >> are in > >> > an atomic context. > >> > >> Something like this? > >> > >> --- > >> From 7c6fbfed72e7d22cbdf7393f9711d521e0fbb4a6 Mon Sep 17 00:00:00 2001 > >> From: Kirill A. Shutemov > >> Date: Mon, 10 Jan 2011 21:24:23 +0200 > >> Subject: [PATCH] x86, fpu_alloc(): call kmem_cache_alloc() with > >> GFP_ATOMIC > >> > >> [ 182.878328] BUG: sleeping function called from invalid context at > >> mm/slub.c:793 > >> [ 182.878339] in_atomic(): 1, irqs_disabled(): 0, pid: 4992, name: qemu > >> [ 182.878355] Pid: 4992, comm: qemu Not tainted 2.6.37+ #31 > >> [ 182.878361] Call Trace: > >> [ 182.878381] [] ? __might_sleep+0xd0/0xd7 > >> [ 182.878394] [] ? slab_pre_alloc_hook.clone.39+0x23/0x27 > >> [ 182.878404] [] ? kmem_cache_alloc+0x22/0xc8 > >> [ 182.878414] [] ? init_fpu+0x44/0x7b > >> [ 182.878426] [] ? do_device_not_available+0x0/0x1b > >> [ 182.878435] [] ? init_fpu+0x44/0x7b > >> [ 182.878444] [] ? math_state_restore+0x24/0x47 > >> [ 182.878453] [] ? do_device_not_available+0x10/0x1b > >> [ 182.878462] [] ? error_code+0x67/0x6c > >> [ 182.878475] [] ? kvm_load_guest_fpu+0xa1/0xaa > >> [ 182.878484] [] ? kvm_arch_vcpu_ioctl_run+0x798/0xbe8 > >> [ 182.878496] [] ? kvm_vcpu_ioctl+0x105/0x46e > >> [ 182.878508] [] ? get_futex_key+0x73/0x132 > >> [ 182.878517] [] ? futex_wake+0xb6/0xc0 > >> [ 182.878527] [] ? do_futex+0x87/0x669 > >> [ 182.878535] [] ? kvm_vcpu_ioctl+0x0/0x46e > >> [ 182.878545] [] ? do_vfs_ioctl+0x4a0/0x4d1 > >> [ 182.878554] [] ? do_page_fault+0x2eb/0x316 > >> [ 182.878564] [] ? sys_ioctl+0x46/0x68 > >> [ 182.878572] [] ? syscall_call+0x7/0xb > >> [ 182.878585] [] ? aer_probe+0x1da/0x274 > >> > >> Signed-off-by: Kirill A. Shutemov > >> --- > >> arch/x86/include/asm/i387.h | 2 +- > >> 1 files changed, 1 insertions(+), 1 deletions(-) > >> > >> diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h > >> index ef32890..8b896dd 100644 > >> --- a/arch/x86/include/asm/i387.h > >> +++ b/arch/x86/include/asm/i387.h > >> @@ -426,7 +426,7 @@ static inline int fpu_alloc(struct fpu *fpu) > >> { > >> if (fpu_allocated(fpu)) > >> return 0; > >> - fpu->state = kmem_cache_alloc(task_xstate_cachep, GFP_KERNEL); > >> + fpu->state = kmem_cache_alloc(task_xstate_cachep, GFP_ATOMIC); > >> if (!fpu->state) > >> return -ENOMEM; > >> WARN_ON((unsigned long)fpu->state& 15); > > > > If this fails, a task will be killed. I'll patch kvm to ensure that > > the fpu is initialized. > > > > Please try out the attached patch. It helps. Reported-and-tested-by: Kirill A. Shutemov Thanks. > > -- > error compiling committee.c: too many arguments to function > > From f3a6041b5bb3bf7c88f9694a66d7f34be2f78845 Mon Sep 17 00:00:00 2001 > From: Avi Kivity > Date: Tue, 11 Jan 2011 12:15:54 +0200 > Subject: [PATCH] KVM: Initialize fpu state in preemptible context > > init_fpu() (which is indirectly called by the fpu switching code) assumes > it is in process context. Rather than makeing init_fpu() use an atomic > allocation, which can cause a task to be killed, make sure the fpu is > already initialized when we enter the run loop. > > Signed-off-by: Avi Kivity > --- > arch/x86/kernel/i387.c | 1 + > arch/x86/kvm/x86.c | 3 +++ > 2 files changed, 4 insertions(+), 0 deletions(-) > > diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c > index 58bb239..e60c38c 100644 > --- a/arch/x86/kernel/i387.c > +++ b/arch/x86/kernel/i387.c > @@ -169,6 +169,7 @@ int init_fpu(struct task_struct *tsk) > set_stopped_child_used_math(tsk); > return 0; > } > +EXPORT_SYMBOL_GPL(init_fpu); > > /* > * The xstateregs_active() routine is the same as the fpregs_active() routine, > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 8652643..fd93cda 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -5351,6 +5351,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > int r; > sigset_t sigsaved; > > + if (!tsk_used_math(current) && init_fpu(current)) > + return -ENOMEM; > + > if (vcpu->sigset_active) > sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); > > -- > 1.7.1 > -- Kirill A. Shutemov