2008/11/1 Simon Horman <span dir="ltr"><<a href="mailto:horms@verge.net.au">horms@verge.net.au</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Fri, Oct 31, 2008 at 09:53:23AM +0300, Maxim Uvarov wrote:<br>
> 2008/10/31 Simon Horman <<a href="mailto:horms@verge.net.au">horms@verge.net.au</a>><br>
><br>
> > Hi,<br>
> ><br>
> > Could someone please comment on the satus of this patch?<br>
> ><br>
> Hello, Simon<br>
><br>
> I can not reproduce error which you wrote before on my target. So it is a<br>
> little bit<br>
> difficult to say what was wrong exactly.<br>
<br>
</div>Hi,<br>
<br>
the version of the patch below (which I think is the latest)<br>
compiles fine for me. I wanted to confirm that you<br>
and Chandru are happy for it to be merged.<br>
<br>
If so, could you please provide a short descripton for the change-log<br>
and a Signed-off-by line.</blockquote><div>Patch looks good.<br> </div>Description is:<br>
Do not count max_memory_range for allocation. Increase allocation buffers<br>
when it is needed. This actually allows us to avoid a lot of troubles with<br>
various device-tree files.<br>
<br>
Signed-off-by: Maxim Uvarov <<a href="mailto:muvarov@gmail.com">muvarov@gmail.com</a>><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
Thanks<br>
<div class="Ih2E3d"><br>
> > On Wed, Oct 15, 2008 at 12:46:24PM +0400, Maxim Uvarov wrote:<br>
> > > Patch corrected. ( git_kexec_powerpc_v2.patch is attached.)<br>
> > ><br>
> > > I tested it on ppc64 pasemi electra board. Both kexec -l and kexec -p<br>
> > works.<br>
> > ><br>
> > > Maxim.<br>
> ><br>
</div><div><div></div><div class="Wj3C7c">> > > diff --git a/kexec/arch/ppc64/kexec-ppc64.c<br>
> > b/kexec/arch/ppc64/kexec-ppc64.c<br>
> > > index 069a9fc..0ad40fa 100644<br>
> > > --- a/kexec/arch/ppc64/kexec-ppc64.c<br>
> > > +++ b/kexec/arch/ppc64/kexec-ppc64.c<br>
> > > @@ -96,96 +96,46 @@ err1:<br>
> > ><br>
> > > }<br>
> > ><br>
> > > -static int count_dyn_reconf_memory_ranges(void)<br>
> > > +static int realloc_memory_ranges()<br>
> > > {<br>
> > > - char device_tree[] = "/proc/device-tree/";<br>
> > > - char fname[128];<br>
> > > - char buf[32];<br>
> > > - FILE *file;<br>
> > > -<br>
> > > - strcpy(fname, device_tree);<br>
> > > - strcat(fname, "ibm,dynamic-reconfiguration-memory/ibm,lmb-size");<br>
> > > - if ((file = fopen(fname, "r")) == NULL) {<br>
> > > - perror(fname);<br>
> > > - return -1;<br>
> > > - }<br>
> > > + size_t memory_range_len;<br>
> > ><br>
> > > - if (fread(buf, 1, 8, file) < 0) {<br>
> > > - perror(fname);<br>
> > > - fclose(file);<br>
> > > - return -1;<br>
> > > - }<br>
> > > -<br>
> > > - lmb_size = ((uint64_t *)buf)[0];<br>
> > > - fclose(file);<br>
> > > + max_memory_ranges++;<br>
> > > + memory_range_len = sizeof(struct memory_range) * max_memory_ranges;<br>
> > ><br>
> > > - /* Get number of lmbs from ibm,dynamic-memory */<br>
> > > - strcpy(fname, device_tree);<br>
> > > - strcat(fname,<br>
> > "ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory");<br>
> > > - if ((file = fopen(fname, "r")) == NULL) {<br>
> > > - perror(fname);<br>
> > > - return -1;<br>
> > > - }<br>
> > > - /*<br>
> > > - * first 4 bytes provide number of entries(lmbs)<br>
> > > - */<br>
> > > - if (fread(buf, 1, 4, file) < 0) {<br>
> > > - perror(fname);<br>
> > > - fclose(file);<br>
> > > - return -1;<br>
> > > - }<br>
> > > - num_of_lmbs = ((unsigned int *)buf)[0];<br>
> > > - max_memory_ranges += num_of_lmbs;<br>
> > > - fclose(file);<br>
> > > + memory_range = (struct memory_range *) realloc(memory_range,<br>
> > memory_range_len);<br>
> > > + if (!memory_range)<br>
> > > + goto err;<br>
> > ><br>
> > > - return 0;<br>
> > > -}<br>
> > > + base_memory_range = (struct memory_range *) realloc(memory_range,<br>
> > memory_range_len);<br>
> > > + if (!base_memory_range)<br>
> > > + goto err;<br>
> > ><br>
> > > -/*<br>
> > > - * Count the memory nodes under /proc/device-tree and populate the<br>
> > > - * max_memory_ranges variable. This variable replaces MAX_MEMORY_RANGES<br>
> > > - * macro used earlier.<br>
> > > - */<br>
> > > -static int count_memory_ranges(void)<br>
> > > -{<br>
> > > - char device_tree[256] = "/proc/device-tree/";<br>
> > > - struct dirent *dentry;<br>
> > > - DIR *dir;<br>
> > > + exclude_range = (struct memory_range *) realloc(exclude_range,<br>
> > memory_range_len);<br>
> > > + if (!exclude_range)<br>
> > > + goto err;<br>
> > ><br>
> > > - if ((dir = opendir(device_tree)) == NULL) {<br>
> > > - perror(device_tree);<br>
> > > - return -1;<br>
> > > - }<br>
> > > + usablemem_rgns.ranges = (struct memory_range *)<br>
> > > + realloc(usablemem_rgns.ranges,<br>
> > memory_range_len);<br>
> > > + if (!(usablemem_rgns.ranges))<br>
> > > + goto err;<br>
> > ><br>
> > > - while ((dentry = readdir(dir)) != NULL) {<br>
> > > - if (!strncmp(dentry->d_name,<br>
> > > - "ibm,dynamic-reconfiguration-memory", 35)){<br>
> > > - if (count_dyn_reconf_memory_ranges() != 0)<br>
> > > - return -1;<br>
> > > - continue;<br>
> > > - }<br>
> > > + return 0;<br>
> > ><br>
> > > - if (strncmp(dentry->d_name, "memory@", 7) &&<br>
> > > - strcmp(dentry->d_name, "memory") &&<br>
> > > - strncmp(dentry->d_name, "pci@", 4))<br>
> > > - continue;<br>
> > > - max_memory_ranges++;<br>
> > > - }<br>
> > > - /* need to add extra region for retained initrd */<br>
> > > - if (reuse_initrd) {<br>
> > > - max_memory_ranges++;<br>
> > > - }<br>
> > > +err:<br>
> > > + fprintf(stderr, "memory range structure re-allocation failure\n");<br>
> > > + return -1;<br>
> > > +}<br>
> > ><br>
> > > - closedir(dir);<br>
> > ><br>
> > > - return 0;<br>
> > > -}<br>
> > > static void add_base_memory_range(uint64_t start, uint64_t end)<br>
> > > {<br>
> > > base_memory_range[nr_memory_ranges].start = start;<br>
> > > base_memory_range[nr_memory_ranges].end = end;<br>
> > > base_memory_range[nr_memory_ranges].type = RANGE_RAM;<br>
> > > nr_memory_ranges++;<br>
> > > + if (nr_memory_ranges >= max_memory_ranges)<br>
> > > + realloc_memory_ranges();<br>
> > ><br>
> > > dbgprintf("%016llx-%016llx : %x\n",<br>
> > > base_memory_range[nr_memory_ranges-1].start,<br>
> > > @@ -300,8 +250,8 @@ static int get_base_ranges(void)<br>
> > > return -1;<br>
> > > }<br>
> > > if (nr_memory_ranges >= max_memory_ranges) {<br>
> > > - fclose(file);<br>
> > > - break;<br>
> > > + if (realloc_memory_ranges() < 0)<br>
> > > + break;<br>
> > > }<br>
> > > start = ((uint64_t *)buf)[0];<br>
> > > end = start + ((uint64_t *)buf)[1];<br>
> > > @@ -396,6 +346,8 @@ static int get_devtree_details(unsigned long<br>
> > kexec_flags)<br>
> > > exclude_range[i].start = 0x0UL;<br>
> > > exclude_range[i].end = kernel_end;<br>
> > > i++;<br>
> > > + if (i >= max_memory_ranges)<br>
> > > + realloc_memory_ranges();<br>
> > ><br>
> > > if (kexec_flags & KEXEC_ON_CRASH) {<br>
> > > memset(fname, 0, sizeof(fname));<br>
> > > @@ -470,6 +422,8 @@ static int get_devtree_details(unsigned long<br>
> > kexec_flags)<br>
> > > exclude_range[i].start = htab_base;<br>
> > > exclude_range[i].end = htab_base + htab_size;<br>
> > > i++;<br>
> > > + if (i >= max_memory_ranges)<br>
> > > + realloc_memory_ranges();<br>
> > ><br>
> > > /* reserve the initrd_start and end locations. */<br>
> > > if (reuse_initrd) {<br>
> > > @@ -545,6 +499,8 @@ static int get_devtree_details(unsigned long<br>
> > kexec_flags)<br>
> > > exclude_range[i].start = rtas_base;<br>
> > > exclude_range[i].end = rtas_base + rtas_size;<br>
> > > i++;<br>
> > > + if (i >= max_memory_ranges)<br>
> > > + realloc_memory_ranges();<br>
> > > if (kexec_flags & KEXEC_ON_CRASH)<br>
> > > add_usable_mem_rgns(rtas_base, rtas_size);<br>
> > > } /* rtas */<br>
> > > @@ -740,9 +696,10 @@ out:<br>
> > > /* Return a list of valid memory ranges */<br>
> > > int get_memory_ranges(struct memory_range **range, int *ranges,<br>
> > > unsigned long kexec_flags)<br>
> > > -{<br>
> > > - if (count_memory_ranges())<br>
> > > - return -1;<br>
> > > +{<br>
> > > + /* allocate memory_range dynamically */<br>
> > > + max_memory_ranges = 1;<br>
> > > +<br>
> > > if (alloc_memory_ranges())<br>
> > > return -1;<br>
> > > if (setup_memory_ranges(kexec_flags))<br>
> ><br>
> ><br>
> > --<br>
> > Simon Horman<br>
> > VA Linux Systems Japan K.K., Sydney, Australia Satellite Office<br>
> > H: <a href="http://www.vergenet.net/%7Ehorms/" target="_blank">www.vergenet.net/~horms/</a> <<a href="http://www.vergenet.net/%7Ehorms/" target="_blank">http://www.vergenet.net/%7Ehorms/</a>><br>
> > W: <a href="http://www.valinux.co.jp/en" target="_blank">www.valinux.co.jp/en</a><br>
> ><br>
> ><br>
><br>
><br>
> --<br>
> Best regards,<br>
> Maxim Uvarov<br>
<br>
</div></div>--<br>
<div><div></div><div class="Wj3C7c">Simon Horman<br>
VA Linux Systems Japan K.K., Sydney, Australia Satellite Office<br>
H: <a href="http://www.vergenet.net/%7Ehorms/" target="_blank">www.vergenet.net/~horms/</a> W: <a href="http://www.valinux.co.jp/en" target="_blank">www.valinux.co.jp/en</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Maxim Uvarov<br>