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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 5CE0EC432BE for ; Mon, 30 Aug 2021 22:01:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E8C560ED6 for ; Mon, 30 Aug 2021 22:01:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238759AbhH3WCc (ORCPT ); Mon, 30 Aug 2021 18:02:32 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:55034 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229887AbhH3WCb (ORCPT ); Mon, 30 Aug 2021 18:02:31 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1630360896; 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: in-reply-to:in-reply-to:references:references; bh=nmaQ9EYP/RanOcLyCAKUVbgRCdBpSu5eePr9qPV/r/Q=; b=N5/OS1oP5Svn4voy7opArs0XjL1bUuHxvTnlbIbX2T5UjcrgTJ9w6s8tM7+Ow7Qh36l6zt oE5Fst5Cv7GFxbffdk4Wtlb63c6iqcaRO8aI2SfFUX9Ek7idrpQ2v+MWqnG9Jjuh+HYUmL bThR0+yLh9+JeoGYJeVnOTEW0EItn6Z9BWRUpoy6ZmXXlDXD16Ugd5HhjVmlZG8hk0khS7 ecRitnK9oz/GBpN96GqfXXCgQ5EHuY829jSB9mdJXH+QRiTeqAh7zrK+sxpn++aQpiny6B DAmQROfqq+SgrgJabQzlqp5VckPyVF0Xe0N79y7jhckyTAqsTd0DVh47YjeqrA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1630360896; 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: in-reply-to:in-reply-to:references:references; bh=nmaQ9EYP/RanOcLyCAKUVbgRCdBpSu5eePr9qPV/r/Q=; b=Y5MLms6tTE9Dd1U41LWFW9aMtzgoYj6puIht9IkGsxxBEOS2+O8dUQEBoqHHdi1bx1h1Lc JG0AZKs4qakw41Ag== To: Linus Torvalds , Al Viro , Dan Williams Cc: Borislav Petkov , LKML , the arch/x86 maintainers Subject: Re: [patch 01/10] x86/fpu/signal: Clarify exception handling in restore_fpregs_from_user() In-Reply-To: References: <20210830154702.247681585@linutronix.de> <20210830162545.374070793@linutronix.de> <87zgsyg0eg.ffs@tglx> Date: Tue, 31 Aug 2021 00:01:35 +0200 Message-ID: <87r1eafv7k.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 30 2021 at 14:26, Linus Torvalds wrote: > On Mon, Aug 30, 2021 at 2:07 PM Al Viro wrote: >> >> Incidentally, why do we bother with negation in those? Why not have >> user_insn(), XSTATE_OP() and kernel_insn_err() return 0 or trap >> number... Correct. > I really wish we didn't have that odd _ASM_EXTABLE_FAULT/ > ex_handler_fault() special case at all. > > It's *very* confusing, and it actually seems to be mis-used. It looks > like the "copy_mc_fragile" code uses it by mistake, and doesn't > actually want that "modify %%rax" behavior of that exception handler > AT ALL. > > If I read that code correctly, it almost by mistake doesn't actually > care, and will overwrite %%rax with the right result, but it doesn't > look like the "fault code in %eax" was ever *intentional*. There's no > mention of it. > > Maybe I'm misreading that code, but I look at it and just go "Whaa?" Ooops. I never looked at that usage site. It indeed does not make use of that information. The original __mcsafe_copy() made use of it, but that got removed/replaced long ago. The other user is SGX which actually uses the trap number in EAX for failure analysis. > The code in user_insn() clearly *does* use that fault number (and, as > you say, inverts it for some reason), but I wonder how much it really > cares? Could we get rid of it, and just set a fixed error code? > > I only checked one user, but that one didn't actually care which fault > it was, it only cared about fault-vs-no-fault. The usage sites of user_insn() and XSTATE_OP() need to distinguish: - success - fail due to #PF (which can be tried to handle) - fail due to some other exception (#GP, #MC) I found that _ASM_EXTABLE_FAULT() mechanism pretty conveniant for this and the negation was just me being lazy after I discovered that X86_TRAP_PF == EFAULT. It turned out not to be a brilliant idea, but at the time it looked great... So yes, the negation does not matter, but the ability to check whether the fail was caused by #PF or not matters. Thanks, tglx