* [uml-devel] [patch 1/1] Fix malloc-use-vmalloc
@ 2004-07-04 10:56 blaisorblade_spam
2004-07-13 17:57 ` [uml-devel] " Jeff Dike
0 siblings, 1 reply; 4+ messages in thread
From: blaisorblade_spam @ 2004-07-04 10:56 UTC (permalink / raw)
To: jdike; +Cc: user-mode-linux-devel, blaisorblade_spam
* Avoid allocating more than one page at once: that can require
moving pages around to have two contiguos pages, so we're better
with vmalloc.
* Make sure we free() someway, inside __wrap_free.
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade_spam@yahoo.it>
---
linux-2.4.26-paolo/arch/um/main.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff -puN arch/um/main.c~malloc-use-vmalloc-fix arch/um/main.c
--- linux-2.4.26/arch/um/main.c~malloc-use-vmalloc-fix 2004-07-04 12:52:43.887588064 +0200
+++ linux-2.4.26-paolo/arch/um/main.c 2004-07-04 12:52:43.889587760 +0200
@@ -168,7 +168,7 @@ void *__wrap_malloc(int size)
if(!CAN_KMALLOC())
return(__real_malloc(size));
- else if(size < 128 * 1024) /* kmalloc is good for only 128K */
+ else if(size <= PAGE_SIZE) /* finding contiguos pages is hard */
ret = um_kmalloc(size);
else ret = um_vmalloc(size);
@@ -213,8 +213,11 @@ void __wrap_free(void *ptr)
kfree(ptr);
else if((addr >= start_vm) && (addr <= end_vm))
vfree(ptr);
+ else
+ __real_free(ptr);
}
- else __real_free(ptr);
+ else
+ __real_free(ptr);
}
/*
_
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
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] 4+ messages in thread
* [uml-devel] Re: [patch 1/1] Fix malloc-use-vmalloc
2004-07-04 10:56 [uml-devel] [patch 1/1] Fix malloc-use-vmalloc blaisorblade_spam
@ 2004-07-13 17:57 ` Jeff Dike
2004-07-22 15:55 ` BlaisorBlade
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Dike @ 2004-07-13 17:57 UTC (permalink / raw)
To: blaisorblade_spam; +Cc: user-mode-linux-devel
blaisorblade_spam@yahoo.it said:
> * Avoid allocating more than one page at once: that can require moving
> pages around to have two contiguos pages, so we're better with
> vmalloc.
Yup, makes sense.
> * Make sure we free() someway, inside __wrap_free.
This isn't exactly right. In the case that a buffer was allocated by kmalloc
(through malloc), but freed when the system is coming down, and kmalloc is no
longer operating, then you just want to do nothing. It would be very bad to
try to free it using libc free.
So, what I did is this:
if((addr >= uml_physmem) && (addr <= high_physmem)){
if(CAN_KMALLOC())
kfree(ptr);
}
else if((addr >= start_vm) && (addr <= end_vm)){
if(CAN_KMALLOC())
vfree(ptr);
}
else __real_free(ptr);
Jeff
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
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] 4+ messages in thread* [uml-devel] Re: [patch 1/1] Fix malloc-use-vmalloc
2004-07-13 17:57 ` [uml-devel] " Jeff Dike
@ 2004-07-22 15:55 ` BlaisorBlade
2004-07-26 18:18 ` Jeff Dike
0 siblings, 1 reply; 4+ messages in thread
From: BlaisorBlade @ 2004-07-22 15:55 UTC (permalink / raw)
To: Jeff Dike; +Cc: user-mode-linux-devel
Alle 19:57, martedì 13 luglio 2004, Jeff Dike ha scritto:
> This isn't exactly right. In the case that a buffer was allocated by
> kmalloc (through malloc), but freed when the system is coming down, and
> kmalloc is no longer operating, then you just want to do nothing. It would
> be very bad to try to free it using libc free.
>
> So, what I did is this:
>
> if((addr >= uml_physmem) && (addr <= high_physmem)){
> if(CAN_KMALLOC())
> kfree(ptr);
> }
> else if((addr >= start_vm) && (addr <= end_vm)){
> if(CAN_KMALLOC())
> vfree(ptr);
> }
> else __real_free(ptr);
1) I think that the intervals don't include high_physmem and end_vm, so we
should have addr < ... instead of addr <=.
2) Also, even worse, it seems ok until you read your comment. During the boot,
if random values are in the vars (and it's so until kmalloc_ok is turned on)
we can have malloc()ed memory thought of as kmalloc()ed or vmalloc()ed one,
and then leaked.
3) Solution to 2): if I am right about thing #1, then it should be enough to
set end_vm and high_physmem to 0 at startup (they are global vars, so it's
already true), once there are the < instead of <=. And don't say in the
comment that memory regions are not initialized.
Any comment? I need this to send the patch to Andrew Morton for 2.6-mm
--
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idG21&alloc_id\x10040&opÌk
_______________________________________________
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] 4+ messages in thread* Re: [uml-devel] Re: [patch 1/1] Fix malloc-use-vmalloc
2004-07-22 15:55 ` BlaisorBlade
@ 2004-07-26 18:18 ` Jeff Dike
0 siblings, 0 replies; 4+ messages in thread
From: Jeff Dike @ 2004-07-26 18:18 UTC (permalink / raw)
To: BlaisorBlade; +Cc: user-mode-linux-devel
blaisorblade_spam@yahoo.it said:
> 1) I think that the intervals don't include high_physmem and end_vm,
> so we should have addr < ... instead of addr <=.
Yup.
> 2) Also, even worse, it seems ok until you read your comment. During
> the boot, if random values are in the vars (and it's so until
> kmalloc_ok is turned on) we can have malloc()ed memory thought of as
> kmalloc()ed or vmalloc()ed one, and then leaked.
The comment was badly worded.
> 3) Solution to 2): if I am right about thing #1, then it should be
> enough to set end_vm and high_physmem to 0 at startup (they are
> global vars, so it's already true), once there are the < instead of
> <=. And don't say in the comment that memory regions are not
> initialized.
They are all globals, so they are initialized to 0. It looks to me like
anything which hits that code before kmalloc is set up will correctly go
through the __real_free case.
Jeff
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
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] 4+ messages in thread
end of thread, other threads:[~2004-07-26 17:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-04 10:56 [uml-devel] [patch 1/1] Fix malloc-use-vmalloc blaisorblade_spam
2004-07-13 17:57 ` [uml-devel] " Jeff Dike
2004-07-22 15:55 ` BlaisorBlade
2004-07-26 18:18 ` Jeff Dike
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox