[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 24/29] vhost+postcopy: Lock around set_mem_table
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [RFC 24/29] vhost+postcopy: Lock around set_mem_table |
Date: |
Wed, 28 Jun 2017 20:00:42 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
**HACK - better solution needed **
We have the situation where:
qemu bridge
send set_mem_table
map memory
a) mark area with UFD
send reply with map addresses
b) start using
c) receive reply
As soon as (a) happens qemu might start seeing faults
from memory accesses (but doesn't until b); but it can't
process those faults until (c) when it's received the
mmap addresses.
Make the fault handler spin until it gets the reply in (c).
At the very least this needs some proper locks, but preferably
we need to split the message.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
hw/virtio/vhost-user.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 0f2e05f817..74e4313782 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -138,6 +138,7 @@ struct vhost_user {
* vhost region.
*/
ram_addr_t region_rb_offset[VHOST_MEMORY_MAX_NREGIONS];
+ uint64_t in_set_mem_table; /*Hack! 1 while waiting for
set_mem_table reply */
};
static bool ioeventfd_enabled(void)
@@ -321,6 +322,7 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
msg.flags |= VHOST_USER_NEED_REPLY_MASK;
}
+ atomic_set(&u->in_set_mem_table, true);
for (i = 0; i < dev->mem->nregions; ++i) {
struct vhost_memory_region *reg = dev->mem->regions + i;
ram_addr_t offset;
@@ -351,14 +353,15 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
if (!fd_num) {
error_report("Failed initializing vhost-user memory map, "
"consider using -object memory-backend-file share=on");
+ atomic_set(&u->in_set_mem_table, false);
return -1;
}
msg.size = sizeof(msg.payload.memory.nregions);
msg.size += sizeof(msg.payload.memory.padding);
msg.size += fd_num * sizeof(VhostUserMemoryRegion);
-
if (vhost_user_write(dev, &msg, fds, fd_num) < 0) {
+ atomic_set(&u->in_set_mem_table, false);
return -1;
}
@@ -373,6 +376,7 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
error_report("%s: Received unexpected msg type."
"Expected %d received %d", __func__,
VHOST_USER_SET_MEM_TABLE, msg_reply.request);
+ atomic_set(&u->in_set_mem_table, false);
return -1;
}
/* We're using the same structure, just reusing one of the
@@ -381,6 +385,7 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
if (msg_reply.size != msg.size) {
error_report("%s: Unexpected size for postcopy reply "
"%d vs %d", __func__, msg_reply.size, msg.size);
+ atomic_set(&u->in_set_mem_table, false);
return -1;
}
@@ -410,9 +415,11 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
error_report("%s: postcopy reply not fully consumed "
"%d vs %zd",
__func__, reply_i, fd_num);
+ atomic_set(&u->in_set_mem_table, false);
return -1;
}
}
+ atomic_set(&u->in_set_mem_table, false);
if (reply_supported) {
return process_message_reply(dev, &msg);
}
@@ -821,6 +828,11 @@ static int vhost_user_postcopy_waker(struct PostCopyFD
*pcfd, RAMBlock *rb,
int i;
trace_vhost_user_postcopy_waker(qemu_ram_get_idstr(rb), offset);
+ while (atomic_mb_read(&u->in_set_mem_table)) {
+ fprintf(stderr, "%s: Spin waiting for memtable\n", __func__);
+ usleep(1000*100);
+ }
+
/* Translate the offset into an address in the clients address space */
for (i = 0; i < dev->mem->nregions; i++) {
if (u->region_rb[i] == rb &&
--
2.13.0
- [Qemu-devel] [RFC 14/29] vhost+postcopy: Register new regions with the ufd, (continued)
- [Qemu-devel] [RFC 14/29] vhost+postcopy: Register new regions with the ufd, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 15/29] vhost+postcopy: Send address back to qemu, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 16/29] vhost+postcopy: Stash RAMBlock and offset, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 17/29] vhost+postcopy: Send requests to source for shared pages, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 18/29] vhost+postcopy: Resolve client address, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 19/29] postcopy: wake shared, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 20/29] postcopy: postcopy_notify_shared_wake, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 22/29] vhost+postcopy: Call wakeups, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 21/29] vhost+postcopy: Add vhost waker, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 23/29] vub+postcopy: madvises, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 24/29] vhost+postcopy: Lock around set_mem_table,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [RFC 25/29] vhu: enable = false on get_vring_base, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 26/29] vhost: Add VHOST_USER_POSTCOPY_END message, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 28/29] postcopy: Allow shared memory, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 27/29] vhost+postcopy: Wire up POSTCOPY_END notify, Dr. David Alan Gilbert (git), 2017/06/28
- [Qemu-devel] [RFC 29/29] vhost-user: Claim support for postcopy, Dr. David Alan Gilbert (git), 2017/06/28
- Re: [Qemu-devel] [RFC 00/29] postcopy+vhost-user/shared ram, Dr. David Alan Gilbert, 2017/06/29