Skip to contentSkip to conversation

powerpc: Export thread_struct.used_vr/used_vsr to user space

PATCH In review [email protected] 4 participants 13 messages Jul 7, 2016 – Jul 25, 2016 2 messages not in the archive

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

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

From: Simon Guo <[email protected]>

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.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Kees Cook <[email protected]>
Cc Rashmica Gupta <[email protected]>
Cc Laurent Dufour <[email protected]>

--

v3 -> v4:
- Copying 64 bit data from/to user space using get_user/put_user is not supported on all architectures, and may result in the following build error on 32 bits build:
arch/powerpc/kernel/built-in.o: In function `arch_ptrace':

Quoted 1 line
Quoted 1 line

(.text+0xad4): undefined reference to `__get_user_bad'

using copy_from_user/copy_to_user instead.

v2 -> v3:
- enlarge reg_usage from 32 to 64 bits
- prefix ptrace API with PPC_

v1 -> v2:
- minor change for coding style

---
 arch/powerpc/include/uapi/asm/ptrace.h | 11 ++++++++
 arch/powerpc/kernel/ptrace.c           | 48 ++++++++++++++++++++++++++++++++++
 arch/powerpc/kernel/ptrace32.c         |  2 ++
 3 files changed, 61 insertions(+)
arch/powerpc/include/uapi/asm/ptrace.h +11 -0
index 8036b38..b357677 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 64 bit data.
+ * Currently it is only used for VR/VSR usage.
+ */
+#define PPC_PTRACE_GET_REGS_USAGE	  0x97
+#define PPC_PTRACE_SET_REGS_USAGE	  0x96
+
+#define PPC_PTRACE_REGS_USAGE_VR_BIT  0x01UL
+#define PPC_PTRACE_REGS_USAGE_VSR_BIT 0x02UL
+
 /* 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 +48 -0

54 lines not on this page · raw message

arch/powerpc/kernel/ptrace32.c +2 -0
index f52b7db..3aaa773 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 PPC_PTRACE_GET_REGS_USAGE:
+	case PPC_PTRACE_SET_REGS_USAGE:
 		ret = arch_ptrace(child, request, addr, data);
 		break;
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Simon Guo

From: Simon Guo <[email protected]>

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.

I still dislike this. It's just exporting internal kernel state, which I know is the point.

And I'd still like to know why we're the only arch that needs to do this.

I'm not saying I won't merge it, but I'd like to understand it better first.

Quoted 4 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.

I don't really know how CRIU works, but ..

Does the kernel write a sigframe for the process that's being checkpointed? If so can't you infer the state of the bits based on what was written?

Alternately, when restoring, can you setup the sigframe with the Altivec/VSX fields populated, and the kernel will then load them, regardless of whether they were actually used or not prior to the checkpoint?

cheers

#2 lore raw
Quoted 19 lines · Michael Ellerman
Quoted 5 lines · Simon Guo

From: Simon Guo <[email protected]>

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.

I still dislike this. It's just exporting internal kernel state, which I know is the point.

And I'd still like to know why we're the only arch that needs to do this.

I'm not saying I won't merge it, but I'd like to understand it better first.

Quoted 4 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 4 lines

I don't really know how CRIU works, but ..

Does the kernel write a sigframe for the process that's being checkpointed? If so can't you infer the state of the bits based on what was written?

Hi Michael,

Basically, CRIU checkpoints the process register's state through the ptrace API, and it restores it through a signal frame at restart time. This is quite odd but that the way it works on all the CRIU's supported architectures.

Obviously everything is done from/in user space, so the sigframe building too.
Since we can't know from user space if the thread has used or not the Altivec/VSX registers, since we can't rely on the MSR bits, we always dump these registers.

Quoted 3 lines

Alternately, when restoring, can you setup the sigframe with the Altivec/VSX fields populated, and the kernel will then load them, regardless of whether they were actually used or not prior to the checkpoint?

In the case of Altivec/VSX fields, we currently force the kernel to retrieve them from the signal frame by setting MSR_VEC/MSR_VSX so restore_sigcontext() will copy them to the kernel thread's state. However this doesn't touch to used_vsr and used_vr which may remain at 0.

Most of the time this is fine, but in the case a thread which has really used those registers is catching a signal just after the restore and before it has touched to these registers again (and so set used_vsr/vr), these registers will not be pushed in the newly built signal frame since setup_sigcontext() check for used_vsr/vr before pushing the registers on the stack.
This may be an issue in the case the thread wants to changed those registers (don't ask me why :)) in the stacked signal frame from the signal handler since they will not be there...

Being able to get and set the used_vr and used_vsr thread's variables, fixes this issue.

Cheers,
Laurent.

#3 lore raw
Quoted 11 lines · Laurent Dufour

Basically, CRIU checkpoints the process register's state through the ptrace API, and it restores it through a signal frame at restart time. This is quite odd but that the way it works on all the CRIU's supported architectures.

Obviously everything is done from/in user space, so the sigframe building too.
Since we can't know from user space if the thread has used or not the Altivec/VSX registers, since we can't rely on the MSR bits, we always dump these registers.

Right, however is that an issue ? These days with glibc using V{M,S}X for things like memcpy I would think there is little to gain in trying to avoid dumping them.

Quoted 7 lines
Quoted 3 lines

Alternately, when restoring, can you setup the sigframe with the Altivec/VSX fields populated, and the kernel will then load them, regardless of whether they were actually used or not prior to the checkpoint?

In the case of Altivec/VSX fields, we currently force the kernel to retrieve them from the signal frame by setting MSR_VEC/MSR_VSX so restore_sigcontext() will copy them to the kernel thread's state.

Yup, that's the way to go.

Quoted 1 line

However this doesn't touch to used_vsr and used_vr which may remain at 0.

That would be a kernel bug.

Quoted 10 lines

Most of the time this is fine, but in the case a thread which has really used those registers is catching a signal just after the restore and before it has touched to these registers again (and so set used_vsr/vr), these registers will not be pushed in the newly built signal frame since setup_sigcontext() check for used_vsr/vr before pushing the registers on the stack.
This may be an issue in the case the thread wants to changed those registers (don't ask me why :)) in the stacked signal frame from the signal handler since they will not be there...

Quoted 2 lines

Being able to get and set the used_vr and used_vsr thread's variables, fixes this issue.

I think the right fix is that if a restore_sigcontext() has the MSR bits set, it should set the corresponding used_* flag.

Or is there a reason why that won't work ?

Cheers,
Ben.

Quoted 7 lines

Cheers,
Laurent.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#4 lore raw
Quoted 4 lines · Benjamin Herrenschmidt


I think the right fix is that if a restore_sigcontext() has the MSR bits set,
it should set the corresponding used_* flag.

Something like this:

(totally untested)

arch/powerpc/kernel/signal_32.c +6 -0
index b6aa378..1bf074e 100644
@@ -698,6 +698,7 @@ static long restore_user_regs(struct pt_regs *regs,
 		if (__copy_from_user(&current->thread.vr_state, &sr->mc_vregs,
 				     sizeof(sr->mc_vregs)))
 			return 1;
+		current->thread.used_vr = true;
 	} else if (current->thread.used_vr)
 		memset(&current->thread.vr_state, 0,
 		       ELF_NVRREG * sizeof(vector128));
@@ -724,6 +725,7 @@ static long restore_user_regs(struct pt_regs *regs,
 		 */
 		if (copy_vsx_from_user(current, &sr->mc_vsregs))
 			return 1;
+		current->thread.used_vsr = true;
 	} else if (current->thread.used_vsr)
 		for (i = 0; i < 32 ; i++)
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = 0;
@@ -743,6 +745,7 @@ static long restore_user_regs(struct pt_regs *regs,
 		if (__copy_from_user(current->thread.evr, &sr->mc_vregs,
 				     ELF_NEVRREG * sizeof(u32)))
 			return 1;
+		current->thread.used_spe = true;
 	} else if (current->thread.used_spe)
 		memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32));
 
@@ -799,6 +802,7 @@ static long restore_tm_user_regs(struct pt_regs *regs,
 				     &tm_sr->mc_vregs,
 				     sizeof(sr->mc_vregs)))
 			return 1;
+		current->thread.used_vr = true;
 	} else if (current->thread.used_vr) {
 		memset(&current->thread.vr_state, 0,
 		       ELF_NVRREG * sizeof(vector128));
@@ -832,6 +836,7 @@ static long restore_tm_user_regs(struct pt_regs *regs,
 		if (copy_vsx_from_user(current, &sr->mc_vsregs) ||
 		    copy_transact_vsx_from_user(current, &tm_sr->mc_vsregs))
 			return 1;
+		current->thread.used_vsr = true;
 	} else if (current->thread.used_vsr)
 		for (i = 0; i < 32 ; i++) {
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = 0;
@@ -848,6 +853,7 @@ static long restore_tm_user_regs(struct pt_regs *regs,
 		if (__copy_from_user(current->thread.evr, &sr->mc_vregs,
 				     ELF_NEVRREG * sizeof(u32)))
 			return 1;
+		current->thread.used_spe = true;
 	} else if (current->thread.used_spe)
 		memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32));
 
arch/powerpc/kernel/signal_64.c +8 -3
index 2552079..8704269 100644
@@ -363,9 +363,11 @@ static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig,
 	if (v_regs && !access_ok(VERIFY_READ, v_regs, 34 * sizeof(vector128)))
 		return -EFAULT;
 	/* Copy 33 vec registers (vr0..31 and vscr) from the stack */
-	if (v_regs != NULL && (msr & MSR_VEC) != 0)
+	if (v_regs != NULL && (msr & MSR_VEC) != 0) {
 		err |= __copy_from_user(&current->thread.vr_state, v_regs,
 					33 * sizeof(vector128));
+		current->thread.used_vr = true;
+	}
 	else if (current->thread.used_vr)
 		memset(&current->thread.vr_state, 0, 33 * sizeof(vector128));
 	/* Always get VRSAVE back */
@@ -385,9 +387,10 @@ static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig,
 	 * buffer for formatting, then into the taskstruct.
 	 */
 	v_regs += ELF_NVRREG;
-	if ((msr & MSR_VSX) != 0)
+	if ((msr & MSR_VSX) != 0) {
 		err |= copy_vsx_from_user(current, v_regs);
-	else
+		current->thread.used_vsr = true;
+	} else
 		for (i = 0; i < 32 ; i++)
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = 0;
 #endif
@@ -482,6 +485,7 @@ static long restore_tm_sigcontexts(struct pt_regs *regs,
 					33 * sizeof(vector128));
 		err |= __copy_from_user(&current->thread.transact_vr, tm_v_regs,
 					33 * sizeof(vector128));
+		current->thread.used_vr = true;
 	}
 	else if (current->thread.used_vr) {
 		memset(&current->thread.vr_state, 0, 33 * sizeof(vector128));
@@ -515,6 +519,7 @@ static long restore_tm_sigcontexts(struct pt_regs *regs,
 		tm_v_regs += ELF_NVRREG;
 		err |= copy_vsx_from_user(current, v_regs);
 		err |= copy_transact_vsx_from_user(current, tm_v_regs);
+		current->thread.used_vsr = true;
 	} else {
 		for (i = 0; i < 32 ; i++) {
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = 0;
#5 lore raw
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 4 lines · Benjamin Herrenschmidt

=C2=A0
I think the right fix is that if a restore_sigcontext() has the MSR bits set,
it should set the corresponding used_* flag.

Something like this:

(totally untested)

Simon/Laurent, can you guys test this and let me know if it works for your usecase.

Cyril, can you give this a review, you've been touching this code the most lately.

cheers

arch/powerpc/kernel/signal=

Quoted 1 line
arch/powerpc/kernel/signal= renamed from arch/powerpc/kernel/signal_32.c +0 -0

_32.c

arch/powerpc/kernel/signal=

Quoted 52 lines

index b6aa378..1bf074e 100644

arch/powerpc/kernel/signal_32.c +3 -0
@@ -698,6 +698,7 @@ static long restore_user_regs(struct pt_regs *regs,
 		if (__copy_from_user(&current->thread.vr_state, &sr->mc_vregs,
 				     sizeof(sr->mc_vregs)))
 			return 1;
+		current->thread.used_vr =3D true;
 	} else if (current->thread.used_vr)
 		memset(&current->thread.vr_state, 0,
 		       ELF_NVRREG * sizeof(vector128));
@@ -724,6 +725,7 @@ static long restore_user_regs(struct pt_regs *regs,
 		 */
 		if (copy_vsx_from_user(current, &sr->mc_vsregs))
 			return 1;
+		current->thread.used_vsr =3D true;
 	} else if (current->thread.used_vsr)
 		for (i =3D 0; i < 32 ; i++)
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] =3D 0;
@@ -743,6 +745,7 @@ static long restore_user_regs(struct pt_regs *regs,
 		if (__copy_from_user(current->thread.evr, &sr->mc_vregs,
 				     ELF_NEVRREG * sizeof(u32)))
 			return 1;
+		current->thread.used_spe =3D true;
 	} else if (current->thread.used_spe)
 		memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32));

=20=20

arch/powerpc/kernel/signal_32.c +3 -0
@@ -799,6 +802,7 @@ static long restore_tm_user_regs(struct pt_regs *regs,
 				     &tm_sr->mc_vregs,
 				     sizeof(sr->mc_vregs)))
 			return 1;
+		current->thread.used_vr =3D true;
 	} else if (current->thread.used_vr) {
 		memset(&current->thread.vr_state, 0,
 		       ELF_NVRREG * sizeof(vector128));
@@ -832,6 +836,7 @@ static long restore_tm_user_regs(struct pt_regs *regs,
 		if (copy_vsx_from_user(current, &sr->mc_vsregs) ||
 		    copy_transact_vsx_from_user(current, &tm_sr->mc_vsregs))
 			return 1;
+		current->thread.used_vsr =3D true;
 	} else if (current->thread.used_vsr)
 		for (i =3D 0; i < 32 ; i++) {
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] =3D 0;
@@ -848,6 +853,7 @@ static long restore_tm_user_regs(struct pt_regs *regs,
 		if (__copy_from_user(current->thread.evr, &sr->mc_vregs,
 				     ELF_NEVRREG * sizeof(u32)))
 			return 1;
+		current->thread.used_spe =3D true;
 	} else if (current->thread.used_spe)
 		memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32));

=20=20

arch/powerpc/kernel/signal= renamed from arch/powerpc/kernel/signal_64.c +0 -0

_64.c

arch/powerpc/kernel/signal_64.c static long restore_sigcontext(struct pt_regs *regs,=

Quoted 4 lines

index 2552079..8704269 100644

arch/powerpc/kernel/signal_64.c +0 -0
@@ -363,9 +363,11 @@ static long restore_sigcontext(struct pt_regs *regs,=

sigset_t *set, int sig,

arch/powerpc/kernel/signal_64.c static long restore_sigcontext(struct pt_regs *regs,=

Quoted 13 lines
arch/powerpc/kernel/signal_64.c +3 -1
 	if (v_regs && !access_ok(VERIFY_READ, v_regs, 34 * sizeof(vector128)))
 		return -EFAULT;
 	/* Copy 33 vec registers (vr0..31 and vscr) from the stack */
-	if (v_regs !=3D NULL && (msr & MSR_VEC) !=3D 0)
+	if (v_regs !=3D NULL && (msr & MSR_VEC) !=3D 0) {
 		err |=3D __copy_from_user(&current->thread.vr_state, v_regs,
 					33 * sizeof(vector128));
+		current->thread.used_vr =3D true;
+	}
 	else if (current->thread.used_vr)
 		memset(&current->thread.vr_state, 0, 33 * sizeof(vector128));
 	/* Always get VRSAVE back */
@@ -385,9 +387,10 @@ static long restore_sigcontext(struct pt_regs *regs,=

sigset_t *set, int sig,

arch/powerpc/kernel/signal_64.c static long restore_tm_sigcontexts(struct pt_regs *re=

Quoted 13 lines
arch/powerpc/kernel/signal_64.c +3 -2
 	 * buffer for formatting, then into the taskstruct.
 	 */
 	v_regs +=3D ELF_NVRREG;
-	if ((msr & MSR_VSX) !=3D 0)
+	if ((msr & MSR_VSX) !=3D 0) {
 		err |=3D copy_vsx_from_user(current, v_regs);
-	else
+		current->thread.used_vsr =3D true;
+	} else
 		for (i =3D 0; i < 32 ; i++)
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] =3D 0;
 #endif
@@ -482,6 +485,7 @@ static long restore_tm_sigcontexts(struct pt_regs *re=

gs,

arch/powerpc/kernel/signal_64.c static long restore_tm_sigcontexts(struct pt_regs *re=

Quoted 8 lines
arch/powerpc/kernel/signal_64.c +1 -0
 					33 * sizeof(vector128));
 		err |=3D __copy_from_user(&current->thread.transact_vr, tm_v_regs,
 					33 * sizeof(vector128));
+		current->thread.used_vr =3D true;
 	}
 	else if (current->thread.used_vr) {
 		memset(&current->thread.vr_state, 0, 33 * sizeof(vector128));
@@ -515,6 +519,7 @@ static long restore_tm_sigcontexts(struct pt_regs *re=

gs,

Quoted 7 lines
arch/powerpc/kernel/signal_64.c +1 -0
 		tm_v_regs +=3D ELF_NVRREG;
 		err |=3D copy_vsx_from_user(current, v_regs);
 		err |=3D copy_transact_vsx_from_user(current, tm_v_regs);
+		current->thread.used_vsr =3D true;
 	} else {
 		for (i =3D 0; i < 32 ; i++) {
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] =3D 0;

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

author
#7 lore raw
Quoted 8 lines · Michael Ellerman
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Benjamin Herrenschmidt


I think the right fix is that if a restore_sigcontext() has the MSR bits set,
it should set the corresponding used_* flag.

Quoted 6 lines
Quoted 3 lines

Something like this:

(totally untested)

Simon/Laurent, can you guys test this and let me know if it works for your usecase.

Just notice this note.
Yes I will test it on CRIU and update later.

Thanks,
- Simon

author
#8 lore raw
In reply to a message not in the archive

Michael, Ben,

Quoted 8 lines · Michael Ellerman
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Benjamin Herrenschmidt


I think the right fix is that if a restore_sigcontext() has the MSR bits set,
it should set the corresponding used_* flag.

Quoted 7 lines
Quoted 3 lines

Something like this:

(totally untested)

Simon/Laurent, can you guys test this and let me know if it works for your usecase.

Sorry for the late reply. I tested Ben's patch and the fix works for the CRIU case mentioned before.

Thanks,
Simon

#9 lore raw
Quoted 10 lines · Simon Guo

Michael, Ben,

Quoted 8 lines · Michael Ellerman

Benjamin Herrenschmidt <[email protected]> writes:
=20

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines

=C2=A0
I think the right fix is that if a restore_sigcontext() has the MSR bits set,
it should set the corresponding used_* flag.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Something like this:

(totally untested)

=20
Simon/Laurent, can you guys test this and let me know if it works for your usecase.

Sorry for the late reply. I tested Ben's patch and the fix works for the =

CRIU

Quoted 1 line

case mentioned before.

Thanks.

Can one of you send a properly formatted and signed-off patch.

cheers

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

author
#11 lore raw
Quoted 1 line · Michael Ellerman

Can one of you send a properly formatted and signed-off patch.

I will work on that.

Thanks,
Simon

#12 lore raw
In reply to Benjamin Herrenschmidt
Quoted 41 lines · Benjamin Herrenschmidt
Quoted 11 lines · Laurent Dufour

Basically, CRIU checkpoints the process register's state through the ptrace API, and it restores it through a signal frame at restart time. This is quite odd but that the way it works on all the CRIU's supported architectures.

Obviously everything is done from/in user space, so the sigframe building too.
Since we can't know from user space if the thread has used or not the Altivec/VSX registers, since we can't rely on the MSR bits, we always dump these registers.

Right, however is that an issue ? These days with glibc using V{M,S}X for things like memcpy I would think there is little to gain in trying to avoid dumping them.

Quoted 7 lines
Quoted 3 lines

Alternately, when restoring, can you setup the sigframe with the Altivec/VSX fields populated, and the kernel will then load them, regardless of whether they were actually used or not prior to the checkpoint?

In the case of Altivec/VSX fields, we currently force the kernel to retrieve them from the signal frame by setting MSR_VEC/MSR_VSX so restore_sigcontext() will copy them to the kernel thread's state.

Yup, that's the way to go.

Quoted 1 line

However this doesn't touch to used_vsr and used_vr which may remain at 0.

That would be a kernel bug.

Quoted 10 lines

Most of the time this is fine, but in the case a thread which has really used those registers is catching a signal just after the restore and before it has touched to these registers again (and so set used_vsr/vr), these registers will not be pushed in the newly built signal frame since setup_sigcontext() check for used_vsr/vr before pushing the registers on the stack.
This may be an issue in the case the thread wants to changed those registers (don't ask me why :)) in the stacked signal frame from the signal handler since they will not be there...

Quoted 7 lines
Quoted 2 lines

Being able to get and set the used_vr and used_vsr thread's variables, fixes this issue.

I think the right fix is that if a restore_sigcontext() has the MSR bits set, it should set the corresponding used_* flag.

Or is there a reason why that won't work ?

I got your point and I agree that most of the time now, the Altivec/VSX registers are used by libc. In that case is there still a need for the lazy Altivec/VSX registers dump in the signal frame ?

I'm fine with your proposal, except that every restarted process will have the used_vr/used_vsx turned on after the restart since we can't check if these registers were used or not at checkpoint time. But that may be a minor point...

Cheers,
Laurent.

#13 lore raw
Quoted 15 lines · Laurent Dufour
Quoted 14 lines · Benjamin Herrenschmidt
Quoted 12 lines · Laurent Dufour

Most of the time this is fine, but in the case a thread which has really used those registers is catching a signal just after the restore and before it has touched to these registers again (and so set used_vsr/vr), these registers will not be pushed in the newly built signal frame since setup_sigcontext() check for used_vsr/vr before pushing the registers on the stack.
This may be an issue in the case the thread wants to changed those registers (don't ask me why :)) in the stacked signal frame from the signal handler since they will not be there...

Being able to get and set the used_vr and used_vsr thread's variables, fixes this issue.

Quoted 8 lines
Quoted 4 lines

I think the right fix is that if a restore_sigcontext() has the MSR bits set, it should set the corresponding used_* flag.

Or is there a reason why that won't work ?

I got your point and I agree that most of the time now, the Altivec/VSX registers are used by libc. In that case is there still a need for the lazy Altivec/VSX registers dump in the signal frame ?

Probably not for new programs. But it could conceivably break old software.

Quoted 4 lines

I'm fine with your proposal, except that every restarted process will have the used_vr/used_vsx turned on after the restart since we can't check if these registers were used or not at checkpoint time. But that may be a minor point...

Yeah I'd argue that's not worth worrying about, at least for now.

If it *is* a problem then we can fix it later.

cheers

author
#14 lore raw
In reply to Benjamin Herrenschmidt
Quoted 4 lines · Benjamin Herrenschmidt

I think the right fix is that if a restore_sigcontext() has the MSR bits set, it should set the corresponding used_* flag.

Or is there a reason why that won't work ?

That sounds reaonable to me.
I will prepare a patch based on that.

Michael, Ben, Laurent,
Thanks the discussion and proposal.

- Simon