[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PULL 03/10] microvm: add device tree support.
From: |
Peter Maydell |
Subject: |
Re: [PULL 03/10] microvm: add device tree support. |
Date: |
Fri, 5 Nov 2021 16:01:48 +0000 |
On Tue, 2 Nov 2021 at 16:48, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> Allows edk2 detect virtio-mmio devices and pcie ecam.
> See comment in hw/i386/microvm-dt.c for more details.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> Reviewed-by: Sergio Lopez <slp@redhat.com>
> Message-Id: <20211014193617.2475578-1-kraxel@redhat.com>
Hi; Coverity points out a couple of issues in this code.
> +static void dt_add_pcie(MicrovmMachineState *mms)
> +{
> + hwaddr base = PCIE_MMIO_BASE;
> + int nr_pcie_buses;
> + char *nodename;
> +
> + nodename = g_strdup_printf("/pcie@%" PRIx64, base);
Here we allocate 'nodename'...
> + qemu_fdt_add_subnode(mms->fdt, nodename);
> + qemu_fdt_setprop_string(mms->fdt, nodename,
> + "compatible", "pci-host-ecam-generic");
> + qemu_fdt_setprop_string(mms->fdt, nodename, "device_type", "pci");
> + qemu_fdt_setprop_cell(mms->fdt, nodename, "#address-cells", 3);
> + qemu_fdt_setprop_cell(mms->fdt, nodename, "#size-cells", 2);
> + qemu_fdt_setprop_cell(mms->fdt, nodename, "linux,pci-domain", 0);
> + qemu_fdt_setprop(mms->fdt, nodename, "dma-coherent", NULL, 0);
> +
> + qemu_fdt_setprop_sized_cells(mms->fdt, nodename, "reg",
> + 2, PCIE_ECAM_BASE, 2, PCIE_ECAM_SIZE);
> + if (mms->gpex.mmio64.size) {
> + qemu_fdt_setprop_sized_cells(mms->fdt, nodename, "ranges",
> +
> + 1, FDT_PCI_RANGE_MMIO,
> + 2, mms->gpex.mmio32.base,
> + 2, mms->gpex.mmio32.base,
> + 2, mms->gpex.mmio32.size,
> +
> + 1, FDT_PCI_RANGE_MMIO_64BIT,
> + 2, mms->gpex.mmio64.base,
> + 2, mms->gpex.mmio64.base,
> + 2, mms->gpex.mmio64.size);
> + } else {
> + qemu_fdt_setprop_sized_cells(mms->fdt, nodename, "ranges",
> +
> + 1, FDT_PCI_RANGE_MMIO,
> + 2, mms->gpex.mmio32.base,
> + 2, mms->gpex.mmio32.base,
> + 2, mms->gpex.mmio32.size);
> + }
> +
> + nr_pcie_buses = PCIE_ECAM_SIZE / PCIE_MMCFG_SIZE_MIN;
> + qemu_fdt_setprop_cells(mms->fdt, nodename, "bus-range", 0,
> + nr_pcie_buses - 1);
...but unlike other functions in this file we forget to free it.
(CID 1465240)
Might be worth considering use of g_autofree.
> +}
> +void dt_setup_microvm(MicrovmMachineState *mms)
> +{
> + X86MachineState *x86ms = X86_MACHINE(mms);
> + int size = 0;
> +
> + mms->fdt = create_device_tree(&size);
> +
> + /* root node */
> + qemu_fdt_setprop_string(mms->fdt, "/", "compatible", "linux,microvm");
> + qemu_fdt_setprop_cell(mms->fdt, "/", "#address-cells", 0x2);
> + qemu_fdt_setprop_cell(mms->fdt, "/", "#size-cells", 0x2);
> +
> + qemu_fdt_add_subnode(mms->fdt, "/chosen");
> + dt_setup_sys_bus(mms);
> +
> + /* add to fw_cfg */
> + fprintf(stderr, "%s: add etc/fdt to fw_cfg\n", __func__);
> + fw_cfg_add_file(x86ms->fw_cfg, "etc/fdt", mms->fdt, size);
> +
> + if (debug) {
> + fprintf(stderr, "%s: writing microvm.fdt\n", __func__);
> + g_file_set_contents("microvm.fdt", mms->fdt, size, NULL);
g_file_set_contents() returns a value to indicate success or
failure; we should check it.
(CID 1465239)
> + int ret = system("dtc -I dtb -O dts microvm.fdt");
> + if (ret != 0) {
> + fprintf(stderr, "%s: oops, dtc not installed?\n", __func__);
> + }
> + }
> +}
thanks
-- PMM
- [PULL 00/10] Misc 20211102 patches, Gerd Hoffmann, 2021/11/02
- [PULL 02/10] MAINTAINERS: add myself as partial audio reviewer, Gerd Hoffmann, 2021/11/02
- [PULL 01/10] MAINTAINERS: Add myself as a reviewer for SDL audio, Gerd Hoffmann, 2021/11/02
- [PULL 04/10] ui/gtk: Update the refresh rate for gl-area too, Gerd Hoffmann, 2021/11/02
- [PULL 05/10] ui/gtk: skip any extra draw of same guest scanout blob res, Gerd Hoffmann, 2021/11/02
- [PULL 09/10] hw/misc: deprecate the 'sga' device, Gerd Hoffmann, 2021/11/02
- [PULL 03/10] microvm: add device tree support., Gerd Hoffmann, 2021/11/02
- Re: [PULL 03/10] microvm: add device tree support.,
Peter Maydell <=
- [PULL 07/10] ui/console: replace kbd_timer with chr_accept_input callback, Gerd Hoffmann, 2021/11/02
- [PULL 08/10] ui/console: remove chardev frontend connected test, Gerd Hoffmann, 2021/11/02
- [PULL 10/10] usb-storage: tag usb_msd_csw as packed struct, Gerd Hoffmann, 2021/11/02
- [PULL 06/10] ui/console: replace QEMUFIFO with Fifo8, Gerd Hoffmann, 2021/11/02
- Re: [PULL 00/10] Misc 20211102 patches, Richard Henderson, 2021/11/03