From nobody Tue Feb 10 02:27:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1768220526; cv=none; d=zohomail.com; s=zohoarc; b=Pm8hrbZRGYvWUtpHZF7TP6A+VtqwchQ0X2ErtoDwRw5+t+wmwWwLER1hN61asYDYkKgWfYrwXdtv0BYzGgAo25WXjXvW+O3zZ35HNb1TGeNoVFLcWiwHBZliabBf0GHGky37JJ3esa6yqvIKaDxnSR3qmmogClbziq93Py3OVfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768220526; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=r7ERui18sUFDyMDLpZi8181U1cet7y6/W9eGFoDmrFc=; b=S8AqhLn4P2QMdQBddnN9aI/Wxr4uMT2ESuM4I3xCJ3S0mBC+rTJy0CfQnTQVfHnTPtirgA2dUXdupQfM1d08wN24nLhFnyPzKD1oZGK55CtipTKUMbu6tkobPG+LWIPdk9NxmdlAwHCyL0FBzkPQ1px3RWGLzHVcRczWiUXHy1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768220526638268.79006205049404; Mon, 12 Jan 2026 04:22:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfGup-0000J7-Jp; Mon, 12 Jan 2026 07:20:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfGub-0008L7-DD for qemu-devel@nongnu.org; Mon, 12 Jan 2026 07:20:47 -0500 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfGuO-0002kP-Hm for qemu-devel@nongnu.org; Mon, 12 Jan 2026 07:20:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Cc:To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=r7ERui18sUFDyMDLpZi8181U1cet7y6/W9eGFoDmrFc=; b=q+y5glOARNwc7YS DuuZUHrPVw2ePj0QRcUyTDmdUtfhneoczyt8MBI/WObcrRSFrNIfz+byXxy/EJ+pyIKCnNuDby5o+ LHPEtmHLJES/1Pq4gM2tkXGmyLh4A2RgRWSG+QWOJUSVmp7Yccn3O2bQtsSCzgRlPq/wVOMo/UVgc Ck=; Date: Mon, 12 Jan 2026 13:22:46 +0100 Subject: [PATCH v3 5/7] hw/loongarch: Use loongarch_palen_mask() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260112-phys_addr-v3-5-5f90fdb4015f@rev.ng> References: <20260112-phys_addr-v3-0-5f90fdb4015f@rev.ng> In-Reply-To: <20260112-phys_addr-v3-0-5f90fdb4015f@rev.ng> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Anton Johansson , palmer@dabbelt.com, alistair.francis@wdc.com, pbonzini@redhat.com, gaosong@loongson.cn, maobibo@loongson.cn 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 (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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Anton Johansson From: Anton Johansson via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1768220529279158500 Replaces remaining uses of TARGET_PHYS_ADDR_SPACE_BITS with runtime calls to loongarch_palen_mask() to fetch the physical address mask from the cpucfg PALEN field. Signed-off-by: Anton Johansson --- include/hw/loongarch/boot.h | 3 ++- hw/loongarch/boot.c | 28 ++++++++++++++++------------ hw/loongarch/virt.c | 5 ++++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h index 9819f7fbe3..4984322f75 100644 --- a/include/hw/loongarch/boot.h +++ b/include/hw/loongarch/boot.h @@ -113,6 +113,7 @@ struct memmap_entry { uint32_t reserved; }; =20 -void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *i= nfo); +void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *i= nfo, + uint64_t phys_addr_mask); =20 #endif /* HW_LOONGARCH_BOOT_H */ diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c index 711d5ffbbc..ef8eae237c 100644 --- a/hw/loongarch/boot.c +++ b/hw/loongarch/boot.c @@ -217,10 +217,12 @@ static void init_cmdline(struct loongarch_boot_info *= info, void *p, void *start) =20 static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr) { - return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); + uint64_t *phys_addr_mask =3D opaque; + return addr & *phys_addr_mask; } =20 static int64_t load_loongarch_linux_image(const char *filename, + uint64_t phys_addr_mask, uint64_t *kernel_entry, uint64_t *kernel_low, uint64_t *kernel_high) @@ -251,10 +253,8 @@ static int64_t load_loongarch_linux_image(const char *= filename, } =20 /* Early kernel versions may have those fields in virtual address */ - *kernel_entry =3D extract64(le64_to_cpu(hdr->kernel_entry), - 0, TARGET_PHYS_ADDR_SPACE_BITS); - *kernel_low =3D extract64(le64_to_cpu(hdr->load_offset), - 0, TARGET_PHYS_ADDR_SPACE_BITS); + *kernel_entry =3D le64_to_cpu(hdr->kernel_entry) & phys_addr_mask; + *kernel_low =3D le64_to_cpu(hdr->load_offset) & phys_addr_mask; *kernel_high =3D *kernel_low + size; =20 rom_add_blob_fixed(filename, buffer, size, *kernel_low); @@ -303,19 +303,21 @@ static ram_addr_t alloc_initrd_memory(struct loongarc= h_boot_info *info, exit(1); } =20 -static int64_t load_kernel_info(struct loongarch_boot_info *info) +static int64_t load_kernel_info(struct loongarch_boot_info *info, + uint64_t phys_addr_mask) { uint64_t kernel_entry, kernel_low, kernel_high, initrd_offset =3D 0; ssize_t kernel_size; =20 kernel_size =3D load_elf(info->kernel_filename, NULL, - cpu_loongarch_virt_to_phys, NULL, + cpu_loongarch_virt_to_phys, &phys_addr_mask, &kernel_entry, &kernel_low, &kernel_high, NULL, ELFDATA2LSB, EM_LOONGARCH, 1, 0); - kernel_entry =3D cpu_loongarch_virt_to_phys(NULL, kernel_entry); + kernel_entry =3D cpu_loongarch_virt_to_phys(&phys_addr_mask, kernel_en= try); if (kernel_size < 0) { kernel_size =3D load_loongarch_linux_image(info->kernel_filename, + phys_addr_mask, &kernel_entry, &kernel_lo= w, &kernel_high); } @@ -395,14 +397,15 @@ static void init_boot_rom(MachineState *ms, } =20 static void loongarch_direct_kernel_boot(MachineState *ms, - struct loongarch_boot_info *info) + struct loongarch_boot_info *info, + uint64_t phys_addr_mask) { void *p, *bp; int64_t kernel_addr =3D VIRT_FLASH0_BASE; uint64_t *data; =20 if (info->kernel_filename) { - kernel_addr =3D load_kernel_info(info); + kernel_addr =3D load_kernel_info(info, phys_addr_mask); } else { if (!qtest_enabled()) { warn_report("No kernel provided, booting from flash drive."); @@ -429,7 +432,8 @@ static void loongarch_direct_kernel_boot(MachineState *= ms, g_free(bp); } =20 -void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *i= nfo) +void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *i= nfo, + uint64_t phys_addr_mask) { LoongArchVirtMachineState *lvms =3D LOONGARCH_VIRT_MACHINE(ms); =20 @@ -440,6 +444,6 @@ void loongarch_load_kernel(MachineState *ms, struct loo= ngarch_boot_info *info) if (lvms->bios_loaded) { loongarch_firmware_boot(lvms, info); } else { - loongarch_direct_kernel_boot(ms, info); + loongarch_direct_kernel_boot(ms, info, phys_addr_mask); } } diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 6efa15da47..1e7b55e05c 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -33,6 +33,7 @@ #include "hw/misc/unimp.h" #include "hw/loongarch/fw_cfg.h" #include "target/loongarch/cpu.h" +#include "target/loongarch/cpu-mmu.h" #include "hw/firmware/smbios.h" #include "qapi/qapi-visit-common.h" #include "hw/acpi/generic_event_device.h" @@ -785,6 +786,7 @@ static void virt_init(MachineState *machine) hwaddr base, size, ram_size =3D machine->ram_size; MachineClass *mc =3D MACHINE_GET_CLASS(machine); Object *cpuobj; + uint64_t phys_addr_mask =3D 0; =20 if (!cpu_model) { cpu_model =3D LOONGARCH_CPU_TYPE_NAME("la464"); @@ -872,7 +874,8 @@ static void virt_init(MachineState *machine) qemu_register_powerdown_notifier(&lvms->powerdown_notifier); =20 lvms->bootinfo.ram_size =3D ram_size; - loongarch_load_kernel(machine, &lvms->bootinfo); + phys_addr_mask =3D loongarch_palen_mask(&LOONGARCH_CPU(first_cpu)->env= ); + loongarch_load_kernel(machine, &lvms->bootinfo, phys_addr_mask); } =20 static void virt_get_acpi(Object *obj, Visitor *v, const char *name, --=20 2.51.0