From: Gregory Haskins <ghaskins@novell.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, avi@redhat.com
Subject: [KVM PATCH v2 3/4] kvm: add io_bus unregister function
Date: Fri, 15 May 2009 12:28:18 -0400 [thread overview]
Message-ID: <20090515162818.26209.82481.stgit@dev.haskins.net> (raw)
In-Reply-To: <20090515162047.26209.93545.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 94c1a11..214089f 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 60ba0cf..5f5e443 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2433,16 +2433,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);
}
}
@@ -2451,10 +2453,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;
}
@@ -2463,12 +2465,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-15 16:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-15 16:28 [KVM PATCH v2 0/4] iosignalfd Gregory Haskins
2009-05-15 16:28 ` [KVM PATCH v2 1/4] eventfd: export eventfd interfaces for module use Gregory Haskins
2009-05-15 16:28 ` [KVM PATCH v2 2/4] kvm: add return value to kvm_io_bus_register_dev Gregory Haskins
2009-05-17 20:10 ` Avi Kivity
2009-05-18 2:31 ` Gregory Haskins
2009-05-15 16:28 ` Gregory Haskins [this message]
2009-05-15 16:28 ` [KVM PATCH v2 4/4] kvm: add iosignalfd support Gregory Haskins
2009-05-17 20:15 ` Avi Kivity
2009-05-18 2:37 ` Gregory Haskins
2009-05-15 16:35 ` [KVM PATCH v2 0/4] iosignalfd 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=20090515162818.26209.82481.stgit@dev.haskins.net \
--to=ghaskins@novell.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.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.