* [patch 0/3] QEMU: virtio should register power of two sized regions
@ 2008-03-17 20:20 Marcelo Tosatti
2008-03-17 20:20 ` [patch 1/3] QEMU/KVM: add fls() Marcelo Tosatti
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Marcelo Tosatti @ 2008-03-17 20:20 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel
Otherwise the guest will miscalculate the region size.
--
-------------------------------------------------------------------------
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch 1/3] QEMU/KVM: add fls()
2008-03-17 20:20 [patch 0/3] QEMU: virtio should register power of two sized regions Marcelo Tosatti
@ 2008-03-17 20:20 ` Marcelo Tosatti
2008-03-17 20:20 ` [patch 2/3] QEMU/KVM: virtio register pow2 memory regions Marcelo Tosatti
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Marcelo Tosatti @ 2008-03-17 20:20 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Marcelo Tosatti
[-- Attachment #1: add-fls --]
[-- Type: text/plain, Size: 1170 bytes --]
Find Last Set, in accordance with glibc's ffs.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: kvm-userspace.hotplug3/qemu/cutils.c
===================================================================
--- kvm-userspace.hotplug3.orig/qemu/cutils.c
+++ kvm-userspace.hotplug3/qemu/cutils.c
@@ -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;
+}
+
Index: kvm-userspace.hotplug3/qemu/qemu-common.h
===================================================================
--- kvm-userspace.hotplug3.orig/qemu/qemu-common.h
+++ kvm-userspace.hotplug3/qemu/qemu-common.h
@@ -87,6 +87,7 @@ int stristart(const char *str, const cha
time_t mktimegm(struct tm *tm);
int hex2bin(char ch);
char *urldecode(const char *ptr);
+int fls(int i);
/* Error handling. */
--
-------------------------------------------------------------------------
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch 2/3] QEMU/KVM: virtio register pow2 memory regions
2008-03-17 20:20 [patch 0/3] QEMU: virtio should register power of two sized regions Marcelo Tosatti
2008-03-17 20:20 ` [patch 1/3] QEMU/KVM: add fls() Marcelo Tosatti
@ 2008-03-17 20:20 ` Marcelo Tosatti
2008-03-17 20:20 ` [patch 3/3] QEMU/KVM: bail out if PCI region is not power of two Marcelo Tosatti
2008-03-18 6:38 ` [patch 0/3] QEMU: virtio should register power of two sized regions Avi Kivity
3 siblings, 0 replies; 5+ messages in thread
From: Marcelo Tosatti @ 2008-03-17 20:20 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Marcelo Tosatti
[-- Attachment #1: fix-virtio --]
[-- Type: text/plain, Size: 1256 bytes --]
Otherwise the PCI size for such regions will be calculated erroneously.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Index: kvm-userspace.hotplug3/qemu/hw/virtio.c
===================================================================
--- kvm-userspace.hotplug3.orig/qemu/hw/virtio.c
+++ kvm-userspace.hotplug3/qemu/hw/virtio.c
@@ -404,6 +404,7 @@ VirtIODevice *virtio_init_pci(PCIBus *bu
VirtIODevice *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 *bu
else
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);
--
-------------------------------------------------------------------------
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch 3/3] QEMU/KVM: bail out if PCI region is not power of two
2008-03-17 20:20 [patch 0/3] QEMU: virtio should register power of two sized regions Marcelo Tosatti
2008-03-17 20:20 ` [patch 1/3] QEMU/KVM: add fls() Marcelo Tosatti
2008-03-17 20:20 ` [patch 2/3] QEMU/KVM: virtio register pow2 memory regions Marcelo Tosatti
@ 2008-03-17 20:20 ` Marcelo Tosatti
2008-03-18 6:38 ` [patch 0/3] QEMU: virtio should register power of two sized regions Avi Kivity
3 siblings, 0 replies; 5+ messages in thread
From: Marcelo Tosatti @ 2008-03-17 20:20 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Marcelo Tosatti
[-- Attachment #1: pci-warn-region-mem --]
[-- Type: text/plain, Size: 859 bytes --]
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: kvm-userspace.hotplug3/qemu/hw/pci.c
===================================================================
--- kvm-userspace.hotplug3.orig/qemu/hw/pci.c
+++ kvm-userspace.hotplug3/qemu/hw/pci.c
@@ -236,6 +236,11 @@ void pci_register_io_region(PCIDevice *p
if ((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;
--
-------------------------------------------------------------------------
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 0/3] QEMU: virtio should register power of two sized regions
2008-03-17 20:20 [patch 0/3] QEMU: virtio should register power of two sized regions Marcelo Tosatti
` (2 preceding siblings ...)
2008-03-17 20:20 ` [patch 3/3] QEMU/KVM: bail out if PCI region is not power of two Marcelo Tosatti
@ 2008-03-18 6:38 ` Avi Kivity
3 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2008-03-18 6:38 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: kvm-devel
Marcelo Tosatti wrote:
> Otherwise the guest will miscalculate the region size.
>
>
Applied all, thanks.
--
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-03-18 6:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-17 20:20 [patch 0/3] QEMU: virtio should register power of two sized regions Marcelo Tosatti
2008-03-17 20:20 ` [patch 1/3] QEMU/KVM: add fls() Marcelo Tosatti
2008-03-17 20:20 ` [patch 2/3] QEMU/KVM: virtio register pow2 memory regions Marcelo Tosatti
2008-03-17 20:20 ` [patch 3/3] QEMU/KVM: bail out if PCI region is not power of two Marcelo Tosatti
2008-03-18 6:38 ` [patch 0/3] QEMU: virtio should register power of two sized regions Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox