From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751738AbbCEV1h (ORCPT ); Thu, 5 Mar 2015 16:27:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39934 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750941AbbCEV1f (ORCPT ); Thu, 5 Mar 2015 16:27:35 -0500 Date: Thu, 5 Mar 2015 22:25:32 +0100 From: Oleg Nesterov To: Ingo Molnar Cc: Dave Hansen , Borislav Petkov , Andy Lutomirski , Linus Torvalds , Pekka Riikonen , Rik van Riel , Suresh Siddha , LKML , "Yu, Fenghua" , Quentin Casasnovas Subject: Re: [PATCH 1/1] x86/fpu: math_state_restore() should not blindly disable irqs Message-ID: <20150305212532.GA16890@redhat.com> References: <54F74F59.5070107@intel.com> <20150305195127.GA12657@redhat.com> <20150305195149.GB12657@redhat.com> <20150305201101.GA21571@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150305201101.GA21571@gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/05, Ingo Molnar wrote: > > * Oleg Nesterov wrote: > > > --- a/arch/x86/kernel/traps.c > > +++ b/arch/x86/kernel/traps.c > > @@ -774,7 +774,10 @@ void math_state_restore(void) > > struct task_struct *tsk = current; > > > > if (!tsk_used_math(tsk)) { > > - local_irq_enable(); > > + bool disabled = irqs_disabled(); > > + > > + if (disabled) > > + local_irq_enable(); > > /* > > * does a slab alloc which can sleep > > */ > > @@ -785,7 +788,9 @@ void math_state_restore(void) > > do_group_exit(SIGKILL); > > return; > > } > > - local_irq_disable(); > > + > > + if (disabled) > > + local_irq_disable(); > > } > > Yuck! > > Is there a fundamental reason why we cannot simply enable irqs and > leave them enabled? Math state restore is not atomic and cannot really > be atomic. You know, I didn't even try to verify ;) but see below. Most probably we can simply enable irqs, yes. But what about older kernels, how can we check? And let me repeat, I strongly believe that this !tsk_used_math() case in math_state_restore() must die. And unlazy_fpu() in init_fpu(). And both __restore_xstate_sig() and flush_thread() should not use math_state_restore() at all. At least in its current form. But this is obviously not -stable material. That said, I'll try to look into git history tomorrow. The patch above looks "obviously safe", but perhaps I am paranoid too much... Oleg.