From patchwork Mon Sep 19 23:17:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 12981107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5578FC6FA8B for ; Mon, 19 Sep 2022 23:20:48 +0000 (UTC) Received: from localhost ([::1]:36832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oaQ4F-0000oa-6b for qemu-devel@archiver.kernel.org; Mon, 19 Sep 2022 19:20:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaQ1v-00065g-3g; Mon, 19 Sep 2022 19:18:23 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:37790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oaQ1t-0001np-0x; Mon, 19 Sep 2022 19:18:22 -0400 Received: by mail-ej1-x62d.google.com with SMTP id a26so2208275ejc.4; Mon, 19 Sep 2022 16:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=/k4I9yFOQcmiC4x/pIxNVj/VFsZVkB/VTnKtzXV6Nqg=; b=HeU8zrtYBI/0x6nYhy30ykBOxV7FJFi9qix+CVX0GQ295jAdVYP99cwpVxn/2LzxCi ZP5HRKIK6CCkoV8ZYaMeoxr7Er2J7tkGFzoZESbBQa3Q/GPx3mVwKz2IoZNjt/UK7KTA +ihVNLs1B8kQsrWVCKS154FLqcTZ7LjxhE5wx61z1x9ykd/cnWa6+EObscXByUSrlnxu 2p8uLD9vwG4GAwVM6hnJqUMiO5KALvwOqjrkAiOSaB7w+Ho12rSGreEd514XIyflj9qP 8m6Uxp0tRrmxmCRjrG0e2Upp6UcGEKsXugZH9piZvYjMOtG1eklpjW88WsouvJFJCC5o ldSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=/k4I9yFOQcmiC4x/pIxNVj/VFsZVkB/VTnKtzXV6Nqg=; b=aHyzr0YVJYpl3XCfriI5p6ThUtkYqfow7vkyQZo97xLolhsr/Xxnz1YRa7nhCRKtdA cbehJfc9f/TwFTQZvTqakt74/1K9R4PmYoi3ghzEzsvz6TIZpeZSWsZDt+7Wn9lYJPU/ K3HsWEvNesK2huzr3xDgdh0hevN8jMxvjLsVx1sryuh7m1P1h8w9RtweUlqHDsqVh8Xn 3aJ8Ir9cN9OvBiUJ9i6i6sXA+/lz4Zo2lgb/XedrnDRXBb070LPntvcBmeSS5koCFNSv KAspod57/3csUhqs0kdauF2eRpLLnNyJpk1Y2Z8Vy4Eu7oH8KqrwtEq0JyGXhy2o/zuE UQaQ== X-Gm-Message-State: ACrzQf213X+MyAlbEfU8azFE4VZdsENC+pKrM7lGVETeRafqHCiGqETw B5yMWqUqjWyVKcIZwTUR2bjJOs6jXMdtPQ== X-Google-Smtp-Source: AMsMyM6qssf98dEArMM6jpNsUS/ykm1rQJXRhzB+Z5C5spX4oNAkXfl0aR9MWbXenJhowWfNIt1+Yg== X-Received: by 2002:a17:907:2c62:b0:77a:e3ce:5ef0 with SMTP id ib2-20020a1709072c6200b0077ae3ce5ef0mr15170276ejc.553.1663629496806; Mon, 19 Sep 2022 16:18:16 -0700 (PDT) Received: from localhost.localdomain (dynamic-078-054-077-055.78.54.pool.telefonica.de. [78.54.77.55]) by smtp.gmail.com with ESMTPSA id rn24-20020a170906d93800b00780f6071b5dsm4800926ejb.188.2022.09.19.16.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 16:18:16 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Magnus Damm , Aleksandar Rikalo , Bandan Das , Matthew Rosato , Daniel Henrique Barboza , Sergio Lopez , Alexey Kardashevskiy , Xiaojuan Yang , Cameron Esfahani , Michael Rolnik , Song Gao , Jagannathan Raman , Greg Kurz , Kamil Rytarowski , Peter Xu , Joel Stanley , Alistair Francis , "Dr. David Alan Gilbert" , Paolo Bonzini , haxm-team@intel.com, Roman Bolshakov , Markus Armbruster , Eric Auger , David Gibson , =?utf-8?q?Daniel_P=2E_Berrang?= =?utf-8?q?=C3=A9?= , Christian Borntraeger , =?utf-8?q?C=C3=A9dric_Le?= =?utf-8?q?_Goater?= , Stefan Hajnoczi , qemu-block@nongnu.org, Eduardo Habkost , =?utf-8?q?Her?= =?utf-8?q?v=C3=A9_Poussineau?= , qemu-ppc@nongnu.org, Cornelia Huck , Palmer Dabbelt , Helge Deller , Stefano Stabellini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-riscv@nongnu.org, Stafford Horne , Paul Durrant , Havard Skinnemoen , Elena Ufimtseva , Alexander Graf , Thomas Huth , Alex Williamson , Wenchao Wang , Tony Krowiak , Marcel Apfelbaum , qemu-s390x@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Mark Cave-Ayland , Eric Farman , Reinoud Zandijk , Alexander Bulekov , Yanan Wang , "Edgar E. Iglesias" , Gerd Hoffmann , Tyrone Ting , xen-devel@lists.xenproject.org, Yoshinori Sato , John Snow , Richard Henderson , Darren Kenny , kvm@vger.kernel.org, Qiuhao Li , John G Johnson , Bin Meng , Sunil Muthuswamy , Max Filippov , qemu-arm@nongnu.org, Marcelo Tosatti , Peter Maydell , Anthony Perard , Andrew Jeffery , Artyom Tarasenko , Halil Pasic , "Maciej S. Szmigiero" , Jason Wang , David Hildenbrand , Laurent Vivier , Alistair Francis , Jason Herne , Bernhard Beschow Subject: [PATCH 0/9] Deprecate sysbus_get_default() and get_system_memory() et. al Date: Tue, 20 Sep 2022 01:17:11 +0200 Message-Id: <20220919231720.163121-1-shentey@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=shentey@gmail.com; helo=mail-ej1-x62d.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In address-spaces.h it can be read that get_system_memory() and get_system_io() are temporary interfaces which "should only be used temporarily until a proper bus interface is available". This statement certainly extends to the address_space_memory and address_space_io singletons. This series attempts to stop further proliferation of their use by turning TYPE_SYSTEM_BUS into an object-oriented, "proper bus interface" inspired by PCIBus. While at it, also the main_system_bus singleton is turned into an attribute of MachineState. Together, this resolves five singletons in total, making the ownership relations much more obvious which helps comprehension. The series is structured as follows: Patch 1 fixes a memory corruption issue uncovered by running `make check` on the last but one patch of this series. Patches 2 and 3 turn the main_system_bus singleton into an attribute of MachineState which provides an alternative to sysbus_get_default(). Patches 4-7 resolve the address space singletons and deprecate the legacy get_system_memory() et. al functions. Patch 8 attempts to optimize the new implementations of these legacy functions. Testing done: * make check (passes without any issues) * make check-avocado (no new issues seem to be introduced compared to master) Bernhard Beschow (9): hw/riscv/sifive_e: Fix inheritance of SiFiveEState exec/hwaddr.h: Add missing include hw/core/sysbus: Resolve main_system_bus singleton hw/ppc/spapr: Fix code style problems reported by checkpatch exec/address-spaces: Wrap address space singletons into functions target/loongarch/cpu: Remove unneeded include directive hw/sysbus: Introduce dedicated struct SysBusState for TYPE_SYSTEM_BUS softmmu/physmem: Let SysBusState absorb memory region and address space singletons exec/address-spaces: Inline legacy functions accel/hvf/hvf-accel-ops.c | 2 +- accel/kvm/kvm-all.c | 12 +++---- hw/alpha/dp264.c | 4 +-- hw/alpha/typhoon.c | 4 +-- hw/arm/smmu-common.c | 4 +-- hw/arm/smmuv3.c | 14 ++++---- hw/arm/virt.c | 2 +- hw/char/goldfish_tty.c | 4 +-- hw/core/bus.c | 5 ++- hw/core/loader.c | 2 +- hw/core/machine.c | 3 ++ hw/core/sysbus.c | 24 ++++---------- hw/dma/pl330.c | 2 +- hw/dma/rc4030.c | 2 +- hw/dma/xlnx-zynq-devcfg.c | 4 +-- hw/dma/xlnx_dpdma.c | 8 ++--- hw/hppa/machine.c | 4 +-- hw/hyperv/hyperv.c | 2 +- hw/hyperv/vmbus.c | 2 +- hw/i386/amd_iommu.c | 18 +++++----- hw/i386/fw_cfg.c | 2 +- hw/i386/intel_iommu.c | 24 +++++++------- hw/i386/microvm.c | 4 +-- hw/i386/pc.c | 2 +- hw/i386/xen/xen-hvm.c | 4 +-- hw/ide/ahci.c | 2 +- hw/ide/macio.c | 10 +++--- hw/intc/apic.c | 2 +- hw/intc/openpic_kvm.c | 2 +- hw/intc/pnv_xive.c | 6 ++-- hw/intc/pnv_xive2.c | 6 ++-- hw/intc/riscv_aplic.c | 2 +- hw/intc/spapr_xive.c | 2 +- hw/intc/xive.c | 4 +-- hw/intc/xive2.c | 4 +-- hw/mips/jazz.c | 4 +-- hw/misc/lasi.c | 2 +- hw/misc/macio/mac_dbdma.c | 8 ++--- hw/net/ftgmac100.c | 16 ++++----- hw/net/i82596.c | 24 +++++++------- hw/net/imx_fec.c | 22 ++++++------- hw/net/lasi_i82596.c | 2 +- hw/net/npcm7xx_emc.c | 14 ++++---- hw/openrisc/boot.c | 2 +- hw/pci-host/dino.c | 6 ++-- hw/pci-host/pnv_phb3.c | 6 ++-- hw/pci-host/pnv_phb3_msi.c | 6 ++-- hw/pci-host/pnv_phb4.c | 10 +++--- hw/pci/pci.c | 2 +- hw/ppc/pnv_psi.c | 2 +- hw/ppc/spapr.c | 4 +-- hw/ppc/spapr_events.c | 2 +- hw/ppc/spapr_hcall.c | 4 +-- hw/ppc/spapr_iommu.c | 4 +-- hw/ppc/spapr_ovec.c | 8 ++--- hw/ppc/spapr_rtas.c | 2 +- hw/remote/iommu.c | 2 +- hw/remote/message.c | 4 +-- hw/remote/proxy-memory-listener.c | 2 +- hw/riscv/boot.c | 6 ++-- hw/riscv/sifive_e.c | 2 +- hw/riscv/sifive_u.c | 2 +- hw/riscv/virt.c | 2 +- hw/s390x/css.c | 16 ++++----- hw/s390x/ipl.h | 2 +- hw/s390x/s390-pci-bus.c | 4 +-- hw/s390x/s390-pci-inst.c | 10 +++--- hw/s390x/s390-skeys.c | 2 +- hw/s390x/virtio-ccw.c | 10 +++--- hw/sd/sdhci.c | 2 +- hw/sh4/r2d.c | 4 +-- hw/sparc/sun4m.c | 2 +- hw/sparc/sun4m_iommu.c | 4 +-- hw/sparc64/sun4u_iommu.c | 4 +-- hw/timer/hpet.c | 2 +- hw/usb/hcd-ehci-pci.c | 2 +- hw/usb/hcd-ehci-sysbus.c | 2 +- hw/usb/hcd-ohci.c | 2 +- hw/usb/hcd-xhci-sysbus.c | 2 +- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/common.c | 8 ++--- hw/vfio/platform.c | 2 +- hw/virtio/vhost-vdpa.c | 2 +- hw/virtio/vhost.c | 2 +- hw/virtio/virtio-bus.c | 4 +-- hw/virtio/virtio-iommu.c | 6 ++-- hw/virtio/virtio-pci.c | 2 +- hw/xen/xen_pt.c | 4 +-- include/exec/address-spaces.h | 49 +++++++++++++++++++++++----- include/exec/hwaddr.h | 1 + include/hw/boards.h | 2 ++ include/hw/elf_ops.h | 4 +-- include/hw/misc/macio/macio.h | 2 +- include/hw/ppc/spapr.h | 6 ++-- include/hw/ppc/vof.h | 4 +-- include/hw/riscv/sifive_e.h | 3 +- include/hw/sysbus.h | 14 ++++++-- monitor/misc.c | 4 +-- softmmu/ioport.c | 12 +++---- softmmu/memory_mapping.c | 2 +- softmmu/physmem.c | 41 ++++++++--------------- target/arm/hvf/hvf.c | 4 +-- target/arm/kvm.c | 4 +-- target/avr/helper.c | 8 ++--- target/i386/hax/hax-all.c | 2 +- target/i386/hax/hax-mem.c | 2 +- target/i386/hvf/hvf.c | 2 +- target/i386/hvf/vmx.h | 2 +- target/i386/hvf/x86_mmu.c | 6 ++-- target/i386/nvmm/nvmm-all.c | 4 +-- target/i386/sev.c | 4 +-- target/i386/tcg/sysemu/misc_helper.c | 12 +++---- target/i386/whpx/whpx-all.c | 4 +-- target/loongarch/cpu.h | 1 - target/s390x/diag.c | 2 +- target/s390x/mmu_helper.c | 2 +- target/s390x/sigp.c | 2 +- target/xtensa/dbg_helper.c | 2 +- tests/qtest/fuzz/generic_fuzz.c | 4 +-- 120 files changed, 355 insertions(+), 328 deletions(-)