Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp199693imj; Thu, 14 Feb 2019 18:31:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IYvS9KD/TgtnOvEwnL1TBf4Fjs1GiGz3uigIkxq7JCzUFuE7+MF9mZaLyKK/9DdmG+MrbRA X-Received: by 2002:a62:560f:: with SMTP id k15mr7323582pfb.231.1550197916397; Thu, 14 Feb 2019 18:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550197916; cv=none; d=google.com; s=arc-20160816; b=S/Bg+qhxBHk6CaTVJ6XPwFMmAUVtWMqBn6tMrV9A6xUqdsB1KmGmeE1vxCcQEx3AZp j339i4PqEiblvsITMOMkz2h3UXozQWPV3IopCzsGtUyb6nmYgnkxBIGyKFOcIbHodVcs 84iYBvAXIgyzOOdOfXhbP+uW1dIhiEOWl9Ie/Uo1lSRiE14jjUn//ymNeUDnbz65anQF s3IK/Z65q8I2PtzCW6P0nW0LhTblf/VqsqF7oHF/zQmcPsigynCuOIY3NrpRrfqLm9qj nxT1AKhNxP5aQr+ASWN6o2CDHj0EZQhyRUiqrflv6WLPgI8jdQlBqb+w6zE/jdmYD4tW iLtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m2+qSTosXHiEOEzktKlwtIHlMBfNq9CeiWtoW/2ysgM=; b=Gm3/iD0HB6bv7wFr7ThP/2JWbJvMQNr9DzYMOGvYmvlUKCuB0CfOQMKzn+b8I3wmpc lV/RDk7cE2Fu0RVMuT7B4D/xwi++vK6F14mBYoKlQBRlWYar0KNweXvthxV3kKv81SJe bei8SzpjOVGiiKfP8hY+jEvn0HmTD2Wj9GWA/Tz5sw5cBFpGpwLn8KIHMipEpz9ryu82 n5iywY9T8wgU1muQAMpDdOJX97B1E4cw0x4pbUWVbCCutALU77aQVJgiT742FdpjeRbs gDB3aVcwQ+Ul9MyEPV7Z0qJ3G2lkBeACjo0hQiP+yV2jh9gMkvqCt1t4p0J7amNS9qh3 tsFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MXFwpOhn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32si4448504pls.84.2019.02.14.18.31.40; Thu, 14 Feb 2019 18:31:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MXFwpOhn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392355AbfBOCQQ (ORCPT + 99 others); Thu, 14 Feb 2019 21:16:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:55650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392260AbfBOCQL (ORCPT ); Thu, 14 Feb 2019 21:16:11 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 70B0520643; Fri, 15 Feb 2019 02:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196970; bh=DKVSelkHW5vY8SMhDOWzqKKEfgYv9o8GBo6ABWDjzzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MXFwpOhnwCuxZTFPaBCWfwEqUUEwXH+lVNA4mUTdxbRHjoRWkoHRRBnezfoOTlTjQ ceBkOaJABqbQB9ExsrPIBXLiqH5fVjWFUsUy5bchSyDmztMLnrk/4kk/gQL9cWRNU1 iJsyBAIO/3DVRH/fCmiuUZbBWTkJAn9fxuTh+26M= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vitaly Kuznetsov , Paolo Bonzini , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 3.18 16/16] KVM: nSVM: clear events pending from svm_complete_interrupts() when exiting to L1 Date: Thu, 14 Feb 2019 21:15:46 -0500 Message-Id: <20190215021546.179605-16-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215021546.179605-1-sashal@kernel.org> References: <20190215021546.179605-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit 619ad846fc3452adaf71ca246c5aa711e2055398 ] kvm-unit-tests' eventinj "NMI failing on IDT" test results in NMI being delivered to the host (L1) when it's running nested. The problem seems to be: svm_complete_interrupts() raises 'nmi_injected' flag but later we decide to reflect EXIT_NPF to L1. The flag remains pending and we do NMI injection upon entry so it got delivered to L1 instead of L2. It seems that VMX code solves the same issue in prepare_vmcs12(), this was introduced with code refactoring in commit 5f3d5799974b ("KVM: nVMX: Rework event injection and recovery"). Signed-off-by: Vitaly Kuznetsov Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/svm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 2e0c64a08549..a29d59e205d3 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2431,6 +2431,14 @@ static int nested_svm_vmexit(struct vcpu_svm *svm) kvm_mmu_reset_context(&svm->vcpu); kvm_mmu_load(&svm->vcpu); + /* + * Drop what we picked up for L2 via svm_complete_interrupts() so it + * doesn't end up in L1. + */ + svm->vcpu.arch.nmi_injected = false; + kvm_clear_exception_queue(&svm->vcpu); + kvm_clear_interrupt_queue(&svm->vcpu); + return 0; } -- 2.19.1