From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757952AbbA2Uqw (ORCPT ); Thu, 29 Jan 2015 15:46:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50956 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757017AbbA2Uqv (ORCPT ); Thu, 29 Jan 2015 15:46:51 -0500 Date: Thu, 29 Jan 2015 21:45:34 +0100 From: Oleg Nesterov To: Rik van Riel Cc: "H. Peter Anvin" , Suresh Siddha , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Fenghua Yu , the arch/x86 maintainers , linux-kernel Subject: Re: question about save_xstate_sig() - WHY DOES THIS WORK? Message-ID: <20150129204534.GA30530@redhat.com> References: <54C2A245.4010307@redhat.com> <20150124202021.GA1285@redhat.com> <54C6CD64.10208@redhat.com> <20150127194030.GA29879@redhat.com> <54C7F4BB.5020509@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54C7F4BB.5020509@redhat.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 01/27, Rik van Riel wrote: > > On 01/27/2015 02:40 PM, Oleg Nesterov wrote: > >>> > >>> - Is unlazy_fpu()->__save_init_fpu() safe wrt > >>> __kernel_fpu_begin() from irq? > > It looks like it should be safe, as long as __save_init_fpu() > knows that the task no longer has the FPU after __kernel_fpu_end(), > so it does not try to save the kernel FPU state to the user's > task->thread.fpu.state->xstate Not sure this is enough, but... > The caveat here is that __kernel_fpu_begin()/__kernel_fpu_end() > needs to be kept from running during unlazy_fpu(). Yes, > This means interrupted_kernel_fpu_idle and/or irq_fpu_usable > need to check whether preemption is disabled, and lock out > __kernel_fpu_begin() when preemption is disabled. But we already have kernel_fpu_disable/enable. unlazy_cpu() can use it to avoid the race ? > I can certainly merge unlazy_fpu() and save_init_fpu() into the > same function, but I am not sure whether or not it should call > __thread_fpu_end() - it looks like that would be desirable in some > cases, but not in others... I _think_ that we never actually want __thread_fpu_end(), although it doesn't really hurt if !eager. Probably ulazy/save should do if (!__save_init_fpu()) __thread_fpu_end(); But again, this is minor. Oleg.