Skip to contentSkip to conversation

ARM: mm: Could I change module space size or place modules in vmalloc area?

PATCH Gioh Kim 6 participants 13 messages Jan 2, 2014 – Apr 29, 2014

Subsystems (2)
lore
Share & tools
lore

Gioh Kim

author
#0 lore raw

Hi,

I run out of module space because I have several big driver modules. I know I can strip the modules to decrease size but I need debug info now.

The default size of module is 16MB and the size is statically defined in the header file.
But a description for the module space size tells that it can be configurable at most 32MB.

I have changed the module space size to 18MB and tested my platform. It has been looking good.

I am not sure my patch is proper solution.
Anyway, could I configure the module space size?

Or could I place the modules into vmalloc area?

---
 arch/arm/Kconfig              |    4 ++++
 arch/arm/include/asm/memory.h |   10 +++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)
arch/arm/Kconfig index c1f1a7e..cf1fb55 renamed from arch/arm/Kconfig +0 -0

100644

arch/arm/Kconfig +4 -0
@@ -2257,6 +2257,10 @@ config ARM_CPU_SUSPEND
 
 endmenu
 
+config MODULES_AREA_SIZE
+       int
+       default 0x1000000
+
 source "net/Kconfig"
 
 source "drivers/Kconfig"
arch/arm/include/asm/memory.h +6 -2
index 6976b03..3396758 100644
@@ -32,13 +32,17 @@
 
 #ifdef CONFIG_MMU
 
+#if CONFIG_MODULES_AREA_SIZE > SZ_32M
+#error Too much space for modules
+#endif
+
 /*
  * PAGE_OFFSET - the virtual address of the start of the kernel image
  * TASK_SIZE - the maximum size of a user space task.
  * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
  */
-#define PAGE_OFFSET            UL(CONFIG_PAGE_OFFSET)
-#define TASK_SIZE              (UL(CONFIG_PAGE_OFFSET) - UL(SZ_16M))
+#define PAGE_OFFSET    UL(CONFIG_PAGE_OFFSET)
+#define TASK_SIZE      (UL(CONFIG_PAGE_OFFSET) -

UL(CONFIG_MODULES_AREA_SIZE))
#define TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M)

/*
@@ -51,7 +55,7 @@
* and PAGE_OFFSET - it must be within 32MB of the kernel text. */
#ifndef CONFIG_THUMB2_KERNEL
-#define MODULES_VADDR (PAGE_OFFSET - SZ_16M)
+#define MODULES_VADDR (PAGE_OFFSET - CONFIG_MODULES_AREA_SIZE)
#else
/* smaller range for Thumb-2 symbols relocation (2^24)*/
#define MODULES_VADDR (PAGE_OFFSET - SZ_8M)
--
1.7.9.5

#1 lore raw

Hi Gioh,

Quoted 2 lines · Gioh Kim

I run out of module space because I have several big driver modules. I know I can strip the modules to decrease size but I need debug info now.

Are you sure you need the debug info in kernel memory? I don't think the kernel is actually able to parse DWARF. You can load stripped binaries into the kernel, and still use the debug info with whatever tool you have.

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
author
#2 lore raw

Thank you for reply.

Quoted 10 lines

-----Original Message-----
From: Baruch Siach [mailto:baruch at tkos.co.il]
Sent: Thursday, January 02, 2014 7:14 PM
To: Gioh Kim
Cc: Russell King; linux-mm at kvack.org; linux-arm-kernel; HyoJun Im
Subject: Re: ARM: mm: Could I change module space size or place modules in vmalloc area?

Hi Gioh,

Quoted 8 lines
Quoted 2 lines · Gioh Kim

I run out of module space because I have several big driver modules. I know I can strip the modules to decrease size but I need debug info

now.

Are you sure you need the debug info in kernel memory? I don't think the kernel is actually able to parse DWARF. You can load stripped binaries into the kernel, and still use the debug info with whatever tool you have.

I agree you but driver developers of another team don't agree. I don't know why but they say they will strip drivers later :-( So I need to increase modules space size.

Quoted 5 lines

baruch

--
http://baruch.siach.name/blog/ ~. .~ Tk Open

Systems

Quoted 3 lines

=}------------------------------------------------ooO--U--Ooo------------ {=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

#3 lore raw
Quoted 17 lines · Gioh Kim

Thank you for reply.

Quoted 15 lines

-----Original Message-----
From: Baruch Siach [mailto:baruch at tkos.co.il]
Sent: Thursday, January 02, 2014 7:14 PM
To: Gioh Kim
Cc: Russell King; linux-mm at kvack.org; linux-arm-kernel; HyoJun Im
Subject: Re: ARM: mm: Could I change module space size or place modules in vmalloc area?

Hi Gioh,

Quoted 2 lines · Gioh Kim

I run out of module space because I have several big driver modules. I know I can strip the modules to decrease size but I need debug info

now.

Quoted 7 lines
Quoted 3 lines

Are you sure you need the debug info in kernel memory? I don't think the kernel is actually able to parse DWARF. You can load stripped binaries into the kernel, and still use the debug info with whatever tool you have.

I agree you but driver developers of another team don't agree. I don't know why but they say they will strip drivers later :-( So I need to increase modules space size.

ARM can only branch relatively within +/- 32MB. Hence, with a module space of 16MB, modules can reach up to a maximum 16MB into the direct- mapped kernel image. As module space increases in size, so that figure decreases. So, if module space were to be 40MB, the maximum size of the kernel binary would be 8MB.

You want to look at a line similar to this:

      .text : 0xc0008000 - 0xc031eda0   (3164 kB)

Also, note this:

    modules : 0xbf000000 - 0xc0000000   (  16 MB)

If the difference between the lowest module address (0xbf000000) and the highest of .text is greater than 32MB, it's impossible to load modules - they will fail to link.

What is the size of your kernel text? (show us the line(s) like the above.)

Thanks.

Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
author
#4 lore raw
Quoted 50 lines

-----Original Message-----
From: Russell King - ARM Linux [mailto:linux at arm.linux.org.uk]
Sent: Friday, January 03, 2014 9:47 AM
To: Gioh Kim
Cc: 'Baruch Siach'; linux-mm at kvack.org; 'linux-arm-kernel'; 'HyoJun Im'
Subject: Re: ARM: mm: Could I change module space size or place modules in vmalloc area?

Quoted 21 lines · Gioh Kim

Thank you for reply.

Quoted 19 lines

-----Original Message-----
From: Baruch Siach [mailto:baruch at tkos.co.il]
Sent: Thursday, January 02, 2014 7:14 PM
To: Gioh Kim
Cc: Russell King; linux-mm at kvack.org; linux-arm-kernel; HyoJun Im
Subject: Re: ARM: mm: Could I change module space size or place modules in vmalloc area?

Hi Gioh,

Quoted 3 lines · Gioh Kim

I run out of module space because I have several big driver modules. I know I can strip the modules to decrease size but I need debug info

now.

Are you sure you need the debug info in kernel memory? I don't think the kernel is actually able to parse DWARF. You can load stripped binaries into the kernel, and still use the debug info with whatever

tool you have.

Quoted 4 lines

I agree you but driver developers of another team don't agree. I don't know why but they say they will strip drivers later :-( So I need to increase modules space size.

ARM can only branch relatively within +/- 32MB. Hence, with a module space of 16MB, modules can reach up to a maximum 16MB into the direct- mapped kernel image. As module space increases in size, so that figure decreases. So, if module space were to be 40MB, the maximum size of the kernel binary would be 8MB.

You want to look at a line similar to this:

      .text : 0xc0008000 - 0xc031eda0   (3164 kB)

Also, note this:

Quoted 7 lines
    modules : 0xbf000000 - 0xc0000000   (  16 MB)

If the difference between the lowest module address (0xbf000000) and the highest of .text is greater than 32MB, it's impossible to load modules - they will fail to link.

What is the size of your kernel text? (show us the line(s) like the

above.)

My kernel size is about 8MB as below.

[    0.000000]     modules : 0x7f000000 - 0x80000000   (  16 MB)
[    0.000000]       .text : 0x80008000 - 0x8085d2b0   (8533 kB)

I think I can increase the modules space size into 20MB. Thanks for your reply.

Quoted 7 lines

Thanks.

--
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up. Estimation in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad. Estimate before purchase was "up to 13.2Mbit".

#9 lore raw
In reply to Gioh Kim
Quoted 8 lines · Gioh Kim

I run out of module space because I have several big driver modules. I know I can strip the modules to decrease size but I need debug info now.

The default size of module is 16MB and the size is statically defined in the header file.
But a description for the module space size tells that it can be configurable at most 32MB.

Quoted 8 lines

I have changed the module space size to 18MB and tested my platform. It has been looking good.

I am not sure my patch is proper solution.
Anyway, could I configure the module space size?

Or could I place the modules into vmalloc area?

Aside from the good comments that Russell made, I would remark that the fact that you need multiple megabytes worth of modules indicates that you are doing something wrong. Can you point to a git tree containing those modules?

Arnd

#10 lore raw
Quoted 6 lines · Arnd Bergmann

Aside from the good comments that Russell made, I would remark that the fact that you need multiple megabytes worth of modules indicates that you are doing something wrong. Can you point to a git tree containing those modules?

From the comments which have been made, one point that seems to have

been identified is that if this module is first stripped and then loaded, it can load, but if it's unstripped, it's too big. This sounds suboptimal to me - the debug info shouldn't be loaded into the kernel.

However, I guess there's bad interactions with module signing if you don't do this and the module was signed with the debug info present, so I don't think there's a good solution for this.

Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
#11 lore raw
Quoted 10 lines · Russell King - ARM Linux
Quoted 4 lines · Arnd Bergmann

Aside from the good comments that Russell made, I would remark that the fact that you need multiple megabytes worth of modules indicates that you are doing something wrong. Can you point to a git tree containing those modules?

From the comments which have been made, one point that seems to have been identified is that if this module is first stripped and then loaded, it can load, but if it's unstripped, it's too big. This sounds suboptimal to me - the debug info shouldn't be loaded into the kernel.

Reading the layout_and_allocate() function, that is probably the intention already, and if something goes wrong there on ARM, it could be fixed up in an arch specific module_frob_arch_sections() function.

Quoted 3 lines

However, I guess there's bad interactions with module signing if you don't do this and the module was signed with the debug info present, so I don't think there's a good solution for this.

My point was another anyway: I can't think of any good reason why you would end up with this many modules on any sane system. The only cases I've seen so far are

- modules written in C++, with libstdc++ linked into the module
- a closed-source platform port hidden in a loadable module that contains all the device drivers and subsystems while ignoring the infrastructure we have in the kernel, and the possible legal implications.
- a bug in the module using large arrays that should just be dynamically allocated.
- device firmware statically linked into the module rather than loaded using request_firmware.

In each of these cases, the real answer is to fix the code they are trying to load to do things in a more common way, especially if the intention is to eventually merge the code upstream. It is of course possible that they are indeed trying something valid, that's why I asked to see the source code.

Arnd

author
#12 lore raw

I am sorry to read your mail so late.
My module had been a proprietary driver so that I requested to strip it and got small size driver.

Thank you for attention.

Quoted 50 lines

-----Original Message-----
From: Arnd Bergmann [mailto:arnd at arndb.de]
Sent: Friday, January 03, 2014 10:24 PM
To: linux-arm-kernel at lists.infradead.org
Cc: Russell King - ARM Linux; HyoJun Im; linux-mm at kvack.org; Gioh Kim
Subject: Re: ARM: mm: Could I change module space size or place modules in vmalloc area?

Quoted 10 lines · Russell King - ARM Linux
Quoted 4 lines · Arnd Bergmann

Aside from the good comments that Russell made, I would remark that the fact that you need multiple megabytes worth of modules indicates that you are doing something wrong. Can you point to a git tree containing those modules?

From the comments which have been made, one point that seems to have been identified is that if this module is first stripped and then loaded, it can load, but if it's unstripped, it's too big. This sounds suboptimal to me - the debug info shouldn't be loaded into the

kernel.

Reading the layout_and_allocate() function, that is probably the intention already, and if something goes wrong there on ARM, it could be fixed up in an arch specific module_frob_arch_sections() function.

Quoted 3 lines

However, I guess there's bad interactions with module signing if you don't do this and the module was signed with the debug info present, so I don't think there's a good solution for this.

My point was another anyway: I can't think of any good reason why you would end up with this many modules on any sane system. The only cases I've seen so far are

- modules written in C++, with libstdc++ linked into the module
- a closed-source platform port hidden in a loadable module that contains all the device drivers and subsystems while ignoring the infrastructure we have in the kernel, and the possible legal implications.
- a bug in the module using large arrays that should just be dynamically allocated.
- device firmware statically linked into the module rather than loaded using request_firmware.

In each of these cases, the real answer is to fix the code they are trying to load to do things in a more common way, especially if the intention is to eventually merge the code upstream. It is of course possible that they are indeed trying something valid, that's why I asked to see the source code.

Arnd

#5 lore raw
In reply to Russell King - ARM Linux
Quoted 26 lines · Russell King - ARM Linux
Quoted 17 lines · Gioh Kim

Thank you for reply.

Quoted 15 lines

-----Original Message-----
From: Baruch Siach [mailto:baruch at tkos.co.il]
Sent: Thursday, January 02, 2014 7:14 PM
To: Gioh Kim
Cc: Russell King; linux-mm at kvack.org; linux-arm-kernel; HyoJun Im
Subject: Re: ARM: mm: Could I change module space size or place modules in vmalloc area?

Hi Gioh,

Quoted 2 lines · Gioh Kim

I run out of module space because I have several big driver modules. I know I can strip the modules to decrease size but I need debug info

now.

Quoted 7 lines
Quoted 3 lines

Are you sure you need the debug info in kernel memory? I don't think the kernel is actually able to parse DWARF. You can load stripped binaries into the kernel, and still use the debug info with whatever tool you have.

I agree you but driver developers of another team don't agree. I don't know why but they say they will strip drivers later :-( So I need to increase modules space size.

Quoted 6 lines

ARM can only branch relatively within +/- 32MB. Hence, with a module space of 16MB, modules can reach up to a maximum 16MB into the direct- mapped kernel image. As module space increases in size, so that figure decreases. So, if module space were to be 40MB, the maximum size of the kernel binary would be 8MB.

Hi Russell ,Arnd or Will,

I encountered the same situation in arm64, I loaded 80+ modules in arm64, and run out of module address space(64M). Why the module space is restricted to 64M, can it be expanded?

In commit 257cb2519(arm64: Loadable modules), it mentioned that " Loadable modules are loaded 64MB below the kernel image due to branch relocation restrictions", "branch relocation restrictions" is a AArch64 instruction set restrictions?

Thanks,
Jianguo Wu.

Quoted 16 lines

You want to look at a line similar to this:

      .text : 0xc0008000 - 0xc031eda0   (3164 kB)

Also, note this:

    modules : 0xbf000000 - 0xc0000000   (  16 MB)

If the difference between the lowest module address (0xbf000000) and the highest of .text is greater than 32MB, it's impossible to load modules - they will fail to link.

What is the size of your kernel text? (show us the line(s) like the above.)

Thanks.

#6 lore raw
Quoted 35 lines · Jianguo Wu
Quoted 26 lines · Russell King - ARM Linux
Quoted 17 lines · Gioh Kim

Thank you for reply.

Quoted 15 lines

-----Original Message-----
From: Baruch Siach [mailto:baruch at tkos.co.il]
Sent: Thursday, January 02, 2014 7:14 PM
To: Gioh Kim
Cc: Russell King; linux-mm at kvack.org; linux-arm-kernel; HyoJun Im
Subject: Re: ARM: mm: Could I change module space size or place modules in vmalloc area?

Hi Gioh,

Quoted 2 lines · Gioh Kim

I run out of module space because I have several big driver modules. I know I can strip the modules to decrease size but I need debug info

now.

Quoted 7 lines
Quoted 3 lines

Are you sure you need the debug info in kernel memory? I don't think the kernel is actually able to parse DWARF. You can load stripped binaries into the kernel, and still use the debug info with whatever tool you have.

I agree you but driver developers of another team don't agree. I don't know why but they say they will strip drivers later :-( So I need to increase modules space size.

Quoted 6 lines

ARM can only branch relatively within +/- 32MB. Hence, with a module space of 16MB, modules can reach up to a maximum 16MB into the direct- mapped kernel image. As module space increases in size, so that figure decreases. So, if module space were to be 40MB, the maximum size of the kernel binary would be 8MB.

Quoted 5 lines

Hi Russell ,Arnd or Will,

I encountered the same situation in arm64, I loaded 80+ modules in arm64, and run out of module address space(64M). Why the module space is restricted to 64M, can it be expanded?

The module space is restricted to 64M on AArch64 because the range of the BL instruction is += 128M. In order to call kernel functions, we need to ensure that this range is large enough and therefore place the modules 64M below the kernel text, allowing 64M for modules and 64M for the kernel text. We could probably improve this a bit by assuming a maximum size for the kernel text.

If we want to remove the problem altogether, we'd need to hack the module loader to insert trampolines (fiddly) or somehow persuade the tools to use indirect branches (BLR) for all calls (inefficient).

Will

#7 lore raw
Quoted 21 lines · On Tuesday 29 April 2014 12:19:46 Will Deacon wrote:
Quoted 8 lines · Jianguo Wu
Quoted 6 lines · Russell King - ARM Linux

ARM can only branch relatively within +/- 32MB. Hence, with a module space of 16MB, modules can reach up to a maximum 16MB into the direct- mapped kernel image. As module space increases in size, so that figure decreases. So, if module space were to be 40MB, the maximum size of the kernel binary would be 8MB.

Quoted 5 lines

Hi Russell ,Arnd or Will,

I encountered the same situation in arm64, I loaded 80+ modules in arm64, and run out of module address space(64M). Why the module space is restricted to 64M, can it be expanded?

The module space is restricted to 64M on AArch64 because the range of the BL instruction is += 128M. In order to call kernel functions, we need to ensure that this range is large enough and therefore place the modules 64M below the kernel text, allowing 64M for modules and 64M for the kernel text. We could probably improve this a bit by assuming a maximum size for the kernel text.

Quoted 3 lines

If we want to remove the problem altogether, we'd need to hack the module loader to insert trampolines (fiddly) or somehow persuade the tools to use indirect branches (BLR) for all calls (inefficient).

Well, there might also be a bug involved. Loading 80 modules should never take up 64MB. The typical size of a loadable module should be a few dozen kilobytes, although we have a few modules that are hundreds of kilobytes.

Jianguo Wu, can you send the defconfig you were using? Did you have some debugging option enabled that increased the module size?

Arnd

#8 lore raw
Quoted 26 lines · Arnd Bergmann
Quoted 21 lines · On Tuesday 29 April 2014 12:19:46 Will Deacon wrote:
Quoted 8 lines · Jianguo Wu
Quoted 6 lines · Russell King - ARM Linux

ARM can only branch relatively within +/- 32MB. Hence, with a module space of 16MB, modules can reach up to a maximum 16MB into the direct- mapped kernel image. As module space increases in size, so that figure decreases. So, if module space were to be 40MB, the maximum size of the kernel binary would be 8MB.

Quoted 5 lines

Hi Russell ,Arnd or Will,

I encountered the same situation in arm64, I loaded 80+ modules in arm64, and run out of module address space(64M). Why the module space is restricted to 64M, can it be expanded?

The module space is restricted to 64M on AArch64 because the range of the BL instruction is += 128M. In order to call kernel functions, we need to ensure that this range is large enough and therefore place the modules 64M below the kernel text, allowing 64M for modules and 64M for the kernel text. We could probably improve this a bit by assuming a maximum size for the kernel text.

Quoted 3 lines

If we want to remove the problem altogether, we'd need to hack the module loader to insert trampolines (fiddly) or somehow persuade the tools to use indirect branches (BLR) for all calls (inefficient).

Quoted 6 lines

Well, there might also be a bug involved. Loading 80 modules should never take up 64MB. The typical size of a loadable module should be a few dozen kilobytes, although we have a few modules that are hundreds of kilobytes.

Jianguo Wu, can you send the defconfig you were using? Did you have some debugging option enabled that increased the module size?

If 64K pages are in use we could end up with a tonne of fragmentation but yes, worth looking at the .config.

Will