/* TODO not working. Tested with both: /virt_to_phys.sh and on QEMU monitor: xp 0x - https://stackoverflow.com/questions/5748492/is-there-any-api-for-determining-the-physical-address-from-virtual-address-in-li - https://stackoverflow.com/questions/43325205/can-we-use-virt-to-phys-for-user-space-memory-in-kernel-module */ #include /* virt_to_phys */ #include #include /* usleep_range */ #include #include #include #include /* single_open, single_release */ static volatile u32 i = 0x12345678; static struct dentry *debugfs_file; static int show(struct seq_file *m, void *v) { seq_printf(m, "i 0x%llx\n" "&i %p\n" "virt_to_phys 0x%llx\n", (unsigned long long)i, &i, (unsigned long long)virt_to_phys(&i) ); return 0; } static int open(struct inode *inode, struct file *file) { return single_open(file, show, NULL); } static const struct file_operations fops = { .llseek = seq_lseek, .open = open, .owner = THIS_MODULE, .read = seq_read, .release = single_release, }; static int myinit(void) { debugfs_file = debugfs_create_file( "lkmc_virt_to_phys", S_IRUSR, NULL, NULL, &fops); return 0; } static void myexit(void) { debugfs_remove(debugfs_file); } module_init(myinit) module_exit(myexit) MODULE_LICENSE("GPL");