![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
linux内核
search_star
个人博客seekstar.github.io
展开
-
使得两次编译linux内核产生一样的结果
export INSTALL_MOD_STRIP=-sexport KBUILD_BUILD_TIMESTAMP=0export KBUILD_BUILD_USER=rootexport KBUILD_BUILD_HOST=localhostmake mrpropermake allnoconfigmake -j4其中make allnoconfig表示除必须的选项外, 其它选项一律不选。然后就可以发现vmlinux和arch/x86/boot/bzImage都是确定性的。需要注意的是其他原创 2021-08-01 16:30:27 · 280 阅读 · 0 评论 -
Unknown symbol crc32c
是因为提供crc32c这个符号的内核模块没有被load。在内核模块的目录下搜一下(我的是```/ilb/modulescd /lib/modules/$(uname -r)find . -iname "*crc32c*"./kernel/lib/libcrc32c.ko这就是我们要load的模块了。sudo modprobe libcrc32c然后就好了。参考文献:https://dev.archive.openwrt.org/ticket/14452...原创 2021-07-19 21:26:23 · 554 阅读 · 0 评论 -
Linux内核获取当前CPU id
CPU id是percpu变量,调用smp_processor_id()可以取出。内核里对它的注释如下:smp_processor_id() is safe if it's used in a preemption-off critical section, or in a thread that is bound to the current CPU.所以除非是在绑定在CPU上的线程中使用,否则必须要先关抢占。内核已经封装了带关抢占的API:#define get_cpu() ({ preemp原创 2021-07-19 00:48:31 · 4421 阅读 · 0 评论 -
编译安装linux内核时Possible missing firmware
我这里是忘了一开始先跑make menuconfig,而直接make了。所以先make clean把错误的编译历史删掉,然后make menuconfig安装缺少的插件,再按照https://blog.csdn.net/qq_41961459/article/details/111859925的方法重新开始编译。...原创 2021-07-18 18:34:09 · 319 阅读 · 0 评论 -
cannot stat ‘./modules.builtin‘: No such file or directory
make modules_install时报错:cp: cannot stat './modules.builtin': No such file or directory太长不看版make menuconfig找到缺少的依赖,安装后重新makemake menuconfigmakemake modules_installmake install心路历程版是因为make modules.builtin时出问题了,导致这个文件没有被编译出来。再跑一遍make modules.built原创 2021-07-18 16:51:57 · 6132 阅读 · 6 评论 -
Linux kernel kthread用法
先说巨坑:如果kthread_run之后立马kthread_stop,threadfn可能不会被执行,kthread_stop返回-EINTR。这一点网上的教程很少有提及。参考:https://stackoverflow.com/questions/65987208/kthread-stopped-without-running创建线程可以用kthread_create和kthread_run。/** * kthread_create - create a kthread on the curre原创 2021-02-02 17:23:09 · 999 阅读 · 0 评论 -
linux kernel xarray xchg
内核里的xarray里有xa_cmpxchg,但是我想要无条件交换的xa_xchg,找了一个多小时没找到,结果发现xa_store会返回旧值,相当于无条件交换。还是太嫩了。原创 2021-02-02 00:53:56 · 347 阅读 · 0 评论 -
qemu+gdb调试内核模块
制作qemu虚拟机看这里:https://blog.csdn.net/qq_41961459/article/details/112798115如果是PC的话,就不用配置vnc了。虚拟机配置完毕后要把-enable-kvm去掉再重启,不然软件断点不起作用。此外,加上-s以启动gdbserver。sudo qemu-system-x86_64 -m 4096 centos.img -net nic -net tap,ifname=tap0,script=no,downscript=no -s关掉了原创 2021-01-24 00:12:35 · 1090 阅读 · 1 评论 -
qemu gdb不停在断点
首先要保证是在target remote :1234之后设置的断点。然后最好不要使用-enable-kvm,否则硬件貌似是不会给你停下的。参考文献:https://cloud.tencent.com/developer/article/1613356https://stackoverflow.com/questions/18931727/remote-gdb-debugging-does-not-stop-at-breakpoints...原创 2021-01-22 21:59:13 · 1260 阅读 · 6 评论 -
qemu gdb lx-symbols Python Exception <class ‘gdb.MemoryError‘> Cannot access memory at address 0xfff
在/etc/default/grub里的GRUB_CMDLINE_LINUX里加上nokaslr,然后更新一下grub.cfg:centos上用sudo grub2-mkconfig -o /boot/grub2/grub.cfgdebian系好像是sudo update-grub然后重启一下就好了。原创 2021-01-22 13:58:30 · 1288 阅读 · 0 评论 -
编译安装linux内核
下载内核https://www.kernel.org/一般下载tarball,也就是.tar.xz格式的源码包。如果/够大,可以直接解压到/usr/src,也可以解压到机械盘上。配置make menuconfig如果没有特殊需求,可以直接按右键头选中Exit然后按enter,选保存即可。make多线程编译make -j$(cat /proc/cpuinfo| grep "processor"| wc -l)安装内核模块如果没有特殊需求,一般可以把内核模块的debug信息给去掉,节约原创 2020-12-28 13:58:21 · 411 阅读 · 0 评论 -
systemtap跟踪进程生命周期
systemtap man: https://sourceware.org/systemtap/man/本来追踪进程生命周期可以用syscall.fork和syscall.exit之类的。但是有时候它们会失效(或者部分失效)。所以更好的方式是用kprocess系列,文档:https://sourceware.org/systemtap/man/tapset::kprocess.3stap.htmlkprocess.start的上下文(好像)其实是父进程。貌似跟文档不一致。kprocess.exec的原创 2020-12-27 19:16:05 · 224 阅读 · 0 评论 -
systemtap原理
systemtap的核心是probe(探针),可以在任何一条语句上加上探针,当执行到这条语句时将控制流转移到探针的handler上。其实现原理是在module_init时将相应指令的第一个字节替换成0xcc,也就是INT 3。这样执行到这条指令时就会跳转到INT 3的中断处理函数,由其判断出应该跳转到哪个handler。在module_exit中将这些指令还原。...原创 2020-12-26 22:52:47 · 333 阅读 · 0 评论 -
kbuf_get和kbuf_put只能处理一字节!
惊天巨坑!!!文档里信誓旦旦的说是element,结果合着就是byte呗。我看这东西是宏定义,以为会自动用sizeof(typeof(val))把字节数求出来,结果这个信息就这样被漏掉了。。。要压入或者弹出多字节的元素,那只能用kbuf_in和kbuf_out了。...原创 2020-12-01 15:50:37 · 172 阅读 · 0 评论 -
linux kernel spinlock ticket汇编实现解读
spinlock的TAS、TTAS、ticket实现详见https://blog.csdn.net/david_henry/article/details/5405093/queued spinlock详见https://blog.csdn.net/y33988979/article/details/102676849下面详细介绍一下ticket的汇编实现。内嵌汇编基础知识:https://blog.csdn.net/qq_41961459/article/details/104518801tick原创 2020-12-01 13:30:19 · 318 阅读 · 0 评论 -
Bad or missing usercopy whitelist? Kernel memory overwrite attempt detected to SLUB object
Linux内核有一个usercopy whitelist机制,只允许这里面的region来做usercopy。如果是用kmem_cache_create申请的kmem_cache申请的内存空间来copy to user或者copy from user,那么就会报这个错。这时要用kmem_cache_create_usercopy,来将申请的区域加入到usercopy whitelist中。/** * kmem_cache_create_usercopy - Create a cache with a r原创 2020-11-11 14:59:45 · 1325 阅读 · 0 评论 -
解决编译安装内核时/lib/modules过大的问题
原因是编译出来的ko文件里有一些debug信息。安装module的时候加一个strip选项,把这些额外信息去掉就好了。sudo make INSTALL_MOD_STRIP=1 modules_install参考文献:https://unix.stackexchange.com/questions/288438/why-is-lib-modules-so-huge-under-my-gentoo-compared-to-ubuntu...原创 2020-10-29 22:11:52 · 1385 阅读 · 0 评论 -
Linux内核panic后查看dmesg
由于panic后内核不能再将dmesg写入到存储介质中去,所以重启之后dmesg就丢失了。但是kdump可以在内核panic后启用一个小内核来将dmesg和一些内存信息写进存储介质。安装kdumpsudo apt install -y kdump-tools根据这篇文章,默认给crash kernel分配的内存太少了,所以修改/etc/defatul/grub.d/kdump-tools.cfg:crashkernel=512M-:768M,然后grub-mkconfig -o /boot/grub原创 2020-10-17 00:39:43 · 2982 阅读 · 0 评论 -
Linux内核崩溃重启后查看上次的dmesg
参考:https://stackoverflow.com/questions/9682306/android-how-to-get-kernel-logs-after-kernel-panic在centos 8上在/sys/fs/pstore/时间戳最大的就是最近的。原创 2020-09-25 19:14:44 · 6727 阅读 · 0 评论 -
Linux内核看CONFIG宏是否定义
vim /usr/src/linux-headers-$(uname -r)/.config原创 2020-08-24 10:39:20 · 683 阅读 · 0 评论 -
linux kernel get_user include
#include <linux/uaccess.h>vscode居然没有提示原创 2020-08-11 20:24:23 · 168 阅读 · 0 评论 -
linux kernel查看某一版本的代码
参考:https://stackoverflow.com/questions/28136815/linux-kernel-how-to-obtain-a-particular-version-right-upto-sublevelgit tag -l挑一个想要的版本rc表示Release Candidate。(https://www.zhihu.com/question/282995470)这里选择v5.3就好了...原创 2020-08-11 16:11:01 · 298 阅读 · 0 评论 -
C语言内嵌汇编学习笔记
gnu gcc中关于Extended Asm的文档:https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.htmlBasic Asm文档:https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm这里只谈Extended Asm。Extended Asm的基本语法:asm asm-qu...原创 2020-02-27 14:29:22 · 598 阅读 · 0 评论 -
linux内核magic number
参考:https://www.kernel.org/doc/html/v4.17/process/magic-number.htmlhttps://en.wikipedia.org/wiki/Magic_number_(programming)结构体中的magic域可以在运行时判断结构体是否被“偷梁换柱”。如果在运行过程中发现某一结构体的magic域的值不等于这个结构体对应的magic nu...原创 2020-02-24 19:04:48 · 940 阅读 · 0 评论 -
linux内核hash
linux内核API文档:https://www.kernel.org/doc/htmldocs/kernel-api/index.htmllinux内核官方文档中有一个例子:https://www.kernel.org/doc/html/latest/crypto/api-samples.htmlstruct sdesc { struct shash_desc shash; ...原创 2020-02-23 23:08:02 · 1199 阅读 · 0 评论