Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1757895imu; Wed, 28 Nov 2018 14:47:29 -0800 (PST) X-Google-Smtp-Source: AJdET5fs5R75eSbn5uX2pN20c7CDrgmy3raEwrYHwANcXox4aUqJU1fFe/lmmVyguAzLZTaWF8om X-Received: by 2002:a62:19d5:: with SMTP id 204mr39477114pfz.33.1543445249474; Wed, 28 Nov 2018 14:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543445249; cv=none; d=google.com; s=arc-20160816; b=kj6ffJgY4431D1buOip688ZcVVDPIJRLMDg+TdOhsujx3/UyoVfO6j56u9zN0gNWSC qpo7zLwCaK1k3586ThUSVmhh0R0cHcC/Ne8m18/bI65OI3kaqmMOOwK8j7nrDwAM01Eq Rs6+ShahNlyxYEz3978gXNuSMEIDRO08+spLHiGcrF0dAcR5O1q0HNMprKQdpqWNwqcL lSISHk1y252Wj40E3MqX5CIFj7zhiQ7m4Rw43ZnEd3OsWoOukvOUP4eP4Iw/ao5eqKCn L44cfcO/Kfdw7BRGy+I9V7OV+463U7QRw+nx4TufSCpP/K/wAI8DPwGf2uvzHWNBzRY7 gW4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hdPNHDDN1UElHQAi/K7xn0PfbJB3Rlc7oaiKizHJCOM=; b=oQmQD7Np3IuGFvD7VgUefA8W9jCE7nHoPf4uOmmj5eWeiRFE+aVymvFrgHr4Nr91hV tTwrDpttNeDvsUTi8NzUZOG0hYuFR72BFAA0AKGH+s+8hNhSEmcmVzsDHIAeBsNhVM/g +/zyzMeHd0JWK8eLKnxF9HfUsddN8kWxiOUPp2GiKiEuDXtyP4a8H7hu/adWV6g/n03V OgtuZNC2xhR2+pZKifkXFUtKxAQ1ApauLAZh9kzP5JA3h8gefEd8/r0Lg2Cmq7hX0WSp rMu8XEPg2OKfHzVh/SkXBxZekL7oO4Oq7OAHcnJXIWB/tLnoTBYVG/AAS6ym8gLR3/x5 2WAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si8957277pgi.443.2018.11.28.14.47.11; Wed, 28 Nov 2018 14:47:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727366AbeK2JYn (ORCPT + 99 others); Thu, 29 Nov 2018 04:24:43 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:33238 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbeK2JYm (ORCPT ); Thu, 29 Nov 2018 04:24:42 -0500 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1gS8D1-0001GX-NL; Wed, 28 Nov 2018 23:21:28 +0100 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Andy Lutomirski , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel , Dave Hansen , Sebastian Andrzej Siewior Subject: [PATCH 26/29] x86/fpu: Inline copy_user_to_fpregs_zeroing() Date: Wed, 28 Nov 2018 23:20:32 +0100 Message-Id: <20181128222035.2996-27-bigeasy@linutronix.de> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181128222035.2996-1-bigeasy@linutronix.de> References: <20181128222035.2996-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Start refactoring __fpu__restore_sig() by inlining copy_user_to_fpregs_zeroing(). Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/kernel/fpu/signal.c | 42 ++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c index 6e516eeaea328..c66356b168b39 100644 --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -221,28 +221,6 @@ sanitize_restored_xstate(union fpregs_state *state, } } -/* - * Restore the extended state if present. Otherwise, restore the FP/SSE state. - */ -static inline int copy_user_to_fpregs_zeroing(void __user *buf, u64 xbv, int fx_only) -{ - if (use_xsave()) { - if ((unsigned long)buf % 64 || fx_only) { - u64 init_bv = xfeatures_mask & ~XFEATURE_MASK_FPSSE; - copy_kernel_to_xregs(&init_fpstate.xsave, init_bv); - return copy_user_to_fxregs(buf); - } else { - u64 init_bv = xfeatures_mask & ~xbv; - if (unlikely(init_bv)) - copy_kernel_to_xregs(&init_fpstate.xsave, init_bv); - return copy_user_to_xregs(buf, xbv); - } - } else if (use_fxsr()) { - return copy_user_to_fxregs(buf); - } else - return copy_user_to_fregs(buf); -} - static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size) { int ia32_fxstate = (buf != buf_fx); @@ -321,11 +299,29 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size) kfree(tmp); return err; } else { + int ret; + /* * For 64-bit frames and 32-bit fsave frames, restore the user * state to the registers directly (with exceptions handled). */ - if (copy_user_to_fpregs_zeroing(buf_fx, xfeatures, fx_only)) { + if (use_xsave()) { + if ((unsigned long)buf_fx % 64 || fx_only) { + u64 init_bv = xfeatures_mask & ~XFEATURE_MASK_FPSSE; + copy_kernel_to_xregs(&init_fpstate.xsave, init_bv); + ret = copy_user_to_fxregs(buf_fx); + } else { + u64 init_bv = xfeatures_mask & ~xfeatures; + if (unlikely(init_bv)) + copy_kernel_to_xregs(&init_fpstate.xsave, init_bv); + ret = copy_user_to_xregs(buf_fx, xfeatures); + } + } else if (use_fxsr()) { + ret = copy_user_to_fxregs(buf_fx); + } else + ret = copy_user_to_fregs(buf_fx); + + if (ret) { fpu__clear(fpu); return -1; } -- 2.20.0.rc1