From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB2D1C433E0 for ; Mon, 15 Mar 2021 23:38:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9176D64F60 for ; Mon, 15 Mar 2021 23:38:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232427AbhCOXhn (ORCPT ); Mon, 15 Mar 2021 19:37:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231760AbhCOXhd (ORCPT ); Mon, 15 Mar 2021 19:37:33 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81296C06174A for ; Mon, 15 Mar 2021 16:37:33 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id c16so16096412ply.0 for ; Mon, 15 Mar 2021 16:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=m5DKET+zhD2D4Fd/Hccb3C70vrkwKJbqddmWptN5Rcg=; b=CcBIATws8iJMUNgDgLzeoUqd5qjalBXpH3OfRKHqPAmMCK2yg7SfBN4sTLiu5GNTA5 pOZt2vwdaHNnRTMZvRoY6xhc036l2aOZoYx74+eHMoHlne0CYUQ35Rz8fN2nqz8C5qqk 472Zdw6e9uPIq27nr4qLk8X4jRXw8L1lID86G8q32ZGVUlG7qKUS97quQn0Dhwg+Ympf pqt8biCTL8lGuq1qKYdc++NHG8743QNzLPCu/fplbhtvrh5kiL4pLfR//d2Xn8QeDU2h zhmNC7w+PtuvJk98I22AClyO/cqGn5Z4dryqbWUe2bHptxIefXYnQRtWTQ+L+87lS32V Wj7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=m5DKET+zhD2D4Fd/Hccb3C70vrkwKJbqddmWptN5Rcg=; b=RhoFStEFD9hHFhf42v2NLZ6CuvXB8ElU6VnpxxI4myPQvQWMcnASUFwru8ZR0iPyaK VBGL8HkKx71QASuTrbFz7dQFdzQV83qqwLdug9lTjt2zhPY2jbvj0Zd5YjPeRG22y+F1 KIlVLdYtR8UpuuiuGNexycoGZzvIUN1bJLJe87U8rIsRVaFNWT1XQxQdwdFwY1YBkdCK ho8OdsiXf+NFPRaAabYASVjbF/JXEsi1VauJIu7wZT6st2I7NuVKhzhcyRUsOh1m7PNr 56qb8F1+rcS4tDwydxguu88XQa2qEEMYR19jPqcJghzw4wwNcRNRwKo7LV1j7WM24FBX 0dIw== X-Gm-Message-State: AOAM530UxhzjMYOdori4QEnaaXcuKCe5gShhP8O7xWijpQoGfaCyJccG I6F3ay8uShM6yqhgOnO3cGkmlg== X-Google-Smtp-Source: ABdhPJyeOCb//22JJMMlmKYoWfd71Qf5DD7ZghvVWV8EJaoAT8g47yxOwBOQkv7MaJieupA2dD4L1A== X-Received: by 2002:a17:90b:1953:: with SMTP id nk19mr1648941pjb.28.1615851452764; Mon, 15 Mar 2021 16:37:32 -0700 (PDT) Received: from google.com ([2620:15c:f:10:3d60:4c70:d756:da57]) by smtp.gmail.com with ESMTPSA id z11sm14734939pgj.22.2021.03.15.16.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 16:37:32 -0700 (PDT) Date: Mon, 15 Mar 2021 16:37:25 -0700 From: Sean Christopherson To: Maxim Levitsky Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , linux-kernel@vger.kernel.org, Thomas Gleixner , Wanpeng Li , Kieran Bingham , Jessica Yu , Jan Kiszka , Andrew Morton , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Joerg Roedel , Jim Mattson , Borislav Petkov , Stefano Garzarella , "H. Peter Anvin" , Paolo Bonzini , Ingo Molnar Subject: Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping Message-ID: References: <20210315221020.661693-1-mlevitsk@redhat.com> <20210315221020.661693-3-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210315221020.661693-3-mlevitsk@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 16, 2021, Maxim Levitsky wrote: > This change greatly helps with two issues: > > * Resuming from a breakpoint is much more reliable. > > When resuming execution from a breakpoint, with interrupts enabled, more often > than not, KVM would inject an interrupt and make the CPU jump immediately to > the interrupt handler and eventually return to the breakpoint, to trigger it > again. > > From the user point of view it looks like the CPU never executed a > single instruction and in some cases that can even prevent forward progress, > for example, when the breakpoint is placed by an automated script > (e.g lx-symbols), which does something in response to the breakpoint and then > continues the guest automatically. > If the script execution takes enough time for another interrupt to arrive, > the guest will be stuck on the same breakpoint RIP forever. > > * Normal single stepping is much more predictable, since it won't land the > debugger into an interrupt handler, so it is much more usable. > > (If entry to an interrupt handler is desired, the user can still place a > breakpoint at it and resume the guest, which won't activate this workaround > and let the gdb still stop at the interrupt handler) > > Since this change is only active when guest is debugged, it won't affect > KVM running normal 'production' VMs. > > > Signed-off-by: Maxim Levitsky > Tested-by: Stefano Garzarella > --- > arch/x86/kvm/x86.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index a9d95f90a0487..b75d990fcf12b 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8458,6 +8458,12 @@ static void inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate_exit > can_inject = false; > } > > + /* > + * Don't inject interrupts while single stepping to make guest debug easier > + */ > + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) > + return; Is this something userspace can deal with? E.g. disable IRQs and/or set NMI blocking at the start of single-stepping, unwind at the end? Deviating this far from architectural behavior will end in tears at some point. > + > /* > * Finally, inject interrupt events. If an event cannot be injected > * due to architectural conditions (e.g. IF=0) a window-open exit > -- > 2.26.2 >