From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: BUG: sleeping function called from invalid context at mm/slub.c:793 Date: Thu, 13 Jan 2011 13:59:03 +0100 Message-ID: <4D2EF717.8080604@siemens.com> 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=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: "Kirill A. Shutemov" , 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: In-Reply-To: <4D2C3115.9030301@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org Am 11.01.2011 11:29, Avi Kivity wrote: > Please try out the attached patch. > > 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; > + Could become a rainy day for the kvm-kmod maintainer: For compat support on kernels without init_fpu exported yet, can I trigger the same result by simply issuing an FPU instruction here so that do_device_not_available will perform the allocation? Not really nice, but it doesn't appear to me like there is any code path that would complain about in-kernel FPU usage (provided we don't need math emulation - which is quite likely). Jan -- Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux