Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4314137pxf; Tue, 16 Mar 2021 10:21:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweionpN7U5pp9RXqham2iPHqQJI6LAQjq1GzW+clHn4bZrJ8XfXRQS6eUgmcAMtY3raLSc X-Received: by 2002:a17:906:2e08:: with SMTP id n8mr30293600eji.527.1615915314999; Tue, 16 Mar 2021 10:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615915314; cv=none; d=google.com; s=arc-20160816; b=LAxqO7s2DB24cxdlxp3r21AZ3PcttTR5FWJPidPnofeH2CCy+5EKq0iNqp6cG7oiY9 yPJdZX+qUQV2egcroa/VgfsHObBeJeoy19t6du+OPHCZ+YCSOXFgzBVQ8o+jg9EpAKI2 n+1TjEOEjKykrE3R6KyjUuwrGKPWYJfF+2C9QyokI7ap9Cp9GFrisoG9LsmUk+lN+Uev La7tFXCWC2fZDLx9AZ0Ud53knpa8IgDyNXliT+dcr8UrY/Hvehw87hZs+GzbHoIz9UqT OXonHjqOK89BvapPmZEAxLgjhp3jPG1SqTKbi6eEM4DAMMubB06uCV892aM5vOTV5fjg 6rCg== 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=P3cgybX7ioPXwPBlHSP7Ta0F/dtycULJBVQIjaI9xwU=; b=l2Gma2n44lxBxEvHHDQ3TtdrHjh/bDXvUqr+pWhXDXt3b7nnZ+jgG883tAycdzub5y kCOcDCh0LfNcpAKq8yoPLMIZKVcivKvfJswddmP7q1pXumt3oGdr2pKKGMM68coWxNVo P4XMgqbV8JSN7KenqRwcyl5K/MCprA3Ur7Rb4V5GdGkdtkIzR2ZO7cRRLDJJik3GGIJT IEbduOYmL+PPrGUWiWegzlqdrzc6LZIyRw/wkP9k6mKDy83w5TCPdAPRGKx2hIAA/eBM HKqSAUjMqG7VKAlVcvGj42TIzvYsNXxR8o71YKFFW/SolNqIFPTKN6KxmeJoB41EXkh0 KfIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="DfXQ/GWd"; 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 g24si4020409ejw.478.2021.03.16.10.21.32; Tue, 16 Mar 2021 10:21:54 -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="DfXQ/GWd"; 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 S235582AbhCPQvD (ORCPT + 99 others); Tue, 16 Mar 2021 12:51:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231923AbhCPQuc (ORCPT ); Tue, 16 Mar 2021 12:50:32 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B59F3C06174A for ; Tue, 16 Mar 2021 09:50:31 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id j6so17223410plx.6 for ; Tue, 16 Mar 2021 09:50:31 -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=P3cgybX7ioPXwPBlHSP7Ta0F/dtycULJBVQIjaI9xwU=; b=DfXQ/GWdyAlC4zxhPCDDGwTw2EUrPyaCI0RSD+ug5wU3vDRF2d6gbvVtY3wopM/YAn 4V8f83ZQzBY9ZWONW8ntZO6X9TxEyNaN2tmQGTZdzVce2hVVh27ITLx7SobeLsg1cxPe wlpCbtUoEYwaYcjwszpRKAcfekKYdH4LUMZg8daXW9O7p7uwioGZCDBEueR7MBy1DIen sdb4Gr7mmfAVym3aAOXGqLkNjjCTWh0q+DATJUAZxbDenj2Da6bC88VwGl9aoNW6HFU4 /QWktyzuxGDohdwxiwaxjs57oYsDnLn2JtPYeolvi0z69+am4f64mUakv0B+Hg9XWQDT 9Udw== 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=P3cgybX7ioPXwPBlHSP7Ta0F/dtycULJBVQIjaI9xwU=; b=RAp1F+CoopTfEjfZJoJVSaNqz7eyq2/5y1q7/e6ZK6E9GMbm1UN7G1YIw5stWVjNvN FiU7tvDephaTiRLMKdTU+i9O5lg2qzlPNTmNpzx+FJrOPPfXHusNk4BVyWvobBbrnoZv PGZER2998geNcZiHUiW82/n++SqsOBlQ6bdI2WgaX31cyw3kMswOTgKRNTVSlQvWZXuR V1lAhcfdI1pvjtDTd0Q0u7iyyZ5q0dkV1bnZ1DQpFJcVb/Nd5WbbK+poXUJZDXSEqCLK SxkfeQXT58IFB5u/zQAbZYbImNQwOzIBjDdgOoJPimKoWQ65EqfxZQSNLXfGUw60/VYf 4y/Q== X-Gm-Message-State: AOAM5317wooTMo2tg2tr+M5wlKbiDQYLS+4Q8393pUdw0f4cNhEn0b9N U4GI+yQnj4J3/ZsN4JcntTLCOg== X-Received: by 2002:a17:90a:f184:: with SMTP id bv4mr516993pjb.43.1615913430998; Tue, 16 Mar 2021 09:50:30 -0700 (PDT) Received: from google.com ([2620:15c:f:10:e113:95c2:2d1:e304]) by smtp.gmail.com with ESMTPSA id y23sm16911202pfo.50.2021.03.16.09.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 09:50:30 -0700 (PDT) Date: Tue, 16 Mar 2021 09:50:23 -0700 From: Sean Christopherson To: Maxim Levitsky Cc: Jan Kiszka , kvm list , Vitaly Kuznetsov , LKML , Thomas Gleixner , Wanpeng Li , Kieran Bingham , Jessica Yu , 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-3-mlevitsk@redhat.com> <1259724f-1bdb-6229-2772-3192f6d17a4a@siemens.com> <71ae8b75c30fd0f87e760216ad310ddf72d31c7b.camel@redhat.com> <2a44c302-744e-2794-59f6-c921b895726d@siemens.com> <1d27b215a488f8b8fc175e97c5ab973cc811922d.camel@redhat.com> <727e5ef1-f771-1301-88d6-d76f05540b01@siemens.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 16, 2021, Maxim Levitsky wrote: > On Tue, 2021-03-16 at 16:31 +0100, Jan Kiszka wrote: > > Back then, when I was hacking on the gdb-stub and KVM support, the > > monitor trap flag was not yet broadly available, but the idea to once > > use it was already there. Now it can be considered broadly available, > > but it would still require some changes to get it in. > > > > Unfortunately, we don't have such thing with SVM, even recent versions, > > right? So, a proper way of avoiding diverting event injections while we > > are having the guest in an "incorrect" state should definitely be the goal. > Yes, I am not aware of anything like monitor trap on SVM. > > > > > Given that KVM knows whether TF originates solely from guest debugging > > or was (also) injected by the guest, we should be able to identify the > > cases where your approach is best to apply. And that without any extra > > control knob that everyone will only forget to set. > Well I think that the downside of this patch is that the user might actually > want to single step into an interrupt handler, and this patch makes it a bit > more complicated, and changes the default behavior. Yes. And, as is, this also blocks NMIs and SMIs. I suspect it also doesn't prevent weirdness if the guest is running in L2, since IRQs for L1 will cause exits from L2 during nested_ops->check_events(). > I have no objections though to use this patch as is, or at least make this > the new default with a new flag to override this. That's less bad, but IMO still violates the principle of least surprise, e.g. someone that is single-stepping a guest and is expecting an IRQ to fire will be all kinds of confused if they see all the proper IRR, ISR, EFLAGS.IF, etc... settings, but no interrupt. > Sean Christopherson, what do you think? Rather than block all events in KVM, what about having QEMU "pause" the timer? E.g. save MSR_TSC_DEADLINE and APIC_TMICT (or inspect the guest to find out which flavor it's using), clear them to zero, then restore both when single-stepping is disabled. I think that will work?