From patchwork Mon Jun 13 10:16:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Li X-Patchwork-Id: 9172555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A44DE60573 for ; Mon, 13 Jun 2016 10:23:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9464227C0C for ; Mon, 13 Jun 2016 10:23:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 893B227C0F; Mon, 13 Jun 2016 10:23:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF71422064 for ; Mon, 13 Jun 2016 10:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161123AbcFMKXT (ORCPT ); Mon, 13 Jun 2016 06:23:19 -0400 Received: from mga09.intel.com ([134.134.136.24]:6154 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161049AbcFMKXS (ORCPT ); Mon, 13 Jun 2016 06:23:18 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 13 Jun 2016 03:23:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,466,1459839600"; d="scan'208";a="974471240" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.123]) by orsmga001.jf.intel.com with ESMTP; 13 Jun 2016 03:23:15 -0700 From: Liang Li To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, mst@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, quintela@redhat.com, amit.shah@redhat.com, dgilbert@redhat.com, Liang Li Subject: [QEMU 6/7] kvm: Add two new arch specific functions Date: Mon, 13 Jun 2016 18:16:48 +0800 Message-Id: <1465813009-21390-7-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465813009-21390-1-git-send-email-liang.z.li@intel.com> References: <1465813009-21390-1-git-send-email-liang.z.li@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new function to get the vm's max pfn and a new function to filter out the holes to get a tight free page bitmap. They are implemented on X86, and all the arches should implement them for live migration optimization. Signed-off-by: Liang Li --- include/sysemu/kvm.h | 2 ++ target-arm/kvm.c | 14 ++++++++++++++ target-i386/kvm.c | 35 +++++++++++++++++++++++++++++++++++ target-mips/kvm.c | 14 ++++++++++++++ target-ppc/kvm.c | 14 ++++++++++++++ target-s390x/kvm.c | 14 ++++++++++++++ 6 files changed, 93 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index ad6f837..50915f9 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -230,6 +230,8 @@ int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr, target_ulong len, int type); void kvm_remove_all_breakpoints(CPUState *cpu); int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap); +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap); +unsigned long get_guest_max_pfn(void); #ifndef _WIN32 int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset); #endif diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 83da447..6464542 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -627,3 +627,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { return (data - 32) & 0xffff; } + +unsigned long get_guest_max_pfn(void) +{ + /* To be done */ + + return 0; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + /* To be done */ + + return bmap; +} diff --git a/target-i386/kvm.c b/target-i386/kvm.c index abf50e6..0b394cb 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -3327,3 +3327,38 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +unsigned long get_guest_max_pfn(void) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + ram_addr_t above_4g_mem = pcms->above_4g_mem_size; + unsigned long max_pfn; + + if (above_4g_mem) { + max_pfn = ((1ULL << 32) + above_4g_mem) >> TARGET_PAGE_BITS; + } else { + max_pfn = pcms->below_4g_mem_size >> TARGET_PAGE_BITS; + } + + return max_pfn; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + ram_addr_t above_4g_mem = pcms->above_4g_mem_size; + + if (above_4g_mem) { + unsigned long *src, *dst, len, pos; + ram_addr_t below_4g_mem = pcms->below_4g_mem_size; + src = bmap + ((1ULL << 32) >> TARGET_PAGE_BITS) / BITS_PER_LONG; + dst = bmap + (below_4g_mem >> TARGET_PAGE_BITS) / BITS_PER_LONG; + bitmap_move(dst, src, above_4g_mem >> TARGET_PAGE_BITS); + + pos = (above_4g_mem + below_4g_mem) >> TARGET_PAGE_BITS; + len = ((1ULL << 32) - below_4g_mem) >> TARGET_PAGE_BITS; + bitmap_clear(bmap, pos, len); + } + + return bmap; +} diff --git a/target-mips/kvm.c b/target-mips/kvm.c index a854e4d..89a54e5 100644 --- a/target-mips/kvm.c +++ b/target-mips/kvm.c @@ -1048,3 +1048,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +unsigned long get_guest_max_pfn(void) +{ + /* To be done */ + + return 0; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + /* To be done */ + + return bmap; +} diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 24d6032..e222b31 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -2579,3 +2579,17 @@ int kvmppc_enable_hwrng(void) return kvmppc_enable_hcall(kvm_state, H_RANDOM); } + +unsigned long get_guest_max_pfn(void) +{ + /* To be done */ + + return 0; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + /* To be done */ + + return bmap; +} diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 8f46fd0..893755b 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -2271,3 +2271,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +unsigned long get_guest_max_pfn(void) +{ + /* To be done */ + + return 0; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + /* To be done */ + + return bmap; +}