Hello,
I have written a linux kernel module. The linux version is 2.2.14.
In this module I have declared an array of size 2048. If I use this array, the execution of this module function causes kernel to reboot. If I kmalloc() this array then execution of this module function doesnot cause any problem. Can you explain this behaviour?
Thnaks,
Dinesh
Quoted 4 lines · --On Tuesday, October 02, 2001 3:29 PM +0000 Dinesh Gandhewar…
In this module I have declared an array of size 2048. If I use this array, the execution of this module function causes kernel to reboot. If I
kmalloc()this array then execution of this module function doesnot cause any problem.
If you are allocating it on the stack (i.e. as a local variable) you are probably running out of kernel stack space (depending what it's an array of).
If you are declaring it non-local, it's possible you are overwriting the end of it, and, kmalloc() being what it is, there happens to be some wasted space next to it.
--
Alex Bligh
Re: your mail
In reply to Dinesh GandhewarQuoted 3 lines
I have written a linux kernel module. The linux version is 2.2.14.
In this module I have declared an array of size 2048. If I use this array, the execution of this module function causes kernel to reboot. If Ikmalloc()this array then execution of this module function doesnot cause any problem. Can you explain this behaviour?
Yes
--
Alan
[Oh wait you want to know why...]
Either
1. You are using it for DMA
2. You are putting it on the stack and causing a stack overflow
"Dinesh Gandhewar" <[email protected]> was pleased to say:
Quoted 5 lines
I have written a linux kernel module. The linux version is 2.2.14. In this module I have declared an array of size 2048. If I use this array, the execution of this module function causes kernel to reboot. If I
kmalloc()this array then execution of this module function doesnot cause any problem. Can you explain this behaviour?
Unlike userland application programming, the kernel stack does not grow: it has a fixed size. You are using too much stack space and corrupting your system. The kernel stack is quite small (less than 8K is available for ALL nested modules and interrupt handlers), so driver functions should use an absolute minimum of local variables, such as a pointer to a per-instance data area. Kernel-leval kmalloc() is efficient enough to use frequently.
---------------------------------------------+-----------------------------
Tommy Reynolds | mailto: <[email protected]> Red Hat, Inc., Embedded Development Services | Phone: +1.256.704.9286 307 Wynn Drive NW, Huntsville, AL 35805 USA | FAX: +1.236.837.3839 Senior Software Developer | Mobile: +1.919.641.2923
Re: your mail
In reply to Dinesh GandhewarQuoted 10 lines · Dinesh Gandhewar
Hello,
I have written a linux kernel module. The linux version is 2.2.14. In this module I have declared an array of size 2048. If I use this array, the execution of this module function causes kernel to reboot. If Ikmalloc()this array then execution of this module function doesnot cause any problem.
Can you explain this behaviour?
Thnaks,
Dinesh
I would check that you are not accidentally exceeding the bounds of your array. Actual allocation occurs in page-size chunks. You may be exceeding your 2048 byte-limit without exceeding the 4096-byte page-size (of ix86).
However, a global array, or an array on the stack, has very strict limits. You can blow things up on the stack by exceeding an array boundary by one byte. And you can overwrite important memory objects by exceeding the bounds of a global memory object.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).
I was going to compile a list of innovations that could be attributed to Microsoft. Once I realized that Ctrl-Alt-Del was handled in the BIOS, I found that there aren't any.
Re: your mail
In reply to Dinesh GandhewarQuoted 3 lines · Dinesh Gandhewar
Hello,
I have written a linux kernel module. The linux version is 2.2.14. In this module I have declared an array of size 2048. If I use this
array, the execution of this module function causes kernel to reboot. If I kmalloc() this array then execution of this module function doesnot cause any problem.
Quoted 1 line
Can you explain this behaviour?
You didn't say how you declared the array or what the element
size was. If the array elements were larger than a char, by saying an array of size 2048, do you mean in bytes or in array elements?
You also didn't say where you called your module from. Was it
in an interrupt handler or at insmod time or from a system call.
If it was a automatic array on the stack (declared inside the
function and not declared static), you probably overflowed the stack.
Quoted 2 lines
Thnaks,
Dinesh
Mike
Signature · 4 lines
Michael H. Warfield | (770) 985-6132 | [email protected] (The Mad Wizard) | (678) 463-0932 | http://www.wittsend.com/mhw/ NIC whois: MHW9 | An optimist believes we live in the best of all PGP Key: 0xDF1DD471 | possible worlds. A pessimist is sure of it!