QEMU: virtio should register power of two sized regions
cover QEMU: virtio should register power of two sized regions
Otherwise the guest will miscalculate the region size.
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 1/3 QEMU/KVM: add fls()
Find Last Set, in accordance with glibc's ffs.
Signed-off-by Marcelo Tosatti <[email protected]>
qemu/cutils.c +11 -0
@@ -135,3 +135,14 @@ char *urldecode(const char *ptr)return ret; } +int fls (int i) +{ +int bit; + +for (bit=31 ; bit >=0 ; bit--) +if (i & (1 << bit)) +return bit+1 ; + +return 0 ; +} +
qemu/qemu-common.h +1 -0
@@ -87,6 +87,7 @@ int stristart(const char *str, const chatime_t mktimegm (struct tm *tm);int hex2bin (char ch);char *urldecode (const char *ptr); +int fls (int i);/* Error handling. */
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 2/3 QEMU/KVM: virtio register pow2 memory regions
In reply to Marcelo TosattiOtherwise the PCI size for such regions will be calculated erroneously.
Signed-off-by Marcelo Tosatti <[email protected]>
Cc Anthony Liguori <[email protected]>
qemu/hw/virtio.c +6 -1
@@ -404,6 +404,7 @@ VirtIODevice *virtio_init_pci(PCIBus *buVirtIODevice *vdev;PCIDevice *pci_dev;uint8_t *config; +uint32_t size; pci_dev =pci_register_device (bus, name, struct_size,-1 ,NULL ,NULL );
@@ -441,7 +442,11 @@ VirtIODevice *virtio_init_pci(PCIBus *buelse vdev->config =NULL ; -pci_register_io_region (pci_dev,0 ,20 + config_size,PCI_ADDRESS_SPACE_IO , + size =20 + config_size; +if (size & (size-1 )) + size =1 <<fls (size); + +pci_register_io_region (pci_dev,0 , size,PCI_ADDRESS_SPACE_IO , virtio_map);qemu_register_reset (virtio_reset, vdev);
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 3/3 QEMU/KVM: bail out if PCI region is not power of two
In reply to Marcelo TosattiSigned-off-by Marcelo Tosatti <[email protected]>
qemu/hw/pci.c +5 -0
@@ -236,6 +236,11 @@ void pci_register_io_region(PCIDevice *pif ((unsigned int )region_num >=PCI_NUM_REGIONS )return ; + +if (size & (size-1 )) +term_printf ("WARNING: PCI region size must be pow2 " +"type=0x%x, size=0x%x\n" , type, size); + r = &pci_dev->io_regions[region_num]; r->addr =-1 ; r->size = size;
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Avi Kivity
AppliedQuoted 3 lines · Marcelo Tosatti
Otherwise the guest will miscalculate the region size.
Applied all, thanks.
Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/