We know at user configuration time if the firmware address is outside RAM, validate the address in kvm__arch_validate_cfg() before creating the VM. Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx> --- arm/kvm.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/arm/kvm.c b/arm/kvm.c index 3edc6fdbcb5f..79d085ab9965 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -33,8 +33,20 @@ int fw_addr_parser(const struct option *opt, const char *arg, int unset) void kvm__arch_validate_cfg(struct kvm *kvm) { - if (kvm->cfg.arch.fw_addr && !kvm->cfg.firmware_filename) - die("--firmware-address is only valid when loading a firmware image"); + u64 fw_addr = kvm->cfg.arch.fw_addr; + u64 ram_addr = kvm->cfg.ram_addr; + u64 ram_size = kvm->cfg.ram_size; + + if (fw_addr) { + if (!kvm->cfg.firmware_filename) + die("--firmware-address is only valid when loading a firmware image"); + + if (fw_addr < ram_addr || fw_addr >= ram_addr + ram_size) { + die("Firmware address 0x%016llx outside guest memory: " + "0x%016llx - 0x%016llx", + fw_addr, ram_addr, ram_addr + ram_size); + } + } kvm__arm_validate_cfg(kvm); } @@ -196,23 +208,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, return true; } -static bool validate_fw_addr(struct kvm *kvm, u64 fw_addr) -{ - u64 ram_phys; - - ram_phys = host_to_guest_flat(kvm, kvm->ram_start); - - if (fw_addr < ram_phys || fw_addr >= ram_phys + kvm->ram_size) { - pr_err("Provide --firmware-address an address in RAM: " - "0x%016llx - 0x%016llx", - ram_phys, ram_phys + kvm->ram_size); - - return false; - } - - return true; -} - bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) { u64 fw_addr = kvm->cfg.arch.fw_addr; @@ -227,9 +222,6 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) if (fw_addr == 0) fw_addr = kvm->arch.memory_guest_start; - if (!validate_fw_addr(kvm, fw_addr)) - die("Bad firmware destination: 0x%016llx", fw_addr); - fd = open(firmware_filename, O_RDONLY); if (fd < 0) return false; -- 2.36.0 _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm