From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F02AC49361 for ; Fri, 18 Jun 2021 15:26:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 196946127C for ; Fri, 18 Jun 2021 15:26:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235335AbhFRP2G (ORCPT ); Fri, 18 Jun 2021 11:28:06 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:56454 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235100AbhFRPXd (ORCPT ); Fri, 18 Jun 2021 11:23:33 -0400 Message-Id: <20210618143451.682092608@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1624029637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=qYd0qw4ZVzYh7yNprnuEvT0RODoBW7zuFTXQuUEQqgk=; b=BlwqvaxMpexmQ5ky1mwCWGAmyZIOOpoHY1NpXZYUpLWlRg1LQ1HohU1Zq/R5rKFzAbOfEc 49BxRChG3BeXyzaLbG/SntOyyoad8yhABIF4XxUNESwfCQtQZkQpCnL/bU1mKL2ZtaqMdp yIg/zzZPmDbC1y0tQozl30hOL8ZkUCr+78QnBUzOXBiJwYLtlRTQaur/4cSgmyyurYOXDJ 05TUrPfd6JUhBINuYIIpjJSpSH5M0wp1Dnz4Qdoc6qWsMTG4KY3RySiu+HjOsMMPZJjJ6K IF0pOX9MvqD69I0VMr3IQIyxNXN5j01Ag1+/czSmCHH20FQaCCDlN7nL5JqEtQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1624029637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=qYd0qw4ZVzYh7yNprnuEvT0RODoBW7zuFTXQuUEQqgk=; b=dOCTtpKcQRp3ELR6G1w5PJcnKR0VQ7uUf3vwDYH/tnqNoNxa61Hq1dK5SaZwwCkBZ0p0bH BtixLmwHBuhppFAQ== Date: Fri, 18 Jun 2021 16:19:27 +0200 From: Thomas Gleixner To: LKML Cc: Andy Lutomirski , Dave Hansen , Fenghua Yu , Tony Luck , Yu-cheng Yu , Sebastian Andrzej Siewior , Borislav Petkov , Peter Zijlstra , Kan Liang Subject: [patch V3 64/66] x86/fpu: Return proper error codes from user access functions References: <20210618141823.161158090@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 seperate the fast path and let it handle faults directly and avoid the slow path for all other exceptions. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/fpu/internal.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -87,6 +87,7 @@ extern void fpstate_init_soft(struct swr static inline void fpstate_init_soft(struct swregs_state *soft) {} #endif +/* Returns 0 or the negated trap number, which results in -EFAULT for #PF */ #define user_insn(insn, output, input...) \ ({ \ int err; \ @@ -94,14 +95,14 @@ static inline void fpstate_init_soft(str 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; \ })