On 05/01, Peter Zijlstra wrote: > > On Tue, May 01, 2018 at 03:59:24PM +0200, Oleg Nesterov wrote: > > On 05/01, Peter Zijlstra wrote: > > > > > > The only code I found that seems to care is ptrace_attach(), where we > > > wait for JOBCTL_TRAPPING to get cleared. That same function has a > > > comment about hiding the STOPPED -> RUNNING -> TRACED transition. So I'm > > > assuming it needs to observe TRACED if it observes !TRAPPING. > > > > Yes, exactly. > > > > > But I don't think there's enough barriers on that end to guarantee this. > > > Any ->state load after wait_on_bit() is, afact, free to have happened > > > before the ->jobctl load. > > > > do_wait() does set_current_state() before it checks ->state or anything > > else. > > But how are ptrace_attach() and do_wait() related?
Yes. > I guess I'm missing > something fairly fundamental here. You are missing the fact that ptrace API is very old and ugly ;) Just one example. If the debugger knows that the task is STOPPED then it has all rights to do, say, ptrace(PTRACE_ATTACH, pid); BUG_ON(pid != waitpid(pid, WNOHANG)); Or even do another ptrace() request right after ptrace(PTRACE_ATTACH) returns, without do_wait(). And unless my memory fools me, gdb even has some test-cases for this... Not sure, but it certainly looks at tracee->state in /proc before it does PTRACE_ATTACH, because if it was already STOPPED then gdb won't have any notification from the tracee. > Anyway, does the below look ok? Yes, thanks. Oleg.