From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752552AbbCOQws (ORCPT ); Sun, 15 Mar 2015 12:52:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36182 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752453AbbCOQwr (ORCPT ); Sun, 15 Mar 2015 12:52:47 -0400 Date: Sun, 15 Mar 2015 17:50:36 +0100 From: Oleg Nesterov To: Dave Hansen , Borislav Petkov , Ingo Molnar Cc: Andy Lutomirski , Linus Torvalds , Pekka Riikonen , Rik van Riel , Suresh Siddha , LKML , "Yu, Fenghua" , Quentin Casasnovas , "H. Peter Anvin" Subject: [PATCH RFC 2/2] x86/fpu: change xsave_user() and xrestore_user() to use __user_insn() Message-ID: <20150315165036.GC28149@redhat.com> References: <54F74F59.5070107@intel.com> <20150315164948.GA28149@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150315164948.GA28149@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 Change xsave_user() and xrestore_user() to avoid the (imho) horrible and should-die xstate_fault helper, they both can use __user_insn(). This also removes the "memory" clobber but I think it was never needed. xrestore_user() doesn't change the memory, it only changes the FPU regs. xsave_user() does write to "*buf" but this memory is "__user", we must never access it directly. This patch adds '"=m" (*buf)' in both cases, but this is only because currently __user_insn() needs the non-empty "output" arg. Note: I think we can change all other xstate_fault users too, including alternative_input's. Signed-off-by: Oleg Nesterov --- arch/x86/include/asm/xsave.h | 19 +++++-------------- 1 files changed, 5 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h index 5fa9770..441f171 100644 --- a/arch/x86/include/asm/xsave.h +++ b/arch/x86/include/asm/xsave.h @@ -229,12 +229,8 @@ static inline int xsave_user(struct xsave_struct __user *buf) if (unlikely(err)) return -EFAULT; - __asm__ __volatile__(ASM_STAC "\n" - "1:"XSAVE"\n" - "2: " ASM_CLAC "\n" - xstate_fault - : "D" (buf), "a" (-1), "d" (-1), "0" (0) - : "memory"); + err = __user_insn(XSAVE, "=m" (*buf), /* unneeded */ + "D" (buf), "a" (-1), "d" (-1)); return err; } @@ -243,17 +239,12 @@ static inline int xsave_user(struct xsave_struct __user *buf) */ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask) { - int err = 0; - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf); u32 lmask = mask; u32 hmask = mask >> 32; + int err; - __asm__ __volatile__(ASM_STAC "\n" - "1:"XRSTOR"\n" - "2: " ASM_CLAC "\n" - xstate_fault - : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0) - : "memory"); /* memory required? */ + err = __user_insn(XRSTOR, "=m" (*buf), /* unneeded */ + "D" (buf), "a" (lmask), "d" (hmask)); return err; } -- 1.5.5.1