drechsler drechsler - 11 days ago 5x
Linux Question

Why doesn't configfs support mmap?

I'm developing a linux kernel module for an embedded system.

The system contains programmable logic (PL), which needs to be accessed from userspace processes.

  • The PL can change at runtime.

  • My module allows processes to access specified hw registers and pages.

    These mappings are configured (at runtime) in the configfs binding of my module.

  • Every mapping gets an entry in configfs over which its accessible.

I would like to allow processes to mmap whole pages, so they're able to communicate directly with the PL.

But configfs doesn't support mmap.

  • Is there a reason why?

  • Sysfs supports mmap, so I see no problem why configfs shouldn't.

A solution would be to mirror my configfs tree into sysfs,

but this defeats the whole reason to use configfs... Any ideas?


configfs is not a replacement for sysfs. In fact, it can be viewed as an opposite to sysfs.

sysfs provides a view of kernel's objects though the filesystem interface. It can be used to change things in or cause some actions on those objects, but it was not meant for that. The major point here is that each object that is represented in sysfs is created and destroyed in kernel. The kernel controls the lifecycle of the sysfs representation, and sysfs is just a window on all this.

configfs, on the other hand, provides a way to create or change kernel objects through the filesystem interface. That's a fundamental difference. A user-space process can create directories within configfs. That action will cause a callback execution within the kernel and the creation of the corresponding kernel object. The files in the directory would represent states of various object's components.

I suspect that due to the nature of data exchange between the kernel and a user space process in these two cases it was deemed unnecessary to have mmap support in configfs.

Without seeing the design/architecture of your system it's difficult to say something definitive in your case. From your description is appears that sysfs may be what you need to satisfy the desired goals. All objects that you need access to are created, modified, and destroyed from the kernel. Limited settings/changes to existing kernel structures/objects in your module can be done through sysfs interface. Then again, it may well be that you would want to have both sysfs and configfs interfaces in your module, each for its specific purpose. There's nothing bad in that if it makes things cleaner and clearer.