kernel-module

How to debug Linux kernel modules with QEMU?

笑着哭i 提交于 2019-11-27 14:55:02
I am working on academic project that modifies some Kernel Networking code as well as include a new Kernel module . I am using QEMU to load modified kernel and test. However, i find that a complete OS is required in some .img to debug. Is it possible without it ? Or, which is the distro that can be used with Kernel 2.6 for system. The distro need not have any features, except ability to run programs, including networking support. The easiest way in my opinion is to use buildroot http://buildroot.uclibc.org/ clone it, configure it to use your custom kernel (default userspace is fine for a start

How remap_pfn_range remaps kernel memory to user space?

穿精又带淫゛_ 提交于 2019-11-27 14:44:07
问题 remap_pfn_range function (used in mmap call in driver) can be used to map kernel memory to user space. How is it done? Can anyone explain precise steps? Kernel Mode is a privileged mode (PM) while user space is non privileged (NPM). In PM CPU can access all memory while in NPM some memory is restricted - cannot be accessed by CPU. When remap_pfn_range is called, how is that range of memory which was restricted only to PM is now accessible to user space? Looking at remap_pfn_range code there

How to get current hour (time of day) in linux kernel space

a 夏天 提交于 2019-11-27 12:56:35
问题 I'm writing a kernel module that checks to see if the time is between two specified hours, and disables input if it is. This has to do with me wanting to make sure I go to bed early. (I know I could also use any number of different techniques including cron etc, but I wanted to learn kernel programming...) As a first version, I therefore check if the current hour is between start and end, which are set via parameters to the module. My question is therefore : How do I get the current hour? I

Linux Kernel Modules: When to use try_module_get / module_put

核能气质少年 提交于 2019-11-27 12:20:48
问题 I was reading the LKMPG ( See Section 4.1.4. Unregistering A Device ) and it wasn't clear to me when to use the try_module_get / module_put functions. Some of the LKMPG examples use them, some don't. To add to the confusion, try_module_get appears 282 times in 193 files in the 2.6.24 source, yet in Linux Device Drivers ( LDD3 ) and Essential Linux Device Drivers, they appears in not even a single code example. I thought maybe they were tied to the old register_chrdev interface ( superseded in

Is there a way to figure out what is using a Linux kernel module?

こ雲淡風輕ζ 提交于 2019-11-27 09:13:30
问题 If I load a kernel module and list the loaded modules with lsmod , I can get the "use count" of the module (number of other modules with a reference to the module). Is there a way to figure out what is using a module, though? The issue is that a module I am developing insists its use count is 1 and thus I cannot use rmmod to unload it, but its "by" column is empty. This means that every time I want to re-compile and re-load the module, I have to reboot the machine (or, at least, I can't

netfilter-like kernel module to get source and destination address

旧巷老猫 提交于 2019-11-27 08:28:49
问题 I read this guide to write a kernel module to do simple network filtering. First, I have no idea of what below text this means, and what's the difference between inbound and outbound data packet(by transportation layer)? When a packet goes in from wire, it travels from physical layer, data link layer, network layer upwards, therefore it might not go through the functions defined in netfilter for skb_transport_header to work. Second, I hate magic numbers, and I want to replace the 20 (the

File I/O in a Linux kernel module

删除回忆录丶 提交于 2019-11-27 07:38:52
I'm writing a Linux kernel module that needs to open and read files. What's the best way to accomplish that? Can I ask why are you trying to open a file? I like to follow Linux development (out of curiosity, I'm not a kernel developer, I do Java), and I've seen discussion of this question before. I was able to find a LKML message about this, basically mentioning it's usually a bad idea. I'm almost positive that LWN covered it in the last year, but I'm having trouble finding the article. If this is a private module (like for some custom hardware and the module won't be distributed) then you can

why my kernel log is not showing the latest output?

早过忘川 提交于 2019-11-27 07:33:20
问题 I'm coding a simple kernel module, in linux ubuntu 17.04, that takes a string and prints it in the kernel log. #include<linux/module.h> #include<linux/init.h> #include<linux/moduleparam.h> char* mystring = "hello world"; module_param(mystring ,charp ,S_IRUSR | S_IWUSR); void display(void){ printk(KERN_ALERT "%s" ,mystring); } static int hello(void){ //printk(KERN_ALERT "hello module"); display(); return 0; } static void bye(void){ printk(KERN_ALERT "bye"); } module_init(hello); module_exit

kvm: module verification failed: signature and/or required key missing - tainting kernel

懵懂的女人 提交于 2019-11-27 06:35:04
问题 I'm using Ubuntu 14.04 LTS and kernel version 3.13.11.4 . I'm trying to load patched KVM modules kvm and kvm-intel and I'm getting the following errors kvm: module verification failed: signature and/or required key missing - tainting kernel and kvm: module has bad taint, not creating trace events . The source used is the same source that created the image that I am currently running. I've check the symbols and made sure to the error isn't cause by not including EXPORT_SYMBOL_GPL() in the

Driver code in kernel module doesn't execute?

核能气质少年 提交于 2019-11-27 06:16:14
问题 Why this kernel module doesn't do anything when i load it? #include <linux/init.h> #include <linux/module.h> #include <linux/platform_device.h> #define DEVICE_NAME "hello-1.00.a" #define DRIVER_NAME "hello" MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(struct platform_device *pdev){ printk(KERN_ALERT "Hello, world\n"); return 0; } static int hello_exit(struct platform_device *pdev){ printk(KERN_ALERT "Goodbye, cruel world\n"); return 0; } static const struct of_device_id myled_of