xen: fix ram init regression
A message that is not in the archive (sent off-list or not yet received): [email protected]
From: Gerd Hoffmann <[email protected]>
Commit "8156d48 pc: allow raising low memory via max-ram-below-4g option" causes a regression on xen, because it uses a different memory split.
This patch initializes max-ram-below-4g to zero and leaves the initialization to the memory initialization functions. That way they can pick different default values (max-ram-below-4g is zero still) or use the user supplied value (max-ram-below-4g is non-zero).
Also skip the whole ram split calculation on Xen. xen_ram_init() does its own split calculation anyway so it is superfluous, also this way xen_ram_init can actually see whenever max-ram-below-4g is zero or not.
--- hw/i386/pc.c | 2 +- hw/i386/pc_piix.c | 50 ++++++++++++++++++++++++++++---------------------- hw/i386/pc_q35.c | 3 +++ xen-hvm.c | 3 +++ 4 files changed, 35 insertions(+), 23 deletions(-)
hw/i386/pc.c +1 -1
@@ -1919,7 +1919,7 @@ static void pc_machine_initfn(Object *obj) pc_machine_get_hotplug_memory_region_size, NULL, NULL, NULL, &error_abort); - pcms->max_ram_below_4g =0xe0000000 ;/* 3.5G */ + pcms->max_ram_below_4g =0 ;/* use default */ object_property_add(obj, PC_MACHINE_MAX_RAM_BELOW_4G, "size", pc_machine_get_max_ram_below_4g, pc_machine_set_max_ram_below_4g,
hw/i386/pc_piix.c +28 -22
65 lines not on this page · raw message
hw/i386/pc_q35.c +3 -0
@@ -94,6 +94,9 @@ static void pc_q35_init(MachineState *machine)/* Handle the machine opt max-ram-below-4g. It is basically doing * min(qemu limit, user limit). */ +if (!pcms->max_ram_below_4g) { + pcms->max_ram_below_4g =1ULL <<32 ;/* default: 4G */ ; + }if (lowmem > pcms->max_ram_below_4g) { lowmem = pcms->max_ram_below_4g; if (machine->ram_size - lowmem > lowmem &&
xen-hvm.c +3 -0
@@ -190,6 +190,9 @@ static void xen_ram_init(PCMachineState *pcms,/* Handle the machine opt max-ram-below-4g. It is basically doing * min(xen limit, user limit). */ +if (!user_lowmem) { + user_lowmem =HVM_BELOW_4G_RAM_END ;/* default */ + }if (HVM_BELOW_4G_RAM_END <= user_lowmem) { user_lowmem =HVM_BELOW_4G_RAM_END ; }
Signature · 7 lines
MST _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
[Qemu-devel] [PULL 02/36] hw/ppc: realize the PCI root bus as part of mac99 init
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
Mac99's PCI root bus is not part of a host bridge, realize it manually.
--- hw/ppc/mac_newworld.c | 1 + 1 file changed, 1 insertion(+)
hw/ppc/mac_newworld.c +1 -0
@@ -380,6 +380,7 @@ static void ppc_core99_init(MachineState *machine) pci_bus =pci_pmac_init (pic,get_system_memory (),get_system_io ()); machine_arch =ARCH_MAC99 ; } +object_property_set_bool (OBJECT (pci_bus), true,"realized" , &error_abort); machine->usb |=defaults_enabled () && !machine->usb_disabled;
Signature · 1 line
MST
[Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
Skip bus_master_enable region creation on PCI device init in order to be sure the IOMMU device (if present) would be created in advance. Add this memory region at machine_done time.
--- include/hw/pci/pci_bus.h | 2 ++ include/sysemu/sysemu.h | 1 + hw/pci/pci.c | 41 ++++++++++++++++++++++++++++++++--------- vl.c | 5 +++++ 4 files changed, 40 insertions(+), 9 deletions(-)
include/hw/pci/pci_bus.h +2 -0
@@ -39,6 +39,8 @@ struct PCIBus {Keep a count of the number of devices with raised IRQs. */ int nirq;int *irq_count; + +Notifier machine_done; };typedef struct PCIBridgeWindows PCIBridgeWindows ;
include/sysemu/sysemu.h +1 -0
@@ -75,6 +75,7 @@ void qemu_add_exit_notifier(Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);void qemu_add_machine_init_done_notifier (Notifier *notify); +void qemu_remove_machine_init_done_notifier (Notifier *notify);void hmp_savevm (Monitor *mon,const QDict *qdict);int load_vmstate (const char *name);
hw/pci/pci.c +32 -9
70 lines not on this page · raw message
vl.c +5 -0
@@ -2675,6 +2675,11 @@ void qemu_add_machine_init_done_notifier(Notifier *notify) } } +void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +notifier_remove (notify); +} +static void qemu_run_machine_init_done_notifiers (void ) {notifier_list_notify (&machine_init_done_notifiers,NULL );
Signature · 1 line
MST
Re: [Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization
Quoted 126 lines · Michael S. Tsirkin
From: Marcel Apfelbaum <[email protected]>
Skip
bus_master_enableregion creation on PCI device init in order to be sure the IOMMU device (if present) would be created in advance. Add this memory region atmachine_donetime.Signed-off-by Marcel Apfelbaum <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ include/sysemu/sysemu.h | 1 + hw/pci/pci.c | 41 ++++++++++++++++++++++++++++++++--------- vl.c | 5 +++++ 4 files changed, 40 insertions(+), 9 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -39,6 +39,8 @@ struct PCIBus {Keep a count of the number of devices with raised IRQs. */ int nirq;int *irq_count; + +Notifier machine_done; };typedef struct PCIBridgeWindows PCIBridgeWindows ;include/sysemu/sysemu.h +1
-0@@ -75,6 +75,7 @@ void qemu_add_exit_notifier(Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);void qemu_add_machine_init_done_notifier (Notifier *notify); +void qemu_remove_machine_init_done_notifier (Notifier *notify);void hmp_savevm (Monitor *mon,const QDict *qdict);int load_vmstate (const char *name);hw/pci/pci.c +32
-9@@ -78,10 +78,37 @@ static const VMStateDescription vmstate_pcibus = { } }; +static void pci_init_bus_master (PCIDevice *pci_dev) +{ +AddressSpace *dma_as =pci_device_iommu_address_space (pci_dev); + +memory_region_init_alias (&pci_dev->bus_master_enable_region, +OBJECT (pci_dev),"bus master" , + dma_as->root,0 ,memory_region_size (dma_as->root)); +memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); +address_space_init (&pci_dev->bus_master_as, + &pci_dev->bus_master_enable_region, pci_dev->name); +} + +static void pcibus_machine_done (Notifier *notifier,void *data) +{ +PCIBus *bus =container_of (notifier, PCIBus, machine_done); +int i; + +for (i =0 ; i <ARRAY_SIZE (bus->devices); ++i) { +if (bus->devices[i]) { +pci_init_bus_master (bus->devices[i]); + } + } +} +static void pci_bus_realize (BusState *qbus,Error **errp) {PCIBus *bus =PCI_BUS (qbus); + bus->machine_done.notify = pcibus_machine_done; +qemu_add_machine_init_done_notifier (&bus->machine_done); +vmstate_register (NULL ,-1 , &vmstate_pcibus, bus); }@@ -89,6 +116,8 @@ static void pci_bus_unrealize(BusState *qbus, Error **errp) {PCIBus *bus =PCI_BUS (qbus); +qemu_remove_machine_init_done_notifier (&bus->machine_done); +vmstate_unregister (NULL , &vmstate_pcibus, bus); }@@ -920,7 +949,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,PCIConfigReadFunc *config_read = pc->config_read;PCIConfigWriteFunc *config_write = pc->config_write;Error *local_err =NULL ; -AddressSpace *dma_as;DeviceState *dev =DEVICE (pci_dev); pci_dev->bus = bus;@@ -961,15 +989,10 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, pci_dev->devfn = devfn; pci_dev->requester_id_cache =pci_req_id_cache_get (pci_dev); - dma_as =pci_device_iommu_address_space (pci_dev); - -memory_region_init_alias (&pci_dev->bus_master_enable_region, -OBJECT (pci_dev),"bus master" , - dma_as->root,0 ,memory_region_size (dma_as->root)); -memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); -address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region, - name); +if (qdev_hotplug) { +pci_init_bus_master (pci_dev); + }pstrcpy (pci_dev->name,sizeof (pci_dev->name), name); pci_dev->irq_state =0 ;pci_config_alloc (pci_dev);vl.c +0
-0@@ -2675,6 +2675,11 @@ void qemu_add_machine_init_done_notifier(Notifier *notify) }
vl.c void qemu_add_machine_init_done_notifier(Notifier *notify) · line 2685
Quoted 10 lines
vl.c +5
-0} +void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +notifier_remove (notify); +} +static void qemu_run_machine_init_done_notifiers (void ) {notifier_list_notify (&machine_init_done_notifiers,NULL );
Unfortunately this patch causes a regression booting my Debian 7.8.0 and NetBSD 7.0 test images under qemu-system-sparc64 when accessing the CDROM device, and rather unusually causes the qemu-system-sparc64 executable itself to segfault:
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffe8453700 (LWP 21454)] 0x000000000041494a in address_space_lookup_region (d=0x0, addr=3221225472, resolve_subpage=true) at /home/build/src/qemu/git/qemu/exec.c:359
359 MemoryRegionSection *section = atomic_read(&d->mru_section);
(gdb) bt
#0 0x000000000041494a in address_space_lookup_region (d=0x0, addr=3221225472, resolve_subpage=true) at /home/build/src/qemu/git/qemu/exec.c:359
#1 0x0000000000414aa7 in address_space_translate_internal (d=0x0, addr=3221225472, xlat=0x7fffe8451c40, plen=0x7fffe8451d10, resolve_subpage=true) at /home/build/src/qemu/git/qemu/exec.c:390 #2 0x0000000000414c8f in address_space_translate (as=0x1961600, addr=3221225472, xlat=0x7fffe8451d18, plen=0x7fffe8451d10, is_write=false) at /home/build/src/qemu/git/qemu/exec.c:428 #3 0x000000000041a4be in address_space_read_full (as=0x1961600, addr=3221225472, attrs=..., buf=0x7fffe8451f10 "\030(\226\001", len=8) at /home/build/src/qemu/git/qemu/exec.c:2724
#4 0x000000000041a5b3 in address_space_read (len=8, buf=0x7fffe8451f10 "\030(\226\001", attrs=..., addr=3221225472, as=0x1961600) at /home/build/src/qemu/git/qemu/include/exec/memory.h:1460
#5 address_space_rw (as=0x1961600, addr=3221225472, attrs=..., buf=0x7fffe8451f10 "\030(\226\001", len=8, is_write=false) at /home/build/src/qemu/git/qemu/exec.c:2739
#6 0x00000000005c71e0 in dma_memory_rw_relaxed (as=0x1961600, addr=3221225472, buf=0x7fffe8451f10, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /home/build/src/qemu/git/qemu/include/sysemu/dma.h:87
#7 0x00000000005c7258 in dma_memory_rw (as=0x1961600, addr=3221225472, buf=0x7fffe8451f10, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /home/build/src/qemu/git/qemu/include/sysemu/dma.h:110
#8 0x00000000005c72fa in pci_dma_rw (dev=0x19613f0, addr=3221225472, buf=0x7fffe8451f10, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /home/build/src/qemu/git/qemu/include/hw/pci/pci.h:731
#9 0x00000000005c735a in pci_dma_read (dev=0x19613f0, addr=3221225472, buf=0x7fffe8451f10, len=8) at /home/build/src/qemu/git/qemu/include/hw/pci/pci.h:738
#10 0x00000000005c7980 in bmdma_rw_buf (dma=0x1962fa8, is_write=1) at hw/ide/pci.c:139
#11 0x00000000005c4372 in ide_atapi_cmd_read_dma_cb (opaque=0x1962550, ret=0) at hw/ide/atapi.c:413
#12 0x00000000005c7dfe in bmdma_cmd_writeb (bm=0x1962fa8, val=9) at hw/ide/pci.c:245
#13 0x00000000005c91a9 in bmdma_write (opaque=0x1962fa8, addr=0, val=9, size=1) at hw/ide/cmd646.c:219
#14 0x0000000000469fb8 in memory_region_write_accessor (mr=0x1963100, addr=0, value=0x7fffe8452148, size=1, shift=0, mask=255, attrs=...) at /home/build/src/qemu/git/qemu/memory.c:525
#15 0x000000000046a1e4 in access_with_adjusted_size (addr=0, value=0x7fffe8452148, size=1, access_size_min=1, access_size_max=4, access=0x469ec1 <memory_region_write_accessor>, mr=0x1963100, attrs=...)
at /home/build/src/qemu/git/qemu/memory.c:586
#16 0x000000000046d42b in memory_region_dispatch_write (mr=0x1963100, addr=0, data=9, size=1, attrs=...) at /home/build/src/qemu/git/qemu/memory.c:1262
#17 0x000000000041a051 in address_space_write_continue (as=0x12bb4b0, addr=2190466908936, attrs=..., buf=0x7fffe8452323 "\t\376\001", len=1, addr1=0, l=1, mr=0x1963100) at /home/build/src/qemu/git/qemu/exec.c:2590 #18 0x000000000041a1c3 in address_space_write (as=0x12bb4b0, addr=2190466908936, attrs=..., buf=0x7fffe8452323 "\t\376\001", len=1) at /home/build/src/qemu/git/qemu/exec.c:2635
#19 0x000000000041a569 in address_space_rw (as=0x12bb4b0, addr=2190466908936, attrs=..., buf=0x7fffe8452323 "\t\376\001", len=1, is_write=true) at /home/build/src/qemu/git/qemu/exec.c:2737 #20 0x000000000041c27d in address_space_stb (as=0x12bb4b0, addr=2190466908936, val=9, attrs=..., result=0x0) at /home/build/src/qemu/git/qemu/exec.c:3477
#21 0x000000000041c2f5 in stb_phys (as=0x12bb4b0, addr=2190466908936, val=9) at /home/build/src/qemu/git/qemu/exec.c:3485
#22 0x0000000000504759 in helper_st_asi (env=0x12d57e8, addr=2190466908936, val=9, asi=29, size=1) at /home/build/src/qemu/git/qemu/target-sparc/ldst_helper.c:1801 #23 0x00000000405bf4b0 in code_gen_buffer ()
#24 0x0000000000420c97 in cpu_tb_exec (cpu=0x12cd570, itb=0x7fffe8fc10c0) at /home/build/src/qemu/git/qemu/cpu-exec.c:166 #25 0x0000000000421882 in cpu_loop_exec_tb (cpu=0x12cd570, tb=0x7fffe8fc10c0, last_tb=0x7fffe8452988, tb_exit=0x7fffe8452984, sc=0x7fffe84529a0) at /home/build/src/qemu/git/qemu/cpu-exec.c:530 #26 0x0000000000421b40 in cpu_exec (cpu=0x12cd570) at /home/build/src/qemu/git/qemu/cpu-exec.c:626
#27 0x0000000000451e6b in tcg_cpu_exec (cpu=0x12cd570) at /home/build/src/qemu/git/qemu/cpus.c:1541
#28 0x0000000000451f6d in tcg_exec_all () at /home/build/src/qemu/git/qemu/cpus.c:1574
#29 0x00000000004510b4 in qemu_tcg_cpu_thread_fn (arg=0x12cd570) at /home/build/src/qemu/git/qemu/cpus.c:1171
#30 0x00007ffff264bb50 in start_thread (arg=<optimized out>) at pthread_create.c:304
#31 0x00007ffff2395fbd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#32 0x0000000000000000 in ?? ()
(gdb)
ATB,
Mark.
Re: [Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization
Quoted 129 lines · Mark Cave-Ayland
Quoted 127 lines · Michael S. Tsirkin
From: Marcel Apfelbaum <[email protected]>
Skip
bus_master_enableregion creation on PCI device init in order to be sure the IOMMU device (if present) would be created in advance. Add this memory region atmachine_donetime.Signed-off-by Marcel Apfelbaum <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ include/sysemu/sysemu.h | 1 + hw/pci/pci.c | 41 ++++++++++++++++++++++++++++++++--------- vl.c | 5 +++++ 4 files changed, 40 insertions(+), 9 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -39,6 +39,8 @@ struct PCIBus {Keep a count of the number of devices with raised IRQs. */ int nirq;int *irq_count; + +Notifier machine_done; };typedef struct PCIBridgeWindows PCIBridgeWindows ;include/sysemu/sysemu.h +1
-0@@ -75,6 +75,7 @@ void qemu_add_exit_notifier(Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);void qemu_add_machine_init_done_notifier (Notifier *notify); +void qemu_remove_machine_init_done_notifier (Notifier *notify);void hmp_savevm (Monitor *mon,const QDict *qdict);int load_vmstate (const char *name);hw/pci/pci.c +32
-9@@ -78,10 +78,37 @@ static const VMStateDescription vmstate_pcibus = { } }; +static void pci_init_bus_master (PCIDevice *pci_dev) +{ +AddressSpace *dma_as =pci_device_iommu_address_space (pci_dev); + +memory_region_init_alias (&pci_dev->bus_master_enable_region, +OBJECT (pci_dev),"bus master" , + dma_as->root,0 ,memory_region_size (dma_as->root)); +memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); +address_space_init (&pci_dev->bus_master_as, + &pci_dev->bus_master_enable_region, pci_dev->name); +} + +static void pcibus_machine_done (Notifier *notifier,void *data) +{ +PCIBus *bus =container_of (notifier, PCIBus, machine_done); +int i; + +for (i =0 ; i <ARRAY_SIZE (bus->devices); ++i) { +if (bus->devices[i]) { +pci_init_bus_master (bus->devices[i]); + } + } +} +static void pci_bus_realize (BusState *qbus,Error **errp) {PCIBus *bus =PCI_BUS (qbus); + bus->machine_done.notify = pcibus_machine_done; +qemu_add_machine_init_done_notifier (&bus->machine_done); +vmstate_register (NULL ,-1 , &vmstate_pcibus, bus); }@@ -89,6 +116,8 @@ static void pci_bus_unrealize(BusState *qbus, Error **errp) {PCIBus *bus =PCI_BUS (qbus); +qemu_remove_machine_init_done_notifier (&bus->machine_done); +vmstate_unregister (NULL , &vmstate_pcibus, bus); }@@ -920,7 +949,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,PCIConfigReadFunc *config_read = pc->config_read;PCIConfigWriteFunc *config_write = pc->config_write;Error *local_err =NULL ; -AddressSpace *dma_as;DeviceState *dev =DEVICE (pci_dev); pci_dev->bus = bus;@@ -961,15 +989,10 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, pci_dev->devfn = devfn; pci_dev->requester_id_cache =pci_req_id_cache_get (pci_dev); - dma_as =pci_device_iommu_address_space (pci_dev); - -memory_region_init_alias (&pci_dev->bus_master_enable_region, -OBJECT (pci_dev),"bus master" , - dma_as->root,0 ,memory_region_size (dma_as->root)); -memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); -address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region, - name); +if (qdev_hotplug) { +pci_init_bus_master (pci_dev); + }pstrcpy (pci_dev->name,sizeof (pci_dev->name), name); pci_dev->irq_state =0 ;pci_config_alloc (pci_dev);vl.c +0
-0@@ -2675,6 +2675,11 @@ void qemu_add_machine_init_done_notifier(Notifier *notify) } }
Quoted 15 lines
vl.c void qemu_add_machine_init_done_notifier(Notifier *notify) · line 2685
Quoted 9 lines
vl.c +5
-0+void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +notifier_remove (notify); +} +static void qemu_run_machine_init_done_notifiers (void ) {notifier_list_notify (&machine_init_done_notifiers,NULL );Unfortunately this patch causes a regression booting my Debian 7.8.0 and NetBSD 7.0 test images under qemu-system-sparc64 when accessing the CDROM device, and rather unusually causes the qemu-system-sparc64 executable itself to segfault:
Hi Mark,
Thank you for finding it, can you please provide a command line and maybe one of your test images? I'll be sure to address it.
Thanks,
Marcel
Quoted 100 lines
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread
0x7fffe8453700(LWP 21454)]0x000000000041494ainaddress_space_lookup_region(d=0x0, addr=3221225472, resolve_subpage=true) at/home/build/src/qemu/git/qemu/exec.c:359
359 MemoryRegionSection *section =atomic_read(&d->mru_section);
(gdb) bt
#00x000000000041494ainaddress_space_lookup_region(d=0x0, addr=3221225472, resolve_subpage=true) at/home/build/src/qemu/git/qemu/exec.c:359
#10x0000000000414aa7inaddress_space_translate_internal(d=0x0, addr=3221225472, xlat=0x7fffe8451c40, plen=0x7fffe8451d10, resolve_subpage=true) at/home/build/src/qemu/git/qemu/exec.c:390#20x0000000000414c8finaddress_space_translate(as=0x1961600, addr=3221225472, xlat=0x7fffe8451d18, plen=0x7fffe8451d10, is_write=false) at/home/build/src/qemu/git/qemu/exec.c:428#30x000000000041a4beinaddress_space_read_full(as=0x1961600, addr=3221225472, attrs=..., buf=0x7fffe8451f10 "\030(\226\001", len=8) at/home/build/src/qemu/git/qemu/exec.c:2724
#40x000000000041a5b3inaddress_space_read(len=8, buf=0x7fffe8451f10 "\030(\226\001", attrs=..., addr=3221225472, as=0x1961600) at/home/build/src/qemu/git/qemu/include/exec/memory.h:1460
#5address_space_rw(as=0x1961600, addr=3221225472, attrs=..., buf=0x7fffe8451f10 "\030(\226\001", len=8, is_write=false) at/home/build/src/qemu/git/qemu/exec.c:2739
#60x00000000005c71e0indma_memory_rw_relaxed(as=0x1961600, addr=3221225472, buf=0x7fffe8451f10, len=8, dir=DMA_DIRECTION_TO_DEVICE) at/home/build/src/qemu/git/qemu/include/sysemu/dma.h:87
#70x00000000005c7258indma_memory_rw(as=0x1961600, addr=3221225472, buf=0x7fffe8451f10, len=8, dir=DMA_DIRECTION_TO_DEVICE) at/home/build/src/qemu/git/qemu/include/sysemu/dma.h:110
#80x00000000005c72fainpci_dma_rw(dev=0x19613f0, addr=3221225472, buf=0x7fffe8451f10, len=8, dir=DMA_DIRECTION_TO_DEVICE) at/home/build/src/qemu/git/qemu/include/hw/pci/pci.h:731
#90x00000000005c735ainpci_dma_read(dev=0x19613f0, addr=3221225472, buf=0x7fffe8451f10, len=8) at/home/build/src/qemu/git/qemu/include/hw/pci/pci.h:738
#100x00000000005c7980inbmdma_rw_buf(dma=0x1962fa8, is_write=1) athw/ide/pci.c:139
#110x00000000005c4372inide_atapi_cmd_read_dma_cb(opaque=0x1962550, ret=0) athw/ide/atapi.c:413
#120x00000000005c7dfeinbmdma_cmd_writeb(bm=0x1962fa8, val=9) athw/ide/pci.c:245
#130x00000000005c91a9inbmdma_write(opaque=0x1962fa8, addr=0, val=9, size=1) athw/ide/cmd646.c:219
#140x0000000000469fb8inmemory_region_write_accessor(mr=0x1963100, addr=0, value=0x7fffe8452148, size=1, shift=0, mask=255, attrs=...) at/home/build/src/qemu/git/qemu/memory.c:525
#150x000000000046a1e4inaccess_with_adjusted_size(addr=0, value=0x7fffe8452148, size=1, access_size_min=1, access_size_max=4, access=0x469ec1 <memory_region_write_accessor>, mr=0x1963100, attrs=...)at /home/build/src/qemu/git/qemu/memory.c:586#16
0x000000000046d42binmemory_region_dispatch_write(mr=0x1963100, addr=0, data=9, size=1, attrs=...) at/home/build/src/qemu/git/qemu/memory.c:1262
#170x000000000041a051inaddress_space_write_continue(as=0x12bb4b0, addr=2190466908936, attrs=..., buf=0x7fffe8452323 "\t\376\001", len=1, addr1=0, l=1, mr=0x1963100) at/home/build/src/qemu/git/qemu/exec.c:2590#180x000000000041a1c3inaddress_space_write(as=0x12bb4b0, addr=2190466908936, attrs=..., buf=0x7fffe8452323 "\t\376\001", len=1) at/home/build/src/qemu/git/qemu/exec.c:2635
#190x000000000041a569inaddress_space_rw(as=0x12bb4b0, addr=2190466908936, attrs=..., buf=0x7fffe8452323 "\t\376\001", len=1, is_write=true) at/home/build/src/qemu/git/qemu/exec.c:2737#200x000000000041c27dinaddress_space_stb(as=0x12bb4b0, addr=2190466908936, val=9, attrs=..., result=0x0) at/home/build/src/qemu/git/qemu/exec.c:3477
#210x000000000041c2f5instb_phys(as=0x12bb4b0, addr=2190466908936, val=9) at/home/build/src/qemu/git/qemu/exec.c:3485
#220x0000000000504759inhelper_st_asi(env=0x12d57e8, addr=2190466908936, val=9, asi=29, size=1) at/home/build/src/qemu/git/qemu/target-sparc/ldst_helper.c:1801#230x00000000405bf4b0incode_gen_buffer()
#240x0000000000420c97incpu_tb_exec(cpu=0x12cd570, itb=0x7fffe8fc10c0) at/home/build/src/qemu/git/qemu/cpu-exec.c:166#250x0000000000421882incpu_loop_exec_tb(cpu=0x12cd570, tb=0x7fffe8fc10c0, last_tb=0x7fffe8452988, tb_exit=0x7fffe8452984, sc=0x7fffe84529a0) at/home/build/src/qemu/git/qemu/cpu-exec.c:530#260x0000000000421b40incpu_exec(cpu=0x12cd570) at/home/build/src/qemu/git/qemu/cpu-exec.c:626
#270x0000000000451e6bintcg_cpu_exec(cpu=0x12cd570) at/home/build/src/qemu/git/qemu/cpus.c:1541
#280x0000000000451f6dintcg_exec_all() at/home/build/src/qemu/git/qemu/cpus.c:1574
#290x00000000004510b4inqemu_tcg_cpu_thread_fn(arg=0x12cd570) at/home/build/src/qemu/git/qemu/cpus.c:1171
#300x00007ffff264bb50instart_thread(arg=<optimized out>) at pthread_create.c:304
#310x00007ffff2395fbdin clone () at../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#320x0000000000000000in ?? ()
(gdb)ATB,
Mark.
Re: [Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization
Quoted 157 lines · Marcel Apfelbaum
Quoted 140 lines · Mark Cave-Ayland
Quoted 138 lines · Michael S. Tsirkin
From: Marcel Apfelbaum <[email protected]>
Skip
bus_master_enableregion creation on PCI device init in order to be sure the IOMMU device (if present) would be created in advance. Add this memory region atmachine_donetime.Signed-off-by Marcel Apfelbaum <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ include/sysemu/sysemu.h | 1 + hw/pci/pci.c | 41 ++++++++++++++++++++++++++++++++--------- vl.c | 5 +++++ 4 files changed, 40 insertions(+), 9 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -39,6 +39,8 @@ struct PCIBus {Keep a count of the number of devices with raised IRQs. */ int nirq;int *irq_count; + +Notifier machine_done; };typedef struct PCIBridgeWindows PCIBridgeWindows ;include/sysemu/sysemu.h +1
-0@@ -75,6 +75,7 @@ void qemu_add_exit_notifier(Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);void qemu_add_machine_init_done_notifier (Notifier *notify); +void qemu_remove_machine_init_done_notifier (Notifier *notify);void hmp_savevm (Monitor *mon,const QDict *qdict);int load_vmstate (const char *name);hw/pci/pci.c +27
-0@@ -78,10 +78,37 @@ static const VMStateDescription vmstate_pcibus = { } }; +static void pci_init_bus_master (PCIDevice *pci_dev) +{ +AddressSpace *dma_as =pci_device_iommu_address_space (pci_dev); + +memory_region_init_alias (&pci_dev->bus_master_enable_region, +OBJECT (pci_dev),"bus master" , + dma_as->root,0 ,memory_region_size (dma_as->root)); +memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); +address_space_init (&pci_dev->bus_master_as, + &pci_dev->bus_master_enable_region, pci_dev->name); +} + +static void pcibus_machine_done (Notifier *notifier,void *data) +{ +PCIBus *bus =container_of (notifier, PCIBus, machine_done); +int i; + +for (i =0 ; i <ARRAY_SIZE (bus->devices); ++i) { +if (bus->devices[i]) { +pci_init_bus_master (bus->devices[i]); + } + } +} +static void pci_bus_realize (BusState *qbus,Error **errp) {PCIBus *bus =PCI_BUS (qbus); + bus->machine_done.notify = pcibus_machine_done; +qemu_add_machine_init_done_notifier (&bus->machine_done); +vmstate_register(NULL, -1, &vmstate_pcibus, bus);}
hw/pci/pci.c +2
-1@@ -89,6 +116,8 @@ static void pci_bus_unrealize(BusState *qbus, Error **errp) {PCIBus *bus =PCI_BUS (qbus); +qemu_remove_machine_init_done_notifier (&bus->machine_done); +vmstate_unregister (NULL , &vmstate_pcibus, bus); }@@ -920,7 +949,6 @@ static PCIDevice *do_pci_register_device (PCIDevice *pci_dev, PCIBus *bus, PCIConfigReadFunc *config_read = pc->config_read;PCIConfigWriteFunc *config_write = pc->config_write;Error *local_err =NULL ; -AddressSpace *dma_as;DeviceState *dev =DEVICE (pci_dev);pci_dev->bus = bus;hw/pci/pci.c +3
-8@@ -961,15 +989,10 @@ static PCIDevice *do_pci_register_device (PCIDevice *pci_dev, PCIBus *bus, pci_dev->devfn = devfn; pci_dev->requester_id_cache =pci_req_id_cache_get (pci_dev); - dma_as =pci_device_iommu_address_space (pci_dev); - -memory_region_init_alias (&pci_dev->bus_master_enable_region, -OBJECT (pci_dev),"bus master" , - dma_as->root,0 , memory_region_size(dma_as->root)); -memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); -address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region, - name); + if (qdev_hotplug) { +pci_init_bus_master (pci_dev); + }pstrcpy (pci_dev->name,sizeof (pci_dev->name), name); pci_dev->irq_state =0 ;pci_config_alloc (pci_dev);vl.c +0
-0@@ -2675,6 +2675,11 @@ void qemu_add_machine_init_done_notifier(Notifier *notify) } }Quoted 15 lines
Quoted 9 lines
vl.c +5
-0+void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +notifier_remove (notify); +} +static void qemu_run_machine_init_done_notifiers (void ) {notifier_list_notify(&machine_init_done_notifiers, NULL);Unfortunately this patch causes a regression booting my Debian 7.8.0 and NetBSD 7.0 test images under qemu-system-sparc64 when accessing the CDROM device, and rather unusually causes the qemu-system-sparc64 executable itself to segfault:
Quoted 7 lines
Hi Mark,
Thank you for finding it, can you please provide a command line and maybe one of your test images?
I'll be sure to address it.Thanks,
Marcel
Hi Marcel,
The failure was easy to reproduce with my NetBSD 7.0 image using the following command line:
./qemu-system-sparc64 -cdrom NetBSD-7.0-sparc64.iso -boot d -nographic
The segfault occurs just after the CDROM is accessed.
Many thanks,
Mark.
Re: [Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization
In reply to Michael S. TsirkinHi,
This commit causes regressions in my MIPS tests. QEMU segfaults when booting Linux on Malta board; this can be easily reproduced with Aurelien's Debian images:
wget https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-5kc-malta
wget https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2
qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0" -nographic
...
[ 1.468000] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100 [ 1.476000] ata1.00: ATA-7: QEMU HARDDISK, 2.5+, max UDMA/100 [ 1.476000] ata1.00: 52428800 sectors, multi 16: LBA48 [ 1.480000] ata2.00: configured for UDMA/33 [ 1.484000] ata1.00: configured for UDMA/33 [ 1.536000] scsi 0:0:0:0: Direct-Access ATA QEMU HARDDISK 2.5+ PQ: 0 ANSI: 5 [ 1.552000] sd 0:0:0:0: [sda] 52428800 512-byte logical blocks: (26.8 GB/25.0 GiB) [ 1.568000] scsi 1:0:0:0: CD-ROM QEMU QEMU DVD-ROM 2.5+ PQ: 0 ANSI: 5 [ 1.576000] sd 0:0:0:0: [sda] Write Protect is off [ 1.580000] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffec79e700 (LWP 29679)]0x00007ffff792f806 in address_space_lookup_region (d=0x0, addr=12582912, resolve_subpage=true) at /user/lea/dev/qemu/exec.c:359
359 MemoryRegionSection *section = atomic_read(&d->mru_section);
(gdb) bt
#0 0x00007ffff792f806 in address_space_lookup_region (d=0x0, addr=12582912, resolve_subpage=true) at /user/lea/dev/qemu/exec.c:359 #1 0x00007ffff792f95e in address_space_translate_internal (d=0x0, addr=12582912, xlat=0x7fffec79ca30, plen=0x7fffec79cb18, resolve_subpage=true) at /user/lea/dev/qemu/exec.c:390 #2 0x00007ffff792fb5a in address_space_translate (as=0x7ffff8bc1ef0, addr=12582912, xlat=0x7fffec79cb10, plen=0x7fffec79cb18, is_write=false) at /user/lea/dev/qemu/exec.c:428 #3 0x00007ffff7935720 in address_space_read_full (as=0x7ffff8bc1ef0, addr=12582912, attrs=..., buf=0x7fffec79cd60 "\260^\324\370", <incomplete sequence \330>, len=8) at /user/lea/dev/qemu/exec.c:2724 #4 0x00007ffff7935821 in address_space_read (as=0x7ffff8bc1ef0, addr=12582912, attrs=..., buf=0x7fffec79cd60 "\260^\324\370", <incomplete sequence \330>, len=8, is_write=false) at /user/lea/dev/qemu/include/exec/memory.h:1476 #5 address_space_rw (as=0x7ffff8bc1ef0, addr=12582912, attrs=..., buf=0x7fffec79cd60 "\260^\324\370", <incomplete sequence \330>, len=8, is_write=false) at /user/lea/dev/qemu/exec.c:2739 #6 0x00007ffff7baf9a7 in dma_memory_rw_relaxed (as=0x7ffff8bc1ef0, addr=12582912, buf=0x7fffec79cd60, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /user/lea/dev/qemu/include/sysemu/dma.h:87 #7 0x00007ffff7bafa28 in dma_memory_rw (as=0x7ffff8bc1ef0, addr=12582912, buf=0x7fffec79cd60, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /user/lea/dev/qemu/include/sysemu/dma.h:110 #8 0x00007ffff7bafad3 in pci_dma_rw (dev=0x7ffff8bc1ce0, addr=12582912, buf=0x7fffec79cd60, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /user/lea/dev/qemu/include/hw/pci/pci.h:731 #9 0x00007ffff7bafb3c in pci_dma_read (dev=0x7ffff8bc1ce0, addr=12582912, buf=0x7fffec79cd60, len=8) at /user/lea/dev/qemu/include/hw/pci/pci.h:738
#10 0x00007ffff7baff6d in bmdma_prepare_buf (dma=0x7ffff8bc3620, limit=4096) at /user/lea/dev/qemu/hw/ide/pci.c:85
#11 0x00007ffff7ba66bc in ide_dma_cb (opaque=0x7ffff8bc25e8, ret=0) at /user/lea/dev/qemu/hw/ide/core.c:844
#12 0x00007ffff7bb0615 in bmdma_cmd_writeb (bm=0x7ffff8bc3620, val=9) at /user/lea/dev/qemu/hw/ide/pci.c:245
#13 0x00007ffff7bb1408 in bmdma_write (opaque=0x7ffff8bc3620, addr=0, val=9, size=1) at /user/lea/dev/qemu/hw/ide/piix.c:77
#14 0x00007ffff7988548 in memory_region_write_accessor (mr=0x7ffff8bc3778, addr=0, value=0x7fffec79cfd8, size=1, shift=0, mask=255, attrs=...) at /user/lea/dev/qemu/memory.c:525
#15 0x00007ffff79887dd in access_with_adjusted_size (addr=0, value=0x7fffec79cfd8, size=1, access_size_min=1, access_size_max=4, access=0x7ffff798843e <memory_region_write_accessor>, mr=0x7ffff8bc3778, attrs=...) at /user/lea/dev/qemu/memory.c:591 #16 0x00007ffff798bc6e in memory_region_dispatch_write (mr=0x7ffff8bc3778, addr=0, data=9, size=1, attrs=...) at /user/lea/dev/qemu/memory.c:1262
#17 0x00007ffff7935294 in address_space_write_continue (as=0x7ffff8921a90, addr=402657344, attrs=..., buf=0x7fffec79d170 "\t\345y\354\377\177", len=1, addr1=0, l=1, mr=0x7ffff8bc3778) at /user/lea/dev/qemu/exec.c:2590 #18 0x00007ffff793540d in address_space_write (as=0x7ffff8921a90, addr=402657344, attrs=..., buf=0x7fffec79d170 "\t\345y\354\377\177", len=1) at /user/lea/dev/qemu/exec.c:2635
#19 0x00007ffff79344c0 in subpage_write (opaque=0x7fffd4569730, addr=64, value=9, len=1, attrs=...) at /user/lea/dev/qemu/exec.c:2221
#20 0x00007ffff7988678 in memory_region_write_with_attrs_accessor (mr=0x7fffd4569730, addr=64, value=0x7fffec79d2b8, size=1, shift=0, mask=255, attrs=...) at /user/lea/dev/qemu/memory.c:551
#21 0x00007ffff79887dd in access_with_adjusted_size (addr=64, value=0x7fffec79d2b8, size=1, access_size_min=1, access_size_max=8, access=0x7ffff7988568 <memory_region_write_with_attrs_accessor>, mr=0x7fffd4569730, attrs=...) at /user/lea/dev/qemu/memory.c:591 #22 0x00007ffff798bcc9 in memory_region_dispatch_write (mr=0x7fffd4569730, addr=64, data=9, size=1, attrs=...) at /user/lea/dev/qemu/memory.c:1269
#23 0x00007ffff7993676 in io_writeb (env=0x7ffff8941978, iotlbentry=0x7ffff894a0e8, val=9 '\t', addr=10376293541864280128, retaddr=140737194805689) at /user/lea/dev/qemu/softmmu_template.h:349
#24 0x00007ffff7993ae0 in helper_ret_stb_mmu (env=0x7ffff8941978, addr=10376293541864280128, val=9 '\t', oi=0, retaddr=140737194805689) at /user/lea/dev/qemu/softmmu_template.h:390
#25 0x00007fffee80c9bb in code_gen_buffer ()
#26 0x00007ffff793c093 in cpu_tb_exec (cpu=0x7ffff8939700, itb=0x7fffedaf4ee0) at /user/lea/dev/qemu/cpu-exec.c:166
#27 0x00007ffff793ccd1 in cpu_loop_exec_tb (cpu=0x7ffff8939700, tb=0x7fffedaf4ee0, last_tb=0x7fffec79d9e0, tb_exit=0x7fffec79d9fc, sc=0x7fffec79d9c0) at /user/lea/dev/qemu/cpu-exec.c:530
#28 0x00007ffff793cf98 in cpu_exec (cpu=0x7ffff8939700) at /user/lea/dev/qemu/cpu-exec.c:626
#29 0x00007ffff796f949 in tcg_cpu_exec (cpu=0x7ffff8939700) at /user/lea/dev/qemu/cpus.c:1541
#30 0x00007ffff796fa52 in tcg_exec_all () at /user/lea/dev/qemu/cpus.c:1574
#31 0x00007ffff796eb15 in qemu_tcg_cpu_thread_fn (arg=0x7ffff8939700) at /user/lea/dev/qemu/cpus.c:1171
#32 0x00007ffff30ce9d1 in start_thread () from /lib64/libpthread.so.0
#33 0x00007ffff2e1b86d in clone () from /lib64/libc.so.6
Regards,
Leon
Quoted 139 lines · Michael S. Tsirkin
From: Marcel Apfelbaum <[email protected]>
Skip
bus_master_enableregion creation on PCI device init in order to be sure the IOMMU device (if present) would be created in advance. Add this memory region atmachine_donetime.Signed-off-by Marcel Apfelbaum <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ include/sysemu/sysemu.h | 1 + hw/pci/pci.c | 41 ++++++++++++++++++++++++++++++++--------- vl.c | 5 +++++ 4 files changed, 40 insertions(+), 9 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -39,6 +39,8 @@ struct PCIBus {Keep a count of the number of devices with raised IRQs. */ int nirq;int *irq_count; + +Notifier machine_done; };typedef struct PCIBridgeWindows PCIBridgeWindows ;include/sysemu/sysemu.h +1
-0@@ -75,6 +75,7 @@ void qemu_add_exit_notifier(Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);void qemu_add_machine_init_done_notifier (Notifier *notify); +void qemu_remove_machine_init_done_notifier (Notifier *notify);void hmp_savevm (Monitor *mon,const QDict *qdict);int load_vmstate (const char *name);hw/pci/pci.c +32
-9@@ -78,10 +78,37 @@ static const VMStateDescription vmstate_pcibus = { } }; +static void pci_init_bus_master (PCIDevice *pci_dev) +{ +AddressSpace *dma_as =pci_device_iommu_address_space (pci_dev); + +memory_region_init_alias (&pci_dev->bus_master_enable_region, +OBJECT (pci_dev),"bus master" , + dma_as->root,0 ,memory_region_size (dma_as->root)); +memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); +address_space_init (&pci_dev->bus_master_as, + &pci_dev->bus_master_enable_region, pci_dev->name); +} + +static void pcibus_machine_done (Notifier *notifier,void *data) +{ +PCIBus *bus =container_of (notifier, PCIBus, machine_done); +int i; + +for (i =0 ; i <ARRAY_SIZE (bus->devices); ++i) { +if (bus->devices[i]) { +pci_init_bus_master (bus->devices[i]); + } + } +} +static void pci_bus_realize (BusState *qbus,Error **errp) {PCIBus *bus =PCI_BUS (qbus); + bus->machine_done.notify = pcibus_machine_done; +qemu_add_machine_init_done_notifier (&bus->machine_done); +vmstate_register (NULL ,-1 , &vmstate_pcibus, bus); }@@ -89,6 +116,8 @@ static void pci_bus_unrealize(BusState *qbus, Error **errp) {PCIBus *bus =PCI_BUS (qbus); +qemu_remove_machine_init_done_notifier (&bus->machine_done); +vmstate_unregister (NULL , &vmstate_pcibus, bus); }@@ -920,7 +949,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,PCIConfigReadFunc *config_read = pc->config_read;PCIConfigWriteFunc *config_write = pc->config_write;Error *local_err =NULL ; -AddressSpace *dma_as;DeviceState *dev =DEVICE (pci_dev); pci_dev->bus = bus;@@ -961,15 +989,10 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, pci_dev->devfn = devfn; pci_dev->requester_id_cache =pci_req_id_cache_get (pci_dev); - dma_as =pci_device_iommu_address_space (pci_dev); - -memory_region_init_alias (&pci_dev->bus_master_enable_region, -OBJECT (pci_dev),"bus master" , - dma_as->root,0 ,memory_region_size (dma_as->root)); -memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); -address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region, - name); +if (qdev_hotplug) { +pci_init_bus_master (pci_dev); + }pstrcpy (pci_dev->name,sizeof (pci_dev->name), name); pci_dev->irq_state =0 ;pci_config_alloc (pci_dev);vl.c +5
-0@@ -2675,6 +2675,11 @@ void qemu_add_machine_init_done_notifier(Notifier *notify) } } +void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +notifier_remove (notify); +} +static void qemu_run_machine_init_done_notifiers (void ) {notifier_list_notify (&machine_init_done_notifiers,NULL );Signature · 1 line
MST
Re: [Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization
Quoted 4 lines · Leon Alrae
Hi,
This commit causes regressions in my MIPS tests. QEMU segfaults when booting Linux on Malta board;
Hi Leon,
Is a good thing you caught it in the pull request, thanks!
Is a pity we don't have a way to run sanity tests on all archs (beyond make check)
this can be easily reproduced with
Quoted 6 lines
Aurelien's Debian images:
wget https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-5kc-malta
wget https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2
qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0" -nographic
I'll reproduce and handle it, thanks!
Marcel
Quoted 195 lines
...
[ 1.468000] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100 [ 1.476000] ata1.00: ATA-7: QEMU HARDDISK, 2.5+, max UDMA/100 [ 1.476000] ata1.00: 52428800 sectors, multi 16: LBA48 [ 1.480000] ata2.00: configured for UDMA/33 [ 1.484000] ata1.00: configured for UDMA/33 [ 1.536000] scsi 0:0:0:0: Direct-Access ATA QEMU HARDDISK 2.5+ PQ: 0 ANSI: 5 [ 1.552000] sd 0:0:0:0: [sda] 52428800 512-byte logical blocks: (26.8 GB/25.0 GiB) [ 1.568000] scsi 1:0:0:0: CD-ROM QEMU QEMU DVD-ROM 2.5+ PQ: 0 ANSI: 5 [ 1.576000] sd 0:0:0:0: [sda] Write Protect is off [ 1.580000] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUAProgram received signal SIGSEGV, Segmentation fault.
[Switching to Thread0x7fffec79e700(LWP 29679)]0x00007ffff792f806inaddress_space_lookup_region(d=0x0, addr=12582912, resolve_subpage=true) at /user/lea/dev/qemu/exec.c:359
359 MemoryRegionSection *section =atomic_read(&d->mru_section);
(gdb) bt#0 0x00007ffff792f806 in address_space_lookup_region (d=0x0, addr=12582912, resolve_subpage=true) at /user/lea/dev/qemu/exec.c:359 #1 0x00007ffff792f95e in address_space_translate_internal (d=0x0, addr=12582912, xlat=0x7fffec79ca30, plen=0x7fffec79cb18, resolve_subpage=true) at /user/lea/dev/qemu/exec.c:390 #2 0x00007ffff792fb5a in address_space_translate (as=0x7ffff8bc1ef0, addr=12582912, xlat=0x7fffec79cb10, plen=0x7fffec79cb18, is_write=false) at /user/lea/dev/qemu/exec.c:428 #3 0x00007ffff7935720 in address_space_read_full (as=0x7ffff8bc1ef0, addr=12582912, attrs=..., buf=0x7fffec79cd60 "\260^\324\370", <incomplete sequence \330>, len=8) at /user/lea/dev/qemu/exec.c:2724 #4 0x00007ffff7935821 in address_space_read (as=0x7ffff8bc1ef0, addr=12582912, attrs=..., buf=0x7fffec79cd60 "\260^\324\370", <incomplete sequence \330>, len=8, is_write=false) at /user/lea/dev/qemu/include/exec/memory.h:1476 #5 address_space_rw (as=0x7ffff8bc1ef0, addr=12582912, attrs=..., buf=0x7fffec79cd60 "\260^\324\370", <incomplete sequence \330>, len=8, is_write=false) at /user/lea/dev/qemu/exec.c:2739 #6 0x00007ffff7baf9a7 in dma_memory_rw_relaxed (as=0x7ffff8bc1ef0, addr=12582912, buf=0x7fffec79cd60, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /user/lea/dev/qemu/include/sysemu/dma.h:87 #7 0x00007ffff7bafa28 in dma_memory_rw (as=0x7ffff8bc1ef0, addr=12582912, buf=0x7fffec79cd60, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /user/lea/dev/qemu/include/sysemu/dma.h:110 #8 0x00007ffff7bafad3 in pci_dma_rw (dev=0x7ffff8bc1ce0, addr=12582912, buf=0x7fffec79cd60, len=8, dir=DMA_DIRECTION_TO_DEVICE) at /user/lea/dev/qemu/include/hw/pci/pci.h:731 #9 0x00007ffff7bafb3c in pci_dma_read (dev=0x7ffff8bc1ce0, addr=12582912, buf=0x7fffec79cd60, len=8) at /user/lea/dev/qemu/include/hw/pci/pci.h:738#10
0x00007ffff7baff6dinbmdma_prepare_buf(dma=0x7ffff8bc3620, limit=4096) at /user/lea/dev/qemu/hw/ide/pci.c:85
#110x00007ffff7ba66bcinide_dma_cb(opaque=0x7ffff8bc25e8, ret=0) at /user/lea/dev/qemu/hw/ide/core.c:844
#120x00007ffff7bb0615inbmdma_cmd_writeb(bm=0x7ffff8bc3620, val=9) at /user/lea/dev/qemu/hw/ide/pci.c:245
#130x00007ffff7bb1408inbmdma_write(opaque=0x7ffff8bc3620, addr=0, val=9, size=1) at /user/lea/dev/qemu/hw/ide/piix.c:77
#140x00007ffff7988548inmemory_region_write_accessor(mr=0x7ffff8bc3778, addr=0, value=0x7fffec79cfd8, size=1, shift=0, mask=255, attrs=...) at /user/lea/dev/qemu/memory.c:525
#150x00007ffff79887ddinaccess_with_adjusted_size(addr=0, value=0x7fffec79cfd8, size=1, access_size_min=1, access_size_max=4, access=0x7ffff798843e <memory_region_write_accessor>, mr=0x7ffff8bc3778, attrs=...) at /user/lea/dev/qemu/memory.c:591 #160x00007ffff798bc6einmemory_region_dispatch_write(mr=0x7ffff8bc3778, addr=0, data=9, size=1, attrs=...) at /user/lea/dev/qemu/memory.c:1262
#170x00007ffff7935294inaddress_space_write_continue(as=0x7ffff8921a90, addr=402657344, attrs=..., buf=0x7fffec79d170 "\t\345y\354\377\177", len=1, addr1=0, l=1, mr=0x7ffff8bc3778) at /user/lea/dev/qemu/exec.c:2590 #180x00007ffff793540dinaddress_space_write(as=0x7ffff8921a90, addr=402657344, attrs=..., buf=0x7fffec79d170 "\t\345y\354\377\177", len=1) at /user/lea/dev/qemu/exec.c:2635
#190x00007ffff79344c0insubpage_write(opaque=0x7fffd4569730, addr=64, value=9, len=1, attrs=...) at /user/lea/dev/qemu/exec.c:2221
#200x00007ffff7988678inmemory_region_write_with_attrs_accessor(mr=0x7fffd4569730, addr=64, value=0x7fffec79d2b8, size=1, shift=0, mask=255, attrs=...) at /user/lea/dev/qemu/memory.c:551
#210x00007ffff79887ddinaccess_with_adjusted_size(addr=64, value=0x7fffec79d2b8, size=1, access_size_min=1, access_size_max=8, access=0x7ffff7988568 <memory_region_write_with_attrs_accessor>, mr=0x7fffd4569730, attrs=...) at /user/lea/dev/qemu/memory.c:591 #220x00007ffff798bcc9inmemory_region_dispatch_write(mr=0x7fffd4569730, addr=64, data=9, size=1, attrs=...) at /user/lea/dev/qemu/memory.c:1269
#230x00007ffff7993676inio_writeb(env=0x7ffff8941978, iotlbentry=0x7ffff894a0e8, val=9 '\t', addr=10376293541864280128, retaddr=140737194805689) at /user/lea/dev/qemu/softmmu_template.h:349
#240x00007ffff7993ae0inhelper_ret_stb_mmu(env=0x7ffff8941978, addr=10376293541864280128, val=9 '\t', oi=0, retaddr=140737194805689) at /user/lea/dev/qemu/softmmu_template.h:390
#250x00007fffee80c9bbincode_gen_buffer()
#260x00007ffff793c093incpu_tb_exec(cpu=0x7ffff8939700, itb=0x7fffedaf4ee0) at /user/lea/dev/qemu/cpu-exec.c:166
#270x00007ffff793ccd1incpu_loop_exec_tb(cpu=0x7ffff8939700, tb=0x7fffedaf4ee0, last_tb=0x7fffec79d9e0, tb_exit=0x7fffec79d9fc, sc=0x7fffec79d9c0) at /user/lea/dev/qemu/cpu-exec.c:530
#280x00007ffff793cf98incpu_exec(cpu=0x7ffff8939700) at /user/lea/dev/qemu/cpu-exec.c:626
#290x00007ffff796f949intcg_cpu_exec(cpu=0x7ffff8939700) at /user/lea/dev/qemu/cpus.c:1541
#300x00007ffff796fa52intcg_exec_all() at /user/lea/dev/qemu/cpus.c:1574
#310x00007ffff796eb15inqemu_tcg_cpu_thread_fn(arg=0x7ffff8939700) at /user/lea/dev/qemu/cpus.c:1171
#320x00007ffff30ce9d1instart_thread() from/lib64/libpthread.so.0
#330x00007ffff2e1b86din clone () from/lib64/libc.so.6Regards,
LeonQuoted 139 lines · Michael S. Tsirkin
From: Marcel Apfelbaum <[email protected]>
Skip
bus_master_enableregion creation on PCI device init in order to be sure the IOMMU device (if present) would be created in advance. Add this memory region atmachine_donetime.Signed-off-by Marcel Apfelbaum <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ include/sysemu/sysemu.h | 1 + hw/pci/pci.c | 41 ++++++++++++++++++++++++++++++++--------- vl.c | 5 +++++ 4 files changed, 40 insertions(+), 9 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -39,6 +39,8 @@ struct PCIBus {Keep a count of the number of devices with raised IRQs. */ int nirq;int *irq_count; + +Notifier machine_done; };typedef struct PCIBridgeWindows PCIBridgeWindows ;include/sysemu/sysemu.h +1
-0@@ -75,6 +75,7 @@ void qemu_add_exit_notifier(Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);void qemu_add_machine_init_done_notifier (Notifier *notify); +void qemu_remove_machine_init_done_notifier (Notifier *notify);void hmp_savevm (Monitor *mon,const QDict *qdict);int load_vmstate (const char *name);hw/pci/pci.c +32
-9@@ -78,10 +78,37 @@ static const VMStateDescription vmstate_pcibus = { } }; +static void pci_init_bus_master (PCIDevice *pci_dev) +{ +AddressSpace *dma_as =pci_device_iommu_address_space (pci_dev); + +memory_region_init_alias (&pci_dev->bus_master_enable_region, +OBJECT (pci_dev),"bus master" , + dma_as->root,0 ,memory_region_size (dma_as->root)); +memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); +address_space_init (&pci_dev->bus_master_as, + &pci_dev->bus_master_enable_region, pci_dev->name); +} + +static void pcibus_machine_done (Notifier *notifier,void *data) +{ +PCIBus *bus =container_of (notifier, PCIBus, machine_done); +int i; + +for (i =0 ; i <ARRAY_SIZE (bus->devices); ++i) { +if (bus->devices[i]) { +pci_init_bus_master (bus->devices[i]); + } + } +} +static void pci_bus_realize (BusState *qbus,Error **errp) {PCIBus *bus =PCI_BUS (qbus); + bus->machine_done.notify = pcibus_machine_done; +qemu_add_machine_init_done_notifier (&bus->machine_done); +vmstate_register (NULL ,-1 , &vmstate_pcibus, bus); }@@ -89,6 +116,8 @@ static void pci_bus_unrealize(BusState *qbus, Error **errp) {PCIBus *bus =PCI_BUS (qbus); +qemu_remove_machine_init_done_notifier (&bus->machine_done); +vmstate_unregister (NULL , &vmstate_pcibus, bus); }@@ -920,7 +949,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,PCIConfigReadFunc *config_read = pc->config_read;PCIConfigWriteFunc *config_write = pc->config_write;Error *local_err =NULL ; -AddressSpace *dma_as;DeviceState *dev =DEVICE (pci_dev); pci_dev->bus = bus;@@ -961,15 +989,10 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, pci_dev->devfn = devfn; pci_dev->requester_id_cache =pci_req_id_cache_get (pci_dev); - dma_as =pci_device_iommu_address_space (pci_dev); - -memory_region_init_alias (&pci_dev->bus_master_enable_region, -OBJECT (pci_dev),"bus master" , - dma_as->root,0 ,memory_region_size (dma_as->root)); -memory_region_set_enabled (&pci_dev->bus_master_enable_region, false); -address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region, - name); +if (qdev_hotplug) { +pci_init_bus_master (pci_dev); + }pstrcpy (pci_dev->name,sizeof (pci_dev->name), name); pci_dev->irq_state =0 ;pci_config_alloc (pci_dev);vl.c +5
-1@@ -2675,6 +2675,11 @@ void qemu_add_machine_init_done_notifier(Notifier *notify) } } +void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +notifier_remove (notify); +} +static void qemu_run_machine_init_done_notifiers (void ) {notifier_list_notify (&machine_init_done_notifiers,NULL ); --MST
Re: [Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization
Quoted 20 lines · Marcel Apfelbaum
Quoted 4 lines · Leon Alrae
Hi,
This commit causes regressions in my MIPS tests. QEMU segfaults when booting Linux on Malta board;
Hi Leon,
Is a good thing you caught it in the pull request, thanks! Is a pity we don't have a way to run sanity tests on all archs (beyond make check)
this can be easily reproduced with
Quoted 7 lines
Aurelien's Debian images:
wget
https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-5kc-malta
wget
https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2
Quoted 7 lines
Quoted 4 lines
qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0" -nographic
I'll reproduce and handle it, thanks!
Marcel
FWIW this looks like the exact same backtrace I reported with qemu-system-sparc64 so hopefully the solution should fix both problems :)
ATB,
Mark.
Re: [Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization
Quoted 27 lines · Mark Cave-Ayland
Quoted 25 lines · Marcel Apfelbaum
Quoted 4 lines · Leon Alrae
Hi,
This commit causes regressions in my MIPS tests. QEMU segfaults when booting Linux on Malta board;
Hi Leon,
Is a good thing you caught it in the pull request, thanks! Is a pity we don't have a way to run sanity tests on all archs (beyond make check)
this can be easily reproduced with
Quoted 11 lines
Aurelien's Debian images:
wget
https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-5kc-malta
wget
https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0" -nographic
Quoted 6 lines
Quoted 2 lines
I'll reproduce and handle it, thanks!
MarcelFWIW this looks like the exact same backtrace I reported with qemu-system-sparc64 so hopefully the solution should fix both problems :)
Hi Mark and Leon,
I've reproduced both failures and I've found the root cause. The PCI root bus is not realized as part of the machine initialization.
Until now the only consequence was the machine couldn't be migrated (because the vmstate is initialized as part of 'realize').
However, from now on the devices cannot do DMA requests if the bus is not 'realized'.
It took some time because I had to go over all the archs and check this issue. I have the patches ready, I am running some more tests and post them soon.
Thanks for the patience,
Marcel
Quoted 5 lines
ATB,
Mark.
[Qemu-devel] [PULL 04/36] q35: allow dynamic sysbus
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
Allow adding sysbus devices with -device on Q35.
At first Q35 will support only intel-iommu to be added this way, however the command line will support all sysbus devices.
Mark with 'cannot_instantiate_with_device_add_yet' the ones causing immediate problems (e.g. crashes).
--- hw/i386/pc_q35.c | 1 + hw/pci-bridge/pci_expander_bridge.c | 2 ++ hw/pci-host/piix.c | 2 ++ hw/pci-host/q35.c | 2 ++ 4 files changed, 7 insertions(+)
hw/i386/pc_q35.c +1 -0
@@ -290,6 +290,7 @@ static void pc_q35_machine_options(MachineClass *m) m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; m->no_floppy =1 ; + m->has_dynamic_sysbus = true; }static void pc_q35_2_7_machine_options (MachineClass *m)
hw/pci-bridge/pci_expander_bridge.c +2 -0
@@ -149,6 +149,8 @@ static void pxb_host_class_init(ObjectClass *class, void *data)PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (class); dc->fw_name ="pci" ; +/* Reason: Internal part of the pxb/pxb-pcie device, not usable by itself */ + dc->cannot_instantiate_with_device_add_yet = true; sbc->explicit_ofw_unit_address = pxb_host_ofw_unit_address; hc->root_bus_path = pxb_host_root_bus_path; }
hw/pci-host/piix.c +2 -0
@@ -865,6 +865,8 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data) dc->realize = i440fx_pcihost_realize; dc->fw_name ="pci" ; dc->props = i440fx_props; +/* Reason: needs to be wired up by pc_init1 */ + dc->cannot_instantiate_with_device_add_yet = true; }static const TypeInfo i440fx_pcihost_info = {
hw/pci-host/q35.c +2 -0
@@ -142,6 +142,8 @@ static void q35_host_class_init(ObjectClass *klass, void *data) hc->root_bus_path = q35_host_root_bus_path; dc->realize = q35_host_realize; dc->props = mch_props; +/* Reason: needs to be wired up by pc_q35_init */ + dc->cannot_instantiate_with_device_add_yet = true;set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories); dc->fw_name ="pci" ; }
Signature · 1 line
MST
[Qemu-devel] [PULL 05/36] hw/iommu: enable iommu with -device
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
Use the standard '-device intel-iommu' to create the IOMMU device. The legacy '-machine,iommu=on' can still be used.
--- hw/i386/intel_iommu.c | 16 ++++++++++++++++ hw/i386/pc_q35.c | 1 - hw/pci-host/q35.c | 17 +---------------- 3 files changed, 17 insertions(+), 17 deletions(-)
hw/i386/intel_iommu.c +16 -0
@@ -25,6 +25,7 @@#include "intel_iommu_internal.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" +#include "hw/i386/pc.h" /*#define DEBUG_INTEL_IOMMU*/ #ifdef DEBUG_INTEL_IOMMU
@@ -2026,8 +2027,20 @@ static void vtd_reset(DeviceState *dev)vtd_init (s); } +static AddressSpace *vtd_host_dma_iommu (PCIBus *bus,void *opaque,int devfn) +{ +IntelIOMMUState *s = opaque; +VTDAddressSpace *vtd_as; + +assert (0 <= devfn && devfn <=VTD_PCI_DEVFN_MAX ); + + vtd_as =vtd_find_add_as (s, bus, devfn); +return &vtd_as->as; +} +static void vtd_realize (DeviceState *dev,Error **errp) { +PCIBus *bus =PC_MACHINE (qdev_get_machine ())->bus;IntelIOMMUState *s =INTEL_IOMMU_DEVICE (dev);VTD_DPRINTF (GENERAL ,"" );
@@ -2041,6 +2054,8 @@ static void vtd_realize(DeviceState *dev, Error **errp) s->vtd_as_by_busptr =g_hash_table_new_full (vtd_uint64_hash, vtd_uint64_equal, g_free, g_free);vtd_init (s); +sysbus_mmio_map (SYS_BUS_DEVICE (s),0 ,Q35_HOST_BRIDGE_IOMMU_ADDR ); +pci_setup_iommu (bus, vtd_host_dma_iommu, dev); }static void vtd_class_init (ObjectClass *klass,void *data)
@@ -2051,6 +2066,7 @@ static void vtd_class_init(ObjectClass *klass, void *data) dc->realize = vtd_realize; dc->vmsd = &vtd_vmstate; dc->props = vtd_properties; + dc->hotpluggable = false; }static const TypeInfo vtd_info = {
hw/i386/pc_q35.c +0 -1
@@ -179,7 +179,6 @@ static void pc_q35_init(MachineState *machine)qdev_init_nofail (DEVICE (q35_host)); phb =PCI_HOST_BRIDGE (q35_host); host_bus = phb->bus; - pcms->bus = phb->bus;/* create ISA bus */ lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV, ICH9_LPC_FUNC), true,
hw/pci-host/q35.c +1 -16
@@ -52,6 +52,7 @@ static void q35_host_realize(DeviceState *dev, Error **errp) pci->bus =pci_bus_new (DEVICE (s),"pcie.0" , s->mch.pci_address_space, s->mch.address_space_io,0 ,TYPE_PCIE_BUS ); +PC_MACHINE (qdev_get_machine ())->bus = pci->bus;qdev_set_parent_bus (DEVICE (&s->mch),BUS (pci->bus));qdev_init_nofail (DEVICE (&s->mch)); }
@@ -446,28 +447,12 @@ static void mch_reset(DeviceState *qdev)mch_update (mch); } -static AddressSpace *q35_host_dma_iommu (PCIBus *bus,void *opaque,int devfn) -{ -IntelIOMMUState *s = opaque; -VTDAddressSpace *vtd_as; - -assert (0 <= devfn && devfn <=VTD_PCI_DEVFN_MAX ); - - vtd_as =vtd_find_add_as (s, bus, devfn); -return &vtd_as->as; -} -static void mch_init_dmar (MCHPCIState *mch) { -PCIBus *pci_bus =PCI_BUS (qdev_get_parent_bus (DEVICE (mch))); - mch->iommu =INTEL_IOMMU_DEVICE (qdev_create (NULL ,TYPE_INTEL_IOMMU_DEVICE ));object_property_add_child (OBJECT (mch),"intel-iommu" ,OBJECT (mch->iommu),NULL );qdev_init_nofail (DEVICE (mch->iommu)); -sysbus_mmio_map (SYS_BUS_DEVICE (mch->iommu),0 ,Q35_HOST_BRIDGE_IOMMU_ADDR ); - -pci_setup_iommu (pci_bus, q35_host_dma_iommu, mch->iommu); }static void mch_realize (PCIDevice *d,Error **errp)
Signature · 1 line
MST
[Qemu-devel] [PULL 06/36] machine: remove iommu property
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
Since iommu devices can be created with '-device' there is no need to keep iommu as machine and mch property.
--- include/hw/pci-host/q35.h | 1 - hw/core/machine.c | 20 -------------------- hw/pci-host/q35.c | 12 ------------ qemu-options.hx | 3 --- 4 files changed, 36 deletions(-)
include/hw/pci-host/q35.h +0 -1
@@ -60,7 +60,6 @@ typedef struct MCHPCIState {uint64_t above_4g_mem_size;uint64_t pci_hole64_size;uint32_t short_root_bus; -IntelIOMMUState *iommu; } MCHPCIState; typedef struct Q35PCIHost {
hw/core/machine.c +0 -20
@@ -300,20 +300,6 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) ms->firmware =g_strdup (value); } -static bool machine_get_iommu (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return ms->iommu; -} - -static void machine_set_iommu (Object *obj,bool value,Error **errp) -{ -MachineState *ms =MACHINE (obj); - - ms->iommu = value; -} -static void machine_set_suppress_vmdesc (Object *obj,bool value,Error **errp) {MachineState *ms =MACHINE (obj);
@@ -493,12 +479,6 @@ static void machine_initfn(Object *obj)object_property_set_description (obj,"firmware" ,"Firmware image" ,NULL ); -object_property_add_bool (obj,"iommu" , - machine_get_iommu, - machine_set_iommu,NULL ); -object_property_set_description (obj,"iommu" , -"Set on/off to enable/disable Intel IOMMU (VT-d)" , -NULL );object_property_add_bool (obj,"suppress-vmdesc" , machine_get_suppress_vmdesc, machine_set_suppress_vmdesc,NULL );
hw/pci-host/q35.c +0 -12
@@ -447,14 +447,6 @@ static void mch_reset(DeviceState *qdev)mch_update (mch); } -static void mch_init_dmar (MCHPCIState *mch) -{ - mch->iommu =INTEL_IOMMU_DEVICE (qdev_create (NULL ,TYPE_INTEL_IOMMU_DEVICE )); -object_property_add_child (OBJECT (mch),"intel-iommu" , -OBJECT (mch->iommu),NULL ); -qdev_init_nofail (DEVICE (mch->iommu)); -} -static void mch_realize (PCIDevice *d,Error **errp) {int i;
@@ -513,10 +505,6 @@ static void mch_realize(PCIDevice *d, Error **errp) mch->pci_address_space, &mch->pam_regions[i+1 ], PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); } -/* Intel IOMMU (VT-d) */ -if (object_property_get_bool (qdev_get_machine (),"iommu" ,NULL )) { -mch_init_dmar (mch); - } }uint64_t mch_mcfg_base (void )
qemu-options.hx +0 -3
@@ -38,7 +38,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)\n" " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n"
@@ -73,8 +72,6 @@ Include guest memory in a core dump. The default is on. Enables or disables memory merge support. This feature, when supported by the host, de-duplicates identical memory pages among VMs instances (enabled by default). -@item iommu=on|off -Enables or disables emulated Intel IOMMU (VT-d) support. The default is off. @item aes-key-wrap=on|off Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created to allow
Signature · 1 line
MST
[Qemu-devel] [PULL 07/36] piix: Set I440FXState member pci_info.w32 in one place
In reply to a message not in the archiveFrom: Markus Armbruster <[email protected]>
Range pci_info.w32 records the location of the PCI hole.
It's initialized to empty when QOM zeroes I440FXState. That's a fine value for a still unknown PCI hole.
i440fx_init() sets pci_info.w32.begin = below_4g_mem_size. Changes the PCI hole from empty to [below_4g_mem_size, UINT64_MAX]. That's a bogus value.
i440fx_pcihost_initfn() sets pci_info.end = IO_APIC_DEFAULT_ADDRESS. Since i440fx_init() ran already, this changes the PCI hole to [below_4g_mem_size, IO_APIC_DEFAULT_ADDRESS-1]. That's the correct value.
Setting the bounds of the PCI hole in two separate places is confusing, and begs the question whether the bogus intermediate value could be used by something, or what would happen if we somehow managed to realize an i440FX device without having run the board init function i440fx_init() first.
Avoid the confusion by setting the (constant) upper bound along with the lower bound in i440fx_init().
--- hw/pci-host/piix.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/pci-host/piix.c +1 -3
@@ -263,7 +263,6 @@ static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v,static void i440fx_pcihost_initfn (Object *obj) {PCIHostState *s =PCI_HOST_BRIDGE (obj); -I440FXState *d =I440FX_PCI_HOST_BRIDGE (obj);memory_region_init_io (&s->conf_mem, obj, &pci_host_conf_le_ops, s,"pci-conf-idx" ,4 );
@@ -285,8 +284,6 @@ static void i440fx_pcihost_initfn(Object *obj)object_property_add (obj,PCI_HOST_PROP_PCI_HOLE64_END ,"int" , i440fx_pcihost_get_pci_hole64_end,NULL ,NULL ,NULL ,NULL ); - - d->pci_info.w32.end =IO_APIC_DEFAULT_ADDRESS ; }static void i440fx_pcihost_realize (DeviceState *dev,Error **errp)
@@ -348,6 +345,7 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type, i440fx =I440FX_PCI_HOST_BRIDGE (dev); i440fx->pci_info.w32.begin = below_4g_mem_size; + i440fx->pci_info.w32.end =IO_APIC_DEFAULT_ADDRESS ;/* setup pci memory mapping */ pc_pci_as_mapping_init(OBJECT(f), f->system_memory,
Signature · 1 line
MST
[Qemu-devel] [PULL 08/36] pc: Eliminate PcPciInfo
In reply to a message not in the archiveFrom: Markus Armbruster <[email protected]>
PcPciInfo has two (ill-named) members: Range w32 is the PCI hole, and w64 is the PCI64 hole.
Three users:
* I440FXState and MCHPCIState have a member PcPciInfo pci_info, but only pci_info.w32 is actually used. This is confusing. Replace by Range pci_hole.
* acpi_build() uses auto PcPciInfo pci_info to forward both PCI holes from acpi_get_pci_info() to build_dsdt(). Replace by two variables Range pci_hole, pci_hole64. Rename acpi_get_pci_info() to acpi_get_pci_holes().
PcPciInfo is now unused; drop it.
--- include/hw/i386/pc.h | 5 ----- include/hw/pci-host/q35.h | 2 +- hw/i386/acpi-build.c | 43 ++++++++++++++++++++++--------------------- hw/pci-host/piix.c | 10 +++++----- hw/pci-host/q35.c | 12 ++++++------ 5 files changed, 34 insertions(+), 38 deletions(-)
include/hw/i386/pc.h +0 -5
@@ -150,11 +150,6 @@ struct PCMachineClass {/* PC-style peripherals (also used by other machines). */ -typedef struct PcPciInfo { -Range w32; -Range w64; -}PcPciInfo ; -#define ACPI_PM_PROP_S3_DISABLED "disable_s3"#define ACPI_PM_PROP_S4_DISABLED "disable_s4"#define ACPI_PM_PROP_S4_VAL "s4_val"
include/hw/pci-host/q35.h +1 -1
@@ -55,7 +55,7 @@ typedef struct MCHPCIState {MemoryRegion smram_region, open_high_smram;MemoryRegion smram, low_smram, high_smram;MemoryRegion tseg_blackhole, tseg_window; -PcPciInfo pci_info; +Range pci_hole;uint64_t below_4g_mem_size;uint64_t above_4g_mem_size;uint64_t pci_hole64_size;
hw/i386/acpi-build.c +22 -21
95 lines not on this page · raw message
hw/pci-host/piix.c +5 -5
@@ -48,7 +48,7 @@typedef struct I440FXState {PCIHostState parent_obj; -PcPciInfo pci_info; +Range pci_hole;uint64_t pci_hole64_size;uint32_t short_root_bus; }I440FXState ;
@@ -221,7 +221,7 @@ static void i440fx_pcihost_get_pci_hole_start(Object *obj, Visitor *v, Error **errp) {I440FXState *s =I440FX_PCI_HOST_BRIDGE (obj); -uint32_t value = s->pci_info.w32.begin; +uint32_t value = s->pci_hole.begin;visit_type_uint32 (v, name, &value, errp); }
@@ -231,7 +231,7 @@ static void i440fx_pcihost_get_pci_hole_end(Object *obj, Visitor *v, Error **errp) {I440FXState *s =I440FX_PCI_HOST_BRIDGE (obj); -uint32_t value = s->pci_info.w32.end; +uint32_t value = s->pci_hole.end;visit_type_uint32 (v, name, &value, errp); }
@@ -344,8 +344,8 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type, f->ram_memory = ram_memory; i440fx =I440FX_PCI_HOST_BRIDGE (dev); - i440fx->pci_info.w32.begin = below_4g_mem_size; - i440fx->pci_info.w32.end =IO_APIC_DEFAULT_ADDRESS ; + i440fx->pci_hole.begin = below_4g_mem_size; + i440fx->pci_hole.end =IO_APIC_DEFAULT_ADDRESS ;/* setup pci memory mapping */ pc_pci_as_mapping_init(OBJECT(f), f->system_memory,
hw/pci-host/q35.c +6 -6
@@ -74,7 +74,7 @@ static void q35_host_get_pci_hole_start(Object *obj, Visitor *v, Error **errp) {Q35PCIHost *s =Q35_HOST_DEVICE (obj); -uint32_t value = s->mch.pci_info.w32.begin; +uint32_t value = s->mch.pci_hole.begin;visit_type_uint32 (v, name, &value, errp); }
@@ -84,7 +84,7 @@ static void q35_host_get_pci_hole_end(Object *obj, Visitor *v, Error **errp) {Q35PCIHost *s =Q35_HOST_DEVICE (obj); -uint32_t value = s->mch.pci_info.w32.end; +uint32_t value = s->mch.pci_hole.end;visit_type_uint32 (v, name, &value, errp); }
@@ -205,9 +205,9 @@ static void q35_host_initfn(Object *obj)* it's not a power of two, which means an MTRR * can't cover it exactly. */ - s->mch.pci_info.w32.begin =MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT + + s->mch.pci_hole.begin =MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT +MCH_HOST_BRIDGE_PCIEXBAR_MAX ; - s->mch.pci_info.w32.end =IO_APIC_DEFAULT_ADDRESS ; + s->mch.pci_hole.end =IO_APIC_DEFAULT_ADDRESS ; }static const TypeInfo q35_host_info = {
@@ -288,9 +288,9 @@ static void mch_update_pciexbar(MCHPCIState *mch)* which means an MTRR can't cover it exactly. */ if (enable) { - mch->pci_info.w32.begin = addr + length; + mch->pci_hole.begin = addr + length; }else { - mch->pci_info.w32.begin =MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT ; + mch->pci_hole.begin =MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT ; } }
Signature · 1 line
MST
[Qemu-devel] [PULL 09/36] virtio: revert host notifiers to old semantics
In reply to a message not in the archiveFrom: Cornelia Huck <[email protected]>
The host notifier rework tried both to unify host notifiers across transports and plug a possible hole during host notifier re-assignment. Unfortunately, this meant a change in semantics that breaks vhost and iSCSI+dataplane.
As the minimal fix, keep the common host notifier code but revert to the old semantics so that we have time to figure out the proper fix.
--- hw/virtio/virtio-bus.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
hw/virtio/virtio-bus.c +10 -16
@@ -176,8 +176,8 @@ static int set_host_notifier_internal(DeviceState *proxy, VirtioBusState *bus,return r; } }else { -virtio_queue_set_host_notifier_fd_handler (vq, false, false); k->ioeventfd_assign (proxy, notifier, n, assign); +virtio_queue_set_host_notifier_fd_handler (vq, false, false);event_notifier_cleanup (notifier); }return r;
@@ -251,31 +251,25 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign) {VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (bus);DeviceState *proxy =DEVICE (BUS (bus)->parent); -VirtIODevice *vdev =virtio_bus_get_device (bus); -VirtQueue *vq =virtio_get_queue (vdev, n);if (!k->ioeventfd_started) {return -ENOSYS ; } + k->ioeventfd_set_disabled (proxy, assign);if (assign) {/* * Stop using the generic ioeventfd, we are doing eventfd handling * ourselves below +* +* FIXME: We should just switch the handler and not deassign the +* ioeventfd. +* Otherwise, there's a window where we don't have an +* ioeventfd and we may end up with a notification where +* we don't expect one. */ - k->ioeventfd_set_disabled (proxy, true); - } -/* -* Just switch the handler, don't deassign the ioeventfd. -* Otherwise, there's a window where we don't have an -* ioeventfd and we may end up with a notification where -* we don't expect one. -*/ -virtio_queue_set_host_notifier_fd_handler (vq, assign, !assign); -if (!assign) { -/* Use generic ioeventfd handler again. */ - k->ioeventfd_set_disabled (proxy, false); +virtio_bus_stop_ioeventfd (bus); } -return 0 ; +return set_host_notifier_internal (proxy, bus, n, assign, false); }static char *virtio_bus_get_dev_path (DeviceState *dev)
Signature · 1 line
MST
[Qemu-devel] [PULL 10/36] virtio: set low features early on load
In reply to a message not in the archivevirtio migrates the low 32 feature bits twice, the first copy is there for compatibility but ever since 019a3edbb25f1571e876f8af1ce4c55412939e5d: ("virtio: make features 64bit wide") it's ignored on load. This is wrong since virtio_net_load tests self announcement and guest offloads before the second copy including high feature bits is loaded. This means that self announcement, control vq and guest offloads are all broken after migration.
Fix it up by loading low feature bits: somewhat ugly since high and low bits become out of sync temporarily, but seems unavoidable for compatibility. The right thing to do for new features is probably to test the host features, anyway.
("virtio: make features 64bit wide")
--- hw/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/virtio/virtio.c +10 -0
@@ -1499,6 +1499,16 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) }qemu_get_be32s (f, &features); +/* +* Temporarily set guest_features low bits - needed by +* virtio net load code testing for VIRTIO_NET_F_CTRL_GUEST_OFFLOADS +* VIRTIO_NET_F_GUEST_ANNOUNCE and VIRTIO_NET_F_CTRL_VQ. +* +* Note: devices should always test host features in future - don't create +* new dependencies like this. +*/ + vdev->guest_features = features; + config_len =qemu_get_be32 (f);/*
Signature · 1 line
MST
[Qemu-devel] [PULL 11/36] Revert "virtio-net: unbreak self announcement and guest offloads after migration"
In reply to a message not in the archiveThis reverts commit 1f8828ef573c83365b4a87a776daf8bcef1caa21.
--- hw/net/virtio-net.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)
hw/net/virtio-net.c +17 -23
@@ -1542,33 +1542,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) {VirtIONet *n = opaque;VirtIODevice *vdev =VIRTIO_DEVICE (n); -int ret;if (version_id <2 || version_id >VIRTIO_NET_VM_VERSION )return -EINVAL ; - ret =virtio_load (vdev, f, version_id); -if (ret) { -return ret; - } - -if (virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_GUEST_OFFLOADS )) { - n->curr_guest_offloads =qemu_get_be64 (f); - }else { - n->curr_guest_offloads =virtio_net_supported_guest_offloads (n); - } - -if (peer_has_vnet_hdr (n)) { -virtio_net_apply_guest_offloads (n); - } - -if (virtio_vdev_has_feature (vdev,VIRTIO_NET_F_GUEST_ANNOUNCE ) && -virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ )) { - n->announce_counter =SELF_ANNOUNCE_ROUNDS ; -timer_mod (n->announce_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL )); - } - -return 0 ; +return virtio_load (vdev, f, version_id); } static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
@@ -1665,6 +1643,16 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f, } } +if (virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_GUEST_OFFLOADS )) { + n->curr_guest_offloads =qemu_get_be64 (f); + }else { + n->curr_guest_offloads =virtio_net_supported_guest_offloads (n); + } + +if (peer_has_vnet_hdr (n)) { +virtio_net_apply_guest_offloads (n); + } +virtio_net_set_queues (n);/* Find the first multicast entry in the saved MAC filter */
@@ -1682,6 +1670,12 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_subqueue (n->nic, i)->link_down = link_down; } +if (virtio_vdev_has_feature (vdev,VIRTIO_NET_F_GUEST_ANNOUNCE ) && +virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ )) { + n->announce_counter =SELF_ANNOUNCE_ROUNDS ; +timer_mod (n->announce_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL )); + } +return 0 ; }
Signature · 1 line
MST
[Qemu-devel] [PULL 12/36] pci_register_bar: cleanup
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
place relevant code tegother, make the code easier to read
--- hw/pci/pci.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
hw/pci/pci.c +8 -8
@@ -1074,7 +1074,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, uint8_t type, MemoryRegion *memory) { PCIIORegion *r; -uint32_t addr; +uint32_t addr;/* offset in pci config space */ uint64_t wmask;pcibus_t size =memory_region_size (memory);
@@ -1090,15 +1090,20 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, r->addr =PCI_BAR_UNMAPPED ; r->size = size; r->type = type; - r->memory =NULL ; + r->memory = memory; + r->address_space = type &PCI_BASE_ADDRESS_SPACE_IO + ? pci_dev->bus->address_space_io + : pci_dev->bus->address_space_mem; wmask = ~(size -1 ); - addr =pci_bar (pci_dev, region_num);if (region_num ==PCI_ROM_SLOT ) {/* ROM enable bit is writable */ wmask |=PCI_ROM_ADDRESS_ENABLE ; } + + addr =pci_bar (pci_dev, region_num);pci_set_long (pci_dev->config + addr, type); +if (!(r->type &PCI_BASE_ADDRESS_SPACE_IO ) && r->type &PCI_BASE_ADDRESS_MEM_TYPE_64 ) {pci_set_quad (pci_dev->wmask + addr, wmask);
@@ -1107,11 +1112,6 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,pci_set_long (pci_dev->wmask + addr, wmask &0xffffffff );pci_set_long (pci_dev->cmask + addr,0xffffffff ); } - pci_dev->io_regions[region_num].memory = memory; - pci_dev->io_regions[region_num].address_space - = type &PCI_BASE_ADDRESS_SPACE_IO - ? pci_dev->bus->address_space_io - : pci_dev->bus->address_space_mem; }static void pci_update_vga (PCIDevice *pci_dev)
Signature · 1 line
MST
[Qemu-devel] [PULL 13/36] log: Clean up misuse of Range for -dfilter
In reply to a message not in the archiveFrom: Markus Armbruster <[email protected]>
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 }, where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent [0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB where LOB > UPB when UPB is zero, but happily create an empty Range when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound UINT64_MAX.
--- tests/test-logging.c | 10 ++++++++++ util/log.c | 28 +++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-)
tests/test-logging.c +10 -0
@@ -68,6 +68,16 @@ static void test_parse_range(void)g_assert (qemu_log_in_addr_range (0x2050 ));g_assert (qemu_log_in_addr_range (0x3050 )); +qemu_set_dfilter_ranges ("0xffffffffffffffff-1" , &error_abort); +g_assert (qemu_log_in_addr_range (UINT64_MAX )); +g_assert_false (qemu_log_in_addr_range (UINT64_MAX -1 )); + +qemu_set_dfilter_ranges ("0..0xffffffffffffffff" , &err); +error_free_or_abort (&err); + +qemu_set_dfilter_ranges ("2..1" , &err); +error_free_or_abort (&err); +qemu_set_dfilter_ranges ("0x1000+onehundred" , &err);error_free_or_abort (&err);
util/log.c +15 -13
@@ -131,8 +131,8 @@ bool qemu_log_in_addr_range(uint64_t addr)if (debug_regions) {int i =0 ;for (i =0 ; i < debug_regions->len; i++) { -struct Range *range = &g_array_index (debug_regions, Range, i); -if (addr >= range->begin && addr <= range->end) { +Range *range = &g_array_index (debug_regions, Range, i); +if (addr >= range->begin && addr <= range->end -1 ) {return true; } }
@@ -158,7 +158,7 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)for (i =0 ; ranges[i]; i++) {const char *r = ranges[i];const char *range_op, *r2, *e; -uint64_t r1val, r2val; +uint64_t r1val, r2val, lob, upb;struct Range range; range_op =strstr (r,"-" );
@@ -187,27 +187,29 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp) (int)(r2 - range_op), range_op); goto out; } -if (r2val ==0 ) { -error_setg (errp,"Invalid range" ); - goto out; - }switch (*range_op) {case '+' : - range.begin = r1val; - range.end = r1val + (r2val -1 ); + lob = r1val; + upb = r1val + r2val -1 ;break ;case '-' : - range.end = r1val; - range.begin = r1val - (r2val -1 ); + upb = r1val; + lob = r1val - (r2val -1 );break ;case '.' : - range.begin = r1val; - range.end = r2val; + lob = r1val; + upb = r2val;break ;default :g_assert_not_reached (); } +if (lob > upb || (lob ==0 && upb ==UINT64_MAX )) { +error_setg (errp,"Invalid range" ); + goto out; + } + range.begin = lob; + range.end = upb +1 ;g_array_append_val (debug_regions, range); } out:
Signature · 1 line
MST
[Qemu-devel] [PULL 14/36] range: Eliminate direct Range member access
In reply to a message not in the archiveFrom: Markus Armbruster <[email protected]>
Users of struct Range mess liberally with its members, which makes refactoring hard. Create a set of methods, and convert all users to call them instead of accessing members. The methods have carefully worded contracts, and use assertions to check them.
--- include/qemu/range.h | 85 ++++++++++++++++++++++++++++++++++++++++++-- hw/i386/acpi-build.c | 35 +++++++++--------- hw/pci-host/piix.c | 26 +++++++++----- hw/pci-host/q35.c | 41 +++++++++++++-------- hw/pci/pci.c | 17 ++++----- qapi/string-input-visitor.c | 20 +++++------ qapi/string-output-visitor.c | 18 +++++----- util/log.c | 5 ++- util/range.c | 3 +- 9 files changed, 176 insertions(+), 74 deletions(-)
include/qemu/range.h +83 -2
@@ -36,12 +36,91 @@ struct Range {uint64_t end;/* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */ }; +static inline void range_invariant (Range *range) +{ +assert ((!range->begin && !range->end)/* empty */ + || range->begin <= range->end -1 );/* non-empty */ +} + +/* Compound literal encoding the empty range */ +#define range_empty ((Range){ .begin = 0, .end = 0 }) + +/* Is @range empty? */ +static inline bool range_is_empty (Range *range) +{ +range_invariant (range); +return !range->begin && !range->end; +} + +/* Does @range contain @val? */ +static inline bool range_contains (Range *range,uint64_t val) +{ +return !range_is_empty (range) + && val >= range->begin && val <= range->end -1 ; +} + +/* Initialize @range to the empty range */ +static inline void range_make_empty (Range *range) +{ + *range = range_empty; +assert (range_is_empty (range)); +} + +/* +* Initialize @range to span the interval [@lob,@upb]. +* Both bounds are inclusive. +* The interval must not be empty, i.e. @lob must be less than or +* equal @upb. +* The interval must not be [0,UINT64_MAX], because Range can't +* represent that. +*/ +static inline void range_set_bounds (Range *range,uint64_t lob,uint64_t upb) +{ +assert (lob <= upb); + range->begin = lob; + range->end = upb +1 ;/* may wrap to zero, that's okay */ +assert (!range_is_empty (range)); +} + +/* +* Initialize @range to span the interval [@lob,@upb_plus1). +* The lower bound is inclusive, the upper bound is exclusive. +* Zero @upb_plus1 is special: if @lob is also zero, set @range to the +* empty range. Else, set @range to [@lob,UINT64_MAX]. +*/ +static inline void range_set_bounds1 (Range *range, +uint64_t lob,uint64_t upb_plus1) +{ + range->begin = lob; + range->end = upb_plus1; +range_invariant (range); +} + +/* Return @range's lower bound. @range must not be empty. */ +static inline uint64_t range_lob (Range *range) +{ +assert (!range_is_empty (range)); +return range->begin; +} + +/* Return @range's upper bound. @range must not be empty. */ +static inline uint64_t range_upb (Range *range) +{ +assert (!range_is_empty (range)); +return range->end -1 ; +} + +/* +* Extend @range to the smallest interval that includes @extend_by, too. +* This must not extend @range to cover the interval [0,UINT64_MAX], +* because Range can't represent that. +*/ static inline void range_extend (Range *range,Range *extend_by) { -if (!extend_by->begin && !extend_by->end) { +if (range_is_empty (extend_by)) {return ; } -if (!range->begin && !range->end) { +if (range_is_empty (range)) { *range = *extend_by;return ; }
@@ -52,6 +131,8 @@ static inline void range_extend(Range *range, Range *extend_by)if (range->end -1 < extend_by->end -1 ) { range->end = extend_by->end; } +/* Must not extend to { .begin = 0, .end = 0 }: */ +assert (!range_is_empty (range)); }/* Get last byte of a range from offset + length.
hw/i386/acpi-build.c +19 -16
@@ -236,18 +236,20 @@ static void acpi_get_pci_holes(Range *hole, Range *hole64) pci_host =acpi_get_i386_pci_host ();g_assert (pci_host); - hole->begin =object_property_get_int (pci_host, -PCI_HOST_PROP_PCI_HOLE_START , -NULL ); - hole->end =object_property_get_int (pci_host, -PCI_HOST_PROP_PCI_HOLE_END , -NULL ); - hole64->begin =object_property_get_int (pci_host, -PCI_HOST_PROP_PCI_HOLE64_START , -NULL ); - hole64->end =object_property_get_int (pci_host, -PCI_HOST_PROP_PCI_HOLE64_END , -NULL ); +range_set_bounds1 (hole, +object_property_get_int (pci_host, +PCI_HOST_PROP_PCI_HOLE_START , +NULL ), +object_property_get_int (pci_host, +PCI_HOST_PROP_PCI_HOLE_END , +NULL )); +range_set_bounds1 (hole64, +object_property_get_int (pci_host, +PCI_HOST_PROP_PCI_HOLE64_START , +NULL ), +object_property_get_int (pci_host, +PCI_HOST_PROP_PCI_HOLE64_END , +NULL )); }#define ACPI_PORT_SMI_CMD 0x00b2/* TODO: this is APM_CNT_IOPORT */
@@ -2047,7 +2049,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, 0, 0x000A0000, 0x000BFFFF, 0, 0x00020000));crs_replace_with_free_ranges (mem_ranges, - pci_hole->begin, pci_hole->end -1 ); +range_lob (pci_hole), +range_upb (pci_hole));for (i =0 ; i < mem_ranges->len; i++) { entry =g_ptr_array_index (mem_ranges, i); aml_append(crs,
@@ -2057,12 +2060,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, 0, entry->limit - entry->base + 1)); } -if (pci_hole64->begin) { +if (!range_is_empty (pci_hole64)) {aml_append (crs,aml_qword_memory (AML_POS_DECODE ,AML_MIN_FIXED ,AML_MAX_FIXED ,AML_CACHEABLE ,AML_READ_WRITE , -0 , pci_hole64->begin, pci_hole64->end -1 ,0 , - pci_hole64->end - pci_hole64->begin)); +0 ,range_lob (pci_hole64),range_upb (pci_hole64),0 , +range_upb (pci_hole64) +1 -range_lob (pci_hole64))); }if (misc->tpm_version !=TPM_VERSION_UNSPEC ) {
hw/pci-host/piix.c +18 -8
@@ -221,8 +221,12 @@ static void i440fx_pcihost_get_pci_hole_start(Object *obj, Visitor *v, Error **errp) {I440FXState *s =I440FX_PCI_HOST_BRIDGE (obj); -uint32_t value = s->pci_hole.begin; +uint64_t val64; +uint32_t value; + val64 =range_is_empty (&s->pci_hole) ?0 :range_lob (&s->pci_hole); + value = val64; +assert (value == val64);visit_type_uint32 (v, name, &value, errp); }
@@ -231,8 +235,12 @@ static void i440fx_pcihost_get_pci_hole_end(Object *obj, Visitor *v, Error **errp) {I440FXState *s =I440FX_PCI_HOST_BRIDGE (obj); -uint32_t value = s->pci_hole.end; +uint64_t val64; +uint32_t value; + val64 =range_is_empty (&s->pci_hole) ?0 :range_upb (&s->pci_hole) +1 ; + value = val64; +assert (value == val64);visit_type_uint32 (v, name, &value, errp); }
@@ -242,10 +250,11 @@ static void i440fx_pcihost_get_pci_hole64_start(Object *obj, Visitor *v, {PCIHostState *h =PCI_HOST_BRIDGE (obj);Range w64; +uint64_t value;pci_bus_get_w64_range (h->bus, &w64); - -visit_type_uint64 (v, name, &w64.begin, errp); + value =range_is_empty (&w64) ?0 :range_lob (&w64); +visit_type_uint64 (v, name, &value, errp); } static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v,
@@ -254,10 +263,11 @@ static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v, {PCIHostState *h =PCI_HOST_BRIDGE (obj);Range w64; +uint64_t value;pci_bus_get_w64_range (h->bus, &w64); - -visit_type_uint64 (v, name, &w64.end, errp); + value =range_is_empty (&w64) ?0 :range_upb (&w64) +1 ; +visit_type_uint64 (v, name, &value, errp); }static void i440fx_pcihost_initfn (Object *obj)
@@ -344,8 +354,8 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type, f->ram_memory = ram_memory; i440fx =I440FX_PCI_HOST_BRIDGE (dev); - i440fx->pci_hole.begin = below_4g_mem_size; - i440fx->pci_hole.end =IO_APIC_DEFAULT_ADDRESS ; +range_set_bounds (&i440fx->pci_hole, below_4g_mem_size, +IO_APIC_DEFAULT_ADDRESS -1 );/* setup pci memory mapping */ pc_pci_as_mapping_init(OBJECT(f), f->system_memory,
hw/pci-host/q35.c +27 -14
91 lines not on this page · raw message
hw/pci/pci.c +9 -8
@@ -2533,13 +2533,13 @@ static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, void *opaque)if (limit >= base) {Range pref_range; - pref_range.begin = base; - pref_range.end = limit +1 ; +range_set_bounds (&pref_range, base, limit);range_extend (range, &pref_range); } }for (i =0 ; i <PCI_NUM_REGIONS ; ++i) {PCIIORegion *r = &dev->io_regions[i]; +pcibus_t lob, upb;Range region_range; if (!r->size ||
@@ -2547,16 +2547,17 @@ static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, void *opaque) !(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64)) {continue ; } - region_range.begin =pci_bar_address (dev, i, r->type, r->size); - region_range.end = region_range.begin + r->size; -if (region_range.begin ==PCI_BAR_UNMAPPED ) { + lob =pci_bar_address (dev, i, r->type, r->size); + upb = lob + r->size -1 ; +if (lob ==PCI_BAR_UNMAPPED ) {continue ; } - region_range.begin =MAX (region_range.begin,0x1ULL <<32 ); + lob =MAX (lob,0x1ULL <<32 ); -if (region_range.end -1 >= region_range.begin) { +if (upb >= lob) { +range_set_bounds (®ion_range, lob, upb);range_extend (range, ®ion_range); } }
@@ -2564,7 +2565,7 @@ static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, void *opaque)void pci_bus_get_w64_range (PCIBus *bus,Range *range) { - range->begin = range->end =0 ; +range_make_empty (range);pci_for_each_device_under_bus (bus, pci_dev_get_w64, range); }
qapi/string-input-visitor.c +8 -12
@@ -59,8 +59,7 @@ static int parse_str(StringInputVisitor *siv, const char *name, Error **errp)if (errno ==0 && endptr > str) {if (*endptr =='\0' ) { cur =g_malloc0 (sizeof (*cur)); - cur->begin = start; - cur->end = start +1 ; +range_set_bounds (cur, start, start); siv->ranges =range_list_insert (siv->ranges, cur); cur =NULL ; str =NULL ;
@@ -73,16 +72,14 @@ static int parse_str(StringInputVisitor *siv, const char *name, Error **errp) end < start + 65536)) {if (*endptr =='\0' ) { cur =g_malloc0 (sizeof (*cur)); - cur->begin = start; - cur->end = end +1 ; +range_set_bounds (cur, start, end); siv->ranges =range_list_insert (siv->ranges, cur); cur =NULL ; str =NULL ; }else if (*endptr ==',' ) { str = endptr +1 ; cur =g_malloc0 (sizeof (*cur)); - cur->begin = start; - cur->end = end +1 ; +range_set_bounds (cur, start, end); siv->ranges =range_list_insert (siv->ranges, cur); cur =NULL ; }else {
@@ -94,8 +91,7 @@ static int parse_str(StringInputVisitor *siv, const char *name, Error **errp) }else if (*endptr ==',' ) { str = endptr +1 ; cur =g_malloc0 (sizeof (*cur)); - cur->begin = start; - cur->end = start +1 ; +range_set_bounds (cur, start, start); siv->ranges =range_list_insert (siv->ranges, cur); cur =NULL ; }else {
@@ -134,7 +130,7 @@ start_list(Visitor *v, const char *name, GenericList **list, size_t size,if (siv->cur_range) {Range *r = siv->cur_range->data;if (r) { - siv->cur = r->begin; + siv->cur =range_lob (r); } *list =g_malloc0 (size); }else {
@@ -156,7 +152,7 @@ static GenericList *next_list(Visitor *v, GenericList *tail, size_t size)return NULL ; } -if (siv->cur < r->begin || siv->cur >= r->end) { +if (!range_contains (r, siv->cur)) { siv->cur_range =g_list_next (siv->cur_range);if (!siv->cur_range) {return NULL ;
@@ -165,7 +161,7 @@ static GenericList *next_list(Visitor *v, GenericList *tail, size_t size)if (!r) {return NULL ; } - siv->cur = r->begin; + siv->cur =range_lob (r); } tail->next =g_malloc0 (size);
@@ -208,7 +204,7 @@ static void parse_type_int64(Visitor *v, const char *name, int64_t *obj, goto error; } - siv->cur = r->begin; + siv->cur =range_lob (r); } *obj = siv->cur;
qapi/string-output-visitor.c +9 -9
@@ -83,8 +83,8 @@ static void string_output_set(StringOutputVisitor *sov, char *string)static void string_output_append (StringOutputVisitor *sov,int64_t a) {Range *r =g_malloc0 (sizeof (*r)); - r->begin = a; - r->end = a +1 ; + +range_set_bounds (r, a, a); sov->ranges =range_list_insert (sov->ranges, r); }
@@ -92,28 +92,28 @@ static void string_output_append_range(StringOutputVisitor *sov, int64_t s, int64_t e) {Range *r =g_malloc0 (sizeof (*r)); - r->begin = s; - r->end = e +1 ; + +range_set_bounds (r, s, e); sov->ranges =range_list_insert (sov->ranges, r); }static void format_string (StringOutputVisitor *sov,Range *r,bool next,bool human) { -if (r->end - r->begin >1 ) { +if (range_lob (r) !=range_upb (r)) {if (human) {g_string_append_printf (sov->string,"0x%" PRIx64"-0x%" PRIx64, - r->begin, r->end -1 ); +range_lob (r),range_upb (r)); }else {g_string_append_printf (sov->string,"%" PRId64"-%" PRId64, - r->begin, r->end -1 ); +range_lob (r),range_upb (r)); } }else {if (human) { -g_string_append_printf (sov->string,"0x%" PRIx64, r->begin); +g_string_append_printf (sov->string,"0x%" PRIx64,range_lob (r)); }else { -g_string_append_printf (sov->string,"%" PRId64, r->begin); +g_string_append_printf (sov->string,"%" PRId64,range_lob (r)); } }if (next) {
util/log.c +2 -3
@@ -132,7 +132,7 @@ bool qemu_log_in_addr_range(uint64_t addr)int i =0 ;for (i =0 ; i < debug_regions->len; i++) {Range *range = &g_array_index (debug_regions, Range, i); -if (addr >= range->begin && addr <= range->end -1 ) { +if (range_contains (range, addr)) {return true; } }
@@ -208,8 +208,7 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)error_setg (errp,"Invalid range" ); goto out; } - range.begin = lob; - range.end = upb +1 ; +range_set_bounds (&range, lob, upb);g_array_append_val (debug_regions, range); } out:
util/range.c +1 -2
@@ -46,8 +46,7 @@ GList *range_list_insert(GList *list, Range *data) {GList *l; -/* Range lists require no empty ranges */ -assert (data->begin < data->end || (data->begin && !data->end)); +assert (!range_is_empty (data));/* Skip all list elements strictly less than data */ for (l = list; l &&range_compare (l->data, data) <0 ; l = l->next) {
Signature · 1 line
MST
[Qemu-devel] [PULL 15/36] range: Replace internal representation of Range
In reply to a message not in the archiveFrom: Markus Armbruster <[email protected]>
Range represents a range as follows. Member @start is the inclusive lower bound, member @end is the exclusive upper bound. Zero @end is
special: if @start is also zero, the range is empty, else @end is to be interpreted as 2^64. No other empty ranges may occur.
The range [0,2^64-1] cannot be represented. If you try to create it with range_set_bounds1(), you get the empty range instead. If you try to create it with range_set_bounds() or range_extend(), assertions fail. Before range_set_bounds() existed, the open-coded creation usually got you the empty range instead. Open deathtrap.
Moreover, the code dealing with the janus-faced @end is too clever by half.
Dumb this down to a more pedestrian representation: members @lob and @upb are inclusive lower and upper bounds. The empty range is encoded as @lob = 1, @upb = 0.
--- include/qemu/range.h | 56 +++++++++++++++++++++++++--------------------------- util/range.c | 16 +++++++-------- 2 files changed, 34 insertions(+), 38 deletions(-)
include/qemu/range.h +27 -29
@@ -26,37 +26,38 @@/* * Operations on 64 bit address ranges. * Notes: -* - ranges must not wrap around 0, but can include the last byte ~0x0LL. -* - this can not represent a full 0 to ~0x0LL range. +* - Ranges must not wrap around 0, but can include UINT64_MAX. */ -/* A structure representing a range of addresses. */ struct Range { -uint64_t begin;/* First byte of the range, or 0 if empty. */ -uint64_t end;/* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */ +/* +* Do not access members directly, use the functions! +* A non-empty range has @lob <= @upb. +* An empty range has @lob == @upb + 1. +*/ +uint64_t lob;/* inclusive lower bound */ +uint64_t upb;/* inclusive upper bound */ };static inline void range_invariant (Range *range) { -assert ((!range->begin && !range->end)/* empty */ - || range->begin <= range->end -1 );/* non-empty */ +assert (range->lob <= range->upb || range->lob == range->upb +1 ); }/* Compound literal encoding the empty range */ -#define range_empty ((Range){ .begin = 0, .end = 0 }) +#define range_empty ((Range){ .lob = 1, .upb = 0 })/* Is @range empty? */ static inline bool range_is_empty (Range *range) {range_invariant (range); -return !range->begin && !range->end; +return range->lob > range->upb; }/* Does @range contain @val? */ static inline bool range_contains (Range *range,uint64_t val) { -return !range_is_empty (range) - && val >= range->begin && val <= range->end -1 ; +return val >= range->lob && val <= range->upb; }/* Initialize @range to the empty range */
@@ -71,14 +72,11 @@ static inline void range_make_empty(Range *range)* Both bounds are inclusive. * The interval must not be empty, i.e. @lob must be less than or * equal @upb. -* The interval must not be [0,UINT64_MAX], because Range can't -* represent that. */ static inline void range_set_bounds (Range *range,uint64_t lob,uint64_t upb) { -assert (lob <= upb); - range->begin = lob; - range->end = upb +1 ;/* may wrap to zero, that's okay */ + range->lob = lob; + range->upb = upb;assert (!range_is_empty (range)); }
@@ -91,8 +89,12 @@ static inline void range_set_bounds(Range *range, uint64_t lob, uint64_t upb)static inline void range_set_bounds1 (Range *range,uint64_t lob,uint64_t upb_plus1) { - range->begin = lob; - range->end = upb_plus1; +if (!lob && !upb_plus1) { + *range = range_empty; + }else { + range->lob = lob; + range->upb = upb_plus1 -1 ; + }range_invariant (range); }
@@ -100,20 +102,18 @@ static inline void range_set_bounds1(Range *range,static inline uint64_t range_lob (Range *range) {assert (!range_is_empty (range)); -return range->begin; +return range->lob; }/* Return @range's upper bound. @range must not be empty. */ static inline uint64_t range_upb (Range *range) {assert (!range_is_empty (range)); -return range->end -1 ; +return range->upb; }/* * Extend @range to the smallest interval that includes @extend_by, too. -* This must not extend @range to cover the interval [0,UINT64_MAX], -* because Range can't represent that. */ static inline void range_extend (Range *range,Range *extend_by) {
@@ -124,15 +124,13 @@ static inline void range_extend(Range *range, Range *extend_by) *range = *extend_by;return ; } -if (range->begin > extend_by->begin) { - range->begin = extend_by->begin; +if (range->lob > extend_by->lob) { + range->lob = extend_by->lob; } -/* Compare last byte in case region ends at ~0x0LL */ -if (range->end -1 < extend_by->end -1 ) { - range->end = extend_by->end; +if (range->upb < extend_by->upb) { + range->upb = extend_by->upb; } -/* Must not extend to { .begin = 0, .end = 0 }: */ -assert (!range_is_empty (range)); +range_invariant (range); }/* Get last byte of a range from offset + length.
util/range.c +7 -9
@@ -22,20 +22,18 @@#include "qemu/range.h" /* -* Operations on 64 bit address ranges. -* Notes: -* - ranges must not wrap around 0, but can include the last byte ~0x0LL. -* - this can not represent a full 0 to ~0x0LL range. +* Return -1 if @a < @b, 1 @a > @b, and 0 if they touch or overlap. +* Both @a and @b must not be empty. */ - -/* Return -1 if @a < @b, 1 if greater, and 0 if they touch or overlap. */ static inline int range_compare (Range *a,Range *b) { -/* Zero a->end is 2**64, and therefore not less than any b->begin */ -if (a->end && a->end < b->begin) { +assert (!range_is_empty (a) && !range_is_empty (b)); + +/* Careful, avoid wraparound */ +if (b->lob && b->lob -1 > a->upb) {return -1 ; } -if (b->end && a->begin > b->end) { +if (a->lob && a->lob -1 > b->upb) {return 1 ; }return 0 ;
Signature · 1 line
MST
[Qemu-devel] [PULL 16/36] log: Permit -dfilter 0..0xffffffffffffffff
In reply to a message not in the archiveFrom: Markus Armbruster <[email protected]>
Works fine since the previous commit fixed the underlying range data type. Of course it filters out nothing, but so does 0..1,2..0xffffffffffffffff, and we don't bother rejecting that either.
--- tests/test-logging.c | 5 +++-- util/log.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
tests/test-logging.c +3 -2
@@ -73,8 +73,9 @@ static void test_parse_range(void)g_assert_false (qemu_log_in_addr_range (UINT64_MAX -1 ));qemu_set_dfilter_ranges ("0..0xffffffffffffffff" , &err); -error_free_or_abort (&err); - +g_assert (qemu_log_in_addr_range (0 )); +g_assert (qemu_log_in_addr_range (UINT64_MAX )); +qemu_set_dfilter_ranges ("2..1" , &err);error_free_or_abort (&err);
util/log.c +1 -1
@@ -204,7 +204,7 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)default :g_assert_not_reached (); } -if (lob > upb || (lob ==0 && upb ==UINT64_MAX )) { +if (lob > upb) {error_setg (errp,"Invalid range" ); goto out; }
Signature · 1 line
MST
[Qemu-devel] [PULL 17/36] tests: acpi: add CPU hotplug testcase
In reply to a message not in the archiveFrom: Igor Mammedov <[email protected]>
Test with:
-smp 2,cores=3,sockets=2,maxcpus=6
to capture sparse APIC ID values that default AMD CPU has in above configuration.
--- tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
tests/bios-tables-test.c +28 -0
@@ -801,6 +801,32 @@ static void test_acpi_q35_tcg_bridge(void)free_test_data (&data); } +static void test_acpi_piix4_tcg_cphp (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".cphp" ; +test_acpi_one ("-machine accel=tcg" +" -smp 2,cores=3,sockets=2,maxcpus=6" , + &data); +free_test_data (&data); +} + +static void test_acpi_q35_tcg_cphp (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".cphp" ; +test_acpi_one ("-machine q35,accel=tcg" +" -smp 2,cores=3,sockets=2,maxcpus=6" , + &data); +free_test_data (&data); +} +static uint8_t ipmi_required_struct_types[] = {0 ,1 ,3 ,4 ,16 ,17 ,19 ,32 ,38 ,127 };
@@ -856,6 +882,8 @@ int main(int argc, char *argv[])qtest_add_func ("acpi/q35/tcg/bridge" , test_acpi_q35_tcg_bridge);qtest_add_func ("acpi/piix4/tcg/ipmi" , test_acpi_piix4_tcg_ipmi);qtest_add_func ("acpi/q35/tcg/ipmi" , test_acpi_q35_tcg_ipmi); +qtest_add_func ("acpi/piix4/tcg/cpuhp" , test_acpi_piix4_tcg_cphp); +qtest_add_func ("acpi/q35/tcg/cpuhp" , test_acpi_q35_tcg_cphp); } ret =g_test_run ();boot_sector_cleanup (disk);
Signature · 1 line
MST
[Qemu-devel] [PULL 18/36] tests: add APIC.cphp and DSDT.cphp blobs
In reply to a message not in the archiveFrom: Igor Mammedov <[email protected]>
--- tests/acpi-test-data/pc/APIC.cphp | Bin 0 -> 160 bytes tests/acpi-test-data/pc/DSDT.cphp | Bin 0 -> 6435 bytes tests/acpi-test-data/q35/APIC.cphp | Bin 0 -> 160 bytes tests/acpi-test-data/q35/DSDT.cphp | Bin 0 -> 9197 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/acpi-test-data/pc/APIC.cphp create mode 100644 tests/acpi-test-data/pc/DSDT.cphp create mode 100644 tests/acpi-test-data/q35/APIC.cphp create mode 100644 tests/acpi-test-data/q35/DSDT.cphp
tests/acpi-test-data/pc/APIC.cphp new file binary +0 -0
tests/acpi-test-data/pc/DSDT.cphp new file binary +0 -0
tests/acpi-test-data/q35/APIC.cphp new file binary +0 -0
tests/acpi-test-data/q35/DSDT.cphp new file binary +0 -0
Signature · 1 line
MST
[Qemu-devel] [PULL 19/36] tests/acpi: add pxb/pxb-pcie tests
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
Add an ivshmem device with 4G shared memory to
pxb in order to check the ACPI code of 64bit MMIO allocation.
--- tests/bios-tables-test.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
tests/bios-tables-test.c +37 -0
@@ -864,6 +864,41 @@ static void test_acpi_piix4_tcg_ipmi(void)free_test_data (&data); } +static void test_acpi_piix4_tcg_pxb (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".pxb" ; + data.required_struct_types = base_required_struct_types; + data.required_struct_types_len =ARRAY_SIZE (base_required_struct_types); +test_acpi_one ("-machine accel=tcg" +" -device pxb,id=pxb,bus_nr=0x80,bus=pci.0" +" -object memory-backend-file,size=4G,mem-path=/tmp/shmem,share,id=mb" +" -device ivshmem-plain,memdev=mb,bus=pxb" , + &data); +free_test_data (&data); +} + +static void test_acpi_q35_tcg_pxb_pcie (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".pxb_pcie" ; + data.required_struct_types = base_required_struct_types; + data.required_struct_types_len =ARRAY_SIZE (ipmi_required_struct_types); +test_acpi_one ("-machine q35,accel=tcg" +" -device pxb-pcie,id=pxb,bus_nr=0x80,bus=pcie.0" +" -device ioh3420,id=rp,bus=pxb,slot=1" +" -object memory-backend-file,size=4G,mem-path=/tmp/shmem,share,id=mb" +" -device ivshmem-plain,memdev=mb,bus=rp" , + &data); +free_test_data (&data); +} +int main (int argc,char *argv[]) {const char *arch =qtest_get_arch ();
@@ -884,6 +919,8 @@ int main(int argc, char *argv[])qtest_add_func ("acpi/q35/tcg/ipmi" , test_acpi_q35_tcg_ipmi);qtest_add_func ("acpi/piix4/tcg/cpuhp" , test_acpi_piix4_tcg_cphp);qtest_add_func ("acpi/q35/tcg/cpuhp" , test_acpi_q35_tcg_cphp); +qtest_add_func ("acpi/piix4/tcg/pxb" , test_acpi_piix4_tcg_pxb); +qtest_add_func ("acpi/q35/tcg/pxb-pcie" , test_acpi_q35_tcg_pxb_pcie); } ret =g_test_run ();boot_sector_cleanup (disk);
Signature · 1 line
MST
[Qemu-devel] [PULL 20/36] hw/pxb: declare pxb devices as not hot-pluggable
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
Prevent future issues when hotplug will work for devices attached to pxbs.
--- hw/pci-bridge/pci_expander_bridge.c | 2 ++ 1 file changed, 2 insertions(+)
hw/pci-bridge/pci_expander_bridge.c +2 -0
@@ -310,6 +310,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void *data) dc->desc ="PCI Expander Bridge" ; dc->props = pxb_dev_properties; + dc->hotpluggable = false;set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories); }
@@ -343,6 +344,7 @@ static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data) dc->desc ="PCI Express Expander Bridge" ; dc->props = pxb_dev_properties; + dc->hotpluggable = false;set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories); }
Signature · 1 line
MST
[Qemu-devel] [PULL 21/36] hw/acpi: fix a DSDT table issue when a pxb is present.
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
PXBs do not support hotplug so they don't have a PCNT function. Since the PXB's PCI root-bus is a child bus of bus 0, the build_dsdt code will add a call to the corresponding PCNT function.
Fix this by skipping the PCNT call for the above case. While at it skip also PCIe child buses.
--- hw/i386/acpi-build.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/i386/acpi-build.c +4 -0
@@ -597,6 +597,10 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, QLIST_FOREACH(sec, &bus->child, sibling) {int32_t devfn = sec->parent_dev->devfn; +if (pci_bus_is_root (sec) ||pci_bus_is_express (sec)) { +continue ; + } +aml_append (method,aml_name ("^S%.02X.PCNT" , devfn)); } }
Signature · 1 line
MST
[Qemu-devel] [PULL 22/36] acpi: refactor pxb crs computation
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
Instead of always passing both IO and MEM ranges when computing CRS ranges, define a new CrsRangeSet structure that include them both.
This is done before introducing a third type of range, 64-bit MEM, so it will be easier to pass them all around.
--- hw/i386/acpi-build.c | 81 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 31 deletions(-)
hw/i386/acpi-build.c +50 -31
@@ -748,6 +748,23 @@ static void crs_range_free(gpointer data)g_free (entry); } +typedef struct CrsRangeSet { +GPtrArray *io_ranges; +GPtrArray *mem_ranges; + }CrsRangeSet ; + +static void crs_range_set_init (CrsRangeSet *range_set) +{ + range_set->io_ranges =g_ptr_array_new_with_free_func (crs_range_free); + range_set->mem_ranges =g_ptr_array_new_with_free_func (crs_range_free); +} + +static void crs_range_set_free (CrsRangeSet *range_set) +{ +g_ptr_array_free (range_set->io_ranges, true); +g_ptr_array_free (range_set->mem_ranges, true); +} +static gint crs_range_compare (gconstpointer a,gconstpointer b) {CrsRangeEntry *entry_a = *(CrsRangeEntry **)a;
@@ -832,18 +849,17 @@ static void crs_range_merge(GPtrArray *range)g_ptr_array_free (tmp, true); } -static Aml *build_crs (PCIHostState *host, -GPtrArray *io_ranges,GPtrArray *mem_ranges) +static Aml *build_crs (PCIHostState *host,CrsRangeSet *range_set) {Aml *crs =aml_resource_template (); -GPtrArray *host_io_ranges =g_ptr_array_new_with_free_func (crs_range_free); -GPtrArray *host_mem_ranges =g_ptr_array_new_with_free_func (crs_range_free); +CrsRangeSet temp_range_set;CrsRangeEntry *entry;uint8_t max_bus =pci_bus_num (host->bus);uint8_t type;int devfn;int i; +crs_range_set_init (&temp_range_set);for (devfn =0 ; devfn <ARRAY_SIZE (host->bus->devices); devfn++) {uint64_t range_base, range_limit;PCIDevice *dev = host->bus->devices[devfn];
@@ -867,9 +883,11 @@ static Aml *build_crs(PCIHostState *host, }if (r->type &PCI_BASE_ADDRESS_SPACE_IO ) { -crs_range_insert (host_io_ranges, range_base, range_limit); +crs_range_insert (temp_range_set.io_ranges, + range_base, range_limit); }else {/* "memory" */ -crs_range_insert (host_mem_ranges, range_base, range_limit); +crs_range_insert (temp_range_set.mem_ranges, + range_base, range_limit); } }
@@ -888,7 +906,8 @@ static Aml *build_crs(PCIHostState *host,* that do not support multiple root buses */ if (range_base && range_base <= range_limit) { -crs_range_insert (host_io_ranges, range_base, range_limit); +crs_range_insert (temp_range_set.io_ranges, + range_base, range_limit); } range_base =
@@ -901,7 +920,8 @@ static Aml *build_crs(PCIHostState *host,* that do not support multiple root buses */ if (range_base && range_base <= range_limit) { -crs_range_insert (host_mem_ranges, range_base, range_limit); +crs_range_insert (temp_range_set.mem_ranges, + range_base, range_limit); } range_base =
@@ -914,35 +934,36 @@ static Aml *build_crs(PCIHostState *host,* that do not support multiple root buses */ if (range_base && range_base <= range_limit) { -crs_range_insert (host_mem_ranges, range_base, range_limit); +crs_range_insert (temp_range_set.mem_ranges, + range_base, range_limit); } } } -crs_range_merge (host_io_ranges); -for (i =0 ; i < host_io_ranges->len; i++) { - entry =g_ptr_array_index (host_io_ranges, i); +crs_range_merge (temp_range_set.io_ranges); +for (i =0 ; i < temp_range_set.io_ranges->len; i++) { + entry =g_ptr_array_index (temp_range_set.io_ranges, i);aml_append (crs,aml_word_io (AML_MIN_FIXED ,AML_MAX_FIXED ,AML_POS_DECODE ,AML_ENTIRE_RANGE ,0 , entry->base, entry->limit,0 , entry->limit - entry->base +1 )); -crs_range_insert (io_ranges, entry->base, entry->limit); +crs_range_insert (range_set->io_ranges, entry->base, entry->limit); } -g_ptr_array_free (host_io_ranges, true); -crs_range_merge (host_mem_ranges); -for (i =0 ; i < host_mem_ranges->len; i++) { - entry =g_ptr_array_index (host_mem_ranges, i); +crs_range_merge (temp_range_set.mem_ranges); +for (i =0 ; i < temp_range_set.mem_ranges->len; i++) { + entry =g_ptr_array_index (temp_range_set.mem_ranges, i);aml_append (crs,aml_dword_memory (AML_POS_DECODE ,AML_MIN_FIXED ,AML_MAX_FIXED ,AML_NON_CACHEABLE ,AML_READ_WRITE ,0 , entry->base, entry->limit,0 , entry->limit - entry->base +1 )); -crs_range_insert (mem_ranges, entry->base, entry->limit); +crs_range_insert (range_set->mem_ranges, entry->base, entry->limit); } -g_ptr_array_free (host_mem_ranges, true); + +crs_range_set_free (&temp_range_set); aml_append(crs, aml_word_bus_number(AML_MIN_FIXED, AML_MAX_FIXED, AML_POS_DECODE,
@@ -1899,8 +1920,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, {CrsRangeEntry *entry;Aml *dsdt, *sb_scope, *scope, *dev, *method, *field, *pkg, *crs; -GPtrArray *mem_ranges =g_ptr_array_new_with_free_func (crs_range_free); -GPtrArray *io_ranges =g_ptr_array_new_with_free_func (crs_range_free); +CrsRangeSet crs_range_set;PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (machine);uint32_t nr_mem = machine->ram_slots;
@@ -1989,6 +2009,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, }aml_append (dsdt, scope); +crs_range_set_init (&crs_range_set); bus =PC_MACHINE (machine)->bus;if (bus) { QLIST_FOREACH(bus, &bus->child, sibling) {
@@ -2015,8 +2036,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, }aml_append (dev,build_prt (false)); - crs =build_crs (PCI_HOST_BRIDGE (BUS (bus)->parent), - io_ranges, mem_ranges); + crs =build_crs (PCI_HOST_BRIDGE (BUS (bus)->parent), &crs_range_set);aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev);aml_append (dsdt, scope);
@@ -2037,9 +2057,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,AML_POS_DECODE ,AML_ENTIRE_RANGE , 0x0000, 0x0000, 0x0CF7, 0x0000, 0x0CF8)); -crs_replace_with_free_ranges (io_ranges,0x0D00 ,0xFFFF ); -for (i =0 ; i < io_ranges->len; i++) { - entry =g_ptr_array_index (io_ranges, i); +crs_replace_with_free_ranges (crs_range_set.io_ranges,0x0D00 ,0xFFFF ); +for (i =0 ; i < crs_range_set.io_ranges->len; i++) { + entry =g_ptr_array_index (crs_range_set.io_ranges, i); aml_append(crs, aml_word_io(AML_MIN_FIXED, AML_MAX_FIXED, AML_POS_DECODE, AML_ENTIRE_RANGE,
@@ -2052,11 +2072,11 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,AML_CACHEABLE ,AML_READ_WRITE , 0, 0x000A0000, 0x000BFFFF, 0, 0x00020000)); -crs_replace_with_free_ranges (mem_ranges, +crs_replace_with_free_ranges (crs_range_set.mem_ranges,range_lob (pci_hole),range_upb (pci_hole)); -for (i =0 ; i < mem_ranges->len; i++) { - entry =g_ptr_array_index (mem_ranges, i); +for (i =0 ; i < crs_range_set.mem_ranges->len; i++) { + entry =g_ptr_array_index (crs_range_set.mem_ranges, i); aml_append(crs, aml_dword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED, AML_NON_CACHEABLE, AML_READ_WRITE,
@@ -2091,8 +2111,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev); -g_ptr_array_free (io_ranges, true); -g_ptr_array_free (mem_ranges, true); +crs_range_set_free (&crs_range_set);/* reserve PCIHP resources */ if (pm->pcihp_io_len) {
Signature · 1 line
MST
[Qemu-devel] [PULL 23/36] hw/apci: handle 64-bit MMIO regions correctly
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
In build_crs(), the calculation and merging of the ranges already happens in 64-bit, but the entry boundaries are silently truncated to 32-bit in the call to aml_dword_memory(). Fix it by handling the 64-bit MMIO ranges separately. This fixes 64-bit BARs behind PXBs.
--- hw/i386/acpi-build.c | 54 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-)
hw/i386/acpi-build.c +45 -9
@@ -751,18 +751,22 @@ static void crs_range_free(gpointer data)typedef struct CrsRangeSet {GPtrArray *io_ranges;GPtrArray *mem_ranges; +GPtrArray *mem_64bit_ranges; }CrsRangeSet ;static void crs_range_set_init (CrsRangeSet *range_set) { range_set->io_ranges =g_ptr_array_new_with_free_func (crs_range_free); range_set->mem_ranges =g_ptr_array_new_with_free_func (crs_range_free); + range_set->mem_64bit_ranges = +g_ptr_array_new_with_free_func (crs_range_free); }static void crs_range_set_free (CrsRangeSet *range_set) {g_ptr_array_free (range_set->io_ranges, true);g_ptr_array_free (range_set->mem_ranges, true); +g_ptr_array_free (range_set->mem_64bit_ranges, true); }static gint crs_range_compare (gconstpointer a,gconstpointer b)
@@ -920,8 +924,14 @@ static Aml *build_crs(PCIHostState *host, CrsRangeSet *range_set)* that do not support multiple root buses */ if (range_base && range_base <= range_limit) { -crs_range_insert (temp_range_set.mem_ranges, - range_base, range_limit); +uint64_t length = range_limit - range_base +1 ; +if (range_limit <=UINT32_MAX && length <=UINT32_MAX ) { +crs_range_insert (temp_range_set.mem_ranges, + range_base, range_limit); + }else { +crs_range_insert (temp_range_set.mem_64bit_ranges, + range_base, range_limit); + } } range_base =
@@ -934,8 +944,14 @@ static Aml *build_crs(PCIHostState *host, CrsRangeSet *range_set)* that do not support multiple root buses */ if (range_base && range_base <= range_limit) { -crs_range_insert (temp_range_set.mem_ranges, - range_base, range_limit); +uint64_t length = range_limit - range_base +1 ; +if (range_limit <=UINT32_MAX && length <=UINT32_MAX ) { +crs_range_insert (temp_range_set.mem_ranges, + range_base, range_limit); + }else { +crs_range_insert (temp_range_set.mem_64bit_ranges, + range_base, range_limit); + } } } }
@@ -963,6 +979,19 @@ static Aml *build_crs(PCIHostState *host, CrsRangeSet *range_set)crs_range_insert (range_set->mem_ranges, entry->base, entry->limit); } +crs_range_merge (temp_range_set.mem_64bit_ranges); +for (i =0 ; i < temp_range_set.mem_64bit_ranges->len; i++) { + entry =g_ptr_array_index (temp_range_set.mem_64bit_ranges, i); +aml_append (crs, +aml_qword_memory (AML_POS_DECODE ,AML_MIN_FIXED , +AML_MAX_FIXED ,AML_NON_CACHEABLE , +AML_READ_WRITE , +0 , entry->base, entry->limit,0 , + entry->limit - entry->base +1 )); +crs_range_insert (range_set->mem_64bit_ranges, + entry->base, entry->limit); + } +crs_range_set_free (&temp_range_set); aml_append(crs,
@@ -2085,11 +2114,18 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, }if (!range_is_empty (pci_hole64)) { -aml_append (crs, -aml_qword_memory (AML_POS_DECODE ,AML_MIN_FIXED ,AML_MAX_FIXED , -AML_CACHEABLE ,AML_READ_WRITE , -0 ,range_lob (pci_hole64),range_upb (pci_hole64),0 , -range_upb (pci_hole64) +1 -range_lob (pci_hole64))); +crs_replace_with_free_ranges (crs_range_set.mem_64bit_ranges, +range_lob (pci_hole64), +range_upb (pci_hole64)); +for (i =0 ; i < crs_range_set.mem_64bit_ranges->len; i++) { + entry =g_ptr_array_index (crs_range_set.mem_64bit_ranges, i); +aml_append (crs, +aml_qword_memory (AML_POS_DECODE ,AML_MIN_FIXED , +AML_MAX_FIXED , +AML_CACHEABLE ,AML_READ_WRITE , +0 , entry->base, entry->limit, +0 , entry->limit - entry->base +1 )); + } }if (misc->tpm_version !=TPM_VERSION_UNSPEC ) {
Signature · 1 line
MST
[Qemu-devel] [PULL 24/36] tests/acpi: Add pxb/pxb-pcie tests blobs
In reply to a message not in the archiveFrom: Marcel Apfelbaum <[email protected]>
--- tests/acpi-test-data/pc/DSDT.pxb | Bin 0 -> 6280 bytes tests/acpi-test-data/q35/DSDT.pxb_pcie | Bin 0 -> 9098 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/acpi-test-data/pc/DSDT.pxb create mode 100644 tests/acpi-test-data/q35/DSDT.pxb_pcie
tests/acpi-test-data/pc/DSDT.pxb new file binary +0 -0
tests/acpi-test-data/q35/DSDT.pxb_pcie new file binary +0 -0
Signature · 1 line
MST
[Qemu-devel] [PULL 25/36] change pvscsi_init_msi() type to void
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Nobody use its return value, so change the type to void.
--- hw/scsi/vmw_pvscsi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/scsi/vmw_pvscsi.c +1 -3
@@ -1056,7 +1056,7 @@ pvscsi_io_read(void *opaque, hwaddr addr, unsigned size) } -static bool +static void pvscsi_init_msi (PVSCSIState *s) {int res;
@@ -1070,8 +1070,6 @@ pvscsi_init_msi(PVSCSIState *s) }else { s->msi_used = true; } - -return s->msi_used; } static void
Signature · 1 line
MST
[Qemu-devel] [PULL 26/36] usb xhci: change msi/msix property type
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Quoted 1 line
From bit to enum OnOffAuto
--- hw/usb/hcd-xhci.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
hw/usb/hcd-xhci.c +9 -7
@@ -461,6 +461,8 @@ struct XHCIState {uint32_t numslots;uint32_t flags;uint32_t max_pstreams_mask; +OnOffAuto msi; +OnOffAuto msix;/* Operational Registers */ uint32_t usbcmd;
@@ -498,9 +500,7 @@ typedef struct XHCIEvRingSeg { } XHCIEvRingSeg;enum xhci_flags { -XHCI_FLAG_USE_MSI =1 , -XHCI_FLAG_USE_MSI_X , -XHCI_FLAG_SS_FIRST , +XHCI_FLAG_SS_FIRST =1 ,XHCI_FLAG_FORCE_PCIE_ENDCAP ,XHCI_FLAG_ENABLE_STREAMS , };
@@ -3648,10 +3648,12 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)assert (ret >=0 ); } -if (xhci_get_flag (xhci,XHCI_FLAG_USE_MSI )) { +if (xhci->msi !=ON_OFF_AUTO_OFF ) { +/* TODO check for errors */ msi_init (dev,0x70 , xhci->numintrs, true, false); } -if (xhci_get_flag (xhci,XHCI_FLAG_USE_MSI_X )) { +if (xhci->msix !=ON_OFF_AUTO_OFF ) { +/* TODO check for errors */ msix_init(dev, xhci->numintrs, &xhci->mem, 0, OFF_MSIX_TABLE, &xhci->mem, 0, OFF_MSIX_PBA,
@@ -3872,8 +3874,8 @@ static const VMStateDescription vmstate_xhci = { };static Property xhci_properties[] = { -DEFINE_PROP_BIT ("msi" , XHCIState, flags,XHCI_FLAG_USE_MSI , true), -DEFINE_PROP_BIT ("msix" , XHCIState, flags,XHCI_FLAG_USE_MSI_X , true), +DEFINE_PROP_ON_OFF_AUTO ("msi" , XHCIState, msi,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_ON_OFF_AUTO ("msix" , XHCIState, msix,ON_OFF_AUTO_AUTO ),DEFINE_PROP_BIT ("superspeed-ports-first" , XHCIState, flags,XHCI_FLAG_SS_FIRST , true), DEFINE_PROP_BIT("force-pcie-endcap", XHCIState, flags,
Signature · 1 line
MST
[Qemu-devel] [PULL 27/36] intel-hda: change msi property type
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Quoted 1 line
From uint32 to enum OnOffAuto.
--- hw/audio/intel-hda.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/audio/intel-hda.c +5 -4
@@ -191,7 +191,7 @@ struct IntelHDAState {/* properties */ uint32_t debug; -uint32_t msi; +OnOffAuto msi;bool old_msi_addr; };
@@ -256,7 +256,7 @@ static void intel_hda_update_int_sts(IntelHDAState *d)static void intel_hda_update_irq (IntelHDAState *d) { -int msi = d->msi &&msi_enabled (&d->pci); +bool msi =msi_enabled (&d->pci);int level;intel_hda_update_int_sts (d);
@@ -1143,7 +1143,8 @@ static void intel_hda_realize(PCIDevice *pci, Error **errp)memory_region_init_io (&d->mmio,OBJECT (d), &intel_hda_mmio_ops, d,"intel-hda" ,0x4000 );pci_register_bar (&d->pci,0 ,0 , &d->mmio); -if (d->msi) { +if (d->msi !=ON_OFF_AUTO_OFF ) { +/* TODO check for errors */ msi_init (&d->pci, d->old_msi_addr ?0x50 :0x60 ,1 , true, false); }
@@ -1235,7 +1236,7 @@ static const VMStateDescription vmstate_intel_hda = {static Property intel_hda_properties[] = {DEFINE_PROP_UINT32 ("debug" , IntelHDAState, debug,0 ), -DEFINE_PROP_UINT32 ("msi" , IntelHDAState, msi,1 ), +DEFINE_PROP_ON_OFF_AUTO ("msi" , IntelHDAState, msi,ON_OFF_AUTO_AUTO ),DEFINE_PROP_BOOL ("old_msi_addr" , IntelHDAState, old_msi_addr, false),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
MST
[Qemu-devel] [PULL 28/36] mptsas: change msi property type
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Quoted 1 line
From uint32 to enum OnOffAuto, and give it a shorter name.
--- hw/scsi/mptsas.h | 3 ++- hw/scsi/mptsas.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-)
hw/scsi/mptsas.h +2 -1
@@ -27,7 +27,8 @@ struct MPTSASState {MemoryRegion diag_io;QEMUBH *request_bh; -uint32_t msi_available; +/* properties */ +OnOffAuto msi;uint64_t sas_addr;bool msi_in_use;
hw/scsi/mptsas.c +3 -2
@@ -1284,8 +1284,9 @@ static void mptsas_scsi_init(PCIDevice *dev, Error **errp)memory_region_init_io (&s->diag_io,OBJECT (s), &mptsas_diag_ops, s,"mptsas-diag" ,0x10000 ); -if (s->msi_available && +if (s->msi !=ON_OFF_AUTO_OFF &&msi_init (dev,0 ,1 , true, false) >=0 ) { +/* TODO check for errors */ s->msi_in_use = true; }
@@ -1403,7 +1404,7 @@ static const VMStateDescription vmstate_mptsas = {static Property mptsas_properties[] = {DEFINE_PROP_UINT64 ("sas_address" , MPTSASState, sas_addr,0 ),/* TODO: test MSI support under Windows */ -DEFINE_PROP_BIT ("msi" , MPTSASState, msi_available,0 , true), +DEFINE_PROP_ON_OFF_AUTO ("msi" , MPTSASState, msi,ON_OFF_AUTO_AUTO ),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
MST
[Qemu-devel] [PULL 30/36] pci bridge dev: change msi property type
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Quoted 1 line
From bit to enum OnOffAuto.
--- hw/pci-bridge/pci_bridge_dev.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
hw/pci-bridge/pci_bridge_dev.c +7 -6
@@ -42,9 +42,10 @@ struct PCIBridgeDev {MemoryRegion bar;uint8_t chassis_nr; -#define PCI_BRIDGE_DEV_F_MSI_REQ 0 -#define PCI_BRIDGE_DEV_F_SHPC_REQ 1 +#define PCI_BRIDGE_DEV_F_SHPC_REQ 0uint32_t flags; + +OnOffAuto msi; };typedef struct PCIBridgeDev PCIBridgeDev ;
@@ -66,7 +67,7 @@ static int pci_bridge_dev_initfn(PCIDevice *dev) } }else {/* MSI is not applicable without SHPC */ - bridge_dev->flags &= ~(1 <<PCI_BRIDGE_DEV_F_MSI_REQ ); + bridge_dev->msi =ON_OFF_AUTO_OFF ; } err =slotid_cap_init (dev,0 , bridge_dev->chassis_nr,0 );
@@ -74,7 +75,7 @@ static int pci_bridge_dev_initfn(PCIDevice *dev) goto slotid_error; } -if ((bridge_dev->flags & (1 <<PCI_BRIDGE_DEV_F_MSI_REQ )) && +if (bridge_dev->msi !=ON_OFF_AUTO_OFF && msi_nonbroken) { err =msi_init (dev,0 ,1 , true, true);if (err <0 ) {
@@ -147,8 +148,8 @@ static Property pci_bridge_dev_properties[] = {/* Note: 0 is not a legal chassis number. */ DEFINE_PROP_UINT8 (PCI_BRIDGE_DEV_PROP_CHASSIS_NR , PCIBridgeDev, chassis_nr,0 ), -DEFINE_PROP_BIT (PCI_BRIDGE_DEV_PROP_MSI , PCIBridgeDev, flags, -PCI_BRIDGE_DEV_F_MSI_REQ , true), +DEFINE_PROP_ON_OFF_AUTO (PCI_BRIDGE_DEV_PROP_MSI , PCIBridgeDev, msi, +ON_OFF_AUTO_AUTO ),DEFINE_PROP_BIT (PCI_BRIDGE_DEV_PROP_SHPC , PCIBridgeDev, flags,PCI_BRIDGE_DEV_F_SHPC_REQ , true), DEFINE_PROP_END_OF_LIST(),
Signature · 1 line
MST
[Qemu-devel] [PULL 29/36] megasas: change msi/msix property type
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Quoted 1 line
From bit to enum OnOffAuto.
--- hw/scsi/megasas.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
hw/scsi/megasas.c +11 -17
@@ -48,11 +48,7 @@#define MEGASAS_FLAG_USE_JBOD 0#define MEGASAS_MASK_USE_JBOD (1 << MEGASAS_FLAG_USE_JBOD) -#define MEGASAS_FLAG_USE_MSI 1 -#define MEGASAS_MASK_USE_MSI (1 << MEGASAS_FLAG_USE_MSI) -#define MEGASAS_FLAG_USE_MSIX 2 -#define MEGASAS_MASK_USE_MSIX (1 << MEGASAS_FLAG_USE_MSIX) -#define MEGASAS_FLAG_USE_QUEUE64 3 +#define MEGASAS_FLAG_USE_QUEUE64 1#define MEGASAS_MASK_USE_QUEUE64 (1 << MEGASAS_FLAG_USE_QUEUE64)static const char *mfi_frame_desc[] = {
@@ -96,6 +92,8 @@ typedef struct MegasasState {int busy;int diag;int adp_reset; +OnOffAuto msi; +OnOffAuto msix;MegasasCmd *event_cmd;int event_locale;
@@ -159,12 +157,12 @@ static bool megasas_use_queue64(MegasasState *s)static bool megasas_use_msi (MegasasState *s) { -return s->flags &MEGASAS_MASK_USE_MSI ; +return s->msi !=ON_OFF_AUTO_OFF ; }static bool megasas_use_msix (MegasasState *s) { -return s->flags &MEGASAS_MASK_USE_MSIX ; +return s->msix !=ON_OFF_AUTO_OFF ; }static bool megasas_is_jbod (MegasasState *s)
@@ -2349,12 +2347,12 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)if (megasas_use_msi (s) &&msi_init (dev,0x50 ,1 , true, false)) { - s->flags &= ~MEGASAS_MASK_USE_MSI ; + s->msi =ON_OFF_AUTO_OFF ; }if (megasas_use_msix (s) &&msix_init (dev,15 , &s->mmio_io, b->mmio_bar,0x2000 , &s->mmio_io, b->mmio_bar,0x3800 ,0x68 )) { - s->flags &= ~MEGASAS_MASK_USE_MSIX ; + s->msix =ON_OFF_AUTO_OFF ; }if (pci_is_express (dev)) {pcie_endpoint_cap_init (dev,0xa0 );
@@ -2422,10 +2420,8 @@ static Property megasas_properties_gen1[] = { MEGASAS_DEFAULT_FRAMES),DEFINE_PROP_STRING ("hba_serial" , MegasasState, hba_serial),DEFINE_PROP_UINT64 ("sas_address" , MegasasState, sas_addr,0 ), -DEFINE_PROP_BIT ("use_msi" , MegasasState, flags, -MEGASAS_FLAG_USE_MSI , false), -DEFINE_PROP_BIT ("use_msix" , MegasasState, flags, -MEGASAS_FLAG_USE_MSIX , false), +DEFINE_PROP_ON_OFF_AUTO ("msi" , MegasasState, msi,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_ON_OFF_AUTO ("msix" , MegasasState, msix,ON_OFF_AUTO_AUTO ),DEFINE_PROP_BIT ("use_jbod" , MegasasState, flags,MEGASAS_FLAG_USE_JBOD , false), DEFINE_PROP_END_OF_LIST(),
@@ -2438,10 +2434,8 @@ static Property megasas_properties_gen2[] = { MEGASAS_GEN2_DEFAULT_FRAMES),DEFINE_PROP_STRING ("hba_serial" , MegasasState, hba_serial),DEFINE_PROP_UINT64 ("sas_address" , MegasasState, sas_addr,0 ), -DEFINE_PROP_BIT ("use_msi" , MegasasState, flags, -MEGASAS_FLAG_USE_MSI , true), -DEFINE_PROP_BIT ("use_msix" , MegasasState, flags, -MEGASAS_FLAG_USE_MSIX , true), +DEFINE_PROP_ON_OFF_AUTO ("msi" , MegasasState, msi,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_ON_OFF_AUTO ("msix" , MegasasState, msix,ON_OFF_AUTO_AUTO ),DEFINE_PROP_BIT ("use_jbod" , MegasasState, flags,MEGASAS_FLAG_USE_JBOD , false), DEFINE_PROP_END_OF_LIST(),
Signature · 1 line
MST
[Qemu-devel] [PULL 32/36] megasas: remove unnecessary megasas_use_msi()
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
megasas overwrites user configuration when msi_init fail to flag internal msi state, which is unsuitable. megasa_use_msi() is unnecessary, we can call msi_uninit() directly when unrealize, even no need to call msi_enabled() first.
--- hw/scsi/megasas.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
hw/scsi/megasas.c +2 -9
@@ -155,11 +155,6 @@ static bool megasas_use_queue64(MegasasState *s)return s->flags &MEGASAS_MASK_USE_QUEUE64 ; } -static bool megasas_use_msi (MegasasState *s) -{ -return s->msi !=ON_OFF_AUTO_OFF ; -} -static bool megasas_use_msix (MegasasState *s) {return s->msix !=ON_OFF_AUTO_OFF ;
@@ -2307,9 +2302,7 @@ static void megasas_scsi_uninit(PCIDevice *d)if (megasas_use_msix (s)) {msix_uninit (d, &s->mmio_io, &s->mmio_io); } -if (megasas_use_msi (s)) { -msi_uninit (d); - } +msi_uninit (d); }static const struct SCSIBusInfo megasas_scsi_info = {
@@ -2340,7 +2333,7 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)/* Interrupt pin 1 */ pci_conf[PCI_INTERRUPT_PIN ] =0x01 ; -if (megasas_use_msi (s)) { +if (s->msi !=ON_OFF_AUTO_OFF ) { ret =msi_init (dev,0x50 ,1 , true, false, &err);/* Any error other than -ENOTSUP(board's MSI support is broken) * is a programming error */
Signature · 1 line
MST
[Qemu-devel] [PULL 31/36] pci: Convert msi_init() to Error and fix callers to check it
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
msi_init() reports errors with error_report(), which is wrong when it's used in realize().
Fix by converting it to Error.
Fix its callers to handle failure instead of ignoring it.
For those callers who don't handle the failure, it might happen:
when user want msi on, but he doesn't get what he want because of msi_init fails silently.
--- include/hw/pci/msi.h | 3 ++- hw/audio/intel-hda.c | 24 ++++++++++++++++++++---- hw/ide/ich.c | 7 +++++-- hw/net/e1000e.c | 8 ++------ hw/net/vmxnet3.c | 37 ++++++++++++------------------------- hw/pci-bridge/ioh3420.c | 6 +++++- hw/pci-bridge/pci_bridge_dev.c | 20 ++++++++++++++++---- hw/pci-bridge/xio3130_downstream.c | 6 +++++- hw/pci-bridge/xio3130_upstream.c | 6 +++++- hw/pci/msi.c | 11 ++++++++--- hw/scsi/megasas.c | 26 +++++++++++++++++++++----- hw/scsi/mptsas.c | 31 ++++++++++++++++++++++++------- hw/scsi/vmw_pvscsi.c | 2 +- hw/usb/hcd-xhci.c | 23 +++++++++++++++++++---- hw/vfio/pci.c | 7 +++++-- 15 files changed, 150 insertions(+), 67 deletions(-)
include/hw/pci/msi.h +2 -1
@@ -35,7 +35,8 @@ void msi_set_message(PCIDevice *dev, MSIMessage msg);MSIMessage msi_get_message (PCIDevice *dev,unsigned int vector);bool msi_enabled (const PCIDevice *dev);int msi_init (struct PCIDevice *dev,uint8_t offset, -unsigned int nr_vectors,bool msi64bit,bool msi_per_vector_mask); +unsigned int nr_vectors,bool msi64bit, +bool msi_per_vector_mask,Error **errp);void msi_uninit (struct PCIDevice *dev);void msi_reset (PCIDevice *dev);void msi_notify (PCIDevice *dev,unsigned int vector);
hw/audio/intel-hda.c +20 -4
@@ -1132,6 +1132,8 @@ static void intel_hda_realize(PCIDevice *pci, Error **errp) {IntelHDAState *d =INTEL_HDA (pci);uint8_t *conf = d->pci.config; +Error *err =NULL ; +int ret; d->name =object_get_typename (OBJECT (d));
@@ -1140,13 +1142,27 @@ static void intel_hda_realize(PCIDevice *pci, Error **errp)/* HDCTL off 0x40 bit 0 selects signaling mode (1-HDA, 0 - Ac97) 18.1.19 */ conf[0x40 ] =0x01 ; +if (d->msi !=ON_OFF_AUTO_OFF ) { + ret =msi_init (&d->pci, d->old_msi_addr ?0x50 :0x60 , +1 , true, false, &err); +/* Any error other than -ENOTSUP(board's MSI support is broken) +* is a programming error */ +assert (!ret || ret == -ENOTSUP ); +if (ret && d->msi ==ON_OFF_AUTO_ON ) { +/* Can't satisfy user's explicit msi=on request, fail */ +error_append_hint (&err,"You have to use msi=auto (default) or " +"msi=off with this machine type.\n" ); +error_propagate (errp, err); +return ; + } +assert (!err || d->msi ==ON_OFF_AUTO_AUTO ); +/* With msi=auto, we fall back to MSI off silently */ +error_free (err); + } +memory_region_init_io (&d->mmio,OBJECT (d), &intel_hda_mmio_ops, d,"intel-hda" ,0x4000 );pci_register_bar (&d->pci,0 ,0 , &d->mmio); -if (d->msi !=ON_OFF_AUTO_OFF ) { -/* TODO check for errors */ -msi_init (&d->pci, d->old_msi_addr ?0x50 :0x60 ,1 , true, false); - }hda_codec_bus_init (DEVICE (pci), &d->codecs,sizeof (d->codecs), intel_hda_response, intel_hda_xfer);
hw/ide/ich.c +5 -2
@@ -68,7 +68,6 @@#include <hw/isa/isa.h> #include "sysemu/block-backend.h" #include "sysemu/dma.h" -#include <hw/ide/pci.h> #include <hw/ide/ahci.h>
@@ -111,6 +110,7 @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error **errp)int sata_cap_offset;uint8_t *sata_cap; d =ICH_AHCI (dev); +int ret;ahci_realize (&d->ahci,DEVICE (dev),pci_get_address_space (dev),6 );
@@ -146,7 +146,10 @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error **errp)/* Although the AHCI 1.3 specification states that the first capability * should be PMCAP, the Intel ICH9 data sheet specifies that the ICH9 * AHCI device puts the MSI capability first, pointing to 0x80. */ -msi_init (dev,ICH9_MSI_CAP_OFFSET ,1 , true, false); + ret =msi_init (dev,ICH9_MSI_CAP_OFFSET ,1 , true, false,NULL ); +/* Any error other than -ENOTSUP(board's MSI support is broken) +* is a programming error. Fall back to INTx silently on -ENOTSUP */ +assert (!ret || ret == -ENOTSUP ); }static void pci_ich9_uninit (PCIDevice *dev)
hw/net/e1000e.c +2 -6
@@ -268,13 +268,9 @@ e1000e_init_msi(E1000EState *s) {int res; - res =msi_init (PCI_DEVICE (s), -0xD0 ,/* MSI capability offset */ -1 ,/* MAC MSI interrupts */ - true,/* 64-bit message addresses supported */ - false);/* Per vector mask supported */ + res =msi_init (PCI_DEVICE (s),0xD0 ,1 , true, false,NULL ); -if (res >0 ) { +if (!res) { s->intr_state |=E1000E_USE_MSI ; }else {trace_e1000e_msi_init_fail (res);
hw/net/vmxnet3.c +12 -25
@@ -2216,27 +2216,6 @@ vmxnet3_cleanup_msix(VMXNET3State *s) } } -#define VMXNET3_USE_64BIT (true) -#define VMXNET3_PER_VECTOR_MASK (false) - -static bool -vmxnet3_init_msi (VMXNET3State *s) -{ -PCIDevice *d =PCI_DEVICE (s); -int res; - - res =msi_init (d,VMXNET3_MSI_OFFSET (s),VMXNET3_MAX_NMSIX_INTRS , -VMXNET3_USE_64BIT ,VMXNET3_PER_VECTOR_MASK ); -if (0 > res) { -VMW_WRPRN ("Failed to initialize MSI, error %d" , res); - s->msi_used = false; - }else { - s->msi_used = true; - } - -return s->msi_used; -} -static void vmxnet3_cleanup_msi (VMXNET3State *s) {
@@ -2298,10 +2277,15 @@ static uint64_t vmxnet3_device_serial_num(VMXNET3State *s)return dsn_payload; } + +#define VMXNET3_USE_64BIT (true) +#define VMXNET3_PER_VECTOR_MASK (false) +static void vmxnet3_pci_realize (PCIDevice *pci_dev,Error **errp) {DeviceState *dev =DEVICE (pci_dev);VMXNET3State *s =VMXNET3 (pci_dev); +int ret;VMW_CBPRN ("Starting init..." );
@@ -2325,14 +2309,17 @@ static void vmxnet3_pci_realize(PCIDevice *pci_dev, Error **errp)/* Interrupt pin A */ pci_dev->config[PCI_INTERRUPT_PIN ] =0x01 ; + ret =msi_init (pci_dev,VMXNET3_MSI_OFFSET (s),VMXNET3_MAX_NMSIX_INTRS , +VMXNET3_USE_64BIT ,VMXNET3_PER_VECTOR_MASK ,NULL ); +/* Any error other than -ENOTSUP(board's MSI support is broken) +* is a programming error. Fall back to INTx silently on -ENOTSUP */ +assert (!ret || ret == -ENOTSUP ); + s->msi_used = !ret; +if (!vmxnet3_init_msix (s)) {VMW_WRPRN ("Failed to initialize MSI-X, configuration is inconsistent." ); } -if (!vmxnet3_init_msi (s)) { -VMW_WRPRN ("Failed to initialize MSI, configuration is inconsistent." ); - } -vmxnet3_net_init (s);if (pci_is_express (pci_dev)) {
hw/pci-bridge/ioh3420.c +5 -1
@@ -25,6 +25,7 @@#include "hw/pci/msi.h" #include "hw/pci/pcie.h" #include "ioh3420.h" +#include "qapi/error.h" #define PCI_DEVICE_ID_IOH_EPORT 0x3420/* D0:F0 express mode */ #define PCI_DEVICE_ID_IOH_REV 0x2
@@ -97,6 +98,7 @@ static int ioh3420_initfn(PCIDevice *d)PCIEPort *p =PCIE_PORT (d);PCIESlot *s =PCIE_SLOT (d);int rc; +Error *err =NULL ;pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d);
@@ -109,8 +111,10 @@ static int ioh3420_initfn(PCIDevice *d) rc =msi_init (d,IOH_EP_MSI_OFFSET ,IOH_EP_MSI_NR_VECTOR ,IOH_EP_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_64BIT , -IOH_EP_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_MASKBIT ); +IOH_EP_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_MASKBIT , &err);if (rc <0 ) { +assert (rc == -ENOTSUP ); +error_report_err (err); goto err_bridge; }
hw/pci-bridge/pci_bridge_dev.c +16 -4
@@ -54,6 +54,7 @@ static int pci_bridge_dev_initfn(PCIDevice *dev)PCIBridge *br =PCI_BRIDGE (dev);PCIBridgeDev *bridge_dev =PCI_BRIDGE_DEV (dev);int err; +Error *local_err =NULL ;pci_bridge_initfn (dev,TYPE_PCI_BUS );
@@ -75,12 +76,23 @@ static int pci_bridge_dev_initfn(PCIDevice *dev) goto slotid_error; } -if (bridge_dev->msi !=ON_OFF_AUTO_OFF && - msi_nonbroken) { - err =msi_init (dev,0 ,1 , true, true); -if (err <0 ) { +if (bridge_dev->msi !=ON_OFF_AUTO_OFF ) { +/* it means SHPC exists, because MSI is needed by SHPC */ + + err =msi_init (dev,0 ,1 , true, true, &local_err); +/* Any error other than -ENOTSUP(board's MSI support is broken) +* is a programming error */ +assert (!err || err == -ENOTSUP ); +if (err && bridge_dev->msi ==ON_OFF_AUTO_ON ) { +/* Can't satisfy user's explicit msi=on request, fail */ +error_append_hint (&local_err,"You have to use msi=auto (default) " +"or msi=off with this machine type.\n" ); +error_report_err (local_err); goto msi_error; } +assert (!local_err || bridge_dev->msi ==ON_OFF_AUTO_AUTO ); +/* With msi=auto, we fall back to MSI off silently */ +error_free (local_err); }if (shpc_present (dev)) {
hw/pci-bridge/xio3130_downstream.c +5 -1
@@ -24,6 +24,7 @@#include "hw/pci/msi.h" #include "hw/pci/pcie.h" #include "xio3130_downstream.h" +#include "qapi/error.h" #define PCI_DEVICE_ID_TI_XIO3130D 0x8233/* downstream port */ #define XIO3130_REVISION 0x1
@@ -60,14 +61,17 @@ static int xio3130_downstream_initfn(PCIDevice *d)PCIEPort *p =PCIE_PORT (d);PCIESlot *s =PCIE_SLOT (d);int rc; +Error *err =NULL ;pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d); rc =msi_init (d,XIO3130_MSI_OFFSET ,XIO3130_MSI_NR_VECTOR ,XIO3130_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_64BIT , -XIO3130_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_MASKBIT ); +XIO3130_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_MASKBIT , &err);if (rc <0 ) { +assert (rc == -ENOTSUP ); +error_report_err (err); goto err_bridge; }
hw/pci-bridge/xio3130_upstream.c +5 -1
@@ -24,6 +24,7 @@#include "hw/pci/msi.h" #include "hw/pci/pcie.h" #include "xio3130_upstream.h" +#include "qapi/error.h" #define PCI_DEVICE_ID_TI_XIO3130U 0x8232/* upstream port */ #define XIO3130_REVISION 0x2
@@ -56,14 +57,17 @@ static int xio3130_upstream_initfn(PCIDevice *d) {PCIEPort *p =PCIE_PORT (d);int rc; +Error *err =NULL ;pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d); rc =msi_init (d,XIO3130_MSI_OFFSET ,XIO3130_MSI_NR_VECTOR ,XIO3130_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_64BIT , -XIO3130_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_MASKBIT ); +XIO3130_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_MASKBIT , &err);if (rc <0 ) { +assert (rc == -ENOTSUP ); +error_report_err (err); goto err_bridge; }
hw/pci/msi.c +8 -3
@@ -22,6 +22,7 @@#include "hw/pci/msi.h" #include "hw/xen/xen.h" #include "qemu/range.h" +#include "qapi/error.h" /* PCI_MSI_ADDRESS_LO */ #define PCI_MSI_ADDRESS_LO_MASK (~0x3)
@@ -173,7 +174,8 @@ bool msi_enabled(const PCIDevice *dev)* If @msi64bit, make the device capable of sending a 64-bit message * address. * If @msi_per_vector_mask, make the device support per-vector masking. -* Return 0 on success, return -errno on error. +* @errp is for returning errors. +* Return 0 on success; set @errp and return -errno on error. * * -ENOTSUP means lacking msi support for a msi-capable platform. * -EINVAL means capability overlap, happens when @offset is non-zero,
@@ -181,7 +183,8 @@ bool msi_enabled(const PCIDevice *dev)* if a real HW is broken. */ int msi_init (struct PCIDevice *dev,uint8_t offset, -unsigned int nr_vectors,bool msi64bit,bool msi_per_vector_mask) +unsigned int nr_vectors,bool msi64bit, +bool msi_per_vector_mask,Error **errp) {unsigned int vectors_order;uint16_t flags;
@@ -189,6 +192,7 @@ int msi_init(struct PCIDevice *dev, uint8_t offset,int config_offset;if (!msi_nonbroken) { +error_setg (errp,"MSI is not supported by interrupt controller" );return -ENOTSUP ; }
@@ -212,7 +216,8 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, } cap_size =msi_cap_sizeof (flags); - config_offset =pci_add_capability (dev,PCI_CAP_ID_MSI , offset, cap_size); + config_offset =pci_add_capability2 (dev,PCI_CAP_ID_MSI , offset, + cap_size, errp);if (config_offset <0 ) {return config_offset; }
hw/scsi/megasas.c +21 -5
@@ -29,7 +29,7 @@#include "hw/scsi/scsi.h" #include "block/scsi.h" #include "trace.h" - +#include "qapi/error.h" #include "mfi.h" #define MEGASAS_VERSION_GEN1 "1.70"
@@ -2330,6 +2330,8 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)MegasasBaseClass *b =MEGASAS_DEVICE_GET_CLASS (s);uint8_t *pci_conf;int i, bar_type; +Error *err =NULL ; +int ret; pci_conf = dev->config;
@@ -2338,6 +2340,24 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)/* Interrupt pin 1 */ pci_conf[PCI_INTERRUPT_PIN ] =0x01 ; +if (megasas_use_msi (s)) { + ret =msi_init (dev,0x50 ,1 , true, false, &err); +/* Any error other than -ENOTSUP(board's MSI support is broken) +* is a programming error */ +assert (!ret || ret == -ENOTSUP ); +if (ret && s->msi ==ON_OFF_AUTO_ON ) { +/* Can't satisfy user's explicit msi=on request, fail */ +error_append_hint (&err,"You have to use msi=auto (default) or " +"msi=off with this machine type.\n" ); +error_propagate (errp, err); +return ; + }else if (ret) { +/* With msi=auto, we fall back to MSI off silently */ + s->msi =ON_OFF_AUTO_OFF ; +error_free (err); + } + } +memory_region_init_io (&s->mmio_io,OBJECT (s), &megasas_mmio_ops, s,"megasas-mmio" ,0x4000 ); memory_region_init_io(&s->port_io, OBJECT(s), &megasas_port_ops, s,
@@ -2345,10 +2365,6 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)memory_region_init_io (&s->queue_io,OBJECT (s), &megasas_queue_ops, s,"megasas-queue" ,0x40000 ); -if (megasas_use_msi (s) && -msi_init (dev,0x50 ,1 , true, false)) { - s->msi =ON_OFF_AUTO_OFF ; - }if (megasas_use_msix (s) &&msix_init (dev,15 , &s->mmio_io, b->mmio_bar,0x2000 , &s->mmio_io, b->mmio_bar,0x3800 ,0x68 )) {
hw/scsi/mptsas.c +24 -7
@@ -32,7 +32,7 @@#include "hw/scsi/scsi.h" #include "block/scsi.h" #include "trace.h" - +#include "qapi/error.h" #include "mptsas.h" #include "mpi.h"
@@ -1273,10 +1273,33 @@ static void mptsas_scsi_init(PCIDevice *dev, Error **errp) {DeviceState *d =DEVICE (dev);MPTSASState *s =MPT_SAS (dev); +Error *err =NULL ; +int ret; dev->config[PCI_LATENCY_TIMER ] =0 ; dev->config[PCI_INTERRUPT_PIN ] =0x01 ; +if (s->msi !=ON_OFF_AUTO_OFF ) { + ret =msi_init (dev,0 ,1 , true, false, &err); +/* Any error other than -ENOTSUP(board's MSI support is broken) +* is a programming error */ +assert (!ret || ret == -ENOTSUP ); +if (ret && s->msi ==ON_OFF_AUTO_ON ) { +/* Can't satisfy user's explicit msi=on request, fail */ +error_append_hint (&err,"You have to use msi=auto (default) or " +"msi=off with this machine type.\n" ); +error_propagate (errp, err); + s->msi_in_use = false; +return ; + }else if (ret) { +/* With msi=auto, we fall back to MSI off silently */ +error_free (err); + s->msi_in_use = false; + }else { + s->msi_in_use = true; + } + } +memory_region_init_io (&s->mmio_io,OBJECT (s), &mptsas_mmio_ops, s,"mptsas-mmio" ,0x4000 ); memory_region_init_io(&s->port_io, OBJECT(s), &mptsas_port_ops, s,
@@ -1284,12 +1307,6 @@ static void mptsas_scsi_init(PCIDevice *dev, Error **errp)memory_region_init_io (&s->diag_io,OBJECT (s), &mptsas_diag_ops, s,"mptsas-diag" ,0x10000 ); -if (s->msi !=ON_OFF_AUTO_OFF && -msi_init (dev,0 ,1 , true, false) >=0 ) { -/* TODO check for errors */ - s->msi_in_use = true; - } -pci_register_bar (dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , &s->port_io);pci_register_bar (dev,1 ,PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_32 , &s->mmio_io);
hw/scsi/vmw_pvscsi.c +1 -1
@@ -1063,7 +1063,7 @@ pvscsi_init_msi(PVSCSIState *s)PCIDevice *d =PCI_DEVICE (s); res =msi_init (d,PVSCSI_MSI_OFFSET (s),PVSCSI_MSIX_NUM_VECTORS , -PVSCSI_USE_64BIT ,PVSCSI_PER_VECTOR_MASK ); +PVSCSI_USE_64BIT ,PVSCSI_PER_VECTOR_MASK ,NULL );if (res <0 ) {trace_pvscsi_init_msi_fail (res); s->msi_used = false;
hw/usb/hcd-xhci.c +19 -4
@@ -26,6 +26,7 @@#include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "trace.h" +#include "qapi/error.h" //#define DEBUG_XHCI //#define DEBUG_DATA
@@ -3581,6 +3582,7 @@ static void usb_xhci_init(XHCIState *xhci)static void usb_xhci_realize (struct PCIDevice *dev,Error **errp) {int i, ret; +Error *err =NULL ;XHCIState *xhci =XHCI (dev);
@@ -3591,6 +3593,23 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)usb_xhci_init (xhci); +if (xhci->msi !=ON_OFF_AUTO_OFF ) { + ret =msi_init (dev,0x70 , xhci->numintrs, true, false, &err); +/* Any error other than -ENOTSUP(board's MSI support is broken) +* is a programming error */ +assert (!ret || ret == -ENOTSUP ); +if (ret && xhci->msi ==ON_OFF_AUTO_ON ) { +/* Can't satisfy user's explicit msi=on request, fail */ +error_append_hint (&err,"You have to use msi=auto (default) or " +"msi=off with this machine type.\n" ); +error_propagate (errp, err); +return ; + } +assert (!err || xhci->msi ==ON_OFF_AUTO_AUTO ); +/* With msi=auto, we fall back to MSI off silently */ +error_free (err); + } +if (xhci->numintrs >MAXINTRS ) { xhci->numintrs =MAXINTRS ; }
@@ -3648,10 +3667,6 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)assert (ret >=0 ); } -if (xhci->msi !=ON_OFF_AUTO_OFF ) { -/* TODO check for errors */ -msi_init (dev,0x70 , xhci->numintrs, true, false); - }if (xhci->msix !=ON_OFF_AUTO_OFF ) {/* TODO check for errors */ msix_init(dev, xhci->numintrs,
hw/vfio/pci.c +5 -2
@@ -31,6 +31,7 @@#include "sysemu/sysemu.h" #include "pci.h" #include "trace.h" +#include "qapi/error.h" #define MSIX_CAP_LENGTH 12
@@ -1170,6 +1171,7 @@ static int vfio_msi_setup(VFIOPCIDevice *vdev, int pos)uint16_t ctrl;bool msi_64bit, msi_maskbit;int ret, entries; +Error *err =NULL ;if (pread (vdev->vbasedev.fd, &ctrl,sizeof (ctrl), vdev->config_offset + pos +PCI_CAP_FLAGS ) !=sizeof (ctrl)) {
@@ -1183,12 +1185,13 @@ static int vfio_msi_setup(VFIOPCIDevice *vdev, int pos)trace_vfio_msi_setup (vdev->vbasedev.name, pos); - ret =msi_init (&vdev->pdev, pos, entries, msi_64bit, msi_maskbit); + ret =msi_init (&vdev->pdev, pos, entries, msi_64bit, msi_maskbit, &err);if (ret <0 ) {if (ret == -ENOTSUP ) {return 0 ; } -error_report ("vfio: msi_init failed" ); +error_prepend (&err,"vfio: msi_init failed: " ); +error_report_err (err);return ret; } vdev->msi_cap_size =0xa + (msi_maskbit ?0xa :0 ) + (msi_64bit ?0x4 :0 );
Signature · 1 line
MST
[Qemu-devel] [PULL 33/36] mptsas: remove unnecessary internal msi state flag
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
internal flag msi_in_use in unnecessary, msi_uninit() could be called directly, and msi_enabled() is enough to check device msi state.
--- hw/scsi/mptsas.h | 2 -- hw/scsi/mptsas.c | 18 ++++++------------ 2 files changed, 6 insertions(+), 14 deletions(-)
hw/scsi/mptsas.h +0 -2
@@ -31,8 +31,6 @@ struct MPTSASState {OnOffAuto msi;uint64_t sas_addr; -bool msi_in_use; -/* Doorbell register */ uint32_t state;uint8_t who_init;
hw/scsi/mptsas.c +6 -12
@@ -63,7 +63,7 @@ static void mptsas_update_interrupt(MPTSASState *s)PCIDevice *pci = (PCIDevice *) s;uint32_t state = s->intr_status & ~(s->intr_mask |MPI_HIS_IOP_DOORBELL_STATUS ); -if (s->msi_in_use &&msi_enabled (pci)) { +if (msi_enabled (pci)) {if (state) {trace_mptsas_irq_msi (s);msi_notify (pci,0 );
@@ -1289,15 +1289,12 @@ static void mptsas_scsi_init(PCIDevice *dev, Error **errp)error_append_hint (&err,"You have to use msi=auto (default) or " "msi=off with this machine type.\n" );error_propagate (errp, err); - s->msi_in_use = false;return ; - }else if (ret) { -/* With msi=auto, we fall back to MSI off silently */ -error_free (err); - s->msi_in_use = false; - }else { - s->msi_in_use = true; } +assert (!err || s->msi ==ON_OFF_AUTO_AUTO ); +/* With msi=auto, we fall back to MSI off silently */ +error_free (err); + } memory_region_init_io(&s->mmio_io, OBJECT(s), &mptsas_mmio_ops, s,
@@ -1337,9 +1334,7 @@ static void mptsas_scsi_uninit(PCIDevice *dev)MPTSASState *s =MPT_SAS (dev);qemu_bh_delete (s->request_bh); -if (s->msi_in_use) { -msi_uninit (dev); - } +msi_uninit (dev); }static void mptsas_reset (DeviceState *dev)
@@ -1375,7 +1370,6 @@ static const VMStateDescription vmstate_mptsas = { .post_load = mptsas_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (dev, MPTSASState), -VMSTATE_BOOL (msi_in_use, MPTSASState),VMSTATE_UINT32 (state, MPTSASState),VMSTATE_UINT8 (who_init, MPTSASState),
Signature · 1 line
MST
[Qemu-devel] [PULL 34/36] vmxnet3: remove unnecessary internal msi state flag
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Internal flag msi_used is unnecessary, it has the same effect as msi_enabled(). msi_uninit() could be called directly without risk.
--- hw/net/vmxnet3.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
hw/net/vmxnet3.c +6 -11
@@ -283,8 +283,6 @@ typedef struct {/* Whether MSI-X support was installed successfully */ bool msix_used; -/* Whether MSI support was installed successfully */ -bool msi_used;hwaddr drv_shmem;hwaddr temp_shared_guest_driver_memory;
@@ -366,7 +364,7 @@ static bool _vmxnet3_assert_interrupt_line(VMXNET3State *s, uint32_t int_idx)msix_notify (d, int_idx);return false; } -if (s->msi_used &&msi_enabled (d)) { +if (msi_enabled (d)) {VMW_IRPRN ("Sending MSI notification for vector %u" , int_idx);msi_notify (d, int_idx);return false;
@@ -390,7 +388,7 @@ static void _vmxnet3_deassert_interrupt_line(VMXNET3State *s, int lidx)* This function should never be called for MSI(X) interrupts * because deassertion never required for message interrupts */ -assert (!s->msi_used || !msi_enabled (d)); +assert (!msi_enabled (d));VMW_IRPRN ("Deasserting line for interrupt %u" , lidx);pci_irq_deassert (d);
@@ -427,7 +425,7 @@ static void vmxnet3_trigger_interrupt(VMXNET3State *s, int lidx) goto do_automask; } -if (s->msi_used &&msi_enabled (d) && s->auto_int_masking) { +if (msi_enabled (d) && s->auto_int_masking) { goto do_automask; }
@@ -1425,8 +1423,8 @@ static void vmxnet3_update_features(VMXNET3State *s)static bool vmxnet3_verify_intx (VMXNET3State *s,int intx) { -return s->msix_used || s->msi_used || (intx == - (pci_get_byte (s->parent_obj.config +PCI_INTERRUPT_PIN ) -1 )); +return s->msix_used ||msi_enabled (PCI_DEVICE (s)) + || intx ==pci_get_byte (s->parent_obj.config +PCI_INTERRUPT_PIN ) -1 ; }static void vmxnet3_validate_interrupt_idx (bool is_msix,int idx)
@@ -2221,9 +2219,7 @@ vmxnet3_cleanup_msi(VMXNET3State *s) {PCIDevice *d =PCI_DEVICE (s); -if (s->msi_used) { -msi_uninit (d); - } +msi_uninit (d); } static void
@@ -2314,7 +2310,6 @@ static void vmxnet3_pci_realize(PCIDevice *pci_dev, Error **errp)/* Any error other than -ENOTSUP(board's MSI support is broken) * is a programming error. Fall back to INTx silently on -ENOTSUP */ assert (!ret || ret == -ENOTSUP ); - s->msi_used = !ret;if (!vmxnet3_init_msix (s)) {VMW_WRPRN ("Failed to initialize MSI-X, configuration is inconsistent." );
Signature · 1 line
MST
[Qemu-devel] [PULL 35/36] e1000e: remove unnecessary internal msi state flag
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Internal big flag E1000E_USE_MSI is unnecessary, also is the helper
function: e1000e_init_msi(), e1000e_cleanup_msi(), so, remove them all.
--- hw/net/e1000e.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-)
hw/net/e1000e.c +7 -26
@@ -89,8 +89,7 @@ typedef struct E1000EState {#define E1000E_MSIX_TABLE (0x0000)#define E1000E_MSIX_PBA (0x2000) -#define E1000E_USE_MSI BIT(0) -#define E1000E_USE_MSIX BIT(1) +#define E1000E_USE_MSIX BIT(0)static uint64_t e1000e_mmio_read (void *opaque,hwaddr addr,unsigned size)
@@ -264,28 +263,6 @@ static void e1000e_core_realize(E1000EState *s) }static void -e1000e_init_msi (E1000EState *s) -{ -int res; - - res =msi_init (PCI_DEVICE (s),0xD0 ,1 , true, false,NULL ); - -if (!res) { - s->intr_state |=E1000E_USE_MSI ; - }else { -trace_e1000e_msi_init_fail (res); - } -} - -static void -e1000e_cleanup_msi (E1000EState *s) -{ -if (s->intr_state &E1000E_USE_MSI ) { -msi_uninit (PCI_DEVICE (s)); - } -} - -static void e1000e_unuse_msix_vectors (E1000EState *s,int num_vectors) {int i;
@@ -440,6 +417,7 @@ static void e1000e_pci_realize(PCIDevice *pci_dev, Error **errp)static const uint16_t e1000e_dsn_offset =0x140 ;E1000EState *s =E1000E (pci_dev);uint8_t *macaddr; +int ret;trace_e1000e_cb_pci_realize ();
@@ -489,7 +467,10 @@ static void e1000e_pci_realize(PCIDevice *pci_dev, Error **errp)hw_error ("Failed to initialize PCIe capability" ); } -e1000e_init_msi (s); + ret =msi_init (PCI_DEVICE (s),0xD0 ,1 , true, false,NULL ); +if (ret) { +trace_e1000e_msi_init_fail (ret); + }if (e1000e_add_pm_capability (pci_dev, e1000e_pmrb_offset,PCI_PM_CAP_DSI ) <0 ) {
@@ -528,7 +509,7 @@ static void e1000e_pci_uninit(PCIDevice *pci_dev)qemu_del_nic (s->nic);e1000e_cleanup_msix (s); -e1000e_cleanup_msi (s); +msi_uninit (pci_dev); }static void e1000e_qdev_reset (DeviceState *dev)
Signature · 1 line
MST
[Qemu-devel] [PULL 36/36] vmw_pvscsi: remove unnecessary internal msi state flag
In reply to a message not in the archiveFrom: Cao jin <[email protected]>
Internal flag msi_used is uncesessary, msi_uninit() could be called directly, msi_enabled() is enough to check device msi state.
But for migration compatibility, keep the field in structure.
--- hw/scsi/vmw_pvscsi.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
hw/scsi/vmw_pvscsi.c +3 -6
@@ -121,8 +121,7 @@ typedef struct {uint8_t msg_ring_info_valid;/* Whether message ring initialized */ uint8_t use_msg;/* Whether to use message ring */ -uint8_t msi_used;/* Whether MSI support was installed successfully */ - +uint8_t msi_used;/* For migration compatibility */ PVSCSIRingInfo rings;/* Data transfer rings manager */ uint32_t resetting;/* Reset in progress */
@@ -362,7 +361,7 @@ pvscsi_update_irq_status(PVSCSIState *s)trace_pvscsi_update_irq_level (should_raise, s->reg_interrupt_enabled, s->reg_interrupt_status); -if (s->msi_used &&msi_enabled (d)) { +if (msi_enabled (d)) {if (should_raise) {trace_pvscsi_update_irq_msi ();msi_notify (d,PVSCSI_VECTOR_COMPLETION );
@@ -1077,9 +1076,7 @@ pvscsi_cleanup_msi(PVSCSIState *s) {PCIDevice *d =PCI_DEVICE (s); -if (s->msi_used) { -msi_uninit (d); - } +msi_uninit (d); }static const MemoryRegionOps pvscsi_ops = {
Signature · 1 line
MST