From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 97D933858C20 for ; Mon, 31 Jan 2022 10:42:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 97D933858C20 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-4_ijksI5MIGbCAHrGDx0YQ-1; Mon, 31 Jan 2022 05:42:55 -0500 X-MC-Unique: 4_ijksI5MIGbCAHrGDx0YQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE5B41853024; Mon, 31 Jan 2022 10:42:54 +0000 (UTC) Received: from starship (unknown [10.40.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52A5779593; Mon, 31 Jan 2022 10:42:53 +0000 (UTC) Message-ID: Subject: Re: gdb switches to __sysvec_apic_timer_interrupt or __default_send_IPI_dest_field with KVM enabled From: Maxim Levitsky To: Vasyl Vavrychuk , qemu-discuss@nongnu.org, linux-kernel@vger.kernel.org, gdb@sourceware.org Date: Mon, 31 Jan 2022 12:42:52 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2022 10:43:00 -0000 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=, > vector=, 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 >