kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Suthikulpanit, Suravee" <Suravee.Suthikulpanit@amd.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"x86@kernel.org" <x86@kernel.org>
Cc: "joro@8bytes.org" <joro@8bytes.org>,
	"rkrcmar@redhat.com" <rkrcmar@redhat.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"bp@alien8.de" <bp@alien8.de>, "hpa@zytor.com" <hpa@zytor.com>,
	"jsteckli@amazon.de" <jsteckli@amazon.de>,
	"sironi@amazon.de" <sironi@amazon.de>,
	"wawei@amazon.de" <wawei@amazon.de>,
	"Suthikulpanit, Suravee" <Suravee.Suthikulpanit@amd.com>
Subject: [RFC PATCH 7/8] KVM: i8254: Remove need for irq ack notifier
Date: Mon, 4 Feb 2019 14:42:27 +0000	[thread overview]
Message-ID: <20190204144128.9489-8-suravee.suthikulpanit@amd.com> (raw)
In-Reply-To: <20190204144128.9489-1-suravee.suthikulpanit@amd.com>

From: Julian Stecklina <jsteckli@amazon.de>

ACK notifiers don't work with AMD AVIC when the PIT interrupt is
delivered as edge-triggered fixed interrupt via the IOAPIC. AMD
processors cannot exit on EOI for these interrupts. The ACK notifiers do
work when the interrupt is delivered via PIC as ExtINT, because the ACK
comes as PIO write that KVM sees.

Change the PIT code to not rely on the ACK notifiers. The IRQ ACK
notifier in the PIT emulation re-schedules pit->expired to reinject any
pending PIT interrupt. This seems useless, because we can pulse the PIT
interrupt even when the interrupt is not ACKed yet. This means any timer
expiry when the interrupt was being handled by the guest, will cause an
interrupt to be injected automatically when the interrupt is ACKed.

Reviewed-by: Filippo Sironi <sironi@amazon.de>
Signed-off-by: Julian Stecklina <jsteckli@amazon.de>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 arch/x86/kvm/i8254.c | 22 +---------------------
 arch/x86/kvm/i8254.h |  2 --
 2 files changed, 1 insertion(+), 23 deletions(-)

diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index af192895b1fc..a8f6eb0ac1a0 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -200,21 +200,6 @@ static inline struct kvm_pit *pit_state_to_pit(struct kvm_kpit_state *ps)
 	return container_of(ps, struct kvm_pit, pit_state);
 }
 
-static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian)
-{
-	struct kvm_kpit_state *ps = container_of(kian, struct kvm_kpit_state,
-						 irq_ack_notifier);
-	struct kvm_pit *pit = pit_state_to_pit(ps);
-
-	atomic_set(&ps->irq_ack, 1);
-	/* irq_ack should be set before pending is read.  Order accesses with
-	 * inc(pending) in pit_timer_fn and xchg(irq_ack, 0) in pit_do_work.
-	 */
-	smp_mb();
-	if (atomic_dec_if_positive(&ps->pending) > 0)
-		kthread_queue_work(pit->worker, &pit->expired);
-}
-
 void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
 {
 	struct kvm_pit *pit = vcpu->kvm->arch.vpit;
@@ -244,7 +229,7 @@ static void pit_do_work(struct kthread_work *work)
 	int i;
 	struct kvm_kpit_state *ps = &pit->pit_state;
 
-	if (atomic_read(&ps->reinject) && !atomic_xchg(&ps->irq_ack, 0))
+	if (atomic_read(&ps->reinject) && !atomic_xchg(&ps->pending, 0))
 		return;
 
 	kvm_set_irq(kvm, pit->irq_source_id, 0, 1, false);
@@ -284,7 +269,6 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
 static inline void kvm_pit_reset_reinject(struct kvm_pit *pit)
 {
 	atomic_set(&pit->pit_state.pending, 0);
-	atomic_set(&pit->pit_state.irq_ack, 1);
 }
 
 void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject)
@@ -298,10 +282,8 @@ void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject)
 	if (reinject) {
 		/* The initial state is preserved while ps->reinject == 0. */
 		kvm_pit_reset_reinject(pit);
-		kvm_register_irq_ack_notifier(kvm, &ps->irq_ack_notifier);
 		kvm_register_irq_mask_notifier(kvm, 0, &pit->mask_notifier);
 	} else {
-		kvm_unregister_irq_ack_notifier(kvm, &ps->irq_ack_notifier);
 		kvm_unregister_irq_mask_notifier(kvm, 0, &pit->mask_notifier);
 	}
 
@@ -679,8 +661,6 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
 	hrtimer_init(&pit_state->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
 	pit_state->timer.function = pit_timer_fn;
 
-	pit_state->irq_ack_notifier.gsi = 0;
-	pit_state->irq_ack_notifier.irq_acked = kvm_pit_ack_irq;
 	pit->mask_notifier.func = pit_mask_notifer;
 
 	kvm_pit_reset(pit);
diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h
index 394d9527da7e..4a9cfe00306f 100644
--- a/arch/x86/kvm/i8254.h
+++ b/arch/x86/kvm/i8254.h
@@ -34,8 +34,6 @@ struct kvm_kpit_state {
 	struct mutex lock;
 	atomic_t reinject;
 	atomic_t pending; /* accumulated triggered timers */
-	atomic_t irq_ack;
-	struct kvm_irq_ack_notifier irq_ack_notifier;
 };
 
 struct kvm_pit {
-- 
2.17.1

  parent reply	other threads:[~2019-02-04 14:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 14:41 [RFC PATCH 0/8] KVM: x86: svm: Enabling AVIC with in kernel irqchip Suthikulpanit, Suravee
2019-02-04 14:41 ` [RFC PATCH 1/8] svm: Fix improper check when deactivate AVIC Suthikulpanit, Suravee
2019-02-04 14:42 ` [RFC PATCH 2/8] KVM: x86: Add interface for run-time activate/de-activate APIC virtualization Suthikulpanit, Suravee
2019-02-04 14:42 ` [RFC PATCH 3/8] KVM: x86: Add callback functions for handling APIC ID, DFR and LDR update Suthikulpanit, Suravee
2019-02-04 14:42 ` [RFC PATCH 4/8] svm: Add AMD AVIC handlers for " Suthikulpanit, Suravee
2019-02-04 14:42 ` [RFC PATCH 5/8] svm: Add support for APIC_ACCESS_PAGE_PRIVATE_MEMSLOT setup/destroy Suthikulpanit, Suravee
2019-02-04 14:42 ` [RFC PATCH 6/8] svm: Temporary deactivate AVIC during ExtINT handling Suthikulpanit, Suravee
2019-02-04 14:42 ` Suthikulpanit, Suravee [this message]
2019-02-06 10:29   ` [RFC PATCH 7/8] KVM: i8254: Remove need for irq ack notifier Paolo Bonzini
2019-02-06 12:53     ` Julian Stecklina
2019-02-04 14:42 ` [RFC PATCH 8/8] svm: Allow AVIC with in-kernel irqchip mode Suthikulpanit, Suravee
2019-02-05 18:34   ` Alex Williamson
2019-02-06 11:20     ` Suthikulpanit, Suravee
2019-06-15 14:28       ` Maxim Levitsky
2019-06-18 14:34         ` Suthikulpanit, Suravee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190204144128.9489-8-suravee.suthikulpanit@amd.com \
    --to=suravee.suthikulpanit@amd.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=joro@8bytes.org \
    --cc=jsteckli@amazon.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=sironi@amazon.de \
    --cc=tglx@linutronix.de \
    --cc=wawei@amazon.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).