From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754151AbbKQOHK (ORCPT ); Tue, 17 Nov 2015 09:07:10 -0500 Received: from www.linutronix.de ([62.245.132.108]:48919 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752679AbbKQOHH (ORCPT ); Tue, 17 Nov 2015 09:07:07 -0500 Date: Tue, 17 Nov 2015 15:06:20 +0100 (CET) From: Thomas Gleixner To: "Jason A. Donenfeld" cc: mingo@redhat.com, hpa@zytor.com, LKML Subject: Re: irq_fpu_usable() is irreliable In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jason, On Tue, 17 Nov 2015, Jason A. Donenfeld wrote: > The availability of the FPU in kernel space, as you know, is determined by > this function: > > bool irq_fpu_usable(void) > { > return !in_interrupt() || > interrupted_user_mode() || > interrupted_kernel_fpu_idle(); > } > > My understanding is that the first check is !in_interrupt(), because if > `current` is valid - if we are in process context - then we have a place to > store the existing FPU regs in kernel_fpu_begin, to be restored later in > kernel_fpu_end. Recently I've been tracking down a problem in > which irq_fpu_usable() returns false, yet a stack trace shows the first > function is the syscall entry point. This leads me to believe that > in_interrupt() is not an adequate way of testing for a valid `current`. This function has absolute nothing to do with current. current is always valid. The function checks whether we can use the fpu safely in kernel context. > In my particular problematic case, the reason in_interrupt() was > returning false is because a number of rcu_read_lock_bh()s were > being held; IOW this is occurring in the ndo_start_xmit path of a > network driver. > > I therefore propose changing the function to this: > > bool irq_fpu_usable(void) > { > return (!in_irq() && !in_nmi()) || > interrupted_user_mode() || > interrupted_kernel_fpu_idle(); > } > > What would you think of that? That's broken. Assume we interrupted a kernel thread which fiddles with the FPU and then on irq exit we run a softirq which tries to use the FPU.... The real question in your case is WHY interrupted_kernel_fpu_idle() returns false. We know for sure that in a syscall with BH disabled the first two checks are false. Thanks, tglx