From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756326AbbEFC5v (ORCPT ); Tue, 5 May 2015 22:57:51 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:35153 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756281AbbEFC5o (ORCPT ); Tue, 5 May 2015 22:57:44 -0400 Date: Wed, 6 May 2015 04:57:40 +0200 From: Ingo Molnar To: Borislav Petkov Cc: linux-kernel@vger.kernel.org, Andy Lutomirski , Dave Hansen , Fenghua Yu , "H. Peter Anvin" , Linus Torvalds , Oleg Nesterov , Thomas Gleixner Subject: Re: [PATCH 176/208] x86/alternatives, x86/fpu: Add 'alternatives_patched' debug flag and use it in xsave_state() Message-ID: <20150506025740.GC29486@gmail.com> References: <1430848712-28064-1-git-send-email-mingo@kernel.org> <1430848712-28064-16-git-send-email-mingo@kernel.org> <20150505224759.GT3910@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150505224759.GT3910@pd.tnic> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Borislav Petkov wrote: > On Tue, May 05, 2015 at 07:58:00PM +0200, Ingo Molnar wrote: > > We'd like to use xsave_state() earlier, but its SYSTEM_BOOTING check > > is too imprecise. > > > > The real condition that xsave_state() would like to check is whether > > alternative XSAVE instructions were patched into the kernel image > > already. > > > > Add such a (read-mostly) debug flag and use it in xsave_state(). > > > > Cc: Andy Lutomirski > > Cc: Borislav Petkov > > Cc: Dave Hansen > > Cc: Fenghua Yu > > Cc: H. Peter Anvin > > Cc: Linus Torvalds > > Cc: Oleg Nesterov > > Cc: Thomas Gleixner > > Signed-off-by: Ingo Molnar > > --- > > arch/x86/include/asm/alternative.h | 6 ++++++ > > arch/x86/include/asm/fpu/xstate.h | 2 +- > > arch/x86/kernel/alternative.c | 5 +++++ > > 3 files changed, 12 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h > > index ba32af062f61..7bfc85bbb8ff 100644 > > --- a/arch/x86/include/asm/alternative.h > > +++ b/arch/x86/include/asm/alternative.h > > @@ -52,6 +52,12 @@ struct alt_instr { > > u8 padlen; /* length of build-time padding */ > > } __packed; > > > > +/* > > + * Debug flag that can be tested to see whether alternative > > + * instructions were patched in already: > > + */ > > +extern int alternatives_patched; > > Looks useful... > > > + > > extern void alternative_instructions(void); > > extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end); > > > > diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h > > index 31a002ad5aeb..ab2c507b58b6 100644 > > --- a/arch/x86/include/asm/fpu/xstate.h > > +++ b/arch/x86/include/asm/fpu/xstate.h > > @@ -119,7 +119,7 @@ static inline int xsave_state(struct xsave_struct *fx) > > u32 hmask = mask >> 32; > > int err = 0; > > > > - WARN_ON(system_state == SYSTEM_BOOTING); > > + WARN_ON(!alternatives_patched); > > Btw, shouldn't we be doing this check in what is called now > copy_kernel_to_xregs() too, i.e., right under this function which is now > called copy_xregs_to_kernel()? Yeah, makes sense - and we can now use WARN_ON_FPU() as well to not have the overhead when debugging is disabled. Thanks, Ingo