From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@redhat.com>, kvm@vger.kernel.org
Cc: Gregory Haskins <gregory.haskins@gmail.com>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 2/4] KVM: move coalesced_mmio locking to its own device
Date: Wed, 20 May 2009 15:48:43 -0300 [thread overview]
Message-ID: <20090520185134.623968425@localhost.localdomain> (raw)
In-Reply-To: 20090520184841.954066003@localhost.localdomain
[-- Attachment #1: coalesced-mmio-lock --]
[-- Type: text/plain, Size: 2666 bytes --]
Get rid of kvm->lock dependency on coalesced_mmio methods. Use an
atomic variable instead to guarantee only one vcpu is batching
data into the ring at a given time.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: kvm-irqlock/virt/kvm/coalesced_mmio.c
===================================================================
--- kvm-irqlock.orig/virt/kvm/coalesced_mmio.c
+++ kvm-irqlock/virt/kvm/coalesced_mmio.c
@@ -26,9 +26,12 @@ static int coalesced_mmio_in_range(struc
if (!is_write)
return 0;
- /* kvm->lock is taken by the caller and must be not released before
- * dev.read/write
- */
+ /*
+ * Some other vcpu might be batching data into the ring,
+ * fallback to userspace. Ordering not our problem.
+ */
+ if (!atomic_add_unless(&dev->in_use, 1, 1))
+ return 0;
/* Are we able to batch it ? */
@@ -41,7 +44,7 @@ static int coalesced_mmio_in_range(struc
KVM_COALESCED_MMIO_MAX;
if (next == dev->kvm->coalesced_mmio_ring->first) {
/* full */
- return 0;
+ goto out_denied;
}
/* is it in a batchable area ? */
@@ -57,6 +60,8 @@ static int coalesced_mmio_in_range(struc
addr + len <= zone->addr + zone->size)
return 1;
}
+out_denied:
+ atomic_set(&dev->in_use, 0);
return 0;
}
@@ -67,15 +72,14 @@ static void coalesced_mmio_write(struct
(struct kvm_coalesced_mmio_dev*)this->private;
struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring;
- /* kvm->lock must be taken by caller before call to in_range()*/
-
/* copy data in first free entry of the ring */
ring->coalesced_mmio[ring->last].phys_addr = addr;
ring->coalesced_mmio[ring->last].len = len;
memcpy(ring->coalesced_mmio[ring->last].data, val, len);
- smp_wmb();
ring->last = (ring->last + 1) % KVM_COALESCED_MMIO_MAX;
+ smp_wmb();
+ atomic_set(&dev->in_use, 0);
}
static void coalesced_mmio_destructor(struct kvm_io_device *this)
@@ -90,6 +94,8 @@ int kvm_coalesced_mmio_init(struct kvm *
dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
+ atomic_set(&dev->in_use, 0);
+
dev->dev.write = coalesced_mmio_write;
dev->dev.in_range = coalesced_mmio_in_range;
dev->dev.destructor = coalesced_mmio_destructor;
Index: kvm-irqlock/virt/kvm/coalesced_mmio.h
===================================================================
--- kvm-irqlock.orig/virt/kvm/coalesced_mmio.h
+++ kvm-irqlock/virt/kvm/coalesced_mmio.h
@@ -12,6 +12,7 @@
struct kvm_coalesced_mmio_dev {
struct kvm_io_device dev;
struct kvm *kvm;
+ atomic_t in_use;
int nb_zones;
struct kvm_coalesced_mmio_zone zone[KVM_COALESCED_MMIO_ZONE_MAX];
};
--
next prev parent reply other threads:[~2009-05-20 18:54 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-18 16:56 [patch 0/4] move irq protection role to separate kvm->irq_lock Marcelo Tosatti
2009-05-18 16:56 ` [patch 1/4] KVM: x86: grab pic lock in kvm_pic_clear_isr_ack Marcelo Tosatti
2009-05-18 16:56 ` [patch 2/4] KVM: move coalesced_mmio locking to its own device Marcelo Tosatti
2009-05-20 12:06 ` Avi Kivity
2009-05-20 14:09 ` Marcelo Tosatti
2009-05-20 14:29 ` Avi Kivity
2009-05-20 15:13 ` Marcelo Tosatti
2009-05-20 15:22 ` Marcelo Tosatti
2009-05-20 15:22 ` Avi Kivity
2009-05-20 18:48 ` [patch 0/4] move irq protection role to separate lock v2 Marcelo Tosatti
2009-05-20 18:48 ` [patch 1/4] KVM: x86: grab pic lock in kvm_pic_clear_isr_ack Marcelo Tosatti
2009-05-20 18:48 ` Marcelo Tosatti [this message]
2009-05-24 14:04 ` [patch 2/4] KVM: move coalesced_mmio locking to its own device Avi Kivity
2009-05-25 11:04 ` Marcelo Tosatti
2009-05-26 11:24 ` Avi Kivity
2009-05-26 13:15 ` Marcelo Tosatti
2009-05-26 13:27 ` Avi Kivity
2009-05-20 18:48 ` [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic Marcelo Tosatti
2009-05-24 14:10 ` Avi Kivity
2009-05-25 11:11 ` Marcelo Tosatti
2009-05-26 11:33 ` Avi Kivity
2009-05-28 4:45 ` [patch 0/4] move irq protection role to separate lock v3 Marcelo Tosatti
2009-05-28 4:45 ` [patch 1/4] KVM: x86: grab pic lock in kvm_pic_clear_isr_ack Marcelo Tosatti
2009-05-28 4:45 ` [patch 2/4] KVM: move coalesced_mmio locking to its own device Marcelo Tosatti
2009-05-31 12:14 ` Avi Kivity
2009-06-01 21:23 ` Marcelo Tosatti
2009-06-01 21:43 ` Avi Kivity
2009-06-04 18:08 ` [patch 0/4] move irq protection role to separate lock v4 Marcelo Tosatti
2009-06-04 18:08 ` [patch 1/4] KVM: x86: grab pic lock in kvm_pic_clear_isr_ack Marcelo Tosatti
2009-06-04 18:08 ` [patch 2/4] KVM: move coalesced_mmio locking to its own device Marcelo Tosatti
2009-06-04 18:08 ` [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic Marcelo Tosatti
2009-06-04 18:08 ` [patch 4/4] KVM: switch irq injection/acking data structures to irq_lock Marcelo Tosatti
2009-06-08 9:18 ` [patch 0/4] move irq protection role to separate lock v4 Avi Kivity
2009-05-28 4:45 ` [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic Marcelo Tosatti
2009-05-28 4:45 ` [patch 4/4] KVM: switch irq injection/acking data structures to irq_lock Marcelo Tosatti
2009-05-20 18:48 ` [patch 4/4] KVM: switch irq injection/acking " Marcelo Tosatti
2009-05-21 4:50 ` [patch 0/4] move irq protection role to separate lock v2 Marcelo Tosatti
2009-05-21 6:55 ` Christian Bornträger
2009-05-21 7:26 ` Avi Kivity
2009-05-21 14:32 ` Marcelo Tosatti
2009-05-21 15:02 ` Avi Kivity
2009-05-18 16:56 ` [patch 3/4] KVM: introduce irq_lock, use it protect ioapic Marcelo Tosatti
2009-05-20 12:11 ` Avi Kivity
2009-05-20 14:11 ` Marcelo Tosatti
2009-05-20 14:29 ` Avi Kivity
2009-05-18 16:56 ` [patch 4/4] KVM: switch irq injection/acking to irq_lock Marcelo Tosatti
2009-05-20 12:15 ` Gregory Haskins
2009-05-20 14:16 ` Marcelo Tosatti
2009-05-24 14:53 ` Avi Kivity
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=20090520185134.623968425@localhost.localdomain \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=gregory.haskins@gmail.com \
--cc=kvm@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).