fishinabarrel / linux-kernel-module-rust

Framework for writing Linux kernel modules in safe Rust
GNU General Public License v2.0
1.33k stars 120 forks source link

Implement support for custom printk formats #269

Open geofft opened 4 years ago

geofft commented 4 years ago

A couple folks asked about this at Plumbers. printk supports format specifiers for various kernel types: https://www.kernel.org/doc/Documentation/printk-formats.txt

For instance, %pd will print the path of a struct dentry (by walking its parents), and %pD will print the path of a struct file.

It'd be nice to support those in Rust, probably through impl Display. We should reuse the existing code to format it, somehow.

There's also some unique behavior around printing pointers: %p hashes the pointer before printing it (so equal pointers display equal, but they don't leak kernel memory layout), and %pK will possibly print zero depending on kptr_restrict. You need %px to deliberately print a pointer. I'm not sure how to match that behavior. (I don't think we have any use cases for printing pointers yet, at all....)