Message ID | 124f9c026652aca0eb95c4210c0eaee108e390fe.1408096657.git.hutao@cn.fujitsu.com |
---|---|
State | New |
Headers | show |
On Fri, Aug 15, 2014 at 8:07 PM, Hu Tao <hutao@cn.fujitsu.com> wrote: > Report an error when memory < hpagesize in file_ram_alloc() so callers > can handle the error. > > If user adds a memory-backend-file object using object_add command, > specifying a size that is less than huge page size, qemu will core dump > with message: > > Bad ram offset fffffffffffff000 > Aborted (core dumped) > > This patch fixes the problem. With this patch, qemu reports error > message like: > > qemu-system-x86_64: -object memory-backend-file,mem-path=/hugepages,id=mem-file0,size=1M: memory > size 0x100000 must be equal to or larger than huge page size 0x200000 > > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> > --- > exec.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/exec.c b/exec.c > index c361752..ed59f3c 100644 > --- a/exec.c > +++ b/exec.c > @@ -1024,9 +1024,9 @@ static void *file_ram_alloc(RAMBlock *block, > char *filename; > char *sanitized_name; > char *c; > - void *area; > + void *area = NULL; > int fd; > - unsigned long hpagesize; > + uint64_t hpagesize; > > hpagesize = gethugepagesize(path); > if (!hpagesize) { > @@ -1034,7 +1034,10 @@ static void *file_ram_alloc(RAMBlock *block, > } > > if (memory < hpagesize) { > - return NULL; > + error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " > + "or larger than huge page size 0x%" PRIx64, > + memory, hpagesize); > + goto error; > } > > if (kvm_enabled() && !kvm_has_sync_mmu()) { > -- > 1.9.3 > >
diff --git a/exec.c b/exec.c index c361752..ed59f3c 100644 --- a/exec.c +++ b/exec.c @@ -1024,9 +1024,9 @@ static void *file_ram_alloc(RAMBlock *block, char *filename; char *sanitized_name; char *c; - void *area; + void *area = NULL; int fd; - unsigned long hpagesize; + uint64_t hpagesize; hpagesize = gethugepagesize(path); if (!hpagesize) { @@ -1034,7 +1034,10 @@ static void *file_ram_alloc(RAMBlock *block, } if (memory < hpagesize) { - return NULL; + error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " + "or larger than huge page size 0x%" PRIx64, + memory, hpagesize); + goto error; } if (kvm_enabled() && !kvm_has_sync_mmu()) {
Report an error when memory < hpagesize in file_ram_alloc() so callers can handle the error. If user adds a memory-backend-file object using object_add command, specifying a size that is less than huge page size, qemu will core dump with message: Bad ram offset fffffffffffff000 Aborted (core dumped) This patch fixes the problem. With this patch, qemu reports error message like: qemu-system-x86_64: -object memory-backend-file,mem-path=/hugepages,id=mem-file0,size=1M: memory size 0x100000 must be equal to or larger than huge page size 0x200000 Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- exec.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)