diff mbox

[RFC,4/8] s390: Simplify the RAM allocation hook

Message ID 1371106939-6968-5-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster June 13, 2013, 7:02 a.m. UTC
Less code and ifdeffery.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 exec.c               |  4 ++--
 include/sysemu/kvm.h |  3 +--
 kvm-all.c            | 15 ++-------------
 target-s390x/kvm.c   | 17 ++++++-----------
 4 files changed, 11 insertions(+), 28 deletions(-)

Comments

Andreas Färber June 13, 2013, 8:19 a.m. UTC | #1
Am 13.06.2013 09:02, schrieb Markus Armbruster:
> Less code and ifdeffery.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Andreas Färber <afaerber@suse.de>

Andreas
Paolo Bonzini June 13, 2013, 10:14 p.m. UTC | #2
Il 13/06/2013 03:02, Markus Armbruster ha scritto:
> Less code and ifdeffery.

Less ifdeffery is of course fine, but please add instead
kvm_arch_ram_alloc to the other target-*/kvm.c files.  It can just
return NULL.  I think this may affect the karma that comes from a
negative diffstat, but it is more similar to other kvm_arch_ hooks.

Paolo

> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  exec.c               |  4 ++--
>  include/sysemu/kvm.h |  3 +--
>  kvm-all.c            | 15 ++-------------
>  target-s390x/kvm.c   | 17 ++++++-----------
>  4 files changed, 11 insertions(+), 28 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 4dbb0f1..7552e3c 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1098,9 +1098,9 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
>  #endif
>          }
>          if (!new_block->host) {
> -            if (kvm_enabled()) {
> +            if (kvm_enabled() && kvm_arch_ram_alloc) {
>                  /* some s390/kvm configurations have special constraints */
> -                new_block->host = kvm_ram_alloc(size);
> +                new_block->host = kvm_arch_ram_alloc(size);
>              } else {
>                  new_block->host = qemu_anon_ram_alloc(size);
>              }
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index 8b19322..dd79914 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -152,8 +152,7 @@ int kvm_init_vcpu(CPUState *cpu);
>  int kvm_cpu_exec(CPUArchState *env);
>  
>  #if !defined(CONFIG_USER_ONLY)
> -void *kvm_ram_alloc(ram_addr_t size);
> -void *kvm_arch_ram_alloc(ram_addr_t size);
> +extern void *(*kvm_arch_ram_alloc)(ram_addr_t size);
>  #endif
>  
>  void kvm_setup_guest_memory(void *start, size_t size);
> diff --git a/kvm-all.c b/kvm-all.c
> index 405480e..5e0cc9b 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -119,6 +119,8 @@ static const KVMCapabilityInfo kvm_required_capabilites[] = {
>      KVM_CAP_LAST_INFO
>  };
>  
> +void *(*kvm_arch_ram_alloc)(ram_addr_t size);
> +
>  static KVMSlot *kvm_alloc_slot(KVMState *s)
>  {
>      int i;
> @@ -1816,19 +1818,6 @@ int kvm_has_intx_set_mask(void)
>      return kvm_state->intx_set_mask;
>  }
>  
> -void *kvm_ram_alloc(ram_addr_t size)
> -{
> -#ifdef TARGET_S390X
> -    void *mem;
> -
> -    mem = kvm_arch_ram_alloc(size);
> -    if (mem) {
> -        return mem;
> -    }
> -#endif
> -    return qemu_anon_ram_alloc(size);
> -}
> -
>  void kvm_setup_guest_memory(void *start, size_t size)
>  {
>  #ifdef CONFIG_VALGRIND_H
> diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
> index 862fb12..be802ab 100644
> --- a/target-s390x/kvm.c
> +++ b/target-s390x/kvm.c
> @@ -92,9 +92,15 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
>  
>  static int cap_sync_regs;
>  
> +static void *legacy_s390_alloc(ram_addr_t size);
> +
>  int kvm_arch_init(KVMState *s)
>  {
>      cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
> +    if (!kvm_check_extension(s, KVM_CAP_S390_GMAP)
> +        || !kvm_check_extension(s, KVM_CAP_S390_COW)) {
> +        kvm_arch_ram_alloc = legacy_s390_alloc;
> +    }
>      return 0;
>  }
>  
> @@ -332,17 +338,6 @@ static void *legacy_s390_alloc(ram_addr_t size)
>      return mem;
>  }
>  
> -void *kvm_arch_ram_alloc(ram_addr_t size)
> -{
> -    /* Can we use the standard allocation ? */
> -    if (kvm_check_extension(kvm_state, KVM_CAP_S390_GMAP) &&
> -        kvm_check_extension(kvm_state, KVM_CAP_S390_COW)) {
> -        return NULL;
> -    } else {
> -        return legacy_s390_alloc(size);
> -    }
> -}
> -
>  int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
>  {
>      S390CPU *cpu = S390_CPU(cs);
>
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 4dbb0f1..7552e3c 100644
--- a/exec.c
+++ b/exec.c
@@ -1098,9 +1098,9 @@  ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
 #endif
         }
         if (!new_block->host) {
-            if (kvm_enabled()) {
+            if (kvm_enabled() && kvm_arch_ram_alloc) {
                 /* some s390/kvm configurations have special constraints */
-                new_block->host = kvm_ram_alloc(size);
+                new_block->host = kvm_arch_ram_alloc(size);
             } else {
                 new_block->host = qemu_anon_ram_alloc(size);
             }
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 8b19322..dd79914 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -152,8 +152,7 @@  int kvm_init_vcpu(CPUState *cpu);
 int kvm_cpu_exec(CPUArchState *env);
 
 #if !defined(CONFIG_USER_ONLY)
-void *kvm_ram_alloc(ram_addr_t size);
-void *kvm_arch_ram_alloc(ram_addr_t size);
+extern void *(*kvm_arch_ram_alloc)(ram_addr_t size);
 #endif
 
 void kvm_setup_guest_memory(void *start, size_t size);
diff --git a/kvm-all.c b/kvm-all.c
index 405480e..5e0cc9b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -119,6 +119,8 @@  static const KVMCapabilityInfo kvm_required_capabilites[] = {
     KVM_CAP_LAST_INFO
 };
 
+void *(*kvm_arch_ram_alloc)(ram_addr_t size);
+
 static KVMSlot *kvm_alloc_slot(KVMState *s)
 {
     int i;
@@ -1816,19 +1818,6 @@  int kvm_has_intx_set_mask(void)
     return kvm_state->intx_set_mask;
 }
 
-void *kvm_ram_alloc(ram_addr_t size)
-{
-#ifdef TARGET_S390X
-    void *mem;
-
-    mem = kvm_arch_ram_alloc(size);
-    if (mem) {
-        return mem;
-    }
-#endif
-    return qemu_anon_ram_alloc(size);
-}
-
 void kvm_setup_guest_memory(void *start, size_t size)
 {
 #ifdef CONFIG_VALGRIND_H
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 862fb12..be802ab 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -92,9 +92,15 @@  const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
 
 static int cap_sync_regs;
 
+static void *legacy_s390_alloc(ram_addr_t size);
+
 int kvm_arch_init(KVMState *s)
 {
     cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
+    if (!kvm_check_extension(s, KVM_CAP_S390_GMAP)
+        || !kvm_check_extension(s, KVM_CAP_S390_COW)) {
+        kvm_arch_ram_alloc = legacy_s390_alloc;
+    }
     return 0;
 }
 
@@ -332,17 +338,6 @@  static void *legacy_s390_alloc(ram_addr_t size)
     return mem;
 }
 
-void *kvm_arch_ram_alloc(ram_addr_t size)
-{
-    /* Can we use the standard allocation ? */
-    if (kvm_check_extension(kvm_state, KVM_CAP_S390_GMAP) &&
-        kvm_check_extension(kvm_state, KVM_CAP_S390_COW)) {
-        return NULL;
-    } else {
-        return legacy_s390_alloc(size);
-    }
-}
-
 int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
 {
     S390CPU *cpu = S390_CPU(cs);