From patchwork Wed Jul 31 13:11:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 263709 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 589842C00AC for ; Wed, 31 Jul 2013 23:46:17 +1000 (EST) Received: from localhost ([::1]:53859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4WjG-0007Ky-PZ for incoming@patchwork.ozlabs.org; Wed, 31 Jul 2013 09:46:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4Wis-0007JM-7d for qemu-devel@nongnu.org; Wed, 31 Jul 2013 09:45:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4WBS-0006TS-EQ for qemu-devel@nongnu.org; Wed, 31 Jul 2013 09:11:31 -0400 Received: from oxygen.pond.sub.org ([2a01:4f8:121:10e4::3]:60894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4WBR-0006Sp-QY for qemu-devel@nongnu.org; Wed, 31 Jul 2013 09:11:18 -0400 Received: from blackfin.pond.sub.org (p5B32B152.dip0.t-ipconnect.de [91.50.177.82]) by oxygen.pond.sub.org (Postfix) with ESMTPA id AD976A460D; Wed, 31 Jul 2013 15:11:13 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B55C9200BB; Wed, 31 Jul 2013 15:11:12 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2013 15:11:08 +0200 Message-Id: <1375276272-15988-5-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1375276272-15988-1-git-send-email-armbru@redhat.com> References: <1375276272-15988-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:4f8:121:10e4::3 Cc: peter.maydell@linaro.org, stefano.stabellini@eu.citrix.com, mtosatti@redhat.com, agraf@suse.de, borntraeger@de.ibm.com, mkletzan@redhat.com, pbonzini@redhat.com, afaerber@suse.de, rth@twiddle.net Subject: [Qemu-devel] [PATCH v3 for 1.6 4/8] exec: Simplify the guest physical memory allocation hook X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make it a generic hook rather than a KVM hook. Less code and ifdeffery. Since the only user of the hook is old S390 KVM, there's hope we can get rid of it some day. Acked-by: Christian Borntraeger Signed-off-by: Markus Armbruster --- exec.c | 19 +++++++++++++------ include/exec/exec-all.h | 2 ++ include/sysemu/kvm.h | 5 ----- kvm-all.c | 13 ------------- target-s390x/kvm.c | 17 ++++++----------- 5 files changed, 21 insertions(+), 35 deletions(-) diff --git a/exec.c b/exec.c index 4a825fa..dc87cce 100644 --- a/exec.c +++ b/exec.c @@ -761,6 +761,18 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, uint16_t section); static subpage_t *subpage_init(AddressSpace *as, hwaddr base); +static void *(*phys_mem_alloc)(ram_addr_t size) = qemu_anon_ram_alloc; + +/* + * Set a custom physical guest memory alloator. + * Accelerators with unusual needs may need this. Hopefully, we can + * get rid of it eventually. + */ +void phys_mem_set_alloc(void *(*alloc)(ram_addr_t)) +{ + phys_mem_alloc = alloc; +} + static uint16_t phys_section_add(MemoryRegionSection *section) { /* The physical section number is ORed with a page-aligned @@ -1136,12 +1148,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, #endif } if (!new_block->host) { - if (kvm_enabled()) { - /* some s390/kvm configurations have special constraints */ - new_block->host = kvm_ram_alloc(size); - } else { - new_block->host = qemu_anon_ram_alloc(size); - } + new_block->host = phys_mem_alloc(size); memory_try_enable_merging(new_block->host, size); } } diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 5920f73..33b43d2 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -383,6 +383,8 @@ bool is_tcg_gen_code(uintptr_t pc_ptr); #if !defined(CONFIG_USER_ONLY) +void phys_mem_set_alloc(void *(*alloc)(ram_addr_t)); + struct MemoryRegion *iotlb_to_region(hwaddr index); bool io_mem_read(struct MemoryRegion *mr, hwaddr addr, uint64_t *pvalue, unsigned size); diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index de74411..a50a474 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -161,11 +161,6 @@ int kvm_cpu_exec(CPUState *cpu); #ifdef NEED_CPU_H -#if !defined(CONFIG_USER_ONLY) -void *kvm_ram_alloc(ram_addr_t size); -void *kvm_arch_ram_alloc(ram_addr_t size); -#endif - void kvm_setup_guest_memory(void *start, size_t size); void kvm_flush_coalesced_mmio_buffer(void); diff --git a/kvm-all.c b/kvm-all.c index 716860f..971bed8 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1820,19 +1820,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 ab0e2b5..b5351e6 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)) { + phys_mem_set_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) { static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01};