From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by sourceware.org (Postfix) with ESMTPS id CC23C3858D20 for ; Mon, 7 Feb 2022 14:18:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC23C3858D20 Received: by mail-yb1-xb34.google.com with SMTP id p5so40248478ybd.13 for ; Mon, 07 Feb 2022 06:18:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zQXY/DFSzqSNiVJeW4YwRdZR282rLknOMgBOkiHlEuo=; b=tglc3Ti2KdsJzqEybWPLqdiRrC5IneaL5+vfPfDxzMQLevJKaMppoUrBS97Lpa3xS1 AU5z/NcDZYLch8m9ovvfd6CxNqtaCNZ69xQHLng4A6x8fvtbbxLw76EqrX1QjmhhqF5l CAP15Zial5M355RsUoiezGFo5fa+GSA/xMGn1JyK+87vZMSlQ+NSDMc+gVEV7X/egV7y iMkQA+7pvpe5T8rPBya6pCMkHabuxyjk07pr4Jln9ZlUdzzHZSE75d4qwRTJgyuiu0F0 lWadxvG5wyCmBykoD/C8n5xJU6Rm9QsiyUolc1iytIU1P9/JKUxSMLfJCdLJBGulEn2s mMLg== X-Gm-Message-State: AOAM532fBa7ffFbyz1Ijt9nezVlzntMWtvHWSPp/4RRDKWGuFnxbLUu5 Z82dO7kYe55r7E0nIqjL2J/ADpDNi4OmtRNqc9EWJ17YnOG4VQ== X-Google-Smtp-Source: ABdhPJxy2MlXd9a/hyL/9UP4akGZbizEHVkkHC+bD8k0rI38YcLVHvIGoctdFBk1N/JfyL+Aw2UCzknoksUVSEFofbA= X-Received: by 2002:a0d:f0c7:: with SMTP id z190mr11108005ywe.61.1644243528608; Mon, 07 Feb 2022 06:18:48 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Vasyl Vavrychuk Date: Mon, 7 Feb 2022 16:18:36 +0200 Message-ID: Subject: Re: gdb switches to __sysvec_apic_timer_interrupt or __default_send_IPI_dest_field with KVM enabled To: Maxim Levitsky Cc: qemu-discuss@nongnu.org, linux-kernel@vger.kernel.org, gdb@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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, 07 Feb 2022 14:18:52 -0000 Thanks a lot for these fixes which I can use, and for detailed explanation. On Mon, Jan 31, 2022 at 12:42 PM Maxim Levitsky wrote: > 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. You are right, I have observed some unrelated gdb issue when debugging kernel under QEMU and prepared packaging backport: https://salsa.debian.org/gdb-team/gdb/-/merge_requests/9 > 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/ What a coincidence, I use lx-symbols with an external kernel module. I have noticed that it behaves strangely sometimes, but somehow I found a proper order of comments when it works for me. On Mon, Jan 31, 2022 at 12:42 PM Maxim Levitsky wrote: > > 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 > > > >