[v2,1/3] lib: Add system config option to enable kexec_file_load

Submitted by Eric Richter on March 30, 2017, 6:56 p.m.

Details

Message ID 1490900184-26327-2-git-send-email-erichte@linux.vnet.ibm.com
State New
Headers show

Commit Message

Eric Richter March 30, 2017, 6:56 p.m.
Currently, pb-discover only supports one method (syscall) for loading the
next kernel for kexec: kexec_load. This patch adds a system configuration
option for toggling between using kexec_load (false), and
kexec_file_load (true).

When the kernel is running in a secure mode, a regular kexec_load should
be disabled by the kernel. To avoid having to set this config option on
every single boot, this patch introduces an nvram field for persisting
the state of the kexec_file config option across reboots.

This will be used in subsequent patches for determining the argument to
kexec-lite/kexec-tools, and modified by a menu option.

Signed-off-by: Eric Richter <erichte@linux.vnet.ibm.com>
---
 discover/platform-powerpc.c   | 9 +++++++++
 lib/pb-protocol/pb-protocol.c | 9 +++++++++
 lib/types/types.h             | 2 ++
 3 files changed, 20 insertions(+)

Patch hide | download patch | download mbox

diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index b5ad682..c0a64c7 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -61,6 +61,7 @@  static const char *known_params[] = {
 	"petitboot,console",
 	"petitboot,http_proxy",
 	"petitboot,https_proxy",
+	"petitboot,fileload?",
 	NULL,
 };
 
@@ -550,6 +551,11 @@  static void populate_config(struct platform_powerpc *platform,
 	val = get_param(platform, "petitboot,console");
 	if (val)
 		config->boot_console = talloc_strdup(config, val);
+
+	val = get_param(platform, "petitboot,fileload?");
+	if (val)
+		config->kexec_file = !!strcmp(val, "false");
+
 	/* If a full path is already set we don't want to override it */
 	config->manual_console = config->boot_console &&
 					!strchr(config->boot_console, '[');
@@ -742,6 +748,9 @@  static int update_config(struct platform_powerpc *platform,
 	update_string_config(platform, "petitboot,https_proxy", val);
 	set_proxy_variables(config);
 
+	val = config->kexec_file ? "true" : "false";
+	update_string_config(platform, "petitboot,fileload?", val);
+
 	update_network_config(platform, config);
 
 	update_bootdev_config(platform, config);
diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c
index 18edf57..1a19619 100644
--- a/lib/pb-protocol/pb-protocol.c
+++ b/lib/pb-protocol/pb-protocol.c
@@ -322,6 +322,8 @@  int pb_protocol_config_len(const struct config *config)
 
 	len += 4; /* allow_writes */
 
+	len += 4; /* kexec_file */
+
 	len += 4; /* n_consoles */
 	for (i = 0; i < config->n_consoles; i++)
 		len += 4 + optional_strlen(config->consoles[i]);
@@ -582,6 +584,9 @@  int pb_protocol_serialise_config(const struct config *config,
 	*(uint32_t *)pos = config->allow_writes;
 	pos += 4;
 
+	*(uint32_t *)pos = config->kexec_file;
+	pos += 4;
+
 	*(uint32_t *)pos = __cpu_to_be32(config->n_consoles);
 	pos += 4;
 	for (i = 0; i < config->n_consoles; i++)
@@ -1121,6 +1126,10 @@  int pb_protocol_deserialise_config(struct config *config,
 		goto out;
 	config->allow_writes = !!tmp;
 
+	if (read_u32(&pos, &len, &tmp))
+		goto out;
+	config->kexec_file = !!tmp;
+
 	if (read_u32(&pos, &len, &config->n_consoles))
 		goto out;
 
diff --git a/lib/types/types.h b/lib/types/types.h
index 7f4ae1f..132ebd3 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -171,6 +171,8 @@  struct config {
 
 	bool			allow_writes;
 
+	bool			kexec_file;
+
 	char			*boot_console;
 	bool			manual_console;
 	char			*lang;