Skip to contentSkip to conversation

arm64: add architecture specified current_pt_regs

PATCH In review Zhi-zhou Zhang 3 participants 5 messages Feb 18, 2016 – Feb 19, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: add architecture specified current_pt_regs

From: zhizhou <[email protected]>

This patch is based on the implementation of arm. The generic current_pt_regs is implemented with current->stack. It need to access memory that would be too expensive.

---
 arch/arm64/include/asm/ptrace.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm64/include/asm/ptrace.h +4 -0
index e9e5467..1865d54 100644
@@ -185,5 +185,9 @@ static inline int valid_user_regs(struct user_pt_regs *regs)
 
 extern unsigned long profile_pc(struct pt_regs *regs);
 
+#define current_pt_regs(void) ({ (struct pt_regs *)			\
+	((current_stack_pointer | (THREAD_SIZE - 1)) - 0xf) - 1;	\
+})
+
 #endif /* __ASSEMBLY__ */
 #endif
Signature · 1 line
2.5.0
maintainer
#1 lore raw
Quoted 5 lines · Zhi-zhou Zhang

From: zhizhou <[email protected]>

This patch is based on the implementation of arm. The generic current_pt_regs is implemented with current->stack. It need to access memory that would be too expensive.

Do you have any performance numbers?

arch/arm64/include/asm/ptrace.h static inline int valid_user_regs(struct user_pt_regs *regs) · line 190

Quoted 11 lines
arch/arm64/include/asm/ptrace.h +3 -0
index e9e5467..1865d54 100644
@@ -185,5 +185,9 @@ static inline int valid_user_regs(struct user_pt_regs *regs)
 
 extern unsigned long profile_pc(struct pt_regs *regs);
 
+#define current_pt_regs(void) ({ (struct pt_regs *)			\
+	((current_stack_pointer | (THREAD_SIZE - 1)) - 0xf) - 1;	\
+})

I don't think this works well with the separate IRQ stack that we merged in 4.5-rc1. current_thread_info() explicitly uses "sp_el0" while current_stack_pointer is just "sp" (though I don't think we ever use current_pt_regs in interrupt context).

Signature · 1 line
Catalin
author
#2 lore raw
Quoted 9 lines · Catalin Marinas
Quoted 5 lines · Zhi-zhou Zhang

From: zhizhou <[email protected]>

This patch is based on the implementation of arm. The generic current_pt_regs is implemented with current->stack. It need to access memory that would be too expensive.

Do you have any performance numbers?

I'm using QEMU, so no. Actually this macro isn't heavily used. I just think using the generic
implementation is not very nice. It get task_struct from sp_el0, then get stack(which is
equal to sp_el0) from task_struct. There are two unnecessary memory accesses.

Quoted 10 lines
Quoted 10 lines
arch/arm64/include/asm/ptrace.h +0 -0
index e9e5467..1865d54 100644
@@ -185,5 +185,9 @@ static inline int valid_user_regs(struct user_pt_regs *regs)
 
 extern unsigned long profile_pc(struct pt_regs *regs);
 
Quoted 9 lines

arch/arm64/include/asm/ptrace.h static inline int valid_user_regs(struct user_pt_regs *regs) · line 190

Quoted 3 lines
arch/arm64/include/asm/ptrace.h +3 -0
+#define current_pt_regs(void) ({ (struct pt_regs *)                  \
+     ((current_stack_pointer | (THREAD_SIZE - 1)) - 0xf) - 1;        \
+})

I don't think this works well with the separate IRQ stack that we merged in 4.5-rc1. current_thread_info() explicitly uses "sp_el0" while current_stack_pointer is just "sp" (though I don't think we ever use current_pt_regs in interrupt context).

Thank you, that's a problem. So how about write it like this?

arch/arm64/include/asm/ptrace.h +0 -0
index e9e5467..b68e01c 100644
@@ -185,5 +185,10 @@ static inline int valid_user_regs(struct

user_pt_regs *regs)

extern unsigned long profile_pc(struct pt_regs *regs);

+#define current_pt_regs(void) ({ (struct pt_regs *)            \
+               (((unsigned long)current_thread_info() |        \
+               (THREAD_SIZE - 1)) - 0xf) - 1;                  \

+})
+
#endif /* __ASSEMBLY__ */
#endif

Quoted 2 lines

--
Catalin

Signature · 2 lines
Regards,
Zhi-zhou
#3 lore raw
Quoted 10 lines · Zhi-zhou
Quoted 8 lines · Catalin Marinas
Quoted 5 lines · Zhi-zhou Zhang

From: zhizhou <[email protected]>

This patch is based on the implementation of arm. The generic current_pt_regs is implemented with current->stack. It need to access memory that would be too expensive.

Quoted 7 lines
Quoted 1 line

Do you have any performance numbers?

I'm using QEMU, so no. Actually this macro isn't heavily used. I just think using the generic
implementation is not very nice. It get task_struct from sp_el0, then get stack(which is
equal to sp_el0) from task_struct. There are two unnecessary memory accesses.

I'd much rather use the generic implementation unless there's a compelling reason not to. "I think it's not very nice" doesn't really cut it for me!

Will

#4 lore raw
Quoted 13 lines · Will Deacon
Quoted 12 lines · Zhi-zhou
Quoted 9 lines · Catalin Marinas
Quoted 5 lines · Zhi-zhou Zhang

From: zhizhou <[email protected]>

This patch is based on the implementation of arm. The generic current_pt_regs is implemented with current->stack. It need to access memory that would be too expensive.

Do you have any performance numbers?

Quoted 8 lines
Quoted 5 lines

I'm using QEMU, so no. Actually this macro isn't heavily used. I just think using the generic
implementation is not very nice. It get task_struct from sp_el0, then get stack(which is
equal to sp_el0) from task_struct. There are two unnecessary memory accesses.

I'd much rather use the generic implementation unless there's a compelling reason not to. "I think it's not very nice" doesn't really cut it for me!

Refer to memory twice may incur cache eviction. I'm really a newbie to kernel. Anyway, I have a look at kernel and I'm very curious what's the 'compelling reason' of 16 architectures implement their own current_pt_regs?

Quoted 2 lines

Will

Signature · 2 lines
Regards,
Zhizhou