From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/x86: use dynamically adjusted upper bound for contiguous regions Date: Mon, 25 Jul 2011 11:26:37 +0100 Message-ID: <4E2D60FD020000780004F6F9@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part82ADECCD.0__=" Return-path: 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 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. --=__Part82ADECCD.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline After years of not causing problems, the 2Mb (order 9) limit on contiguous regions' size was recently found to prevent booting of certain systems - at least the FC variant of the MPT driver can (possibly only for out-of-tree and/or post-2.6.18 versions) require allocation of a buffer quite a bit larger than 2Mb. Rather than increasing the limit on the order to 10, make the whole logic dynamic - start out with a static order and respective argument buffers large enough to allow initialization up to the point where core_initcall()-s get processed, and from then on dynamically allocate (and re-size) argument buffers on demand. Signed-off-by: Jan Beulich --- a/arch/i386/mm/hypervisor.c +++ b/arch/i386/mm/hypervisor.c @@ -191,17 +191,71 @@ void xen_set_ldt(const void *ptr, unsign } =20 /* Protected by balloon_lock. */ -#define MAX_CONTIG_ORDER 9 /* 2MB */ -static unsigned long discontig_frames[1<=3D 32)) +#else + if (unlikely(order > BITS_PER_LONG - fls(sizeof(*cr_mcl)))) +#endif + return -ENOMEM; + + if (unlikely(order > max_contig_order)) + { + unsigned long *df =3D __vmalloc((sizeof(*discontig_frames) + + sizeof(*cr_mcl)) << = order, + GFP_ATOMIC, PAGE_KERNEL); + unsigned long flags; + + if (!df) { + vfree(df); + return -ENOMEM; + } + balloon_lock(flags); + if (order > max_contig_order) { + void *temp =3D discontig_frames; + + discontig_frames =3D df; + cr_mcl =3D (void *)(df + (1U << order)); + df =3D temp; + + wmb(); + max_contig_order =3D order; + } + balloon_unlock(flags); + vfree(df); + printk(KERN_INFO + "Adjusted maximum contiguous region order to %u\n", + order); + } + + return 0; +} =20 /* Ensure multi-page extents are contiguous in machine memory. */ int xen_create_contiguous_region( unsigned long vstart, unsigned int order, unsigned int address_bits= ) { - unsigned long *in_frames =3D discontig_frames, out_frame; - unsigned long frame, flags; + unsigned long *in_frames, out_frame, frame, flags; unsigned int i; int rc, success; struct xen_memory_exchange exchange =3D { @@ -226,16 +280,19 @@ int xen_create_contiguous_region( if (xen_feature(XENFEAT_auto_translated_physmap)) return 0; =20 - if (unlikely(order > MAX_CONTIG_ORDER)) - return -ENOMEM; + rc =3D check_contig_order(order); + if (unlikely(rc)) + return rc; =20 - set_xen_guest_handle(exchange.in.extent_start, in_frames); set_xen_guest_handle(exchange.out.extent_start, &out_frame); =20 scrub_pages((void *)vstart, 1 << order); =20 balloon_lock(flags); =20 + in_frames =3D discontig_frames; + set_xen_guest_handle(exchange.in.extent_start, in_frames); + /* 1. Zap current PTEs, remembering MFNs. */ for (i =3D 0; i < (1U<> PAGE_SHIFT) + = i); @@ -294,8 +351,7 @@ EXPORT_SYMBOL_GPL(xen_create_contiguous_ =20 void xen_destroy_contiguous_region(unsigned long vstart, unsigned int = order) { - unsigned long *out_frames =3D discontig_frames, in_frame; - unsigned long frame, flags; + unsigned long *out_frames, in_frame, frame, flags; unsigned int i; int rc, success; struct xen_memory_exchange exchange =3D { @@ -314,16 +370,18 @@ void xen_destroy_contiguous_region(unsig if (xen_feature(XENFEAT_auto_translated_physmap)) return; =20 - if (unlikely(order > MAX_CONTIG_ORDER)) + if (unlikely(order > max_contig_order)) return; =20 set_xen_guest_handle(exchange.in.extent_start, &in_frame); - set_xen_guest_handle(exchange.out.extent_start, out_frames); =20 scrub_pages((void *)vstart, 1 << order); =20 balloon_lock(flags); =20 + out_frames =3D discontig_frames; + set_xen_guest_handle(exchange.out.extent_start, out_frames); + /* 1. Find start MFN of contiguous extent. */ in_frame =3D pfn_to_mfn(__pa(vstart) >> PAGE_SHIFT); =20 @@ -384,7 +432,7 @@ EXPORT_SYMBOL_GPL(xen_destroy_contiguous static void undo_limit_pages(struct page *pages, unsigned int order) { BUG_ON(xen_feature(XENFEAT_auto_translated_physmap)); - BUG_ON(order > MAX_CONTIG_ORDER); + BUG_ON(order > max_contig_order); xen_limit_pages_to_max_mfn(pages, order, 0); ClearPageForeign(pages); __free_pages(pages, order); @@ -393,12 +451,11 @@ static void undo_limit_pages(struct page int xen_limit_pages_to_max_mfn( struct page *pages, unsigned int order, unsigned int address_bits) { - unsigned long flags, frame; - unsigned long *in_frames =3D discontig_frames, *out_frames =3D = limited_frames; + unsigned long flags, frame, *limit_map, _limit_map; + unsigned long *in_frames, *out_frames; struct page *page; 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 { @@ -415,23 +472,30 @@ int xen_limit_pages_to_max_mfn( if (xen_feature(XENFEAT_auto_translated_physmap)) return 0; =20 - if (unlikely(order > MAX_CONTIG_ORDER)) - return -ENOMEM; + if (address_bits && address_bits < PAGE_SHIFT) + return -EINVAL; + + rc =3D check_contig_order(order + 1); + if (unlikely(rc)) + return rc; + + if (BITS_PER_LONG >> order) { + limit_map =3D kmalloc(BITS_TO_LONGS(1U << order) + * sizeof(*limit_map), GFP_ATOMIC); + if (unlikely(!limit_map)) + return -ENOMEM; + } else + limit_map =3D &_limit_map; =20 - if (address_bits) { - if (address_bits < PAGE_SHIFT) - return -EINVAL; + if (address_bits) bitmap_zero(limit_map, 1U << order); - } else if (order) { + else if (order) { BUILD_BUG_ON(sizeof(pages->index) !=3D sizeof(*limit_map));= for (i =3D 0; i < BITS_TO_LONGS(1U << order); ++i) limit_map[i] =3D pages[i + 1].index; } else __set_bit(0, limit_map); =20 - set_xen_guest_handle(exchange.in.extent_start, in_frames); - set_xen_guest_handle(exchange.out.extent_start, out_frames); - /* 0. Scrub the pages. */ for (i =3D 0, n =3D 0; i < 1U<= index)); for (i =3D 0; i < BITS_TO_LONGS(1U << order); ++i) @@ -537,7 +606,10 @@ int xen_limit_pages_to_max_mfn( SetPageForeign(pages, undo_limit_pages); } =20 - return 0; + if (limit_map !=3D &_limit_map) + kfree(limit_map); + + return success ? 0 : -ENOMEM; } EXPORT_SYMBOL_GPL(xen_limit_pages_to_max_mfn); =20 --=__Part82ADECCD.0__= Content-Type: text/plain; name="xen-x86-max-contig-order.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-x86-max-contig-order.patch" Subject: x86: use dynamically adjusted upper bound for contiguous = regions=0A=0AAfter years of not causing problems, the 2Mb (order 9) limit = on=0Acontiguous regions' size was recently found to prevent booting = of=0Acertain systems - at least the FC variant of the MPT driver can=0A(pos= sibly only for out-of-tree and/or post-2.6.18 versions) require=0Aallocatio= n of a buffer quite a bit larger than 2Mb.=0A=0ARather than increasing the = limit on the order to 10, make the whole=0Alogic dynamic - start out with = a static order and respective argument=0Abuffers large enough to allow = initialization up to the point where=0Acore_initcall()-s get processed, = and from then on dynamically allocate=0A(and re-size) argument buffers on = demand.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/arch/i386/mm/hypervisor.c=0A+++ b/arch/i386/mm/hypervisor.c=0A@@ -191,17 = +191,71 @@ void xen_set_ldt(const void *ptr, unsign=0A }=0A =0A /* = Protected by balloon_lock. */=0A-#define MAX_CONTIG_ORDER 9 /* 2MB = */=0A-static unsigned long discontig_frames[1<=3D 32))=0A+#else=0A+ if (unlikely(order > BITS_PER_LONG = - fls(sizeof(*cr_mcl))))=0A+#endif=0A+ return -ENOMEM;=0A+=0A+ if = (unlikely(order > max_contig_order))=0A+ {=0A+ unsigned = long *df =3D __vmalloc((sizeof(*discontig_frames)=0A+ = + sizeof(*cr_mcl)) << order,=0A+ = GFP_ATOMIC, PAGE_KERNEL);=0A+ unsigned long flags;=0A+=0A= + if (!df) {=0A+ vfree(df);=0A+ = return -ENOMEM;=0A+ }=0A+ balloon_lock(flags);=0A+ = if (order > max_contig_order) {=0A+ void *temp = =3D discontig_frames;=0A+=0A+ discontig_frames =3D = df;=0A+ cr_mcl =3D (void *)(df + (1U << order));=0A+ = df =3D temp;=0A+=0A+ wmb();=0A+ = max_contig_order =3D order;=0A+ }=0A+ balloon_unlock(flag= s);=0A+ vfree(df);=0A+ printk(KERN_INFO=0A+ = "Adjusted maximum contiguous region order to %u\n",=0A+ = order);=0A+ }=0A+=0A+ return 0;=0A+}=0A =0A /* Ensure multi-page = extents are contiguous in machine memory. */=0A int xen_create_contiguous_r= egion(=0A unsigned long vstart, unsigned int order, unsigned int = address_bits)=0A {=0A- unsigned long *in_frames =3D discontig_frames, = out_frame;=0A- unsigned long frame, flags;=0A+ unsigned long = *in_frames, out_frame, frame, flags;=0A unsigned int i;=0A = int rc, success;=0A struct xen_memory_exchange exchange =3D = {=0A@@ -226,16 +280,19 @@ int xen_create_contiguous_region(=0A if = (xen_feature(XENFEAT_auto_translated_physmap))=0A return = 0;=0A =0A- if (unlikely(order > MAX_CONTIG_ORDER))=0A- = return -ENOMEM;=0A+ rc =3D check_contig_order(order);=0A+ if = (unlikely(rc))=0A+ return rc;=0A =0A- set_xen_guest_handl= e(exchange.in.extent_start, in_frames);=0A set_xen_guest_handle(exchan= ge.out.extent_start, &out_frame);=0A =0A scrub_pages((void = *)vstart, 1 << order);=0A =0A balloon_lock(flags);=0A =0A+ in_frames = =3D discontig_frames;=0A+ set_xen_guest_handle(exchange.in.extent_sta= rt, in_frames);=0A+=0A /* 1. Zap current PTEs, remembering MFNs. */=0A = for (i =3D 0; i < (1U<> PAGE_SHIFT) + i);=0A@@ -294,8 +351,7 @@ = EXPORT_SYMBOL_GPL(xen_create_contiguous_=0A =0A void xen_destroy_contiguous= _region(unsigned long vstart, unsigned int order)=0A {=0A- unsigned = long *out_frames =3D discontig_frames, in_frame;=0A- unsigned long = frame, flags;=0A+ unsigned long *out_frames, in_frame, frame, = flags;=0A unsigned int i;=0A int rc, success;=0A = struct xen_memory_exchange exchange =3D {=0A@@ -314,16 +370,18 @@ void = xen_destroy_contiguous_region(unsig=0A if (xen_feature(XENFEAT_auto_transl= ated_physmap))=0A return;=0A =0A- if (unlikely(order > = MAX_CONTIG_ORDER))=0A+ if (unlikely(order > max_contig_order))=0A = return;=0A =0A set_xen_guest_handle(exchange.in.extent_start, &in_frame);= =0A- set_xen_guest_handle(exchange.out.extent_start, out_frames);=0A = =0A scrub_pages((void *)vstart, 1 << order);=0A =0A balloon_loc= k(flags);=0A =0A+ out_frames =3D discontig_frames;=0A+ set_xen_gue= st_handle(exchange.out.extent_start, out_frames);=0A+=0A /* 1. Find = start MFN of contiguous extent. */=0A in_frame =3D pfn_to_mfn(__pa(vstart= ) >> PAGE_SHIFT);=0A =0A@@ -384,7 +432,7 @@ EXPORT_SYMBOL_GPL(xen_destroy_c= ontiguous=0A static void undo_limit_pages(struct page *pages, unsigned int = order)=0A {=0A BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));=0A- = BUG_ON(order > MAX_CONTIG_ORDER);=0A+ BUG_ON(order > max_contig_order);= =0A xen_limit_pages_to_max_mfn(pages, order, 0);=0A ClearPageFo= reign(pages);=0A __free_pages(pages, order);=0A@@ -393,12 +451,11 = @@ static void undo_limit_pages(struct page=0A int xen_limit_pages_to_max_m= fn(=0A struct page *pages, unsigned int order, unsigned int address_bits)= =0A {=0A- unsigned long flags, frame;=0A- unsigned long *in_frames = =3D discontig_frames, *out_frames =3D limited_frames;=0A+ unsigned = long flags, frame, *limit_map, _limit_map;=0A+ unsigned long *in_frames, = *out_frames;=0A struct page *page;=0A unsigned int i, n, = nr_mcl;=0A int rc, success;=0A- DECLARE_BITMAP(limit_map, 1 << = MAX_CONTIG_ORDER);=0A =0A struct xen_memory_exchange exchange =3D = {=0A .in =3D {=0A@@ -415,23 +472,30 @@ int xen_limit_pages_to_ma= x_mfn(=0A if (xen_feature(XENFEAT_auto_translated_physmap))=0A = return 0;=0A =0A- if (unlikely(order > MAX_CONTIG_ORDER))=0A- = return -ENOMEM;=0A+ if (address_bits && address_bits < PAGE_SHIFT)=0A+ = return -EINVAL;=0A+=0A+ rc =3D check_contig_order(order + 1);=0A+ = if (unlikely(rc))=0A+ return rc;=0A+=0A+ if (BITS_PER_LONG = >> order) {=0A+ limit_map =3D kmalloc(BITS_TO_LONGS(1U << = order)=0A+ * sizeof(*limit_map), = GFP_ATOMIC);=0A+ if (unlikely(!limit_map))=0A+ = return -ENOMEM;=0A+ } else=0A+ limit_map =3D &_limit_map;= =0A =0A- if (address_bits) {=0A- if (address_bits < = PAGE_SHIFT)=0A- return -EINVAL;=0A+ if (address_bits)= =0A bitmap_zero(limit_map, 1U << order);=0A- } else if = (order) {=0A+ else if (order) {=0A BUILD_BUG_ON(sizeof(pages->= index) !=3D sizeof(*limit_map));=0A for (i =3D 0; i < = BITS_TO_LONGS(1U << order); ++i)=0A limit_map[i] =3D = pages[i + 1].index;=0A } else=0A __set_bit(0, limit_map);=0A= =0A- set_xen_guest_handle(exchange.in.extent_start, in_frames);=0A- = set_xen_guest_handle(exchange.out.extent_start, out_frames);=0A-=0A /* = 0. Scrub the pages. */=0A for (i =3D 0, n =3D 0; i < 1U<index));=0A for (i =3D = 0; i < BITS_TO_LONGS(1U << order); ++i)=0A@@ -537,7 +606,10 @@ int = xen_limit_pages_to_max_mfn(=0A SetPageForeign(pages, undo_limit_pa= ges);=0A }=0A =0A- return 0;=0A+ if (limit_map !=3D = &_limit_map)=0A+ kfree(limit_map);=0A+=0A+ return = success ? 0 : -ENOMEM;=0A }=0A EXPORT_SYMBOL_GPL(xen_limit_pages_to_max_mfn= );=0A =0A --=__Part82ADECCD.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.xensource.com http://lists.xensource.com/xen-devel --=__Part82ADECCD.0__=--