Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
To: "Michal Suchánek" <msuchanek@suse.de>
Cc: Petr Tesarik <ptesarik@suse.cz>,
	kexec@lists.infradead.org, Tony Jones <tonyj@suse.com>,
	horms@verge.net.au, hbathini@linux.vnet.ibm.com,
	Dave Young <dyoung@redhat.com>
Subject: Re: [PATCH v5 4/5] kexec: Add option to fall back to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported
Date: Mon, 26 Mar 2018 15:52:39 -0300	[thread overview]
Message-ID: <87in9i3c08.fsf@morokweng.localdomain> (raw)
In-Reply-To: <20180326193810.028a94b5@kitsune.suse.cz>


Michal Suchánek <msuchanek@suse.de> writes:

> On Mon, 26 Mar 2018 17:12:10 +0800
> Dave Young <dyoung@redhat.com> wrote:
>
>> On 03/26/18 at 05:08pm, Dave Young wrote:
>> > On 03/20/18 at 04:56pm, Michal Suchanek wrote:  
>> > > Not all architectures implement KEXEC_FILE_LOAD. However, on some
>> > > archiectures KEXEC_FILE_LOAD is required when secure boot is
>> > > enabled in locked-down mode. Previously users had to select the
>> > > KEXEC_FILE_LOAD syscall with undocumented -s option. However, if
>> > > they did pass the option kexec would fail on architectures that
>> > > do not support it.
>> > > 
>> > > So add an -a option that tries KEXEC_FILE_LOAD and when it is not
>> > > supported tries KEXEC_LOAD.
>> > > 
>> > > Signed-off-by: Michal Suchanek <msuchanek@suse.de>
>> > > ---
>> > > v3: instead of changing the deafult add extra option
>> > > v4: actually check -ENOSYS as well
>> > > v5: add missing break
>> > > ---
>> > >  kexec/kexec.c | 58
>> > > +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
>> > > kexec/kexec.h |  6 +++++- 2 files changed, 58 insertions(+), 6
>> > > deletions(-)
>> > > 
>> > > diff --git a/kexec/kexec.c b/kexec/kexec.c
>> > > index 68ae0594d4a7..44042345a16e 100644
>> > > --- a/kexec/kexec.c
>> > > +++ b/kexec/kexec.c
>> > > @@ -1243,6 +1243,7 @@ int main(int argc, char *argv[])
>> > >  	int do_unload = 0;
>> > >  	int do_reuse_initrd = 0;
>> > >  	int do_kexec_file_syscall = 0;
>> > > +	int do_kexec_fallback = 0;
>> > >  	int do_status = 0;
>> > >  	void *entry = 0;
>> > >  	char *type = 0;
>> > > @@ -1367,6 +1368,15 @@ int main(int argc, char *argv[])
>> > >  			break;
>> > >  		case OPT_KEXEC_FILE_SYSCALL:
>> > >  			do_kexec_file_syscall = 1;
>> > > +			do_kexec_fallback = 0;
>> > > +			break;
>> > > +		case OPT_KEXEC_SYSCALL:
>> > > +			do_kexec_file_syscall = 0;
>> > > +			do_kexec_fallback = 0;
>> > > +			break;
>> > > +		case OPT_KEXEC_SYSCALL_AUTO:
>> > > +			do_kexec_file_syscall = 1;
>> > > +			do_kexec_fallback = 1;
>> > >  			break;
>> > >  		case OPT_STATUS:
>> > >  			do_status = 1;
>> > > @@ -1433,7 +1443,7 @@ int main(int argc, char *argv[])
>> > >  		}
>> > >  	}
>> > >  	if (do_kexec_file_syscall) {
>> > > -		if (do_load_jump_back_helper)
>> > > +		if (do_load_jump_back_helper
>> > > && !do_kexec_fallback) die("--load-jump-back-helper not supported
>> > > with kexec_file_load\n"); if (kexec_flags &
>> > > KEXEC_PRESERVE_CONTEXT) die("--load-preserve-context not
>> > > supported with kexec_file_load\n"); @@ -1447,16 +1457,54 @@ int
>> > > main(int argc, char *argv[]) result = k_status(kexec_flags);
>> > >  	}
>> > >  	if (do_unload) {
>> > > -		if (do_kexec_file_syscall)
>> > > +		if (do_kexec_file_syscall) {
>> > >  			result =
>> > > kexec_file_unload(kexec_file_flags);
>> > > -		else
>> > > +			if ((result == -ENOSYS) &&
>> > > do_kexec_fallback)
>> > > +				do_kexec_file_syscall = 0;
>> > > +		}
>> > > +		if (!do_kexec_file_syscall)
>> > >  			result = k_unload(kexec_flags);
>> > >  	}
>> > >  	if (do_load && (result == 0)) {
>> > > -		if (do_kexec_file_syscall)
>> > > +		if (do_kexec_file_syscall) {
>> > >  			result = do_kexec_file_load(fileind,
>> > > argc, argv, kexec_file_flags);
>> > > -		else
>> > > +			if (do_kexec_fallback) switch (result) {
>> > > +				/*
>> > > +				 * Something failed with
>> > > signature verification.
>> > > +				 * Reject the image.
>> > > +				 */
>> > > +				case -ELIBBAD:
>> > > +				case -EKEYREJECTED:
>> > > +				case -ENOPKG:
>> > > +				case -ENOKEY:
>> > > +				case -EBADMSG:
>> > > +				case -EMSGSIZE:
>> > > +					/*
>> > > +					 * By default reject or
>> > > do nothing if
>> > > +					 * succeded
>> > > +					 */
>> > > +				default: break;
>> > > +				case -ENOSYS: /* not implemented
>> > > */
>> > > +					/*
>> > > +					 * Parsing image or
>> > > other options failed
>> > > +					 * The image may be
>> > > invalid or image
>> > > +					 * type may not
>> > > supported by kernel so
>> > > +					 * retry parsing in
>> > > kexec-tools.
>> > > +					 */
>> > > +				case -EINVAL:
>> > > +				case -ENOEXEC:
>> > > +					 /*
>> > > +					  * ENOTSUPP can be
>> > > unsupported image
>> > > +					  * type or unsupported
>> > > PE signature
>> > > +					  * wrapper type, duh
>> > > +					  */
>> > > +				case -ENOTSUP:  
>> > 
>> > Hmm, this is still used in latest version.  kernel does not return
>> > such error number,  I might not say clearly previously.  Please
>> > check the kernel code, the only one place I know is because no
>> > kdump support in power kexec_file:
>> > arch/powerpc/kernel/machine_kexec_file_64.c
>> > 
>> >         /* We don't support crash kernels yet. */
>> >         if (image->type == KEXEC_TYPE_CRASH)
>> >                 return -ENOTSUPP;
>> > 
>> > So I suggest not checking this as well since -ENOTSUPP is not
>> > populated in userspace headers, and -ENOTSUP is not used at all.
>> > 
>> > Also as I mentioned in another reply -EINVAL and -ENOEXEC is also
>> > not ncessary.
>> > 
>> > For -ENOTSUP, maybe someone can submit a patch to switch to
>> > -ENOTSUPP so that userspace can check it.
>> > Ccing Thiago and Hari for the -ENOTSUPP errno issue.  
>> 
>> Oops for the hurry reply,  I means -ENOTSUPP might be able to replaced
>> with -EOPNOTSUPP, a similar change like this:
>> https://patchwork.kernel.org/patch/8490791/
>
> Thanks for catching this. In Linux ENOTSUPP with extra P is different
> from EOPNOTSUPP and ENOTSUP (single P). Since we are talking to the
> kernel and it returns the double P ENOTSUPP we need to define it in
> kexec as well. And we should check ENOTSUP with single P in case
> somebody some day thinks that returning undefined error codes to
> userspace is not nice like in the patch above.

I wasn't aware that ENOTSUPP was an in-kernel only errno. Should I
submit a patch for the kernel so that powerpc returns -EOPNOTSUPP in
case of trying to load kdump kernel with kexec_file_load()?

-- 
Thiago Jung Bauermann
IBM Linux Technology Center


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

  reply	other threads:[~2018-03-26 18:53 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-26 12:00 [PATCH 1/5] kexec: Return -ENOSYS when kexec does not know how to call KEXEC_FILE_LOAD Michal Suchanek
2018-02-26 12:00 ` [PATCH 2/5] kexec: do not special-case the -s option Michal Suchanek
2018-03-02 12:36   ` Simon Horman
2018-03-02 13:38     ` Michal Suchánek
2018-03-05  6:38       ` Simon Horman
2018-02-26 12:00 ` [PATCH 3/5] kexec: add option to revert -s Michal Suchanek
2018-02-26 12:00 ` [PATCH 4/5] kexec: fallback to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported Michal Suchanek
2018-02-28 13:05   ` Michal Suchánek
2018-03-02  9:17   ` Dave Young
2018-03-05 17:49     ` Michal Suchánek
2018-03-06 13:15     ` [PATCH v4 1/5] kexec: Return -ENOSYS when kexec does not know how to call KEXEC_FILE_LOAD Michal Suchanek
2018-03-06 13:15     ` [PATCH v4 2/5] kexec: do not special-case the -s option Michal Suchanek
2018-03-15 10:38       ` Simon Horman
2018-03-15 11:13         ` Michal Suchánek
2018-03-16 11:20           ` Simon Horman
2018-03-16 11:38             ` Michal Suchánek
2018-03-16 11:47               ` Simon Horman
2018-03-06 13:15     ` [PATCH v4 3/5] kexec: add option to revert -s Michal Suchanek
2018-03-06 13:15     ` [PATCH v4 4/5] kexec: add option to fall back to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported Michal Suchanek
2018-03-13 17:30       ` Tony Jones
2018-03-14  3:44         ` Dave Young
2018-03-14  3:21       ` Dave Young
2018-03-15 11:06         ` Michal Suchánek
2018-03-16  6:45           ` Dave Young
2018-03-16 11:44             ` Michal Suchánek
2018-03-14  3:22       ` Dave Young
2018-03-14  7:23         ` Michal Suchánek
2018-03-14  7:48           ` Dave Young
2018-03-06 13:15     ` [PATCH v4 5/5] kexec: document -s, -c and -a options Michal Suchanek
2018-03-14  3:41       ` Dave Young
2018-03-14  7:25         ` Michal Suchánek
2018-03-14  7:50           ` Dave Young
2018-03-15 11:44             ` Michal Suchánek
2018-03-16  6:51               ` Dave Young
2018-03-16 16:01                 ` Michal Suchánek
2018-03-14  3:43       ` Dave Young
2018-03-15 11:18         ` Michal Suchánek
2018-03-20 15:56     ` [PATCH v5 1/5] kexec: Return -ENOSYS when kexec does not know how to call KEXEC_FILE_LOAD Michal Suchanek
2018-03-26  7:25       ` Simon Horman
2018-03-26  7:53         ` Dave Young
2018-03-26 18:17           ` Michal Suchánek
2018-03-27  9:39             ` Dave Young
2018-03-20 15:56     ` [PATCH v5 2/5] kexec: Fix option checks to take KEXEC_FILE_LOAD into account Michal Suchanek
2018-03-20 15:56     ` [PATCH v5 3/5] kexec: Do not special-case the -s option Michal Suchanek
2018-03-20 15:56     ` [PATCH v5 4/5] kexec: Add option to fall back to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported Michal Suchanek
2018-03-26  9:08       ` Dave Young
2018-03-26  9:12         ` Dave Young
2018-03-26 17:38           ` Michal Suchánek
2018-03-26 18:52             ` Thiago Jung Bauermann [this message]
2018-03-26 19:07               ` Michal Suchánek
2018-03-27  9:59               ` Dave Young
2018-03-28 13:15                 ` [PATCH v6 1/5] kexec: Return -ENOSYS when kexec does not know how to call KEXEC_FILE_LOAD Michal Suchanek
2018-03-28 13:15                   ` [PATCH v6 2/5] kexec: Fix option checks to take KEXEC_FILE_LOAD into account Michal Suchanek
2018-03-28 13:15                   ` [PATCH v6 3/5] kexec: Do not special-case the -s option Michal Suchanek
2018-04-05 11:05                     ` Petr Tesarik
2018-04-09  8:38                       ` Bhupesh Sharma
2018-03-28 13:15                   ` [PATCH v6 4/5] kexec: Add option to revert -s Michal Suchanek
2018-03-28 13:15                   ` [PATCH v6 5/5] kexec: Add option to fall back to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported Michal Suchanek
2018-03-28 13:15                   ` [PATCH 6/6] kexec: Document -s, -c and -a options in the man page Michal Suchanek
2018-03-30  6:29                   ` [PATCH v6 1/5] kexec: Return -ENOSYS when kexec does not know how to call KEXEC_FILE_LOAD Simon Horman
2018-03-30  8:00                     ` Dave Young
2018-03-30  8:46                       ` Simon Horman
2018-03-27 10:06             ` [PATCH v5 4/5] kexec: Add option to fall back to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported Dave Young
2018-03-27 11:01               ` Michal Suchánek
2018-03-27 11:10                 ` Petr Tesarik
2018-03-28  0:53                 ` Dave Young
2018-03-28  7:42                   ` Simon Horman
2018-03-20 15:56     ` [PATCH v5 5/5] kexec: Document -s, -c and -a options Michal Suchanek
2018-03-02  9:24   ` [PATCH 4/5] kexec: fallback to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported Dave Young
2018-03-02 12:32     ` Michal Suchánek
2018-03-02 12:46       ` Simon Horman
2018-03-02 13:28         ` Michal Suchánek
2018-03-02 13:32         ` [PATCH v3 1/5] kexec: Return -ENOSYS when kexec does not know how to call KEXEC_FILE_LOAD Michal Suchanek
2018-03-02 13:33         ` [PATCH v3 2/5] kexec: do not special-case the -s option Michal Suchanek
2018-03-02 13:33         ` [PATCH v3 3/5] kexec: add option to revert -s Michal Suchanek
2018-03-02 13:33         ` [PATCH v3 4/5] kexec: fallback to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported Michal Suchanek
2018-03-02 13:55           ` Michal Suchánek
2018-03-05 12:52           ` [PATCH] kexec: add option to fall back " Michal Suchanek
2018-03-02 13:33         ` [PATCH v3 5/5] kexec: document -s, -c and -a options Michal Suchanek
2018-03-05  1:51         ` [PATCH 4/5] kexec: fallback to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported Dave Young
2018-03-02 12:44   ` Simon Horman
2018-03-13 20:43     ` Michal Suchánek
2018-02-26 12:00 ` [PATCH 5/5] kexec: document -s and -c options Michal Suchanek
2018-03-02 12:34 ` [PATCH 1/5] kexec: Return -ENOSYS when kexec does not know how to call KEXEC_FILE_LOAD Simon Horman
2018-03-02 13:44   ` Michal Suchánek

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=87in9i3c08.fsf@morokweng.localdomain \
    --to=bauerman@linux.vnet.ibm.com \
    --cc=dyoung@redhat.com \
    --cc=hbathini@linux.vnet.ibm.com \
    --cc=horms@verge.net.au \
    --cc=kexec@lists.infradead.org \
    --cc=msuchanek@suse.de \
    --cc=ptesarik@suse.cz \
    --cc=tonyj@suse.com \
    /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