Skip to contentSkip to conversation

m68k, signals and single-stepping

DISCUSSION Geert Uytterhoeven 4 participants 10 messages Sep 30, 2010 – Oct 2, 2010 1 message not in the archive

lore
Share & tools
lore

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

#1 lore raw

Hi Al,

Quoted 31 lines · Al Viro

       I've been trying to sort out what's going on with TIF_DELAYED_TRACE, but unfortunately neither User's Manual for 68040 nor Programmer's Reference Manual for 68k family cover tracing exceptions in enough details ;-/

       a) regs.SR.T1 is cleared if you have created a sigframe; in addition, SIGTRAP is sent to yourself.
       b) if you leave a syscall and see TIF_DELAYED_TRACE set, you do the same thing, signals or no signals.
       c) if you leave an exception *and* no signal handlers are triggered, you leave T1 alone.
       d) if you step into a tracing exception, you get SIGTRAP again, with si_code set to TRAP_TRACE (instead of SI_KERNEL); si_addr is set (unlike the previous cases).
       e) TIF_DELAYED_TRACE is set when you ask for singlestepping; the same thing sets SR.T1.
       f) PTRACE_POKEUSR can't change tracing bits in SR; neither can sigreturn.
       g) if UM is clear on anything, it's that for TRAP the tracing exception is handled before entering the trap itself.

So what's that SIGTRAP on exit from syscall in single-stepping mode for? I can understand doing that when we've set a signal handler up, but...

There'd been some changes of behaviour in cset with rather uninformative commit message
   [PATCH] M68k update (part 42)
   M68k task and thread updates
and AFAICS until that point we had the same "send SIGTRAP and clear T1" on ret_from_exception, no matter what had led there.  Was that a bugfix or just an unintended change?

Quoted 4 lines

BTW, there's a bunch of signal races in m68k, mostly parallel to similar crap I'd been fixing lately on other targets; I have fixes, but I'd rather understand what's going on with tracing in there before touching the more subtle ones...

Sorry, I don't know. I try to stay away from the signal code as much as possible.

Perhaps Andreas knows?

Anyway, thanks for looking into this!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#2 lore raw
Quoted 1 line · Geert Uytterhoeven
Quoted 1 line

So what's that SIGTRAP on exit from syscall in single-stepping mode for?

The trace exception is low priority exception that is executed after all other exceptions are processed. So if the cpu single steps over a trap insns, the trace exception processing is started when the trap exception processing is complete, which is just before the cpu starts executing the trap exception handler in the kernel. You want the SIGTRAP to be sent to the user process, so you have to delay sending it until the kernel returns to user space.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#3 lore raw
Quoted 11 lines · Andreas Schwab
Quoted 1 line · Geert Uytterhoeven
Quoted 1 line

So what's that SIGTRAP on exit from syscall in single-stepping mode for?

The trace exception is low priority exception that is executed after all other exceptions are processed. So if the cpu single steps over a trap insns, the trace exception processing is started when the trap exception processing is complete, which is just before the cpu starts executing the trap exception handler in the kernel. You want the SIGTRAP to be sent to the user process, so you have to delay sending it until the kernel returns to user space.

Um... What's wrong with doing that from trap_c()?

#4 lore raw
Quoted 13 lines · Al Viro
Quoted 11 lines · Andreas Schwab
Quoted 1 line · Geert Uytterhoeven
Quoted 1 line

So what's that SIGTRAP on exit from syscall in single-stepping mode for?

The trace exception is low priority exception that is executed after all other exceptions are processed. So if the cpu single steps over a trap insns, the trace exception processing is started when the trap exception processing is complete, which is just before the cpu starts executing the trap exception handler in the kernel. You want the SIGTRAP to be sent to the user process, so you have to delay sending it until the kernel returns to user space.

Quoted 1 line

Um... What's wrong with doing that from trap_c()?

IIRC that was the only way to make gdb work correctly wrt. single stepping over system calls and into signal handlers. If anyone wants to test it with today's kernel on real hardware, please go ahead.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#5 lore raw
Quoted 5 lines · Andreas Schwab
Quoted 1 line

Um... What's wrong with doing that from trap_c()?

IIRC that was the only way to make gdb work correctly wrt. single stepping over system calls and into signal handlers. If anyone wants to test it with today's kernel on real hardware, please go ahead.

Ouch... Resurrecting that 840av box will be interesting - most likely a dead battery, but... ;-/ And yes, I certainly understand why qemu testing is not sufficient for that kind of stuff - subtle enough to make the odds of stepping on qemu bugs...

Oh, well. Anyway, the obvious ones I've got are:
* setup_frame/setup_rt_frame should report failure, so that
handle_signal() wouldn't block signals in that case (losing the original mask, since it's not stored anywhere in that case)
* notify_resume isn't handled at all
* sigsuspend would be better off with ERESTARTNOHAND scheme.

FWIW, I wonder if it would be better to have handle_signal() call send_sig() and clear regs.SR.T1 and forget about checking return value of do_signal(); do_delayed_trace is still needed, since currently there are two places that can reach it, but it'd make the code around calling do_signal() simpler while preserving the current behaviour...

#6 lore raw
Quoted 10 lines · Al Viro
Quoted 5 lines · Andreas Schwab
Quoted 1 line

Um... What's wrong with doing that from trap_c()?

IIRC that was the only way to make gdb work correctly wrt. single stepping over system calls and into signal handlers. If anyone wants to test it with today's kernel on real hardware, please go ahead.

Ouch... Resurrecting that 840av box will be interesting - most likely a dead battery, but... ;-/

My 840av has a weird issue where it powers up and lights the front LED but doesn't POST, chime, etc. Eventually (after waiting 2 minutes? 15 minutes... it varies) I can then reset it with ctrl-apple-power key and it comes good. New battery didn't affect this. I've been considering swapping in a PSU from a pmac 8500 but maybe it just needs some new capacitors.

Quoted 3 lines

And yes, I certainly understand why qemu testing is not sufficient for that kind of stuff - subtle enough to make the odds of stepping on qemu bugs...

I can test patches for you on a quadra 700 (MC68040) that I have set up at the moment. My time is in demand at present, but if you've tested them on aranym, and you can tell me what to look for, it shouldn't take too long.

What are the userland pre-requisites for this kind of testing? I have etch-m68k handy, but it is getting long in the tooth (that is, it pre-dates the siginfo patches that Maxim wrote, all of the ptrace work that Andreas has done recently, and probably a bunch of other related stuff that I didn't notice).

Finn

Quoted 18 lines

Oh, well. Anyway, the obvious ones I've got are:
* setup_frame/setup_rt_frame should report failure, so that
handle_signal() wouldn't block signals in that case (losing the original mask, since it's not stored anywhere in that case)
* notify_resume isn't handled at all
* sigsuspend would be better off with ERESTARTNOHAND scheme.

FWIW, I wonder if it would be better to have handle_signal() call send_sig() and clear regs.SR.T1 and forget about checking return value of do_signal(); do_delayed_trace is still needed, since currently there are two places that can reach it, but it'd make the code around calling do_signal() simpler while preserving the current behaviour... --
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
Quoted 1 line · Finn Thain

What are the userland pre-requisites for this kind of testing?

The best way to test it is to run the gdb testsuite and look for regressions.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#8 lore raw
Quoted 6 lines · Andreas Schwab
Quoted 1 line · Finn Thain

What are the userland pre-requisites for this kind of testing?

The best way to test it is to run the gdb testsuite and look for regressions.

That sounds convenient enough. What test failures might one expect for recent kernel, tools and libc? (Other than failures due to race conditions Al mentioned.)

Finn

Quoted 4 lines

Andreas.

#9 lore raw
Quoted 2 lines · Finn Thain

That sounds convenient enough. What test failures might one expect for recent kernel, tools and libc?

You'll need to compare the runs before and after any patching.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#10 lore raw
In reply to Geert Uytterhoeven
Quoted 6 lines · Geert Uytterhoeven

Hi Al,

Quoted 3 lines · Al Viro

       I've been trying to sort out what's going on with TIF_DELAYED_TRACE, but unfortunately neither User's Manual for 68040 nor Programmer's Reference Manual for 68k family cover tracing exceptions in enough details ;-/

See 8.3 (Exception Priorities) in the MC68040UM, or 8.1.12 (Multiple Exceptions) in the MC68030UM.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."