Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5642218pxv; Wed, 28 Jul 2021 16:13:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDM8SNtKeJjgzzredjCysq64S9v6kMSwVZs9bTUSyvCsQl/f69CyTRy8StdlwSTxNvfoK6 X-Received: by 2002:a50:f61b:: with SMTP id c27mr2601207edn.96.1627513986166; Wed, 28 Jul 2021 16:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627513986; cv=none; d=google.com; s=arc-20160816; b=tyDU6xIf4qlKlKhedDWB2eb9l1z4L9f1gtXIn4X6BdCjwzQbxnDyTKNZgw1baZjqoR 9iJW/l4dHuH78jZtw1lAwfJX++rL4cOH5J/AYhwRofXmuBn8BX5lQsqC9pHibDoKJa+U YXFWWnOqgaaThqc2edNL7t+CJbE0RMtKSK1WJgZAevO52bfzXDcfjO12oPW2fStrnb/V pQoakiZSLlqDu5hSDn4YYA6peLUKImswcSQSVR25cTCxQsvyO8bB6b6xxfvuYY7CtTDg /c6i6d8iMXM5d9UqvuguSJB35VQgxvBaq6gJKafpGRS+3PSTWmh9NbjS0NLrr5tmAiw+ 0Hjw== 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=wjVZYNNKvkz+dEqnRUcvgnvoiUT+17D6nY+LOvQaqFM=; b=Z/SOZrM2J0yW+ZCm9/BQxdHxVdt/Ws6iy3cmSB/L2BSdH+2VP+zY3pHz2xspNnaA5V 8yYSmppOSHtzQBVBrxKVhf87uD3jGRhusjFnLL3X1Zrbhp+2hQOu117R2AC4oV7wyUId F+THM/jYf6nMzSqFdeGDe+JkXsENF9e6NX+P0sV4dgv/r64Hk8haGYPb58z3xk5fFkEP PNtPewYXGJuTCX3ZIoMwa26Mb3Miy0nENASJHS0S1ZeS2HTnaqy/s3dDqThGR2MQsGLT pkhkfmsO8zqskayTDt1qfXOQZv1zs9bTndfZWC52cIW4RVNh4w66myCI0++nXJ9cRudR aNIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LyMc9TiB; 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 rn12si1081358ejb.594.2021.07.28.16.12.41; Wed, 28 Jul 2021 16:13:06 -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=LyMc9TiB; 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 S232230AbhG1XLQ (ORCPT + 99 others); Wed, 28 Jul 2021 19:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232163AbhG1XLQ (ORCPT ); Wed, 28 Jul 2021 19:11:16 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07D24C061757 for ; Wed, 28 Jul 2021 16:11:14 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id pf12-20020a17090b1d8cb0290175c085e7a5so12618449pjb.0 for ; Wed, 28 Jul 2021 16:11:13 -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=wjVZYNNKvkz+dEqnRUcvgnvoiUT+17D6nY+LOvQaqFM=; b=LyMc9TiBuRMdPTTAqLyUditTfLnTTRPuRFiSp1/g8qRVaSD911B/hJ1JigdxNGzzZf ZHDMhL9XPwZG0HIqkWCW3SRP6cYblxII2QqbZ8fV6TaLmbFo8yqjFMTib+i6WYFJT4sa IS+58xCLXSpKvXmnCksM0Ei9UmmjMgvt+D6PsoZKlOXTW1JNEoz2ICejKZ4GhKjStROc SVpNxF9wX1owUlE9qVtbjcXiGgU6XC57ml5EvUyT+9nNzkUIO+tvjupt7nbZBOwxAHDX Lk5rYLBoFYdJENOhInfMC+gB4BDDNYozGaNPHUto8QY+oIZsV9E4sLKSqGMHV/oM9B3T Y2Sg== 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=wjVZYNNKvkz+dEqnRUcvgnvoiUT+17D6nY+LOvQaqFM=; b=Ly4WcP4tXfCwNo1mS7OxeSV5TflZD06cEQPr6HAE4rMPOIucGbZwZ/TwUVjxwaeczX c65n77thMurNDlUg9XGtZd77J5fBk6X4lRPpsR+WkZjYf/R6HqiVwAVLuPk8YxsPW5KP DkNd4BBVKXechqAuFiFoJZIhRAw/pU6aJ9v/LBwvvSoL5BTTL+EsoFFFY8JcAm8SKvAV cfwBGb0nohFlM/zjwcgmrVdEos9jJ7Ix4oGOT/H2cKUTBQI3nYavwoD7kOSc0IcecIvi 3gcZym3t3Hxxh8JExNNqA26URny4P5GwMvGedhCQ+3LcIA9aWdsGyUaPZThTW/XOxPSg 7sTw== X-Gm-Message-State: AOAM533bPfX5DLZIseztA77AGu/nhWfc0QD3Dda21MLuozl6k9YxHQR2 D5iZtx03oP5vDpMRo3r5tO4y8xRYZB9tBg== X-Received: by 2002:a17:90a:bd06:: with SMTP id y6mr2147490pjr.6.1627513873271; Wed, 28 Jul 2021 16:11:13 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id p17sm1058543pfh.33.2021.07.28.16.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 16:11:12 -0700 (PDT) Date: Wed, 28 Jul 2021 23:11:08 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, stable@vger.kernel.org, Stas Sergeev Subject: Re: [PATCH v3] KVM: x86: accept userspace interrupt only if no event is injected Message-ID: References: <20210727210916.1652841-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210727210916.1652841-1-pbonzini@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 27, 2021, Paolo Bonzini wrote: > Once an exception has been injected, any side effects related to > the exception (such as setting CR2 or DR6) have been taked place. > Therefore, once KVM sets the VM-entry interruption information > field or the AMD EVENTINJ field, the next VM-entry must deliver that > exception. > > Pending interrupts are processed after injected exceptions, so > in theory it would not be a problem to use KVM_INTERRUPT when > an injected exception is present. However, DOSEMU is using > run->ready_for_interrupt_injection to detect interrupt windows > and then using KVM_SET_SREGS/KVM_SET_REGS to inject the > interrupt manually. For this to work, the interrupt window > must be delayed after the completion of the previous event > injection. > > Cc: stable@vger.kernel.org > Reported-by: Stas Sergeev > Tested-by: Stas Sergeev > Fixes: 71cc849b7093 ("KVM: x86: Fix split-irqchip vs interrupt injection window request") > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/x86.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 4116567f3d44..e5d5c5ed7dd4 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -4358,8 +4358,17 @@ static int kvm_cpu_accept_dm_intr(struct kvm_vcpu *vcpu) > > static int kvm_vcpu_ready_for_interrupt_injection(struct kvm_vcpu *vcpu) > { > - return kvm_arch_interrupt_allowed(vcpu) && > - kvm_cpu_accept_dm_intr(vcpu); > + /* > + * Do not cause an interrupt window exit if an exception > + * is pending or an event needs reinjection; userspace > + * might want to inject the interrupt manually using KVM_SET_REGS > + * or KVM_SET_SREGS. For that to work, we must be at an > + * instruction boundary and with no events half-injected. > + */ > + return (kvm_arch_interrupt_allowed(vcpu) && Ha, adding a '(' is one way to fix the indentation. Reviewed-by: Sean Christopherson > + kvm_cpu_accept_dm_intr(vcpu) && > + !kvm_event_needs_reinjection(vcpu) && > + !vcpu->arch.exception.pending); > } > > static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, > -- > 2.27.0 >