login
Header Space

 
 

How to exec user process in kernel mode.

September 5, 2008 - 8:36am
Submitted by Anonymous on September 5, 2008 - 8:36am.
Linux

I want to run a specific process in kernel mode.
How to execute it in kernel mode?

you can't

September 5, 2008 - 1:53pm
sileNT (not verified)

You can't.

Unless you make it a kernel module - for which you'll need program sources and some degree of kernel programming.

Or, define what you understand by "running process in kernel mode".

Without making .ko, I know

September 8, 2008 - 8:09am
Anonymous (not verified)

Without making .ko, I know that it is possible to run user process in kernel mode. But I don't know how to make.
I will put the question otherway, is it possible to set the supervisor bit in user process?
Because as we know when sys call is triggered it will generate int80 which puts exec mode to kernel and while returning back from sys-call post wrapper disables it back to user mode. Instead is it possible that in post call we still maintain the mode of supervisor?

what do you want to solve

September 8, 2008 - 9:43am

what problem do you want to solve by doing this? you seem to have a solution in mind and want linux to behave like some other system where this solution is the right one. maybe you have to adapt your solution to how unix works and get it cleaner, more crash proof and more portable on the way.

what do you mean with 'I know that it is possible to run user process in kernel mode', which example do you have in mind? I don't want to have to guess your thoughts, just tell us. there is no simple supervisor bit that lets you just do more, at least not on i386, and not every syscall goes through int80.

user space processes don't work in kernel mode, the programming model is totally different. code using the in kernel programming model is called modules. what you can do from user space is mmap()ing your device's i/o area and get interrupts via the UIO interface (cf. http://lwn.net/Articles/232575/) which only requires a very minimal kernel module just for receiving and transmitting the interrupts.

I have a set of code which

September 9, 2008 - 9:31am
Anonymous (not verified)

I have a set of code which was earlier running on some other OS where everything runs in supervisor mode.
Now I am porting it to linux. In the code there are hardcoded address which touches the PCI device mem. I don't want to modify the code.
I want this process to be run in kernel mode so that it can access the PCI mem.

pci mem

September 9, 2008 - 10:05am

pci device memory by definition has no hardcodeable address. it may have worked by chance (because hardware and setup code never changed) but this simplistic approach is not supported in linux. you can get a base address from the kernel and add your constant offsets, of course, this way you only have to split your absolute addresses into base address and offset. this book http://lwn.net/Kernel/LDD3/ may be what you need, or have a real look at the UIO interface.

One solution

September 10, 2008 - 10:52am
Andrew Klossner (not verified)

You can solve this specific problem by using mmap() on file /dev/mem to map the desired portion of PCI memory space into your process's address space at the hard-coded address. To discovery the true addresses, read the BAR registers from the device's config space by using the lspci command or by looking at the config file in the device's directory under /sys/bus/pci/devices.

Mmap is working fine for me.

September 11, 2008 - 7:43am
Anonymous (not verified)

Mmap is working fine for me. But the problem is mapped address is not to the one I have (i.e hardcoded address).
The first param to mmap tells where I want the mapping addr to be. But it is neglecting and mapping to some low address.

To adjust to this I need to change all the hardcoded address which consumes my huge time.

Without changing my hardcoded address if I get any alternative soln I will be very happy.

What is your hard-coded

September 11, 2008 - 12:18pm
Andrew Klossner (not verified)

What is your hard-coded address? Most kernels on 32-bit machines won't let a process use an address that is >= 0xc0000000.

My hardcoded address is

September 12, 2008 - 8:26am
Anonymous (not verified)

My hardcoded address is 0xd0000000.
Thats why I wanted to run this process in kernel mode.

64 bit kernel

September 12, 2008 - 4:29pm

32 bit processes on a 64 bit kernel apparently have a full 4G address space, the kernel sits at the end of the (inaccessible for 32 bit processes) 64 bit address space. as you can see here:

$ cat /proc/self/maps
08048000-0804f000 r-xp 00000000 08:01 1439239                            /bin/cat
0804f000-08050000 rw-p 00006000 08:01 1439239                            /bin/cat
08050000-08071000 rw-p 08050000 00:00 0                                  [heap]
f7e41000-f7e42000 rw-p f7e41000 00:00 0 
f7e42000-f7f7a000 r-xp 00000000 08:01 1440336                            /lib/libc-2.7.so
f7f7a000-f7f7b000 r--p 00138000 08:01 1440336                            /lib/libc-2.7.so
f7f7b000-f7f7d000 rw-p 00139000 08:01 1440336                            /lib/libc-2.7.so
f7f7d000-f7f80000 rw-p f7f7d000 00:00 0 
f7f87000-f7f89000 rw-p f7f87000 00:00 0 
f7f89000-f7fa3000 r-xp 00000000 08:01 1440333                            /lib/ld-2.7.so
f7fa3000-f7fa5000 rw-p 0001a000 08:01 1440333                            /lib/ld-2.7.so
ffca1000-ffcb6000 rw-p 7ffffffea000 00:00 0                              [stack]
ffffe000-fffff000 r-xp ffffe000 00:00 0                                  [vdso]

cat uses the full 4G space to map libraries, heap, stack.
these days it's nearly impossible to buy a pc without 64 bit capability and if in doubt you can use a normal 32 bit userspace on a 64 bit kernel.

btw, why did the original developer choose to hardcode the addresses in the code? it is much more readable to at lease use constants for that, eg. BASE=0xd000000, COMMAND=BASE+0x123, etc. someone decided to write unmaintainable code, here, and now you have to clean up the mess.

mmap() the BARs

September 11, 2008 - 4:01am
Anonymous (not verified)

Under current Linux kernels, the various PCI BARs exist as mmap-able files in /sys/bus/pci; for example, /sys/bus/pci/devices/0000:02:09.1/resource0 is BAR 0 of device 0000:02:09.1 on this machine. You could mmap() the BARs at the address you want and access the device directly.

____call_usermodehelper().

September 12, 2008 - 8:29am
Anonymous (not verified)

____call_usermodehelper().

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary