From patchwork Wed Jan 25 21:17:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 13116201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D205BC54E94 for ; Wed, 25 Jan 2023 21:17:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236240AbjAYVRa (ORCPT ); Wed, 25 Jan 2023 16:17:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236251AbjAYVR0 (ORCPT ); Wed, 25 Jan 2023 16:17:26 -0500 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5359A92; Wed, 25 Jan 2023 13:17:25 -0800 (PST) Received: from localhost.localdomain (unknown [182.253.88.152]) by gnuweeb.org (Postfix) with ESMTPSA id D0181824E0; Wed, 25 Jan 2023 21:17:18 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1674681444; bh=mMKZVmuKM6fU8lQxvVDK6YkHm5Mt6xLHRlUcyJGpWYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJNb5BgfXQFRKdSAycB7gaoxUZ5yW4xEIC1UXGscBybZlApitnrj+WIaItnN11K3H DrPBzFFOn/dK619msJ84gs8yBdzVoCUsVKZoNDnHtox9c8ZjP+C+H1XeAtF0EN81ga bX3ImXUNTablWSylmPsFcJx8NDgT8UfuHAjq5V+bJPmneq4GDDbaH2zfcWjtfoamfN U5BvW9/l0XHw4xNbFx2yWCw+TTqRsGHUbW7C95+ffGLAZItV2EngNLA03tIn7ykxZt N6bLBH2uSV7NQn1lxWAVzvIgln+XUB+nyiqycfXDTn19ejOKIgZX8/f1pBSJ6Dlc8C ZXJRVev1mvp+A== From: Ammar Faizi To: "H. Peter Anvin" , Xin Li Cc: Dave Hansen , Dave Hansen , "Kirill A. Shutemov" , Thomas Gleixner , Andrew Cooper , Peter Zijlstra , Brian Gerst , Borislav Petkov , Shuah Khan , Ingo Molnar , Andy Lutomirski , x86 Mailing List , Linux Kselftest Mailing List , Linux Kernel Mailing List Subject: [RFC PATCH v6 0/3] sysret_rip update for the Intel FRED architecture Date: Thu, 26 Jan 2023 04:17:11 +0700 Message-Id: <20230125211714.838216-1-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: <25b96960-a07e-a952-5c23-786b55054126@zytor.com> <6cd0db14-c9e2-3598-fd10-4b473d78c373@citrix.com> <5ecc383c-621b-57d9-7f6d-d63496fca3b3@zytor.com> <20230124022729.596997-1-ammarfaizi2@gnuweeb.org> <20230124022729.596997-3-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Ammar Faizi Hi, This is an RFC patchset v6. There are three patches in this series. Xin Li reported that the sysret_rip test fails at: assert(ctx->uc_mcontext.gregs[REG_EFL] == ctx->uc_mcontext.gregs[REG_R11]); on the Intel FRED architecture. Let's handle the FRED system scenario too. The 'syscall' instruction in a FRED system doesn't set %rcx=%rip and %r11=%rflags. Syscall and sysenter in a FRED system are treated equivalently to software interrupts, e.g. INT 0x80. They do not modify any registers. Link: https://lore.kernel.org/lkml/5d4ad3e3-034f-c7da-d141-9c001c2343af@intel.com ## Changelog v6: - Move the check-regs assertion in sigusr1() to check_regs_result() (HPA). - Add a new test just like sigusr1(), but don't modify REG_RCX and REG_R11. This is used to test SYSRET behavior consistency (HPA). ## Changelog v5: - Fix do_syscall() return value (Ammar). ## Changelog v4: - Fix the assertion condition inside the SIGUSR1 handler (Xin Li). - Explain the purpose of patch #2 in the commit message (HPA). - Update commit message (Ammar). - Repeat test_syscall_rcx_r11_consistent() 32 times to be more sure that the result is really consistent (Ammar). ## Changelog v3: - Test that we don't get a mix of REGS_SAVED and REGS_SYSRET, which is a major part of the point (HPA). ## Changelog v2: - Use "+r"(rsp) as the right way to avoid redzone problems per Andrew's comment (HPA). Co-developed-by: H. Peter Anvin (Intel) Signed-off-by: H. Peter Anvin (Intel) Signed-off-by: Ammar Faizi --- Ammar Faizi (3): selftests/x86: sysret_rip: Handle syscall in a FRED system selftests/x86: sysret_rip: Add more syscall tests with respect to `%rcx` and `%r11` selftests/x86: sysret_rip: Test opportunistic SYSRET tools/testing/selftests/x86/sysret_rip.c | 177 +++++++++++++++++++++-- 1 file changed, 168 insertions(+), 9 deletions(-) base-commit: e12ad468c22065a2826b2fc4c11d2113a7975301