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 559BDC05027 for ; Tue, 24 Jan 2023 00:27:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232299AbjAXA1B (ORCPT ); Mon, 23 Jan 2023 19:27:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231663AbjAXA06 (ORCPT ); Mon, 23 Jan 2023 19:26:58 -0500 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 462C939B89; Mon, 23 Jan 2023 16:26:52 -0800 (PST) Received: from localhost.localdomain (unknown [182.253.88.152]) by gnuweeb.org (Postfix) with ESMTPSA id D2214824E0; Tue, 24 Jan 2023 00:26:45 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1674520012; bh=SXQXpbuiBQdiwXpH2+78kfJuScDGyhqpyjZmkT1By0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qZ4AUcVqaCg4Eqketr209fH1DlzQ7tYfr4oo/RJDieFUYL3SPhUeuiFadn9JS9c/u cT9mBLn3vi89aAsRL6rZ7aL9Yw1Xq27Gwc32zhDxTo+IeJRgy6a8B2aEjH2rNL+z9a uvgGnK5S+WAwfJjetSfovuygOacgRjMorVPIfejVRtmKBUoRxDvVGeg5e/U5wt+GNr XsBNLifoZj/ZZJSwNqzDWWe7UXrLyuoefZlHDp7brkzMeIdM5581OlwRSIKB5BE+g+ 9Y2OUde4q6XdCj+rNvyX0Y19rF+C/nf+8/EZXoth5qbswSFnJnn2UfT+64VgJFCms8 dyZebDu32OVmA== From: Ammar Faizi To: x86 Mailing List Cc: Ammar Faizi , "H. Peter Anvin" , Dave Hansen , Dave Hansen , Xin Li , Thomas Gleixner , Andrew Cooper , Brian Gerst , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Shuah Khan , Ingo Molnar , Andy Lutomirski , "Kirill A. Shutemov" , Linux Kselftest Mailing List , Linux Kernel Mailing List Subject: [RFC PATCH v1 2/2] selftests/x86: sysret_rip: Add more syscall tests with respect to `%rcx` and `%r11` Date: Tue, 24 Jan 2023 07:26:25 +0700 Message-Id: <20230124002625.581323-3-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230124002625.581323-1-ammarfaizi2@gnuweeb.org> References: <5d4ad3e3-034f-c7da-d141-9c001c2343af@intel.com> <18B5DB6D-AEBD-4A67-A7B3-CE64940819B7@zytor.com> <25b96960-a07e-a952-5c23-786b55054126@zytor.com> <509443c8-e0fd-935f-63d8-7264f5dd3c05@zytor.com> <20230124002625.581323-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ammar Faizi Test that: - "syscall" in a FRED system doesn't clobber %rcx and %r11. - "syscall" in a non-FRED system sets %rcx=%rip and %r11=%rflags. Test them out with a trivial system call like __NR_getppid and friends which are extremely likely to return with SYSRET on an IDT system; check that it returns a nonnegative value and then save the result. Link: https://lore.kernel.org/lkml/25b96960-a07e-a952-5c23-786b55054126@zytor.com Co-developed-by: "H. Peter Anvin" Signed-off-by: Ammar Faizi --- Missing a Signed-off-by tag from HPA. @hpa send your sign off if you like this patch. tools/testing/selftests/x86/sysret_rip.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/selftests/x86/sysret_rip.c b/tools/testing/selftests/x86/sysret_rip.c index 9056f2e2674d2bc5..c55f6d04f0ae1f2d 100644 --- a/tools/testing/selftests/x86/sysret_rip.c +++ b/tools/testing/selftests/x86/sysret_rip.c @@ -252,8 +252,17 @@ static void test_syscall_fallthrough_to(unsigned long ip) printf("[OK]\tWe survived\n"); } +static void test_syscall_rcx_r11(void) +{ + do_syscall(__NR_getpid, 0, 0, 0, 0, 0, 0); + do_syscall(__NR_gettid, 0, 0, 0, 0, 0, 0); + do_syscall(__NR_getppid, 0, 0, 0, 0, 0, 0); +} + int main() { + test_syscall_rcx_r11(); + /* * When the kernel returns from a slow-path syscall, it will * detect whether SYSRET is appropriate. If it incorrectly -- Ammar Faizi