From nobody Mon May 13 03:24:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165164757188251.88724641796546; Tue, 3 May 2022 23:59:31 -0700 (PDT) Received: from localhost ([::1]:42390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nm8ys-0005oK-IX for importer@patchew.org; Wed, 04 May 2022 02:59:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nm8vK-00041Z-8g; Wed, 04 May 2022 02:55:46 -0400 Received: from ozlabs.ru ([107.174.27.60]:35066) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nm8vH-0008VX-NQ; Wed, 04 May 2022 02:55:45 -0400 Received: from fstn1-p1.ozlabs.ibm.com. (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 30DD580511; Wed, 4 May 2022 02:55:38 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-ppc@nongnu.org Cc: Alexey Kardashevskiy , qemu-devel@nongnu.org, David Gibson , Daniel Henrique Barboza Subject: [PATCH qemu] spapr: Use address from elf parser for kernel address Date: Wed, 4 May 2022 16:55:36 +1000 Message-Id: <20220504065536.3534488-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=107.174.27.60; envelope-from=aik@ozlabs.ru; helo=ozlabs.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1651647574891100001 Content-Type: text/plain; charset="utf-8" tl;dr: This allows Big Endian zImage booting via -kernel + x-vof=3Don. QEMU loads the kernel at 0x400000 by default which works most of the time as Linux kernels are relocatable, 64bit and compiled with "-pie" (position independent code). This works for a little endian zImage too. However a big endian zImage is compiled without -pie, is 32bit, linked to 0x4000000 so current QEMU ends up loading it at 0x4400000 but keeps spapr->kernel_addr unchanged so booting fails. This uses the kernel address returned from load_elf(). If the default kernel_addr is used, there is no change in behavior (as translate_kernel_address() takes care of this), which is: LE/BE vmlinux and LE zImage boot, BE zImage does not. If the VM created with "-machine kernel-addr=3D0,x-vof=3Don", then QEMU prints a warning and BE zImage boots. Note #1: SLOF (x-vof=3Doff) still cannot boot a big endian zImage as SLOF enables MSR_SF for everything loaded by QEMU and this leads to early crash of 32bit zImage. Note #2: BE/LE vmlinux images set MSR_SF in early boot so these just work; a LE zImage restores MSR_SF after every CI call and we are lucky enough not to crash before the first CI call. Signed-off-by: Alexey Kardashevskiy Reviewed-by: Fabiano Rosas Tested-by: Joel Stanley --- We could probably change SLOF to always clear MSR_SF before jumping to the kernel but this is 1) SLOF fix 2) not quite sure if it brings lots of value. I really wish I had this when tested this fix: https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220406070038.3704= 604-1-aik@ozlabs.ru/ --- hw/ppc/spapr.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a4372ba1891e..89f18f6564bd 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2971,14 +2971,16 @@ static void spapr_machine_init(MachineState *machin= e) } =20 if (kernel_filename) { + uint64_t loaded_addr =3D 0; + spapr->kernel_size =3D load_elf(kernel_filename, NULL, translate_kernel_address, spapr, - NULL, NULL, NULL, NULL, 1, + NULL, &loaded_addr, NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); if (spapr->kernel_size =3D=3D ELF_LOAD_WRONG_ENDIAN) { spapr->kernel_size =3D load_elf(kernel_filename, NULL, translate_kernel_address, spapr, - NULL, NULL, NULL, NULL, 0, + NULL, &loaded_addr, NULL, NULL, = 0, PPC_ELF_MACHINE, 0, 0); spapr->kernel_le =3D spapr->kernel_size > 0; } @@ -2988,6 +2990,12 @@ static void spapr_machine_init(MachineState *machine) exit(1); } =20 + if (spapr->kernel_addr !=3D loaded_addr) { + warn_report("spapr: kernel_addr changed from 0x%lx to 0x%lx", + spapr->kernel_addr, loaded_addr); + spapr->kernel_addr =3D loaded_addr; + } + /* load initrd */ if (initrd_filename) { /* Try to locate the initrd in the gap between the kernel --=20 2.30.2