* [PATCH] kexec: fix kexec_file_load fallback error handling
@ 2026-08-14 7:53 Mukesh Pilaniya
2026-08-21 19:14 ` Bradley Morgan
0 siblings, 1 reply; 6+ messages in thread
From: Mukesh Pilaniya @ 2026-08-14 7:53 UTC (permalink / raw)
To: kexec, Philipp Rudo, Tao Liu, Simon Horman; +Cc: Mukesh pilaniya
With the default -a (--kexec-syscall-auto) option, kexec-tools first
tries kexec_file_load() and falls back to kexec_load() when the syscall
is not implemented (ENOSYS) or the kernel does not have a loader for the
image format (ENOEXEC/ENOTSUP). With -s (--kexec-file-syscall),
kexec-tools uses only kexec_file_load() and does not fall back.
Falling back on EINVAL hides the real error, because EINVAL means
something went wrong during loading.
Remove EINVAL from the fallback path. Print the actual errno for
ENOEXEC/ENOTSUP before falling back and track it so the final message
distinguishes a missing syscall from other failures.
Several kexec_file_load() image probe functions incorrectly return
-EINVAL rather than -ENOEXEC when encountering an unrecognized image
format. This kernel patch fixes the issue:
https://lore.kernel.org/all/20260813-mpilaniy-v1-1-777d4d0e30f7@redhat.com/
Signed-off-by: Mukesh Pilaniya <mpilaniy@redhat.com>
Reviewed-by: Tao Liu <ltao@redhat.com>
Reviewed-by: Philipp Rudo <prudo@redhat.com>
---
kernel patch:
https://lore.kernel.org/all/20260813-mpilaniy-v1-1-777d4d0e30f7@redhat.com/
---
kexec/kexec.c | 63 ++++++++++++++++++++++++++++++++++++---------------
1 file changed, 45 insertions(+), 18 deletions(-)
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 4a49ad4..0726996 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -68,6 +68,8 @@ int do_hotplug = 0;
static unsigned long kexec_flags = 0;
/* Flags for kexec file (fd) based syscall */
static unsigned long kexec_file_flags = 0;
+/* errno from kexec_file_load when it returned EFALLBACK */
+static int kexec_file_load_errno;
/* initrd detected in probe phase */
int implicit_initrd_fd = -1;
int kexec_debug = 0;
@@ -869,12 +871,16 @@ static int my_load(const char *type, int fileind, int argc, char **argv,
info.nr_segments, info.segment,
info.kexec_flags);
if (result != 0) {
- /* The load failed, print some debugging information */
- fprintf(stderr, "kexec_load failed: %s\n",
- strerror(errno));
- fprintf(stderr, "entry = %p flags = 0x%lx\n",
- info.entry, info.kexec_flags);
- print_segments(stderr, &info);
+ if (errno == ENOSYS) {
+ fprintf(stderr,
+ "syscall kexec_load is not available on this system.\n");
+ } else {
+ fprintf(stderr, "kexec_load failed: %s\n",
+ strerror(errno));
+ fprintf(stderr, "entry = %p flags = 0x%lx\n",
+ info.entry, info.kexec_flags);
+ print_segments(stderr, &info);
+ }
}
return result;
}
@@ -883,12 +889,15 @@ static int kexec_file_unload(unsigned long kexec_file_flags)
{
int ret = 0;
- if (!is_kexec_file_load_implemented())
+ if (!is_kexec_file_load_implemented()) {
+ kexec_file_load_errno = ENOSYS;
return EFALLBACK;
+ }
ret = kexec_file_load(-1, -1, 0, NULL, kexec_file_flags);
if (ret != 0) {
if (errno == ENOSYS) {
+ kexec_file_load_errno = ENOSYS;
ret = EFALLBACK;
} else {
/*
@@ -919,9 +928,12 @@ static int k_unload (unsigned long kexec_flags)
else
result = kexec_load(NULL, 0, NULL, kexec_flags);
if (result != 0) {
- /* The unload failed, print some debugging information */
- fprintf(stderr, "kexec unload failed: %s\n",
- strerror(errno));
+ if (errno == ENOSYS)
+ fprintf(stderr,
+ "syscall kexec_load is not available on this system.\n");
+ else
+ fprintf(stderr, "kexec unload failed: %s\n",
+ strerror(errno));
}
return result;
}
@@ -1336,8 +1348,10 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
info.kernel_fd = -1;
info.initrd_fd = -1;
- if (!is_kexec_file_load_implemented())
+ if (!is_kexec_file_load_implemented()) {
+ kexec_file_load_errno = ENOSYS;
return EFALLBACK;
+ }
if (argc - fileind <= 0) {
fprintf(stderr, "No kernel specified\n");
@@ -1441,13 +1455,14 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
/* Not implemented. */
case ENOSYS:
+ kexec_file_load_errno = ENOSYS;
+ ret = EFALLBACK;
+ break;
+
/*
- * 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.
+ * The kernel does not have a loader for this
+ * image format, retry parsing in kexec-tools.
*/
- case EINVAL:
case ENOEXEC:
/*
* ENOTSUP can be unsupported image
@@ -1455,6 +1470,9 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
* wrapper type, duh.
*/
case ENOTSUP:
+ kexec_file_load_errno = errno;
+ fprintf(stderr, "kexec_file_load failed: %s\n",
+ strerror(errno));
ret = EFALLBACK;
break;
}
@@ -1823,8 +1841,17 @@ int main(int argc, char *argv[])
if ((result == 0) && do_load_jump_back_helper) {
result = my_load_jump_back_helper(kexec_flags, entry);
}
- if (result == EFALLBACK)
- fputs("syscall kexec_file_load not available.\n", stderr);
+ /*
+ * When fallback to kexec_load was attempted, my_load()
+ * already reported the kexec_load error and overwrote
+ * result with its own return value, so this condition
+ * is only true when no fallback was attempted and
+ * kexec_file_load does not exist.
+ */
+ if (result == EFALLBACK && kexec_file_load_errno == ENOSYS) {
+ fputs("syscall kexec_file_load is not available on this system.\n",
+ stderr);
+ }
fflush(stdout);
fflush(stderr);
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] kexec: fix kexec_file_load fallback error handling
2026-08-14 7:53 [PATCH] kexec: fix kexec_file_load fallback error handling Mukesh Pilaniya
@ 2026-08-21 19:14 ` Bradley Morgan
2026-08-24 11:03 ` Mukesh Pilaniya
0 siblings, 1 reply; 6+ messages in thread
From: Bradley Morgan @ 2026-08-21 19:14 UTC (permalink / raw)
To: mpilaniy; +Cc: horms, kexec, ltao, prudo
On 14 August 2026 08:53:29 BST, Mukesh Pilaniya <mpilaniy@redhat.com>
wrote:
>With the default -a (--kexec-syscall-auto) option, kexec-tools first
>tries kexec_file_load() and falls back to kexec_load() when the syscall
>is not implemented (ENOSYS) or the kernel does not have a loader for the
>image format (ENOEXEC/ENOTSUP). [...] Falling back on EINVAL hides the
>real error, because EINVAL means something went wrong during loading.
>
>Remove EINVAL from the fallback path.
Hiding the real error behind a fallback is exactly what makes this one
hurt to debug, so good direction.
>Several kexec_file_load() image probe functions incorrectly return
>-EINVAL rather than -ENOEXEC when encountering an unrecognized image
>format. This kernel patch fixes the issue:
>https://lore.kernel.org/all/20260813-mpilaniy-v1-1-777d4d0e30f7@redhat.com/
That one is still being reworked, Pratyush just LGTM'd the
probe_default change a couple days ago and the fix isn't in any tree
yet. And until it is, the arm64 probe and the riscv image probe still
return -EINVAL, and that last errno is what kexec_image_probe_default()
leaks to userspace (I checked the loader lists in the tree). So if this
lands on tools before the kernel fix lands, an image that used to
silently fall back to kexec_load() on those arches now just fails with
EINVAL.
Is the plan to hold this one until the kernel side is in? Because right
now it looks like it can race ahead of its dependency.
>Print the actual errno for ENOEXEC/ENOTSUP before falling back
Good, that is the part that makes the s390 command line case visible.
The my_load/k_unload ENOSYS message hunks are unrelated cosmetics, fine
but could be their own patch if you feel like splitting.
Its a good patch, I just want the ordering question answered first.
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] kexec: fix kexec_file_load fallback error handling
2026-08-21 19:14 ` Bradley Morgan
@ 2026-08-24 11:03 ` Mukesh Pilaniya
2026-11-27 13:18 ` [PATCH kexec-tools] " Mukesh Pilaniya
0 siblings, 1 reply; 6+ messages in thread
From: Mukesh Pilaniya @ 2026-08-24 11:03 UTC (permalink / raw)
To: Bradley Morgan; +Cc: horms, kexec, ltao, prudo
Hi Bradley, thanks for review.
On 22/08/26 12:44 am, Bradley Morgan wrote:
> On 14 August 2026 08:53:29 BST, Mukesh Pilaniya <mpilaniy@redhat.com>
> wrote:
>> With the default -a (--kexec-syscall-auto) option, kexec-tools first
>> tries kexec_file_load() and falls back to kexec_load() when the syscall
>> is not implemented (ENOSYS) or the kernel does not have a loader for the
>> image format (ENOEXEC/ENOTSUP). [...] Falling back on EINVAL hides the
>> real error, because EINVAL means something went wrong during loading.
>>
>> Remove EINVAL from the fallback path.
>
> Hiding the real error behind a fallback is exactly what makes this one
> hurt to debug, so good direction.
>
>> Several kexec_file_load() image probe functions incorrectly return
>> -EINVAL rather than -ENOEXEC when encountering an unrecognized image
>> format. This kernel patch fixes the issue:
>> https://lore.kernel.org/all/20260813-mpilaniy-v1-1-777d4d0e30f7@redhat.com/
>
> That one is still being reworked, Pratyush just LGTM'd the
> probe_default change a couple days ago and the fix isn't in any tree
> yet. And until it is, the arm64 probe and the riscv image probe still
> return -EINVAL, and that last errno is what kexec_image_probe_default()
> leaks to userspace (I checked the loader lists in the tree). So if this
> lands on tools before the kernel fix lands, an image that used to
> silently fall back to kexec_load() on those arches now just fails with
> EINVAL.
>
> Is the plan to hold this one until the kernel side is in? Because right
> now it looks like it can race ahead of its dependency.
>
Yes, the kernel patch will merge first, then this one. I will follow up
on the same thread once the kernel fix is merged.
>> Print the actual errno for ENOEXEC/ENOTSUP before falling back
>
> Good, that is the part that makes the s390 command line case visible.
>
> The my_load/k_unload ENOSYS message hunks are unrelated cosmetics, fine
> but could be their own patch if you feel like splitting.
>
The my_load/k_unload ENOSYS hunks are not just cosmetic, they address a
misleading error output. Today, when kexec_load is absent, my_load dumps
the entry pointer, flags, and all segments, which is debug noise for
what is simply an unsupported syscall. Similar, k_unload prints "kexec
unload failed: Function not implemented", which reads like something
went wrong rather than the syscall not being available.
I'm happy to split this if you'd prefer, but since they're small and
directly related to the error-path cleanup, I kept them together.
> Its a good patch, I just want the ordering question answered first.
>
> Thanks!
--
Regards,
Mukesh Pilaniya
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH kexec-tools] kexec: fix kexec_file_load fallback error handling
2026-08-24 11:03 ` Mukesh Pilaniya
@ 2026-11-27 13:18 ` Mukesh Pilaniya
2026-11-27 16:08 ` Bradley Morgan
0 siblings, 1 reply; 6+ messages in thread
From: Mukesh Pilaniya @ 2026-11-27 13:18 UTC (permalink / raw)
To: Bradley Morgan, Simon Horman; +Cc: horms, kexec, ltao, prudo
Hi Bradley,
On 24/08/26 4:33 pm, Mukesh Pilaniya wrote:
> Hi Bradley, thanks for review.
>
> On 22/08/26 12:44 am, Bradley Morgan wrote:
>> On 14 August 2026 08:53:29 BST, Mukesh Pilaniya <mpilaniy@redhat.com>
>> wrote:
>>> With the default -a (--kexec-syscall-auto) option, kexec-tools first
>>> tries kexec_file_load() and falls back to kexec_load() when the syscall
>>> is not implemented (ENOSYS) or the kernel does not have a loader for the
>>> image format (ENOEXEC/ENOTSUP). [...] Falling back on EINVAL hides the
>>> real error, because EINVAL means something went wrong during loading.
>>>
>>> Remove EINVAL from the fallback path.
>>
>> Hiding the real error behind a fallback is exactly what makes this one
>> hurt to debug, so good direction.
>>
>>> Several kexec_file_load() image probe functions incorrectly return
>>> -EINVAL rather than -ENOEXEC when encountering an unrecognized image
>>> format. This kernel patch fixes the issue:
>>> https://lore.kernel.org/all/20260813-mpilaniy-v1-1-777d4d0e30f7@redhat.com/
>>
>> That one is still being reworked, Pratyush just LGTM'd the
>> probe_default change a couple days ago and the fix isn't in any tree
>> yet. And until it is, the arm64 probe and the riscv image probe still
>> return -EINVAL, and that last errno is what kexec_image_probe_default()
>> leaks to userspace (I checked the loader lists in the tree). So if this
>> lands on tools before the kernel fix lands, an image that used to
>> silently fall back to kexec_load() on those arches now just fails with
>> EINVAL.
>>
>> Is the plan to hold this one until the kernel side is in? Because right
>> now it looks like it can race ahead of its dependency.
>>
> Yes, the kernel patch will merge first, then this one. I will follow up
> on the same thread once the kernel fix is merged.
Both kernel commits (b7c94f4d096 and 2792b4b15f) have been merged
upstream from Linux v7.4-rc1 onward, so this change should be good to
merge as well.
>
>>> Print the actual errno for ENOEXEC/ENOTSUP before falling back
>>
>> Good, that is the part that makes the s390 command line case visible.
>>
>> The my_load/k_unload ENOSYS message hunks are unrelated cosmetics, fine
>> but could be their own patch if you feel like splitting.
>>
> The my_load/k_unload ENOSYS hunks are not just cosmetic, they address a
> misleading error output. Today, when kexec_load is absent, my_load dumps
> the entry pointer, flags, and all segments, which is debug noise for
> what is simply an unsupported syscall. Similar, k_unload prints "kexec
> unload failed: Function not implemented", which reads like something
> went wrong rather than the syscall not being available.
>
> I'm happy to split this if you'd prefer, but since they're small and
> directly related to the error-path cleanup, I kept them together.
>
>> Its a good patch, I just want the ordering question answered first.
>>
>> Thanks!
>
--
Regards,
Mukesh Pilaniya
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH kexec-tools] kexec: fix kexec_file_load fallback error handling
2026-11-27 13:18 ` [PATCH kexec-tools] " Mukesh Pilaniya
@ 2026-11-27 16:08 ` Bradley Morgan
2026-12-01 20:04 ` Simon Horman
0 siblings, 1 reply; 6+ messages in thread
From: Bradley Morgan @ 2026-11-27 16:08 UTC (permalink / raw)
To: mpilaniy; +Cc: horms, include, kexec, ltao, prudo
On 27 November 2026 13:18:57 GMT, Mukesh Pilaniya <mpilaniy@redhat.com>
wrote:
>Hi Bradley,
>
>On 24/08/26 4:33 pm, Mukesh Pilaniya wrote:
>> Hi Bradley, thanks for review.
>>
>> On 22/08/26 12:44 am, Bradley Morgan wrote:
>>> On 14 August 2026 08:53:29 BST, Mukesh Pilaniya <mpilaniy@redhat.com>
>>> wrote:
>>>> With the default -a (--kexec-syscall-auto) option, kexec-tools first
>>>> tries kexec_file_load() and falls back to kexec_load() when the
>syscall
>>>> is not implemented (ENOSYS) or the kernel does not have a loader for
>the
>>>> image format (ENOEXEC/ENOTSUP). [...] Falling back on EINVAL hides the
>>>> real error, because EINVAL means something went wrong during loading.
>>>>
>>>> Remove EINVAL from the fallback path.
>>>
>>> Hiding the real error behind a fallback is exactly what makes this one
>>> hurt to debug, so good direction.
>>>
>>>> Several kexec_file_load() image probe functions incorrectly return
>>>> -EINVAL rather than -ENOEXEC when encountering an unrecognized image
>>>> format. This kernel patch fixes the issue:
>>>>
>https://lore.kernel.org/all/20260813-mpilaniy-v1-1-777d4d0e30f7@redhat.com/
>>>
>>> That one is still being reworked, Pratyush just LGTM'd the
>>> probe_default change a couple days ago and the fix isn't in any tree
>>> yet. And until it is, the arm64 probe and the riscv image probe still
>>> return -EINVAL, and that last errno is what kexec_image_probe_default()
>>> leaks to userspace (I checked the loader lists in the tree). So if this
>>> lands on tools before the kernel fix lands, an image that used to
>>> silently fall back to kexec_load() on those arches now just fails with
>>> EINVAL.
>>>
>>> Is the plan to hold this one until the kernel side is in? Because right
>>> now it looks like it can race ahead of its dependency.
>>>
>> Yes, the kernel patch will merge first, then this one. I will follow up
>> on the same thread once the kernel fix is merged.
>Both kernel commits (b7c94f4d096 and 2792b4b15f) have been merged
>upstream from Linux v7.4-rc1 onward, so this change should be good to
>merge as well.
Thx!
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
>
>>
>>>> Print the actual errno for ENOEXEC/ENOTSUP before falling back
>>>
>>> Good, that is the part that makes the s390 command line case visible.
>>>
>>> The my_load/k_unload ENOSYS message hunks are unrelated cosmetics, fine
>>> but could be their own patch if you feel like splitting.
>>>
>> The my_load/k_unload ENOSYS hunks are not just cosmetic, they address a
>> misleading error output. Today, when kexec_load is absent, my_load dumps
>> the entry pointer, flags, and all segments, which is debug noise for
>> what is simply an unsupported syscall. Similar, k_unload prints "kexec
>> unload failed: Function not implemented", which reads like something
>> went wrong rather than the syscall not being available.
>>
>> I'm happy to split this if you'd prefer, but since they're small and
>> directly related to the error-path cleanup, I kept them together.
>>
>>> Its a good patch, I just want the ordering question answered first.
>>>
>>> Thanks!
>>
>
>
--- Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH kexec-tools] kexec: fix kexec_file_load fallback error handling
2026-11-27 16:08 ` Bradley Morgan
@ 2026-12-01 20:04 ` Simon Horman
0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2026-12-01 20:04 UTC (permalink / raw)
To: Bradley Morgan; +Cc: mpilaniy, include, kexec, ltao, prudo
On Fri, Nov 27, 2026 at 04:08:47PM +0000, Bradley Morgan wrote:
> On 27 November 2026 13:18:57 GMT, Mukesh Pilaniya <mpilaniy@redhat.com>
> wrote:
> >Hi Bradley,
> >
> >On 24/08/26 4:33 pm, Mukesh Pilaniya wrote:
> >> Hi Bradley, thanks for review.
> >>
> >> On 22/08/26 12:44 am, Bradley Morgan wrote:
> >>> On 14 August 2026 08:53:29 BST, Mukesh Pilaniya <mpilaniy@redhat.com>
> >>> wrote:
> >>>> With the default -a (--kexec-syscall-auto) option, kexec-tools first
> >>>> tries kexec_file_load() and falls back to kexec_load() when the
> >syscall
> >>>> is not implemented (ENOSYS) or the kernel does not have a loader for
> >the
> >>>> image format (ENOEXEC/ENOTSUP). [...] Falling back on EINVAL hides the
> >>>> real error, because EINVAL means something went wrong during loading.
> >>>>
> >>>> Remove EINVAL from the fallback path.
> >>>
> >>> Hiding the real error behind a fallback is exactly what makes this one
> >>> hurt to debug, so good direction.
> >>>
> >>>> Several kexec_file_load() image probe functions incorrectly return
> >>>> -EINVAL rather than -ENOEXEC when encountering an unrecognized image
> >>>> format. This kernel patch fixes the issue:
> >>>>
> >https://lore.kernel.org/all/20260813-mpilaniy-v1-1-777d4d0e30f7@redhat.com/
> >>>
> >>> That one is still being reworked, Pratyush just LGTM'd the
> >>> probe_default change a couple days ago and the fix isn't in any tree
> >>> yet. And until it is, the arm64 probe and the riscv image probe still
> >>> return -EINVAL, and that last errno is what kexec_image_probe_default()
> >>> leaks to userspace (I checked the loader lists in the tree). So if this
> >>> lands on tools before the kernel fix lands, an image that used to
> >>> silently fall back to kexec_load() on those arches now just fails with
> >>> EINVAL.
> >>>
> >>> Is the plan to hold this one until the kernel side is in? Because right
> >>> now it looks like it can race ahead of its dependency.
> >>>
> >> Yes, the kernel patch will merge first, then this one. I will follow up
> >> on the same thread once the kernel fix is merged.
> >Both kernel commits (b7c94f4d096 and 2792b4b15f) have been merged
> >upstream from Linux v7.4-rc1 onward, so this change should be good to
> >merge as well.
>
>
> Thx!
>
>
> Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
Likewise, thanks. Applied.
- kexec: fix kexec_file_load fallback error handling
https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=12469cc6e39d
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-01 20:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 7:53 [PATCH] kexec: fix kexec_file_load fallback error handling Mukesh Pilaniya
2026-08-21 19:14 ` Bradley Morgan
2026-08-24 11:03 ` Mukesh Pilaniya
2026-11-27 13:18 ` [PATCH kexec-tools] " Mukesh Pilaniya
2026-11-27 16:08 ` Bradley Morgan
2026-12-01 20:04 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox