aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Elisei <alexandru.elisei@arm.com>2021-09-23 15:45:02 +0100
committerWill Deacon <will@kernel.org>2021-10-12 09:40:46 +0100
commit5613ae26b9989dec93869090b426c99913ea9ab4 (patch)
tree2724f4fa074b050a9314244cae25ae14cb8bca08
parenta5253f7cc8104c3cb162bc218d4c18a010425882 (diff)
downloadkvmtool-5613ae26b9989dec93869090b426c99913ea9ab4.tar.gz
Add --nodefaults command line argument
kvmtool attempts to make it as easier as possible on the user to run a VM by doing a few different things: it tries to create a rootfs filesystem in a directory if not disk or initrd is set by the user, and it adds various parameters to the kernel command line based on the VM configuration options. While this is generally very useful, today there isn't any way for the user to prohibit this behaviour, even though there are situations where this might not be desirable, like, for example: loading something which is not a kernel (kvm-unit-tests comes to mind, which expects test parameters on the kernel command line); the kernel has a built-in initramfs and there is no need to generate the root filesystem, or it not possible; and what is probably the most important use case, when the user is actively trying to break things for testing purposes. Add a --nodefaults command line argument which disables everything that cannot be disabled via another command line switch. The purpose of this knob is not to disable the default options for arguments that can be set via the kvmtool command line, but rather to inhibit behaviour that cannot be disabled otherwise. Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> Link: https://lore.kernel.org/r/20210923144505.60776-8-alexandru.elisei@arm.com Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r--arm/fdt.c3
-rw-r--r--builtin-run.c13
-rw-r--r--include/kvm/kvm-config.h1
-rw-r--r--mips/kvm.c3
4 files changed, 16 insertions, 4 deletions
diff --git a/arm/fdt.c b/arm/fdt.c
index 7032985e..635de7f2 100644
--- a/arm/fdt.c
+++ b/arm/fdt.c
@@ -136,9 +136,10 @@ static int setup_fdt(struct kvm *kvm)
if (kvm->cfg.kernel_cmdline)
_FDT(fdt_property_string(fdt, "bootargs",
kvm->cfg.kernel_cmdline));
- } else
+ } else if (kvm->cfg.real_cmdline) {
_FDT(fdt_property_string(fdt, "bootargs",
kvm->cfg.real_cmdline));
+ }
_FDT(fdt_property_u64(fdt, "kaslr-seed", kvm->cfg.arch.kaslr_seed));
_FDT(fdt_property_string(fdt, "stdout-path", "serial0"));
diff --git a/builtin-run.c b/builtin-run.c
index 478b5a95..9a1a0c1f 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -108,6 +108,9 @@ void kvm_run_set_wrapper_sandbox(void)
OPT_BOOLEAN('\0', "sdl", &(cfg)->sdl, "Enable SDL framebuffer"),\
OPT_BOOLEAN('\0', "rng", &(cfg)->virtio_rng, "Enable virtio" \
" Random Number Generator"), \
+ OPT_BOOLEAN('\0', "nodefaults", &(cfg)->nodefaults, "Disable" \
+ " implicit configuration that cannot be" \
+ " disabled otherwise"), \
OPT_CALLBACK('\0', "9p", NULL, "dir_to_share,tag_name", \
"Enable virtio 9p to share files between host and" \
" guest", virtio_9p_rootdir_parser, kvm), \
@@ -642,7 +645,10 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
}
}
- if (!kvm->cfg.using_rootfs && !kvm->cfg.disk_image[0].filename && !kvm->cfg.initrd_filename) {
+ if (!kvm->cfg.nodefaults &&
+ !kvm->cfg.using_rootfs &&
+ !kvm->cfg.disk_image[0].filename &&
+ !kvm->cfg.initrd_filename) {
char tmp[PATH_MAX];
kvm_setup_create_new(kvm->cfg.custom_rootfs_name);
@@ -662,7 +668,10 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
die("Failed to setup init for guest.");
}
- kvm_run_set_real_cmdline(kvm);
+ if (kvm->cfg.nodefaults)
+ kvm->cfg.real_cmdline = kvm->cfg.kernel_cmdline;
+ else
+ kvm_run_set_real_cmdline(kvm);
if (kvm->cfg.kernel_filename) {
printf(" # %s run -k %s -m %Lu -c %d --name %s\n", KVM_BINARY_NAME,
diff --git a/include/kvm/kvm-config.h b/include/kvm/kvm-config.h
index 35d45c0f..6a5720c4 100644
--- a/include/kvm/kvm-config.h
+++ b/include/kvm/kvm-config.h
@@ -27,6 +27,7 @@ struct kvm_config {
u8 num_vfio_devices;
u64 vsock_cid;
bool virtio_rng;
+ bool nodefaults;
int active_console;
int debug_iodelay;
int nrcpus;
diff --git a/mips/kvm.c b/mips/kvm.c
index e110e5d5..3470dbb2 100644
--- a/mips/kvm.c
+++ b/mips/kvm.c
@@ -131,7 +131,8 @@ static void kvm__mips_install_cmdline(struct kvm *kvm)
(unsigned long long)kvm->ram_size - KVM_MMIO_START,
(unsigned long long)(KVM_MMIO_START + KVM_MMIO_SIZE));
- strcat(p + cmdline_offset, kvm->cfg.real_cmdline); /* maximum size is 2K */
+ if (kvm->cfg.real_cmdline)
+ strcat(p + cmdline_offset, kvm->cfg.real_cmdline); /* maximum size is 2K */
while (p[cmdline_offset]) {
if (!isspace(p[cmdline_offset])) {