Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5308890imu; Tue, 29 Jan 2019 17:05:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN78JMwabU2sdj7ky8cTLt8QVs2f6KenrYjGf6WGANdEGNnyqqW2oojOU91dO3YBTKMfLLCu X-Received: by 2002:a62:b24a:: with SMTP id x71mr29094114pfe.148.1548810311099; Tue, 29 Jan 2019 17:05:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548810311; cv=none; d=google.com; s=arc-20160816; b=LCIrJdY+Z8hcTJjVd3YkehvYA5zAf/FSeCf3nHgIfX0Yd7NogOzBMJ4ITOAHB4nK6f DO6F39no0wY44wOejSfZpsFPyN3ydnQ73ekXSPKPYO3liPlIElzt04cWXXYsKAhqtqgT XRhhseinu4yRiFb/x9S2np9a4xldTql9WSknPLXU6gk0KVQR8LTfnKqraQcIqPdhjU4Y /RirVW/Y0+vIQNOvRHgMv/eAiFBlj43KKt+5ztxsDL4jfQbx434d7OYXCLQkhjCAlxqm ZkehtmnX59IiZTm4Mmfs+PaGZSDSYek8rAc6j9XO3lYQtyALjqAVnLQdcdPvCt/DKSFQ rrpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=CYax0f1SZfAJb7E/n+2uDWoDSBvLlLvWcPo3eiUYakw=; b=YTCfTT8XoMdWkk3sldhbCGEos0WwuwuJuF3SRdq7FSYDkp34N6V106J3UqOBxQ0Vdm 7IBNcq/k4Ma38drad1M3pgcyAauqNIZpU9gUcYiIRartDFqhVozXsVNOkXVT7MH5MGnZ ZKRl3iZOVV7RaLRE3ZKw2/UHPJHrHOjcc5u9NX/CmC/4MFMi3wYda9BwnnFZyBLpVK6i qbPfHFNubm2RjsNztvi+d8yAhv3zvI9Ue5E/eCda5SzZWTWe0JxLSEUb+NqEVG1wY5QU JQ/mr7JPw8/I0gFbIJRlEtRg1BJBZRWmkFamI6Atr4kPTgUuuyja7t18fIXm9qdZFw2s ROpA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d25si28420pgd.88.2019.01.29.17.04.21; Tue, 29 Jan 2019 17:05:11 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727542AbfA3BAl (ORCPT + 99 others); Tue, 29 Jan 2019 20:00:41 -0500 Received: from mga12.intel.com ([192.55.52.136]:58796 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726693AbfA3BAl (ORCPT ); Tue, 29 Jan 2019 20:00:41 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2019 17:00:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,538,1539673200"; d="scan'208";a="129608937" Received: from skl-d.bj.intel.com ([10.238.135.173]) by FMSMGA003.fm.intel.com with ESMTP; 29 Jan 2019 17:00:38 -0800 From: Luwei Kang To: pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Luwei Kang Subject: [PATCH v2] KVM: x86: Sync the pending Posted-Interrupts Date: Wed, 30 Jan 2019 08:59:32 +0800 Message-Id: <1548809972-32100-1-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some Posted-Interrupts from passthrough devices may be lost or overwritten when the vCPU is in runnable state. The SN (Suppress Notification) of PID (Posted Interrupt Descriptor) will be set when the vCPU is preempted (vCPU in KVM_MP_STATE_RUNNABLE state but not running on physical CPU). If a posted interrupt coming at this time, the irq remmaping facility will set the bit of PIR (Posted Interrupt Requests) without ON (Outstanding Notification). So this interrupt can't be sync to APIC virtualization register and will not be handled by Guest because ON is zero. Signed-off-by: Luwei Kang --- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/x86.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index f6915f1..820a03b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6048,7 +6048,7 @@ static int vmx_sync_pir_to_irr(struct kvm_vcpu *vcpu) bool max_irr_updated; WARN_ON(!vcpu->arch.apicv_active); - if (pi_test_on(&vmx->pi_desc)) { + if (!bitmap_empty((unsigned long *)vmx->pi_desc.pir, NR_VECTORS)) { pi_clear_on(&vmx->pi_desc); /* * IOMMU can write to PIR.ON, so the barrier matters even on UP. diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 02c8e09..c31b608 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7793,7 +7793,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) * 1) We should set ->mode before checking ->requests. Please see * the comment in kvm_vcpu_exiting_guest_mode(). * - * 2) For APICv, we should set ->mode before checking PIR.ON. This + * 2) For APICv, we should set ->mode before checking PID.PIR. This * pairs with the memory barrier implicit in pi_test_and_set_on * (see vmx_deliver_posted_interrupt). * -- 1.8.3.1