Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp198017imj; Thu, 14 Feb 2019 18:29:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IZYkbRef3UVq2r5nFRk915iAj8tzEpw94B6tmvSxpSFaR2wVnWVAlgnR8Jbl1heqi3l4gY/ X-Received: by 2002:a63:d34a:: with SMTP id u10mr3109833pgi.301.1550197795438; Thu, 14 Feb 2019 18:29:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550197795; cv=none; d=google.com; s=arc-20160816; b=iy35kuM4msYe6yY4M4ro7Fo6syFQvLAFeFZlWd3Qjx+Vm68kOQlN6xJoLzn77Ckg15 g+L+/ZYAGzPpruX5sS4UX7ci6l/50QU88SaiMjaOPEINLJRvcS9B+9MRQT6CEdw9yafg 6VDzgGlAQqtZ5S3Kn88GYZk1gFcltOB2HdNk2577BOrOKxGMfFCezOUvJqAKBaM8irPJ cpkur5/Vbdu31uNjJMaowAUjT+Bv6LM0dKE7g/canWRuoPIQSFd8rHo9vc/CForhg+2l 7Cawduduwgmbem1Cd1ThHG/np2Osb292gZ4TuHuoi/WQEFElMIwBdI0M2A6BLm50Em8Q kLwQ== 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=LN6Pij7084h4o0zG/6c3sIs/RucQ+1d36y8caxGfRSw=; b=Krds/9jAVnbXPw7I1BRNXUYA9d/5y6zMIgW/BtjP2kdvyjtR26D73ZtA+wytkZrr0L ClybPIABzdx/3s6/TDUAMnNHH2rvvc/xAi2UKZhzUAMgCiSXukOp16+qzQsbkDrY/4X1 Ems+b0EHUrlY0+h3IGFnduCMNj/5RlhkCVOkOAdUSFr5l5k+62KGTKHhkI+TLbP1tCoj Jm3wrj1ndCSl8Cmdb0fjtlkZ31Gpbf9Ap+Q3qQInxjaGKsr6LantzmsXbl/LpLQV5EI3 knLIEkHEkBR4rM6Y8dTcbMgNWIuXKNB2BS4V/NbcIe2tKmMImlO6+euqA8y2ZXLrk2l7 H3Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="L/sBGxCW"; 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 4si4284612pff.161.2019.02.14.18.29.39; Thu, 14 Feb 2019 18:29:55 -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="L/sBGxCW"; 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 S1732177AbfBOCLI (ORCPT + 99 others); Thu, 14 Feb 2019 21:11:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:51176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732159AbfBOCLG (ORCPT ); Thu, 14 Feb 2019 21:11:06 -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 D7BDD222D0; Fri, 15 Feb 2019 02:11:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196665; bh=UQtZ/xPv5SVvDmOfXm3oaPed7JqTH7fjVh359hv7WjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/sBGxCWZJUQQr6Pt/5uhW/LWvgXQ8kO3XBuMBZkkdE9sIoUz5t+eN/OHFKOKr/5o F+vX9TH+FCotv8ZBe/IM1tm/GxZu9ij0wt/0uewQtmfkRXKRVk0xF6KqM9EHs/f/Su yO6X1cyZlhh0It+RSU91S1pnlStjUAjDdosN2pCM= 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 4.20 74/77] KVM: nSVM: clear events pending from svm_complete_interrupts() when exiting to L1 Date: Thu, 14 Feb 2019 21:08:52 -0500 Message-Id: <20190215020855.176727-74-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-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 cea8f8c03e8c..3411c32a8770 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3401,6 +3401,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