hw/pci: fixed crash when using rombar=0 for hotplugged devices
PATCH 1/1 hw/pci: fixed crash when using rombar=0 for hotplugged devices
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
hw/pci/pci.c +10 -1
@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; } -pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }
@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;
Signature · 1 line
1.8.3.1
Quoted 5 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
I think it could also make sense to just ignore the option ROM and allow the hotplug.
Sooner or later we should drop the oldest compat machine types... everything until 0.12 probably could go.
Paolo
Quoted 35 lines
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +10
-1@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; } -pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;
Quoted 9 lines · Paolo Bonzini
Quoted 5 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Quoted 7 lines
I think it could also make sense to just ignore the option ROM and allow the hotplug.
Sooner or later we should drop the oldest compat machine types... everything until 0.12 probably could go.
Paolo
Unfortunately, we made the mistake of exposing the rombar attribute to management.
See rom element at
http://libvirt.org/formatdomain.html#elementsHostDevSubsys
and in theory some users might have configured rombar=off but set file to some value.
I'd be OK with removing support for this combination, if we want the legacy fw cfg thing, we should have a separate attribute.
But I'd like someone from libvirt to OK this ...
Eric?
Quoted 35 lines
Quoted 35 lines
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +10
-1@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; } -pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;
Quoted 10 lines · Paolo Bonzini
Quoted 5 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
I think it could also make sense to just ignore the option ROM and allow the hotplug.
We need a way to inform the user we did that, he *specifically* asked for a ROM he might need it.
Thanks,
Marcel
Quoted 41 lines
Sooner or later we should drop the oldest compat machine types... everything until 0.12 probably could go.
Paolo
Quoted 35 lines
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +10
-1@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; } -pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;
Quoted 9 lines · Marcel Apfelbaum
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Quoted 7 lines
Quoted 2 lines
I think it could also make sense to just ignore the option ROM and allow the hotplug.
We need a way to inform the user we did that, he *specifically* asked for a ROM he might need it.
Thanks,
Marcel
But he also asked to disable BAR.
I don't see valid reasons for this configuration
expcept compatibility.
But I have a vague memory Alex thought differently. Alex?
Quoted 43 lines
Quoted 41 lines
Sooner or later we should drop the oldest compat machine types... everything until 0.12 probably could go.
Paolo
Quoted 35 lines
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +10
-1@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; } -pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;
Quoted 18 lines · Michael S. Tsirkin
Quoted 9 lines · Marcel Apfelbaum
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Quoted 7 lines
Quoted 2 lines
I think it could also make sense to just ignore the option ROM and allow the hotplug.
We need a way to inform the user we did that, he *specifically* asked for a ROM he might need it.
Thanks,
Marcel
Quoted 7 lines
But he also asked to disable BAR.
I don't see valid reasons for this configuration
expcept compatibility.But I have a vague memory Alex thought differently. Alex?
The comment in the original patch is really confusing for device assignment where rombar=0 is perfectly valid for any case, hotplug or not, but only in combination with romfile= do we end up trying to use fw_cfg, which I think is what we're trying to prevent here. Emulated devices are the ones that will still try to use fw_cfg because they have an implicit romfile.
I can't think of any use cases for requiring fw_cfg for an assigned device, it usually ends up being a user error to specify both rombar=0 with romfile=$FILE. Doing that for any device, emulated or assigned, disassociates the ROM from the device which breaks things like bootindex as well.
If a user specifies rombar=0,romfile=$FILE we should probably error and reject the device for hotplug. Emulated devices with implicit romfiles are a bit harder to know what will break. Silently dropping the implicit romfile seems like a reasonable thing, but then we have different behavior between cold- and hot-plugged devices. I think that's reproducible for migration using romfile="", but I don't expect libvirt handles that properly. It's a can of worms...
Thanks,
Alex
Quoted 44 lines
Quoted 43 lines
Quoted 41 lines
Sooner or later we should drop the oldest compat machine types... everything until 0.12 probably could go.
Paolo
Quoted 35 lines
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +10
-1@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; } -pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;
Quoted 24 lines · Alex Williamson
Quoted 23 lines · Michael S. Tsirkin
Quoted 9 lines · Marcel Apfelbaum
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Quoted 7 lines
Quoted 2 lines
I think it could also make sense to just ignore the option ROM and allow the hotplug.
We need a way to inform the user we did that, he *specifically* asked for a ROM he might need it.
Thanks,
MarcelBut he also asked to disable BAR.
I don't see valid reasons for this configuration
expcept compatibility.
Quoted 6 lines
Quoted 2 lines
But I have a vague memory Alex thought differently. Alex?
The comment in the original patch is really confusing for device assignment where rombar=0 is perfectly valid for any case, hotplug or not,
Yes, I should have made it more clear:
ROM images must be loaded at startup. Assigning ROM images to devices and disabling the BAR at hotplug
is not allowed, but should not crash QEMU.
Quoted 11 lines
but only in combination with romfile= do we end up trying to use
fw_cfg, which I think is what we're trying to prevent here. Emulated devices are the ones that will still try to usefw_cfgbecause they have an implicit romfile.I can't think of any use cases for requiring
fw_cfgfor an assigned device, it usually ends up being a user error to specify both rombar=0 with romfile=$FILE. Doing that for any device, emulated or assigned, disassociates the ROM from the device which breaks things like bootindex as well.
Quoted 5 lines
If a user specifies rombar=0,romfile=$FILE we should probably error and reject the device for hotplug.
Emulated devices with implicit romfiles
are a bit harder to know what will break. Silently dropping the implicit romfile seems like a reasonable thing,
It seems that this is the general agreement, I am going to post a v2 for this and see what libvirt guys have to say about it. I'll cc Eric.
Thanks,
Marcel
Quoted 55 lines
but then we have
different behavior between cold- and hot-plugged devices. I think that's reproducible for migration using romfile="", but I don't expect libvirt handles that properly. It's a can of worms...Thanks,
AlexQuoted 44 lines
Quoted 43 lines
Quoted 41 lines
Sooner or later we should drop the oldest compat machine types... everything until 0.12 probably could go.
Paolo
Quoted 35 lines
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +10
-1@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; } -pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;
Quoted 19 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +0
-0@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; }
hw/pci/pci.c static int pci_qdev_init(DeviceState *qdev) · line 1787
Quoted 10 lines
hw/pci/pci.c +6
-1-pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }
Fair enough for this chunk.
hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1954
Quoted 11 lines
hw/pci/pci.c +4
-0@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;
The message is confusing. rombar=0 is ok if you
don't also try to force romfile.
Generally why are you adding this logic in pci?
And what about e.g. vga?
I think the right thing to do is to propagate return codes correctly, and report the error where it occurs.
Quoted 2 lines
Signature · 1 line
1.8.3.1
Quoted 33 lines · Michael S. Tsirkin
Quoted 19 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +0
-0@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; }hw/pci/pci.c static int pci_qdev_init(DeviceState *qdev) · line 1787
Quoted 10 lines
hw/pci/pci.c +6
-1-pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }Fair enough for this chunk.
Quoted 16 lines
hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1954
Quoted 11 lines
hw/pci/pci.c +4
-0@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;The message is confusing. rombar=0 is ok if you
don't also try to force romfile.
Generally why are you adding this logic in pci?
Because rom_add_option will call eventually rom_insert that will crash QEMU with the call to hw_error.
Quoted 1 line
And what about e.g. vga?
This logic would apply also to rom_add_vga, I was not aware we can hotplug vga devices. Can we?
I can add it also to vga, of course.
Quoted 2 lines
I think the right thing to do is to propagate return codes correctly, and report the error where it occurs.
I can remove the error_report, but this gives an extra hint to user. I didn't see any other way to propagate the error message. Should I drop it?
Thanks,
Marcel
Quoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1
Quoted 50 lines · Marcel Apfelbaum
Quoted 33 lines · Michael S. Tsirkin
Quoted 19 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +0
-0@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; }hw/pci/pci.c static int pci_qdev_init(DeviceState *qdev) · line 1787
Quoted 10 lines
hw/pci/pci.c +6
-1-pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }Fair enough for this chunk.
Quoted 16 lines
hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1954
Quoted 11 lines
hw/pci/pci.c +4
-0@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;The message is confusing. rombar=0 is ok if you
don't also try to force romfile.
Generally why are you adding this logic in pci?
Quoted 2 lines
Because
rom_add_optionwill call eventuallyrom_insertthat will crash QEMU with the call tohw_error.
So fix rom_insert to return an error code instead?
Quoted 8 lines
Quoted 1 line
And what about e.g. vga?
This logic would apply also to
rom_add_vga, I was not aware we can hotplug vga devices. Can we?
I can add it also to vga, of course.Quoted 2 lines
I think the right thing to do is to propagate return codes correctly, and report the error where it occurs.
I can remove the
error_report, but this gives an extra hint to user.
Move it to rom_insert, instead of hw_error.
Quoted 10 lines
I didn't see any other way to propagate the error message. Should I drop it?
Thanks,
MarcelQuoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Marcel Apfelbaum
Quoted 49 lines · Michael S. Tsirkin
Quoted 19 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +0
-0@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; }hw/pci/pci.c static int pci_qdev_init(DeviceState *qdev) · line 1787
Quoted 10 lines
hw/pci/pci.c +6
-1-pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }Fair enough for this chunk.
hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1954
Quoted 11 lines
hw/pci/pci.c +4
-0@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;The message is confusing. rombar=0 is ok if you
don't also try to force romfile.
Generally why are you adding this logic in pci?
Quoted 4 lines
Quoted 2 lines
Because
rom_add_optionwill call eventuallyrom_insertthat will crash QEMU with the call tohw_error.So fix
rom_insertto return an error code instead?
OK, thanks
Quoted 11 lines
Quoted 9 lines
Quoted 2 lines
And what about e.g. vga?
This logic would apply also to
rom_add_vga, I was not aware we can hotplug vga devices. Can we?
I can add it also to vga, of course.Quoted 2 lines
I think the right thing to do is to propagate return codes correctly, and report the error where it occurs.
I can remove the
error_report, but this gives an extra hint to user.Move it to
rom_insert, instead ofhw_error.
Sure, I was a little "afraid" to change the "crash" policy of rom_insert.
Thanks,
Marcel
Quoted 11 lines
Quoted 11 lines
I didn't see any other way to propagate the error message. Should I drop it?
Thanks,
MarcelQuoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1
Quoted 66 lines · Marcel Apfelbaum
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Marcel Apfelbaum
Quoted 49 lines · Michael S. Tsirkin
Quoted 19 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +0
-0@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; }hw/pci/pci.c static int pci_qdev_init(DeviceState *qdev) · line 1787
Quoted 10 lines
hw/pci/pci.c +6
-1-pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }Fair enough for this chunk.
hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1954
Quoted 11 lines
hw/pci/pci.c +4
-0@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;The message is confusing. rombar=0 is ok if you
don't also try to force romfile.
Generally why are you adding this logic in pci?Quoted 4 lines
Quoted 2 lines
Because
rom_add_optionwill call eventuallyrom_insertthat will crash QEMU with the call tohw_error.So fix
rom_insertto return an error code instead?OK, thanks
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
And what about e.g. vga?
This logic would apply also to
rom_add_vga, I was not aware we can hotplug vga devices. Can we?
I can add it also to vga, of course.Quoted 2 lines
I think the right thing to do is to propagate return codes correctly, and report the error where it occurs.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
I can remove the
error_report, but this gives an extra hint to user.Move it to
rom_insert, instead ofhw_error.Sure, I was a little "afraid" to change the "crash" policy of
rom_insert.Thanks,
Marcel
You will need to audit all users, and make sure they check the error and handle it.
So it's a lot of work ...
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
I didn't see any other way to propagate the error message. Should I drop it?
Thanks,
MarcelQuoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Marcel Apfelbaum
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Marcel Apfelbaum
Quoted 49 lines · Michael S. Tsirkin
Quoted 19 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +0
-0@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; }hw/pci/pci.c static int pci_qdev_init(DeviceState *qdev) · line 1787
Quoted 10 lines
hw/pci/pci.c +6
-1-pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }Fair enough for this chunk.
hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1954
Quoted 11 lines
hw/pci/pci.c +4
-0@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;The message is confusing. rombar=0 is ok if you
don't also try to force romfile.
Generally why are you adding this logic in pci?Quoted 4 lines
Quoted 2 lines
Because
rom_add_optionwill call eventuallyrom_insertthat will crash QEMU with the call tohw_error.So fix
rom_insertto return an error code instead?OK, thanks
Quoted 11 lines
Quoted 9 lines
Quoted 2 lines
And what about e.g. vga?
This logic would apply also to
rom_add_vga, I was not aware we can hotplug vga devices. Can we?
I can add it also to vga, of course.Quoted 2 lines
I think the right thing to do is to propagate return codes correctly, and report the error where it occurs.
I can remove the
error_report, but this gives an extra hint to user.Move it to
rom_insert, instead ofhw_error.
Quoted 8 lines
Quoted 4 lines
Sure, I was a little "afraid" to change the "crash" policy of
rom_insert.Thanks,
MarcelYou will need to audit all users, and make sure they check the error and handle it.
So it's a lot of work ...
The truth is, while I don't mind getting into it, I was interested in solving the crash issue rather than re-factoring hw_error.
I'll prefer to find a solution for the crash and deffer hw_error re-factoring to another series...
Checking "hotplugged" at pci_add_option_rom for both rom_ad_option and rom_add_vga can be a PCI specific solution since it connects hotplug -> no rombar=0.
Propagating rom_insert error seems indeed difficult since the callers are mostly returning void.
Thanks,
Marcel
Quoted 14 lines
Quoted 14 lines
Quoted 12 lines
Quoted 12 lines
I didn't see any other way to propagate the error message. Should I drop it?
Thanks,
MarcelQuoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1
Quoted 89 lines · Marcel Apfelbaum
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Marcel Apfelbaum
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Marcel Apfelbaum
Quoted 49 lines · Michael S. Tsirkin
Quoted 19 lines · Marcel Apfelbaum
ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU.
Check that the device is not hotplugged before trying to insert the rom file.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/pci/pci.c +0
-0@@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile =g_strdup (pc->romfile); is_default_rom = true; }hw/pci/pci.c static int pci_qdev_init(DeviceState *qdev) · line 1787
Quoted 10 lines
hw/pci/pci.c +6
-1-pci_add_option_rom (pci_dev, is_default_rom); + + rc =pci_add_option_rom (pci_dev, is_default_rom); +if (rc !=0 ) { +pci_unregister_device (DEVICE (pci_dev)); +return rc; + }return 0 ; }Fair enough for this chunk.
hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1954
Quoted 11 lines
hw/pci/pci.c +4
-0@@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else { +if (DEVICE (pdev)->hotplugged) { +error_report ("PCI: rombar can't be 0 for hotplugged devices!" ); +return -1 ; + }rom_add_option (pdev->romfile,-1 ); }return 0 ;The message is confusing. rombar=0 is ok if you
don't also try to force romfile.
Generally why are you adding this logic in pci?Quoted 4 lines
Quoted 2 lines
Because
rom_add_optionwill call eventuallyrom_insertthat will crash QEMU with the call tohw_error.So fix
rom_insertto return an error code instead?OK, thanks
Quoted 11 lines
Quoted 9 lines
Quoted 2 lines
And what about e.g. vga?
This logic would apply also to
rom_add_vga, I was not aware we can hotplug vga devices. Can we?
I can add it also to vga, of course.Quoted 2 lines
I think the right thing to do is to propagate return codes correctly, and report the error where it occurs.
I can remove the
error_report, but this gives an extra hint to user.Move it to
rom_insert, instead ofhw_error.Quoted 8 lines
Quoted 4 lines
Sure, I was a little "afraid" to change the "crash" policy of
rom_insert.Thanks,
MarcelYou will need to audit all users, and make sure they check the error and handle it.
So it's a lot of work ...The truth is, while I don't mind getting into it, I was interested in solving the crash issue rather than re-factoring
hw_error.
I'll prefer to find a solution for the crash and defferhw_errorre-factoring to another series...Checking "hotplugged" at
pci_add_option_romfor bothrom_ad_optionandrom_add_vgacan be a PCI specific solution since it connects hotplug -> no rombar=0.
Quoted 5 lines
Propagating
rom_inserterror seems indeed difficult since the callers are mostly returning void.Thanks,
Marcel
But it's ugly, I'm not sure the crash as result of user error is important enough to justify this.
Quoted 16 lines
Quoted 14 lines
Quoted 14 lines
Quoted 12 lines
Quoted 12 lines
I didn't see any other way to propagate the error message. Should I drop it?
Thanks,
MarcelQuoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1