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 09/12] kvm tools: Fixes for ioeventfd module
Date: Mon, 19 Dec 2011 15:58:31 +0200	[thread overview]
Message-ID: <1324303114-5948-10-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/pci.h |    5 ++-
 tools/kvm/pci.c             |   58 +++++++++++++++++++++++++++++++------------
 3 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 2be3949..2950ea8 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -988,7 +988,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 		goto fail;
 	}
 
-	pci__init();
+	r = pci__init(kvm);
+	if (r < 0) {
+		pr_error("pci__init() failed with error %d\n", r);
+		goto fail;
+	}
 
 	r = ioport__init(kvm);
 	if (r < 0) {
@@ -1239,6 +1243,10 @@ static void kvm_cmd_run_uninit(int guest_ret)
 	if (r < 0)
 		pr_warning("ioeventfd__uninit() failed with error %d\n", r);
 
+	r = pci__uninit(kvm);
+	if (r < 0)
+		pr_warning("pci__uninit() failed with error %d\n", r);
+
 	kvm__delete(kvm);
 
 	if (guest_ret == 0)
diff --git a/tools/kvm/include/kvm/pci.h b/tools/kvm/include/kvm/pci.h
index 07b5403..f5536c7 100644
--- a/tools/kvm/include/kvm/pci.h
+++ b/tools/kvm/include/kvm/pci.h
@@ -84,8 +84,9 @@ struct pci_device_header {
 	u32		bar_size[6];
 } __attribute__((packed));
 
-void pci__init(void);
-void pci__register(struct pci_device_header *dev, u8 dev_num);
+int pci__init(struct kvm *kvm);
+int pci__uninit(struct kvm *kvm);
+int pci__register(struct pci_device_header *dev, u8 dev_num);
 struct pci_device_header *pci__find_dev(u8 dev_num);
 u32 pci_get_io_space_block(u32 size);
 void pci__config_wr(struct kvm *kvm, union pci_config_address addr, void *data, int size);
diff --git a/tools/kvm/pci.c b/tools/kvm/pci.c
index 06eea0f..3696619 100644
--- a/tools/kvm/pci.c
+++ b/tools/kvm/pci.c
@@ -3,6 +3,7 @@
 #include "kvm/util.h"
 #include "kvm/kvm.h"
 
+#include <linux/err.h>
 #include <assert.h>
 
 #define PCI_BAR_OFFSET(b)		(offsetof(struct pci_device_header, bar[b]))
@@ -31,8 +32,8 @@ static void *pci_config_address_ptr(u16 port)
 	unsigned long offset;
 	void *base;
 
-	offset		= port - PCI_CONFIG_ADDRESS;
-	base		= &pci_config_address;
+	offset	= port - PCI_CONFIG_ADDRESS;
+	base	= &pci_config_address;
 
 	return base + offset;
 }
@@ -56,8 +57,8 @@ static bool pci_config_address_in(struct ioport *ioport, struct kvm *kvm, u16 po
 }
 
 static struct ioport_operations pci_config_address_ops = {
-	.io_in		= pci_config_address_in,
-	.io_out		= pci_config_address_out,
+	.io_in	= pci_config_address_in,
+	.io_out	= pci_config_address_out,
 };
 
 static bool pci_device_exists(u8 bus_number, u8 device_number, u8 function_number)
@@ -73,7 +74,7 @@ static bool pci_device_exists(u8 bus_number, u8 device_number, u8 function_numbe
 	if (device_number >= PCI_MAX_DEVICES)
 		return false;
 
-	dev		= pci_devices[device_number];
+	dev = pci_devices[device_number];
 
 	return dev != NULL;
 }
@@ -105,15 +106,15 @@ static bool pci_config_data_in(struct ioport *ioport, struct kvm *kvm, u16 port,
 }
 
 static struct ioport_operations pci_config_data_ops = {
-	.io_in		= pci_config_data_in,
-	.io_out		= pci_config_data_out,
+	.io_in	= pci_config_data_in,
+	.io_out	= pci_config_data_out,
 };
 
 void pci__config_wr(struct kvm *kvm, union pci_config_address addr, void *data, int size)
 {
 	u8 dev_num;
 
-	dev_num		= addr.device_number;
+	dev_num	= addr.device_number;
 
 	if (pci_device_exists(0, dev_num, 0)) {
 		unsigned long offset;
@@ -150,7 +151,7 @@ void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data,
 {
 	u8 dev_num;
 
-	dev_num		= addr.device_number;
+	dev_num	= addr.device_number;
 
 	if (pci_device_exists(0, dev_num, 0)) {
 		unsigned long offset;
@@ -168,20 +169,45 @@ void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data,
 	}
 }
 
-void pci__register(struct pci_device_header *dev, u8 dev_num)
+int pci__register(struct pci_device_header *dev, u8 dev_num)
 {
-	assert(dev_num < PCI_MAX_DEVICES);
-	pci_devices[dev_num]	= dev;
+	if (dev_num >= PCI_MAX_DEVICES)
+		return -ENOSPC;
+
+	pci_devices[dev_num] = dev;
+
+	return 0;
 }
 
 struct pci_device_header *pci__find_dev(u8 dev_num)
 {
-	assert(dev_num < PCI_MAX_DEVICES);
+	if (dev_num >= PCI_MAX_DEVICES)
+		return ERR_PTR(-EOVERFLOW);
+
 	return pci_devices[dev_num];
 }
 
-void pci__init(void)
+int pci__init(struct kvm *kvm)
 {
-	ioport__register(PCI_CONFIG_DATA + 0, &pci_config_data_ops, 4, NULL);
-	ioport__register(PCI_CONFIG_ADDRESS + 0, &pci_config_address_ops, 4, NULL);
+	int r;
+
+	r = ioport__register(PCI_CONFIG_DATA + 0, &pci_config_data_ops, 4, NULL);
+	if (r < 0)
+		return r;
+
+	r = ioport__register(PCI_CONFIG_ADDRESS + 0, &pci_config_address_ops, 4, NULL);
+	if (r < 0) {
+		ioport__unregister(PCI_CONFIG_DATA);
+		return r;
+	}
+
+	return 0;
+}
+
+int pci__uninit(struct kvm *kvm)
+{
+	ioport__unregister(PCI_CONFIG_DATA);
+	ioport__unregister(PCI_CONFIG_ADDRESS);
+
+	return 0;
 }
-- 
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 ` [RFC 03/12] kvm tools: Fixes for IRQ module Sasha Levin
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 ` Sasha Levin [this message]
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-10-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.