From patchwork Tue Aug 26 16:27:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Wei W" X-Patchwork-Id: 4778731 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 85A0BC0338 for ; Tue, 26 Aug 2014 08:03:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6C06F20149 for ; Tue, 26 Aug 2014 08:03:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EC1772016C for ; Tue, 26 Aug 2014 08:03:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934030AbaHZIDU (ORCPT ); Tue, 26 Aug 2014 04:03:20 -0400 Received: from mga01.intel.com ([192.55.52.88]:13217 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934005AbaHZIDQ (ORCPT ); Tue, 26 Aug 2014 04:03:16 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 26 Aug 2014 01:03:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,402,1406617200"; d="scan'208";a="589899217" Received: from unknown (HELO otc.sh.intel.com) ([10.239.48.14]) by fmsmga002.fm.intel.com with ESMTP; 26 Aug 2014 01:03:14 -0700 From: Wei Wang To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, alex.williamson@redhat.com, Wei Wang , Yang Zhang Subject: [PATCH] KVM: x86: sync old tmr with ioapic to update Date: Wed, 27 Aug 2014 00:27:21 +0800 Message-Id: <1409070441-31239-1-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 1.7.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP kvm_ioapic_scan_entry() needs to update tmr. The previous lapic tmr value (old_tmr) needs to sync with ioapic to get an accurate updated tmr value before the updating work. Tested-by: Rongrong Liu Signed-off-by: Yang Zhang Signed-off-by: Wei Wang --- arch/x86/kvm/lapic.c | 11 ++++++++++- arch/x86/kvm/x86.c | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 08e8a89..93c2e93 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -518,10 +518,19 @@ static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu) void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr) { struct kvm_lapic *apic = vcpu->arch.apic; + u32 irr[8]; + u32 isr[8]; + u32 old_tmr[8]; int i; - for (i = 0; i < 8; i++) + for (i = 0; i < 8; i++) { + irr[i] = kvm_apic_get_reg(apic, APIC_IRR + 0x10 * i); + isr[i] = kvm_apic_get_reg(apic, APIC_ISR + 0x10 * i); + old_tmr[i] = kvm_apic_get_reg(apic, APIC_TMR + 0x10 * i); + tmr[i] = (~(irr[i] | isr[i]) & tmr[i]) + | ((irr[i] | isr[i]) & old_tmr[i]); apic_set_reg(apic, APIC_TMR + 0x10 * i, tmr[i]); + } } static void apic_update_ppr(struct kvm_lapic *apic) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5f5edb6..d401684 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5991,8 +5991,8 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu) memset(tmr, 0, 32); kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr); - kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap); kvm_apic_update_tmr(vcpu, tmr); + kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap); } /*