From patchwork Mon Jan 29 16:44:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13535980 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 D2339C47DB3 for ; Mon, 29 Jan 2024 16:45:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.673042.1047176 (Exim 4.92) (envelope-from ) id 1rUUlF-0004xi-9n; Mon, 29 Jan 2024 16:45:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 673042.1047176; Mon, 29 Jan 2024 16:45:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rUUlF-0004xb-5V; Mon, 29 Jan 2024 16:45:29 +0000 Received: by outflank-mailman (input) for mailman id 673042; Mon, 29 Jan 2024 16:45:27 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rUUlD-0004xV-Nu for xen-devel@lists.xenproject.org; Mon, 29 Jan 2024 16:45:27 +0000 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [2a00:1450:4864:20::32a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cd5d7ae1-bec5-11ee-8a43-1f161083a0e0; Mon, 29 Jan 2024 17:45:26 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40ee705e9bfso32595395e9.0 for ; Mon, 29 Jan 2024 08:45:26 -0800 (PST) Received: from m1x-phil.lan ([176.187.219.39]) by smtp.gmail.com with ESMTPSA id m8-20020a05600c4f4800b0040efc268713sm854310wmq.26.2024.01.29.08.45.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Jan 2024 08:45:24 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cd5d7ae1-bec5-11ee-8a43-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706546725; x=1707151525; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xBAuw8z0uG8eCaMVzH857DmMp0S8FwvlSIliw26a1Io=; b=U3oqbPl48lxPL58pfq34k/NpcVLQk+FUsGBcZFPQmsLAOuBiSdfoMwfBocJb9XVKSL 89sMPBqMqvzGxVyLW2Tdua8/WbFE0sjYuLoltlg4BA5wvbsoJOcEVzaWEu0oVSCBj2J5 ZNNI0SjZ3ES3XbgoZux5UmZj7b0Hoj44G+iKG2LXpG5Di9Kl8q3fAa9XeikXMq1SItOz pAmTteN3JcE+Msh76thC3V5euIKAPC4qTVPg+JcH4WUUcg3rQr1b1wA6O7QxOqyXgDbL N1tppQ4E102tWVxRBU/39tMa9Fet8+UZOr6o8uwAskAgWRUrIAJnYdecUL21PFTT9rXv v58Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706546725; x=1707151525; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xBAuw8z0uG8eCaMVzH857DmMp0S8FwvlSIliw26a1Io=; b=V+ay8PoyD82iYJrEe1m+1X28sMLpIOlRNfHV/pWkylsZIIW9CsLQGZFeNZs8jYQT/0 ciDJEXoYV6g5KlhHUrEOXvVQLovME6l2D0RbxFx1Ah1FbWIfK0s/5eKzAeEGuwaPDTjP aw1ceIjok8hPZ8MTIZg8pZXNCr+wPiQQV5vu2KdvhMgPiWKTDq/ZnDb9nn1NGWj+lEib 6oW2JiC42pAbv0zPg3ah4q5RYLptG41EGYrObbxM97z5BBZ5ayu0bFhvh0l5Zjr69TD4 xCsTtM6efIrVQ/Q5ZsSDM7nTc47w7gf9tp0pEN1z2ngC1Uyb+Phd4Zo+RtmmQ6mygXoz 3sVA== X-Gm-Message-State: AOJu0Yy4KUTKOz8gk2mo4fiXB0aNq3ed9I+KkHw4zSIsYUBF7T4vW2vs gu3AT5oEbmDPc7pOKAgIFMCXuPYf2mhiYvZfDsMWgO1Cd/CiWpdDMBxWAyewxzI= X-Google-Smtp-Source: AGHT+IHdySqf8l0B9eRILTzofQq4FI067bCYaqQHaOlpomTXnMMg2eMjSm5D6MRXFRyoc/eMCrPXNw== X-Received: by 2002:a05:600c:4d96:b0:40e:e7c6:ddd3 with SMTP id v22-20020a05600c4d9600b0040ee7c6ddd3mr5188843wmp.9.1706546725381; Mon, 29 Jan 2024 08:45:25 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Paolo Bonzini , kvm@vger.kernel.org, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Zhao Liu , Mark Cave-Ayland , "Michael S. Tsirkin" , Marcel Apfelbaum , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Nicholas Piggin , =?utf-8?b?RnLDqWTDqXJpYyBCYXJyYXQ=?= , =?utf-8?q?Ale?= =?utf-8?q?x_Benn=C3=A9e?= , Viresh Kumar , mzamazal@redhat.com, Stefano Stabellini , Anthony Perard , Paul Durrant , Peter Xu , Fabiano Rosas , Peter Maydell , Cameron Esfahani , Roman Bolshakov , Laurent Vivier , Daniel Henrique Barboza , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , xen-devel@lists.xenproject.org Subject: [PATCH v3 01/29] bulk: Access existing variables initialized to &S->F when available Date: Mon, 29 Jan 2024 17:44:43 +0100 Message-ID: <20240129164514.73104-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240129164514.73104-1-philmd@linaro.org> References: <20240129164514.73104-1-philmd@linaro.org> MIME-Version: 1.0 When a variable is initialized to &struct->field, use it in place. Rationale: while this makes the code more concise, this also helps static analyzers. Mechanical change using the following Coccinelle spatch script: @@ type S, F; identifier s, m, v; @@ S *s; ... F *v = &s->m; <+... - &s->m + v ...+> Inspired-by: Zhao Liu Signed-off-by: Philippe Mathieu-Daudé Acked-by: Fabiano Rosas Reviewed-by: Zhao Liu Reviewed-by: Anthony PERARD --- hw/display/ati.c | 2 +- hw/misc/macio/pmu.c | 2 +- hw/misc/pvpanic-pci.c | 2 +- hw/pci-bridge/cxl_root_port.c | 2 +- hw/ppc/pnv.c | 20 ++++++++++---------- hw/virtio/vhost-user-gpio.c | 8 ++++---- hw/virtio/vhost-user-scmi.c | 6 +++--- hw/virtio/virtio-pci.c | 2 +- hw/xen/xen_pt.c | 6 +++--- migration/multifd-zlib.c | 2 +- target/arm/cpu.c | 4 ++-- target/arm/kvm.c | 2 +- target/arm/machine.c | 6 +++--- target/i386/hvf/x86hvf.c | 2 +- target/m68k/helper.c | 2 +- target/ppc/kvm.c | 8 ++++---- target/riscv/cpu_helper.c | 2 +- 17 files changed, 39 insertions(+), 39 deletions(-) diff --git a/hw/display/ati.c b/hw/display/ati.c index 569b8f6165..8d2501bd82 100644 --- a/hw/display/ati.c +++ b/hw/display/ati.c @@ -991,7 +991,7 @@ static void ati_vga_realize(PCIDevice *dev, Error **errp) } vga_init(vga, OBJECT(s), pci_address_space(dev), pci_address_space_io(dev), true); - vga->con = graphic_console_init(DEVICE(s), 0, s->vga.hw_ops, &s->vga); + vga->con = graphic_console_init(DEVICE(s), 0, s->vga.hw_ops, vga); if (s->cursor_guest_mode) { vga->cursor_invalidate = ati_cursor_invalidate; vga->cursor_draw_line = ati_cursor_draw_line; diff --git a/hw/misc/macio/pmu.c b/hw/misc/macio/pmu.c index e9a90da88f..7fe1c4e517 100644 --- a/hw/misc/macio/pmu.c +++ b/hw/misc/macio/pmu.c @@ -737,7 +737,7 @@ static void pmu_realize(DeviceState *dev, Error **errp) timer_mod(s->one_sec_timer, s->one_sec_target); if (s->has_adb) { - qbus_init(&s->adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS, + qbus_init(adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS, dev, "adb.0"); adb_register_autopoll_callback(adb_bus, pmu_adb_poll, s); } diff --git a/hw/misc/pvpanic-pci.c b/hw/misc/pvpanic-pci.c index c01e4ce864..83be95d0d2 100644 --- a/hw/misc/pvpanic-pci.c +++ b/hw/misc/pvpanic-pci.c @@ -48,7 +48,7 @@ static void pvpanic_pci_realizefn(PCIDevice *dev, Error **errp) PVPanicPCIState *s = PVPANIC_PCI_DEVICE(dev); PVPanicState *ps = &s->pvpanic; - pvpanic_setup_io(&s->pvpanic, DEVICE(s), 2); + pvpanic_setup_io(ps, DEVICE(s), 2); pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &ps->mr); } diff --git a/hw/pci-bridge/cxl_root_port.c b/hw/pci-bridge/cxl_root_port.c index 8f97697631..2cf2f7bf5f 100644 --- a/hw/pci-bridge/cxl_root_port.c +++ b/hw/pci-bridge/cxl_root_port.c @@ -175,7 +175,7 @@ static void cxl_rp_realize(DeviceState *dev, Error **errp) cxl_cstate->dvsec_offset = CXL_ROOT_PORT_DVSEC_OFFSET; cxl_cstate->pdev = pci_dev; - build_dvsecs(&crp->cxl_cstate); + build_dvsecs(cxl_cstate); cxl_component_register_block_init(OBJECT(pci_dev), cxl_cstate, TYPE_CXL_ROOT_PORT); diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 0297871bdd..202a569e27 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -1257,11 +1257,11 @@ static void pnv_chip_power8_realize(DeviceState *dev, Error **errp) } /* Processor Service Interface (PSI) Host Bridge */ - object_property_set_int(OBJECT(&chip8->psi), "bar", PNV_PSIHB_BASE(chip), + object_property_set_int(OBJECT(psi8), "bar", PNV_PSIHB_BASE(chip), &error_fatal); - object_property_set_link(OBJECT(&chip8->psi), ICS_PROP_XICS, + object_property_set_link(OBJECT(psi8), ICS_PROP_XICS, OBJECT(chip8->xics), &error_abort); - if (!qdev_realize(DEVICE(&chip8->psi), NULL, errp)) { + if (!qdev_realize(DEVICE(psi8), NULL, errp)) { return; } pnv_xscom_add_subregion(chip, PNV_XSCOM_PSIHB_BASE, @@ -1292,7 +1292,7 @@ static void pnv_chip_power8_realize(DeviceState *dev, Error **errp) } pnv_xscom_add_subregion(chip, PNV_XSCOM_OCC_BASE, &chip8->occ.xscom_regs); qdev_connect_gpio_out(DEVICE(&chip8->occ), 0, - qdev_get_gpio_in(DEVICE(&chip8->psi), PSIHB_IRQ_OCC)); + qdev_get_gpio_in(DEVICE(psi8), PSIHB_IRQ_OCC)); /* OCC SRAM model */ memory_region_add_subregion(get_system_memory(), PNV_OCC_SENSOR_BASE(chip), @@ -1543,12 +1543,12 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp) &chip9->xive.xscom_regs); /* Processor Service Interface (PSI) Host Bridge */ - object_property_set_int(OBJECT(&chip9->psi), "bar", PNV9_PSIHB_BASE(chip), + object_property_set_int(OBJECT(psi9), "bar", PNV9_PSIHB_BASE(chip), &error_fatal); /* This is the only device with 4k ESB pages */ - object_property_set_int(OBJECT(&chip9->psi), "shift", XIVE_ESB_4K, + object_property_set_int(OBJECT(psi9), "shift", XIVE_ESB_4K, &error_fatal); - if (!qdev_realize(DEVICE(&chip9->psi), NULL, errp)) { + if (!qdev_realize(DEVICE(psi9), NULL, errp)) { return; } pnv_xscom_add_subregion(chip, PNV9_XSCOM_PSIHB_BASE, @@ -1571,7 +1571,7 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp) } pnv_xscom_add_subregion(chip, PNV9_XSCOM_OCC_BASE, &chip9->occ.xscom_regs); qdev_connect_gpio_out(DEVICE(&chip9->occ), 0, qdev_get_gpio_in( - DEVICE(&chip9->psi), PSIHB9_IRQ_OCC)); + DEVICE(psi9), PSIHB9_IRQ_OCC)); /* OCC SRAM model */ memory_region_add_subregion(get_system_memory(), PNV9_OCC_SENSOR_BASE(chip), @@ -1586,7 +1586,7 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp) pnv_xscom_add_subregion(chip, PNV9_XSCOM_SBE_MBOX_BASE, &chip9->sbe.xscom_mbox_regs); qdev_connect_gpio_out(DEVICE(&chip9->sbe), 0, qdev_get_gpio_in( - DEVICE(&chip9->psi), PSIHB9_IRQ_PSU)); + DEVICE(psi9), PSIHB9_IRQ_PSU)); /* HOMER */ object_property_set_link(OBJECT(&chip9->homer), "chip", OBJECT(chip), @@ -1627,7 +1627,7 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp) PNV9_XSCOM_I2CM_SIZE, &chip9->i2c[i].xscom_regs); qdev_connect_gpio_out(DEVICE(&chip9->i2c[i]), 0, - qdev_get_gpio_in(DEVICE(&chip9->psi), + qdev_get_gpio_in(DEVICE(psi9), PSIHB9_IRQ_SBE_I2C)); } } diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index a83437a5da..6d4e9200ff 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -79,9 +79,9 @@ static int vu_gpio_start(VirtIODevice *vdev) * set needed for the vhost configuration. The backend may also * apply backend_features when the feature set is sent. */ - vhost_ack_features(&gpio->vhost_dev, feature_bits, vdev->guest_features); + vhost_ack_features(vhost_dev, feature_bits, vdev->guest_features); - ret = vhost_dev_start(&gpio->vhost_dev, vdev, false); + ret = vhost_dev_start(vhost_dev, vdev, false); if (ret < 0) { error_report("Error starting vhost-user-gpio: %d", ret); goto err_guest_notifiers; @@ -94,7 +94,7 @@ static int vu_gpio_start(VirtIODevice *vdev) * enabling/disabling irqfd. */ for (i = 0; i < gpio->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&gpio->vhost_dev, vdev, i, false); + vhost_virtqueue_mask(vhost_dev, vdev, i, false); } /* @@ -114,7 +114,7 @@ static int vu_gpio_start(VirtIODevice *vdev) err_guest_notifiers: k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, false); err_host_notifiers: - vhost_dev_disable_notifiers(&gpio->vhost_dev, vdev); + vhost_dev_disable_notifiers(vhost_dev, vdev); return ret; } diff --git a/hw/virtio/vhost-user-scmi.c b/hw/virtio/vhost-user-scmi.c index 918bb7dcf7..300847e672 100644 --- a/hw/virtio/vhost-user-scmi.c +++ b/hw/virtio/vhost-user-scmi.c @@ -56,9 +56,9 @@ static int vu_scmi_start(VirtIODevice *vdev) goto err_host_notifiers; } - vhost_ack_features(&scmi->vhost_dev, feature_bits, vdev->guest_features); + vhost_ack_features(vhost_dev, feature_bits, vdev->guest_features); - ret = vhost_dev_start(&scmi->vhost_dev, vdev, true); + ret = vhost_dev_start(vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost-user-scmi: %d", ret); goto err_guest_notifiers; @@ -71,7 +71,7 @@ static int vu_scmi_start(VirtIODevice *vdev) * enabling/disabling irqfd. */ for (i = 0; i < scmi->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&scmi->vhost_dev, vdev, i, false); + vhost_virtqueue_mask(vhost_dev, vdev, i, false); } return 0; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 1a7039fb0c..cb6940fc0e 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1929,7 +1929,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; uint8_t *config; uint32_t size; - VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + VirtIODevice *vdev = virtio_bus_get_device(bus); /* * Virtio capabilities present without diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 36e6f93c37..10ddf6bc91 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -710,7 +710,7 @@ static void xen_pt_destroy(PCIDevice *d) { uint8_t intx; int rc; - if (machine_irq && !xen_host_pci_device_closed(&s->real_device)) { + if (machine_irq && !xen_host_pci_device_closed(host_dev)) { intx = xen_pt_pci_intx(s); rc = xc_domain_unbind_pt_irq(xen_xc, xen_domid, machine_irq, PT_IRQ_TYPE_PCI, @@ -759,8 +759,8 @@ static void xen_pt_destroy(PCIDevice *d) { memory_listener_unregister(&s->io_listener); s->listener_set = false; } - if (!xen_host_pci_device_closed(&s->real_device)) { - xen_host_pci_device_put(&s->real_device); + if (!xen_host_pci_device_closed(host_dev)) { + xen_host_pci_device_put(host_dev); } } /* init */ diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 37ce48621e..237ee49928 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -75,7 +75,7 @@ static int zlib_send_setup(MultiFDSendParams *p, Error **errp) err_free_zbuff: g_free(z->zbuff); err_deflate_end: - deflateEnd(&z->zs); + deflateEnd(zs); err_free_z: g_free(z); error_setg(errp, "multifd %u: %s", p->id, err_msg); diff --git a/target/arm/cpu.c b/target/arm/cpu.c index b60e103046..60ab8f3242 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2087,7 +2087,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) * We rely on no XScale CPU having VFP so we can use the same bits in the * TB flags field for VECSTRIDE and XSCALE_CPAR. */ - assert(arm_feature(&cpu->env, ARM_FEATURE_AARCH64) || + assert(arm_feature(env, ARM_FEATURE_AARCH64) || !cpu_isar_feature(aa32_vfp_simd, cpu) || !arm_feature(env, ARM_FEATURE_XSCALE)); @@ -2129,7 +2129,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) } if (cpu->cfgend) { - if (arm_feature(&cpu->env, ARM_FEATURE_V7)) { + if (arm_feature(env, ARM_FEATURE_V7)) { cpu->reset_sctlr |= SCTLR_EE; } else { cpu->reset_sctlr |= SCTLR_B; diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 81813030a5..ab85d628a8 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -1888,7 +1888,7 @@ int kvm_arch_init_vcpu(CPUState *cs) cpu->psci_version = QEMU_PSCI_VERSION_0_2; cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2; } - if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { + if (!arm_feature(env, ARM_FEATURE_AARCH64)) { cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_EL1_32BIT; } if (!kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PMU_V3)) { diff --git a/target/arm/machine.c b/target/arm/machine.c index 9d7dbaea54..b2b39b2475 100644 --- a/target/arm/machine.c +++ b/target/arm/machine.c @@ -773,7 +773,7 @@ static int cpu_pre_load(void *opaque) env->irq_line_state = UINT32_MAX; if (!kvm_enabled()) { - pmu_op_start(&cpu->env); + pmu_op_start(env); } return 0; @@ -871,11 +871,11 @@ static int cpu_post_load(void *opaque, int version_id) } if (!kvm_enabled()) { - pmu_op_finish(&cpu->env); + pmu_op_finish(env); } if (tcg_enabled()) { - arm_rebuild_hflags(&cpu->env); + arm_rebuild_hflags(env); } return 0; diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c index 3b1ef5f49a..be2c46246e 100644 --- a/target/i386/hvf/x86hvf.c +++ b/target/i386/hvf/x86hvf.c @@ -408,7 +408,7 @@ bool hvf_inject_interrupts(CPUState *cs) if (!(env->hflags & HF_INHIBIT_IRQ_MASK) && (cs->interrupt_request & CPU_INTERRUPT_HARD) && (env->eflags & IF_MASK) && !(info & VMCS_INTR_VALID)) { - int line = cpu_get_pic_interrupt(&x86cpu->env); + int line = cpu_get_pic_interrupt(env); cs->interrupt_request &= ~CPU_INTERRUPT_HARD; if (line >= 0) { wvmcs(cs->accel->fd, VMCS_ENTRY_INTR_INFO, line | diff --git a/target/m68k/helper.c b/target/m68k/helper.c index 14508dfa11..a812f328a1 100644 --- a/target/m68k/helper.c +++ b/target/m68k/helper.c @@ -972,7 +972,7 @@ bool m68k_cpu_tlb_fill(CPUState *cs, vaddr address, int size, access_type |= ACCESS_SUPER; } - ret = get_physical_address(&cpu->env, &physical, &prot, + ret = get_physical_address(env, &physical, &prot, address, access_type, &page_size); if (likely(ret == 0)) { tlb_set_page(cs, address & TARGET_PAGE_MASK, diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 26fa9d0575..b95a0b4928 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -635,8 +635,8 @@ static int kvm_put_fp(CPUState *cs) for (i = 0; i < 32; i++) { uint64_t vsr[2]; - uint64_t *fpr = cpu_fpr_ptr(&cpu->env, i); - uint64_t *vsrl = cpu_vsrl_ptr(&cpu->env, i); + uint64_t *fpr = cpu_fpr_ptr(env, i); + uint64_t *vsrl = cpu_vsrl_ptr(env, i); #if HOST_BIG_ENDIAN vsr[0] = float64_val(*fpr); @@ -704,8 +704,8 @@ static int kvm_get_fp(CPUState *cs) for (i = 0; i < 32; i++) { uint64_t vsr[2]; - uint64_t *fpr = cpu_fpr_ptr(&cpu->env, i); - uint64_t *vsrl = cpu_vsrl_ptr(&cpu->env, i); + uint64_t *fpr = cpu_fpr_ptr(env, i); + uint64_t *vsrl = cpu_vsrl_ptr(env, i); reg.addr = (uintptr_t) &vsr; reg.id = vsx ? KVM_REG_PPC_VSR(i) : KVM_REG_PPC_FPR(i); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index c7cc7eb423..791435d628 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1200,7 +1200,7 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) CPURISCVState *env = &cpu->env; hwaddr phys_addr; int prot; - int mmu_idx = cpu_mmu_index(&cpu->env, false); + int mmu_idx = cpu_mmu_index(env, false); if (get_physical_address(env, &phys_addr, &prot, addr, NULL, 0, mmu_idx, true, env->virt_enabled, true)) { From patchwork Mon Jan 29 16:44:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13535981 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 2E19BC47DB3 for ; Mon, 29 Jan 2024 16:47:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.673044.1047186 (Exim 4.92) (envelope-from ) id 1rUUmZ-0005XT-MN; Mon, 29 Jan 2024 16:46:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 673044.1047186; Mon, 29 Jan 2024 16:46:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rUUmZ-0005XM-JD; Mon, 29 Jan 2024 16:46:51 +0000 Received: by outflank-mailman (input) for mailman id 673044; Mon, 29 Jan 2024 16:46:49 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rUUmX-0005Wr-G7 for xen-devel@lists.xenproject.org; Mon, 29 Jan 2024 16:46:49 +0000 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [2a00:1450:4864:20::42d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fd81ecd8-bec5-11ee-98f5-efadbce2ee36; Mon, 29 Jan 2024 17:46:46 +0100 (CET) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33ae42033e2so1631367f8f.1 for ; Mon, 29 Jan 2024 08:46:46 -0800 (PST) Received: from m1x-phil.lan ([176.187.219.39]) by smtp.gmail.com with ESMTPSA id t18-20020adfe112000000b0033ade19da41sm7770957wrz.76.2024.01.29.08.46.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Jan 2024 08:46:45 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fd81ecd8-bec5-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706546806; x=1707151606; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lpXGLN2/IW24ZmgFDsSJNzcKsXfzg0OW+1h+hViDXfI=; b=GsdjRYbJjbh5IsKODtVL9gBsJ9IWHe/edBFRjqGs6nIwlNz4Qae1KGoCQz20TphCal BWB9LHpwegu0YCnoYqU6OUOL8E51CmaDZL3PS/hKXS7MHH7f7BP2Bp8cMQ7V24jIoUCG zNKBfTDXVgHdqNsJCYfzrqyz9M3KKggtkA3XEnF5ZVOZ/7AYHRIPQyKj6YroK4cIjxD6 wmtX1Vp1quC+ZaKh3iXJwdV2qIPl5qNaZYKuDBfBLjqrdUBUdnn4WdaQkMPF2/1TPEA/ x1mvUJNMtZhkJSEVGjv5YXyoNGv3wioMRiDo5hw30ntji1DW6qT8iKQzu7J5UZ38t+2j lmuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706546806; x=1707151606; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lpXGLN2/IW24ZmgFDsSJNzcKsXfzg0OW+1h+hViDXfI=; b=TzNGnoWyuOJO7mepSaRhBuxGd/hDAdTsOQqEvvTQxw5bN1cdRPWUh5iG8+fOyZnpT1 0lZQb1fORxt+VXZ3jUUMJAlg8uunMLGVCpddfemRnh6vFZihy8XijveQtrs4cBa/FCFi Jk7c4KWtS4tv6r6BSMmu62q5ZZl5Wn0dxub1KtOWgJ0zKJBs7HYWO4YKEBcG2NIgttpM KPz9oQlP0bxNpxt9tuNV8XabMz2aNIIYp7oTPUZq3BqOGEV2u+u2/mEIjtWxWFlXWlrO mq2o3ZYm8KuVEgcr3zk04Q5aCCYfWNRqzLYZIA4f9hSKGXBGWUfQqx56eLxq3li9625F MYWw== X-Gm-Message-State: AOJu0YzxKvSiLkaRhiOtfk44fAGsWmhxVoI2uvyvjvYUVPPXvIajTvb9 rS3yCGIAqoVg1e7HCQsplPjXARYL6w8ftjZB0UbBzTLzvQ4CQsQPeFiPZvrnwyU= X-Google-Smtp-Source: AGHT+IHYP78wTun1efbdPT3m4ED9+tbNOVo7TfxCjm+JiqqtOKQrQXroDflnsjZz5SiBtFeBKbp9LA== X-Received: by 2002:adf:fdd0:0:b0:33a:df56:1f02 with SMTP id i16-20020adffdd0000000b0033adf561f02mr4447265wrs.13.1706546806131; Mon, 29 Jan 2024 08:46:46 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Paolo Bonzini , kvm@vger.kernel.org, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , "Michael S. Tsirkin" , Marcel Apfelbaum , Eduardo Habkost , Stefano Stabellini , Anthony Perard , Paul Durrant , Cameron Esfahani , Roman Bolshakov , Marcelo Tosatti , David Woodhouse , xen-devel@lists.xenproject.org Subject: [PATCH v3 14/29] target/i386: Prefer fast cpu_env() over slower CPU QOM cast macro Date: Mon, 29 Jan 2024 17:44:56 +0100 Message-ID: <20240129164514.73104-15-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240129164514.73104-1-philmd@linaro.org> References: <20240129164514.73104-1-philmd@linaro.org> MIME-Version: 1.0 Mechanical patch produced running the command documented in scripts/coccinelle/cpu_env.cocci_template header. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Acked-by: David Woodhouse Reviewed-by: Zhao Liu Reviewed-by: Zhao Liu --- target/i386/hvf/vmx.h | 13 ++------- hw/i386/fw_cfg.c | 3 +- hw/i386/vmmouse.c | 6 ++-- hw/i386/xen/xen-hvm.c | 3 +- target/i386/arch_dump.c | 11 ++------ target/i386/arch_memory_mapping.c | 3 +- target/i386/cpu-dump.c | 3 +- target/i386/cpu.c | 37 ++++++++---------------- target/i386/helper.c | 42 ++++++++-------------------- target/i386/hvf/hvf.c | 8 ++---- target/i386/hvf/x86.c | 4 +-- target/i386/hvf/x86_emu.c | 6 ++-- target/i386/hvf/x86_task.c | 10 ++----- target/i386/hvf/x86hvf.c | 9 ++---- target/i386/kvm/kvm.c | 6 ++-- target/i386/kvm/xen-emu.c | 32 +++++++-------------- target/i386/tcg/sysemu/bpt_helper.c | 3 +- target/i386/tcg/sysemu/excp_helper.c | 3 +- target/i386/tcg/tcg-cpu.c | 14 +++------- target/i386/tcg/user/excp_helper.c | 6 ++-- target/i386/tcg/user/seg_helper.c | 3 +- 21 files changed, 67 insertions(+), 158 deletions(-) diff --git a/target/i386/hvf/vmx.h b/target/i386/hvf/vmx.h index 0fffcfa46c..1ad042269b 100644 --- a/target/i386/hvf/vmx.h +++ b/target/i386/hvf/vmx.h @@ -175,8 +175,7 @@ static inline void macvm_set_cr4(hv_vcpuid_t vcpu, uint64_t cr4) static inline void macvm_set_rip(CPUState *cpu, uint64_t rip) { - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; + CPUX86State *env = cpu_env(cpu); uint64_t val; /* BUG, should take considering overlap.. */ @@ -196,10 +195,7 @@ static inline void macvm_set_rip(CPUState *cpu, uint64_t rip) static inline void vmx_clear_nmi_blocking(CPUState *cpu) { - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; - - env->hflags2 &= ~HF2_NMI_MASK; + cpu_env(cpu)->hflags2 &= ~HF2_NMI_MASK; uint32_t gi = (uint32_t) rvmcs(cpu->accel->fd, VMCS_GUEST_INTERRUPTIBILITY); gi &= ~VMCS_INTERRUPTIBILITY_NMI_BLOCKING; wvmcs(cpu->accel->fd, VMCS_GUEST_INTERRUPTIBILITY, gi); @@ -207,10 +203,7 @@ static inline void vmx_clear_nmi_blocking(CPUState *cpu) static inline void vmx_set_nmi_blocking(CPUState *cpu) { - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; - - env->hflags2 |= HF2_NMI_MASK; + cpu_env(cpu)->hflags2 |= HF2_NMI_MASK; uint32_t gi = (uint32_t)rvmcs(cpu->accel->fd, VMCS_GUEST_INTERRUPTIBILITY); gi |= VMCS_INTERRUPTIBILITY_NMI_BLOCKING; wvmcs(cpu->accel->fd, VMCS_GUEST_INTERRUPTIBILITY, gi); diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c index 7362daa45a..5239cd40fa 100644 --- a/hw/i386/fw_cfg.c +++ b/hw/i386/fw_cfg.c @@ -155,8 +155,7 @@ FWCfgState *fw_cfg_arch_create(MachineState *ms, void fw_cfg_build_feature_control(MachineState *ms, FWCfgState *fw_cfg) { - X86CPU *cpu = X86_CPU(ms->possible_cpus->cpus[0].cpu); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(ms->possible_cpus->cpus[0].cpu); uint32_t unused, ebx, ecx, edx; uint64_t feature_control_bits = 0; uint64_t *val; diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c index a8d014d09a..f292a14a15 100644 --- a/hw/i386/vmmouse.c +++ b/hw/i386/vmmouse.c @@ -74,8 +74,7 @@ struct VMMouseState { static void vmmouse_get_data(uint32_t *data) { - X86CPU *cpu = X86_CPU(current_cpu); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(current_cpu); data[0] = env->regs[R_EAX]; data[1] = env->regs[R_EBX]; data[2] = env->regs[R_ECX]; data[3] = env->regs[R_EDX]; @@ -84,8 +83,7 @@ static void vmmouse_get_data(uint32_t *data) static void vmmouse_set_data(const uint32_t *data) { - X86CPU *cpu = X86_CPU(current_cpu); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(current_cpu); env->regs[R_EAX] = data[0]; env->regs[R_EBX] = data[1]; env->regs[R_ECX] = data[2]; env->regs[R_EDX] = data[3]; diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index f42621e674..61e5060117 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -487,8 +487,7 @@ static void regs_to_cpu(vmware_regs_t *vmport_regs, ioreq_t *req) static void regs_from_cpu(vmware_regs_t *vmport_regs) { - X86CPU *cpu = X86_CPU(current_cpu); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(current_cpu); vmport_regs->ebx = env->regs[R_EBX]; vmport_regs->ecx = env->regs[R_ECX]; diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c index c290910a04..8939ff9fa9 100644 --- a/target/i386/arch_dump.c +++ b/target/i386/arch_dump.c @@ -203,7 +203,6 @@ int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, DumpState *s) { - X86CPU *cpu = X86_CPU(cs); x86_elf_prstatus prstatus; Elf32_Nhdr *note; char *buf; @@ -211,7 +210,7 @@ int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, const char *name = "CORE"; int ret; - x86_fill_elf_prstatus(&prstatus, &cpu->env, cpuid); + x86_fill_elf_prstatus(&prstatus, cpu_env(cs), cpuid); descsz = sizeof(x86_elf_prstatus); note_size = ELF_NOTE_SIZE(sizeof(Elf32_Nhdr), name_size, descsz); note = g_malloc0(note_size); @@ -381,17 +380,13 @@ static inline int cpu_write_qemu_note(WriteCoreDumpFunction f, int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cs, DumpState *s) { - X86CPU *cpu = X86_CPU(cs); - - return cpu_write_qemu_note(f, &cpu->env, s, 1); + return cpu_write_qemu_note(f, cpu_env(cs), s, 1); } int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cs, DumpState *s) { - X86CPU *cpu = X86_CPU(cs); - - return cpu_write_qemu_note(f, &cpu->env, s, 0); + return cpu_write_qemu_note(f, cpu_env(cs), s, 0); } int cpu_get_dump_info(ArchDumpInfo *info, diff --git a/target/i386/arch_memory_mapping.c b/target/i386/arch_memory_mapping.c index d1ff659128..c0604d5956 100644 --- a/target/i386/arch_memory_mapping.c +++ b/target/i386/arch_memory_mapping.c @@ -269,8 +269,7 @@ static void walk_pml5e(MemoryMappingList *list, AddressSpace *as, bool x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list, Error **errp) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); int32_t a20_mask; if (!cpu_paging_enabled(cs)) { diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c index 40697064d9..5459d84abd 100644 --- a/target/i386/cpu-dump.c +++ b/target/i386/cpu-dump.c @@ -343,8 +343,7 @@ void x86_cpu_dump_local_apic_state(CPUState *cs, int flags) void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); int eflags, i, nb; char cc_op_name[32]; static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" }; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 66345c204a..5d7a266d27 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5062,8 +5062,7 @@ static void x86_cpuid_version_get_family(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); int64_t value; value = (env->cpuid_version >> 8) & 0xf; @@ -5077,8 +5076,7 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); const int64_t min = 0; const int64_t max = 0xff + 0xf; int64_t value; @@ -5104,8 +5102,7 @@ static void x86_cpuid_version_get_model(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); int64_t value; value = (env->cpuid_version >> 4) & 0xf; @@ -5117,8 +5114,7 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); const int64_t min = 0; const int64_t max = 0xff; int64_t value; @@ -5140,11 +5136,9 @@ static void x86_cpuid_version_get_stepping(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; int64_t value; - value = env->cpuid_version & 0xf; + value = cpu_env(CPU(obj))->cpuid_version & 0xf; visit_type_int(v, name, &value, errp); } @@ -5152,8 +5146,7 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); const int64_t min = 0; const int64_t max = 0xf; int64_t value; @@ -5173,8 +5166,7 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, static char *x86_cpuid_get_vendor(Object *obj, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); char *value; value = g_malloc(CPUID_VENDOR_SZ + 1); @@ -5186,8 +5178,7 @@ static char *x86_cpuid_get_vendor(Object *obj, Error **errp) static void x86_cpuid_set_vendor(Object *obj, const char *value, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); int i; if (strlen(value) != CPUID_VENDOR_SZ) { @@ -5208,8 +5199,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value, static char *x86_cpuid_get_model_id(Object *obj, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); char *value; int i; @@ -5224,8 +5214,7 @@ static char *x86_cpuid_get_model_id(Object *obj, Error **errp) static void x86_cpuid_set_model_id(Object *obj, const char *model_id, Error **errp) { - X86CPU *cpu = X86_CPU(obj); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(CPU(obj)); int c, len, i; if (model_id == NULL) { @@ -7673,8 +7662,7 @@ static vaddr x86_cpu_get_pc(CPUState *cs) int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); #if !defined(CONFIG_USER_ONLY) if (interrupt_request & CPU_INTERRUPT_POLL) { @@ -7722,8 +7710,7 @@ static bool x86_cpu_has_work(CPUState *cs) static void x86_disas_set_info(CPUState *cs, disassemble_info *info) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); info->mach = (env->hflags & HF_CS64_MASK ? bfd_mach_x86_64 : env->hflags & HF_CS32_MASK ? bfd_mach_i386_i386 diff --git a/target/i386/helper.c b/target/i386/helper.c index 2070dd0dda..4c11ef70f0 100644 --- a/target/i386/helper.c +++ b/target/i386/helper.c @@ -230,8 +230,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4) hwaddr x86_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, MemTxAttrs *attrs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); target_ulong pde_addr, pte_addr; uint64_t pte; int32_t a20_mask; @@ -373,8 +372,7 @@ static void emit_guest_memory_failure(MemoryFailureAction action, bool ar, static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data) { MCEInjectionParams *params = data.host_ptr; - X86CPU *cpu = X86_CPU(cs); - CPUX86State *cenv = &cpu->env; + CPUX86State *cenv = cpu_env(cs); uint64_t *banks = cenv->mce_banks + 4 * params->bank; g_autofree char *msg = NULL; bool need_reset = false; @@ -625,9 +623,7 @@ void cpu_load_efer(CPUX86State *env, uint64_t val) uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); return address_space_ldub(as, addr, attrs, NULL); @@ -635,9 +631,7 @@ uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr) uint32_t x86_lduw_phys(CPUState *cs, hwaddr addr) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); return address_space_lduw(as, addr, attrs, NULL); @@ -645,9 +639,7 @@ uint32_t x86_lduw_phys(CPUState *cs, hwaddr addr) uint32_t x86_ldl_phys(CPUState *cs, hwaddr addr) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); return address_space_ldl(as, addr, attrs, NULL); @@ -655,9 +647,7 @@ uint32_t x86_ldl_phys(CPUState *cs, hwaddr addr) uint64_t x86_ldq_phys(CPUState *cs, hwaddr addr) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); return address_space_ldq(as, addr, attrs, NULL); @@ -665,9 +655,7 @@ uint64_t x86_ldq_phys(CPUState *cs, hwaddr addr) void x86_stb_phys(CPUState *cs, hwaddr addr, uint8_t val) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); address_space_stb(as, addr, val, attrs, NULL); @@ -675,9 +663,7 @@ void x86_stb_phys(CPUState *cs, hwaddr addr, uint8_t val) void x86_stl_phys_notdirty(CPUState *cs, hwaddr addr, uint32_t val) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); address_space_stl_notdirty(as, addr, val, attrs, NULL); @@ -685,9 +671,7 @@ void x86_stl_phys_notdirty(CPUState *cs, hwaddr addr, uint32_t val) void x86_stw_phys(CPUState *cs, hwaddr addr, uint32_t val) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); address_space_stw(as, addr, val, attrs, NULL); @@ -695,9 +679,7 @@ void x86_stw_phys(CPUState *cs, hwaddr addr, uint32_t val) void x86_stl_phys(CPUState *cs, hwaddr addr, uint32_t val) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); address_space_stl(as, addr, val, attrs, NULL); @@ -705,9 +687,7 @@ void x86_stl_phys(CPUState *cs, hwaddr addr, uint32_t val) void x86_stq_phys(CPUState *cs, hwaddr addr, uint64_t val) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - MemTxAttrs attrs = cpu_get_mem_attrs(env); + MemTxAttrs attrs = cpu_get_mem_attrs(cpu_env(cs)); AddressSpace *as = cpu_addressspace(cs, attrs); address_space_stq(as, addr, val, attrs, NULL); diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 11ffdd4c69..772578e3f4 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -159,10 +159,7 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual) void hvf_arch_vcpu_destroy(CPUState *cpu) { - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; - - g_free(env->hvf_mmio_buf); + g_free(cpu_env(cpu)->hvf_mmio_buf); } static void init_tsc_freq(CPUX86State *env) @@ -313,8 +310,7 @@ int hvf_arch_init_vcpu(CPUState *cpu) static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idtvec_info) { - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; + CPUX86State *env = cpu_env(cpu); env->exception_nr = -1; env->exception_pending = 0; diff --git a/target/i386/hvf/x86.c b/target/i386/hvf/x86.c index 80e36136d0..932635232b 100644 --- a/target/i386/hvf/x86.c +++ b/target/i386/hvf/x86.c @@ -128,9 +128,7 @@ bool x86_is_real(CPUState *cpu) bool x86_is_v8086(CPUState *cpu) { - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; - return x86_is_protected(cpu) && (env->eflags & VM_MASK); + return x86_is_protected(cpu) && (cpu_env(cpu)->eflags & VM_MASK); } bool x86_is_long_mode(CPUState *cpu) diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c index 3a3f0a50d0..0d13b32f91 100644 --- a/target/i386/hvf/x86_emu.c +++ b/target/i386/hvf/x86_emu.c @@ -1419,8 +1419,7 @@ static void init_cmd_handler() void load_regs(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); int i = 0; RRX(env, R_EAX) = rreg(cs->accel->fd, HV_X86_RAX); @@ -1442,8 +1441,7 @@ void load_regs(CPUState *cs) void store_regs(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); int i = 0; wreg(cs->accel->fd, HV_X86_RAX, RAX(env)); diff --git a/target/i386/hvf/x86_task.c b/target/i386/hvf/x86_task.c index f09bfbdda5..c173e9d883 100644 --- a/target/i386/hvf/x86_task.c +++ b/target/i386/hvf/x86_task.c @@ -33,8 +33,7 @@ // TODO: taskswitch handling static void save_state_to_tss32(CPUState *cpu, struct x86_tss_segment32 *tss) { - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; + CPUX86State *env = cpu_env(cpu); /* CR3 and ldt selector are not saved intentionally */ tss->eip = (uint32_t)env->eip; @@ -58,8 +57,7 @@ static void save_state_to_tss32(CPUState *cpu, struct x86_tss_segment32 *tss) static void load_state_from_tss32(CPUState *cpu, struct x86_tss_segment32 *tss) { - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; + CPUX86State *env = cpu_env(cpu); wvmcs(cpu->accel->fd, VMCS_GUEST_CR3, tss->cr3); @@ -128,9 +126,7 @@ void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int rea uint32_t desc_limit; struct x86_call_gate task_gate_desc; struct vmx_segment vmx_seg; - - X86CPU *x86_cpu = X86_CPU(cpu); - CPUX86State *env = &x86_cpu->env; + CPUX86State *env = cpu_env(cpu); x86_read_segment_descriptor(cpu, &next_tss_desc, tss_sel); x86_read_segment_descriptor(cpu, &curr_tss_desc, old_tss_sel); diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c index be2c46246e..10f79849b3 100644 --- a/target/i386/hvf/x86hvf.c +++ b/target/i386/hvf/x86hvf.c @@ -238,8 +238,7 @@ void hvf_get_msrs(CPUState *cs) int hvf_put_registers(CPUState *cs) { - X86CPU *x86cpu = X86_CPU(cs); - CPUX86State *env = &x86cpu->env; + CPUX86State *env = cpu_env(cs); wreg(cs->accel->fd, HV_X86_RAX, env->regs[R_EAX]); wreg(cs->accel->fd, HV_X86_RBX, env->regs[R_EBX]); @@ -282,8 +281,7 @@ int hvf_put_registers(CPUState *cs) int hvf_get_registers(CPUState *cs) { - X86CPU *x86cpu = X86_CPU(cs); - CPUX86State *env = &x86cpu->env; + CPUX86State *env = cpu_env(cs); env->regs[R_EAX] = rreg(cs->accel->fd, HV_X86_RAX); env->regs[R_EBX] = rreg(cs->accel->fd, HV_X86_RBX); @@ -342,8 +340,7 @@ void vmx_clear_int_window_exiting(CPUState *cs) bool hvf_inject_interrupts(CPUState *cs) { - X86CPU *x86cpu = X86_CPU(cs); - CPUX86State *env = &x86cpu->env; + CPUX86State *env = cpu_env(cs); uint8_t vector; uint64_t intr_type; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 76a66246eb..e4f1c62888 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -754,8 +754,7 @@ static inline bool freq_within_bounds(int freq, int target_freq) static int kvm_arch_set_tsc_khz(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); int r, cur_freq; bool set_ioctl = false; @@ -5369,8 +5368,7 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) bool kvm_arch_stop_on_emulation_error(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); kvm_cpu_synchronize_state(cs); return !(env->cr[0] & CR0_PE_MASK) || diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index fc2c2321ac..10350a22d1 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -313,10 +313,7 @@ static int kvm_xen_set_vcpu_callback_vector(CPUState *cs) static void do_set_vcpu_callback_vector(CPUState *cs, run_on_cpu_data data) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - - env->xen_vcpu_callback_vector = data.host_int; + cpu_env(cs)->xen_vcpu_callback_vector = data.host_int; if (kvm_xen_has_cap(EVTCHN_SEND)) { kvm_xen_set_vcpu_callback_vector(cs); @@ -325,8 +322,7 @@ static void do_set_vcpu_callback_vector(CPUState *cs, run_on_cpu_data data) static int set_vcpu_info(CPUState *cs, uint64_t gpa) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); MemoryRegionSection mrs = { .mr = NULL }; void *vcpu_info_hva = NULL; int ret; @@ -362,8 +358,7 @@ static int set_vcpu_info(CPUState *cs, uint64_t gpa) static void do_set_vcpu_info_default_gpa(CPUState *cs, run_on_cpu_data data) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); env->xen_vcpu_info_default_gpa = data.host_ulong; @@ -375,8 +370,7 @@ static void do_set_vcpu_info_default_gpa(CPUState *cs, run_on_cpu_data data) static void do_set_vcpu_info_gpa(CPUState *cs, run_on_cpu_data data) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); env->xen_vcpu_info_gpa = data.host_ulong; @@ -479,8 +473,7 @@ void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type) /* Must always be called with xen_timers_lock held */ static int kvm_xen_set_vcpu_timer(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); struct kvm_xen_vcpu_attr va = { .type = KVM_XEN_VCPU_ATTR_TYPE_TIMER, @@ -527,8 +520,7 @@ int kvm_xen_set_vcpu_virq(uint32_t vcpu_id, uint16_t virq, uint16_t port) static void do_set_vcpu_time_info_gpa(CPUState *cs, run_on_cpu_data data) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); env->xen_vcpu_time_info_gpa = data.host_ulong; @@ -538,8 +530,7 @@ static void do_set_vcpu_time_info_gpa(CPUState *cs, run_on_cpu_data data) static void do_set_vcpu_runstate_gpa(CPUState *cs, run_on_cpu_data data) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); env->xen_vcpu_runstate_gpa = data.host_ulong; @@ -549,8 +540,7 @@ static void do_set_vcpu_runstate_gpa(CPUState *cs, run_on_cpu_data data) static void do_vcpu_soft_reset(CPUState *cs, run_on_cpu_data data) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); env->xen_vcpu_info_gpa = INVALID_GPA; env->xen_vcpu_info_default_gpa = INVALID_GPA; @@ -1813,8 +1803,7 @@ uint16_t kvm_xen_get_evtchn_max_pirq(void) int kvm_put_xen_state(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); uint64_t gpa; int ret; @@ -1887,8 +1876,7 @@ int kvm_put_xen_state(CPUState *cs) int kvm_get_xen_state(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); uint64_t gpa; int ret; diff --git a/target/i386/tcg/sysemu/bpt_helper.c b/target/i386/tcg/sysemu/bpt_helper.c index 4d96a48a3c..90d6117497 100644 --- a/target/i386/tcg/sysemu/bpt_helper.c +++ b/target/i386/tcg/sysemu/bpt_helper.c @@ -208,8 +208,7 @@ bool check_hw_breakpoints(CPUX86State *env, bool force_dr6_update) void breakpoint_handler(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); if (cs->watchpoint_hit) { if (cs->watchpoint_hit->flags & BP_CPU) { diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/excp_helper.c index 5b86f439ad..1afa177551 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -639,6 +639,5 @@ G_NORETURN void x86_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { - X86CPU *cpu = X86_CPU(cs); - handle_unaligned_access(&cpu->env, vaddr, access_type, retaddr); + handle_unaligned_access(cpu_env(cs), vaddr, access_type, retaddr); } diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c index e1405b7be9..8f8fd6529d 100644 --- a/target/i386/tcg/tcg-cpu.c +++ b/target/i386/tcg/tcg-cpu.c @@ -29,8 +29,7 @@ static void x86_cpu_exec_enter(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); env->df = 1 - (2 * ((env->eflags >> 10) & 1)); @@ -40,8 +39,7 @@ static void x86_cpu_exec_enter(CPUState *cs) static void x86_cpu_exec_exit(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); env->eflags = cpu_compute_eflags(env); } @@ -65,8 +63,7 @@ static void x86_restore_state_to_opc(CPUState *cs, const TranslationBlock *tb, const uint64_t *data) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); int cc_op = data[1]; uint64_t new_pc; @@ -96,11 +93,8 @@ static void x86_restore_state_to_opc(CPUState *cs, #ifndef CONFIG_USER_ONLY static bool x86_debug_check_breakpoint(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - /* RF disables all architectural breakpoints. */ - return !(env->eflags & RF_MASK); + return !(cpu_env(cs)->eflags & RF_MASK); } #endif diff --git a/target/i386/tcg/user/excp_helper.c b/target/i386/tcg/user/excp_helper.c index b3bdb7831a..9ea5566149 100644 --- a/target/i386/tcg/user/excp_helper.c +++ b/target/i386/tcg/user/excp_helper.c @@ -26,8 +26,7 @@ void x86_cpu_record_sigsegv(CPUState *cs, vaddr addr, MMUAccessType access_type, bool maperr, uintptr_t ra) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); /* * The error_code that hw reports as part of the exception frame @@ -52,6 +51,5 @@ void x86_cpu_record_sigsegv(CPUState *cs, vaddr addr, void x86_cpu_record_sigbus(CPUState *cs, vaddr addr, MMUAccessType access_type, uintptr_t ra) { - X86CPU *cpu = X86_CPU(cs); - handle_unaligned_access(&cpu->env, addr, access_type, ra); + handle_unaligned_access(cpu_env(cs), addr, access_type, ra); } diff --git a/target/i386/tcg/user/seg_helper.c b/target/i386/tcg/user/seg_helper.c index c45f2ac2ba..2f89dbb51e 100644 --- a/target/i386/tcg/user/seg_helper.c +++ b/target/i386/tcg/user/seg_helper.c @@ -78,8 +78,7 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int, void x86_cpu_do_interrupt(CPUState *cs) { - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; + CPUX86State *env = cpu_env(cs); /* if user mode only, we simulate a fake exception which will be handled outside the cpu execution