From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 699331990BA; Thu, 6 Jun 2024 14:11:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683116; cv=none; b=F8hgOdLIaUoaMiXE6Hq5DUtJIEYlrSONcPn1ylCXyo3ylKOseaQdi8RmeqcXBzTGQ3xAKUaUayd70Rp4dLN72gEEUqnTTIpXotDuZnhK7vA6vlMvUVwAWzHcEprHAwuOBKMMkBFUk2PxEZ39c4Owv4VKU2gporpCv8SrXUO1Jjc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683116; c=relaxed/simple; bh=+Lr6WZGxgAeu7/I9mjb6xDj7uopFzCfEkytKcfugN6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W26r1B0iIJixJM6nJx28M5XTKyREVwe1rg0zpkgdlreSX/+sILmUR404WEQYw+ywjzRTID638pcjjWtkOpoVYPiHMFuTJuyTvus3jBZyaSyHjwvqABRN0m5DgwduZNWt5ZQ3jKHbkeKHqIIgntBGViZWOhDp3P3j3f6XIoZACPE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=j6wMTV5+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="j6wMTV5+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40B14C2BD10; Thu, 6 Jun 2024 14:11:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1717683116; bh=+Lr6WZGxgAeu7/I9mjb6xDj7uopFzCfEkytKcfugN6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j6wMTV5+ZBEcFckUdonfcQFQ8HRcW40AW9I1ZYIaH5PbYEzMZp/jOpmlRThTEcQ5O gPYzwJts4r5milSPFSaA0Lkh9aTg6Sb0bPr2f21Dmy0DuZMlEjgXkdbxPc3Iz69G1U Wy0fbcLZ1AXmkt8vz5J9e2/LR4On4EHyEDPxkSCE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Palmer Dabbelt , Sasha Levin Subject: [PATCH 6.6 051/744] selftests: sud_test: return correct emulated syscall value on RISC-V Date: Thu, 6 Jun 2024 15:55:23 +0200 Message-ID: <20240606131734.077732206@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240606131732.440653204@linuxfoundation.org> References: <20240606131732.440653204@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Clément Léger [ Upstream commit 17c67ed752d6a456602b3dbb25c5ae4d3de5deab ] Currently, the sud_test expects the emulated syscall to return the emulated syscall number. This assumption only works on architectures were the syscall calling convention use the same register for syscall number/syscall return value. This is not the case for RISC-V and thus the return value must be also emulated using the provided ucontext. Signed-off-by: Clément Léger Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt Link: https://lore.kernel.org/r/20231206134438.473166-1-cleger@rivosinc.com Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- .../selftests/syscall_user_dispatch/sud_test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/syscall_user_dispatch/sud_test.c b/tools/testing/selftests/syscall_user_dispatch/sud_test.c index b5d592d4099e8..d975a67673299 100644 --- a/tools/testing/selftests/syscall_user_dispatch/sud_test.c +++ b/tools/testing/selftests/syscall_user_dispatch/sud_test.c @@ -158,6 +158,20 @@ static void handle_sigsys(int sig, siginfo_t *info, void *ucontext) /* In preparation for sigreturn. */ SYSCALL_DISPATCH_OFF(glob_sel); + + /* + * The tests for argument handling assume that `syscall(x) == x`. This + * is a NOP on x86 because the syscall number is passed in %rax, which + * happens to also be the function ABI return register. Other + * architectures may need to swizzle the arguments around. + */ +#if defined(__riscv) +/* REG_A7 is not defined in libc headers */ +# define REG_A7 (REG_A0 + 7) + + ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A0] = + ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A7]; +#endif } TEST(dispatch_and_return) -- 2.43.0