From: "Michael S. Tsirkin" <mst@redhat.com>
To: Hu Tao <hutao@cn.fujitsu.com>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org, Igor Mammedov <imammedo@redhat.com>
Subject: Re: [Qemu-devel] [PATCH V3 for 2.1 2/2] exec: improve error handling and reporting in file_ram_alloc() and gethugepagesize()
Date: Mon, 7 Jul 2014 15:38:45 +0300 [thread overview]
Message-ID: <20140707123845.GA21346@redhat.com> (raw)
In-Reply-To: <ce0e5552fff550c4c27aa95faec9ffaa32ba6aa7.1404730357.git.hutao@cn.fujitsu.com>
On Mon, Jul 07, 2014 at 06:55:28PM +0800, Hu Tao wrote:
> This patch fixes two problems of memory-backend-file:
>
> 1. If user adds a memory-backend-file object using object_add command,
> specifying a non-existing directory for property mem-path, qemu
> will core dump with message:
>
> /nonexistingdir: No such file or directory
> Bad ram offset fffffffffffff000
> Aborted (core dumped)
>
> with this patch, qemu reports error message like:
>
> qemu-system-x86_64: -object memory-backend-file,mem-path=/nonexistingdir,id=mem-file0,size=128M:
> failed to stat file /nonexistingdir: No such file or directory
>
> 2. 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)
>
> 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 should be euqal or larger than huge page size 0x200000
>
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Build fails on 32 bit host
/scm/qemu/exec.c:1037:9: error: format ‘%llx’ expects argument of type
‘long long unsigned int’, but argument 5 has type ‘long unsigned int’
[-Werror=format=]
> ---
> exec.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index ca7741b..bb97b15 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -996,7 +996,7 @@ void qemu_mutex_unlock_ramlist(void)
>
> #define HUGETLBFS_MAGIC 0x958458f6
>
> -static long gethugepagesize(const char *path)
> +static long gethugepagesize(const char *path, Error **errp)
> {
> struct statfs fs;
> int ret;
> @@ -1006,7 +1006,7 @@ static long gethugepagesize(const char *path)
> } while (ret != 0 && errno == EINTR);
>
> if (ret != 0) {
> - perror(path);
> + error_setg_errno(errp, errno, "failed to get size of file %s", path);
> return 0;
> }
>
> @@ -1024,17 +1024,20 @@ static void *file_ram_alloc(RAMBlock *block,
> char *filename;
> char *sanitized_name;
> char *c;
> - void *area;
> + void *area = NULL;
> int fd;
> unsigned long hpagesize;
>
> - hpagesize = gethugepagesize(path);
> - if (!hpagesize) {
> + hpagesize = gethugepagesize(path, errp);
> + if (errp && *errp) {
> goto error;
> }
>
> if (memory < hpagesize) {
> - return NULL;
> + error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be euqal to "
> + "or larger than huge page size 0x%" PRIx64,
> + memory, hpagesize);
> + goto error;
> }
>
> if (kvm_enabled() && !kvm_has_sync_mmu()) {
> @@ -1094,8 +1097,8 @@ static void *file_ram_alloc(RAMBlock *block,
> return area;
>
> error:
> - if (mem_prealloc) {
> - exit(1);
> + if (area && area != MAP_FAILED) {
> + munmap(area, memory);
> }
> return NULL;
> }
> --
> 1.9.3
next prev parent reply other threads:[~2014-07-07 12:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-07 10:55 [Qemu-devel] [PATCH V3 for 2.1 0/2] bug fixs for memory backend Hu Tao
2014-07-07 10:55 ` [Qemu-devel] [PATCH V3 for 2.1 1/2] memory: add memory_region_init_ram_may_fail() and memory_region_init_ram_ptr_may_fail() Hu Tao
2014-07-07 12:27 ` Michael S. Tsirkin
2014-07-11 8:40 ` Hu Tao
2014-07-07 10:55 ` [Qemu-devel] [PATCH V3 for 2.1 2/2] exec: improve error handling and reporting in file_ram_alloc() and gethugepagesize() Hu Tao
2014-07-07 12:38 ` Michael S. Tsirkin [this message]
2014-07-07 12:39 ` [Qemu-devel] [PATCH V3 for 2.1 0/2] bug fixs for memory backend Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140707123845.GA21346@redhat.com \
--to=mst@redhat.com \
--cc=hutao@cn.fujitsu.com \
--cc=imammedo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=y-goto@jp.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.