* [uml-devel] [PATCH 4/6] UML - free() wrapper should call libc free
@ 2007-05-01 18:21 ` Jeff Dike
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Dike @ 2007-05-01 18:21 UTC (permalink / raw)
To: akpm; +Cc: LKML, uml-devel
The libc free wrapper wasn't correctly detecting buffers obtained with
malloc(). This is now done by seeing if the page was reserved. This is
the case for memory which is left aside for libc and isn't given to
the page allocator. If we free a pointer in a reserved page, it is
given to free() rather than kfree().
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
--
arch/um/include/user.h | 1 +
arch/um/kernel/um_arch.c | 7 +++++++
arch/um/os-Linux/main.c | 6 +++++-
3 files changed, 13 insertions(+), 1 deletion(-)
Index: linux-2.6.21-mm/arch/um/include/user.h
===================================================================
--- linux-2.6.21-mm.orig/arch/um/include/user.h 2007-04-26 17:33:01.000000000 -0400
+++ linux-2.6.21-mm/arch/um/include/user.h 2007-04-27 14:21:35.000000000 -0400
@@ -27,5 +27,6 @@ extern int in_aton(char *str);
extern int open_gdb_chan(void);
extern size_t strlcpy(char *, const char *, size_t);
extern size_t strlcat(char *, const char *, size_t);
+extern int reserved_address(void *addr);
#endif
Index: linux-2.6.21-mm/arch/um/kernel/um_arch.c
===================================================================
--- linux-2.6.21-mm.orig/arch/um/kernel/um_arch.c 2007-04-26 17:41:21.000000000 -0400
+++ linux-2.6.21-mm/arch/um/kernel/um_arch.c 2007-04-27 14:30:36.000000000 -0400
@@ -500,6 +500,13 @@ void __init check_bugs(void)
os_check_bugs();
}
+int reserved_address(void *addr)
+{
+ struct page *page = virt_to_page(addr);
+
+ return(PageReserved(page));
+}
+
void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
{
}
Index: linux-2.6.21-mm/arch/um/os-Linux/main.c
===================================================================
--- linux-2.6.21-mm.orig/arch/um/os-Linux/main.c 2007-04-26 17:41:10.000000000 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/main.c 2007-04-27 14:30:31.000000000 -0400
@@ -266,6 +266,8 @@ void __wrap_free(void *ptr)
/* We need to know how the allocation happened, so it can be correctly
* freed. This is done by seeing what region of memory the pointer is
* in -
+ * in a reserved page - free, assume the pointer was
+ * acquired with malloc, since it couldn't have been kmalloced.
* physical memory - kmalloc/kfree
* kernel virtual memory - vmalloc/vfree
* anywhere else - malloc/free
@@ -281,7 +283,9 @@ void __wrap_free(void *ptr)
* there is a possibility for memory leaks.
*/
- if((addr >= uml_physmem) && (addr < high_physmem)){
+ if(kmalloc_ok && reserved_address(ptr))
+ __real_free(ptr);
+ else if((addr >= uml_physmem) && (addr < high_physmem)){
if(CAN_KMALLOC())
kfree(ptr);
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/6] UML - free() wrapper should call libc free
@ 2007-05-01 18:21 ` Jeff Dike
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Dike @ 2007-05-01 18:21 UTC (permalink / raw)
To: akpm; +Cc: LKML, uml-devel
The libc free wrapper wasn't correctly detecting buffers obtained with
malloc(). This is now done by seeing if the page was reserved. This is
the case for memory which is left aside for libc and isn't given to
the page allocator. If we free a pointer in a reserved page, it is
given to free() rather than kfree().
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
--
arch/um/include/user.h | 1 +
arch/um/kernel/um_arch.c | 7 +++++++
arch/um/os-Linux/main.c | 6 +++++-
3 files changed, 13 insertions(+), 1 deletion(-)
Index: linux-2.6.21-mm/arch/um/include/user.h
===================================================================
--- linux-2.6.21-mm.orig/arch/um/include/user.h 2007-04-26 17:33:01.000000000 -0400
+++ linux-2.6.21-mm/arch/um/include/user.h 2007-04-27 14:21:35.000000000 -0400
@@ -27,5 +27,6 @@ extern int in_aton(char *str);
extern int open_gdb_chan(void);
extern size_t strlcpy(char *, const char *, size_t);
extern size_t strlcat(char *, const char *, size_t);
+extern int reserved_address(void *addr);
#endif
Index: linux-2.6.21-mm/arch/um/kernel/um_arch.c
===================================================================
--- linux-2.6.21-mm.orig/arch/um/kernel/um_arch.c 2007-04-26 17:41:21.000000000 -0400
+++ linux-2.6.21-mm/arch/um/kernel/um_arch.c 2007-04-27 14:30:36.000000000 -0400
@@ -500,6 +500,13 @@ void __init check_bugs(void)
os_check_bugs();
}
+int reserved_address(void *addr)
+{
+ struct page *page = virt_to_page(addr);
+
+ return(PageReserved(page));
+}
+
void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
{
}
Index: linux-2.6.21-mm/arch/um/os-Linux/main.c
===================================================================
--- linux-2.6.21-mm.orig/arch/um/os-Linux/main.c 2007-04-26 17:41:10.000000000 -0400
+++ linux-2.6.21-mm/arch/um/os-Linux/main.c 2007-04-27 14:30:31.000000000 -0400
@@ -266,6 +266,8 @@ void __wrap_free(void *ptr)
/* We need to know how the allocation happened, so it can be correctly
* freed. This is done by seeing what region of memory the pointer is
* in -
+ * in a reserved page - free, assume the pointer was
+ * acquired with malloc, since it couldn't have been kmalloced.
* physical memory - kmalloc/kfree
* kernel virtual memory - vmalloc/vfree
* anywhere else - malloc/free
@@ -281,7 +283,9 @@ void __wrap_free(void *ptr)
* there is a possibility for memory leaks.
*/
- if((addr >= uml_physmem) && (addr < high_physmem)){
+ if(kmalloc_ok && reserved_address(ptr))
+ __real_free(ptr);
+ else if((addr >= uml_physmem) && (addr < high_physmem)){
if(CAN_KMALLOC())
kfree(ptr);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [uml-devel] [PATCH 4/6] UML - free() wrapper should call libc free
2007-05-01 18:21 ` Jeff Dike
@ 2007-05-02 2:49 ` Nick Piggin
-1 siblings, 0 replies; 6+ messages in thread
From: Nick Piggin @ 2007-05-02 2:49 UTC (permalink / raw)
To: Jeff Dike; +Cc: akpm, LKML, uml-devel
Jeff Dike wrote:
> The libc free wrapper wasn't correctly detecting buffers obtained with
> malloc(). This is now done by seeing if the page was reserved. This is
> the case for memory which is left aside for libc and isn't given to
> the page allocator. If we free a pointer in a reserved page, it is
> given to free() rather than kfree().
I want to get rid of PG_reserved eventually. Is it possible to use PG_arch_1
for this?
>
> Signed-off-by: Jeff Dike <jdike@linux.intel.com>
> --
> arch/um/include/user.h | 1 +
> arch/um/kernel/um_arch.c | 7 +++++++
> arch/um/os-Linux/main.c | 6 +++++-
> 3 files changed, 13 insertions(+), 1 deletion(-)
>
> Index: linux-2.6.21-mm/arch/um/include/user.h
> ===================================================================
> --- linux-2.6.21-mm.orig/arch/um/include/user.h 2007-04-26 17:33:01.000000000 -0400
> +++ linux-2.6.21-mm/arch/um/include/user.h 2007-04-27 14:21:35.000000000 -0400
> @@ -27,5 +27,6 @@ extern int in_aton(char *str);
> extern int open_gdb_chan(void);
> extern size_t strlcpy(char *, const char *, size_t);
> extern size_t strlcat(char *, const char *, size_t);
> +extern int reserved_address(void *addr);
>
> #endif
> Index: linux-2.6.21-mm/arch/um/kernel/um_arch.c
> ===================================================================
> --- linux-2.6.21-mm.orig/arch/um/kernel/um_arch.c 2007-04-26 17:41:21.000000000 -0400
> +++ linux-2.6.21-mm/arch/um/kernel/um_arch.c 2007-04-27 14:30:36.000000000 -0400
> @@ -500,6 +500,13 @@ void __init check_bugs(void)
> os_check_bugs();
> }
>
> +int reserved_address(void *addr)
> +{
> + struct page *page = virt_to_page(addr);
> +
> + return(PageReserved(page));
> +}
> +
> void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
> {
> }
> Index: linux-2.6.21-mm/arch/um/os-Linux/main.c
> ===================================================================
> --- linux-2.6.21-mm.orig/arch/um/os-Linux/main.c 2007-04-26 17:41:10.000000000 -0400
> +++ linux-2.6.21-mm/arch/um/os-Linux/main.c 2007-04-27 14:30:31.000000000 -0400
> @@ -266,6 +266,8 @@ void __wrap_free(void *ptr)
> /* We need to know how the allocation happened, so it can be correctly
> * freed. This is done by seeing what region of memory the pointer is
> * in -
> + * in a reserved page - free, assume the pointer was
> + * acquired with malloc, since it couldn't have been kmalloced.
> * physical memory - kmalloc/kfree
> * kernel virtual memory - vmalloc/vfree
> * anywhere else - malloc/free
> @@ -281,7 +283,9 @@ void __wrap_free(void *ptr)
> * there is a possibility for memory leaks.
> */
>
> - if((addr >= uml_physmem) && (addr < high_physmem)){
> + if(kmalloc_ok && reserved_address(ptr))
> + __real_free(ptr);
> + else if((addr >= uml_physmem) && (addr < high_physmem)){
> if(CAN_KMALLOC())
> kfree(ptr);
> }
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
--
SUSE Labs, Novell Inc.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 4/6] UML - free() wrapper should call libc free
@ 2007-05-02 2:49 ` Nick Piggin
0 siblings, 0 replies; 6+ messages in thread
From: Nick Piggin @ 2007-05-02 2:49 UTC (permalink / raw)
To: Jeff Dike; +Cc: akpm, LKML, uml-devel
Jeff Dike wrote:
> The libc free wrapper wasn't correctly detecting buffers obtained with
> malloc(). This is now done by seeing if the page was reserved. This is
> the case for memory which is left aside for libc and isn't given to
> the page allocator. If we free a pointer in a reserved page, it is
> given to free() rather than kfree().
I want to get rid of PG_reserved eventually. Is it possible to use PG_arch_1
for this?
>
> Signed-off-by: Jeff Dike <jdike@linux.intel.com>
> --
> arch/um/include/user.h | 1 +
> arch/um/kernel/um_arch.c | 7 +++++++
> arch/um/os-Linux/main.c | 6 +++++-
> 3 files changed, 13 insertions(+), 1 deletion(-)
>
> Index: linux-2.6.21-mm/arch/um/include/user.h
> ===================================================================
> --- linux-2.6.21-mm.orig/arch/um/include/user.h 2007-04-26 17:33:01.000000000 -0400
> +++ linux-2.6.21-mm/arch/um/include/user.h 2007-04-27 14:21:35.000000000 -0400
> @@ -27,5 +27,6 @@ extern int in_aton(char *str);
> extern int open_gdb_chan(void);
> extern size_t strlcpy(char *, const char *, size_t);
> extern size_t strlcat(char *, const char *, size_t);
> +extern int reserved_address(void *addr);
>
> #endif
> Index: linux-2.6.21-mm/arch/um/kernel/um_arch.c
> ===================================================================
> --- linux-2.6.21-mm.orig/arch/um/kernel/um_arch.c 2007-04-26 17:41:21.000000000 -0400
> +++ linux-2.6.21-mm/arch/um/kernel/um_arch.c 2007-04-27 14:30:36.000000000 -0400
> @@ -500,6 +500,13 @@ void __init check_bugs(void)
> os_check_bugs();
> }
>
> +int reserved_address(void *addr)
> +{
> + struct page *page = virt_to_page(addr);
> +
> + return(PageReserved(page));
> +}
> +
> void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
> {
> }
> Index: linux-2.6.21-mm/arch/um/os-Linux/main.c
> ===================================================================
> --- linux-2.6.21-mm.orig/arch/um/os-Linux/main.c 2007-04-26 17:41:10.000000000 -0400
> +++ linux-2.6.21-mm/arch/um/os-Linux/main.c 2007-04-27 14:30:31.000000000 -0400
> @@ -266,6 +266,8 @@ void __wrap_free(void *ptr)
> /* We need to know how the allocation happened, so it can be correctly
> * freed. This is done by seeing what region of memory the pointer is
> * in -
> + * in a reserved page - free, assume the pointer was
> + * acquired with malloc, since it couldn't have been kmalloced.
> * physical memory - kmalloc/kfree
> * kernel virtual memory - vmalloc/vfree
> * anywhere else - malloc/free
> @@ -281,7 +283,9 @@ void __wrap_free(void *ptr)
> * there is a possibility for memory leaks.
> */
>
> - if((addr >= uml_physmem) && (addr < high_physmem)){
> + if(kmalloc_ok && reserved_address(ptr))
> + __real_free(ptr);
> + else if((addr >= uml_physmem) && (addr < high_physmem)){
> if(CAN_KMALLOC())
> kfree(ptr);
> }
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
--
SUSE Labs, Novell Inc.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [uml-devel] [PATCH 4/6] UML - free() wrapper should call libc free
2007-05-02 2:49 ` Nick Piggin
@ 2007-05-02 15:41 ` Jeff Dike
-1 siblings, 0 replies; 6+ messages in thread
From: Jeff Dike @ 2007-05-02 15:41 UTC (permalink / raw)
To: Nick Piggin; +Cc: akpm, LKML, uml-devel
On Wed, May 02, 2007 at 12:49:01PM +1000, Nick Piggin wrote:
> I want to get rid of PG_reserved eventually. Is it possible to use PG_arch_1
> for this?
Yup.
Andrew - Feel free to drop this or just sit on it until I send a
replacement. Whichever is easier.
Jeff
--
Work email - jdike at linux dot intel dot com
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 4/6] UML - free() wrapper should call libc free
@ 2007-05-02 15:41 ` Jeff Dike
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Dike @ 2007-05-02 15:41 UTC (permalink / raw)
To: Nick Piggin; +Cc: akpm, LKML, uml-devel
On Wed, May 02, 2007 at 12:49:01PM +1000, Nick Piggin wrote:
> I want to get rid of PG_reserved eventually. Is it possible to use PG_arch_1
> for this?
Yup.
Andrew - Feel free to drop this or just sit on it until I send a
replacement. Whichever is easier.
Jeff
--
Work email - jdike at linux dot intel dot com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-05-02 15:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-01 18:21 [uml-devel] [PATCH 4/6] UML - free() wrapper should call libc free Jeff Dike
2007-05-01 18:21 ` Jeff Dike
2007-05-02 2:49 ` [uml-devel] " Nick Piggin
2007-05-02 2:49 ` Nick Piggin
2007-05-02 15:41 ` [uml-devel] " Jeff Dike
2007-05-02 15:41 ` Jeff Dike
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.