2011-03-22 20:41:21

by Mike Frysinger

[permalink] [raw]
Subject: [PATCH] NOMMU: support SMP dynamic percpu_alloc

From: Graf Yang <[email protected]>

The percpu code requires more functions to be implemented in the mm core
which nommu currently does not provide. So add inline implementations
since these are largely meaningless on nommu systems.

Signed-off-by: Graf Yang <[email protected]>
Signed-off-by: Mike Frysinger <[email protected]>
---
include/linux/vmalloc.h | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 81f8622..01bbeb4 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -98,10 +98,27 @@ extern struct vm_struct *remove_vm_area(const void *addr);

extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
struct page ***pages);
+#ifdef CONFIG_MMU
extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
pgprot_t prot, struct page **pages);
extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size);
extern void unmap_kernel_range(unsigned long addr, unsigned long size);
+#else
+static inline int
+map_kernel_range_noflush(unsigned long start, unsigned long size,
+ pgprot_t prot, struct page **pages)
+{
+ return size >> PAGE_SHIFT;
+}
+static inline void
+unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
+{
+}
+static inline void
+unmap_kernel_range(unsigned long addr, unsigned long size)
+{
+}
+#endif

/* Allocate/destroy a 'vmalloc' VM area. */
extern struct vm_struct *alloc_vm_area(size_t size);
@@ -119,11 +136,26 @@ extern struct vm_struct *vmlist;
extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);

#ifdef CONFIG_SMP
+# ifdef CONFIG_MMU
struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
const size_t *sizes, int nr_vms,
size_t align);

void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
+# else
+static inline struct vm_struct **
+pcpu_get_vm_areas(const unsigned long *offsets,
+ const size_t *sizes, int nr_vms,
+ size_t align)
+{
+ return NULL;
+}
+
+static inline void
+pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
+{
+}
+# endif
#endif

#endif /* _LINUX_VMALLOC_H */
--
1.7.4.1


2011-03-23 12:38:15

by Paul Mundt

[permalink] [raw]
Subject: Re: [PATCH] NOMMU: support SMP dynamic percpu_alloc

On Tue, Mar 22, 2011 at 04:41:46PM -0400, Mike Frysinger wrote:
> From: Graf Yang <[email protected]>
>
> The percpu code requires more functions to be implemented in the mm core
> which nommu currently does not provide. So add inline implementations
> since these are largely meaningless on nommu systems.
>
> Signed-off-by: Graf Yang <[email protected]>
> Signed-off-by: Mike Frysinger <[email protected]>

Looks ok to me. I've got a couple other fixes I'm working on at the
moment, so I'll roll this in to my nommu tree and send it along.

2011-03-23 13:37:19

by Greg Ungerer

[permalink] [raw]
Subject: Re: [PATCH] NOMMU: support SMP dynamic percpu_alloc

On 23/03/11 06:41, Mike Frysinger wrote:
> From: Graf Yang<[email protected]>
>
> The percpu code requires more functions to be implemented in the mm core
> which nommu currently does not provide. So add inline implementations
> since these are largely meaningless on nommu systems.
>
> Signed-off-by: Graf Yang<[email protected]>
> Signed-off-by: Mike Frysinger<[email protected]>

Acked-by: Greg Ungerer <[email protected]>


> ---
> include/linux/vmalloc.h | 32 ++++++++++++++++++++++++++++++++
> 1 files changed, 32 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 81f8622..01bbeb4 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -98,10 +98,27 @@ extern struct vm_struct *remove_vm_area(const void *addr);
>
> extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
> struct page ***pages);
> +#ifdef CONFIG_MMU
> extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
> pgprot_t prot, struct page **pages);
> extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size);
> extern void unmap_kernel_range(unsigned long addr, unsigned long size);
> +#else
> +static inline int
> +map_kernel_range_noflush(unsigned long start, unsigned long size,
> + pgprot_t prot, struct page **pages)
> +{
> + return size>> PAGE_SHIFT;
> +}
> +static inline void
> +unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
> +{
> +}
> +static inline void
> +unmap_kernel_range(unsigned long addr, unsigned long size)
> +{
> +}
> +#endif
>
> /* Allocate/destroy a 'vmalloc' VM area. */
> extern struct vm_struct *alloc_vm_area(size_t size);
> @@ -119,11 +136,26 @@ extern struct vm_struct *vmlist;
> extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);
>
> #ifdef CONFIG_SMP
> +# ifdef CONFIG_MMU
> struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
> const size_t *sizes, int nr_vms,
> size_t align);
>
> void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
> +# else
> +static inline struct vm_struct **
> +pcpu_get_vm_areas(const unsigned long *offsets,
> + const size_t *sizes, int nr_vms,
> + size_t align)
> +{
> + return NULL;
> +}
> +
> +static inline void
> +pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
> +{
> +}
> +# endif
> #endif
>
> #endif /* _LINUX_VMALLOC_H */


--
------------------------------------------------------------------------
Greg Ungerer -- Principal Engineer EMAIL: [email protected]
SnapGear Group, McAfee PHONE: +61 7 3435 2888
8 Gardner Close FAX: +61 7 3217 5323
Milton, QLD, 4064, Australia WEB: http://www.SnapGear.com

2011-03-23 23:09:32

by Mike Frysinger

[permalink] [raw]
Subject: Re: [uclinux-dist-devel] [PATCH] NOMMU: support SMP dynamic percpu_alloc

On Wed, Mar 23, 2011 at 08:37, Paul Mundt wrote:
> Looks ok to me. I've got a couple other fixes I'm working on at the
> moment, so I'll roll this in to my nommu tree and send it along.

are you picking up nommu fixes in general now ? there's a long
standing issue of the firmware subdir not working on nommu due to its
usage of vmap() and i wrote a patch for it, but David seems to be afk
for a while ?
-mike

2011-03-24 00:06:32

by David Howells

[permalink] [raw]
Subject: Re: [uclinux-dist-devel] [PATCH] NOMMU: support SMP dynamic percpu_alloc

Mike Frysinger <[email protected]> wrote:

> but David seems to be afk for a while ?

Yeah... I moved house and then we had to redecorate and stuff, and whilst all
that was going on, my FRV board has been locked away in storage.

David

2011-03-24 00:13:51

by Mike Frysinger

[permalink] [raw]
Subject: Re: [uclinux-dist-devel] [PATCH] NOMMU: support SMP dynamic percpu_alloc

On Wed, Mar 23, 2011 at 8:06 PM, David Howells wrote:
> Mike Frysinger <[email protected]> wrote:
>> but David seems to be afk for a while ?
>
> Yeah... ?I moved house and then we had to redecorate and stuff, and whilst all

ah, np

> that was going on, my FRV board has been locked away in storage.

i can send you a free Blackfin board :)
-mike

2011-03-24 00:20:19

by David Howells

[permalink] [raw]
Subject: Re: [uclinux-dist-devel] [PATCH] NOMMU: support SMP dynamic percpu_alloc

Mike Frysinger <[email protected]> wrote:

> > that was going on, my FRV board has been locked away in storage.
>
> i can send you a free Blackfin board :)

I never say no to stuff - which is part of the reason my office is a mess -
but I have my FRV board connected back up now.

David

2011-03-24 00:20:38

by David Howells

[permalink] [raw]
Subject: Re: [PATCH] NOMMU: support SMP dynamic percpu_alloc

Mike Frysinger <[email protected]> wrote:

> The percpu code requires more functions to be implemented in the mm core
> which nommu currently does not provide. So add inline implementations
> since these are largely meaningless on nommu systems.

Under what conditions are these required?

I've seen one percpu compilation bug that I've made a patch for (see
attached), but none of these. Is SMP required to trigger them?

David
---
From: David Howells <[email protected]>
Subject: [PATCH] NOMMU: percpu should use is_vmalloc_addr().

per_cpu_ptr_to_phys() uses VMALLOC_START and VMALLOC_END to determine if an
address is in the vmalloc() region or not. This is incorrect on NOMMU as
there is no real vmalloc() capability (vmalloc() is emulated by kmalloc()).

The correct way to do this is to use is_vmalloc_addr(). This encapsulates the
vmalloc() region test in MMU mode and just returns 0 in NOMMU mode.

On FRV in NOMMU mode, the percpu compilation fails without this patch:

mm/percpu.c: In function 'per_cpu_ptr_to_phys':
mm/percpu.c:1011: error: 'VMALLOC_START' undeclared (first use in this function)
mm/percpu.c:1011: error: (Each undeclared identifier is reported only once
mm/percpu.c:1011: error: for each function it appears in.)
mm/percpu.c:1012: error: 'VMALLOC_END' undeclared (first use in this function)
mm/percpu.c:1018: warning: control reaches end of non-void function

Signed-off-by: David Howells <[email protected]>
---

mm/percpu.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)


diff --git a/mm/percpu.c b/mm/percpu.c
index 3f93001..55d4d11 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1008,8 +1008,7 @@ phys_addr_t per_cpu_ptr_to_phys(void *addr)
}

if (in_first_chunk) {
- if ((unsigned long)addr < VMALLOC_START ||
- (unsigned long)addr >= VMALLOC_END)
+ if (!is_vmalloc_addr(addr))
return __pa(addr);
else
return page_to_phys(vmalloc_to_page(addr));

2011-03-24 00:32:05

by Mike Frysinger

[permalink] [raw]
Subject: Re: [PATCH] NOMMU: support SMP dynamic percpu_alloc

On Wed, Mar 23, 2011 at 8:20 PM, David Howells wrote:
> Mike Frysinger wrote:
>> The percpu code requires more functions to be implemented in the mm core
>> which nommu currently does not provide. ?So add inline implementations
>> since these are largely meaningless on nommu systems.
>
> Under what conditions are these required?
>
> I've seen one percpu compilation bug that I've made a patch for (see
> attached), but none of these. ?Is SMP required to trigger them?

yes, it only occurs in SMP builds.

i havent seen the build error you mention below, but i think that's
because in a past discussion we determined that NOMMU ports should be
setting VMALLOC_START to 0 and VMALLOC_END to -1. is that no longer
the case ?

there are bunch more places where things would fail if
VMALLOC_{START,END} werent defined ...
-mike

2011-03-24 09:40:34

by David Howells

[permalink] [raw]
Subject: Re: [PATCH] NOMMU: support SMP dynamic percpu_alloc

Mike Frysinger <[email protected]> wrote:

> i havent seen the build error you mention below, but i think that's
> because in a past discussion we determined that NOMMU ports should be
> setting VMALLOC_START to 0 and VMALLOC_END to -1. is that no longer
> the case ?

Given that there's an explicit test now, I feel we should use it where
appropriate. I'll have a look to see what else might be renderable to that
test.

David