2008-02-11 22:33:19

by Pekka Enberg

[permalink] [raw]
Subject: [PATCH] slob: fix linking for user mode linux

From: Pekka Enberg <[email protected]>

UML has some header magic that expects a non-inline __kmalloc() function to be
available. Fixes the following link time errors:

arch/um/drivers/built-in.o: In function `kmalloc':
/home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
/home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
/home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
/home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
/home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
arch/um/drivers/built-in.o:/home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: more undefined references to `__kmalloc' follow

Cc: Jeff Dike <[email protected]>
Cc: Paolo 'Blaisorblade' Giarrusso <[email protected]>
Cc: Matt Mackall <[email protected]>
Cc: Christoph Lameter <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
---
Matt, does this look ok to you? Can we merge it via Christoph's tree?

include/linux/slob_def.h | 5 +----
mm/slob.c | 6 ++++++
2 files changed, 7 insertions(+), 4 deletions(-)

Index: linux-2.6/include/linux/slob_def.h
===================================================================
--- linux-2.6.orig/include/linux/slob_def.h 2008-01-12 01:00:37.000000000 +0200
+++ linux-2.6/include/linux/slob_def.h 2008-02-12 00:27:38.000000000 +0200
@@ -28,9 +28,6 @@
return __kmalloc_node(size, flags, -1);
}

-static inline void *__kmalloc(size_t size, gfp_t flags)
-{
- return kmalloc(size, flags);
-}
+extern void *__kmalloc(size_t size, gfp_t flags);

#endif /* __LINUX_SLOB_DEF_H */
Index: linux-2.6/mm/slob.c
===================================================================
--- linux-2.6.orig/mm/slob.c 2008-02-11 23:47:19.000000000 +0200
+++ linux-2.6/mm/slob.c 2008-02-12 00:27:38.000000000 +0200
@@ -486,6 +486,12 @@
}
EXPORT_SYMBOL(__kmalloc_node);

+void *__kmalloc(size_t size, gfp_t gfp)
+{
+ return __kmalloc_node(size, gfp, -1);
+}
+EXPORT_SYMBOL(__kmalloc);
+
void kfree(const void *block)
{
struct slob_page *sp;


2008-02-11 22:39:55

by Matt Mackall

[permalink] [raw]
Subject: Re: [PATCH] slob: fix linking for user mode linux


On Tue, 2008-02-12 at 00:32 +0200, Pekka J Enberg wrote:
> From: Pekka Enberg <[email protected]>
>
> UML has some header magic that expects a non-inline __kmalloc() function to be
> available. Fixes the following link time errors:
>
> arch/um/drivers/built-in.o: In function `kmalloc':
> /home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
> /home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
> /home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
> /home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
> /home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: undefined reference to `__kmalloc'
> arch/um/drivers/built-in.o:/home/penberg/linux-2.6/arch/um/include/um_malloc.h:14: more undefined references to `__kmalloc' follow

Can someone explain why the magic is needed (and preferably capture it
in a comment somewhere sensible)? I took a peek at this and have no idea
what's going on.

--
Mathematics is the supreme nostalgia of our time.

2008-02-11 22:44:33

by Christoph Lameter

[permalink] [raw]
Subject: Re: [PATCH] slob: fix linking for user mode linux

On Mon, 11 Feb 2008, Matt Mackall wrote:

> Can someone explain why the magic is needed (and preferably capture it
> in a comment somewhere sensible)? I took a peek at this and have no idea
> what's going on.

UML defined its own external __kmalloc and things. Isnt there some other
way to fix it? I guess including slab.h is not possible here?


/*
* Copyright (C) 2005 Paolo 'Blaisorblade' Giarrusso <[email protected]>
* Licensed under the GPL
*/

#ifndef __UM_MALLOC_H__
#define __UM_MALLOC_H__

#include "kern_constants.h"

extern void *__kmalloc(int size, int flags);
static inline void *kmalloc(int size, int flags)
{
return __kmalloc(size, flags);
}

extern void kfree(const void *ptr);

extern void *vmalloc(unsigned long size);
extern void vfree(void *ptr);

#endif /* __UM_MALLOC_H__ */

2008-02-11 23:32:59

by Jeff Dike

[permalink] [raw]
Subject: Re: [PATCH] slob: fix linking for user mode linux

On Mon, Feb 11, 2008 at 02:44:21PM -0800, Christoph Lameter wrote:
> UML defined its own external __kmalloc and things. Isnt there some other
> way to fix it? I guess including slab.h is not possible here?

This is definitely dubious code on my part and I wouldn't support
Pekka's patch unless you're going to uninline __kmalloc for some
other reason.

The reason for this is that part of UML is userspace code, and thus
can't use kernel headers. However, they do need some kernel
interfaces in some form. That form has traditionally been little
wrappers in the kernel side of UML which just call the kernel
interface.

In this case, there used to be um_kmalloc, which just called kmalloc.
I've been trying to get rid of these stupid little helpers for a
while, and this is what I ended up with for kmalloc.

It would be an annoyance to reintroduce um_kmalloc, but that might be
the best thing to do here.

Jeff

--
Work email - jdike at linux dot intel dot com

2008-02-12 06:25:15

by Pekka Enberg

[permalink] [raw]
Subject: Re: [PATCH] slob: fix linking for user mode linux

Jeff Dike wrote:
>> UML defined its own external __kmalloc and things. Isnt there some other
>> way to fix it? I guess including slab.h is not possible here?
>
> It would be an annoyance to reintroduce um_kmalloc, but that might be
> the best thing to do here.

I'm ok with that as long as we get this annoying bug fixed.