public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: Vasyl Vavrychuk <vvavrychuk@gmail.com>,
	qemu-discuss@nongnu.org,  linux-kernel@vger.kernel.org,
	gdb@sourceware.org
Subject: Re: gdb switches to __sysvec_apic_timer_interrupt or __default_send_IPI_dest_field with KVM enabled
Date: Mon, 31 Jan 2022 12:42:52 +0200	[thread overview]
Message-ID: <a6916dea7c771b04d8c97d25214b6918524ab9ea.camel@redhat.com> (raw)
In-Reply-To: <CAGj4m+4QPE7uHzbsQbG6Fp3Ke2eQRQQ2z2-1rsKDPtXqs-vpGg@mail.gmail.com>

On Sat, 2022-01-29 at 23:06 +0200, Vasyl Vavrychuk wrote:
> Hello,
> 
> I run Linux kernel under qemu-system-x86_64 via the "-kernel" option.
> 
> Also, I added the "-s" option to accept the gdb connection.
> 
> After Linux boot up I connect with gdb and set a breakpoint in some
> function, for example "device_del", does not matter really.
> 
> The problem is if I also use "--enable-kvm", then after breakpoint
> triggered and sending "n" from gdb, it switches to
> 
>     __sysvec_apic_timer_interrupt (regs=0xffffc90000297de8) at
> arch/x86/kernel/apic/apic.c:1102
>     1102            trace_local_timer_entry(LOCAL_TIMER_VECTOR);
> 
> or to
> 
>     __default_send_IPI_dest_field (mask=<optimized out>,
> vector=<optimized out>, dest=dest@entry=2048) at
> arch/x86/kernel/apic/ipi.c:161
>     161             cfg = __prepare_ICR2(mask);
> 
> I am stepping over kernel code that does not perform any waiting or blocking.
> 
> Everything works fine with "--enable-kvm" removed.

I recently fixed that, and the code AFAIK is upstream, but probably, the qemu
side of it didn't yet made it to the release.

The problem you are seeing is that every time you single step, an interrupt
occures because you are not as fast as computer is - timer interrupt happens
like 1000 times in a second, so after each single step you do it will be pending.

That makes GDB land you in the interrupt handler, which is correct
technically but makes single stepping pretty much impossible.

The solution is to tell kernel to mask interrupts regardless
if they are masked by the guest, something that qemu even does when TCCG 
is used but was not implemented for KVM.

Best regards,
	Maxim Levitsky

PS: you might also want to patch kernel's lx-symbols gdb script to fix loadable module support,
which currently doesn't work well - I run out of time to upstream it,  I'll get to it
someday.

There problem here is that kernel's gdb script uses a breakpoint in the function that
loads modules and when it hits, it reloads gdb symbols - that is frowned upon in gdb docs,
but pretty much the only way to do it.

I patched the lx-symbols script to at least work with recent gdb, but this no doubt relies on at least some undefined
behavier in gdb, therefore I didn't push this futher.

https://patchwork.kernel.org/project/kvm/patch/20210811122927.900604-5-mlevitsk@redhat.com/



> 
> Thanks,
> Vasyl
> 



  reply	other threads:[~2022-01-31 10:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-29 21:06 Vasyl Vavrychuk
2022-01-31 10:42 ` Maxim Levitsky [this message]
2022-02-07 14:18   ` Vasyl Vavrychuk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6916dea7c771b04d8c97d25214b6918524ab9ea.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qemu-discuss@nongnu.org \
    --cc=vvavrychuk@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).