Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Luis Machado <luis.machado@arm.com>
To: Mark Brown <broonie@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Shuah Khan <shuah@kernel.org>
Cc: Alan Hayward <alan.hayward@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 3/4] arm64/ptrace: Support access to TPIDR2_EL0
Date: Thu, 18 Aug 2022 11:59:44 +0100	[thread overview]
Message-ID: <2533a13d-9f8d-9d7b-ff9d-0ce8fc781d89@arm.com> (raw)
In-Reply-To: <20220815133034.231718-4-broonie@kernel.org>

On 8/15/22 14:30, Mark Brown wrote:
> SME introduces an additional EL0 register, TPIDR2_EL0, intended for use
> by userspace as part of the SME. Provide ptrace access to it through the
> existing NT_ARM_TLS regset used for TPIDR_EL0 by expanding it to two
> registers with TPIDR2_EL0 being the second one.
> 
> Existing programs that query the size of the register set will be able
> to observe the increased size of the register set. Programs that assume
> the register set is single register will see no change. On systems that
> do not support SME TPIDR2_EL0 will read as 0 and writes will be ignored,
> support for SME should be queried via hwcaps as normal.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
>   arch/arm64/kernel/ptrace.c | 25 ++++++++++++++++++++-----
>   1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
> index 21da83187a60..82feabba3911 100644
> --- a/arch/arm64/kernel/ptrace.c
> +++ b/arch/arm64/kernel/ptrace.c
> @@ -666,10 +666,18 @@ static int fpr_set(struct task_struct *target, const struct user_regset *regset,
>   static int tls_get(struct task_struct *target, const struct user_regset *regset,
>   		   struct membuf to)
>   {
> +	int ret;
> +
>   	if (target == current)
>   		tls_preserve_current_state();
>   
> -	return membuf_store(&to, target->thread.uw.tp_value);
> +	ret = membuf_store(&to, target->thread.uw.tp_value);
> +	if (system_supports_tpidr2())
> +		ret = membuf_store(&to, target->thread.tpidr2_el0);
> +	else
> +		ret = membuf_zero(&to, sizeof(u64));
> +
> +	return ret;
>   }
>   
>   static int tls_set(struct task_struct *target, const struct user_regset *regset,
> @@ -677,13 +685,20 @@ static int tls_set(struct task_struct *target, const struct user_regset *regset,
>   		   const void *kbuf, const void __user *ubuf)
>   {
>   	int ret;
> -	unsigned long tls = target->thread.uw.tp_value;
> +	unsigned long tls[2];
>   
> -	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &tls, 0, -1);
> +	tls[0] = target->thread.uw.tp_value;
> +	if (system_supports_sme())
> +		tls[1] = target->thread.tpidr2_el0;
> +
> +	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, tls, 0, count);
>   	if (ret)
>   		return ret;
>   
> -	target->thread.uw.tp_value = tls;
> +	target->thread.uw.tp_value = tls[0];
> +	if (system_supports_sme())
> +		target->thread.tpidr2_el0 = tls[1];
> +
>   	return ret;
>   }
>   
> @@ -1392,7 +1407,7 @@ static const struct user_regset aarch64_regsets[] = {
>   	},
>   	[REGSET_TLS] = {
>   		.core_note_type = NT_ARM_TLS,
> -		.n = 1,
> +		.n = 2,
>   		.size = sizeof(void *),
>   		.align = sizeof(void *),
>   		.regset_get = tls_get,

This looks good from GDB's perspective. I tried it with an unpatched GDB and it still works as it should.

TPIDR can be read correctly. I'll check TPIDR2 once it gets implemented.

Thanks,
Luis

  reply	other threads:[~2022-08-18 11:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 13:30 [PATCH v2 0/4] arm64/sme: ptrace support for TPIDR2_EL0 Mark Brown
2022-08-15 13:30 ` [PATCH v2 1/4] kselftest/arm64: Add test coverage for NT_ARM_TLS Mark Brown
2022-08-18  9:03   ` Luis Machado
2022-08-15 13:30 ` [PATCH v2 2/4] arm64/ptrace: Document extension of NT_ARM_TLS to cover TPIDR2_EL0 Mark Brown
2022-08-18  9:17   ` Luis Machado
2022-08-18 12:52     ` Mark Brown
2022-08-15 13:30 ` [PATCH v2 3/4] arm64/ptrace: Support access to TPIDR2_EL0 Mark Brown
2022-08-18 10:59   ` Luis Machado [this message]
2022-08-15 13:30 ` [PATCH v2 4/4] kselftest/arm64: Add coverage of TPIDR2_EL0 ptrace interface Mark Brown

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=2533a13d-9f8d-9d7b-ff9d-0ce8fc781d89@arm.com \
    --to=luis.machado@arm.com \
    --cc=alan.hayward@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=will@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox