From: Liu Ping Fan <qemulist@gmail.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Anthony Liguori <aliguori@us.ibm.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v2 1/6] hostmem: make hostmem single, not per Vring related
Date: Fri, 3 May 2013 10:45:17 +0800 [thread overview]
Message-ID: <1367549122-2948-2-git-send-email-qemulist@gmail.com> (raw)
In-Reply-To: <1367549122-2948-1-git-send-email-qemulist@gmail.com>
From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
The hwaddr and hva mapping relation is system wide, no need to
be created for each Vring
Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
exec.c | 1 +
hw/virtio/dataplane/hostmem.c | 33 +++++++++++++++++++--------------
hw/virtio/dataplane/vring.c | 11 ++++-------
include/exec/memory.h | 1 +
include/hw/virtio/dataplane/hostmem.h | 5 +----
include/hw/virtio/dataplane/vring.h | 1 -
6 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/exec.c b/exec.c
index fa1e0c3..df01f08 100644
--- a/exec.c
+++ b/exec.c
@@ -1809,6 +1809,7 @@ static void memory_map_init(void)
memory_listener_register(&core_memory_listener, &address_space_memory);
memory_listener_register(&io_memory_listener, &address_space_io);
memory_listener_register(&tcg_memory_listener, &address_space_memory);
+ hostmem_init();
dma_context_init(&dma_context_memory, &address_space_memory,
NULL, NULL, NULL);
diff --git a/hw/virtio/dataplane/hostmem.c b/hw/virtio/dataplane/hostmem.c
index 37292ff..756b09f 100644
--- a/hw/virtio/dataplane/hostmem.c
+++ b/hw/virtio/dataplane/hostmem.c
@@ -14,6 +14,10 @@
#include "exec/address-spaces.h"
#include "hw/virtio/dataplane/hostmem.h"
+HostMem *system_mem;
+
+static void hostmem_finalize(void);
+
static int hostmem_lookup_cmp(const void *phys_, const void *region_)
{
hwaddr phys = *(const hwaddr *)phys_;
@@ -31,11 +35,12 @@ static int hostmem_lookup_cmp(const void *phys_, const void *region_)
/**
* Map guest physical address to host pointer
*/
-void *hostmem_lookup(HostMem *hostmem, hwaddr phys, hwaddr len, bool is_write)
+void *hostmem_lookup(hwaddr phys, hwaddr len, bool is_write)
{
HostMemRegion *region;
void *host_addr = NULL;
hwaddr offset_within_region;
+ HostMem *hostmem = system_mem;
qemu_mutex_lock(&hostmem->current_regions_lock);
region = bsearch(&phys, hostmem->current_regions,
@@ -137,13 +142,12 @@ static void hostmem_listener_coalesced_mmio_dummy(MemoryListener *listener,
{
}
-void hostmem_init(HostMem *hostmem)
+void hostmem_init(void)
{
- memset(hostmem, 0, sizeof(*hostmem));
+ system_mem = g_new0(HostMem, 1);
+ qemu_mutex_init(&system_mem->current_regions_lock);
- qemu_mutex_init(&hostmem->current_regions_lock);
-
- hostmem->listener = (MemoryListener){
+ system_mem->listener = (MemoryListener) {
.begin = hostmem_listener_dummy,
.commit = hostmem_listener_commit,
.region_add = hostmem_listener_append_region,
@@ -161,16 +165,17 @@ void hostmem_init(HostMem *hostmem)
.priority = 10,
};
- memory_listener_register(&hostmem->listener, &address_space_memory);
- if (hostmem->num_new_regions > 0) {
- hostmem_listener_commit(&hostmem->listener);
+ memory_listener_register(&system_mem->listener, &address_space_memory);
+ if (system_mem->num_new_regions > 0) {
+ hostmem_listener_commit(&system_mem->listener);
}
+ atexit(hostmem_finalize);
}
-void hostmem_finalize(HostMem *hostmem)
+static void hostmem_finalize(void)
{
- memory_listener_unregister(&hostmem->listener);
- g_free(hostmem->new_regions);
- g_free(hostmem->current_regions);
- qemu_mutex_destroy(&hostmem->current_regions_lock);
+ memory_listener_unregister(&system_mem->listener);
+ g_free(system_mem->new_regions);
+ g_free(system_mem->current_regions);
+ qemu_mutex_destroy(&system_mem->current_regions_lock);
}
diff --git a/hw/virtio/dataplane/vring.c b/hw/virtio/dataplane/vring.c
index e0d6e83..4d6d735 100644
--- a/hw/virtio/dataplane/vring.c
+++ b/hw/virtio/dataplane/vring.c
@@ -27,8 +27,7 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
vring->broken = false;
- hostmem_init(&vring->hostmem);
- vring_ptr = hostmem_lookup(&vring->hostmem, vring_addr, vring_size, true);
+ vring_ptr = hostmem_lookup(vring_addr, vring_size, true);
if (!vring_ptr) {
error_report("Failed to map vring "
"addr %#" HWADDR_PRIx " size %" HWADDR_PRIu,
@@ -51,7 +50,6 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
void vring_teardown(Vring *vring)
{
- hostmem_finalize(&vring->hostmem);
}
/* Disable guest->host notifies */
@@ -138,8 +136,7 @@ static int get_indirect(Vring *vring,
struct vring_desc *desc_ptr;
/* Translate indirect descriptor */
- desc_ptr = hostmem_lookup(&vring->hostmem,
- indirect->addr + found * sizeof(desc),
+ desc_ptr = hostmem_lookup(indirect->addr + found * sizeof(desc),
sizeof(desc), false);
if (!desc_ptr) {
error_report("Failed to map indirect descriptor "
@@ -172,7 +169,7 @@ static int get_indirect(Vring *vring,
return -ENOBUFS;
}
- iov->iov_base = hostmem_lookup(&vring->hostmem, desc.addr, desc.len,
+ iov->iov_base = hostmem_lookup(desc.addr, desc.len,
desc.flags & VRING_DESC_F_WRITE);
if (!iov->iov_base) {
error_report("Failed to map indirect descriptor"
@@ -300,7 +297,7 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
}
/* TODO handle non-contiguous memory across region boundaries */
- iov->iov_base = hostmem_lookup(&vring->hostmem, desc.addr, desc.len,
+ iov->iov_base = hostmem_lookup(desc.addr, desc.len,
desc.flags & VRING_DESC_F_WRITE);
if (!iov->iov_base) {
error_report("Failed to map vring desc addr %#" PRIx64 " len %u",
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 9e88320..2761668 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -887,6 +887,7 @@ void *address_space_map(AddressSpace *as, hwaddr addr,
void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
int is_write, hwaddr access_len);
+void hostmem_init(void);
#endif
diff --git a/include/hw/virtio/dataplane/hostmem.h b/include/hw/virtio/dataplane/hostmem.h
index b2cf093..7f967a5 100644
--- a/include/hw/virtio/dataplane/hostmem.h
+++ b/include/hw/virtio/dataplane/hostmem.h
@@ -41,9 +41,6 @@ typedef struct {
size_t num_current_regions;
} HostMem;
-void hostmem_init(HostMem *hostmem);
-void hostmem_finalize(HostMem *hostmem);
-
/**
* Map a guest physical address to a pointer
*
@@ -52,6 +49,6 @@ void hostmem_finalize(HostMem *hostmem);
* can be done with other mechanisms like bdrv_drain_all() that quiesce
* in-flight I/O.
*/
-void *hostmem_lookup(HostMem *hostmem, hwaddr phys, hwaddr len, bool is_write);
+void *hostmem_lookup(hwaddr phys, hwaddr len, bool is_write);
#endif /* HOSTMEM_H */
diff --git a/include/hw/virtio/dataplane/vring.h b/include/hw/virtio/dataplane/vring.h
index 9380cb5..56acffb 100644
--- a/include/hw/virtio/dataplane/vring.h
+++ b/include/hw/virtio/dataplane/vring.h
@@ -23,7 +23,6 @@
#include "hw/virtio/virtio.h"
typedef struct {
- HostMem hostmem; /* guest memory mapper */
struct vring vr; /* virtqueue vring mapped to host memory */
uint16_t last_avail_idx; /* last processed avail ring index */
uint16_t last_used_idx; /* last processed used ring index */
--
1.7.4.4
next prev parent reply other threads:[~2013-05-03 2:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-03 2:45 [Qemu-devel] [PATCH v2 0/6] proposal to make hostmem listener RAM unplug safe Liu Ping Fan
2013-05-03 2:45 ` Liu Ping Fan [this message]
2013-05-03 8:54 ` [Qemu-devel] [PATCH v2 1/6] hostmem: make hostmem single, not per Vring related Stefan Hajnoczi
2013-05-03 2:45 ` [Qemu-devel] [PATCH v2 2/6] hostmem: AddressSpace has its own map and maintained by RCU prepared style Liu Ping Fan
2013-05-03 9:10 ` Stefan Hajnoczi
2013-05-06 1:44 ` liu ping fan
2013-05-03 2:45 ` [Qemu-devel] [PATCH v2 3/6] memory: add ref/unref interface for MemroyRegionOps Liu Ping Fan
2013-05-03 2:45 ` [Qemu-devel] [PATCH v2 4/6] hostmem: hostmem listener pin RAM-Device by refcnt Liu Ping Fan
2013-05-03 9:35 ` Stefan Hajnoczi
2013-05-06 1:45 ` liu ping fan
2013-05-03 2:45 ` [Qemu-devel] [PATCH v2 5/6] Vring: use hostmem's RAM safe api Liu Ping Fan
2013-05-03 10:02 ` Stefan Hajnoczi
2013-05-06 1:45 ` liu ping fan
2013-05-03 2:45 ` [Qemu-devel] [PATCH v2 6/6] virtio-blk: release reference to RAM's memoryRegion Liu Ping Fan
2013-05-03 10:09 ` Stefan Hajnoczi
2013-05-06 2:39 ` liu ping fan
2013-05-04 9:53 ` [Qemu-devel] [PATCH v2 0/6] proposal to make hostmem listener RAM unplug safe Paolo Bonzini
2013-05-06 1:42 ` liu ping fan
2013-05-06 6:17 ` Paolo Bonzini
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=1367549122-2948-2-git-send-email-qemulist@gmail.com \
--to=qemulist@gmail.com \
--cc=aliguori@us.ibm.com \
--cc=jan.kiszka@siemens.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vasilis.liaskovitis@profitbricks.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;
as well as URLs for NNTP newsgroup(s).