From: Wei Liu Subject: [PATCH RFC] xen/balloon: check whether a page is pointed to scratch page MFN Date: Thu, 5 Sep 2013 11:00:19 +0100 Message-ID: <1378375219-28193-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VHWUA-0003oy-Tk for xen-devel@lists.xenproject.org; Thu, 05 Sep 2013 10:08:23 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: stefano.stabellini@eu.citrix.com, Wei Liu , david.vrabel@citrix.com List-Id: xen-devel@lists.xenproject.org Now that balloon pages might have two kind of P2M entries, a) INVALID_P2M_ENTRY when that page is never used, b) mfn of one of the many ballooned scratch pages. Refelct this in increase_reservation to avoid hitting BUG_ON. Signed-off-by: Wei Liu --- drivers/xen/balloon.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 3101cf6..63a7e5e 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -305,6 +305,24 @@ static enum bp_state reserve_additional_memory(long credit) } #endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ +static bool p2m_is_ballooned_scratch_page(unsigned long pfn) +{ + int cpu; + unsigned long bpfn; + struct page *bpage; + + for_each_possible_cpu(cpu) { + bpage = per_cpu(balloon_scratch_page, cpu); + if (!bpage) + continue; + bpfn = page_to_pfn(bpage); + if (pfn_to_mfn(pfn) == pfn_to_mfn(bpfn)) + return true; + } + + return false; +} + static enum bp_state increase_reservation(unsigned long nr_pages) { int rc; @@ -350,7 +368,8 @@ static enum bp_state increase_reservation(unsigned long nr_pages) pfn = page_to_pfn(page); BUG_ON(!xen_feature(XENFEAT_auto_translated_physmap) && - phys_to_machine_mapping_valid(pfn)); + phys_to_machine_mapping_valid(pfn) && + !p2m_is_ballooned_scratch_page(pfn)); set_phys_to_machine(pfn, frame_list[i]); -- 1.7.10.4