[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 16/35] Add qemu_ram_remap
From: |
Marcelo Tosatti |
Subject: |
[Qemu-devel] [PATCH 16/35] Add qemu_ram_remap |
Date: |
Tue, 15 Mar 2011 18:50:30 -0300 |
From: Huang Ying <address@hidden>
qemu_ram_remap() unmaps the specified RAM pages, then re-maps these
pages again. This is used by KVM HWPoison support to clear HWPoisoned
page tables across guest rebooting, so that a new page may be
allocated later to recover the memory error.
[ Jan: style fixlets, WIN32 fix ]
Signed-off-by: Huang Ying <address@hidden>
Signed-off-by: Jan Kiszka <address@hidden>
Signed-off-by: Marcelo Tosatti <address@hidden>
---
cpu-all.h | 4 +++
cpu-common.h | 1 +
exec.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 67 insertions(+), 1 deletions(-)
diff --git a/cpu-all.h b/cpu-all.h
index caf5e6c..4f4631d 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -863,10 +863,14 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env,
target_ulong addr);
extern int phys_ram_fd;
extern ram_addr_t ram_size;
+/* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */
+#define RAM_PREALLOC_MASK (1 << 0)
+
typedef struct RAMBlock {
uint8_t *host;
ram_addr_t offset;
ram_addr_t length;
+ uint32_t flags;
char idstr[256];
QLIST_ENTRY(RAMBlock) next;
#if defined(__linux__) && !defined(TARGET_S390X)
diff --git a/cpu-common.h b/cpu-common.h
index 54d21d4..ef4e8da 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -50,6 +50,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const
char *name,
ram_addr_t size, void *host);
ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size);
void qemu_ram_free(ram_addr_t addr);
+void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
/* This should only be used for ram local to a device. */
void *qemu_get_ram_ptr(ram_addr_t addr);
/* Same but slower, to use for migration, where the order of
diff --git a/exec.c b/exec.c
index 3d78063..723ace4 100644
--- a/exec.c
+++ b/exec.c
@@ -2867,6 +2867,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev,
const char *name,
if (host) {
new_block->host = host;
+ new_block->flags |= RAM_PREALLOC_MASK;
} else {
if (mem_path) {
#if defined (__linux__) && !defined(TARGET_S390X)
@@ -2920,7 +2921,9 @@ void qemu_ram_free(ram_addr_t addr)
QLIST_FOREACH(block, &ram_list.blocks, next) {
if (addr == block->offset) {
QLIST_REMOVE(block, next);
- if (mem_path) {
+ if (block->flags & RAM_PREALLOC_MASK) {
+ ;
+ } else if (mem_path) {
#if defined (__linux__) && !defined(TARGET_S390X)
if (block->fd) {
munmap(block->host, block->length);
@@ -2943,6 +2946,64 @@ void qemu_ram_free(ram_addr_t addr)
}
+#ifndef _WIN32
+void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
+{
+ RAMBlock *block;
+ ram_addr_t offset;
+ int flags;
+ void *area, *vaddr;
+
+ QLIST_FOREACH(block, &ram_list.blocks, next) {
+ offset = addr - block->offset;
+ if (offset < block->length) {
+ vaddr = block->host + offset;
+ if (block->flags & RAM_PREALLOC_MASK) {
+ ;
+ } else {
+ flags = MAP_FIXED;
+ munmap(vaddr, length);
+ if (mem_path) {
+#if defined(__linux__) && !defined(TARGET_S390X)
+ if (block->fd) {
+#ifdef MAP_POPULATE
+ flags |= mem_prealloc ? MAP_POPULATE | MAP_SHARED :
+ MAP_PRIVATE;
+#else
+ flags |= MAP_PRIVATE;
+#endif
+ area = mmap(vaddr, length, PROT_READ | PROT_WRITE,
+ flags, block->fd, offset);
+ } else {
+ flags |= MAP_PRIVATE | MAP_ANONYMOUS;
+ area = mmap(vaddr, length, PROT_READ | PROT_WRITE,
+ flags, -1, 0);
+ }
+#endif
+ } else {
+#if defined(TARGET_S390X) && defined(CONFIG_KVM)
+ flags |= MAP_SHARED | MAP_ANONYMOUS;
+ area = mmap(vaddr, length, PROT_EXEC|PROT_READ|PROT_WRITE,
+ flags, -1, 0);
+#else
+ flags |= MAP_PRIVATE | MAP_ANONYMOUS;
+ area = mmap(vaddr, length, PROT_READ | PROT_WRITE,
+ flags, -1, 0);
+#endif
+ }
+ if (area != vaddr) {
+ fprintf(stderr, "Could not remap addr: address@hidden",
+ length, addr);
+ exit(1);
+ }
+ qemu_madvise(vaddr, length, QEMU_MADV_MERGEABLE);
+ }
+ return;
+ }
+ }
+}
+#endif /* !_WIN32 */
+
/* Return a host pointer to ram allocated with qemu_ram_alloc.
With the exception of the softmmu code in this file, this should
only be used for local memory (e.g. video ram) that the device owns,
--
1.7.4
- [Qemu-devel] [PATCH 02/35] kvm: Fix build warning when KVM_CAP_SET_GUEST_DEBUG is lacking, (continued)
- [Qemu-devel] [PATCH 02/35] kvm: Fix build warning when KVM_CAP_SET_GUEST_DEBUG is lacking, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 04/35] x86: Perform implicit mcg_status reset, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 12/35] x86: Run qemu_inject_x86_mce on target VCPU, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 14/35] kvm: x86: Clean up kvm_setup_mce, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 08/35] Synchronize VCPU states before reset, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 07/35] x86: Optionally avoid injecting AO MCEs while others are pending, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 22/35] kvm: Add in-kernel irqchip awareness to cpu_thread_is_idle, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 03/35] x86: Account for MCE in cpu_has_work, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 06/35] x86: Refine error reporting of MCE injection services, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 24/35] kvm: Mark VCPU state dirty on creation, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 16/35] Add qemu_ram_remap,
Marcelo Tosatti <=
- [Qemu-devel] [PATCH 15/35] kvm: x86: Fail kvm_arch_init_vcpu if MCE initialization fails, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 01/35] kvm: ppc: Fix breakage of kvm_arch_pre_run/process_irqchip_events, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 10/35] kvm: Rename kvm_arch_process_irqchip_events to async_events, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 19/35] x86: Unbreak TCG support for hardware breakpoints, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 17/35] KVM, MCE, unpoison memory address across reboot, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 25/35] x86: Properly reset PAT MSR, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 09/35] kvm: x86: Move MCE functions together, Marcelo Tosatti, 2011/03/15
- [Qemu-devel] [PATCH 21/35] Break up user and system cpu_interrupt implementations, Marcelo Tosatti, 2011/03/15