From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757510AbbCPOhn (ORCPT ); Mon, 16 Mar 2015 10:37:43 -0400 Received: from cantor2.suse.de ([195.135.220.15]:42717 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754093AbbCPOhj (ORCPT ); Mon, 16 Mar 2015 10:37:39 -0400 Date: Mon, 16 Mar 2015 15:36:05 +0100 From: Borislav Petkov To: Oleg Nesterov Cc: Dave Hansen , Ingo Molnar , Andy Lutomirski , Linus Torvalds , Pekka Riikonen , Rik van Riel , Suresh Siddha , LKML , "Yu, Fenghua" , Quentin Casasnovas , "H. Peter Anvin" Subject: Re: [PATCH RFC 0/2] x86/fpu: avoid "xstate_fault" in xsave_user/xrestore_user Message-ID: <20150316143605.GL22995@pd.tnic> References: <54F74F59.5070107@intel.com> <20150315164948.GA28149@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150315164948.GA28149@redhat.com> 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 On Sun, Mar 15, 2015 at 05:49:48PM +0100, Oleg Nesterov wrote: > Hello. > > Another a bit off-topic change, but I'd like to finish the discussion > with Quentin. > > And almost cosmetic. But I added the RFC tag to make it clear that this > needs a review from someone who understands gcc-asm better. In particular > I am worried if that dummy "=m" (*buf) is actually correct. > > > And I agree with Quentin, user_insn/check_insn can be improved to allow > clobbers, more flexible "output", etc. But imo they already can make this > code look a bit better, and "xstate_fault" must die eventually. FWIW, I did poke at that but there's still something wrong with my macros, will take a look when I get a chance: --- arch/x86/include/asm/xsave.h | 130 +++++++++++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 48 deletions(-) diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h index c9a6d68b8d62..a35e9d49843d 100644 --- a/arch/x86/include/asm/xsave.h +++ b/arch/x86/include/asm/xsave.h @@ -67,6 +67,51 @@ extern int init_fpu(struct task_struct *child); _ASM_EXTABLE(1b, 3b) \ : [err] "=r" (err) +#define XSTATE_OP(op, st, lmask, hmask, err) \ + asm volatile("1:" op "\n\t" \ + "2:\n\t" \ + ".pushsection .fixup,\"ax\"\n\t" \ + "3: movl $-1,%[err]\n\t" \ + "jmp 2b\n\t" \ + ".popsection\n\t" \ + _ASM_EXTABLE(1b, 3b) \ + : [err] "=r" (err) \ + : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ + : "memory") + +/* + * 661 and alt_end_marker labels below are defined in ALTERNATIVE* + * and we're reusing them here so as not to clutter this macro + * unnecessarily. + */ +#define XSTATE_XSAVE(st, lmask, hmask, err) \ + asm volatile(ALTERNATIVE_2(XSAVE, \ + XSAVEOPT, X86_FEATURE_XSAVEOPT, \ + XSAVES, X86_FEATURE_XSAVES) \ + "\n" \ + ".pushsection .fixup,\"ax\"\n" \ + "3: movl $-1, %[err]\n" \ + "jmp " alt_end_marker "b\n" \ + ".popsection\n" \ + _ASM_EXTABLE(661b, 3b) \ + : [err] "=r" (err) \ + : "D" (st), "a" (lmask), "d" (hmask) \ + : "memory") + +#define XSTATE_XRESTORE(st, lmask, hmask, err) \ + asm volatile(ALTERNATIVE(XRSTOR, \ + XRSTORS, X86_FEATURE_XSAVES) \ + "\n" \ + ".pushsection .fixup,\"ax\"\n" \ + "3: movl $-1, %[err]\n" \ + "jmp 663b\n" \ + ".popsection\n" \ + _ASM_EXTABLE(661b, 3b) \ + : [err] "=r" (err) \ + : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ + : "memory") + + /* * This function is called only during boot time when x86 caps are not set * up and alternative can not be used yet. @@ -77,20 +122,11 @@ static inline int xsave_state_booting(struct xsave_struct *fx, u64 mask) u32 hmask = mask >> 32; int err = 0; - WARN_ON(system_state != SYSTEM_BOOTING); - - if (boot_cpu_has(X86_FEATURE_XSAVES)) - asm volatile("1:"XSAVES"\n\t" - "2:\n\t" - xstate_fault - : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask) - : "memory"); + if (static_cpu_has_safe(X86_FEATURE_XSAVES)) + XSTATE_OP(XSAVES, fx, lmask, hmask, err); else - asm volatile("1:"XSAVE"\n\t" - "2:\n\t" - xstate_fault - : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask) - : "memory"); + XSTATE_OP(XSAVE, fx, lmask, hmask, err); + return err; } ... To be continued... -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. --