Patchwork memory: fix a bug of detection of memory region collision

login
register
mail settings
Submitter Hu Tao
Date March 15, 2013, 6:32 a.m.
Message ID <1363329121-20625-1-git-send-email-hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/227856/
State New
Headers show

Comments

Hu Tao - March 15, 2013, 6:32 a.m.
The collision reports before and after this patch are:

before:

warning: subregion collision cfc/4 (pci-conf-data) vs cf8/4 (pci-conf-idx)
warning: subregion collision 8000000/f8000000 (pci-hole) vs 0/8000000 (ram-below-4g)
warning: subregion collision 100000000/4000000000000000 (pci-hole64) vs 8000000/f8000000 (pci-hole)
warning: subregion collision 4d1/1 (kvm-elcr) vs 4d0/1 (kvm-elcr)
warning: subregion collision fec00000/1000 (kvm-ioapic) vs 8000000/f8000000 (pci-hole)
warning: subregion collision 80/1 (ioport80) vs 7e/2 (kvmvapic)
warning: subregion collision fed00000/400 (hpet) vs 8000000/f8000000 (pci-hole)
warning: subregion collision 81/3 (dma-page) vs 80/1 (ioport80)
warning: subregion collision 8/8 (dma-cont) vs 0/8 (dma-chan)
warning: subregion collision d0/10 (dma-cont) vs c0/10 (dma-chan)
warning: subregion collision 0/80 (ich9-pm) vs 8/8 (dma-cont)
warning: subregion collision 0/80 (ich9-pm) vs 0/8 (dma-chan)
warning: subregion collision 0/80 (ich9-pm) vs 64/1 (i8042-cmd)
warning: subregion collision 0/80 (ich9-pm) vs 60/1 (i8042-data)
warning: subregion collision 0/80 (ich9-pm) vs 61/1 (elcr)
warning: subregion collision 0/80 (ich9-pm) vs 40/4 (kvm-pit)
warning: subregion collision 0/80 (ich9-pm) vs 70/2 (rtc)
warning: subregion collision 0/80 (ich9-pm) vs 20/2 (kvm-pic)
warning: subregion collision 0/80 (ich9-pm) vs 7e/2 (kvmvapic)
warning: subregion collision 4/2 (acpi-cnt) vs 0/4 (acpi-evt)
warning: subregion collision 30/8 (apci-smi) vs 20/10 (apci-gpe0)
warning: subregion collision b0000000/10000000 (pcie-mmcfg) vs 8000000/f8000000 (pci-hole)

after:

warning: subregion collision fec00000/1000 (kvm-ioapic) vs 8000000/f8000000 (pci-hole)
warning: subregion collision fed00000/400 (hpet) vs 8000000/f8000000 (pci-hole)
warning: subregion collision 0/80 (ich9-pm) vs 8/8 (dma-cont)
warning: subregion collision 0/80 (ich9-pm) vs 0/8 (dma-chan)
warning: subregion collision 0/80 (ich9-pm) vs 64/1 (i8042-cmd)
warning: subregion collision 0/80 (ich9-pm) vs 60/1 (i8042-data)
warning: subregion collision 0/80 (ich9-pm) vs 61/1 (elcr)
warning: subregion collision 0/80 (ich9-pm) vs 40/4 (kvm-pit)
warning: subregion collision 0/80 (ich9-pm) vs 70/2 (rtc)
warning: subregion collision 0/80 (ich9-pm) vs 20/2 (kvm-pic)
warning: subregion collision 0/80 (ich9-pm) vs 7e/2 (kvmvapic)
warning: subregion collision b0000000/10000000 (pcie-mmcfg) vs 8000000/f8000000 (pci-hole)

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Stefan Hajnoczi - March 22, 2013, 12:22 p.m.
On Fri, Mar 15, 2013 at 02:32:01PM +0800, Hu Tao wrote:
> The collision reports before and after this patch are:
> 
> before:
> 
> warning: subregion collision cfc/4 (pci-conf-data) vs cf8/4 (pci-conf-idx)
> warning: subregion collision 8000000/f8000000 (pci-hole) vs 0/8000000 (ram-below-4g)
> warning: subregion collision 100000000/4000000000000000 (pci-hole64) vs 8000000/f8000000 (pci-hole)
> warning: subregion collision 4d1/1 (kvm-elcr) vs 4d0/1 (kvm-elcr)
> warning: subregion collision fec00000/1000 (kvm-ioapic) vs 8000000/f8000000 (pci-hole)
> warning: subregion collision 80/1 (ioport80) vs 7e/2 (kvmvapic)
> warning: subregion collision fed00000/400 (hpet) vs 8000000/f8000000 (pci-hole)
> warning: subregion collision 81/3 (dma-page) vs 80/1 (ioport80)
> warning: subregion collision 8/8 (dma-cont) vs 0/8 (dma-chan)
> warning: subregion collision d0/10 (dma-cont) vs c0/10 (dma-chan)
> warning: subregion collision 0/80 (ich9-pm) vs 8/8 (dma-cont)
> warning: subregion collision 0/80 (ich9-pm) vs 0/8 (dma-chan)
> warning: subregion collision 0/80 (ich9-pm) vs 64/1 (i8042-cmd)
> warning: subregion collision 0/80 (ich9-pm) vs 60/1 (i8042-data)
> warning: subregion collision 0/80 (ich9-pm) vs 61/1 (elcr)
> warning: subregion collision 0/80 (ich9-pm) vs 40/4 (kvm-pit)
> warning: subregion collision 0/80 (ich9-pm) vs 70/2 (rtc)
> warning: subregion collision 0/80 (ich9-pm) vs 20/2 (kvm-pic)
> warning: subregion collision 0/80 (ich9-pm) vs 7e/2 (kvmvapic)
> warning: subregion collision 4/2 (acpi-cnt) vs 0/4 (acpi-evt)
> warning: subregion collision 30/8 (apci-smi) vs 20/10 (apci-gpe0)
> warning: subregion collision b0000000/10000000 (pcie-mmcfg) vs 8000000/f8000000 (pci-hole)
> 
> after:
> 
> warning: subregion collision fec00000/1000 (kvm-ioapic) vs 8000000/f8000000 (pci-hole)
> warning: subregion collision fed00000/400 (hpet) vs 8000000/f8000000 (pci-hole)
> warning: subregion collision 0/80 (ich9-pm) vs 8/8 (dma-cont)
> warning: subregion collision 0/80 (ich9-pm) vs 0/8 (dma-chan)
> warning: subregion collision 0/80 (ich9-pm) vs 64/1 (i8042-cmd)
> warning: subregion collision 0/80 (ich9-pm) vs 60/1 (i8042-data)
> warning: subregion collision 0/80 (ich9-pm) vs 61/1 (elcr)
> warning: subregion collision 0/80 (ich9-pm) vs 40/4 (kvm-pit)
> warning: subregion collision 0/80 (ich9-pm) vs 70/2 (rtc)
> warning: subregion collision 0/80 (ich9-pm) vs 20/2 (kvm-pic)
> warning: subregion collision 0/80 (ich9-pm) vs 7e/2 (kvmvapic)
> warning: subregion collision b0000000/10000000 (pcie-mmcfg) vs 8000000/f8000000 (pci-hole)
> 
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  memory.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

The int128_le() comparison below suggests that int128_gt() really should
be int128_ge().

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan
Peter Maydell - March 22, 2013, 12:50 p.m.
On 22 March 2013 12:22, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> The int128_le() comparison below suggests that int128_gt() really should
> be int128_ge().

Agreed. It might be clearer to rephrase as:

 AddrRange thisrange = addrrange_make(int128_make64(offset),
                                      int128_make64(subregion->size));

 QTAILQ_FOREACH(....) {
     [...]
     AddrRange otherrange = addrrange_make(int128_make64(other->addr),
                                           int128_make64(other->size));
     if (!addrrange_intersects(thisrange, otherrange)) {
         continue;
     }
     [...]
 }

(maybe with a new utility addrrange_make_64() that takes uint64_ts;
there are a few other places in memory.c that could use it.)

-- PMM

Patch

diff --git a/memory.c b/memory.c
index 92a2196..75ca281 100644
--- a/memory.c
+++ b/memory.c
@@ -1321,7 +1321,7 @@  static void memory_region_add_subregion_common(MemoryRegion *mr,
         if (subregion->may_overlap || other->may_overlap) {
             continue;
         }
-        if (int128_gt(int128_make64(offset),
+        if (int128_ge(int128_make64(offset),
                       int128_add(int128_make64(other->addr), other->size))
             || int128_le(int128_add(int128_make64(offset), subregion->size),
                          int128_make64(other->addr))) {