All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, Sheng Yang <sheng@linux.intel.com>,
	Mark McLoughlin <markmc@redhat.com>
Subject: [PATCH 3/4] KVM: gracefully handle zero in kvm_free_irq_source_id()
Date: Fri, 28 Nov 2008 10:26:10 +0000	[thread overview]
Message-ID: <1227867971-1716-3-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1227867971-1716-2-git-send-email-markmc@redhat.com>

Allow kvm_free_irq_source_id() to be called with a zero ID.

Zero is reserved for KVM_USERSPACE_IRQ_SOURCE_ID, so we can
guarantee that kvm_request_irq_source_id() will never return
zero and use zero to indicate "no source ID allocated".

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 virt/kvm/irq_comm.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index db75045..869f5e8 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -72,11 +72,15 @@ int kvm_request_irq_source_id(struct kvm *kvm)
 	unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;
 	int irq_source_id = find_first_zero_bit(bitmap,
 				sizeof(kvm->arch.irq_sources_bitmap));
+
 	if (irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) {
 		printk(KERN_WARNING "kvm: exhaust allocatable IRQ sources!\n");
-		irq_source_id = -EFAULT;
-	} else
-		set_bit(irq_source_id, bitmap);
+		return -EFAULT;
+	}
+
+	ASSERT(irq_source_id != 0); /* KVM_USERSPACE_IRQ_SOURCE_ID reserved */
+	set_bit(irq_source_id, bitmap);
+
 	return irq_source_id;
 }
 
@@ -84,7 +88,9 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
 {
 	int i;
 
-	if (irq_source_id <= 0 ||
+	if (!irq_source_id)
+		return;
+	if (irq_source_id < 0 ||
 	    irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) {
 		printk(KERN_ERR "kvm: IRQ source ID out of range!\n");
 		return;
-- 
1.5.4.3


  reply	other threads:[~2008-11-28 10:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-20  8:07 [PATCH 1/1] KVM: IRQ ACK notifier should be used with in-kernel irqchip Sheng Yang
2008-10-22 10:26 ` Avi Kivity
2008-11-28 10:25 ` Mark McLoughlin
2008-11-28 10:26   ` [PATCH 1/4] KVM: remove the IRQ ACK notifier assertions Mark McLoughlin
2008-11-28 10:26     ` [PATCH 2/4] KVM: make kvm_unregister_irq_ack_notifier() safe Mark McLoughlin
2008-11-28 10:26       ` Mark McLoughlin [this message]
2008-11-28 10:26         ` [PATCH 4/4] KVM: split out kvm_free_assigned_irq() Mark McLoughlin
2008-11-30 10:28         ` [PATCH 3/4] KVM: gracefully handle zero in kvm_free_irq_source_id() Avi Kivity
2008-12-01 13:56           ` Mark McLoughlin
2008-12-01 13:57             ` [PATCH 1/5] KVM: remove the IRQ ACK notifier assertions Mark McLoughlin
2008-12-01 13:57               ` [PATCH 2/5] KVM: make kvm_unregister_irq_ack_notifier() safe Mark McLoughlin
2008-12-01 13:57                 ` [PATCH 3/5] KVM: don't fee an unallocated irq source id Mark McLoughlin
2008-12-01 13:57                   ` [PATCH 4/5] KVM: add KVM_USERSPACE_IRQ_SOURCE_ID assertions Mark McLoughlin
2008-12-01 13:57                     ` [PATCH 5/5] KVM: split out kvm_free_assigned_irq() Mark McLoughlin
2008-12-02 12:41                     ` [PATCH 4/5] KVM: add KVM_USERSPACE_IRQ_SOURCE_ID assertions Avi Kivity
2008-12-02 12:39               ` [PATCH 1/5] KVM: remove the IRQ ACK notifier assertions Avi Kivity
2008-12-01  2:31   ` [PATCH 1/1] KVM: IRQ ACK notifier should be used with in-kernel irqchip Sheng Yang

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=1227867971-1716-3-git-send-email-markmc@redhat.com \
    --to=markmc@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=sheng@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.