All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] translate-all: use g_malloc0 for all page descriptor allocations
@ 2015-04-09 17:24 Emilio G. Cota
  2015-04-09 19:07 ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Emilio G. Cota @ 2015-04-09 17:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell

Since commit

  b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free"

the exception we make here for usermode has been unnecessary.
Get rid of it.

Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 translate-all.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/translate-all.c b/translate-all.c
index 11763c6..3a6d116 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
     void **lp;
     int i;
 
-#if defined(CONFIG_USER_ONLY)
-    /* We can't use g_malloc because it may recurse into a locked mutex. */
-# define ALLOC(P, SIZE)                                 \
-    do {                                                \
-        P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,    \
-                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);   \
-    } while (0)
-#else
-# define ALLOC(P, SIZE) \
-    do { P = g_malloc0(SIZE); } while (0)
-#endif
-
     /* Level 1.  Always allocated.  */
     lp = l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1));
 
@@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
             if (!alloc) {
                 return NULL;
             }
-            ALLOC(p, sizeof(void *) * V_L2_SIZE);
+            p = g_malloc0(sizeof(void *) * V_L2_SIZE);
             *lp = p;
         }
 
@@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
         if (!alloc) {
             return NULL;
         }
-        ALLOC(pd, sizeof(PageDesc) * V_L2_SIZE);
+        pd = g_malloc0(sizeof(PageDesc) * V_L2_SIZE);
         *lp = pd;
     }
 
-#undef ALLOC
-
     return pd + (index & (V_L2_SIZE - 1));
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] translate-all: use g_malloc0 for all page descriptor allocations
  2015-04-09 17:24 [Qemu-devel] [PATCH] translate-all: use g_malloc0 for all page descriptor allocations Emilio G. Cota
@ 2015-04-09 19:07 ` Paolo Bonzini
  2015-04-09 20:03   ` [Qemu-devel] [PATCH v2] translate-all: use glib " Emilio G. Cota
  2015-04-09 20:07   ` [Qemu-devel] [PATCH v3] " Emilio G. Cota
  0 siblings, 2 replies; 5+ messages in thread
From: Paolo Bonzini @ 2015-04-09 19:07 UTC (permalink / raw)
  To: Emilio G. Cota, qemu-devel; +Cc: Peter Maydell



On 09/04/2015 19:24, Emilio G. Cota wrote:
> Since commit
> 
>   b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free"
> 
> the exception we make here for usermode has been unnecessary.
> Get rid of it.
> 
> Signed-off-by: Emilio G. Cota <cota@braap.org>
> ---
>  translate-all.c | 18 ++----------------
>  1 file changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/translate-all.c b/translate-all.c
> index 11763c6..3a6d116 100644
> --- a/translate-all.c
> +++ b/translate-all.c
> @@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
>      void **lp;
>      int i;
>  
> -#if defined(CONFIG_USER_ONLY)
> -    /* We can't use g_malloc because it may recurse into a locked mutex. */
> -# define ALLOC(P, SIZE)                                 \
> -    do {                                                \
> -        P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,    \
> -                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);   \
> -    } while (0)
> -#else
> -# define ALLOC(P, SIZE) \
> -    do { P = g_malloc0(SIZE); } while (0)
> -#endif
> -
>      /* Level 1.  Always allocated.  */
>      lp = l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1));
>  
> @@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
>              if (!alloc) {
>                  return NULL;
>              }
> -            ALLOC(p, sizeof(void *) * V_L2_SIZE);
> +            p = g_malloc0(sizeof(void *) * V_L2_SIZE);

Using g_new0 would be even better. :)

Paolo

>              *lp = p;
>          }
>  
> @@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
>          if (!alloc) {
>              return NULL;
>          }
> -        ALLOC(pd, sizeof(PageDesc) * V_L2_SIZE);
> +        pd = g_malloc0(sizeof(PageDesc) * V_L2_SIZE);
>          *lp = pd;
>      }
>  
> -#undef ALLOC
> -
>      return pd + (index & (V_L2_SIZE - 1));
>  }
>  
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v2] translate-all: use glib for all page descriptor allocations
  2015-04-09 19:07 ` Paolo Bonzini
@ 2015-04-09 20:03   ` Emilio G. Cota
  2015-04-09 20:07   ` [Qemu-devel] [PATCH v3] " Emilio G. Cota
  1 sibling, 0 replies; 5+ messages in thread
From: Emilio G. Cota @ 2015-04-09 20:03 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Peter Maydell, qemu-devel

Since commit

  b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free"

the exception we make here for usermode has been unnecessary.
Get rid of it.

Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 translate-all.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/translate-all.c b/translate-all.c
index 4d05898..c8f0e8c 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
     void **lp;
     int i;
 
-#if defined(CONFIG_USER_ONLY)
-    /* We can't use g_malloc because it may recurse into a locked mutex. */
-# define ALLOC(P, SIZE)                                 \
-    do {                                                \
-        P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,    \
-                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);   \
-    } while (0)
-#else
-# define ALLOC(P, SIZE) \
-    do { P = g_malloc0(SIZE); } while (0)
-#endif
-
     /* Level 1.  Always allocated.  */
     lp = l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1));
 
@@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
             if (!alloc) {
                 return NULL;
             }
-            ALLOC(p, sizeof(void *) * V_L2_SIZE);
+            p = g_malloc0(sizeof(void *) * V_L2_SIZE);
             *lp = p;
         }
 
@@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
         if (!alloc) {
             return NULL;
         }
-        ALLOC(pd, sizeof(PageDesc) * V_L2_SIZE);
+        pd = g_malloc0(sizeof(PageDesc) * V_L2_SIZE);
         *lp = pd;
     }
 
-#undef ALLOC
-
     return pd + (index & (V_L2_SIZE - 1));
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v3] translate-all: use glib for all page descriptor allocations
  2015-04-09 19:07 ` Paolo Bonzini
  2015-04-09 20:03   ` [Qemu-devel] [PATCH v2] translate-all: use glib " Emilio G. Cota
@ 2015-04-09 20:07   ` Emilio G. Cota
  2015-04-09 20:21     ` Paolo Bonzini
  1 sibling, 1 reply; 5+ messages in thread
From: Emilio G. Cota @ 2015-04-09 20:07 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Peter Maydell, qemu-devel

Since commit

  b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free"

the exception we make here for usermode has been unnecessary.
Get rid of it.

Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 translate-all.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/translate-all.c b/translate-all.c
index 4d05898..acf792c 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
     void **lp;
     int i;
 
-#if defined(CONFIG_USER_ONLY)
-    /* We can't use g_malloc because it may recurse into a locked mutex. */
-# define ALLOC(P, SIZE)                                 \
-    do {                                                \
-        P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,    \
-                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);   \
-    } while (0)
-#else
-# define ALLOC(P, SIZE) \
-    do { P = g_malloc0(SIZE); } while (0)
-#endif
-
     /* Level 1.  Always allocated.  */
     lp = l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1));
 
@@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
             if (!alloc) {
                 return NULL;
             }
-            ALLOC(p, sizeof(void *) * V_L2_SIZE);
+            p = g_new0(void *, V_L2_SIZE);
             *lp = p;
         }
 
@@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
         if (!alloc) {
             return NULL;
         }
-        ALLOC(pd, sizeof(PageDesc) * V_L2_SIZE);
+        pd = g_new0(PageDesc, V_L2_SIZE);
         *lp = pd;
     }
 
-#undef ALLOC
-
     return pd + (index & (V_L2_SIZE - 1));
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v3] translate-all: use glib for all page descriptor allocations
  2015-04-09 20:07   ` [Qemu-devel] [PATCH v3] " Emilio G. Cota
@ 2015-04-09 20:21     ` Paolo Bonzini
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2015-04-09 20:21 UTC (permalink / raw)
  To: Emilio G. Cota; +Cc: Peter Maydell, qemu-devel



On 09/04/2015 22:07, Emilio G. Cota wrote:
> Since commit
> 
>   b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free"
> 
> the exception we make here for usermode has been unnecessary.
> Get rid of it.
> 
> Signed-off-by: Emilio G. Cota <cota@braap.org>
> ---
>  translate-all.c | 18 ++----------------
>  1 file changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/translate-all.c b/translate-all.c
> index 4d05898..acf792c 100644
> --- a/translate-all.c
> +++ b/translate-all.c
> @@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
>      void **lp;
>      int i;
>  
> -#if defined(CONFIG_USER_ONLY)
> -    /* We can't use g_malloc because it may recurse into a locked mutex. */
> -# define ALLOC(P, SIZE)                                 \
> -    do {                                                \
> -        P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,    \
> -                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);   \
> -    } while (0)
> -#else
> -# define ALLOC(P, SIZE) \
> -    do { P = g_malloc0(SIZE); } while (0)
> -#endif
> -
>      /* Level 1.  Always allocated.  */
>      lp = l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1));
>  
> @@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
>              if (!alloc) {
>                  return NULL;
>              }
> -            ALLOC(p, sizeof(void *) * V_L2_SIZE);
> +            p = g_new0(void *, V_L2_SIZE);
>              *lp = p;
>          }
>  
> @@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
>          if (!alloc) {
>              return NULL;
>          }
> -        ALLOC(pd, sizeof(PageDesc) * V_L2_SIZE);
> +        pd = g_new0(PageDesc, V_L2_SIZE);
>          *lp = pd;
>      }
>  
> -#undef ALLOC
> -
>      return pd + (index & (V_L2_SIZE - 1));
>  }
>  
> 

Thanks, looks good.

Paolo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-04-09 20:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-09 17:24 [Qemu-devel] [PATCH] translate-all: use g_malloc0 for all page descriptor allocations Emilio G. Cota
2015-04-09 19:07 ` Paolo Bonzini
2015-04-09 20:03   ` [Qemu-devel] [PATCH v2] translate-all: use glib " Emilio G. Cota
2015-04-09 20:07   ` [Qemu-devel] [PATCH v3] " Emilio G. Cota
2015-04-09 20:21     ` Paolo Bonzini

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.