2008/10/31 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;">
Hi,<br>
<br>
Could someone please comment on the satus of this patch?<br>
<div><div></div><div class="Wj3C7c"></div></div></blockquote><div>Hello, Simon<br><br>I can not reproduce error which you wrote before on my target. So it is a little bit<br>difficult to say what was wrong exactly.<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div class="Wj3C7c"><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 works.<br>
><br>
> Maxim.<br>
><br>
><br>
><br>
> 2008/10/15 Simon Horman <<a href="mailto:horms@verge.net.au">horms@verge.net.au</a>><br>
><br>
> > On Tue, Oct 14, 2008 at 07:11:19PM +0400, Maxim Uvarov wrote:<br>
> > > Hello all,<br>
> > ><br>
> > > As you all know it is not easy to count exact value of memory ranges from<br>
> > > device tree on powerpc.<br>
> > > It very depends on how dts file was written. What do you think about<br>
> > really<br>
> > > dynamic allocation buffers<br>
> > > for this buffers?<br>
> ><br>
> > Conceptually I have no objections to the change,<br>
> > though I would like to get some review from ppc people.<br>
> > (<a href="mailto:linuxppc-dev@ozlabs.org">linuxppc-dev@ozlabs.org</a> CCed)<br>
> ><br>
> > > Patch is attached.<br>
> ><br>
> > This patch doesn't seem to compile for me.<br>
> ><br>
> > # powerpc64-unknown-linux-gnu-gcc --version<br>
> > powerpc64-unknown-linux-gnu-gcc (GCC) 4.1.1<br>
> > Copyright (C) 2006 Free Software Foundation, Inc.<br>
> > This is free software; see the source for copying conditions. There is NO<br>
> > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.<br>
> ><br>
> > #make<br>
> > [snip]<br>
> > kexec/arch/ppc64/kexec-ppc64.c:100: warning: function declaration isn't a<br>
> > prototype<br>
> > kexec/arch/ppc64/kexec-ppc64.c: In function 'realloc_memory_ranges':<br>
> > kexec/arch/ppc64/kexec-ppc64.c:107: warning: passing argument 1 of<br>
> > 'realloc' makes pointer from integer without a cast<br>
> > kexec/arch/ppc64/kexec-ppc64.c:107: error: too few arguments to function<br>
> > 'realloc'<br>
> > kexec/arch/ppc64/kexec-ppc64.c:102: warning: unused variable 'tmp'<br>
> ><br>
> > --<br>
> > Simon Horman<br>
> > VA Linux Systems Japan K.K., Sydney, Australia Satellite Office<br>
</div></div>> > 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>
<div class="Ih2E3d">> > 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>> diff --git a/kexec/arch/ppc64/kexec-ppc64.c 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, "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, 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, 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, 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, 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 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 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 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>
<font color="#888888"><br>
<br>
--<br>
</font><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>