All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jes Sorensen <jes-sJ/iWh9BUns@public.gmane.org>
To: Avi Kivity <avi-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: "Zhang,
	Xiantao" <xiantao.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Hollis Blanchard
	<hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
	"kvm-ia64-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<kvm-ia64-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also.
Date: Mon, 04 May 2009 11:25:04 +0200	[thread overview]
Message-ID: <49FEB470.3060702@sgi.com> (raw)
In-Reply-To: <49FEAC9A.6060500-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

Avi Kivity wrote:
> Jes Sorensen wrote:
>> +int destroy_region_works = 0;
> 
> Global name, prefix with kvm_.  Does it actually need to be global?

Gone, now local to qemu-kvm-x86.c. I moved the initializer into
kvm_arch_create_context() instead.

> The header depends on target_phys_addr_t, so it must include whatever 
> defines it.

Added an #include "cpu-all.h" which defines it.

> Missing other archs...
> 
> Instead of duplicating this for every arch, you can have a #define that 
> tells you if you want non-trivial arch definitions, and supply the 
> trivial definitions in qemu-kvm.h.

Done, I also added a PPC header file - which may or may not be wanted
at this point. You can just cut it out if you don't think it should be
added.

What do you think of this version then?

Cheers,
Jes



[-- Attachment #2: 0004-qemu-kvm-arch-alias-handling.patch --]
[-- Type: text/x-patch, Size: 7631 bytes --]

Move must_use_aliases_{source,target} functions to qemu-kvm-<arch> and
introduce qemu-kvm-arch.h header files, making it possible to inline
functions that a noops on a given architecture.

This removes a lot of ugly #ifdef TARGET_I386 from qemu-kvm.c

Signed-off-by: Jes Sorensen <jes-sJ/iWh9BUns@public.gmane.org>
---
 qemu-kvm-x86.c              |   25 +++++++++++++++++++-
 qemu-kvm.c                  |   53 +++++++-------------------------------------
 qemu-kvm.h                  |   13 ++++++++++
 target-i386/qemu-kvm-arch.h |   17 ++++++++++++++
 target-ia64/qemu-kvm-arch.h |   14 +++++++++++
 target-ppc/qemu-kvm-arch.h  |   14 +++++++++++
 6 files changed, 91 insertions(+), 45 deletions(-)

Index: qemu-kvm/qemu-kvm-x86.c
===================================================================
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -28,6 +28,8 @@
 
 static int lm_capable_kernel;
 
+static int destroy_region_works = 0;
+
 int kvm_qemu_create_memory_alias(uint64_t phys_start,
                                  uint64_t len,
                                  uint64_t target_phys)
@@ -57,7 +59,10 @@
     for (i = 0; i < kvm_msr_list->nmsrs; ++i)
 	if (kvm_msr_list->indices[i] == MSR_STAR)
 	    kvm_has_msr_star = 1;
-	return 0;
+
+    destroy_region_works = kvm_destroy_memory_region_works(kvm_context);
+
+    return 0;
 }
 
 static void set_msr_entry(struct kvm_msr_entry *entry, uint32_t index,
@@ -856,3 +861,21 @@
     struct ioperm_data *data = _data;
     ioperm(data->start_port, data->num, data->turn_on);
 }
+
+int kvm_arch_must_use_aliases_source(target_phys_addr_t addr)
+{
+    if (destroy_region_works)
+        return false;
+    if (addr == 0xa0000 || addr == 0xa8000)
+        return true;
+    return false;
+}
+
+int kvm_arch_must_use_aliases_target(target_phys_addr_t addr)
+{
+    if (destroy_region_works)
+        return false;
+    if (addr >= 0xe0000000 && addr < 0x100000000ull)
+        return true;
+    return false;
+}
Index: qemu-kvm/qemu-kvm.c
===================================================================
--- qemu-kvm.orig/qemu-kvm.c
+++ qemu-kvm/qemu-kvm.c
@@ -767,10 +767,6 @@
     return 0;
 }
 
-#ifdef TARGET_I386
-static int destroy_region_works = 0;
-#endif
-
 int kvm_qemu_create_context(void)
 {
     int r;
@@ -795,9 +791,6 @@
             return -1;
         }
     }
-#ifdef TARGET_I386
-    destroy_region_works = kvm_destroy_memory_region_works(kvm_context);
-#endif
 
     if (kvm_irqchip && kvm_has_gsi_routing(kvm_context)) {
         kvm_clear_gsi_routes(kvm_context);
@@ -829,24 +822,6 @@
 }
 
 #ifdef TARGET_I386
-static int must_use_aliases_source(target_phys_addr_t addr)
-{
-    if (destroy_region_works)
-        return false;
-    if (addr == 0xa0000 || addr == 0xa8000)
-        return true;
-    return false;
-}
-
-static int must_use_aliases_target(target_phys_addr_t addr)
-{
-    if (destroy_region_works)
-        return false;
-    if (addr >= 0xe0000000 && addr < 0x100000000ull)
-        return true;
-    return false;
-}
-
 static struct mapping {
     target_phys_addr_t phys;
     ram_addr_t ram;
@@ -905,14 +880,13 @@
     area_flags = phys_offset & ~TARGET_PAGE_MASK;
 
     if (area_flags != IO_MEM_RAM) {
-#ifdef TARGET_I386
-        if (must_use_aliases_source(start_addr)) {
+        if (kvm_arch_must_use_aliases_source(start_addr)) {
             kvm_destroy_memory_alias(kvm_context, start_addr);
             return;
         }
-        if (must_use_aliases_target(start_addr))
+        if (kvm_arch_must_use_aliases_target(start_addr))
             return;
-#endif
+
         while (size > 0) {
             p = find_mapping(start_addr);
             if (p) {
@@ -936,8 +910,7 @@
     if (area_flags >= TLB_MMIO)
         return;
 
-#ifdef TARGET_I386
-    if (must_use_aliases_source(start_addr)) {
+    if (kvm_arch_must_use_aliases_source(start_addr)) {
         p = find_ram_mapping(phys_offset);
         if (p) {
             kvm_create_memory_alias(kvm_context, start_addr, size,
@@ -945,7 +918,6 @@
         }
         return;
     }
-#endif
 
     r = kvm_register_phys_mem(kvm_context, start_addr,
                               qemu_get_ram_ptr(phys_offset),
@@ -1256,10 +1228,9 @@
     if (log)
 	kvm_dirty_pages_log_enable_slot(kvm_context, start, size);
     else {
-#ifdef TARGET_I386
-        if (must_use_aliases_target(start))
+        if (kvm_arch_must_use_aliases_target(start))
             return;
-#endif
+
 	kvm_dirty_pages_log_disable_slot(kvm_context, start, size);
     }
 }
@@ -1375,10 +1346,8 @@
 #ifndef TARGET_IA64
     void *buf;
 
-#ifdef TARGET_I386
-    if (must_use_aliases_source(start_addr))
+    if (kvm_arch_must_use_aliases_source(start_addr))
         return;
-#endif
 
     buf = qemu_malloc((end_addr - start_addr) / 8 + 2);
     kvm_get_dirty_pages_range(kvm_context, start_addr, end_addr - start_addr,
@@ -1389,10 +1358,8 @@
 
 int kvm_log_start(target_phys_addr_t phys_addr, target_phys_addr_t len)
 {
-#ifdef TARGET_I386
-    if (must_use_aliases_source(phys_addr))
+    if (kvm_arch_must_use_aliases_source(phys_addr))
         return 0;
-#endif
 
 #ifndef TARGET_IA64
     kvm_qemu_log_memory(phys_addr, len, 1);
@@ -1402,10 +1369,8 @@
 
 int kvm_log_stop(target_phys_addr_t phys_addr, target_phys_addr_t len)
 {
-#ifdef TARGET_I386
-    if (must_use_aliases_source(phys_addr))
+    if (kvm_arch_must_use_aliases_source(phys_addr))
         return 0;
-#endif
 
 #ifndef TARGET_IA64
     kvm_qemu_log_memory(phys_addr, len, 0);
Index: qemu-kvm/qemu-kvm.h
===================================================================
--- qemu-kvm.orig/qemu-kvm.h
+++ qemu-kvm/qemu-kvm.h
@@ -9,6 +9,7 @@
 #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
 
 #include "cpu.h"
+#include "qemu-kvm-arch.h"
 
 #include <signal.h>
 
@@ -233,4 +234,16 @@
     }
 }
 
+#ifdef KVM_ARCH_NO_ADDR_ALIASING
+static inline int kvm_arch_must_use_aliases_source(target_phys_addr_t addr)
+{
+    return 0;
+}
+
+static inline int kvm_arch_must_use_aliases_target(target_phys_addr_t addr)
+{
+    return 0;
+}
+#endif
+
 #endif
Index: qemu-kvm/target-i386/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-i386/qemu-kvm-arch.h
@@ -0,0 +1,17 @@
+/*
+ * qemu/kvm x86 integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 Silicon Graphics Inc.
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#include "cpu-all.h"
+
+extern int kvm_arch_must_use_aliases_source(target_phys_addr_t addr);
+extern int kvm_arch_must_use_aliases_target(target_phys_addr_t addr);
+
+#endif
Index: qemu-kvm/target-ia64/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-ia64/qemu-kvm-arch.h
@@ -0,0 +1,14 @@
+/*
+ * qemu/kvm ia64 integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 SGI
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#define KVM_ARCH_NO_ADDR_ALIASING    1
+
+#endif
Index: qemu-kvm/target-ppc/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-ppc/qemu-kvm-arch.h
@@ -0,0 +1,14 @@
+/*
+ * qemu/kvm PPC integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 SGI
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#define KVM_ARCH_NO_ADDR_ALIASING    1
+
+#endif

WARNING: multiple messages have this Message-ID (diff)
From: Jes Sorensen <jes@sgi.com>
To: Avi Kivity <avi-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: "Zhang,
	Xiantao" <xiantao.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Hollis Blanchard
	<hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
	"kvm-ia64-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<kvm-ia64-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping
Date: Mon, 04 May 2009 09:25:04 +0000	[thread overview]
Message-ID: <49FEB470.3060702@sgi.com> (raw)
In-Reply-To: <49FEAC9A.6060500-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

Avi Kivity wrote:
> Jes Sorensen wrote:
>> +int destroy_region_works = 0;
> 
> Global name, prefix with kvm_.  Does it actually need to be global?

Gone, now local to qemu-kvm-x86.c. I moved the initializer into
kvm_arch_create_context() instead.

> The header depends on target_phys_addr_t, so it must include whatever 
> defines it.

Added an #include "cpu-all.h" which defines it.

> Missing other archs...
> 
> Instead of duplicating this for every arch, you can have a #define that 
> tells you if you want non-trivial arch definitions, and supply the 
> trivial definitions in qemu-kvm.h.

Done, I also added a PPC header file - which may or may not be wanted
at this point. You can just cut it out if you don't think it should be
added.

What do you think of this version then?

Cheers,
Jes



[-- Attachment #2: 0004-qemu-kvm-arch-alias-handling.patch --]
[-- Type: text/x-patch, Size: 7610 bytes --]

Move must_use_aliases_{source,target} functions to qemu-kvm-<arch> and
introduce qemu-kvm-arch.h header files, making it possible to inline
functions that a noops on a given architecture.

This removes a lot of ugly #ifdef TARGET_I386 from qemu-kvm.c

Signed-off-by: Jes Sorensen <jes@sgi.com>
---
 qemu-kvm-x86.c              |   25 +++++++++++++++++++-
 qemu-kvm.c                  |   53 +++++++-------------------------------------
 qemu-kvm.h                  |   13 ++++++++++
 target-i386/qemu-kvm-arch.h |   17 ++++++++++++++
 target-ia64/qemu-kvm-arch.h |   14 +++++++++++
 target-ppc/qemu-kvm-arch.h  |   14 +++++++++++
 6 files changed, 91 insertions(+), 45 deletions(-)

Index: qemu-kvm/qemu-kvm-x86.c
===================================================================
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -28,6 +28,8 @@
 
 static int lm_capable_kernel;
 
+static int destroy_region_works = 0;
+
 int kvm_qemu_create_memory_alias(uint64_t phys_start,
                                  uint64_t len,
                                  uint64_t target_phys)
@@ -57,7 +59,10 @@
     for (i = 0; i < kvm_msr_list->nmsrs; ++i)
 	if (kvm_msr_list->indices[i] == MSR_STAR)
 	    kvm_has_msr_star = 1;
-	return 0;
+
+    destroy_region_works = kvm_destroy_memory_region_works(kvm_context);
+
+    return 0;
 }
 
 static void set_msr_entry(struct kvm_msr_entry *entry, uint32_t index,
@@ -856,3 +861,21 @@
     struct ioperm_data *data = _data;
     ioperm(data->start_port, data->num, data->turn_on);
 }
+
+int kvm_arch_must_use_aliases_source(target_phys_addr_t addr)
+{
+    if (destroy_region_works)
+        return false;
+    if (addr == 0xa0000 || addr == 0xa8000)
+        return true;
+    return false;
+}
+
+int kvm_arch_must_use_aliases_target(target_phys_addr_t addr)
+{
+    if (destroy_region_works)
+        return false;
+    if (addr >= 0xe0000000 && addr < 0x100000000ull)
+        return true;
+    return false;
+}
Index: qemu-kvm/qemu-kvm.c
===================================================================
--- qemu-kvm.orig/qemu-kvm.c
+++ qemu-kvm/qemu-kvm.c
@@ -767,10 +767,6 @@
     return 0;
 }
 
-#ifdef TARGET_I386
-static int destroy_region_works = 0;
-#endif
-
 int kvm_qemu_create_context(void)
 {
     int r;
@@ -795,9 +791,6 @@
             return -1;
         }
     }
-#ifdef TARGET_I386
-    destroy_region_works = kvm_destroy_memory_region_works(kvm_context);
-#endif
 
     if (kvm_irqchip && kvm_has_gsi_routing(kvm_context)) {
         kvm_clear_gsi_routes(kvm_context);
@@ -829,24 +822,6 @@
 }
 
 #ifdef TARGET_I386
-static int must_use_aliases_source(target_phys_addr_t addr)
-{
-    if (destroy_region_works)
-        return false;
-    if (addr == 0xa0000 || addr == 0xa8000)
-        return true;
-    return false;
-}
-
-static int must_use_aliases_target(target_phys_addr_t addr)
-{
-    if (destroy_region_works)
-        return false;
-    if (addr >= 0xe0000000 && addr < 0x100000000ull)
-        return true;
-    return false;
-}
-
 static struct mapping {
     target_phys_addr_t phys;
     ram_addr_t ram;
@@ -905,14 +880,13 @@
     area_flags = phys_offset & ~TARGET_PAGE_MASK;
 
     if (area_flags != IO_MEM_RAM) {
-#ifdef TARGET_I386
-        if (must_use_aliases_source(start_addr)) {
+        if (kvm_arch_must_use_aliases_source(start_addr)) {
             kvm_destroy_memory_alias(kvm_context, start_addr);
             return;
         }
-        if (must_use_aliases_target(start_addr))
+        if (kvm_arch_must_use_aliases_target(start_addr))
             return;
-#endif
+
         while (size > 0) {
             p = find_mapping(start_addr);
             if (p) {
@@ -936,8 +910,7 @@
     if (area_flags >= TLB_MMIO)
         return;
 
-#ifdef TARGET_I386
-    if (must_use_aliases_source(start_addr)) {
+    if (kvm_arch_must_use_aliases_source(start_addr)) {
         p = find_ram_mapping(phys_offset);
         if (p) {
             kvm_create_memory_alias(kvm_context, start_addr, size,
@@ -945,7 +918,6 @@
         }
         return;
     }
-#endif
 
     r = kvm_register_phys_mem(kvm_context, start_addr,
                               qemu_get_ram_ptr(phys_offset),
@@ -1256,10 +1228,9 @@
     if (log)
 	kvm_dirty_pages_log_enable_slot(kvm_context, start, size);
     else {
-#ifdef TARGET_I386
-        if (must_use_aliases_target(start))
+        if (kvm_arch_must_use_aliases_target(start))
             return;
-#endif
+
 	kvm_dirty_pages_log_disable_slot(kvm_context, start, size);
     }
 }
@@ -1375,10 +1346,8 @@
 #ifndef TARGET_IA64
     void *buf;
 
-#ifdef TARGET_I386
-    if (must_use_aliases_source(start_addr))
+    if (kvm_arch_must_use_aliases_source(start_addr))
         return;
-#endif
 
     buf = qemu_malloc((end_addr - start_addr) / 8 + 2);
     kvm_get_dirty_pages_range(kvm_context, start_addr, end_addr - start_addr,
@@ -1389,10 +1358,8 @@
 
 int kvm_log_start(target_phys_addr_t phys_addr, target_phys_addr_t len)
 {
-#ifdef TARGET_I386
-    if (must_use_aliases_source(phys_addr))
+    if (kvm_arch_must_use_aliases_source(phys_addr))
         return 0;
-#endif
 
 #ifndef TARGET_IA64
     kvm_qemu_log_memory(phys_addr, len, 1);
@@ -1402,10 +1369,8 @@
 
 int kvm_log_stop(target_phys_addr_t phys_addr, target_phys_addr_t len)
 {
-#ifdef TARGET_I386
-    if (must_use_aliases_source(phys_addr))
+    if (kvm_arch_must_use_aliases_source(phys_addr))
         return 0;
-#endif
 
 #ifndef TARGET_IA64
     kvm_qemu_log_memory(phys_addr, len, 0);
Index: qemu-kvm/qemu-kvm.h
===================================================================
--- qemu-kvm.orig/qemu-kvm.h
+++ qemu-kvm/qemu-kvm.h
@@ -9,6 +9,7 @@
 #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
 
 #include "cpu.h"
+#include "qemu-kvm-arch.h"
 
 #include <signal.h>
 
@@ -233,4 +234,16 @@
     }
 }
 
+#ifdef KVM_ARCH_NO_ADDR_ALIASING
+static inline int kvm_arch_must_use_aliases_source(target_phys_addr_t addr)
+{
+    return 0;
+}
+
+static inline int kvm_arch_must_use_aliases_target(target_phys_addr_t addr)
+{
+    return 0;
+}
+#endif
+
 #endif
Index: qemu-kvm/target-i386/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-i386/qemu-kvm-arch.h
@@ -0,0 +1,17 @@
+/*
+ * qemu/kvm x86 integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 Silicon Graphics Inc.
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#include "cpu-all.h"
+
+extern int kvm_arch_must_use_aliases_source(target_phys_addr_t addr);
+extern int kvm_arch_must_use_aliases_target(target_phys_addr_t addr);
+
+#endif
Index: qemu-kvm/target-ia64/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-ia64/qemu-kvm-arch.h
@@ -0,0 +1,14 @@
+/*
+ * qemu/kvm ia64 integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 SGI
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#define KVM_ARCH_NO_ADDR_ALIASING    1
+
+#endif
Index: qemu-kvm/target-ppc/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-ppc/qemu-kvm-arch.h
@@ -0,0 +1,14 @@
+/*
+ * qemu/kvm PPC integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 SGI
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#define KVM_ARCH_NO_ADDR_ALIASING    1
+
+#endif

WARNING: multiple messages have this Message-ID (diff)
From: Jes Sorensen <jes@sgi.com>
To: kvm-ia64@vger.kernel.org
Subject: Re: [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping
Date: Mon, 04 May 2009 09:25:04 +0000	[thread overview]
Message-ID: <49FEB470.3060702@sgi.com> (raw)
In-Reply-To: <706158FABBBA044BAD4FE898A02E4BC236A2BC03@pdsmsx503.ccr.corp.intel.com>

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

Avi Kivity wrote:
> Jes Sorensen wrote:
>> +int destroy_region_works = 0;
> 
> Global name, prefix with kvm_.  Does it actually need to be global?

Gone, now local to qemu-kvm-x86.c. I moved the initializer into
kvm_arch_create_context() instead.

> The header depends on target_phys_addr_t, so it must include whatever 
> defines it.

Added an #include "cpu-all.h" which defines it.

> Missing other archs...
> 
> Instead of duplicating this for every arch, you can have a #define that 
> tells you if you want non-trivial arch definitions, and supply the 
> trivial definitions in qemu-kvm.h.

Done, I also added a PPC header file - which may or may not be wanted
at this point. You can just cut it out if you don't think it should be
added.

What do you think of this version then?

Cheers,
Jes



[-- Attachment #2: 0004-qemu-kvm-arch-alias-handling.patch --]
[-- Type: text/x-patch, Size: 7610 bytes --]

Move must_use_aliases_{source,target} functions to qemu-kvm-<arch> and
introduce qemu-kvm-arch.h header files, making it possible to inline
functions that a noops on a given architecture.

This removes a lot of ugly #ifdef TARGET_I386 from qemu-kvm.c

Signed-off-by: Jes Sorensen <jes@sgi.com>
---
 qemu-kvm-x86.c              |   25 +++++++++++++++++++-
 qemu-kvm.c                  |   53 +++++++-------------------------------------
 qemu-kvm.h                  |   13 ++++++++++
 target-i386/qemu-kvm-arch.h |   17 ++++++++++++++
 target-ia64/qemu-kvm-arch.h |   14 +++++++++++
 target-ppc/qemu-kvm-arch.h  |   14 +++++++++++
 6 files changed, 91 insertions(+), 45 deletions(-)

Index: qemu-kvm/qemu-kvm-x86.c
===================================================================
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -28,6 +28,8 @@
 
 static int lm_capable_kernel;
 
+static int destroy_region_works = 0;
+
 int kvm_qemu_create_memory_alias(uint64_t phys_start,
                                  uint64_t len,
                                  uint64_t target_phys)
@@ -57,7 +59,10 @@
     for (i = 0; i < kvm_msr_list->nmsrs; ++i)
 	if (kvm_msr_list->indices[i] == MSR_STAR)
 	    kvm_has_msr_star = 1;
-	return 0;
+
+    destroy_region_works = kvm_destroy_memory_region_works(kvm_context);
+
+    return 0;
 }
 
 static void set_msr_entry(struct kvm_msr_entry *entry, uint32_t index,
@@ -856,3 +861,21 @@
     struct ioperm_data *data = _data;
     ioperm(data->start_port, data->num, data->turn_on);
 }
+
+int kvm_arch_must_use_aliases_source(target_phys_addr_t addr)
+{
+    if (destroy_region_works)
+        return false;
+    if (addr == 0xa0000 || addr == 0xa8000)
+        return true;
+    return false;
+}
+
+int kvm_arch_must_use_aliases_target(target_phys_addr_t addr)
+{
+    if (destroy_region_works)
+        return false;
+    if (addr >= 0xe0000000 && addr < 0x100000000ull)
+        return true;
+    return false;
+}
Index: qemu-kvm/qemu-kvm.c
===================================================================
--- qemu-kvm.orig/qemu-kvm.c
+++ qemu-kvm/qemu-kvm.c
@@ -767,10 +767,6 @@
     return 0;
 }
 
-#ifdef TARGET_I386
-static int destroy_region_works = 0;
-#endif
-
 int kvm_qemu_create_context(void)
 {
     int r;
@@ -795,9 +791,6 @@
             return -1;
         }
     }
-#ifdef TARGET_I386
-    destroy_region_works = kvm_destroy_memory_region_works(kvm_context);
-#endif
 
     if (kvm_irqchip && kvm_has_gsi_routing(kvm_context)) {
         kvm_clear_gsi_routes(kvm_context);
@@ -829,24 +822,6 @@
 }
 
 #ifdef TARGET_I386
-static int must_use_aliases_source(target_phys_addr_t addr)
-{
-    if (destroy_region_works)
-        return false;
-    if (addr == 0xa0000 || addr == 0xa8000)
-        return true;
-    return false;
-}
-
-static int must_use_aliases_target(target_phys_addr_t addr)
-{
-    if (destroy_region_works)
-        return false;
-    if (addr >= 0xe0000000 && addr < 0x100000000ull)
-        return true;
-    return false;
-}
-
 static struct mapping {
     target_phys_addr_t phys;
     ram_addr_t ram;
@@ -905,14 +880,13 @@
     area_flags = phys_offset & ~TARGET_PAGE_MASK;
 
     if (area_flags != IO_MEM_RAM) {
-#ifdef TARGET_I386
-        if (must_use_aliases_source(start_addr)) {
+        if (kvm_arch_must_use_aliases_source(start_addr)) {
             kvm_destroy_memory_alias(kvm_context, start_addr);
             return;
         }
-        if (must_use_aliases_target(start_addr))
+        if (kvm_arch_must_use_aliases_target(start_addr))
             return;
-#endif
+
         while (size > 0) {
             p = find_mapping(start_addr);
             if (p) {
@@ -936,8 +910,7 @@
     if (area_flags >= TLB_MMIO)
         return;
 
-#ifdef TARGET_I386
-    if (must_use_aliases_source(start_addr)) {
+    if (kvm_arch_must_use_aliases_source(start_addr)) {
         p = find_ram_mapping(phys_offset);
         if (p) {
             kvm_create_memory_alias(kvm_context, start_addr, size,
@@ -945,7 +918,6 @@
         }
         return;
     }
-#endif
 
     r = kvm_register_phys_mem(kvm_context, start_addr,
                               qemu_get_ram_ptr(phys_offset),
@@ -1256,10 +1228,9 @@
     if (log)
 	kvm_dirty_pages_log_enable_slot(kvm_context, start, size);
     else {
-#ifdef TARGET_I386
-        if (must_use_aliases_target(start))
+        if (kvm_arch_must_use_aliases_target(start))
             return;
-#endif
+
 	kvm_dirty_pages_log_disable_slot(kvm_context, start, size);
     }
 }
@@ -1375,10 +1346,8 @@
 #ifndef TARGET_IA64
     void *buf;
 
-#ifdef TARGET_I386
-    if (must_use_aliases_source(start_addr))
+    if (kvm_arch_must_use_aliases_source(start_addr))
         return;
-#endif
 
     buf = qemu_malloc((end_addr - start_addr) / 8 + 2);
     kvm_get_dirty_pages_range(kvm_context, start_addr, end_addr - start_addr,
@@ -1389,10 +1358,8 @@
 
 int kvm_log_start(target_phys_addr_t phys_addr, target_phys_addr_t len)
 {
-#ifdef TARGET_I386
-    if (must_use_aliases_source(phys_addr))
+    if (kvm_arch_must_use_aliases_source(phys_addr))
         return 0;
-#endif
 
 #ifndef TARGET_IA64
     kvm_qemu_log_memory(phys_addr, len, 1);
@@ -1402,10 +1369,8 @@
 
 int kvm_log_stop(target_phys_addr_t phys_addr, target_phys_addr_t len)
 {
-#ifdef TARGET_I386
-    if (must_use_aliases_source(phys_addr))
+    if (kvm_arch_must_use_aliases_source(phys_addr))
         return 0;
-#endif
 
 #ifndef TARGET_IA64
     kvm_qemu_log_memory(phys_addr, len, 0);
Index: qemu-kvm/qemu-kvm.h
===================================================================
--- qemu-kvm.orig/qemu-kvm.h
+++ qemu-kvm/qemu-kvm.h
@@ -9,6 +9,7 @@
 #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
 
 #include "cpu.h"
+#include "qemu-kvm-arch.h"
 
 #include <signal.h>
 
@@ -233,4 +234,16 @@
     }
 }
 
+#ifdef KVM_ARCH_NO_ADDR_ALIASING
+static inline int kvm_arch_must_use_aliases_source(target_phys_addr_t addr)
+{
+    return 0;
+}
+
+static inline int kvm_arch_must_use_aliases_target(target_phys_addr_t addr)
+{
+    return 0;
+}
+#endif
+
 #endif
Index: qemu-kvm/target-i386/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-i386/qemu-kvm-arch.h
@@ -0,0 +1,17 @@
+/*
+ * qemu/kvm x86 integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 Silicon Graphics Inc.
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#include "cpu-all.h"
+
+extern int kvm_arch_must_use_aliases_source(target_phys_addr_t addr);
+extern int kvm_arch_must_use_aliases_target(target_phys_addr_t addr);
+
+#endif
Index: qemu-kvm/target-ia64/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-ia64/qemu-kvm-arch.h
@@ -0,0 +1,14 @@
+/*
+ * qemu/kvm ia64 integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 SGI
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#define KVM_ARCH_NO_ADDR_ALIASING    1
+
+#endif
Index: qemu-kvm/target-ppc/qemu-kvm-arch.h
===================================================================
--- /dev/null
+++ qemu-kvm/target-ppc/qemu-kvm-arch.h
@@ -0,0 +1,14 @@
+/*
+ * qemu/kvm PPC integration
+ *
+ * Copyright (C) 2006-2008 Qumranet Technologies
+ * Copyright (C) 2009 SGI
+ *
+ * Licensed under the terms of the GNU GPL version 2 or higher.
+ */
+#ifndef QEMU_KVM_ARCH_H
+#define QEMU_KVM_ARCH_H
+
+#define KVM_ARCH_NO_ADDR_ALIASING    1
+
+#endif

  parent reply	other threads:[~2009-05-04  9:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-28  9:29 [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Zhang, Xiantao
2009-04-28  9:29 ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping Zhang, Xiantao
2009-04-28  9:39 ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Avi Kivity
2009-04-28  9:39   ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping Avi Kivity
2009-04-28  9:39   ` Avi Kivity
2009-04-29 14:59   ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Jes Sorensen
2009-04-29 14:59     ` Jes Sorensen
2009-04-29 14:59     ` Jes Sorensen
2009-04-29 15:04   ` Jes Sorensen
2009-04-29 15:04     ` Re: [PATCH 04/04] qemu-kvm: other archs should maintain memory Jes Sorensen
2009-04-29 15:04     ` Jes Sorensen
2009-05-04  8:51     ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Avi Kivity
2009-05-04  8:51       ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping Avi Kivity
2009-05-04  8:51       ` Avi Kivity
     [not found]       ` <49FEAC9A.6060500-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2009-05-04  9:25         ` Jes Sorensen [this message]
2009-05-04  9:25           ` Jes Sorensen
2009-05-04  9:25           ` Jes Sorensen
2009-05-04 21:57           ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mappingalso Hollis Blanchard
2009-05-04 21:57             ` [PATCH 04/04] qemu-kvm: other archs should maintain memory Hollis Blanchard
2009-05-04 21:57             ` Hollis Blanchard
     [not found]   ` <49F6CED2.1060202-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2009-04-29 15:06     ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Jes Sorensen
2009-04-29 15:06       ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping Jes Sorensen
2009-04-29 15:06       ` Jes Sorensen
     [not found]       ` <49FEAE3A.2070001@redhat.com>
2009-05-04  8:59         ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Avi Kivity
2009-05-04  8:59           ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping Avi Kivity
2009-05-04  8:59           ` Avi Kivity
2009-05-04  9:17           ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Jes Sorensen
2009-05-04  9:17             ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping Jes Sorensen
2009-05-04  9:17             ` Jes Sorensen
2009-05-11 10:15 ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Zhang, Xiantao
2009-05-11 10:15   ` [PATCH 04/04] qemu-kvm: other archs should maintain memory Zhang, Xiantao
2009-05-11 11:18   ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping also Jes Sorensen
2009-05-11 11:18     ` [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping Jes Sorensen

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=49FEB470.3060702@sgi.com \
    --to=jes-sj/iwh9buns@public.gmane.org \
    --cc=avi-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    --cc=kvm-ia64-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=xiantao.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.