Skip to content
Advertisement

How to make LKM multi-process safe?

I make simple LKM (Linux kernel module) to interact my MPI application (multi process per one compute node) at user level with kernel level information. I need to extract some data from kernel to the user level application at runtime. My MPI application uses few processes run on the same compute node simultaneously.

My LKM provides two files in /proc. The file /proc/mylkm_input uses to provide some virtual addresses to the LKM. The file /proc/mylkm_output uses to read information from the LKM by my MPI application.

The application is multi processes. At least two processes can provide data into LKM and expect respond from LKM (via /proc/mylkm_output) with data unique for particular process.

Also, the file /proc/mylkm_output can be read by different process at the same time. To read information I do lseek(fileId, 0, SEEK_SET) and then read(fileId, buffer, size)

Are any solutions to make LKM multi-process safe?

Thank you

Sergey

Update

I implemented following code as proposed below. I hope this is help me to make the LKM process-safe.

JavaScript

Advertisement

Answer

Kernel module may distinguish processes, which access the file, using variable current:

JavaScript

Of course, storing to and loading from accessor variable should be protected somehow from concurrent accesses (e.g., with mutexes).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement