From patchwork Wed Dec 24 03:14:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wincy Van X-Patchwork-Id: 5536131 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 053529F1CD for ; Wed, 24 Dec 2014 03:15:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 333EB201BC for ; Wed, 24 Dec 2014 03:15:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48779201BB for ; Wed, 24 Dec 2014 03:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751587AbaLXDPa (ORCPT ); Tue, 23 Dec 2014 22:15:30 -0500 Received: from mail-pa0-f51.google.com ([209.85.220.51]:57811 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751582AbaLXDP0 (ORCPT ); Tue, 23 Dec 2014 22:15:26 -0500 Received: by mail-pa0-f51.google.com with SMTP id ey11so9120707pad.24; Tue, 23 Dec 2014 19:15:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=+FGvPL5156TvS6xsBYq7XoBwjY9D4FHnLqRSa15IkFc=; b=OB6UzL6xMJxuFYzQA4+UYD8f7R7l1Oci9fK4ANkNxULXXzSuU7Jo8ID8RGkvsnPmdP 3yA2jQK11aNvbrpb4h1z9Izz/9/R9jaxPeTfhXWsqYfh4nFfuMnbr+qQrcNPzbTF9kju Qnu0rSoAOHo1ugPGGF62MU21Fs0aDeAwsKt37KWxc4W+CNcmX3eaBVWWw2AN7KFep0uN Pp1oo4DfxnUvYRo2Jbahlt5xFF3Cwh3rTMnqkBzkJpsGrcTiJS+9HRznK5krLq7BilJg UdAQKCnjHTiTWwlQR3fVTJg1HuICuhTMBlXvHgz/0xdq6CYt6p/KAXHbnXUzA1838kdB Muqg== X-Received: by 10.66.121.168 with SMTP id ll8mr49863736pab.34.1419390925816; Tue, 23 Dec 2014 19:15:25 -0800 (PST) Received: from localhost ([219.141.176.228]) by mx.google.com with ESMTPSA id i3sm5195201pdf.39.2014.12.23.19.15.22 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Tue, 23 Dec 2014 19:15:23 -0800 (PST) From: Wincy Van To: pbonzini@redhat.com, bsd@redhat.com Cc: yang.z.zhang@intel.com, wanpeng.li@linux.intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, fanwenyi0529@gmail.com Subject: [PATCH 1/1] KVM: ioapic: Record edge-triggered interrupts delivery status. Date: Wed, 24 Dec 2014 11:14:29 +0800 Message-Id: <1419390869-1636-1-git-send-email-fanwenyi0529@gmail.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=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 This patch fixes the bug discussed in https://www.mail-archive.com/kvm@vger.kernel.org/msg109813.html This patch uses a new field named irr_delivered to record the delivery status of edge-triggered interrupts, and clears the delivered interrupts in kvm_get_ioapic. So it has the same effect of commit 0bc830b05c667218d703f2026ec866c49df974fc ("KVM: ioapic: clear IRR for edge-triggered interrupts at delivery") while avoids the bug of Windows guests. Signed-off-by: Wincy Van --- arch/x86/kvm/ioapic.c | 7 ++++++- arch/x86/kvm/ioapic.h | 1 + 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index b1947e0..a2e9d96 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c @@ -206,6 +206,8 @@ static int ioapic_set_irq(struct kvm_ioapic *ioapic, unsigned int irq, old_irr = ioapic->irr; ioapic->irr |= mask; + if (edge) + ioapic->irr_delivered &= ~mask; if ((edge && old_irr == ioapic->irr) || (!edge && entry.fields.remote_irr)) { ret = 0; @@ -349,7 +351,7 @@ static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status) irqe.shorthand = 0; if (irqe.trig_mode == IOAPIC_EDGE_TRIG) - ioapic->irr &= ~(1 << irq); + ioapic->irr_delivered |= 1 << irq; if (irq == RTC_GSI && line_status) { /* @@ -597,6 +599,7 @@ static void kvm_ioapic_reset(struct kvm_ioapic *ioapic) ioapic->base_address = IOAPIC_DEFAULT_BASE_ADDRESS; ioapic->ioregsel = 0; ioapic->irr = 0; + ioapic->irr_delivered = 0; ioapic->id = 0; memset(ioapic->irq_eoi, 0x00, IOAPIC_NUM_PINS); rtc_irq_eoi_tracking_reset(ioapic); @@ -654,6 +657,7 @@ int kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state) spin_lock(&ioapic->lock); memcpy(state, ioapic, sizeof(struct kvm_ioapic_state)); + state->irr &= ~ioapic->irr_delivered; spin_unlock(&ioapic->lock); return 0; } @@ -667,6 +671,7 @@ int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state) spin_lock(&ioapic->lock); memcpy(ioapic, state, sizeof(struct kvm_ioapic_state)); ioapic->irr = 0; + ioapic->irr_delivered = 0; update_handled_vectors(ioapic); kvm_vcpu_request_scan_ioapic(kvm); kvm_ioapic_inject_all(ioapic, state->irr); diff --git a/arch/x86/kvm/ioapic.h b/arch/x86/kvm/ioapic.h index 3c91955..a5cdfc0 100644 --- a/arch/x86/kvm/ioapic.h +++ b/arch/x86/kvm/ioapic.h @@ -77,6 +77,7 @@ struct kvm_ioapic { struct rtc_status rtc_status; struct delayed_work eoi_inject; u32 irq_eoi[IOAPIC_NUM_PINS]; + u32 irr_delivered; }; #ifdef DEBUG