2006-05-12 15:22:15

by sej.kernel

[permalink] [raw]
Subject: mlock into kernel module

Hello,
I need to use mlock and munlock function into a kernel module. How so
I call this system call from my module ?
I need to do this because I must use mlock in my software, but I can't
use root or suser to start it. So mlock alwaays fail.
Regards,
sej


2006-05-12 15:52:34

by linux-os (Dick Johnson)

[permalink] [raw]
Subject: Re: mlock into kernel module


On Fri, 12 May 2006, sej.kernel wrote:

> Hello,
> I need to use mlock and munlock function into a kernel module. How so
> I call this system call from my module ?
> I need to do this because I must use mlock in my software, but I can't
> use root or suser to start it. So mlock alwaays fail.
> Regards,
> sej

You don't call mlock from a module. You can lock down pages inside
your module by using non-paged RAM. This can be accessed from user-space
by implimenting mmap() in your module so that the user-code can
memory-map it. That way, the page(s) you have allocated in the
kernel are never swapped.


Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.4 on an i686 machine (5592.89 BogoMips).
New book: http://www.lymanschool.com
_


****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

2006-05-12 18:44:51

by Arjan van de Ven

[permalink] [raw]
Subject: Re: mlock into kernel module

On Fri, 2006-05-12 at 17:22 +0200, sej.kernel wrote:
> Hello,
> I need to use mlock and munlock function into a kernel module. How so
> I call this system call from my module ?

no it's a bug if you need to do that

> I need to do this because I must use mlock in my software, but I can't
> use root or suser to start it. So mlock alwaays fail.

that's an rlimit thing, just fix the rlimit on your system.

Also if you want to do this for pinning hardware at a physical address
you have a really wrong design (mlock is the wrong api) which also
includes a security hole btw


2006-05-12 19:05:05

by Chris Wright

[permalink] [raw]
Subject: Re: mlock into kernel module

* sej.kernel ([email protected]) wrote:
> I need to use mlock and munlock function into a kernel module. How so
> I call this system call from my module ?

You shouldn't.

> I need to do this because I must use mlock in my software, but I can't
> use root or suser to start it. So mlock alwaays fail.

You should be using rlimits for this.

thanks,
-chris

2006-05-15 08:36:16

by sej

[permalink] [raw]
Subject: Re: mlock into kernel module

Chris Wright a ?crit :
> * sej.kernel ([email protected]) wrote:
>> I need to use mlock and munlock function into a kernel module. How so
>> I call this system call from my module ?
>
> You shouldn't.
>
>> I need to do this because I must use mlock in my software, but I can't
>> use root or suser to start it. So mlock alwaays fail.
>
> You should be using rlimits for this.
>
> thanks,
> -chris

So how to set rlimits ?
My program is in user mode and has to allocate about 128MB to 512MB of
non swappable memory. Maybe I can change the rlimits rights into my
kernel module ?
Do you know how to do this and where to find informations ?
Regards,
sej

2006-05-15 17:23:06

by Chris Wright

[permalink] [raw]
Subject: Re: mlock into kernel module

* sej ([email protected]) wrote:
> So how to set rlimits ?

You have a few options. Considering your program can't run as root,
that means directly using setrlimit (or smth like ulimit in bash) is
probably not right for you. Take a look at the pam docs for
/etc/security/limits.conf, specifically for memlock.

> My program is in user mode and has to allocate about 128MB to 512MB of
> non swappable memory. Maybe I can change the rlimits rights into my
> kernel module ?

I have no idea what your kernel module is, nor what your exact
requirements are. However, you shouldn't be changing rlimits in a
kernel module, there's plenty of userspace support for that.

thanks,
-chris