Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6875344imu; Thu, 31 Jan 2019 00:52:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN7Nl5CSo5ETKTKgf9ebCUF/5/Gl31j5BtW51KnRPMlshouykbd+2d4Ymref70qHQwLlGGc1 X-Received: by 2002:a17:902:bcc7:: with SMTP id o7mr34560284pls.281.1548924762094; Thu, 31 Jan 2019 00:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548924762; cv=none; d=google.com; s=arc-20160816; b=CvLwEkzPA9QWv73JbXRrj1z/WIXcsFrP+90eMduc/keorewvBjbZe062gZJvdAl9gI zw08PEI6WS9KUMejjt29b5ejvZUgxOgaff7IwYLbrPIHoFs1jxmo1/RDYCPPp99xPLeA dWhQCwUpTZeHkHEI8YHpmiJfufqVJyAK7k7EU+MrvTvKkBhzfVz7PLWr9iyD86HwSmPG fE5czy0oUa6yItVVas69OeHRMdckrxmNzkyG8uicsoejXb2myYiGfeDHxorWbkh0JVG5 Ph20cocnjU4Nj7QZb1Y3EGEr6NqQ8EQczNFZ36q+JXLOf0IMnPYkTerrGj4n5XRSY8ym ctbQ== 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=qyoeDlBhEVn+viUIx72glVfMq1mDtDiWfd7Ynkg9oAs=; b=yh4vFeLF2uvbwMhSNAdHMZtCWGmVRZOxKbR8ceeWpSovSnXIh0SUNLh+0+puJ65jye YKX5DY2YyNWBQmcycx6ywNBjFJ7L4VHuYR1fz1d8SDXEYi/EjyD4ed3sFg6SNRv1Ay1W Xsff0C5FqnEAr5Dcloe/U+482XcAoTXKDTd2ugPlSJ/+QWor4mvo5zwwNJNpqKOYCmJS tB6hgfOrz0/78LdAUQSq/b80YCVigu2YvZW606OHG5g/L0MNCR5d3f3DOmAYjNWAIfyX ZPJ81EJSfjy9Y9R1v7sQgUrSP0JexoPe2H/I1r0yTIzdaCVpaaMHWkm00CRNBgegjjKF mKOA== 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 z12si4104415plk.90.2019.01.31.00.52.27; Thu, 31 Jan 2019 00:52:42 -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 S1729869AbfAaIwW (ORCPT + 99 others); Thu, 31 Jan 2019 03:52:22 -0500 Received: from mga07.intel.com ([134.134.136.100]:2665 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbfAaIwV (ORCPT ); Thu, 31 Jan 2019 03:52:21 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2019 00:52:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,543,1539673200"; d="scan'208";a="139449698" Received: from sqa-gate.sh.intel.com (HELO p-demo5.tsp.org) ([10.239.48.212]) by fmsmga002.fm.intel.com with ESMTP; 31 Jan 2019 00:52:18 -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 V3] KVM: x86: Sync the pending Posted-Interrupts Date: Thu, 31 Jan 2019 16:52:02 +0800 Message-Id: <1548924722-64060-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 | 5 +++++ arch/x86/kvm/x86.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 4341175..8ed9634 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1221,6 +1221,11 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) new.sn = 0; } while (cmpxchg64(&pi_desc->control, old.control, new.control) != old.control); + + smp_mb__after_atomic(); + + if (!bitmap_empty((unsigned long *)pi_desc->pir, NR_VECTORS)) + pi_test_and_set_on(pi_desc); } /* diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3d27206..5bcf2c4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7794,7 +7794,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