[PATCH 6/6] kvm tools: Protect IOPORT tree by rwsem

2011-05-26 Thread Sasha Levin
Makes ioport thread-safe.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/ioport.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c
index 1f13960..db9ff0f 100644
--- a/tools/kvm/ioport.c
+++ b/tools/kvm/ioport.c
@@ -3,6 +3,7 @@
 #include kvm/kvm.h
 #include kvm/util.h
 #include kvm/rbtree-interval.h
+#include kvm/rwsem.h
 
 #include linux/kvm.h /* for KVM_EXIT_* */
 #include linux/types.h
@@ -22,6 +23,7 @@ struct ioport_entry {
 
 static struct rb_root ioport_tree = RB_ROOT;
 bool ioport_debug;
+static DECLARE_RWSEM(ioport_tree_sem);
 
 static struct ioport_entry *ioport_search(struct rb_root *root, u64 addr)
 {
@@ -71,6 +73,7 @@ void ioport__register(u16 port, struct ioport_operations 
*ops, int count)
 {
struct ioport_entry *entry;
 
+   down_write(ioport_tree_sem);
entry = ioport_search(ioport_tree, port);
if (entry) {
pr_warning(ioport re-registered: %x, port);
@@ -87,6 +90,8 @@ void ioport__register(u16 port, struct ioport_operations 
*ops, int count)
};
 
ioport_insert(ioport_tree, entry);
+
+   up_write(ioport_tree_sem);
 }
 
 static const char *to_direction(int direction)
@@ -108,7 +113,9 @@ bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, 
int direction, int s
bool ret;
struct ioport_entry *entry;
 
+   down_read(ioport_tree_sem);
entry = ioport_search(ioport_tree, port);
+   up_read(ioport_tree_sem);
if (!entry)
goto error;
 
-- 
1.7.5.rc3

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 6/6] kvm tools: Protect IOPORT tree by rwsem

2011-05-26 Thread Pekka Enberg

On Thu, 26 May 2011, Sasha Levin wrote:

Makes ioport thread-safe.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
tools/kvm/ioport.c |7 +++
1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c
index 1f13960..db9ff0f 100644
--- a/tools/kvm/ioport.c
+++ b/tools/kvm/ioport.c
@@ -3,6 +3,7 @@
#include kvm/kvm.h
#include kvm/util.h
#include kvm/rbtree-interval.h
+#include kvm/rwsem.h

#include linux/kvm.h/* for KVM_EXIT_* */
#include linux/types.h
@@ -22,6 +23,7 @@ struct ioport_entry {

static struct rb_root ioport_tree = RB_ROOT;
bool ioport_debug;
+static DECLARE_RWSEM(ioport_tree_sem);


Why do we need a new lock here? Can't we reuse the new ioport_mutex?

Pekka
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 6/6] kvm tools: Protect IOPORT tree by rwsem

2011-05-26 Thread Sasha Levin
On Thu, 2011-05-26 at 19:01 +0300, Pekka Enberg wrote:
 On Thu, 26 May 2011, Sasha Levin wrote:
  Makes ioport thread-safe.
 
  Signed-off-by: Sasha Levin levinsasha...@gmail.com
  ---
  tools/kvm/ioport.c |7 +++
  1 files changed, 7 insertions(+), 0 deletions(-)
 
  diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c
  index 1f13960..db9ff0f 100644
  --- a/tools/kvm/ioport.c
  +++ b/tools/kvm/ioport.c
  @@ -3,6 +3,7 @@
  #include kvm/kvm.h
  #include kvm/util.h
  #include kvm/rbtree-interval.h
  +#include kvm/rwsem.h
 
  #include linux/kvm.h  /* for KVM_EXIT_* */
  #include linux/types.h
  @@ -22,6 +23,7 @@ struct ioport_entry {
 
  static struct rb_root ioport_tree = RB_ROOT;
  bool ioport_debug;
  +static DECLARE_RWSEM(ioport_tree_sem);
 
 Why do we need a new lock here? Can't we reuse the new ioport_mutex?

ioport_mutex is used for allocations of ioports to devices, this lock is
intended to protect the ioport tree from being read while new devices
are added.

-- 

Sasha.

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html