From: "Jan Beulich" Subject: [PATCH] linux/x86: fix and improve xen_limit_pages_to_max_mfn() Date: Fri, 08 Feb 2008 15:07:08 +0000 Message-ID: <47AC7E2C.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org - don't do multicall when nr_mcl is zero (and specifically don't access cr_mcl[nr_mcl - 1] in that case) - fix CONFIG_XEN_COMPAT <=3D 0x030002 handling - don't exchange pages already meeting the restriction (likely avoiding exchanging anything at all) - avoid calling kmap functions without CONFIG_XEN_SCRUB_PAGES - eliminate a few local variables As usual, written and tested on 2.6.24 and made apply to the 2.6.18 tree without further testing. Signed-off-by: Jan Beulich Index: head-2008-01-28/arch/i386/mm/hypervisor.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head-2008-01-28.orig/arch/i386/mm/hypervisor.c 2008-02-08 = 11:30:34.000000000 +0100 +++ head-2008-01-28/arch/i386/mm/hypervisor.c 2008-02-08 14:35:09.0000000= 00 +0100 @@ -432,19 +432,17 @@ int xen_limit_pages_to_max_mfn( { unsigned long flags, frame; unsigned long *in_frames =3D discontig_frames, *out_frames =3D = limited_frames; - void *v; struct page *page; - unsigned int i, nr_mcl; + unsigned int i, n, nr_mcl; int rc, success; + DECLARE_BITMAP(limit_map, 1 << MAX_CONTIG_ORDER); =20 struct xen_memory_exchange exchange =3D { .in =3D { - .nr_extents =3D 1UL << order, .extent_order =3D 0, .domid =3D DOMID_SELF }, .out =3D { - .nr_extents =3D 1UL << order, .extent_order =3D 0, .address_bits =3D address_bits, .domid =3D DOMID_SELF @@ -457,80 +455,98 @@ int xen_limit_pages_to_max_mfn( if (unlikely(order > MAX_CONTIG_ORDER)) return -ENOMEM; =20 + bitmap_zero(limit_map, 1U << order); set_xen_guest_handle(exchange.in.extent_start, in_frames); set_xen_guest_handle(exchange.out.extent_start, out_frames); =20 /* 0. Scrub the pages. */ - for ( i =3D 0 ; i < 1UL<> (address_bits - = PAGE_SHIFT))) + continue; + __set_bit(i, limit_map); =20 - if (!PageHighMem(page)) { - v =3D page_address(page); - scrub_pages(v, 1); - } else { - v =3D kmap(page); - scrub_pages(v, 1); + if (!PageHighMem(page)) + scrub_pages(page_address(page), 1); +#ifdef CONFIG_XEN_SCRUB_PAGES + else { + scrub_pages(kmap(page), 1); kunmap(page); + ++n; } +#endif } + if (bitmap_empty(limit_map, 1U << order)) + return 0; =20 - kmap_flush_unused(); + if (n) + kmap_flush_unused(); =20 balloon_lock(flags); =20 /* 1. Zap current PTEs (if any), remembering MFNs. */ - for (i =3D 0, nr_mcl =3D 0; i < (1U<