From: Anthony PERARD <anthony.perard@citrix.com>
To: QEMU-devel <qemu-devel@nongnu.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
Xen Devel <xen-devel@lists.xensource.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [Qemu-devel] [PATCH V2 2/5] xen mapcache: Check if a memory space has moved.
Date: Fri, 9 Dec 2011 21:54:02 +0000 [thread overview]
Message-ID: <1323467645-24271-3-git-send-email-anthony.perard@citrix.com> (raw)
In-Reply-To: <1323467645-24271-1-git-send-email-anthony.perard@citrix.com>
This patch change the xen_map_cache behavior. Before trying to map a guest
addr, mapcache will look into the list of range of address that have been moved
(physmap/set_memory). There is currently one memory space like this, the vram,
"moved" from were it's allocated to were the guest will look into.
This help to have a succefull migration.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen-all.c | 18 +++++++++++++++++-
xen-mapcache.c | 22 +++++++++++++++++++---
xen-mapcache.h | 9 +++++++--
3 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/xen-all.c b/xen-all.c
index b5e28ab..b2e9853 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -218,6 +218,22 @@ static XenPhysmap *get_physmapping(XenIOState *state,
return NULL;
}
+static target_phys_addr_t xen_phys_offset_to_gaddr(target_phys_addr_t start_addr,
+ ram_addr_t size, void *opaque)
+{
+ target_phys_addr_t addr = start_addr & TARGET_PAGE_MASK;
+ XenIOState *xen_io_state = opaque;
+ XenPhysmap *physmap = NULL;
+
+ QLIST_FOREACH(physmap, &xen_io_state->physmap, list) {
+ if (range_covers_byte(physmap->phys_offset, physmap->size, addr)) {
+ return physmap->start_addr;
+ }
+ }
+
+ return start_addr;
+}
+
#if CONFIG_XEN_CTRL_INTERFACE_VERSION >= 340
static int xen_add_to_physmap(XenIOState *state,
target_phys_addr_t start_addr,
@@ -938,7 +954,7 @@ int xen_hvm_init(void)
}
/* Init RAM management */
- xen_map_cache_init();
+ xen_map_cache_init(xen_phys_offset_to_gaddr, state);
xen_ram_init(ram_size);
qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state);
diff --git a/xen-mapcache.c b/xen-mapcache.c
index 7bcb86e..d5f52b2 100644
--- a/xen-mapcache.c
+++ b/xen-mapcache.c
@@ -76,6 +76,9 @@ typedef struct MapCache {
uint8_t *last_address_vaddr;
unsigned long max_mcache_size;
unsigned int mcache_bucket_shift;
+
+ phys_offset_to_gaddr_t phys_offset_to_gaddr;
+ void *opaque;
} MapCache;
static MapCache *mapcache;
@@ -89,13 +92,16 @@ static inline int test_bits(int nr, int size, const unsigned long *addr)
return 0;
}
-void xen_map_cache_init(void)
+void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
{
unsigned long size;
struct rlimit rlimit_as;
mapcache = g_malloc0(sizeof (MapCache));
+ mapcache->phys_offset_to_gaddr = f;
+ mapcache->opaque = opaque;
+
QTAILQ_INIT(&mapcache->locked_entries);
mapcache->last_address_index = -1;
@@ -191,9 +197,14 @@ uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
uint8_t lock)
{
MapCacheEntry *entry, *pentry = NULL;
- target_phys_addr_t address_index = phys_addr >> MCACHE_BUCKET_SHIFT;
- target_phys_addr_t address_offset = phys_addr & (MCACHE_BUCKET_SIZE - 1);
+ target_phys_addr_t address_index;
+ target_phys_addr_t address_offset;
target_phys_addr_t __size = size;
+ bool translated = false;
+
+tryagain:
+ address_index = phys_addr >> MCACHE_BUCKET_SHIFT;
+ address_offset = phys_addr & (MCACHE_BUCKET_SIZE - 1);
trace_xen_map_cache(phys_addr);
@@ -235,6 +246,11 @@ uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
if(!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT,
entry->valid_mapping)) {
mapcache->last_address_index = -1;
+ if (!translated && mapcache->phys_offset_to_gaddr) {
+ phys_addr = mapcache->phys_offset_to_gaddr(phys_addr, size, mapcache->opaque);
+ translated = true;
+ goto tryagain;
+ }
trace_xen_map_cache_return(NULL);
return NULL;
}
diff --git a/xen-mapcache.h b/xen-mapcache.h
index da874ca..70301a5 100644
--- a/xen-mapcache.h
+++ b/xen-mapcache.h
@@ -11,9 +11,13 @@
#include <stdlib.h>
+typedef target_phys_addr_t (*phys_offset_to_gaddr_t)(target_phys_addr_t start_addr,
+ ram_addr_t size,
+ void *opaque);
#ifdef CONFIG_XEN
-void xen_map_cache_init(void);
+void xen_map_cache_init(phys_offset_to_gaddr_t f,
+ void *opaque);
uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
uint8_t lock);
ram_addr_t xen_ram_addr_from_mapcache(void *ptr);
@@ -22,7 +26,8 @@ void xen_invalidate_map_cache(void);
#else
-static inline void xen_map_cache_init(void)
+static inline void xen_map_cache_init(phys_offset_to_gaddr_t f,
+ void *opaque)
{
}
--
Anthony PERARD
next prev parent reply other threads:[~2011-12-09 21:54 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-09 21:54 [Qemu-devel] [PATCH V2 0/5] Have a working migration with Xen Anthony PERARD
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 1/5] vl.c: Do not save RAM state when Xen is used Anthony PERARD
2011-12-15 15:12 ` Anthony Liguori
2011-12-18 17:44 ` Avi Kivity
2011-12-20 16:46 ` Anthony PERARD
2011-12-09 21:54 ` Anthony PERARD [this message]
2011-12-12 12:53 ` [Qemu-devel] [PATCH V2 2/5] xen mapcache: Check if a memory space has moved Stefano Stabellini
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 3/5] Introduce premigrate RunState Anthony PERARD
2011-12-15 15:14 ` Anthony Liguori
2011-12-15 16:31 ` Luiz Capitulino
2011-12-19 17:27 ` Anthony PERARD
2012-01-03 19:05 ` Luiz Capitulino
2012-01-05 12:26 ` Anthony PERARD
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 4/5] xen: Change memory access behavior during migration Anthony PERARD
2011-12-12 12:55 ` Stefano Stabellini
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 5/5] vga-cirrus: Workaround during restore when using Xen Anthony PERARD
2011-12-10 10:45 ` Jan Kiszka
2011-12-12 13:18 ` Stefano Stabellini
2011-12-12 14:03 ` Jan Kiszka
2011-12-12 14:41 ` Stefano Stabellini
2011-12-12 15:03 ` Jan Kiszka
2011-12-12 15:32 ` Stefano Stabellini
2011-12-13 11:55 ` [Qemu-devel] early_savevm (was: [PATCH V2 5/5] vga-cirrus: Workaround during restore when using Xen.) Stefano Stabellini
2011-12-13 12:35 ` [Qemu-devel] early_savevm Jan Kiszka
2011-12-13 13:59 ` Stefano Stabellini
2011-12-18 17:43 ` Avi Kivity
2012-01-11 17:55 ` Anthony Liguori
2011-12-18 17:41 ` [Qemu-devel] [PATCH V2 5/5] vga-cirrus: Workaround during restore when using Xen Avi Kivity
2012-01-04 16:38 ` Stefano Stabellini
2012-01-04 17:23 ` Avi Kivity
2012-01-05 12:30 ` Stefano Stabellini
2012-01-05 12:50 ` Avi Kivity
2012-01-05 13:17 ` Stefano Stabellini
2012-01-05 13:32 ` Avi Kivity
2012-01-05 14:34 ` Stefano Stabellini
2012-01-05 15:19 ` Avi Kivity
2012-01-05 15:53 ` Stefano Stabellini
2012-01-05 16:33 ` Avi Kivity
2012-01-05 17:21 ` Stefano Stabellini
2012-01-05 17:50 ` Avi Kivity
2012-01-05 18:49 ` Jan Kiszka
2012-01-06 10:50 ` Stefano Stabellini
2012-01-06 13:30 ` Jan Kiszka
2012-01-06 14:40 ` Stefano Stabellini
2012-01-08 10:39 ` Avi Kivity
2012-01-09 15:25 ` Stefano Stabellini
2012-01-09 15:28 ` Jan Kiszka
2012-01-09 15:36 ` Avi Kivity
2012-01-06 15:58 ` Peter Maydell
2012-01-06 16:50 ` Jan Kiszka
2012-01-06 12:19 ` Avi Kivity
2012-01-06 12:22 ` Jan Kiszka
2012-01-06 12:47 ` Avi Kivity
2011-12-12 12:58 ` Stefano Stabellini
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=1323467645-24271-3-git-send-email-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xensource.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).