All of lore.kernel.org
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@rivosinc.com>
To: cleger@rivosinc.com, tglx@linutronix.de
Cc: shuah@kernel.org, krisman@collabora.com,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-riscv@lists.infradead.org, cleger@rivosinc.com,
	Bjorn Topel <bjorn@rivosinc.com>
Subject: Re: [PATCH v2] selftests: sud_test: return correct emulated syscall value on RISC-V
Date: Wed, 06 Dec 2023 08:29:01 -0800 (PST)	[thread overview]
Message-ID: <mhng-bd5d2bdb-99ab-464a-a043-bdfc34b96b71@palmer-ri-x1c9> (raw)
In-Reply-To: <20231206134438.473166-1-cleger@rivosinc.com>

On Wed, 06 Dec 2023 05:44:37 PST (-0800), cleger@rivosinc.com wrote:
> 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 <cleger@rivosinc.com>
> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
> Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
>
> ---
>
> Changes in V2:
>  - Changes comment to be more explicit
>  - Use A7 syscall arg rather than hardcoding MAGIC_SYSCALL_1
>
> ---
>  .../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 b5d592d4099e..d975a6767329 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)

Thanks.

Thomas: looks like you picked up all the commits that touched this?  No 
rush on my end, just LMK if you want me to pick it up -- I'm going to 
leave it alone for now.

WARNING: multiple messages have this Message-ID (diff)
From: Palmer Dabbelt <palmer@rivosinc.com>
To: cleger@rivosinc.com, tglx@linutronix.de
Cc: shuah@kernel.org, krisman@collabora.com,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-riscv@lists.infradead.org, cleger@rivosinc.com,
	Bjorn Topel <bjorn@rivosinc.com>
Subject: Re: [PATCH v2] selftests: sud_test: return correct emulated syscall value on RISC-V
Date: Wed, 06 Dec 2023 08:29:01 -0800 (PST)	[thread overview]
Message-ID: <mhng-bd5d2bdb-99ab-464a-a043-bdfc34b96b71@palmer-ri-x1c9> (raw)
In-Reply-To: <20231206134438.473166-1-cleger@rivosinc.com>

On Wed, 06 Dec 2023 05:44:37 PST (-0800), cleger@rivosinc.com wrote:
> 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 <cleger@rivosinc.com>
> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
> Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
>
> ---
>
> Changes in V2:
>  - Changes comment to be more explicit
>  - Use A7 syscall arg rather than hardcoding MAGIC_SYSCALL_1
>
> ---
>  .../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 b5d592d4099e..d975a6767329 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)

Thanks.

Thomas: looks like you picked up all the commits that touched this?  No 
rush on my end, just LMK if you want me to pick it up -- I'm going to 
leave it alone for now.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2023-12-06 16:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06 13:44 [PATCH v2] selftests: sud_test: return correct emulated syscall value on RISC-V Clément Léger
2023-12-06 13:44 ` Clément Léger
2023-12-06 16:29 ` Palmer Dabbelt [this message]
2023-12-06 16:29   ` Palmer Dabbelt
2024-04-10 14:20 ` patchwork-bot+linux-riscv
2024-04-10 14:20   ` patchwork-bot+linux-riscv

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mhng-bd5d2bdb-99ab-464a-a043-bdfc34b96b71@palmer-ri-x1c9 \
    --to=palmer@rivosinc.com \
    --cc=bjorn@rivosinc.com \
    --cc=cleger@rivosinc.com \
    --cc=krisman@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.