* [Qemu-devel] [PATCH v2] cirrus_vga: adding sanity check for vram size
@ 2014-05-09 11:04 arei.gonglei
2014-05-09 11:15 ` Michael Tokarev
2014-05-09 11:39 ` Andreas Färber
0 siblings, 2 replies; 5+ messages in thread
From: arei.gonglei @ 2014-05-09 11:04 UTC (permalink / raw)
To: qemu-devel
Cc: weidong.huang, mst, blauwirbel, Gonglei, kraxel, pbonzini,
afaerber
From: Gonglei <arei.gonglei@huawei.com>
when configure a invalid vram size for cirrus card, such as less
2 MB, which will crash qemu. Follow the real hardware, the cirrus
card has 4 MB video memory. Also for backward compatibility, accept
8 MB and 16 MB vram size.
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
v2: fix checkpatch fails.
"WARNING: suspect code indent for conditional statements (5, 9)"
maybe not a real warning.
hw/display/cirrus_vga.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
index d1afc76..399a2ef 100644
--- a/hw/display/cirrus_vga.c
+++ b/hw/display/cirrus_vga.c
@@ -2959,6 +2959,14 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
int16_t device_id = pc->device_id;
+ /* follow real hardware, cirrus card emulated has 4 MB video memory.
+ Also accept 8 MB/16 MB for backward compatibility. */
+ if (s->vga.vram_size_mb != 4 || s->vga.vram_size_mb != 8 ||
+ s->vga.vram_size_mb != 16) {
+ error_report("Invalid cirrus_vga ram size '%u'\n",
+ s->vga.vram_size_mb);
+ return -1;
+ }
/* setup VGA */
vga_common_init(&s->vga, OBJECT(dev), true);
cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev),
--
1.7.12.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] cirrus_vga: adding sanity check for vram size
2014-05-09 11:04 [Qemu-devel] [PATCH v2] cirrus_vga: adding sanity check for vram size arei.gonglei
@ 2014-05-09 11:15 ` Michael Tokarev
2014-05-12 6:39 ` Gonglei (Arei)
2014-05-09 11:39 ` Andreas Färber
1 sibling, 1 reply; 5+ messages in thread
From: Michael Tokarev @ 2014-05-09 11:15 UTC (permalink / raw)
To: arei.gonglei, qemu-devel
Cc: weidong.huang, mst, blauwirbel, kraxel, pbonzini, afaerber
09.05.2014 15:04, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
>
> when configure a invalid vram size for cirrus card, such as less
> 2 MB, which will crash qemu. Follow the real hardware, the cirrus
> card has 4 MB video memory. Also for backward compatibility, accept
> 8 MB and 16 MB vram size.
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
> v2: fix checkpatch fails.
> "WARNING: suspect code indent for conditional statements (5, 9)"
> maybe not a real warning.
>
> hw/display/cirrus_vga.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
> index d1afc76..399a2ef 100644
> --- a/hw/display/cirrus_vga.c
> +++ b/hw/display/cirrus_vga.c
> @@ -2959,6 +2959,14 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
> PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
> int16_t device_id = pc->device_id;
>
> + /* follow real hardware, cirrus card emulated has 4 MB video memory.
> + Also accept 8 MB/16 MB for backward compatibility. */
> + if (s->vga.vram_size_mb != 4 || s->vga.vram_size_mb != 8 ||
> + s->vga.vram_size_mb != 16) {
This condition will always be true, because a number can't be equal
to 3 _different_ numbers at the same time.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] cirrus_vga: adding sanity check for vram size
2014-05-09 11:15 ` Michael Tokarev
@ 2014-05-12 6:39 ` Gonglei (Arei)
0 siblings, 0 replies; 5+ messages in thread
From: Gonglei (Arei) @ 2014-05-12 6:39 UTC (permalink / raw)
To: Michael Tokarev, qemu-devel@nongnu.org
Cc: Huangweidong (C), mst@redhat.com, blauwirbel@gmail.com,
kraxel@redhat.com, pbonzini@redhat.com, afaerber@suse.de
Hi,
> > diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
> > index d1afc76..399a2ef 100644
> > --- a/hw/display/cirrus_vga.c
> > +++ b/hw/display/cirrus_vga.c
> > @@ -2959,6 +2959,14 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
> > PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
> > int16_t device_id = pc->device_id;
> >
> > + /* follow real hardware, cirrus card emulated has 4 MB video
> memory.
> > + Also accept 8 MB/16 MB for backward compatibility. */
> > + if (s->vga.vram_size_mb != 4 || s->vga.vram_size_mb != 8 ||
> > + s->vga.vram_size_mb != 16) {
>
> This condition will always be true, because a number can't be equal
> to 3 _different_ numbers at the same time.
>
Yep, good catch. Thanks.
Best regards,
-Gonglei
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] cirrus_vga: adding sanity check for vram size
2014-05-09 11:04 [Qemu-devel] [PATCH v2] cirrus_vga: adding sanity check for vram size arei.gonglei
2014-05-09 11:15 ` Michael Tokarev
@ 2014-05-09 11:39 ` Andreas Färber
2014-05-12 6:46 ` Gonglei (Arei)
1 sibling, 1 reply; 5+ messages in thread
From: Andreas Färber @ 2014-05-09 11:39 UTC (permalink / raw)
To: arei.gonglei, qemu-devel; +Cc: blauwirbel, pbonzini, weidong.huang, kraxel, mst
Am 09.05.2014 13:04, schrieb arei.gonglei@huawei.com:
> From: Gonglei <arei.gonglei@huawei.com>
>
> when configure a invalid vram size for cirrus card, such as less
> 2 MB, which will crash qemu. Follow the real hardware, the cirrus
> card has 4 MB video memory. Also for backward compatibility, accept
> 8 MB and 16 MB vram size.
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
> v2: fix checkpatch fails.
> "WARNING: suspect code indent for conditional statements (5, 9)"
> maybe not a real warning.
>
> hw/display/cirrus_vga.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
> index d1afc76..399a2ef 100644
> --- a/hw/display/cirrus_vga.c
> +++ b/hw/display/cirrus_vga.c
> @@ -2959,6 +2959,14 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
> PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
> int16_t device_id = pc->device_id;
>
> + /* follow real hardware, cirrus card emulated has 4 MB video memory.
> + Also accept 8 MB/16 MB for backward compatibility. */
> + if (s->vga.vram_size_mb != 4 || s->vga.vram_size_mb != 8 ||
> + s->vga.vram_size_mb != 16) {
Apart from the logic bug mjt already pointed out, I note that this check
is in the PCI initfn. Should the same restriction also apply for the ISA
version of the device?
> + error_report("Invalid cirrus_vga ram size '%u'\n",
> + s->vga.vram_size_mb);
Thanks for using our new error_report(). It does not require a trailing
\n though.
Regards,
Andreas
> + return -1;
> + }
> /* setup VGA */
> vga_common_init(&s->vga, OBJECT(dev), true);
> cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev),
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] cirrus_vga: adding sanity check for vram size
2014-05-09 11:39 ` Andreas Färber
@ 2014-05-12 6:46 ` Gonglei (Arei)
0 siblings, 0 replies; 5+ messages in thread
From: Gonglei (Arei) @ 2014-05-12 6:46 UTC (permalink / raw)
To: Andreas Färber, qemu-devel@nongnu.org
Cc: blauwirbel@gmail.com, pbonzini@redhat.com, Huangweidong (C),
kraxel@redhat.com, mst@redhat.com
Hi,
> > diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
> > index d1afc76..399a2ef 100644
> > --- a/hw/display/cirrus_vga.c
> > +++ b/hw/display/cirrus_vga.c
> > @@ -2959,6 +2959,14 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
> > PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
> > int16_t device_id = pc->device_id;
> >
> > + /* follow real hardware, cirrus card emulated has 4 MB video
> memory.
> > + Also accept 8 MB/16 MB for backward compatibility. */
> > + if (s->vga.vram_size_mb != 4 || s->vga.vram_size_mb != 8 ||
> > + s->vga.vram_size_mb != 16) {
>
> Apart from the logic bug mjt already pointed out, I note that this check
> is in the PCI initfn. Should the same restriction also apply for the ISA
> version of the device?
>
Yes, I have noted this issue in v1. In other mail, you gave me some advices,
thanks a lot, Andreas. I will post v3.
> > + error_report("Invalid cirrus_vga ram size '%u'\n",
> > + s->vga.vram_size_mb);
>
> Thanks for using our new error_report(). It does not require a trailing
> \n though.
>
Got it. Thanks.
Best regards,
-Gonglei
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-12 6:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-09 11:04 [Qemu-devel] [PATCH v2] cirrus_vga: adding sanity check for vram size arei.gonglei
2014-05-09 11:15 ` Michael Tokarev
2014-05-12 6:39 ` Gonglei (Arei)
2014-05-09 11:39 ` Andreas Färber
2014-05-12 6:46 ` Gonglei (Arei)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).