From: Stefano Stabellini Subject: [PATCH 1/3] xen/balloon: set a mapping for ballooned out pages Date: Sun, 21 Jul 2013 18:32:29 +0100 Message-ID: <1374427951-24126-1-git-send-email-stefano.stabellini@eu.citrix.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: 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.xensource.com Cc: Ian.Campbell@citrix.com, Stefano Stabellini , david.vrabel@citrix.com, alex@alex.org.uk, dcrisan@flexiant.com List-Id: xen-devel@lists.xenproject.org Currently ballooned out pages are mapped to 0 and have INVALID_P2M_ENTRY in the p2m. These ballooned out pages are used to map foreign grants by gntdev and blkback (see alloc_xenballooned_pages). Allocate a page and map all the ballooned out pages to the corresponding mfn. Set the p2m accordingly. This way reading from a ballooned out page won't cause a kernel crash (see http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html). Signed-off-by: Stefano Stabellini CC: alex@alex.org.uk CC: dcrisan@flexiant.com --- drivers/xen/balloon.c | 10 ++++++++-- include/xen/balloon.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 930fb68..91bd599 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -88,6 +88,8 @@ EXPORT_SYMBOL_GPL(balloon_stats); /* We increase/decrease in batches which fit in a page */ static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)]; +struct page* balloon_trade_page; + #ifdef CONFIG_HIGHMEM #define inc_totalhigh_pages() (totalhigh_pages++) @@ -423,7 +425,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) if (xen_pv_domain() && !PageHighMem(page)) { ret = HYPERVISOR_update_va_mapping( (unsigned long)__va(pfn << PAGE_SHIFT), - __pte_ma(0), 0); + pfn_pte(page_to_pfn(balloon_trade_page), PAGE_KERNEL_RO), 0); BUG_ON(ret); } #endif @@ -436,7 +438,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) /* No more mappings: invalidate P2M and add to balloon. */ for (i = 0; i < nr_pages; i++) { pfn = mfn_to_pfn(frame_list[i]); - __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); + __set_phys_to_machine(pfn, pfn_to_mfn(page_to_pfn(balloon_trade_page))); balloon_append(pfn_to_page(pfn)); } @@ -591,6 +593,10 @@ static int __init balloon_init(void) if (!xen_domain()) return -ENODEV; + balloon_trade_page = alloc_page(GFP_KERNEL); + if (balloon_trade_page == NULL) + return -ENOMEM; + pr_info("xen/balloon: Initialising balloon driver.\n"); balloon_stats.current_pages = xen_pv_domain() diff --git a/include/xen/balloon.h b/include/xen/balloon.h index cc2e1a7..5c01a15 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -22,6 +22,7 @@ struct balloon_stats { }; extern struct balloon_stats balloon_stats; +extern struct page *balloon_trade_page; void balloon_set_new_target(unsigned long target); -- 1.7.2.5