Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp351644rwb; Fri, 4 Aug 2023 13:56:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtcNmkLfaJg29O1kln1TEgj0JhYooGjmrg0dVopgSUkkk2/KyO16TP9vNlXZqYqDTtU0Hq X-Received: by 2002:a17:902:dac6:b0:1bb:cd10:823a with SMTP id q6-20020a170902dac600b001bbcd10823amr3258090plx.39.1691182605403; Fri, 04 Aug 2023 13:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691182605; cv=none; d=google.com; s=arc-20160816; b=H0B0GxZgufec2qUXkkgdzBW9VSQvIJ9ww385e6grPTTby4oAUafHIyx2ClZdfV+hda GM5By2RdJ+NIZU9HK+BR8FIjLRRliGbYRndXlIf/RRtzSWUdL7DS6FN+hqjtP1UAAjGi ryDWVNbYYhMnnggsHsjNE0BCu//UIHhIF3ZzOmmR1W0jUPhpso7UrkfheEGkPXI/sYM1 jlKqY1O0GM9rCKNr8347DyyrCp0LqSpbP32dFwF025/CtAiVWUcjxsWNWRdYgVIpQvS3 Kygm28Y0PIlE4RDdXwX5qf4maX67NyIcAfzWibUPyd0/h5Dy6TQmtJ2Qe4FbkIgO7Zvc xOcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qVJ80sMcFC+VhDcYrAkI2SgTfMYHIJ7m/A06T6Wu06Q=; fh=MD6fDrpUxKahUjD+bW4GSNrj+BKB4ckPKjM9I2khTBY=; b=mZAwZUYGy0QBQ1pXlHzT84ZetsHxctcI9/1Bq3sscprcD+l8qFNzX4/HVjJvFfkIQf I0ulX1IK1FkgKJmof2pr7PJYKNSVH9BTjpPPOM2A4t25/3W08yMRSzYvtk96JFxqe0yG IdHebhhcBm5RbCPmguzf6g8GC6EJQhROxKfVeKeiuOsvZ742fbE5PTAlM4Ufn8GnwPBo flJISPGyaJ4sYONLyarfwBdDvu3oD6cqk/h6KlW1Tg/V+QeMrAIOhZ9iAcU1NGA0Atub hkbxyO9NyRxNuKh3OJqvljPZ1k9GBF5fuPv5qbXqN33eCRs7+4YYQwfuV7MBHNt/iN6W nRWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="hfKY/spE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k12-20020a170902c40c00b001b8a69660c1si2302384plk.88.2023.08.04.13.56.33; Fri, 04 Aug 2023 13:56:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="hfKY/spE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231144AbjHDTC4 (ORCPT + 99 others); Fri, 4 Aug 2023 15:02:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230347AbjHDTCe (ORCPT ); Fri, 4 Aug 2023 15:02:34 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69F1B5589 for ; Fri, 4 Aug 2023 12:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=qVJ80sMcFC+VhDcYrAkI2SgTfMYHIJ7m/A06T6Wu06Q=; b=hfKY/spEx8pQzuYmLSdq9dv+ju EYFl2ED+zOu6Mv2khT5qlOwja516BIIBhqMT3r/zi9lu6hIsIuoUw0bMw9HjPvKUqrfV3uMAvnG1f h//f5x7xEABRlxHBwLGdCly3AewzeXENjeUblyU2y5wR72h6zRh6TTHV9QUOS4dxuGUTP7XtB6rYF 8fkqXYfhcnQ0sZpGPcbt50Et/9WXTzGTSUOGp6srdNJQqx9taX0rm9HxRZzhEIGKHdFsyiZqwvQKY GbiXAbKL+HTKGvUNNuShKatS7IwrlDoy0NGqZjXaRH927d7WFo7U0oM1j8GX2hWmlIk17X+h6wZB6 Cdhp5gOA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qS037-000YFD-23; Fri, 04 Aug 2023 19:01:22 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 991C330007E; Fri, 4 Aug 2023 21:01:20 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7A46721FA7AFF; Fri, 4 Aug 2023 21:01:20 +0200 (CEST) Date: Fri, 4 Aug 2023 21:01:20 +0200 From: Peter Zijlstra To: "Li, Xin3" Cc: "linux-kernel@vger.kernel.org" , "xen-devel@lists.xenproject.org" , "Lutomirski, Andy" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "x86@kernel.org" , "H . Peter Anvin" , "Gross, Jurgen" , "Ostrovsky, Boris" Subject: Re: [RFC PATCH 1/1] x86/traps: Get rid of exception handlers' second argument error code Message-ID: <20230804190120.GP212435@hirez.programming.kicks-ass.net> References: <20230804075734.8372-1-xin3.li@intel.com> <20230804101321.GH214207@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 04, 2023 at 05:35:11PM +0000, Li, Xin3 wrote: > > > The IDT event delivery of X86_TRAP_DF, X86_TRAP_TS, X86_TRAP_NP, > > > X86_TRAP_SS, X86_TRAP_GP, X86_TRAP_AC and X86_TRAP_CP pushes an error > > > code into the orig_ax member of the pt_regs structure, and the error > > > code is passed as the second argument of their C-handlers, although > > > the pt_regs structure is already passed as the first argument. > > > > > > The asm entry code of such faults does the following > > > > > > movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/ > > > movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ > > > > > > to set the orig_ax member to -1 just before calling the C-handler. > > > > > > In addition, the IRQ entry code uses the second error code argument as > > > its IRQ vector, as the IRQ asm entry code pushes its IRQ vector into > > > the orig_ax member. > > > > > > The commit d99015b1abbad ("x86: move entry_64.S register saving out of > > > the macros") introduced the changes to set orig_ax to -1, but I can't > > > see why it's required. Our tests on x86_64 and x86_32 seem fine if > > > orig_ax is left unchanged instead of set to -1. > > > > That means that SYSCALL_NUM(regs) get to be garbage; or something like that. > > I find SYSCALL_NUM(regs) in tools/testing/selftests/seccomp/seccomp_bpf.c, > but nothing obvious to me. > > I think it's clear that once exceptions and IRQs are handled, the original > context will be fully recovered in a normal case. > > Is it related to preemption after such a event? > > I must have missed something; can you please elaborate it? arch/x86/include/asm/syscall.h syscall_get_nr() syscall_rollback()