Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3839157pxv; Mon, 19 Jul 2021 09:59:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHwdAd3pr03JxdQ6SqqFxa95LS/mgk+6QWNgCOhk2SlkN+3ZtWEjUrmxHt466TQMCIshLI X-Received: by 2002:a6b:f813:: with SMTP id o19mr18951984ioh.49.1626713950607; Mon, 19 Jul 2021 09:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626713950; cv=none; d=google.com; s=arc-20160816; b=lSlicnFQ1WowAPpyInTh2v2t/orJMWAEOHWF/zRCiMfyS86kbtvhoih5jYgcXcszCC O1lI+WNCgv2wvvtnrnf1OJPdzR0xMdkgF9U92OvvalqzM7WOFTF0R+/ZSxrWsyvC+G5R 25PlNbrQAhK9jUGX/PE4q8N/ofGkxLnBBT61W/+tknml7ajz7bgSp6c+pIZ39foBmy86 uXtRx92pi6CE8kfbfJWQzunMW08pozu6cE3RxB2pka0U9x5cNy99rteqSpWXjQZBfzfz I8GtkLDTbUb2UG/nHi02hugITanmDqsJKiE8JKktH/jTbi65s9S0ntATVv0NowGpubKG CrjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3b/Nj11oKFLnADZZ6t0IqTwS6QgpoPeHCoMYFESuwEQ=; b=cTFdWt3oCIa2LWGf/UBhS97gnjh+yEkCnBnpSR7d5sY4o820FoffhZzX+DG+g24ti1 OUAY4L0NNjlxvP2cWyCKakloOT/DN2VmPqnLk4/7zAFmWCm9JSd1DJPxSkQoH92VY1rX 0SGuN7wcKF3sTE7rzmEwvU7r4Ee5Rdr0wtg1vK/Etx5SX5Ukl7qF9cMKfRCQ7BXc/aIN V4j9Bk/KMat7UM1Kw68xKVyQjP1GljYqlsUcRe8HwwW2yJW7l9jp0zzEljdP2vwkkftI b8qOvsWUv3Bc2xRvb9ZCzUNXPLjw9h4qASoPkOwAwdplUhudyAqPZ7XcbDoyb45vnkqe A71A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QWm7JvXL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si19958094ils.118.2021.07.19.09.58.58; Mon, 19 Jul 2021 09:59:10 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QWm7JvXL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351608AbhGSQQG (ORCPT + 99 others); Mon, 19 Jul 2021 12:16:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:41086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345495AbhGSPJZ (ORCPT ); Mon, 19 Jul 2021 11:09:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5DCF360FED; Mon, 19 Jul 2021 15:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626709748; bh=VN4Y+FpsP27Ub+rsgDyJmi/V48KYLIuW8ep61SNb5gc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QWm7JvXLokyKxGGbB6pWsiQTHZw/59BHnzgr5lVwYbRx5AxgoO6ul0gZFGUmoILH/ l1gP5DVpLtKs8R364UtJyTJ1rHshidA9ND6wMaGL7AJn6esRTkiOo/aFR6qkIsUGr7 uD0R6NaoRvSSBTaz2Ws/Md+ELpXUmcVXztSMCM94= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov , Sasha Levin Subject: [PATCH 5.4 082/149] x86/fpu: Return proper error codes from user access functions Date: Mon, 19 Jul 2021 16:53:10 +0200 Message-Id: <20210719144920.784633435@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144901.370365147@linuxfoundation.org> References: <20210719144901.370365147@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner [ Upstream commit aee8c67a4faa40a8df4e79316dbfc92d123989c1 ] When *RSTOR from user memory raises an exception, there is no way to differentiate them. That's bad because it forces the slow path even when the failure was not a fault. If the operation raised eg. #GP then going through the slow path is pointless. Use _ASM_EXTABLE_FAULT() which stores the trap number and let the exception fixup return the negated trap number as error. This allows to separate the fast path and let it handle faults directly and avoid the slow path for all other exceptions. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20210623121457.601480369@linutronix.de Signed-off-by: Sasha Levin --- arch/x86/include/asm/fpu/internal.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index 9f135e5b9cf5..a9d1dd82d820 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -102,6 +102,7 @@ static inline void fpstate_init_fxstate(struct fxregs_state *fx) } extern void fpstate_sanitize_xstate(struct fpu *fpu); +/* Returns 0 or the negated trap number, which results in -EFAULT for #PF */ #define user_insn(insn, output, input...) \ ({ \ int err; \ @@ -109,14 +110,14 @@ extern void fpstate_sanitize_xstate(struct fpu *fpu); might_fault(); \ \ asm volatile(ASM_STAC "\n" \ - "1:" #insn "\n\t" \ + "1: " #insn "\n" \ "2: " ASM_CLAC "\n" \ ".section .fixup,\"ax\"\n" \ - "3: movl $-1,%[err]\n" \ + "3: negl %%eax\n" \ " jmp 2b\n" \ ".previous\n" \ - _ASM_EXTABLE(1b, 3b) \ - : [err] "=r" (err), output \ + _ASM_EXTABLE_FAULT(1b, 3b) \ + : [err] "=a" (err), output \ : "0"(0), input); \ err; \ }) @@ -210,16 +211,20 @@ static inline void copy_fxregs_to_kernel(struct fpu *fpu) #define XRSTOR ".byte " REX_PREFIX "0x0f,0xae,0x2f" #define XRSTORS ".byte " REX_PREFIX "0x0f,0xc7,0x1f" +/* + * After this @err contains 0 on success or the negated trap number when + * the operation raises an exception. For faults this results in -EFAULT. + */ #define XSTATE_OP(op, st, lmask, hmask, err) \ asm volatile("1:" op "\n\t" \ "xor %[err], %[err]\n" \ "2:\n\t" \ ".pushsection .fixup,\"ax\"\n\t" \ - "3: movl $-2,%[err]\n\t" \ + "3: negl %%eax\n\t" \ "jmp 2b\n\t" \ ".popsection\n\t" \ - _ASM_EXTABLE(1b, 3b) \ - : [err] "=r" (err) \ + _ASM_EXTABLE_FAULT(1b, 3b) \ + : [err] "=a" (err) \ : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ : "memory") -- 2.30.2