Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3759159pxt; Tue, 10 Aug 2021 10:39:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfNXF3wLQWG7jF1h4KNW8Zu+PVWqx1D4IL3cVTKnAJySvBUdkASP0g1GKpVZcx/1q/Pred X-Received: by 2002:a05:6402:4cb:: with SMTP id n11mr6223161edw.292.1628617148603; Tue, 10 Aug 2021 10:39:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617148; cv=none; d=google.com; s=arc-20160816; b=KjMWwVCPhQOws2qECTqz9SVXFYLvtZpJSNprQ5XnyVLE/SjWhBFidORwMViEwg/jMG +FMZbIKnmXkpyjX2zEducJnrzfZvso+rWvwkmSGZzPBpQTTys6Ro5vZHgsgRB75o0uF3 jNaRbiTSyHvL9iy0HfyD/+TiuxxPQTIvGjVR9T9Bt4LmDTI17lKlYdoeSXvL7pJSRYWP PxTKQ6dNsVYk3A7B4H+3g8cK/nyJCS/YZ+Fi1LP7/UWwHB7+YEsD9T25mQmAFHnopOIy s5IkIBIwrWH8yRoAxv1J5AdTkTLiIuJxjP3FNjcAkAhtzdYtMvAdWbgQ5Ee7snin87L+ nyJg== 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=usVv+9faeYHfDpLGg2HvhIjJ2000ipzOECIEhhPJ1po=; b=iPvcrzoBvy++v70d3+7SwlDgUTnD8PJ97HqFXuVfobxVEbpsd/VRT6C3vFSTqmEHQY eB+XOhsU3wKgnSSyVuCDsbR+zwcK7shtgN7iHPpE4DIOzsy9T+cHsTkehl3PsfKkzPTw VHPTcuR15RlPQizLjb0ATiF25TeE94K/JuNqUtc4qzKa4uQx79wwWciIqRLD9wsy7NLe HbgMQWT+On2J/RbWhXa/oSCMvTbdDeSA/7RI8xTQIadxe29X9etKP+DSZPRK6hlFucJr rcZN1y8vqduIxN7ZnZ5rqi57ianJw/bZCjtXmA1KmxNAtDBdUzSiMaXakKGiL29SRWYF DRmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oHEy9yNw; 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 cw26si4251040edb.32.2021.08.10.10.38.44; Tue, 10 Aug 2021 10:39:08 -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=oHEy9yNw; 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 S233002AbhHJRef (ORCPT + 99 others); Tue, 10 Aug 2021 13:34:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:37570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232763AbhHJRdt (ORCPT ); Tue, 10 Aug 2021 13:33:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D9EB0610A0; Tue, 10 Aug 2021 17:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616807; bh=eSCplMMCmiCFNQYwKjfzRjfCkcDnLonYxNHYlBDptFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oHEy9yNwMePnDsU3qLKM1bRVyDyjJ+D6jlqXsheQ4vF+gzwWw0eb2LPG6VEwCYbB5 wzCxzYFk5iOfumDb23hvUcofPXo3wLsemclJnpfcf8jIY4MeyEf7+HxBbNBQlSb0Y8 dctOFil67IiOrAUcUhuqrp3k2klhyo0dXM5SOvfw= 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 4.19 44/54] KVM: x86: accept userspace interrupt only if no event is injected Date: Tue, 10 Aug 2021 19:30:38 +0200 Message-Id: <20210810172945.648257457@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172944.179901509@linuxfoundation.org> References: <20210810172944.179901509@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 @@ -3366,8 +3366,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,