Skip to contentSkip to conversation

kexec: Add option to fallback to old kexec syscall when kexec file based syscall failed

PATCH In review Lee, Chun-Yi 5 participants 14 messages Jul 14, 2016 – Jul 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec: Add option to fallback to old kexec syscall when kexec file based syscall failed

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

This option works with --kexec-file-syscall to provide more flexible way to adapt to different kernels that those kernels built with different kexec syscall config or have different verification policy.

Cc Simon Horman <[email protected]>
Cc Petr Tesarik <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 kexec/kexec.c | 13 +++++++++++++
 kexec/kexec.h |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)
kexec/kexec.c +13 -0
index 500e5a9..e05b43f 100644
@@ -969,6 +969,7 @@ void usage(void)
 	       "                      preserve context)\n"
 	       "                      to original kernel.\n"
 	       " -s, --kexec-file-syscall Use file based syscall for kexec operation\n"
+	       "     --fallback-kexec     Fallback to old kexec when file based syscall failed\n"
 	       " -d, --debug           Enable debugging to help spot a failure.\n"
 	       "\n"
 	       "Supported kernel file types and options: \n");
@@ -1204,6 +1205,7 @@ int main(int argc, char *argv[])
 	int do_unload = 0;
 	int do_reuse_initrd = 0;
 	int do_kexec_file_syscall = 0;
+	int do_fallback_kexec_syscall = 0;
 	void *entry = 0;
 	char *type = 0;
 	char *endptr;
@@ -1226,9 +1228,13 @@ int main(int argc, char *argv[])
 		case OPT_KEXEC_FILE_SYSCALL:
 			do_kexec_file_syscall = 1;
 			break;
+		case OPT_FALLBACK_KEXEC:
+			do_fallback_kexec_syscall = 1;
+			break;
 		}
 	}
 
+fallback:
 	/* Reset getopt for the next pass. */
 	opterr = 1;
 	optind = 1;
@@ -1407,6 +1413,13 @@ int main(int argc, char *argv[])
 			result = my_load(type, fileind, argc, argv,
 						kexec_flags, entry);
 	}
+	/* fallback to old kexec syscall */
+	if (do_kexec_file_syscall && result != 0 && do_fallback_kexec_syscall) {
+		fprintf(stderr, "Fallback to kexec syscall\n");
+		do_kexec_file_syscall = 0;
+		do_fallback_kexec_syscall = 0;
+		goto fallback;
+	}
 	/* Don't shutdown unless there is something to reboot to! */
 	if ((result == 0) && (do_shutdown || do_exec) && !kexec_loaded()) {
 		die("Nothing has been loaded!\n");
kexec/kexec.h +3 -1
index 9194f1c..65dbd56 100644
@@ -225,7 +225,8 @@ extern int file_types;
 #define OPT_LOAD_PRESERVE_CONTEXT 259
 #define OPT_LOAD_JUMP_BACK_HELPER 260
 #define OPT_ENTRY		261
-#define OPT_MAX			262
+#define OPT_FALLBACK_KEXEC	262
+#define OPT_MAX			263
 #define KEXEC_OPTIONS \
 	{ "help",		0, 0, OPT_HELP }, \
 	{ "version",		0, 0, OPT_VERSION }, \
@@ -244,6 +245,7 @@ extern int file_types;
 	{ "mem-max",		1, 0, OPT_MEM_MAX }, \
 	{ "reuseinitrd",	0, 0, OPT_REUSE_INITRD }, \
 	{ "kexec-file-syscall",	0, 0, OPT_KEXEC_FILE_SYSCALL }, \
+	{ "fallback-kexec",     0, 0, OPT_FALLBACK_KEXEC }, \
 	{ "debug",		0, 0, OPT_DEBUG }, \
 
 #define KEXEC_OPT_STR "h?vdfxyluet:ps"
Signature · 7 lines
2.6.6


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 7 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

This option works with --kexec-file-syscall to provide more flexible way to adapt to different kernels that those kernels built with different kexec syscall config or have different verification policy.

Usually distribuition system uses script to build a framework to connect the kexec/kdump, makedumpfile utility chain. This can make user execute a very simple script command to implement kexec load or kexec jumping job. In this case script can do what you are trying to do.

Besides, have you actually met that kexec-file failed but old kexec syscall works? I mean how did you test it? I am wondering when it will happen.

Thanks
Baoquan

Quoted 88 lines
Cc Simon Horman <[email protected]>
Cc Petr Tesarik <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 kexec/kexec.c | 13 +++++++++++++
 kexec/kexec.h |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)
kexec/kexec.c +13 -0
index 500e5a9..e05b43f 100644
@@ -969,6 +969,7 @@ void usage(void)
 	       "                      preserve context)\n"
 	       "                      to original kernel.\n"
 	       " -s, --kexec-file-syscall Use file based syscall for kexec operation\n"
+	       "     --fallback-kexec     Fallback to old kexec when file based syscall failed\n"
 	       " -d, --debug           Enable debugging to help spot a failure.\n"
 	       "\n"
 	       "Supported kernel file types and options: \n");
@@ -1204,6 +1205,7 @@ int main(int argc, char *argv[])
 	int do_unload = 0;
 	int do_reuse_initrd = 0;
 	int do_kexec_file_syscall = 0;
+	int do_fallback_kexec_syscall = 0;
 	void *entry = 0;
 	char *type = 0;
 	char *endptr;
@@ -1226,9 +1228,13 @@ int main(int argc, char *argv[])
 		case OPT_KEXEC_FILE_SYSCALL:
 			do_kexec_file_syscall = 1;
 			break;
+		case OPT_FALLBACK_KEXEC:
+			do_fallback_kexec_syscall = 1;
+			break;
 		}
 	}
 
+fallback:
 	/* Reset getopt for the next pass. */
 	opterr = 1;
 	optind = 1;
@@ -1407,6 +1413,13 @@ int main(int argc, char *argv[])
 			result = my_load(type, fileind, argc, argv,
 						kexec_flags, entry);
 	}
+	/* fallback to old kexec syscall */
+	if (do_kexec_file_syscall && result != 0 && do_fallback_kexec_syscall) {
+		fprintf(stderr, "Fallback to kexec syscall\n");
+		do_kexec_file_syscall = 0;
+		do_fallback_kexec_syscall = 0;
+		goto fallback;
+	}
 	/* Don't shutdown unless there is something to reboot to! */
 	if ((result == 0) && (do_shutdown || do_exec) && !kexec_loaded()) {
 		die("Nothing has been loaded!\n");
kexec/kexec.h +3 -1
index 9194f1c..65dbd56 100644
@@ -225,7 +225,8 @@ extern int file_types;
 #define OPT_LOAD_PRESERVE_CONTEXT 259
 #define OPT_LOAD_JUMP_BACK_HELPER 260
 #define OPT_ENTRY		261
-#define OPT_MAX			262
+#define OPT_FALLBACK_KEXEC	262
+#define OPT_MAX			263
 #define KEXEC_OPTIONS \
 	{ "help",		0, 0, OPT_HELP }, \
 	{ "version",		0, 0, OPT_VERSION }, \
@@ -244,6 +245,7 @@ extern int file_types;
 	{ "mem-max",		1, 0, OPT_MEM_MAX }, \
 	{ "reuseinitrd",	0, 0, OPT_REUSE_INITRD }, \
 	{ "kexec-file-syscall",	0, 0, OPT_KEXEC_FILE_SYSCALL }, \
+	{ "fallback-kexec",     0, 0, OPT_FALLBACK_KEXEC }, \
 	{ "debug",		0, 0, OPT_DEBUG }, \
 
 #define KEXEC_OPT_STR "h?vdfxyluet:ps"
Signature · 7 lines
2.6.6


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 10 lines · Baoquan He
Quoted 7 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

This option works with --kexec-file-syscall to provide more flexible way to adapt to different kernels that those kernels built with different kexec syscall config or have different verification policy.

Usually distribuition system uses script to build a framework to

~ I mean distro here.

Quoted 95 lines

connect the kexec/kdump, makedumpfile utility chain. This can make user execute a very simple script command to implement kexec load or kexec jumping job. In this case script can do what you are trying to do.

Besides, have you actually met that kexec-file failed but old kexec syscall works? I mean how did you test it? I am wondering when it will happen.

Thanks
Baoquan

Quoted 84 lines
Cc Simon Horman <[email protected]>
Cc Petr Tesarik <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 kexec/kexec.c | 13 +++++++++++++
 kexec/kexec.h |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)
kexec/kexec.c +13 -0
index 500e5a9..e05b43f 100644
@@ -969,6 +969,7 @@ void usage(void)
 	       "                      preserve context)\n"
 	       "                      to original kernel.\n"
 	       " -s, --kexec-file-syscall Use file based syscall for kexec operation\n"
+	       "     --fallback-kexec     Fallback to old kexec when file based syscall failed\n"
 	       " -d, --debug           Enable debugging to help spot a failure.\n"
 	       "\n"
 	       "Supported kernel file types and options: \n");
@@ -1204,6 +1205,7 @@ int main(int argc, char *argv[])
 	int do_unload = 0;
 	int do_reuse_initrd = 0;
 	int do_kexec_file_syscall = 0;
+	int do_fallback_kexec_syscall = 0;
 	void *entry = 0;
 	char *type = 0;
 	char *endptr;
@@ -1226,9 +1228,13 @@ int main(int argc, char *argv[])
 		case OPT_KEXEC_FILE_SYSCALL:
 			do_kexec_file_syscall = 1;
 			break;
+		case OPT_FALLBACK_KEXEC:
+			do_fallback_kexec_syscall = 1;
+			break;
 		}
 	}
 
+fallback:
 	/* Reset getopt for the next pass. */
 	opterr = 1;
 	optind = 1;
@@ -1407,6 +1413,13 @@ int main(int argc, char *argv[])
 			result = my_load(type, fileind, argc, argv,
 						kexec_flags, entry);
 	}
+	/* fallback to old kexec syscall */
+	if (do_kexec_file_syscall && result != 0 && do_fallback_kexec_syscall) {
+		fprintf(stderr, "Fallback to kexec syscall\n");
+		do_kexec_file_syscall = 0;
+		do_fallback_kexec_syscall = 0;
+		goto fallback;
+	}
 	/* Don't shutdown unless there is something to reboot to! */
 	if ((result == 0) && (do_shutdown || do_exec) && !kexec_loaded()) {
 		die("Nothing has been loaded!\n");
kexec/kexec.h +3 -1
index 9194f1c..65dbd56 100644
@@ -225,7 +225,8 @@ extern int file_types;
 #define OPT_LOAD_PRESERVE_CONTEXT 259
 #define OPT_LOAD_JUMP_BACK_HELPER 260
 #define OPT_ENTRY		261
-#define OPT_MAX			262
+#define OPT_FALLBACK_KEXEC	262
+#define OPT_MAX			263
 #define KEXEC_OPTIONS \
 	{ "help",		0, 0, OPT_HELP }, \
 	{ "version",		0, 0, OPT_VERSION }, \
@@ -244,6 +245,7 @@ extern int file_types;
 	{ "mem-max",		1, 0, OPT_MEM_MAX }, \
 	{ "reuseinitrd",	0, 0, OPT_REUSE_INITRD }, \
 	{ "kexec-file-syscall",	0, 0, OPT_KEXEC_FILE_SYSCALL }, \
+	{ "fallback-kexec",     0, 0, OPT_FALLBACK_KEXEC }, \
 	{ "debug",		0, 0, OPT_DEBUG }, \
 
 #define KEXEC_OPT_STR "h?vdfxyluet:ps"
Signature · 1 line
2.6.6
Quoted 9 lines
Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw
In reply to Baoquan He

Hi Baoquan,

Thanks for your response!

Quoted 5 lines · Baoquan He
Quoted 4 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

Quoted 9 lines
Quoted 3 lines

This option works with --kexec-file-syscall to provide more flexible way to adapt to different kernels that those kernels built with different kexec syscall config or have different verification policy.

Usually distribuition system uses script to build a framework to connect the kexec/kdump, makedumpfile utility chain. This can make user execute a very simple script command to implement kexec load or kexec jumping job. In this case script can do what you are trying to do.

Yes, the fallback function can be implemented by script. But a new kexec option is useful to the distro that it may not provides help scripts to user.

Quoted 7 lines

Besides, have you actually met that kexec-file failed but old kexec syscall works? I mean how did you test it? I am wondering when it will happen.

Thanks
Baoquan

The currently mainline kernel allows to set CONFIG_KEXEC or CONFIG_KEXEC_FILE individual. So if kexec found that the file based kexec syscall isn't available then this is a case to fallback to old kexec.

Another case is when KEXEC_VERIFY_SIG is set, The fallback function is more convenient to user to build his own kernel for using or testing. The kexec tool can try old syscall when verification failed.

Thanks a lot!
Joey Lee

Quoted 84 lines
Quoted 84 lines
Cc Simon Horman <[email protected]>
Cc Petr Tesarik <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 kexec/kexec.c | 13 +++++++++++++
 kexec/kexec.h |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)
kexec/kexec.c +13 -0
index 500e5a9..e05b43f 100644
@@ -969,6 +969,7 @@ void usage(void)
 	       "                      preserve context)\n"
 	       "                      to original kernel.\n"
 	       " -s, --kexec-file-syscall Use file based syscall for kexec operation\n"
+	       "     --fallback-kexec     Fallback to old kexec when file based syscall failed\n"
 	       " -d, --debug           Enable debugging to help spot a failure.\n"
 	       "\n"
 	       "Supported kernel file types and options: \n");
@@ -1204,6 +1205,7 @@ int main(int argc, char *argv[])
 	int do_unload = 0;
 	int do_reuse_initrd = 0;
 	int do_kexec_file_syscall = 0;
+	int do_fallback_kexec_syscall = 0;
 	void *entry = 0;
 	char *type = 0;
 	char *endptr;
@@ -1226,9 +1228,13 @@ int main(int argc, char *argv[])
 		case OPT_KEXEC_FILE_SYSCALL:
 			do_kexec_file_syscall = 1;
 			break;
+		case OPT_FALLBACK_KEXEC:
+			do_fallback_kexec_syscall = 1;
+			break;
 		}
 	}
 
+fallback:
 	/* Reset getopt for the next pass. */
 	opterr = 1;
 	optind = 1;
@@ -1407,6 +1413,13 @@ int main(int argc, char *argv[])
 			result = my_load(type, fileind, argc, argv,
 						kexec_flags, entry);
 	}
+	/* fallback to old kexec syscall */
+	if (do_kexec_file_syscall && result != 0 && do_fallback_kexec_syscall) {
+		fprintf(stderr, "Fallback to kexec syscall\n");
+		do_kexec_file_syscall = 0;
+		do_fallback_kexec_syscall = 0;
+		goto fallback;
+	}
 	/* Don't shutdown unless there is something to reboot to! */
 	if ((result == 0) && (do_shutdown || do_exec) && !kexec_loaded()) {
 		die("Nothing has been loaded!\n");
kexec/kexec.h +3 -1
index 9194f1c..65dbd56 100644
@@ -225,7 +225,8 @@ extern int file_types;
 #define OPT_LOAD_PRESERVE_CONTEXT 259
 #define OPT_LOAD_JUMP_BACK_HELPER 260
 #define OPT_ENTRY		261
-#define OPT_MAX			262
+#define OPT_FALLBACK_KEXEC	262
+#define OPT_MAX			263
 #define KEXEC_OPTIONS \
 	{ "help",		0, 0, OPT_HELP }, \
 	{ "version",		0, 0, OPT_VERSION }, \
@@ -244,6 +245,7 @@ extern int file_types;
 	{ "mem-max",		1, 0, OPT_MEM_MAX }, \
 	{ "reuseinitrd",	0, 0, OPT_REUSE_INITRD }, \
 	{ "kexec-file-syscall",	0, 0, OPT_KEXEC_FILE_SYSCALL }, \
+	{ "fallback-kexec",     0, 0, OPT_FALLBACK_KEXEC }, \
 	{ "debug",		0, 0, OPT_DEBUG }, \
 
 #define KEXEC_OPT_STR "h?vdfxyluet:ps"
Signature · 1 line
2.6.6
Quoted 4 lines
Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw
Quoted 20 lines · joeyli

Hi Baoquan,

Thanks for your response!

Quoted 5 lines · Baoquan He
Quoted 4 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

Quoted 9 lines
Quoted 3 lines

This option works with --kexec-file-syscall to provide more flexible way to adapt to different kernels that those kernels built with different kexec syscall config or have different verification policy.

Usually distribuition system uses script to build a framework to connect the kexec/kdump, makedumpfile utility chain. This can make user execute a very simple script command to implement kexec load or kexec jumping job. In this case script can do what you are trying to do.

Quoted 12 lines

Yes, the fallback function can be implemented by script. But a new kexec option is useful to the distro that it may not provides help scripts to user.

Quoted 7 lines

Besides, have you actually met that kexec-file failed but old kexec syscall works? I mean how did you test it? I am wondering when it will happen.

Thanks
Baoquan

I understand, thanks for telling, Joey Lee.

However it seems not very necessary to me. So leave this to other people, see if you can get support and an Acked-by.

Thanks
Baoquan

Quoted 7 lines

The currently mainline kernel allows to set CONFIG_KEXEC or CONFIG_KEXEC_FILE individual. So if kexec found that the file based kexec syscall isn't available then this is a case to fallback to old kexec.

Another case is when KEXEC_VERIFY_SIG is set, The fallback function is more convenient to user to build his own kernel for using or testing. The kexec tool can try old syscall when verification failed.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw
In reply to Lee, Chun-Yi
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Vivek

Quoted 86 lines

This option works with --kexec-file-syscall to provide more flexible way to adapt to different kernels that those kernels built with different kexec syscall config or have different verification policy.

Cc Simon Horman <[email protected]>
Cc Petr Tesarik <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 kexec/kexec.c | 13 +++++++++++++
 kexec/kexec.h |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)
kexec/kexec.c +13 -0
index 500e5a9..e05b43f 100644
@@ -969,6 +969,7 @@ void usage(void)
 	       "                      preserve context)\n"
 	       "                      to original kernel.\n"
 	       " -s, --kexec-file-syscall Use file based syscall for kexec operation\n"
+	       "     --fallback-kexec     Fallback to old kexec when file based syscall failed\n"
 	       " -d, --debug           Enable debugging to help spot a failure.\n"
 	       "\n"
 	       "Supported kernel file types and options: \n");
@@ -1204,6 +1205,7 @@ int main(int argc, char *argv[])
 	int do_unload = 0;
 	int do_reuse_initrd = 0;
 	int do_kexec_file_syscall = 0;
+	int do_fallback_kexec_syscall = 0;
 	void *entry = 0;
 	char *type = 0;
 	char *endptr;
@@ -1226,9 +1228,13 @@ int main(int argc, char *argv[])
 		case OPT_KEXEC_FILE_SYSCALL:
 			do_kexec_file_syscall = 1;
 			break;
+		case OPT_FALLBACK_KEXEC:
+			do_fallback_kexec_syscall = 1;
+			break;
 		}
 	}
 
+fallback:
 	/* Reset getopt for the next pass. */
 	opterr = 1;
 	optind = 1;
@@ -1407,6 +1413,13 @@ int main(int argc, char *argv[])
 			result = my_load(type, fileind, argc, argv,
 						kexec_flags, entry);
 	}
+	/* fallback to old kexec syscall */
+	if (do_kexec_file_syscall && result != 0 && do_fallback_kexec_syscall) {
+		fprintf(stderr, "Fallback to kexec syscall\n");
+		do_kexec_file_syscall = 0;
+		do_fallback_kexec_syscall = 0;
+		goto fallback;
+	}
 	/* Don't shutdown unless there is something to reboot to! */
 	if ((result == 0) && (do_shutdown || do_exec) && !kexec_loaded()) {
 		die("Nothing has been loaded!\n");
kexec/kexec.h +3 -1
index 9194f1c..65dbd56 100644
@@ -225,7 +225,8 @@ extern int file_types;
 #define OPT_LOAD_PRESERVE_CONTEXT 259
 #define OPT_LOAD_JUMP_BACK_HELPER 260
 #define OPT_ENTRY		261
-#define OPT_MAX			262
+#define OPT_FALLBACK_KEXEC	262
+#define OPT_MAX			263
 #define KEXEC_OPTIONS \
 	{ "help",		0, 0, OPT_HELP }, \
 	{ "version",		0, 0, OPT_VERSION }, \
@@ -244,6 +245,7 @@ extern int file_types;
 	{ "mem-max",		1, 0, OPT_MEM_MAX }, \
 	{ "reuseinitrd",	0, 0, OPT_REUSE_INITRD }, \
 	{ "kexec-file-syscall",	0, 0, OPT_KEXEC_FILE_SYSCALL }, \
+	{ "fallback-kexec",     0, 0, OPT_FALLBACK_KEXEC }, \
 	{ "debug",		0, 0, OPT_DEBUG }, \
 
 #define KEXEC_OPT_STR "h?vdfxyluet:ps"
Signature · 1 line
2.6.6

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

Hi Vivek

Quoted 10 lines · Vivek Goyal
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Vivek

OK~ Understood!

Thanks for Baoquan's and your opinion for this patch.

Joey Lee

Quoted 83 lines
Quoted 83 lines

This option works with --kexec-file-syscall to provide more flexible way to adapt to different kernels that those kernels built with different kexec syscall config or have different verification policy.

Cc Simon Horman <[email protected]>
Cc Petr Tesarik <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 kexec/kexec.c | 13 +++++++++++++
 kexec/kexec.h |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)
kexec/kexec.c +13 -0
index 500e5a9..e05b43f 100644
@@ -969,6 +969,7 @@ void usage(void)
 	       "                      preserve context)\n"
 	       "                      to original kernel.\n"
 	       " -s, --kexec-file-syscall Use file based syscall for kexec operation\n"
+	       "     --fallback-kexec     Fallback to old kexec when file based syscall failed\n"
 	       " -d, --debug           Enable debugging to help spot a failure.\n"
 	       "\n"
 	       "Supported kernel file types and options: \n");
@@ -1204,6 +1205,7 @@ int main(int argc, char *argv[])
 	int do_unload = 0;
 	int do_reuse_initrd = 0;
 	int do_kexec_file_syscall = 0;
+	int do_fallback_kexec_syscall = 0;
 	void *entry = 0;
 	char *type = 0;
 	char *endptr;
@@ -1226,9 +1228,13 @@ int main(int argc, char *argv[])
 		case OPT_KEXEC_FILE_SYSCALL:
 			do_kexec_file_syscall = 1;
 			break;
+		case OPT_FALLBACK_KEXEC:
+			do_fallback_kexec_syscall = 1;
+			break;
 		}
 	}
 
+fallback:
 	/* Reset getopt for the next pass. */
 	opterr = 1;
 	optind = 1;
@@ -1407,6 +1413,13 @@ int main(int argc, char *argv[])
 			result = my_load(type, fileind, argc, argv,
 						kexec_flags, entry);
 	}
+	/* fallback to old kexec syscall */
+	if (do_kexec_file_syscall && result != 0 && do_fallback_kexec_syscall) {
+		fprintf(stderr, "Fallback to kexec syscall\n");
+		do_kexec_file_syscall = 0;
+		do_fallback_kexec_syscall = 0;
+		goto fallback;
+	}
 	/* Don't shutdown unless there is something to reboot to! */
 	if ((result == 0) && (do_shutdown || do_exec) && !kexec_loaded()) {
 		die("Nothing has been loaded!\n");
kexec/kexec.h +3 -1
index 9194f1c..65dbd56 100644
@@ -225,7 +225,8 @@ extern int file_types;
 #define OPT_LOAD_PRESERVE_CONTEXT 259
 #define OPT_LOAD_JUMP_BACK_HELPER 260
 #define OPT_ENTRY		261
-#define OPT_MAX			262
+#define OPT_FALLBACK_KEXEC	262
+#define OPT_MAX			263
 #define KEXEC_OPTIONS \
 	{ "help",		0, 0, OPT_HELP }, \
 	{ "version",		0, 0, OPT_VERSION }, \
@@ -244,6 +245,7 @@ extern int file_types;
 	{ "mem-max",		1, 0, OPT_MEM_MAX }, \
 	{ "reuseinitrd",	0, 0, OPT_REUSE_INITRD }, \
 	{ "kexec-file-syscall",	0, 0, OPT_KEXEC_FILE_SYSCALL }, \
+	{ "fallback-kexec",     0, 0, OPT_FALLBACK_KEXEC }, \
 	{ "debug",		0, 0, OPT_DEBUG }, \
 
Quoted 3 lines
Quoted 3 lines
kexec/kexec.h +0 -0
 #define KEXEC_OPT_STR "h?vdfxyluet:ps"
Signature · 1 line
2.6.6

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#7 lore raw
Quoted 11 lines · On Fri, 15 Jul 2016 07:57:22 +0800 joeyli <[email protected]> wrote:

Hi Vivek

Quoted 8 lines · Vivek Goyal
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Quoted 6 lines
Quoted 2 lines

Vivek

OK~ Understood!

Thanks for Baoquan's and your opinion for this patch.

Is there some sort of diagnostics, so a calling script can determine whether kexec failed, because there's no suppor for kexec_file_load(2) or for a different reason?

Thanks,
Petr T

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#8 lore raw
Quoted 19 lines · Petr Tesarik
Quoted 16 lines · On Fri, 15 Jul 2016 07:57:22 +0800 joeyli <[email protected]> wrote:

Hi Vivek

Quoted 10 lines · Vivek Goyal
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Vivek

OK~ Understood!

Quoted 8 lines
Quoted 1 line

Thanks for Baoquan's and your opinion for this patch.

Is there some sort of diagnostics, so a calling script can determine whether kexec failed, because there's no suppor for kexec_file_load(2) or for a different reason?

Thanks,
Petr T

The calling script needs to use "-s" option to access file based kexec, then check the result and call kexec without -s to access old kexec syscall.

With this patch is just more convenience.

Thanks a lot!
Joey Lee

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#9 lore raw
Quoted 26 lines · On Fri, 15 Jul 2016 18:28:05 +0800 joeyli <[email protected]> wrote:
Quoted 25 lines · Petr Tesarik
Quoted 11 lines · On Fri, 15 Jul 2016 07:57:22 +0800 joeyli <[email protected]> wrote:

Hi Vivek

Quoted 8 lines · Vivek Goyal
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Quoted 6 lines
Quoted 2 lines

Vivek

OK~ Understood!

Thanks for Baoquan's and your opinion for this patch.

Is there some sort of diagnostics, so a calling script can determine whether kexec failed, because there's no suppor for kexec_file_load(2) or for a different reason?

Quoted 5 lines
Quoted 2 lines

Thanks,
Petr T

The calling script needs to use "-s" option to access file based kexec, then check the result

This is the part I was asking about. How do I "check the result"? In other words, what is "the result" if kexec fails because of missing kernel syscall, and what is "the result" if it fails for any other reason (e.g. insufficient privileges)?

Or do you suggest that the script always retrius without "-s" after "kexec -s" fails, just in case loading might work the old way?

Petr T

Quoted 7 lines

and call kexec without -s to access old kexec syscall.

With this patch is just more convenience.

Thanks a lot!
Joey Lee

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#10 lore raw
In reply to Petr Tesarik
Quoted 17 lines · Petr Tesarik
Quoted 14 lines · On Fri, 15 Jul 2016 07:57:22 +0800 joeyli <[email protected]> wrote:

Hi Vivek

Quoted 10 lines · Vivek Goyal
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Vivek

Quoted 7 lines
Quoted 3 lines

OK~ Understood!

Thanks for Baoquan's and your opinion for this patch.

Is there some sort of diagnostics, so a calling script can determine whether kexec failed, because there's no suppor for kexec_file_load(2) or for a different reason?

Will we not get -ENOSYS if kexec_file_load() is not implemented?

Vivek

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#11 lore raw
Quoted 20 lines · On Fri, 15 Jul 2016 08:51:14 -0400 Vivek Goyal <[email protected]> wrote:
Quoted 19 lines · Petr Tesarik
Quoted 16 lines · On Fri, 15 Jul 2016 07:57:22 +0800 joeyli <[email protected]> wrote:

Hi Vivek

Quoted 10 lines · Vivek Goyal
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Vivek

OK~ Understood!

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Thanks for Baoquan's and your opinion for this patch.

Is there some sort of diagnostics, so a calling script can determine whether kexec failed, because there's no suppor for kexec_file_load(2) or for a different reason?

Will we not get -ENOSYS if kexec_file_load() is not implemented?

Sure, the kexec code will see a beautiful ENOSYS in errno, but it merely prints this message on stderr (possibly with a different error string if not linked against glibc):

kexec_file_load failed: Function not implemented

...and exits with status 255 (same for any other error). Which is, um, not very friendly to automated error handling...

Petr T

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#12 lore raw
Quoted 31 lines · Petr Tesarik
Quoted 20 lines · On Fri, 15 Jul 2016 08:51:14 -0400 Vivek Goyal <[email protected]> wrote:
Quoted 19 lines · Petr Tesarik
Quoted 16 lines · On Fri, 15 Jul 2016 07:57:22 +0800 joeyli <[email protected]> wrote:

Hi Vivek

Quoted 10 lines · Vivek Goyal
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Vivek

OK~ Understood!

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Thanks for Baoquan's and your opinion for this patch.

Is there some sort of diagnostics, so a calling script can determine whether kexec failed, because there's no suppor for kexec_file_load(2) or for a different reason?

Will we not get -ENOSYS if kexec_file_load() is not implemented?

Quoted 8 lines

Sure, the kexec code will see a beautiful ENOSYS in errno, but it merely prints this message on stderr (possibly with a different error string if not linked against glibc):

kexec_file_load failed: Function not implemented

...and exits with status 255 (same for any other error). Which is, um, not very friendly to automated error handling...

So what are the options? One should return different error codes as returned by glibc? But bash or other script will not have a library to translate it. I guess scripts will have to hard code the meaning of a particular return code.

BTW, user can always try kexec_file_load() and if it fails, try older version of syscall and that should work for lot of use cases?

Vivek

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#13 lore raw
Quoted 41 lines · On Fri, 15 Jul 2016 11:13:46 -0400 Vivek Goyal <[email protected]> wrote:
Quoted 31 lines · Petr Tesarik
Quoted 20 lines · On Fri, 15 Jul 2016 08:51:14 -0400 Vivek Goyal <[email protected]> wrote:
Quoted 19 lines · Petr Tesarik
Quoted 16 lines · On Fri, 15 Jul 2016 07:57:22 +0800 joeyli <[email protected]> wrote:

Hi Vivek

Quoted 10 lines · Vivek Goyal
Quoted 3 lines · Chun-Yi

This patch adds a new "--fallback-kexec" option to give a chance to fallback to old kexec syscall when file based kexec syscall operation failed.

I think caller should switch to using different interface if need be. But I don't see much point in providing an option for this in kexec-tools.

Vivek

OK~ Understood!

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Thanks for Baoquan's and your opinion for this patch.

Is there some sort of diagnostics, so a calling script can determine whether kexec failed, because there's no suppor for kexec_file_load(2) or for a different reason?

Will we not get -ENOSYS if kexec_file_load() is not implemented?

Quoted 8 lines

Sure, the kexec code will see a beautiful ENOSYS in errno, but it merely prints this message on stderr (possibly with a different error string if not linked against glibc):

kexec_file_load failed: Function not implemented

...and exits with status 255 (same for any other error). Which is, um, not very friendly to automated error handling...

Quoted 7 lines

So what are the options? One should return different error codes as returned by glibc? But bash or other script will not have a library to translate it. I guess scripts will have to hard code the meaning of a particular return code.

BTW, user can always try kexec_file_load() and if it fails, try older version of syscall and that should work for lot of use cases?

Yes, I can blindly retry. Thanks for considering other options.

Petr T

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec