From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D95C6606A31A for ; Wed, 2 Dec 2026 13:53:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=oIBdfsm/ Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYkm0-0005QF-AF; Wed, 02 Dec 2026 08:53:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYklo-0005OJ-9C; Wed, 02 Dec 2026 08:53:21 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYklh-0000bw-KS; Wed, 02 Dec 2026 08:53:13 -0500 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2AN4cF239010; Wed, 2 Dec 2026 13:52:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=pbD14n dr17gM4j9pUVhkj5yDJ2NBlodKRt4LJozH9PQ=; b=oIBdfsm/w3mMam/UObiHmv 2IhpiolZTK2cbk4kZP/qBtX3LR+d4Scdy5Axjkc7YKRpKsUikDBWJzqbp/Ga0aYs qgj6gsqHpNMEr4rAqpiTrJ4m8QRpzi2jBBmEFr3tZELV6Pa0tJsmQQsF49jA5RUk K24/+Go3s/Dte/e6wCCJRumzsdQs1G5u6XpDJx3ffPByBt+amIbHRkwcYxa7A07V YUyTTwLxJlg3u9BnzCzEkfYxdZdnAEUZEUfASOltkjPuC/NOAsZUBt0DkNx7onew qnR2A8QkcDf0YkPEUu9qm7rAzs5TLM4A4CFUMDUtO2rci6SGB//Vjv56uhthW67w == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pp6222y-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 13:52:55 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2BW8EE2799573; Wed, 2 Dec 2026 13:52:54 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j9v5w57yh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 13:52:54 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B2Dqo6d51708380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2026 13:52:50 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B864A2004B; Wed, 2 Dec 2026 13:52:50 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9491F20040; Wed, 2 Dec 2026 13:52:46 +0000 (GMT) Received: from [9.124.212.61] (unknown [9.124.212.61]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 2 Dec 2026 13:52:46 +0000 (GMT) Message-ID: <0f42ca7e-a76f-4530-a3e1-ce389716a5a7@linux.ibm.com> Date: Wed, 2 Dec 2026 19:22:45 +0530 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v2 3/8] ppc/spapr: add baseline VOF disk boot support To: uverma@linux.ibm.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, aik@amd.com, avnish@linux.ibm.com Cc: pbonzini@redhat.com, th.huth@posteo.eu, sbhat@linux.ibm.com, harshpb@linux.ibm.com, amachhiw@linux.ibm.com, rathc@linux.ibm.com, balaton@eik.bme.hu, philmd@linaro.org, npiggin@gmail.com, marcandre.lureau@redhat.com, fam@euphon.net, alex.bennee@linaro.org, richard.henderson@linaro.org References: <20261002052605.605858-1-uverma@linux.ibm.com> <20261002052605.605858-4-uverma@linux.ibm.com> Content-Language: en-US From: Narayana Murty N In-Reply-To: <20261002052605.605858-4-uverma@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-GUID: uHNbtFhUowTZPtJEM8g9nJzTr0A4LkNL X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDA1NCBTYWx0ZWRfX8XshBhEv/sZo 1xfKyPULeFo3wTkWyjNowSMpf/LXNGbLkcR2r7yYqpHEM8qNXyztp2XlGAN1N6byprBvAX9uq1I WYrfPEvYwv7NALhXBWDsVGCMy60YUYU= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDA1NCBTYWx0ZWRfX2AFblH/q6KrE FOUibO3wgEKtqryNcH/oNFikDUKXrK2WLqqqbRWjdNCOVGp3vr6oq6f5952L1RTefKaU/s2Gr5M eVt8Ki1Lh8o+g/KLUsEqzm3s1ONOXMOOvN7HPNoiDu4JklsPYYmyEQJ4Gvbf8cLzbK4+PbIePik Eb8BfZ9L9wfIIApqANr2NsyDdKG2T6TiozJqKb6wJl1HKWieoHP5o3WXvMzu2lySvQ9LvYB9mHP Gm3VcYtBQ7plivKXHVQAF4zRHUv82sYS1RUXjTZOwBE1o7B6hXtZgH0hHhdsJ72nQIfNxeZGNrm eDOWRk0yfenRNmIRLN66bg1MovmIA2C4oBgsMelt5Ou/NWcJtEvNPPoFXTv53B9hVCd2eP3bo05 JqhDO5HcdeSUXWeG+PIuNmndG5t+7lBWcbzmedsA8ZP8A5639VuCnPgTMSTu8udtJvMSVOFfd4P 5PIlwTjONBf3bVh8Dkg== X-Authority-Analysis: v=2.4 cv=Ae8kjHXG c=1 sm=1 tr=0 ts=6b1022b8 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=taxXk4MN6LwNqIeyzF8A:9 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: u43ojeTw-5ECRnlYd-BPDBNkKQgpFpOZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_02,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020054 Received-SPF: pass client-ip=148.163.156.1; envelope-from=nnmlinux@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Utkarsh, On 02/10/26 10:55 AM, uverma@linux.ibm.com wrote: > From: Utkarsh Verma > > Add initial support for disk boot via VOF. > Scan all the block devices, and for each device search for PReP partition, > load the ELF payload (GRUB), and set the '/chosen' node in FDT with boot kernel > and bootpath properties. > > AI-used-for: code > Signed-off-by: Utkarsh Verma > --- > Chaneglog: > v2: > - Added bounds checking for partition size before doing g_malloc. > - Added a roll back logic for cleaning the memory map FDT for paritial > claims. > --- > hw/ppc/spapr_vof.c | 162 ++++++++++++++++++++++++++++++++++++++++--- > hw/ppc/vof.c | 3 + > include/hw/ppc/vof.h | 2 + > 3 files changed, 159 insertions(+), 8 deletions(-) > > diff --git a/hw/ppc/spapr_vof.c b/hw/ppc/spapr_vof.c > index 46d78756e6..78d5b7d5b5 100644 > --- a/hw/ppc/spapr_vof.c > +++ b/hw/ppc/spapr_vof.c > @@ -10,10 +10,19 @@ > #include "hw/ppc/spapr_cpu_core.h" > #include "hw/ppc/fdt.h" > #include "hw/ppc/vof.h" > +#include "hw/ppc/spapr_vof.h" > +#include "hw/core/qdev.h" > +#include "hw/core/loader.h" > #include "system/system.h" > +#include "system/block-backend.h" > +#include "system/block-backend-global-state.h" > #include "qom/qom-qobject.h" > +#include "target/ppc/cpu.h" > +#include "elf.h" > #include "trace.h" > > +#define SPAPR_VOF_PREP_MAX_SIZE (10 * 1024 * 1024) > + > target_ulong spapr_h_vof_client(PowerPCCPU *cpu, SpaprMachineState *spapr, > target_ulong opcode, target_ulong *_args) > { > @@ -32,10 +41,10 @@ void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt) > > vof_build_dt(fdt, spapr->vof); > > - if (spapr->vof->bootargs) { > - int chosen; > + int chosen; > + _FDT(chosen = fdt_path_offset(fdt, "/chosen")); > > - _FDT(chosen = fdt_path_offset(fdt, "/chosen")); > + if (spapr->vof->bootargs) { > /* > * If the client did not change "bootargs", spapr_dt_chosen() must have > * stored machine->kernel_cmdline in it before getting here. > @@ -43,6 +52,22 @@ void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt) > _FDT(fdt_setprop_string(fdt, chosen, "bootargs", spapr->vof->bootargs)); > } > > + if (spapr->vof->disk_boot) { > + /* > + * If disk boot is detected change the "qemu,boot-kernel" to hold > + * kernel_addr/kernel_size which contain the GRUB entry point and size > + */ > + uint64_t kern[2]; > + kern[0] = cpu_to_be64(spapr->kernel_addr); > + kern[1] = cpu_to_be64(spapr->kernel_size); > + _FDT(fdt_setprop(fdt, chosen, "qemu,boot-kernel", &kern, sizeof(kern))); > + > + if (spapr->vof->bootpath) { > + _FDT(fdt_setprop_string(fdt, chosen, "bootpath", > + spapr->vof->bootpath)); > + } > + } > + > /* > * SLOF-less setup requires an open instance of stdout for early > * kernel printk. By now all phandles are settled so we can open > @@ -54,11 +79,116 @@ void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt) > } > } > > +static bool vof_elf_segment_cb(void *opaque, > + uint64_t paddr, uint64_t vaddr, > + uint64_t filesz, uint64_t memsz) > +{ > + Vof *vof = opaque; > + > + if (memsz == 0) { > + return true; > + } > + > + if (paddr != vaddr) { > + error_report("spapr_vof_load_elf: segment paddr/vaddr mismatch " > + "(paddr=0x%" PRIx64 " vaddr=0x%" PRIx64 ")", > + paddr, vaddr); > + return false; > + } > + > + if (vof_claim(vof, paddr, memsz, 0) == -1) { > + error_report("spapr_vof_load_elf: vof_claim failed for " > + "paddr=0x%" PRIx64 " size=0x%" PRIx64, paddr, memsz); > + return false; > + } paddr and memsz are derived from the ELF program headers and are 64-bit values. Are we guaranteed that both values, including the resulting address range, can be represented by the VOF claim interface? Should we validate the complete segment range before passing these values to vof_claim()? > + > + return true; > +} > + > +static bool spapr_vof_try_prep_boot(SpaprMachineState *spapr, Vof *vof) > +{ > + BlockBackend *blk; > + DeviceState *dev; > + uint64_t partition_offset; > + uint64_t partition_size; > + uint8_t *prep_data; > + uint64_t entry_point; > + uint64_t load_size; > + int64_t blk_len; > + > + for (blk = blk_next(NULL); blk; blk = blk_next(blk)) { > + > + if (!blk_is_inserted(blk)) { > + continue; > + } Shouldn't the boot device selection follow the configured firmware boot order rather than the BlockBackend iteration order? If multiple disks contain valid PReP partitions, what guarantees that the disk specified by bootindex is selected? Also, blk_next() is not restricted to block devices supported by the VOF client interface. For example, could we load GRUB from a virtio-blk device while the VOF block backend in patch 5 only supports vSCSI devices? Should the boot device discovery be restricted to devices that VOF can subsequently access? > + > + partition_offset = 0; > + partition_size = 0; > + > + if (!spapr_vof_find_prep_partition(blk, &partition_offset, > + &partition_size)) { > + continue; > + } > + > + blk_len = blk_getlength(blk); > + if (blk_len < 0 || > + partition_size == 0 || > + partition_size > SPAPR_VOF_PREP_MAX_SIZE || > + partition_offset > (uint64_t)blk_len || > + partition_size > (uint64_t)blk_len - partition_offset) { > + continue; > + } > + > + prep_data = g_malloc(partition_size); > + if (blk_pread(blk, partition_offset, partition_size, > + prep_data, 0) < 0) { > + g_free(prep_data); > + continue; > + } > + > + guint saved_claimed_len = vof->claimed->len; > + uint64_t saved_claimed_base = vof->claimed_base; > + > + uint64_t lowaddr = UINT64_MAX, highaddr = 0; > + entry_point = 0; > + ssize_t ret = load_elf_ram_sym_buf(prep_data, partition_size, > + NULL, NULL, NULL, > + &entry_point, &lowaddr, &highaddr, > + NULL, ELFDATA2MSB, > + PPC_ELF_MACHINE, 0, 0, > + NULL, false, NULL, > + vof_elf_segment_cb, vof); > + if (ret <= 0) { > + error_report("spapr_vof_try_prep_boot: %s", load_elf_strerror(ret)); > + /* Roll back any partial claims made during the failed load. */ > + g_array_set_size(vof->claimed, saved_claimed_len); > + vof->claimed_base = saved_claimed_base; > + g_free(prep_data); > + continue; > + } Does truncating the array restore the original memory claims if vof_claim() inserts or sorts entries within the array? We could potentially remove an existing claim while retaining one of the claims introduced by the failed ELF load. Would it be better to snapshot the original claim state or provide a helper to roll back the newly created claims? Also, does this rollback cover the effects of any segments already processed by the ELF loader? > + load_size = highaddr - lowaddr; > + > + g_free(prep_data); > + > + spapr->kernel_addr = entry_point; > + spapr->kernel_size = load_size; > + The load size is calculated from highaddr - lowaddr, but kernel_addr is set to entry_point. Are we guaranteed that entry_point is equal to lowaddr? If not, does the resulting address/size pair correctly describe the loaded image to the VOF firmware? > + vof->disk_boot = true; > + dev = blk_get_attached_dev(blk); > + if (dev) { > + vof->bootpath = qdev_get_fw_dev_path(dev); > + } > + return true; Should we consider the boot successful when there is no attached device or a valid firmware device path? Without a valid bootpath, how does GRUB identify the disk from which it was loaded? > + } > + return false; > +} > + > void spapr_vof_reset(SpaprMachineState *spapr, void *fdt, Error **errp) > { > target_ulong stack_ptr; > Vof *vof = spapr->vof; > PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu); > + MachineState *machine = MACHINE(spapr); > > vof_init(vof, spapr->rma_size, errp); > > @@ -70,7 +200,7 @@ void spapr_vof_reset(SpaprMachineState *spapr, void *fdt, Error **errp) > /* Stack grows downwards plus reserve space for the minimum stack frame */ > stack_ptr += VOF_STACK_SIZE - 0x20; > > - if (spapr->kernel_size && > + if (machine->kernel_filename && spapr->kernel_size && > vof_claim(vof, spapr->kernel_addr, spapr->kernel_size, 0) == -1) { > error_setg(errp, "Memory for kernel is in use"); > return; > @@ -82,6 +212,14 @@ void spapr_vof_reset(SpaprMachineState *spapr, void *fdt, Error **errp) > return; > } > > + /* > + * Disk boot: load GRUB from the PReP boot partition on the block device, if > + * no kernel/initrd are provided > + */ > + if (!machine->kernel_filename) { > + spapr_vof_try_prep_boot(spapr, vof); > + } > + Should we handle the return value here? Consider a reset after a successful disk boot, where the original boot disk is no longer available. Do we need to clear the previous kernel_addr/kernel_size values before attempting another disk boot to avoid retaining stale boot state? Thanks, Narayana Murty > spapr_vof_client_dt_finalize(spapr, fdt); > > spapr_cpu_set_entry_state(first_ppc_cpu, SPAPR_ENTRY_POINT, > @@ -91,10 +229,18 @@ void spapr_vof_reset(SpaprMachineState *spapr, void *fdt, Error **errp) > /* > * At this point the expected allocation map is: > * > - * 0..c38 - the initial firmware > - * 8000..10000 - stack > - * 400000.. - kernel > - * 3ea0000.. - initramdisk > + * Kernel + initrd boot: > + * 0..d80 - the initial firmware > + * 8000..10000 - stack > + * 10000..20000 - vscsi-report-luns table (up to 64 KB, if needed) > + * 400000.. - kernel > + * 3ea0000.. - initramdisk > + * > + * Disk (GRUB) boot: > + * 0..d80 - the initial firmware > + * 8000..10000 - stack > + * 10000..20000 - vscsi-report-luns table (up to 64 KB, if needed) > + * 400000.. - GRUB (loaded from PReP partition) > * > * We skip writing FDT as nothing expects it; OF client interface is > * going to be used for reading the device tree. > diff --git a/hw/ppc/vof.c b/hw/ppc/vof.c > index 873e967f1e..9ad1aa7626 100644 > --- a/hw/ppc/vof.c > +++ b/hw/ppc/vof.c > @@ -1042,6 +1042,9 @@ void vof_cleanup(Vof *vof) > vof->of_instances = NULL; > vof->of_instance_last = 0; > vof->claimed_base = 0; > + g_free(vof->bootpath); > + vof->bootpath = NULL; > + vof->disk_boot = false; > } > > void vof_build_dt(void *fdt, Vof *vof) > diff --git a/include/hw/ppc/vof.h b/include/hw/ppc/vof.h > index 3a0fbffe54..e17779ee8a 100644 > --- a/include/hw/ppc/vof.h > +++ b/include/hw/ppc/vof.h > @@ -18,6 +18,8 @@ typedef struct Vof { > GHashTable *of_instances; /* ihandle -> SpaprOfInstance */ > uint32_t of_instance_last; > char *bootargs; > + char *bootpath; > + bool disk_boot; > long fw_size; > } Vof; >