shared memory via /dev/shm?
Apologies if this has been asked before: Yes, I’ve read all the disclaimers against accessing files in the kernel, but I want to set up a shared memory segment between a kernel module and one or more user processes, and /dev/shm seems like a good way to do that. Given that, what’s the preferred way to access files within the kernel (specifically within a kernel module)? At the moment, I’m using filp_open() on module load to open the file (which seems to work), then: filp_close() to close the file * kern_path() to get the entry for the /dev/shm file vfs_unlink() to delete the /dev/shm file dput() to free the dentry path_put() to free the path …on module unload, and it hangs. Any suggestions what I’m doing wrong? Thanks, Nick
On Thu, 30 Jul 2015 16:03:51 -0700, Nicholas Murphy said:
Yes, I’ve read all the disclaimers against accessing files in the kernel, but I want to set up a shared memory segment between a kernel module and one or more user processes, and /dev/shm seems like a good way to do that.
Is there a specific reason you aren't letting the userspace program create an mmap() area and then write the identifying information to a /sys attribute file (or other means of notifying the kernel of what to use)?
Hmm…I suppose not. I’d would still be curious what the right way to do this is, though? I think I can get away with that trick, but I can also imagine scenarios where I’d want the kernel module itself to create the file. Thanks, Nick
On Jul 30, 2015, at 5:00 PM, Valdis.Kletnieks@vt.edu wrote:
On Thu, 30 Jul 2015 16:03:51 -0700, Nicholas Murphy said:
Yes, I’ve read all the disclaimers against accessing files in the kernel, but I want to set up a shared memory segment between a kernel module and one or more user processes, and /dev/shm seems like a good way to do that.
Is there a specific reason you aren't letting the userspace program create an mmap() area and then write the identifying information to a /sys attribute file (or other means of notifying the kernel of what to use)?
On Fri, 31 Jul 2015 16:16:14 -0700, Nicholas Murphy said:
Hmm…I suppose not. I’d would still be curious what the right way to do this is, though? I think I can get away with that trick, but I can also imagine scenarios where I’d want the kernel module itself to create the file.
In general, the right answer is to do the file handling in userspace. Among other things, that makes it possible to avoid hard-coding a filename in kernel code (remember - we try to make the kernel be about mechanism, not policy). Among other things, it avoids the effort of opening a file that userspace never actually does anything with - if you wait for userspace to open it and notify the kernel, you can be pretty sure that it's about to be used.
participants (2)
-
Nicholas Murphy -
Valdis.Kletnieks@vt.edu