From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com,
gorcunov@gmail.com, prasadjoshi124@gmail.com,
Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH v2 8/8] kvm tools: Use brlock in MMIO and IOPORT
Date: Mon, 30 May 2011 11:30:47 +0300 [thread overview]
Message-ID: <1306744247-26051-8-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1306744247-26051-1-git-send-email-levinsasha928@gmail.com>
Use brlock to protect mmio and ioport modules and make them
update-safe.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/ioport.c | 10 +++++++++-
tools/kvm/mmio.c | 17 +++++++++++++++--
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c
index d0a1aa8..e00fb59 100644
--- a/tools/kvm/ioport.c
+++ b/tools/kvm/ioport.c
@@ -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);
diff --git a/tools/kvm/mmio.c b/tools/kvm/mmio.c
index ef986bf..a57abeb 100644
--- a/tools/kvm/mmio.c
+++ b/tools/kvm/mmio.c
@@ -1,5 +1,6 @@
#include "kvm/kvm.h"
#include "kvm/rbtree-interval.h"
+#include "kvm/brlock.h"
#include <stdio.h>
#include <stdlib.h>
@@ -55,41 +56,53 @@ 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)
return false;
+ br_write_lock();
*mmio = (struct mmio_mapping) {
.node = RB_INT_INIT(phys_addr, phys_addr + phys_addr_len),
.kvm_mmio_callback_fn = kvm_mmio_callback_fn,
};
- return mmio_insert(&mmio_tree, mmio);
+ 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)
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;
}
--
1.7.5.rc3
next prev parent reply other threads:[~2011-05-30 8:31 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-30 8:30 [PATCH v2 1/8] kvm tools: Use correct value for user signal base Sasha Levin
2011-05-30 8:30 ` [PATCH v2 2/8] kvm tools: Remove wrong global definition of kvm Sasha Levin
2011-05-30 8:38 ` Ingo Molnar
2011-05-30 8:59 ` Sasha Levin
2011-05-30 8:30 ` [PATCH v2 3/8] kvm tools: Allow pausing guests Sasha Levin
2011-05-30 8:39 ` Ingo Molnar
2011-05-30 8:30 ` [PATCH v2 4/8] kvm tools: Pause/resume guest using SIGUSR2 Sasha Levin
2011-05-30 8:41 ` Ingo Molnar
2011-05-30 8:30 ` [PATCH v2 5/8] kvm tools: Add a brlock Sasha Levin
2011-05-30 8:30 ` [PATCH v2 6/8] kvm tools: Add rwlock wrapper Sasha Levin
2011-05-30 8:43 ` Ingo Molnar
2011-05-30 9:29 ` Pekka Enberg
2011-05-30 9:34 ` Sasha Levin
2011-05-30 9:40 ` Pekka Enberg
2011-05-30 9:46 ` Sasha Levin
2011-05-30 9:48 ` Pekka Enberg
2011-05-30 9:54 ` Ingo Molnar
2011-05-30 11:11 ` Takuya Yoshikawa
2011-05-30 11:12 ` Sasha Levin
2011-05-30 11:26 ` Takuya Yoshikawa
2011-05-30 11:39 ` Avi Kivity
2011-05-30 11:49 ` Ingo Molnar
2011-05-30 11:55 ` Pekka Enberg
2011-05-30 11:58 ` Sasha Levin
2011-05-30 12:20 ` Ingo Molnar
2011-05-30 12:22 ` Sasha Levin
2011-05-30 12:25 ` Avi Kivity
2011-05-30 12:23 ` Avi Kivity
2011-05-30 12:30 ` Pekka Enberg
2011-05-30 12:32 ` Avi Kivity
2011-05-30 14:10 ` Ingo Molnar
2011-05-30 14:30 ` Avi Kivity
2011-05-30 14:43 ` Ingo Molnar
2011-05-30 14:50 ` Avi Kivity
2011-05-30 19:32 ` Ingo Molnar
2011-05-30 12:04 ` Avi Kivity
2011-05-30 12:36 ` Ingo Molnar
2011-05-30 12:44 ` Avi Kivity
2011-05-30 12:46 ` Pekka Enberg
2011-05-30 12:48 ` Avi Kivity
2011-05-30 13:05 ` Sasha Levin
2011-06-03 7:27 ` Sasha Levin
2011-06-03 7:34 ` Ingo Molnar
2011-06-03 7:54 ` Sasha Levin
2011-06-03 19:31 ` Paul E. McKenney
2011-06-03 19:56 ` Sasha Levin
2011-06-03 20:22 ` Paul E. McKenney
2011-06-03 21:03 ` Sasha Levin
2011-06-03 21:20 ` Paul E. McKenney
2011-06-03 22:54 ` Sasha Levin
2011-06-03 23:05 ` Paul E. McKenney
2011-06-04 6:26 ` Sasha Levin
2011-06-04 16:30 ` Paul E. McKenney
2011-06-14 22:26 ` Sasha Levin
2011-06-14 23:42 ` Paul E. McKenney
2011-06-15 1:25 ` Sasha Levin
2011-06-15 4:22 ` Paul E. McKenney
2011-06-05 12:12 ` Avi Kivity
2011-05-30 14:16 ` Takuya Yoshikawa
2011-05-30 9:56 ` Ingo Molnar
2011-05-30 10:05 ` Sasha Levin
2011-05-30 10:13 ` Ingo Molnar
2011-05-30 10:22 ` Sasha Levin
2011-05-30 10:30 ` Ingo Molnar
2011-05-30 10:41 ` Sasha Levin
2011-05-30 8:30 ` [PATCH v2 7/8] kvm tools: Add debug mode to brlock Sasha Levin
2011-05-30 8:30 ` Sasha Levin [this message]
2011-05-30 8:47 ` [PATCH v2 8/8] kvm tools: Use brlock in MMIO and IOPORT Ingo Molnar
2011-05-30 8:56 ` Sasha Levin
2011-05-30 8:35 ` [PATCH v2 1/8] kvm tools: Use correct value for user signal base Ingo Molnar
2011-05-30 8:40 ` Sasha Levin
2011-05-30 8:49 ` Ingo Molnar
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=1306744247-26051-8-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 \
--cc=prasadjoshi124@gmail.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