]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Use brlock in MMIO and IOPORT
authorSasha Levin <levinsasha928@gmail.com>
Mon, 30 May 2011 17:27:58 +0000 (20:27 +0300)
committerPekka Enberg <penberg@kernel.org>
Thu, 2 Jun 2011 08:38:14 +0000 (11:38 +0300)
Use brlock to protect mmio and ioport modules and make them
update-safe.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/ioport.c
tools/kvm/mmio.c

index d0a1aa8655f7eebb58afaefbc7983688b3b1110d..e00fb59ed1519d88072eb3ce7b6758d26cd64629 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "kvm/kvm.h"
 #include "kvm/util.h"
-
+#include "kvm/brlock.h"
 #include "kvm/rbtree-interval.h"
 #include "kvm/mutex.h"
 
@@ -84,6 +84,7 @@ u16 ioport__register(u16 port, struct ioport_operations *ops, int count, void *p
 {
        struct ioport *entry;
 
+       br_write_lock();
        if (port == IOPORT_EMPTY)
                port = ioport__find_free_port();
 
@@ -105,6 +106,8 @@ u16 ioport__register(u16 port, struct ioport_operations *ops, int count, void *p
 
        ioport_insert(&ioport_tree, entry);
 
+       br_write_unlock();
+
        return port;
 }
 
@@ -127,6 +130,7 @@ bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int s
        bool ret = false;
        struct ioport *entry;
 
+       br_read_lock();
        entry = ioport_search(&ioport_tree, port);
        if (!entry)
                goto error;
@@ -141,11 +145,15 @@ bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int s
                        ret = ops->io_out(entry, kvm, port, data, size, count);
        }
 
+       br_read_unlock();
+
        if (!ret)
                goto error;
 
        return true;
 error:
+       br_read_unlock();
+
        if (ioport_debug)
                ioport_error(port, data, direction, size, count);
 
index ef986bf57d03e5f92c15828c6cc2a3c055b14394..acd091ead6aea19769d2bc2d6cc7e55c8337ad60 100644 (file)
@@ -1,5 +1,6 @@
 #include "kvm/kvm.h"
 #include "kvm/rbtree-interval.h"
+#include "kvm/brlock.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -55,6 +56,7 @@ static const char *to_direction(u8 is_write)
 bool kvm__register_mmio(u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write))
 {
        struct mmio_mapping *mmio;
+       int ret;
 
        mmio = malloc(sizeof(*mmio));
        if (mmio == NULL)
@@ -65,31 +67,44 @@ bool kvm__register_mmio(u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callba
                .kvm_mmio_callback_fn = kvm_mmio_callback_fn,
        };
 
-       return mmio_insert(&mmio_tree, mmio);
+       br_write_lock();
+       ret = mmio_insert(&mmio_tree, mmio);
+       br_write_unlock();
+
+       return ret;
 }
 
 bool kvm__deregister_mmio(u64 phys_addr)
 {
        struct mmio_mapping *mmio;
 
+       br_write_lock();
        mmio = mmio_search_single(&mmio_tree, phys_addr);
-       if (mmio == NULL)
+       if (mmio == NULL) {
+               br_write_unlock();
                return false;
+       }
 
        rb_int_erase(&mmio_tree, &mmio->node);
+       br_write_unlock();
+
        free(mmio);
        return true;
 }
 
 bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write)
 {
-       struct mmio_mapping *mmio = mmio_search(&mmio_tree, phys_addr, len);
+       struct mmio_mapping *mmio;
+
+       br_read_lock();
+       mmio = mmio_search(&mmio_tree, phys_addr, len);
 
        if (mmio)
                mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write);
        else
                fprintf(stderr, "Warning: Ignoring MMIO %s at %016llx (length %u)\n",
                        to_direction(is_write), phys_addr, len);
+       br_read_unlock();
 
        return true;
 }