Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3882129pxf; Mon, 15 Mar 2021 23:24:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwb5eUWp9+rB7scskA/cyNK/Q6KZFqHFYJiCMDf8unZffXDZb19wu/qOiltfh0wZnpdj+5d X-Received: by 2002:a17:906:1c41:: with SMTP id l1mr27648291ejg.299.1615875862764; Mon, 15 Mar 2021 23:24:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615875862; cv=none; d=google.com; s=arc-20160816; b=EdJK+rYfQjhsC4grEMIeNE4LNTxMMoPb+W1Ew8WRWodKeH/ygXocZwsfLWj0k6Q1cB 2uRddlOzxT1c7KAy+PXLeZBLk1IwyAnImZZxZcPG5zLc1URLGcgKLos8IcE+3L4dWyOQ beRv/meXcTjM+mOGmIQNOqhgnn4DCgLolDwtATNJR+92XmVWNoZ2HHsUkbkcb6eCQ0RI 6Ge6FKMQzA2sm1e88Hgxb6k+MC1ylcmvQvsgXIFGaBAvuFKwjxRWgagaqcyCsNGbiv/K r6ldTnFupXAgP612uZvw7dFg/mbmdPofpFRJskfCmefEQ5CxTS/FlVXKOpZ1Ii9wFebn CGqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=m5DKET+zhD2D4Fd/Hccb3C70vrkwKJbqddmWptN5Rcg=; b=WfoJKXxXTH62R642EnFazmJXt7rgfTH6boRZ2Ab1w8EO1z0kXgCzSQ6CyIMpKUeqFF 6Je4HwbT5m+cIBB1OGWxGBrBlCG5rK9fkAIJgUGW9iGmW0KZRlYBkkud7h9Pe6e11idS kCBrIcqvXHgMRixxgYdg7uqGiKto/YN4Ango5vBOwxYaKnlaQ+l1Y2g3ptSCK/DVQwru o9IoRle4fjGCdwPX/YMRso+qrScAMcI/xvuJmI8TJAYl9IExPeMtUGv8HXjsEsO2mTB0 4OLyxv4H2nTQtrrg4zeNOvv/peH4FMjz6tG3lSA+jFWZyR273GQCWx+XiDuyiLzy4pP2 OZjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CcBIATws; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t22si5575184ejj.746.2021.03.15.23.24.00; Mon, 15 Mar 2021 23:24:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CcBIATws; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231490AbhCOXhn (ORCPT + 99 others); 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-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 >