From: Oleg Nesterov on
On 12/18, K.Prasad wrote:
>
> On Fri, Dec 18, 2009 at 06:27:47PM +0100, Oleg Nesterov wrote:
> > On 12/18, Frederic Weisbecker wrote:
> > >
> > > On Fri, Dec 18, 2009 at 01:56:50AM +0100, Oleg Nesterov wrote:
> > > > Hi.
>
> <snipped>
>
> > > Single stepping works well for me, after a quick check on
> > > gdb. How did you trigger the bug?
> >
> > Please find the trivial test-case below. It hangs, because
> > PTRACE_SINGLESTEP doesn't trigger the trap.
> >
>
> aah...my other mail just criss-crossed yours.
>
> I quickly ran on the said x86 box, loaded with -tip (commit
> 7818b3d0fc68f5c2a85fed86d9fa37131c5a3068) and it runs fine.

Hmm. Just re-tested 2.6.33-rc1 under kvm, it hangs...

Oleg.

> [root(a)llm05 prasadkr]# cat oleg.c
> #include <stdio.h>
> #include <unistd.h>
> #include <signal.h>
> #include <sys/ptrace.h>
> #include <sys/wait.h>
> #include <assert.h>
>
> int main(void)
> {
> int pid, status, i;
>
> pid = fork();
> if (!pid)
> for (;;);
>
> sleep(1);
> assert(ptrace(PTRACE_ATTACH, pid, 0,0) == 0);
>
> assert(pid == wait(&status));
> assert(WIFSTOPPED(status));
>
> for (i = 0; i < 10; ++i) {
> assert(ptrace(PTRACE_SINGLESTEP, pid, 0,0) == 0);
>
> printf("wait %d ...\n", i);
> assert(pid == wait(&status));
>
> assert(WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP);
> }
>
> kill(pid, SIGKILL);
> return 0;
> }
>
> [root(a)llm05 prasadkr]# gcc -o oleg oleg.c -g -Wall
> [root(a)llm05 prasadkr]# ./oleg
> wait 0 ...
> wait 1 ...
> wait 2 ...
> wait 3 ...
> wait 4 ...
> wait 5 ...
> wait 6 ...
> wait 7 ...
> wait 8 ...
> wait 9 ...
> [root(a)llm05 prasadkr]#
>
> Am I missing something here?
>
> Thanks,
> K.Prasad
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Roland McGrath on
> Please find the trivial test-case below. It hangs, because
> PTRACE_SINGLESTEP doesn't trigger the trap.

2.6.33-rc1 x86-64 works for me with either -m64 or -m32 version of that test.

> (not sure this matters, but I did the testing under kvm)

Apparently it does. You should hack some printks into do_debug() and see
how kvm is differing from real hardware. (Actually you can probably do
this with a notifier added by a module, not that you are shy about
recompiling!)

Probably kvm's emulation of the hardware behavior wrt the DR6 bits is not
sufficiently faithful. Conceivably, kvm is being consistent with some
older hardware and we have encoded assumptions that only newer hardware
meets. But I'd guess it's just a plain kvm bug.


Thanks,
Roland
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Oleg Nesterov on
On 12/18, Roland McGrath wrote:
>
> > Please find the trivial test-case below. It hangs, because
> > PTRACE_SINGLESTEP doesn't trigger the trap.
>
> 2.6.33-rc1 x86-64 works for me with either -m64 or -m32 version of that test.
>
> > (not sure this matters, but I did the testing under kvm)
>
> Apparently it does. You should hack some printks into do_debug() and see
> how kvm is differing from real hardware. (Actually you can probably do
> this with a notifier added by a module, not that you are shy about
> recompiling!)
>
> Probably kvm's emulation of the hardware behavior wrt the DR6 bits is not
> sufficiently faithful. Conceivably, kvm is being consistent with some
> older hardware and we have encoded assumptions that only newer hardware
> meets. But I'd guess it's just a plain kvm bug.

OK, thanks.

Hmm. Now I see how wrong I was when I said this code is "obviously wrong" ;)

I'll add the debugging printk's and report the output. Sorry for delay,
can't do this today.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Frederic Weisbecker on
On Fri, Dec 18, 2009 at 12:05:03PM -0800, Roland McGrath wrote:
> > Please find the trivial test-case below. It hangs, because
> > PTRACE_SINGLESTEP doesn't trigger the trap.
>
> 2.6.33-rc1 x86-64 works for me with either -m64 or -m32 version of that test.
>
> > (not sure this matters, but I did the testing under kvm)
>
> Apparently it does. You should hack some printks into do_debug() and see
> how kvm is differing from real hardware. (Actually you can probably do
> this with a notifier added by a module, not that you are shy about
> recompiling!)
>
> Probably kvm's emulation of the hardware behavior wrt the DR6 bits is not
> sufficiently faithful. Conceivably, kvm is being consistent with some
> older hardware and we have encoded assumptions that only newer hardware
> meets. But I'd guess it's just a plain kvm bug.


It looks like in kvm, before entering the guest, we restore its
debug registers:

vcpu_enter_guest():
if (unlikely(vcpu->arch.switch_db_regs)) {
set_debugreg(0, 7);
set_debugreg(vcpu->arch.eff_db[0], 0);
set_debugreg(vcpu->arch.eff_db[1], 1);
set_debugreg(vcpu->arch.eff_db[2], 2);
set_debugreg(vcpu->arch.eff_db[3], 3);
}


But what happens to dr6, I don't know.

Adding Avi and Jan in Cc.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Oleg Nesterov on
On 12/21, Jan Kiszka wrote:
>
> Oleg Nesterov wrote:
> >
> > Hmm. Now I see how wrong I was when I said this code is "obviously wrong" ;)

Yes, it is easy to blame the code you don't understand.

My apologies to all.

> > I'll add the debugging printk's and report the output. Sorry for delay,
> > can't do this today.
>
> Can't reproduce, runs fine here with with 2.6.33-rc1 as both host&guest
> and qemu-kvm latest git. Host uses kvm-intel.

Everything runs fine under 2.6.32 as a _host_ kernel. Previously I did
the testing under 2.6.26.5-45.fc9.

Sorry for noise, thanks all for your help.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/