public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Add reading critical region for kvm_io_bus_read/write
@ 2010-12-06  8:44 Sheng Yang
  2010-12-06 12:58 ` Avi Kivity
  0 siblings, 1 reply; 3+ messages in thread
From: Sheng Yang @ 2010-12-06  8:44 UTC (permalink / raw)
  To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang

Seems we missed it.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
Do we need this, or slot_lock covered this?

 virt/kvm/kvm_main.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c4ee364..3e71b91 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2228,28 +2228,36 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *bus)
 int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 		     int len, const void *val)
 {
-	int i;
+	int i, idx, r = -EOPNOTSUPP;
 	struct kvm_io_bus *bus;
 
+	idx = srcu_read_lock(&kvm->srcu);
 	bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
 	for (i = 0; i < bus->dev_count; i++)
-		if (!kvm_iodevice_write(bus->devs[i], addr, len, val))
-			return 0;
-	return -EOPNOTSUPP;
+		if (!kvm_iodevice_write(bus->devs[i], addr, len, val)) {
+			r = 0;
+			break;
+		}
+	srcu_read_unlock(&kvm->srcu, idx);
+	return r;
 }
 
 /* kvm_io_bus_read - called under kvm->slots_lock */
 int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 		    int len, void *val)
 {
-	int i;
+	int i, idx, r = -EOPNOTSUPP;
 	struct kvm_io_bus *bus;
 
+	idx = srcu_read_lock(&kvm->srcu);
 	bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
 	for (i = 0; i < bus->dev_count; i++)
-		if (!kvm_iodevice_read(bus->devs[i], addr, len, val))
-			return 0;
-	return -EOPNOTSUPP;
+		if (!kvm_iodevice_read(bus->devs[i], addr, len, val)) {
+			r = 0;
+			break;
+		}
+	srcu_read_unlock(&kvm->srcu, idx);
+	return r;
 }
 
 /* Caller must hold slots_lock. */
-- 
1.7.0.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-12-07  2:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-06  8:44 [PATCH] KVM: Add reading critical region for kvm_io_bus_read/write Sheng Yang
2010-12-06 12:58 ` Avi Kivity
2010-12-07  2:35   ` Sheng Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox