public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Avi Kivity <avi@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	kvm@vger.kernel.org, Alex Williamson <alex.williamson@redhat.com>,
	gleb@redhat.com
Subject: [PATCH RFC untested] kvm_set_irq: report coalesced for clear
Date: Thu, 19 Jul 2012 01:11:53 +0300	[thread overview]
Message-ID: <20120718221152.GA14049@redhat.com> (raw)

This creates a way to detect when kvm_set_irq(...,0) was run
twice with the same source id by returning 0 in this case.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

This is on top of my bugfix patch.  Uncompiled and untested.  Alex, I
think something like this patch will make it possible for you to simply
do
	if (kvm_set_irq(...., 0))
		eventfd_signal()

without need for further tricks.

 arch/x86/include/asm/kvm_host.h |  9 ++++-----
 arch/x86/kvm/i8259.c            | 11 +++++++----
 virt/kvm/ioapic.c               | 17 ++++++++++-------
 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index fe6e9f1..6f5ed0a 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -802,16 +802,15 @@ int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
 void kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault);
 bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl);
 
-static inline int kvm_irq_line_state(unsigned long *irq_state,
+/* Tweak line state. Return true if state was changed. */
+static inline bool kvm_irq_line_state(unsigned long *irq_state,
 				     int irq_source_id, int level)
 {
 	/* Logical OR for level trig interrupt */
 	if (level)
-		__set_bit(irq_source_id, irq_state);
+		return !__test_and_set_bit(irq_source_id, irq_state);
 	else
-		__clear_bit(irq_source_id, irq_state);
-
-	return !!(*irq_state);
+		return __test_and_clear_bit(irq_source_id, irq_state);
 }
 
 int kvm_pic_set_irq(struct kvm_pic *pic, int irq, int irq_source_id, int level);
diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index 95b504b..44e3635 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -190,12 +190,15 @@ void kvm_pic_update_irq(struct kvm_pic *s)
 
 int kvm_pic_set_irq(struct kvm_pic *s, int irq, int src_id, int l)
 {
-	int ret = -1;
-	int level;
+	int ret, level;
 
 	pic_lock(s);
-	if (irq >= 0 && irq < PIC_NUM_PINS) {
-		level = kvm_irq_line_state(&s->irq_states[irq], src_id, l);
+	if (irq < 0 || irq >= PIC_NUM_PINS) {
+		ret = -1;
+	} else if (!kvm_irq_line_state(&s->irq_states[irq], src_id, l)) {
+		ret = 0;
+	} else {
+		level = !!s->irq_states[irq];
 		ret = pic_set_irq1(&s->pics[irq >> 3], irq & 7, level);
 		pic_update_irq(s);
 		trace_kvm_pic_set_irq(irq >> 3, irq & 7, s->pics[irq >> 3].elcr,
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
index 268b332..edc9445 100644
--- a/virt/kvm/ioapic.c
+++ b/virt/kvm/ioapic.c
@@ -196,18 +196,21 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int src_id, int l)
 	u32 old_irr;
 	u32 mask = 1 << irq;
 	union kvm_ioapic_redirect_entry entry;
-	int ret = 1;
-	int level;
+	int ret, level;
 
 	spin_lock(&ioapic->lock);
 	old_irr = ioapic->irr;
-	if (irq >= 0 && irq < IOAPIC_NUM_PINS) {
+	if (irq < 0 || irq >= IOAPIC_NUM_PINS) {
+		ret = -1;
+	} else if (!kvm_irq_line_state(&ioapic->irq_states[irq], src_id, l)) {
+		ret = 0;
+	} else {
 		entry = ioapic->redirtbl[irq];
-		level = kvm_irq_line_state(&ioapic->irq_states[irq], src_id, l);
-		level ^= entry.fields.polarity;
-		if (!level)
+		level = (!!ioapic->irq_states[irq]) ^ entry.fields.polarity;
+		if (!level) {
 			ioapic->irr &= ~mask;
-		else {
+			ret = 1;
+		} else {
 			int edge = (entry.fields.trig_mode == IOAPIC_EDGE_TRIG);
 			ioapic->irr |= mask;
 			if ((edge && old_irr != ioapic->irr) ||
-- 
MST

             reply	other threads:[~2012-07-18 22:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-18 22:11 Michael S. Tsirkin [this message]
2012-07-18 22:40 ` [PATCH RFC untested] kvm_set_irq: report coalesced for clear Alex Williamson
2012-07-18 22:51   ` Michael S. Tsirkin
2012-07-19  7:53 ` Gleb Natapov
2012-07-19  9:17   ` Michael S. Tsirkin
2012-07-19  9:21     ` Gleb Natapov
2012-07-19  9:33       ` Michael S. Tsirkin
2012-07-19  9:41         ` Gleb Natapov
2012-07-19 10:26           ` Michael S. Tsirkin
2012-07-19 10:54             ` Gleb Natapov
2012-07-19 11:12               ` Michael S. Tsirkin
2012-07-19 11:18                 ` Michael S. Tsirkin
2012-07-19 11:25                 ` Gleb Natapov
2012-07-19 11:57                   ` Michael S. Tsirkin
2012-07-19 16:38                     ` Alex Williamson
2012-07-19 16:51                       ` Michael S. Tsirkin

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=20120718221152.GA14049@redhat.com \
    --to=mst@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /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