On Thu, Mar 26, 2015 at 11:36 PM, Elazar Leibovich <elaz...@gmail.com> wrote: > Hi, > > I'm writing a kernel module, and I want to expose some debug > information about it. > > The debug information is often of the form of request-response. > > For example: > > - Hey module, what's up with data at 0xffffe8ff0040c000? > - Cached, populated two hours ago. > > - Hey module, please invalidate data at 0xffffe8ff0002cb00 > - Sure thing. > > - Hey module, please record all accesses to 0xffffe8ff0006bbf0. > - OK, ask me again for stats-5 > ... > - Hey module, what's in stats-5? > - So far, 41 accesses by 22 users. > > Now, the question is, what is a good design to expose this information. > > I think that the most reasonable way to interact with userspace is > through a debugfs file.
In my view, I usually prefer using ioctl-over-character device with *strongly* defined API / structures. Looking at the examples, your API should be fairly simple: typedef struct _debug_request_ { request_t request_type; void *request_pointer; answer_t answer_type; union answer_data { int __out error_code; int __out next_answer_time; struct access_info { int __out access_count; int __out user_count; }; }; } debug_request_t; If you make sure you copy_from/to_user this structure in-and-out of user-space, you get fairly robust interface in a fairly short and easy to debug code. (E.g. compared to having to parse user-supplied text string in kernel mode or using debugfs [partial read/write, etc]). - Gilboa _______________________________________________ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il