[PATCH 07/11] kexec_file: Simplify kexec_purgatory_setup_sechdrs 1

kbuild test robot lkp at intel.com
Wed Feb 28 14:49:30 PST 2018


Hi Philipp,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.16-rc3 next-20180228]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Philipp-Rudo/kexec_file-Clean-up-purgatory-load/20180228-223538
config: x86_64-randconfig-s4-03010216 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

Note: the linux-review/Philipp-Rudo/kexec_file-Clean-up-purgatory-load/20180228-223538 HEAD 28c77b126e4b2796074bd704e2370a38beb037c1 builds fine.
      It only hurts bisectibility.

All errors (new ones prefixed by >>):

   kernel/kexec_file.c: In function 'kexec_purgatory_setup_sechdrs':
>> kernel/kexec_file.c:798:3: error: expected ';' before '}' token
      }
      ^

vim +798 kernel/kexec_file.c

   713	
   714	/*
   715	 * kexec_purgatory_setup_sechdrs - prepares the pi->sechdrs buffer.
   716	 * @pi:		Purgatory to be loaded.
   717	 * @kbuf:	Buffer prepared to store purgatory.
   718	 *
   719	 * Allocates the memory needed for the buffer. Caller is responsible to free
   720	 * the memory after use.
   721	 *
   722	 * Return: 0 on success, negative errno on error.
   723	 */
   724	static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi,
   725						 struct kexec_buf *kbuf)
   726	{
   727		unsigned long curr_load_addr;
   728		unsigned long load_addr;
   729		unsigned long bss_addr;
   730		unsigned long offset;
   731		unsigned char *buf_addr;
   732		unsigned char *src;
   733		Elf_Shdr *sechdrs;
   734		int i;
   735	
   736		sechdrs = vzalloc(pi->ehdr->e_shnum * sizeof(Elf_Shdr));
   737		if (!sechdrs)
   738			return -ENOMEM;
   739		memcpy(sechdrs, (void *)pi->ehdr + pi->ehdr->e_shoff,
   740		       pi->ehdr->e_shnum * sizeof(Elf_Shdr));
   741		pi->sechdrs = sechdrs;
   742	
   743		/*
   744		 * We seem to have multiple copies of sections. First copy is which
   745		 * is embedded in kernel in read only section. Some of these sections
   746		 * will be copied to a temporary buffer and relocated. And these
   747		 * sections will finally be copied to their final destination at
   748		 * segment load time.
   749		 *
   750		 * Use ->sh_offset to reflect section address in memory. It will
   751		 * point to original read only copy if section is not allocatable.
   752		 * Otherwise it will point to temporary copy which will be relocated.
   753		 *
   754		 * Use ->sh_addr to contain final address of the section where it
   755		 * will go during execution time.
   756		 */
   757		for (i = 0; i < pi->ehdr->e_shnum; i++) {
   758			if (sechdrs[i].sh_type == SHT_NOBITS)
   759				continue;
   760	
   761			sechdrs[i].sh_offset = (unsigned long)pi->ehdr +
   762							sechdrs[i].sh_offset;
   763		}
   764	
   765		/* Load SHF_ALLOC sections */
   766		buf_addr = kbuf->buffer;
   767		load_addr = curr_load_addr = kbuf->mem;
   768		bss_addr = load_addr + kbuf->bufsz;
   769		kbuf->image->start = pi->ehdr->e_entry;
   770	
   771		for (i = 0; i < pi->ehdr->e_shnum; i++) {
   772			unsigned long align;
   773	
   774			if (!(sechdrs[i].sh_flags & SHF_ALLOC))
   775				continue;
   776	
   777			align = sechdrs[i].sh_addralign;
   778	
   779			if (sechdrs[i].sh_type == SHT_NOBITS) {
   780				bss_addr = ALIGN(bss_addr, align);
   781				sechdrs[i].sh_addr = bss_addr;
   782				bss_addr += sechdrs[i].sh_size;
   783				continue;
   784			}
   785	
   786			curr_load_addr = ALIGN(curr_load_addr, align);
   787			offset = curr_load_addr - load_addr;
   788			/* We already modifed ->sh_offset to keep src addr */
   789			src = (char *)sechdrs[i].sh_offset;
   790			memcpy(buf_addr + offset, src, sechdrs[i].sh_size);
   791	
   792			if (sechdrs[i].sh_flags & SHF_EXECINSTR &&
   793			    pi->ehdr->e_entry >= sechdrs[i].sh_addr &&
   794			    pi->ehdr->e_entry < (sechdrs[i].sh_addr
   795						 + sechdrs[i].sh_size)) {
   796				kbuf->image->start -= sechdrs[i].sh_addr;
   797				kbuf->image->start += curr_load_addr
 > 798			}
   799	
   800			/* Store load address and source address of section */
   801			sechdrs[i].sh_addr = curr_load_addr;
   802	
   803			/*
   804			 * This section got copied to temporary buffer. Update
   805			 * ->sh_offset accordingly.
   806			 */
   807			sechdrs[i].sh_offset = (unsigned long)(buf_addr + offset);
   808	
   809			/* Advance to the next address */
   810			curr_load_addr += sechdrs[i].sh_size;
   811		}
   812	
   813		return 0;
   814	}
   815	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 30838 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/kexec/attachments/20180301/dbacac4f/attachment-0001.gz>


More information about the kexec mailing list