public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@verge.net.au>
To: Zhaofeng Li <hello@zhaofeng.li>
Cc: kexec@lists.infradead.org
Subject: Re: [PATCH 3/3] multiboot2: Accept x86-64 images
Date: Mon, 13 Sep 2021 11:17:10 +0200	[thread overview]
Message-ID: <20210913091708.GC11132@vergenet.net> (raw)
In-Reply-To: <20210911024900.1899877-4-hello@zhaofeng.li>

On Fri, Sep 10, 2021 at 07:49:00PM -0700, Zhaofeng Li wrote:
> Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
> ---
>  kexec/arch/i386/kexec-mb2-x86.c  | 34 ++++++++++++++++++++++++++++++--
>  kexec/arch/x86_64/kexec-x86_64.c |  4 ++--
>  2 files changed, 34 insertions(+), 4 deletions(-)
> 
> diff --git a/kexec/arch/i386/kexec-mb2-x86.c b/kexec/arch/i386/kexec-mb2-x86.c
> index 49fcc2d..31b4ce1 100644
> --- a/kexec/arch/i386/kexec-mb2-x86.c
> +++ b/kexec/arch/i386/kexec-mb2-x86.c
> @@ -72,12 +72,42 @@ struct multiboot2_header_info {
>  #define ALIGN_UP(addr, align) \
>  	((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1))
>  
> +static const int probe_debug = 0;
> +
> +static int elf_x86_or_x64_probe(const char *buf, off_t len)

There is a lot of duplication between at least this function,
elf_x86_probe and elf_x86_64_probe. I wonder if there is any value in
reconciling that.

> +{
> +	struct mem_ehdr ehdr;
> +	int result;
> +	result = build_elf_exec_info(buf, len, &ehdr, 0);
> +	if (result < 0) {
> +		if (probe_debug) {
> +			fprintf(stderr, "Not an ELF executable\n");
> +		}
> +		goto out;
> +	}
> +
> +	/* Verify the architecuture specific bits */
> +	if ((ehdr.e_machine != EM_386) && (ehdr.e_machine != EM_486) && (ehdr.e_machine != EM_X86_64)) {

nit: line-wrap please

> +		/* for a different architecture */
> +		if (probe_debug) {
> +			fprintf(stderr, "Not i386 or x86_64 ELF executable\n");
> +		}
> +		result = -1;
> +		goto out;
> +	}
> +	result = 0;
> + out:
> +	free_elf_info(&ehdr);
> +	return result;
> +}
> +
>  int multiboot2_x86_probe(const char *buf, off_t buf_len)
>  /* Is it a good idea to try booting this file? */
>  {
>  	int i, len;
> -	/* First of all, check that this is an ELF file */
> -	if ((i=elf_x86_probe(buf, buf_len)) < 0)
> +
> +	/* First of all, check that this is an ELF file for either x86 or x86-64 */
> +	if ((i=elf_x86_or_x64_probe(buf, buf_len)) < 0)

nit: as we are touching this line could we split the assignment and test of i?

	i = ...;
	if (i < 0)

>  		return i;
>  
>  	/* Now look for a multiboot header. */
> diff --git a/kexec/arch/x86_64/kexec-x86_64.c b/kexec/arch/x86_64/kexec-x86_64.c
> index 394cfca..ffd84f0 100644
> --- a/kexec/arch/x86_64/kexec-x86_64.c
> +++ b/kexec/arch/x86_64/kexec-x86_64.c
> @@ -33,11 +33,11 @@
>  #include <arch/options.h>
>  
>  struct file_type file_type[] = {
> +	{ "multiboot2-x86", multiboot2_x86_probe, multiboot2_x86_load,
> +	  multiboot2_x86_usage },
>  	{ "elf-x86_64", elf_x86_64_probe, elf_x86_64_load, elf_x86_64_usage },
>  	{ "multiboot-x86", multiboot_x86_probe, multiboot_x86_load,
>  	  multiboot_x86_usage },
> -	{ "multiboot2-x86", multiboot2_x86_probe, multiboot2_x86_load,
> -	  multiboot2_x86_usage },
>  	{ "elf-x86", elf_x86_probe, elf_x86_load, elf_x86_usage },
>  	{ "bzImage64", bzImage64_probe, bzImage64_load, bzImage64_usage },
>  	{ "bzImage", bzImage_probe, bzImage_load, bzImage_usage },
> -- 
> 2.32.0
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

      reply	other threads:[~2021-09-13  9:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11  2:48 [PATCH 0/3] kexec-tools: multiboot2: Accept x86-64 images Zhaofeng Li
2021-09-11  2:48 ` [PATCH 1/3] multiboot2: Correct MBI size calculation Zhaofeng Li
2021-09-13  9:17   ` Simon Horman
2021-09-11  2:48 ` [PATCH 2/3] multiboot2: Use rel_min and rel_max for mbi destination Zhaofeng Li
2021-09-13  9:06   ` Simon Horman
2021-09-11  2:49 ` [PATCH 3/3] multiboot2: Accept x86-64 images Zhaofeng Li
2021-09-13  9:17   ` Simon Horman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210913091708.GC11132@vergenet.net \
    --to=horms@verge.net.au \
    --cc=hello@zhaofeng.li \
    --cc=kexec@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox