target-arm queue
Subsystems (4)
The following changes since commit b10d00d8811fa4eed4862963273d7353ce310c82:
Merge remote-tracking branch 'remotes/kraxel/tags/seabios-20220118-pull-request' into staging (2022-01-19 18:46:28 +0000)
are available in the Git repository at:
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20220120
for you to fetch changes up to 9705e3c1dcff96b0b3c7e594b6cd68d27d6c4ced:
hw/intc/arm_gicv3: Check for !MEMTX_OK instead of MEMTX_ERROR (2022-01-20 11:47:54 +0000)
----------------------------------------------------------------
target-arm:
* hw/intc/arm_gicv3_its: Fix various minor bugs
* hw/arm/aspeed: Add the i3c device to the AST2600 SoC
* hw/arm: kudo: add lm75s behind bus 1 switch at 75
* hw/arm/virt: Fix support for running guests on hosts with restricted IPA ranges
* hw/intc/arm_gic: Allow reset of the running priority
* hw/intc/arm_gic: Implement read of GICC_IIDR
* hw/arm/virt: Support for virtio-mem-pci
* hw/arm/virt: Support CPU cluster on ARM virt machine
* docs/can: convert to restructuredText
* hw/net: Move MV88W8618 network device out of hw/arm/ directory
* hw/arm/virt: KVM: Enable PAuth when supported by the host
----------------------------------------------------------------
Gavin Shan (2):
virtio-mem: Correct default THP size for ARM64 hw/arm/virt: Support for virtio-mem-pci
Lucas Ramage (1):
docs/can: convert to restructuredText
Marc Zyngier (7):
hw/arm/virt: KVM: Enable PAuth when supported by the host hw/arm/virt: Add a control for the the highmem PCIe MMIO hw/arm/virt: Add a control for the the highmem redistributors hw/arm/virt: Honor highmem setting when computing the memory map hw/arm/virt: Use the PA range to compute the memory map hw/arm/virt: Disable highmem devices that don't fit in the PA range hw/arm/virt: Drop superfluous checks against highmem
Patrick Venture (1):
hw/arm: kudo add lm75s behind bus 1 switch at 75
Peter Maydell (13):
hw/intc/arm_gicv3_its: Fix event ID bounds checks hw/intc/arm_gicv3_its: Convert int ID check to num_intids convention hw/intc/arm_gicv3_its: Fix handling of process_its_cmd() return value hw/intc/arm_gicv3_its: Don't use data if reading command failed hw/intc/arm_gicv3_its: Use enum for return value of process_* functions hw/intc/arm_gicv3_its: Fix return codes in process_its_cmd() hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce nesting hw/intc/arm_gicv3_its: Fix return codes in process_mapti() hw/intc/arm_gicv3_its: Fix return codes in process_mapc() hw/intc/arm_gicv3_its: Fix return codes in process_mapd() hw/intc/arm_gicv3_its: Factor out "find address of table entry" code hw/intc/arm_gicv3_its: Check indexes before use, not after hw/intc/arm_gicv3_its: Range-check ICID before indexing into collection table
Petr Pavlu (2):
hw/intc/arm_gic: Implement read of GICC_IIDR hw/intc/arm_gic: Allow reset of the running priority
Philippe Mathieu-Daudé (4):
hw: Move MARVELL_88W8618 Kconfig from audio/ to arm/ hw/arm/musicpal: Fix coding style of code related to MV88W8618 device hw/net: Move MV88W8618 network device out of hw/arm/ directory hw/intc/arm_gicv3: Check for !MEMTX_OK instead of MEMTX_ERROR
Troy Lee (2):
hw/misc/aspeed_i3c.c: Introduce a dummy AST2600 I3C model. hw/arm/aspeed: Add the i3c device to the AST2600 SoC
Yanan Wang (6):
hw/arm/virt: Support CPU cluster on ARM virt machine hw/arm/virt: Support cluster level in DT cpu-map hw/acpi/aml-build: Improve scalability of PPTT generation tests/acpi/bios-tables-test: Allow changes to virt/PPTT file hw/acpi/aml-build: Support cluster level in PPTT generation tests/acpi/bios-table-test: Update expected virt/PPTT file
docs/system/arm/cpu-features.rst | 4 -
docs/system/device-emulation.rst | 1 +
docs/{can.txt => system/devices/can.rst} | 90 +++---
include/hw/arm/aspeed_soc.h | 3 +
include/hw/arm/virt.h | 5 +-
include/hw/misc/aspeed_i3c.h | 48 +++
include/hw/net/mv88w8618_eth.h | 12 +
target/arm/cpu.h | 1 +
hw/acpi/aml-build.c | 68 +++--
hw/arm/aspeed_ast2600.c | 16 +
hw/arm/musicpal.c | 381 +-----------------------
hw/arm/npcm7xx_boards.c | 10 +-
hw/arm/virt-acpi-build.c | 10 +-
hw/arm/virt.c | 184 ++++++++++--
hw/intc/arm_gic.c | 11 +
hw/intc/arm_gicv3_its.c | 492 ++++++++++++++-----------------
hw/intc/arm_gicv3_redist.c | 4 +-
hw/misc/aspeed_i3c.c | 381 ++++++++++++++++++++++++
hw/net/mv88w8618_eth.c | 403 +++++++++++++++++++++++++
hw/virtio/virtio-mem.c | 36 ++-
target/arm/cpu.c | 16 +-
target/arm/cpu64.c | 31 +-
target/arm/kvm64.c | 21 ++
MAINTAINERS | 2 +
hw/arm/Kconfig | 4 +
hw/audio/Kconfig | 3 -
hw/misc/meson.build | 1 +
hw/misc/trace-events | 6 +
hw/net/meson.build | 1 +
qemu-options.hx | 10 +
tests/data/acpi/virt/PPTT | Bin 76 -> 96 bytes
31 files changed, 1473 insertions(+), 782 deletions(-)
rename docs/{can.txt => system/devices/can.rst} (68%)
create mode 100644 include/hw/misc/aspeed_i3c.h
create mode 100644 include/hw/net/mv88w8618_eth.h
create mode 100644 hw/misc/aspeed_i3c.c
create mode 100644 hw/net/mv88w8618_eth.c[PULL 05/38] hw/arm/virt: Support CPU cluster on ARM virt machine
From: Yanan Wang <[email protected]>
ARM64 machines like Kunpeng Family Server Chips have a level of hardware topology in which a group of CPU cores share L3 cache tag or L2 cache. For example, Kunpeng 920 typically has 6 or 8 clusters in each NUMA node (also represent range of CPU die), and each cluster has 4 CPU cores. All clusters share L3 cache data, but CPU cores in each cluster share a local L3 tag.
Running a guest kernel with Cluster-Aware Scheduling on the Hosts which have physical clusters, if we can design a vCPU topology with cluster level for guest kernel and then have a dedicated vCPU pinning, the guest will gain scheduling performance improvement from cache affinity of CPU cluster.
So let's enable the support for this new parameter on ARM virt machines. After this patch, we can define a 4-level CPU hierarchy like: cpus=*,maxcpus=*,sockets=*,clusters=*, cores=*,threads=*.
Message-id: [email protected]
--- hw/arm/virt.c | 1 + qemu-options.hx | 10 ++++++++++ 2 files changed, 11 insertions(+)
hw/arm/virt.c +1 -0
@@ -2718,6 +2718,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) hc->unplug_request = virt_machine_device_unplug_request_cb; hc->unplug = virt_machine_device_unplug_cb; mc->nvdimm_supported = true; + mc->smp_props.clusters_supported = true; mc->auto_enable_numa_with_memhp = true; mc->auto_enable_numa_with_memdev = true; mc->default_ram_id ="mach-virt.ram" ;
qemu-options.hx +10 -0
@@ -277,6 +277,16 @@ SRST -smp 16,sockets=2,dies=2,cores=2,threads=2,maxcpus=16 + The following sub-option defines a CPU topology hierarchy (2 sockets + totally on the machine, 2 clusters per socket, 2 cores per cluster, + 2 threads per core) for ARM virt machines which support sockets/clusters + /cores/threads. Some members of the option can be omitted but their values + will be automatically computed: + + :: + + -smp 16,sockets=2,clusters=2,cores=2,threads=2,maxcpus=16 + Historically preference was given to the coarsest topology parameters when computing missing values (ie sockets preferred over cores, which were preferred over threads), however, this behaviour is considered
Signature · 1 line
2.25.1
[PULL 08/38] tests/acpi/bios-tables-test: Allow changes to virt/PPTT file
In reply to Peter MaydellFrom: Yanan Wang <[email protected]>
List test/data/acpi/virt/PPTT as the expected files allowed to be changed in tests/qtest/bios-tables-test-allowed-diff.h
Message-id: [email protected]
--- tests/qtest/bios-tables-test-allowed-diff.h | 1 + 1 file changed, 1 insertion(+)
tests/qtest/bios-tables-test-allowed-diff.h +1 -0
@@ -1 +1,2 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/virt/PPTT",
Signature · 1 line
2.25.1
[PULL 13/38] hw/arm/virt: Support for virtio-mem-pci
In reply to Peter MaydellFrom: Gavin Shan <[email protected]>
This supports virtio-mem-pci device on "virt" platform, by simply following the implementation on x86.
* This implements the hotplug handlers to support virtio-mem-pci device hot-add, while the hot-remove isn't supported as we have on x86.
* The block size is 512MB on ARM64 instead of 128MB on x86.
* It has been passing the tests with various combinations like 64KB and 4KB page sizes on host and guest, different memory device backends like normal, transparent huge page and HugeTLB, plus migration.
Message-id: [email protected]
--- hw/arm/virt.c | 70 ++++++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-mem.c | 4 ++- hw/arm/Kconfig | 1 + 3 files changed, 74 insertions(+), 1 deletion(-)
hw/arm/virt.c +70 -0
@@ -71,9 +71,11 @@#include "hw/arm/smmuv3.h" #include "hw/acpi/acpi.h" #include "target/arm/internals.h" +#include "hw/mem/memory-device.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" #include "hw/acpi/generic_event_device.h" +#include "hw/virtio/virtio-mem-pci.h" #include "hw/virtio/virtio-iommu.h" #include "hw/char/pl011.h" #include "qemu/guest-random.h"
@@ -2501,6 +2503,64 @@ static void virt_memory_plug(HotplugHandler *hotplug_dev, dev, &error_abort); } +static void virt_virtio_md_pci_pre_plug (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +HotplugHandler *hotplug_dev2 =qdev_get_bus_hotplug_handler (dev); +Error *local_err =NULL ; + +if (!hotplug_dev2 && dev->hotplugged) { +/* +* Without a bus hotplug handler, we cannot control the plug/unplug +* order. We should never reach this point when hotplugging on ARM. +* However, it's nice to add a safety net, similar to what we have +* on x86. +*/ +error_setg (errp,"hotplug of virtio based memory devices not supported" +" on this bus." ); +return ; + } +/* +* First, see if we can plug this memory device at all. If that +* succeeds, branch of to the actual hotplug handler. +*/ +memory_device_pre_plug (MEMORY_DEVICE (dev),MACHINE (hotplug_dev),NULL , + &local_err); +if (!local_err && hotplug_dev2) { +hotplug_handler_pre_plug (hotplug_dev2, dev, &local_err); + } +error_propagate (errp, local_err); +} + +static void virt_virtio_md_pci_plug (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +HotplugHandler *hotplug_dev2 =qdev_get_bus_hotplug_handler (dev); +Error *local_err =NULL ; + +/* +* Plug the memory device first and then branch off to the actual +* hotplug handler. If that one fails, we can easily undo the memory +* device bits. +*/ +memory_device_plug (MEMORY_DEVICE (dev),MACHINE (hotplug_dev)); +if (hotplug_dev2) { +hotplug_handler_plug (hotplug_dev2, dev, &local_err); +if (local_err) { +memory_device_unplug (MEMORY_DEVICE (dev),MACHINE (hotplug_dev)); + } + } +error_propagate (errp, local_err); +} + +static void virt_virtio_md_pci_unplug_request (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +/* We don't support hot unplug of virtio based memory devices */ +error_setg (errp,"virtio based memory devices cannot be unplugged." ); +} + +static void virt_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
@@ -2508,6 +2568,8 @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {virt_memory_pre_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) { +virt_virtio_md_pci_pre_plug (hotplug_dev, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {hwaddr db_start =0 , db_end =0 ;char *resv_prop_str;
@@ -2559,6 +2621,11 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {virt_memory_plug (hotplug_dev, dev, errp); } + +if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) { +virt_virtio_md_pci_plug (hotplug_dev, dev, errp); + } +if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {PCIDevice *pdev =PCI_DEVICE (dev);
@@ -2615,6 +2682,8 @@ static void virt_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev, {if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {virt_dimm_unplug_request (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI )) { +virt_virtio_md_pci_unplug_request (hotplug_dev, dev, errp); }else {error_setg (errp,"device unplug request for unsupported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -2639,6 +2708,7 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,if (device_is_dynamic_sysbus (mc, dev) ||object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) || +object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MEM_PCI ) ||object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) {return HOTPLUG_HANDLER (machine); }
hw/virtio/virtio-mem.c +3 -1
@@ -146,7 +146,7 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)* The memory block size corresponds mostly to the section size. * * This allows e.g., to add 20MB with a section size of 128MB on x86_64, and -* a section size of 1GB on arm64 (as long as the start address is properly +* a section size of 512MB on arm64 (as long as the start address is properly * aligned, similar to ordinary DIMMs). * * We can change this at any time and maybe even make it configurable if
@@ -155,6 +155,8 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)*/ #if defined(TARGET_X86_64 ) || defined(TARGET_I386 )#define VIRTIO_MEM_USABLE_EXTENT (2 * (128 * MiB)) +#elif defined(TARGET_ARM ) +#define VIRTIO_MEM_USABLE_EXTENT (2 * (512 * MiB))#else #error VIRTIO_MEM_USABLE_EXTENT not defined#endif
hw/arm/Kconfig +1 -0
@@ -28,6 +28,7 @@ config ARM_VIRT select ACPI_HW_REDUCED select ACPI_APEI select ACPI_VIOT + select VIRTIO_MEM_SUPPORTED config CHEETAH bool
Signature · 1 line
2.25.1
[PULL 27/38] hw/intc/arm_gicv3_its: Fix handling of process_its_cmd() return value
In reply to Peter Maydellprocess_its_cmd() returns a bool, like all the other process_ functions. However we were putting its return value into 'res', not 'result', which meant we would ignore it when deciding whether to continue or stall the command queue. Fix the typo.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/intc/arm_gicv3_its.c +2 -2
@@ -678,10 +678,10 @@ static void process_cmdq(GICv3ITSState *s)switch (cmd) {case GITS_CMD_INT : - res =process_its_cmd (s, data, cq_offset,INTERRUPT ); + result =process_its_cmd (s, data, cq_offset,INTERRUPT );break ;case GITS_CMD_CLEAR : - res =process_its_cmd (s, data, cq_offset,CLEAR ); + result =process_its_cmd (s, data, cq_offset,CLEAR );break ;case GITS_CMD_SYNC :/*
Signature · 1 line
2.25.1
[PULL 34/38] hw/intc/arm_gicv3_its: Fix return codes in process_mapd()
In reply to Peter MaydellFix process_mapd() to consistently return CMD_STALL for memory errors and CMD_CONTINUE for parameter errors, as we claim in the comments that we do.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
hw/intc/arm_gicv3_its.c +4 -6
@@ -597,7 +597,6 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,uint64_t itt_addr;bool valid;MemTxResult res =MEMTX_OK ; -ItsCmdResult result =CMD_STALL ; devid = ((value &DEVID_MASK ) >>DEVID_SHIFT );
@@ -606,7 +605,7 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value, MEMTXATTRS_UNSPECIFIED, &res);if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } size = (value &SIZE_MASK );
@@ -616,7 +615,7 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value, MEMTXATTRS_UNSPECIFIED, &res);if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } itt_addr = (value &ITTADDR_MASK ) >>ITTADDR_SHIFT ;
@@ -633,11 +632,10 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,* we ignore this command and move onto the next * command in the queue */ - }else { - result =update_dte (s, devid, valid, size, itt_addr) ?CMD_CONTINUE :CMD_STALL ; +return CMD_CONTINUE ; } -return result; +return update_dte (s, devid, valid, size, itt_addr) ?CMD_CONTINUE :CMD_STALL ; }/*
Signature · 1 line
2.25.1
[PULL 07/38] hw/acpi/aml-build: Improve scalability of PPTT generation
In reply to Peter MaydellFrom: Yanan Wang <[email protected]>
Use g_queue APIs to reduce the nested loops and code indentation with the processor hierarchy levels increasing. Consenquently, it's more scalable to add new topology level to build_pptt.
No functional change intended.
Message-id: [email protected]
--- hw/acpi/aml-build.c | 50 +++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-)
hw/acpi/aml-build.c +32 -18
@@ -2001,7 +2001,10 @@ static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags,void build_pptt (GArray *table_data,BIOSLinker *linker,MachineState *ms,const char *oem_id,const char *oem_table_id) { -int pptt_start = table_data->len; +GQueue *list =g_queue_new (); +guint pptt_start = table_data->len; +guint parent_offset; +guint length, i;int uid =0 ;int socket;AcpiTable table = { .sig ="PPTT" , .rev =2 ,
@@ -2010,9 +2013,8 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,acpi_table_begin (&table, table_data);for (socket =0 ; socket < ms->smp.sockets; socket++) { -uint32_t socket_offset = table_data->len - pptt_start; -int core; - +g_queue_push_tail (list, +GUINT_TO_POINTER (table_data->len - pptt_start)); build_processor_hierarchy_node( table_data,/*
@@ -2021,35 +2023,47 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,*/ (1 <<0 ), 0, socket, NULL, 0); + } + length =g_queue_get_length (list); +for (i =0 ; i < length; i++) { +int core; + + parent_offset =GPOINTER_TO_UINT (g_queue_pop_head (list));for (core =0 ; core < ms->smp.cores; core++) { -uint32_t core_offset = table_data->len - pptt_start; -int thread; -if (ms->smp.threads >1 ) { +g_queue_push_tail (list, +GUINT_TO_POINTER (table_data->len - pptt_start));build_processor_hierarchy_node ( table_data, (0 <<0 ),/* not a physical package */ - socket_offset, core,NULL ,0 ); - -for (thread =0 ; thread < ms->smp.threads; thread++) { -build_processor_hierarchy_node ( - table_data, - (1 <<1 ) |/* ACPI Processor ID valid */ - (1 <<2 ) |/* Processor is a Thread */ - (1 <<3 ),/* Node is a Leaf */ - core_offset, uid++,NULL ,0 ); - } + parent_offset, core,NULL ,0 ); }else {build_processor_hierarchy_node ( table_data, (1 <<1 ) |/* ACPI Processor ID valid */ (1 <<3 ),/* Node is a Leaf */ - socket_offset, uid++,NULL ,0 ); + parent_offset, uid++,NULL ,0 ); } } } + length =g_queue_get_length (list); +for (i =0 ; i < length; i++) { +int thread; + + parent_offset =GPOINTER_TO_UINT (g_queue_pop_head (list)); +for (thread =0 ; thread < ms->smp.threads; thread++) { +build_processor_hierarchy_node ( + table_data, + (1 <<1 ) |/* ACPI Processor ID valid */ + (1 <<2 ) |/* Processor is a Thread */ + (1 <<3 ),/* Node is a Leaf */ + parent_offset, uid++,NULL ,0 ); + } + } + +g_queue_free (list);acpi_table_end (linker, &table); }
Signature · 1 line
2.25.1
[PULL 31/38] hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce nesting
In reply to Peter MaydellRefactor process_its_cmd() so that it consistently uses the structure
do thing;
if (error condition) {
return early; }
do next thing;
rather than doing some of the work nested inside if (not error) code blocks.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 103 +++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 53 deletions(-)
hw/intc/arm_gicv3_its.c +50 -53
@@ -273,79 +273,76 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, } dte_valid =FIELD_EX64 (dte,DTE ,VALID ); -if (dte_valid) { - num_eventids =1ULL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); - - ite_valid =get_ite (s, eventid, dte, &icid, &pIntid, &res); - -if (res !=MEMTX_OK ) { -return CMD_STALL ; - } - -if (ite_valid) { - cte_valid =get_cte (s, icid, &cte, &res); - } - -if (res !=MEMTX_OK ) { -return CMD_STALL ; - } - }else { +if (!dte_valid) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid command attributes: " -"invalid dte: %" PRIx64" for %d (MEM_TX: %d)\n" , - __func__, dte, devid, res); +"invalid dte: %" PRIx64" for %d\n" , + __func__, dte, devid);return CMD_CONTINUE ; } + num_eventids =1ULL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); + + ite_valid =get_ite (s, eventid, dte, &icid, &pIntid, &res); +if (res !=MEMTX_OK ) { +return CMD_STALL ; + } + +if (!ite_valid) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid command attributes: invalid ITE\n" , + __func__); +return CMD_CONTINUE ; + } + + cte_valid =get_cte (s, icid, &cte, &res); +if (res !=MEMTX_OK ) { +return CMD_STALL ; + } +if (!cte_valid) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid command attributes: " +"invalid cte: %" PRIx64"\n" , + __func__, cte); +return CMD_CONTINUE ; + } -/* -* In this implementation, in case of guest errors we ignore the -* command and move onto the next command in the queue. -*/ if (devid >= s->dt.num_ids) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid command attributes: devid %d>=%d" , __func__, devid, s->dt.num_ids);return CMD_CONTINUE ; - }else if (!dte_valid || !ite_valid || !cte_valid) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: invalid command attributes: " -"dte: %s, ite: %s, cte: %s\n" , - __func__, - dte_valid ?"valid" :"invalid" , - ite_valid ?"valid" :"invalid" , - cte_valid ?"valid" :"invalid" ); -return CMD_CONTINUE ; - }else if (eventid >= num_eventids) { + } +if (eventid >= num_eventids) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid command attributes: eventid %d >= %" PRId64"\n" , __func__, eventid, num_eventids);return CMD_CONTINUE ; - }else { -/* -* Current implementation only supports rdbase == procnum -* Hence rdbase physical address is ignored -*/ - rdbase =FIELD_EX64 (cte,CTE ,RDBASE ); + } -if (rdbase >= s->gicv3->num_cpu) { -return CMD_CONTINUE ; - } +/* +* Current implementation only supports rdbase == procnum +* Hence rdbase physical address is ignored +*/ + rdbase =FIELD_EX64 (cte,CTE ,RDBASE ); -if ((cmd ==CLEAR ) || (cmd ==DISCARD )) { -gicv3_redist_process_lpi (&s->gicv3->cpu[rdbase], pIntid,0 ); - }else { -gicv3_redist_process_lpi (&s->gicv3->cpu[rdbase], pIntid,1 ); - } - -if (cmd ==DISCARD ) { -IteEntry ite = {}; -/* remove mapping from interrupt translation table */ -return update_ite (s, eventid, dte, ite) ?CMD_CONTINUE :CMD_STALL ; - } +if (rdbase >= s->gicv3->num_cpu) {return CMD_CONTINUE ; } + +if ((cmd ==CLEAR ) || (cmd ==DISCARD )) { +gicv3_redist_process_lpi (&s->gicv3->cpu[rdbase], pIntid,0 ); + }else { +gicv3_redist_process_lpi (&s->gicv3->cpu[rdbase], pIntid,1 ); + } + +if (cmd ==DISCARD ) { +IteEntry ite = {}; +/* remove mapping from interrupt translation table */ +return update_ite (s, eventid, dte, ite) ?CMD_CONTINUE :CMD_STALL ; + } +return CMD_CONTINUE ; } static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
Signature · 1 line
2.25.1
[PULL 16/38] hw/arm/virt: Add a control for the the highmem PCIe MMIO
In reply to Peter MaydellFrom: Marc Zyngier <[email protected]>
Just like we can control the enablement of the highmem PCIe ECAM region using highmem_ecam, let's add a control for the highmem PCIe MMIO region.
Similarily to highmem_ecam, this region is disabled when highmem is off.
Message-id: [email protected]
--- include/hw/arm/virt.h | 1 + hw/arm/virt-acpi-build.c | 10 ++++------ hw/arm/virt.c | 7 +++++-- 3 files changed, 10 insertions(+), 8 deletions(-)
include/hw/arm/virt.h +1 -0
@@ -143,6 +143,7 @@ struct VirtMachineState {bool secure;bool highmem;bool highmem_ecam; +bool highmem_mmio;bool its;bool tcg_its;bool virt;
hw/arm/virt-acpi-build.c +4 -6
@@ -158,10 +158,9 @@ static void acpi_dsdt_add_virtio(Aml *scope, }static void acpi_dsdt_add_pci (Aml *scope,const MemMapEntry *memmap, -uint32_t irq,bool use_highmem,bool highmem_ecam, -VirtMachineState *vms) +uint32_t irq,VirtMachineState *vms) { -int ecam_id =VIRT_ECAM_ID (highmem_ecam); +int ecam_id =VIRT_ECAM_ID (vms->highmem_ecam);struct GPEXConfig cfg = { .mmio32 = memmap[VIRT_PCIE_MMIO ], .pio = memmap[VIRT_PCIE_PIO ],
@@ -170,7 +169,7 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap, .bus = vms->bus, }; -if (use_highmem) { +if (vms->highmem_mmio) { cfg.mmio64 = memmap[VIRT_HIGH_PCIE_MMIO ]; }
@@ -869,8 +868,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)acpi_dsdt_add_fw_cfg (scope, &memmap[VIRT_FW_CFG ]);acpi_dsdt_add_virtio (scope, &memmap[VIRT_MMIO ], (irqmap[VIRT_MMIO ] +ARM_SPI_BASE ),NUM_VIRTIO_TRANSPORTS ); -acpi_dsdt_add_pci (scope, memmap, (irqmap[VIRT_PCIE ] +ARM_SPI_BASE ), - vms->highmem, vms->highmem_ecam, vms); +acpi_dsdt_add_pci (scope, memmap, irqmap[VIRT_PCIE ] +ARM_SPI_BASE , vms);if (vms->acpi_dev) { build_ged_aml(scope, "\\_SB."GED_DEVICE, HOTPLUG_HANDLER(vms->acpi_dev),
hw/arm/virt.c +5 -2
@@ -1419,7 +1419,7 @@ static void create_pcie(VirtMachineState *vms) mmio_reg, base_mmio, size_mmio);memory_region_add_subregion (get_system_memory (), base_mmio, mmio_alias); -if (vms->highmem) { +if (vms->highmem_mmio) {/* Map high MMIO space */ MemoryRegion *high_mmio_alias =g_new0 (MemoryRegion,1 );
@@ -1473,7 +1473,7 @@ static void create_pcie(VirtMachineState *vms)qemu_fdt_setprop_sized_cells (ms->fdt, nodename,"reg" ,2 , base_ecam,2 , size_ecam); -if (vms->highmem) { +if (vms->highmem_mmio) { qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "ranges", 1, FDT_PCI_RANGE_IOPORT, 2, 0, 2, base_pio, 2, size_pio,
@@ -2112,6 +2112,8 @@ static void machvirt_init(MachineState *machine)virt_flash_fdt (vms, sysmem, secure_sysmem ?: sysmem); + vms->highmem_mmio &= vms->highmem; +create_gic (vms, sysmem);virt_cpu_post_init (vms, sysmem);
@@ -2899,6 +2901,7 @@ static void virt_instance_init(Object *obj) vms->gic_version =VIRT_GIC_VERSION_NOSEL ; vms->highmem_ecam = !vmc->no_highmem_ecam; + vms->highmem_mmio = true;if (vmc->no_its) { vms->its = false;
Signature · 1 line
2.25.1
[PULL 36/38] hw/intc/arm_gicv3_its: Check indexes before use, not after
In reply to Peter MaydellIn a few places in the ITS command handling functions, we were doing the range-check of an event ID or device ID only after using it as a table index; move the checks to before the uses.
This misordering wouldn't have very bad effects because the tables are in guest memory anyway.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 42 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-)
hw/intc/arm_gicv3_its.c +25 -17
@@ -255,6 +255,13 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, eventid = (value &EVENTID_MASK ); +if (devid >= s->dt.num_ids) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid command attributes: devid %d>=%d" , + __func__, devid, s->dt.num_ids); +return CMD_CONTINUE ; + } + dte =get_dte (s, devid, &res);if (res !=MEMTX_OK ) {
@@ -272,6 +279,14 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, num_eventids =1ULL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); +if (eventid >= num_eventids) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid command attributes: eventid %d >= %" + PRId64"\n" , + __func__, eventid, num_eventids); +return CMD_CONTINUE ; + } + ite_valid =get_ite (s, eventid, dte, &icid, &pIntid, &res);if (res !=MEMTX_OK ) {return CMD_STALL ;
@@ -296,20 +311,6 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,return CMD_CONTINUE ; } -if (devid >= s->dt.num_ids) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: invalid command attributes: devid %d>=%d" , - __func__, devid, s->dt.num_ids); -return CMD_CONTINUE ; - } -if (eventid >= num_eventids) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: invalid command attributes: eventid %d >= %" - PRId64"\n" , - __func__, eventid, num_eventids); -return CMD_CONTINUE ; - } -/* * Current implementation only supports rdbase == procnum * Hence rdbase physical address is ignored
@@ -375,6 +376,13 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, icid = value &ICID_MASK ; +if (devid >= s->dt.num_ids) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid command attributes: devid %d>=%d" , + __func__, devid, s->dt.num_ids); +return CMD_CONTINUE ; + } + dte =get_dte (s, devid, &res);if (res !=MEMTX_OK ) {
@@ -384,14 +392,14 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, num_eventids =1ULL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); num_intids =1ULL << (GICD_TYPER_IDBITS +1 ); -if ((devid >= s->dt.num_ids) || (icid >= s->ct.num_ids) +if ((icid >= s->ct.num_ids) || !dte_valid || (eventid >= num_eventids) || (((pIntid <GICV3_LPI_INTID_START ) || (pIntid >= num_intids)) && (pIntid !=INTID_SPURIOUS ))) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid command attributes " -"devid %d or icid %d or eventid %d or pIntid %d or" -"unmapped dte %d\n" , __func__, devid, icid, eventid, +"icid %d or eventid %d or pIntid %d or" +"unmapped dte %d\n" , __func__, icid, eventid, pIntid, dte_valid);/* * in this implementation, in case of error
Signature · 1 line
2.25.1
[PULL 15/38] hw/intc/arm_gic: Allow reset of the running priority
In reply to Peter MaydellFrom: Petr Pavlu <[email protected]>
When running Linux on a machine with GICv2, the kernel can crash while processing an interrupt and can subsequently start a kdump kernel from the active interrupt handler. In such a case, the crashed kernel might not gracefully signal the end of interrupt to the GICv2 hardware. The kdump kernel will however try to reset the GIC state on startup to get the controller into a sane state, in particular the kernel writes ones to GICD_ICACTIVERn and wipes out GICC_APRn to make sure that no interrupt is active.
The patch adds a logic to recalculate the running priority when GICC_APRn/GICC_NSAPRn is written which makes sure that the mentioned reset works with the GICv2 emulation in QEMU too and the kdump kernel starts receiving interrupts.
The described scenario can be reproduced on an AArch64 QEMU virt machine with a kdump-enabled Linux system by using the softdog module. The kdump kernel will hang at some point because QEMU still thinks the running priority is that of the timer interrupt and asserts no new interrupts to the system:
$ modprobe softdog soft_margin=10 soft_panic=1 $ cat > /dev/watchdog [Press Enter to start the watchdog, wait for its timeout and observe that the kdump kernel hangs on startup.]
Message-id: [email protected]
--- hw/intc/arm_gic.c | 2 ++ 1 file changed, 2 insertions(+)
hw/intc/arm_gic.c +2 -0
@@ -1736,6 +1736,7 @@ static MemTxResult gic_cpu_write(GICState *s, int cpu, int offset, }else { s->apr[regno][cpu] = value; } + s->running_priority[cpu] =gic_get_prio_from_apr_bits (s, cpu);break ; }case 0xe0 :case 0xe4 :case 0xe8 :case 0xec :
@@ -1752,6 +1753,7 @@ static MemTxResult gic_cpu_write(GICState *s, int cpu, int offset,return MEMTX_OK ; } s->nsapr[regno][cpu] = value; + s->running_priority[cpu] =gic_get_prio_from_apr_bits (s, cpu);break ; }case 0x1000 :
Signature · 1 line
2.25.1
[PULL 37/38] hw/intc/arm_gicv3_its: Range-check ICID before indexing into collection table
In reply to Peter MaydellIn process_its_cmd(), we read an ICID out of the interrupt table entry, and then use it as an index into the collection table. Add a check that it is within range for the collection table first.
This check is not strictly necessary, because:
* we range check the ICID from the guest before writing it into the interrupt table entry, so the the only way to get an out of range ICID in process_its_cmd() is if a badly-behaved guest is writing directly to the interrupt table memory
* the collection table is in guest memory, so QEMU won't fall over if we read off the end of it
However, it seems clearer to include the check.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/intc/arm_gicv3_its.c +7 -0
@@ -299,6 +299,13 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,return CMD_CONTINUE ; } +if (icid >= s->ct.num_ids) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid ICID 0x%x in ITE (table corrupted?)\n" , + __func__, icid); +return CMD_CONTINUE ; + } + cte_valid =get_cte (s, icid, &cte, &res);if (res !=MEMTX_OK ) {return CMD_STALL ;
Signature · 1 line
2.25.1
[PULL 18/38] hw/arm/virt: Honor highmem setting when computing the memory map
In reply to Peter MaydellFrom: Marc Zyngier <[email protected]>
Even when the VM is configured with highmem=off, the highest_gpa field includes devices that are above the 4GiB limit. Similarily, nothing seem to check that the memory is within the limit set by the highmem=off option.
This leads to failures in virt_kvm_type() on systems that have a crippled IPA range, as the reported IPA space is larger than what it should be.
Instead, honor the user-specified limit to only use the devices at the lowest end of the spectrum, and fail if we have memory crossing the 4GiB limit.
Message-id: [email protected]
--- hw/arm/virt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
hw/arm/virt.c +7 -3
@@ -1670,7 +1670,7 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_memmap (VirtMachineState *vms) {MachineState *ms =MACHINE (vms); -hwaddr base, device_memory_base, device_memory_size; +hwaddr base, device_memory_base, device_memory_size, memtop;int i; vms->memmap = extended_memmap;
@@ -1697,7 +1697,11 @@ static void virt_set_memmap(VirtMachineState *vms) device_memory_size = ms->maxram_size - ms->ram_size + ms->ram_slots * GiB;/* Base address of the high IO region */ - base = device_memory_base +ROUND_UP (device_memory_size, GiB); + memtop = base = device_memory_base +ROUND_UP (device_memory_size, GiB); +if (!vms->highmem && memtop >4 * GiB) { +error_report ("highmem=off, but memory crosses the 4GiB limit\n" ); +exit (EXIT_FAILURE ); + }if (base < device_memory_base) {error_report ("maxmem/slots too huge" );exit (EXIT_FAILURE );
@@ -1714,7 +1718,7 @@ static void virt_set_memmap(VirtMachineState *vms) vms->memmap[i].size = size; base += size; } - vms->highest_gpa = base -1 ; + vms->highest_gpa = (vms->highmem ? base : memtop) -1 ;if (device_memory_size >0 ) { ms->device_memory =g_malloc0 (sizeof (*ms->device_memory)); ms->device_memory->base = device_memory_base;
Signature · 1 line
2.25.1
Re: [PULL 18/38] hw/arm/virt: Honor highmem setting when computing the memory map
Quoted 51 lines · Peter Maydell
From: Marc Zyngier <[email protected]>
Even when the VM is configured with highmem=off, the
highest_gpafield includes devices that are above the 4GiB limit. Similarily, nothing seem to check that the memory is within the limit set by the highmem=off option.This leads to failures in
virt_kvm_type()on systems that have a crippled IPA range, as the reported IPA space is larger than what it should be.Instead, honor the user-specified limit to only use the devices at the lowest end of the spectrum, and fail if we have memory crossing the 4GiB limit.
Reviewed-by Andrew Jones <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Marc Zyngier <[email protected]>Message-id: [email protected]
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)hw/arm/virt.c +6
-2@@ -1670,7 +1670,7 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_memmap (VirtMachineState *vms) {MachineState *ms =MACHINE (vms); -hwaddr base, device_memory_base, device_memory_size; +hwaddr base, device_memory_base, device_memory_size, memtop;int i; vms->memmap = extended_memmap;@@ -1697,7 +1697,11 @@ static void virt_set_memmap(VirtMachineState *vms) device_memory_size = ms->maxram_size - ms->ram_size + ms->ram_slots * GiB;/* Base address of the high IO region */ - base = device_memory_base +ROUND_UP (device_memory_size, GiB); + memtop = base = device_memory_base +ROUND_UP (device_memory_size, GiB); +if (!vms->highmem && memtop >4 * GiB) { +error_report ("highmem=off, but memory crosses the 4GiB limit\n" ); +exit (EXIT_FAILURE ); + }if (base < device_memory_base) {error_report ("maxmem/slots too huge" );exit (EXIT_FAILURE );
hw/arm/virt.c static void virt_set_memmap(VirtMachineState *vms) · line 1724
Quoted 8 lines
hw/arm/virt.c +1
-1@@ -1714,7 +1718,7 @@ static void virt_set_memmap(VirtMachineState *vms) vms->memmap[i].size = size; base += size; } - vms->highest_gpa = base -1 ; + vms->highest_gpa = (vms->highmem ? base : memtop) -1 ;if (device_memory_size >0 ) { ms->device_memory =g_malloc0 (sizeof (*ms->device_memory)); ms->device_memory->base = device_memory_base;
Hi,
This breaks in a case where highmem is disabled but can have more than 4 GiB of RAM. M1 (Apple Silicon) actually can have 36-bit PA with HVF, which is not enough for highmem MMIO but is enough to contain 32 GiB of RAM.
Where the magic number of 4 GiB / 32-bit came from? I also don't quite understand what failures virt_kvm_type() had.
Regards,
Akihiko Odaki
Marc Zyngier
maintainerRe: [PULL 18/38] hw/arm/virt: Honor highmem setting when computing the memory map
[+ Alex for HVF]
Quoted 57 lines · Akihiko Odaki
Quoted 55 lines · Peter Maydell
From: Marc Zyngier <[email protected]>
Even when the VM is configured with highmem=off, the
highest_gpafield includes devices that are above the 4GiB limit. Similarily, nothing seem to check that the memory is within the limit set by the highmem=off option.This leads to failures in
virt_kvm_type()on systems that have a crippled IPA range, as the reported IPA space is larger than what it should be.Instead, honor the user-specified limit to only use the devices at the lowest end of the spectrum, and fail if we have memory crossing the 4GiB limit.
Reviewed-by Andrew Jones <[email protected]>Reviewed-by Eric Auger <[email protected]>Signed-off-by Marc Zyngier <[email protected]>Message-id: [email protected]
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)hw/arm/virt.c +7
-3@@ -1670,7 +1670,7 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_memmap (VirtMachineState *vms) {MachineState *ms =MACHINE (vms); -hwaddr base, device_memory_base, device_memory_size; +hwaddr base, device_memory_base, device_memory_size, memtop;int i; vms->memmap = extended_memmap;@@ -1697,7 +1697,11 @@ static void virt_set_memmap(VirtMachineState *vms) device_memory_size = ms->maxram_size - ms->ram_size + ms->ram_slots * GiB;/* Base address of the high IO region */ - base = device_memory_base +ROUND_UP (device_memory_size, GiB); + memtop = base = device_memory_base +ROUND_UP (device_memory_size, GiB); +if (!vms->highmem && memtop >4 * GiB) { +error_report ("highmem=off, but memory crosses the 4GiB limit\n" ); +exit (EXIT_FAILURE ); + }if (base < device_memory_base) {error_report ("maxmem/slots too huge" );exit (EXIT_FAILURE );@@ -1714,7 +1718,7 @@ static void virt_set_memmap(VirtMachineState *vms) vms->memmap[i].size = size; base += size; } - vms->highest_gpa = base -1 ; + vms->highest_gpa = (vms->highmem ? base : memtop) -1 ;if (device_memory_size >0 ) {
Quoted 8 lines
hw/arm/virt.c static void virt_set_memmap(VirtMachineState *vms) · line 1724
Quoted 2 lines
hw/arm/virt.c +0
-0ms->device_memory =g_malloc0 (sizeof (*ms->device_memory)); ms->device_memory->base = device_memory_base;Hi,
This breaks in a case where highmem is disabled but can have more than 4 GiB of RAM. M1 (Apple Silicon) actually can have 36-bit PA with HVF, which is not enough for highmem MMIO but is enough to contain 32 GiB of RAM.
Funny. The whole point of this series is to make it all work correctly on M1.
Quoted 1 line
Where the magic number of 4 GiB / 32-bit came from?
Not exactly a magic number. From QEMU's docs/system/arm/virt.rst:
<quote>
highmem
Set ``on``/``off`` to enable/disable placing devices and RAM in physical address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``.
</quote>
TL;DR: Removing the bogus 'highmem=off' option from your command-line should get you going with large memory spaces, up to the IPA limit.
The fact that you could run with 32GB of RAM while mandating that the guest IPA space was limited to 32bit was nothing but a bug, further "exploited" by HVF to allow disabling the highhmem devices which are out of reach given the HW limitations (see [1] for details on the discussion, specially around patch 3).
This is now fixed, and has been extended to work with any IPA size (including 36bit machines such as M1).
Quoted 1 line
I also don't quite understand what failures
virt_kvm_type()had.
QEMU works by first computing the memory map and passing the required IPA limit to KVM as part of the VM type. By failing to take into account the initial limit requirements to the IPA space (either via a command-line option such as 'highmem', or by using the value provided by KVM itself), QEMU would try to create a VM that cannot run on the HW, and KVM would simply return an error.
All of this is documented as part of the KVM/arm64 API [2]. And with this fixed, QEMU is able to correctly drive KVM on M1.
M.
[1] https://lore.kernel.org/all/[email protected]
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/virt/kvm/api.rst#n138
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PULL 18/38] hw/arm/virt: Honor highmem setting when computing the memory map
Quoted 25 lines · Marc Zyngier
[+ Alex for HVF]
Quoted 5 lines · Akihiko Odaki
Hi,
This breaks in a case where highmem is disabled but can have more than 4 GiB of RAM. M1 (Apple Silicon) actually can have 36-bit PA with HVF, which is not enough for highmem MMIO but is enough to contain 32 GiB of RAM.Funny. The whole point of this series is to make it all work correctly on M1.
Quoted 1 line
Where the magic number of 4 GiB / 32-bit came from?
Not exactly a magic number. From QEMU's
docs/system/arm/virt.rst:<quote>
highmem
Set ``on``/``off`` to enable/disable placing devices and RAM in physical address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``.
</quote>
Quoted 2 lines
TL;DR: Removing the bogus 'highmem=off' option from your command-line should get you going with large memory spaces, up to the IPA limit.
Yep. I've tested this with hvf, and we now correctly:
* refuse to put RAM above 32-bits if you asked for a 32-bit IPA space with highmem=off
* use the full 36-bit address space if you don't say highmem=off on an M1
Note that there is a macos bug where if you don't say highmem=off on an M1 Pro then you'll get a macos kernel panic. M1 non-Pro is fine.
thanks
-- PMM
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PULL 18/38] hw/arm/virt: Honor highmem setting when computing the memory map
Quoted 36 lines · Peter Maydell
Quoted 25 lines · Marc Zyngier
[+ Alex for HVF]
Quoted 5 lines · Akihiko Odaki
Hi,
This breaks in a case where highmem is disabled but can have more than 4 GiB of RAM. M1 (Apple Silicon) actually can have 36-bit PA with HVF, which is not enough for highmem MMIO but is enough to contain 32 GiB of RAM.Funny. The whole point of this series is to make it all work correctly on M1.
Quoted 1 line
Where the magic number of 4 GiB / 32-bit came from?
Not exactly a magic number. From QEMU's
docs/system/arm/virt.rst:<quote>
highmem
Set ``on``/``off`` to enable/disable placing devices and RAM in physical address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``.
</quote>Quoted 2 lines
TL;DR: Removing the bogus 'highmem=off' option from your command-line should get you going with large memory spaces, up to the IPA limit.
Yep. I've tested this with hvf, and we now correctly:
* refuse to put RAM above 32-bits if you asked for a 32-bit IPA space with highmem=off
* use the full 36-bit address space if you don't say highmem=off on an M1
Quoted 5 lines
Note that there is a macos bug where if you don't say highmem=off on an M1 Pro then you'll get a macos kernel panic. M1 non-Pro is fine.
thanks
-- PMM
I found that it actually gets the available PA bit of the emulated CPU when highmem=on. I used "cortex-a72", which can have more than 36 bits. I just simply switched to "host"; hvf didn't support "host" when I set up my VM but now it does.
Thanks for your prompt replies.
Regards,
Akihiko Odaki
Re: [PULL 18/38] hw/arm/virt: Honor highmem setting when computing the memory map
Quoted 4 lines · Akihiko Odaki
I found that it actually gets the available PA bit of the emulated CPU when highmem=on. I used "cortex-a72", which can have more than 36 bits. I just simply switched to "host"; hvf didn't support "host" when I set up my VM but now it does.
It's a bug that we accept 'cortex-a72' there. What should happen is something like:
* we want to use the ID register values of a cortex-a72
* QEMU's hvf layer should say "no, that doesn't match the actual CPU we're running on", and give an error
This works correctly with KVM because there the kernel refuses attempts to set ID registers to values that don't match the host; for hvf the hvf APIs do permit lying to the guest about ID register values so we need to do the check ourselves.
(The other approach would be to check the ID register values and allow them to the extent that the host CPU actually has the support for the features they imply, so you could "downgrade" to a less capable CPU but not tell the guest it has feature X if it isn't really there. But this is (a) a lot more complicated and (b) gets into the swamp of trying to figure out how to tell the guest about CPU errata -- the guest needs to apply errata workarounds for the real host CPU, not for whatever the emulated CPU is. So "just reject anything that's not an exact match" is the easy approach.)
-- PMM
[PULL 38/38] hw/intc/arm_gicv3: Check for !MEMTX_OK instead of MEMTX_ERROR
In reply to Peter MaydellFrom: Philippe Mathieu-Daudé <[email protected]>
Quoting Peter Maydell:
"These MEMTX_* aren't from the memory transaction
API functions; they're just being used by gicd_readl() and friends as a way to indicate a success/failure so that the actual MemoryRegionOps read/write fns like gicv3_dist_read() can log a guest error."
We are going to introduce more MemTxResult bits, so it is safer to check for !MEMTX_OK rather than MEMTX_ERROR.
--- hw/intc/arm_gicv3_redist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/intc/arm_gicv3_redist.c +2 -2
@@ -462,7 +462,7 @@ MemTxResult gicv3_redist_read(void *opaque, hwaddr offset, uint64_t *data,break ; } -if (r ==MEMTX_ERROR ) { +if (r !=MEMTX_OK ) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid guest read at offset " TARGET_FMT_plx" size %u\n" , __func__, offset, size);
@@ -521,7 +521,7 @@ MemTxResult gicv3_redist_write(void *opaque, hwaddr offset, uint64_t data,break ; } -if (r ==MEMTX_ERROR ) { +if (r !=MEMTX_OK ) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid guest write at offset " TARGET_FMT_plx" size %u\n" , __func__, offset, size);
Signature · 1 line
2.25.1
[PULL 23/38] hw/misc/aspeed_i3c.c: Introduce a dummy AST2600 I3C model.
In reply to Peter MaydellFrom: Troy Lee <[email protected]>
Aspeed 2600 SDK enables I3C support by default. The I3C driver will try to reset the device controller and set it up through device address table register. This dummy model responds to these registers with default values as listed in the ast2600v10 datasheet chapter 54.2.
This avoids a guest machine kernel panic due to referencing an invalid kernel address if the device address table register isn't set correctly.
Message-id: [email protected]
--- include/hw/misc/aspeed_i3c.h | 48 +++++ hw/misc/aspeed_i3c.c | 381 +++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 6 + 4 files changed, 436 insertions(+) create mode 100644 include/hw/misc/aspeed_i3c.h create mode 100644 hw/misc/aspeed_i3c.c
include/hw/misc/aspeed_i3c.h new file +48 -0
@@ -0,0 +1,48 @@ +/* +* ASPEED I3C Controller +* +* Copyright (C) 2021 ASPEED Technology Inc. +* +* This code is licensed under the GPL version 2 or later. See +* the COPYING file in the top-level directory. +*/ + +#ifndef ASPEED_I3C_H +#define ASPEED_I3C_H + +#include "hw/sysbus.h" + +#define TYPE_ASPEED_I3C "aspeed.i3c" +#define TYPE_ASPEED_I3C_DEVICE "aspeed.i3c.device" +OBJECT_DECLARE_TYPE(AspeedI3CState, AspeedI3CClass, ASPEED_I3C) + +#define ASPEED_I3C_NR_REGS (0x70 >> 2) +#define ASPEED_I3C_DEVICE_NR_REGS (0x300 >> 2) +#define ASPEED_I3C_NR_DEVICES 6 + +OBJECT_DECLARE_SIMPLE_TYPE(AspeedI3CDevice, ASPEED_I3C_DEVICE) +typedef struct AspeedI3CDevice { +/* <private> */ +SysBusDevice parent; + +/* <public> */ +MemoryRegion mr; +qemu_irq irq; + +uint8_t id; +uint32_t regs[ASPEED_I3C_DEVICE_NR_REGS ]; +}AspeedI3CDevice ; + +typedef struct AspeedI3CState { +/* <private> */ +SysBusDevice parent; + +/* <public> */ +MemoryRegion iomem; +MemoryRegion iomem_container; +qemu_irq irq; + +uint32_t regs[ASPEED_I3C_NR_REGS ]; +AspeedI3CDevice devices[ASPEED_I3C_NR_DEVICES ]; +}AspeedI3CState ; +#endif /* ASPEED_I3C_H */
hw/misc/aspeed_i3c.c new file +381 -0
381 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -105,6 +105,7 @@ softmmu_ss.add(when: 'CONFIG_PVPANIC_PCI', if_true: files('pvpanic-pci.c')) softmmu_ss.add(when: 'CONFIG_AUX', if_true: files('auxbus.c')) softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files( 'aspeed_hace.c', + 'aspeed_i3c.c', 'aspeed_lpc.c', 'aspeed_scu.c', 'aspeed_sdmc.c',
hw/misc/trace-events +6 -0
@@ -199,6 +199,12 @@ armsse_mhu_write(uint64_t offset, uint64_t data, unsigned size) "SSE-200 MHU wri # aspeed_xdma.c aspeed_xdma_write(uint64_t offset, uint64_t data) "XDMA write: offset 0x%" PRIx64 " data 0x%" PRIx64 +# aspeed_i3c.c +aspeed_i3c_read(uint64_t offset, uint64_t data) "I3C read: offset 0x%" PRIx64 " data 0x%" PRIx64 +aspeed_i3c_write(uint64_t offset, uint64_t data) "I3C write: offset 0x%" PRIx64 " data 0x%" PRIx64 +aspeed_i3c_device_read(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%u] read: offset 0x%" PRIx64 " data 0x%" PRIx64 +aspeed_i3c_device_write(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%u] write: offset 0x%" PRIx64 " data 0x%" PRIx64 + # bcm2835_property.c bcm2835_mbox_property(uint32_t tag, uint32_t bufsize, size_t resplen) "mbox property tag:0x%08x in_sz:%u out_sz:%zu"
Signature · 1 line
2.25.1
[PULL 01/38] hw/arm/virt: KVM: Enable PAuth when supported by the host
In reply to Peter MaydellFrom: Marc Zyngier <[email protected]>
Add basic support for Pointer Authentication when running a KVM guest and that the host supports it, loosely based on the SVE support.
Although the feature is enabled by default when the host advertises it, it is possible to disable it by setting the 'pauth=off' CPU property. The 'pauth' comment is removed from cpu-features.rst, as it is now common to both TCG and KVM.
Tested on an Apple M1 running 5.16-rc6.
Message-id: [email protected]
--- docs/system/arm/cpu-features.rst | 4 ---- target/arm/cpu.h | 1 + target/arm/cpu.c | 16 +++++----------- target/arm/cpu64.c | 31 +++++++++++++++++++++++++++---- target/arm/kvm64.c | 21 +++++++++++++++++++++ 5 files changed, 54 insertions(+), 19 deletions(-)
docs/system/arm/cpu-features.rst +0 -4
@@ -217,10 +217,6 @@ TCG VCPU Features TCG VCPU features are CPU features that are specific to TCG. Below is the list of TCG VCPU features and their descriptions. - pauth Enable or disable ``FEAT_Pauth``, pointer - authentication. By default, the feature is - enabled with ``-cpu max``. - pauth-impdef When ``FEAT_Pauth`` is enabled, either the *impdef* (Implementation Defined) algorithm is enabled or the *architected* QARMA algorithm
target/arm/cpu.h +1 -0
@@ -1076,6 +1076,7 @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq);void aarch64_sve_change_el (CPUARMState *env,int old_el,int new_el,bool el0_a64);void aarch64_add_sve_properties (Object *obj); +void aarch64_add_pauth_properties (Object *obj);/* * SVE registers are encoded in KVM's memory in an endianness-invariant format.
target/arm/cpu.c +5 -11
@@ -1380,17 +1380,10 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)return ; } -/* -* KVM does not support modifications to this feature. -* We have not registered the cpu properties when KVM -* is in use, so the user will not be able to set them. -*/ -if (!kvm_enabled ()) { -arm_cpu_pauth_finalize (cpu, &local_err); -if (local_err !=NULL ) { -error_propagate (errp, local_err); -return ; - } +arm_cpu_pauth_finalize (cpu, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; } }
@@ -2091,6 +2084,7 @@ static void arm_host_initfn(Object *obj)kvm_arm_set_cpu_features_from_host (cpu);if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) {aarch64_add_sve_properties (obj); +aarch64_add_pauth_properties (obj); }#else hvf_arm_set_cpu_features_from_host (cpu);
target/arm/cpu64.c +27 -4
@@ -630,6 +630,15 @@ void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp)int arch_val =0 , impdef_val =0 ;uint64_t t; +/* Exit early if PAuth is enabled, and fall through to disable it */ +if (kvm_enabled () && cpu->prop_pauth) { +if (!cpu_isar_feature (aa64_pauth, cpu)) { +error_setg (errp,"'pauth' feature not supported by KVM on this host" ); + } + +return ; + } +/* TODO: Handle HaveEnhancedPAC, HaveEnhancedPAC2, HaveFPAC. */ if (cpu->prop_pauth) {if (cpu->prop_pauth_impdef) {
@@ -655,6 +664,23 @@ static Property arm_cpu_pauth_property =static Property arm_cpu_pauth_impdef_property =DEFINE_PROP_BOOL ("pauth-impdef" ,ARMCPU , prop_pauth_impdef, false); +void aarch64_add_pauth_properties (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); + +/* Default to PAUTH on, with the architected algorithm on TCG. */ +qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_property); +if (kvm_enabled ()) { +/* +* Mirror PAuth support from the probed sysregs back into the +* property for KVM. Is it just a bit backward? Yes it is! +*/ + cpu->prop_pauth =cpu_isar_feature (aa64_pauth, cpu); + }else { +qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_impdef_property); + } +} +/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); * otherwise, a CPU with as many features enabled as our emulation supports. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c;
@@ -829,13 +855,10 @@ static void aarch64_max_initfn(Object *obj) cpu->dcz_blocksize =7 ;/* 512 bytes */ #endif -/* Default to PAUTH on, with the architected algorithm. */ -qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_property); -qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_impdef_property); -bitmap_fill (cpu->sve_vq_supported,ARM_MAX_VQ ); } +aarch64_add_pauth_properties (obj);aarch64_add_sve_properties (obj);object_property_add (obj,"sve-max-vq" ,"uint32" , cpu_max_get_sve_max_vq, cpu_max_set_sve_max_vq,NULL ,NULL );
target/arm/kvm64.c +21 -0
@@ -491,6 +491,12 @@ static int read_sys_reg64(int fd, uint64_t *pret, uint64_t id)return ioctl (fd,KVM_GET_ONE_REG , &idreg); } +static bool kvm_arm_pauth_supported (void ) +{ +return (kvm_check_extension (kvm_state,KVM_CAP_ARM_PTRAUTH_ADDRESS ) && +kvm_check_extension (kvm_state,KVM_CAP_ARM_PTRAUTH_GENERIC )); +} +bool kvm_arm_get_host_cpu_features (ARMHostCPUFeatures *ahcf) {/* Identify the feature bits corresponding to the host CPU, and
@@ -521,6 +527,17 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)*/ struct kvm_vcpu_init init = { .target =-1 , }; +/* +* Ask for Pointer Authentication if supported. We can't play the +* SVE trick of synthesising the ID reg as KVM won't tell us +* whether we have the architected or IMPDEF version of PAuth, so +* we have to use the actual ID regs. +*/ +if (kvm_arm_pauth_supported ()) { + init.features[0 ] |= (1 <<KVM_ARM_VCPU_PTRAUTH_ADDRESS | +1 <<KVM_ARM_VCPU_PTRAUTH_GENERIC ); + } +if (!kvm_arm_create_scratch_host_vcpu (cpus_to_try, fdarray, &init)) {return false; }
@@ -865,6 +882,10 @@ int kvm_arch_init_vcpu(CPUState *cs)assert (kvm_arm_sve_supported ()); cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_SVE ; } +if (cpu_isar_feature (aa64_pauth, cpu)) { + cpu->kvm_init_features[0 ] |= (1 <<KVM_ARM_VCPU_PTRAUTH_ADDRESS | +1 <<KVM_ARM_VCPU_PTRAUTH_GENERIC ); + }/* Do KVM_ARM_VCPU_INIT ioctl */ ret =kvm_arm_vcpu_init (cs);
Signature · 1 line
2.25.1
[PULL 26/38] hw/intc/arm_gicv3_its: Convert int ID check to num_intids convention
In reply to Peter MaydellThe bounds check on the number of interrupt IDs is correct, but doesn't match our convention; change the variable name, initialize it to the 2^n value rather than (2^n)-1, and use >= instead of > in the comparison.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/intc/arm_gicv3_its.c +3 -3
@@ -338,7 +338,7 @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,uint32_t devid, eventid;uint32_t pIntid =0 ;uint64_t num_eventids; -uint32_t max_Intid; +uint32_t num_intids;bool dte_valid;MemTxResult res =MEMTX_OK ;uint16_t icid =0 ;
@@ -379,11 +379,11 @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset, } dte_valid =FIELD_EX64 (dte,DTE ,VALID ); num_eventids =1ULL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); - max_Intid = (1ULL << (GICD_TYPER_IDBITS +1 )) -1 ; + num_intids =1ULL << (GICD_TYPER_IDBITS +1 );if ((devid >= s->dt.num_ids) || (icid >= s->ct.num_ids) || !dte_valid || (eventid >= num_eventids) || - (((pIntid <GICV3_LPI_INTID_START ) || (pIntid > max_Intid)) && + (((pIntid <GICV3_LPI_INTID_START ) || (pIntid >= num_intids)) && (pIntid !=INTID_SPURIOUS ))) {qemu_log_mask (LOG_GUEST_ERROR , "%s: invalid command attributes "
Signature · 1 line
2.25.1
[PULL 06/38] hw/arm/virt: Support cluster level in DT cpu-map
In reply to Peter MaydellFrom: Yanan Wang <[email protected]>
Support one cluster level between core and physical package in the cpu-map of Arm/virt devicetree. This is also consistent with Linux Doc "Documentation/devicetree/bindings/cpu/cpu-topology.txt".
Message-id: [email protected]
--- hw/arm/virt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
hw/arm/virt.c +8 -7
@@ -434,9 +434,8 @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms)* can contain several layers of clustering within a single physical * package and cluster nodes can be contained in parent cluster nodes. * -* Given that cluster is not yet supported in the vCPU topology, -* we currently generate one cluster node within each socket node -* by default. +* Note: currently we only support one layer of clustering within +* each physical package. */ qemu_fdt_add_subnode (ms->fdt,"/cpus/cpu-map" );
@@ -446,14 +445,16 @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms)if (ms->smp.threads >1 ) { map_path =g_strdup_printf ( -"/cpus/cpu-map/socket%d/cluster0/core%d/thread%d" , - cpu / (ms->smp.cores * ms->smp.threads), +"/cpus/cpu-map/socket%d/cluster%d/core%d/thread%d" , + cpu / (ms->smp.clusters * ms->smp.cores * ms->smp.threads), + (cpu / (ms->smp.cores * ms->smp.threads)) % ms->smp.clusters, (cpu / ms->smp.threads) % ms->smp.cores, cpu % ms->smp.threads); }else { map_path =g_strdup_printf ( -"/cpus/cpu-map/socket%d/cluster0/core%d" , - cpu / ms->smp.cores, +"/cpus/cpu-map/socket%d/cluster%d/core%d" , + cpu / (ms->smp.clusters * ms->smp.cores), + (cpu / ms->smp.cores) % ms->smp.clusters, cpu % ms->smp.cores); }qemu_fdt_add_path (ms->fdt, map_path);
Signature · 1 line
2.25.1
[PULL 28/38] hw/intc/arm_gicv3_its: Don't use data if reading command failed
In reply to Peter MaydellIn process_cmdq(), we read 64 bits of the command packet, which contain the command identifier, which we then switch() on to dispatch to an appropriate sub-function. However, if address_space_ldq_le() reports a memory transaction failure, we still read the command identifier out of the data and switch() on it. Restructure the code so that we stop immediately (stalling the command queue) in this case.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3_its.c +6 -1
@@ -672,8 +672,13 @@ static void process_cmdq(GICv3ITSState *s) data =address_space_ldq_le (as, s->cq.base_addr + cq_offset,MEMTXATTRS_UNSPECIFIED , &res);if (res !=MEMTX_OK ) { - result = false; + s->creadr =FIELD_DP64 (s->creadr,GITS_CREADR ,STALLED ,1 ); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: could not read command at 0x%" PRIx64"\n" , + __func__, s->cq.base_addr + cq_offset); +break ; } + cmd = (data &CMD_MASK );switch (cmd) {
Signature · 1 line
2.25.1
[PULL 03/38] hw/arm/musicpal: Fix coding style of code related to MV88W8618 device
In reply to Peter MaydellFrom: Philippe Mathieu-Daudé <[email protected]>
We are going to move this code, so fix its style first to avoid:
ERROR: spaces required around that '/' (ctx:VxV)
Message-id: [email protected]
--- hw/arm/musicpal.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
hw/arm/musicpal.c +7 -7
@@ -310,13 +310,13 @@ static uint64_t mv88w8618_eth_read(void *opaque, hwaddr offset,return s->imr; case MP_ETH_FRDP0 ... MP_ETH_FRDP3: -return s->frx_queue[(offset -MP_ETH_FRDP0 )/4 ]; +return s->frx_queue[(offset -MP_ETH_FRDP0 ) /4 ]; case MP_ETH_CRDP0 ... MP_ETH_CRDP3: -return s->rx_queue[(offset -MP_ETH_CRDP0 )/4 ]; +return s->rx_queue[(offset -MP_ETH_CRDP0 ) /4 ]; case MP_ETH_CTDP0 ... MP_ETH_CTDP1: -return s->tx_queue[(offset -MP_ETH_CTDP0 )/4 ]; +return s->tx_queue[(offset -MP_ETH_CTDP0 ) /4 ];default :return 0 ;
@@ -361,16 +361,16 @@ static void mv88w8618_eth_write(void *opaque, hwaddr offset,break ; case MP_ETH_FRDP0 ... MP_ETH_FRDP3: - s->frx_queue[(offset -MP_ETH_FRDP0 )/4 ] = value; + s->frx_queue[(offset -MP_ETH_FRDP0 ) /4 ] = value;break ; case MP_ETH_CRDP0 ... MP_ETH_CRDP3: - s->rx_queue[(offset -MP_ETH_CRDP0 )/4 ] = - s->cur_rx[(offset -MP_ETH_CRDP0 )/4 ] = value; + s->rx_queue[(offset -MP_ETH_CRDP0 ) /4 ] = + s->cur_rx[(offset -MP_ETH_CRDP0 ) /4 ] = value;break ; case MP_ETH_CTDP0 ... MP_ETH_CTDP1: - s->tx_queue[(offset -MP_ETH_CTDP0 )/4 ] = value; + s->tx_queue[(offset -MP_ETH_CTDP0 ) /4 ] = value;break ; } }
Signature · 1 line
2.25.1
[PULL 33/38] hw/intc/arm_gicv3_its: Fix return codes in process_mapc()
In reply to Peter MaydellFix process_mapc() to consistently return CMD_STALL for memory errors and CMD_CONTINUE for parameter errors, as we claim in the comments that we do.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
hw/intc/arm_gicv3_its.c +3 -5
@@ -491,7 +491,6 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset)uint64_t rdbase;bool valid;MemTxResult res =MEMTX_OK ; -ItsCmdResult result =CMD_STALL ;uint64_t value; offset +=NUM_BYTES_IN_DW ;
@@ -501,7 +500,7 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset) MEMTXATTRS_UNSPECIFIED, &res);if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } icid = value &ICID_MASK ;
@@ -520,11 +519,10 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset)* we ignore this command and move onto the next * command in the queue */ - }else { - result =update_cte (s, icid, valid, rdbase) ?CMD_CONTINUE :CMD_STALL ; +return CMD_CONTINUE ; } -return result; +return update_cte (s, icid, valid, rdbase) ?CMD_CONTINUE :CMD_STALL ; } static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid,
Signature · 1 line
2.25.1
[PULL 12/38] virtio-mem: Correct default THP size for ARM64
In reply to Peter MaydellFrom: Gavin Shan <[email protected]>
The default block size is same as to the THP size, which is either retrieved from "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" or hardcoded to 2MB. There are flaws in both mechanisms and this intends to fix them up.
* When "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" is used to getting the THP size, 32MB and 512MB are valid values when we have 16KB and 64KB page size on ARM64.
* When the hardcoded THP size is used, 2MB, 32MB and 512MB are valid values when we have 4KB, 16KB and 64KB page sizes on ARM64.
Message-id: [email protected]
--- hw/virtio/virtio-mem.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
hw/virtio/virtio-mem.c +20 -12
@@ -46,14 +46,25 @@*/ #define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)(1 * MiB)) -#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \ - defined(__powerpc64__) -#define VIRTIO_MEM_DEFAULT_THP_SIZE ((uint32_t)(2 * MiB)) -#else -/* fallback to 1 MiB (e.g., the THP size on s390x) */ -#define VIRTIO_MEM_DEFAULT_THP_SIZE VIRTIO_MEM_MIN_BLOCK_SIZE +static uint32_t virtio_mem_default_thp_size (void ) +{ +uint32_t default_thp_size =VIRTIO_MEM_MIN_BLOCK_SIZE ; + +#if defined(__x86_64__) || defined(__arm__) || defined(__powerpc64__) + default_thp_size =2 * MiB; +#elif defined(__aarch64__) +if (qemu_real_host_page_size ==4 * KiB) { + default_thp_size =2 * MiB; + }else if (qemu_real_host_page_size ==16 * KiB) { + default_thp_size =32 * MiB; + }else if (qemu_real_host_page_size ==64 * KiB) { + default_thp_size =512 * MiB; + }#endif +return default_thp_size; +} +/* * We want to have a reasonable default block size such that * 1. We avoid splitting THPs when unplugging memory, which degrades
@@ -86,11 +97,8 @@ static uint32_t virtio_mem_thp_size(void)if (g_file_get_contents (HPAGE_PMD_SIZE_PATH , &content,NULL ,NULL ) && !qemu_strtou64 (content, &endptr,0 , &tmp) && (!endptr || *endptr =='\n' )) { -/* -* Sanity-check the value, if it's too big (e.g., aarch64 with 64k base -* pages) or weird, fallback to something smaller. -*/ -if (!tmp || !is_power_of_2 (tmp) || tmp >16 * MiB) { +/* Sanity-check the value and fallback to something reasonable. */ +if (!tmp || !is_power_of_2 (tmp)) {warn_report ("Read unsupported THP size: %" PRIx64, tmp); }else { thp_size = tmp;
@@ -98,7 +106,7 @@ static uint32_t virtio_mem_thp_size(void) }if (!thp_size) { - thp_size =VIRTIO_MEM_DEFAULT_THP_SIZE ; + thp_size =virtio_mem_default_thp_size ();warn_report ("Could not detect THP size, falling back to %" PRIx64" MiB." , thp_size / MiB); }
Signature · 1 line
2.25.1
[PULL 02/38] hw: Move MARVELL_88W8618 Kconfig from audio/ to arm/
In reply to Peter MaydellFrom: Philippe Mathieu-Daudé <[email protected]>
The Marvell 88W8618 is a system-on-chip with an ARM core. We implement its audio codecs and network interface. Homogeneous SoC Kconfig are usually defined in the hw/$ARCH directory. Move it there.
Message-id: [email protected]
--- hw/arm/Kconfig | 3 +++ hw/audio/Kconfig | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-)
hw/arm/Kconfig +3 -0
@@ -94,6 +94,9 @@ config MUSCA select SPLIT_IRQ select UNIMP +config MARVELL_88W8618 + bool + config MUSICPAL bool select OR_IRQ
hw/audio/Kconfig +0 -3
@@ -47,6 +47,3 @@ config PL041 config CS4231 bool - -config MARVELL_88W8618 - bool
Signature · 1 line
2.25.1
[PULL 10/38] tests/acpi/bios-table-test: Update expected virt/PPTT file
In reply to Peter MaydellFrom: Yanan Wang <[email protected]>
Run ./tests/data/acpi/rebuild-expected-aml.sh from build directory to update PPTT binary. Also empty bios-tables-test-allowed-diff.h.
The disassembled differences between actual and expected PPTT:
/*
* Intel ACPI Component Architecture
* AML/ASL+ Disassembler version 20200528 (64-bit version)
* Copyright (c) 2000 - 2020 Intel Corporation
*
- * Disassembly of tests/data/acpi/virt/PPTT, Tue Jan 4 12:51:11 2022
+ * Disassembly of /tmp/aml-2ZGOF1, Tue Jan 4 12:51:11 2022 *
* ACPI Data Table [PPTT]
*
* Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue */
[000h 0000 4] Signature : "PPTT" [Processor Properties Topology Table] -[004h 0004 4] Table Length : 0000004C +[004h 0004 4] Table Length : 00000060 [008h 0008 1] Revision : 02 -[009h 0009 1] Checksum : A8 +[009h 0009 1] Checksum : 48 [00Ah 0010 6] Oem ID : "BOCHS " [010h 0016 8] Oem Table ID : "BXPC " [018h 0024 4] Oem Revision : 00000001 [01Ch 0028 4] Asl Compiler ID : "BXPC" [020h 0032 4] Asl Compiler Revision : 00000001
[024h 0036 1] Subtable Type : 00 [Processor Hierarchy Node]
[025h 0037 1] Length : 14
[026h 0038 2] Reserved : 0000
[028h 0040 4] Flags (decoded below) : 00000001
Physical package : 1
ACPI Processor ID valid : 0
Processor is a thread : 0
Node is a leaf : 0
Identical Implementation : 0
[02Ch 0044 4] Parent : 00000000
[030h 0048 4] ACPI Processor ID : 00000000
[034h 0052 4] Private Resource Number : 00000000[038h 0056 1] Subtable Type : 00 [Processor Hierarchy Node] [039h 0057 1] Length : 14 [03Ah 0058 2] Reserved : 0000 -[03Ch 0060 4] Flags (decoded below) : 0000000A +[03Ch 0060 4] Flags (decoded below) : 00000000
Physical package : 0
- ACPI Processor ID valid : 1
+ ACPI Processor ID valid : 0
Processor is a thread : 0
- Node is a leaf : 1
+ Node is a leaf : 0
Identical Implementation : 0
[040h 0064 4] Parent : 00000024 [044h 0068 4] ACPI Processor ID : 00000000 [048h 0072 4] Private Resource Number : 00000000
-Raw Table Data: Length 76 (0x4C)
+[04Ch 0076 1] Subtable Type : 00 [Processor Hierarchy Node] +[04Dh 0077 1] Length : 14 +[04Eh 0078 2] Reserved : 0000 +[050h 0080 4] Flags (decoded below) : 0000000A
+ Physical package : 0
+ ACPI Processor ID valid : 1
+ Processor is a thread : 0
+ Node is a leaf : 1
+ Identical Implementation : 0
+[054h 0084 4] Parent : 00000038 +[058h 0088 4] ACPI Processor ID : 00000000 +[05Ch 0092 4] Private Resource Number : 00000000
+
+Raw Table Data: Length 96 (0x60)
- 0000: 50 50 54 54 4C 00 00 00 02 A8 42 4F 43 48 53 20 // PPTTL.....BOCHS
+ 0000: 50 50 54 54 60 00 00 00 02 48 42 4F 43 48 53 20 // PPTT`....HBOCHS
0010: 42 58 50 43 20 20 20 20 01 00 00 00 42 58 50 43 // BXPC ....BXPC
0020: 01 00 00 00 00 14 00 00 01 00 00 00 00 00 00 00 // ................
- 0030: 00 00 00 00 00 00 00 00 00 14 00 00 0A 00 00 00 // ................
- 0040: 24 00 00 00 00 00 00 00 00 00 00 00 // $...........
+ 0030: 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 // ................
+ 0040: 24 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 // $...............
+ 0050: 0A 00 00 00 38 00 00 00 00 00 00 00 00 00 00 00 // ....8...........Message-id: [email protected]
--- tests/qtest/bios-tables-test-allowed-diff.h | 1 - tests/data/acpi/virt/PPTT | Bin 76 -> 96 bytes 2 files changed, 1 deletion(-)
tests/qtest/bios-tables-test-allowed-diff.h +0 -1
@@ -1,2 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/virt/PPTT",
tests/data/acpi/virt/PPTT binary +0 -0
Signature · 1 line
2.25.1
[PULL 04/38] hw/net: Move MV88W8618 network device out of hw/arm/ directory
In reply to Peter MaydellFrom: Philippe Mathieu-Daudé <[email protected]>
The Marvell 88W8618 network device is hidden in the Musicpal machine. Move it into a new unit file under the hw/net/ directory.
Message-id: [email protected]
--- include/hw/net/mv88w8618_eth.h | 12 + hw/arm/musicpal.c | 381 +------------------------------ hw/net/mv88w8618_eth.c | 403 +++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/net/meson.build | 1 + 5 files changed, 419 insertions(+), 380 deletions(-) create mode 100644 include/hw/net/mv88w8618_eth.h create mode 100644 hw/net/mv88w8618_eth.c
include/hw/net/mv88w8618_eth.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Marvell MV88W8618 / Freecom MusicPal emulation. +* +* Copyright (c) 2008-2021 QEMU contributors +*/ +#ifndef HW_NET_MV88W8618_H +#define HW_NET_MV88W8618_H + +#define TYPE_MV88W8618_ETH "mv88w8618_eth" + +#endif
hw/arm/musicpal.c +1 -380
404 lines not on this page · raw message
hw/net/mv88w8618_eth.c new file +403 -0
403 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -774,6 +774,8 @@ M: Peter Maydell <[email protected]> L: [email protected] S: Odd Fixes F: hw/arm/musicpal.c +F: hw/net/mv88w8618_eth.c +F: include/hw/net/mv88w8618_eth.h F: docs/system/arm/musicpal.rst Nuvoton NPCM7xx
hw/net/meson.build +1 -0
@@ -26,6 +26,7 @@ softmmu_ss.add(when: 'CONFIG_ALLWINNER_EMAC', if_true: files('allwinner_emac.c') softmmu_ss.add(when: 'CONFIG_ALLWINNER_SUN8I_EMAC', if_true: files('allwinner-sun8i-emac.c')) softmmu_ss.add(when: 'CONFIG_IMX_FEC', if_true: files('imx_fec.c')) softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-emac.c')) +softmmu_ss.add(when: 'CONFIG_MARVELL_88W8618', if_true: files('mv88w8618_eth.c')) softmmu_ss.add(when: 'CONFIG_CADENCE', if_true: files('cadence_gem.c')) softmmu_ss.add(when: 'CONFIG_STELLARIS_ENET', if_true: files('stellaris_enet.c'))
Signature · 1 line
2.25.1
[PULL 09/38] hw/acpi/aml-build: Support cluster level in PPTT generation
In reply to Peter MaydellFrom: Yanan Wang <[email protected]>
Support CPU cluster topology level in generation of ACPI Processor Properties Topology Table (PPTT).
Message-id: [email protected]
--- hw/acpi/aml-build.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
hw/acpi/aml-build.c +18 -0
@@ -2001,6 +2001,7 @@ static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags,void build_pptt (GArray *table_data,BIOSLinker *linker,MachineState *ms,const char *oem_id,const char *oem_table_id) { +MachineClass *mc =MACHINE_GET_CLASS (ms);GQueue *list =g_queue_new ();guint pptt_start = table_data->len;guint parent_offset;
@@ -2025,6 +2026,23 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms, 0, socket, NULL, 0); } +if (mc->smp_props.clusters_supported) { + length =g_queue_get_length (list); +for (i =0 ; i < length; i++) { +int cluster; + + parent_offset =GPOINTER_TO_UINT (g_queue_pop_head (list)); +for (cluster =0 ; cluster < ms->smp.clusters; cluster++) { +g_queue_push_tail (list, +GUINT_TO_POINTER (table_data->len - pptt_start)); +build_processor_hierarchy_node ( + table_data, + (0 <<0 ),/* not a physical package */ + parent_offset, cluster,NULL ,0 ); + } + } + } + length =g_queue_get_length (list);for (i =0 ; i < length; i++) {int core;
Signature · 1 line
2.25.1
[PULL 14/38] hw/intc/arm_gic: Implement read of GICC_IIDR
In reply to Peter MaydellFrom: Petr Pavlu <[email protected]>
Implement support for reading GICC_IIDR. This register is used by the Linux kernel to recognize that GICv2 with GICC_APRn is present.
Message-id: [email protected]
--- hw/intc/arm_gic.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/intc/arm_gic.c +9 -0
@@ -1662,6 +1662,15 @@ static MemTxResult gic_cpu_read(GICState *s, int cpu, int offset, }break ; } +case 0xfc : +if (s->revision ==REV_11MPCORE ) { +/* Reserved on 11MPCore */ + *data =0 ; + }else { +/* GICv1 or v2; Arm implementation */ + *data = (s->revision <<16 ) |0x43b ; + } +break ;default :qemu_log_mask (LOG_GUEST_ERROR ,"gic_cpu_read: Bad offset %x\n" , (int )offset);
Signature · 1 line
2.25.1
[PULL 19/38] hw/arm/virt: Use the PA range to compute the memory map
In reply to Peter MaydellFrom: Marc Zyngier <[email protected]>
The highmem attribute is nothing but another way to express the PA range of a VM. To support HW that has a smaller PA range then what QEMU assumes, pass this PA range to the virt_set_memmap() function, allowing it to correctly exclude highmem devices if they are outside of the PA range.
Message-id: [email protected]
--- hw/arm/virt.c | 64 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 12 deletions(-)
hw/arm/virt.c +52 -12
@@ -1667,7 +1667,7 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)return arm_cpu_mp_affinity (idx, clustersz); } -static void virt_set_memmap (VirtMachineState *vms) +static void virt_set_memmap (VirtMachineState *vms,int pa_bits) {MachineState *ms =MACHINE (vms);hwaddr base, device_memory_base, device_memory_size, memtop;
@@ -1685,6 +1685,14 @@ static void virt_set_memmap(VirtMachineState *vms)exit (EXIT_FAILURE ); } +/* +* !highmem is exactly the same as limiting the PA space to 32bit, +* irrespective of the underlying capabilities of the HW. +*/ +if (!vms->highmem) { + pa_bits =32 ; + } +/* * We compute the base of the high IO region depending on the * amount of initial and device memory. The device memory start/size
@@ -1698,8 +1706,9 @@ static void virt_set_memmap(VirtMachineState *vms)/* Base address of the high IO region */ memtop = base = device_memory_base +ROUND_UP (device_memory_size, GiB); -if (!vms->highmem && memtop >4 * GiB) { -error_report ("highmem=off, but memory crosses the 4GiB limit\n" ); +if (memtop >BIT_ULL (pa_bits)) { +error_report ("Addressing limited to %d bits, but memory exceeds it by %llu bytes\n" , + pa_bits, memtop -BIT_ULL (pa_bits));exit (EXIT_FAILURE ); }if (base < device_memory_base) {
@@ -1718,7 +1727,13 @@ static void virt_set_memmap(VirtMachineState *vms) vms->memmap[i].size = size; base += size; } - vms->highest_gpa = (vms->highmem ? base : memtop) -1 ; + +/* +* If base fits within pa_bits, all good. If it doesn't, limit it +* to the end of RAM, which is guaranteed to fit within pa_bits. +*/ + vms->highest_gpa = (base <=BIT_ULL (pa_bits) ? base : memtop) -1 ; +if (device_memory_size >0 ) { ms->device_memory =g_malloc0 (sizeof (*ms->device_memory)); ms->device_memory->base = device_memory_base;
@@ -1909,12 +1924,43 @@ static void machvirt_init(MachineState *machine)unsigned int smp_cpus = machine->smp.cpus;unsigned int max_cpus = machine->smp.max_cpus; +if (!cpu_type_valid (machine->cpu_type)) { +error_report ("mach-virt: CPU type %s not supported" , machine->cpu_type); +exit (1 ); + } + + possible_cpus = mc->possible_cpu_arch_ids (machine); +/* * In accelerated mode, the memory map is computed earlier in kvm_type() * to create a VM with the right number of IPA bits. */ if (!vms->memmap) { -virt_set_memmap (vms); +Object *cpuobj; +ARMCPU *armcpu; +int pa_bits; + +/* +* Instanciate a temporary CPU object to find out about what +* we are about to deal with. Once this is done, get rid of +* the object. +*/ + cpuobj =object_new (possible_cpus->cpus[0 ].type); + armcpu =ARM_CPU (cpuobj); + +if (object_property_get_bool (cpuobj,"aarch64" ,NULL )) { + pa_bits =arm_pamax (armcpu); + }else if (arm_feature (&armcpu->env,ARM_FEATURE_LPAE )) { +/* v7 with LPAE */ + pa_bits =40 ; + }else { +/* Anything else */ + pa_bits =32 ; + } + +object_unref (cpuobj); + +virt_set_memmap (vms, pa_bits); }/* We can probe only here because during property set
@@ -1922,11 +1968,6 @@ static void machvirt_init(MachineState *machine)*/ finalize_gic_version (vms); -if (!cpu_type_valid (machine->cpu_type)) { -error_report ("mach-virt: CPU type %s not supported" , machine->cpu_type); -exit (1 ); - } -if (vms->secure) {/* * The Secure view of the world is the same as the NonSecure,
@@ -1996,7 +2037,6 @@ static void machvirt_init(MachineState *machine)create_fdt (vms); - possible_cpus = mc->possible_cpu_arch_ids (machine);assert (possible_cpus->len == max_cpus);for (n =0 ; n < possible_cpus->len; n++) {Object *cpuobj;
@@ -2735,7 +2775,7 @@ static int virt_kvm_type(MachineState *ms, const char *type_str) max_vm_pa_size =kvm_arm_get_max_vm_ipa_size (ms, &fixed_ipa);/* we freeze the memory map to compute the highest gpa */ -virt_set_memmap (vms); +virt_set_memmap (vms, max_vm_pa_size); requested_pa_size =64 -clz64 (vms->highest_gpa);
Signature · 1 line
2.25.1
[PULL 11/38] docs/can: convert to restructuredText
In reply to Peter MaydellFrom: Lucas Ramage <[email protected]>
Message-id: [email protected]
[PMM: Move to docs/system/devices/ rather than top-level;
fix a pre-existing typo in passing]
---
docs/system/device-emulation.rst | 1 +
docs/{can.txt => system/devices/can.rst} | 90 +++++++++++-------------
2 files changed, 41 insertions(+), 50 deletions(-)
rename docs/{can.txt => system/devices/can.rst} (68%)docs/system/device-emulation.rst +1 -0
@@ -82,6 +82,7 @@ Emulated Devices .. toctree:: :maxdepth: 1 + devices/can.rst devices/ivshmem.rst devices/net.rst devices/nvme.rst
docs/system/devices/can.rst renamed from docs/can.txt +40 -50
173 lines not on this page · raw message
Signature · 1 line
2.25.1
[PULL 22/38] hw/arm: kudo add lm75s behind bus 1 switch at 75
In reply to Peter MaydellFrom: Patrick Venture <[email protected]>
Message-id: [email protected]
--- hw/arm/npcm7xx_boards.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
hw/arm/npcm7xx_boards.c +9 -1
@@ -332,7 +332,15 @@ static void kudo_bmc_i2c_init(NPCM7xxState *soc) {I2CSlave *i2c_mux; -i2c_slave_create_simple (npcm7xx_i2c_get_bus (soc,1 ),TYPE_PCA9548 ,0x75 ); + i2c_mux =i2c_slave_create_simple (npcm7xx_i2c_get_bus (soc,1 ), +TYPE_PCA9548 ,0x75 ); + +/* tmp105 is compatible with the lm75 */ +i2c_slave_create_simple (pca954x_i2c_get_bus (i2c_mux,4 ),"tmp105" ,0x5c ); +i2c_slave_create_simple (pca954x_i2c_get_bus (i2c_mux,5 ),"tmp105" ,0x5c ); +i2c_slave_create_simple (pca954x_i2c_get_bus (i2c_mux,6 ),"tmp105" ,0x5c ); +i2c_slave_create_simple (pca954x_i2c_get_bus (i2c_mux,7 ),"tmp105" ,0x5c ); +i2c_slave_create_simple (npcm7xx_i2c_get_bus (soc,1 ),TYPE_PCA9548 ,0x77 );i2c_slave_create_simple (npcm7xx_i2c_get_bus (soc,4 ),TYPE_PCA9548 ,0x77 );
Signature · 1 line
2.25.1
[PULL 17/38] hw/arm/virt: Add a control for the the highmem redistributors
In reply to Peter MaydellFrom: Marc Zyngier <[email protected]>
Just like we can control the enablement of the highmem PCIe region using highmem_ecam, let's add a control for the highmem GICv3 redistributor region.
Similarily to highmem_ecam, these redistributors are disabled when highmem is off.
Message-id: [email protected]
--- include/hw/arm/virt.h | 4 +++- hw/arm/virt-acpi-build.c | 2 ++ hw/arm/virt.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-)
include/hw/arm/virt.h +3 -1
@@ -144,6 +144,7 @@ struct VirtMachineState {bool highmem;bool highmem_ecam;bool highmem_mmio; +bool highmem_redists;bool its;bool tcg_its;bool virt;
@@ -191,7 +192,8 @@ static inline int virt_gicv3_redist_region_count(VirtMachineState *vms)assert (vms->gic_version ==VIRT_GIC_VERSION_3 ); - return MACHINE(vms)->smp.cpus > redist0_capacity ? 2 : 1; +return (MACHINE (vms)->smp.cpus > redist0_capacity && + vms->highmem_redists) ? 2 : 1; }#endif /* QEMU_ARM_VIRT_H */
hw/arm/virt-acpi-build.c +2 -0
@@ -947,6 +947,8 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_fadt_rev5 (tables_blob, tables->linker, vms, dsdt); + vms->highmem_redists &= vms->highmem; +acpi_add_table (table_offsets, tables_blob);build_madt (tables_blob, tables->linker, vms);
hw/arm/virt.c +2 -0
@@ -2113,6 +2113,7 @@ static void machvirt_init(MachineState *machine)virt_flash_fdt (vms, sysmem, secure_sysmem ?: sysmem); vms->highmem_mmio &= vms->highmem; + vms->highmem_redists &= vms->highmem;create_gic (vms, sysmem);
@@ -2902,6 +2903,7 @@ static void virt_instance_init(Object *obj) vms->highmem_ecam = !vmc->no_highmem_ecam; vms->highmem_mmio = true; + vms->highmem_redists = true;if (vmc->no_its) { vms->its = false;
Signature · 1 line
2.25.1
[PULL 25/38] hw/intc/arm_gicv3_its: Fix event ID bounds checks
In reply to Peter MaydellIn process_its_cmd() and process_mapti() we must check the event ID against a limit defined by the size field in the DTE, which specifies the number of ID bits minus one. Convert this code to our num_foo convention:
* change the variable names
* use uint64_t and 1ULL when calculating the number of valid event IDs, because DTE.SIZE is 5 bits and so num_eventids may be up to 2^32
* fix the off-by-one error in the comparison
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
hw/intc/arm_gicv3_its.c +10 -8
@@ -225,7 +225,7 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,MemTxResult res =MEMTX_OK ;bool dte_valid;uint64_t dte =0 ; -uint32_t max_eventid; +uint64_t num_eventids;uint16_t icid =0 ;uint32_t pIntid =0 ;bool ite_valid = false;
@@ -258,7 +258,7 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset, dte_valid =FIELD_EX64 (dte,DTE ,VALID );if (dte_valid) { - max_eventid =1UL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); + num_eventids =1ULL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); ite_valid =get_ite (s, eventid, dte, &icid, &pIntid, &res);
@@ -299,10 +299,11 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset, dte_valid ?"valid" :"invalid" , ite_valid ?"valid" :"invalid" , cte_valid ? "valid" : "invalid"); - }else if (eventid > max_eventid) { + }else if (eventid >= num_eventids) {qemu_log_mask (LOG_GUEST_ERROR , -"%s: invalid command attributes: eventid %d > %d\n" , - __func__, eventid, max_eventid); +"%s: invalid command attributes: eventid %d >= %" + PRId64"\n" , + __func__, eventid, num_eventids); }else {/* * Current implementation only supports rdbase == procnum
@@ -336,7 +337,8 @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,AddressSpace *as = &s->gicv3->dma_as;uint32_t devid, eventid;uint32_t pIntid =0 ; -uint32_t max_eventid, max_Intid; +uint64_t num_eventids; +uint32_t max_Intid;bool dte_valid;MemTxResult res =MEMTX_OK ;uint16_t icid =0 ;
@@ -376,11 +378,11 @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,return result; } dte_valid =FIELD_EX64 (dte,DTE ,VALID ); - max_eventid =1UL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); + num_eventids =1ULL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 ); max_Intid = (1ULL << (GICD_TYPER_IDBITS +1 )) -1 ;if ((devid >= s->dt.num_ids) || (icid >= s->ct.num_ids) - || !dte_valid || (eventid > max_eventid) || + || !dte_valid || (eventid >= num_eventids) || (((pIntid <GICV3_LPI_INTID_START ) || (pIntid > max_Intid)) && (pIntid !=INTID_SPURIOUS ))) { qemu_log_mask(LOG_GUEST_ERROR,
Signature · 1 line
2.25.1
[PULL 20/38] hw/arm/virt: Disable highmem devices that don't fit in the PA range
In reply to Peter MaydellFrom: Marc Zyngier <[email protected]>
In order to only keep the highmem devices that actually fit in the PA range, check their location against the range and update highest_gpa if they fit. If they don't, mark them as disabled.
Message-id: [email protected]
--- hw/arm/virt.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
hw/arm/virt.c +28 -6
@@ -1719,21 +1719,43 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits) base = vms->memmap[VIRT_MEM ].base +LEGACY_RAMLIMIT_BYTES ; } +/* We know for sure that at least the memory fits in the PA space */ + vms->highest_gpa = memtop -1 ; +for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) {hwaddr size = extended_memmap[i].size; +bool fits; base =ROUND_UP (base, size); vms->memmap[i].base = base; vms->memmap[i].size = size; + +/* +* Check each device to see if they fit in the PA space, +* moving highest_gpa as we go. +* +* For each device that doesn't fit, disable it. +*/ + fits = (base + size) <=BIT_ULL (pa_bits); +if (fits) { + vms->highest_gpa = base + size -1 ; + } + +switch (i) { +case VIRT_HIGH_GIC_REDIST2 : + vms->highmem_redists &= fits; +break ; +case VIRT_HIGH_PCIE_ECAM : + vms->highmem_ecam &= fits; +break ; +case VIRT_HIGH_PCIE_MMIO : + vms->highmem_mmio &= fits; +break ; + } + base += size; } -/* -* If base fits within pa_bits, all good. If it doesn't, limit it -* to the end of RAM, which is guaranteed to fit within pa_bits. -*/ - vms->highest_gpa = (base <=BIT_ULL (pa_bits) ? base : memtop) -1 ; -if (device_memory_size >0 ) { ms->device_memory =g_malloc0 (sizeof (*ms->device_memory)); ms->device_memory->base = device_memory_base;
Signature · 1 line
2.25.1
[PULL 29/38] hw/intc/arm_gicv3_its: Use enum for return value of process_* functions
In reply to Peter MaydellWhen an ITS detects an error in a command, it has an implementation-defined (CONSTRAINED UNPREDICTABLE) choice of whether to ignore the command, proceeding to the next one in the queue, or to stall the ITS command queue, processing nothing further. The behaviour required when the read of the command packet from memory fails is less clearly documented, but the same set of choices as for command errors seem reasonable.
The intention of the QEMU implementation, as documented in the comments, is that if we encounter a memory error reading the command packet or one of the various data tables then we should stall, but for command parameter errors we should ignore the queue and continue. However, we don't actually do this. To get the desired behaviour, the various process_* functions need to return true to cause process_cmdq() to advance to the next command and keep processing, and false to stall command processing. What they mostly do is return false for any kind of error.
To make the code clearer, replace the 'bool' return from the process_ functions with an enum which may be either CMD_STALL or CMD_CONTINUE. In this commit no behaviour changes; in subsequent commits we will adjust the error-return paths for the process_ functions one by one.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 59 ++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-)
hw/intc/arm_gicv3_its.c +38 -21
@@ -45,6 +45,23 @@ typedef struct {uint64_t itel; } IteEntry; +/* +* The ITS spec permits a range of CONSTRAINED UNPREDICTABLE options +* if a command parameter is not correct. These include both "stall +* processing of the command queue" and "ignore this command, and +* keep processing the queue". In our implementation we choose that +* memory transaction errors reading the command packet provoke a +* stall, but errors in parameters cause us to ignore the command +* and continue processing. +* The process_* functions which handle individual ITS commands all +* return an ItsCmdResult which tells process_cmdq() whether it should +* stall or keep going. +*/ +typedef enum ItsCmdResult { +CMD_STALL =0 , +CMD_CONTINUE =1 , +}ItsCmdResult ; +static uint64_t baser_base_addr (uint64_t value,uint32_t page_sz) {uint64_t result =0 ;
@@ -217,8 +234,8 @@ static uint64_t get_dte(GICv3ITSState *s, uint32_t devid, MemTxResult *res)* 3. handling of ITS CLEAR command * 4. handling of ITS DISCARD command */ -static bool process_its_cmd (GICv3ITSState *s,uint64_t value,uint32_t offset, -ItsCmdType cmd) +static ItsCmdResult process_its_cmd (GICv3ITSState *s,uint64_t value, +uint32_t offset,ItsCmdType cmd) {AddressSpace *as = &s->gicv3->dma_as;uint32_t devid, eventid;
@@ -231,7 +248,7 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,bool ite_valid = false;uint64_t cte =0 ;bool cte_valid = false; -bool result = false; +ItsCmdResult result =CMD_STALL ;uint64_t rdbase;if (cmd ==NONE ) {
@@ -324,15 +341,15 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,if (cmd ==DISCARD ) {IteEntry ite = {};/* remove mapping from interrupt translation table */ - result =update_ite (s, eventid, dte, ite); + result =update_ite (s, eventid, dte, ite) ?CMD_CONTINUE :CMD_STALL ; } }return result; } -static bool process_mapti (GICv3ITSState *s,uint64_t value,uint32_t offset, -bool ignore_pInt) +static ItsCmdResult process_mapti (GICv3ITSState *s,uint64_t value, +uint32_t offset,bool ignore_pInt) {AddressSpace *as = &s->gicv3->dma_as;uint32_t devid, eventid;
@@ -343,7 +360,7 @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,MemTxResult res =MEMTX_OK ;uint16_t icid =0 ;uint64_t dte =0 ; -bool result = false; +ItsCmdResult result =CMD_STALL ; devid = ((value &DEVID_MASK ) >>DEVID_SHIFT ); offset +=NUM_BYTES_IN_DW ;
@@ -404,7 +421,7 @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset, ite.itel =FIELD_DP64 (ite.itel,ITE_L ,DOORBELL ,INTID_SPURIOUS ); ite.iteh =FIELD_DP32 (ite.iteh,ITE_H ,ICID , icid); - result =update_ite (s, eventid, dte, ite); + result =update_ite (s, eventid, dte, ite) ?CMD_CONTINUE :CMD_STALL ; }return result;
@@ -472,14 +489,14 @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid, } } -static bool process_mapc (GICv3ITSState *s,uint32_t offset) +static ItsCmdResult process_mapc (GICv3ITSState *s,uint32_t offset) {AddressSpace *as = &s->gicv3->dma_as;uint16_t icid;uint64_t rdbase;bool valid;MemTxResult res =MEMTX_OK ; -bool result = false; +ItsCmdResult result =CMD_STALL ;uint64_t value; offset +=NUM_BYTES_IN_DW ;
@@ -509,7 +526,7 @@ static bool process_mapc(GICv3ITSState *s, uint32_t offset)* command in the queue */ }else { - result =update_cte (s, icid, valid, rdbase); + result =update_cte (s, icid, valid, rdbase) ?CMD_CONTINUE :CMD_STALL ; }return result;
@@ -578,7 +595,8 @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid, } } -static bool process_mapd (GICv3ITSState *s,uint64_t value,uint32_t offset) +static ItsCmdResult process_mapd (GICv3ITSState *s,uint64_t value, +uint32_t offset) {AddressSpace *as = &s->gicv3->dma_as;uint32_t devid;
@@ -586,7 +604,7 @@ static bool process_mapd(GICv3ITSState *s, uint64_t value, uint32_t offset)uint64_t itt_addr;bool valid;MemTxResult res =MEMTX_OK ; -bool result = false; +ItsCmdResult result =CMD_STALL ; devid = ((value &DEVID_MASK ) >>DEVID_SHIFT );
@@ -623,7 +641,7 @@ static bool process_mapd(GICv3ITSState *s, uint64_t value, uint32_t offset)* command in the queue */ }else { - result =update_dte (s, devid, valid, size, itt_addr); + result =update_dte (s, devid, valid, size, itt_addr) ?CMD_CONTINUE :CMD_STALL ; }return result;
@@ -641,7 +659,6 @@ static void process_cmdq(GICv3ITSState *s)uint64_t data;AddressSpace *as = &s->gicv3->dma_as;MemTxResult res =MEMTX_OK ; -bool result = true;uint8_t cmd;int i;
@@ -668,6 +685,8 @@ static void process_cmdq(GICv3ITSState *s) }while (wr_offset != rd_offset) { +ItsCmdResult result =CMD_CONTINUE ; + cq_offset = (rd_offset *GITS_CMDQ_ENTRY_SIZE ); data =address_space_ldq_le (as, s->cq.base_addr + cq_offset,MEMTXATTRS_UNSPECIFIED , &res);
@@ -726,18 +745,16 @@ static void process_cmdq(GICv3ITSState *s)default :break ; } -if (result) { +if (result ==CMD_CONTINUE ) { rd_offset++; rd_offset %= s->cq.num_entries; s->creadr =FIELD_DP64 (s->creadr,GITS_CREADR ,OFFSET , rd_offset); }else { -/* -* in this implementation, in case of dma read/write error -* we stall the command processing -*/ +/* CMD_STALL */ s->creadr =FIELD_DP64 (s->creadr,GITS_CREADR ,STALLED ,1 );qemu_log_mask (LOG_GUEST_ERROR , -"%s: %x cmd processing failed\n" , __func__, cmd); +"%s: 0x%x cmd processing failed, stalling\n" , + __func__, cmd);break ; } }
Signature · 1 line
2.25.1
[PULL 21/38] hw/arm/virt: Drop superfluous checks against highmem
In reply to Peter MaydellFrom: Marc Zyngier <[email protected]>
Now that the devices present in the extended memory map are checked against the available PA space and disabled when they don't fit, there is no need to keep the same checks against highmem, as highmem really is a shortcut for the PA space being 32bit.
Message-id: [email protected]
--- hw/arm/virt-acpi-build.c | 2 -- hw/arm/virt.c | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-)
hw/arm/virt-acpi-build.c +0 -2
@@ -947,8 +947,6 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_fadt_rev5 (tables_blob, tables->linker, vms, dsdt); - vms->highmem_redists &= vms->highmem; -acpi_add_table (table_offsets, tables_blob);build_madt (tables_blob, tables->linker, vms);
hw/arm/virt.c +1 -4
@@ -2178,9 +2178,6 @@ static void machvirt_init(MachineState *machine)virt_flash_fdt (vms, sysmem, secure_sysmem ?: sysmem); - vms->highmem_mmio &= vms->highmem; - vms->highmem_redists &= vms->highmem; -create_gic (vms, sysmem);virt_cpu_post_init (vms, sysmem);
@@ -2199,7 +2196,7 @@ static void machvirt_init(MachineState *machine) machine->ram_size, "mach-virt.tag"); } - vms->highmem_ecam &= vms->highmem && (!firmware_loaded || aarch64); + vms->highmem_ecam &= (!firmware_loaded || aarch64);create_rtc (vms);
Signature · 1 line
2.25.1
[PULL 30/38] hw/intc/arm_gicv3_its: Fix return codes in process_its_cmd()
In reply to Peter MaydellFix process_its_cmd() to consistently return CMD_STALL for memory errors and CMD_CONTINUE for parameter errors, as we claim in the comments that we do.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
hw/intc/arm_gicv3_its.c +11 -11
@@ -248,7 +248,6 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,bool ite_valid = false;uint64_t cte =0 ;bool cte_valid = false; -ItsCmdResult result =CMD_STALL ;uint64_t rdbase;if (cmd ==NONE ) {
@@ -262,7 +261,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, }if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } eventid = (value &EVENTID_MASK );
@@ -270,7 +269,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, dte =get_dte (s, devid, &res);if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } dte_valid =FIELD_EX64 (dte,DTE ,VALID );
@@ -280,7 +279,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, ite_valid =get_ite (s, eventid, dte, &icid, &pIntid, &res);if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; }if (ite_valid) {
@@ -288,14 +287,14 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, }if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } }else {qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid command attributes: " "invalid dte: %" PRIx64" for %d (MEM_TX: %d)\n" , __func__, dte, devid, res); -return result; +return CMD_CONTINUE ; }
@@ -307,7 +306,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid command attributes: devid %d>=%d" , __func__, devid, s->dt.num_ids); - +return CMD_CONTINUE ; }else if (!dte_valid || !ite_valid || !cte_valid) {qemu_log_mask (LOG_GUEST_ERROR , "%s: invalid command attributes: "
@@ -316,11 +315,13 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, dte_valid ?"valid" :"invalid" , ite_valid ?"valid" :"invalid" , cte_valid ? "valid" : "invalid"); +return CMD_CONTINUE ; }else if (eventid >= num_eventids) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid command attributes: eventid %d >= %" PRId64"\n" , __func__, eventid, num_eventids); +return CMD_CONTINUE ; }else {/* * Current implementation only supports rdbase == procnum
@@ -329,7 +330,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, rdbase =FIELD_EX64 (cte,CTE ,RDBASE );if (rdbase >= s->gicv3->num_cpu) { -return result; +return CMD_CONTINUE ; }if ((cmd ==CLEAR ) || (cmd ==DISCARD )) {
@@ -341,11 +342,10 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,if (cmd ==DISCARD ) {IteEntry ite = {};/* remove mapping from interrupt translation table */ - result =update_ite (s, eventid, dte, ite) ?CMD_CONTINUE :CMD_STALL ; +return update_ite (s, eventid, dte, ite) ?CMD_CONTINUE :CMD_STALL ; } +return CMD_CONTINUE ; } - -return result; } static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
Signature · 1 line
2.25.1
[PULL 32/38] hw/intc/arm_gicv3_its: Fix return codes in process_mapti()
In reply to Peter MaydellFix process_mapti() to consistently return CMD_STALL for memory errors and CMD_CONTINUE for parameter errors, as we claim in the comments that we do.
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
hw/intc/arm_gicv3_its.c +13 -15
@@ -357,7 +357,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,MemTxResult res =MEMTX_OK ;uint16_t icid =0 ;uint64_t dte =0 ; -ItsCmdResult result =CMD_STALL ; +IteEntry ite = {}; devid = ((value &DEVID_MASK ) >>DEVID_SHIFT ); offset +=NUM_BYTES_IN_DW ;
@@ -365,7 +365,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, MEMTXATTRS_UNSPECIFIED, &res);if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } eventid = (value &EVENTID_MASK );
@@ -381,7 +381,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, MEMTXATTRS_UNSPECIFIED, &res);if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } icid = value &ICID_MASK ;
@@ -389,7 +389,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, dte =get_dte (s, devid, &res);if (res !=MEMTX_OK ) { -return result; +return CMD_STALL ; } dte_valid =FIELD_EX64 (dte,DTE ,VALID ); num_eventids =1ULL << (FIELD_EX64 (dte,DTE ,SIZE ) +1 );
@@ -409,19 +409,17 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,* we ignore this command and move onto the next * command in the queue */ - }else { -/* add ite entry to interrupt translation table */ -IteEntry ite = {}; - ite.itel =FIELD_DP64 (ite.itel,ITE_L ,VALID , dte_valid); - ite.itel =FIELD_DP64 (ite.itel,ITE_L ,INTTYPE ,ITE_INTTYPE_PHYSICAL ); - ite.itel =FIELD_DP64 (ite.itel,ITE_L ,INTID , pIntid); - ite.itel =FIELD_DP64 (ite.itel,ITE_L ,DOORBELL ,INTID_SPURIOUS ); - ite.iteh =FIELD_DP32 (ite.iteh,ITE_H ,ICID , icid); - - result =update_ite (s, eventid, dte, ite) ?CMD_CONTINUE :CMD_STALL ; +return CMD_CONTINUE ; } -return result; +/* add ite entry to interrupt translation table */ + ite.itel =FIELD_DP64 (ite.itel,ITE_L ,VALID , dte_valid); + ite.itel =FIELD_DP64 (ite.itel,ITE_L ,INTTYPE ,ITE_INTTYPE_PHYSICAL ); + ite.itel =FIELD_DP64 (ite.itel,ITE_L ,INTID , pIntid); + ite.itel =FIELD_DP64 (ite.itel,ITE_L ,DOORBELL ,INTID_SPURIOUS ); + ite.iteh =FIELD_DP32 (ite.iteh,ITE_H ,ICID , icid); + +return update_ite (s, eventid, dte, ite) ?CMD_CONTINUE :CMD_STALL ; } static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid,
Signature · 1 line
2.25.1
[PULL 24/38] hw/arm/aspeed: Add the i3c device to the AST2600 SoC
In reply to Peter MaydellFrom: Troy Lee <[email protected]>
Add the new i3c device to the AST2600 SoC.
Message-id: [email protected]
--- include/hw/arm/aspeed_soc.h | 3 +++ hw/arm/aspeed_ast2600.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+)
include/hw/arm/aspeed_soc.h +3 -0
@@ -21,6 +21,7 @@#include "hw/timer/aspeed_timer.h" #include "hw/rtc/aspeed_rtc.h" #include "hw/i2c/aspeed_i2c.h" +#include "hw/misc/aspeed_i3c.h" #include "hw/ssi/aspeed_smc.h" #include "hw/misc/aspeed_hace.h" #include "hw/watchdog/wdt_aspeed.h"
@@ -51,6 +52,7 @@ struct AspeedSoCState {AspeedRtcState rtc;AspeedTimerCtrlState timerctrl;AspeedI2CState i2c; +AspeedI3CState i3c;AspeedSCUState scu;AspeedHACEState hace;AspeedXDMAState xdma;
@@ -141,6 +143,7 @@ enum {ASPEED_DEV_HACE ,ASPEED_DEV_DPMCU ,ASPEED_DEV_DP , + ASPEED_DEV_I3C, };#endif /* ASPEED_SOC_H */
hw/arm/aspeed_ast2600.c +16 -0
@@ -61,6 +61,7 @@ static const hwaddr aspeed_soc_ast2600_memmap[] = { [ASPEED_DEV_UART1] = 0x1E783000, [ASPEED_DEV_UART5] = 0x1E784000, [ASPEED_DEV_VUART] = 0x1E787000, + [ASPEED_DEV_I3C] = 0x1E7A0000, [ASPEED_DEV_SDRAM] = 0x80000000, };
@@ -108,6 +109,7 @@ static const int aspeed_soc_ast2600_irqmap[] = { [ASPEED_DEV_ETH4] = 33, [ASPEED_DEV_KCS] = 138, /* 138 -> 142 */ [ASPEED_DEV_DP] = 62, + [ASPEED_DEV_I3C] = 102, /* 102 -> 107 */ };static qemu_irq aspeed_soc_get_irq (AspeedSoCState *s,int ctrl)
@@ -223,6 +225,8 @@ static void aspeed_soc_ast2600_init(Object *obj)snprintf (typename,sizeof (typename),"aspeed.hace-%s" , socname);object_initialize_child (obj,"hace" , &s->hace, typename); + +object_initialize_child (obj,"i3c" , &s->i3c,TYPE_ASPEED_I3C ); }/*
@@ -523,6 +527,18 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->hace),0 , sc->memmap[ASPEED_DEV_HACE ]);sysbus_connect_irq (SYS_BUS_DEVICE (&s->hace),0 ,aspeed_soc_get_irq (s,ASPEED_DEV_HACE )); + +/* I3C */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->i3c), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->i3c),0 , sc->memmap[ASPEED_DEV_I3C ]); +for (i =0 ; i <ASPEED_I3C_NR_DEVICES ; i++) { +qemu_irq irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore), + sc->irqmap[ASPEED_DEV_I3C ] + i); +/* The AST2600 I3C controller has one IRQ per bus. */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->i3c.devices[i]),0 , irq); + } }static void aspeed_soc_ast2600_class_init (ObjectClass *oc,void *data)
Signature · 1 line
2.25.1
[PULL 35/38] hw/intc/arm_gicv3_its: Factor out "find address of table entry" code
In reply to Peter MaydellThe ITS has several tables which all share a similar format, described by the TableDesc struct: the guest may configure them to be a single-level table or a two-level table. Currently we open-code the process of finding the table entry in all the functions which read or write the device table or the collection table. Factor out the "get the address of the table entry" logic into a new function, so that the code which needs to read or write a table entry only needs to call table_entry_addr() and then perform a suitable load or store to that address.
Note that the error handling is slightly complicated because we want to handle two cases differently:
* failure to read the L1 table entry should end up causing a command stall, like other kinds of DMA error
* an L1 table entry that says there is no L2 table for this index (ie whose valid bit is 0) must result in us treating the table entry as not-valid on read, and discarding writes (this is mandated by the spec)
Message-id: [email protected]
--- hw/intc/arm_gicv3_its.c | 212 +++++++++++++--------------------------- 1 file changed, 70 insertions(+), 142 deletions(-)
hw/intc/arm_gicv3_its.c +70 -142
@@ -83,44 +83,62 @@ static uint64_t baser_base_addr(uint64_t value, uint32_t page_sz)return result; } +static uint64_t table_entry_addr (GICv3ITSState *s,TableDesc *td, +uint32_t idx,MemTxResult *res) +{ +/* +* Given a TableDesc describing one of the ITS in-guest-memory +* tables and an index into it, return the guest address +* corresponding to that table entry. +* If there was a memory error reading the L1 table of an +* indirect table, *res is set accordingly, and we return -1. +* If the L1 table entry is marked not valid, we return -1 with +* *res set to MEMTX_OK. +* +* The specification defines the format of level 1 entries of a +* 2-level table, but the format of level 2 entries and the format +* of flat-mapped tables is IMPDEF. +*/ +AddressSpace *as = &s->gicv3->dma_as; +uint32_t l2idx; +uint64_t l2; +uint32_t num_l2_entries; + + *res =MEMTX_OK ; + +if (!td->indirect) { +/* Single level table */ +return td->base_addr + idx * td->entry_sz; + } + +/* Two level table */ + l2idx = idx / (td->page_sz /L1TABLE_ENTRY_SIZE ); + + l2 =address_space_ldq_le (as, + td->base_addr + (l2idx *L1TABLE_ENTRY_SIZE ), +MEMTXATTRS_UNSPECIFIED , res); +if (*res !=MEMTX_OK ) { +return -1 ; + } +if (!(l2 &L2_TABLE_VALID_MASK )) { +return -1 ; + } + + num_l2_entries = td->page_sz / td->entry_sz; +return (l2 & ((1ULL <<51 ) -1 )) + (idx % num_l2_entries) * td->entry_sz; +} +static bool get_cte (GICv3ITSState *s,uint16_t icid,uint64_t *cte,MemTxResult *res) {AddressSpace *as = &s->gicv3->dma_as; -uint64_t l2t_addr; -uint64_t value; -bool valid_l2t; -uint32_t l2t_id; -uint32_t num_l2_entries; +uint64_t entry_addr =table_entry_addr (s, &s->ct, icid, res); -if (s->ct.indirect) { - l2t_id = icid / (s->ct.page_sz /L1TABLE_ENTRY_SIZE ); - - value =address_space_ldq_le (as, - s->ct.base_addr + - (l2t_id *L1TABLE_ENTRY_SIZE ), -MEMTXATTRS_UNSPECIFIED , res); - -if (*res ==MEMTX_OK ) { - valid_l2t = (value &L2_TABLE_VALID_MASK ) !=0 ; - -if (valid_l2t) { - num_l2_entries = s->ct.page_sz / s->ct.entry_sz; - - l2t_addr = value & ((1ULL <<51 ) -1 ); - - *cte =address_space_ldq_le (as, l2t_addr + - ((icid % num_l2_entries) *GITS_CTE_SIZE ), -MEMTXATTRS_UNSPECIFIED , res); - } - } - }else { -/* Flat level table */ - *cte =address_space_ldq_le (as, s->ct.base_addr + - (icid *GITS_CTE_SIZE ), -MEMTXATTRS_UNSPECIFIED , res); +if (entry_addr ==-1 ) { +return false;/* not valid */ } + *cte =address_space_ldq_le (as, entry_addr,MEMTXATTRS_UNSPECIFIED , res);return FIELD_EX64 (*cte,CTE ,VALID ); }
@@ -189,41 +207,12 @@ static bool get_ite(GICv3ITSState *s, uint32_t eventid, uint64_t dte,static uint64_t get_dte (GICv3ITSState *s,uint32_t devid,MemTxResult *res) {AddressSpace *as = &s->gicv3->dma_as; -uint64_t l2t_addr; -uint64_t value; -bool valid_l2t; -uint32_t l2t_id; -uint32_t num_l2_entries; +uint64_t entry_addr =table_entry_addr (s, &s->dt, devid, res); -if (s->dt.indirect) { - l2t_id = devid / (s->dt.page_sz /L1TABLE_ENTRY_SIZE ); - - value =address_space_ldq_le (as, - s->dt.base_addr + - (l2t_id *L1TABLE_ENTRY_SIZE ), -MEMTXATTRS_UNSPECIFIED , res); - -if (*res ==MEMTX_OK ) { - valid_l2t = (value &L2_TABLE_VALID_MASK ) !=0 ; - -if (valid_l2t) { - num_l2_entries = s->dt.page_sz / s->dt.entry_sz; - - l2t_addr = value & ((1ULL <<51 ) -1 ); - - value =address_space_ldq_le (as, l2t_addr + - ((devid % num_l2_entries) *GITS_DTE_SIZE ), -MEMTXATTRS_UNSPECIFIED , res); - } - } - }else { -/* Flat level table */ - value =address_space_ldq_le (as, s->dt.base_addr + - (devid *GITS_DTE_SIZE ), -MEMTXATTRS_UNSPECIFIED , res); +if (entry_addr ==-1 ) { +return 0 ;/* a DTE entry with the Valid bit clear */ } - -return value; +return address_space_ldq_le (as, entry_addr,MEMTXATTRS_UNSPECIFIED , res); }/*
@@ -426,11 +415,7 @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid, uint64_t rdbase) {AddressSpace *as = &s->gicv3->dma_as; -uint64_t value; -uint64_t l2t_addr; -bool valid_l2t; -uint32_t l2t_id; -uint32_t num_l2_entries; +uint64_t entry_addr;uint64_t cte =0 ;MemTxResult res =MEMTX_OK ;
@@ -444,44 +429,18 @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid, cte =FIELD_DP64 (cte,CTE ,RDBASE , rdbase); } -/* -* The specification defines the format of level 1 entries of a -* 2-level table, but the format of level 2 entries and the format -* of flat-mapped tables is IMPDEF. -*/ -if (s->ct.indirect) { - l2t_id = icid / (s->ct.page_sz /L1TABLE_ENTRY_SIZE ); - - value =address_space_ldq_le (as, - s->ct.base_addr + - (l2t_id *L1TABLE_ENTRY_SIZE ), -MEMTXATTRS_UNSPECIFIED , &res); - -if (res !=MEMTX_OK ) { -return false; - } - - valid_l2t = (value &L2_TABLE_VALID_MASK ) !=0 ; - -if (valid_l2t) { - num_l2_entries = s->ct.page_sz / s->ct.entry_sz; - - l2t_addr = value & ((1ULL <<51 ) -1 ); - -address_space_stq_le (as, l2t_addr + - ((icid % num_l2_entries) *GITS_CTE_SIZE ), - cte,MEMTXATTRS_UNSPECIFIED , &res); - } - }else { -/* Flat level table */ -address_space_stq_le (as, s->ct.base_addr + (icid *GITS_CTE_SIZE ), - cte,MEMTXATTRS_UNSPECIFIED , &res); - } + entry_addr =table_entry_addr (s, &s->ct, icid, &res);if (res !=MEMTX_OK ) { +/* memory access error: stall */ return false; - }else { + } +if (entry_addr ==-1 ) { +/* No L2 table for this index: discard write and continue */ return true; } + +address_space_stq_le (as, entry_addr, cte,MEMTXATTRS_UNSPECIFIED , &res); +return res ==MEMTX_OK ; }static ItsCmdResult process_mapc (GICv3ITSState *s,uint32_t offset)
@@ -529,11 +488,7 @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid, uint8_t size, uint64_t itt_addr) {AddressSpace *as = &s->gicv3->dma_as; -uint64_t value; -uint64_t l2t_addr; -bool valid_l2t; -uint32_t l2t_id; -uint32_t num_l2_entries; +uint64_t entry_addr;uint64_t dte =0 ;MemTxResult res =MEMTX_OK ;
@@ -548,44 +503,17 @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid,return true; } -/* -* The specification defines the format of level 1 entries of a -* 2-level table, but the format of level 2 entries and the format -* of flat-mapped tables is IMPDEF. -*/ -if (s->dt.indirect) { - l2t_id = devid / (s->dt.page_sz /L1TABLE_ENTRY_SIZE ); - - value =address_space_ldq_le (as, - s->dt.base_addr + - (l2t_id *L1TABLE_ENTRY_SIZE ), -MEMTXATTRS_UNSPECIFIED , &res); - -if (res !=MEMTX_OK ) { -return false; - } - - valid_l2t = (value &L2_TABLE_VALID_MASK ) !=0 ; - -if (valid_l2t) { - num_l2_entries = s->dt.page_sz / s->dt.entry_sz; - - l2t_addr = value & ((1ULL <<51 ) -1 ); - -address_space_stq_le (as, l2t_addr + - ((devid % num_l2_entries) *GITS_DTE_SIZE ), - dte,MEMTXATTRS_UNSPECIFIED , &res); - } - }else { -/* Flat level table */ -address_space_stq_le (as, s->dt.base_addr + (devid *GITS_DTE_SIZE ), - dte,MEMTXATTRS_UNSPECIFIED , &res); - } + entry_addr =table_entry_addr (s, &s->dt, devid, &res);if (res !=MEMTX_OK ) { +/* memory access error: stall */ return false; - }else { + } +if (entry_addr ==-1 ) { +/* No L2 table for this index: discard write and continue */ return true; } +address_space_stq_le (as, entry_addr, dte,MEMTXATTRS_UNSPECIFIED , &res); +return res ==MEMTX_OK ; } static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,
Signature · 1 line
2.25.1