FAQ Database Discussion Community


Linux Kernel Driver Module: Handle multiple device files using a single driver

linux-kernel,kernel-module
I am a beginner to kernel module programming. And using resources online (especially this tutorial) I have managed to write most of my driver. The driver basically is a character device which maps different areas of SRAM into separate files. You can see the actual code here. Right now I...

Timer in FreeBSD kernel module?

timer,kernel,freebsd,kernel-module,callout
I'd like to let my kernel module periodically do something (a certain time interval, like 10 sec) in FreeBSD kernel. Any example for doing that? I searched and found that there are functions like callout/timeout(old), but they seem complicated, and I cannot find good examples for them. For callout'', it...

How are some Linux device drivers automatically loaded/unloaded?

linux,linux-kernel,linux-device-driver,kernel-module
With regards to Linux device drivers, my understanding (obtained from reading this excellent DIY article) is that there are essentially six events/parts of a device driver "lifecycle": Load - the compiled driver is loaded as a Linux kernel module via insmod Open - the device is opened/readied for usage Read/Write...

Dynamically creating variable in Kernel Module

linux-kernel,kernel,kernel-module
I am planning to use kthread_run API in my kernel module. As kthread_run, returns a struct task_struct *, which i want to store in a variable global across my module. However, i want one thread each for a cpu and i obtain no of cpus using num_online_cpus. However, when i...

Modprobe mutiple instances of a kernel module to prevent race conditions (device tree)

linux-device-driver,kernel-module,race-condition,device-tree
I am writing a kernel module for an embedded Linux system. The module works fine and is automatically loaded by using the compatible entry in the device tree. It creates a device in /dev/, which i can access using ioctl massages. The module manages several discrete memory regions. Since the...

Accessing pins of Linux hardware inside device driver

linux,linux-device-driver,kernel-module,device-driver
I read this excellent DIY article on writing Linux device drivers, but am still not seeing the "forest through the trees" on a major item here. Ultimately the end user software (in user space) needs to communicate with the hardware (that the device drivers are driving/wrapping/adapting). Hardware is driven by...

Intercept ELF loader in linux kernel: fs/binfmt_elf.c file via loadable kernel module

c,linux-kernel,kernel,kernel-module,elf
I am new to kernel coding and at present I am working with ELF files which have been modified a little bit for the security purposes for which I need to look at some of it's custom section headers and extract the unique code encryption key from it for the...

Is it possible to use dma_set_mask() to tell kernel not to use memory under 4G

linux-kernel,linux-device-driver,kernel-module,dma,pci-e
My pcie device has a bug that it cant dma to addresses below 4G, What mask should i use with dma_set_mask to tell this to the kernel?

How to load a module before another module loads?

c,module,linux-kernel,make,kernel-module
I have two modules, X and Y. I need to load the Y module when X module loaded. How can I do this without adding any softdeps? Is there any other way to specify to the kernel that X depends on Y and kernel need to load Y before loading...

Best way to handle ERESTARTSYS in kthread?

thread-safety,kernel,kernel-module
I have a kthread that blocks on a wait event until a timeout is reached. However, if a system event interrupts it (such as the system going into suspend), it returns -ERESTARTSYS. I'm curious to know how to handle this situation, since I don't want the kthread to die, just...

insmod not throwing error for a positive return

kernel-module,insmod
I am writing my first kernel module and it is a simple Hello World Kernel Module. The tldp guide I am following said that insmod would not load a module if the init_module function returns a non-zero value. It is working as expected when returning some negative number but while...

Setting TSD Bit in CR4 causes crash

c,linux-kernel,kernel-module
I want to restrict the usage of the rdtsc instruction such that it can only be executed when in ring 0. According to the Intel Manuals this is possible by setting CR4.TSD which is done by the following kernel module: #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> MODULE_LICENSE("GPL"); #define TSD_BIT 2...

Compiling a kernel module using makefile in linux

c,linux,makefile,linux-kernel,kernel-module
I am new to kernel programming. I ahve written a hello world program but I am not able to complie it. I have serached and so made a make file under /usr/src and then doing sudo make command to run it. But its giving the following error: make -C /lib/modules/3.2.0-23-generic-pae/build...

Compiling a loadable kernel module(Debian/Ubuntu)

c,linux,ubuntu,linux-kernel,kernel-module
This question is a follow up of this one. I am trying to compile the ELF loader as an individual LKM and use it as a standalone application(replacing the original module within the base kernel sounds too risky). Up to this point I have copied the source file into a...

“Segmentation fault” when `rmmod` or `modprobe -r`

c,linux,kernel,embedded,kernel-module
Trying the simplest kernel module from LDD3 without any modification on custom built kernel v4.1.0-rc6 for Beagle Bone board with BusyBox v1.23.0. The code for the module is as follows: #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, world\n"); return 0; } static void hello_exit(void) {...

Get details of Linux kernel modules in C++

c++,linux,kernel-module
In Linux, I need to get the details(viz. service exit code,status,type,etc) of all the driver modules and I tried reading /proc/modules. But it gives only name, size and use count. I read that modinfo retrieves info from lib/modules/,but all modules doesn't have all info in it. From where can I...

Testing modules/drivers of Linux kernel running in any target board

testing,linux-kernel,embedded-linux,kernel-module,device-driver
How do we test the modules and drivers(like USB,I2C,HDMI etc..) of a Linux kernel running in a target board? is there any tools/frameworks doing the job? i found this thread.Can anyone suggest me the best one? thanks in advance...

What stands p2v8 in mod_unload modversions ARMv6 p2v8 for?

linux-kernel,kernel-module
After compiling a kernel for qemu, I get a lots of errors like listed below: ipv6: version magic '3.18.11-hypriotos+ mod_unload modversions ARMv6 ' should be '3.18.11-hypriotos+ mod_unload modversions ARMv6 p2v8 ' Obviously my kernel and the Hypriotos kernel are somehow different. What means p2v8? And how can I enable it...

How to restrict receiving a generic netlink multicast to the root user?

linux,linux-kernel,kernel,kernel-module,netlink
I wrote a kernel module that sends generic Netlink multicasts, and wrote a userland client using libmnl that receives them. That all works fine, but my client works even when it's not the root user, and I want to prevent that. man 7 netlink says: Only processes with an effective...

Missing headers for kernel in bzImage loaded on qemu

linux-kernel,kernel,header-files,kernel-module,qemu
I am trying to compile a kernel module of kernel version 3.2.0 on a linux kernel bzImage loaded on a qemu emulator, however I am getting the following error: /lib/modules/3.2.0/build no such file or directory. I tried to look up solutions over the net but nothing specific related to solve...

How to directly access Resident Set Size (RSS) of a process from within kernel module?

linux,linux-kernel,kernel-module
I want to directly access the Resident Set Size (RSS) of a process from inside a kernel module (I want to take a real time decision based on RSS, so calculating it every time is a bad option for me). /proc/$PID/status has a VmRSS field which I can use, but...

Pool of Memory in Kernel driver for Multiple processes

memory-management,linux-kernel,linux-device-driver,kernel-module,kmalloc
Suppose we want to maintain a pool of memory in a device driver or module. How can that pool be created and be available to multiple processes lets say 4 processes, accessing this driver/module. Assume 1 MB of memory in the pool. When I was reading LDD I came across...

Error compiling kernel module linux/module.h: No such file or directory found

c,linux,makefile,linux-kernel,kernel-module
I am using a simple example to create a Hello World Kernel module. Link below: http://www.thegeekstuff.com/2013/07/write-linux-kernel-module/ when attempting to run the makefile using "make hello" in the same directory as hello.c. I get the following error: hello.c:1:64: fatal error: linux/module.h: No such file or directory I have successfully installed linux...