How to communicate with a Linux kernel module from user space without littering /dev with new nodes?

Asked
Active3 hr before
Viewed126 times

5 Answers

modulecommunicatelinux
90%

What are the ways to communicate with a kernel module from user space? By communication i mean sending information and commands between the kernel module and a user space process.,Also, udev rules make /dev very similar to sysfs and debugfs: How to create a device in /dev automatically upon loading of the kernel module for a device driver?,More specifically, can someone advice the best way to communicate with a kernel module that does not actually drives any hardware and therefore should not be littering /dev with stub nodes that exists solely for ioctl calls? I mostly need to check its various status variables and send it a block of data with a request type tag and see if the request succeeded.,Sysfs exports information about devices and drivers from the kernel device model to userspace, and is also used for configuration.

In any case, you will have to dirty some namespace... a filesystem entry in case of sysfs and debugfs. Just choose your poison.

Also, udev rules make /dev very similar to sysfs and debugfs: How to create a device in /dev automatically upon loading of the kernel module for a device driver?

udev
load more v
88%

More specifically, can someone advice the best way to communicate with a kernel module that does not actually drives any hardware and therefore should not be littering /dev with stub nodes that exists solely for ioctl calls? I mostly need to check its various status variables and send it a block of data with a request type tag and see if the request succeeded.,What are the ways to communicate with a kernel module from user space? By communication i mean sending information and commands between the kernel module and a user space process.,I'm not saying that it's the best solution but it works fine for me. You can even create an automatic detection of the keyboard by parsing the ls result ...,You may provide the callback function from module A. In that case you don't need to export each function you need to the kernel namespace. I presume you just could supply some structure to the B. Something like:

Thank you for the clue about ls -l /dev/input/by-id it helped me a lot !.

defenderdz @defenderdz - pc: ~$ ls - l / dev / input / by - id | grep kbd
lrwxrwxrwx 1 root root 9 nov.28 14: 04 usb - Logitech_USB_Receiver - event - kbd - > .. / event7
lrwxrwxrwx 1 root root 10 nov.29 00: 33 usb - NOVATEK_USB_Keyboard - event - kbd - > .. / event26
lrwxrwxrwx 1 root root 9 nov.28 14: 04 usb - SONiX_USB_DEVICE - event - kbd - > .. / event3
defenderdz @defenderdz - pc: ~$

In my example the correct path is :

defenderdz @defenderdz - pc: ~$ sudo cat / dev / input / by - id / usb - NOVATEK_USB_Keyboard - event - kbd ??
   ? ] ? I ?? ? ] ? I ?? ? ] ? Ia ?? ? ] ? b ?? ? ] ? b ?? ? ] ? b ?? ? ] ?? ?? ? ] ?? ?? ? ] ?? s ?? ? ] ?? ?? ] ?? ?? ] ?? ?? ] ? >
??
? ] ? >
??
? ] ? >
d ?? ? ] ? 8
   ??
   ? ] ? 8
   ??
   ? ] ? 8
   ??
   ? ] ?? ?? ? ] ?? ?? ? ] ?? s ?? ? ] H | ?? ? ] H | ?? ? ] H | ?? ? ] ?? ?? ? ] ?? ?? ? ] ?? d ?? ? ] ?? ?? ] ? ?? ? ] ?

In your case

neel @pc1$ sudo cat / dev / input / by - id / usb - Plus_More_Enterprise_LTD._USB - compliant_keyboard - event - kbd
load more v
72%

Linux kernel extension is used to monitor application health, communicate with user-level applications, and manage kernel logs. The following prerequisites are required for users to make use of it.,Kernel module: It contains the definition of the system calls that can be used by the application and kernel level APIs to monitor application health, communicate with user level applications, and so on.,This section shows a sample user application and a kernel module. The user application will be able to communicate with the kernel module and exchange data.,Application: It can be any application running at user-level which can interact with kernel module.

# insmod helloWorld.ko
Welcome to Hello world Module.
load more v
65%

We usually refer to the execution modes as kernel space and user space. These terms encompass not only the different privilege levels inherent in the two modes, but also the fact that each mode can have its own memory mapping—its own address space—as well.,User-space utilities that load modules into the running kernels and remove them.,Using stacking to split modules into multiple layers can help reduce development time by simplifying each layer. This is similar to the separation between mechanism and policy that we discussed in Chapter 1.,The command name stored in current->comm is the base name of the program file (trimmed to 15 characters if need be) that is being executed by the current process.

#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)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);
% make
make[1]: Entering directory `/usr/src/linux-2.6.10'
  CC [M]  /home/ldd3/src/misc-modules/hello.o
  Building modules, stage 2.
  MODPOST
  CC      /home/ldd3/src/misc-modules/hello.mod.o
  LD [M]  /home/ldd3/src/misc-modules/hello.ko
make[1]: Leaving directory ` / usr / src / linux - 2.6 .10 ' %
   su
root # insmod. / hello.ko
Hello, world
root # rmmod hello
Goodbye cruel world
root #
load more v
75%

What are the ways to communicate with a kernel module from user space? By communication i mean sending information and commands between the kernel mod ... , I am reading Embedded Linux Primer book and The Linux Kernel Module Programming Guide and I am confused about user space application communication with kernel module , I am developing a user space program that interacts with my linux kernel module. I know one of the ways to achieve this is by using netlink sockets. H ... , I have developed a simple linux kernel module which I will send to it a char message from user space program. This is the module : And this my C ...

load more v

Other "module-communicate" queries related to "How to communicate with a Linux kernel module from user space without littering /dev with new nodes?"