From: Gregory Haskins <ghaskins@novell.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, avi@redhat.com, mtosatti@redhat.com
Subject: [KVM PATCH v3 3/4] kvm: add io_bus unregister function
Date: Thu, 21 May 2009 12:51:24 -0400 [thread overview]
Message-ID: <20090521165124.14851.53719.stgit@dev.haskins.net> (raw)
In-Reply-To: <20090521165059.14851.83681.stgit@dev.haskins.net>
We want to support the notion of dynamic MMIO/PIO registrations and
therefore will need to support both register as well as unregister.
However, the current io_bus code is structured as a linear array and
is not conducive to unregistering, so refactor to allow "holes" in the
array. We then enhance the API with an unregister function.
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---
include/linux/kvm_host.h | 4 +++-
virt/kvm/kvm_main.c | 48 ++++++++++++++++++++++++++++++++++++++--------
2 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 5289552..7dcae4b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -52,7 +52,7 @@ extern struct kmem_cache *kvm_vcpu_cache;
* in one place.
*/
struct kvm_io_bus {
- int dev_count;
+ spinlock_t lock;
#define NR_IOBUS_DEVS 6
struct kvm_io_device *devs[NR_IOBUS_DEVS];
};
@@ -63,6 +63,8 @@ struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus,
gpa_t addr, int len, int is_write);
int kvm_io_bus_register_dev(struct kvm_io_bus *bus,
struct kvm_io_device *dev);
+int kvm_io_bus_unregister_dev(struct kvm_io_bus *bus,
+ struct kvm_io_device *dev);
struct kvm_vcpu {
struct kvm *kvm;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c71f276..4c36ac8 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2435,16 +2435,18 @@ static struct notifier_block kvm_reboot_notifier = {
void kvm_io_bus_init(struct kvm_io_bus *bus)
{
memset(bus, 0, sizeof(*bus));
+ spin_lock_init(&bus->lock);
}
void kvm_io_bus_destroy(struct kvm_io_bus *bus)
{
int i;
- for (i = 0; i < bus->dev_count; i++) {
+ for (i = 0; i < NR_IOBUS_DEVS; i++) {
struct kvm_io_device *pos = bus->devs[i];
- kvm_iodevice_destructor(pos);
+ if (pos)
+ kvm_iodevice_destructor(pos);
}
}
@@ -2453,10 +2455,10 @@ struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus,
{
int i;
- for (i = 0; i < bus->dev_count; i++) {
+ for (i = 0; i < NR_IOBUS_DEVS; i++) {
struct kvm_io_device *pos = bus->devs[i];
- if (pos->in_range(pos, addr, len, is_write))
+ if (pos && pos->in_range(pos, addr, len, is_write))
return pos;
}
@@ -2465,12 +2467,42 @@ struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus,
int kvm_io_bus_register_dev(struct kvm_io_bus *bus, struct kvm_io_device *dev)
{
- if (bus->dev_count > (NR_IOBUS_DEVS-1))
- return -ENOSPC;
+ int i;
- bus->devs[bus->dev_count++] = dev;
+ spin_lock(&bus->lock);
- return 0;
+ for (i = 0; i < NR_IOBUS_DEVS; i++) {
+ if (bus->devs[i])
+ continue;
+
+ bus->devs[i] = dev;
+ spin_unlock(&bus->lock);
+ return 0;
+ }
+
+ spin_unlock(&bus->lock);
+
+ return -ENOSPC;
+}
+
+int kvm_io_bus_unregister_dev(struct kvm_io_bus *bus, struct kvm_io_device *dev)
+{
+ int i;
+
+ spin_lock(&bus->lock);
+
+ for (i = 0; i < NR_IOBUS_DEVS; i++) {
+
+ if (bus->devs[i] == dev) {
+ bus->devs[i] = NULL;
+ spin_unlock(&bus->lock);
+ return 0;
+ }
+ }
+
+ spin_unlock(&bus->lock);
+
+ return -ENOENT;
}
static struct notifier_block kvm_cpu_notifier = {
next prev parent reply other threads:[~2009-05-21 16:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-21 16:51 [KVM PATCH v3 0/4] iosignalfd Gregory Haskins
2009-05-21 16:51 ` [KVM PATCH v3 1/4] eventfd: export eventfd interfaces for module use Gregory Haskins
2009-05-21 16:51 ` [KVM PATCH v3 2/4] kvm: add return value to kvm_io_bus_register_dev Gregory Haskins
2009-05-26 15:23 ` Gregory Haskins
2009-05-21 16:51 ` Gregory Haskins [this message]
2009-05-21 16:51 ` [KVM PATCH v3 4/4] kvm: add iosignalfd support Gregory Haskins
2009-05-22 22:05 ` Marcelo Tosatti
2009-05-23 4:57 ` Gregory Haskins
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=20090521165124.14851.53719.stgit@dev.haskins.net \
--to=ghaskins@novell.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@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;
as well as URLs for NNTP newsgroup(s).