virtio,pc,pci: fixes,cleanups,features
Subsystems (3)
Changes from pull v1:
dropped introspection patches from the pull
The following changes since commit 9de5f2b40860c5f8295e73fea9922df6f0b8d89a:
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2022-05-12 10:52:15 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
for you to fetch changes up to 6852c21db229c4bf4c1db772444bdfbbd027e5b8:
vhost-user-scsi: avoid unlink(NULL) with fd passing (2022-05-16 16:48:35 -0400)
----------------------------------------------------------------
virtio,pc,pci: fixes,cleanups,features
most of CXL support
fixes, cleanups all over the place
----------------------------------------------------------------
Alex Bennée (9):
hw/virtio: move virtio-pci.h into shared include space
virtio-pci: add notification trace points
hw/virtio: add vhost_user_[read|write] trace points vhost-user.rst: add clarifying language about protocol negotiation
libvhost-user: expose vu_request_to_string
docs/devel: start documenting writing VirtIO devices include/hw: start documenting the vhost API hw/virtio/vhost-user: don't suppress F_CONFIG when supported virtio/vhost-user: dynamically assign VhostUserHostNotifiers
Ben Widawsky (24):
hw/pci/cxl: Add a CXL component type (interface) hw/cxl/component: Introduce CXL components (8.1.x, 8.2.5) hw/cxl/device: Introduce a CXL device (8.2.8) hw/cxl/device: Implement the CAP array (8.2.8.1-2) hw/cxl/device: Implement basic mailbox (8.2.8.4) hw/cxl/device: Add memory device utilities hw/cxl/device: Add cheap EVENTS implementation (8.2.9.1) hw/cxl/device: Timestamp implementation (8.2.9.3) hw/cxl/device: Add log commands (8.2.9.4) + CEL hw/pxb: Use a type for realizing expanders hw/pci/cxl: Create a CXL bus type
hw/pxb: Allow creation of a CXL PXB (host bridge) hw/cxl/rp: Add a root port
hw/cxl/device: Add a memory device (8.2.8.5) hw/cxl/device: Implement MMIO HDM decoding (8.2.5.12) hw/cxl/device: Add some trivial commands hw/cxl/device: Plumb real Label Storage Area (LSA) sizing hw/cxl/device: Implement get/set Label Storage Area (LSA) hw/cxl/component: Implement host bridge MMIO (8.2.5, table 142) acpi/cxl: Add _OSC implementation (9.14.2)
acpi/cxl: Create the CEDT (9.14.1)
acpi/cxl: Introduce CFMWS structures in CEDT hw/cxl/component Add a dumb HDM decoder handler qtest/cxl: Add more complex test cases with CFMWs
David Woodhouse (4):
target/i386: Fix sanity check on max APIC ID / X2APIC enablement
intel_iommu: Support IR-only mode without DMA translation
intel_iommu: Only allow interrupt remapping to be enabled if it's supported
intel_iommu: Fix irqchip / X2APIC configuration checks
Eugenio Pérez (5):
vhost: Track descriptor chain in private at SVQ
vhost: Fix device's used descriptor dequeue
vdpa: Fix bad index calculus at vhost_vdpa_get_vring_base
vdpa: Fix index calculus at vhost_vdpa_svqs_start
vhost: Fix element in vhost_svq_add failure
Francisco Iglesias (2):
include/hw/pci/pcie_host: Correct PCIE_MMCFG_BUS_MASK include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Halil Pasic (1):
virtio: fix feature negotiation for ACCESS_PLATFORM
Ilya Maximets (1):
vhost_net: Print feature masks in hex
Jason Wang (5):
intel-iommu: correct the value used for error_setg_errno()
intel-iommu: remove VTD_FR_RESERVED_ERR
intel-iommu: block output address in interrupt address range
intel-iommu: update root_scalable before switching as during post_load
intel-iommu: update iq_dw during post load
Jonah Palmer (2):
virtio: drop name parameter for virtio_init()
virtio: add vhost support for virtio devices
Jonathan Cameron (16):
MAINTAINERS: Add entry for Compute Express Link Emulation
cxl: Machine level control on whether CXL support is enabled qtest/cxl: Introduce initial test for pxb-cxl only. qtests/cxl: Add initial root port and CXL type3 tests hw/cxl/component: Add utils for interleave parameter encoding/decoding hw/cxl/host: Add support for CXL Fixed Memory Windows. hw/pci-host/gpex-acpi: Add support for dsdt construction for pxb-cxl pci/pcie_port: Add pci_find_port_by_pn() CXL/cxl_component: Add cxl_get_hb_cstate()
mem/cxl_type3: Add read and write functions for associated hostmem. cxl/cxl-host: Add memops for CFMWS region.
i386/pc: Enable CXL fixed memory windows
tests/acpi: q35: Allow addition of a CXL test. qtests/bios-tables-test: Add a test for CXL emulation. tests/acpi: Add tables for CXL emulation.
docs/cxl: Add initial Compute eXpress Link (CXL) documentation.
Kevin Wolf (1):
docs/vhost-user: Clarifications for VHOST_USER_ADD/REM_MEM_REG
Michael S. Tsirkin (1):
vhost-user: more master/slave things
Paolo Bonzini (3):
docs: vhost-user: clean up request/reply description
docs: vhost-user: rewrite section on ring state machine
docs: vhost-user: replace master/slave with front-end/back-end
Philippe Mathieu-Daudé (1):
hw/virtio: Replace g_memdup() by g_memdup2()
Si-Wei Liu (7):
virtio-net: setup vhost_dev and notifiers for cvq only when feature is negotiated
virtio-net: align ctrl_vq index for non-mq guest for vhost_vdpa
vhost-vdpa: fix improper cleanup in net_init_vhost_vdpa
vhost-net: fix improper cleanup in vhost_net_start
vhost-vdpa: backend feature should set only once
vhost-vdpa: change name and polarity for vhost_vdpa_one_time_request()
virtio-net: don't handle mq request in userspace handler for vhost-vdpa
Stefan Hajnoczi (1):
vhost-user-scsi: avoid unlink(NULL) with fd passing
Wei Huang (1):
hw/i386/amd_iommu: Fix IOMMU event log encoding errors
Xiaoyao Li (2):
hw/i386: Make pit a property of common x86 base machine type hw/i386: Make pic a property of common x86 base machine type
qapi/machine.json | 21 ++
hw/i386/intel_iommu_internal.h | 9 +-
hw/virtio/vhost-shadow-virtqueue.h | 6 +
include/hw/acpi/cxl.h | 28 ++
include/hw/boards.h | 2 +
include/hw/cxl/cxl.h | 61 ++++
include/hw/cxl/cxl_component.h | 223 ++++++++++++
include/hw/cxl/cxl_device.h | 268 ++++++++++++++
include/hw/cxl/cxl_pci.h | 167 +++++++++
include/hw/i386/intel_iommu.h | 1 +
include/hw/i386/microvm.h | 4 -
include/hw/i386/pc.h | 2 -
include/hw/i386/x86.h | 4 +
include/hw/pci/pci.h | 14 +
include/hw/pci/pci_bridge.h | 20 ++
include/hw/pci/pci_bus.h | 7 +
include/hw/pci/pci_ids.h | 1 +
include/hw/pci/pcie_host.h | 6 +-
include/hw/pci/pcie_port.h | 2 +
include/hw/virtio/vhost-user.h | 43 ++-
include/hw/virtio/vhost-vsock-common.h | 2 +-
include/hw/virtio/vhost.h | 132 ++++++-
include/hw/virtio/virtio-gpu.h | 3 +-
{hw => include/hw}/virtio/virtio-pci.h | 0
include/hw/virtio/virtio.h | 7 +-
subprojects/libvhost-user/libvhost-user.h | 9 +
contrib/vhost-user-scsi/vhost-user-scsi.c | 5 +-
hw/9pfs/virtio-9p-device.c | 2 +-
hw/acpi/cxl-stub.c | 12 +
hw/acpi/cxl.c | 257 +++++++++++++
hw/block/vhost-user-blk.c | 9 +-
hw/block/virtio-blk.c | 2 +-
hw/char/virtio-serial-bus.c | 3 +-
hw/core/machine.c | 28 ++
hw/cxl/cxl-component-utils.c | 396 ++++++++++++++++++++
hw/cxl/cxl-device-utils.c | 265 ++++++++++++++
hw/cxl/cxl-host-stubs.c | 16 +
hw/cxl/cxl-host.c | 222 ++++++++++++
hw/cxl/cxl-mailbox-utils.c | 478 ++++++++++++++++++++++++
hw/display/vhost-user-gpu.c | 7 +
hw/display/virtio-gpu-base.c | 2 +-
hw/i386/acpi-build.c | 57 ++-
hw/i386/amd_iommu.c | 24 +-
hw/i386/intel_iommu.c | 95 +++--
hw/i386/microvm.c | 54 +--
hw/i386/pc.c | 89 +++--
hw/i386/pc_piix.c | 4 +-
hw/i386/pc_q35.c | 4 +-
hw/i386/x86.c | 66 ++++
hw/input/vhost-user-input.c | 7 +
hw/input/virtio-input.c | 3 +-
hw/mem/cxl_type3.c | 371 +++++++++++++++++++
hw/net/vhost_net.c | 8 +-
hw/net/virtio-net.c | 63 +++-
hw/pci-bridge/cxl_root_port.c | 236 ++++++++++++
hw/pci-bridge/pci_expander_bridge.c | 168 ++++++++-
hw/pci-bridge/pcie_root_port.c | 6 +-
hw/pci-host/gpex-acpi.c | 20 +-
hw/pci/pci.c | 21 +-
hw/pci/pcie_port.c | 25 ++
hw/scsi/vhost-scsi.c | 8 +
hw/scsi/vhost-user-scsi.c | 1 +
hw/scsi/virtio-scsi.c | 3 +-
hw/virtio/vhost-scsi-pci.c | 2 +-
hw/virtio/vhost-shadow-virtqueue.c | 35 +-
hw/virtio/vhost-user-blk-pci.c | 2 +-
hw/virtio/vhost-user-fs-pci.c | 2 +-
hw/virtio/vhost-user-fs.c | 10 +-
hw/virtio/vhost-user-i2c-pci.c | 2 +-
hw/virtio/vhost-user-i2c.c | 7 +-
hw/virtio/vhost-user-input-pci.c | 2 +-
hw/virtio/vhost-user-rng-pci.c | 2 +-
hw/virtio/vhost-user-rng.c | 9 +-
hw/virtio/vhost-user-scsi-pci.c | 2 +-
hw/virtio/vhost-user-vsock-pci.c | 2 +-
hw/virtio/vhost-user-vsock.c | 2 +-
hw/virtio/vhost-user.c | 131 +++++--
hw/virtio/vhost-vdpa.c | 29 +-
hw/virtio/vhost-vsock-common.c | 12 +-
hw/virtio/vhost-vsock-pci.c | 2 +-
hw/virtio/vhost-vsock.c | 2 +-
hw/virtio/vhost.c | 4 +-
hw/virtio/virtio-9p-pci.c | 2 +-
hw/virtio/virtio-balloon-pci.c | 2 +-
hw/virtio/virtio-balloon.c | 3 +-
hw/virtio/virtio-blk-pci.c | 2 +-
hw/virtio/virtio-bus.c | 22 +-
hw/virtio/virtio-crypto.c | 18 +-
hw/virtio/virtio-input-host-pci.c | 2 +-
hw/virtio/virtio-input-pci.c | 2 +-
hw/virtio/virtio-iommu-pci.c | 2 +-
hw/virtio/virtio-iommu.c | 3 +-
hw/virtio/virtio-mem.c | 3 +-
hw/virtio/virtio-net-pci.c | 2 +-
hw/virtio/virtio-pci.c | 5 +-
hw/virtio/virtio-pmem.c | 3 +-
hw/virtio/virtio-rng-pci.c | 2 +-
hw/virtio/virtio-rng.c | 2 +-
hw/virtio/virtio-scsi-pci.c | 2 +-
hw/virtio/virtio-serial-pci.c | 2 +-
hw/virtio/virtio.c | 56 ++-
net/vhost-vdpa.c | 4 +-
softmmu/vl.c | 47 +++
subprojects/libvhost-user/libvhost-user.c | 2 +-
target/i386/kvm/kvm-cpu.c | 2 +-
tests/qtest/bios-tables-test.c | 44 +++
tests/qtest/cxl-test.c | 151 ++++++++
MAINTAINERS | 7 +
docs/devel/index-internals.rst | 1 +
docs/devel/virtio-backends.rst | 214 +++++++++++
docs/interop/vhost-user-gpu.rst | 10 +-
docs/interop/vhost-user.rst | 579 ++++++++++++++++--------------
docs/system/device-emulation.rst | 1 +
docs/system/devices/cxl.rst | 302 ++++++++++++++++
hw/Kconfig | 1 +
hw/acpi/Kconfig | 5 +
hw/acpi/meson.build | 4 +-
hw/arm/Kconfig | 1 +
hw/cxl/Kconfig | 3 +
hw/cxl/meson.build | 12 +
hw/mem/Kconfig | 5 +
hw/mem/meson.build | 1 +
hw/meson.build | 1 +
hw/pci-bridge/Kconfig | 5 +
hw/pci-bridge/meson.build | 1 +
hw/virtio/trace-events | 10 +-
qemu-options.hx | 38 ++
scripts/device-crash-test | 1 +
tests/data/acpi/q35/CEDT.cxl | Bin 0 -> 184 bytes
tests/data/acpi/q35/DSDT.cxl | Bin 0 -> 9615 bytes
tests/qtest/meson.build | 4 +
131 files changed, 5352 insertions(+), 577 deletions(-)
create mode 100644 include/hw/acpi/cxl.h
create mode 100644 include/hw/cxl/cxl.h
create mode 100644 include/hw/cxl/cxl_component.h
create mode 100644 include/hw/cxl/cxl_device.h
create mode 100644 include/hw/cxl/cxl_pci.h
rename {hw => include/hw}/virtio/virtio-pci.h (100%)
create mode 100644 hw/acpi/cxl-stub.c
create mode 100644 hw/acpi/cxl.c
create mode 100644 hw/cxl/cxl-component-utils.c
create mode 100644 hw/cxl/cxl-device-utils.c
create mode 100644 hw/cxl/cxl-host-stubs.c
create mode 100644 hw/cxl/cxl-host.c
create mode 100644 hw/cxl/cxl-mailbox-utils.c
create mode 100644 hw/mem/cxl_type3.c
create mode 100644 hw/pci-bridge/cxl_root_port.c
create mode 100644 tests/qtest/cxl-test.c
create mode 100644 docs/devel/virtio-backends.rst
create mode 100644 docs/system/devices/cxl.rst
create mode 100644 hw/cxl/Kconfig
create mode 100644 hw/cxl/meson.build
create mode 100644 tests/data/acpi/q35/CEDT.cxl
create mode 100644 tests/data/acpi/q35/DSDT.cxl[PULL v2 21/86] hw/cxl/device: Add some trivial commands
From: Ben Widawsky <[email protected]>
GET_FW_INFO and GET_PARTITION_INFO, for this emulation, is equivalent to info already returned in the IDENTIFY command. To have a more robust implementation, add those.
Message-Id: <[email protected]>
--- hw/cxl/cxl-mailbox-utils.c | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
hw/cxl/cxl-mailbox-utils.c +69 -0
@@ -10,6 +10,7 @@#include "qemu/osdep.h" #include "hw/cxl/cxl.h" #include "hw/pci/pci.h" +#include "qemu/cutils.h" #include "qemu/log.h" #include "qemu/uuid.h"
@@ -44,6 +45,8 @@ enum {#define CLEAR_RECORDS 0x1#define GET_INTERRUPT_POLICY 0x2#define SET_INTERRUPT_POLICY 0x3 + FIRMWARE_UPDATE = 0x02, +#define GET_INFO 0x0 TIMESTAMP = 0x03,#define GET 0x0#define SET 0x1
@@ -52,6 +55,8 @@ enum {#define GET_LOG 0x1 IDENTIFY = 0x40,#define MEMORY_DEVICE 0x0 + CCLS = 0x41, +#define GET_PARTITION_INFO 0x0 };/* 8.2.8.4.5.1 Command Return Codes */
@@ -114,6 +119,39 @@ DEFINE_MAILBOX_HANDLER_NOP(events_clear_records);DEFINE_MAILBOX_HANDLER_ZEROED (events_get_interrupt_policy,4 );DEFINE_MAILBOX_HANDLER_NOP (events_set_interrupt_policy); +/* 8.2.9.2.1 */ +static ret_code cmd_firmware_update_get_info (struct cxl_cmd *cmd, +CXLDeviceState *cxl_dstate, +uint16_t *len) +{ +struct { +uint8_t slots_supported; +uint8_t slot_info; +uint8_t caps; +uint8_t rsvd[0xd ]; +char fw_rev1[0x10 ]; +char fw_rev2[0x10 ]; +char fw_rev3[0x10 ]; +char fw_rev4[0x10 ]; + } QEMU_PACKED *fw_info; +QEMU_BUILD_BUG_ON (sizeof (*fw_info) !=0x50 ); + +if (cxl_dstate->pmem_size < (256 <<20 )) { +return CXL_MBOX_INTERNAL_ERROR ; + } + + fw_info = (void *)cmd->payload; +memset (fw_info,0 ,sizeof (*fw_info)); + + fw_info->slots_supported =2 ; + fw_info->slot_info =BIT (0 ) |BIT (3 ); + fw_info->caps =0 ; +pstrcpy (fw_info->fw_rev1,sizeof (fw_info->fw_rev1),"BWFW VERSION 0" ); + + *len =sizeof (*fw_info); +return CXL_MBOX_SUCCESS ; +} +/* 8.2.9.3.1 */ static ret_code cmd_timestamp_get(struct cxl_cmd *cmd, CXLDeviceState *cxl_dstate,
@@ -258,6 +296,33 @@ static ret_code cmd_identify_memory_device(struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } +static ret_code cmd_ccls_get_partition_info (struct cxl_cmd *cmd, +CXLDeviceState *cxl_dstate, +uint16_t *len) +{ +struct { +uint64_t active_vmem; +uint64_t active_pmem; +uint64_t next_vmem; +uint64_t next_pmem; + } QEMU_PACKED *part_info = (void *)cmd->payload; +QEMU_BUILD_BUG_ON (sizeof (*part_info) !=0x20 ); +uint64_t size = cxl_dstate->pmem_size; + +if (!QEMU_IS_ALIGNED (size,256 <<20 )) { +return CXL_MBOX_INTERNAL_ERROR ; + } + +/* PMEM only */ + part_info->active_vmem =0 ; + part_info->next_vmem =0 ; + part_info->active_pmem = size / (256 <<20 ); + part_info->next_pmem =0 ; + + *len =sizeof (*part_info); +return CXL_MBOX_SUCCESS ; +} +#define IMMEDIATE_CONFIG_CHANGE (1 << 1)#define IMMEDIATE_POLICY_CHANGE (1 << 3)#define IMMEDIATE_LOG_CHANGE (1 << 4)
@@ -271,12 +336,16 @@ static struct cxl_cmd cxl_cmd_set[256][256] = { cmd_events_get_interrupt_policy, 0, 0 }, [EVENTS][SET_INTERRUPT_POLICY] = { "EVENTS_SET_INTERRUPT_POLICY", cmd_events_set_interrupt_policy, 4, IMMEDIATE_CONFIG_CHANGE }, + [FIRMWARE_UPDATE][GET_INFO] = { "FIRMWARE_UPDATE_GET_INFO", + cmd_firmware_update_get_info, 0, 0 }, [TIMESTAMP][GET] = { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 }, [TIMESTAMP][SET] = { "TIMESTAMP_SET", cmd_timestamp_set, 8, IMMEDIATE_POLICY_CHANGE }, [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported, 0, 0 }, [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 }, [IDENTIFY][MEMORY_DEVICE] = { "IDENTIFY_MEMORY_DEVICE", cmd_identify_memory_device, 0, 0 }, + [CCLS][GET_PARTITION_INFO] = { "CCLS_GET_PARTITION_INFO", + cmd_ccls_get_partition_info, 0, 0 }, };void cxl_process_mailbox (CXLDeviceState *cxl_dstate)
Signature · 1 line
MST
[PULL v2 31/86] hw/pci-host/gpex-acpi: Add support for dsdt construction for pxb-cxl
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
This adds code to instantiate the slightly extended ACPI root port description in DSDT as per the CXL 2.0 specification.
Basically a cut and paste job from the i386/pc code.
Message-Id: <[email protected]>
--- hw/pci-host/gpex-acpi.c | 20 +++++++++++++++++--- hw/arm/Kconfig | 1 + 2 files changed, 18 insertions(+), 3 deletions(-)
hw/pci-host/gpex-acpi.c +17 -3
@@ -5,6 +5,7 @@#include "hw/pci/pci_bus.h" #include "hw/pci/pci_bridge.h" #include "hw/pci/pcie_host.h" +#include "hw/acpi/cxl.h" static void acpi_dsdt_add_pci_route_table (Aml *dev,uint32_t irq) {
@@ -139,6 +140,7 @@ void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg) QLIST_FOREACH(bus, &bus->child, sibling) {uint8_t bus_num =pci_bus_num (bus);uint8_t numa_node =pci_bus_numa_node (bus); +bool is_cxl =pci_bus_is_cxl (bus);if (!pci_bus_is_root (bus)) {continue ;
@@ -154,8 +156,16 @@ void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg) } dev =aml_device ("PC%.02X" , bus_num); -aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A08" ))); -aml_append (dev,aml_name_decl ("_CID" ,aml_string ("PNP0A03" ))); +if (is_cxl) { +struct Aml *pkg =aml_package (2 ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("ACPI0016" ))); +aml_append (pkg,aml_eisaid ("PNP0A08" )); +aml_append (pkg,aml_eisaid ("PNP0A03" )); +aml_append (dev,aml_name_decl ("_CID" , pkg)); + }else { +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A08" ))); +aml_append (dev,aml_name_decl ("_CID" ,aml_string ("PNP0A03" ))); + }aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_STR" ,aml_unicode ("pxb Device" )));
@@ -175,7 +185,11 @@ void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg) cfg->pio.base, 0, 0, 0);aml_append (dev,aml_name_decl ("_CRS" , crs)); -acpi_dsdt_add_pci_osc (dev); +if (is_cxl) { +build_cxl_osc_method (dev); + }else { +acpi_dsdt_add_pci_osc (dev); + }aml_append (scope, dev); }
hw/arm/Kconfig +1 -0
@@ -29,6 +29,7 @@ config ARM_VIRT select ACPI_APEI select ACPI_VIOT select VIRTIO_MEM_SUPPORTED + select ACPI_CXL config CHEETAH bool
Signature · 1 line
MST
[PULL v2 02/86] intel-iommu: correct the value used for error_setg_errno()
In reply to Michael S. TsirkinFrom: Jason Wang <[email protected]>
error_setg_errno() expects a normal errno value, not a negated one, so we should use ENOTSUP instead of -ENOSUP.
Message-Id: <[email protected]>
--- hw/i386/intel_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu.c +1 -1
@@ -3032,7 +3032,7 @@ static int vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,/* TODO: add support for VFIO and vhost users */ if (s->snoop_control) { -error_setg_errno (errp, -ENOTSUP , +error_setg_errno (errp,ENOTSUP ,"Snoop Control with vhost or VFIO is not supported" );return -ENOTSUP ; }
Signature · 1 line
MST
[PULL v2 01/86] virtio: fix feature negotiation for ACCESS_PLATFORM
In reply to Michael S. TsirkinFrom: Halil Pasic <[email protected]>
Unlike most virtio features ACCESS_PLATFORM is considered mandatory by QEMU, i.e. the driver must accept it if offered by the device. The virtio specification says that the driver SHOULD accept the ACCESS_PLATFORM feature if offered, and that the device MAY fail to operate if ACCESS_PLATFORM was offered but not negotiated.
While a SHOULD ain't exactly a MUST, we are certainly allowed to fail the device when the driver fences ACCESS_PLATFORM. With commit 2943b53f68 ("virtio: force VIRTIO_F_IOMMU_PLATFORM") we already made the decision to do so whenever the get_dma_as() callback is implemented (by the bus), which in practice means for the entirety of virtio-pci.
That means, if the device needs to translate I/O addresses, then ACCESS_PLATFORM is mandatory. The aforementioned commit tells us in the commit message that this is for security reasons. More precisely if we were to allow a less then trusted driver (e.g. an user-space driver, or a nested guest) to make the device bypass the IOMMU by not negotiating ACCESS_PLATFORM, then the guest kernel would have no ability to control/police (by programming the IOMMU) what pieces of guest memory the driver may manipulate using the device. Which would break security assumptions within the guest.
If ACCESS_PLATFORM is offered not because we want the device to utilize an IOMMU and do address translation, but because the device does not have access to the entire guest RAM, and needs the driver to grant access to the bits it needs access to (e.g. confidential guest support), we still require the guest to have the corresponding logic and to accept ACCESS_PLATFORM. If the driver does not accept ACCESS_PLATFORM, then things are bound to go wrong, and we may see failures much less graceful than failing the device because the driver didn't negotiate ACCESS_PLATFORM.
So let us make ACCESS_PLATFORM mandatory for the driver regardless of whether the get_dma_as() callback is implemented or not.
Message-Id: <[email protected]>
--- hw/virtio/virtio-bus.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
hw/virtio/virtio-bus.c +14 -8
@@ -78,17 +78,23 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)return ; } - vdev_has_iommu =virtio_host_has_feature (vdev,VIRTIO_F_IOMMU_PLATFORM ); -if (klass->get_dma_as !=NULL && has_iommu) { + vdev->dma_as = &address_space_memory; +if (has_iommu) { + vdev_has_iommu =virtio_host_has_feature (vdev,VIRTIO_F_IOMMU_PLATFORM ); +/* +* Present IOMMU_PLATFORM to the driver iff iommu_plattform=on and +* device operational. If the driver does not accept IOMMU_PLATFORM +* we fail the device. +*/ virtio_add_feature (&vdev->host_features,VIRTIO_F_IOMMU_PLATFORM ); - vdev->dma_as = klass->get_dma_as (qbus->parent); -if (!vdev_has_iommu && vdev->dma_as != &address_space_memory) { -error_setg (errp, +if (klass->get_dma_as) { + vdev->dma_as = klass->get_dma_as (qbus->parent); +if (!vdev_has_iommu && vdev->dma_as != &address_space_memory) { +error_setg (errp,"iommu_platform=true is not supported by the device" ); -return ; +return ; + } } - }else { - vdev->dma_as = &address_space_memory; } }
Signature · 1 line
MST
[PULL v2 03/86] hw/pci/cxl: Add a CXL component type (interface)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
A CXL component is a hardware entity that implements CXL component registers from the CXL 2.0 spec (8.2.3). Currently these represent 3 general types.
1. Host Bridge
2. Ports (root, upstream, downstream)
3. Devices (memory, other)
A CXL component can be conceptually thought of as a PCIe device with extra functionality when enumerated and enabled. For this reason, CXL does here, and will continue to add on to existing PCI code paths.
Host bridges will typically need to be handled specially and so they can implement this newly introduced interface or not. All other components should implement this interface. Implementing this interface allows the core PCI code to treat these devices as special where appropriate.
Message-Id: <[email protected]>
--- include/hw/pci/pci.h | 8 ++++++++ hw/pci/pci.c | 10 ++++++++++ 2 files changed, 18 insertions(+)
include/hw/pci/pci.h +8 -0
@@ -194,6 +194,8 @@ enum { QEMU_PCIE_LNKSTA_DLLLA = (1 << QEMU_PCIE_LNKSTA_DLLLA_BITNR),#define QEMU_PCIE_EXTCAP_INIT_BITNR 9 QEMU_PCIE_EXTCAP_INIT = (1 << QEMU_PCIE_EXTCAP_INIT_BITNR), +#define QEMU_PCIE_CXL_BITNR 10 + QEMU_PCIE_CAP_CXL = (1 << QEMU_PCIE_CXL_BITNR), };#define TYPE_PCI_DEVICE "pci-device"
@@ -201,6 +203,12 @@ typedef struct PCIDeviceClass PCIDeviceClass;DECLARE_OBJ_CHECKERS (PCIDevice, PCIDeviceClass,PCI_DEVICE ,TYPE_PCI_DEVICE ) +/* +* Implemented by devices that can be plugged on CXL buses. In the spec, this is +* actually a "CXL Component, but we name it device to match the PCI naming. + */ +#define INTERFACE_CXL_DEVICE "cxl-device" +/* Implemented by devices that can be plugged on PCI Express buses */ #define INTERFACE_PCIE_DEVICE "pci-express-device"
hw/pci/pci.c +10 -0
@@ -200,6 +200,11 @@ static const TypeInfo pci_bus_info = { .class_init = pci_bus_class_init, }; +static const TypeInfo cxl_interface_info = { + .name =INTERFACE_CXL_DEVICE , + .parent =TYPE_INTERFACE , +}; +static const TypeInfo pcie_interface_info = { .name =INTERFACE_PCIE_DEVICE , .parent =TYPE_INTERFACE ,
@@ -2182,6 +2187,10 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp) pci_dev->cap_present |=QEMU_PCI_CAP_EXPRESS ; } +if (object_class_dynamic_cast (klass,INTERFACE_CXL_DEVICE )) { + pci_dev->cap_present |=QEMU_PCIE_CAP_CXL ; + } + pci_dev =do_pci_register_device (pci_dev,object_get_typename (OBJECT (qdev)), pci_dev->devfn, errp);
@@ -2938,6 +2947,7 @@ static void pci_register_types(void)type_register_static (&pci_bus_info);type_register_static (&pcie_bus_info);type_register_static (&conventional_pci_interface_info); +type_register_static (&cxl_interface_info);type_register_static (&pcie_interface_info);type_register_static (&pci_device_type_info); }
Signature · 1 line
MST
[PULL v2 58/86] hw/virtio: move virtio-pci.h into shared include space
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
This allows other device classes that will be exposed via PCI to be able to do so in the appropriate hw/ directory. I resisted the temptation to re-order headers to be more aesthetically pleasing.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
---
{hw => include/hw}/virtio/virtio-pci.h | 0
hw/virtio/vhost-scsi-pci.c | 2 +-
hw/virtio/vhost-user-blk-pci.c | 2 +-
hw/virtio/vhost-user-fs-pci.c | 2 +-
hw/virtio/vhost-user-i2c-pci.c | 2 +-
hw/virtio/vhost-user-input-pci.c | 2 +-
hw/virtio/vhost-user-rng-pci.c | 2 +-
hw/virtio/vhost-user-scsi-pci.c | 2 +-
hw/virtio/vhost-user-vsock-pci.c | 2 +-
hw/virtio/vhost-vsock-pci.c | 2 +-
hw/virtio/virtio-9p-pci.c | 2 +-
hw/virtio/virtio-balloon-pci.c | 2 +-
hw/virtio/virtio-blk-pci.c | 2 +-
hw/virtio/virtio-input-host-pci.c | 2 +-
hw/virtio/virtio-input-pci.c | 2 +-
hw/virtio/virtio-iommu-pci.c | 2 +-
hw/virtio/virtio-net-pci.c | 2 +-
hw/virtio/virtio-pci.c | 2 +-
hw/virtio/virtio-rng-pci.c | 2 +-
hw/virtio/virtio-scsi-pci.c | 2 +-
hw/virtio/virtio-serial-pci.c | 2 +-
21 files changed, 20 insertions(+), 20 deletions(-)
rename {hw => include/hw}/virtio/virtio-pci.h (100%)include/hw/virtio/virtio-pci.h renamed from hw/virtio/virtio-pci.h +0 -0
hw/virtio/vhost-scsi-pci.c +1 -1
@@ -21,7 +21,7 @@#include "hw/virtio/vhost-scsi.h" #include "qapi/error.h" #include "qemu/module.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" typedef struct VHostSCSIPCI VHostSCSIPCI ;
hw/virtio/vhost-user-blk-pci.c +1 -1
@@ -26,7 +26,7 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/module.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" typedef struct VHostUserBlkPCI VHostUserBlkPCI ;
hw/virtio/vhost-user-fs-pci.c +1 -1
@@ -14,7 +14,7 @@#include "qemu/osdep.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-user-fs.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" struct VHostUserFSPCI {
hw/virtio/vhost-user-i2c-pci.c +1 -1
@@ -9,7 +9,7 @@#include "qemu/osdep.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-user-i2c.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" struct VHostUserI2CPCI {VirtIOPCIProxy parent_obj;
hw/virtio/vhost-user-input-pci.c +1 -1
@@ -9,7 +9,7 @@#include "hw/virtio/virtio-input.h" #include "qapi/error.h" #include "qemu/error-report.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" typedef struct VHostUserInputPCI VHostUserInputPCI ;
hw/virtio/vhost-user-rng-pci.c +1 -1
@@ -9,7 +9,7 @@#include "qemu/osdep.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-user-rng.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" struct VHostUserRNGPCI {VirtIOPCIProxy parent_obj;
hw/virtio/vhost-user-scsi-pci.c +1 -1
@@ -30,7 +30,7 @@#include "hw/pci/msix.h" #include "hw/loader.h" #include "sysemu/kvm.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" typedef struct VHostUserSCSIPCI VHostUserSCSIPCI ;
hw/virtio/vhost-user-vsock-pci.c +1 -1
@@ -10,7 +10,7 @@#include "qemu/osdep.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-user-vsock.h" #include "qom/object.h"
hw/virtio/vhost-vsock-pci.c +1 -1
@@ -13,7 +13,7 @@#include "qemu/osdep.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-vsock.h" #include "qemu/module.h"
hw/virtio/virtio-9p-pci.c +1 -1
@@ -15,7 +15,7 @@#include "qemu/osdep.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/9pfs/virtio-9p.h" #include "hw/qdev-properties.h" #include "qemu/module.h"
hw/virtio/virtio-balloon-pci.c +1 -1
@@ -14,7 +14,7 @@#include "qemu/osdep.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/qdev-properties.h" #include "hw/virtio/virtio-balloon.h" #include "qapi/error.h"
hw/virtio/virtio-blk-pci.c +1 -1
@@ -19,7 +19,7 @@#include "hw/qdev-properties.h" #include "hw/virtio/virtio-blk.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qapi/error.h" #include "qemu/module.h" #include "qom/object.h"
hw/virtio/virtio-input-host-pci.c +1 -1
@@ -8,7 +8,7 @@#include "qemu/osdep.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-input.h" #include "qemu/module.h" #include "qom/object.h"
hw/virtio/virtio-input-pci.c +1 -1
@@ -8,7 +8,7 @@#include "qemu/osdep.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/qdev-properties.h" #include "hw/virtio/virtio-input.h" #include "qemu/module.h"
hw/virtio/virtio-iommu-pci.c +1 -1
@@ -11,7 +11,7 @@#include "qemu/osdep.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-iommu.h" #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h"
hw/virtio/virtio-net-pci.c +1 -1
@@ -19,7 +19,7 @@#include "hw/qdev-properties.h" #include "hw/virtio/virtio-net.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qapi/error.h" #include "qemu/module.h" #include "qom/object.h"
hw/virtio/virtio-pci.c +1 -1
@@ -33,7 +33,7 @@#include "hw/pci/msix.h" #include "hw/loader.h" #include "sysemu/kvm.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qemu/range.h" #include "hw/virtio/virtio-bus.h" #include "qapi/visitor.h"
hw/virtio/virtio-rng-pci.c +1 -1
@@ -11,7 +11,7 @@#include "qemu/osdep.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-rng.h" #include "qapi/error.h" #include "qemu/module.h"
hw/virtio/virtio-scsi-pci.c +1 -1
@@ -18,7 +18,7 @@#include "hw/qdev-properties.h" #include "hw/virtio/virtio-scsi.h" #include "qemu/module.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" typedef struct VirtIOSCSIPCI VirtIOSCSIPCI ;
hw/virtio/virtio-serial-pci.c +1 -1
@@ -20,7 +20,7 @@#include "hw/qdev-properties.h" #include "hw/virtio/virtio-serial.h" #include "qemu/module.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" typedef struct VirtIOSerialPCI VirtIOSerialPCI ;
Signature · 1 line
MST
[PULL v2 70/86] virtio: drop name parameter for virtio_init()
In reply to Michael S. TsirkinFrom: Jonah Palmer <[email protected]>
This patch drops the name parameter for the virtio_init function.
The pair between the numeric device ID and the string device ID (name) of a virtio device already exists, but not in a way that lets us map between them.
This patch lets us do this and removes the need for the name parameter in the virtio_init function.
Message-Id: <[email protected]>
--- include/hw/virtio/vhost-vsock-common.h | 2 +- include/hw/virtio/virtio-gpu.h | 3 +- include/hw/virtio/virtio.h | 4 +- hw/9pfs/virtio-9p-device.c | 2 +- hw/block/vhost-user-blk.c | 2 +- hw/block/virtio-blk.c | 2 +- hw/char/virtio-serial-bus.c | 3 +- hw/display/virtio-gpu-base.c | 2 +- hw/input/virtio-input.c | 3 +- hw/net/virtio-net.c | 2 +- hw/scsi/virtio-scsi.c | 3 +- hw/virtio/vhost-user-fs.c | 3 +- hw/virtio/vhost-user-i2c.c | 7 +--- hw/virtio/vhost-user-rng.c | 2 +- hw/virtio/vhost-user-vsock.c | 2 +- hw/virtio/vhost-vsock-common.c | 5 +-- hw/virtio/vhost-vsock.c | 2 +- hw/virtio/virtio-balloon.c | 3 +- hw/virtio/virtio-crypto.c | 2 +- hw/virtio/virtio-iommu.c | 3 +- hw/virtio/virtio-mem.c | 3 +- hw/virtio/virtio-pmem.c | 3 +- hw/virtio/virtio-rng.c | 2 +- hw/virtio/virtio.c | 55 ++++++++++++++++++++++++-- 24 files changed, 77 insertions(+), 43 deletions(-)
include/hw/virtio/vhost-vsock-common.h +1 -1
@@ -44,7 +44,7 @@ int vhost_vsock_common_start(VirtIODevice *vdev);void vhost_vsock_common_stop (VirtIODevice *vdev);int vhost_vsock_common_pre_save (void *opaque);int vhost_vsock_common_post_load (void *opaque,int version_id); -void vhost_vsock_common_realize (VirtIODevice *vdev,const char *name); +void vhost_vsock_common_realize (VirtIODevice *vdev);void vhost_vsock_common_unrealize (VirtIODevice *vdev);uint64_t vhost_vsock_common_get_features (VirtIODevice *vdev,uint64_t features,Error **errp);
include/hw/virtio/virtio-gpu.h +1 -2
@@ -22,6 +22,7 @@#include "sysemu/vhost-user-backend.h" #include "standard-headers/linux/virtio_gpu.h" +#include "standard-headers/linux/virtio_ids.h" #include "qom/object.h" #define TYPE_VIRTIO_GPU_BASE "virtio-gpu-base"
@@ -37,8 +38,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(VirtIOGPUGL, VIRTIO_GPU_GL)#define TYPE_VHOST_USER_GPU "vhost-user-gpu" OBJECT_DECLARE_SIMPLE_TYPE(VhostUserGPU, VHOST_USER_GPU) -#define VIRTIO_ID_GPU 16 -struct virtio_gpu_simple_resource {uint32_t resource_id;uint32_t width;
include/hw/virtio/virtio.h +2 -2
@@ -165,8 +165,8 @@ struct VirtioDeviceClass {void virtio_instance_init_common (Object *proxy_obj,void *data,size_t vdev_size,const char *vdev_name); -void virtio_init (VirtIODevice *vdev,const char *name, -uint16_t device_id,size_t config_size); +void virtio_init (VirtIODevice *vdev,uint16_t device_id,size_t config_size); +void virtio_cleanup (VirtIODevice *vdev); void virtio_error(VirtIODevice *vdev, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
hw/9pfs/virtio-9p-device.c +1 -1
@@ -216,7 +216,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp) } v->config_size =sizeof (struct virtio_9p_config ) +strlen (s->fsconf.tag); -virtio_init (vdev,"virtio-9p" ,VIRTIO_ID_9P , v->config_size); +virtio_init (vdev,VIRTIO_ID_9P , v->config_size); v->vq =virtio_add_queue (vdev,MAX_REQ , handle_9p_output); }
hw/block/vhost-user-blk.c +1 -1
@@ -491,7 +491,7 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , +virtio_init (vdev,VIRTIO_ID_BLOCK ,sizeof (struct virtio_blk_config )); s->virtqs = g_new(VirtQueue *, s->num_queues);
hw/block/virtio-blk.c +1 -1
@@ -1206,7 +1206,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)virtio_blk_set_config_size (s, s->host_features); -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , s->config_size); +virtio_init (vdev,VIRTIO_ID_BLOCK , s->config_size); s->blk = conf->conf.blk; s->rq =NULL ;
hw/char/virtio-serial-bus.c +1 -2
@@ -1044,8 +1044,7 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp) VIRTIO_CONSOLE_F_EMERG_WRITE)) { config_size = offsetof(struct virtio_console_config , emerg_wr); } -virtio_init (vdev,"virtio-serial" ,VIRTIO_ID_CONSOLE , - config_size); +virtio_init (vdev,VIRTIO_ID_CONSOLE , config_size);/* Spawn a new virtio-serial bus on which the ports will ride as devices */ qbus_init(&vser->bus, sizeof(vser->bus), TYPE_VIRTIO_SERIAL_BUS,
hw/display/virtio-gpu-base.c +1 -1
@@ -173,7 +173,7 @@ virtio_gpu_base_device_realize(DeviceState *qdev, } g->virtio_config.num_scanouts =cpu_to_le32 (g->conf.max_outputs); -virtio_init (VIRTIO_DEVICE (g),"virtio-gpu" ,VIRTIO_ID_GPU , +virtio_init (VIRTIO_DEVICE (g),VIRTIO_ID_GPU ,sizeof (struct virtio_gpu_config ));if (virtio_gpu_virgl_enabled (g->conf)) {
hw/input/virtio-input.c +1 -2
@@ -257,8 +257,7 @@ static void virtio_input_device_realize(DeviceState *dev, Error **errp) vinput->cfg_size +=8 ;assert (vinput->cfg_size <=sizeof (virtio_input_config)); -virtio_init (vdev,"virtio-input" ,VIRTIO_ID_INPUT , - vinput->cfg_size); +virtio_init (vdev,VIRTIO_ID_INPUT , vinput->cfg_size); vinput->evt =virtio_add_queue (vdev,64 , virtio_input_handle_evt); vinput->sts =virtio_add_queue (vdev,64 , virtio_input_handle_sts); }
hw/net/virtio-net.c +1 -1
@@ -3393,7 +3393,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) }virtio_net_set_config_size (n, n->host_features); -virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); +virtio_init (vdev,VIRTIO_ID_NET , n->config_size);/* * We set a lower limit on RX queue size to what it always was.
hw/scsi/virtio-scsi.c +1 -2
@@ -1013,8 +1013,7 @@ void virtio_scsi_common_realize(DeviceState *dev,VirtIOSCSICommon *s =VIRTIO_SCSI_COMMON (dev);int i; -virtio_init (vdev,"virtio-scsi" ,VIRTIO_ID_SCSI , -sizeof (VirtIOSCSIConfig)); +virtio_init (vdev,VIRTIO_ID_SCSI ,sizeof (VirtIOSCSIConfig));if (s->conf.num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { s->conf.num_queues =1 ;
hw/virtio/vhost-user-fs.c +1 -2
@@ -219,8 +219,7 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"vhost-user-fs" ,VIRTIO_ID_FS , -sizeof (struct virtio_fs_config )); +virtio_init (vdev,VIRTIO_ID_FS ,sizeof (struct virtio_fs_config ));/* Hiprio queue */ fs->hiprio_vq =virtio_add_queue (vdev, fs->conf.queue_size, vuf_handle_output);
hw/virtio/vhost-user-i2c.c +1 -6
@@ -14,11 +14,6 @@#include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -/* Remove this once the header is updated in Linux kernel */ -#ifndef VIRTIO_ID_I2C_ADAPTER -#define VIRTIO_ID_I2C_ADAPTER 34 -#endif -static const int feature_bits[] = {VIRTIO_I2C_F_ZERO_LENGTH_REQUEST ,VHOST_INVALID_FEATURE_BIT
@@ -227,7 +222,7 @@ static void vu_i2c_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"vhost-user-i2c" ,VIRTIO_ID_I2C_ADAPTER ,0 ); +virtio_init (vdev,VIRTIO_ID_I2C_ADAPTER ,0 ); i2c->vhost_dev.nvqs =1 ; i2c->vq =virtio_add_queue (vdev,4 , vu_i2c_handle_output);
hw/virtio/vhost-user-rng.c +1 -1
@@ -203,7 +203,7 @@ static void vu_rng_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"vhost-user-rng" ,VIRTIO_ID_RNG ,0 ); +virtio_init (vdev,VIRTIO_ID_RNG ,0 ); rng->req_vq =virtio_add_queue (vdev,4 , vu_rng_handle_output);if (!rng->req_vq) {
hw/virtio/vhost-user-vsock.c +1 -1
@@ -107,7 +107,7 @@ static void vuv_device_realize(DeviceState *dev, Error **errp)return ; } -vhost_vsock_common_realize (vdev,"vhost-user-vsock" ); +vhost_vsock_common_realize (vdev);vhost_dev_set_config_notifier (&vvc->vhost_dev, &vsock_ops);
hw/virtio/vhost-vsock-common.c +2 -3
@@ -224,12 +224,11 @@ int vhost_vsock_common_post_load(void *opaque, int version_id)return 0 ; } -void vhost_vsock_common_realize (VirtIODevice *vdev,const char *name) +void vhost_vsock_common_realize (VirtIODevice *vdev) {VHostVSockCommon *vvc =VHOST_VSOCK_COMMON (vdev); -virtio_init (vdev, name,VIRTIO_ID_VSOCK , -sizeof (struct virtio_vsock_config )); +virtio_init (vdev,VIRTIO_ID_VSOCK ,sizeof (struct virtio_vsock_config ));/* Receive and transmit queues belong to vhost */ vvc->recv_vq = virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE,
hw/virtio/vhost-vsock.c +1 -1
@@ -169,7 +169,7 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp) } } -vhost_vsock_common_realize (vdev,"vhost-vsock" ); +vhost_vsock_common_realize (vdev); ret =vhost_dev_init (&vvc->vhost_dev, (void *)(uintptr_t )vhostfd,VHOST_BACKEND_TYPE_KERNEL ,0 , errp);
hw/virtio/virtio-balloon.c +1 -2
@@ -882,8 +882,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)VirtIOBalloon *s =VIRTIO_BALLOON (dev);int ret; -virtio_init (vdev,"virtio-balloon" ,VIRTIO_ID_BALLOON , -virtio_balloon_config_size (s)); +virtio_init (vdev,VIRTIO_ID_BALLOON ,virtio_balloon_config_size (s)); ret =qemu_add_balloon_handler (virtio_balloon_to_target, virtio_balloon_stat, s);
hw/virtio/virtio-crypto.c +1 -1
@@ -810,7 +810,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"virtio-crypto" ,VIRTIO_ID_CRYPTO , vcrypto->config_size); +virtio_init (vdev,VIRTIO_ID_CRYPTO , vcrypto->config_size); vcrypto->curr_queues =1 ; vcrypto->vqs =g_new0 (VirtIOCryptoQueue, vcrypto->max_queues);for (i =0 ; i < vcrypto->max_queues; i++) {
hw/virtio/virtio-iommu.c +1 -2
@@ -1033,8 +1033,7 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIOIOMMU *s =VIRTIO_IOMMU (dev); -virtio_init (vdev,"virtio-iommu" ,VIRTIO_ID_IOMMU , -sizeof (struct virtio_iommu_config )); +virtio_init (vdev,VIRTIO_ID_IOMMU ,sizeof (struct virtio_iommu_config ));memset (s->iommu_pcibus_by_bus_num,0 ,sizeof (s->iommu_pcibus_by_bus_num));
hw/virtio/virtio-mem.c +1 -2
@@ -867,8 +867,7 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp) vmem->block_size; vmem->bitmap =bitmap_new (vmem->bitmap_size); -virtio_init (vdev,TYPE_VIRTIO_MEM ,VIRTIO_ID_MEM , -sizeof (struct virtio_mem_config )); +virtio_init (vdev,VIRTIO_ID_MEM ,sizeof (struct virtio_mem_config )); vmem->vq =virtio_add_queue (vdev,128 , virtio_mem_handle_request);host_memory_backend_set_mapped (vmem->memdev, true);
hw/virtio/virtio-pmem.c +1 -2
@@ -122,8 +122,7 @@ static void virtio_pmem_realize(DeviceState *dev, Error **errp) }host_memory_backend_set_mapped (pmem->memdev, true); -virtio_init (vdev,TYPE_VIRTIO_PMEM ,VIRTIO_ID_PMEM , -sizeof (struct virtio_pmem_config )); +virtio_init (vdev,VIRTIO_ID_PMEM ,sizeof (struct virtio_pmem_config )); pmem->rq_vq =virtio_add_queue (vdev,128 , virtio_pmem_flush); }
hw/virtio/virtio-rng.c +1 -1
@@ -215,7 +215,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"virtio-rng" ,VIRTIO_ID_RNG ,0 ); +virtio_init (vdev,VIRTIO_ID_RNG ,0 ); vrng->vq =virtio_add_queue (vdev,8 , handle_input); vrng->quota_remaining = vrng->conf.max_bytes;
hw/virtio/virtio.c +52 -3
73 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 71/86] virtio: add vhost support for virtio devices
In reply to Michael S. TsirkinFrom: Jonah Palmer <[email protected]>
This patch adds a get_vhost() callback function for VirtIODevices that returns the device's corresponding vhost_dev structure, if the vhost device is running. This patch also adds a vhost_started flag for VirtIODevices.
Previously, a VirtIODevice wouldn't be able to tell if its corresponding vhost device was active or not.
Message-Id: <[email protected]>
--- include/hw/virtio/virtio.h | 3 +++ hw/block/vhost-user-blk.c | 7 +++++++ hw/display/vhost-user-gpu.c | 7 +++++++ hw/input/vhost-user-input.c | 7 +++++++ hw/net/virtio-net.c | 9 +++++++++ hw/scsi/vhost-scsi.c | 8 ++++++++ hw/virtio/vhost-user-fs.c | 7 +++++++ hw/virtio/vhost-user-rng.c | 7 +++++++ hw/virtio/vhost-vsock-common.c | 7 +++++++ hw/virtio/vhost.c | 4 +++- hw/virtio/virtio-crypto.c | 10 ++++++++++ hw/virtio/virtio.c | 1 + 12 files changed, 76 insertions(+), 1 deletion(-)
include/hw/virtio/virtio.h +3 -0
@@ -22,6 +22,7 @@#include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" #include "qom/object.h" +#include "hw/virtio/vhost.h" /* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30
@@ -102,6 +103,7 @@ struct VirtIODevicebool started;bool start_on_kick;/* when virtio 1.0 feature has not been negotiated */ bool disable_legacy_check; +bool vhost_started;VMChangeStateEntry *vmstate;char *bus_name;uint8_t device_endian;
@@ -160,6 +162,7 @@ struct VirtioDeviceClass {int (*post_load)(VirtIODevice *vdev);const VMStateDescription *vmsd;bool (*primary_unplug_pending)(void *opaque); +struct vhost_dev *(*get_vhost)(VirtIODevice *vdev); }; void virtio_instance_init_common(Object *proxy_obj, void *data,
hw/block/vhost-user-blk.c +7 -0
@@ -569,6 +569,12 @@ static void vhost_user_blk_instance_init(Object *obj) "/disk@0,0", DEVICE(obj)); } +static struct vhost_dev *vhost_user_blk_get_vhost (VirtIODevice *vdev) +{ +VHostUserBlk *s =VHOST_USER_BLK (vdev); +return &s->dev; +} +static const VMStateDescription vmstate_vhost_user_blk = { .name ="vhost-user-blk" , .minimum_version_id =1 ,
@@ -603,6 +609,7 @@ static void vhost_user_blk_class_init(ObjectClass *klass, void *data) vdc->get_features = vhost_user_blk_get_features; vdc->set_status = vhost_user_blk_set_status; vdc->reset = vhost_user_blk_reset; + vdc->get_vhost = vhost_user_blk_get_vhost; }static const TypeInfo vhost_user_blk_info = {
hw/display/vhost-user-gpu.c +7 -0
@@ -565,6 +565,12 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp) g->vhost_gpu_fd =-1 ; } +static struct vhost_dev *vhost_user_gpu_get_vhost (VirtIODevice *vdev) +{ +VhostUserGPU *g =VHOST_USER_GPU (vdev); +return &g->vhost->dev; +} +static Property vhost_user_gpu_properties[] = {VIRTIO_GPU_BASE_PROPERTIES (VhostUserGPU, parent_obj.conf),DEFINE_PROP_END_OF_LIST (),
@@ -586,6 +592,7 @@ vhost_user_gpu_class_init(ObjectClass *klass, void *data) vdc->guest_notifier_pending = vhost_user_gpu_guest_notifier_pending; vdc->get_config = vhost_user_gpu_get_config; vdc->set_config = vhost_user_gpu_set_config; + vdc->get_vhost = vhost_user_gpu_get_vhost;device_class_set_props (dc, vhost_user_gpu_properties); }
hw/input/vhost-user-input.c +7 -0
@@ -78,6 +78,12 @@ static void vhost_input_set_config(VirtIODevice *vdev,virtio_notify_config (vdev); } +static struct vhost_dev *vhost_input_get_vhost (VirtIODevice *vdev) +{ +VHostUserInput *vhi =VHOST_USER_INPUT (vdev); +return &vhi->vhost->dev; +} +static const VMStateDescription vmstate_vhost_input = { .name ="vhost-user-input" , .unmigratable =1 ,
@@ -92,6 +98,7 @@ static void vhost_input_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_vhost_input; vdc->get_config = vhost_input_get_config; vdc->set_config = vhost_input_set_config; + vdc->get_vhost = vhost_input_get_vhost; vic->realize = vhost_input_realize; vic->change_active = vhost_input_change_active; }
hw/net/virtio-net.c +9 -0
@@ -3620,6 +3620,14 @@ static bool dev_unplug_pending(void *opaque)return vdc->primary_unplug_pending (dev); } +static struct vhost_dev *virtio_net_get_vhost (VirtIODevice *vdev) +{ +VirtIONet *n =VIRTIO_NET (vdev); +NetClientState *nc =qemu_get_queue (n->nic); +struct vhost_net *net =get_vhost_net (nc->peer); +return &net->dev; +} +static const VMStateDescription vmstate_virtio_net = { .name ="virtio-net" , .minimum_version_id =VIRTIO_NET_VM_VERSION ,
@@ -3722,6 +3730,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data) vdc->post_load = virtio_net_post_load_virtio; vdc->vmsd = &vmstate_virtio_net_device; vdc->primary_unplug_pending = primary_unplug_pending; + vdc->get_vhost = virtio_net_get_vhost; }static const TypeInfo virtio_net_info = {
hw/scsi/vhost-scsi.c +8 -0
@@ -273,6 +273,13 @@ static void vhost_scsi_unrealize(DeviceState *dev)virtio_scsi_common_unrealize (dev); } +static struct vhost_dev *vhost_scsi_get_vhost (VirtIODevice *vdev) +{ +VHostSCSI *s =VHOST_SCSI (vdev); +VHostSCSICommon *vsc =VHOST_SCSI_COMMON (s); +return &vsc->dev; +} +static Property vhost_scsi_properties[] = {DEFINE_PROP_STRING ("vhostfd" , VirtIOSCSICommon, conf.vhostfd),DEFINE_PROP_STRING ("wwpn" , VirtIOSCSICommon, conf.wwpn),
@@ -307,6 +314,7 @@ static void vhost_scsi_class_init(ObjectClass *klass, void *data) vdc->get_features = vhost_scsi_common_get_features; vdc->set_config = vhost_scsi_common_set_config; vdc->set_status = vhost_scsi_set_status; + vdc->get_vhost = vhost_scsi_get_vhost; fwc->get_dev_path = vhost_scsi_common_get_fw_dev_path; }
hw/virtio/vhost-user-fs.c +7 -0
@@ -276,6 +276,12 @@ static void vuf_device_unrealize(DeviceState *dev) fs->vhost_dev.vqs =NULL ; } +static struct vhost_dev *vuf_get_vhost (VirtIODevice *vdev) +{ +VHostUserFS *fs =VHOST_USER_FS (vdev); +return &fs->vhost_dev; +} +static const VMStateDescription vuf_vmstate = { .name ="vhost-user-fs" , .unmigratable =1 ,
@@ -313,6 +319,7 @@ static void vuf_class_init(ObjectClass *klass, void *data) vdc->set_status = vuf_set_status; vdc->guest_notifier_mask = vuf_guest_notifier_mask; vdc->guest_notifier_pending = vuf_guest_notifier_pending; + vdc->get_vhost = vuf_get_vhost; }static const TypeInfo vuf_info = {
hw/virtio/vhost-user-rng.c +7 -0
@@ -247,6 +247,12 @@ static void vu_rng_device_unrealize(DeviceState *dev)vhost_user_cleanup (&rng->vhost_user); } +static struct vhost_dev *vu_rng_get_vhost (VirtIODevice *vdev) +{ +VHostUserRNG *rng =VHOST_USER_RNG (vdev); +return &rng->vhost_dev; +} +static const VMStateDescription vu_rng_vmstate = { .name ="vhost-user-rng" , .unmigratable =1 ,
@@ -272,6 +278,7 @@ static void vu_rng_class_init(ObjectClass *klass, void *data) vdc->set_status = vu_rng_set_status; vdc->guest_notifier_mask = vu_rng_guest_notifier_mask; vdc->guest_notifier_pending = vu_rng_guest_notifier_pending; + vdc->get_vhost = vu_rng_get_vhost; }static const TypeInfo vu_rng_info = {
hw/virtio/vhost-vsock-common.c +7 -0
@@ -258,6 +258,12 @@ void vhost_vsock_common_unrealize(VirtIODevice *vdev)virtio_cleanup (vdev); } +static struct vhost_dev *vhost_vsock_common_get_vhost (VirtIODevice *vdev) +{ +VHostVSockCommon *vvc =VHOST_VSOCK_COMMON (vdev); +return &vvc->vhost_dev; +} +static Property vhost_vsock_common_properties[] = {DEFINE_PROP_ON_OFF_AUTO ("seqpacket" , VHostVSockCommon, seqpacket,ON_OFF_AUTO_AUTO ),
@@ -273,6 +279,7 @@ static void vhost_vsock_common_class_init(ObjectClass *klass, void *data)set_bit (DEVICE_CATEGORY_MISC , dc->categories); vdc->guest_notifier_mask = vhost_vsock_common_guest_notifier_mask; vdc->guest_notifier_pending = vhost_vsock_common_guest_notifier_pending; + vdc->get_vhost = vhost_vsock_common_get_vhost; }static const TypeInfo vhost_vsock_common_info = {
hw/virtio/vhost.c +3 -1
@@ -1738,6 +1738,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)/* should only be called after backend is connected */ assert (hdev->vhost_ops); + vdev->vhost_started = true; hdev->started = true; hdev->vdev = vdev;
@@ -1810,7 +1811,7 @@ fail_vq: fail_mem: fail_features: - + vdev->vhost_started = false; hdev->started = false;return r; }
@@ -1841,6 +1842,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) }vhost_log_put (hdev, true); hdev->started = false; + vdev->vhost_started = false; hdev->vdev =NULL ; }
hw/virtio/virtio-crypto.c +10 -0
@@ -961,6 +961,15 @@ static bool virtio_crypto_guest_notifier_pending(VirtIODevice *vdev, int idx)return cryptodev_vhost_virtqueue_pending (vdev, queue, idx); } +static struct vhost_dev *virtio_crypto_get_vhost (VirtIODevice *vdev) +{ +VirtIOCrypto *vcrypto =VIRTIO_CRYPTO (vdev); +CryptoDevBackend *b = vcrypto->cryptodev; +CryptoDevBackendClient *cc = b->conf.peers.ccs[0 ]; +CryptoDevBackendVhost *vhost_crypto =cryptodev_get_vhost (cc, b,0 ); +return &vhost_crypto->dev; +} +static void virtio_crypto_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -977,6 +986,7 @@ static void virtio_crypto_class_init(ObjectClass *klass, void *data) vdc->set_status = virtio_crypto_set_status; vdc->guest_notifier_mask = virtio_crypto_guest_notifier_mask; vdc->guest_notifier_pending = virtio_crypto_guest_notifier_pending; + vdc->get_vhost = virtio_crypto_get_vhost; }static void virtio_crypto_instance_init (Object *obj)
hw/virtio/virtio.c +1 -0
@@ -3271,6 +3271,7 @@ void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size) vdev->start_on_kick = false; vdev->started = false; + vdev->vhost_started = false; vdev->device_id = device_id; vdev->status =0 ;qatomic_set (&vdev->isr,0 );
Signature · 1 line
MST
[PULL v2 10/86] hw/cxl/device: Add cheap EVENTS implementation (8.2.9.1)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
Using the previously implemented stubbed helpers, it is now possible to easily add the missing, required commands to the implementation.
Message-Id: <[email protected]>
--- hw/cxl/cxl-mailbox-utils.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
hw/cxl/cxl-mailbox-utils.c +26 -1
@@ -38,6 +38,14 @@* a register interface that already deals with it. */ +enum { + EVENTS = 0x01, + #define GET_RECORDS 0x0 +#define CLEAR_RECORDS 0x1 +#define GET_INTERRUPT_POLICY 0x2 +#define SET_INTERRUPT_POLICY 0x3 +}; +/* 8.2.8.4.5.1 Command Return Codes */ typedef enum { CXL_MBOX_SUCCESS = 0x0,
@@ -93,9 +101,26 @@ struct cxl_cmd {return CXL_MBOX_SUCCESS ; \ } +DEFINE_MAILBOX_HANDLER_ZEROED (events_get_records,0x20 ); +DEFINE_MAILBOX_HANDLER_NOP (events_clear_records); +DEFINE_MAILBOX_HANDLER_ZEROED (events_get_interrupt_policy,4 ); +DEFINE_MAILBOX_HANDLER_NOP (events_set_interrupt_policy); +static QemuUUID cel_uuid; -static struct cxl_cmd cxl_cmd_set[256 ][256 ] = {}; +#define IMMEDIATE_CONFIG_CHANGE (1 << 1) +#define IMMEDIATE_LOG_CHANGE (1 << 4) + +static struct cxl_cmd cxl_cmd_set[256 ][256 ] = { + [EVENTS ][GET_RECORDS ] = {"EVENTS_GET_RECORDS" , + cmd_events_get_records,1 ,0 }, + [EVENTS ][CLEAR_RECORDS ] = {"EVENTS_CLEAR_RECORDS" , + cmd_events_clear_records, ~0 ,IMMEDIATE_LOG_CHANGE }, + [EVENTS ][GET_INTERRUPT_POLICY ] = {"EVENTS_GET_INTERRUPT_POLICY" , + cmd_events_get_interrupt_policy,0 ,0 }, + [EVENTS ][SET_INTERRUPT_POLICY ] = {"EVENTS_SET_INTERRUPT_POLICY" , + cmd_events_set_interrupt_policy,4 ,IMMEDIATE_CONFIG_CHANGE }, +};void cxl_process_mailbox (CXLDeviceState *cxl_dstate) {
Signature · 1 line
MST
[PULL v2 04/86] hw/cxl/component: Introduce CXL components (8.1.x, 8.2.5)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
A CXL 2.0 component is any entity in the CXL topology. All components have a analogous function in PCIe. Except for the CXL host bridge, all have a PCIe config space that is accessible via the common PCIe mechanisms. CXL components are enumerated via DVSEC fields in the extended PCIe header space. CXL components will minimally implement some subset of CXL.mem and CXL.cache registers defined in 8.2.5 of the CXL 2.0 specification. Two headers and a utility library are introduced to support the minimum functionality needed to enumerate components.
The cxl_pci header manages bits associated with PCI, specifically the DVSEC and related fields. The cxl_component.h variant has data structures and APIs that are useful for drivers implementing any of the CXL 2.0 components. The library takes care of making use of the DVSEC bits and the CXL.[mem|cache] registers. Per spec, the registers are little endian.
None of the mechanisms required to enumerate a CXL capable hostbridge are introduced at this point.
Note that the CXL.mem and CXL.cache registers used are always 4B wide. It's possible in the future that this constraint will not hold.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl.h | 16 ++ include/hw/cxl/cxl_component.h | 213 ++++++++++++++++++++++ include/hw/cxl/cxl_pci.h | 146 +++++++++++++++ hw/cxl/cxl-component-utils.c | 313 +++++++++++++++++++++++++++++++++ hw/Kconfig | 1 + hw/cxl/Kconfig | 3 + hw/cxl/meson.build | 4 + hw/meson.build | 1 + 8 files changed, 697 insertions(+) create mode 100644 include/hw/cxl/cxl.h create mode 100644 include/hw/cxl/cxl_component.h create mode 100644 include/hw/cxl/cxl_pci.h create mode 100644 hw/cxl/cxl-component-utils.c create mode 100644 hw/cxl/Kconfig create mode 100644 hw/cxl/meson.build
include/hw/cxl/cxl.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* QEMU CXL Support +* +* Copyright (c) 2020 Intel +* +* This work is licensed under the terms of the GNU GPL, version 2. See the +* COPYING file in the top-level directory. +*/ + +#ifndef CXL_H +#define CXL_H + +#include "cxl_pci.h" +#include "cxl_component.h" + +#endif
include/hw/cxl/cxl_component.h new file +213 -0
213 lines not on this page · raw message
include/hw/cxl/cxl_pci.h new file +146 -0
146 lines not on this page · raw message
hw/cxl/cxl-component-utils.c new file +313 -0
313 lines not on this page · raw message
hw/Kconfig +1 -0
@@ -6,6 +6,7 @@ source audio/Kconfig source block/Kconfig source char/Kconfig source core/Kconfig +source cxl/Kconfig source display/Kconfig source dma/Kconfig source gpio/Kconfig
hw/cxl/Kconfig new file +3 -0
@@ -0,0 +1,3 @@ +config CXL + bool + default y if PCI_EXPRESS
hw/cxl/meson.build new file +4 -0
@@ -0,0 +1,4 @@ +softmmu_ss.add(when: 'CONFIG_CXL', + if_true: files( + 'cxl-component-utils.c', + ))
hw/meson.build +1 -0
@@ -6,6 +6,7 @@ subdir('block') subdir('char') subdir('core') subdir('cpu') +subdir('cxl') subdir('display') subdir('dma') subdir('gpio')
Signature · 1 line
MST
[PULL v2 07/86] hw/cxl/device: Implement the CAP array (8.2.8.1-2)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
This implements all device MMIO up to the first capability. That includes the CXL Device Capabilities Array Register, as well as all of the CXL Device Capability Header Registers. The latter are filled in as they are implemented in the following patches.
Endianness and alignment are managed by softmmu memory core.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_device.h | 31 +++++++++- hw/cxl/cxl-device-utils.c | 109 ++++++++++++++++++++++++++++++++++++ hw/cxl/meson.build | 1 + 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 hw/cxl/cxl-device-utils.c
include/hw/cxl/cxl_device.h +30 -1
@@ -58,6 +58,8 @@#define CXL_DEVICE_CAP_HDR1_OFFSET 0x10/* Figure 138 */ #define CXL_DEVICE_CAP_REG_SIZE 0x10/* 8.2.8.2 */ #define CXL_DEVICE_CAPS_MAX 4/* 8.2.8.2.1 + 8.2.8.5 */ +#define CXL_CAPS_SIZE \ + (CXL_DEVICE_CAP_REG_SIZE * (CXL_DEVICE_CAPS_MAX + 1))/* +1 for header */ #define CXL_DEVICE_STATUS_REGISTERS_OFFSET 0x80/* Read comment above */ #define CXL_DEVICE_STATUS_REGISTERS_LENGTH 0x8/* 8.2.8.3.1 */
@@ -70,12 +72,22 @@#define CXL_MAILBOX_REGISTERS_LENGTH \ (CXL_MAILBOX_REGISTERS_SIZE + CXL_MAILBOX_MAX_PAYLOAD_SIZE) +#define CXL_MMIO_SIZE \ + (CXL_DEVICE_CAP_REG_SIZE + CXL_DEVICE_STATUS_REGISTERS_LENGTH + \ + CXL_MAILBOX_REGISTERS_LENGTH) + typedef struct cxl_device_state { MemoryRegion device_registers; /* mmio for device capabilities array - 8.2.8.2 */ MemoryRegion device; - MemoryRegion caps; + struct { + MemoryRegion caps; + union { + uint32_t caps_reg_state32[CXL_CAPS_SIZE / 4]; + uint64_t caps_reg_state64[CXL_CAPS_SIZE / 8]; + }; + }; /* mmio for the mailbox registers 8.2.8.4 */ MemoryRegion mailbox;
@@ -128,6 +140,23 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(DEVICE_STATUS, CXL_DEVICE_CAP_HDR1_OFFSET)CXL_DEVICE_CAPABILITY_HEADER_REGISTER (MAILBOX ,CXL_DEVICE_CAP_HDR1_OFFSET + \ CXL_DEVICE_CAP_REG_SIZE) +#define cxl_device_cap_init (dstate, reg, cap_id) \ + do { \ + uint32_t *cap_hdrs = dstate->caps_reg_state32; \ + int which = R_CXL_DEV_##reg##_CAP_HDR0; \ + cap_hdrs[which] = \ + FIELD_DP32(cap_hdrs[which], CXL_DEV_##reg##_CAP_HDR0, \ + CAP_ID, cap_id); \ + cap_hdrs[which] = FIELD_DP32( \ + cap_hdrs[which], CXL_DEV_##reg##_CAP_HDR0, CAP_VERSION, 1); \ + cap_hdrs[which + 1] = \ + FIELD_DP32(cap_hdrs[which + 1], CXL_DEV_##reg##_CAP_HDR1, \ + CAP_OFFSET, CXL_##reg##_REGISTERS_OFFSET); \ + cap_hdrs[which + 2] = \ + FIELD_DP32(cap_hdrs[which + 2], CXL_DEV_##reg##_CAP_HDR2, \ + CAP_LENGTH, CXL_##reg##_REGISTERS_LENGTH); \ + } while (0) +/* CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register */ REG32(CXL_DEV_MAILBOX_CAP, 0)FIELD (CXL_DEV_MAILBOX_CAP ,PAYLOAD_SIZE ,0 ,5 )
hw/cxl/cxl-device-utils.c new file +109 -0
109 lines not on this page · raw message
hw/cxl/meson.build +1 -0
@@ -1,4 +1,5 @@ softmmu_ss.add(when: 'CONFIG_CXL', if_true: files( 'cxl-component-utils.c', + 'cxl-device-utils.c', ))
Signature · 1 line
MST
[PULL v2 15/86] cxl: Machine level control on whether CXL support is enabled
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
There are going to be some potential overheads to CXL enablement, for example the host bridge region reserved in memory maps. Add a machine level control so that CXL is disabled by default.
Message-Id: <[email protected]>
--- include/hw/boards.h | 2 ++ include/hw/cxl/cxl.h | 4 ++++ hw/core/machine.c | 28 ++++++++++++++++++++++++++++ hw/i386/pc.c | 1 + 4 files changed, 35 insertions(+)
include/hw/boards.h +2 -0
@@ -269,6 +269,7 @@ struct MachineClass {bool ignore_boot_device_suffixes;bool smbus_no_migration_support;bool nvdimm_supported; +bool cxl_supported;bool numa_mem_supported;bool auto_enable_numa;SMPCompatProps smp_props;
@@ -359,6 +360,7 @@ struct MachineState {CPUArchIdList *possible_cpus;CpuTopology smp;struct NVDIMMState *nvdimms_state; +struct CXLState *cxl_devices_state;struct NumaState *numa_state; };
include/hw/cxl/cxl.h +4 -0
@@ -17,4 +17,8 @@#define CXL_COMPONENT_REG_BAR_IDX 0#define CXL_DEVICE_REG_BAR_IDX 2 +typedef struct CXLState { +bool is_enabled; +}CXLState ; +#endif
hw/core/machine.c +28 -0
@@ -33,6 +33,7 @@#include "sysemu/qtest.h" #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" +#include "hw/cxl/cxl.h" #include "migration/global_state.h" #include "migration/vmstate.h" #include "exec/confidential-guest-support.h"
@@ -625,6 +626,20 @@ static void machine_set_nvdimm_persistence(Object *obj, const char *value, nvdimms_state->persistence_string =g_strdup (value); } +static bool machine_get_cxl (Object *obj,Error **errp) +{ +MachineState *ms =MACHINE (obj); + +return ms->cxl_devices_state->is_enabled; +} + +static void machine_set_cxl (Object *obj,bool value,Error **errp) +{ +MachineState *ms =MACHINE (obj); + + ms->cxl_devices_state->is_enabled = value; +} +void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type) {QAPI_LIST_PREPEND (mc->allowed_dynamic_sysbus_devices,g_strdup (type));
@@ -911,6 +926,8 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->default_ram_size =128 * MiB; mc->rom_file_has_mr = true; +/* Few machines support CXL, so default to off */ + mc->cxl_supported = false;/* numa node memory size aligned on 8MB by default. * On Linux, each node's border has to be 8MB aligned */
@@ -1071,6 +1088,16 @@ static void machine_initfn(Object *obj) "Valid values are cpu, mem-ctrl"); } +if (mc->cxl_supported) { +Object *obj =OBJECT (ms); + + ms->cxl_devices_state =g_new0 (CXLState,1 ); +object_property_add_bool (obj,"cxl" , machine_get_cxl, machine_set_cxl); +object_property_set_description (obj,"cxl" , +"Set on/off to enable/disable " +"CXL instantiation" ); + } +if (mc->cpu_index_to_instance_props && mc->get_default_cpu_node_id) { ms->numa_state =g_new0 (NumaState,1 ); object_property_add_bool(obj, "hmat",
@@ -1108,6 +1135,7 @@ static void machine_finalize(Object *obj)g_free (ms->device_memory);g_free (ms->nvdimms_state);g_free (ms->numa_state); +g_free (ms->cxl_devices_state); }bool machine_usb (MachineState *machine)
hw/i386/pc.c +1 -0
@@ -1761,6 +1761,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) mc->default_cpu_type =TARGET_DEFAULT_CPU_TYPE ; mc->nvdimm_supported = true; mc->smp_props.dies_supported = true; + mc->cxl_supported = true; mc->default_ram_id ="pc.ram" ; object_class_property_add(oc, PC_MACHINE_MAX_RAM_BELOW_4G, "size",
Signature · 1 line
MST
[PULL v2 14/86] hw/pci/cxl: Create a CXL bus type
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
The easiest way to differentiate a CXL bus, and a PCIE bus is using a flag. A CXL bus, in hardware, is backward compatible with PCIE, and therefore the code tries pretty hard to keep them in sync as much as possible.
The other way to implement this would be to try to cast the bus to the correct type. This is less code and useful for debugging via simply looking at the flags.
Message-Id: <[email protected]>
--- include/hw/pci/pci_bus.h | 7 +++++++ hw/pci-bridge/pci_expander_bridge.c | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
include/hw/pci/pci_bus.h +7 -0
@@ -24,6 +24,8 @@ enum PCIBusFlags {PCI_BUS_IS_ROOT =0x0001 ,/* PCIe extended configuration space is accessible on this bus */ PCI_BUS_EXTENDED_CONFIG_SPACE =0x0002 , +/* This is a CXL Type BUS */ + PCI_BUS_CXL = 0x0004, }; struct PCIBus {
@@ -53,6 +55,11 @@ struct PCIBus {Notifier machine_done; }; +static inline bool pci_bus_is_cxl (PCIBus *bus) +{ +return !!(bus->flags &PCI_BUS_CXL ); +} +static inline bool pci_bus_is_root (PCIBus *bus) {return !!(bus->flags &PCI_BUS_IS_ROOT );
hw/pci-bridge/pci_expander_bridge.c +8 -1
@@ -24,7 +24,7 @@#include "hw/boards.h" #include "qom/object.h" -enum BusType {PCI ,PCIE }; +enum BusType {PCI ,PCIE ,CXL };#define TYPE_PXB_BUS "pxb-bus"typedef struct PXBBus PXBBus ;
@@ -35,6 +35,10 @@ DECLARE_INSTANCE_CHECKER(PXBBus, PXB_BUS,DECLARE_INSTANCE_CHECKER (PXBBus,PXB_PCIE_BUS , TYPE_PXB_PCIE_BUS) +#define TYPE_PXB_CXL_BUS "pxb-cxl-bus" +DECLARE_INSTANCE_CHECKER (PXBBus,PXB_CXL_BUS , + TYPE_PXB_CXL_BUS) +struct PXBBus {/*< private >*/ PCIBus parent_obj;
@@ -251,6 +255,9 @@ static void pxb_dev_realize_common(PCIDevice *dev, enum BusType type, ds =qdev_new (TYPE_PXB_HOST );if (type ==PCIE ) { bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_PCIE_BUS ); + }else if (type ==CXL ) { + bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_CXL_BUS ); + bus->flags |=PCI_BUS_CXL ; }else { bus =pci_root_bus_new (ds,"pxb-internal" ,NULL ,NULL ,0 ,TYPE_PXB_BUS ); bds =qdev_new ("pci-bridge" );
Signature · 1 line
MST
[PULL v2 05/86] MAINTAINERS: Add entry for Compute Express Link Emulation
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
The CXL emulation will be jointly maintained by Ben Widawsky and Jonathan Cameron. Broken out as a separate patch to improve visibility.
Message-Id: <[email protected]>
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -2545,6 +2545,13 @@ F: qapi/block*.json F: qapi/transaction.json T: git https://repo.or.cz/qemu/armbru.git block-next +Compute Express Link +M: Ben Widawsky <[email protected]> +M: Jonathan Cameron <[email protected]> +S: Supported +F: hw/cxl/ +F: include/hw/cxl/ + Dirty Bitmaps M: Eric Blake <[email protected]> M: Vladimir Sementsov-Ogievskiy <[email protected]>
Signature · 1 line
MST
[PULL v2 08/86] hw/cxl/device: Implement basic mailbox (8.2.8.4)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
This is the beginning of implementing mailbox support for CXL 2.0 devices. The implementation recognizes when the doorbell is rung, handles the command/payload, clears the doorbell while returning error codes and data.
Generally the mailbox mechanism is designed to permit communication between the host OS and the firmware running on the device. For our purposes, we emulate both the firmware, implemented primarily in cxl-mailbox-utils.c, and the hardware.
No commands are implemented yet.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl.h | 3 + include/hw/cxl/cxl_device.h | 19 ++++- hw/cxl/cxl-device-utils.c | 122 ++++++++++++++++++++++++++- hw/cxl/cxl-mailbox-utils.c | 164 ++++++++++++++++++++++++++++++++++++ hw/cxl/meson.build | 1 + 5 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 hw/cxl/cxl-mailbox-utils.c
include/hw/cxl/cxl.h +3 -0
@@ -14,4 +14,7 @@#include "cxl_component.h" #include "cxl_device.h" +#define CXL_COMPONENT_REG_BAR_IDX 0 +#define CXL_DEVICE_REG_BAR_IDX 2 +#endif
include/hw/cxl/cxl_device.h +18 -1
@@ -90,7 +90,21 @@ typedef struct cxl_device_state { };/* mmio for the mailbox registers 8.2.8.4 */ -MemoryRegion mailbox; +struct { +MemoryRegion mailbox; +uint16_t payload_size; +union { +uint8_t mbox_reg_state[CXL_MAILBOX_REGISTERS_LENGTH ]; +uint16_t mbox_reg_state16[CXL_MAILBOX_REGISTERS_LENGTH /2 ]; +uint32_t mbox_reg_state32[CXL_MAILBOX_REGISTERS_LENGTH /4 ]; +uint64_t mbox_reg_state64[CXL_MAILBOX_REGISTERS_LENGTH /8 ]; + }; +struct cel_log { +uint16_t opcode; +uint16_t effect; + } cel_log[1 <<16 ]; +size_t cel_size; + };/* memory region for persistent memory, HDM */ uint64_t pmem_size;
@@ -140,6 +154,9 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(DEVICE_STATUS, CXL_DEVICE_CAP_HDR1_OFFSET)CXL_DEVICE_CAPABILITY_HEADER_REGISTER (MAILBOX ,CXL_DEVICE_CAP_HDR1_OFFSET + \ CXL_DEVICE_CAP_REG_SIZE) +int cxl_initialize_mailbox (CXLDeviceState *cxl_dstate); +void cxl_process_mailbox (CXLDeviceState *cxl_dstate); +#define cxl_device_cap_init (dstate, reg, cap_id) \ do { \ uint32_t *cap_hdrs = dstate->caps_reg_state32; \
hw/cxl/cxl-device-utils.c +121 -1
151 lines not on this page · raw message
hw/cxl/cxl-mailbox-utils.c new file +164 -0
164 lines not on this page · raw message
hw/cxl/meson.build +1 -0
@@ -2,4 +2,5 @@ softmmu_ss.add(when: 'CONFIG_CXL', if_true: files( 'cxl-component-utils.c', 'cxl-device-utils.c', + 'cxl-mailbox-utils.c', ))
Signature · 1 line
MST
[PULL v2 16/86] hw/pxb: Allow creation of a CXL PXB (host bridge)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
This works like adding a typical pxb device, except the name is 'pxb-cxl' instead of 'pxb-pcie'. An example command line would be as follows:
-device pxb-cxl,id=cxl.0,bus="pcie.0",bus_nr=1
A CXL PXB is backward compatible with PCIe. What this means in practice is that an operating system that is unaware of CXL should still be able to enumerate this topology as if it were PCIe.
One can create multiple CXL PXB host bridges, but a host bridge can only be connected to the main root bus. Host bridges cannot appear elsewhere in the topology.
Note that as of this patch, the ACPI tables needed for the host bridge (specifically, an ACPI object in _SB named ACPI0016 and the CEDT) aren't created. So while this patch internally creates it, it cannot be properly used by an operating system or other system software.
Also necessary is to add an exception to scripts/device-crash-test similar to that for exiting pxb as both must created on a PCIexpress host bus.
Message-Id: <[email protected]>
--- include/hw/pci/pci.h | 6 ++ hw/pci-bridge/pci_expander_bridge.c | 86 ++++++++++++++++++++++++++++- hw/pci/pci.c | 7 +++ scripts/device-crash-test | 1 + 4 files changed, 98 insertions(+), 2 deletions(-)
include/hw/pci/pci.h +6 -0
@@ -408,6 +408,7 @@ typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);#define TYPE_PCI_BUS "PCI" OBJECT_DECLARE_TYPE(PCIBus, PCIBusClass, PCI_BUS)#define TYPE_PCIE_BUS "PCIE" +#define TYPE_CXL_BUS "CXL"typedef void (*pci_bus_dev_fn )(PCIBus *b,PCIDevice *d,void *opaque);typedef void (*pci_bus_fn )(PCIBus *b,void *opaque);
@@ -770,6 +771,11 @@ static inline void pci_irq_pulse(PCIDevice *pci_dev)pci_irq_deassert (pci_dev); } +static inline int pci_is_cxl (const PCIDevice *d) +{ +return d->cap_present &QEMU_PCIE_CAP_CXL ; +} +static inline int pci_is_express (const PCIDevice *d) {return d->cap_present &QEMU_PCI_CAP_EXPRESS ;
hw/pci-bridge/pci_expander_bridge.c +84 -2
132 lines not on this page · raw message
hw/pci/pci.c +7 -0
@@ -228,6 +228,12 @@ static const TypeInfo pcie_bus_info = { .class_init = pcie_bus_class_init, }; +static const TypeInfo cxl_bus_info = { + .name =TYPE_CXL_BUS , + .parent =TYPE_PCIE_BUS , + .class_init = pcie_bus_class_init, +}; +static PCIBus *pci_find_bus_nr (PCIBus *bus,int bus_num);static void pci_update_mappings (PCIDevice *d);static void pci_irq_handler (void *opaque,int irq_num,int level);
@@ -2946,6 +2952,7 @@ static void pci_register_types(void) {type_register_static (&pci_bus_info);type_register_static (&pcie_bus_info); +type_register_static (&cxl_bus_info);type_register_static (&conventional_pci_interface_info);type_register_static (&cxl_interface_info);type_register_static (&pcie_interface_info);
scripts/device-crash-test +1 -0
@@ -93,6 +93,7 @@ ERROR_RULE_LIST = [ {'device':'pci-bridge', 'expected':True}, # Bridge chassis not specified. Each bridge is required to be assigned a unique chassis id > 0. {'device':'pci-bridge-seat', 'expected':True}, # Bridge chassis not specified. Each bridge is required to be assigned a unique chassis id > 0. {'device':'pxb', 'expected':True}, # Bridge chassis not specified. Each bridge is required to be assigned a unique chassis id > 0. + {'device':'pxb-cxl', 'expected':True}, # pxb-cxl devices cannot reside on a PCI bus. {'device':'scsi-block', 'expected':True}, # drive property not set {'device':'scsi-generic', 'expected':True}, # drive property not set {'device':'scsi-hd', 'expected':True}, # drive property not set
Signature · 1 line
MST
[PULL v2 06/86] hw/cxl/device: Introduce a CXL device (8.2.8)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
A CXL device is a type of CXL component. Conceptually, a CXL device would be a leaf node in a CXL topology. From an emulation perspective, CXL devices are the most complex and so the actual implementation is reserved for discrete commits.
This new device type is specifically catered towards the eventual implementation of a Type3 CXL.mem device, 8.2.8.5 in the CXL 2.0 specification.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl.h | 1 + include/hw/cxl/cxl_device.h | 166 ++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 include/hw/cxl/cxl_device.h
include/hw/cxl/cxl.h +1 -0
@@ -12,5 +12,6 @@#include "cxl_pci.h" #include "cxl_component.h" +#include "cxl_device.h" #endif
include/hw/cxl/cxl_device.h new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 11/86] hw/cxl/device: Timestamp implementation (8.2.9.3)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
Errata F4 to CXL 2.0 clarified the meaning of the timer as the sum of the value set with the timestamp set command and the number of nano seconds since it was last set.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_device.h | 6 ++++++ hw/cxl/cxl-mailbox-utils.c | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
include/hw/cxl/cxl_device.h +6 -0
@@ -111,6 +111,12 @@ typedef struct cxl_device_state {size_t cel_size; }; +struct { +bool set; +uint64_t last_set; +uint64_t host_set; + } timestamp; +/* memory region for persistent memory, HDM */ uint64_t pmem_size; } CXLDeviceState;
hw/cxl/cxl-mailbox-utils.c +42 -0
63 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 17/86] qtest/cxl: Introduce initial test for pxb-cxl only.
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Initial test with just pxb-cxl. Other tests will be added alongside functionality.
Message-Id: <[email protected]>
--- tests/qtest/cxl-test.c | 22 ++++++++++++++++++++++ tests/qtest/meson.build | 4 ++++ 2 files changed, 26 insertions(+) create mode 100644 tests/qtest/cxl-test.c
tests/qtest/cxl-test.c new file +22 -0
@@ -0,0 +1,22 @@ +/* +* QTest testcase for CXL +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "libqtest-single.h" + +static void cxl_basic_pxb (void ) +{ +qtest_start ("-machine q35,cxl=on -device pxb-cxl,bus=pcie.0" ); +qtest_end (); +} + +int main (int argc,char **argv) +{ +g_test_init (&argc, &argv,NULL ); +qtest_add_func ("/pci/cxl/basic_pxb" , cxl_basic_pxb); +return g_test_run (); +}
tests/qtest/meson.build +4 -0
@@ -35,6 +35,9 @@ qtests_pci = \ (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : []) + \ (config_all_devices.has_key('CONFIG_IVSHMEM_DEVICE') ? ['ivshmem-test'] : []) +qtests_cxl = \ + (config_all_devices.has_key('CONFIG_CXL') ? ['cxl-test'] : []) + qtests_i386 = \ (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) + \ (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) + \
@@ -74,6 +77,7 @@ qtests_i386 = \ slirp.found() ? ['virtio-net-failover'] : []) + \ (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \ qtests_pci + \ + qtests_cxl + \ ['fdc-test', 'ide-test', 'hd-geo-test',
Signature · 1 line
MST
[PULL v2 13/86] hw/pxb: Use a type for realizing expanders
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
This opens up the possibility for more types of expanders (other than PCI and PCIe). We'll need this to create a CXL expander.
Message-Id: <[email protected]>
--- hw/pci-bridge/pci_expander_bridge.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
hw/pci-bridge/pci_expander_bridge.c +7 -4
@@ -24,6 +24,8 @@#include "hw/boards.h" #include "qom/object.h" +enum BusType {PCI ,PCIE }; +#define TYPE_PXB_BUS "pxb-bus"typedef struct PXBBus PXBBus ; DECLARE_INSTANCE_CHECKER(PXBBus, PXB_BUS,
@@ -221,7 +223,8 @@ static gint pxb_compare(gconstpointer a, gconstpointer b)0 ; } -static void pxb_dev_realize_common (PCIDevice *dev,bool pcie,Error **errp) +static void pxb_dev_realize_common (PCIDevice *dev,enum BusType type, +Error **errp) {PXBDev *pxb =convert_to_pxb (dev);DeviceState *ds, *bds =NULL ;
@@ -246,7 +249,7 @@ static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp) } ds =qdev_new (TYPE_PXB_HOST ); -if (pcie) { +if (type ==PCIE ) { bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_PCIE_BUS ); }else { bus =pci_root_bus_new (ds,"pxb-internal" ,NULL ,NULL ,0 ,TYPE_PXB_BUS );
@@ -295,7 +298,7 @@ static void pxb_dev_realize(PCIDevice *dev, Error **errp)return ; } -pxb_dev_realize_common (dev, false, errp); +pxb_dev_realize_common (dev,PCI , errp); }static void pxb_dev_exitfn (PCIDevice *pci_dev)
@@ -348,7 +351,7 @@ static void pxb_pcie_dev_realize(PCIDevice *dev, Error **errp)return ; } -pxb_dev_realize_common (dev, true, errp); +pxb_dev_realize_common (dev,PCIE , errp); }static void pxb_pcie_dev_class_init (ObjectClass *klass,void *data)
Signature · 1 line
MST
[PULL v2 09/86] hw/cxl/device: Add memory device utilities
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
Memory devices implement extra capabilities on top of CXL devices. This adds support for that.
A large part of memory devices is the mailbox/command interface. All of the mailbox handling is done in the mailbox-utils library. Longer term, new CXL devices that are being emulated may want to handle commands differently, and therefore would need a mechanism to opt in/out of the specific generic handlers. As such, this is considered sufficient for now, but may need more depth in the future.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_device.h | 21 +++++++++++++++++--- hw/cxl/cxl-device-utils.c | 38 ++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-)
include/hw/cxl/cxl_device.h +18 -3
@@ -72,15 +72,20 @@#define CXL_MAILBOX_REGISTERS_LENGTH \ (CXL_MAILBOX_REGISTERS_SIZE + CXL_MAILBOX_MAX_PAYLOAD_SIZE) -#define CXL_MMIO_SIZE \ - (CXL_DEVICE_CAP_REG_SIZE + CXL_DEVICE_STATUS_REGISTERS_LENGTH + \ - CXL_MAILBOX_REGISTERS_LENGTH) +#define CXL_MEMORY_DEVICE_REGISTERS_OFFSET \ + (CXL_MAILBOX_REGISTERS_OFFSET + CXL_MAILBOX_REGISTERS_LENGTH) +#define CXL_MEMORY_DEVICE_REGISTERS_LENGTH 0x8 + +#define CXL_MMIO_SIZE \ + (CXL_DEVICE_CAP_REG_SIZE + CXL_DEVICE_STATUS_REGISTERS_LENGTH + \ + CXL_MAILBOX_REGISTERS_LENGTH + CXL_MEMORY_DEVICE_REGISTERS_LENGTH) typedef struct cxl_device_state { MemoryRegion device_registers; /* mmio for device capabilities array - 8.2.8.2 */ MemoryRegion device; + MemoryRegion memory_device; struct { MemoryRegion caps; union {
@@ -153,6 +158,9 @@ REG64(CXL_DEV_CAP_ARRAY, 0) /* Documented as 128 bit register but 64 byte access CXL_DEVICE_CAPABILITY_HEADER_REGISTER(DEVICE_STATUS, CXL_DEVICE_CAP_HDR1_OFFSET)CXL_DEVICE_CAPABILITY_HEADER_REGISTER (MAILBOX ,CXL_DEVICE_CAP_HDR1_OFFSET + \ CXL_DEVICE_CAP_REG_SIZE) +CXL_DEVICE_CAPABILITY_HEADER_REGISTER (MEMORY_DEVICE , +CXL_DEVICE_CAP_HDR1_OFFSET + + CXL_DEVICE_CAP_REG_SIZE * 2)int cxl_initialize_mailbox (CXLDeviceState *cxl_dstate);void cxl_process_mailbox (CXLDeviceState *cxl_dstate);
@@ -209,4 +217,11 @@ REG64(CXL_DEV_BG_CMD_STS, 0x18)/* CXL 2.0 8.2.8.4.8 Command Payload Registers */ REG32(CXL_DEV_CMD_PAYLOAD, 0x20) +REG64(CXL_MEM_DEV_STS, 0) + FIELD(CXL_MEM_DEV_STS, FATAL, 0, 1) + FIELD(CXL_MEM_DEV_STS, FW_HALT, 1, 1) + FIELD(CXL_MEM_DEV_STS, MEDIA_STATUS, 2, 2) + FIELD(CXL_MEM_DEV_STS, MBOX_READY, 4, 1) + FIELD(CXL_MEM_DEV_STS, RESET_NEEDED, 5, 3) +#endif
hw/cxl/cxl-device-utils.c +37 -1
@@ -131,6 +131,31 @@ static void mailbox_reg_write(void *opaque, hwaddr offset, uint64_t value, } } +static uint64_t mdev_reg_read (void *opaque,hwaddr offset,unsigned size) +{ +uint64_t retval =0 ; + + retval =FIELD_DP64 (retval,CXL_MEM_DEV_STS ,MEDIA_STATUS ,1 ); + retval =FIELD_DP64 (retval,CXL_MEM_DEV_STS ,MBOX_READY ,1 ); + +return retval; +} + +static const MemoryRegionOps mdev_ops = { + .read = mdev_reg_read, + .write =NULL ,/* memory device register is read only */ + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =8 , + .unaligned = false, + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; +static const MemoryRegionOps mailbox_ops = { .read = mailbox_reg_read, .write = mailbox_reg_write,
@@ -188,6 +213,9 @@ void cxl_device_register_block_init(Object *obj, CXLDeviceState *cxl_dstate) "device-status", CXL_DEVICE_STATUS_REGISTERS_LENGTH);memory_region_init_io (&cxl_dstate->mailbox, obj, &mailbox_ops, cxl_dstate,"mailbox" ,CXL_MAILBOX_REGISTERS_LENGTH ); +memory_region_init_io (&cxl_dstate->memory_device, obj, &mdev_ops, + cxl_dstate,"memory device caps" , +CXL_MEMORY_DEVICE_REGISTERS_LENGTH );memory_region_add_subregion (&cxl_dstate->device_registers,0 , &cxl_dstate->caps);
@@ -197,6 +225,9 @@ void cxl_device_register_block_init(Object *obj, CXLDeviceState *cxl_dstate)memory_region_add_subregion (&cxl_dstate->device_registers,CXL_MAILBOX_REGISTERS_OFFSET , &cxl_dstate->mailbox); +memory_region_add_subregion (&cxl_dstate->device_registers, +CXL_MEMORY_DEVICE_REGISTERS_OFFSET , + &cxl_dstate->memory_device); }static void device_reg_init_common (CXLDeviceState *cxl_dstate) { }
@@ -209,10 +240,12 @@ static void mailbox_reg_init_common(CXLDeviceState *cxl_dstate) cxl_dstate->payload_size =CXL_MAILBOX_MAX_PAYLOAD_SIZE ; } +static void memdev_reg_init_common (CXLDeviceState *cxl_dstate) { } +void cxl_device_register_init_common (CXLDeviceState *cxl_dstate) {uint64_t *cap_hdrs = cxl_dstate->caps_reg_state64; -const int cap_count =2 ; +const int cap_count =3 ;/* CXL Device Capabilities Array Register */ ARRAY_FIELD_DP64 (cap_hdrs,CXL_DEV_CAP_ARRAY ,CAP_ID ,0 );
@@ -225,5 +258,8 @@ void cxl_device_register_init_common(CXLDeviceState *cxl_dstate)cxl_device_cap_init (cxl_dstate,MAILBOX ,2 );mailbox_reg_init_common (cxl_dstate); +cxl_device_cap_init (cxl_dstate,MEMORY_DEVICE ,0x4000 ); +memdev_reg_init_common (cxl_dstate); +assert (cxl_initialize_mailbox (cxl_dstate) ==0 ); }
Signature · 1 line
MST
[PULL v2 12/86] hw/cxl/device: Add log commands (8.2.9.4) + CEL
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
CXL specification provides for the ability to obtain logs from the device. Logs are either spec defined, like the "Command Effects Log" (CEL), or vendor specific. UUIDs are defined for all log types.
The CEL is a mechanism to provide information to the host about which commands are supported. It is useful both to determine which spec'd optional commands are supported, as well as provide a list of vendor specified commands that might be used. The CEL is already created as part of mailbox initialization, but here it is now exported to hosts that use these log commands.
Message-Id: <[email protected]>
--- hw/cxl/cxl-mailbox-utils.c | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
hw/cxl/cxl-mailbox-utils.c +69 -0
@@ -47,6 +47,9 @@ enum { TIMESTAMP = 0x03,#define GET 0x0#define SET 0x1 + LOGS = 0x04, +#define GET_SUPPORTED 0x0 +#define GET_LOG 0x1 };/* 8.2.8.4.5.1 Command Return Codes */
@@ -147,6 +150,70 @@ static ret_code cmd_timestamp_set(struct cxl_cmd *cmd,static QemuUUID cel_uuid; +/* 8.2.9.4.1 */ +static ret_code cmd_logs_get_supported (struct cxl_cmd *cmd, +CXLDeviceState *cxl_dstate, +uint16_t *len) +{ +struct { +uint16_t entries; +uint8_t rsvd[6 ]; +struct { +QemuUUID uuid; +uint32_t size; + } log_entries[1 ]; + } QEMU_PACKED *supported_logs = (void *)cmd->payload; +QEMU_BUILD_BUG_ON (sizeof (*supported_logs) !=0x1c ); + + supported_logs->entries =1 ; + supported_logs->log_entries[0 ].uuid = cel_uuid; + supported_logs->log_entries[0 ].size =4 * cxl_dstate->cel_size; + + *len =sizeof (*supported_logs); +return CXL_MBOX_SUCCESS ; +} + +/* 8.2.9.4.2 */ +static ret_code cmd_logs_get_log (struct cxl_cmd *cmd, +CXLDeviceState *cxl_dstate, +uint16_t *len) +{ +struct { +QemuUUID uuid; +uint32_t offset; +uint32_t length; + } QEMU_PACKED QEMU_ALIGNED(16) *get_log = (void *)cmd->payload; + +/* +* 8.2.9.4.2 +* The device shall return Invalid Parameter if the Offset or Length +* fields attempt to access beyond the size of the log as reported by Get +* Supported Logs. +* +* XXX: Spec is wrong, "Invalid Parameter" isn't a thing. +* XXX: Spec doesn't address incorrect UUID incorrectness. +* +* The CEL buffer is large enough to fit all commands in the emulation, so +* the only possible failure would be if the mailbox itself isn't big +* enough. +*/ +if (get_log->offset + get_log->length > cxl_dstate->payload_size) { +return CXL_MBOX_INVALID_INPUT ; + } + +if (!qemu_uuid_is_equal (&get_log->uuid, &cel_uuid)) { +return CXL_MBOX_UNSUPPORTED ; + } + +/* Store off everything to local variables so we can wipe out the payload */ + *len = get_log->length; + +memmove (cmd->payload, cxl_dstate->cel_log + get_log->offset, + get_log->length); + +return CXL_MBOX_SUCCESS ; +} +#define IMMEDIATE_CONFIG_CHANGE (1 << 1)#define IMMEDIATE_POLICY_CHANGE (1 << 3)#define IMMEDIATE_LOG_CHANGE (1 << 4)
@@ -162,6 +229,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] = { cmd_events_set_interrupt_policy, 4, IMMEDIATE_CONFIG_CHANGE }, [TIMESTAMP][GET] = { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 }, [TIMESTAMP][SET] = { "TIMESTAMP_SET", cmd_timestamp_set, 8, IMMEDIATE_POLICY_CHANGE }, + [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported, 0, 0 }, + [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 }, };void cxl_process_mailbox (CXLDeviceState *cxl_dstate)
Signature · 1 line
MST
[PULL v2 23/86] hw/cxl/device: Implement get/set Label Storage Area (LSA)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
Implement get and set handlers for the Label Storage Area used to hold data describing persistent memory configuration so that it can be ensured it is seen in the same configuration after reboot.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_device.h | 5 ++++ hw/cxl/cxl-mailbox-utils.c | 60 +++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 56 +++++++++++++++++++++++++++++++++- 3 files changed, 120 insertions(+), 1 deletion(-)
include/hw/cxl/cxl_device.h +5 -0
@@ -252,6 +252,11 @@ struct CXLType3Class {/* public */ uint64_t (*get_lsa_size)(CXLType3Dev *ct3d); + +uint64_t (*get_lsa)(CXLType3Dev *ct3d,void *buf,uint64_t size, +uint64_t offset); +void (*set_lsa)(CXLType3Dev *ct3d,const void *buf,uint64_t size, + uint64_t offset); };#endif
hw/cxl/cxl-mailbox-utils.c +60 -0
79 lines not on this page · raw message
hw/mem/cxl_type3.c +55 -1
85 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 49/86] target/i386: Fix sanity check on max APIC ID / X2APIC enablement
In reply to Michael S. TsirkinFrom: David Woodhouse <[email protected]>
The check on x86ms->apic_id_limit in pc_machine_done() had two problems.
Firstly, we need KVM to support the X2APIC API in order to allow IRQ delivery to APICs >= 255. So we need to call/check kvm_enable_x2apic(), which was done elsewhere in *some* cases but not all.
Secondly, microvm needs the same check. So move it from pc_machine_done() to x86_cpus_init() where it will work for both.
The check in kvm_cpu_instance_init() is now redundant and can be dropped.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 8 -------- hw/i386/x86.c | 16 ++++++++++++++++ target/i386/kvm/kvm-cpu.c | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-)
hw/i386/pc.c +0 -8
@@ -744,14 +744,6 @@ void pc_machine_done(Notifier *notifier, void *data)/* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16 (x86ms->fw_cfg,FW_CFG_NB_CPUS , x86ms->boot_cpus); } - - -if (x86ms->apic_id_limit >255 && !xen_enabled () && - !kvm_irqchip_in_kernel ()) { -error_report ("current -smp configuration requires kernel " -"irqchip support." ); -exit (EXIT_FAILURE ); - } }void pc_guest_info_init (PCMachineState *pcms)
hw/i386/x86.c +16 -0
@@ -38,6 +38,7 @@#include "sysemu/replay.h" #include "sysemu/sysemu.h" #include "sysemu/cpu-timers.h" +#include "sysemu/xen.h" #include "trace.h" #include "hw/i386/x86.h"
@@ -122,6 +123,21 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)*/ x86ms->apic_id_limit =x86_cpu_apic_id_from_index (x86ms, ms->smp.max_cpus -1 ) +1 ; + +/* +* Can we support APIC ID 255 or higher? +* +* Under Xen: yes. +* With userspace emulated lapic: no +* With KVM's in-kernel lapic: only if X2APIC API is enabled. +*/ +if (x86ms->apic_id_limit >255 && !xen_enabled () && + (!kvm_irqchip_in_kernel () || !kvm_enable_x2apic ())) { +error_report ("current -smp configuration requires kernel " +"irqchip and X2APIC API support." ); +exit (EXIT_FAILURE ); + } + possible_cpus = mc->possible_cpu_arch_ids (ms);for (i =0 ; i < ms->smp.cpus; i++) {x86_cpu_new (x86ms, possible_cpus->cpus[i].arch_id, &error_fatal);
target/i386/kvm/kvm-cpu.c +1 -1
@@ -171,7 +171,7 @@ static void kvm_cpu_instance_init(CPUState *cs)/* only applies to builtin_x86_defs cpus */ if (!kvm_irqchip_in_kernel ()) {x86_cpu_change_kvm_default ("x2apic" ,"off" ); - }else if (kvm_irqchip_is_split () &&kvm_enable_x2apic ()) { + }else if (kvm_irqchip_is_split ()) {x86_cpu_change_kvm_default ("kvm-msi-ext-dest-id" ,"on" ); }
Signature · 1 line
MST
[PULL v2 18/86] hw/cxl/rp: Add a root port
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
This adds just enough of a root port implementation to be able to enumerate root ports (creating the required DVSEC entries). What's not here yet is the MMIO nor the ability to write some of the DVSEC entries.
This can be added with the qemu commandline by adding a rootport to a specific CXL host bridge. For example:
-device cxl-rp,id=rp0,bus="cxl.0",addr=0.0,chassis=4
Like the host bridge patch, the ACPI tables aren't generated at this point and so system software cannot use it.
Message-Id: <[email protected]>
--- hw/pci-bridge/cxl_root_port.c | 236 +++++++++++++++++++++++++++++++++ hw/pci-bridge/pcie_root_port.c | 6 +- hw/pci/pci.c | 4 +- hw/pci-bridge/Kconfig | 5 + hw/pci-bridge/meson.build | 1 + 5 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 hw/pci-bridge/cxl_root_port.c
hw/pci-bridge/cxl_root_port.c new file +236 -0
@@ -0,0 +1,236 @@ +/* +* CXL 2.0 Root Port Implementation +* +* Copyright(C) 2020 Intel Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/range.h" +#include "hw/pci/pci_bridge.h" +#include "hw/pci/pcie_port.h" +#include "hw/qdev-properties.h" +#include "hw/sysbus.h" +#include "qapi/error.h" +#include "hw/cxl/cxl.h" + +#define CXL_ROOT_PORT_DID 0x7075 + +/* Copied from the gen root port which we derive */ +#define GEN_PCIE_ROOT_PORT_AER_OFFSET 0x100 +#define GEN_PCIE_ROOT_PORT_ACS_OFFSET \ + (GEN_PCIE_ROOT_PORT_AER_OFFSET + PCI_ERR_SIZEOF) +#define CXL_ROOT_PORT_DVSEC_OFFSET \ + (GEN_PCIE_ROOT_PORT_ACS_OFFSET + PCI_ACS_SIZEOF) + +typedef struct CXLRootPort { +/*< private >*/ +PCIESlot parent_obj; + +CXLComponentState cxl_cstate; +PCIResReserve res_reserve; +}CXLRootPort ; + +#define TYPE_CXL_ROOT_PORT "cxl-rp" +DECLARE_INSTANCE_CHECKER(CXLRootPort, CXL_ROOT_PORT, TYPE_CXL_ROOT_PORT) + +static void latch_registers (CXLRootPort *crp) +{ +uint32_t *reg_state = crp->cxl_cstate.crb.cache_mem_registers; +uint32_t *write_msk = crp->cxl_cstate.crb.cache_mem_regs_write_mask; + +cxl_component_register_init_common (reg_state, write_msk,CXL2_ROOT_PORT ); +} + +static void build_dvsecs (CXLComponentState *cxl) +{ +uint8_t *dvsec; + + dvsec = (uint8_t *)&(CXLDVSECPortExtensions ){0 }; +cxl_component_create_dvsec (cxl,CXL2_ROOT_PORT , +EXTENSIONS_PORT_DVSEC_LENGTH , +EXTENSIONS_PORT_DVSEC , +EXTENSIONS_PORT_DVSEC_REVID , dvsec); + + dvsec = (uint8_t *)&(CXLDVSECPortGPF ){ + .rsvd =0 , + .phase1_ctrl =1 ,/* 1μs timeout */ + .phase2_ctrl =1 ,/* 1μs timeout */ + }; +cxl_component_create_dvsec (cxl,CXL2_ROOT_PORT , +GPF_PORT_DVSEC_LENGTH ,GPF_PORT_DVSEC , +GPF_PORT_DVSEC_REVID , dvsec); + + dvsec = (uint8_t *)&(CXLDVSECPortFlexBus ){ + .cap =0x26 ,/* IO, Mem, non-MLD */ + .ctrl =0x2 , + .status =0x26 ,/* same */ + .rcvd_mod_ts_data_phase1 =0xef , + }; +cxl_component_create_dvsec (cxl,CXL2_ROOT_PORT , +PCIE_FLEXBUS_PORT_DVSEC_LENGTH_2_0 , +PCIE_FLEXBUS_PORT_DVSEC , +PCIE_FLEXBUS_PORT_DVSEC_REVID_2_0 , dvsec); + + dvsec = (uint8_t *)&(CXLDVSECRegisterLocator ){ + .rsvd =0 , + .reg0_base_lo =RBI_COMPONENT_REG |CXL_COMPONENT_REG_BAR_IDX , + .reg0_base_hi =0 , + }; +cxl_component_create_dvsec (cxl,CXL2_ROOT_PORT , +REG_LOC_DVSEC_LENGTH ,REG_LOC_DVSEC , +REG_LOC_DVSEC_REVID , dvsec); +} + +static void cxl_rp_realize (DeviceState *dev,Error **errp) +{ +PCIDevice *pci_dev =PCI_DEVICE (dev); +PCIERootPortClass *rpc =PCIE_ROOT_PORT_GET_CLASS (dev); +CXLRootPort *crp =CXL_ROOT_PORT (dev); +CXLComponentState *cxl_cstate = &crp->cxl_cstate; +ComponentRegisters *cregs = &cxl_cstate->crb; +MemoryRegion *component_bar = &cregs->component_registers; +Error *local_err =NULL ; + + rpc->parent_realize (dev, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +int rc = +pci_bridge_qemu_reserve_cap_init (pci_dev,0 , crp->res_reserve, errp); +if (rc <0 ) { + rpc->parent_class.exit (pci_dev); +return ; + } + +if (!crp->res_reserve.io || crp->res_reserve.io ==-1 ) { +pci_word_test_and_clear_mask (pci_dev->wmask +PCI_COMMAND , +PCI_COMMAND_IO ); + pci_dev->wmask[PCI_IO_BASE ] =0 ; + pci_dev->wmask[PCI_IO_LIMIT ] =0 ; + } + + cxl_cstate->dvsec_offset =CXL_ROOT_PORT_DVSEC_OFFSET ; + cxl_cstate->pdev = pci_dev; +build_dvsecs (&crp->cxl_cstate); + +cxl_component_register_block_init (OBJECT (pci_dev), cxl_cstate, +TYPE_CXL_ROOT_PORT ); + +pci_register_bar (pci_dev,CXL_COMPONENT_REG_BAR_IDX , +PCI_BASE_ADDRESS_SPACE_MEMORY | +PCI_BASE_ADDRESS_MEM_TYPE_64 , + component_bar); +} + +static void cxl_rp_reset (DeviceState *dev) +{ +PCIERootPortClass *rpc =PCIE_ROOT_PORT_GET_CLASS (dev); +CXLRootPort *crp =CXL_ROOT_PORT (dev); + + rpc->parent_reset (dev); + +latch_registers (crp); +} + +static Property gen_rp_props[] = { +DEFINE_PROP_UINT32 ("bus-reserve" , CXLRootPort, res_reserve.bus,-1 ), +DEFINE_PROP_SIZE ("io-reserve" , CXLRootPort, res_reserve.io,-1 ), +DEFINE_PROP_SIZE ("mem-reserve" , CXLRootPort, res_reserve.mem_non_pref,-1 ), +DEFINE_PROP_SIZE ("pref32-reserve" , CXLRootPort, res_reserve.mem_pref_32, +-1 ), +DEFINE_PROP_SIZE ("pref64-reserve" , CXLRootPort, res_reserve.mem_pref_64, +-1 ), +DEFINE_PROP_END_OF_LIST () +}; + +static void cxl_rp_dvsec_write_config (PCIDevice *dev,uint32_t addr, +uint32_t val,int len) +{ +CXLRootPort *crp =CXL_ROOT_PORT (dev); + +if (range_contains (&crp->cxl_cstate.dvsecs[EXTENSIONS_PORT_DVSEC ], addr)) { +uint8_t *reg = &dev->config[addr]; + addr -= crp->cxl_cstate.dvsecs[EXTENSIONS_PORT_DVSEC ].lob; +if (addr ==PORT_CONTROL_OFFSET ) { +if (pci_get_word (reg) &PORT_CONTROL_UNMASK_SBR ) { +/* unmask SBR */ +qemu_log_mask (LOG_UNIMP ,"SBR mask control is not supported\n" ); + } +if (pci_get_word (reg) &PORT_CONTROL_ALT_MEMID_EN ) { +/* Alt Memory & ID Space Enable */ +qemu_log_mask (LOG_UNIMP , +"Alt Memory & ID space is not supported\n" ); + } + } + } +} + +static void cxl_rp_write_config (PCIDevice *d,uint32_t address,uint32_t val, +int len) +{ +uint16_t slt_ctl, slt_sta; + +pcie_cap_slot_get (d, &slt_ctl, &slt_sta); +pci_bridge_write_config (d, address, val, len); +pcie_cap_flr_write_config (d, address, val, len); +pcie_cap_slot_write_config (d, slt_ctl, slt_sta, address, val, len); +pcie_aer_write_config (d, address, val, len); + +cxl_rp_dvsec_write_config (d, address, val, len); +} + +static void cxl_root_port_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +PCIDeviceClass *k =PCI_DEVICE_CLASS (oc); +PCIERootPortClass *rpc =PCIE_ROOT_PORT_CLASS (oc); + + k->vendor_id =PCI_VENDOR_ID_INTEL ; + k->device_id =CXL_ROOT_PORT_DID ; + dc->desc ="CXL Root Port" ; + k->revision =0 ; +device_class_set_props (dc, gen_rp_props); + k->config_write = cxl_rp_write_config; + +device_class_set_parent_realize (dc, cxl_rp_realize, &rpc->parent_realize); +device_class_set_parent_reset (dc, cxl_rp_reset, &rpc->parent_reset); + + rpc->aer_offset =GEN_PCIE_ROOT_PORT_AER_OFFSET ; + rpc->acs_offset =GEN_PCIE_ROOT_PORT_ACS_OFFSET ; + + dc->hotpluggable = false; +} + +static const TypeInfo cxl_root_port_info = { + .name =TYPE_CXL_ROOT_PORT , + .parent =TYPE_PCIE_ROOT_PORT , + .instance_size =sizeof (CXLRootPort), + .class_init = cxl_root_port_class_init, + .interfaces = (InterfaceInfo []) { + {INTERFACE_CXL_DEVICE }, + { } + }, +}; + +static void cxl_register (void ) +{ +type_register_static (&cxl_root_port_info); +} + +type_init (cxl_register);
hw/pci-bridge/pcie_root_port.c +5 -1
@@ -67,7 +67,11 @@ static void rp_realize(PCIDevice *d, Error **errp)int rc;pci_config_set_interrupt_pin (d->config,1 ); -pci_bridge_initfn (d,TYPE_PCIE_BUS ); +if (d->cap_present &QEMU_PCIE_CAP_CXL ) { +pci_bridge_initfn (d,TYPE_CXL_BUS ); + }else { +pci_bridge_initfn (d,TYPE_PCIE_BUS ); + }pcie_port_init_reg (d); rc = pci_bridge_ssvid_init(d, rpc->ssvid_offset, dc->vendor_id,
hw/pci/pci.c +3 -1
@@ -2762,7 +2762,9 @@ static void pci_device_class_base_init(ObjectClass *klass, void *data)object_class_dynamic_cast (klass,INTERFACE_CONVENTIONAL_PCI_DEVICE );ObjectClass *pcie =object_class_dynamic_cast (klass,INTERFACE_PCIE_DEVICE ); -assert (conventional || pcie); +ObjectClass *cxl = +object_class_dynamic_cast (klass,INTERFACE_CXL_DEVICE ); +assert (conventional || pcie || cxl); } }
hw/pci-bridge/Kconfig +5 -0
@@ -27,3 +27,8 @@ config DEC_PCI config SIMBA bool + +config CXL + bool + default y if PCI_EXPRESS && PXB + depends on PCI_EXPRESS && MSI_NONBROKEN && PXB
hw/pci-bridge/meson.build +1 -0
@@ -5,6 +5,7 @@ pci_ss.add(when: 'CONFIG_IOH3420', if_true: files('ioh3420.c')) pci_ss.add(when: 'CONFIG_PCIE_PORT', if_true: files('pcie_root_port.c', 'gen_pcie_root_port.c', 'pcie_pci_bridge.c')) pci_ss.add(when: 'CONFIG_PXB', if_true: files('pci_expander_bridge.c')) pci_ss.add(when: 'CONFIG_XIO3130', if_true: files('xio3130_upstream.c', 'xio3130_downstream.c')) +pci_ss.add(when: 'CONFIG_CXL', if_true: files('cxl_root_port.c')) # NewWorld PowerMac pci_ss.add(when: 'CONFIG_DEC_PCI', if_true: files('dec.c'))
Signature · 1 line
MST
[PULL v2 26/86] acpi/cxl: Add _OSC implementation (9.14.2)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
CXL 2.0 specification adds 2 new dwords to the existing _OSC definition from PCIe. The new dwords are accessed with a new uuid. This implementation supports what is in the specification.
iasl -d decodes the result of this patch as:
Name (SUPP, Zero)
Name (CTRL, Zero)
Name (SUPC, Zero)
Name (CTRC, Zero)
Method (_OSC, 4, NotSerialized) // _OSC: Operating System Capabilities
{
CreateDWordField (Arg3, Zero, CDW1)
If (((Arg0 == ToUUID ("33db4d5b-1ff7-401c-9657-7441c03dd766") /* PCI Host Bridge Device */) || (Arg0 == ToUUID ("68f2d50b-c469-4d8a-bd3d-941a103fd3fc") /* Unknown UUID */)))
{
CreateDWordField (Arg3, 0x04, CDW2)
CreateDWordField (Arg3, 0x08, CDW3)
Local0 = CDW3 /* \_SB_.PC0C._OSC.CDW3 */
Local0 &= 0x1F
If ((Arg1 != One))
{
CDW1 |= 0x08
}
If ((CDW3 != Local0))
{
CDW1 |= 0x10
}
SUPP = CDW2 /* \_SB_.PC0C._OSC.CDW2 */
CTRL = CDW3 /* \_SB_.PC0C._OSC.CDW3 */
CDW3 = Local0
If ((Arg0 == ToUUID ("68f2d50b-c469-4d8a-bd3d-941a103fd3fc") /* Unknown UUID */))
{
CreateDWordField (Arg3, 0x0C, CDW4)
CreateDWordField (Arg3, 0x10, CDW5)
SUPC = CDW4 /* \_SB_.PC0C._OSC.CDW4 */
CTRC = CDW5 /* \_SB_.PC0C._OSC.CDW5 */
CDW5 |= One
}
Return (Arg3)
}
Else
{
CDW1 |= 0x04
Return (Arg3)
}Message-Id: <[email protected]>
--- include/hw/acpi/cxl.h | 23 ++++++++ hw/acpi/cxl-stub.c | 12 ++++ hw/acpi/cxl.c | 130 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 13 +++-- hw/acpi/Kconfig | 5 ++ hw/acpi/meson.build | 4 +- 6 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 include/hw/acpi/cxl.h create mode 100644 hw/acpi/cxl-stub.c create mode 100644 hw/acpi/cxl.c
include/hw/acpi/cxl.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (C) 2020 Intel Corporation +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_ACPI_CXL_H +#define HW_ACPI_CXL_H + +void build_cxl_osc_method (Aml *dev); + +#endif
hw/acpi/cxl-stub.c new file +12 -0
@@ -0,0 +1,12 @@ + +/* +* Stubs for ACPI platforms that don't support CXl +*/ +#include "qemu/osdep.h" +#include "hw/acpi/aml-build.h" +#include "hw/acpi/cxl.h" + +void build_cxl_osc_method (Aml *dev) +{ +g_assert_not_reached (); +}
hw/acpi/cxl.c new file +130 -0
130 lines not on this page · raw message
hw/i386/acpi-build.c +9 -4
@@ -67,6 +67,7 @@#include "hw/acpi/aml-build.h" #include "hw/acpi/utils.h" #include "hw/acpi/pci.h" +#include "hw/acpi/cxl.h" #include "qom/qom-qobject.h" #include "hw/i386/amd_iommu.h"
@@ -1582,11 +1583,15 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num)));if (pci_bus_is_cxl (bus)) { -aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" ))); -aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" ))); +struct Aml *pkg =aml_package (2 ); -/* Expander bridges do not have ACPI PCI Hot-plug enabled */ -aml_append (dev,build_q35_osc_method (true)); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("ACPI0016" ))); +aml_append (pkg,aml_eisaid ("PNP0A08" )); +aml_append (pkg,aml_eisaid ("PNP0A03" )); +aml_append (dev,aml_name_decl ("_CID" , pkg)); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (0 ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num))); +build_cxl_osc_method (dev); }else if (pci_bus_is_express (bus)) {aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" )));aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" )));
hw/acpi/Kconfig +5 -0
@@ -5,6 +5,7 @@ config ACPI_X86 bool select ACPI select ACPI_NVDIMM + select ACPI_CXL select ACPI_CPU_HOTPLUG select ACPI_MEMORY_HOTPLUG select ACPI_HMAT
@@ -66,3 +67,7 @@ config ACPI_ERST bool default y depends on ACPI && PCI + +config ACPI_CXL + bool + depends on ACPI
hw/acpi/meson.build +3 -1
@@ -13,6 +13,7 @@ acpi_ss.add(when: 'CONFIG_ACPI_MEMORY_HOTPLUG', if_false: files('acpi-mem-hotplu acpi_ss.add(when: 'CONFIG_ACPI_NVDIMM', if_true: files('nvdimm.c')) acpi_ss.add(when: 'CONFIG_ACPI_NVDIMM', if_false: files('acpi-nvdimm-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_PCI', if_true: files('pci.c')) +acpi_ss.add(when: 'CONFIG_ACPI_CXL', if_true: files('cxl.c'), if_false: files('cxl-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_VMGENID', if_true: files('vmgenid.c')) acpi_ss.add(when: 'CONFIG_ACPI_HW_REDUCED', if_true: files('generic_event_device.c')) acpi_ss.add(when: 'CONFIG_ACPI_HMAT', if_true: files('hmat.c'))
@@ -33,4 +34,5 @@ softmmu_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('acpi-stub.c', 'aml-build-stub.c', 'acpi-x86-stub.c', 'ipmi-stub.c', 'ghes-stub.c', 'acpi-mem-hotplug-stub.c', 'acpi-cpu-hotplug-stub.c', - 'acpi-pci-hotplug-stub.c', 'acpi-nvdimm-stub.c')) + 'acpi-pci-hotplug-stub.c', 'acpi-nvdimm-stub.c', + 'cxl-stub.c'))
Signature · 1 line
MST
[PULL v2 22/86] hw/cxl/device: Plumb real Label Storage Area (LSA) sizing
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
This should introduce no change. Subsequent work will make use of this new class member.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_device.h | 11 ++++++++++- hw/cxl/cxl-mailbox-utils.c | 3 +++ hw/mem/cxl_type3.c | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-)
include/hw/cxl/cxl_device.h +10 -1
@@ -236,6 +236,7 @@ struct CXLType3Dev {/* Properties */ HostMemoryBackend *hostmem; +HostMemoryBackend *lsa;/* State */ CXLComponentState cxl_cstate;
@@ -243,6 +244,14 @@ struct CXLType3Dev { }; #define TYPE_CXL_TYPE3 "cxl-type3" -OBJECT_DECLARE_SIMPLE_TYPE(CXLType3Dev, CXL_TYPE3) +OBJECT_DECLARE_TYPE(CXLType3Dev, CXLType3Class, CXL_TYPE3) + +struct CXLType3Class { +/* Private */ +PCIDeviceClass parent_class; + +/* public */ +uint64_t (*get_lsa_size)(CXLType3Dev *ct3d); +};#endif
hw/cxl/cxl-mailbox-utils.c +3 -0
@@ -277,6 +277,8 @@ static ret_code cmd_identify_memory_device(struct cxl_cmd *cmd, }QEMU_PACKED *id;QEMU_BUILD_BUG_ON (sizeof (*id) !=0x43 ); +CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate); +CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d);uint64_t size = cxl_dstate->pmem_size;if (!QEMU_IS_ALIGNED (size,256 <<20 )) {
@@ -291,6 +293,7 @@ static ret_code cmd_identify_memory_device(struct cxl_cmd *cmd, id->total_capacity = size / (256 <<20 ); id->persistent_capacity = size / (256 <<20 ); + id->lsa_size = cvc->get_lsa_size (ct3d); *len =sizeof (*id);return CXL_MBOX_SUCCESS ;
hw/mem/cxl_type3.c +9 -0
@@ -179,10 +179,16 @@ static Property ct3_props[] = { DEFINE_PROP_END_OF_LIST(), }; +static uint64_t get_lsa_size (CXLType3Dev *ct3d) +{ +return 0 ; +} +static void ct3_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc);PCIDeviceClass *pc =PCI_DEVICE_CLASS (oc); +CXLType3Class *cvc =CXL_TYPE3_CLASS (oc); pc->realize = ct3_realize; pc->exit = ct3_exit;
@@ -195,11 +201,14 @@ static void ct3_class_init(ObjectClass *oc, void *data) dc->desc ="CXL PMEM Device (Type 3)" ; dc->reset = ct3d_reset;device_class_set_props (dc, ct3_props); + + cvc->get_lsa_size = get_lsa_size; }static const TypeInfo ct3d_info = { .name =TYPE_CXL_TYPE3 , .parent =TYPE_PCI_DEVICE , + .class_size =sizeof (struct CXLType3Class ), .class_init = ct3_class_init, .instance_size =sizeof (CXLType3Dev), .interfaces = (InterfaceInfo []) {
Signature · 1 line
MST
[PULL v2 19/86] hw/cxl/device: Add a memory device (8.2.8.5)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
A CXL memory device (AKA Type 3) is a CXL component that contains some combination of volatile and persistent memory. It also implements the previously defined mailbox interface as well as the memory device firmware interface.
Although the memory device is configured like a normal PCIe device, the memory traffic is on an entirely separate bus conceptually (using the same physical wires as PCIe, but different protocol).
Once the CXL topology is fully configure and address decoders committed, the guest physical address for the memory device is part of a larger window which is owned by the platform. The creation of these windows is later in this series.
The following example will create a 256M device in a 512M window:
-object "memory-backend-file,id=cxl-mem1,share,mem-path=cxl-type3,size=512M" -device "cxl-type3,bus=rp0,memdev=cxl-mem1,id=cxl-pmem0"
Note: Dropped PCDIMM info interfaces for now. They can be added if appropriate at a later date.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_device.h | 15 ++++ include/hw/cxl/cxl_pci.h | 21 +++++ include/hw/pci/pci_ids.h | 1 + hw/cxl/cxl-component-utils.c | 18 ++++ hw/cxl/cxl-mailbox-utils.c | 46 ++++++++++ hw/mem/cxl_type3.c | 162 +++++++++++++++++++++++++++++++++++ hw/mem/Kconfig | 5 ++ hw/mem/meson.build | 1 + 8 files changed, 269 insertions(+) create mode 100644 hw/mem/cxl_type3.c
include/hw/cxl/cxl_device.h +15 -0
@@ -230,4 +230,19 @@ REG64(CXL_MEM_DEV_STS, 0) FIELD(CXL_MEM_DEV_STS, MBOX_READY, 4, 1) FIELD(CXL_MEM_DEV_STS, RESET_NEEDED, 5, 3) +struct CXLType3Dev { +/* Private */ +PCIDevice parent_obj; + +/* Properties */ +HostMemoryBackend *hostmem; + +/* State */ +CXLComponentState cxl_cstate; +CXLDeviceState cxl_dstate; +}; + +#define TYPE_CXL_TYPE3 "cxl-type3" +OBJECT_DECLARE_SIMPLE_TYPE(CXLType3Dev, CXL_TYPE3) +#endif
include/hw/cxl/cxl_pci.h +21 -0
@@ -67,6 +67,27 @@ QEMU_BUILD_BUG_ON(sizeof(DVSECHeader) != 10);* CXL 2.0 Downstream Port: 3, 4, 7, 8 */ +/* CXL 2.0 - 8.1.3 (ID 0001) */ +typedef struct CXLDVSECDevice { +DVSECHeader hdr; +uint16_t cap; +uint16_t ctrl; +uint16_t status; +uint16_t ctrl2; +uint16_t status2; +uint16_t lock; +uint16_t cap2; +uint32_t range1_size_hi; +uint32_t range1_size_lo; +uint32_t range1_base_hi; +uint32_t range1_base_lo; +uint32_t range2_size_hi; +uint32_t range2_size_lo; +uint32_t range2_base_hi; +uint32_t range2_base_lo; +}CXLDVSECDevice ; +QEMU_BUILD_BUG_ON (sizeof (CXLDVSECDevice) !=0x38 ); +/* CXL 2.0 - 8.1.5 (ID 0003) */ typedef struct CXLDVSECPortExtensions { DVSECHeader hdr;
include/hw/pci/pci_ids.h +1 -0
@@ -53,6 +53,7 @@#define PCI_BASE_CLASS_MEMORY 0x05#define PCI_CLASS_MEMORY_RAM 0x0500#define PCI_CLASS_MEMORY_FLASH 0x0501 +#define PCI_CLASS_MEMORY_CXL 0x0502#define PCI_CLASS_MEMORY_OTHER 0x0580#define PCI_BASE_CLASS_BRIDGE 0x06
hw/cxl/cxl-component-utils.c +18 -0
@@ -252,6 +252,24 @@ void cxl_component_create_dvsec(CXLComponentState *cxl,/* Configure write masks */ switch (type) {case PCIE_CXL_DEVICE_DVSEC : +/* Cntrl RW Lock - so needs explicit blocking when lock is set */ + wmask[offset + offsetof(CXLDVSECDevice , ctrl)] =0xFD ; + wmask[offset + offsetof(CXLDVSECDevice , ctrl) +1 ] =0x4F ; +/* Status is RW1CS */ + wmask[offset + offsetof(CXLDVSECDevice , ctrl2)] =0x0F ; +/* Lock is RW Once */ + wmask[offset + offsetof(CXLDVSECDevice , lock)] =0x01 ; +/* range1/2_base_high/low is RW Lock */ + wmask[offset + offsetof(CXLDVSECDevice , range1_base_hi)] =0xFF ; + wmask[offset + offsetof(CXLDVSECDevice , range1_base_hi) +1 ] =0xFF ; + wmask[offset + offsetof(CXLDVSECDevice , range1_base_hi) +2 ] =0xFF ; + wmask[offset + offsetof(CXLDVSECDevice , range1_base_hi) +3 ] =0xFF ; + wmask[offset + offsetof(CXLDVSECDevice , range1_base_lo) +3 ] =0xF0 ; + wmask[offset + offsetof(CXLDVSECDevice , range2_base_hi)] =0xFF ; + wmask[offset + offsetof(CXLDVSECDevice , range2_base_hi) +1 ] =0xFF ; + wmask[offset + offsetof(CXLDVSECDevice , range2_base_hi) +2 ] =0xFF ; + wmask[offset + offsetof(CXLDVSECDevice , range2_base_hi) +3 ] =0xFF ; + wmask[offset + offsetof(CXLDVSECDevice , range2_base_lo) +3 ] =0xF0 ;break ;case NON_CXL_FUNCTION_MAP_DVSEC :break ;/* Not yet implemented */
hw/cxl/cxl-mailbox-utils.c +46 -0
64 lines not on this page · raw message
hw/mem/cxl_type3.c new file +162 -0
162 lines not on this page · raw message
hw/mem/Kconfig +5 -0
@@ -11,3 +11,8 @@ config NVDIMM config SPARSE_MEM bool + +config CXL_MEM_DEVICE + bool + default y if CXL + select MEM_DEVICE
hw/mem/meson.build +1 -0
@@ -3,6 +3,7 @@ mem_ss.add(files('memory-device.c')) mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c')) mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c')) mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c')) +mem_ss.add(when: 'CONFIG_CXL_MEM_DEVICE', if_true: files('cxl_type3.c')) softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss)
Signature · 1 line
MST
[PULL v2 38/86] tests/acpi: q35: Allow addition of a CXL test.
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Add exceptions for the DSDT and the new CEDT tables specific to a new CXL test in the following patch.
Message-Id: <[email protected]>
--- tests/qtest/bios-tables-test-allowed-diff.h | 2 ++ tests/data/acpi/q35/CEDT.cxl | 0 tests/data/acpi/q35/DSDT.cxl | 0 3 files changed, 2 insertions(+) create mode 100644 tests/data/acpi/q35/CEDT.cxl create mode 100644 tests/data/acpi/q35/DSDT.cxl
tests/qtest/bios-tables-test-allowed-diff.h +2 -0
@@ -1 +1,3 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/q35/DSDT.cxl" , +"tests/data/acpi/q35/CEDT.cxl",
tests/data/acpi/q35/CEDT.cxl new file +0 -0
tests/data/acpi/q35/DSDT.cxl new file +0 -0
Signature · 1 line
MST
[PULL v2 34/86] mem/cxl_type3: Add read and write functions for associated hostmem.
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Once a read or write reaches a CXL type 3 device, the HDM decoders on the device are used to establish the Device Physical Address which should be accessed. These functions peform the required maths and then use a device specific address space to access the hostmem->mr to fullfil the actual operation. Note that failed writes are silent, but failed reads return poison. Note this is based loosely on:
https://lore.kernel.org/qemu-devel/[email protected]/
[RFC PATCH 0/9] hw/misc: Add support for interleaved memory accesses
Only lightly tested so far. More complex test cases yet to be written.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_device.h | 6 +++ hw/mem/cxl_type3.c | 91 +++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+)
include/hw/cxl/cxl_device.h +6 -0
@@ -239,6 +239,7 @@ struct CXLType3Dev {HostMemoryBackend *lsa;/* State */ +AddressSpace hostmem_as;CXLComponentState cxl_cstate;CXLDeviceState cxl_dstate; };
@@ -259,4 +260,9 @@ struct CXLType3Class { uint64_t offset); }; +MemTxResult cxl_type3_read (PCIDevice *d,hwaddr host_addr,uint64_t *data, +unsigned size,MemTxAttrs attrs); +MemTxResult cxl_type3_write (PCIDevice *d,hwaddr host_addr,uint64_t data, +unsigned size,MemTxAttrs attrs); +#endif
hw/mem/cxl_type3.c +91 -0
110 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 24/86] qtests/cxl: Add initial root port and CXL type3 tests
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
At this stage we can boot configurations with host bridges, root ports and type 3 memory devices, so add appropriate tests.
Message-Id: <[email protected]>
--- tests/qtest/cxl-test.c | 127 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+)
tests/qtest/cxl-test.c +127 -0
@@ -8,15 +8,142 @@#include "qemu/osdep.h" #include "libqtest-single.h" +#define QEMU_PXB_CMD "-machine q35,cxl=on " \ + "-device pxb-cxl,id=cxl.0,bus=pcie.0,bus_nr=52 " + +#define QEMU_2PXB_CMD "-machine q35,cxl=on " \ + "-device pxb-cxl,id=cxl.0,bus=pcie.0,bus_nr=52 " \ + "-device pxb-cxl,id=cxl.1,bus=pcie.0,bus_nr=53 " + +#define QEMU_RP "-device cxl-rp,id=rp0,bus=cxl.0,chassis=0,slot=0 " + +/* Dual ports on first pxb */ +#define QEMU_2RP "-device cxl-rp,id=rp0,bus=cxl.0,chassis=0,slot=0 " \ + "-device cxl-rp,id=rp1,bus=cxl.0,chassis=0,slot=1 " + +/* Dual ports on each of the pxb instances */ +#define QEMU_4RP "-device cxl-rp,id=rp0,bus=cxl.0,chassis=0,slot=0 " \ + "-device cxl-rp,id=rp1,bus=cxl.0,chassis=0,slot=1 " \ + "-device cxl-rp,id=rp2,bus=cxl.1,chassis=0,slot=2 " \ + "-device cxl-rp,id=rp3,bus=cxl.1,chassis=0,slot=3 " + +#define QEMU_T3D "-object memory-backend-file,id=cxl-mem0,mem-path=%s,size=256M " \ + "-object memory-backend-file,id=lsa0,mem-path=%s,size=256M " \ + "-device cxl-type3,bus=rp0,memdev=cxl-mem0,lsa=lsa0,id=cxl-pmem0 " + +#define QEMU_2T3D "-object memory-backend-file,id=cxl-mem0,mem-path=%s,size=256M " \ + "-object memory-backend-file,id=lsa0,mem-path=%s,size=256M " \ + "-device cxl-type3,bus=rp0,memdev=cxl-mem0,lsa=lsa0,id=cxl-pmem0 " \ + "-object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M " \ + "-object memory-backend-file,id=lsa1,mem-path=%s,size=256M " \ + "-device cxl-type3,bus=rp1,memdev=cxl-mem1,lsa=lsa1,id=cxl-pmem1 " + +#define QEMU_4T3D "-object memory-backend-file,id=cxl-mem0,mem-path=%s,size=256M " \ + "-object memory-backend-file,id=lsa0,mem-path=%s,size=256M " \ + "-device cxl-type3,bus=rp0,memdev=cxl-mem0,lsa=lsa0,id=cxl-pmem0 " \ + "-object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M " \ + "-object memory-backend-file,id=lsa1,mem-path=%s,size=256M " \ + "-device cxl-type3,bus=rp1,memdev=cxl-mem1,lsa=lsa1,id=cxl-pmem1 " \ + "-object memory-backend-file,id=cxl-mem2,mem-path=%s,size=256M " \ + "-object memory-backend-file,id=lsa2,mem-path=%s,size=256M " \ + "-device cxl-type3,bus=rp2,memdev=cxl-mem2,lsa=lsa2,id=cxl-pmem2 " \ + "-object memory-backend-file,id=cxl-mem3,mem-path=%s,size=256M " \ + "-object memory-backend-file,id=lsa3,mem-path=%s,size=256M " \ + "-device cxl-type3,bus=rp3,memdev=cxl-mem3,lsa=lsa3,id=cxl-pmem3 " + +static void cxl_basic_hb (void ) +{ +qtest_start ("-machine q35,cxl=on" ); +qtest_end (); +} +static void cxl_basic_pxb (void ) {qtest_start ("-machine q35,cxl=on -device pxb-cxl,bus=pcie.0" );qtest_end (); } +static void cxl_pxb_with_window (void ) +{ +qtest_start (QEMU_PXB_CMD ); +qtest_end (); +} + +static void cxl_2pxb_with_window (void ) +{ +qtest_start (QEMU_2PXB_CMD ); +qtest_end (); +} + +static void cxl_root_port (void ) +{ + qtest_start(QEMU_PXB_CMD QEMU_RP); +qtest_end (); +} + +static void cxl_2root_port (void ) +{ + qtest_start(QEMU_PXB_CMD QEMU_2RP); +qtest_end (); +} + +static void cxl_t3d (void ) +{ +g_autoptr (GString) cmdline =g_string_new (NULL ); +char template[] ="/tmp/cxl-test-XXXXXX" ; +const char *tmpfs; + + tmpfs =mkdtemp (template); + + g_string_printf(cmdline, QEMU_PXB_CMD QEMU_RP QEMU_T3D, tmpfs, tmpfs); + +qtest_start (cmdline->str); +qtest_end (); +} + +static void cxl_1pxb_2rp_2t3d (void ) +{ +g_autoptr (GString) cmdline =g_string_new (NULL ); +char template[] ="/tmp/cxl-test-XXXXXX" ; +const char *tmpfs; + + tmpfs =mkdtemp (template); + + g_string_printf(cmdline, QEMU_PXB_CMD QEMU_2RP QEMU_2T3D, + tmpfs, tmpfs, tmpfs, tmpfs); + +qtest_start (cmdline->str); +qtest_end (); +} + +static void cxl_2pxb_4rp_4t3d (void ) +{ +g_autoptr (GString) cmdline =g_string_new (NULL ); +char template[] ="/tmp/cxl-test-XXXXXX" ; +const char *tmpfs; + + tmpfs =mkdtemp (template); + + g_string_printf(cmdline, QEMU_2PXB_CMD QEMU_4RP QEMU_4T3D, + tmpfs, tmpfs, tmpfs, tmpfs, tmpfs, tmpfs, + tmpfs, tmpfs); + +qtest_start (cmdline->str); +qtest_end (); +} +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL ); + +qtest_add_func ("/pci/cxl/basic_hostbridge" , cxl_basic_hb);qtest_add_func ("/pci/cxl/basic_pxb" , cxl_basic_pxb); +qtest_add_func ("/pci/cxl/pxb_with_window" , cxl_pxb_with_window); +qtest_add_func ("/pci/cxl/pxb_x2_with_window" , cxl_2pxb_with_window); +qtest_add_func ("/pci/cxl/rp" , cxl_root_port); +qtest_add_func ("/pci/cxl/rp_x2" , cxl_2root_port); +qtest_add_func ("/pci/cxl/type3_device" , cxl_t3d); +qtest_add_func ("/pci/cxl/rp_x2_type3_x2" , cxl_1pxb_2rp_2t3d); +qtest_add_func ("/pci/cxl/pxb_x2_root_port_x4_type3_x4" , cxl_2pxb_4rp_4t3d);return g_test_run (); }
Signature · 1 line
MST
[PULL v2 20/86] hw/cxl/device: Implement MMIO HDM decoding (8.2.5.12)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
A device's volatile and persistent memory are known Host Defined Memory (HDM) regions. The mechanism by which the device is programmed to claim the addresses associated with those regions is through dedicated logic known as the HDM decoder. In order to allow the OS to properly program the HDMs, the HDM decoders must be modeled.
There are two ways the HDM decoders can be implemented, the legacy mechanism is through the PCIe DVSEC programming from CXL 1.1 (8.1.3.8), and MMIO is found in 8.2.5.12 of the spec. For now, 8.1.3.8 is not implemented.
Much of CXL device logic is implemented in cxl-utils. The HDM decoder however is implemented directly by the device implementation. Whilst the implementation currently does no validity checks on the encoder set up, future work will add sanity checking specific to the type of cxl component.
Message-Id: <[email protected]>
--- hw/mem/cxl_type3.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
hw/mem/cxl_type3.c +55 -0
@@ -52,6 +52,48 @@ static void build_dvsecs(CXLType3Dev *ct3d) GPF_DEVICE_DVSEC_REVID, dvsec); } +static void hdm_decoder_commit (CXLType3Dev *ct3d,int which) +{ +ComponentRegisters *cregs = &ct3d->cxl_cstate.crb; +uint32_t *cache_mem = cregs->cache_mem_registers; + +assert (which ==0 ); + +/* TODO: Sanity checks that the decoder is possible */ +ARRAY_FIELD_DP32 (cache_mem,CXL_HDM_DECODER0_CTRL ,COMMIT ,0 ); +ARRAY_FIELD_DP32 (cache_mem,CXL_HDM_DECODER0_CTRL ,ERR ,0 ); + +ARRAY_FIELD_DP32 (cache_mem,CXL_HDM_DECODER0_CTRL ,COMMITTED ,1 ); +} + +static void ct3d_reg_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +CXLComponentState *cxl_cstate = opaque; +ComponentRegisters *cregs = &cxl_cstate->crb; +CXLType3Dev *ct3d =container_of (cxl_cstate, CXLType3Dev, cxl_cstate); +uint32_t *cache_mem = cregs->cache_mem_registers; +bool should_commit = false; +int which_hdm =-1 ; + +assert (size ==4 ); +g_assert (offset <CXL2_COMPONENT_CM_REGION_SIZE ); + +switch (offset) { +case A_CXL_HDM_DECODER0_CTRL : + should_commit =FIELD_EX32 (value,CXL_HDM_DECODER0_CTRL ,COMMIT ); + which_hdm =0 ; +break ; +default : +break ; + } + +stl_le_p ((uint8_t *)cache_mem + offset, value); +if (should_commit) { +hdm_decoder_commit (ct3d, which_hdm); + } +} +static bool cxl_setup_memory (CXLType3Dev *ct3d,Error **errp) {MemoryRegion *mr;
@@ -95,6 +137,9 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) ct3d->cxl_cstate.pdev = pci_dev;build_dvsecs (ct3d); + regs->special_ops =g_new0 (MemoryRegionOps,1 ); + regs->special_ops->write = ct3d_reg_write; +cxl_component_register_block_init (OBJECT (pci_dev), cxl_cstate,TYPE_CXL_TYPE3 );
@@ -109,6 +154,15 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) &ct3d->cxl_dstate.device_registers); } +static void ct3_exit (PCIDevice *pci_dev) +{ +CXLType3Dev *ct3d =CXL_TYPE3 (pci_dev); +CXLComponentState *cxl_cstate = &ct3d->cxl_cstate; +ComponentRegisters *regs = &cxl_cstate->crb; + +g_free (regs->special_ops); +} +static void ct3d_reset (DeviceState *dev) {CXLType3Dev *ct3d =CXL_TYPE3 (dev);
@@ -131,6 +185,7 @@ static void ct3_class_init(ObjectClass *oc, void *data)PCIDeviceClass *pc =PCI_DEVICE_CLASS (oc); pc->realize = ct3_realize; + pc->exit = ct3_exit; pc->class_id =PCI_CLASS_STORAGE_EXPRESS ; pc->vendor_id =PCI_VENDOR_ID_INTEL ; pc->device_id =0xd93 ;/* LVF for now */
Signature · 1 line
MST
[PULL v2 43/86] vhost: Track descriptor chain in private at SVQ
In reply to Michael S. TsirkinFrom: Eugenio Pérez <[email protected]>
The device could have access to modify them, and it definitely have access when we implement packed vq. Harden SVQ maintaining a private copy of the descriptor chain. Other fields like buffer addresses are already maintained sepparatedly.
Message-Id: <[email protected]>
--- hw/virtio/vhost-shadow-virtqueue.h | 6 ++++++ hw/virtio/vhost-shadow-virtqueue.c | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-)
hw/virtio/vhost-shadow-virtqueue.h +6 -0
@@ -53,6 +53,12 @@ typedef struct VhostShadowVirtqueue {/* Next VirtQueue element that guest made available */ VirtQueueElement *next_guest_avail_elem; +/* +* Backup next field for each descriptor so we can recover securely, not +* needing to trust the device access. +*/ +uint16_t *desc_next; +/* Next head to expose to the device */ uint16_t shadow_avail_idx;
hw/virtio/vhost-shadow-virtqueue.c +7 -5
@@ -138,6 +138,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,for (n =0 ; n < num; n++) {if (more_descs || (n +1 < num)) { descs[i].flags = flags |cpu_to_le16 (VRING_DESC_F_NEXT ); + descs[i].next =cpu_to_le16 (svq->desc_next[i]); }else { descs[i].flags = flags; }
@@ -145,10 +146,10 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, descs[i].len =cpu_to_le32 (iovec[n].iov_len); last = i; - i =cpu_to_le16 (descs[i].next); + i =cpu_to_le16 (svq->desc_next[i]); } - svq->free_head =le16_to_cpu (descs[last].next); + svq->free_head =le16_to_cpu (svq->desc_next[last]); } static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
@@ -336,7 +337,6 @@ static void vhost_svq_disable_notification(VhostShadowVirtqueue *svq)static VirtQueueElement *vhost_svq_get_buf (VhostShadowVirtqueue *svq,uint32_t *len) { -vring_desc_t *descs = svq->vring.desc;const vring_used_t *used = svq->vring.used;vring_used_elem_t used_elem;uint16_t last_used;
@@ -365,7 +365,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,return NULL ; } - descs[used_elem.id].next = svq->free_head; + svq->desc_next[used_elem.id] = svq->free_head; svq->free_head = used_elem.id; *len = used_elem.len;
@@ -540,8 +540,9 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, svq->vring.used =qemu_memalign (qemu_real_host_page_size (), device_size);memset (svq->vring.used,0 , device_size); svq->ring_id_maps = g_new0(VirtQueueElement *, svq->vring.num); + svq->desc_next =g_new0 (uint16_t, svq->vring.num);for (unsigned i =0 ; i < svq->vring.num -1 ; i++) { - svq->vring.desc[i].next =cpu_to_le16 (i +1 ); + svq->desc_next[i] =cpu_to_le16 (i +1 ); } }
@@ -574,6 +575,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)virtqueue_detach_element (svq->vq, next_avail_elem,0 ); } svq->vq =NULL ; +g_free (svq->desc_next);g_free (svq->ring_id_maps);qemu_vfree (svq->vring.desc);qemu_vfree (svq->vring.used);
Signature · 1 line
MST
[PULL v2 25/86] hw/cxl/component: Implement host bridge MMIO (8.2.5, table 142)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
CXL host bridges themselves may have MMIO. Since host bridges don't have a BAR they are treated as special for MMIO. This patch includes i386/pc support.
Also hook up the device reset now that we have have the MMIO space in which the results are visible.
Note that we duplicate the PCI express case for the aml_build but the implementations will diverge when the CXL specific _OSC is introduced.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl.h | 14 ++++++ hw/i386/acpi-build.c | 25 ++++++++++- hw/i386/pc.c | 27 +++++++++++- hw/pci-bridge/pci_expander_bridge.c | 66 ++++++++++++++++++++++++++--- 4 files changed, 122 insertions(+), 10 deletions(-)
include/hw/cxl/cxl.h +14 -0
@@ -10,6 +10,7 @@#ifndef CXL_H #define CXL_H +#include "hw/pci/pci_host.h" #include "cxl_pci.h" #include "cxl_component.h" #include "cxl_device.h"
@@ -17,8 +18,21 @@#define CXL_COMPONENT_REG_BAR_IDX 0#define CXL_DEVICE_REG_BAR_IDX 2 +#define CXL_WINDOW_MAX 10 +typedef struct CXLState {bool is_enabled; +MemoryRegion host_mr; +unsigned int next_mr_idx; }CXLState ; +struct CXLHost { +PCIHostState parent_obj; + +CXLComponentState cxl_cstate; +}; + +#define TYPE_PXB_CXL_HOST "pxb-cxl-host" +OBJECT_DECLARE_SIMPLE_TYPE(CXLHost, PXB_CXL_HOST) +#endif
hw/i386/acpi-build.c +23 -2
@@ -28,6 +28,7 @@#include "qemu/bitmap.h" #include "qemu/error-report.h" #include "hw/pci/pci.h" +#include "hw/cxl/cxl.h" #include "hw/core/cpu.h" #include "target/i386/cpu.h" #include "hw/misc/pvpanic.h"
@@ -1572,10 +1573,21 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } scope =aml_scope ("\\_SB" ); - dev =aml_device ("PC%.02X" , bus_num); + +if (pci_bus_is_cxl (bus)) { + dev =aml_device ("CL%.02X" , bus_num); + }else { + dev =aml_device ("PC%.02X" , bus_num); + }aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num))); -if (pci_bus_is_express (bus)) { +if (pci_bus_is_cxl (bus)) { +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" ))); +aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" ))); + +/* Expander bridges do not have ACPI PCI Hot-plug enabled */ +aml_append (dev,build_q35_osc_method (true)); + }else if (pci_bus_is_express (bus)) {aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" )));aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" )));
@@ -1595,6 +1607,15 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev);aml_append (dsdt, scope); + +/* Handle the ranges for the PXB expanders */ +if (pci_bus_is_cxl (bus)) { +MemoryRegion *mr = &machine->cxl_devices_state->host_mr; +uint64_t base = mr->addr; + +crs_range_insert (crs_range_set.mem_ranges, base, + base +memory_region_size (mr) -1 ); + } } }
hw/i386/pc.c +26 -1
@@ -75,6 +75,7 @@#include "acpi-build.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" +#include "hw/cxl/cxl.h" #include "qapi/error.h" #include "qapi/qapi-visit-common.h" #include "qapi/qapi-visit-machine.h"
@@ -816,6 +817,7 @@ void pc_memory_init(PCMachineState *pcms,MachineClass *mc =MACHINE_GET_CLASS (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (pcms); +hwaddr cxl_base;assert (machine->ram_size == x86ms->below_4g_mem_size + x86ms->above_4g_mem_size);
@@ -905,6 +907,26 @@ void pc_memory_init(PCMachineState *pcms, &machine->device_memory->mr); } +if (machine->cxl_devices_state->is_enabled) { +MemoryRegion *mr = &machine->cxl_devices_state->host_mr; +hwaddr cxl_size = MiB; + +if (pcmc->has_reserved_memory && machine->device_memory->base) { + cxl_base = machine->device_memory->base; +if (!pcmc->broken_reserved_end) { + cxl_base +=memory_region_size (&machine->device_memory->mr); + } + }else if (pcms->sgx_epc.size !=0 ) { + cxl_base =sgx_epc_above_4g_end (&pcms->sgx_epc); + }else { + cxl_base =0x100000000ULL + x86ms->above_4g_mem_size; + } + +e820_add_entry (cxl_base, cxl_size,E820_RESERVED ); +memory_region_init (mr,OBJECT (machine),"cxl_host_reg" , cxl_size); +memory_region_add_subregion (system_memory, cxl_base, mr); + } +/* Initialize PC system firmware */ pc_system_firmware_init (pcms, rom_memory);
@@ -965,7 +987,10 @@ uint64_t pc_pci_hole64_start(void)X86MachineState *x86ms =X86_MACHINE (pcms);uint64_t hole64_start =0 ; -if (pcmc->has_reserved_memory && ms->device_memory->base) { +if (ms->cxl_devices_state->host_mr.addr) { + hole64_start = ms->cxl_devices_state->host_mr.addr + +memory_region_size (&ms->cxl_devices_state->host_mr); + }else if (pcmc->has_reserved_memory && ms->device_memory->base) { hole64_start = ms->device_memory->base;if (!pcmc->broken_reserved_end) { hole64_start +=memory_region_size (&ms->device_memory->mr);
hw/pci-bridge/pci_expander_bridge.c +59 -7
107 lines not on this page · raw message
Signature · 1 line
MST
Re: [PULL v2 25/86] hw/cxl/component: Implement host bridge MMIO (8.2.5, table 142)
Quoted 135 lines · On Mon, 16 May 2022 16:51:34 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
From: Ben Widawsky <[email protected]>
CXL host bridges themselves may have MMIO. Since host bridges don't have a BAR they are treated as special for MMIO. This patch includes i386/pc support.
Also hook up the device reset now that we have have the MMIO space in which the results are visible.Note that we duplicate the PCI express case for the
aml_buildbut the implementations will diverge when the CXL specific_OSCis introduced.Signed-off-by Ben Widawsky <[email protected]>Co-developed-by Jonathan Cameron <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Reviewed-by Alex Bennée <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/cxl/cxl.h | 14 ++++++ hw/i386/acpi-build.c | 25 ++++++++++- hw/i386/pc.c | 27 +++++++++++- hw/pci-bridge/pci_expander_bridge.c | 66 ++++++++++++++++++++++++++--- 4 files changed, 122 insertions(+), 10 deletions(-)include/hw/cxl/cxl.h +14
-0@@ -10,6 +10,7 @@#ifndef CXL_H #define CXL_H +#include "hw/pci/pci_host.h" #include "cxl_pci.h" #include "cxl_component.h" #include "cxl_device.h" @@ -17,8 +18,21 @@#define CXL_COMPONENT_REG_BAR_IDX 0#define CXL_DEVICE_REG_BAR_IDX 2 +#define CXL_WINDOW_MAX 10 +typedef struct CXLState {bool is_enabled; +MemoryRegion host_mr; +unsigned int next_mr_idx; }CXLState ; +struct CXLHost { +PCIHostState parent_obj; + +CXLComponentState cxl_cstate; +}; + +#define TYPE_PXB_CXL_HOST "pxb-cxl-host" +OBJECT_DECLARE_SIMPLE_TYPE(CXLHost, PXB_CXL_HOST) +#endif hw/i386/acpi-build.c +23
-2@@ -28,6 +28,7 @@#include "qemu/bitmap.h" #include "qemu/error-report.h" #include "hw/pci/pci.h" +#include "hw/cxl/cxl.h" #include "hw/core/cpu.h" #include "target/i386/cpu.h" #include "hw/misc/pvpanic.h" @@ -1572,10 +1573,21 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } scope =aml_scope ("\\_SB" ); - dev =aml_device ("PC%.02X" , bus_num); + +if (pci_bus_is_cxl (bus)) { + dev =aml_device ("CL%.02X" , bus_num); + }else { + dev =aml_device ("PC%.02X" , bus_num); + }aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num))); -if (pci_bus_is_express (bus)) { +if (pci_bus_is_cxl (bus)) { +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" ))); +aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" ))); + +/* Expander bridges do not have ACPI PCI Hot-plug enabled */ +aml_append (dev,build_q35_osc_method (true)); + }else if (pci_bus_is_express (bus)) {aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" )));aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" )));@@ -1595,6 +1607,15 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev);aml_append (dsdt, scope); + +/* Handle the ranges for the PXB expanders */ +if (pci_bus_is_cxl (bus)) { +MemoryRegion *mr = &machine->cxl_devices_state->host_mr; +uint64_t base = mr->addr; + +crs_range_insert (crs_range_set.mem_ranges, base, + base +memory_region_size (mr) -1 ); + } } }hw/i386/pc.c +2
-0@@ -75,6 +75,7 @@#include "acpi-build.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" +#include "hw/cxl/cxl.h" #include "qapi/error.h" #include "qapi/qapi-visit-common.h" #include "qapi/qapi-visit-machine.h" @@ -816,6 +817,7 @@ void pc_memory_init(PCMachineState *pcms,MachineClass *mc =MACHINE_GET_CLASS (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (pcms); +hwaddr cxl_base;assert (machine->ram_size == x86ms->below_4g_mem_size + x86ms->above_4g_mem_size);@@ -905,6 +907,26 @@ void pc_memory_init(PCMachineState *pcms, &machine->device_memory->mr); }
hw/i386/pc.c void pc_memory_init(PCMachineState *pcms, · line 918
Quoted 10 lines
hw/i386/pc.c +9
-0+if (machine->cxl_devices_state->is_enabled) { +MemoryRegion *mr = &machine->cxl_devices_state->host_mr; +hwaddr cxl_size = MiB; + +if (pcmc->has_reserved_memory && machine->device_memory->base) { + cxl_base = machine->device_memory->base; +if (!pcmc->broken_reserved_end) { + cxl_base +=memory_region_size (&machine->device_memory->mr); + }
while reviewing 1Tb hole patches, I've stumbled onto this
it looks wrong to ignore device_memory size here as RAM is/might still be mapped there and guest can try to use it as RAM and then as CXL MMIO or other way around. Most likely nothing good will come out of it, suggest make it unconditional and always put cxl_base _after_ actual device_memory
Quoted 143 lines
hw/i386/pc.c +15
-1+ }else if (pcms->sgx_epc.size !=0 ) { + cxl_base =sgx_epc_above_4g_end (&pcms->sgx_epc); + }else { + cxl_base =0x100000000ULL + x86ms->above_4g_mem_size; + } + +e820_add_entry (cxl_base, cxl_size,E820_RESERVED ); +memory_region_init (mr,OBJECT (machine),"cxl_host_reg" , cxl_size); +memory_region_add_subregion (system_memory, cxl_base, mr); + } +/* Initialize PC system firmware */ pc_system_firmware_init (pcms, rom_memory);@@ -965,7 +987,10 @@ uint64_t pc_pci_hole64_start(void)X86MachineState *x86ms =X86_MACHINE (pcms);uint64_t hole64_start =0 ; -if (pcmc->has_reserved_memory && ms->device_memory->base) { +if (ms->cxl_devices_state->host_mr.addr) { + hole64_start = ms->cxl_devices_state->host_mr.addr + +memory_region_size (&ms->cxl_devices_state->host_mr); + }else if (pcmc->has_reserved_memory && ms->device_memory->base) { hole64_start = ms->device_memory->base;if (!pcmc->broken_reserved_end) { hole64_start +=memory_region_size (&ms->device_memory->mr);hw/pci-bridge/pci_expander_bridge.c +59
-7@@ -61,12 +61,6 @@ DECLARE_INSTANCE_CHECKER(PXBDev, PXB_PCIE_DEV,DECLARE_INSTANCE_CHECKER (PXBDev,PXB_CXL_DEV , TYPE_PXB_CXL_DEVICE) -typedef struct CXLHost { -PCIHostState parent_obj; - -CXLComponentState cxl_cstate; -}CXLHost ; -struct PXBDev {/*< private >*/ PCIDevice parent_obj;@@ -75,6 +69,9 @@ struct PXBDev {uint8_t bus_nr;uint16_t numa_node;bool bypass_iommu; +struct cxl_dev { +CXLHost *cxl_host_bridge; + } cxl; };static PXBDev *convert_to_pxb (PCIDevice *dev)@@ -197,6 +194,52 @@ static const TypeInfo pxb_host_info = { .class_init = pxb_host_class_init, }; +static void pxb_cxl_realize (DeviceState *dev,Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +CXLHost *cxl =PXB_CXL_HOST (dev); +CXLComponentState *cxl_cstate = &cxl->cxl_cstate; +struct MemoryRegion *mr = &cxl_cstate->crb.component_registers; +hwaddr offset; + +cxl_component_register_block_init (OBJECT (dev), cxl_cstate, +TYPE_PXB_CXL_HOST ); +sysbus_init_mmio (sbd, mr); + + offset =memory_region_size (mr) * ms->cxl_devices_state->next_mr_idx; +if (offset >memory_region_size (&ms->cxl_devices_state->host_mr)) { +error_setg (errp,"Insufficient space for pxb cxl host register space" ); +return ; + } + +memory_region_add_subregion (&ms->cxl_devices_state->host_mr, offset, mr); + ms->cxl_devices_state->next_mr_idx++; +} + +static void pxb_cxl_host_class_init (ObjectClass *class,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (class); +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (class); + + hc->root_bus_path = pxb_host_root_bus_path; + dc->fw_name ="cxl" ; + dc->realize = pxb_cxl_realize; +/* Reason: Internal part of the pxb/pxb-pcie device, not usable by itself */ + dc->user_creatable = false; +} + +/* +* This is a device to handle the MMIO for a CXL host bridge. It does nothing +* else. +*/ +static const TypeInfo cxl_host_info = { + .name =TYPE_PXB_CXL_HOST , + .parent =TYPE_PCI_HOST_BRIDGE , + .instance_size =sizeof (CXLHost), + .class_init = pxb_cxl_host_class_init, +}; +/* * Registers the PXB bus as a child of pci host root bus. */ @@ -245,6 +288,13 @@ static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)static void pxb_dev_reset (DeviceState *dev) { +CXLHost *cxl =PXB_CXL_DEV (dev)->cxl.cxl_host_bridge; +CXLComponentState *cxl_cstate = &cxl->cxl_cstate; +uint32_t *reg_state = cxl_cstate->crb.cache_mem_registers; +uint32_t *write_msk = cxl_cstate->crb.cache_mem_regs_write_mask; + +cxl_component_register_init_common (reg_state, write_msk,CXL2_ROOT_PORT ); +ARRAY_FIELD_DP32 (reg_state,CXL_HDM_DECODER_CAPABILITY ,TARGET_COUNT ,8 ); }static gint pxb_compare (gconstpointer a,gconstpointer b)@@ -281,12 +331,13 @@ static void pxb_dev_realize_common(PCIDevice *dev, enum BusType type, dev_name = dev->qdev.id; } - ds =qdev_new (TYPE_PXB_HOST ); + ds =qdev_new (type ==CXL ?TYPE_PXB_CXL_HOST :TYPE_PXB_HOST );if (type ==PCIE ) { bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_PCIE_BUS ); }else if (type ==CXL ) { bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_CXL_BUS ); bus->flags |=PCI_BUS_CXL ; +PXB_CXL_DEV (dev)->cxl.cxl_host_bridge =PXB_CXL_HOST (ds); }else { bus =pci_root_bus_new (ds,"pxb-internal" ,NULL ,NULL ,0 ,TYPE_PXB_BUS ); bds =qdev_new ("pci-bridge" );@@ -475,6 +526,7 @@ static void pxb_register_types(void)type_register_static (&pxb_pcie_bus_info);type_register_static (&pxb_cxl_bus_info);type_register_static (&pxb_host_info); +type_register_static (&cxl_host_info);type_register_static (&pxb_dev_info);type_register_static (&pxb_pcie_dev_info);type_register_static (&pxb_cxl_dev_info);
Re: [PULL v2 25/86] hw/cxl/component: Implement host bridge MMIO (8.2.5, table 142)
Quoted 139 lines · On Thu, 16 Jun 2022 16:45:00 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 136 lines · On Mon, 16 May 2022 16:51:34 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
From: Ben Widawsky <[email protected]>
CXL host bridges themselves may have MMIO. Since host bridges don't have a BAR they are treated as special for MMIO. This patch includes i386/pc support.
Also hook up the device reset now that we have have the MMIO space in which the results are visible.Note that we duplicate the PCI express case for the
aml_buildbut the implementations will diverge when the CXL specific_OSCis introduced.Signed-off-by Ben Widawsky <[email protected]>Co-developed-by Jonathan Cameron <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Reviewed-by Alex Bennée <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/cxl/cxl.h | 14 ++++++ hw/i386/acpi-build.c | 25 ++++++++++- hw/i386/pc.c | 27 +++++++++++- hw/pci-bridge/pci_expander_bridge.c | 66 ++++++++++++++++++++++++++--- 4 files changed, 122 insertions(+), 10 deletions(-)include/hw/cxl/cxl.h +14
-0@@ -10,6 +10,7 @@#ifndef CXL_H #define CXL_H +#include "hw/pci/pci_host.h" #include "cxl_pci.h" #include "cxl_component.h" #include "cxl_device.h" @@ -17,8 +18,21 @@#define CXL_COMPONENT_REG_BAR_IDX 0#define CXL_DEVICE_REG_BAR_IDX 2 +#define CXL_WINDOW_MAX 10 +typedef struct CXLState {bool is_enabled; +MemoryRegion host_mr; +unsigned int next_mr_idx; }CXLState ; +struct CXLHost { +PCIHostState parent_obj; + +CXLComponentState cxl_cstate; +}; + +#define TYPE_PXB_CXL_HOST "pxb-cxl-host" +OBJECT_DECLARE_SIMPLE_TYPE(CXLHost, PXB_CXL_HOST) +#endif hw/i386/acpi-build.c +23
-2@@ -28,6 +28,7 @@#include "qemu/bitmap.h" #include "qemu/error-report.h" #include "hw/pci/pci.h" +#include "hw/cxl/cxl.h" #include "hw/core/cpu.h" #include "target/i386/cpu.h" #include "hw/misc/pvpanic.h" @@ -1572,10 +1573,21 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } scope =aml_scope ("\\_SB" ); - dev =aml_device ("PC%.02X" , bus_num); + +if (pci_bus_is_cxl (bus)) { + dev =aml_device ("CL%.02X" , bus_num); + }else { + dev =aml_device ("PC%.02X" , bus_num); + }aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num))); -if (pci_bus_is_express (bus)) { +if (pci_bus_is_cxl (bus)) { +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" ))); +aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" ))); + +/* Expander bridges do not have ACPI PCI Hot-plug enabled */ +aml_append (dev,build_q35_osc_method (true)); + }else if (pci_bus_is_express (bus)) {aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" )));aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" )));@@ -1595,6 +1607,15 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev);aml_append (dsdt, scope); + +/* Handle the ranges for the PXB expanders */ +if (pci_bus_is_cxl (bus)) { +MemoryRegion *mr = &machine->cxl_devices_state->host_mr; +uint64_t base = mr->addr; + +crs_range_insert (crs_range_set.mem_ranges, base, + base +memory_region_size (mr) -1 ); + } } }hw/i386/pc.c +2
-0@@ -75,6 +75,7 @@#include "acpi-build.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" +#include "hw/cxl/cxl.h" #include "qapi/error.h" #include "qapi/qapi-visit-common.h" #include "qapi/qapi-visit-machine.h" @@ -816,6 +817,7 @@ void pc_memory_init(PCMachineState *pcms,MachineClass *mc =MACHINE_GET_CLASS (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (pcms); +hwaddr cxl_base;assert (machine->ram_size == x86ms->below_4g_mem_size + x86ms->above_4g_mem_size);@@ -905,6 +907,26 @@ void pc_memory_init(PCMachineState *pcms, &machine->device_memory->mr); }
Quoted 15 lines
hw/i386/pc.c void pc_memory_init(PCMachineState *pcms, · line 918
Quoted 9 lines
hw/i386/pc.c +9
-0+if (machine->cxl_devices_state->is_enabled) { +MemoryRegion *mr = &machine->cxl_devices_state->host_mr; +hwaddr cxl_size = MiB; + +if (pcmc->has_reserved_memory && machine->device_memory->base) { + cxl_base = machine->device_memory->base; +if (!pcmc->broken_reserved_end) { + cxl_base +=memory_region_size (&machine->device_memory->mr); + }while reviewing 1Tb hole patches, I've stumbled onto this
it looks wrong to ignoredevice_memorysize here as RAM is/might still be mapped there and guest can try to use it as RAM and then as CXL MMIO or other way around. Most likely nothing good will come out of it, suggest make it unconditional and always putcxl_base_after_ actualdevice_memory
Ah. I didn't fully understand the broken_reserved_end handling.
Just to check I understand correctly are you suggesting.
if (pcmc->has_reserved_memory && machine->device_memory->base) {
cxl_base = machine->device_memory->base +
memory_region_size(&machine->device_memory->mr);
} else if (pcms->sgx_epc.size != 0) {...
?
Thanks,
Jonathan
Quoted 146 lines
Quoted 145 lines
hw/i386/pc.c +15
-1+ }else if (pcms->sgx_epc.size !=0 ) { + cxl_base =sgx_epc_above_4g_end (&pcms->sgx_epc); + }else { + cxl_base =0x100000000ULL + x86ms->above_4g_mem_size; + } + +e820_add_entry (cxl_base, cxl_size,E820_RESERVED ); +memory_region_init (mr,OBJECT (machine),"cxl_host_reg" , cxl_size); +memory_region_add_subregion (system_memory, cxl_base, mr); + } +/* Initialize PC system firmware */ pc_system_firmware_init (pcms, rom_memory);@@ -965,7 +987,10 @@ uint64_t pc_pci_hole64_start(void)X86MachineState *x86ms =X86_MACHINE (pcms);uint64_t hole64_start =0 ; -if (pcmc->has_reserved_memory && ms->device_memory->base) { +if (ms->cxl_devices_state->host_mr.addr) { + hole64_start = ms->cxl_devices_state->host_mr.addr + +memory_region_size (&ms->cxl_devices_state->host_mr); + }else if (pcmc->has_reserved_memory && ms->device_memory->base) { hole64_start = ms->device_memory->base;if (!pcmc->broken_reserved_end) { hole64_start +=memory_region_size (&ms->device_memory->mr);hw/pci-bridge/pci_expander_bridge.c +59
-7@@ -61,12 +61,6 @@ DECLARE_INSTANCE_CHECKER(PXBDev, PXB_PCIE_DEV,DECLARE_INSTANCE_CHECKER (PXBDev,PXB_CXL_DEV , TYPE_PXB_CXL_DEVICE) -typedef struct CXLHost { -PCIHostState parent_obj; - -CXLComponentState cxl_cstate; -}CXLHost ; -struct PXBDev {/*< private >*/ PCIDevice parent_obj;@@ -75,6 +69,9 @@ struct PXBDev {uint8_t bus_nr;uint16_t numa_node;bool bypass_iommu; +struct cxl_dev { +CXLHost *cxl_host_bridge; + } cxl; };static PXBDev *convert_to_pxb (PCIDevice *dev)@@ -197,6 +194,52 @@ static const TypeInfo pxb_host_info = { .class_init = pxb_host_class_init, }; +static void pxb_cxl_realize (DeviceState *dev,Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +CXLHost *cxl =PXB_CXL_HOST (dev); +CXLComponentState *cxl_cstate = &cxl->cxl_cstate; +struct MemoryRegion *mr = &cxl_cstate->crb.component_registers; +hwaddr offset; + +cxl_component_register_block_init (OBJECT (dev), cxl_cstate, +TYPE_PXB_CXL_HOST ); +sysbus_init_mmio (sbd, mr); + + offset =memory_region_size (mr) * ms->cxl_devices_state->next_mr_idx; +if (offset >memory_region_size (&ms->cxl_devices_state->host_mr)) { +error_setg (errp,"Insufficient space for pxb cxl host register space" ); +return ; + } + +memory_region_add_subregion (&ms->cxl_devices_state->host_mr, offset, mr); + ms->cxl_devices_state->next_mr_idx++; +} + +static void pxb_cxl_host_class_init (ObjectClass *class,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (class); +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (class); + + hc->root_bus_path = pxb_host_root_bus_path; + dc->fw_name ="cxl" ; + dc->realize = pxb_cxl_realize; +/* Reason: Internal part of the pxb/pxb-pcie device, not usable by itself */ + dc->user_creatable = false; +} + +/* +* This is a device to handle the MMIO for a CXL host bridge. It does nothing +* else. +*/ +static const TypeInfo cxl_host_info = { + .name =TYPE_PXB_CXL_HOST , + .parent =TYPE_PCI_HOST_BRIDGE , + .instance_size =sizeof (CXLHost), + .class_init = pxb_cxl_host_class_init, +}; +/* * Registers the PXB bus as a child of pci host root bus. */ @@ -245,6 +288,13 @@ static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)static void pxb_dev_reset (DeviceState *dev) { +CXLHost *cxl =PXB_CXL_DEV (dev)->cxl.cxl_host_bridge; +CXLComponentState *cxl_cstate = &cxl->cxl_cstate; +uint32_t *reg_state = cxl_cstate->crb.cache_mem_registers; +uint32_t *write_msk = cxl_cstate->crb.cache_mem_regs_write_mask; + +cxl_component_register_init_common (reg_state, write_msk,CXL2_ROOT_PORT ); +ARRAY_FIELD_DP32 (reg_state,CXL_HDM_DECODER_CAPABILITY ,TARGET_COUNT ,8 ); }static gint pxb_compare (gconstpointer a,gconstpointer b)@@ -281,12 +331,13 @@ static void pxb_dev_realize_common(PCIDevice *dev, enum BusType type, dev_name = dev->qdev.id; } - ds =qdev_new (TYPE_PXB_HOST ); + ds =qdev_new (type ==CXL ?TYPE_PXB_CXL_HOST :TYPE_PXB_HOST );if (type ==PCIE ) { bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_PCIE_BUS ); }else if (type ==CXL ) { bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_CXL_BUS ); bus->flags |=PCI_BUS_CXL ; +PXB_CXL_DEV (dev)->cxl.cxl_host_bridge =PXB_CXL_HOST (ds); }else { bus =pci_root_bus_new (ds,"pxb-internal" ,NULL ,NULL ,0 ,TYPE_PXB_BUS ); bds =qdev_new ("pci-bridge" );@@ -475,6 +526,7 @@ static void pxb_register_types(void)type_register_static (&pxb_pcie_bus_info);type_register_static (&pxb_cxl_bus_info);type_register_static (&pxb_host_info); +type_register_static (&cxl_host_info);type_register_static (&pxb_dev_info);type_register_static (&pxb_pcie_dev_info);type_register_static (&pxb_cxl_dev_info);
Re: [PULL v2 25/86] hw/cxl/component: Implement host bridge MMIO (8.2.5, table 142)
Quoted 160 lines · On Fri, 17 Jun 2022 11:51:44 +0100 Jonathan Cameron…
Quoted 139 lines · On Thu, 16 Jun 2022 16:45:00 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 136 lines · On Mon, 16 May 2022 16:51:34 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
From: Ben Widawsky <[email protected]>
CXL host bridges themselves may have MMIO. Since host bridges don't have a BAR they are treated as special for MMIO. This patch includes i386/pc support.
Also hook up the device reset now that we have have the MMIO space in which the results are visible.Note that we duplicate the PCI express case for the
aml_buildbut the implementations will diverge when the CXL specific_OSCis introduced.Signed-off-by Ben Widawsky <[email protected]>Co-developed-by Jonathan Cameron <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Reviewed-by Alex Bennée <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/cxl/cxl.h | 14 ++++++ hw/i386/acpi-build.c | 25 ++++++++++- hw/i386/pc.c | 27 +++++++++++- hw/pci-bridge/pci_expander_bridge.c | 66 ++++++++++++++++++++++++++--- 4 files changed, 122 insertions(+), 10 deletions(-)include/hw/cxl/cxl.h +14
-0@@ -10,6 +10,7 @@#ifndef CXL_H #define CXL_H +#include "hw/pci/pci_host.h" #include "cxl_pci.h" #include "cxl_component.h" #include "cxl_device.h" @@ -17,8 +18,21 @@#define CXL_COMPONENT_REG_BAR_IDX 0#define CXL_DEVICE_REG_BAR_IDX 2 +#define CXL_WINDOW_MAX 10 +typedef struct CXLState {bool is_enabled; +MemoryRegion host_mr; +unsigned int next_mr_idx; }CXLState ; +struct CXLHost { +PCIHostState parent_obj; + +CXLComponentState cxl_cstate; +}; + +#define TYPE_PXB_CXL_HOST "pxb-cxl-host" +OBJECT_DECLARE_SIMPLE_TYPE(CXLHost, PXB_CXL_HOST) +#endif hw/i386/acpi-build.c +23
-2@@ -28,6 +28,7 @@#include "qemu/bitmap.h" #include "qemu/error-report.h" #include "hw/pci/pci.h" +#include "hw/cxl/cxl.h" #include "hw/core/cpu.h" #include "target/i386/cpu.h" #include "hw/misc/pvpanic.h" @@ -1572,10 +1573,21 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } scope =aml_scope ("\\_SB" ); - dev =aml_device ("PC%.02X" , bus_num); + +if (pci_bus_is_cxl (bus)) { + dev =aml_device ("CL%.02X" , bus_num); + }else { + dev =aml_device ("PC%.02X" , bus_num); + }aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num))); -if (pci_bus_is_express (bus)) { +if (pci_bus_is_cxl (bus)) { +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" ))); +aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" ))); + +/* Expander bridges do not have ACPI PCI Hot-plug enabled */ +aml_append (dev,build_q35_osc_method (true)); + }else if (pci_bus_is_express (bus)) {aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" )));aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" )));@@ -1595,6 +1607,15 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev);aml_append (dsdt, scope); + +/* Handle the ranges for the PXB expanders */ +if (pci_bus_is_cxl (bus)) { +MemoryRegion *mr = &machine->cxl_devices_state->host_mr; +uint64_t base = mr->addr; + +crs_range_insert (crs_range_set.mem_ranges, base, + base +memory_region_size (mr) -1 ); + } } }hw/i386/pc.c +2
-0@@ -75,6 +75,7 @@#include "acpi-build.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" +#include "hw/cxl/cxl.h" #include "qapi/error.h" #include "qapi/qapi-visit-common.h" #include "qapi/qapi-visit-machine.h" @@ -816,6 +817,7 @@ void pc_memory_init(PCMachineState *pcms,MachineClass *mc =MACHINE_GET_CLASS (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (pcms); +hwaddr cxl_base;assert (machine->ram_size == x86ms->below_4g_mem_size + x86ms->above_4g_mem_size);@@ -905,6 +907,26 @@ void pc_memory_init(PCMachineState *pcms, &machine->device_memory->mr); }Quoted 15 lines
hw/i386/pc.c void pc_memory_init(PCMachineState *pcms, · line 918
Quoted 9 lines
hw/i386/pc.c +9
-0+if (machine->cxl_devices_state->is_enabled) { +MemoryRegion *mr = &machine->cxl_devices_state->host_mr; +hwaddr cxl_size = MiB; + +if (pcmc->has_reserved_memory && machine->device_memory->base) { + cxl_base = machine->device_memory->base; +if (!pcmc->broken_reserved_end) { + cxl_base +=memory_region_size (&machine->device_memory->mr); + }while reviewing 1Tb hole patches, I've stumbled onto this
it looks wrong to ignoredevice_memorysize here as RAM is/might still be mapped there and guest can try to use it as RAM and then as CXL MMIO or other way around. Most likely nothing good will come out of it, suggest make it unconditional and always putcxl_base_after_ actualdevice_memoryAh. I didn't fully understand the
broken_reserved_endhandling.
Quoted 7 lines
Just to check I understand correctly are you suggesting.
if (pcmc->has_reserved_memory && machine->device_memory->base) { cxl_base = machine->device_memory->base + memory_region_size(&machine->device_memory->mr); } else if (pcms->sgx_epc.size != 0) {...
yep, something like this
(fix should be ready and go into qemu-7.1 as it regresses access to RAM and would change memory layout)
Quoted 155 lines
?
Thanks,
Jonathan
Quoted 146 lines
Quoted 145 lines
hw/i386/pc.c +15
-1+ }else if (pcms->sgx_epc.size !=0 ) { + cxl_base =sgx_epc_above_4g_end (&pcms->sgx_epc); + }else { + cxl_base =0x100000000ULL + x86ms->above_4g_mem_size; + } + +e820_add_entry (cxl_base, cxl_size,E820_RESERVED ); +memory_region_init (mr,OBJECT (machine),"cxl_host_reg" , cxl_size); +memory_region_add_subregion (system_memory, cxl_base, mr); + } +/* Initialize PC system firmware */ pc_system_firmware_init (pcms, rom_memory);@@ -965,7 +987,10 @@ uint64_t pc_pci_hole64_start(void)X86MachineState *x86ms =X86_MACHINE (pcms);uint64_t hole64_start =0 ; -if (pcmc->has_reserved_memory && ms->device_memory->base) { +if (ms->cxl_devices_state->host_mr.addr) { + hole64_start = ms->cxl_devices_state->host_mr.addr + +memory_region_size (&ms->cxl_devices_state->host_mr); + }else if (pcmc->has_reserved_memory && ms->device_memory->base) { hole64_start = ms->device_memory->base;if (!pcmc->broken_reserved_end) { hole64_start +=memory_region_size (&ms->device_memory->mr);hw/pci-bridge/pci_expander_bridge.c +59
-7@@ -61,12 +61,6 @@ DECLARE_INSTANCE_CHECKER(PXBDev, PXB_PCIE_DEV,DECLARE_INSTANCE_CHECKER (PXBDev,PXB_CXL_DEV , TYPE_PXB_CXL_DEVICE) -typedef struct CXLHost { -PCIHostState parent_obj; - -CXLComponentState cxl_cstate; -}CXLHost ; -struct PXBDev {/*< private >*/ PCIDevice parent_obj;@@ -75,6 +69,9 @@ struct PXBDev {uint8_t bus_nr;uint16_t numa_node;bool bypass_iommu; +struct cxl_dev { +CXLHost *cxl_host_bridge; + } cxl; };static PXBDev *convert_to_pxb (PCIDevice *dev)@@ -197,6 +194,52 @@ static const TypeInfo pxb_host_info = { .class_init = pxb_host_class_init, }; +static void pxb_cxl_realize (DeviceState *dev,Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +CXLHost *cxl =PXB_CXL_HOST (dev); +CXLComponentState *cxl_cstate = &cxl->cxl_cstate; +struct MemoryRegion *mr = &cxl_cstate->crb.component_registers; +hwaddr offset; + +cxl_component_register_block_init (OBJECT (dev), cxl_cstate, +TYPE_PXB_CXL_HOST ); +sysbus_init_mmio (sbd, mr); + + offset =memory_region_size (mr) * ms->cxl_devices_state->next_mr_idx; +if (offset >memory_region_size (&ms->cxl_devices_state->host_mr)) { +error_setg (errp,"Insufficient space for pxb cxl host register space" ); +return ; + } + +memory_region_add_subregion (&ms->cxl_devices_state->host_mr, offset, mr); + ms->cxl_devices_state->next_mr_idx++; +} + +static void pxb_cxl_host_class_init (ObjectClass *class,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (class); +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (class); + + hc->root_bus_path = pxb_host_root_bus_path; + dc->fw_name ="cxl" ; + dc->realize = pxb_cxl_realize; +/* Reason: Internal part of the pxb/pxb-pcie device, not usable by itself */ + dc->user_creatable = false; +} + +/* +* This is a device to handle the MMIO for a CXL host bridge. It does nothing +* else. +*/ +static const TypeInfo cxl_host_info = { + .name =TYPE_PXB_CXL_HOST , + .parent =TYPE_PCI_HOST_BRIDGE , + .instance_size =sizeof (CXLHost), + .class_init = pxb_cxl_host_class_init, +}; +/* * Registers the PXB bus as a child of pci host root bus. */ @@ -245,6 +288,13 @@ static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)static void pxb_dev_reset (DeviceState *dev) { +CXLHost *cxl =PXB_CXL_DEV (dev)->cxl.cxl_host_bridge; +CXLComponentState *cxl_cstate = &cxl->cxl_cstate; +uint32_t *reg_state = cxl_cstate->crb.cache_mem_registers; +uint32_t *write_msk = cxl_cstate->crb.cache_mem_regs_write_mask; + +cxl_component_register_init_common (reg_state, write_msk,CXL2_ROOT_PORT ); +ARRAY_FIELD_DP32 (reg_state,CXL_HDM_DECODER_CAPABILITY ,TARGET_COUNT ,8 ); }static gint pxb_compare (gconstpointer a,gconstpointer b)@@ -281,12 +331,13 @@ static void pxb_dev_realize_common(PCIDevice *dev, enum BusType type, dev_name = dev->qdev.id; } - ds =qdev_new (TYPE_PXB_HOST ); + ds =qdev_new (type ==CXL ?TYPE_PXB_CXL_HOST :TYPE_PXB_HOST );if (type ==PCIE ) { bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_PCIE_BUS ); }else if (type ==CXL ) { bus =pci_root_bus_new (ds, dev_name,NULL ,NULL ,0 ,TYPE_PXB_CXL_BUS ); bus->flags |=PCI_BUS_CXL ; +PXB_CXL_DEV (dev)->cxl.cxl_host_bridge =PXB_CXL_HOST (ds); }else { bus =pci_root_bus_new (ds,"pxb-internal" ,NULL ,NULL ,0 ,TYPE_PXB_BUS ); bds =qdev_new ("pci-bridge" );@@ -475,6 +526,7 @@ static void pxb_register_types(void)type_register_static (&pxb_pcie_bus_info);type_register_static (&pxb_cxl_bus_info);type_register_static (&pxb_host_info); +type_register_static (&cxl_host_info);type_register_static (&pxb_dev_info);type_register_static (&pxb_pcie_dev_info);type_register_static (&pxb_cxl_dev_info);
[PULL v2 44/86] vhost: Fix device's used descriptor dequeue
In reply to Michael S. TsirkinFrom: Eugenio Pérez <[email protected]>
Only the first one of them were properly enqueued back.
Message-Id: <[email protected]>
--- hw/virtio/vhost-shadow-virtqueue.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
hw/virtio/vhost-shadow-virtqueue.c +15 -2
@@ -334,12 +334,22 @@ static void vhost_svq_disable_notification(VhostShadowVirtqueue *svq) svq->vring.avail->flags |=cpu_to_le16 (VRING_AVAIL_F_NO_INTERRUPT ); } +static uint16_t vhost_svq_last_desc_of_chain (const VhostShadowVirtqueue *svq, +uint16_t num,uint16_t i) +{ +for (uint16_t j =0 ; j < (num -1 ); ++j) { + i =le16_to_cpu (svq->desc_next[i]); + } + +return i; +} +static VirtQueueElement *vhost_svq_get_buf (VhostShadowVirtqueue *svq,uint32_t *len) {const vring_used_t *used = svq->vring.used;vring_used_elem_t used_elem; -uint16_t last_used; +uint16_t last_used, last_used_chain, num;if (!vhost_svq_more_used (svq)) {return NULL ;
@@ -365,7 +375,10 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,return NULL ; } - svq->desc_next[used_elem.id] = svq->free_head; + num = svq->ring_id_maps[used_elem.id]->in_num + + svq->ring_id_maps[used_elem.id]->out_num; + last_used_chain =vhost_svq_last_desc_of_chain (svq, num, used_elem.id); + svq->desc_next[last_used_chain] = svq->free_head; svq->free_head = used_elem.id; *len = used_elem.len;
Signature · 1 line
MST
[PULL v2 46/86] vdpa: Fix index calculus at vhost_vdpa_svqs_start
In reply to Michael S. TsirkinFrom: Eugenio Pérez <[email protected]>
With the introduction of MQ the index of the vq needs to be calculated with the device model vq_index.
Message-Id: <[email protected]>
--- hw/virtio/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +1 -1
@@ -1018,7 +1018,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev)VirtQueue *vq =virtio_get_queue (dev->vdev, dev->vq_index + i);VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, i);struct vhost_vring_addr addr = { - .index = i, + .index = dev->vq_index + i, };int r;bool ok =vhost_vdpa_svq_setup (dev, svq, i, &err);
Signature · 1 line
MST
[PULL v2 27/86] acpi/cxl: Create the CEDT (9.14.1)
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
The CXL Early Discovery Table is defined in the CXL 2.0 specification as a way for the OS to get CXL specific information from the system firmware.
CXL 2.0 specification adds an _HID, ACPI0016, for CXL capable host bridges, with a _CID of PNP0A08 (PCIe host bridge). CXL aware software is able to use this initiate the proper _OSC method, and get the _UID which is referenced by the CEDT. Therefore the existence of an ACPI0016 device allows a CXL aware driver perform the necessary actions. For a CXL capable OS, this works. For a CXL unaware OS, this works.
CEDT awaremess requires more. The motivation for ACPI0017 is to provide the possibility of having a Linux CXL module that can work on a legacy Linux kernel. Linux core PCI/ACPI which won't be built as a module, will see the _CID of PNP0A08 and bind a driver to it. If we later loaded a driver for ACPI0016, Linux won't be able to bind it to the hardware because it has already bound the PNP0A08 driver. The ACPI0017 device is an opportunity to have an object to bind a driver will be used by a Linux driver to walk the CXL topology and do everything that we would have preferred to do with ACPI0016.
There is another motivation for an ACPI0017 device which isn't implemented here. An operating system needs an attach point for a non-volatile region provider that understands cross-hostbridge interleaving. Since QEMU emulation doesn't support interleaving yet, this is more important on the OS side, for now.
As of CXL 2.0 spec, only 1 sub structure is defined, the CXL Host Bridge Structure (CHBS) which is primarily useful for telling the OS exactly where the MMIO for the host bridge is.
Message-Id: <[email protected]>
--- include/hw/acpi/cxl.h | 5 +++ include/hw/pci/pci_bridge.h | 20 +++++++++ hw/acpi/cxl.c | 68 +++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 27 ++++++++++++ hw/pci-bridge/pci_expander_bridge.c | 17 -------- 5 files changed, 120 insertions(+), 17 deletions(-)
include/hw/acpi/cxl.h +5 -0
@@ -18,6 +18,11 @@#ifndef HW_ACPI_CXL_H #define HW_ACPI_CXL_H +#include "hw/acpi/bios-linker-loader.h" + +void cxl_build_cedt (MachineState *ms,GArray *table_offsets,GArray *table_data, +BIOSLinker *linker,const char *oem_id, +const char *oem_table_id);void build_cxl_osc_method (Aml *dev);#endif
include/hw/pci/pci_bridge.h +20 -0
@@ -28,6 +28,7 @@#include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" +#include "hw/cxl/cxl.h" #include "qom/object.h" typedef struct PCIBridgeWindows PCIBridgeWindows ;
@@ -80,6 +81,25 @@ struct PCIBridge {#define PCI_BRIDGE_DEV_PROP_CHASSIS_NR "chassis_nr"#define PCI_BRIDGE_DEV_PROP_MSI "msi"#define PCI_BRIDGE_DEV_PROP_SHPC "shpc" +typedef struct CXLHost CXLHost ; + +struct PXBDev { +/*< private >*/ +PCIDevice parent_obj; +/*< public >*/ + +uint8_t bus_nr; +uint16_t numa_node; +bool bypass_iommu; +struct cxl_dev { +CXLHost *cxl_host_bridge;/* Pointer to a CXLHost */ + } cxl; +}; + +typedef struct PXBDev PXBDev ; +#define TYPE_PXB_CXL_DEVICE "pxb-cxl" +DECLARE_INSTANCE_CHECKER (PXBDev,PXB_CXL_DEV , + TYPE_PXB_CXL_DEVICE) int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset, uint16_t svid, uint16_t ssid,
hw/acpi/cxl.c +68 -0
81 lines not on this page · raw message
hw/i386/acpi-build.c +27 -0
@@ -77,6 +77,7 @@#include "hw/acpi/ipmi.h" #include "hw/acpi/hmat.h" #include "hw/acpi/viot.h" +#include "hw/acpi/cxl.h" #include CONFIG_DEVICES
@@ -1411,6 +1412,22 @@ static void build_smb0(Aml *table, I2CBus *smbus, int devnr, int func)aml_append (table, scope); } +static void build_acpi0017 (Aml *table) +{ +Aml *dev, *scope, *method; + + scope =aml_scope ("_SB" ); + dev =aml_device ("CXLM" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("ACPI0017" ))); + + method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_return (aml_int (0x01 ))); +aml_append (dev, method); + +aml_append (scope, dev); +aml_append (table, scope); +} + static void build_dsdt(GArray *table_data, BIOSLinker *linker, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -1430,6 +1447,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,#ifdef CONFIG_TPM TPMIf *tpm =tpm_find ();#endif +bool cxl_present = false;int i;VMBusBridge *vmbus_bridge =vmbus_bridge_find ();AcpiTable table = { .sig ="DSDT" , .rev =1 , .oem_id = x86ms->oem_id,
@@ -1618,12 +1636,17 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,MemoryRegion *mr = &machine->cxl_devices_state->host_mr;uint64_t base = mr->addr; + cxl_present = true;crs_range_insert (crs_range_set.mem_ranges, base, base +memory_region_size (mr) -1 ); } } } +if (cxl_present) { +build_acpi0017 (dsdt); + } +/* * At this point crs_range_set has all the ranges used by pci * busses *other* than PCI0. These ranges will be excluded from
@@ -2688,6 +2711,10 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) machine->nvdimms_state, machine->ram_slots, x86ms->oem_id, x86ms->oem_table_id); } +if (machine->cxl_devices_state->is_enabled) { +cxl_build_cedt (machine, table_offsets, tables_blob, tables->linker, + x86ms->oem_id, x86ms->oem_table_id); + }acpi_add_table (table_offsets, tables_blob);build_waet (tables_blob, tables->linker, x86ms->oem_id, x86ms->oem_table_id);
hw/pci-bridge/pci_expander_bridge.c +0 -17
@@ -57,23 +57,6 @@ DECLARE_INSTANCE_CHECKER(PXBDev, PXB_DEV,DECLARE_INSTANCE_CHECKER (PXBDev,PXB_PCIE_DEV , TYPE_PXB_PCIE_DEVICE) -#define TYPE_PXB_CXL_DEVICE "pxb-cxl" -DECLARE_INSTANCE_CHECKER (PXBDev,PXB_CXL_DEV , - TYPE_PXB_CXL_DEVICE) - -struct PXBDev { -/*< private >*/ -PCIDevice parent_obj; -/*< public >*/ - -uint8_t bus_nr; -uint16_t numa_node; -bool bypass_iommu; -struct cxl_dev { -CXLHost *cxl_host_bridge; - } cxl; -}; -static PXBDev *convert_to_pxb (PCIDevice *dev) {/* A CXL PXB's parent bus is PCIe, so the normal check won't work */
Signature · 1 line
MST
[PULL v2 30/86] acpi/cxl: Introduce CFMWS structures in CEDT
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
The CEDT CXL Fixed Window Memory Window Structures (CFMWs) define regions of the host phyiscal address map which (via an impdef means) are configured such that they have a particular interleave setup across one or more CXL Host Bridges.
Message-Id: <[email protected]>
--- hw/acpi/cxl.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
hw/acpi/cxl.c +59 -0
@@ -60,6 +60,64 @@ static void cedt_build_chbs(GArray *table_data, PXBDev *cxl)build_append_int_noprefix (table_data,memory_region_size (mr),8 ); } +/* +* CFMWS entries in CXL 2.0 ECN: CEDT CFMWS & QTG _DSM. +* Interleave ways encoding in CXL 2.0 ECN: 3, 6, 12 and 16-way memory +* interleaving. +*/ +static void cedt_build_cfmws (GArray *table_data,MachineState *ms) +{ +CXLState *cxls = ms->cxl_devices_state; +GList *it; + +for (it = cxls->fixed_windows; it; it = it->next) { +CXLFixedWindow *fw = it->data; +int i; + +/* Type */ +build_append_int_noprefix (table_data,1 ,1 ); + +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); + +/* Record Length */ +build_append_int_noprefix (table_data,36 +4 * fw->num_targets,2 ); + +/* Reserved */ +build_append_int_noprefix (table_data,0 ,4 ); + +/* Base HPA */ +build_append_int_noprefix (table_data, fw->mr.addr,8 ); + +/* Window Size */ +build_append_int_noprefix (table_data, fw->size,8 ); + +/* Host Bridge Interleave Ways */ +build_append_int_noprefix (table_data, fw->enc_int_ways,1 ); + +/* Host Bridge Interleave Arithmetic */ +build_append_int_noprefix (table_data,0 ,1 ); + +/* Reserved */ +build_append_int_noprefix (table_data,0 ,2 ); + +/* Host Bridge Interleave Granularity */ +build_append_int_noprefix (table_data, fw->enc_int_gran,4 ); + +/* Window Restrictions */ +build_append_int_noprefix (table_data,0x0f ,2 );/* No restrictions */ + +/* QTG ID */ +build_append_int_noprefix (table_data,0 ,2 ); + +/* Host Bridge List (list of UIDs - currently bus_nr) */ +for (i =0 ; i < fw->num_targets; i++) { +g_assert (fw->target_hbs[i]); +build_append_int_noprefix (table_data, fw->target_hbs[i]->bus_nr,4 ); + } + } +} +static int cxl_foreach_pxb_hb (Object *obj,void *opaque) {Aml *cedt = opaque;
@@ -86,6 +144,7 @@ void cxl_build_cedt(MachineState *ms, GArray *table_offsets, GArray *table_data,/* reserve space for CEDT header */ object_child_foreach_recursive (object_get_root (), cxl_foreach_pxb_hb, cedt); +cedt_build_cfmws (cedt->buf, ms);/* copy AML table into ACPI tables blob and patch header there */ g_array_append_vals (table_data, cedt->buf->data, cedt->buf->len);
Signature · 1 line
MST
[PULL v2 48/86] vhost: Fix element in vhost_svq_add failure
In reply to Michael S. TsirkinFrom: Eugenio Pérez <[email protected]>
Coverity rightly reports that is not free in that case.
Message-Id: <[email protected]>
--- hw/virtio/vhost-shadow-virtqueue.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/virtio/vhost-shadow-virtqueue.c +8 -0
@@ -199,11 +199,19 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,return true; } +/** +* Add an element to a SVQ. +* +* The caller must check that there is enough slots for the new element. It +* takes ownership of the element: In case of failure, it is free and the SVQ +* is considered broken. +*/ static bool vhost_svq_add (VhostShadowVirtqueue *svq,VirtQueueElement *elem) {unsigned qemu_head;bool ok =vhost_svq_add_split (svq, elem, &qemu_head);if (unlikely (!ok)) { +g_free (elem);return false; }
Signature · 1 line
MST
[PULL v2 28/86] hw/cxl/component: Add utils for interleave parameter encoding/decoding
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Both registers and the CFMWS entries in CDAT use simple encodings for the number of interleave ways and the interleave granularity. Introduce simple conversion functions to/from the unencoded number / size. So far the iw decode has not been needed so is it not implemented.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_component.h | 8 ++++++++ hw/cxl/cxl-component-utils.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
include/hw/cxl/cxl_component.h +8 -0
@@ -210,4 +210,12 @@ static inline int cxl_decoder_count_enc(int count) return 0; } +uint8_t cxl_interleave_ways_enc (int iw,Error **errp); +uint8_t cxl_interleave_granularity_enc (uint64_t gran,Error **errp); + +static inline hwaddr cxl_decode_ig (int ig) +{ +return 1 << (ig +8 ); +} +#endif
hw/cxl/cxl-component-utils.c +34 -0
@@ -9,6 +9,7 @@#include "qemu/osdep.h" #include "qemu/log.h" +#include "qapi/error.h" #include "hw/pci/pci.h" #include "hw/cxl/cxl.h"
@@ -329,3 +330,36 @@ void cxl_component_create_dvsec(CXLComponentState *cxl,range_init_nofail (&cxl->dvsecs[type], cxl->dvsec_offset, length); cxl->dvsec_offset += length; } + +uint8_t cxl_interleave_ways_enc (int iw,Error **errp) +{ +switch (iw) { +case 1 :return 0x0 ; +case 2 :return 0x1 ; +case 4 :return 0x2 ; +case 8 :return 0x3 ; +case 16 :return 0x4 ; +case 3 :return 0x8 ; +case 6 :return 0x9 ; +case 12 :return 0xa ; +default : +error_setg (errp,"Interleave ways: %d not supported" , iw); +return 0 ; + } +} + +uint8_t cxl_interleave_granularity_enc (uint64_t gran,Error **errp) +{ +switch (gran) { +case 256 :return 0 ; +case 512 :return 1 ; +case 1024 :return 2 ; +case 2048 :return 3 ; +case 4096 :return 4 ; +case 8192 :return 5 ; +case 16384 :return 6 ; +default : +error_setg (errp,"Interleave granularity: %" PRIu64" invalid" , gran); +return 0 ; + } +}
Signature · 1 line
MST
Re: [PULL v2 28/86] hw/cxl/component: Add utils for interleave parameter encoding/decoding
Quoted 24 lines · Michael S. Tsirkin
From: Jonathan Cameron <[email protected]>
Both registers and the CFMWS entries in CDAT use simple encodings for the number of interleave ways and the interleave granularity. Introduce simple conversion functions to/from the unencoded number / size. So far the iw decode has not been needed so is it not implemented.
Signed-off-by Jonathan Cameron <[email protected]>Reviewed-by Alex Bennée <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/cxl/cxl_component.h | 8 ++++++++ hw/cxl/cxl-component-utils.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)include/hw/cxl/cxl_component.h +0
-0
include/hw/cxl/cxl_component.h static inline int cxl_decoder_count_enc(int count) · line 219
Quoted 10 lines
include/hw/cxl/cxl_component.h +7
-0@@ -210,4 +210,12 @@ static inline int cxl_decoder_count_enc(int count)return 0 ; } +uint8_t cxl_interleave_ways_enc (int iw,Error **errp); +uint8_t cxl_interleave_granularity_enc (uint64_t gran,Error **errp); + +static inline hwaddr cxl_decode_ig (int ig) +{ +return 1 << (ig +8 ); +}
Hi; Coverity warns about this (CID 1488868) because the shift is calculated with 32-bit arithmetic but the function returns a 64-bit result. I assume that 'ig' is supposed to never be large enough that the result is >4GB, but we can make Coverity happy by using "1ULL" here.
thanks
-- PMM
Re: [PULL v2 28/86] hw/cxl/component: Add utils for interleave parameter encoding/decoding
Quoted 28 lines · On Mon, 27 Jun 2022 14:29:19 +0100 Peter Maydell <[email protected]>…
Quoted 27 lines · Michael S. Tsirkin
From: Jonathan Cameron <[email protected]>
Both registers and the CFMWS entries in CDAT use simple encodings for the number of interleave ways and the interleave granularity. Introduce simple conversion functions to/from the unencoded number / size. So far the iw decode has not been needed so is it not implemented.
Signed-off-by Jonathan Cameron <[email protected]>Reviewed-by Alex Bennée <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/cxl/cxl_component.h | 8 ++++++++ hw/cxl/cxl-component-utils.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)include/hw/cxl/cxl_component.h +0
-0@@ -210,4 +210,12 @@ static inline int cxl_decoder_count_enc(int count)return 0 ; }
Quoted 14 lines
include/hw/cxl/cxl_component.h static inline int cxl_decoder_count_enc(int count) · line 219
Quoted 7 lines
include/hw/cxl/cxl_component.h +7
-0+uint8_t cxl_interleave_ways_enc (int iw,Error **errp); +uint8_t cxl_interleave_granularity_enc (uint64_t gran,Error **errp); + +static inline hwaddr cxl_decode_ig (int ig) +{ +return 1 << (ig +8 ); +}Hi; Coverity warns about this (CID 1488868) because the shift is calculated with 32-bit arithmetic but the function returns a 64-bit result. I assume that 'ig' is supposed to never be large enough that the result is >4GB, but we can make Coverity happy by using "1ULL" here.
You are correct on range never hitting that.
Will send a fix in next few days.
Jonathan
Quoted 2 lines
thanks
-- PMM
[PULL v2 50/86] intel_iommu: Support IR-only mode without DMA translation
In reply to Michael S. TsirkinFrom: David Woodhouse <[email protected]>
By setting none of the SAGAW bits we can indicate to a guest that DMA translation isn't supported. Tested by booting Windows 10, as well as Linux guests with the fix at https://git.kernel.org/torvalds/c/c40aaaac10
Message-Id: <[email protected]>
--- include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)
include/hw/i386/intel_iommu.h +1 -0
@@ -267,6 +267,7 @@ struct IntelIOMMUState {bool buggy_eim;/* Force buggy EIM unless eim=off */ uint8_t aw_bits;/* Host/IOVA address width (in bits) */ bool dma_drain;/* Whether DMA r/w draining enabled */ +bool dma_translation;/* Whether DMA translation supported */ /* * Protects IOMMU states in general. Currently it protects the
hw/i386/intel_iommu.c +10 -4
@@ -2214,7 +2214,7 @@ static void vtd_handle_gcmd_write(IntelIOMMUState *s)uint32_t changed = status ^ val;trace_vtd_reg_write_gcmd (status, val); -if (changed &VTD_GCMD_TE ) { +if ((changed &VTD_GCMD_TE ) && s->dma_translation) {/* Translation enable/disable */ vtd_handle_gcmd_te (s, val &VTD_GCMD_TE ); }
@@ -3122,6 +3122,7 @@ static Property vtd_properties[] = {DEFINE_PROP_BOOL ("x-scalable-mode" , IntelIOMMUState, scalable_mode, FALSE),DEFINE_PROP_BOOL ("snoop-control" , IntelIOMMUState, snoop_control, false),DEFINE_PROP_BOOL ("dma-drain" , IntelIOMMUState, dma_drain, true), +DEFINE_PROP_BOOL ("dma-translation" , IntelIOMMUState, dma_translation, true), DEFINE_PROP_END_OF_LIST(), };
@@ -3627,12 +3628,17 @@ static void vtd_init(IntelIOMMUState *s) s->next_frcd_reg =0 ; s->cap =VTD_CAP_FRO |VTD_CAP_NFR |VTD_CAP_ND |VTD_CAP_MAMV |VTD_CAP_PSI |VTD_CAP_SLLPS | - VTD_CAP_SAGAW_39bit |VTD_CAP_MGAW (s->aw_bits); +VTD_CAP_MGAW (s->aw_bits);if (s->dma_drain) { s->cap |=VTD_CAP_DRAIN ; } -if (s->aw_bits ==VTD_HOST_AW_48BIT ) { - s->cap |= VTD_CAP_SAGAW_48bit; +if (s->dma_translation) { +if (s->aw_bits >=VTD_HOST_AW_39BIT ) { + s->cap |= VTD_CAP_SAGAW_39bit; + } +if (s->aw_bits >=VTD_HOST_AW_48BIT ) { + s->cap |= VTD_CAP_SAGAW_48bit; + } } s->ecap =VTD_ECAP_QI |VTD_ECAP_IRO ;
Signature · 1 line
MST
[PULL v2 32/86] pci/pcie_port: Add pci_find_port_by_pn()
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Simple function to search a PCIBus to find a port by it's port number.
CXL interleave decoding uses the port number as a target so it is necessary to locate the port when doing interleave decoding.
Message-Id: <[email protected]>
--- include/hw/pci/pcie_port.h | 2 ++ hw/pci/pcie_port.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/hw/pci/pcie_port.h +2 -0
@@ -39,6 +39,8 @@ struct PCIEPort {void pcie_port_init_reg (PCIDevice *d); +PCIDevice *pcie_find_port_by_pn (PCIBus *bus,uint8_t pn); +#define TYPE_PCIE_SLOT "pcie-slot"OBJECT_DECLARE_SIMPLE_TYPE (PCIESlot,PCIE_SLOT )
hw/pci/pcie_port.c +25 -0
@@ -136,6 +136,31 @@ static void pcie_port_class_init(ObjectClass *oc, void *data)device_class_set_props (dc, pcie_port_props); } +PCIDevice *pcie_find_port_by_pn (PCIBus *bus,uint8_t pn) +{ +int devfn; + +for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { +PCIDevice *d = bus->devices[devfn]; +PCIEPort *port; + +if (!d || !pci_is_express (d) || !d->exp.exp_cap) { +continue ; + } + +if (!object_dynamic_cast (OBJECT (d),TYPE_PCIE_PORT )) { +continue ; + } + + port =PCIE_PORT (d); +if (port->port == pn) { +return d; + } + } + +return NULL ; +} +static const TypeInfo pcie_port_type_info = { .name =TYPE_PCIE_PORT , .parent =TYPE_PCI_BRIDGE ,
Signature · 1 line
MST
[PULL v2 55/86] intel-iommu: update root_scalable before switching as during post_load
In reply to Michael S. TsirkinFrom: Jason Wang <[email protected]>
We need check whether passthrough is enabled during vtd_switch_address_space() by checking the context entries. This requires the root_scalable to be set correctly otherwise we may try to check legacy rsvd bits instead of scalable ones.
Fixing this by updating root_scalable before switching the address spaces during post_load.
Message-Id: <[email protected]>
--- hw/i386/intel_iommu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
hw/i386/intel_iommu.c +7 -7
@@ -3073,13 +3073,6 @@ static int vtd_post_load(void *opaque, int version_id) {IntelIOMMUState *iommu = opaque; -/* -* Memory regions are dynamically turned on/off depending on -* context entry configurations from the guest. After migration, -* we need to make sure the memory regions are still correct. -*/ -vtd_switch_address_space_all (iommu); -/* * We don't need to migrate the root_scalable because we can * simply do the calculation after the loading is complete. We
@@ -3089,6 +3082,13 @@ static int vtd_post_load(void *opaque, int version_id)*/ vtd_update_scalable_state (iommu); +/* +* Memory regions are dynamically turned on/off depending on +* context entry configurations from the guest. After migration, +* we need to make sure the memory regions are still correct. +*/ +vtd_switch_address_space_all (iommu); +return 0 ; }
Signature · 1 line
MST
[PULL v2 29/86] hw/cxl/host: Add support for CXL Fixed Memory Windows.
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
The concept of these is introduced in [1] in terms of the description the CEDT ACPI table. The principal is more general. Unlike once traffic hits the CXL root bridges, the host system memory address routing is implementation defined and effectively static once observable by standard / generic system software. Each CXL Fixed Memory Windows (CFMW) is a region of PA space which has fixed system dependent routing configured so that accesses can be routed to the CXL devices below a set of target root bridges. The accesses may be interleaved across multiple root bridges.
For QEMU we could have fully specified these regions in terms of a base PA + size, but as the absolute address does not matter it is simpler to let individual platforms place the memory regions.
ExampleS:
-cxl-fixed-memory-window targets.0=cxl.0,size=128G
-cxl-fixed-memory-window targets.0=cxl.1,size=128G
-cxl-fixed-memory-window targets.0=cxl0,targets.1=cxl.1,size=256G,interleave-granularity=2k
Specifies
* 2x 128G regions not interleaved across root bridges, one for each of the root bridges with ids cxl.0 and cxl.1
* 256G region interleaved across root bridges with ids cxl.0 and cxl.1 with a 2k interleave granularity.
When system software enumerates the devices below a given root bridge it can then decide which CFMW to use. If non interleave is desired (or possible) it can use the appropriate CFMW for the root bridge in question. If there are suitable devices to interleave across the two root bridges then it may use the 3rd CFMS.
A number of other designs were considered but the following constraints made it hard to adapt existing QEMU approaches to this particular problem.
1) The size must be known before a specific architecture / board brings up it's PA memory map. We need to set up an appropriate region.
2) Using links to the host bridges provides a clean command line interface but these links cannot be established until command line devices have been added.
Hence the two step process used here of first establishing the size, interleave-ways and granularity + caching the ids of the host bridges and then, once available finding the actual host bridges so they can be used later to support interleave decoding.
[1] CXL 2.0 ECN: CEDT CFMWS & QTG DSM (computeexpresslink.org / specifications)
Message-Id: <[email protected]>
--- qapi/machine.json | 21 +++++++++ include/hw/cxl/cxl.h | 21 +++++++++ hw/cxl/cxl-host-stubs.c | 14 ++++++ hw/cxl/cxl-host.c | 94 +++++++++++++++++++++++++++++++++++++++++ softmmu/vl.c | 47 +++++++++++++++++++++ hw/cxl/meson.build | 6 +++ qemu-options.hx | 38 +++++++++++++++++ 7 files changed, 241 insertions(+) create mode 100644 hw/cxl/cxl-host-stubs.c create mode 100644 hw/cxl/cxl-host.c
qapi/machine.json +21 -0
@@ -502,6 +502,27 @@ 'dst': 'uint16', 'val': 'uint8' }} +## +# @CXLFixedMemoryWindowOptions: +# +# Create a CXL Fixed Memory Window +# +# @size: Size of the Fixed Memory Window in bytes. Must be a multiple +# of 256MiB. +# @interleave-granularity: Number of contiguous bytes for which +# accesses will go to a given interleave target. +# Accepted values [256, 512, 1k, 2k, 4k, 8k, 16k] +# @targets: Target root bridge IDs from -device ...,id=<ID> for each root +# bridge. +# +# Since 7.1 +## +{ 'struct': 'CXLFixedMemoryWindowOptions', + 'data': { + 'size': 'size', + '*interleave-granularity': 'size', + 'targets': ['str'] }} + ## # @X86CPURegister32: #
include/hw/cxl/cxl.h +21 -0
@@ -10,6 +10,9 @@#ifndef CXL_H #define CXL_H + +#include "qapi/qapi-types-machine.h" +#include "hw/pci/pci_bridge.h" #include "hw/pci/pci_host.h" #include "cxl_pci.h" #include "cxl_component.h"
@@ -20,10 +23,23 @@#define CXL_WINDOW_MAX 10 +typedef struct CXLFixedWindow { +uint64_t size; +char **targets; +struct PXBDev *target_hbs[8 ]; +uint8_t num_targets; +uint8_t enc_int_ways; +uint8_t enc_int_gran; +/* Todo: XOR based interleaving */ +MemoryRegion mr; +hwaddr base; +}CXLFixedWindow ; +typedef struct CXLState {bool is_enabled;MemoryRegion host_mr;unsigned int next_mr_idx; +GList *fixed_windows; }CXLState ;struct CXLHost {
@@ -35,4 +51,9 @@ struct CXLHost {#define TYPE_PXB_CXL_HOST "pxb-cxl-host" OBJECT_DECLARE_SIMPLE_TYPE(CXLHost, PXB_CXL_HOST) +void cxl_fixed_memory_window_config (MachineState *ms, +CXLFixedMemoryWindowOptions *object, +Error **errp); +void cxl_fixed_memory_window_link_targets (Error **errp); +#endif
hw/cxl/cxl-host-stubs.c new file +14 -0
@@ -0,0 +1,14 @@ +/* +* CXL host parameter parsing routine stubs +* +* Copyright (c) 2022 Huawei +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/cxl/cxl.h" + +void cxl_fixed_memory_window_config (MachineState *ms, +CXLFixedMemoryWindowOptions *object, +Error **errp) {}; + +void cxl_fixed_memory_window_link_targets (Error **errp) {};
hw/cxl/cxl-host.c new file +94 -0
94 lines not on this page · raw message
softmmu/vl.c +47 -0
101 lines not on this page · raw message
hw/cxl/meson.build +6 -0
@@ -3,4 +3,10 @@ softmmu_ss.add(when: 'CONFIG_CXL', 'cxl-component-utils.c', 'cxl-device-utils.c', 'cxl-mailbox-utils.c', + 'cxl-host.c', + ), + if_false: files( + 'cxl-host-stubs.c', )) + +softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('cxl-host-stubs.c'))
qemu-options.hx +38 -0
@@ -467,6 +467,44 @@ SRST -numa hmat-cache,node-id=1,size=10K,level=1,associativity=direct,policy=write-back,line=8 ERST +DEF("cxl-fixed-memory-window", HAS_ARG, QEMU_OPTION_cxl_fixed_memory_window, + "-cxl-fixed-memory-window targets.0=firsttarget,targets.1=secondtarget,size=size[,interleave-granularity=granularity]\n", + QEMU_ARCH_ALL) +SRST +``-cxl-fixed-memory-window targets.0=firsttarget,targets.1=secondtarget,size=size[,interleave-granularity=granularity]`` + Define a CXL Fixed Memory Window (CFMW). + + Described in the CXL 2.0 ECN: CEDT CFMWS & QTG _DSM. + + They are regions of Host Physical Addresses (HPA) on a system which + may be interleaved across one or more CXL host bridges. The system + software will assign particular devices into these windows and + configure the downstream Host-managed Device Memory (HDM) decoders + in root ports, switch ports and devices appropriately to meet the + interleave requirements before enabling the memory devices. + + ``targets.X=firsttarget`` provides the mapping to CXL host bridges + which may be identified by the id provied in the -device entry. + Multiple entries are needed to specify all the targets when + the fixed memory window represents interleaved memory. X is the + target index from 0. + + ``size=size`` sets the size of the CFMW. This must be a multiple of + 256MiB. The region will be aligned to 256MiB but the location is + platform and configuration dependent. + + ``interleave-granularity=granularity`` sets the granularity of + interleave. Default 256KiB. Only 256KiB, 512KiB, 1024KiB, 2048KiB + 4096KiB, 8192KiB and 16384KiB granularities supported. + + Example: + + :: + + -cxl-fixed-memory-window targets.0=cxl.0,targets.1=cxl.1,size=128G,interleave-granularity=512k + +ERST + DEF("add-fd", HAS_ARG, QEMU_OPTION_add_fd, "-add-fd fd=fd,set=set[,opaque=opaque]\n" " Add 'fd' to fd 'set'\n", QEMU_ARCH_ALL)
Signature · 1 line
MST
Re: [PULL v2 29/86] hw/cxl/host: Add support for CXL Fixed Memory Windows.
Quoted 13 lines · Michael S. Tsirkin
From: Jonathan Cameron <[email protected]>
The concept of these is introduced in [1] in terms of the description the CEDT ACPI table. The principal is more general. Unlike once traffic hits the CXL root bridges, the host system memory address routing is implementation defined and effectively static once observable by standard / generic system software. Each CXL Fixed Memory Windows (CFMW) is a region of PA space which has fixed system dependent routing configured so that accesses can be routed to the CXL devices below a set of target root bridges. The accesses may be interleaved across multiple root bridges.
Hi; Coverity points out a memory leak in this function (CID 1488872):
hw/cxl/cxl-host.c line 23
Quoted 5 lines
hw/cxl/cxl-host.c new file +5
-0+void cxl_fixed_memory_window_config (MachineState *ms, +CXLFixedMemoryWindowOptions *object, +Error **errp) +{ +CXLFixedWindow *fw =g_malloc0 (sizeof (*fw));
Here we allocate memory...
hw/cxl/cxl-host.c line 33
Quoted 10 lines
hw/cxl/cxl-host.c new file +10
-0+strList *target; +int i; + +for (target = object->targets; target; target = target->next) { + fw->num_targets++; + } + + fw->enc_int_ways =cxl_interleave_ways_enc (fw->num_targets, errp); +if (*errp) { +return ;
...but in the error returns here..
hw/cxl/cxl-host.c line 45
Quoted 12 lines
hw/cxl/cxl-host.c new file +12
-0+ } + + fw->targets =g_malloc0_n (fw->num_targets,sizeof (*fw->targets)); +for (i =0 , target = object->targets; target; i++, target = target->next) { +/* This link cannot be resolved yet, so stash the name for now */ + fw->targets[i] =g_strdup (target->value); + } + +if (object->size % (256 * MiB)) { +error_setg (errp, +"Size of a CXL fixed memory window must my a multiple of 256MiB" ); +return ;
...here..
hw/cxl/cxl-host.c line 54
Quoted 9 lines
hw/cxl/cxl-host.c new file +9
-0+ } + fw->size = object->size; + +if (object->has_interleave_granularity) { + fw->enc_int_gran = +cxl_interleave_granularity_enc (object->interleave_granularity, + errp); +if (*errp) { +return ;
...and here we fail to free the memory we allocated.
hw/cxl/cxl-host.c line 65
Quoted 11 lines
hw/cxl/cxl-host.c new file +11
-0+ } + }else { +/* Default to 256 byte interleave */ + fw->enc_int_gran =0 ; + } + + ms->cxl_devices_state->fixed_windows = +g_list_append (ms->cxl_devices_state->fixed_windows, fw); + +return ; +}
Would you mind sending a patch to fix this bug ?
The neatest approach probably uses g_autofree and g_steal_pointer().
thanks
-- PMM
[PULL v2 52/86] intel_iommu: Fix irqchip / X2APIC configuration checks
In reply to Michael S. TsirkinFrom: David Woodhouse <[email protected]>
We don't need to check kvm_enable_x2apic(). It's perfectly OK to support interrupt remapping even if we can't address CPUs above 254. Kind of pointless, but still functional.
The check on kvm_enable_x2apic() needs to happen *anyway* in order to allow CPUs above 254 even without an IOMMU, so allow that to happen elsewhere.
However, we do require the *split* irqchip in order to rewrite I/OAPIC destinations. So fix that check while we're here.
Message-Id: <[email protected]>
--- hw/i386/intel_iommu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
hw/i386/intel_iommu.c +1 -6
@@ -3786,15 +3786,10 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) ON_OFF_AUTO_ON :ON_OFF_AUTO_OFF ; }if (s->intr_eim ==ON_OFF_AUTO_ON && !s->buggy_eim) { -if (!kvm_irqchip_in_kernel ()) { +if (!kvm_irqchip_is_split ()) {error_setg (errp,"eim=on requires accel=kvm,kernel-irqchip=split" );return false; } -if (!kvm_enable_x2apic ()) { -error_setg (errp,"eim=on requires support on the KVM side" -"(X2APIC_API, first shipped in v4.7)" ); -return false; - } }/* Currently only address widths supported are 39 and 48 bits */
Signature · 1 line
MST
[PULL v2 36/86] hw/cxl/component Add a dumb HDM decoder handler
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
Add a trivial handler for now to cover the root bridge where we could do some error checking in future.
Message-Id: <[email protected]>
--- hw/cxl/cxl-component-utils.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
hw/cxl/cxl-component-utils.c +31 -0
@@ -32,6 +32,31 @@ static uint64_t cxl_cache_mem_read_reg(void *opaque, hwaddr offset, } } +static void dumb_hdm_handler (CXLComponentState *cxl_cstate,hwaddr offset, +uint32_t value) +{ +ComponentRegisters *cregs = &cxl_cstate->crb; +uint32_t *cache_mem = cregs->cache_mem_registers; +bool should_commit = false; + +switch (offset) { +case A_CXL_HDM_DECODER0_CTRL : + should_commit =FIELD_EX32 (value,CXL_HDM_DECODER0_CTRL ,COMMIT ); +break ; +default : +break ; + } + +memory_region_transaction_begin (); +stl_le_p ((uint8_t *)cache_mem + offset, value); +if (should_commit) { +ARRAY_FIELD_DP32 (cache_mem,CXL_HDM_DECODER0_CTRL ,COMMIT ,0 ); +ARRAY_FIELD_DP32 (cache_mem,CXL_HDM_DECODER0_CTRL ,ERR ,0 ); +ARRAY_FIELD_DP32 (cache_mem,CXL_HDM_DECODER0_CTRL ,COMMITTED ,1 ); + } +memory_region_transaction_commit (); +} +static void cxl_cache_mem_write_reg (void *opaque,hwaddr offset,uint64_t value,unsigned size) {
@@ -50,6 +75,12 @@ static void cxl_cache_mem_write_reg(void *opaque, hwaddr offset, uint64_t value, value |= ~mask & cregs->cache_mem_registers[offset /sizeof (*cregs->cache_mem_registers)];if (cregs->special_ops && cregs->special_ops->write) { cregs->special_ops->write (cxl_cstate, offset, value, size); +return ; + } + +if (offset >=A_CXL_HDM_DECODER_CAPABILITY && + offset <=A_CXL_HDM_DECODER0_TARGET_LIST_HI ) { +dumb_hdm_handler (cxl_cstate, offset, value); }else { cregs->cache_mem_registers[offset /sizeof (*cregs->cache_mem_registers)] = value; }
Signature · 1 line
MST
[PULL v2 56/86] intel-iommu: update iq_dw during post load
In reply to Michael S. TsirkinFrom: Jason Wang <[email protected]>
We need to update iq_dw according to the DMA_IRQ_REG during post load. Otherwise we may get wrong IOTLB invalidation descriptor after migration.
Message-Id: <[email protected]>
--- hw/i386/intel_iommu.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
hw/i386/intel_iommu.c +15 -6
@@ -181,6 +181,18 @@ static void vtd_update_scalable_state(IntelIOMMUState *s) } } +static void vtd_update_iq_dw (IntelIOMMUState *s) +{ +uint64_t val =vtd_get_quad_raw (s,DMAR_IQA_REG ); + +if (s->ecap &VTD_ECAP_SMTS && + val &VTD_IQA_DW_MASK ) { + s->iq_dw = true; + }else { + s->iq_dw = false; + } +} +/* Whether the address space needs to notify new mappings */ static inline gboolean vtd_as_has_map_notifier (VTDAddressSpace *as) {
@@ -2904,12 +2916,7 @@ static void vtd_mem_write(void *opaque, hwaddr addr, }else {vtd_set_quad (s, addr, val); } -if (s->ecap &VTD_ECAP_SMTS && - val &VTD_IQA_DW_MASK ) { - s->iq_dw = true; - }else { - s->iq_dw = false; - } +vtd_update_iq_dw (s);break ;case DMAR_IQA_REG_HI :
@@ -3082,6 +3089,8 @@ static int vtd_post_load(void *opaque, int version_id)*/ vtd_update_scalable_state (iommu); +vtd_update_iq_dw (iommu); +/* * Memory regions are dynamically turned on/off depending on * context entry configurations from the guest. After migration,
Signature · 1 line
MST
[PULL v2 33/86] CXL/cxl_component: Add cxl_get_hb_cstate()
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Accessor to get hold of the cxl state for a CXL host bridge without exposing the internals of the implementation.
Message-Id: <[email protected]>
--- include/hw/cxl/cxl_component.h | 2 ++ hw/pci-bridge/pci_expander_bridge.c | 7 +++++++ 2 files changed, 9 insertions(+)
include/hw/cxl/cxl_component.h +2 -0
@@ -218,4 +218,6 @@ static inline hwaddr cxl_decode_ig(int ig) return 1 << (ig + 8); } +CXLComponentState *cxl_get_hb_cstate (PCIHostState *hb); +#endif
hw/pci-bridge/pci_expander_bridge.c +7 -0
@@ -72,6 +72,13 @@ static GList *pxb_dev_list;#define TYPE_PXB_HOST "pxb-host" +CXLComponentState *cxl_get_hb_cstate (PCIHostState *hb) +{ +CXLHost *host =PXB_CXL_HOST (hb); + +return &host->cxl_cstate; +} +static int pxb_bus_num (PCIBus *bus) {PXBDev *pxb =convert_to_pxb (bus->parent_dev);
Signature · 1 line
MST
[PULL v2 51/86] intel_iommu: Only allow interrupt remapping to be enabled if it's supported
In reply to Michael S. TsirkinFrom: David Woodhouse <[email protected]>
We should probably check if we were meant to be exposing IR, before letting the guest turn the IRE bit on.
Message-Id: <[email protected]>
--- hw/i386/intel_iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/i386/intel_iommu.c +3 -1
@@ -2209,6 +2209,7 @@ static void vtd_handle_gcmd_ire(IntelIOMMUState *s, bool en)/* Handle write to Global Command Register */ static void vtd_handle_gcmd_write (IntelIOMMUState *s) { +X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (s);uint32_t status =vtd_get_long_raw (s,DMAR_GSTS_REG );uint32_t val =vtd_get_long_raw (s,DMAR_GCMD_REG );uint32_t changed = status ^ val;
@@ -2230,7 +2231,8 @@ static void vtd_handle_gcmd_write(IntelIOMMUState *s)/* Set/update the interrupt remapping root-table pointer */ vtd_handle_gcmd_sirtp (s); } -if (changed &VTD_GCMD_IRE ) { +if ((changed &VTD_GCMD_IRE ) && +x86_iommu_ir_supported (x86_iommu)) {/* Interrupt remap enable/disable */ vtd_handle_gcmd_ire (s, val &VTD_GCMD_IRE ); }
Signature · 1 line
MST
[PULL v2 37/86] i386/pc: Enable CXL fixed memory windows
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Add the CFMWs memory regions to the memorymap and adjust the PCI window to avoid hitting the same memory.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
hw/i386/pc.c +30 -1
@@ -817,7 +817,7 @@ void pc_memory_init(PCMachineState *pcms,MachineClass *mc =MACHINE_GET_CLASS (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (pcms); -hwaddr cxl_base; +hwaddr cxl_base, cxl_resv_end =0 ;assert (machine->ram_size == x86ms->below_4g_mem_size + x86ms->above_4g_mem_size);
@@ -925,6 +925,24 @@ void pc_memory_init(PCMachineState *pcms,e820_add_entry (cxl_base, cxl_size,E820_RESERVED );memory_region_init (mr,OBJECT (machine),"cxl_host_reg" , cxl_size);memory_region_add_subregion (system_memory, cxl_base, mr); + cxl_resv_end = cxl_base + cxl_size; +if (machine->cxl_devices_state->fixed_windows) { +hwaddr cxl_fmw_base; +GList *it; + + cxl_fmw_base =ROUND_UP (cxl_base + cxl_size,256 * MiB); +for (it = machine->cxl_devices_state->fixed_windows; it; it = it->next) { +CXLFixedWindow *fw = it->data; + + fw->base = cxl_fmw_base; +memory_region_init_io (&fw->mr,OBJECT (machine), &cfmws_ops, fw, +"cxl-fixed-memory-region" , fw->size); +memory_region_add_subregion (system_memory, fw->base, &fw->mr); +e820_add_entry (fw->base, fw->size,E820_RESERVED ); + cxl_fmw_base += fw->size; + cxl_resv_end = cxl_fmw_base; + } + } }/* Initialize PC system firmware */
@@ -954,6 +972,10 @@ void pc_memory_init(PCMachineState *pcms,if (!pcmc->broken_reserved_end) { res_mem_end +=memory_region_size (&machine->device_memory->mr); } + +if (machine->cxl_devices_state->is_enabled) { + res_mem_end = cxl_resv_end; + } *val =cpu_to_le64 (ROUND_UP (res_mem_end,1 * GiB));fw_cfg_add_file (fw_cfg,"etc/reserved-memory-end" , val,sizeof (*val)); }
@@ -990,6 +1012,13 @@ uint64_t pc_pci_hole64_start(void)if (ms->cxl_devices_state->host_mr.addr) { hole64_start = ms->cxl_devices_state->host_mr.addr +memory_region_size (&ms->cxl_devices_state->host_mr); +if (ms->cxl_devices_state->fixed_windows) { +GList *it; +for (it = ms->cxl_devices_state->fixed_windows; it; it = it->next) { +CXLFixedWindow *fw = it->data; + hole64_start = fw->mr.addr +memory_region_size (&fw->mr); + } + } }else if (pcmc->has_reserved_memory && ms->device_memory->base) { hole64_start = ms->device_memory->base;if (!pcmc->broken_reserved_end) {
Signature · 1 line
MST
[PULL v2 62/86] docs: vhost-user: rewrite section on ring state machine
In reply to Michael S. TsirkinFrom: Paolo Bonzini <[email protected]>
This section is using the word "back-end" to refer to the "slave's back-end", and talking about the "client" for what the rest of the document calls the "slave".
Rework it to free the use of the term "back-end", which in the next patch will replace "slave".
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- docs/interop/vhost-user.rst | 46 +++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 25 deletions(-)
docs/interop/vhost-user.rst +21 -25
@@ -332,40 +332,36 @@ bit was dedicated for this purpose:: #define VHOST_USER_F_PROTOCOL_FEATURES 30 -Starting and stopping rings ---------------------------- +Ring states +----------- -Client must only process each ring when it is started. +Rings can be in one of three states: -Client must only pass data between the ring and the backend, when the -ring is enabled. +* stopped: the slave must not process the ring at all. -If ring is started but disabled, client must process the ring without -talking to the backend. +* started but disabled: the slave must process the ring without + causing any side effects. For example, for a networking device, + in the disabled state the slave must not supply any new RX packets, + but must process and discard any TX packets. -For example, for a networking device, in the disabled state client -must not supply any new RX packets, but must process and discard any -TX packets. +* started and enabled. + +Each ring is initialized in a stopped state. The slave must start +ring upon receiving a kick (that is, detecting that file descriptor is +readable) on the descriptor specified by ``VHOST_USER_SET_VRING_KICK`` +or receiving the in-band message ``VHOST_USER_VRING_KICK`` if negotiated, +and stop ring upon receiving ``VHOST_USER_GET_VRING_BASE``. + +Rings can be enabled or disabled by ``VHOST_USER_SET_VRING_ENABLE``. If ``VHOST_USER_F_PROTOCOL_FEATURES`` has not been negotiated, the -ring is initialized in an enabled state. +ring starts directly in the enabled state. If ``VHOST_USER_F_PROTOCOL_FEATURES`` has been negotiated, the ring is -initialized in a disabled state. Client must not pass data to/from the -backend until ring is enabled by ``VHOST_USER_SET_VRING_ENABLE`` with -parameter 1, or after it has been disabled by -``VHOST_USER_SET_VRING_ENABLE`` with parameter 0. +initialized in a disabled state and is enabled by +``VHOST_USER_SET_VRING_ENABLE`` with parameter 1. -Each ring is initialized in a stopped state, client must not process -it until ring is started, or after it has been stopped. - -Client must start ring upon receiving a kick (that is, detecting that -file descriptor is readable) on the descriptor specified by -``VHOST_USER_SET_VRING_KICK`` or receiving the in-band message -``VHOST_USER_VRING_KICK`` if negotiated, and stop ring upon receiving -``VHOST_USER_GET_VRING_BASE``. - -While processing the rings (whether they are enabled or not), client +While processing the rings (whether they are enabled or not), the slave must support changing some configuration aspects on the fly. Multiple queue support
Signature · 1 line
MST
[PULL v2 35/86] cxl/cxl-host: Add memops for CFMWS region.
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
These memops perform interleave decoding, walking down the CXL topology from CFMWS described host interleave decoder via CXL host bridge HDM decoders, through the CXL root ports and finally call CXL type 3 specific read and write functions.
Note that, whilst functional the current implementation does not support:
* switches
* multiple HDM decoders at a given level.
* unaligned accesses across the interleave boundaries
Message-Id: <[email protected]>
--- include/hw/cxl/cxl.h | 2 + hw/cxl/cxl-host-stubs.c | 2 + hw/cxl/cxl-host.c | 128 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+)
include/hw/cxl/cxl.h +2 -0
@@ -56,4 +56,6 @@ void cxl_fixed_memory_window_config(MachineState *ms, Error **errp);void cxl_fixed_memory_window_link_targets (Error **errp); +extern const MemoryRegionOps cfmws_ops; +#endif
hw/cxl/cxl-host-stubs.c +2 -0
@@ -12,3 +12,5 @@ void cxl_fixed_memory_window_config(MachineState *ms, Error **errp) {};void cxl_fixed_memory_window_link_targets (Error **errp) {}; + +const MemoryRegionOps cfmws_ops;
hw/cxl/cxl-host.c +128 -0
137 lines not on this page · raw message
Signature · 1 line
MST
Re: [PULL v2 35/86] cxl/cxl-host: Add memops for CFMWS region.
Quoted 9 lines · Michael S. Tsirkin
From: Jonathan Cameron <[email protected]>
These memops perform interleave decoding, walking down the CXL topology from CFMWS described host interleave decoder via CXL host bridge HDM decoders, through the CXL root ports and finally call CXL type 3 specific read and write functions.
Quoted 5 lines
Note that, whilst functional the current implementation does not support:
* switches
* multiple HDM decoders at a given level.
* unaligned accesses across the interleave boundaries
Hi; Coverity reports a bug in this code (CID 1488873):
hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 107
Quoted 8 lines
hw/cxl/cxl-host.c +8
-0+/* TODO: support, multiple hdm decoders */ +static bool cxl_hdm_find_target (uint32_t *cache_mem,hwaddr addr, +uint8_t *target) +{ +uint32_t ctrl; +uint32_t ig_enc; +uint32_t iw_enc; +uint32_t target_reg;
target_reg is 32 bits...
hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 119
Quoted 12 lines
hw/cxl/cxl-host.c +12
-0+uint32_t target_idx; + + ctrl = cache_mem[R_CXL_HDM_DECODER0_CTRL ]; +if (!FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,COMMITTED )) { +return false; + } + + ig_enc =FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,IG ); + iw_enc =FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,IW ); + target_idx = (addr /cxl_decode_ig (ig_enc)) % (1 << iw_enc); + +if (target_idx >4 ) {
...in this half of the if() target_idx is at least 5...
hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 121
Quoted 2 lines
hw/cxl/cxl-host.c +2
-0+ target_reg = cache_mem[R_CXL_HDM_DECODER0_TARGET_LIST_LO ]; + target_reg >>= target_idx *8 ;
...but 5 * 8 is 40, so this shift will always be undefined behaviour. Was the if() condition intended to be "< 4" ?
hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 123
Quoted 2 lines
hw/cxl/cxl-host.c +2
-0+ }else { + target_reg = cache_mem[R_CXL_HDM_DECODER0_TARGET_LIST_LO ];
Was this (or the other one) intended to be ...LIST_HI ?
Quoted 1 line
+
target_reg>>= (target_idx- 4) * 8;
Not noticed by Coverity, but in this half of the if(), target_idx is 4 or less, so (target_idx - 4) is in most cases going to be negative, which isn't a valid shift amount. This also suggests the if() condition is wrong.
hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 129
Quoted 5 lines
hw/cxl/cxl-host.c +5
-0+ } + *target = target_reg &0xff ; + +return true; +}
What's the intended behaviour here ?
The code appears to be attempting to extract a particular subfield from one or other of the cache_mem[] values. I would recommend using extract32() for this rather than raw shift and mask operations -- it's generally easier to write and to review.
thanks
-- PMM
Re: [PULL v2 35/86] cxl/cxl-host: Add memops for CFMWS region.
Quoted 10 lines · On Wed, 20 Jul 2022 13:23:10 +0100 Peter Maydell <[email protected]>…
Quoted 9 lines · Michael S. Tsirkin
From: Jonathan Cameron <[email protected]>
These memops perform interleave decoding, walking down the CXL topology from CFMWS described host interleave decoder via CXL host bridge HDM decoders, through the CXL root ports and finally call CXL type 3 specific read and write functions.
Quoted 7 lines
Quoted 5 lines
Note that, whilst functional the current implementation does not support:
* switches
* multiple HDM decoders at a given level.
* unaligned accesses across the interleave boundariesHi; Coverity reports a bug in this code (CID 1488873):
Huh. This looks to be one of those cases where a bunch of different bugs ended up with something that appears to work.
Quoted 27 lines
hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 107
Quoted 9 lines
hw/cxl/cxl-host.c +8
-0+/* TODO: support, multiple hdm decoders */ +static bool cxl_hdm_find_target (uint32_t *cache_mem,hwaddr addr, +uint8_t *target) +{ +uint32_t ctrl; +uint32_t ig_enc; +uint32_t iw_enc; +uint32_t target_reg;
target_regis 32 bits...hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 119
Quoted 12 lines
hw/cxl/cxl-host.c +12
-0+uint32_t target_idx; + + ctrl = cache_mem[R_CXL_HDM_DECODER0_CTRL ]; +if (!FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,COMMITTED )) { +return false; + } + + ig_enc =FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,IG ); + iw_enc =FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,IW ); + target_idx = (addr /cxl_decode_ig (ig_enc)) % (1 << iw_enc); + +if (target_idx >4 ) {...in this half of the
if()target_idxis at least 5...
Quoted 5 lines
hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 121
Quoted 2 lines
hw/cxl/cxl-host.c +2
-0+ target_reg = cache_mem[R_CXL_HDM_DECODER0_TARGET_LIST_LO ]; + target_reg >>= target_idx *8 ;...but 5 * 8 is 40, so this shift will always be undefined behaviour. Was the
if()condition intended to be "< 4" ?
Spot on.
Quoted 6 lines
hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 123
Quoted 3 lines
hw/cxl/cxl-host.c +2
-0+ }else { + target_reg = cache_mem[R_CXL_HDM_DECODER0_TARGET_LIST_LO ];Was this (or the other one) intended to be ...LIST_HI ?
Also correct.
Quoted 15 lines
Quoted 1 line
+
target_reg>>= (target_idx- 4) * 8;Not noticed by Coverity, but in this half of the
if(),target_idxis 4 or less, so (target_idx- 4) is in most cases going to be negative, which isn't a valid shift amount. This also suggests theif()condition is wrong.hw/cxl/cxl-host.c void cxl_fixed_memory_window_link_targets(Error **errp) · line 129
Quoted 5 lines
hw/cxl/cxl-host.c +5
-0+ } + *target = target_reg &0xff ; + +return true; +}What's the intended behaviour here ?
Quoted 2 lines
The code appears to be attempting to extract a particular subfield from one or other of the cache_mem[] values.
The two registers each have 4 target port numbers stored in them. This was supposed to get the right one. Tests weren't exercising greater than 4 as that requires a very flat hierarchy and doesn't exercise some other paths as can't interleave so wide at multiple levels. Oh well, clearly need
an extra test.
Quoted 4 lines
I would
recommend usingextract32()for this rather than raw shift and mask operations -- it's generally easier to write and to review.
Will do.
Unfortunately I've run into an issue testing with
a single host bridge and 8 root ports. Need to pin down if it is a kernel or qemu issue before sending out this fix. I'm away for the next week though so may have to get back to this after returning.
Sorry for the delay.
Thanks,
Jonathan
Quoted 3 lines
thanks
-- PMM
[PULL v2 53/86] intel-iommu: remove VTD_FR_RESERVED_ERR
In reply to Michael S. TsirkinFrom: Jason Wang <[email protected]>
This fault reason is not used and is duplicated with SPT.2 condition code. So let's remove it.
Message-Id: <[email protected]>
--- hw/i386/intel_iommu_internal.h | 5 ----- hw/i386/intel_iommu.c | 6 ------ 2 files changed, 11 deletions(-)
hw/i386/intel_iommu_internal.h +0 -5
@@ -304,11 +304,6 @@ typedef enum VTDFaultReason {VTD_FR_PASID_TABLE_INV =0x58 ,/*Invalid PASID table entry */ -/* This is not a normal fault reason. We use this to indicate some faults -* that are not referenced by the VT-d specification. -* Fault event with such reason should not be recorded. -*/ -VTD_FR_RESERVED_ERR ,VTD_FR_MAX ,/* Guard */ } VTDFaultReason;
hw/i386/intel_iommu.c +0 -6
@@ -469,11 +469,6 @@ static void vtd_report_dmar_fault(IntelIOMMUState *s, uint16_t source_id,assert (fault <VTD_FR_MAX ); -if (fault ==VTD_FR_RESERVED_ERR ) { -/* This is not a normal fault reason case. Drop it. */ -return ; - } -trace_vtd_dmar_fault (source_id, fault, addr, is_write);if (fsts_reg &VTD_FSTS_PFO ) {
@@ -1637,7 +1632,6 @@ static const bool vtd_qualified_faults[] = { [VTD_FR_PAGING_ENTRY_RSVD] = true, [VTD_FR_CONTEXT_ENTRY_TT] = true, [VTD_FR_PASID_TABLE_INV] = false, - [VTD_FR_RESERVED_ERR] = false, [VTD_FR_MAX] = false, };
Signature · 1 line
MST
[PULL v2 40/86] tests/acpi: Add tables for CXL emulation.
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Tables that differ from normal Q35 tables when running the CXL test.
Message-Id: <[email protected]>
--- tests/qtest/bios-tables-test-allowed-diff.h | 2 -- tests/data/acpi/q35/CEDT.cxl | Bin 0 -> 184 bytes tests/data/acpi/q35/DSDT.cxl | Bin 0 -> 9615 bytes 3 files changed, 2 deletions(-)
tests/qtest/bios-tables-test-allowed-diff.h +0 -2
@@ -1,3 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/q35/DSDT.cxl" , -"tests/data/acpi/q35/CEDT.cxl",
tests/data/acpi/q35/CEDT.cxl binary +0 -0
tests/data/acpi/q35/DSDT.cxl binary +0 -0
Signature · 1 line
MST
[PULL v2 79/86] virtio-net: setup vhost_dev and notifiers for cvq only when feature is negotiated
In reply to Michael S. TsirkinFrom: Si-Wei Liu <[email protected]>
When the control virtqueue feature is absent or not negotiated, vhost_net_start() still tries to set up vhost_dev and install vhost notifiers for the control virtqueue, which results in erroneous ioctl calls with incorrect queue index sending down to driver. Do that only when needed.
Message-Id: <[email protected]>
--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +2 -1
@@ -245,7 +245,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)VirtIODevice *vdev =VIRTIO_DEVICE (n);NetClientState *nc =qemu_get_queue (n->nic);int queue_pairs = n->multiqueue ? n->max_queue_pairs :1 ; -int cvq = n->max_ncs - n->max_queue_pairs; +int cvq =virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ ) ? + n->max_ncs - n->max_queue_pairs :0 ;if (!get_vhost_net (nc->peer)) {return ;
Signature · 1 line
MST
[PULL v2 39/86] qtests/bios-tables-test: Add a test for CXL emulation.
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
The DSDT includes several CXL specific elements and the CEDT table is only present if we enable CXL.
The test exercises all current functionality with several CFMWS, CHBS structures in CEDT and ACPI0016/ACPI00017 and _OSC entries in DSDT.
Message-Id: <[email protected]>
--- tests/qtest/bios-tables-test.c | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
tests/qtest/bios-tables-test.c +44 -0
@@ -1536,6 +1536,49 @@ static void test_acpi_q35_viot(void)free_test_data (&data); } +static void test_acpi_q35_cxl (void ) +{ +gchar *tmp_path =g_dir_make_tmp ("qemu-test-cxl.XXXXXX" ,NULL ); +gchar *params; + +test_data data = { + .machine =MACHINE_Q35 , + .variant =".cxl" , + }; +/* +* A complex CXL setup. +*/ + params =g_strdup_printf (" -machine cxl=on" +" -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M" +" -object memory-backend-file,id=cxl-mem2,mem-path=%s,size=256M" +" -object memory-backend-file,id=cxl-mem3,mem-path=%s,size=256M" +" -object memory-backend-file,id=cxl-mem4,mem-path=%s,size=256M" +" -object memory-backend-file,id=lsa1,mem-path=%s,size=256M" +" -object memory-backend-file,id=lsa2,mem-path=%s,size=256M" +" -object memory-backend-file,id=lsa3,mem-path=%s,size=256M" +" -object memory-backend-file,id=lsa4,mem-path=%s,size=256M" +" -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1" +" -device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2" +" -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2" +" -device cxl-type3,bus=rp1,memdev=cxl-mem1,lsa=lsa1" +" -device cxl-rp,port=1,bus=cxl.1,id=rp2,chassis=0,slot=3" +" -device cxl-type3,bus=rp2,memdev=cxl-mem2,lsa=lsa2" +" -device cxl-rp,port=0,bus=cxl.2,id=rp3,chassis=0,slot=5" +" -device cxl-type3,bus=rp3,memdev=cxl-mem3,lsa=lsa3" +" -device cxl-rp,port=1,bus=cxl.2,id=rp4,chassis=0,slot=6" +" -device cxl-type3,bus=rp4,memdev=cxl-mem4,lsa=lsa4" +" -cxl-fixed-memory-window targets.0=cxl.1,size=4G,interleave-granularity=8k" +" -cxl-fixed-memory-window targets.0=cxl.1,targets.1=cxl.2,size=4G,interleave-granularity=8k" , + tmp_path, tmp_path, tmp_path, tmp_path, + tmp_path, tmp_path, tmp_path, tmp_path); +test_acpi_one (params, &data); + +g_free (params); +g_assert (g_rmdir (tmp_path) ==0 ); +g_free (tmp_path); +free_test_data (&data); +} +static void test_acpi_virt_viot (void ) {test_data data = {
@@ -1741,6 +1784,7 @@ int main(int argc, char *argv[])qtest_add_func ("acpi/q35/kvm/dmar" , test_acpi_q35_kvm_dmar); }qtest_add_func ("acpi/q35/viot" , test_acpi_q35_viot); +qtest_add_func ("acpi/q35/cxl" , test_acpi_q35_cxl);qtest_add_func ("acpi/q35/slic" , test_acpi_q35_slic); }else if (strcmp (arch,"aarch64" ) ==0 ) {if (has_tcg) {
Signature · 1 line
MST
[PULL v2 61/86] docs: vhost-user: clean up request/reply description
In reply to Michael S. TsirkinFrom: Paolo Bonzini <[email protected]>
It is not necessary to mention which side is sending/receiving each payload; it is more interesting to say which is the request and which is the reply. This also matches what vhost-user-gpu.rst already does.
While at it, ensure that all messages list both the request and the reply payload.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- docs/interop/vhost-user.rst | 163 +++++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 68 deletions(-)
docs/interop/vhost-user.rst +95 -68
@@ -866,8 +866,8 @@ Master message types ``VHOST_USER_GET_FEATURES`` :id: 1 :equivalent ioctl: ``VHOST_GET_FEATURES`` - :master payload: N/A - :slave payload: ``u64`` + :request payload: N/A + :reply payload: ``u64`` Get from the underlying vhost implementation the features bitmask. Feature bit ``VHOST_USER_F_PROTOCOL_FEATURES`` signals slave support
@@ -877,7 +877,8 @@ Master message types ``VHOST_USER_SET_FEATURES`` :id: 2 :equivalent ioctl: ``VHOST_SET_FEATURES`` - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A Enable features in the underlying vhost implementation using a bitmask. Feature bit ``VHOST_USER_F_PROTOCOL_FEATURES`` signals
@@ -887,8 +888,8 @@ Master message types ``VHOST_USER_GET_PROTOCOL_FEATURES`` :id: 15 :equivalent ioctl: ``VHOST_GET_FEATURES`` - :master payload: N/A - :slave payload: ``u64`` + :request payload: N/A + :reply payload: ``u64`` Get the protocol feature bitmask from the underlying vhost implementation. Only legal if feature bit
@@ -903,7 +904,8 @@ Master message types ``VHOST_USER_SET_PROTOCOL_FEATURES`` :id: 16 :equivalent ioctl: ``VHOST_SET_FEATURES`` - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A Enable protocol features in the underlying vhost implementation.
@@ -917,7 +919,8 @@ Master message types ``VHOST_USER_SET_OWNER`` :id: 3 :equivalent ioctl: ``VHOST_SET_OWNER`` - :master payload: N/A + :request payload: N/A + :reply payload: N/A Issued when a new connection is established. It sets the current *master* as an owner of the session. This can be used on the *slave*
@@ -925,7 +928,8 @@ Master message types ``VHOST_USER_RESET_OWNER`` :id: 4 - :master payload: N/A + :request payload: N/A + :reply payload: N/A .. admonition:: Deprecated
@@ -938,8 +942,8 @@ Master message types ``VHOST_USER_SET_MEM_TABLE`` :id: 5 :equivalent ioctl: ``VHOST_SET_MEM_TABLE`` - :master payload: memory regions description - :slave payload: (postcopy only) memory regions description + :request payload: memory regions description + :reply payload: (postcopy only) memory regions description Sets the memory map regions on the slave so it can translate the vring addresses. In the ancillary data there is an array of file
@@ -962,8 +966,8 @@ Master message types ``VHOST_USER_SET_LOG_BASE`` :id: 6 :equivalent ioctl: ``VHOST_SET_LOG_BASE`` - :master payload: u64 - :slave payload: N/A + :request payload: u64 + :reply payload: N/A Sets logging shared memory space.
@@ -975,44 +979,48 @@ Master message types ``VHOST_USER_SET_LOG_FD`` :id: 7 :equivalent ioctl: ``VHOST_SET_LOG_FD`` - :master payload: N/A + :request payload: N/A + :reply payload: N/A Sets the logging file descriptor, which is passed as ancillary data. ``VHOST_USER_SET_VRING_NUM`` :id: 8 :equivalent ioctl: ``VHOST_SET_VRING_NUM`` - :master payload: vring state description + :request payload: vring state description + :reply payload: N/A Set the size of the queue. ``VHOST_USER_SET_VRING_ADDR`` :id: 9 :equivalent ioctl: ``VHOST_SET_VRING_ADDR`` - :master payload: vring address description - :slave payload: N/A + :request payload: vring address description + :reply payload: N/A Sets the addresses of the different aspects of the vring. ``VHOST_USER_SET_VRING_BASE`` :id: 10 :equivalent ioctl: ``VHOST_SET_VRING_BASE`` - :master payload: vring state description + :request payload: vring state description + :reply payload: N/A Sets the base offset in the available vring. ``VHOST_USER_GET_VRING_BASE`` :id: 11 :equivalent ioctl: ``VHOST_USER_GET_VRING_BASE`` - :master payload: vring state description - :slave payload: vring state description + :request payload: vring state description + :reply payload: vring state description Get the available vring base offset. ``VHOST_USER_SET_VRING_KICK`` :id: 12 :equivalent ioctl: ``VHOST_SET_VRING_KICK`` - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A Set the event file descriptor for adding buffers to the vring. It is passed in the ancillary data.
@@ -1030,7 +1038,8 @@ Master message types ``VHOST_USER_SET_VRING_CALL`` :id: 13 :equivalent ioctl: ``VHOST_SET_VRING_CALL`` - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A Set the event file descriptor to signal when buffers are used. It is passed in the ancillary data.
@@ -1048,7 +1057,8 @@ Master message types ``VHOST_USER_SET_VRING_ERR`` :id: 14 :equivalent ioctl: ``VHOST_SET_VRING_ERR`` - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A Set the event file descriptor to signal when error occurs. It is passed in the ancillary data.
@@ -1065,8 +1075,8 @@ Master message types ``VHOST_USER_GET_QUEUE_NUM`` :id: 17 :equivalent ioctl: N/A - :master payload: N/A - :slave payload: u64 + :request payload: N/A + :reply payload: u64 Query how many queues the backend supports.
@@ -1077,7 +1087,8 @@ Master message types ``VHOST_USER_SET_VRING_ENABLE`` :id: 18 :equivalent ioctl: N/A - :master payload: vring state description + :request payload: vring state description + :reply payload: N/A Signal slave to enable or disable corresponding vring.
@@ -1087,7 +1098,8 @@ Master message types ``VHOST_USER_SEND_RARP`` :id: 19 :equivalent ioctl: N/A - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A Ask vhost user backend to broadcast a fake RARP to notify the migration is terminated for guest that does not support GUEST_ANNOUNCE.
@@ -1102,7 +1114,8 @@ Master message types ``VHOST_USER_NET_SET_MTU`` :id: 20 :equivalent ioctl: N/A - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A Set host MTU value exposed to the guest.
@@ -1119,7 +1132,8 @@ Master message types ``VHOST_USER_SET_SLAVE_REQ_FD`` :id: 21 :equivalent ioctl: N/A - :master payload: N/A + :request payload: N/A + :reply payload: N/A Set the socket file descriptor for slave initiated requests. It is passed in the ancillary data.
@@ -1134,8 +1148,8 @@ Master message types ``VHOST_USER_IOTLB_MSG`` :id: 22 :equivalent ioctl: N/A (equivalent to ``VHOST_IOTLB_MSG`` message type) - :master payload: ``struct vhost_iotlb_msg`` - :slave payload: ``u64`` + :request payload: ``struct vhost_iotlb_msg`` + :reply payload: ``u64`` Send IOTLB messages with ``struct vhost_iotlb_msg`` as payload.
@@ -1149,7 +1163,8 @@ Master message types ``VHOST_USER_SET_VRING_ENDIAN`` :id: 23 :equivalent ioctl: ``VHOST_SET_VRING_ENDIAN`` - :master payload: vring state description + :request payload: vring state description + :reply payload: N/A Set the endianness of a VQ for legacy devices. Little-endian is indicated with state.num set to 0 and big-endian is indicated with
@@ -1164,8 +1179,8 @@ Master message types ``VHOST_USER_GET_CONFIG`` :id: 24 :equivalent ioctl: N/A - :master payload: virtio device config space - :slave payload: virtio device config space + :request payload: virtio device config space + :reply payload: virtio device config space When ``VHOST_USER_PROTOCOL_F_CONFIG`` is negotiated, this message is submitted by the vhost-user master to fetch the contents of the
@@ -1178,8 +1193,8 @@ Master message types ``VHOST_USER_SET_CONFIG`` :id: 25 :equivalent ioctl: N/A - :master payload: virtio device config space - :slave payload: N/A + :request payload: virtio device config space + :reply payload: N/A When ``VHOST_USER_PROTOCOL_F_CONFIG`` is negotiated, this message is submitted by the vhost-user master when the Guest changes the virtio
@@ -1191,8 +1206,8 @@ Master message types ``VHOST_USER_CREATE_CRYPTO_SESSION`` :id: 26 :equivalent ioctl: N/A - :master payload: crypto session description - :slave payload: crypto session description + :request payload: crypto session description + :reply payload: crypto session description Create a session for crypto operation. The server side must return the session id, 0 or positive for success, negative for failure.
@@ -1204,7 +1219,8 @@ Master message types ``VHOST_USER_CLOSE_CRYPTO_SESSION`` :id: 27 :equivalent ioctl: N/A - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A Close a session for crypto operation which was previously created by ``VHOST_USER_CREATE_CRYPTO_SESSION``.
@@ -1216,8 +1232,8 @@ Master message types ``VHOST_USER_POSTCOPY_ADVISE`` :id: 28 - :master payload: N/A - :slave payload: userfault fd + :request payload: N/A + :reply payload: userfault fd When ``VHOST_USER_PROTOCOL_F_PAGEFAULT`` is supported, the master advises slave that a migration with postcopy enabled is underway,
@@ -1226,7 +1242,8 @@ Master message types ``VHOST_USER_POSTCOPY_LISTEN`` :id: 29 - :master payload: N/A + :request payload: N/A + :reply payload: N/A Master advises slave that a transition to postcopy mode has happened. The slave must ensure that shared memory is registered
@@ -1237,10 +1254,11 @@ Master message types ``VHOST_USER_POSTCOPY_END`` :id: 30 - :slave payload: ``u64`` + :request payload: N/A + :reply payload: ``u64`` Master advises that postcopy migration has now completed. The slave - must disable the userfaultfd. The response is an acknowledgement + must disable the userfaultfd. The reply is an acknowledgement only. When ``VHOST_USER_PROTOCOL_F_PAGEFAULT`` is supported, this message
@@ -1252,7 +1270,8 @@ Master message types ``VHOST_USER_GET_INFLIGHT_FD`` :id: 31 :equivalent ioctl: N/A - :master payload: inflight description + :request payload: inflight description + :reply payload: N/A When ``VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD`` protocol feature has been successfully negotiated, this message is submitted by master to
@@ -1263,7 +1282,8 @@ Master message types ``VHOST_USER_SET_INFLIGHT_FD`` :id: 32 :equivalent ioctl: N/A - :master payload: inflight description + :request payload: inflight description + :reply payload: N/A When ``VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD`` protocol feature has been successfully negotiated, this message is submitted by master to
@@ -1273,7 +1293,8 @@ Master message types ``VHOST_USER_GPU_SET_SOCKET`` :id: 33 :equivalent ioctl: N/A - :master payload: N/A + :request payload: N/A + :reply payload: N/A Sets the GPU protocol socket file descriptor, which is passed as ancillary data. The GPU protocol is used to inform the master of
@@ -1282,8 +1303,8 @@ Master message types ``VHOST_USER_RESET_DEVICE`` :id: 34 :equivalent ioctl: N/A - :master payload: N/A - :slave payload: N/A + :request payload: N/A + :reply payload: N/A Ask the vhost user backend to disable all rings and reset all internal device state to the initial state, ready to be
@@ -1296,8 +1317,8 @@ Master message types ``VHOST_USER_VRING_KICK`` :id: 35 :equivalent ioctl: N/A - :slave payload: vring state description - :master payload: N/A + :request payload: vring state description + :reply payload: N/A When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol feature has been successfully negotiated, this message may be
@@ -1310,7 +1331,8 @@ Master message types ``VHOST_USER_GET_MAX_MEM_SLOTS`` :id: 36 :equivalent ioctl: N/A - :slave payload: u64 + :request payload: N/A + :reply payload: u64 When the ``VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS`` protocol feature has been successfully negotiated, this message is submitted
@@ -1323,7 +1345,8 @@ Master message types ``VHOST_USER_ADD_MEM_REG`` :id: 37 :equivalent ioctl: N/A - :slave payload: single memory region description + :request payload: N/A + :reply payload: single memory region description When the ``VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS`` protocol feature has been successfully negotiated, this message is submitted
@@ -1346,7 +1369,8 @@ Master message types ``VHOST_USER_REM_MEM_REG`` :id: 38 :equivalent ioctl: N/A - :slave payload: single memory region description + :request payload: N/A + :reply payload: single memory region description When the ``VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS`` protocol feature has been successfully negotiated, this message is submitted
@@ -1369,8 +1393,8 @@ Master message types ``VHOST_USER_SET_STATUS`` :id: 39 :equivalent ioctl: VHOST_VDPA_SET_STATUS - :slave payload: N/A - :master payload: ``u64`` + :request payload: ``u64`` + :reply payload: N/A When the ``VHOST_USER_PROTOCOL_F_STATUS`` protocol feature has been successfully negotiated, this message is submitted by the master to
@@ -1380,8 +1404,8 @@ Master message types ``VHOST_USER_GET_STATUS`` :id: 40 :equivalent ioctl: VHOST_VDPA_GET_STATUS - :slave payload: ``u64`` - :master payload: N/A + :request payload: N/A + :reply payload: ``u64`` When the ``VHOST_USER_PROTOCOL_F_STATUS`` protocol feature has been successfully negotiated, this message is submitted by the master to
@@ -1392,11 +1416,14 @@ Master message types Slave message types ------------------- +For this type of message, the request is sent by the slave and the reply +is sent by the master. + ``VHOST_USER_SLAVE_IOTLB_MSG`` :id: 1 :equivalent ioctl: N/A (equivalent to ``VHOST_IOTLB_MSG`` message type) - :slave payload: ``struct vhost_iotlb_msg`` - :master payload: N/A + :request payload: ``struct vhost_iotlb_msg`` + :reply payload: N/A Send IOTLB messages with ``struct vhost_iotlb_msg`` as payload. Slave sends such requests to notify of an IOTLB miss, or an IOTLB
@@ -1410,8 +1437,8 @@ Slave message types ``VHOST_USER_SLAVE_CONFIG_CHANGE_MSG`` :id: 2 :equivalent ioctl: N/A - :slave payload: N/A - :master payload: N/A + :request payload: N/A + :reply payload: N/A When ``VHOST_USER_PROTOCOL_F_CONFIG`` is negotiated, vhost-user slave sends such messages to notify that the virtio device's
@@ -1425,8 +1452,8 @@ Slave message types ``VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG`` :id: 3 :equivalent ioctl: N/A - :slave payload: vring area description - :master payload: N/A + :request payload: vring area description + :reply payload: N/A Sets host notifier for a specified queue. The queue index is contained in the ``u64`` field of the vring area description. The
@@ -1448,8 +1475,8 @@ Slave message types ``VHOST_USER_SLAVE_VRING_CALL`` :id: 4 :equivalent ioctl: N/A - :slave payload: vring state description - :master payload: N/A + :request payload: vring state description + :reply payload: N/A When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol feature has been successfully negotiated, this message may be
@@ -1462,8 +1489,8 @@ Slave message types ``VHOST_USER_SLAVE_VRING_ERR`` :id: 5 :equivalent ioctl: N/A - :slave payload: vring state description - :master payload: N/A + :request payload: vring state description + :reply payload: N/A When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol feature has been successfully negotiated, this message may be
@@ -1489,7 +1516,7 @@ client MUST respond with a Payload ``VhostUserMsg`` indicating success or failure. The payload should be set to zero on success or non-zero on failure, unless the message already has an explicit reply body. -The response payload gives QEMU a deterministic indication of the result +The reply payload gives QEMU a deterministic indication of the result of the command. Today, QEMU is expected to terminate the main vhost-user loop upon receiving such errors. In future, qemu could be taught to be more resilient for selective requests.
Signature · 1 line
MST
[PULL v2 45/86] vdpa: Fix bad index calculus at vhost_vdpa_get_vring_base
In reply to Michael S. TsirkinFrom: Eugenio Pérez <[email protected]>
Message-Id: <[email protected]>
--- hw/virtio/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost-vdpa.c +2 -2
@@ -1172,11 +1172,11 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) {struct vhost_vdpa *v = dev->opaque; +int vdpa_idx = ring->index - dev->vq_index;int ret;if (v->shadow_vqs_enabled) { -VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, - ring->index); +VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, vdpa_idx);/* * Setting base as last used idx, so destination will see as available
Signature · 1 line
MST
[PULL v2 41/86] qtest/cxl: Add more complex test cases with CFMWs
In reply to Michael S. TsirkinFrom: Ben Widawsky <[email protected]>
Add CXL Fixed Memory Windows to the CXL tests.
Message-Id: <[email protected]>
--- tests/qtest/cxl-test.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tests/qtest/cxl-test.c +5 -3
@@ -9,11 +9,13 @@#include "libqtest-single.h" #define QEMU_PXB_CMD "-machine q35,cxl=on " \ - "-device pxb-cxl,id=cxl.0,bus=pcie.0,bus_nr=52 " + "-device pxb-cxl,id=cxl.0,bus=pcie.0,bus_nr=52 " \ + "-cxl-fixed-memory-window targets.0=cxl.0,size=4G " -#define QEMU_2PXB_CMD "-machine q35,cxl=on " \ +#define QEMU_2PXB_CMD "-machine q35,cxl=on " \ "-device pxb-cxl,id=cxl.0,bus=pcie.0,bus_nr=52 " \ - "-device pxb-cxl,id=cxl.1,bus=pcie.0,bus_nr=53 " + "-device pxb-cxl,id=cxl.1,bus=pcie.0,bus_nr=53 " \ + "-cxl-fixed-memory-window targets.0=cxl.0,targets.1=cxl.1,size=4G "#define QEMU_RP "-device cxl-rp,id=rp0,bus=cxl.0,chassis=0,slot=0 "
Signature · 1 line
MST
[PULL v2 83/86] vhost-vdpa: backend feature should set only once
In reply to Michael S. TsirkinFrom: Si-Wei Liu <[email protected]>
The vhost_vdpa_one_time_request() branch in vhost_vdpa_set_backend_cap() incorrectly sends down ioctls on vhost_dev with non-zero index. This may end up with multiple VHOST_SET_BACKEND_FEATURES ioctl calls sent down on the vhost-vdpa fd that is shared between all these vhost_dev's.
To fix it, send down ioctl only once via the first vhost_dev with index 0. Toggle the polarity of the vhost_vdpa_one_time_request() test should do the trick.
Message-Id: <[email protected]>
--- hw/virtio/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +1 -1
@@ -667,7 +667,7 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) features &= f; -if (vhost_vdpa_one_time_request (dev)) { +if (!vhost_vdpa_one_time_request (dev)) { r =vhost_vdpa_call (dev,VHOST_SET_BACKEND_FEATURES , &features);if (r) {return -EFAULT ;
Signature · 1 line
MST
[PULL v2 54/86] intel-iommu: block output address in interrupt address range
In reply to Michael S. TsirkinFrom: Jason Wang <[email protected]>
According to vtd spec v3.3 3.14:
"""
Software must not program paging-structure entries to remap any address to the interrupt address range. Untranslated requests and translation requests that result in an address in the interrupt range will be blocked with condition code LGN.4 or SGN.8.
"""
This patch blocks the request that result in interrupt address range.
Message-Id: <[email protected]>
--- hw/i386/intel_iommu_internal.h | 4 ++++ hw/i386/intel_iommu.c | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +4 -0
@@ -289,6 +289,8 @@ typedef enum VTDFaultReason {* context-entry. */ VTD_FR_CONTEXT_ENTRY_TT , +/* Output address in the interrupt address range */ +VTD_FR_INTERRUPT_ADDR =0xE ,/* Interrupt remapping transition faults */ VTD_FR_IR_REQ_RSVD = 0x20, /* One or more IR request reserved
@@ -304,6 +306,8 @@ typedef enum VTDFaultReason {VTD_FR_PASID_TABLE_INV =0x58 ,/*Invalid PASID table entry */ +/* Output address in the interrupt address range for scalable mode */ +VTD_FR_SM_INTERRUPT_ADDR =0x87 ,VTD_FR_MAX ,/* Guard */ } VTDFaultReason;
hw/i386/intel_iommu.c +26 -1
@@ -1020,6 +1020,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce,uint32_t offset;uint64_t slpte;uint64_t access_right_check; +uint64_t xlat, size;if (!vtd_iova_range_check (s, iova, ce, aw_bits)) { error_report_once("%s: detected IOVA overflow (iova=0x%" PRIx64 ")",
@@ -1064,11 +1065,33 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce,if (vtd_is_last_slpte (slpte, level)) { *slptep = slpte; *slpte_level = level; -return 0 ; +break ; } addr =vtd_get_slpte_addr (slpte, aw_bits); level--; } + + xlat =vtd_get_slpte_addr (*slptep, aw_bits); + size = ~vtd_slpt_level_page_mask (level) +1 ; + +/* +* From VT-d spec 3.14: Untranslated requests and translation +* requests that result in an address in the interrupt range will be +* blocked with condition code LGN.4 or SGN.8. +*/ +if ((xlat >VTD_INTERRUPT_ADDR_LAST || + xlat + size -1 <VTD_INTERRUPT_ADDR_FIRST )) { +return 0 ; + }else { +error_report_once ("%s: xlat address is in interrupt range " +"(iova=0x%" PRIx64", level=0x%" PRIx32", " +"slpte=0x%" PRIx64", write=%d, " +"xlat=0x%" PRIx64", size=0x%" PRIx64")" , + __func__, iova, level, slpte, is_write, + xlat, size); +return s->scalable_mode ? -VTD_FR_SM_INTERRUPT_ADDR : + -VTD_FR_INTERRUPT_ADDR ; + } }typedef int (*vtd_page_walk_hook )(IOMMUTLBEvent *event,void *private);
@@ -1628,10 +1651,12 @@ static const bool vtd_qualified_faults[] = { [VTD_FR_PAGING_ENTRY_INV] = true, [VTD_FR_ROOT_TABLE_INV] = false, [VTD_FR_CONTEXT_TABLE_INV] = false, + [VTD_FR_INTERRUPT_ADDR] = true, [VTD_FR_ROOT_ENTRY_RSVD] = false, [VTD_FR_PAGING_ENTRY_RSVD] = true, [VTD_FR_CONTEXT_ENTRY_TT] = true, [VTD_FR_PASID_TABLE_INV] = false, + [VTD_FR_SM_INTERRUPT_ADDR] = true, [VTD_FR_MAX] = false, };
Signature · 1 line
MST
[PULL v2 63/86] docs: vhost-user: replace master/slave with front-end/back-end
In reply to Michael S. TsirkinFrom: Paolo Bonzini <[email protected]>
This matches the nomenclature that is generally used. Also commonly used is client/server, but it is not as clear because sometimes the front-end exposes a passive (server) socket that the back-end connects to.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- docs/interop/vhost-user-gpu.rst | 10 +- docs/interop/vhost-user.rst | 350 ++++++++++++++++---------------- 2 files changed, 180 insertions(+), 180 deletions(-)
docs/interop/vhost-user-gpu.rst +5 -5
@@ -13,10 +13,10 @@ Introduction ============ The vhost-user-gpu protocol is aiming at sharing the rendering result -of a virtio-gpu, done from a vhost-user slave process to a vhost-user -master process (such as QEMU). It bears a resemblance to a display +of a virtio-gpu, done from a vhost-user back-end process to a vhost-user +front-end process (such as QEMU). It bears a resemblance to a display server protocol, if you consider QEMU as the display server and the -slave as the client, but in a very limited way. Typically, it will +back-end as the client, but in a very limited way. Typically, it will work by setting a scanout/display configuration, before sending flush events for the display updates. It will also update the cursor shape and position.
@@ -26,8 +26,8 @@ socket ancillary data to share opened file descriptors (DMABUF fds or shared memory). The socket is usually obtained via ``VHOST_USER_GPU_SET_SOCKET``. -Requests are sent by the *slave*, and the optional replies by the -*master*. +Requests are sent by the *back-end*, and the optional replies by the +*front-end*. Wire format ===========
docs/interop/vhost-user.rst +175 -175
877 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 42/86] docs/cxl: Add initial Compute eXpress Link (CXL) documentation.
In reply to Michael S. TsirkinFrom: Jonathan Cameron <[email protected]>
Provide an introduction to the main components of a CXL system, with detailed explanation of memory interleaving, example command lines and kernel configuration.
This was a challenging document to write due to the need to extract only that subset of CXL information which is relevant to either users of QEMU emulation of CXL or to those interested in the implementation. Much of CXL is concerned with specific elements of the protocol, management of memory pooling etc which is simply not relevant to what is currently planned for CXL emulation in QEMU. All comments welcome
Message-Id: <[email protected]>
--- docs/system/device-emulation.rst | 1 + docs/system/devices/cxl.rst | 302 +++++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 docs/system/devices/cxl.rst
docs/system/device-emulation.rst +1 -0
@@ -84,6 +84,7 @@ Emulated Devices devices/can.rst devices/ccid.rst + devices/cxl.rst devices/ivshmem.rst devices/net.rst devices/nvme.rst
docs/system/devices/cxl.rst new file +302 -0
302 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 60/86] hw/virtio: add vhost_user_[read|write] trace points
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
These are useful when trying to debug the initial vhost-user negotiation, especially when it hard to get logging from the low level library on the other side.
Message-Id: <[email protected]>
--- hw/virtio/vhost-user.c | 4 ++++ hw/virtio/trace-events | 2 ++ 2 files changed, 6 insertions(+)
hw/virtio/vhost-user.c +4 -0
@@ -489,6 +489,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,return ret <0 ? -saved_errno : -EIO ; } +trace_vhost_user_write (msg->hdr.request, msg->hdr.flags); +return 0 ; }
@@ -542,6 +544,8 @@ static int vhost_user_set_log_base(struct vhost_dev *dev, uint64_t base, } } +trace_vhost_user_read (msg.hdr.request, msg.hdr.flags); +return 0 ; }
hw/virtio/trace-events +2 -0
@@ -21,6 +21,8 @@ vhost_user_set_mem_table_withfd(int index, const char *name, uint64_t memory_siz vhost_user_postcopy_waker(const char *rb, uint64_t rb_offset) "%s + 0x%"PRIx64 vhost_user_postcopy_waker_found(uint64_t client_addr) "0x%"PRIx64 vhost_user_postcopy_waker_nomatch(const char *rb, uint64_t rb_offset) "%s + 0x%"PRIx64 +vhost_user_read(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" +vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" # vhost-vdpa.c vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8
Signature · 1 line
MST
[PULL v2 66/86] docs/devel: start documenting writing VirtIO devices
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
While writing my own VirtIO devices I've gotten confused with how things are structured and what sort of shared infrastructure there is. If we can document how everything is supposed to work we can then maybe start cleaning up inconsistencies in the code.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- docs/devel/index-internals.rst | 1 + docs/devel/virtio-backends.rst | 214 +++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 docs/devel/virtio-backends.rst
docs/devel/index-internals.rst +1 -0
@@ -18,3 +18,4 @@ Details about QEMU's various subsystems including how to add features to them. tracing vfio-migration writing-monitor-commands + virtio-backends
docs/devel/virtio-backends.rst new file +214 -0
214 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 47/86] hw/virtio: Replace g_memdup() by g_memdup2()
In reply to Michael S. TsirkinFrom: Philippe Mathieu-Daudé <[email protected]>
Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdup2-now/5538
The old API took the size of the memory to duplicate as a guint, whereas most memory functions take memory sizes as a gsize. This made it easy to accidentally pass a gsize to g_memdup(). For large values, that would lead to a silent truncation of the size from 64 to 32 bits, and result in a heap area being returned which is significantly smaller than what the caller expects. This can likely be exploited in various modules to cause a heap buffer overflow.
Replace g_memdup() by the safer g_memdup2() wrapper.
Message-Id: <[email protected]>
--- hw/net/virtio-net.c | 3 ++- hw/virtio/virtio-crypto.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +2 -1
@@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) } iov_cnt = elem->out_num; - iov2 = iov =g_memdup (elem->out_sg,sizeof (struct iovec ) * elem->out_num); + iov2 = iov =g_memdup2 (elem->out_sg, +sizeof (struct iovec ) * elem->out_num); s =iov_to_buf (iov, iov_cnt,0 , &ctrl,sizeof (ctrl));iov_discard_front (&iov, &iov_cnt,sizeof (ctrl));if (s !=sizeof (ctrl)) {
hw/virtio/virtio-crypto.c +3 -3
@@ -242,7 +242,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) } out_num = elem->out_num; - out_iov_copy =g_memdup (elem->out_sg,sizeof (out_iov[0 ]) * out_num); + out_iov_copy =g_memdup2 (elem->out_sg,sizeof (out_iov[0 ]) * out_num); out_iov = out_iov_copy; in_num = elem->in_num;
@@ -605,11 +605,11 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) } out_num = elem->out_num; - out_iov_copy =g_memdup (elem->out_sg,sizeof (out_iov[0 ]) * out_num); + out_iov_copy =g_memdup2 (elem->out_sg,sizeof (out_iov[0 ]) * out_num); out_iov = out_iov_copy; in_num = elem->in_num; - in_iov_copy =g_memdup (elem->in_sg,sizeof (in_iov[0 ]) * in_num); + in_iov_copy =g_memdup2 (elem->in_sg,sizeof (in_iov[0 ]) * in_num); in_iov = in_iov_copy; if (unlikely(iov_to_buf(out_iov, out_num, 0, &req, sizeof(req))
Signature · 1 line
MST
[PULL v2 68/86] hw/virtio/vhost-user: don't suppress F_CONFIG when supported
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
Previously we would silently suppress VHOST_USER_PROTOCOL_F_CONFIG during the protocol negotiation if the QEMU stub hadn't implemented the vhost_dev_config_notifier. However this isn't the only way we can handle config messages, the existing vdc->get/set_config can do this as well.
Lightly re-factor the code to check for both potential methods and instead of silently squashing the feature error out. It is unlikely that a vhost-user backend expecting to handle CONFIG messages will behave correctly if they never get sent.
Message-Id: <[email protected]>
--- include/hw/virtio/vhost-user.h | 1 + hw/scsi/vhost-user-scsi.c | 1 + hw/virtio/vhost-user.c | 44 ++++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 12 deletions(-)
include/hw/virtio/vhost-user.h +1 -0
@@ -22,6 +22,7 @@ typedef struct VhostUserState {CharBackend *chr;VhostUserHostNotifier notifier[VIRTIO_QUEUE_MAX ];int memory_slots; +bool supports_config; } VhostUserState;bool vhost_user_init (VhostUserState *user,CharBackend *chr,Error **errp);
hw/scsi/vhost-user-scsi.c +1 -0
@@ -121,6 +121,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) vsc->dev.backend_features =0 ; vqs = vsc->dev.vqs; + s->vhost_user.supports_config = true; ret =vhost_dev_init (&vsc->dev, &s->vhost_user,VHOST_BACKEND_TYPE_USER ,0 , errp);if (ret <0 ) {
hw/virtio/vhost-user.c +32 -12
71 lines not on this page · raw message
Signature · 1 line
MST
[PULL v2 57/86] vhost_net: Print feature masks in hex
In reply to Michael S. TsirkinFrom: Ilya Maximets <[email protected]>
"0x200000000" is much more readable than "8589934592". The change saves one step (conversion) while debugging.
Message-Id: <[email protected]>
--- hw/net/vhost_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/net/vhost_net.c +2 -2
@@ -201,7 +201,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) net->dev.features &= ~(1ULL <<VIRTIO_NET_F_MRG_RXBUF ); }if (~net->dev.features & net->dev.backend_features) { -fprintf (stderr,"vhost lacks feature mask %" PRIu64 +fprintf (stderr,"vhost lacks feature mask 0x%" PRIx64" for backend\n" , (uint64_t )(~net->dev.features & net->dev.backend_features)); goto fail;
@@ -213,7 +213,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)if (net->nc->info->type ==NET_CLIENT_DRIVER_VHOST_USER ) { features =vhost_user_get_acked_features (net->nc);if (~net->dev.features & features) { -fprintf (stderr,"vhost lacks feature mask %" PRIu64 +fprintf (stderr,"vhost lacks feature mask 0x%" PRIx64" for backend\n" , (uint64_t )(~net->dev.features & features)); goto fail;
Signature · 1 line
MST
[PULL v2 65/86] libvhost-user: expose vu_request_to_string
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
This is useful for more human readable debug messages in vhost-user programs.
Message-Id: <[email protected]>
--- subprojects/libvhost-user/libvhost-user.h | 9 +++++++++ subprojects/libvhost-user/libvhost-user.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.h +9 -0
@@ -473,6 +473,15 @@ bool vu_init(VuDev *dev,*/ void vu_deinit (VuDev *dev); + +/** +* vu_request_to_string: return string for vhost message request +* @req: VhostUserMsg request +* +* Returns a const string, do not free. +*/ +const char *vu_request_to_string (unsigned int req); +/** * vu_dispatch: * @dev: a VuDev context
subprojects/libvhost-user/libvhost-user.c +1 -1
@@ -99,7 +99,7 @@ static inline bool vu_has_protocol_feature(VuDev *dev, unsigned int fbit)return has_feature (dev->protocol_features, fbit); } -static const char * +const char *vu_request_to_string (unsigned int req) {#define REQ (req) [req] = #req
Signature · 1 line
MST
[PULL v2 72/86] vhost-user: more master/slave things
In reply to Michael S. Tsirkinwe switched to front-end/back-end, but newer patches reintroduced old language. Fix this up.
--- docs/interop/vhost-user.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
docs/interop/vhost-user.rst +1 -1
@@ -340,7 +340,7 @@ drivers cannot negotiate it. This reserved feature bit was reused by the vhost-user protocol to add vhost-user protocol feature negotiation in a backwards compatible -fashion. Old vhost-user master and slave implementations continue to +fashion. Old vhost-user front-end and back-end implementations continue to work even though they are not aware of vhost-user protocol feature negotiation.
Signature · 1 line
MST
[PULL v2 59/86] virtio-pci: add notification trace points
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- hw/virtio/virtio-pci.c | 3 +++ hw/virtio/trace-events | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +3 -0
@@ -38,6 +38,7 @@#include "hw/virtio/virtio-bus.h" #include "qapi/visitor.h" #include "sysemu/replay.h" +#include "trace.h" #define VIRTIO_PCI_REGION_SIZE (dev) VIRTIO_PCI_CONFIG_OFF(msix_present(dev))
@@ -1380,6 +1381,7 @@ static void virtio_pci_notify_write(void *opaque, hwaddr addr,unsigned queue = addr /virtio_pci_queue_mem_mult (proxy);if (vdev !=NULL && queue <VIRTIO_QUEUE_MAX ) { +trace_virtio_pci_notify_write (addr, val, size);virtio_queue_notify (vdev, queue); } }
@@ -1393,6 +1395,7 @@ static void virtio_pci_notify_write_pio(void *opaque, hwaddr addr,unsigned queue = val;if (vdev !=NULL && queue <VIRTIO_QUEUE_MAX ) { +trace_virtio_pci_notify_write_pio (addr, val, size);virtio_queue_notify (vdev, queue); } }
hw/virtio/trace-events +6 -1
@@ -89,7 +89,12 @@ virtio_mmio_guest_page(uint64_t size, int shift) "guest page size 0x%" PRIx64 " virtio_mmio_queue_write(uint64_t value, int max_size) "mmio_queue write 0x%" PRIx64 " max %d" virtio_mmio_setting_irq(int level) "virtio_mmio setting IRQ %d" -# virtio-iommu.c +# virtio-pci.c +virtio_pci_notify(uint16_t vector) "virtio_pci_notify vec 0x%x" +virtio_pci_notify_write(uint64_t addr, uint64_t val, unsigned int size) "0x%" PRIx64" = 0x%" PRIx64 " (%d)" +virtio_pci_notify_write_pio(uint64_t addr, uint64_t val, unsigned int size) "0x%" PRIx64" = 0x%" PRIx64 " (%d)" + +# hw/virtio/virtio-iommu.c virtio_iommu_device_reset(void) "reset!" virtio_iommu_system_reset(void) "system reset!" virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx64
Signature · 1 line
MST
[PULL v2 67/86] include/hw: start documenting the vhost API
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
While trying to get my head around the nest of interactions for vhost devices I though I could start by documenting the key API functions. This patch documents the main API hooks for creating and starting a vhost device as well as how the configuration changes are handled.
Message-Id: <[email protected]>
--- include/hw/virtio/vhost.h | 132 +++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 10 deletions(-)
include/hw/virtio/vhost.h +122 -10
@@ -61,6 +61,12 @@ typedef struct VhostDevConfigOps { } VhostDevConfigOps;struct vhost_memory ; + +/** +* struct vhost_dev - common vhost_dev structure +* @vhost_ops: backend specific ops +* @config_ops: ops for config changes (see @vhost_dev_set_config_notifier) +*/ struct vhost_dev {VirtIODevice *vdev;MemoryListener memory_listener;
@@ -108,15 +114,129 @@ struct vhost_net {NetClientState *nc; }; +/** +* vhost_dev_init() - initialise the vhost interface +* @hdev: the common vhost_dev structure +* @opaque: opaque ptr passed to backend (vhost/vhost-user/vdpa) +* @backend_type: type of backend +* @busyloop_timeout: timeout for polling virtqueue +* @errp: error handle +* +* The initialisation of the vhost device will trigger the +* initialisation of the backend and potentially capability +* negotiation of backend interface. Configuration of the VirtIO +* itself won't happen until the interface is started. +* +* Return: 0 on success, non-zero on error while setting errp. +*/ int vhost_dev_init (struct vhost_dev *hdev,void *opaque,VhostBackendType backend_type,uint32_t busyloop_timeout,Error **errp); + +/** +* vhost_dev_cleanup() - tear down and cleanup vhost interface +* @hdev: the common vhost_dev structure +*/ void vhost_dev_cleanup (struct vhost_dev *hdev); -int vhost_dev_start (struct vhost_dev *hdev,VirtIODevice *vdev); -void vhost_dev_stop (struct vhost_dev *hdev,VirtIODevice *vdev); + +/** +* vhost_dev_enable_notifiers() - enable event notifiers +* @hdev: common vhost_dev structure +* @vdev: the VirtIODevice structure +* +* Enable notifications directly to the vhost device rather than being +* triggered by QEMU itself. Notifications should be enabled before +* the vhost device is started via @vhost_dev_start. +* +* Return: 0 on success, < 0 on error. +*/ int vhost_dev_enable_notifiers (struct vhost_dev *hdev,VirtIODevice *vdev); + +/** +* vhost_dev_disable_notifiers - disable event notifications +* @hdev: common vhost_dev structure +* @vdev: the VirtIODevice structure +* +* Disable direct notifications to vhost device. +*/ void vhost_dev_disable_notifiers (struct vhost_dev *hdev,VirtIODevice *vdev); +/** +* vhost_dev_start() - start the vhost device +* @hdev: common vhost_dev structure +* @vdev: the VirtIODevice structure +* +* Starts the vhost device. From this point VirtIO feature negotiation +* can start and the device can start processing VirtIO transactions. +* +* Return: 0 on success, < 0 on error. +*/ +int vhost_dev_start (struct vhost_dev *hdev,VirtIODevice *vdev); + +/** +* vhost_dev_stop() - stop the vhost device +* @hdev: common vhost_dev structure +* @vdev: the VirtIODevice structure +* +* Stop the vhost device. After the device is stopped the notifiers +* can be disabled (@vhost_dev_disable_notifiers) and the device can +* be torn down (@vhost_dev_cleanup). +*/ +void vhost_dev_stop (struct vhost_dev *hdev,VirtIODevice *vdev); + +/** +* DOC: vhost device configuration handling +* +* The VirtIO device configuration space is used for rarely changing +* or initialisation time parameters. The configuration can be updated +* by either the guest driver or the device itself. If the device can +* change the configuration over time the vhost handler should +* register a @VhostDevConfigOps structure with +* @vhost_dev_set_config_notifier so the guest can be notified. Some +* devices register a handler anyway and will signal an error if an +* unexpected config change happens. +*/ + +/** +* vhost_dev_get_config() - fetch device configuration +* @hdev: common vhost_dev_structure +* @config: pointer to device appropriate config structure +* @config_len: size of device appropriate config structure +* +* Return: 0 on success, < 0 on error while setting errp +*/ +int vhost_dev_get_config (struct vhost_dev *hdev,uint8_t *config, +uint32_t config_len,Error **errp); + +/** +* vhost_dev_set_config() - set device configuration +* @hdev: common vhost_dev_structure +* @data: pointer to data to set +* @offset: offset into configuration space +* @size: length of set +* @flags: @VhostSetConfigType flags +* +* By use of @offset/@size a subset of the configuration space can be +* written to. The @flags are used to indicate if it is a normal +* transaction or related to migration. +* +* Return: 0 on success, non-zero on error +*/ +int vhost_dev_set_config (struct vhost_dev *dev,const uint8_t *data, +uint32_t offset,uint32_t size,uint32_t flags); + +/** +* vhost_dev_set_config_notifier() - register VhostDevConfigOps +* @hdev: common vhost_dev_structure +* @ops: notifier ops +* +* If the device is expected to change configuration a notifier can be +* setup to handle the case. +*/ +void vhost_dev_set_config_notifier (struct vhost_dev *dev, +const VhostDevConfigOps *ops); + +/* Test and clear masked event pending status. * Should be called after unmask to avoid losing events. */
@@ -136,14 +256,6 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file);int vhost_device_iotlb_miss (struct vhost_dev *dev,uint64_t iova,int write); -int vhost_dev_get_config (struct vhost_dev *hdev,uint8_t *config, -uint32_t config_len,Error **errp); -int vhost_dev_set_config (struct vhost_dev *dev,const uint8_t *data, -uint32_t offset,uint32_t size,uint32_t flags); -/* notifier callback in case vhost device config space changed -*/ -void vhost_dev_set_config_notifier (struct vhost_dev *dev, -const VhostDevConfigOps *ops);void vhost_dev_reset_inflight (struct vhost_inflight *inflight);void vhost_dev_free_inflight (struct vhost_inflight *inflight);
Signature · 1 line
MST
[PULL v2 64/86] vhost-user.rst: add clarifying language about protocol negotiation
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
Make the language about feature negotiation explicitly clear about the handling of the VHOST_USER_F_PROTOCOL_FEATURES feature bit. Try and avoid the sort of bug introduced in vhost.rs REPLY_ACK processing:
https://github.com/rust-vmm/vhost/pull/24
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- docs/interop/vhost-user.rst | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
docs/interop/vhost-user.rst +16 -2
@@ -332,6 +332,18 @@ bit was dedicated for this purpose:: #define VHOST_USER_F_PROTOCOL_FEATURES 30 +Note that VHOST_USER_F_PROTOCOL_FEATURES is the UNUSED (30) feature +bit defined in `VIRTIO 1.1 6.3 Legacy Interface: Reserved Feature Bits +<https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.html#x1-4130003>`_. +VIRTIO devices do not advertise this feature bit and therefore VIRTIO +drivers cannot negotiate it. + +This reserved feature bit was reused by the vhost-user protocol to add +vhost-user protocol feature negotiation in a backwards compatible +fashion. Old vhost-user master and slave implementations continue to +work even though they are not aware of vhost-user protocol feature +negotiation. + Ring states -----------
@@ -890,7 +902,8 @@ Front-end message types Get the protocol feature bitmask from the underlying vhost implementation. Only legal if feature bit ``VHOST_USER_F_PROTOCOL_FEATURES`` is present in - ``VHOST_USER_GET_FEATURES``. + ``VHOST_USER_GET_FEATURES``. It does not need to be acknowledged by + ``VHOST_USER_SET_FEATURES``. .. Note:: Back-ends that report ``VHOST_USER_F_PROTOCOL_FEATURES`` must
@@ -906,7 +919,8 @@ Front-end message types Enable protocol features in the underlying vhost implementation. Only legal if feature bit ``VHOST_USER_F_PROTOCOL_FEATURES`` is present in - ``VHOST_USER_GET_FEATURES``. + ``VHOST_USER_GET_FEATURES``. It does not need to be acknowledged by + ``VHOST_USER_SET_FEATURES``. .. Note:: Back-ends that report ``VHOST_USER_F_PROTOCOL_FEATURES`` must support
Signature · 1 line
MST
[PULL v2 73/86] docs/vhost-user: Clarifications for VHOST_USER_ADD/REM_MEM_REG
In reply to Michael S. TsirkinFrom: Kevin Wolf <[email protected]>
The specification for VHOST_USER_ADD/REM_MEM_REG messages is unclear in several points, which has led to clients having incompatible implementations. This changes the specification to be more explicit about them:
* VHOST_USER_ADD_MEM_REG is not specified as receiving a file descriptor, though it obviously does need to do so. All implementations agree on this one, fix the specification.
* VHOST_USER_REM_MEM_REG is not specified as receiving a file descriptor either, and it also has no reason to do so. rust-vmm does not send file descriptors for removing a memory region (in agreement with the specification), libvhost-user and QEMU do (which is a bug), though libvhost-user doesn't actually make any use of it.
Change the specification so that for compatibility QEMU's behaviour becomes legal, even if discouraged, but rust-vmm's behaviour becomes the explicitly recommended mode of operation.
* VHOST_USER_ADD_MEM_REG doesn't have a documented return value, which is the desired behaviour in the non-postcopy case. It also implemented like this in QEMU and rust-vmm, though libvhost-user is buggy and sometimes sends an unexpected reply. This will be fixed in a separate patch.
However, in postcopy mode it does reply like VHOST_USER_SET_MEM_TABLE. This behaviour is shared between libvhost-user and QEMU; rust-vmm doesn't implement postcopy mode yet. Mention it explicitly in the spec.
* The specification doesn't mention how VHOST_USER_REM_MEM_REG identifies the memory region to be removed. Change it to describe the existing behaviour of libvhost-user (guest address, user address and size must match).
Message-Id: <[email protected]>
--- docs/interop/vhost-user.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
docs/interop/vhost-user.rst +16 -0
@@ -1376,6 +1376,14 @@ Front-end message types For further details on postcopy, see ``VHOST_USER_SET_MEM_TABLE``. They apply to ``VHOST_USER_ADD_MEM_REG`` accordingly. + Exactly one file descriptor from which the memory is mapped is + passed in the ancillary data. + + In postcopy mode (see ``VHOST_USER_POSTCOPY_LISTEN``), the back-end + replies with the bases of the memory mapped region to the front-end. + For further details on postcopy, see ``VHOST_USER_SET_MEM_TABLE``. + They apply to ``VHOST_USER_ADD_MEM_REG`` accordingly. + ``VHOST_USER_REM_MEM_REG`` :id: 38 :equivalent ioctl: N/A
@@ -1400,6 +1408,14 @@ Front-end message types accept messages with one file descriptor. If a file descriptor is passed, the back-end MUST close it without using it otherwise. + The memory region to be removed is identified by its guest address, + user address and size. The mmap offset is ignored. + + No file descriptors SHOULD be passed in the ancillary data. For + compatibility with existing incorrect implementations, the back-end MAY + accept messages with one file descriptor. If a file descriptor is + passed, the back-end MUST close it without using it otherwise. + ``VHOST_USER_SET_STATUS`` :id: 39 :equivalent ioctl: VHOST_VDPA_SET_STATUS
Signature · 1 line
MST
[PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
In reply to Michael S. TsirkinFrom: Francisco Iglesias <[email protected]>
According to 7.2.2 in [1] bit 27 is the last bit that can be part of the bus number, this makes the ECAM max size equal to '1 << 28'. This patch restores back this value into the PCIE_MMCFG_SIZE_MAX define (which was changed in commit 58d5b22bbd5 ("ppc4xx: Add device models found in PPC440 core SoCs")).
[1] PCI Express® Base Specification Revision 5.0 Version 1.0
Message-Id: <[email protected]>
--- include/hw/pci/pcie_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/pci/pcie_host.h +1 -1
@@ -65,7 +65,7 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,* bit 12 - 14: function number * bit 0 - 11: offset in configuration space of a given device */ -#define PCIE_MMCFG_SIZE_MAX (1ULL << 29) +#define PCIE_MMCFG_SIZE_MAX (1ULL << 28)#define PCIE_MMCFG_SIZE_MIN (1ULL << 20)#define PCIE_MMCFG_BUS_BIT 20#define PCIE_MMCFG_BUS_MASK 0xff
Signature · 1 line
MST
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Hi,
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel ./buildroot/qemu_ppc_sam460ex-latest/vmlinux \
-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \
-nographic -snapshot
qemu-system-ppc: ../hw/pci/pcie_host.c:97: pcie_host_mmcfg_init: Assertion `size <= PCIE_MMCFG_SIZE_MAX' failed.
The reason is that it changed commit 58d5b22bbd5 ("ppc4xx: Add device models found in PPC440 core SoCs")) in a way that it wasn't expected by the board. The code seems to believe that, for a reason that isn't stated in the 58d5b22bbd5 commit message, PCIE_MMCFG_SIZE_MAX must be set to 1 << 29.
I'm CCing BALATON Zoltan since he's the author of 58d5b22bbd5 and can provide context of his initial change and why the board seems to rely on it. qemu-ppc is being CCed for awareness of the sam460ex problem.
Zoltan, I wasn't able to amend to quickly amend the code in a way that I could preserve the current PCIE_MMCFG_SIZE_MAX setting and make sam460ex work again. Can you please take a look?
Thanks,
Daniel
Quoted 31 lines · Michael S. Tsirkin
From: Francisco Iglesias <[email protected]>
According to 7.2.2 in [1] bit 27 is the last bit that can be part of the bus number, this makes the ECAM max size equal to '1 << 28'. This patch restores back this value into the
PCIE_MMCFG_SIZE_MAXdefine (which was changed in commit58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")).[1] PCI Express® Base Specification Revision 5.0 Version 1.0
Signed-off-by Francisco Iglesias <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pcie_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/pci/pcie_host.h +1
-1@@ -65,7 +65,7 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,* bit 12 - 14: function number * bit 0 - 11: offset in configuration space of a given device */ -#define PCIE_MMCFG_SIZE_MAX (1ULL << 29) +#define PCIE_MMCFG_SIZE_MAX (1ULL << 28)#define PCIE_MMCFG_SIZE_MIN (1ULL << 20)#define PCIE_MMCFG_BUS_BIT 20#define PCIE_MMCFG_BUS_MASK 0xff
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Hello,
Quoted 8 lines · Daniel Henrique Barboza
Hi,
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel ./buildroot/qemu_ppc_sam460ex-latest/vmlinux \
(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init: Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.
Thanks for noticing this. I usually only test it during the freeze. Wasn't there a test patch submitted by Philippe before? Isn't that yet merged or included in CI? That should catch these before breaking it.
Quoted 3 lines
The reason is that it changed commit
58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")) in a way that it wasn't expected by the board. The code seems to believe that, for a reason that isn't stated in the58d5b22bbd5commit message,PCIE_MMCFG_SIZE_MAXmust be set to 1 << 29.I'm CCing BALATON Zoltan since he's the author of
58d5b22bbd5and can provide context of his initial change and why the board seems to rely on it. qemu-ppc is being CCed for awareness of the sam460ex problem.
I'm afraid I don't remember but maybe I did not have a definitive answer even back then as the docs for this PCIe controller were not available so I've mostly worked from docs for similar SoCs and U-Boot and Linux sources so there were a lot of guessing. Maybe it's related to that the board maps peripheral addresses above 4GB as the first 4GB is reserved for memory? Or maybe there's some mixup between address spaces and the PCIe controller should have a separate address space that's mapped in the system? I did not have any knowledge about this back then and my understanding may still be lacking on how this should work.
Quoted 1 line
Zoltan, I wasn't able to amend to quickly amend the code in a way that I could preserve the current
PCIE_MMCFG_SIZE_MAXsetting and make sam460ex work again. Can you please take a look?
The PCIe controllers of the 460EX are implemented at the end of hw/ppc/ppc440_uc.c (a lot of these 4xx SoCs are sharing components and the code organisation is a bit messy). As the comment near it says it's not really fully tested and working. only good enough for firmware and OSes get past testing it. I think trying to attach any device to it probably would fail or I would be surprised if the OS could actually talk to it as there may be some missing parts. So I'm happy with any solution that keeps the current state of being able to boot the OSes running on it (some of which like AmigaOS and MorphOS are closed source though so I don't know what their drivers need; closest open source OS to them is AROS but not sure that's working on real hardware). Some advice from somebody more knowledgeable about PCIe emulation in QEMU would be welcome here.
Regards,
BALATON Zoltan
Quoted 42 lines
Thanks,
Daniel
Quoted 31 lines · Michael S. Tsirkin
From: Francisco Iglesias <[email protected]>
According to 7.2.2 in [1] bit 27 is the last bit that can be part of the bus number, this makes the ECAM max size equal to '1 << 28'. This patch restores back this value into the
PCIE_MMCFG_SIZE_MAXdefine (which was changed in commit58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")).[1] PCI Express® Base Specification Revision 5.0 Version 1.0
Signed-off-by Francisco Iglesias <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pcie_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/pci/pcie_host.h +1
-1@@ -65,7 +65,7 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,* bit 12 - 14: function number * bit 0 - 11: offset in configuration space of a given device */ -#define PCIE_MMCFG_SIZE_MAX (1ULL << 29) +#define PCIE_MMCFG_SIZE_MAX (1ULL << 28)#define PCIE_MMCFG_SIZE_MIN (1ULL << 20)#define PCIE_MMCFG_BUS_BIT 20#define PCIE_MMCFG_BUS_MASK 0xff
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Quoted 11 lines · BALATON Zoltan
Hello,
Quoted 8 lines · Daniel Henrique Barboza
Hi,
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel ./buildroot/qemu_ppc_sam460ex-latest/vmlinux \
(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init: Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.
With just qemu-system-ppc -M sam460ex the assert seems to happen when the guest (board firmware?) writes a value to CFGMSK reg:
(gdb) bt
#0 0x00007ffff68ff4a0 in raise () at /lib64/libc.so.6 #1 0x00007ffff68ea536 in abort () at /lib64/libc.so.6 #2 0x00007ffff68ea42f in _nl_load_domain.cold () at /lib64/libc.so.6 #3 0x00007ffff68f7ed2 in () at /lib64/libc.so.6 #4 0x000055555596646f in pcie_host_mmcfg_init (e=e@entry=0x5555567942f0, size=size@entry=0x20000000) at ../hw/pci/pcie_host.c:97 #5 0x000055555596653b in pcie_host_mmcfg_map (size=0x20000000, addr=0xd20000000, e=0x5555567942f0) at ../hw/pci/pcie_host.c:105 #6 pcie_host_mmcfg_update (e=0x5555567942f0, enable=0x1, addr=0xd20000000, size=0x20000000) at ../hw/pci/pcie_host.c:118 #7 0x0000555555a70d7c in ppc_dcr_write (dcr_env=0x555556669c10, dcrn=0x122, val=0xe0000001) at ../hw/ppc/ppc.c:1418 #8 0x0000555555abdabb in helper_store_dcr (env=0x555556633360, dcrn=0x122, val=0xe0000001) at ../target/ppc/timebase_helper.c:188
This is done in the board firmware here:
when trying to map config space. Here the size is calculated as 0x20000000 which does not fit the assert. I'm not sure what this means though and where is the problem. Any ideas?
Regards,
BALATON Zoltan
Quoted 57 lines
Thanks for noticing this. I usually only test it during the freeze. Wasn't there a test patch submitted by Philippe before? Isn't that yet merged or included in CI? That should catch these before breaking it.
Quoted 3 lines
The reason is that it changed commit
58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")) in a way that it wasn't expected by the board. The code seems to believe that, for a reason that isn't stated in the58d5b22bbd5commit message,PCIE_MMCFG_SIZE_MAXmust be set to 1 << 29.I'm CCing BALATON Zoltan since he's the author of
58d5b22bbd5and can provide context of his initial change and why the board seems to rely on it. qemu-ppc is being CCed for awareness of the sam460ex problem.I'm afraid I don't remember but maybe I did not have a definitive answer even back then as the docs for this PCIe controller were not available so I've mostly worked from docs for similar SoCs and U-Boot and Linux sources so there were a lot of guessing. Maybe it's related to that the board maps peripheral addresses above 4GB as the first 4GB is reserved for memory? Or maybe there's some mixup between address spaces and the PCIe controller should have a separate address space that's mapped in the system? I did not have any knowledge about this back then and my understanding may still be lacking on how this should work.
Quoted 1 line
Zoltan, I wasn't able to amend to quickly amend the code in a way that I could preserve the current
PCIE_MMCFG_SIZE_MAXsetting and make sam460ex work again. Can you please take a look?The PCIe controllers of the 460EX are implemented at the end of
hw/ppc/ppc440_uc.c(a lot of these 4xx SoCs are sharing components and the code organisation is a bit messy). As the comment near it says it's not really fully tested and working. only good enough for firmware and OSes get past testing it. I think trying to attach any device to it probably would fail or I would be surprised if the OS could actually talk to it as there may be some missing parts. So I'm happy with any solution that keeps the current state of being able to boot the OSes running on it (some of which like AmigaOS and MorphOS are closed source though so I don't know what their drivers need; closest open source OS to them is AROS but not sure that's working on real hardware). Some advice from somebody more knowledgeable about PCIe emulation in QEMU would be welcome here.Regards,
BALATON ZoltanQuoted 41 lines
Thanks,
Daniel
Quoted 31 lines · Michael S. Tsirkin
From: Francisco Iglesias <[email protected]>
According to 7.2.2 in [1] bit 27 is the last bit that can be part of the bus number, this makes the ECAM max size equal to '1 << 28'. This patch restores back this value into the
PCIE_MMCFG_SIZE_MAXdefine (which was changed in commit58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")).[1] PCI Express® Base Specification Revision 5.0 Version 1.0
Signed-off-by Francisco Iglesias <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pcie_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/pci/pcie_host.h +1
-1@@ -65,7 +65,7 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,* bit 12 - 14: function number * bit 0 - 11: offset in configuration space of a given device */ -#define PCIE_MMCFG_SIZE_MAX (1ULL << 29) +#define PCIE_MMCFG_SIZE_MAX (1ULL << 28)#define PCIE_MMCFG_SIZE_MIN (1ULL << 20)#define PCIE_MMCFG_BUS_BIT 20#define PCIE_MMCFG_BUS_MASK 0xff
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Quoted 31 lines · BALATON Zoltan
Quoted 5 lines · BALATON Zoltan
Hello,
Quoted 2 lines · Daniel Henrique Barboza
Hi,
Quoted 8 lines
Quoted 8 lines
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel
./buildroot/qemu_ppc_sam460ex-latest/vmlinux \(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init:
Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.With just qemu-system-ppc -M sam460ex the assert seems to happen when the guest (board firmware?) writes a value to CFGMSK reg:
(gdb) bt
#0 0x00007ffff68ff4a0 in raise () at /lib64/libc.so.6 #1 0x00007ffff68ea536 in abort () at /lib64/libc.so.6 #2 0x00007ffff68ea42f in _nl_load_domain.cold () at /lib64/libc.so.6 #3 0x00007ffff68f7ed2 in () at /lib64/libc.so.6 #4 0x000055555596646f in pcie_host_mmcfg_init (e=e@entry=0x5555567942f0, size=size@entry=0x20000000) at ../hw/pci/pcie_host.c:97 #5 0x000055555596653b in pcie_host_mmcfg_map (size=0x20000000, addr=0xd20000000, e=0x5555567942f0) at ../hw/pci/pcie_host.c:105 #6 pcie_host_mmcfg_update (e=0x5555567942f0, enable=0x1, addr=0xd20000000, size=0x20000000) at ../hw/pci/pcie_host.c:118 #7 0x0000555555a70d7c in ppc_dcr_write (dcr_env=0x555556669c10, dcrn=0x122, val=0xe0000001) at ../hw/ppc/ppc.c:1418 #8 0x0000555555abdabb in helper_store_dcr (env=0x555556633360, dcrn=0x122, val=0xe0000001) at ../target/ppc/timebase_helper.c:188This is done in the board firmware here:
Quoted 8 lines
when trying to map config space. Here the size is calculated as
0x20000000which does not fit the assert. I'm not sure what this means though and where is the problem. Any ideas?Regards,
BALATON Zoltan
It says so, does it not?
1051 switch (port) {
1052 case 0:
1053 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high); 1054 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low); 1055 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */ 1056 break; 1057 case 1: 1058 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high); 1059 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low); 1060 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */ 1061 break; 1062 #if CONFIG_SYS_PCIE_NR_PORTS > 2 1063 case 2: 1064 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high); 1065 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low); 1066 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */ 1067 break;
1068 #endif
and basically according to spec max size is 256MB.
we can fix the firmware of course, or we can just drop the assert, or force it within range in the ppc code.
Fixing firmware seems cleaner ... want to try?
Any preference?
Quoted 88 lines
Quoted 88 lines
Thanks for noticing this. I usually only test it during the freeze. Wasn't there a test patch submitted by Philippe before? Isn't that yet merged or included in CI? That should catch these before breaking it.
Quoted 10 lines
The reason is that it changed commit
58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")) in a way that it wasn't expected by the board. The code seems to believe that, for a reason that isn't stated in the58d5b22bbd5commit message,PCIE_MMCFG_SIZE_MAXmust be set to 1 << 29.I'm CCing BALATON Zoltan since he's the author of
58d5b22bbd5and can provide context of his initial change and why the board seems to rely on it. qemu-ppc is being CCed for awareness of the sam460ex problem.I'm afraid I don't remember but maybe I did not have a definitive answer even back then as the docs for this PCIe controller were not available so I've mostly worked from docs for similar SoCs and U-Boot and Linux sources so there were a lot of guessing. Maybe it's related to that the board maps peripheral addresses above 4GB as the first 4GB is reserved for memory? Or maybe there's some mixup between address spaces and the PCIe controller should have a separate address space that's mapped in the system? I did not have any knowledge about this back then and my understanding may still be lacking on how this should work.
Quoted 3 lines
Zoltan, I wasn't able to amend to quickly amend the code in a way that I could preserve the current
PCIE_MMCFG_SIZE_MAXsetting and make sam460ex work again. Can you please take a look?The PCIe controllers of the 460EX are implemented at the end of
hw/ppc/ppc440_uc.c(a lot of these 4xx SoCs are sharing components and the code organisation is a bit messy). As the comment near it says it's not really fully tested and working. only good enough for firmware and OSes get past testing it. I think trying to attach any device to it probably would fail or I would be surprised if the OS could actually talk to it as there may be some missing parts. So I'm happy with any solution that keeps the current state of being able to boot the OSes running on it (some of which like AmigaOS and MorphOS are closed source though so I don't know what their drivers need; closest open source OS to them is AROS but not sure that's working on real hardware). Some advice from somebody more knowledgeable about PCIe emulation in QEMU would be welcome here.Regards,
BALATON ZoltanQuoted 41 lines
Thanks,
Daniel
Quoted 31 lines · Michael S. Tsirkin
From: Francisco Iglesias <[email protected]>
According to 7.2.2 in [1] bit 27 is the last bit that can be part of the bus number, this makes the ECAM max size equal to '1 << 28'. This patch restores back this value into the
PCIE_MMCFG_SIZE_MAXdefine (which was changed in commit58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")).[1] PCI Express® Base Specification Revision 5.0 Version 1.0
Signed-off-by Francisco Iglesias <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pcie_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/pci/pcie_host.h +1
-1@@ -65,7 +65,7 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,* bit 12 - 14: function number * bit 0 - 11: offset in configuration space of a given device */ -#define PCIE_MMCFG_SIZE_MAX (1ULL << 29) +#define PCIE_MMCFG_SIZE_MAX (1ULL << 28)#define PCIE_MMCFG_SIZE_MIN (1ULL << 20)#define PCIE_MMCFG_BUS_BIT 20#define PCIE_MMCFG_BUS_MASK 0xff
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Quoted 61 lines · Michael S. Tsirkin
Quoted 31 lines · BALATON Zoltan
Quoted 5 lines · BALATON Zoltan
Hello,
Quoted 2 lines · Daniel Henrique Barboza
Hi,
Quoted 8 lines
Quoted 8 lines
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel
./buildroot/qemu_ppc_sam460ex-latest/vmlinux \(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init:
Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.With just qemu-system-ppc -M sam460ex the assert seems to happen when the guest (board firmware?) writes a value to CFGMSK reg:
(gdb) bt
#0 0x00007ffff68ff4a0 in raise () at /lib64/libc.so.6 #1 0x00007ffff68ea536 in abort () at /lib64/libc.so.6 #2 0x00007ffff68ea42f in _nl_load_domain.cold () at /lib64/libc.so.6 #3 0x00007ffff68f7ed2 in () at /lib64/libc.so.6 #4 0x000055555596646f in pcie_host_mmcfg_init (e=e@entry=0x5555567942f0, size=size@entry=0x20000000) at ../hw/pci/pcie_host.c:97 #5 0x000055555596653b in pcie_host_mmcfg_map (size=0x20000000, addr=0xd20000000, e=0x5555567942f0) at ../hw/pci/pcie_host.c:105 #6 pcie_host_mmcfg_update (e=0x5555567942f0, enable=0x1, addr=0xd20000000, size=0x20000000) at ../hw/pci/pcie_host.c:118 #7 0x0000555555a70d7c in ppc_dcr_write (dcr_env=0x555556669c10, dcrn=0x122, val=0xe0000001) at ../hw/ppc/ppc.c:1418 #8 0x0000555555abdabb in helper_store_dcr (env=0x555556633360, dcrn=0x122, val=0xe0000001) at ../target/ppc/timebase_helper.c:188This is done in the board firmware here:
Quoted 8 lines
when trying to map config space. Here the size is calculated as
0x20000000which does not fit the assert. I'm not sure what this means though and where is the problem. Any ideas?Regards,
BALATON ZoltanIt says so, does it not?
1051 switch (port) {
1052 case 0:1053 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high); 1054 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low); 1055 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */ 1056 break; 1057 case 1: 1058 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high); 1059 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low); 1060 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */ 1061 break; 1062 #if CONFIG_SYS_PCIE_NR_PORTS > 2 1063 case 2: 1064 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high); 1065 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low); 1066 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */ 1067 break;
Quoted 1 line
1068 #endif
Yes, the size matches what the firmware programs it.
Quoted 1 line
and basically according to spec max size is 256MB.
Maybe this SoC does not follow the spec you're referring to? Complies to some other spec like a newer version or has its own idea? I don't have docs to tell.
Quoted 2 lines
we can fix the firmware of course, or we can just drop the assert, or force it within range in the ppc code.
According to this random Cisco IOS dump I've found:
https://www.hardware.com.br/comunidade/switch-cisco/1128380/
looks like this value is valid on that hardware so that likely means we should not "fix" the firmware. (Also not because it's what the real board uses or at least very close to it so it should work with the emulated board too and keeping it close to the real hardware ensures the emulation is accurate.) That means we should either revert this back (why was this changed back in the first place, did it cause any problems?) or maybe try restricting the value in the PPC model.
Quoted 2 lines
Fixing firmware seems cleaner ... want to try?
Any preference?
I'd leave making a patch to someone else but can help testing it. As per the above if we can't revert it maybe we can try restricting size in ppc440_uc.c where pcie_host_mmcfg_update() is called. Since the PCIe bus on this board probably does not work now anyway probably nothing will notice this for now.
Regards,
BALATON Zoltan
Quoted 93 lines
Quoted 90 lines
Quoted 90 lines
Thanks for noticing this. I usually only test it during the freeze. Wasn't there a test patch submitted by Philippe before? Isn't that yet merged or included in CI? That should catch these before breaking it.
Quoted 10 lines
The reason is that it changed commit
58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")) in a way that it wasn't expected by the board. The code seems to believe that, for a reason that isn't stated in the58d5b22bbd5commit message,PCIE_MMCFG_SIZE_MAXmust be set to 1 << 29.I'm CCing BALATON Zoltan since he's the author of
58d5b22bbd5and can provide context of his initial change and why the board seems to rely on it. qemu-ppc is being CCed for awareness of the sam460ex problem.I'm afraid I don't remember but maybe I did not have a definitive answer even back then as the docs for this PCIe controller were not available so I've mostly worked from docs for similar SoCs and U-Boot and Linux sources so there were a lot of guessing. Maybe it's related to that the board maps peripheral addresses above 4GB as the first 4GB is reserved for memory? Or maybe there's some mixup between address spaces and the PCIe controller should have a separate address space that's mapped in the system? I did not have any knowledge about this back then and my understanding may still be lacking on how this should work.
Quoted 3 lines
Zoltan, I wasn't able to amend to quickly amend the code in a way that I could preserve the current
PCIE_MMCFG_SIZE_MAXsetting and make sam460ex work again. Can you please take a look?The PCIe controllers of the 460EX are implemented at the end of
hw/ppc/ppc440_uc.c(a lot of these 4xx SoCs are sharing components and the code organisation is a bit messy). As the comment near it says it's not really fully tested and working. only good enough for firmware and OSes get past testing it. I think trying to attach any device to it probably would fail or I would be surprised if the OS could actually talk to it as there may be some missing parts. So I'm happy with any solution that keeps the current state of being able to boot the OSes running on it (some of which like AmigaOS and MorphOS are closed source though so I don't know what their drivers need; closest open source OS to them is AROS but not sure that's working on real hardware). Some advice from somebody more knowledgeable about PCIe emulation in QEMU would be welcome here.Regards,
BALATON ZoltanQuoted 41 lines
Thanks,
Daniel
Quoted 31 lines · Michael S. Tsirkin
From: Francisco Iglesias <[email protected]>
According to 7.2.2 in [1] bit 27 is the last bit that can be part of the bus number, this makes the ECAM max size equal to '1 << 28'. This patch restores back this value into the
PCIE_MMCFG_SIZE_MAXdefine (which was changed in commit58d5b22bbd5("ppc4xx: Add device models found in PPC440 core SoCs")).[1] PCI Express® Base Specification Revision 5.0 Version 1.0
Signed-off-by Francisco Iglesias <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pcie_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/pci/pcie_host.h +1
-1@@ -65,7 +65,7 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,* bit 12 - 14: function number * bit 0 - 11: offset in configuration space of a given device */ -#define PCIE_MMCFG_SIZE_MAX (1ULL << 29) +#define PCIE_MMCFG_SIZE_MAX (1ULL << 28)#define PCIE_MMCFG_SIZE_MIN (1ULL << 20)#define PCIE_MMCFG_BUS_BIT 20#define PCIE_MMCFG_BUS_MASK 0xff
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Quoted 79 lines · BALATON Zoltan
Quoted 61 lines · Michael S. Tsirkin
Quoted 31 lines · BALATON Zoltan
Quoted 5 lines · BALATON Zoltan
Hello,
Quoted 2 lines · Daniel Henrique Barboza
Hi,
Quoted 8 lines
Quoted 8 lines
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel
./buildroot/qemu_ppc_sam460ex-latest/vmlinux \(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init:
Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.With just qemu-system-ppc -M sam460ex the assert seems to happen when the guest (board firmware?) writes a value to CFGMSK reg:
(gdb) bt
#0 0x00007ffff68ff4a0 in raise () at /lib64/libc.so.6 #1 0x00007ffff68ea536 in abort () at /lib64/libc.so.6 #2 0x00007ffff68ea42f in _nl_load_domain.cold () at /lib64/libc.so.6 #3 0x00007ffff68f7ed2 in () at /lib64/libc.so.6 #4 0x000055555596646f in pcie_host_mmcfg_init (e=e@entry=0x5555567942f0, size=size@entry=0x20000000) at ../hw/pci/pcie_host.c:97 #5 0x000055555596653b in pcie_host_mmcfg_map (size=0x20000000, addr=0xd20000000, e=0x5555567942f0) at ../hw/pci/pcie_host.c:105 #6 pcie_host_mmcfg_update (e=0x5555567942f0, enable=0x1, addr=0xd20000000, size=0x20000000) at ../hw/pci/pcie_host.c:118 #7 0x0000555555a70d7c in ppc_dcr_write (dcr_env=0x555556669c10, dcrn=0x122, val=0xe0000001) at ../hw/ppc/ppc.c:1418 #8 0x0000555555abdabb in helper_store_dcr (env=0x555556633360, dcrn=0x122, val=0xe0000001) at ../target/ppc/timebase_helper.c:188This is done in the board firmware here:
Quoted 8 lines
when trying to map config space. Here the size is calculated as
0x20000000which does not fit the assert. I'm not sure what this means though and where is the problem. Any ideas?Regards,
BALATON ZoltanIt says so, does it not?
1051 switch (port) {
1052 case 0:1053 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high); 1054 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low); 1055 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */ 1056 break; 1057 case 1: 1058 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high); 1059 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low); 1060 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */ 1061 break; 1062 #if CONFIG_SYS_PCIE_NR_PORTS > 2 1063 case 2: 1064 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high); 1065 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low); 1066 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */ 1067 break;Quoted 1 line
1068 #endif
Yes, the size matches what the firmware programs it.
Quoted 1 line
and basically according to spec max size is 256MB.
Maybe this SoC does not follow the spec you're referring to? Complies to some other spec like a newer version or has its own idea? I don't have docs to tell.
Quoted 2 lines
we can fix the firmware of course, or we can just drop the assert, or force it within range in the ppc code.
According to this random Cisco IOS dump I've found:
https://www.hardware.com.br/comunidade/switch-cisco/1128380/
Quoted 7 lines
looks like this value is valid on that hardware so that likely means we should not "fix" the firmware. (Also not because it's what the real board uses or at least very close to it so it should work with the emulated board too and keeping it close to the real hardware ensures the emulation is accurate.) That means we should either revert this back (why was this changed back in the first place, did it cause any problems?) or maybe try restricting the value in the PPC model.
It didn't it was just weird behaviour. High bit in the address was ignored, so the config space was mapped many times at offsets 0,256M, etc up to whatever size was.
Quoted 10 lines
Quoted 2 lines
Fixing firmware seems cleaner ... want to try?
Any preference?I'd leave making a patch to someone else but can help testing it. As per the above if we can't revert it maybe we can try restricting size in
ppc440_uc.cwherepcie_host_mmcfg_update()is called. Since the PCIe bus on this board probably does not work now anyway probably nothing will notice this for now.Regards,
BALATON Zoltan
I am guessing the unused space is just ignored. so I am inclined to restrict in PPC model,
where we also have a chance to document what is going on.
hw/ppc/ppc440_uc.c +8 -0
@@ -1180,6 +1180,14 @@ static void dcr_write_pcie(void *opaque, int dcrn, uint32_t val)case PEGPL_CFGMSK : s->cfg_mask = val; size = ~(val &0xfffffffe ) +1 ; +/* +* Firmware sets this register to E0000001. Why we are not sure, +* but the current guess is anything above PCIE_MMCFG_SIZE_MAX is +* ignored. +*/ +if (size >PCIE_MMCFG_SIZE_MAX ) { + size =PCIE_MMCFG_SIZE_MAX ; + }pcie_host_mmcfg_update (PCIE_HOST_BRIDGE (s), val &1 , s->cfg_base, size);break ;case PEGPL_MSGBAH :
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Quoted 99 lines · Michael S. Tsirkin
Quoted 79 lines · BALATON Zoltan
Quoted 61 lines · Michael S. Tsirkin
Quoted 31 lines · BALATON Zoltan
Quoted 5 lines · BALATON Zoltan
Hello,
Quoted 2 lines · Daniel Henrique Barboza
Hi,
Quoted 8 lines
Quoted 8 lines
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel
./buildroot/qemu_ppc_sam460ex-latest/vmlinux \(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init:
Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.With just qemu-system-ppc -M sam460ex the assert seems to happen when the guest (board firmware?) writes a value to CFGMSK reg:
(gdb) bt
#0 0x00007ffff68ff4a0 in raise () at /lib64/libc.so.6 #1 0x00007ffff68ea536 in abort () at /lib64/libc.so.6 #2 0x00007ffff68ea42f in _nl_load_domain.cold () at /lib64/libc.so.6 #3 0x00007ffff68f7ed2 in () at /lib64/libc.so.6 #4 0x000055555596646f in pcie_host_mmcfg_init (e=e@entry=0x5555567942f0, size=size@entry=0x20000000) at ../hw/pci/pcie_host.c:97 #5 0x000055555596653b in pcie_host_mmcfg_map (size=0x20000000, addr=0xd20000000, e=0x5555567942f0) at ../hw/pci/pcie_host.c:105 #6 pcie_host_mmcfg_update (e=0x5555567942f0, enable=0x1, addr=0xd20000000, size=0x20000000) at ../hw/pci/pcie_host.c:118 #7 0x0000555555a70d7c in ppc_dcr_write (dcr_env=0x555556669c10, dcrn=0x122, val=0xe0000001) at ../hw/ppc/ppc.c:1418 #8 0x0000555555abdabb in helper_store_dcr (env=0x555556633360, dcrn=0x122, val=0xe0000001) at ../target/ppc/timebase_helper.c:188This is done in the board firmware here:
Quoted 8 lines
when trying to map config space. Here the size is calculated as
0x20000000which does not fit the assert. I'm not sure what this means though and where is the problem. Any ideas?Regards,
BALATON ZoltanIt says so, does it not?
1051 switch (port) {
1052 case 0:1053 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high); 1054 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low); 1055 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */ 1056 break; 1057 case 1: 1058 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high); 1059 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low); 1060 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */ 1061 break; 1062 #if CONFIG_SYS_PCIE_NR_PORTS > 2 1063 case 2: 1064 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high); 1065 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low); 1066 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */ 1067 break;Quoted 1 line
1068 #endif
Yes, the size matches what the firmware programs it.
Quoted 1 line
and basically according to spec max size is 256MB.
Maybe this SoC does not follow the spec you're referring to? Complies to some other spec like a newer version or has its own idea? I don't have docs to tell.
Quoted 2 lines
we can fix the firmware of course, or we can just drop the assert, or force it within range in the ppc code.
According to this random Cisco IOS dump I've found:
https://www.hardware.com.br/comunidade/switch-cisco/1128380/
Quoted 7 lines
looks like this value is valid on that hardware so that likely means we should not "fix" the firmware. (Also not because it's what the real board uses or at least very close to it so it should work with the emulated board too and keeping it close to the real hardware ensures the emulation is accurate.) That means we should either revert this back (why was this changed back in the first place, did it cause any problems?) or maybe try restricting the value in the PPC model.
It didn't it was just weird behaviour. High bit in the address was ignored, so the config space was mapped many times at offsets 0,256M, etc up to whatever size was.
Quoted 8 lines
Quoted 2 lines
Fixing firmware seems cleaner ... want to try?
Any preference?I'd leave making a patch to someone else but can help testing it. As per the above if we can't revert it maybe we can try restricting size in
ppc440_uc.cwherepcie_host_mmcfg_update()is called. Since the PCIe bus on this board probably does not work now anyway probably nothing will notice this for now.
Quoted 8 lines
Quoted 2 lines
Regards,
BALATON ZoltanI am guessing the unused space is just ignored. so I am inclined to restrict in PPC model,
where we also have a chance to document what is going on.
Works for me. Verified that AmigaOS and MorphOS boot with this.
Thanks.
Quoted 24 lines
hw/ppc/ppc440_uc.c +8
-0@@ -1180,6 +1180,14 @@ static void dcr_write_pcie(void *opaque, int dcrn, uint32_t val)case PEGPL_CFGMSK : s->cfg_mask = val; size = ~(val &0xfffffffe ) +1 ; +/* +* Firmware sets this register to E0000001. Why we are not sure, +* but the current guess is anything above PCIE_MMCFG_SIZE_MAX is +* ignored. +*/ +if (size >PCIE_MMCFG_SIZE_MAX ) { + size =PCIE_MMCFG_SIZE_MAX ; + }pcie_host_mmcfg_update (PCIE_HOST_BRIDGE (s), val &1 , s->cfg_base, size);break ;case PEGPL_MSGBAH :
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
In reply to BALATON ZoltanQuoted 5 lines · BALATON Zoltan
Hello,
Quoted 2 lines · Daniel Henrique Barboza
Hi,
Quoted 8 lines
Quoted 6 lines
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel ./buildroot/qemu_ppc_sam460ex-latest/vmlinux \
(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init: Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.Thanks for noticing this. I usually only test it during the freeze. Wasn't there a test patch submitted by Philippe before? Isn't that yet merged or included in CI? That should catch these before breaking it.
Seems like there is only the (primitive) boot-serial test so far:
$ grep -r sam460ex tests/
tests/qtest/boot-serial-test.c: { "ppc", "sam460ex", "-m 256", "DRAM: 256 MiB" },
tests/qtest/boot-serial-test.c: { "ppc64", "sam460ex", "-device e1000", "8086 100e" },If there is a guest kernel available for public download somewhere, it would be great if you could add an avocado test for this machine (see e.g. the tests/avocado/ppc_*.py files for a template).
Thomas
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
Quoted 17 lines · Thomas Huth
Quoted 5 lines · BALATON Zoltan
Hello,
Quoted 2 lines · Daniel Henrique Barboza
Hi,
Quoted 8 lines
Quoted 6 lines
This patch broke the boot of the sam460ex ppc machine:
qemu-system-ppc -M sam460ex -kernel ./buildroot/qemu_ppc_sam460ex-latest/vmlinux \
(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init: Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.Thanks for noticing this. I usually only test it during the freeze. Wasn't there a test patch submitted by Philippe before? Isn't that yet merged or included in CI? That should catch these before breaking it.
Seems like there is only the (primitive) boot-serial test so far:
Quoted 7 lines
$ grep -r sam460ex tests/ tests/qtest/boot-serial-test.c: { "ppc", "sam460ex", "-m 256", "DRAM: 256 MiB" }, tests/qtest/boot-serial-test.c: { "ppc64", "sam460ex", "-device e1000", "8086 100e" },If there is a guest kernel available for public download somewhere, it would be great if you could add an avocado test for this machine (see e.g. the
tests/avocado/ppc_*.pyfiles for a template).
We use these buildroot kernel and rootfs images :
https://github.com/legoater/qemu-ppc-boot
The whole takes about 5m40s to run on a 8*2 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz.
Thanks,
C.
./ppc-boot.sh -q --prefix=/home/legoater/work/qemu/qemu-ppc.git/install/ ref405ep : Linux /init login DONE (PASSED)
bamboo : Linux /init net login DONE (PASSED)
sam460ex : ASSERT (FAILED)
g3beige-604 : FW Linux Linux /init net login DONE (PASSED) g3beige-g3 : FW Linux Linux /init net login DONE (PASSED) mac99-g4 : FW Linux Linux /init net login DONE (PASSED) mac99-7447 : FW Linux Linux /init net login DONE (PASSED) mac99-7448 : FW Linux Linux /init net login DONE (PASSED) mac99-7450 : FW Linux Linux /init net login DONE (PASSED) mpc8544ds : Linux /init net login DONE (PASSED)
e500mc : Linux /init net login DONE (PASSED)
40p : FW login DONE (PASSED)
e5500 : Linux /init net login DONE (PASSED)
e6500 : Linux /init net login DONE (PASSED)
g5-32 : FW Linux Linux /init net login DONE (PASSED)
g5-64 : FW Linux Linux /init net login DONE (PASSED) pseries-970 : FW Linux Linux /init net login DONE (PASSED) pseries-970mp : FW Linux Linux /init net login DONE (PASSED) pseries-POWER5+ : FW Linux Linux /init net login DONE (PASSED) pseries : FW Linux Linux /init net login DONE (PASSED) pseriesle8 : FW Linux Linux /init net login DONE (PASSED) pseriesle9 : FW Linux Linux /init net login DONE (PASSED) pseriesle-vof : Linux /init net login DONE (PASSED) pseriesle10 : FW Linux Linux /init net login DONE (PASSED) powernv8 : FW Linux /init net login DONE (PASSED)
powernv9 : FW Linux /init net login DONE (PASSED)
powernv10 : FW Linux /init net login DONE (PASSED)
Re: [PULL v2 75/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_SIZE_MAX
In reply to Thomas HuthQuoted 19 lines · Thomas Huth
Quoted 7 lines · BALATON Zoltan
Hello,
Quoted 4 lines · Daniel Henrique Barboza
Hi,
This patch broke the boot of the sam460ex ppc machine:
Quoted 10 lines
Quoted 6 lines
qemu-system-ppc -M sam460ex -kernel
./buildroot/qemu_ppc_sam460ex-latest/vmlinux \(quoted diff) +0
-2-device virtio-net-pci,netdev=net0 -netdev user,id=net0 -serial mon:stdio \ -nographic -snapshotqemu-system-ppc:
../hw/pci/pcie_host.c:97:pcie_host_mmcfg_init:
Assertion `size <=PCIE_MMCFG_SIZE_MAX' failed.Thanks for noticing this. I usually only test it during the freeze. Wasn't there a test patch submitted by Philippe before? Isn't that yet merged or included in CI? That should catch these before breaking it.
Quoted 5 lines
Seems like there is only the (primitive) boot-serial test so far:
$ grep -r sam460ex tests/ tests/qtest/boot-serial-test.c: { "ppc", "sam460ex", "-m 256", "DRAM: 256 MiB" }, tests/qtest/boot-serial-test.c: { "ppc64", "sam460ex", "-device e1000", "8086 100e" },
Hmm why don't these tests catch the issue?
Quoted 5 lines
If there is a guest kernel available for public download somewhere, it would be great if you could add an avocado test for this machine (see e.g. the
tests/avocado/ppc_*.pyfiles for a template).Thomas
[PULL v2 69/86] virtio/vhost-user: dynamically assign VhostUserHostNotifiers
In reply to Michael S. TsirkinFrom: Alex Bennée <[email protected]>
At a couple of hundred bytes per notifier allocating one for every potential queue is very wasteful as most devices only have a few queues. Instead of having this handled statically dynamically assign them and track in a GPtrArray.
[AJB: it's hard to trigger the vhost notifiers code, I assume as it requires a KVM guest with appropriate backend]
Message-Id: <[email protected]>
--- include/hw/virtio/vhost-user.h | 42 ++++++++++++++++- hw/virtio/vhost-user.c | 83 +++++++++++++++++++++++++++------- hw/virtio/trace-events | 1 + 3 files changed, 108 insertions(+), 18 deletions(-)
include/hw/virtio/vhost-user.h +41 -1
@@ -11,21 +11,61 @@#include "chardev/char-fe.h" #include "hw/virtio/virtio.h" +/** +* VhostUserHostNotifier - notifier information for one queue +* @rcu: rcu_head for cleanup +* @mr: memory region of notifier +* @addr: current mapped address +* @unmap_addr: address to be un-mapped +* @idx: virtioqueue index +* +* The VhostUserHostNotifier entries are re-used. When an old mapping +* is to be released it is moved to @unmap_addr and @addr is replaced. +* Once the RCU process has completed the unmap @unmap_addr is +* cleared. +*/ typedef struct VhostUserHostNotifier {struct rcu_head rcu;MemoryRegion mr;void *addr;void *unmap_addr; +int idx; }VhostUserHostNotifier ; +/** +* VhostUserState - shared state for all vhost-user devices +* @chr: the character backend for the socket +* @notifiers: GPtrArray of @VhostUserHostnotifier +* @memory_slots: +*/ typedef struct VhostUserState {CharBackend *chr; -VhostUserHostNotifier notifier[VIRTIO_QUEUE_MAX ]; +GPtrArray *notifiers;int memory_slots;bool supports_config; }VhostUserState ; +/** +* vhost_user_init() - initialise shared vhost_user state +* @user: allocated area for storing shared state +* @chr: the chardev for the vhost socket +* @errp: error handle +* +* User can either directly g_new() space for the state or embed +* VhostUserState in their larger device structure and just point to +* it. +* +* Return: true on success, false on error while setting errp. +*/ bool vhost_user_init (VhostUserState *user,CharBackend *chr,Error **errp); + +/** +* vhost_user_cleanup() - cleanup state +* @user: ptr to use state +* +* Cleans up shared state and notifiers, callee is responsible for +* freeing the @VhostUserState memory itself. +*/ void vhost_user_cleanup (VhostUserState *user);#endif
hw/virtio/vhost-user.c +66 -17
137 lines not on this page · raw message
hw/virtio/trace-events +1 -0
@@ -23,6 +23,7 @@ vhost_user_postcopy_waker_found(uint64_t client_addr) "0x%"PRIx64 vhost_user_postcopy_waker_nomatch(const char *rb, uint64_t rb_offset) "%s + 0x%"PRIx64 vhost_user_read(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" +vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8
Signature · 1 line
MST
[PULL v2 76/86] hw/i386: Make pit a property of common x86 base machine type
In reply to Michael S. TsirkinFrom: Xiaoyao Li <[email protected]>
Both pc and microvm have pit property individually. Let's just make it the property of common x86 base machine type.
Message-Id: <[email protected]>
--- include/hw/i386/microvm.h | 2 -- include/hw/i386/pc.h | 2 -- include/hw/i386/x86.h | 2 ++ hw/i386/microvm.c | 27 +-------------------------- hw/i386/pc.c | 24 +++--------------------- hw/i386/x86.c | 25 +++++++++++++++++++++++++ 6 files changed, 31 insertions(+), 51 deletions(-)
include/hw/i386/microvm.h +0 -2
@@ -67,7 +67,6 @@#define PCIE_ECAM_SIZE 0x10000000/* Machine type options */ -#define MICROVM_MACHINE_PIT "pit"#define MICROVM_MACHINE_PIC "pic"#define MICROVM_MACHINE_RTC "rtc"#define MICROVM_MACHINE_PCIE "pcie"
@@ -87,7 +86,6 @@ struct MicrovmMachineState {/* Machine type options */ OnOffAuto pic; -OnOffAuto pit;OnOffAuto rtc;OnOffAuto pcie;OnOffAuto ioapic2;
include/hw/i386/pc.h +0 -2
@@ -46,7 +46,6 @@ typedef struct PCMachineState {bool acpi_build_enabled;bool smbus_enabled;bool sata_enabled; -bool pit_enabled;bool hpet_enabled;bool i8042_enabled;bool default_bus_bypass_iommu;
@@ -64,7 +63,6 @@ typedef struct PCMachineState {#define PC_MACHINE_VMPORT "vmport"#define PC_MACHINE_SMBUS "smbus"#define PC_MACHINE_SATA "sata" -#define PC_MACHINE_PIT "pit"#define PC_MACHINE_I8042 "i8042"#define PC_MACHINE_MAX_FW_SIZE "max-fw-size"#define PC_MACHINE_SMBIOS_EP "smbios-entry-point-type"
include/hw/i386/x86.h +2 -0
@@ -65,6 +65,7 @@ struct X86MachineState {OnOffAuto smm;OnOffAuto acpi; +OnOffAuto pit;char *oem_id;char *oem_table_id;
@@ -84,6 +85,7 @@ struct X86MachineState {#define X86_MACHINE_SMM "smm"#define X86_MACHINE_ACPI "acpi" +#define X86_MACHINE_PIT "pit"#define X86_MACHINE_OEM_ID "x-oem-id"#define X86_MACHINE_OEM_TABLE_ID "x-oem-table-id"#define X86_MACHINE_BUS_LOCK_RATELIMIT "bus-lock-ratelimit"
hw/i386/microvm.c +1 -26
@@ -257,7 +257,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)g_free (i8259); } -if (mms->pit ==ON_OFF_AUTO_ON || mms->pit ==ON_OFF_AUTO_AUTO ) { +if (x86ms->pit ==ON_OFF_AUTO_ON || x86ms->pit ==ON_OFF_AUTO_AUTO ) {if (kvm_pit_in_kernel ()) {kvm_pit_init (isa_bus,0x40 ); }else {
@@ -508,23 +508,6 @@ static void microvm_machine_set_pic(Object *obj, Visitor *v, const char *name,visit_type_OnOffAuto (v, name, &mms->pic, errp); } -static void microvm_machine_get_pit (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -MicrovmMachineState *mms =MICROVM_MACHINE (obj); -OnOffAuto pit = mms->pit; - -visit_type_OnOffAuto (v, name, &pit, errp); -} - -static void microvm_machine_set_pit (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -MicrovmMachineState *mms =MICROVM_MACHINE (obj); - -visit_type_OnOffAuto (v, name, &mms->pit, errp); -} -static void microvm_machine_get_rtc (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -650,7 +633,6 @@ static void microvm_machine_initfn(Object *obj)/* Configuration */ mms->pic =ON_OFF_AUTO_AUTO ; - mms->pit =ON_OFF_AUTO_AUTO ; mms->rtc =ON_OFF_AUTO_AUTO ; mms->pcie =ON_OFF_AUTO_AUTO ; mms->ioapic2 =ON_OFF_AUTO_AUTO ;
@@ -709,13 +691,6 @@ static void microvm_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,MICROVM_MACHINE_PIC ,"Enable i8259 PIC" ); -object_class_property_add (oc,MICROVM_MACHINE_PIT ,"OnOffAuto" , - microvm_machine_get_pit, - microvm_machine_set_pit, -NULL ,NULL ); -object_class_property_set_description (oc,MICROVM_MACHINE_PIT , -"Enable i8254 PIT" ); - object_class_property_add(oc, MICROVM_MACHINE_RTC, "OnOffAuto", microvm_machine_get_rtc, microvm_machine_set_rtc,
hw/i386/pc.c +3 -21
@@ -1123,6 +1123,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,ISADevice *pit =NULL ;MemoryRegion *ioport80_io =g_new (MemoryRegion,1 );MemoryRegion *ioportF0_io =g_new (MemoryRegion,1 ); +X86MachineState *x86ms =X86_MACHINE (pcms);memory_region_init_io (ioport80_io,NULL , &ioport80_io_ops,NULL ,"ioport80" ,1 );memory_region_add_subregion (isa_bus->address_space_io,0x80 , ioport80_io);
@@ -1167,7 +1168,8 @@ void pc_basic_device_init(struct PCMachineState *pcms,qemu_register_boot_set (pc_boot_set, *rtc_state); -if (!xen_enabled () && pcms->pit_enabled) { +if (!xen_enabled () && + (x86ms->pit ==ON_OFF_AUTO_AUTO || x86ms->pit ==ON_OFF_AUTO_ON )) {if (kvm_pit_in_kernel ()) { pit =kvm_pit_init (isa_bus,0x40 ); }else {
@@ -1537,20 +1539,6 @@ static void pc_machine_set_sata(Object *obj, bool value, Error **errp) pcms->sata_enabled = value; } -static bool pc_machine_get_pit (Object *obj,Error **errp) -{ -PCMachineState *pcms =PC_MACHINE (obj); - -return pcms->pit_enabled; -} - -static void pc_machine_set_pit (Object *obj,bool value,Error **errp) -{ -PCMachineState *pcms =PC_MACHINE (obj); - - pcms->pit_enabled = value; -} -static bool pc_machine_get_hpet (Object *obj,Error **errp) {PCMachineState *pcms =PC_MACHINE (obj);
@@ -1707,7 +1695,6 @@ static void pc_machine_initfn(Object *obj) pcms->acpi_build_enabled =PC_MACHINE_GET_CLASS (pcms)->has_acpi_build; pcms->smbus_enabled = true; pcms->sata_enabled = true; - pcms->pit_enabled = true; pcms->i8042_enabled = true; pcms->max_fw_size =8 * MiB;#ifdef CONFIG_HPET
@@ -1836,11 +1823,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,PC_MACHINE_SATA ,"Enable/disable Serial ATA bus" ); -object_class_property_add_bool (oc,PC_MACHINE_PIT , - pc_machine_get_pit, pc_machine_set_pit); -object_class_property_set_description (oc,PC_MACHINE_PIT , -"Enable/disable Intel 8254 programmable interval timer emulation" ); -object_class_property_add_bool (oc,"hpet" , pc_machine_get_hpet, pc_machine_set_hpet); object_class_property_set_description(oc, "hpet",
hw/i386/x86.c +25 -0
@@ -1244,6 +1244,23 @@ static void x86_machine_set_acpi(Object *obj, Visitor *v, const char *name,visit_type_OnOffAuto (v, name, &x86ms->acpi, errp); } +static void x86_machine_get_pit (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +X86MachineState *x86ms =X86_MACHINE (obj); +OnOffAuto pit = x86ms->pit; + +visit_type_OnOffAuto (v, name, &pit, errp); +} + +static void x86_machine_set_pit (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +X86MachineState *x86ms =X86_MACHINE (obj);; + +visit_type_OnOffAuto (v, name, &x86ms->pit, errp); +} +static char *x86_machine_get_oem_id (Object *obj,Error **errp) {X86MachineState *x86ms =X86_MACHINE (obj);
@@ -1333,6 +1350,7 @@ static void x86_machine_initfn(Object *obj) x86ms->smm =ON_OFF_AUTO_AUTO ; x86ms->acpi =ON_OFF_AUTO_AUTO ; + x86ms->pit =ON_OFF_AUTO_AUTO ; x86ms->pci_irq_mask =ACPI_BUILD_PCI_IRQS ; x86ms->oem_id =g_strndup (ACPI_BUILD_APPNAME6 ,6 ); x86ms->oem_table_id =g_strndup (ACPI_BUILD_APPNAME8 ,8 );
@@ -1364,6 +1382,13 @@ static void x86_machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,X86_MACHINE_ACPI ,"Enable ACPI" ); +object_class_property_add (oc,X86_MACHINE_PIT ,"OnOffAuto" , + x86_machine_get_pit, + x86_machine_set_pit, +NULL ,NULL ); +object_class_property_set_description (oc,X86_MACHINE_PIT , +"Enable i8254 PIT" ); +object_class_property_add_str (oc,X86_MACHINE_OEM_ID , x86_machine_get_oem_id, x86_machine_set_oem_id);
Signature · 1 line
MST
[PULL v2 74/86] include/hw/pci/pcie_host: Correct PCIE_MMCFG_BUS_MASK
In reply to Michael S. TsirkinFrom: Francisco Iglesias <[email protected]>
According to [1] address bits 27 - 20 are mapped to the bus number (the TLPs bus number field is 8 bits). Below is the formula taken from Table 7-1 in [1].
"
Memory Address | PCI Express Configuration Space
A[(20+n-1):20] | Bus Number, 1 ≤ n ≤ 8
"
[1] PCI Express® Base Specification Revision 5.0 Version 1.0
Message-Id: <[email protected]>
--- include/hw/pci/pcie_host.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/hw/pci/pcie_host.h +2 -2
@@ -60,7 +60,7 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,/* * PCI express ECAM (Enhanced Configuration Address Mapping) format. * AKA mmcfg address -* bit 20 - 28: bus number +* bit 20 - 27: bus number * bit 15 - 19: device number * bit 12 - 14: function number * bit 0 - 11: offset in configuration space of a given device
@@ -68,7 +68,7 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,#define PCIE_MMCFG_SIZE_MAX (1ULL << 29)#define PCIE_MMCFG_SIZE_MIN (1ULL << 20)#define PCIE_MMCFG_BUS_BIT 20 -#define PCIE_MMCFG_BUS_MASK 0x1ff +#define PCIE_MMCFG_BUS_MASK 0xff#define PCIE_MMCFG_DEVFN_BIT 12#define PCIE_MMCFG_DEVFN_MASK 0xff#define PCIE_MMCFG_CONFOFFSET_MASK 0xfff
Signature · 1 line
MST
[PULL v2 78/86] hw/i386/amd_iommu: Fix IOMMU event log encoding errors
In reply to Michael S. TsirkinFrom: Wei Huang <[email protected]>
Coverity issues several UNINIT warnings against amd_iommu.c [1]. This patch fixes them by clearing evt before encoding. On top of it, this patch changes the event log size to 16 bytes per IOMMU specification, and fixes the event log entry format in amdvi_encode_event().
[1] CID 1487116/1487200/1487190/1487232/1487115/1487258
Message-Id: <[email protected]>
--- hw/i386/amd_iommu.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
hw/i386/amd_iommu.c +14 -10
@@ -201,15 +201,18 @@ static void amdvi_setevent_bits(uint64_t *buffer, uint64_t value, int start,/* * AMDVi event structure * 0:15 -> DeviceID -* 55:63 -> event type + miscellaneous info -* 63:127 -> related address +* 48:63 -> event type + miscellaneous info +* 64:127 -> related address */ static void amdvi_encode_event (uint64_t *evt,uint16_t devid,uint64_t addr,uint16_t info) { + evt[0 ] =0 ; + evt[1 ] =0 ; +amdvi_setevent_bits (evt, devid,0 ,16 ); -amdvi_setevent_bits (evt, info,55 ,8 ); -amdvi_setevent_bits (evt, addr,63 ,64 ); +amdvi_setevent_bits (evt, info,48 ,16 ); +amdvi_setevent_bits (evt, addr,64 ,64 ); }/* log an error encountered during a page walk *
@@ -218,7 +221,7 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t devid, uint64_t addr,static void amdvi_page_fault (AMDVIState *s,uint16_t devid,hwaddr addr,uint16_t info) { -uint64_t evt[4 ]; +uint64_t evt[2 ]; info |=AMDVI_EVENT_IOPF_I |AMDVI_EVENT_IOPF ;amdvi_encode_event (evt, devid, addr, info);
@@ -234,7 +237,7 @@ static void amdvi_page_fault(AMDVIState *s, uint16_t devid,static void amdvi_log_devtab_error (AMDVIState *s,uint16_t devid,hwaddr devtab,uint16_t info) { -uint64_t evt[4 ]; +uint64_t evt[2 ]; info |=AMDVI_EVENT_DEV_TAB_HW_ERROR ;
@@ -248,7 +251,8 @@ static void amdvi_log_devtab_error(AMDVIState *s, uint16_t devid,*/ static void amdvi_log_command_error (AMDVIState *s,hwaddr addr) { -uint64_t evt[4 ], info =AMDVI_EVENT_COMMAND_HW_ERROR ; +uint64_t evt[2 ]; +uint16_t info =AMDVI_EVENT_COMMAND_HW_ERROR ;amdvi_encode_event (evt,0 , addr, info);amdvi_log_event (s, evt);
@@ -261,7 +265,7 @@ static void amdvi_log_command_error(AMDVIState *s, hwaddr addr)static void amdvi_log_illegalcom_error (AMDVIState *s,uint16_t info,hwaddr addr) { -uint64_t evt[4 ]; +uint64_t evt[2 ]; info |=AMDVI_EVENT_ILLEGAL_COMMAND_ERROR ;amdvi_encode_event (evt,0 , addr, info);
@@ -276,7 +280,7 @@ static void amdvi_log_illegalcom_error(AMDVIState *s, uint16_t info,static void amdvi_log_illegaldevtab_error (AMDVIState *s,uint16_t devid,hwaddr addr,uint16_t info) { -uint64_t evt[4 ]; +uint64_t evt[2 ]; info |=AMDVI_EVENT_ILLEGAL_DEVTAB_ENTRY ;amdvi_encode_event (evt, devid, addr, info);
@@ -288,7 +292,7 @@ static void amdvi_log_illegaldevtab_error(AMDVIState *s, uint16_t devid,static void amdvi_log_pagetab_error (AMDVIState *s,uint16_t devid,hwaddr addr,uint16_t info) { -uint64_t evt[4 ]; +uint64_t evt[2 ]; info |=AMDVI_EVENT_PAGE_TAB_HW_ERROR ;amdvi_encode_event (evt, devid, addr, info);
Signature · 1 line
MST
[PULL v2 82/86] vhost-net: fix improper cleanup in vhost_net_start
In reply to Michael S. TsirkinFrom: Si-Wei Liu <[email protected]>
vhost_net_start() missed a corresponding stop_one() upon error from vhost_set_vring_enable(). While at it, make the error handling for err_start more robust. No real issue was found due to this though.
Message-Id: <[email protected]>
--- hw/net/vhost_net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/net/vhost_net.c +3 -1
@@ -381,6 +381,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, r =vhost_set_vring_enable (peer, peer->vring_enable);if (r <0 ) { +vhost_net_stop_one (get_vhost_net (peer), dev); goto err_start; } }
@@ -390,7 +391,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, err_start:while (--i >=0 ) { - peer =qemu_get_peer (ncs , i); + peer =qemu_get_peer (ncs, i < data_queue_pairs ? + i : n->max_queue_pairs);vhost_net_stop_one (get_vhost_net (peer), dev); } e = k->set_guest_notifiers (qbus->parent, total_notifiers, false);
Signature · 1 line
MST
[PULL v2 80/86] virtio-net: align ctrl_vq index for non-mq guest for vhost_vdpa
In reply to Michael S. TsirkinFrom: Si-Wei Liu <[email protected]>
With MQ enabled vdpa device and non-MQ supporting guest e.g. booting vdpa with mq=on over OVMF of single vqp, below assert failure is seen:
../hw/virtio/vhost-vdpa.c:560: vhost_vdpa_get_vq_index: Assertion `idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs' failed.
0 0x00007f8ce3ff3387 in raise () at /lib64/libc.so.6 1 0x00007f8ce3ff4a78 in abort () at /lib64/libc.so.6 2 0x00007f8ce3fec1a6 in __assert_fail_base () at /lib64/libc.so.6 3 0x00007f8ce3fec252 in () at /lib64/libc.so.6 4 0x0000558f52d79421 in vhost_vdpa_get_vq_index (dev=<optimized out>, idx=<optimized out>) at ../hw/virtio/vhost-vdpa.c:563 5 0x0000558f52d79421 in vhost_vdpa_get_vq_index (dev=<optimized out>, idx=<optimized out>) at ../hw/virtio/vhost-vdpa.c:558 6 0x0000558f52d7329a in vhost_virtqueue_mask (hdev=0x558f55c01800, vdev=0x558f568f91f0, n=2, mask=<optimized out>) at ../hw/virtio/vhost.c:1557 7 0x0000558f52c6b89a in virtio_pci_set_guest_notifier (d=d@entry=0x558f568f0f60, n=n@entry=2, assign=assign@entry=true, with_irqfd=with_irqfd@entry=false)
at ../hw/virtio/virtio-pci.c:974
8 0x0000558f52c6c0d8 in virtio_pci_set_guest_notifiers (d=0x558f568f0f60, nvqs=3, assign=true) at ../hw/virtio/virtio-pci.c:1019
9 0x0000558f52bf091d in vhost_net_start (dev=dev@entry=0x558f568f91f0, ncs=0x558f56937cd0, data_queue_pairs=data_queue_pairs@entry=1, cvq=cvq@entry=1)
at ../hw/net/vhost_net.c:361
10 0x0000558f52d4e5e7 in virtio_net_set_status (status=<optimized out>, n=0x558f568f91f0) at ../hw/net/virtio-net.c:289
11 0x0000558f52d4e5e7 in virtio_net_set_status (vdev=0x558f568f91f0, status=15 '\017') at ../hw/net/virtio-net.c:370
12 0x0000558f52d6c4b2 in virtio_set_status (vdev=vdev@entry=0x558f568f91f0, val=val@entry=15 '\017') at ../hw/virtio/virtio.c:1945
13 0x0000558f52c69eff in virtio_pci_common_write (opaque=0x558f568f0f60, addr=<optimized out>, val=<optimized out>, size=<optimized out>) at ../hw/virtio/virtio-pci.c:1292
14 0x0000558f52d15d6e in memory_region_write_accessor (mr=0x558f568f19d0, addr=20, value=<optimized out>, size=1, shift=<optimized out>, mask=<optimized out>, attrs=...)
at ../softmmu/memory.c:492
15 0x0000558f52d127de in access_with_adjusted_size (addr=addr@entry=20, value=value@entry=0x7f8cdbffe748, size=size@entry=1, access_size_min=<optimized out>, access_size_max=<optimized out>, access_fn=0x558f52d15cf0 <memory_region_write_accessor>, mr=0x558f568f19d0, attrs=...) at ../softmmu/memory.c:554 16 0x0000558f52d157ef in memory_region_dispatch_write (mr=mr@entry=0x558f568f19d0, addr=20, data=<optimized out>, op=<optimized out>, attrs=attrs@entry=...)
at ../softmmu/memory.c:1504
17 0x0000558f52d078e7 in flatview_write_continue (fv=fv@entry=0x7f8accbc3b90, addr=addr@entry=103079215124, attrs=..., ptr=ptr@entry=0x7f8ce6300028, len=len@entry=1, addr1=<optimized out>, l=<optimized out>, mr=0x558f568f19d0) at /home/opc/qemu-upstream/include/qemu/host-utils.h:165 18 0x0000558f52d07b06 in flatview_write (fv=0x7f8accbc3b90, addr=103079215124, attrs=..., buf=0x7f8ce6300028, len=1) at ../softmmu/physmem.c:2822
19 0x0000558f52d0b36b in address_space_write (as=<optimized out>, addr=<optimized out>, attrs=..., buf=buf@entry=0x7f8ce6300028, len=<optimized out>)
at ../softmmu/physmem.c:2914
20 0x0000558f52d0b3da in address_space_rw (as=<optimized out>, addr=<optimized out>, attrs=...,
attrs@entry=..., buf=buf@entry=0x7f8ce6300028, len=<optimized out>, is_write=<optimized out>) at ../softmmu/physmem.c:2924
21 0x0000558f52dced09 in kvm_cpu_exec (cpu=cpu@entry=0x558f55c2da60) at ../accel/kvm/kvm-all.c:2903
22 0x0000558f52dcfabd in kvm_vcpu_thread_fn (arg=arg@entry=0x558f55c2da60) at ../accel/kvm/kvm-accel-ops.c:49
23 0x0000558f52f9f04a in qemu_thread_start (args=<optimized out>) at ../util/qemu-thread-posix.c:556
24 0x00007f8ce4392ea5 in start_thread () at /lib64/libpthread.so.0
25 0x00007f8ce40bb9fd in clone () at /lib64/libc.so.6
The cause for the assert failure is due to that the vhost_dev index for the ctrl vq was not aligned with actual one in use by the guest. Upon multiqueue feature negotiation in virtio_net_set_multiqueue(), if guest doesn't support multiqueue, the guest vq layout would shrink to a single queue pair, consisting of 3 vqs in total (rx, tx and ctrl). This results in ctrl_vq taking a different vhost_dev group index than the default. We can map vq to the correct vhost_dev group by checking if MQ is supported by guest and successfully negotiated. Since the MQ feature is only present along with CTRL_VQ, we ensure the index 2 is only meant for the control vq while MQ is not supported by guest.
Message-Id: <[email protected]>
--- hw/net/virtio-net.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
hw/net/virtio-net.c +31 -2
@@ -14,6 +14,7 @@#include "qemu/osdep.h" #include "qemu/atomic.h" #include "qemu/iov.h" +#include "qemu/log.h" #include "qemu/main-loop.h" #include "qemu/module.h" #include "hw/virtio/virtio.h"
@@ -3172,8 +3173,22 @@ static NetClientInfo net_virtio_info = {static bool virtio_net_guest_notifier_pending (VirtIODevice *vdev,int idx) {VirtIONet *n =VIRTIO_NET (vdev); -NetClientState *nc =qemu_get_subqueue (n->nic,vq2q (idx)); +NetClientState *nc;assert (n->vhost_started); +if (!virtio_vdev_has_feature (vdev,VIRTIO_NET_F_MQ ) && idx ==2 ) { +/* Must guard against invalid features and bogus queue index +* from being set by malicious guest, or penetrated through +* buggy migration stream. +*/ +if (!virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ )) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bogus vq index ignored\n" , __func__); +return false; + } + nc =qemu_get_subqueue (n->nic, n->max_queue_pairs); + }else { + nc =qemu_get_subqueue (n->nic,vq2q (idx)); + }return vhost_net_virtqueue_pending (get_vhost_net (nc->peer), idx); }
@@ -3181,8 +3196,22 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) {VirtIONet *n =VIRTIO_NET (vdev); -NetClientState *nc =qemu_get_subqueue (n->nic,vq2q (idx)); +NetClientState *nc;assert (n->vhost_started); +if (!virtio_vdev_has_feature (vdev,VIRTIO_NET_F_MQ ) && idx ==2 ) { +/* Must guard against invalid features and bogus queue index +* from being set by malicious guest, or penetrated through +* buggy migration stream. +*/ +if (!virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ )) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bogus vq index ignored\n" , __func__); +return ; + } + nc =qemu_get_subqueue (n->nic, n->max_queue_pairs); + }else { + nc =qemu_get_subqueue (n->nic,vq2q (idx)); + }vhost_net_virtqueue_mask (get_vhost_net (nc->peer), vdev, idx, mask); }
Signature · 1 line
MST
[PULL v2 84/86] vhost-vdpa: change name and polarity for vhost_vdpa_one_time_request()
In reply to Michael S. TsirkinFrom: Si-Wei Liu <[email protected]>
The name vhost_vdpa_one_time_request() was confusing. No matter whatever it returns, its typical occurrence had always been at requests that only need to be applied once. And the name didn't suggest what it actually checks for. Change it to vhost_vdpa_first_dev() with polarity flipped for better readibility of code. That way it is able to reflect what the check is really about.
This call is applicable to request which performs operation only once, before queues are set up, and usually at the beginning of the caller function. Document the requirement for it in place.
Message-Id: <[email protected]>
--- hw/virtio/vhost-vdpa.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
hw/virtio/vhost-vdpa.c +15 -8
@@ -368,11 +368,18 @@ static void vhost_vdpa_get_iova_range(struct vhost_vdpa *v) v->iova_range.last); } -static bool vhost_vdpa_one_time_request (struct vhost_dev *dev) +/* +* The use of this function is for requests that only need to be +* applied once. Typically such request occurs at the beginning +* of operation, and before setting up queues. It should not be +* used for request that performs operation until all queues are +* set, which would need to check dev->vq_index_end instead. +*/ +static bool vhost_vdpa_first_dev (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -return v->index !=0 ; +return v->index ==0 ; } static int vhost_vdpa_get_dev_features(struct vhost_dev *dev,
@@ -453,7 +460,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)vhost_vdpa_get_iova_range (v); -if (vhost_vdpa_one_time_request (dev)) { +if (!vhost_vdpa_first_dev (dev)) {return 0 ; }
@@ -596,7 +603,7 @@ static int vhost_vdpa_memslots_limit(struct vhost_dev *dev)static int vhost_vdpa_set_mem_table (struct vhost_dev *dev,struct vhost_memory *mem) { -if (vhost_vdpa_one_time_request (dev)) { +if (!vhost_vdpa_first_dev (dev)) {return 0 ; }
@@ -625,7 +632,7 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,struct vhost_vdpa *v = dev->opaque;int ret; -if (vhost_vdpa_one_time_request (dev)) { +if (!vhost_vdpa_first_dev (dev)) {return 0 ; }
@@ -667,7 +674,7 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) features &= f; -if (!vhost_vdpa_one_time_request (dev)) { +if (vhost_vdpa_first_dev (dev)) { r =vhost_vdpa_call (dev,VHOST_SET_BACKEND_FEATURES , &features);if (r) {return -EFAULT ;
@@ -1120,7 +1127,7 @@ static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, struct vhost_log *log) {struct vhost_vdpa *v = dev->opaque; -if (v->shadow_vqs_enabled ||vhost_vdpa_one_time_request (dev)) { +if (v->shadow_vqs_enabled || !vhost_vdpa_first_dev (dev)) {return 0 ; }
@@ -1242,7 +1249,7 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev,static int vhost_vdpa_set_owner (struct vhost_dev *dev) { -if (vhost_vdpa_one_time_request (dev)) { +if (!vhost_vdpa_first_dev (dev)) {return 0 ; }
Signature · 1 line
MST
[PULL v2 77/86] hw/i386: Make pic a property of common x86 base machine type
In reply to Michael S. TsirkinFrom: Xiaoyao Li <[email protected]>
Legacy PIC (8259) cannot be supported for TDX guests since TDX module doesn't allow directly interrupt injection. Using posted interrupts for the PIC is not a viable option as the guest BIOS/kernel will not do EOI for PIC IRQs, i.e. will leave the vIRR bit set.
Make PIC the property of common x86 machine type. Hence all x86 machines, including microvm, can disable it.
Message-Id: <[email protected]>
--- include/hw/i386/microvm.h | 2 -- include/hw/i386/x86.h | 2 ++ hw/i386/microvm.c | 27 +-------------------------- hw/i386/pc_piix.c | 4 +++- hw/i386/pc_q35.c | 4 +++- hw/i386/x86.c | 25 +++++++++++++++++++++++++ 6 files changed, 34 insertions(+), 30 deletions(-)
include/hw/i386/microvm.h +0 -2
@@ -67,7 +67,6 @@#define PCIE_ECAM_SIZE 0x10000000/* Machine type options */ -#define MICROVM_MACHINE_PIC "pic"#define MICROVM_MACHINE_RTC "rtc"#define MICROVM_MACHINE_PCIE "pcie"#define MICROVM_MACHINE_IOAPIC2 "ioapic2"
@@ -85,7 +84,6 @@ struct MicrovmMachineState {X86MachineState parent;/* Machine type options */ -OnOffAuto pic;OnOffAuto rtc;OnOffAuto pcie;OnOffAuto ioapic2;
include/hw/i386/x86.h +2 -0
@@ -66,6 +66,7 @@ struct X86MachineState {OnOffAuto smm;OnOffAuto acpi;OnOffAuto pit; +OnOffAuto pic;char *oem_id;char *oem_table_id;
@@ -86,6 +87,7 @@ struct X86MachineState {#define X86_MACHINE_SMM "smm"#define X86_MACHINE_ACPI "acpi"#define X86_MACHINE_PIT "pit" +#define X86_MACHINE_PIC "pic"#define X86_MACHINE_OEM_ID "x-oem-id"#define X86_MACHINE_OEM_TABLE_ID "x-oem-table-id"#define X86_MACHINE_BUS_LOCK_RATELIMIT "bus-lock-ratelimit"
hw/i386/microvm.c +1 -26
@@ -247,7 +247,7 @@ static void microvm_devices_init(MicrovmMachineState *mms) x86ms->pci_irq_mask =0 ; } -if (mms->pic ==ON_OFF_AUTO_ON || mms->pic ==ON_OFF_AUTO_AUTO ) { +if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) {qemu_irq *i8259; i8259 =i8259_init (isa_bus,x86_allocate_cpu_irq ());
@@ -491,23 +491,6 @@ static void microvm_machine_reset(MachineState *machine) } } -static void microvm_machine_get_pic (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -MicrovmMachineState *mms =MICROVM_MACHINE (obj); -OnOffAuto pic = mms->pic; - -visit_type_OnOffAuto (v, name, &pic, errp); -} - -static void microvm_machine_set_pic (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -MicrovmMachineState *mms =MICROVM_MACHINE (obj); - -visit_type_OnOffAuto (v, name, &mms->pic, errp); -} -static void microvm_machine_get_rtc (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -632,7 +615,6 @@ static void microvm_machine_initfn(Object *obj)MicrovmMachineState *mms =MICROVM_MACHINE (obj);/* Configuration */ - mms->pic =ON_OFF_AUTO_AUTO ; mms->rtc =ON_OFF_AUTO_AUTO ; mms->pcie =ON_OFF_AUTO_AUTO ; mms->ioapic2 =ON_OFF_AUTO_AUTO ;
@@ -684,13 +666,6 @@ static void microvm_class_init(ObjectClass *oc, void *data) x86mc->fwcfg_dma_enabled = true; -object_class_property_add (oc,MICROVM_MACHINE_PIC ,"OnOffAuto" , - microvm_machine_get_pic, - microvm_machine_set_pic, -NULL ,NULL ); -object_class_property_set_description (oc,MICROVM_MACHINE_PIC , -"Enable i8259 PIC" ); - object_class_property_add(oc, MICROVM_MACHINE_RTC, "OnOffAuto", microvm_machine_get_rtc, microvm_machine_set_rtc,
hw/i386/pc_piix.c +3 -1
@@ -218,7 +218,9 @@ static void pc_init1(MachineState *machine, }isa_bus_irqs (isa_bus, x86ms->gsi); -pc_i8259_create (isa_bus, gsi_state->i8259_irq); +if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) { +pc_i8259_create (isa_bus, gsi_state->i8259_irq); + }if (pcmc->pci_enabled) {ioapic_init_gsi (gsi_state,"i440fx" );
hw/i386/pc_q35.c +3 -1
@@ -265,7 +265,9 @@ static void pc_q35_init(MachineState *machine)pci_bus_set_route_irq_fn (host_bus, ich9_route_intx_pin_to_irq); isa_bus = ich9_lpc->isa_bus; -pc_i8259_create (isa_bus, gsi_state->i8259_irq); +if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) { +pc_i8259_create (isa_bus, gsi_state->i8259_irq); + }if (pcmc->pci_enabled) {ioapic_init_gsi (gsi_state,"q35" );
hw/i386/x86.c +25 -0
@@ -1261,6 +1261,23 @@ static void x86_machine_set_pit(Object *obj, Visitor *v, const char *name,visit_type_OnOffAuto (v, name, &x86ms->pit, errp); } +static void x86_machine_get_pic (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +X86MachineState *x86ms =X86_MACHINE (obj); +OnOffAuto pic = x86ms->pic; + +visit_type_OnOffAuto (v, name, &pic, errp); +} + +static void x86_machine_set_pic (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +X86MachineState *x86ms =X86_MACHINE (obj); + +visit_type_OnOffAuto (v, name, &x86ms->pic, errp); +} +static char *x86_machine_get_oem_id (Object *obj,Error **errp) {X86MachineState *x86ms =X86_MACHINE (obj);
@@ -1351,6 +1368,7 @@ static void x86_machine_initfn(Object *obj) x86ms->smm =ON_OFF_AUTO_AUTO ; x86ms->acpi =ON_OFF_AUTO_AUTO ; x86ms->pit =ON_OFF_AUTO_AUTO ; + x86ms->pic =ON_OFF_AUTO_AUTO ; x86ms->pci_irq_mask =ACPI_BUILD_PCI_IRQS ; x86ms->oem_id =g_strndup (ACPI_BUILD_APPNAME6 ,6 ); x86ms->oem_table_id =g_strndup (ACPI_BUILD_APPNAME8 ,8 );
@@ -1389,6 +1407,13 @@ static void x86_machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,X86_MACHINE_PIT ,"Enable i8254 PIT" ); +object_class_property_add (oc,X86_MACHINE_PIC ,"OnOffAuto" , + x86_machine_get_pic, + x86_machine_set_pic, +NULL ,NULL ); +object_class_property_set_description (oc,X86_MACHINE_PIC , +"Enable i8259 PIC" ); +object_class_property_add_str (oc,X86_MACHINE_OEM_ID , x86_machine_get_oem_id, x86_machine_set_oem_id);
Signature · 1 line
MST
[PULL v2 86/86] vhost-user-scsi: avoid unlink(NULL) with fd passing
In reply to Michael S. TsirkinFrom: Stefan Hajnoczi <[email protected]>
Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi") introduced fd-passing support as part of implementing the vhost-user backend program conventions.
When fd passing is used the UNIX domain socket path is NULL and we must not call unlink(2).
The unlink(2) call is necessary when the listen socket, lsock, was created successfully since that means the UNIX domain socket is visible in the file system.
Message-Id: <[email protected]>
--- contrib/vhost-user-scsi/vhost-user-scsi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/vhost-user-scsi/vhost-user-scsi.c +4 -1
@@ -433,13 +433,16 @@ out:if (vdev_scsi) {g_main_loop_unref (vdev_scsi->loop);g_free (vdev_scsi); -unlink (opt_socket_path); }if (csock >=0 ) {close (csock); }if (lsock >=0 ) {close (lsock); + +if (opt_socket_path) { +unlink (opt_socket_path); + } }g_free (opt_socket_path);g_free (iscsi_uri);
Signature · 1 line
MST
[PULL v2 81/86] vhost-vdpa: fix improper cleanup in net_init_vhost_vdpa
In reply to Michael S. TsirkinFrom: Si-Wei Liu <[email protected]>
... such that no memory leaks on dangling net clients in case of error.
Message-Id: <[email protected]>
--- net/vhost-vdpa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/vhost-vdpa.c +3 -1
@@ -306,7 +306,9 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, err:if (i) { -qemu_del_net_client (ncs[0 ]); +for (i--; i >=0 ; i--) { +qemu_del_net_client (ncs[i]); + } }qemu_close (vdpa_device_fd);
Signature · 1 line
MST
[PULL v2 85/86] virtio-net: don't handle mq request in userspace handler for vhost-vdpa
In reply to Michael S. TsirkinFrom: Si-Wei Liu <[email protected]>
virtio_queue_host_notifier_read() tends to read pending event left behind on ioeventfd in the vhost_net_stop() path, and attempts to handle outstanding kicks from userspace vq handler. However, in the ctrl_vq handler, virtio_net_handle_mq() has a recursive call into virtio_net_set_status(), which may lead to segmentation fault as shown in below stack trace:
0 0x000055f800df1780 in qdev_get_parent_bus (dev=0x0) at ../hw/core/qdev.c:376 1 0x000055f800c68ad8 in virtio_bus_device_iommu_enabled (vdev=vdev@entry=0x0) at ../hw/virtio/virtio-bus.c:331 2 0x000055f800d70d7f in vhost_memory_unmap (dev=<optimized out>) at ../hw/virtio/vhost.c:318 3 0x000055f800d70d7f in vhost_memory_unmap (dev=<optimized out>, buffer=0x7fc19bec5240, len=2052, is_write=1, access_len=2052) at ../hw/virtio/vhost.c:336 4 0x000055f800d71867 in vhost_virtqueue_stop (dev=dev@entry=0x55f8037ccc30, vdev=vdev@entry=0x55f8044ec590, vq=0x55f8037cceb0, idx=0) at ../hw/virtio/vhost.c:1241 5 0x000055f800d7406c in vhost_dev_stop (hdev=hdev@entry=0x55f8037ccc30, vdev=vdev@entry=0x55f8044ec590) at ../hw/virtio/vhost.c:1839 6 0x000055f800bf00a7 in vhost_net_stop_one (net=0x55f8037ccc30, dev=0x55f8044ec590) at ../hw/net/vhost_net.c:315 7 0x000055f800bf0678 in vhost_net_stop (dev=dev@entry=0x55f8044ec590, ncs=0x55f80452bae0, data_queue_pairs=data_queue_pairs@entry=7, cvq=cvq@entry=1)
at ../hw/net/vhost_net.c:423
8 0x000055f800d4e628 in virtio_net_set_status (status=<optimized out>, n=0x55f8044ec590) at ../hw/net/virtio-net.c:296
9 0x000055f800d4e628 in virtio_net_set_status (vdev=vdev@entry=0x55f8044ec590, status=15 '\017') at ../hw/net/virtio-net.c:370
10 0x000055f800d534d8 in virtio_net_handle_ctrl (iov_cnt=<optimized out>, iov=<optimized out>, cmd=0 '\000', n=0x55f8044ec590) at ../hw/net/virtio-net.c:1408 11 0x000055f800d534d8 in virtio_net_handle_ctrl (vdev=0x55f8044ec590, vq=0x7fc1a7e888d0) at ../hw/net/virtio-net.c:1452
12 0x000055f800d69f37 in virtio_queue_host_notifier_read (vq=0x7fc1a7e888d0) at ../hw/virtio/virtio.c:2331
13 0x000055f800d69f37 in virtio_queue_host_notifier_read (n=n@entry=0x7fc1a7e8894c) at ../hw/virtio/virtio.c:3575
14 0x000055f800c688e6 in virtio_bus_cleanup_host_notifier (bus=<optimized out>, n=n@entry=14) at ../hw/virtio/virtio-bus.c:312
15 0x000055f800d73106 in vhost_dev_disable_notifiers (hdev=hdev@entry=0x55f8035b51b0, vdev=vdev@entry=0x55f8044ec590)
at ../../../include/hw/virtio/virtio-bus.h:35
16 0x000055f800bf00b2 in vhost_net_stop_one (net=0x55f8035b51b0, dev=0x55f8044ec590) at ../hw/net/vhost_net.c:316
17 0x000055f800bf0678 in vhost_net_stop (dev=dev@entry=0x55f8044ec590, ncs=0x55f80452bae0, data_queue_pairs=data_queue_pairs@entry=7, cvq=cvq@entry=1)
at ../hw/net/vhost_net.c:423
18 0x000055f800d4e628 in virtio_net_set_status (status=<optimized out>, n=0x55f8044ec590) at ../hw/net/virtio-net.c:296
19 0x000055f800d4e628 in virtio_net_set_status (vdev=0x55f8044ec590, status=15 '\017') at ../hw/net/virtio-net.c:370
20 0x000055f800d6c4b2 in virtio_set_status (vdev=0x55f8044ec590, val=<optimized out>) at ../hw/virtio/virtio.c:1945
21 0x000055f800d11d9d in vm_state_notify (running=running@entry=false, state=state@entry=RUN_STATE_SHUTDOWN) at ../softmmu/runstate.c:333 22 0x000055f800d04e7a in do_vm_stop (state=state@entry=RUN_STATE_SHUTDOWN, send_stop=send_stop@entry=false) at ../softmmu/cpus.c:262 23 0x000055f800d04e99 in vm_shutdown () at ../softmmu/cpus.c:280
24 0x000055f800d126af in qemu_cleanup () at ../softmmu/runstate.c:812
25 0x000055f800ad5b13 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at ../softmmu/main.c:51
For now, temporarily disable handling MQ request from the ctrl_vq userspace hanlder to avoid the recursive virtio_net_set_status() call. Some rework is needed to allow changing the number of queues without going through a full virtio_net_set_status cycle, particularly for vhost-vdpa backend.
This patch will need to be reverted as soon as future patches of having the change of #queues handled in userspace is merged.
Message-Id: <[email protected]>
--- hw/net/virtio-net.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/net/virtio-net.c +13 -0
@@ -1381,6 +1381,7 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, {VirtIODevice *vdev =VIRTIO_DEVICE (n);uint16_t queue_pairs; +NetClientState *nc =qemu_get_queue (n->nic);virtio_net_disable_rss (n);if (cmd ==VIRTIO_NET_CTRL_MQ_HASH_CONFIG ) {
@@ -1412,6 +1413,18 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd,return VIRTIO_NET_ERR ; } +/* Avoid changing the number of queue_pairs for vdpa device in +* userspace handler. A future fix is needed to handle the mq +* change in userspace handler with vhost-vdpa. Let's disable +* the mq handling from userspace for now and only allow get +* done through the kernel. Ripples may be seen when falling +* back to userspace, but without doing it qemu process would +* crash on a recursive entry to virtio_net_set_status(). +*/ +if (nc->peer && nc->peer->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +return VIRTIO_NET_ERR ; + } + n->curr_queue_pairs = queue_pairs;/* stop the backend before changing the number of queue_pairs to avoid handling a * disabled queue */
Signature · 1 line
MST
Richard Henderson
AppliedQuoted 16 lines · Michael S. Tsirkin
Changes from pull v1:
dropped introspection patches from the pullThe following changes since commit
9de5f2b40860c5f8295e73fea9922df6f0b8d89a:Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2022-05-12 10:52:15 -0700)are available in the Git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gittags/for_upstreamfor you to fetch changes up to
6852c21db229c4bf4c1db772444bdfbbd027e5b8:vhost-user-scsi: avoid unlink(NULL) with fd passing (2022-05-16 16:48:35 -0400)
Quoted 7 lines
----------------------------------------------------------------
virtio,pc,pci: fixes,cleanups,featuresmost of CXL support
fixes, cleanups all over the placeSigned-off-by Michael S. Tsirkin <[email protected]>
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.
r~
Quoted 280 lines
----------------------------------------------------------------
Alex Bennée (9):
hw/virtio: movevirtio-pci.hinto shared include space
virtio-pci: add notification trace points
hw/virtio: add vhost_user_[read|write] trace pointsvhost-user.rst: add clarifying language about protocol negotiation
libvhost-user: exposevu_request_to_string
docs/devel: start documenting writing VirtIO devicesinclude/hw: start documenting the vhost API hw/virtio/vhost-user: don't suppressF_CONFIGwhen supported virtio/vhost-user: dynamically assign VhostUserHostNotifiersBen Widawsky (24):
hw/pci/cxl: Add a CXL component type (interface) hw/cxl/component: Introduce CXL components (8.1.x, 8.2.5) hw/cxl/device: Introduce a CXL device (8.2.8) hw/cxl/device: Implement the CAP array (8.2.8.1-2) hw/cxl/device: Implement basic mailbox (8.2.8.4) hw/cxl/device: Add memory device utilities hw/cxl/device: Add cheap EVENTS implementation (8.2.9.1) hw/cxl/device: Timestamp implementation (8.2.9.3) hw/cxl/device: Add log commands (8.2.9.4) + CEL hw/pxb: Use a type for realizing expanders hw/pci/cxl: Create a CXL bus type
hw/pxb: Allow creation of a CXL PXB (host bridge) hw/cxl/rp: Add a root port
hw/cxl/device: Add a memory device (8.2.8.5) hw/cxl/device: Implement MMIO HDM decoding (8.2.5.12) hw/cxl/device: Add some trivial commands hw/cxl/device: Plumb real Label Storage Area (LSA) sizing hw/cxl/device: Implement get/set Label Storage Area (LSA) hw/cxl/component: Implement host bridge MMIO (8.2.5, table 142) acpi/cxl: Add_OSCimplementation (9.14.2)
acpi/cxl: Create the CEDT (9.14.1)
acpi/cxl: Introduce CFMWS structures in CEDT hw/cxl/component Add a dumb HDM decoder handler qtest/cxl: Add more complex test cases with CFMWsDavid Woodhouse (4):
target/i386: Fix sanity check on max APIC ID / X2APIC enablement
intel_iommu: Support IR-only mode without DMA translation
intel_iommu: Only allow interrupt remapping to be enabled if it's supported
intel_iommu: Fix irqchip / X2APIC configuration checksEugenio Pérez (5):
vhost: Track descriptor chain in private at SVQ
vhost: Fix device's used descriptor dequeue
vdpa: Fix bad index calculus atvhost_vdpa_get_vring_base
vdpa: Fix index calculus atvhost_vdpa_svqs_start
vhost: Fix element invhost_svq_addfailureFrancisco Iglesias (2):
include/hw/pci/pcie_host: CorrectPCIE_MMCFG_BUS_MASKinclude/hw/pci/pcie_host: CorrectPCIE_MMCFG_SIZE_MAXHalil Pasic (1):
virtio: fix feature negotiation forACCESS_PLATFORMIlya Maximets (1):
vhost_net: Print feature masks in hexJason Wang (5):
intel-iommu: correct the value used forerror_setg_errno()
intel-iommu: removeVTD_FR_RESERVED_ERR
intel-iommu: block output address in interrupt address range
intel-iommu: updateroot_scalablebefore switching as duringpost_load
intel-iommu: updateiq_dwduring post loadJonah Palmer (2):
virtio: drop name parameter forvirtio_init()
virtio: add vhost support for virtio devicesJonathan Cameron (16):
MAINTAINERS: Add entry for Compute Express Link Emulation
cxl: Machine level control on whether CXL support is enabled qtest/cxl: Introduce initial test for pxb-cxl only. qtests/cxl: Add initial root port and CXL type3 tests hw/cxl/component: Add utils for interleave parameter encoding/decoding hw/cxl/host: Add support for CXL Fixed Memory Windows. hw/pci-host/gpex-acpi: Add support for dsdt construction for pxb-cxl pci/pcie_port: Addpci_find_port_by_pn()CXL/cxl_component: Addcxl_get_hb_cstate()
mem/cxl_type3: Add read and write functions for associated hostmem. cxl/cxl-host: Add memops for CFMWS region.
i386/pc: Enable CXL fixed memory windows
tests/acpi: q35: Allow addition of a CXL test. qtests/bios-tables-test: Add a test for CXL emulation. tests/acpi: Add tables for CXL emulation.
docs/cxl: Add initial Compute eXpress Link (CXL) documentation.Kevin Wolf (1):
docs/vhost-user: Clarifications for VHOST_USER_ADD/REM_MEM_REGMichael S. Tsirkin (1):
vhost-user: more master/slave thingsPaolo Bonzini (3):
docs: vhost-user: clean up request/reply description
docs: vhost-user: rewrite section on ring state machine
docs: vhost-user: replace master/slave with front-end/back-endPhilippe Mathieu-Daudé (1):
hw/virtio: Replaceg_memdup()byg_memdup2()Si-Wei Liu (7):
virtio-net: setupvhost_devand notifiers for cvq only when feature is negotiated
virtio-net: alignctrl_vqindex for non-mq guest forvhost_vdpa
vhost-vdpa: fix improper cleanup innet_init_vhost_vdpa
vhost-net: fix improper cleanup invhost_net_start
vhost-vdpa: backend feature should set only once
vhost-vdpa: change name and polarity forvhost_vdpa_one_time_request()
virtio-net: don't handle mq request in userspace handler for vhost-vdpaStefan Hajnoczi (1):
vhost-user-scsi: avoid unlink(NULL) with fd passingWei Huang (1):
hw/i386/amd_iommu: Fix IOMMU event log encoding errorsXiaoyao Li (2):
hw/i386: Make pit a property of common x86 base machine type hw/i386: Make pic a property of common x86 base machine typeqapi/machine.json | 21 ++ hw/i386/intel_iommu_internal.h | 9 +- hw/virtio/vhost-shadow-virtqueue.h | 6 + include/hw/acpi/cxl.h | 28 ++ include/hw/boards.h | 2 + include/hw/cxl/cxl.h | 61 ++++ include/hw/cxl/cxl_component.h | 223 ++++++++++++ include/hw/cxl/cxl_device.h | 268 ++++++++++++++ include/hw/cxl/cxl_pci.h | 167 +++++++++ include/hw/i386/intel_iommu.h | 1 + include/hw/i386/microvm.h | 4 - include/hw/i386/pc.h | 2 - include/hw/i386/x86.h | 4 + include/hw/pci/pci.h | 14 + include/hw/pci/pci_bridge.h | 20 ++ include/hw/pci/pci_bus.h | 7 + include/hw/pci/pci_ids.h | 1 + include/hw/pci/pcie_host.h | 6 +- include/hw/pci/pcie_port.h | 2 + include/hw/virtio/vhost-user.h | 43 ++- include/hw/virtio/vhost-vsock-common.h | 2 +- include/hw/virtio/vhost.h | 132 ++++++- include/hw/virtio/virtio-gpu.h | 3 +- {hw => include/hw}/virtio/virtio-pci.h | 0 include/hw/virtio/virtio.h | 7 +- subprojects/libvhost-user/libvhost-user.h | 9 + contrib/vhost-user-scsi/vhost-user-scsi.c | 5 +- hw/9pfs/virtio-9p-device.c | 2 +- hw/acpi/cxl-stub.c | 12 + hw/acpi/cxl.c | 257 +++++++++++++ hw/block/vhost-user-blk.c | 9 +- hw/block/virtio-blk.c | 2 +- hw/char/virtio-serial-bus.c | 3 +- hw/core/machine.c | 28 ++ hw/cxl/cxl-component-utils.c | 396 ++++++++++++++++++++ hw/cxl/cxl-device-utils.c | 265 ++++++++++++++ hw/cxl/cxl-host-stubs.c | 16 + hw/cxl/cxl-host.c | 222 ++++++++++++ hw/cxl/cxl-mailbox-utils.c | 478 ++++++++++++++++++++++++ hw/display/vhost-user-gpu.c | 7 + hw/display/virtio-gpu-base.c | 2 +- hw/i386/acpi-build.c | 57 ++- hw/i386/amd_iommu.c | 24 +- hw/i386/intel_iommu.c | 95 +++-- hw/i386/microvm.c | 54 +-- hw/i386/pc.c | 89 +++-- hw/i386/pc_piix.c | 4 +- hw/i386/pc_q35.c | 4 +- hw/i386/x86.c | 66 ++++ hw/input/vhost-user-input.c | 7 + hw/input/virtio-input.c | 3 +- hw/mem/cxl_type3.c | 371 +++++++++++++++++++ hw/net/vhost_net.c | 8 +- hw/net/virtio-net.c | 63 +++- hw/pci-bridge/cxl_root_port.c | 236 ++++++++++++ hw/pci-bridge/pci_expander_bridge.c | 168 ++++++++- hw/pci-bridge/pcie_root_port.c | 6 +- hw/pci-host/gpex-acpi.c | 20 +- hw/pci/pci.c | 21 +- hw/pci/pcie_port.c | 25 ++ hw/scsi/vhost-scsi.c | 8 + hw/scsi/vhost-user-scsi.c | 1 + hw/scsi/virtio-scsi.c | 3 +- hw/virtio/vhost-scsi-pci.c | 2 +- hw/virtio/vhost-shadow-virtqueue.c | 35 +- hw/virtio/vhost-user-blk-pci.c | 2 +- hw/virtio/vhost-user-fs-pci.c | 2 +- hw/virtio/vhost-user-fs.c | 10 +- hw/virtio/vhost-user-i2c-pci.c | 2 +- hw/virtio/vhost-user-i2c.c | 7 +- hw/virtio/vhost-user-input-pci.c | 2 +- hw/virtio/vhost-user-rng-pci.c | 2 +- hw/virtio/vhost-user-rng.c | 9 +- hw/virtio/vhost-user-scsi-pci.c | 2 +- hw/virtio/vhost-user-vsock-pci.c | 2 +- hw/virtio/vhost-user-vsock.c | 2 +- hw/virtio/vhost-user.c | 131 +++++-- hw/virtio/vhost-vdpa.c | 29 +- hw/virtio/vhost-vsock-common.c | 12 +- hw/virtio/vhost-vsock-pci.c | 2 +- hw/virtio/vhost-vsock.c | 2 +- hw/virtio/vhost.c | 4 +- hw/virtio/virtio-9p-pci.c | 2 +- hw/virtio/virtio-balloon-pci.c | 2 +- hw/virtio/virtio-balloon.c | 3 +- hw/virtio/virtio-blk-pci.c | 2 +- hw/virtio/virtio-bus.c | 22 +- hw/virtio/virtio-crypto.c | 18 +- hw/virtio/virtio-input-host-pci.c | 2 +- hw/virtio/virtio-input-pci.c | 2 +- hw/virtio/virtio-iommu-pci.c | 2 +- hw/virtio/virtio-iommu.c | 3 +- hw/virtio/virtio-mem.c | 3 +- hw/virtio/virtio-net-pci.c | 2 +- hw/virtio/virtio-pci.c | 5 +- hw/virtio/virtio-pmem.c | 3 +- hw/virtio/virtio-rng-pci.c | 2 +- hw/virtio/virtio-rng.c | 2 +- hw/virtio/virtio-scsi-pci.c | 2 +- hw/virtio/virtio-serial-pci.c | 2 +- hw/virtio/virtio.c | 56 ++- net/vhost-vdpa.c | 4 +- softmmu/vl.c | 47 +++ subprojects/libvhost-user/libvhost-user.c | 2 +- target/i386/kvm/kvm-cpu.c | 2 +- tests/qtest/bios-tables-test.c | 44 +++ tests/qtest/cxl-test.c | 151 ++++++++ MAINTAINERS | 7 + docs/devel/index-internals.rst | 1 + docs/devel/virtio-backends.rst | 214 +++++++++++ docs/interop/vhost-user-gpu.rst | 10 +- docs/interop/vhost-user.rst | 579 ++++++++++++++++-------------- docs/system/device-emulation.rst | 1 + docs/system/devices/cxl.rst | 302 ++++++++++++++++ hw/Kconfig | 1 + hw/acpi/Kconfig | 5 + hw/acpi/meson.build | 4 +- hw/arm/Kconfig | 1 + hw/cxl/Kconfig | 3 + hw/cxl/meson.build | 12 + hw/mem/Kconfig | 5 + hw/mem/meson.build | 1 + hw/meson.build | 1 + hw/pci-bridge/Kconfig | 5 + hw/pci-bridge/meson.build | 1 + hw/virtio/trace-events | 10 +- qemu-options.hx | 38 ++ scripts/device-crash-test | 1 + tests/data/acpi/q35/CEDT.cxl | Bin 0 -> 184 bytes tests/data/acpi/q35/DSDT.cxl | Bin 0 -> 9615 bytes tests/qtest/meson.build | 4 + 131 files changed, 5352 insertions(+), 577 deletions(-)create mode 100644
include/hw/acpi/cxl.hcreate mode 100644include/hw/cxl/cxl.hcreate mode 100644include/hw/cxl/cxl_component.hcreate mode 100644include/hw/cxl/cxl_device.hcreate mode 100644include/hw/cxl/cxl_pci.hrename {hw =>include/hw}/virtio/virtio-pci.h(100%) create mode 100644hw/acpi/cxl-stub.ccreate mode 100644hw/acpi/cxl.c
create mode 100644hw/cxl/cxl-component-utils.ccreate mode 100644hw/cxl/cxl-device-utils.ccreate mode 100644hw/cxl/cxl-host-stubs.ccreate mode 100644hw/cxl/cxl-host.c
create mode 100644hw/cxl/cxl-mailbox-utils.ccreate mode 100644hw/mem/cxl_type3.ccreate mode 100644hw/pci-bridge/cxl_root_port.ccreate mode 100644tests/qtest/cxl-test.ccreate mode 100644docs/devel/virtio-backends.rstcreate mode 100644docs/system/devices/cxl.rstcreate mode 100644 hw/cxl/Kconfig
create mode 100644 hw/cxl/meson.build create mode 100644 tests/data/acpi/q35/CEDT.cxl create mode 100644 tests/data/acpi/q35/DSDT.cxl