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 0186415EFC3; Mon, 27 May 2024 19:19:17 +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=1716837558; cv=none; b=hEfzZcqT/skqIc1a1K1uJ4lBGUcQIv3Smbpf2kyJRZUABaCIzP//t0G2nZqsP3343+ULKFd+KH0T4/Dfp73ju8GGptuIQ2H8IdwB2VaOOyWtEdmbwuJW38pyTR+1osptQxt42U5aJHCluy6xoWkXYToK6zu9qEkjSxrGBWUAkAw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716837558; c=relaxed/simple; bh=XtrSDH8xE6j73gKfuFUw/daXKQLPqDaCKNAKaG4MhdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qyrU8cnNingGgWqc/ikX5FtZyUI8nigmlVFZ92F61xJP5BszZfMRM7chfP+8AIJsdsCJZCMotWujr8CJqK8mdj0PrQhypZNfw47f4GGKTii/Uju+wYTRD1DR7CBXEgPMjAt4VpCaNPTAZ+wL2YwdbonCFZeAm4K28eH+m8VPP8k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=rdP8bPUU; 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="rdP8bPUU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D1A4C2BBFC; Mon, 27 May 2024 19:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1716837557; bh=XtrSDH8xE6j73gKfuFUw/daXKQLPqDaCKNAKaG4MhdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rdP8bPUUrM8ai3a9hyQxX1WE19HfwdtOSs2nbSoVCU+FG/q6kp4M6mxm+XaL2EzYt 7bSuMwJviVfbiQXJv2UpLDxSio7/6UiZMFMGmzpNfSWou6Jr4LWy1Ur9MoVfeLvFp7 /raF68GDFgprluBwkWZYUWamGLguhxrECg1Dmdf8= 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.8 058/493] selftests: sud_test: return correct emulated syscall value on RISC-V Date: Mon, 27 May 2024 20:51:00 +0200 Message-ID: <20240527185631.314909281@linuxfoundation.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527185626.546110716@linuxfoundation.org> References: <20240527185626.546110716@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.8-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