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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6EE2C02185 for ; Wed, 15 Jan 2025 09:42:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55E3D6B007B; Wed, 15 Jan 2025 04:42:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 50CD5280001; Wed, 15 Jan 2025 04:42:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 386DC6B0083; Wed, 15 Jan 2025 04:42:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 179536B007B for ; Wed, 15 Jan 2025 04:42:14 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8F77E458C9 for ; Wed, 15 Jan 2025 09:42:13 +0000 (UTC) X-FDA: 83009195346.29.5B4F89F Received: from flow-a2-smtp.messagingengine.com (flow-a2-smtp.messagingengine.com [103.168.172.137]) by imf17.hostedemail.com (Postfix) with ESMTP id 4C4C340014 for ; Wed, 15 Jan 2025 09:42:11 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=coelacanthus.name header.s=fm3 header.b=mVoJWykJ; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="w ixxW+K"; spf=pass (imf17.hostedemail.com: domain of uwu@coelacanthus.name designates 103.168.172.137 as permitted sender) smtp.mailfrom=uwu@coelacanthus.name; dmarc=pass (policy=quarantine) header.from=coelacanthus.name ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736934131; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YiRbxGu1UHJm8IpldfHhFbmYMUtUE+hZXcRxL0CMUCE=; b=PqADtiMuwDWi89DkUKbZyoTX6wQyWEIAIU/uUxLtGaaiPVKxPY1fELIQxce6o5qC/kU9b0 j/vvMMcw2sh1O2Y2xjPGl7EsbEguMOjP+K+FDIJ9oldTO7StBR+4RTQ0kL2vayemhx+R0H Npb7/uuq1XnYdhZYym/1DVaZxMQ9tsg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736934131; a=rsa-sha256; cv=none; b=UecERYUyukKuoEbpbTqCwpnsLFTNXrndWllwmLOV0yPcee3Eo8gm8eIzbxXUCOKC0bhcm7 3iP6XPtT2dJnOsE1DmzmCIEXcpC/FtTeHeUGFvkFlHQjFf/qHor6O4tCkEP8HAnbgYFGqv Je/O5bgI7yH/B2fj7qG946Ihqdh6MHM= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=coelacanthus.name header.s=fm3 header.b=mVoJWykJ; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="w ixxW+K"; spf=pass (imf17.hostedemail.com: domain of uwu@coelacanthus.name designates 103.168.172.137 as permitted sender) smtp.mailfrom=uwu@coelacanthus.name; dmarc=pass (policy=quarantine) header.from=coelacanthus.name Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailflow.phl.internal (Postfix) with ESMTP id 825E2200C73; Wed, 15 Jan 2025 04:42:10 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Wed, 15 Jan 2025 04:42:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= coelacanthus.name; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1736934130; x=1736941330; bh=YiRbxGu1UH Jm8IpldfHhFbmYMUtUE+hZXcRxL0CMUCE=; b=mVoJWykJvVwY6ulcWer5cqbm6L NPulbUzcxq9J2RsLAKsDDOH3VOrTe66WWakovWl2mRB/SHAz+3PtMktDWlEPc/K6 olTFyquzCnOYQf9EczbOebtLbJnamLoTSMaq7r5ZUb6kZwAN4G3N1J0nstL6qaFg 9Ve0sKcKQ6O02oM/ZcAwdWFX7XSiwYyCa9g5qUPNGskDWhHTM7HJUijAutWrOkWq wFT4EZqblW/vmNoUoCWUCpoABBHXDEZDSh6B/DzgFy/+SJc6z/KV70zfR35uv41V bDit6x+aztrGI1FfI/sZbg2/4M9EEnu6IKKyiy8jwuGLuMTmYQQ+fHEXFW9w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1736934130; x= 1736941330; bh=YiRbxGu1UHJm8IpldfHhFbmYMUtUE+hZXcRxL0CMUCE=; b=w ixxW+KnBVgzt8CodHWBgfKkkhveQB6iY0HmhzagaNBiXTpdlx7fGDdX1bbiEQIS8 mkhQyp07u3etVV2xjiGTgev36m9XkoDCVkbcLFEUMGlPkhAo19pbyP5kXJ79KVbD VyD86rAIaLtVcaM0ohkK9R0oEJPtokKlPXngSaJurnOwH9EGaweOAU40AJIdhYFE UgMQ8BHdv+4NSeOh2IVhMU0PDi7axAHksZZcpavH11vaZg0Y/BwGq9OV2cXcOPmO R6EMMO32QrLOzXa7zHvx/3guvi6kGz2roYY/7NpFFlTFFOsSo5vFTQeb7L6m/Iln K9RY2ybOkiQtMF4Wq3Wvg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudehkedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdej necuhfhrohhmpeevvghlvghsthgvucfnihhuuceouhifuhestghovghlrggtrghnthhhuh hsrdhnrghmvgeqnecuggftrfgrthhtvghrnhepfefhfeefteekgedvfeehhfefvedutedt fefhkeeileehgefgveffvdffudehhfeknecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepuhifuhestghovghlrggtrghnthhhuhhsrdhnrghmvgdp nhgspghrtghpthhtohepvdehpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegrjh honhgvshesvhgvnhhtrghnrghmihgtrhhordgtohhmpdhrtghpthhtohepohhlvghgsehr vgguhhgrthdrtghomhdprhgtphhtthhopehprghulhdrfigrlhhmshhlvgihsehsihhfih hvvgdrtghomhdprhgtphhtthhopehprghlmhgvrhesuggrsggsvghlthdrtghomhdprhgt phhtthhopegvsghivgguvghrmhesgihmihhsshhiohhnrdgtohhmpdhrtghpthhtohepkh gvvghssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehshhhurghhsehkvghrnhgvlhdr ohhrghdprhgtphhtthhopegrohhusegvvggtshdrsggvrhhkvghlvgihrdgvughupdhrtg hpthhtoheprghlvgigsehghhhithhirdhfrh X-ME-Proxy: Feedback-ID: i95c648bc:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 04:42:00 -0500 (EST) Message-ID: <17dfb122-4ae3-477f-93a8-1748b819c59c@coelacanthus.name> Date: Wed, 15 Jan 2025 17:41:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 2/2] riscv: selftests: Add a ptrace test to verify a0 and orig_a0 access Content-Language: en-GB-large To: Andrew Jones Cc: Oleg Nesterov , Paul Walmsley , Palmer Dabbelt , Eric Biederman , Kees Cook , Shuah Khan , Albert Ou , Alexandre Ghiti , "Dmitry V. Levin" , Andrea Bolognani , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Thomas Gleixner , Ron Economos , Charlie Jenkins , Quan Zhou , Felix Yan , Ruizhe Pan , Guo Ren , Yao Zi , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= References: <20250115-riscv-new-regset-v5-0-d0e6ec031a23@coelacanthus.name> <20250115-riscv-new-regset-v5-2-d0e6ec031a23@coelacanthus.name> <20250115-28c95808502d43f84b3fe0a6@orel> From: Celeste Liu In-Reply-To: <20250115-28c95808502d43f84b3fe0a6@orel> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4C4C340014 X-Stat-Signature: 5h6mczxca8d5htxxgttxyh1e74an4zd8 X-Rspam-User: X-HE-Tag: 1736934131-802705 X-HE-Meta: U2FsdGVkX18eVbDYE6zylAGGSruU3iKFDse4nxrnTiGoa0cT7kYu3TpDXWKPNO+m2fUsZjlMUxKOOaeklldMoyX+vVyHSLSN1YMS3cCAWce50stzmddS4pgNb00bXL5gmJsIJb0rELMEOw+OyYc+J5NMMxhxfNQtfnp1q/U1Uo9q4LaY4hWvQSa3yJyiS/HQV7kVjv9BG1Ph12+UI8W7iMUTzUGkh364SpbpqGVPG9eDDCCb82ERiIpmueqaodc2hfC9nmbor6AycTETqyXitI9kwEH5VLdNWARitZFEna/Zj4c2a1Y5Y66SGQkwiKIxEviuaID+5ZB/DhNRh/0H9u0ujIJCL+TmmCP6+CFElBtImSADZ2+SNh3J2PkNRpco4Vh/Pf7apEIGSpig/XL62tpBLsLHxg6IINzM6NRb/Q6CwB41MbJFVyFx7r2ZcSm2enjWYvYg9OFMEc/dXmxBuwf+Rdm5htZsoIfe5SSAEDne76MWKLSDIyNiJr40dVc9V8D1QqQLxL/BMjAPxasSlBLuAclAEtanY+awVBLV1ROKik06LT+MlbD5atgv44+h0t+ezRNTsEY5z2n+SnDeuL6s0XLRdLokvSFzBDyWkgi98w2tJWxI5LQQEpi5u/yvGhujY3VLeYQt7uw8+R6ClDj3JOFUj/Dci//7Gx5dl0bcXXcE8SpCubWDjtXfYadFgVC8d+eIcbdLgQWrX5YbgOBJbWSR0uIckb/a/0Dhx6y7OSYWr9EM7KAdt/C746hkuTDhTHLlXIeip9X/U7lm2SyvP+Kh1l/sEaBAKniiHVCwIiNnfSTlN+fSUYCcJHR5mXrtrOmjTR+BHUxfXIls8iaCHax9Kl/JtcTsiMSA9H8zNbJWktrz4lw5dZ3GWHWHfNXxKzuig5Wop+SMKDRm/xfTCo7mOu8WnYTpSdFKPZcfOBfSfLnboJsLFUAzJ+OfaP0Fja942ycilBVqtzG QIWLbKZg LvZVPqpJuJ8Nw7E35p4ZmIOFmQkEONvOxkcTrU6o8bTkfk6v++aBs0Gp63aPFKH+lpUNgtAcnrmVF9PmuvQdSRgJ1V+3jaHgzxcn+uUebsYw351KUmggEibcBWAlA7tuVM8TSD6GUW3rAjx7KCUFGtLq3tgAdjNJ/iT5VQwMiwoAYHo+pUYznEBXswywCd3hnNJBTv1WjlCDxPwjXppFMWvMtT2h7AMn2R2KOBRWM7Z+A3IRVb9i25yQy7Z77yDCIrRN+LT3FKNg6t8ScJJiUHzxXJ7aj4x+y3ffMDG5pZS5JOs5IQA664H6g1BYOetx/L6ypy8rhuJaqFfOZtECYjx2BQGI/df/qOaJQxy3tJ1taEUf6T64j+67cNhmmjEl44CpkCMuSFtzsXlgh309GLHSxkUp96YVnpMxhJbag1fjVW+2C89teibf8Wcb/W/LgTc4q4I88hbuW8jMNhw29r0cJoprOEgMtSHRpBBWcQ67I349ng4+FlvlczSukTEaR8uKLhibJh+bISP3UiLeM1kX8xfl425E9dMRTUgGwtZAtidN4hnCP3KvBh+gCvYMOnX1ARKfFMlb1NMKiaKQsHYktrznuRhTF6A6c X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2025-01-15 17:14, Andrew Jones wrote: > On Wed, Jan 15, 2025 at 04:24:59AM +0800, Celeste Liu wrote: >> This test checks that orig_a0 and a0 can be modified and accessed >> independently. >> >> Co-developed-by: Quan Zhou >> Signed-off-by: Quan Zhou >> Co-developed-by: Charlie Jenkins >> Signed-off-by: Charlie Jenkins >> Reviewed-by: Björn Töpel >> Signed-off-by: Celeste Liu >> --- >> tools/testing/selftests/riscv/abi/.gitignore | 1 + >> tools/testing/selftests/riscv/abi/Makefile | 6 +- >> tools/testing/selftests/riscv/abi/ptrace.c | 201 +++++++++++++++++++++++++++ >> 3 files changed, 207 insertions(+), 1 deletion(-) >> >> diff --git a/tools/testing/selftests/riscv/abi/.gitignore b/tools/testing/selftests/riscv/abi/.gitignore >> index b38358f91c4d2240ae64892871d9ca98bda1ae58..378c605919a3b3d58eec2701eb7af430cfe315d6 100644 >> --- a/tools/testing/selftests/riscv/abi/.gitignore >> +++ b/tools/testing/selftests/riscv/abi/.gitignore >> @@ -1 +1,2 @@ >> pointer_masking >> +ptrace >> diff --git a/tools/testing/selftests/riscv/abi/Makefile b/tools/testing/selftests/riscv/abi/Makefile >> index ed82ff9c664e7eb3f760cbab81fb957ff72579c5..359a082c88a401883fb3776b35e4dacf69beaaaa 100644 >> --- a/tools/testing/selftests/riscv/abi/Makefile >> +++ b/tools/testing/selftests/riscv/abi/Makefile >> @@ -1,10 +1,14 @@ >> # SPDX-License-Identifier: GPL-2.0 >> >> CFLAGS += -I$(top_srcdir)/tools/include >> +CFLAGS += $(KHDR_INCLUDES) >> >> -TEST_GEN_PROGS := pointer_masking >> +TEST_GEN_PROGS := pointer_masking ptrace >> >> include ../../lib.mk >> >> $(OUTPUT)/pointer_masking: pointer_masking.c >> $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ >> + >> +$(OUTPUT)/ptrace: ptrace.c >> + $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ >> diff --git a/tools/testing/selftests/riscv/abi/ptrace.c b/tools/testing/selftests/riscv/abi/ptrace.c >> new file mode 100644 >> index 0000000000000000000000000000000000000000..f1a0458adccdd040bfaa350e2e8d98b1ef34c0ad >> --- /dev/null >> +++ b/tools/testing/selftests/riscv/abi/ptrace.c >> @@ -0,0 +1,201 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include "../../kselftest_harness.h" >> + >> +#ifndef sizeof_field >> +#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) >> +#endif >> +#ifndef offsetofend >> +#define offsetofend(TYPE, MEMBER) \ >> + (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) >> +#endif > > I think this is the sixth test to define these. We should copy > include/linux/stddef.h into tools/include. We already have > tools/include/uapi/linux/stddef.h with __struct_group and > __DECLARE_FLEX_ARRAY, so I think it should just work. Agreed. But it may be better to be a separate patchset so we can change those definition in different selftests one pass. > >> + >> + >> +#define ORIG_A0_MODIFY 0x01 >> +#define A0_MODIFY 0x02 >> +#define A0_OLD 0xbadbeefbeeff >> +#define A0_NEW 0xffeebfeebdab >> + >> + >> +struct a0_regs { >> + __s64 orig_a0; >> + __u64 a0; >> +}; >> + >> +#define perr_and_exit(fmt, ...) \ >> + ({ \ >> + char buf[256]; \ >> + snprintf(buf, sizeof(buf), "%s:%d:" fmt ": %m\n", \ >> + __func__, __LINE__, ##__VA_ARGS__); \ >> + ksft_exit_fail_perror(buf); \ >> + }) >> + >> +static void ptrace_test(int opt, struct a0_regs result[]) >> +{ >> + int status; >> + long rc; >> + pid_t pid; >> + struct user_regs_struct regs; >> + struct iovec iov = { >> + .iov_base = ®s, >> + .iov_len = sizeof(regs), >> + }; >> + >> + unsigned long orig_a0; >> + struct iovec a0_iov = { >> + .iov_base = &orig_a0, >> + .iov_len = sizeof(orig_a0), >> + }; >> + struct ptrace_syscall_info syscall_info = { >> + .op = 0xff, >> + }; >> + const unsigned int expected_sci_entry_size = >> + offsetofend(struct ptrace_syscall_info, entry.args); >> + const unsigned int expected_sci_exit_size = >> + offsetofend(struct ptrace_syscall_info, exit.is_error); >> + >> + pid = fork(); >> + if (pid == 0) { >> + /* Mark oneself being traced */ >> + long val = ptrace(PTRACE_TRACEME, 0, 0, 0); >> + >> + if (val < 0) >> + perr_and_exit("failed to request for tracer to trace me: %ld", val); >> + >> + kill(getpid(), SIGSTOP); >> + >> + /* Perform chdir syscall that will be intercepted */ >> + syscall(__NR_chdir, A0_OLD); >> + >> + exit(0); >> + } >> + >> + if (pid < 0) >> + ksft_exit_fail_perror("failed to fork"); >> + >> + for (int i = 0; i < 3; i++) { >> + if (waitpid(pid, &status, 0) != pid) >> + perr_and_exit("failed to wait for the tracee %d", pid); >> + if (WIFSTOPPED(status)) { >> + switch (WSTOPSIG(status)) { >> + case SIGSTOP: >> + if (ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_TRACESYSGOOD) < 0) >> + perr_and_exit("failed to set PTRACE_O_TRACESYSGOOD"); >> + break; >> + case SIGTRAP|0x80: >> + /* Modify twice so GET_SYSCALL_INFO get modified a0 and orig_a0 */ >> + if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov)) >> + perr_and_exit("failed to get tracee registers"); >> + if (ptrace(PTRACE_GETREGSET, pid, NT_RISCV_ORIG_A0, &a0_iov)) >> + perr_and_exit("failed to get tracee registers"); >> + >> + /* Modify a0/orig_a0 for the syscall */ >> + switch (opt) { >> + case A0_MODIFY: >> + regs.a0 = A0_NEW; >> + break; >> + case ORIG_A0_MODIFY: >> + orig_a0 = A0_NEW; >> + break; >> + } >> + >> + if (ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov)) >> + perr_and_exit("failed to set tracee registers"); >> + if (ptrace(PTRACE_SETREGSET, pid, NT_RISCV_ORIG_A0, &a0_iov)) >> + perr_and_exit("failed to set tracee registers"); >> + switch (i) { >> + case 1: >> + /* Stop at the beginning of syscall */ >> + rc = ptrace(PTRACE_GET_SYSCALL_INFO, pid, >> + sizeof(syscall_info), &syscall_info); >> + if (rc < 0) >> + perr_and_exit("failed to get syscall info of entry"); >> + if (rc < expected_sci_entry_size >> + || syscall_info.op != PTRACE_SYSCALL_INFO_ENTRY) >> + perr_and_exit("stop position of entry mismatched"); >> + result[0].orig_a0 = syscall_info.entry.args[0]; >> + break; >> + >> + case 2: >> + /* Stop at the end of syscall */ >> + rc = ptrace(PTRACE_GET_SYSCALL_INFO, pid, >> + sizeof(syscall_info), &syscall_info); >> + if (rc < 0) >> + perr_and_exit("failed to get syscall info of entry"); >> + if (rc < expected_sci_exit_size >> + || syscall_info.op != PTRACE_SYSCALL_INFO_EXIT) >> + perr_and_exit("stop position of exit mismatched"); >> + result[0].a0 = syscall_info.exit.rval; >> + >> + if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov)) >> + perr_and_exit("failed to get tracee registers"); >> + result[1].a0 = regs.a0; >> + if (ptrace(PTRACE_GETREGSET, pid, NT_RISCV_ORIG_A0, >> + &a0_iov)) >> + perr_and_exit("failed to get tracee registers"); >> + result[1].orig_a0 = orig_a0; >> + } >> + } >> + if (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) >> + perr_and_exit("failed to resume tracee"); >> + } >> + } >> + >> + /* Resume the tracee */ >> + ptrace(PTRACE_CONT, pid, 0, 0); >> + if (waitpid(pid, &status, 0) != pid) >> + perr_and_exit("failed to wait for the tracee"); >> + >> +} >> + >> +TEST(ptrace_access_a0) >> +{ >> + struct a0_regs result[2]; >> + >> + ptrace_test(A0_MODIFY, result); >> + >> + /* Verify PTRACE_SETREGSET */ >> + /* The modification of a0 cannot affect the first argument of the syscall */ >> + EXPECT_EQ(A0_OLD, result[0].orig_a0); >> + EXPECT_EQ(A0_NEW, result[0].a0); >> + >> + /* Verify PTRACE_GETREGSET */ >> + EXPECT_EQ(result[1].orig_a0, result[0].orig_a0); >> + EXPECT_EQ(result[1].a0, result[0].a0); >> +} >> + >> +TEST(ptrace_access_orig_a0) >> +{ >> + struct a0_regs result[2]; >> + >> + ptrace_test(ORIG_A0_MODIFY, result); >> + >> + /* Verify PTRACE_SETREGSET */ >> + /* Only modify orig_a0 to change the first argument of the syscall */ >> + EXPECT_EQ(A0_NEW, result[0].orig_a0); >> + /* a0 will keep default value, orig_a0 or -ENOSYS, depends on internal. */ >> + EXPECT_NE(A0_NEW, result[0].a0); > > I don't understand this test. Why don't we know what to expect? Also, the > comment says orig_a0 is an option for the value, but then we don't expect > it to be A0_NEW, even though we expect orig_a0 to be A0_NEW? The purpose of the test is to ensure that the ORIG_A0_MODIFY operation will not affect the a0 register (So it will not be our A0_NEW). But there is a problem with the comment. It is written for some old wrong code. I will correct the comment. > >> + >> + /* Verify PTRACE_GETREGSET */ >> + EXPECT_EQ(result[1].orig_a0, result[0].orig_a0); >> + EXPECT_EQ(result[1].a0, result[0].a0); >> +} >> + >> +TEST_HARNESS_MAIN >> >> -- >> 2.48.0 >> > > Other than the two comments/questions, this test looks great. > > Thanks, > drew