All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: mingo@elte.hu, gorcunov@gmail.com, asias.hejun@gmail.com,
	kvm@vger.kernel.org, Sasha Levin <levinsasha928@gmail.com>
Subject: [RFC 03/12] kvm tools: Fixes for IRQ module
Date: Mon, 19 Dec 2011 15:58:25 +0200	[thread overview]
Message-ID: <1324303114-5948-4-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1324303114-5948-1-git-send-email-levinsasha928@gmail.com>

Fixes include:
 - Error handling
 - Cleanup
 - Standard init/uninit

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-run.c     |   10 +++++++++-
 tools/kvm/include/kvm/irq.h |    3 ++-
 tools/kvm/x86/irq.c         |   35 ++++++++++++++++++++++++-----------
 3 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 3d046d7..e40d90b 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -977,7 +977,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 	if (!kvm_cpus)
 		die("Couldn't allocate array for %d CPUs", nrcpus);
 
-	irq__init(kvm);
+	r = irq__init(kvm);
+	if (r < 0) {
+		pr_error("irq__init() failed with error %d\n", r);
+		goto fail;
+	}
 
 	pci__init();
 
@@ -1174,6 +1178,10 @@ static void kvm_cmd_run_uninit(int guest_ret)
 	if (r < 0)
 		pr_warning("symbol__uninit() failed with error %d\n", r);
 
+	r = irq__uninit(kvm);
+	if (r < 0)
+		pr_warning("irq__uninit() failed with error %d\n", r);
+
 	fb__stop();
 
 	virtio_blk__delete_all(kvm);
diff --git a/tools/kvm/include/kvm/irq.h b/tools/kvm/include/kvm/irq.h
index 61f593d..755d7fe 100644
--- a/tools/kvm/include/kvm/irq.h
+++ b/tools/kvm/include/kvm/irq.h
@@ -25,7 +25,8 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line);
 
 struct rb_node *irq__get_pci_tree(void);
 
-void irq__init(struct kvm *kvm);
+int irq__init(struct kvm *kvm);
+int irq__uninit(struct kvm *kvm);
 int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg);
 
 #endif
diff --git a/tools/kvm/x86/irq.c b/tools/kvm/x86/irq.c
index b8a7257..3683cb4 100644
--- a/tools/kvm/x86/irq.c
+++ b/tools/kvm/x86/irq.c
@@ -76,19 +76,20 @@ static int insert(struct rb_root *root, struct pci_dev *data)
 		else if (result > 0)
 			new = &((*new)->rb_right);
 		else
-			return 0;
+			return -EEXIST;
 	}
 
 	/* Add new node and rebalance tree. */
 	rb_link_node(&data->node, parent, new);
 	rb_insert_color(&data->node, root);
 
-	return 1;
+	return 0;
 }
 
 int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 {
 	struct pci_dev *node;
+	int r;
 
 	node = search(&pci_tree, dev);
 
@@ -96,7 +97,7 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 		/* We haven't found a node - First device of it's kind */
 		node = malloc(sizeof(*node));
 		if (node == NULL)
-			return -1;
+			return -ENOMEM;
 
 		*node = (struct pci_dev) {
 			.id	= dev,
@@ -111,9 +112,10 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 
 		INIT_LIST_HEAD(&node->lines);
 
-		if (insert(&pci_tree, node) != 1) {
+		r = insert(&pci_tree, node);
+		if (r) {
 			free(node);
-			return -1;
+			return r;
 		}
 	}
 
@@ -121,7 +123,7 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 		/* This device already has a pin assigned, give out a new line and device id */
 		struct irq_line *new = malloc(sizeof(*new));
 		if (new == NULL)
-			return -1;
+			return -ENOMEM;
 
 		new->line	= next_line++;
 		*line		= new->line;
@@ -133,17 +135,17 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 		return 0;
 	}
 
-	return -1;
+	return -EFAULT;
 }
 
-void irq__init(struct kvm *kvm)
+int irq__init(struct kvm *kvm)
 {
 	int i, r;
 
 	irq_routing = calloc(sizeof(struct kvm_irq_routing) +
 			IRQ_MAX_GSI * sizeof(struct kvm_irq_routing_entry), 1);
 	if (irq_routing == NULL)
-		die("Failed allocating space for GSI table");
+		return -ENOMEM;
 
 	/* Hook first 8 GSIs to master IRQCHIP */
 	for (i = 0; i < 8; i++)
@@ -163,8 +165,19 @@ void irq__init(struct kvm *kvm)
 	}
 
 	r = ioctl(kvm->vm_fd, KVM_SET_GSI_ROUTING, irq_routing);
-	if (r)
-		die("Failed setting GSI routes");
+	if (r) {
+		free(irq_routing);
+		return errno;
+	}
+
+	return 0;
+}
+
+int irq__uninit(struct kvm *kvm)
+{
+	free(irq_routing);
+
+	return 0;
 }
 
 int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
-- 
1.7.8


  parent reply	other threads:[~2011-12-19 13:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-19 13:58 [RFC 00/12] Overhaul of error handling and module init/uninit Sasha Levin
2011-12-19 13:58 ` [RFC 01/12] kvm tools: Split kvm_cmd_run into init, work and uninit Sasha Levin
2011-12-19 21:26   ` Pekka Enberg
2011-12-20 10:09     ` Sasha Levin
2011-12-20  8:55       ` Asias He
2011-12-19 13:58 ` [RFC 02/12] kvm tools: Fixes for symbol resolving module Sasha Levin
2011-12-19 13:58 ` Sasha Levin [this message]
2011-12-19 13:58 ` [RFC 04/12] kvm tools: Fixes for UI modules Sasha Levin
2011-12-19 13:58 ` [RFC 05/12] kvm tools: Fixes for ioport module Sasha Levin
2011-12-19 13:58 ` [RFC 06/12] kvm tools: Fixes for ioeventfd module Sasha Levin
2011-12-19 13:58 ` [RFC 07/12] kvm tools: Fixes for serial module Sasha Levin
2011-12-19 13:58 ` [RFC 08/12] kvm tools: Fixes for mptable module Sasha Levin
2011-12-19 13:58 ` [RFC 09/12] kvm tools: Fixes for ioeventfd module Sasha Levin
2011-12-19 13:58 ` [RFC 10/12] kvm tools: Fixes for disk image module Sasha Levin
2011-12-19 13:58 ` [RFC 11/12] kvm tools: Fixes for rtc module Sasha Levin
2011-12-19 13:58 ` [RFC 12/12] kvm tools: Fixes for ioeventfd module Sasha Levin
2011-12-19 21:29 ` [RFC 00/12] Overhaul of error handling and module init/uninit Pekka Enberg

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=1324303114-5948-4-git-send-email-levinsasha928@gmail.com \
    --to=levinsasha928@gmail.com \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=penberg@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 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.