Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2471130pxb; Sat, 28 Aug 2021 16:04:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSP35vrU2BUfYV98kD1JsGmSvxpoc4nkWZaoGSII04B42F0TNFauQXFbAMhrlfE+yUHPlA X-Received: by 2002:a17:906:1191:: with SMTP id n17mr5058251eja.244.1630191872093; Sat, 28 Aug 2021 16:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630191872; cv=none; d=google.com; s=arc-20160816; b=n6n0IFGrO9ozX891F1ACPt+pKvsnF9Tyy/TRm08XtDRQ7vdQEqluO33bRQf3JqFOej RX5dABHokqV6JHd2/lj+j9UJvEN4+F1qWyKWaIAMP3rUtF2s55wwLiz5WEEETYJkxUiu Uu7tT+29d/X9HNXH4arWDCYqPH49Sqko54WgFUXl2toyhspvAUbFGZnN0Frv5ogtFvEN 8egSn4H0gTsc2j8EeBhcZ3wr6MO02I4dnR/weuyi0d8TGFei5o7hUoOLn5JhoAXv7Sx4 KT5Lr1K5g461VDIZnQpIn4lj8ImAh/2VTguSqLjst5Ocf5sbU5qUc3L4yM5SzFVCr/fl l+IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=y4UBsU1KwZ7j55l/INnQyJEH30djlY4QrTdxFdOiJjc=; b=XKNkp71Lh07MgBy38TmtB7Vyg69sjEVbrQ6zl3x64m3WD2p/7D8OLyrLVXRyGdVX2I HprUyEpKIvi14K8hiuu9248NslCOldaHNzNzPz4FM/Yf+6er8/c6aTXM0oDhnEllvo0K CVf1yBAYVLwqbBZvT+cSeK94Uy9BywpFb2TyaypCDEGmQxuOHT0wx3inssYZUkQ7XXP+ CterTq1i8ustlruPQU5zdSDWtRf8mntd05HDyZbeKGkfxCNWz9AvS+TuE01G9PQCDnxy ATalnr9Fi+RYuATTiYD4v+Jo336aSavH+/x1mkV0DI/b8SeeSX+yiXKKBFuulKN6Owdu q+dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hc39si9765322ejc.485.2021.08.28.16.04.03; Sat, 28 Aug 2021 16:04:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233009AbhH1WwV (ORCPT + 99 others); Sat, 28 Aug 2021 18:52:21 -0400 Received: from zeniv-ca.linux.org.uk ([142.44.231.140]:36524 "EHLO zeniv-ca.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231673AbhH1WwU (ORCPT ); Sat, 28 Aug 2021 18:52:20 -0400 Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mK7AL-00GuHv-Of; Sat, 28 Aug 2021 22:51:09 +0000 Date: Sat, 28 Aug 2021 22:51:09 +0000 From: Al Viro To: Thomas Gleixner Cc: "Luck, Tony" , Linus Torvalds , Andreas Gruenbacher , Christoph Hellwig , "Darrick J. Wong" , Jan Kara , Matthew Wilcox , cluster-devel , linux-fsdevel , Linux Kernel Mailing List , ocfs2-devel@oss.oracle.com, Borislav Petkov , x86@kernel.org Subject: Re: [PATCH v7 05/19] iov_iter: Introduce fault_in_iov_iter_writeable Message-ID: References: <20210827232246.GA1668365@agluck-desk2.amr.corp.intel.com> <87r1edgs2w.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 28, 2021 at 10:19:04PM +0000, Al Viro wrote: > How about taking __clear_user() out of copy_fpregs_to_sigframe() > and replacing the call of fault_in_pages_writeable() with > if (!clear_user(buf_fx, fpu_user_xstate_size)) > goto retry; > return -EFAULT; > in the caller? Something like this (completely untested) Lift __clear_user() out of copy_fpregs_to_sigframe(), do not confuse EFAULT with X86_TRAP_PF, don't bother with fault_in_pages_writeable() (pointless, since now __clear_user() on error is not under pagefault_disable()). And don't bother with retries on anything other than #PF... diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index 5a18694a89b2..71c6621a262f 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -345,7 +346,7 @@ static inline int xsave_to_user_sigframe(struct xregs_state __user *buf) */ err = __clear_user(&buf->header, sizeof(buf->header)); if (unlikely(err)) - return -EFAULT; + return -X86_TRAP_PF; stac(); XSTATE_OP(XSAVE, buf, lmask, hmask, err); diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c index 445c57c9c539..611b9ed9c06b 100644 --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -135,18 +135,12 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame) static inline int copy_fpregs_to_sigframe(struct xregs_state __user *buf) { - int err; - if (use_xsave()) - err = xsave_to_user_sigframe(buf); - else if (use_fxsr()) - err = fxsave_to_user_sigframe((struct fxregs_state __user *) buf); + return xsave_to_user_sigframe(buf); + if (use_fxsr()) + return fxsave_to_user_sigframe((struct fxregs_state __user *) buf); else - err = fnsave_to_user_sigframe((struct fregs_state __user *) buf); - - if (unlikely(err) && __clear_user(buf, fpu_user_xstate_size)) - err = -EFAULT; - return err; + return fnsave_to_user_sigframe((struct fregs_state __user *) buf); } /* @@ -205,9 +199,10 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size) fpregs_unlock(); if (ret) { - if (!fault_in_pages_writeable(buf_fx, fpu_user_xstate_size)) + if (!__clear_user(buf_fx, fpu_user_xstate_size) && + ret == -X86_TRAP_PF) goto retry; - return -EFAULT; + return -1; } /* Save the fsave header for the 32-bit frames. */ @@ -275,7 +270,7 @@ static int restore_fpregs_from_user(void __user *buf, u64 xrestore, fpregs_unlock(); /* Try to handle #PF, but anything else is fatal. */ - if (ret != -EFAULT) + if (ret != -X86_TRAP_PF) return -EINVAL; ret = fault_in_pages_readable(buf, size);