spapr: Allow changing offset for -kernel image

This allows moving the kernel in the guest memory. The option is useful
for step debugging (as Linux is linked at 0x0); it also allows loading
grub which is normally linked to run at 0x20000.

This uses the existing kernel address by default.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Message-Id: <20200203032943.121178-6-aik@ozlabs.ru>
Reviewed-by: Fabiano Rosas <farosas@linux.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Alexey Kardashevskiy 2020-02-03 14:29:42 +11:00 committed by David Gibson
parent e8ead7d579
commit 87262806cb
2 changed files with 32 additions and 7 deletions

View File

@ -1064,7 +1064,7 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt)
} }
if (spapr->kernel_size) { if (spapr->kernel_size) {
uint64_t kprop[2] = { cpu_to_be64(KERNEL_LOAD_ADDR), uint64_t kprop[2] = { cpu_to_be64(spapr->kernel_addr),
cpu_to_be64(spapr->kernel_size) }; cpu_to_be64(spapr->kernel_size) };
_FDT(fdt_setprop(fdt, chosen, "qemu,boot-kernel", _FDT(fdt_setprop(fdt, chosen, "qemu,boot-kernel",
@ -1252,7 +1252,8 @@ void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, size_t space)
/* Build memory reserve map */ /* Build memory reserve map */
if (reset) { if (reset) {
if (spapr->kernel_size) { if (spapr->kernel_size) {
_FDT((fdt_add_mem_rsv(fdt, KERNEL_LOAD_ADDR, spapr->kernel_size))); _FDT((fdt_add_mem_rsv(fdt, spapr->kernel_addr,
spapr->kernel_size)));
} }
if (spapr->initrd_size) { if (spapr->initrd_size) {
_FDT((fdt_add_mem_rsv(fdt, spapr->initrd_base, _FDT((fdt_add_mem_rsv(fdt, spapr->initrd_base,
@ -1285,7 +1286,9 @@ void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, size_t space)
static uint64_t translate_kernel_address(void *opaque, uint64_t addr) static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
{ {
return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR; SpaprMachineState *spapr = opaque;
return (addr & 0x0fffffff) + spapr->kernel_addr;
} }
static void emulate_spapr_hypercall(PPCVirtualHypervisor *vhyp, static void emulate_spapr_hypercall(PPCVirtualHypervisor *vhyp,
@ -2967,14 +2970,15 @@ static void spapr_machine_init(MachineState *machine)
uint64_t lowaddr = 0; uint64_t lowaddr = 0;
spapr->kernel_size = load_elf(kernel_filename, NULL, spapr->kernel_size = load_elf(kernel_filename, NULL,
translate_kernel_address, NULL, translate_kernel_address, spapr,
NULL, &lowaddr, NULL, NULL, 1, NULL, &lowaddr, NULL, NULL, 1,
PPC_ELF_MACHINE, 0, 0); PPC_ELF_MACHINE, 0, 0);
if (spapr->kernel_size == ELF_LOAD_WRONG_ENDIAN) { if (spapr->kernel_size == ELF_LOAD_WRONG_ENDIAN) {
spapr->kernel_size = load_elf(kernel_filename, NULL, spapr->kernel_size = load_elf(kernel_filename, NULL,
translate_kernel_address, NULL, NULL, translate_kernel_address, spapr, NULL,
&lowaddr, NULL, NULL, 0, &lowaddr, NULL, NULL, 0,
PPC_ELF_MACHINE, 0, 0); PPC_ELF_MACHINE,
0, 0);
spapr->kernel_le = spapr->kernel_size > 0; spapr->kernel_le = spapr->kernel_size > 0;
} }
if (spapr->kernel_size < 0) { if (spapr->kernel_size < 0) {
@ -2988,7 +2992,7 @@ static void spapr_machine_init(MachineState *machine)
/* Try to locate the initrd in the gap between the kernel /* Try to locate the initrd in the gap between the kernel
* and the firmware. Add a bit of space just in case * and the firmware. Add a bit of space just in case
*/ */
spapr->initrd_base = (KERNEL_LOAD_ADDR + spapr->kernel_size spapr->initrd_base = (spapr->kernel_addr + spapr->kernel_size
+ 0x1ffff) & ~0xffff; + 0x1ffff) & ~0xffff;
spapr->initrd_size = load_image_targphys(initrd_filename, spapr->initrd_size = load_image_targphys(initrd_filename,
spapr->initrd_base, spapr->initrd_base,
@ -3234,6 +3238,18 @@ static void spapr_set_vsmt(Object *obj, Visitor *v, const char *name,
visit_type_uint32(v, name, (uint32_t *)opaque, errp); visit_type_uint32(v, name, (uint32_t *)opaque, errp);
} }
static void spapr_get_kernel_addr(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
visit_type_uint64(v, name, (uint64_t *)opaque, errp);
}
static void spapr_set_kernel_addr(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
visit_type_uint64(v, name, (uint64_t *)opaque, errp);
}
static char *spapr_get_ic_mode(Object *obj, Error **errp) static char *spapr_get_ic_mode(Object *obj, Error **errp)
{ {
SpaprMachineState *spapr = SPAPR_MACHINE(obj); SpaprMachineState *spapr = SPAPR_MACHINE(obj);
@ -3339,6 +3355,14 @@ static void spapr_instance_init(Object *obj)
object_property_add_bool(obj, "vfio-no-msix-emulation", object_property_add_bool(obj, "vfio-no-msix-emulation",
spapr_get_msix_emulation, NULL, NULL); spapr_get_msix_emulation, NULL, NULL);
object_property_add(obj, "kernel-addr", "uint64", spapr_get_kernel_addr,
spapr_set_kernel_addr, NULL, &spapr->kernel_addr,
&error_abort);
object_property_set_description(obj, "kernel-addr",
stringify(KERNEL_LOAD_ADDR)
" for -kernel is the default",
NULL);
spapr->kernel_addr = KERNEL_LOAD_ADDR;
/* The machine class defines the default interrupt controller mode */ /* The machine class defines the default interrupt controller mode */
spapr->irq = smc->irq; spapr->irq = smc->irq;
object_property_add_str(obj, "ic-mode", spapr_get_ic_mode, object_property_add_str(obj, "ic-mode", spapr_get_ic_mode,

View File

@ -162,6 +162,7 @@ struct SpaprMachineState {
void *fdt_blob; void *fdt_blob;
long kernel_size; long kernel_size;
bool kernel_le; bool kernel_le;
uint64_t kernel_addr;
uint32_t initrd_base; uint32_t initrd_base;
long initrd_size; long initrd_size;
uint64_t rtc_offset; /* Now used only during incoming migration */ uint64_t rtc_offset; /* Now used only during incoming migration */