From: "Jan Beulich" Subject: [PATCH] linux-2.6.18: kexec adjustments Date: Mon, 05 Dec 2011 16:31:35 +0000 Message-ID: <4EDCFFF702000078000657EF@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartFCD363F7.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. --=__PartFCD363F7.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - fix error path after retrieving vmcoreinfo (must no directly return, special casing -EINVAL should only happen if absolutely needed) - improve detection of number of CPUs (utilize platform hypercall) - clean up in error path as far as possible (only after possibly having inserted some or all resources it would be problematic to free the allocated space) - leverage the fact that alloc_bootmem() already clears the memory Signed-off-by: Jan Beulich --- a/drivers/xen/core/machine_kexec.c +++ b/drivers/xen/core/machine_kexec.c @@ -5,6 +5,7 @@ =20 #include #include +#include #include #include =20 @@ -17,7 +18,7 @@ extern void machine_kexec_register_resou =20 static int __initdata xen_max_nr_phys_cpus; static struct resource xen_hypervisor_res; -static struct resource *xen_phys_cpus; +static struct resource *__initdata xen_phys_cpus; =20 size_t vmcoreinfo_size_xen; unsigned long paddr_vmcoreinfo_xen; @@ -25,16 +26,21 @@ unsigned long paddr_vmcoreinfo_xen; void __init xen_machine_kexec_setup_resources(void) { xen_kexec_range_t range; + xen_platform_op_t op; struct resource *res; - int k =3D 0; + unsigned int k =3D 0, nr =3D 0; int rc; =20 if (!is_initial_xendomain()) return; =20 /* determine maximum number of physical cpus */ - - while (1) { + op.cmd =3D XENPF_get_cpuinfo; + op.u.pcpu_info.xen_cpuid =3D 0; + if (HYPERVISOR_platform_op(&op) =3D=3D 0) + k =3D op.u.pcpu_info.max_present + 1; +#if CONFIG_XEN_COMPAT < 0x040000 + else while (1) { memset(&range, 0, sizeof(range)); range.range =3D KEXEC_RANGE_MA_CPU; range.nr =3D k; @@ -44,6 +50,7 @@ void __init xen_machine_kexec_setup_reso =20 k++; } +#endif =20 if (k =3D=3D 0) return; @@ -62,25 +69,27 @@ void __init xen_machine_kexec_setup_reso range.range =3D KEXEC_RANGE_MA_CPU; range.nr =3D k; =20 - if (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, = &range)) - goto err; - - res =3D xen_phys_cpus + k; + if (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range) + || range.size =3D=3D 0) + continue; =20 - memset(res, 0, sizeof(*res)); + res =3D xen_phys_cpus + nr++; res->name =3D "Crash note"; res->start =3D range.start; res->end =3D range.start + range.size - 1; res->flags =3D IORESOURCE_BUSY | IORESOURCE_MEM; } =20 + if (nr =3D=3D 0) + goto free; + /* fill in xen_hypervisor_res with hypervisor machine address = range */ =20 memset(&range, 0, sizeof(range)); range.range =3D KEXEC_RANGE_MA_XEN; =20 if (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range)) - goto err; + goto free; =20 xen_hypervisor_res.name =3D "Hypervisor code and data"; xen_hypervisor_res.start =3D range.start; @@ -93,7 +102,7 @@ void __init xen_machine_kexec_setup_reso range.range =3D KEXEC_RANGE_MA_CRASH; =20 if (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range)) - goto err; + goto free; =20 if (range.size) { crashk_res.start =3D range.start; @@ -118,28 +127,35 @@ void __init xen_machine_kexec_setup_reso vmcoreinfo_size_xen =3D 0; paddr_vmcoreinfo_xen =3D 0; =09 +#if CONFIG_XEN_COMPAT < 0x030300 /* The KEXEC_CMD_kexec_get_range hypercall did not = implement * KEXEC_RANGE_MA_VMCOREINFO until Xen 3.3. * Do not bail out if it fails for this reason. */ if (rc !=3D -EINVAL) - return; +#endif + goto free; } =20 if (machine_kexec_setup_resources(&xen_hypervisor_res, xen_phys_cpu= s, - xen_max_nr_phys_cpus)) + nr)) { + /* + * It's too cumbersome to properly free xen_phys_cpus = here. + * Failure at this stage is unexpected and the amount of + * memory is small therefore we tolerate the potential = leak. + */ goto err; + } + + xen_max_nr_phys_cpus =3D nr; =20 return; =20 + free: + free_bootmem(__pa(xen_phys_cpus), + xen_max_nr_phys_cpus * sizeof(*xen_phys_cpus)); err: - /* - * It isn't possible to free xen_phys_cpus this early in the - * boot. Failure at this stage is unexpected and the amount of - * memory is small therefore we tolerate the potential leak. - */ xen_max_nr_phys_cpus =3D 0; - return; } =20 void __init xen_machine_kexec_register_resources(struct resource *res) --=__PartFCD363F7.0__= Content-Type: text/plain; name="xen-kexec-cleanup.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-kexec-cleanup.patch" kexec adjustments=0A=0A- fix error path after retrieving vmcoreinfo (must = no directly return,=0A special casing -EINVAL should only happen if = absolutely needed)=0A- improve detection of number of CPUs (utilize = platform hypercall)=0A- clean up in error path as far as possible (only = after possibly having=0A inserted some or all resources it would be = problematic to free the=0A allocated space)=0A- leverage the fact that = alloc_bootmem() already clears the memory=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/drivers/xen/core/machine_kexec.c=0A+++ = b/drivers/xen/core/machine_kexec.c=0A@@ -5,6 +5,7 @@=0A =0A #include = =0A #include =0A+#include =0A #include =0A #include =0A = =0A@@ -17,7 +18,7 @@ extern void machine_kexec_register_resou=0A =0A = static int __initdata xen_max_nr_phys_cpus;=0A static struct resource = xen_hypervisor_res;=0A-static struct resource *xen_phys_cpus;=0A+static = struct resource *__initdata xen_phys_cpus;=0A =0A size_t vmcoreinfo_size_xe= n;=0A unsigned long paddr_vmcoreinfo_xen;=0A@@ -25,16 +26,21 @@ unsigned = long paddr_vmcoreinfo_xen;=0A void __init xen_machine_kexec_setup_resources= (void)=0A {=0A xen_kexec_range_t range;=0A+ xen_platform_op_t op;=0A = struct resource *res;=0A- int k =3D 0;=0A+ unsigned int k =3D = 0, nr =3D 0;=0A int rc;=0A =0A if (!is_initial_xendomain())=0A = return;=0A =0A /* determine maximum number of physical cpus = */=0A-=0A- while (1) {=0A+ op.cmd =3D XENPF_get_cpuinfo;=0A+ = op.u.pcpu_info.xen_cpuid =3D 0;=0A+ if (HYPERVISOR_platform_op(&op) = =3D=3D 0)=0A+ k =3D op.u.pcpu_info.max_present + 1;=0A+#if = CONFIG_XEN_COMPAT < 0x040000=0A+ else while (1) {=0A = memset(&range, 0, sizeof(range));=0A range.range =3D KEXEC_RANGE= _MA_CPU;=0A range.nr =3D k;=0A@@ -44,6 +50,7 @@ void __init = xen_machine_kexec_setup_reso=0A =0A k++;=0A }=0A+#endif= =0A =0A if (k =3D=3D 0)=0A return;=0A@@ -62,25 +69,27 = @@ void __init xen_machine_kexec_setup_reso=0A range.range =3D = KEXEC_RANGE_MA_CPU;=0A range.nr =3D k;=0A =0A- if = (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range))=0A- = goto err;=0A-=0A- res =3D xen_phys_cpus + k;=0A+ if = (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range)=0A+ = || range.size =3D=3D 0)=0A+ continue;=0A =0A- = memset(res, 0, sizeof(*res));=0A+ res =3D xen_phys_cpus + = nr++;=0A res->name =3D "Crash note";=0A res->start = =3D range.start;=0A res->end =3D range.start + range.size - = 1;=0A res->flags =3D IORESOURCE_BUSY | IORESOURCE_MEM;=0A = }=0A =0A+ if (nr =3D=3D 0)=0A+ goto free;=0A+=0A /* = fill in xen_hypervisor_res with hypervisor machine address range */=0A =0A = memset(&range, 0, sizeof(range));=0A range.range =3D KEXEC_RANGE= _MA_XEN;=0A =0A if (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, = &range))=0A- goto err;=0A+ goto free;=0A =0A = xen_hypervisor_res.name =3D "Hypervisor code and data";=0A xen_hypervi= sor_res.start =3D range.start;=0A@@ -93,7 +102,7 @@ void __init xen_machine= _kexec_setup_reso=0A range.range =3D KEXEC_RANGE_MA_CRASH;=0A =0A if = (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range))=0A- = goto err;=0A+ goto free;=0A =0A if (range.size) {=0A = crashk_res.start =3D range.start;=0A@@ -118,28 +127,35 @@ void __init = xen_machine_kexec_setup_reso=0A vmcoreinfo_size_xen =3D = 0;=0A paddr_vmcoreinfo_xen =3D 0;=0A =0A+#if CONFIG_XEN_= COMPAT < 0x030300=0A /* The KEXEC_CMD_kexec_get_range hypercall = did not implement=0A * KEXEC_RANGE_MA_VMCOREINFO until Xen = 3.3.=0A * Do not bail out if it fails for this reason.=0A = */=0A if (rc !=3D -EINVAL)=0A- = return;=0A+#endif=0A+ goto free;=0A }=0A =0A if = (machine_kexec_setup_resources(&xen_hypervisor_res, xen_phys_cpus,=0A- = xen_max_nr_phys_cpus))=0A+ = nr)) {=0A+ /*=0A+ * It's too cumbersome to = properly free xen_phys_cpus here.=0A+ * Failure at this stage = is unexpected and the amount of=0A+ * memory is small = therefore we tolerate the potential leak.=0A+ */=0A = goto err;=0A+ }=0A+=0A+ xen_max_nr_phys_cpus =3D nr;=0A =0A = return;=0A =0A+ free:=0A+ free_bootmem(__pa(xen_phys_cpus),=0A+ = xen_max_nr_phys_cpus * sizeof(*xen_phys_cpus));=0A err:=0A- = /*=0A- * It isn't possible to free xen_phys_cpus this early in the=0A- = * boot. Failure at this stage is unexpected and the amount of=0A- * = memory is small therefore we tolerate the potential leak.=0A- = */=0A xen_max_nr_phys_cpus =3D 0;=0A- return;=0A }=0A =0A void __init = xen_machine_kexec_register_resources(struct resource *res)=0A --=__PartFCD363F7.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 --=__PartFCD363F7.0__=--