Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3768623pxt; Tue, 10 Aug 2021 10:53:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBZFFinVJp5/yobL/j+wCH+i4a5yBWDX7IydP0enOiPu5/2BIvW2OeT9Mcr/Gox7B8I96u X-Received: by 2002:a92:a008:: with SMTP id e8mr86111ili.187.1628617996472; Tue, 10 Aug 2021 10:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617996; cv=none; d=google.com; s=arc-20160816; b=y59Ep13V8iSRoPswQ85olnj/sfBSAIW1gs6ZCyx1gWLSYpFuYXQg2lvskXf9MIU3ay fMsadNsthUpoIv7OxWU9VJspEPKOS9Au+ccTsh7JTUsiZrmH1fEKLiOEf3lwmSWl4jew 5umPCO0iM+7uIi6zTGKPH0D/spMvk3tgWOXROac4nur5YGEKaBh1tvi96FJ9bpkvNuqu JhL8hZb5wbhrwhNbKsxrcDFB6il/TPIk9MfKMuAnAdHhBEtxKGv6dPmh+xN8E26l9lSW fNm9PlK6Qj2pFQT/zcyS0QZ5aQJ1Qf1GtaeWoAvkCqv2DXFqZhkQ0Xd81tfd8BwMsknz XakQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5T80IzLRnVx5iZE9ZlI0AfDPSzZXEGQ2p8B1CHR/vUo=; b=gwe2xsVcDpcFAlq2EmS9/RQ0g02IqRo8vulnLOcySuOr9talYhuzjubmIEdou3Ra3B gqgHMPw2sHpwM6NPjkkfwizJnZVE21GZBc267hWzPTWhszHwFg5TE0j9hE0k+0jxgtZl U7AKX/CdNjS63muY7QZ2tc434w2IyAWteOmDFHiA2+xyIEynFu0UEQjhS/fSfTMIounV lqaBO8c48Vq1wnfnCYBltv5BgDyfgKKZdC8WMH/kNRLyFq/0lQ5P09qSo2HvFuPHr/mz Ytk6DRixxj7umsc2P/QIkF10d9f0VUmxFW+XmOwmzRdVsT+HKBaOosFKTQHvqYCj6SdH Y+mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Q/vaOgee"; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s1si21459071ios.1.2021.08.10.10.53.04; Tue, 10 Aug 2021 10:53:16 -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=@linuxfoundation.org header.s=korg header.b="Q/vaOgee"; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236137AbhHJRwi (ORCPT + 99 others); Tue, 10 Aug 2021 13:52:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:56820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236730AbhHJRtl (ORCPT ); Tue, 10 Aug 2021 13:49:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D10236109F; Tue, 10 Aug 2021 17:41:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617308; bh=x4uvM95IeXEncChlZL70/Qu4B9ADzgaoq1ZvYxAOVu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q/vaOgeekKNgXku17gtfsYhhwoGBpSaQ4Twbl1Oe8pTjvdow51E2a5/MoecKrFdLX q1Y7x71xg0YcNs09BRpyw3DjXBeIFuBD2k2wJlRu3OQeYr7N9lHI/+wz5ByC0lT0jN b9bOUEkxA8MRdF0kSB7IBvIHCYqaYJhhPWJJuigY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stas Sergeev , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.10 110/135] KVM: x86: accept userspace interrupt only if no event is injected Date: Tue, 10 Aug 2021 19:30:44 +0200 Message-Id: <20210810172959.514733856@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini commit fa7a549d321a4189677b0cea86e58d9db7977f7b upstream. 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") Reviewed-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4100,8 +4100,17 @@ static int kvm_cpu_accept_dm_intr(struct 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) && + 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,