All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-05  9:56 ` Zhen Lei
  0 siblings, 0 replies; 16+ messages in thread
From: Zhen Lei @ 2022-05-05  9:56 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel; +Cc: Zhen Lei

Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
pcpu access. However, when performing reverse execution based on the
registers and the memory contents in kdump, this information is sometimes
required if there is a pcpu access.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 arch/arm64/kernel/process.c | 5 +++++
 1 file changed, 5 insertions(+)

v2 --> v3:
1) Relace "switch (read_sysreg(CurrentEL))" statement with
   "if (is_kernel_in_hyp_mode())" statement.
2) Change the register name to lowercase.

v1 --> v2:
Directly print the tpidr_elx register of the current exception level.
Avoid coupling with the implementation of 'my_cpu_offset'.

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 7fa97df55e3ad3f..7b6bccce9721c36 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
 	show_regs_print_info(KERN_DEFAULT);
 	print_pstate(regs);
 
+	if (is_kernel_in_hyp_mode())
+		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
+	else
+		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
+
 	if (!user_mode(regs)) {
 		printk("pc : %pS\n", (void *)regs->pc);
 		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-05  9:56 ` Zhen Lei
  0 siblings, 0 replies; 16+ messages in thread
From: Zhen Lei @ 2022-05-05  9:56 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel; +Cc: Zhen Lei

Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
pcpu access. However, when performing reverse execution based on the
registers and the memory contents in kdump, this information is sometimes
required if there is a pcpu access.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 arch/arm64/kernel/process.c | 5 +++++
 1 file changed, 5 insertions(+)

v2 --> v3:
1) Relace "switch (read_sysreg(CurrentEL))" statement with
   "if (is_kernel_in_hyp_mode())" statement.
2) Change the register name to lowercase.

v1 --> v2:
Directly print the tpidr_elx register of the current exception level.
Avoid coupling with the implementation of 'my_cpu_offset'.

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 7fa97df55e3ad3f..7b6bccce9721c36 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
 	show_regs_print_info(KERN_DEFAULT);
 	print_pstate(regs);
 
+	if (is_kernel_in_hyp_mode())
+		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
+	else
+		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
+
 	if (!user_mode(regs)) {
 		printk("pc : %pS\n", (void *)regs->pc);
 		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
-- 
2.25.1


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

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
  2022-05-05  9:56 ` Zhen Lei
@ 2022-05-05 10:51   ` Will Deacon
  -1 siblings, 0 replies; 16+ messages in thread
From: Will Deacon @ 2022-05-05 10:51 UTC (permalink / raw)
  To: Zhen Lei; +Cc: Catalin Marinas, linux-arm-kernel, linux-kernel

On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
> pcpu access. However, when performing reverse execution based on the
> registers and the memory contents in kdump, this information is sometimes
> required if there is a pcpu access.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  arch/arm64/kernel/process.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> v2 --> v3:
> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>    "if (is_kernel_in_hyp_mode())" statement.
> 2) Change the register name to lowercase.
> 
> v1 --> v2:
> Directly print the tpidr_elx register of the current exception level.
> Avoid coupling with the implementation of 'my_cpu_offset'.
> 
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>  	show_regs_print_info(KERN_DEFAULT);
>  	print_pstate(regs);
>  
> +	if (is_kernel_in_hyp_mode())
> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
> +	else
> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
> +

I'd still much prefer if we only printed this information for exceptions
taken in kernel mode. What use is this information for user faults?

We may only store an offset in the register today, but that could easily
change and nobody will come back and fix this code up.

Thanks,

Will

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-05 10:51   ` Will Deacon
  0 siblings, 0 replies; 16+ messages in thread
From: Will Deacon @ 2022-05-05 10:51 UTC (permalink / raw)
  To: Zhen Lei; +Cc: Catalin Marinas, linux-arm-kernel, linux-kernel

On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
> pcpu access. However, when performing reverse execution based on the
> registers and the memory contents in kdump, this information is sometimes
> required if there is a pcpu access.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  arch/arm64/kernel/process.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> v2 --> v3:
> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>    "if (is_kernel_in_hyp_mode())" statement.
> 2) Change the register name to lowercase.
> 
> v1 --> v2:
> Directly print the tpidr_elx register of the current exception level.
> Avoid coupling with the implementation of 'my_cpu_offset'.
> 
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>  	show_regs_print_info(KERN_DEFAULT);
>  	print_pstate(regs);
>  
> +	if (is_kernel_in_hyp_mode())
> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
> +	else
> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
> +

I'd still much prefer if we only printed this information for exceptions
taken in kernel mode. What use is this information for user faults?

We may only store an offset in the register today, but that could easily
change and nobody will come back and fix this code up.

Thanks,

Will

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
  2022-05-05  9:56 ` Zhen Lei
@ 2022-05-05 13:04   ` Mark Rutland
  -1 siblings, 0 replies; 16+ messages in thread
From: Mark Rutland @ 2022-05-05 13:04 UTC (permalink / raw)
  To: Zhen Lei; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel

On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
> pcpu access. However, when performing reverse execution based on the
> registers and the memory contents in kdump, this information is sometimes
> required if there is a pcpu access.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  arch/arm64/kernel/process.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> v2 --> v3:
> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>    "if (is_kernel_in_hyp_mode())" statement.
> 2) Change the register name to lowercase.
> 
> v1 --> v2:
> Directly print the tpidr_elx register of the current exception level.
> Avoid coupling with the implementation of 'my_cpu_offset'.
> 
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>  	show_regs_print_info(KERN_DEFAULT);
>  	print_pstate(regs);
>  
> +	if (is_kernel_in_hyp_mode())
> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
> +	else
> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));

If we care about the offset specifically, this would be simpler as:

	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());

... which should do the right thing even if we repurpose the TPIDRs and move the offset elsewhere.

As Will says, we should only log this for !user_mode(regs), so it could
be placed in the block below, immediately before we print the kernel PC, i.e.

	if (!user_mode_regs) {
		printk("cpu offset : %016lx\n", __my_cpu_offset());
		printk("pc : %pS\n", (void *)regs->pc);
		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
		...
	}

... or in a separate block which checks the same condition.

Thanks,
Mark.

> +
>  	if (!user_mode(regs)) {
>  		printk("pc : %pS\n", (void *)regs->pc);
>  		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-05 13:04   ` Mark Rutland
  0 siblings, 0 replies; 16+ messages in thread
From: Mark Rutland @ 2022-05-05 13:04 UTC (permalink / raw)
  To: Zhen Lei; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel

On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
> pcpu access. However, when performing reverse execution based on the
> registers and the memory contents in kdump, this information is sometimes
> required if there is a pcpu access.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  arch/arm64/kernel/process.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> v2 --> v3:
> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>    "if (is_kernel_in_hyp_mode())" statement.
> 2) Change the register name to lowercase.
> 
> v1 --> v2:
> Directly print the tpidr_elx register of the current exception level.
> Avoid coupling with the implementation of 'my_cpu_offset'.
> 
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>  	show_regs_print_info(KERN_DEFAULT);
>  	print_pstate(regs);
>  
> +	if (is_kernel_in_hyp_mode())
> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
> +	else
> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));

If we care about the offset specifically, this would be simpler as:

	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());

... which should do the right thing even if we repurpose the TPIDRs and move the offset elsewhere.

As Will says, we should only log this for !user_mode(regs), so it could
be placed in the block below, immediately before we print the kernel PC, i.e.

	if (!user_mode_regs) {
		printk("cpu offset : %016lx\n", __my_cpu_offset());
		printk("pc : %pS\n", (void *)regs->pc);
		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
		...
	}

... or in a separate block which checks the same condition.

Thanks,
Mark.

> +
>  	if (!user_mode(regs)) {
>  		printk("pc : %pS\n", (void *)regs->pc);
>  		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
> -- 
> 2.25.1
> 

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
  2022-05-05 13:04   ` Mark Rutland
@ 2022-05-05 13:26     ` Leizhen (ThunderTown)
  -1 siblings, 0 replies; 16+ messages in thread
From: Leizhen (ThunderTown) @ 2022-05-05 13:26 UTC (permalink / raw)
  To: Mark Rutland; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel



On 2022/5/5 21:04, Mark Rutland wrote:
> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
>> pcpu access. However, when performing reverse execution based on the
>> registers and the memory contents in kdump, this information is sometimes
>> required if there is a pcpu access.
>>
>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>> ---
>>  arch/arm64/kernel/process.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> v2 --> v3:
>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>>    "if (is_kernel_in_hyp_mode())" statement.
>> 2) Change the register name to lowercase.
>>
>> v1 --> v2:
>> Directly print the tpidr_elx register of the current exception level.
>> Avoid coupling with the implementation of 'my_cpu_offset'.
>>
>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
>> --- a/arch/arm64/kernel/process.c
>> +++ b/arch/arm64/kernel/process.c
>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>>  	show_regs_print_info(KERN_DEFAULT);
>>  	print_pstate(regs);
>>  
>> +	if (is_kernel_in_hyp_mode())
>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
>> +	else
>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
> 
> If we care about the offset specifically, this would be simpler as:
> 
> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());

The function name is __show_regs(), so not using register name may not be good.
In fact, some other architectures may also have this problem. If we use my_cpu_offset,
we may need to put it in a public.

> 
> ... which should do the right thing even if we repurpose the TPIDRs and move the offset elsewhere.
> 
> As Will says, we should only log this for !user_mode(regs), so it could
> be placed in the block below, immediately before we print the kernel PC, i.e.
> 
> 	if (!user_mode_regs) {
> 		printk("cpu offset : %016lx\n", __my_cpu_offset());
> 		printk("pc : %pS\n", (void *)regs->pc);
> 		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
> 		...
> 	}
> 
> ... or in a separate block which checks the same condition.
> 
> Thanks,
> Mark.
> 
>> +
>>  	if (!user_mode(regs)) {
>>  		printk("pc : %pS\n", (void *)regs->pc);
>>  		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>> -- 
>> 2.25.1
>>
> .
> 

-- 
Regards,
  Zhen Lei

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-05 13:26     ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 16+ messages in thread
From: Leizhen (ThunderTown) @ 2022-05-05 13:26 UTC (permalink / raw)
  To: Mark Rutland; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel



On 2022/5/5 21:04, Mark Rutland wrote:
> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
>> pcpu access. However, when performing reverse execution based on the
>> registers and the memory contents in kdump, this information is sometimes
>> required if there is a pcpu access.
>>
>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>> ---
>>  arch/arm64/kernel/process.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> v2 --> v3:
>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>>    "if (is_kernel_in_hyp_mode())" statement.
>> 2) Change the register name to lowercase.
>>
>> v1 --> v2:
>> Directly print the tpidr_elx register of the current exception level.
>> Avoid coupling with the implementation of 'my_cpu_offset'.
>>
>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
>> --- a/arch/arm64/kernel/process.c
>> +++ b/arch/arm64/kernel/process.c
>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>>  	show_regs_print_info(KERN_DEFAULT);
>>  	print_pstate(regs);
>>  
>> +	if (is_kernel_in_hyp_mode())
>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
>> +	else
>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
> 
> If we care about the offset specifically, this would be simpler as:
> 
> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());

The function name is __show_regs(), so not using register name may not be good.
In fact, some other architectures may also have this problem. If we use my_cpu_offset,
we may need to put it in a public.

> 
> ... which should do the right thing even if we repurpose the TPIDRs and move the offset elsewhere.
> 
> As Will says, we should only log this for !user_mode(regs), so it could
> be placed in the block below, immediately before we print the kernel PC, i.e.
> 
> 	if (!user_mode_regs) {
> 		printk("cpu offset : %016lx\n", __my_cpu_offset());
> 		printk("pc : %pS\n", (void *)regs->pc);
> 		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
> 		...
> 	}
> 
> ... or in a separate block which checks the same condition.
> 
> Thanks,
> Mark.
> 
>> +
>>  	if (!user_mode(regs)) {
>>  		printk("pc : %pS\n", (void *)regs->pc);
>>  		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>> -- 
>> 2.25.1
>>
> .
> 

-- 
Regards,
  Zhen Lei

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
  2022-05-05 13:26     ` Leizhen (ThunderTown)
@ 2022-05-05 13:34       ` Leizhen (ThunderTown)
  -1 siblings, 0 replies; 16+ messages in thread
From: Leizhen (ThunderTown) @ 2022-05-05 13:34 UTC (permalink / raw)
  To: Mark Rutland; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel



On 2022/5/5 21:26, Leizhen (ThunderTown) wrote:
> 
> 
> On 2022/5/5 21:04, Mark Rutland wrote:
>> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
>>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
>>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
>>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
>>> pcpu access. However, when performing reverse execution based on the
>>> registers and the memory contents in kdump, this information is sometimes
>>> required if there is a pcpu access.
>>>
>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>>> ---
>>>  arch/arm64/kernel/process.c | 5 +++++
>>>  1 file changed, 5 insertions(+)
>>>
>>> v2 --> v3:
>>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>>>    "if (is_kernel_in_hyp_mode())" statement.
>>> 2) Change the register name to lowercase.
>>>
>>> v1 --> v2:
>>> Directly print the tpidr_elx register of the current exception level.
>>> Avoid coupling with the implementation of 'my_cpu_offset'.
>>>
>>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
>>> --- a/arch/arm64/kernel/process.c
>>> +++ b/arch/arm64/kernel/process.c
>>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>>>  	show_regs_print_info(KERN_DEFAULT);
>>>  	print_pstate(regs);
>>>  
>>> +	if (is_kernel_in_hyp_mode())
>>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
>>> +	else
>>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
>>
>> If we care about the offset specifically, this would be simpler as:
>>
>> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());
> 
> The function name is __show_regs(), so not using register name may not be good.
> In fact, some other architectures may also have this problem. If we use my_cpu_offset,
> we may need to put it in a public.

The other idea is to back up each my_cpu_offset in an array. In this way, the offset can
be queried through vmcore even if it is not printed.

> 
>>
>> ... which should do the right thing even if we repurpose the TPIDRs and move the offset elsewhere.
>>
>> As Will says, we should only log this for !user_mode(regs), so it could
>> be placed in the block below, immediately before we print the kernel PC, i.e.
>>
>> 	if (!user_mode_regs) {
>> 		printk("cpu offset : %016lx\n", __my_cpu_offset());
>> 		printk("pc : %pS\n", (void *)regs->pc);
>> 		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>> 		...
>> 	}
>>
>> ... or in a separate block which checks the same condition.
>>
>> Thanks,
>> Mark.
>>
>>> +
>>>  	if (!user_mode(regs)) {
>>>  		printk("pc : %pS\n", (void *)regs->pc);
>>>  		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>>> -- 
>>> 2.25.1
>>>
>> .
>>
> 

-- 
Regards,
  Zhen Lei

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-05 13:34       ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 16+ messages in thread
From: Leizhen (ThunderTown) @ 2022-05-05 13:34 UTC (permalink / raw)
  To: Mark Rutland; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel



On 2022/5/5 21:26, Leizhen (ThunderTown) wrote:
> 
> 
> On 2022/5/5 21:04, Mark Rutland wrote:
>> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
>>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
>>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
>>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
>>> pcpu access. However, when performing reverse execution based on the
>>> registers and the memory contents in kdump, this information is sometimes
>>> required if there is a pcpu access.
>>>
>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>>> ---
>>>  arch/arm64/kernel/process.c | 5 +++++
>>>  1 file changed, 5 insertions(+)
>>>
>>> v2 --> v3:
>>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>>>    "if (is_kernel_in_hyp_mode())" statement.
>>> 2) Change the register name to lowercase.
>>>
>>> v1 --> v2:
>>> Directly print the tpidr_elx register of the current exception level.
>>> Avoid coupling with the implementation of 'my_cpu_offset'.
>>>
>>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
>>> --- a/arch/arm64/kernel/process.c
>>> +++ b/arch/arm64/kernel/process.c
>>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>>>  	show_regs_print_info(KERN_DEFAULT);
>>>  	print_pstate(regs);
>>>  
>>> +	if (is_kernel_in_hyp_mode())
>>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
>>> +	else
>>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
>>
>> If we care about the offset specifically, this would be simpler as:
>>
>> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());
> 
> The function name is __show_regs(), so not using register name may not be good.
> In fact, some other architectures may also have this problem. If we use my_cpu_offset,
> we may need to put it in a public.

The other idea is to back up each my_cpu_offset in an array. In this way, the offset can
be queried through vmcore even if it is not printed.

> 
>>
>> ... which should do the right thing even if we repurpose the TPIDRs and move the offset elsewhere.
>>
>> As Will says, we should only log this for !user_mode(regs), so it could
>> be placed in the block below, immediately before we print the kernel PC, i.e.
>>
>> 	if (!user_mode_regs) {
>> 		printk("cpu offset : %016lx\n", __my_cpu_offset());
>> 		printk("pc : %pS\n", (void *)regs->pc);
>> 		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>> 		...
>> 	}
>>
>> ... or in a separate block which checks the same condition.
>>
>> Thanks,
>> Mark.
>>
>>> +
>>>  	if (!user_mode(regs)) {
>>>  		printk("pc : %pS\n", (void *)regs->pc);
>>>  		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>>> -- 
>>> 2.25.1
>>>
>> .
>>
> 

-- 
Regards,
  Zhen Lei

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
  2022-05-05 13:34       ` Leizhen (ThunderTown)
@ 2022-05-06  8:16         ` Leizhen (ThunderTown)
  -1 siblings, 0 replies; 16+ messages in thread
From: Leizhen (ThunderTown) @ 2022-05-06  8:16 UTC (permalink / raw)
  To: Mark Rutland; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel



On 2022/5/5 21:34, Leizhen (ThunderTown) wrote:
> 
> 
> On 2022/5/5 21:26, Leizhen (ThunderTown) wrote:
>>
>>
>> On 2022/5/5 21:04, Mark Rutland wrote:
>>> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
>>>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
>>>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
>>>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
>>>> pcpu access. However, when performing reverse execution based on the
>>>> registers and the memory contents in kdump, this information is sometimes
>>>> required if there is a pcpu access.
>>>>
>>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>>>> ---
>>>>  arch/arm64/kernel/process.c | 5 +++++
>>>>  1 file changed, 5 insertions(+)
>>>>
>>>> v2 --> v3:
>>>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>>>>    "if (is_kernel_in_hyp_mode())" statement.
>>>> 2) Change the register name to lowercase.
>>>>
>>>> v1 --> v2:
>>>> Directly print the tpidr_elx register of the current exception level.
>>>> Avoid coupling with the implementation of 'my_cpu_offset'.
>>>>
>>>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>>>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
>>>> --- a/arch/arm64/kernel/process.c
>>>> +++ b/arch/arm64/kernel/process.c
>>>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>>>>  	show_regs_print_info(KERN_DEFAULT);
>>>>  	print_pstate(regs);
>>>>  
>>>> +	if (is_kernel_in_hyp_mode())
>>>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
>>>> +	else
>>>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
>>>
>>> If we care about the offset specifically, this would be simpler as:
>>>
>>> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());
>>
>> The function name is __show_regs(), so not using register name may not be good.
>> In fact, some other architectures may also have this problem. If we use my_cpu_offset,
>> we may need to put it in a public.
> 
> The other idea is to back up each my_cpu_offset in an array. In this way, the offset can
> be queried through vmcore even if it is not printed.

Sorry, __per_cpu_offset[NR_CPUS] is always defined.

> 
>>
>>>
>>> ... which should do the right thing even if we repurpose the TPIDRs and move the offset elsewhere.
>>>
>>> As Will says, we should only log this for !user_mode(regs), so it could
>>> be placed in the block below, immediately before we print the kernel PC, i.e.
>>>
>>> 	if (!user_mode_regs) {
>>> 		printk("cpu offset : %016lx\n", __my_cpu_offset());
>>> 		printk("pc : %pS\n", (void *)regs->pc);
>>> 		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>>> 		...
>>> 	}
>>>
>>> ... or in a separate block which checks the same condition.
>>>
>>> Thanks,
>>> Mark.
>>>
>>>> +
>>>>  	if (!user_mode(regs)) {
>>>>  		printk("pc : %pS\n", (void *)regs->pc);
>>>>  		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>>>> -- 
>>>> 2.25.1
>>>>
>>> .
>>>
>>
> 

-- 
Regards,
  Zhen Lei

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-06  8:16         ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 16+ messages in thread
From: Leizhen (ThunderTown) @ 2022-05-06  8:16 UTC (permalink / raw)
  To: Mark Rutland; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel



On 2022/5/5 21:34, Leizhen (ThunderTown) wrote:
> 
> 
> On 2022/5/5 21:26, Leizhen (ThunderTown) wrote:
>>
>>
>> On 2022/5/5 21:04, Mark Rutland wrote:
>>> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
>>>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
>>>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
>>>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
>>>> pcpu access. However, when performing reverse execution based on the
>>>> registers and the memory contents in kdump, this information is sometimes
>>>> required if there is a pcpu access.
>>>>
>>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>>>> ---
>>>>  arch/arm64/kernel/process.c | 5 +++++
>>>>  1 file changed, 5 insertions(+)
>>>>
>>>> v2 --> v3:
>>>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>>>>    "if (is_kernel_in_hyp_mode())" statement.
>>>> 2) Change the register name to lowercase.
>>>>
>>>> v1 --> v2:
>>>> Directly print the tpidr_elx register of the current exception level.
>>>> Avoid coupling with the implementation of 'my_cpu_offset'.
>>>>
>>>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>>>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
>>>> --- a/arch/arm64/kernel/process.c
>>>> +++ b/arch/arm64/kernel/process.c
>>>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>>>>  	show_regs_print_info(KERN_DEFAULT);
>>>>  	print_pstate(regs);
>>>>  
>>>> +	if (is_kernel_in_hyp_mode())
>>>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
>>>> +	else
>>>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
>>>
>>> If we care about the offset specifically, this would be simpler as:
>>>
>>> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());
>>
>> The function name is __show_regs(), so not using register name may not be good.
>> In fact, some other architectures may also have this problem. If we use my_cpu_offset,
>> we may need to put it in a public.
> 
> The other idea is to back up each my_cpu_offset in an array. In this way, the offset can
> be queried through vmcore even if it is not printed.

Sorry, __per_cpu_offset[NR_CPUS] is always defined.

> 
>>
>>>
>>> ... which should do the right thing even if we repurpose the TPIDRs and move the offset elsewhere.
>>>
>>> As Will says, we should only log this for !user_mode(regs), so it could
>>> be placed in the block below, immediately before we print the kernel PC, i.e.
>>>
>>> 	if (!user_mode_regs) {
>>> 		printk("cpu offset : %016lx\n", __my_cpu_offset());
>>> 		printk("pc : %pS\n", (void *)regs->pc);
>>> 		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>>> 		...
>>> 	}
>>>
>>> ... or in a separate block which checks the same condition.
>>>
>>> Thanks,
>>> Mark.
>>>
>>>> +
>>>>  	if (!user_mode(regs)) {
>>>>  		printk("pc : %pS\n", (void *)regs->pc);
>>>>  		printk("lr : %pS\n", (void *)ptrauth_strip_insn_pac(lr));
>>>> -- 
>>>> 2.25.1
>>>>
>>> .
>>>
>>
> 

-- 
Regards,
  Zhen Lei

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
  2022-05-06  8:16         ` Leizhen (ThunderTown)
@ 2022-05-06 10:09           ` Mark Rutland
  -1 siblings, 0 replies; 16+ messages in thread
From: Mark Rutland @ 2022-05-06 10:09 UTC (permalink / raw)
  To: Leizhen (ThunderTown)
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel

On Fri, May 06, 2022 at 04:16:55PM +0800, Leizhen (ThunderTown) wrote:
> 
> 
> On 2022/5/5 21:34, Leizhen (ThunderTown) wrote:
> > On 2022/5/5 21:26, Leizhen (ThunderTown) wrote:
> >> On 2022/5/5 21:04, Mark Rutland wrote:
> >>> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
> >>>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
> >>>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
> >>>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
> >>>> pcpu access. However, when performing reverse execution based on the
> >>>> registers and the memory contents in kdump, this information is sometimes
> >>>> required if there is a pcpu access.
> >>>>
> >>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> >>>> ---
> >>>>  arch/arm64/kernel/process.c | 5 +++++
> >>>>  1 file changed, 5 insertions(+)
> >>>>
> >>>> v2 --> v3:
> >>>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
> >>>>    "if (is_kernel_in_hyp_mode())" statement.
> >>>> 2) Change the register name to lowercase.
> >>>>
> >>>> v1 --> v2:
> >>>> Directly print the tpidr_elx register of the current exception level.
> >>>> Avoid coupling with the implementation of 'my_cpu_offset'.
> >>>>
> >>>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> >>>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
> >>>> --- a/arch/arm64/kernel/process.c
> >>>> +++ b/arch/arm64/kernel/process.c
> >>>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
> >>>>  	show_regs_print_info(KERN_DEFAULT);
> >>>>  	print_pstate(regs);
> >>>>  
> >>>> +	if (is_kernel_in_hyp_mode())
> >>>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
> >>>> +	else
> >>>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
> >>>
> >>> If we care about the offset specifically, this would be simpler as:
> >>>
> >>> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());
> >>
> >> The function name is __show_regs(), so not using register name may not be good.
> >> In fact, some other architectures may also have this problem. If we use my_cpu_offset,
> >> we may need to put it in a public.
> > 
> > The other idea is to back up each my_cpu_offset in an array. In this way, the offset can
> > be queried through vmcore even if it is not printed.
> 
> Sorry, __per_cpu_offset[NR_CPUS] is always defined.

Surely that's in the vmcore already? It's just data in memory.

Thanks,
Mark.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-06 10:09           ` Mark Rutland
  0 siblings, 0 replies; 16+ messages in thread
From: Mark Rutland @ 2022-05-06 10:09 UTC (permalink / raw)
  To: Leizhen (ThunderTown)
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel

On Fri, May 06, 2022 at 04:16:55PM +0800, Leizhen (ThunderTown) wrote:
> 
> 
> On 2022/5/5 21:34, Leizhen (ThunderTown) wrote:
> > On 2022/5/5 21:26, Leizhen (ThunderTown) wrote:
> >> On 2022/5/5 21:04, Mark Rutland wrote:
> >>> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
> >>>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
> >>>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
> >>>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
> >>>> pcpu access. However, when performing reverse execution based on the
> >>>> registers and the memory contents in kdump, this information is sometimes
> >>>> required if there is a pcpu access.
> >>>>
> >>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> >>>> ---
> >>>>  arch/arm64/kernel/process.c | 5 +++++
> >>>>  1 file changed, 5 insertions(+)
> >>>>
> >>>> v2 --> v3:
> >>>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
> >>>>    "if (is_kernel_in_hyp_mode())" statement.
> >>>> 2) Change the register name to lowercase.
> >>>>
> >>>> v1 --> v2:
> >>>> Directly print the tpidr_elx register of the current exception level.
> >>>> Avoid coupling with the implementation of 'my_cpu_offset'.
> >>>>
> >>>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> >>>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
> >>>> --- a/arch/arm64/kernel/process.c
> >>>> +++ b/arch/arm64/kernel/process.c
> >>>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
> >>>>  	show_regs_print_info(KERN_DEFAULT);
> >>>>  	print_pstate(regs);
> >>>>  
> >>>> +	if (is_kernel_in_hyp_mode())
> >>>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
> >>>> +	else
> >>>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
> >>>
> >>> If we care about the offset specifically, this would be simpler as:
> >>>
> >>> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());
> >>
> >> The function name is __show_regs(), so not using register name may not be good.
> >> In fact, some other architectures may also have this problem. If we use my_cpu_offset,
> >> we may need to put it in a public.
> > 
> > The other idea is to back up each my_cpu_offset in an array. In this way, the offset can
> > be queried through vmcore even if it is not printed.
> 
> Sorry, __per_cpu_offset[NR_CPUS] is always defined.

Surely that's in the vmcore already? It's just data in memory.

Thanks,
Mark.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
  2022-05-06 10:09           ` Mark Rutland
@ 2022-05-06 10:21             ` Leizhen (ThunderTown)
  -1 siblings, 0 replies; 16+ messages in thread
From: Leizhen (ThunderTown) @ 2022-05-06 10:21 UTC (permalink / raw)
  To: Mark Rutland; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel



On 2022/5/6 18:09, Mark Rutland wrote:
> On Fri, May 06, 2022 at 04:16:55PM +0800, Leizhen (ThunderTown) wrote:
>>
>>
>> On 2022/5/5 21:34, Leizhen (ThunderTown) wrote:
>>> On 2022/5/5 21:26, Leizhen (ThunderTown) wrote:
>>>> On 2022/5/5 21:04, Mark Rutland wrote:
>>>>> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
>>>>>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
>>>>>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
>>>>>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
>>>>>> pcpu access. However, when performing reverse execution based on the
>>>>>> registers and the memory contents in kdump, this information is sometimes
>>>>>> required if there is a pcpu access.
>>>>>>
>>>>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>>>>>> ---
>>>>>>  arch/arm64/kernel/process.c | 5 +++++
>>>>>>  1 file changed, 5 insertions(+)
>>>>>>
>>>>>> v2 --> v3:
>>>>>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>>>>>>    "if (is_kernel_in_hyp_mode())" statement.
>>>>>> 2) Change the register name to lowercase.
>>>>>>
>>>>>> v1 --> v2:
>>>>>> Directly print the tpidr_elx register of the current exception level.
>>>>>> Avoid coupling with the implementation of 'my_cpu_offset'.
>>>>>>
>>>>>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>>>>>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
>>>>>> --- a/arch/arm64/kernel/process.c
>>>>>> +++ b/arch/arm64/kernel/process.c
>>>>>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>>>>>>  	show_regs_print_info(KERN_DEFAULT);
>>>>>>  	print_pstate(regs);
>>>>>>  
>>>>>> +	if (is_kernel_in_hyp_mode())
>>>>>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
>>>>>> +	else
>>>>>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
>>>>>
>>>>> If we care about the offset specifically, this would be simpler as:
>>>>>
>>>>> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());
>>>>
>>>> The function name is __show_regs(), so not using register name may not be good.
>>>> In fact, some other architectures may also have this problem. If we use my_cpu_offset,
>>>> we may need to put it in a public.
>>>
>>> The other idea is to back up each my_cpu_offset in an array. In this way, the offset can
>>> be queried through vmcore even if it is not printed.
>>
>> Sorry, __per_cpu_offset[NR_CPUS] is always defined.
> 
> Surely that's in the vmcore already? It's just data in memory.

Yes. There is also a definition in drivers/base/arch_numa.c. I didn't search the drivers directory
at first. I thought there would be no definition when CONFIG_HAVE_SETUP_PER_CPU_AREA=y.

crash> p -x __per_cpu_offset
__per_cpu_offset = $1 =
 {0xffff8003f460d000, 0xffff8003f4621000, 0xffff8003f4635000, 0xffff8003f4649000


> 
> Thanks,
> Mark.
> .
> 

-- 
Regards,
  Zhen Lei

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs()
@ 2022-05-06 10:21             ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 16+ messages in thread
From: Leizhen (ThunderTown) @ 2022-05-06 10:21 UTC (permalink / raw)
  To: Mark Rutland; +Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel



On 2022/5/6 18:09, Mark Rutland wrote:
> On Fri, May 06, 2022 at 04:16:55PM +0800, Leizhen (ThunderTown) wrote:
>>
>>
>> On 2022/5/5 21:34, Leizhen (ThunderTown) wrote:
>>> On 2022/5/5 21:26, Leizhen (ThunderTown) wrote:
>>>> On 2022/5/5 21:04, Mark Rutland wrote:
>>>>> On Thu, May 05, 2022 at 05:56:40PM +0800, Zhen Lei wrote:
>>>>>> Commit 7158627686f0 ("arm64: percpu: implement optimised pcpu access
>>>>>> using tpidr_el1") and commit 6d99b68933fb ("arm64: alternatives: use
>>>>>> tpidr_el2 on VHE hosts") use tpidr_elx to cache my_cpu_offset to optimize
>>>>>> pcpu access. However, when performing reverse execution based on the
>>>>>> registers and the memory contents in kdump, this information is sometimes
>>>>>> required if there is a pcpu access.
>>>>>>
>>>>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>>>>>> ---
>>>>>>  arch/arm64/kernel/process.c | 5 +++++
>>>>>>  1 file changed, 5 insertions(+)
>>>>>>
>>>>>> v2 --> v3:
>>>>>> 1) Relace "switch (read_sysreg(CurrentEL))" statement with
>>>>>>    "if (is_kernel_in_hyp_mode())" statement.
>>>>>> 2) Change the register name to lowercase.
>>>>>>
>>>>>> v1 --> v2:
>>>>>> Directly print the tpidr_elx register of the current exception level.
>>>>>> Avoid coupling with the implementation of 'my_cpu_offset'.
>>>>>>
>>>>>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>>>>>> index 7fa97df55e3ad3f..7b6bccce9721c36 100644
>>>>>> --- a/arch/arm64/kernel/process.c
>>>>>> +++ b/arch/arm64/kernel/process.c
>>>>>> @@ -216,6 +216,11 @@ void __show_regs(struct pt_regs *regs)
>>>>>>  	show_regs_print_info(KERN_DEFAULT);
>>>>>>  	print_pstate(regs);
>>>>>>  
>>>>>> +	if (is_kernel_in_hyp_mode())
>>>>>> +		printk("tpidr_el2 : %016llx\n", read_sysreg(tpidr_el2));
>>>>>> +	else
>>>>>> +		printk("tpidr_el1 : %016llx\n", read_sysreg(tpidr_el1));
>>>>>
>>>>> If we care about the offset specifically, this would be simpler as:
>>>>>
>>>>> 	printk("cpu offset : 0x%016lx\n", __my_cpu_offset());
>>>>
>>>> The function name is __show_regs(), so not using register name may not be good.
>>>> In fact, some other architectures may also have this problem. If we use my_cpu_offset,
>>>> we may need to put it in a public.
>>>
>>> The other idea is to back up each my_cpu_offset in an array. In this way, the offset can
>>> be queried through vmcore even if it is not printed.
>>
>> Sorry, __per_cpu_offset[NR_CPUS] is always defined.
> 
> Surely that's in the vmcore already? It's just data in memory.

Yes. There is also a definition in drivers/base/arch_numa.c. I didn't search the drivers directory
at first. I thought there would be no definition when CONFIG_HAVE_SETUP_PER_CPU_AREA=y.

crash> p -x __per_cpu_offset
__per_cpu_offset = $1 =
 {0xffff8003f460d000, 0xffff8003f4621000, 0xffff8003f4635000, 0xffff8003f4649000


> 
> Thanks,
> Mark.
> .
> 

-- 
Regards,
  Zhen Lei

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-05-06 10:23 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05  9:56 [PATCH v3] arm64: add the printing of tpidr_elx in __show_regs() Zhen Lei
2022-05-05  9:56 ` Zhen Lei
2022-05-05 10:51 ` Will Deacon
2022-05-05 10:51   ` Will Deacon
2022-05-05 13:04 ` Mark Rutland
2022-05-05 13:04   ` Mark Rutland
2022-05-05 13:26   ` Leizhen (ThunderTown)
2022-05-05 13:26     ` Leizhen (ThunderTown)
2022-05-05 13:34     ` Leizhen (ThunderTown)
2022-05-05 13:34       ` Leizhen (ThunderTown)
2022-05-06  8:16       ` Leizhen (ThunderTown)
2022-05-06  8:16         ` Leizhen (ThunderTown)
2022-05-06 10:09         ` Mark Rutland
2022-05-06 10:09           ` Mark Rutland
2022-05-06 10:21           ` Leizhen (ThunderTown)
2022-05-06 10:21             ` Leizhen (ThunderTown)

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.