hw/pci: fixed crash when using rombar=0 with romfile=path for hotplugged devices
PATCH v2 1/1 hw/pci: fixed crash when using rombar=0 with romfile=path for hotplugged devices
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
---
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.
An OK from libvirt will be nice.
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
hw/pci/pci.c +15 -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 ; }
@@ -1937,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 ); + +/* +* For hot-plugged devices silently ignore the option ROM +* if the rom bar is disabled. +*/ +if (DEVICE (pdev)->hotplugged) { +return 0 ; + } +if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else {
Signature · 1 line
1.8.3.1
Quoted 11 lines · Marcel Apfelbaum
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
Signed-off-by Marcel Apfelbaum <[email protected]>---
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.An OK from libvirt will be nice.
Thanks,
Marcel
Quoted 38 lines
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)hw/pci/pci.c +15
-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 ; }@@ -1937,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 ); + +/* +* For hot-plugged devices silently ignore the option ROM +* if the rom bar is disabled. +*/ +if (DEVICE (pdev)->hotplugged) { +return 0 ; + } +if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else {
Quoted 4 lines · Marcel Apfelbaum
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
Signed-off-by Marcel Apfelbaum <[email protected]>
How about failing adding the device instead? Return error from pci_add_option_rom, and check at calling sites?
Quoted 47 lines
---
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.An OK from libvirt will be nice.
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)hw/pci/pci.c +15
-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 ; }@@ -1937,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 ); + +/* +* For hot-plugged devices silently ignore the option ROM +* if the rom bar is disabled. +*/ +if (DEVICE (pdev)->hotplugged) { +return 0 ; + } +if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else {Signature · 1 line
1.8.3.1
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Marcel Apfelbaum
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
Signed-off-by Marcel Apfelbaum <[email protected]>How about failing adding the device instead? Return error from
pci_add_option_rom, and check at calling sites?
This was was the prev version of this patch has done, we have only one calling site: pci_qdev_init.
I could tweak the prev version to return error on both rom_add_vga/rom_add_option, but I was under the impression that silently drop the romfile was discussion's decision.
I am fine both ways, as it is a user error and hopefully used correctly by libvirt. I only want to avoid the crash.
Thanks,
Marcel
Quoted 48 lines
Quoted 48 lines
---
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.An OK from libvirt will be nice.
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)hw/pci/pci.c +15
-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 ; }@@ -1937,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 ); + +/* +* For hot-plugged devices silently ignore the option ROM +* if the rom bar is disabled. +*/ +if (DEVICE (pdev)->hotplugged) { +return 0 ; + } +if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else {Signature · 1 line
1.8.3.1
Quoted 17 lines · Marcel Apfelbaum
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Marcel Apfelbaum
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
Signed-off-by Marcel Apfelbaum <[email protected]>How about failing adding the device instead? Return error from
pci_add_option_rom, and check at calling sites?This was was the prev version of this patch has done, we have only one calling site:
pci_qdev_init.
I could tweak the prev version to return error on both rom_add_vga/rom_add_option, but I was under the impression that silently drop the romfile was discussion's decision.
Quoted 5 lines
I am fine both ways, as it is a user error and hopefully used correctly by libvirt. I only want to avoid the crash.
Thanks,
Marcel
Let's try the non silent error.
If someone is unhappy we can make it silent again, but if it succeeds we'll have to keep it working forever.
Quoted 49 lines
Quoted 47 lines
Quoted 47 lines
---
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.An OK from libvirt will be nice.
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)hw/pci/pci.c +15
-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 ; }@@ -1937,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 ); + +/* +* For hot-plugged devices silently ignore the option ROM +* if the rom bar is disabled. +*/ +if (DEVICE (pdev)->hotplugged) { +return 0 ; + } +if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else {Signature · 1 line
1.8.3.1
Quoted 21 lines · Michael S. Tsirkin
Quoted 20 lines · Marcel Apfelbaum
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Marcel Apfelbaum
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
Signed-off-by Marcel Apfelbaum <[email protected]>How about failing adding the device instead? Return error from
pci_add_option_rom, and check at calling sites?This was was the prev version of this patch has done, we have only one calling site:
pci_qdev_init.
I could tweak the prev version to return error on both rom_add_vga/rom_add_option, but I was under the impression that silently drop the romfile was discussion's decision.I am fine both ways, as it is a user error and hopefully used correctly by libvirt. I only want to avoid the crash.
Quoted 6 lines
Quoted 2 lines
Thanks,
MarcelLet's try the non silent error.
If someone is unhappy we can make it silent again, but if it succeeds we'll have to keep it working forever.
I agree - from the libvirt perspective, it is better to be conservative and have a noisy failure on an incompatible combination, to prove no one is using it (or give us reason to relax it later), than to accidentally silently accept it and change from what was requested, and then find out people were relying on the silent change in semantics.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 23 lines · Marcel Apfelbaum
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
Signed-off-by Marcel Apfelbaum <[email protected]>---
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.An OK from libvirt will be nice.
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 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 ; }
Looks like this part isn't covered by the commit message.
Before: errors in pci_add_option_rom() are reported, but the function succeeds anyway. After: it fails. Is this a silent bug fix?
Quoted 6 lines
hw/pci/pci.c +2
-0@@ -1937,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 ); + +/*
hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1956
Quoted 10 lines
hw/pci/pci.c +7
-0+* For hot-plugged devices silently ignore the option ROM +* if the rom bar is disabled. +*/ +if (DEVICE (pdev)->hotplugged) { +return 0 ; + } +if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else {
This part is covered by the commit message.
Quoted 33 lines · Markus Armbruster
Quoted 31 lines · Marcel Apfelbaum
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
Signed-off-by Marcel Apfelbaum <[email protected]>---
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.An OK from libvirt will be nice.
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 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; + }
Quoted 7 lines
hw/pci/pci.c static int pci_qdev_init(DeviceState *qdev) · line 1787
Quoted 2 lines
hw/pci/pci.c +0
-0return 0 ; }Looks like this part isn't covered by the commit message.
Before: errors in
pci_add_option_rom()are reported, but the function succeeds anyway. After: it fails. Is this a silent bug fix?
Yes, it made sense for V1, less for V2, but I wanted to keep it. Should I split in 2 patches?
Quoted 19 lines
Quoted 7 lines
hw/pci/pci.c +2
-0@@ -1937,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 ); + +/* hw/pci/pci.c static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) · line 1956
Quoted 10 lines
hw/pci/pci.c +7
-0+* For hot-plugged devices silently ignore the option ROM +* if the rom bar is disabled. +*/ +if (DEVICE (pdev)->hotplugged) { +return 0 ; + } +if (class ==0x0300 ) {rom_add_vga (pdev->romfile); }else {This part is covered by the commit message.
Quoted 39 lines · Marcel Apfelbaum
Quoted 38 lines · Markus Armbruster
Quoted 23 lines · Marcel Apfelbaum
Combining rombar=0 with romfile=<path> is an user error, silently dropping the romfile is a reasonable thing to do.
Signed-off-by Marcel Apfelbaum <[email protected]>---
v1 -> v2:
After a discussion with Michael, Paolo and Alex, this patch silent drops the romfile instead of not allowing the hotplug.An OK from libvirt will be nice.
hw/pci/pci.c | 16 +++++++++++++++- 1 file changed, 15 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 ; }Looks like this part isn't covered by the commit message.
Quoted 4 lines
Quoted 2 lines
Before: errors in
pci_add_option_rom()are reported, but the function succeeds anyway. After: it fails. Is this a silent bug fix?Yes, it made sense for V1, less for V2, but I wanted to keep it. Should I split in 2 patches?
Yes, please.
[...]