memory-device: rewrite address assignment using ranges
authorDavid Hildenbrand <david@redhat.com>
Fri, 14 Dec 2018 13:10:43 +0000 (14:10 +0100)
committerEduardo Habkost <ehabkost@redhat.com>
Thu, 10 Jan 2019 00:09:31 +0000 (22:09 -0200)
commite3213eb5ecd541f182e1a5a719feed99d6b225af
treec41f6b9d9afbd6580322c9ae6b9c2293fdc99c1f
parentf3b0b626f615c6155d0cbb2f1781e1d1476144fc
memory-device: rewrite address assignment using ranges

Let's rewrite it properly using ranges. This fixes certain overflows that
are right now possible. E.g.

qemu-system-x86_64 -m 4G,slots=20,maxmem=40G -M pc \
    -object memory-backend-file,id=mem1,share,mem-path=/dev/zero,size=2G
    -device pc-dimm,memdev=mem1,id=dimm1,addr=-0x40000000

Now properly errors out instead of succeeding. (Note that qapi
parsing of huge uint64_t values is broken and fixes are on the way)

"can't add memory device [0xffffffffa0000000:0x80000000], usable range for
memory devices [0x140000000:0xe00000000]"

Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20181214131043.25071-3-david@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
hw/mem/memory-device.c