Skip to contentSkip to conversation

m68k: Fix task info flags handling for 68000

PATCH Superseded Daniel Palmer 3 participants 7 messages Mar 12 – Mar 31

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 m68k: Fix task info flags handling for 68000

The logic for deciding what to do after a syscall should be checking if any of the lower word bits are set and then checking if the reschedule bit is set.

Currently we are loading the top word, checking if any bits are set (which never seems to be true) and thus jumping over loading the whole long and checking if the reschedule bit is set.

We get the thread info in two places so split that logic out in a macro and then fix the code so that it just loads the whole of the flags, checks if anything is set and then checks if the reschedule bit in particular is set.

---

I have had a variation of this patch for ages and haven't gotten around to sending it. Christoph e-mailed us (Greg, Sasha and me) to report this issue with a similar patch. Apparently this is an issue all the way back to 5.15.

Christoph, can you check this works for you? I took this out of my personal branch and made sure it built but I have a bunch of other junk I need to actually boot it on the things I have.

 arch/m68k/68000/entry.S | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
arch/m68k/68000/entry.S +13 -8
index 72e95663b62f..cd193fd34c19 100644
@@ -18,6 +18,13 @@
 
 .text
 
+/* get thread_info pointer into a2 */
+ .macro getthreadinfo
+	movel	%sp,%d1
+	andl	#-THREAD_SIZE,%d1
+	movel	%d1,%a2
+ .endm
+
 .globl system_call
 .globl resume
 .globl ret_from_exception
@@ -70,9 +77,8 @@ ENTRY(system_call)
 
 	movel	%sp@(PT_OFF_ORIG_D0),%d0
 
-	movel	%sp,%d1			/* get thread_info pointer */
-	andl	#-THREAD_SIZE,%d1
-	movel	%d1,%a2
+	/* Doing a trace ? */
+	getthreadinfo
 	btst	#(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
 	jne	do_trace
 	cmpl	#NR_syscalls,%d0
@@ -96,16 +102,15 @@ Luser_return:
 	/* heavy interrupt load*/
 	andw	#ALLOWINT,%sr
 
-	movel	%sp,%d1			/* get thread_info pointer */
-	andl	#-THREAD_SIZE,%d1
-	movel	%d1,%a2
+	getthreadinfo
 1:
-	move	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */
+	/* check if any of the flags are set */
+	movel	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */
 	jne	Lwork_to_do
 	RESTORE_ALL
 
 Lwork_to_do:
-	movel	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */
+	/* check if reschedule needs to be called */
 	btst	#TIF_NEED_RESCHED,%d1
 	jne	reschedule
 
Signature · 1 line
2.51.0
#1 lore raw

Hello Daniel,

I tested first the 6.18.17 kernel with my full patch, which was OK.
Then I re-started with a new kernel, added your patch and removed my "movel" from my patch, which I applied afterwards. Kernel boots fine, shell running, even telnetd is running, all OK.

So, green light !

Thank you
Christoph

Quoted 80 lines · Daniel Palmer

The logic for deciding what to do after a syscall should be checking if any of the lower word bits are set and then checking if the reschedule bit is set.

Currently we are loading the top word, checking if any bits are set (which never seems to be true) and thus jumping over loading the whole long and checking if the reschedule bit is set.

We get the thread info in two places so split that logic out in a macro and then fix the code so that it just loads the whole of the flags, checks if anything is set and then checks if the reschedule bit in particular is set.

---

I have had a variation of this patch for ages and haven't gotten around to sending it. Christoph e-mailed us (Greg, Sasha and me) to report this issue with a similar patch. Apparently this is an issue all the way back to 5.15.

Christoph, can you check this works for you? I took this out of my personal branch and made sure it built but I have a bunch of other junk I need to actually boot it on the things I have.

  arch/m68k/68000/entry.S | 21 +++++++++++++--------
  1 file changed, 13 insertions(+), 8 deletions(-)
arch/m68k/68000/entry.S +13 -8
index 72e95663b62f..cd193fd34c19 100644
@@ -18,6 +18,13 @@
 
  .text
 
+/* get thread_info pointer into a2 */
+ .macro getthreadinfo
+	movel	%sp,%d1
+	andl	#-THREAD_SIZE,%d1
+	movel	%d1,%a2
+ .endm
+
  .globl system_call
  .globl resume
  .globl ret_from_exception
@@ -70,9 +77,8 @@ ENTRY(system_call)
 
  	movel	%sp@(PT_OFF_ORIG_D0),%d0
 
-	movel	%sp,%d1			/* get thread_info pointer */
-	andl	#-THREAD_SIZE,%d1
-	movel	%d1,%a2
+	/* Doing a trace ? */
+	getthreadinfo
  	btst	#(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
  	jne	do_trace
  	cmpl	#NR_syscalls,%d0
@@ -96,16 +102,15 @@ Luser_return:
  	/* heavy interrupt load*/
  	andw	#ALLOWINT,%sr
 
-	movel	%sp,%d1			/* get thread_info pointer */
-	andl	#-THREAD_SIZE,%d1
-	movel	%d1,%a2
+	getthreadinfo
  1:
-	move	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */
+	/* check if any of the flags are set */
+	movel	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */
  	jne	Lwork_to_do
  	RESTORE_ALL
 
  Lwork_to_do:
-	movel	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */
+	/* check if reschedule needs to be called */
  	btst	#TIF_NEED_RESCHED,%d1
  	jne	reschedule
 
maintainer
#2 lore raw
In reply to Daniel Palmer

Hi Daniel,

Quoted 61 lines · Daniel Palmer

The logic for deciding what to do after a syscall should be checking if any of the lower word bits are set and then checking if the reschedule bit is set.

Currently we are loading the top word, checking if any bits are set (which never seems to be true) and thus jumping over loading the whole long and checking if the reschedule bit is set.

We get the thread info in two places so split that logic out in a macro and then fix the code so that it just loads the whole of the flags, checks if anything is set and then checks if the reschedule bit in particular is set.

---

I have had a variation of this patch for ages and haven't gotten around to sending it. Christoph e-mailed us (Greg, Sasha and me) to report this issue with a similar patch. Apparently this is an issue all the way back to 5.15.

Christoph, can you check this works for you? I took this out of my personal branch and made sure it built but I have a bunch of other junk I need to actually boot it on the things I have.

  arch/m68k/68000/entry.S | 21 +++++++++++++--------
  1 file changed, 13 insertions(+), 8 deletions(-)
arch/m68k/68000/entry.S +9 -3
index 72e95663b62f..cd193fd34c19 100644
@@ -18,6 +18,13 @@
 
  .text
 
+/* get thread_info pointer into a2 */
+ .macro getthreadinfo
+	movel	%sp,%d1
+	andl	#-THREAD_SIZE,%d1
+	movel	%d1,%a2
+ .endm
+
  .globl system_call
  .globl resume
  .globl ret_from_exception
@@ -70,9 +77,8 @@ ENTRY(system_call)
 
  	movel	%sp@(PT_OFF_ORIG_D0),%d0
 
-	movel	%sp,%d1			/* get thread_info pointer */
-	andl	#-THREAD_SIZE,%d1
-	movel	%d1,%a2
+	/* Doing a trace ? */
+	getthreadinfo
  	btst	#(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
  	jne	do_trace
  	cmpl	#NR_syscalls,%d0
@@ -96,16 +102,15 @@ Luser_return:
  	/* heavy interrupt load*/

arch/m68k/68000/entry.S Luser_return: · line 108

Quoted 10 lines
arch/m68k/68000/entry.S +3 -4
  	andw	#ALLOWINT,%sr
 
-	movel	%sp,%d1			/* get thread_info pointer */
-	andl	#-THREAD_SIZE,%d1
-	movel	%d1,%a2
+	getthreadinfo
  1:
-	move	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */
+	/* check if any of the flags are set */
+	movel	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */

The comments from arch/m68k/include/asm/thread_info.h are this:

/* entry.S relies on these definitions!
* bits 0-7 are tested at every exception exit
* bits 8-15 are also tested at syscall exit
*/

So looking at what check is in arch/m68k/coldfire/entry.S:

    moveb   %a0@(TINFO_FLAGS+3),%d1 /* thread_info->flags (low 8 bits) */

In arch/m68k/kernel/entry.S it looks to be doing basically the same thing:

    moveb   %a1@(TINFO_FLAGS+3),%d0

So they do really only check bits 0-7 here.

If you code the check like that do you still get correct running behavior?

Regards
Greg

Quoted 9 lines
arch/m68k/68000/entry.S +1 -1
  	jne	Lwork_to_do
  	RESTORE_ALL
 
  Lwork_to_do:
-	movel	%a2@(TINFO_FLAGS),%d1	/* thread_info->flags */
+	/* check if reschedule needs to be called */
  	btst	#TIF_NEED_RESCHED,%d1
  	jne	reschedule
 
#3 lore raw

Hi Greg,

Quoted 12 lines · Greg Ungerer

The comments from arch/m68k/include/asm/thread_info.h are this:

/* entry.S relies on these definitions!
* bits 0-7 are tested at every exception exit
* bits 8-15 are also tested at syscall exit
*/

So looking at what check is in arch/m68k/coldfire/entry.S:

     moveb   %a0@(TINFO_FLAGS+3),%d1 /* thread_info->flags (low 8 bits) */
Quoted 7 lines

In arch/m68k/kernel/entry.S it looks to be doing basically the same thing:

     moveb   %a1@(TINFO_FLAGS+3),%d0

So they do really only check bits 0-7 here.

If you code the check like that do you still get correct running behavior?

That seems to work. One thing I'm unsure about is this in the coldfire version:

Luser_return:
movel %sp,%d1 /* get thread_info pointer */
andl #-THREAD_SIZE,%d1 /* at base of kernel stack */ movel %d1,%a0
moveb %a0@(TINFO_FLAGS+3),%d1 /* thread_info->flags (low 8 bits) */

^^^^^^
So the bottom 8 bits are in d1

jne Lwork_to_do /* still work to do */

Lreturn:
RESTORE_USER

Lwork_to_do:
movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */

^^^^^^^
Now the whole value is loaded into d1 to do the bit test.. but the value needed is already in d1 as we'll be testing bit 7?

move #0x2000,%sr /* enable intrs again */
btst #TIF_NEED_RESCHED,%d1
jne reschedule

Thanks,

Daniel

maintainer
#4 lore raw

Hi Daniel,

Quoted 17 lines · Daniel Palmer

Hi Greg,

Quoted 14 lines · Greg Ungerer

The comments from arch/m68k/include/asm/thread_info.h are this:

/* entry.S relies on these definitions!
* bits 0-7 are tested at every exception exit
* bits 8-15 are also tested at syscall exit
*/

So looking at what check is in arch/m68k/coldfire/entry.S:

      moveb   %a0@(TINFO_FLAGS+3),%d1 /* thread_info->flags (low 8 bits) */

In arch/m68k/kernel/entry.S it looks to be doing basically the same thing:

Quoted 7 lines
Quoted 5 lines
      moveb   %a1@(TINFO_FLAGS+3),%d0

So they do really only check bits 0-7 here.

If you code the check like that do you still get correct running behavior?

That seems to work.

Thanks for the confirmation.

Quoted 16 lines

One thing I'm unsure about is this in the coldfire version:

Luser_return:
movel %sp,%d1 /* get thread_info pointer */
andl #-THREAD_SIZE,%d1 /* at base of kernel stack */ movel %d1,%a0
moveb %a0@(TINFO_FLAGS+3),%d1 /* thread_info->flags (low 8 bits) */

^^^^^^
So the bottom 8 bits are in d1

jne Lwork_to_do /* still work to do */

Lreturn:
RESTORE_USER

Quoted 6 lines

Lwork_to_do:
movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */

^^^^^^^
Now the whole value is loaded into d1 to do the bit test.. but the value needed is already in d1 as we'll be testing bit 7?

Yeah, agreed. The more I look at the ColdFire version the more I think it may not be totally correct. Its flow here doesn't match the comments from arch/m68k/include/asm/thread_info.h. The legacy MMU m68k code does appear to do as the comments say with respect to the TINFO flag bits.

The ColdFire code was forked from the original arch/m68k/kernel/entry.S a very long time back - there was some differences that needed to be dealt with.

Anyway what I am looking more closely at is if the higher TINFO flag bits are actually not being checked at all - so things like single stepping.

Regards
Greg

Quoted 8 lines

move #0x2000,%sr /* enable intrs again */
btst #TIF_NEED_RESCHED,%d1
jne reschedule

Thanks,

Daniel

#5 lore raw

Hi Greg,

Quoted 11 lines · Greg Ungerer

Yeah, agreed. The more I look at the ColdFire version the more I think it may not be totally correct. Its flow here doesn't match the comments from arch/m68k/include/asm/thread_info.h. The legacy MMU m68k code does appear to do as the comments say with respect to the TINFO flag bits.

The ColdFire code was forked from the original arch/m68k/kernel/entry.S a very long time back - there was some differences that needed to be dealt with.

Anyway what I am looking more closely at is if the higher TINFO flag bits are actually not being checked at all - so things like single stepping.

For now would it be ok to just fix the reschedule flag for 68000 (i.e. I send a v2 that loads a single byte instead as you suggested). That would at least make it usable for me and the other few strange people using it. :)
I have poked around at converting 68000 to the generic entry stuff. I think that would make most of this custom asm go away... but it'll take a while before its ready.

Thanks,

Daniel

maintainer
#6 lore raw

Hi Daniel,

Quoted 15 lines · Daniel Palmer

Hi Greg,

Quoted 11 lines · Greg Ungerer

Yeah, agreed. The more I look at the ColdFire version the more I think it may not be totally correct. Its flow here doesn't match the comments from arch/m68k/include/asm/thread_info.h. The legacy MMU m68k code does appear to do as the comments say with respect to the TINFO flag bits.

The ColdFire code was forked from the original arch/m68k/kernel/entry.S a very long time back - there was some differences that needed to be dealt with.

Anyway what I am looking more closely at is if the higher TINFO flag bits are actually not being checked at all - so things like single stepping.

Quoted 7 lines

For now would it be ok to just fix the reschedule flag for 68000 (i.e. I send a v2 that loads a single byte instead as you suggested). That would at least make it usable for me and the other few strange people using it. :)
I have poked around at converting 68000 to the generic entry stuff. I think that would make most of this custom asm go away... but it'll take a while before its ready.

Yes, lets do that. Send a v2 and I will push into the m68knommu git tree.

Regards
Greg