linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re:
  2001-10-02 15:29 Dinesh  Gandhewar
@ 2001-10-02 15:23 ` Tommy Reynolds
  2001-10-02 15:30 ` your mail Alan Cox
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tommy Reynolds @ 2001-10-02 15:23 UTC (permalink / raw)
  To: Dinesh  Gandhewar; +Cc: mlist-linux-kernel

"Dinesh  Gandhewar" <dinesh_gandhewar@rediffmail.com> was pleased to say:

> 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:	<reynolds@redhat.com>
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* (no subject)
@ 2001-10-02 15:29 Dinesh  Gandhewar
  2001-10-02 15:23 ` Tommy Reynolds
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Dinesh  Gandhewar @ 2001-10-02 15:29 UTC (permalink / raw)
  To: mlist-linux-kernel


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 
 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: your mail
  2001-10-02 15:29 Dinesh  Gandhewar
  2001-10-02 15:23 ` Tommy Reynolds
@ 2001-10-02 15:30 ` Alan Cox
  2001-10-02 15:32 ` Alex Bligh - linux-kernel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Alan Cox @ 2001-10-02 15:30 UTC (permalink / raw)
  To: dinesh_gandhewar; +Cc: mlist-linux-kernel

> 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?

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re:
  2001-10-02 15:29 Dinesh  Gandhewar
  2001-10-02 15:23 ` Tommy Reynolds
  2001-10-02 15:30 ` your mail Alan Cox
@ 2001-10-02 15:32 ` Alex Bligh - linux-kernel
  2001-10-02 15:49 ` your mail Richard B. Johnson
  2001-10-02 15:52 ` Michael H. Warfield
  4 siblings, 0 replies; 6+ messages in thread
From: Alex Bligh - linux-kernel @ 2001-10-02 15:32 UTC (permalink / raw)
  To: Dinesh Gandhewar, mlist-linux-kernel; +Cc: Alex Bligh - linux-kernel



--On Tuesday, October 02, 2001 3:29 PM +0000 Dinesh  Gandhewar 
<dinesh_gandhewar@rediffmail.com> wrote:

> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: your mail
  2001-10-02 15:29 Dinesh  Gandhewar
                   ` (2 preceding siblings ...)
  2001-10-02 15:32 ` Alex Bligh - linux-kernel
@ 2001-10-02 15:49 ` Richard B. Johnson
  2001-10-02 15:52 ` Michael H. Warfield
  4 siblings, 0 replies; 6+ messages in thread
From: Richard B. Johnson @ 2001-10-02 15:49 UTC (permalink / raw)
  To: Dinesh Gandhewar; +Cc: mlist-linux-kernel

On 2 Oct 2001, Dinesh  Gandhewar wrote:

> 
> 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 

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.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: your mail
  2001-10-02 15:29 Dinesh  Gandhewar
                   ` (3 preceding siblings ...)
  2001-10-02 15:49 ` your mail Richard B. Johnson
@ 2001-10-02 15:52 ` Michael H. Warfield
  4 siblings, 0 replies; 6+ messages in thread
From: Michael H. Warfield @ 2001-10-02 15:52 UTC (permalink / raw)
  To: Dinesh Gandhewar; +Cc: mlist-linux-kernel

On Tue, Oct 02, 2001 at 03:29:45PM -0000, Dinesh  Gandhewar wrote:

> 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?

	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.

> Thnaks,
> Dinesh 

	Mike
-- 
 Michael H. Warfield    |  (770) 985-6132   |  mhw@WittsEnd.com
  (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!


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-10-02 16:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-02 15:29 Dinesh  Gandhewar
2001-10-02 15:23 ` Tommy Reynolds
2001-10-02 15:30 ` your mail Alan Cox
2001-10-02 15:32 ` Alex Bligh - linux-kernel
2001-10-02 15:49 ` your mail Richard B. Johnson
2001-10-02 15:52 ` Michael H. Warfield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).