[Qemu-devel] [PATCH] hostmem-file: make available memory-backend-file on macOS hosts

hikarupsp@gmail.com posted 1 patch 7 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180924081304.19475-1-hikarupsp@gmail.com
Test docker-clang@ubuntu failed
Test checkpatch passed
backends/Makefile.objs  | 1 +
backends/hostmem-file.c | 2 +-
exec.c                  | 4 ++--
include/exec/memory.h   | 2 +-
memory.c                | 2 +-
5 files changed, 6 insertions(+), 5 deletions(-)
[Qemu-devel] [PATCH] hostmem-file: make available memory-backend-file on macOS hosts
Posted by hikarupsp@gmail.com 7 years, 1 month ago
From: Hikaru Nishida <hikarupsp@gmail.com>

Before this change, memory-backend-file object is invalid for macOS
hosts because hostmem-file.c is compiled only on Linux hosts.
However, macOS hosts can support memory-backend-file object in the same
way as on Linux hosts.
This patch makes hostmem-file.c and related functions to be compiled on
macOS hosts as well to make available memory-backend-file on macOS.

Signed-off-by: Hikaru Nishida <hikarupsp@gmail.com>
---
 backends/Makefile.objs  | 1 +
 backends/hostmem-file.c | 2 +-
 exec.c                  | 4 ++--
 include/exec/memory.h   | 2 +-
 memory.c                | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index ad7c0325ed..a0558a21d9 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -5,6 +5,7 @@ common-obj-$(CONFIG_TPM) += tpm.o
 
 common-obj-y += hostmem.o hostmem-ram.o
 common-obj-$(CONFIG_LINUX) += hostmem-file.o
+common-obj-$(CONFIG_DARWIN) += hostmem-file.o
 
 common-obj-y += cryptodev.o
 common-obj-y += cryptodev-builtin.o
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 2476dcb435..e12ec9538a 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -51,7 +51,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
         error_setg(errp, "mem-path property not set");
         return;
     }
-#ifndef CONFIG_LINUX
+#if !defined(CONFIG_LINUX) && !defined(CONFIG_DARWIN)
     error_setg(errp, "-mem-path not supported on this host");
 #else
     if (!host_memory_backend_mr_inited(backend)) {
diff --git a/exec.c b/exec.c
index 6826c8337d..602da77fb8 100644
--- a/exec.c
+++ b/exec.c
@@ -1734,7 +1734,7 @@ long qemu_getrampagesize(void)
 }
 #endif
 
-#ifdef __linux__
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
 static int64_t get_file_size(int fd)
 {
     int64_t size = lseek(fd, 0, SEEK_END);
@@ -2230,7 +2230,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
     }
 }
 
-#ifdef __linux__
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
                                  Error **errp)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index eb4f2fb249..86d6696306 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -633,7 +633,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
                                                        uint64_t length,
                                                        void *host),
                                        Error **errp);
-#ifdef __linux__
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
 
 /**
  * memory_region_init_ram_from_file:  Initialize RAM memory region with a
diff --git a/memory.c b/memory.c
index 9b73892768..88422c3cac 100644
--- a/memory.c
+++ b/memory.c
@@ -1545,7 +1545,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
     mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
 }
 
-#ifdef __linux__
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
 void memory_region_init_ram_from_file(MemoryRegion *mr,
                                       struct Object *owner,
                                       const char *name,
-- 
2.15.2 (Apple Git-101.1)


Re: [Qemu-devel] [PATCH] hostmem-file: make available memory-backend-file on macOS hosts
Posted by Paolo Bonzini 7 years, 1 month ago
On 24/09/2018 10:13, hikarupsp@gmail.com wrote:
> From: Hikaru Nishida <hikarupsp@gmail.com>
> 
> Before this change, memory-backend-file object is invalid for macOS
> hosts because hostmem-file.c is compiled only on Linux hosts.
> However, macOS hosts can support memory-backend-file object in the same
> way as on Linux hosts.
> This patch makes hostmem-file.c and related functions to be compiled on
> macOS hosts as well to make available memory-backend-file on macOS.
> 
> Signed-off-by: Hikaru Nishida <hikarupsp@gmail.com>
> ---
>  backends/Makefile.objs  | 1 +
>  backends/hostmem-file.c | 2 +-
>  exec.c                  | 4 ++--
>  include/exec/memory.h   | 2 +-
>  memory.c                | 2 +-
>  5 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/backends/Makefile.objs b/backends/Makefile.objs
> index ad7c0325ed..a0558a21d9 100644
> --- a/backends/Makefile.objs
> +++ b/backends/Makefile.objs
> @@ -5,6 +5,7 @@ common-obj-$(CONFIG_TPM) += tpm.o
>  
>  common-obj-y += hostmem.o hostmem-ram.o
>  common-obj-$(CONFIG_LINUX) += hostmem-file.o
> +common-obj-$(CONFIG_DARWIN) += hostmem-file.o

The original reason to have CONFIG_LINUX was that -mem-path and
hostmem-file were tied to hugetlbfs.  However, nowadays there are other
uses such as vhost-user so it's indeed better to enable it on all hosts
that can support it.  CONFIG_POSIX (that is, all non-Windows hosts)
would be even better than CONFIG_DARWIN, can you prepare a patch that
does that?

Thanks,

Paolo

>  
>  common-obj-y += cryptodev.o
>  common-obj-y += cryptodev-builtin.o
> diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
> index 2476dcb435..e12ec9538a 100644
> --- a/backends/hostmem-file.c
> +++ b/backends/hostmem-file.c
> @@ -51,7 +51,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
>          error_setg(errp, "mem-path property not set");
>          return;
>      }
> -#ifndef CONFIG_LINUX
> +#if !defined(CONFIG_LINUX) && !defined(CONFIG_DARWIN)
>      error_setg(errp, "-mem-path not supported on this host");
>  #else
>      if (!host_memory_backend_mr_inited(backend)) {
> diff --git a/exec.c b/exec.c
> index 6826c8337d..602da77fb8 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1734,7 +1734,7 @@ long qemu_getrampagesize(void)
>  }
>  #endif
>  
> -#ifdef __linux__
> +#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
>  static int64_t get_file_size(int fd)
>  {
>      int64_t size = lseek(fd, 0, SEEK_END);
> @@ -2230,7 +2230,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
>      }
>  }
>  
> -#ifdef __linux__
> +#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
>  RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
>                                   uint32_t ram_flags, int fd,
>                                   Error **errp)
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index eb4f2fb249..86d6696306 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -633,7 +633,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
>                                                         uint64_t length,
>                                                         void *host),
>                                         Error **errp);
> -#ifdef __linux__
> +#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
>  
>  /**
>   * memory_region_init_ram_from_file:  Initialize RAM memory region with a
> diff --git a/memory.c b/memory.c
> index 9b73892768..88422c3cac 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1545,7 +1545,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
>      mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
>  }
>  
> -#ifdef __linux__
> +#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
>  void memory_region_init_ram_from_file(MemoryRegion *mr,
>                                        struct Object *owner,
>                                        const char *name,
> 


Re: [Qemu-devel] [PATCH] hostmem-file: make available memory-backend-file on macOS hosts
Posted by Hikaru Nishida 7 years, 1 month ago
Thank you for letting me know about CONFIG_POSIX.
I'll fix my patch to utilize it and submit again.

Hikaru Nishida

2018年9月24日(月) 17:51 Paolo Bonzini <pbonzini@redhat.com>:
>
> On 24/09/2018 10:13, hikarupsp@gmail.com wrote:
> > From: Hikaru Nishida <hikarupsp@gmail.com>
> >
> > Before this change, memory-backend-file object is invalid for macOS
> > hosts because hostmem-file.c is compiled only on Linux hosts.
> > However, macOS hosts can support memory-backend-file object in the same
> > way as on Linux hosts.
> > This patch makes hostmem-file.c and related functions to be compiled on
> > macOS hosts as well to make available memory-backend-file on macOS.
> >
> > Signed-off-by: Hikaru Nishida <hikarupsp@gmail.com>
> > ---
> >  backends/Makefile.objs  | 1 +
> >  backends/hostmem-file.c | 2 +-
> >  exec.c                  | 4 ++--
> >  include/exec/memory.h   | 2 +-
> >  memory.c                | 2 +-
> >  5 files changed, 6 insertions(+), 5 deletions(-)
> >
> > diff --git a/backends/Makefile.objs b/backends/Makefile.objs
> > index ad7c0325ed..a0558a21d9 100644
> > --- a/backends/Makefile.objs
> > +++ b/backends/Makefile.objs
> > @@ -5,6 +5,7 @@ common-obj-$(CONFIG_TPM) += tpm.o
> >
> >  common-obj-y += hostmem.o hostmem-ram.o
> >  common-obj-$(CONFIG_LINUX) += hostmem-file.o
> > +common-obj-$(CONFIG_DARWIN) += hostmem-file.o
>
> The original reason to have CONFIG_LINUX was that -mem-path and
> hostmem-file were tied to hugetlbfs.  However, nowadays there are other
> uses such as vhost-user so it's indeed better to enable it on all hosts
> that can support it.  CONFIG_POSIX (that is, all non-Windows hosts)
> would be even better than CONFIG_DARWIN, can you prepare a patch that
> does that?
>
> Thanks,
>
> Paolo
>
> >
> >  common-obj-y += cryptodev.o
> >  common-obj-y += cryptodev-builtin.o
> > diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
> > index 2476dcb435..e12ec9538a 100644
> > --- a/backends/hostmem-file.c
> > +++ b/backends/hostmem-file.c
> > @@ -51,7 +51,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
> >          error_setg(errp, "mem-path property not set");
> >          return;
> >      }
> > -#ifndef CONFIG_LINUX
> > +#if !defined(CONFIG_LINUX) && !defined(CONFIG_DARWIN)
> >      error_setg(errp, "-mem-path not supported on this host");
> >  #else
> >      if (!host_memory_backend_mr_inited(backend)) {
> > diff --git a/exec.c b/exec.c
> > index 6826c8337d..602da77fb8 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -1734,7 +1734,7 @@ long qemu_getrampagesize(void)
> >  }
> >  #endif
> >
> > -#ifdef __linux__
> > +#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
> >  static int64_t get_file_size(int fd)
> >  {
> >      int64_t size = lseek(fd, 0, SEEK_END);
> > @@ -2230,7 +2230,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
> >      }
> >  }
> >
> > -#ifdef __linux__
> > +#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
> >  RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
> >                                   uint32_t ram_flags, int fd,
> >                                   Error **errp)
> > diff --git a/include/exec/memory.h b/include/exec/memory.h
> > index eb4f2fb249..86d6696306 100644
> > --- a/include/exec/memory.h
> > +++ b/include/exec/memory.h
> > @@ -633,7 +633,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
> >                                                         uint64_t length,
> >                                                         void *host),
> >                                         Error **errp);
> > -#ifdef __linux__
> > +#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
> >
> >  /**
> >   * memory_region_init_ram_from_file:  Initialize RAM memory region with a
> > diff --git a/memory.c b/memory.c
> > index 9b73892768..88422c3cac 100644
> > --- a/memory.c
> > +++ b/memory.c
> > @@ -1545,7 +1545,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
> >      mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
> >  }
> >
> > -#ifdef __linux__
> > +#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
> >  void memory_region_init_ram_from_file(MemoryRegion *mr,
> >                                        struct Object *owner,
> >                                        const char *name,
> >
>