Skip to contentSkip to conversation

powerpc: Export thread_struct.used_vr/used_vsr to user space

PATCH RESEND Superseded Simon Guo 2 participants 5 messages Apr 6, 2016 – Jul 5, 2016 1 message not in the archive

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Simon Guo

author
#0 lore raw

PATCH RESEND v2 1/1 powerpc: Export thread_struct.used_vr/used_vsr to user space

These 2 fields track whether user process has used Altivec/VSX registers or not. They are used by kernel to setup signal frame on user stack correctly regarding vector part.

CRIU(Checkpoint and Restore In User space) builds signal frame for restored process. It will need this export information to setup signal frame correctly. And CRIU will need to restore these 2 fields for the restored process.

---
 arch/powerpc/include/uapi/asm/ptrace.h | 11 ++++++++++
 arch/powerpc/kernel/ptrace.c           | 39 ++++++++++++++++++++++++++++++++++
 arch/powerpc/kernel/ptrace32.c         |  2 ++
 3 files changed, 52 insertions(+)
arch/powerpc/include/uapi/asm/ptrace.h +11 -0
index 8036b38..d5afe95 100644
@@ -176,6 +176,17 @@ struct pt_regs {
 #define PTRACE_GETREGS64	  0x16
 #define PTRACE_SETREGS64	  0x17
 
+/*
+ * Get or set some register used bit.
+ * The flags will be saved in a 32 bit data.
+ * Currently it is only used for VR/VSR usage.
+ */
+#define PTRACE_GET_REGS_USAGE	  0x1e
+#define PTRACE_SET_REGS_USAGE	  0x1f
+
+#define PTRACE_REGS_USAGE_VR_BIT  0x00000001
+#define PTRACE_REGS_USAGE_VSR_BIT 0x00000002
+
 /* Calls to trace a 64bit program from a 32bit program */
 #define PPC_PTRACE_PEEKTEXT_3264 0x95
 #define PPC_PTRACE_PEEKDATA_3264 0x94
arch/powerpc/kernel/ptrace.c +39 -0
index 30a03c0..39b8ff2 100644
@@ -1755,6 +1755,45 @@ long arch_ptrace(struct task_struct *child, long request,
 					     REGSET_SPE, 0, 35 * sizeof(u32),
 					     datavp);
 #endif
+	case PTRACE_GET_REGS_USAGE:
+		{
+			u32 *u32_datap = (u32 *)datavp;
+			u32 reg_usage = 0;
+
+			if (addr != sizeof(u32))
+				return -EINVAL;
+
+#ifdef CONFIG_ALTIVEC
+			if (child->thread.used_vr)
+				reg_usage |= PTRACE_REGS_USAGE_VR_BIT;
+#endif
+#ifdef CONFIG_VSX
+			if (child->thread.used_vsr)
+				reg_usage |= PTRACE_REGS_USAGE_VSR_BIT;
+#endif
+			return put_user(reg_usage, u32_datap);
+		}
+	case PTRACE_SET_REGS_USAGE:
+		{
+			u32 *u32_datap = (u32 *)datavp;
+			u32 reg_usage = 0;
+
+			if (addr != sizeof(u32))
+				return -EINVAL;
+
+			ret = get_user(reg_usage, u32_datap);
+			if (ret)
+				return ret;
+#ifdef CONFIG_ALTIVEC
+			child->thread.used_vr =
+				!!(reg_usage & PTRACE_REGS_USAGE_VR_BIT);
+#endif
+#ifdef CONFIG_VSX
+			child->thread.used_vsr =
+				!!(reg_usage & PTRACE_REGS_USAGE_VSR_BIT);
+#endif
+			break;
+		}
 
 	default:
 		ret = ptrace_request(child, request, addr, data);
arch/powerpc/kernel/ptrace32.c +2 -0
index f52b7db..ff359a1 100644
@@ -305,6 +305,8 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
 	case PPC_PTRACE_GETHWDBGINFO:
 	case PPC_PTRACE_SETHWDEBUG:
 	case PPC_PTRACE_DELHWDEBUG:
+	case PTRACE_GET_REGS_USAGE:
+	case PTRACE_SET_REGS_USAGE:
 		ret = arch_ptrace(child, request, addr, data);
 		break;
 
Signature · 1 line
2.7.0
author
#1 lore raw

Hi Michael,

Quoted 4 lines · Simon Guo

These 2 fields track whether user process has used Altivec/VSX registers or not. They are used by kernel to setup signal frame on user stack correctly regarding vector part.

Quoted 8 lines

CRIU(Checkpoint and Restore In User space) builds signal frame for restored process. It will need this export information to setup signal frame correctly. And CRIU will need to restore these 2 fields for the restored process.

---

Is there any chance that this patch can be merged upstream soon? The corresponding work of CRIU has to follow after that.

Thanks,
Simon

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#3 lore raw
Quoted 15 lines · Simon Guo

Hi Michael,

Quoted 4 lines · Simon Guo

These 2 fields track whether user process has used Altivec/VSX registers or not. They are used by kernel to setup signal frame on user stack correctly regarding vector part.

Quoted 8 lines

CRIU(Checkpoint and Restore In User space) builds signal frame for restored process. It will need this export information to setup signal frame correctly. And CRIU will need to restore these 2 fields for the restored process.

---

Quoted 7 lines

Just a kind reminder per our previous discussion.
If possible, please help pull this in during 4.8 merge window. Some CRIU work items are pending for it.

Have a nice day.

Thanks,
- Simon

+ linuxppc-dev list

Thanks,
- Simon (IBM LTC)

#4 lore raw
In reply to Simon Guo
Quoted 20 lines · Simon Guo

These 2 fields track whether user process has used Altivec/VSX registers or not. They are used by kernel to setup signal frame on user stack correctly regarding vector part.

CRIU(Checkpoint and Restore In User space) builds signal frame for restored process. It will need this export information to setup signal frame correctly. And CRIU will need to restore these 2 fields for the restored process.

arch/powerpc/include/uapi/asm/ptrace.h +0 -0
index 8036b38..d5afe95 100644
@@ -176,6 +176,17 @@ struct pt_regs {
 #define PTRACE_GETREGS64	  0x16
 #define PTRACE_SETREGS64	  0x17
 

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs { · line 188

Quoted 10 lines
arch/powerpc/include/uapi/asm/ptrace.h +10 -0
+/*
+ * Get or set some register used bit.
+ * The flags will be saved in a 32 bit data.
+ * Currently it is only used for VR/VSR usage.
+ */
+#define PTRACE_GET_REGS_USAGE	  0x1e
+#define PTRACE_SET_REGS_USAGE	  0x1f
+
+#define PTRACE_REGS_USAGE_VR_BIT  0x00000001
+#define PTRACE_REGS_USAGE_VSR_BIT 0x00000002

It looks like you just made up this new ptrace ABI ?

Or is it used on other arches ? (no AFAICS)

How do other arches handle this ?

I'm a bit wary of adding new ptrace ABIs.

If we do want to do this, I'd at least think the mask should be u64, to give us more capacity to add new registers.

cheers

author
#5 lore raw

Hi Michael,

Quoted 32 lines · Michael Ellerman
Quoted 15 lines · Simon Guo

These 2 fields track whether user process has used Altivec/VSX registers or not. They are used by kernel to setup signal frame on user stack correctly regarding vector part.

CRIU(Checkpoint and Restore In User space) builds signal frame for restored process. It will need this export information to setup signal frame correctly. And CRIU will need to restore these 2 fields for the restored process.

arch/powerpc/include/uapi/asm/ptrace.h +0 -0
@@ -176,6 +176,17 @@ struct pt_regs {
 #define PTRACE_GETREGS64	  0x16
 #define PTRACE_SETREGS64	  0x17
 

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs { · line 188

Quoted 10 lines
arch/powerpc/include/uapi/asm/ptrace.h +10 -0
+/*
+ * Get or set some register used bit.
+ * The flags will be saved in a 32 bit data.
+ * Currently it is only used for VR/VSR usage.
+ */
+#define PTRACE_GET_REGS_USAGE	  0x1e
+#define PTRACE_SET_REGS_USAGE	  0x1f
+
+#define PTRACE_REGS_USAGE_VR_BIT  0x00000001
+#define PTRACE_REGS_USAGE_VSR_BIT 0x00000002

It looks like you just made up this new ptrace ABI ?

Or is it used on other arches ? (no AFAICS)

Quoted 8 lines

How do other arches handle this ?

I'm a bit wary of adding new ptrace ABIs.

If we do want to do this, I'd at least think the mask should be u64, to give us more capacity to add new registers.

cheers

It is only used on PowerPc currently. I had better rename it to:
#define PPC_PTRACE_GET_REGS_USAGE 0x96
#define PPC_PTRACE_SET_REGS_USAGE 0x97

I will change the mask into u64.

Thanks,
- Simon