From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/balloon: don't crash in HVM-with-PoD guests Date: Mon, 20 Jan 2014 09:46:26 +0000 Message-ID: <52DCFE820200007800114F17@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part7447F762.0__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1W5BRB-0004Cp-6M for xen-devel@lists.xenproject.org; Mon, 20 Jan 2014 09:46:33 +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 List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part7447F762.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 989:a7781c0a3b9a ("xen/balloon: fix balloon driver accounting for HVM-with-PoD case") was almost entirely broken - the BUG_ON() there triggers as soon as there's any meaningful amount of excess memory. Re-implement the logic assuming that XENMEM_get_pod_target will at some point be allowed for a domain to query on itself. Basing the calculation on just num_physpages results in significantly too much memory getting balloned out when there's memory beyond the 4G boundary. Using what recent upstream's get_num_physpages() returns is not an alternative because that value is too small (even if not as small as totalram_pages), resulting in not enough pages getting ballooned out. Signed-off-by: Jan Beulich --- a/drivers/xen/balloon/balloon.c +++ b/drivers/xen/balloon/balloon.c @@ -537,17 +537,11 @@ static int __init balloon_init(void) * extent of 1. When start_extent > nr_extents (>=3D in newer = Xen), we * simply get start_extent returned. */ - totalram_bias =3D HYPERVISOR_memory_op(rc !=3D -ENOSYS && rc !=3D = 1 - ? XENMEM_maximum_reservation : XENMEM_current_reservation, - &pod_target.domid); - if ((long)totalram_bias !=3D -ENOSYS) { - BUG_ON(totalram_bias < totalram_pages); - bs.current_pages =3D totalram_bias; - totalram_bias -=3D totalram_pages; - } else { - totalram_bias =3D 0; - bs.current_pages =3D totalram_pages; - } + bs.current_pages =3D pod_target.tot_pages + pod_target.pod_entries + - pod_target.pod_cache_pages; + if (rc || bs.current_pages > num_physpages) + bs.current_pages =3D num_physpages; + totalram_bias =3D bs.current_pages - totalram_pages; #endif bs.target_pages =3D bs.current_pages; bs.balloon_low =3D 0; --=__Part7447F762.0__= Content-Type: text/plain; name="xenlinux-balloon-HVM-PoD.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xenlinux-balloon-HVM-PoD.patch" balloon: don't crash in HVM-with-PoD guests=0A=0A989:a7781c0a3b9a = ("xen/balloon: fix balloon driver accounting for=0AHVM-with-PoD case") was = almost entirely broken - the BUG_ON() there=0Atriggers as soon as there's = any meaningful amount of excess memory.=0A=0ARe-implement the logic = assuming that XENMEM_get_pod_target will at some=0Apoint be allowed for a = domain to query on itself. Basing the=0Acalculation on just num_physpages = results in significantly too much=0Amemory getting balloned out when = there's memory beyond the 4G boundary.=0A=0AUsing what recent upstream's = get_num_physpages() returns is not an=0Aalternative because that value is = too small (even if not as small as=0Atotalram_pages), resulting in not = enough pages getting ballooned out.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/drivers/xen/balloon/balloon.c=0A+++ = b/drivers/xen/balloon/balloon.c=0A@@ -537,17 +537,11 @@ static int __init = balloon_init(void)=0A * extent of 1. When start_extent > nr_extents = (>=3D in newer Xen), we=0A * simply get start_extent returned.=0A = */=0A- totalram_bias =3D HYPERVISOR_memory_op(rc !=3D -ENOSYS && rc !=3D = 1=0A- ? XENMEM_maximum_reservation : XENMEM_current_reservation,= =0A- &pod_target.domid);=0A- if ((long)totalram_bias !=3D = -ENOSYS) {=0A- BUG_ON(totalram_bias < totalram_pages);=0A- = bs.current_pages =3D totalram_bias;=0A- totalram_bias -=3D = totalram_pages;=0A- } else {=0A- totalram_bias =3D 0;=0A- = bs.current_pages =3D totalram_pages;=0A- }=0A+ bs.current_= pages =3D pod_target.tot_pages + pod_target.pod_entries=0A+ = - pod_target.pod_cache_pages;=0A+ if (rc || bs.current_pages > = num_physpages)=0A+ bs.current_pages =3D num_physpages;=0A+ = totalram_bias =3D bs.current_pages - totalram_pages;=0A #endif=0A = bs.target_pages =3D bs.current_pages;=0A bs.balloon_low =3D 0;=0A --=__Part7447F762.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part7447F762.0__=--