hw/pci: fixed hotplug crash when using rombar=0 with devices having romfile
v3 cover hw/pci: fixed hotplug crash when using rombar=0 with devices having romfile
Hot-plugging a device that has a romfile (either supplied by user or built-in) using rombar=0 option is an user error,
do not allow the device to be hot-plugged.
v2 -> v3:
- Reverse the decision to forbit the hotplug on user error (Michael S. Tsirkin)
- Split the patch in two, first part being a separate fix (Markus Armbruster)
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.
Marcel Apfelbaum (2):
hw/pci: fixed error flow in pci_qdev_init
hw/pci: fixed hotplug crash when using rombar=0 with devices having
romfile
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.1
PATCH v3 1/2 hw/pci: fixed error flow in pci_qdev_init
Verify return code for pci_add_option_rom.
--- hw/pci/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/pci/pci.c +6 -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 ; }
Signature · 1 line
1.8.3.1
PATCH v3 2/2 hw/pci: fixed hotplug crash when using rombar=0 with devices having romfile
In reply to Marcel ApfelbaumHot-plugging a device that has a romfile (either supplied by user or built-in) using rombar=0 option is an user error,
do not allow the device to be hot-plugged.
--- hw/pci/pci.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/pci/pci.c +9 -0
@@ -1942,6 +1942,15 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)* for 0.11 compatibility. */ int class =pci_get_word (pdev->config +PCI_CLASS_DEVICE ); + +/* +* Hot-plugged devices can't use the option ROM +* if the rom bar is disabled. +*/ +if (DEVICE (pdev)->hotplugged) { +return -1 ; + } +if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else {
Signature · 1 line
1.8.3.1
Quoted 2 lines · Marcel Apfelbaum
Hot-plugging a device that has a romfile (either supplied by user or built-in) using rombar=0 option is an user error,
s/an/a/ (user is pronounced with a leading hard "y" sound rather than a soft "u", it may help to remember you can "give a unicorn an umbrella")
Quoted 7 lines
do not allow the device to be hot-plugged.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 9 +++++++++ 1 file changed, 9 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 6 lines · Eric Blake
Quoted 2 lines · Marcel Apfelbaum
Hot-plugging a device that has a romfile (either supplied by user or built-in) using rombar=0 option is an user error,
s/an/a/ (user is pronounced with a leading hard "y" sound rather than a soft "u", it may help to remember you can "give a unicorn an umbrella")
Thanks, still hard to get it right, but your tip will surely help :)
Michael, do you want me to send another version,
or you can change it on the fly?
Thanks,
Marcel
Quoted 11 lines
Quoted 8 lines
do not allow the device to be hot-plugged.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 9 +++++++++ 1 file changed, 9 insertions(+)Reviewed-by Eric Blake <[email protected]>
Quoted 7 lines · Marcel Apfelbaum
Quoted 6 lines · Eric Blake
Quoted 2 lines · Marcel Apfelbaum
Hot-plugging a device that has a romfile (either supplied by user or built-in) using rombar=0 option is an user error,
s/an/a/ (user is pronounced with a leading hard "y" sound rather than a soft "u", it may help to remember you can "give a unicorn an umbrella")
Quoted 7 lines
Thanks, still hard to get it right, but your tip will surely help :)
Michael, do you want me to send another version,
or you can change it on the fly?Thanks,
Marcel
go ahead and repost, easier for me.
Quoted 13 lines
Quoted 11 lines
Quoted 8 lines
do not allow the device to be hot-plugged.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci.c | 9 +++++++++ 1 file changed, 9 insertions(+)Reviewed-by Eric Blake <[email protected]>