Category: kernel
-
The packet flow, from userspace to kernel driver in Linux network stack
這是一個想要從 userspace 一直深入到 driver,理解 Linux packet 究竟如何運行的流程圖。 我在交大做的東西都在 driver space,使用 ath9k/ath10k 做實驗。我所理解的是 ath9k 上面對著 mac80211 (Linux 的 softmac),也就是說,driver 在功能上,只需要實做struct ieee80211_ops 的功能即可。主要都在處理 .wake_tx_queue 的功能。 對於他之上,頂多知道 ieee80211_queue_skb 最後會 call drv_wake_tx_queue 然後根據 driver 不同呼叫不同 driver 的實做,以 ath9k 而言就是 ath9k_wake_tx_queue。 還是想要知道一下,究竟這個 packet 是如何被傳入 mac80211 這層,順便解答一個以前問自己的問題「wireshark 抓封包時究竟是從那一層抓的」。 使用兩種工具,一個是 cflow、一個是 pycflow2dot。前者用來描述 call graph,後者拿來轉成 graphviz 的 dot 語言並且輸出 svg。兩者都有做修改,cflow 的部份請參考備註的部份,pycflow2dot 請參考我修改的版本: mlouielu/pycflow2dot。 […]
-
netlink: No buffer space available
問題在於 kernel buffer 不足。 http://lists.netfilter.org/pipermail/netfilter/2007-February/067929.html 解法: echo 500000 > /proc/sys/net/core/rmem_max
-
Intel 64 and IA32 architectures Memory Model - Segmentation and Paging
32-bit paging: CR0.PG = 1 & CR4.PAE = 0 (section 4.3) CR0.WP CR4.PSE CR4.PGE CR4.SMEP CR4.SMAP PAE paging; CR0.PG = 1 & CR4.PAE = 1 & IA32_EFER.LME = 0 (section 4.4) CR0.WP CR4.PGE CR4.SMEP CR4.SMAP IA32_EFER.NXE 4-level paging: CR0.PG = 1 & CR4.PAE = 1 & IE32_EFER.LME = 1 (section 4.5) CR0.WP CR4.PGE CR4.PCIDE CR4.SMEP […]
-
Python socket OSError: [Errno 105] No buffer space available
今天在處理 netlink 的時候,使用 Python 當作 user-space 承接來自 kernel-space 訊息的工具。我的情況是大約每 10ms 會由 kernel-space 發起一次 netlink multicast 到 user-space。當在運行 user-space script 的時候,過一陣子會出現這個錯誤: [crayon-65185282a6859917716325/] 一陣搜尋後, 其中一個方法是調整 sysctl 的參數,沒用。 修改 net.ipv4.xfrm4_gc_thresh=999999,沒用。 來自 netfilter 的說明: 來自 netfilter 說明:這代表 kernel-side 的 netlink socker buffer 沒有空間了。因此 user-space 的程式沒有辦法處理來自 kernel 的資料。 有三種解法,1) 把 buffer size 透過 /proc/sys/net/core, sysctl 加大,或是使用 SO_RCVBUF file descriptor。2) 加快處理端的處理速度。3) 如果不需要太大的 buffer,嘗試把 buffer […]
-
TIL: private data struct in Linux kernel
在 Linux kernel 當中有許多的 common struct,例如說 ieee80211_txq 這樣的結構,透過這樣的方式,可以讓不同的 driver 重用相同的 struct。但是,針對每個不同的 driver,還是會有不同的 private data,這時候就會用 private data struct 的方式來處理。 例如說,struct ieee80211_txq 是 mac80211 中的 intermediate tx queue,目前有使用的 wireless driver 為 ath9k, ath10k 以及 mt76。struct ieee80211_txq 的整個結構為: [crayon-65185282a69e1200963069/] 可以看到,除了前四個 member 外,最後還定義了一個 drv_priv,這是用來指向各個 driver 的 private data 的 member。以 ath9k 為例,這邊是指向一個 struct ath_atx_tid,ath10k 則是 struct ath10k_txq。 以 ath9k 為例,這邊是在 sta_info_alloc 的地方 allocated: […]
-
TIL: ARRAY_SIZE in Linux kernel
from net/mac80211/sta_info.c, define at include/linux/kernel.h [crayon-65185282a6bbd254547456/] __must_be_array: 檢查 a 是否為 array,當 a 為 array 時,會因為 &(a)[0] 變成 pointer,而讓 __same_type 產生 0 的結果,反之如果 a 為 pointer,因為 &(a)[0] 仍然是 pointer, __same_type 回傳 1 而導致 BUILD_BUG_ON_ZERO 產生編譯 error,從而檢查傳入的 object 是否為 array: [crayon-65185282a6bc2666619340/] BUILD_BUG_ON_ZERO: 當 BUILD_BUG_ON_ZERO 的值為 true 的時候,編譯時會發出 error (error: negative width in bit-field ‘’)。但值為 false 時會產生 value […]
-
Qualcomm ath9k 驅動程式解析 (二) - 幾個重要結構
ieee80211_local *local 用途: contains information about the real hardware, and is created when the interface is first added. (Daniel Caps Mur, Linux Wi-Fi open source drivers-mac80211,ath9k/ath5k-, pp.1) each instance of these (hw is embedded into local) represents a wireless driver, ieee80211_hw is the part of the ieee80211_local that is visible to drivers, contains all operating […]
-
Qualcomm ath9k 驅動程式解析 (一) - 初始化過程
以 linux-4.19-rc2 為例,平台為 TP-Link WDR4300。程式碼以 linux-4.19-rc2 為準,有特別標示者以 OpenWrt/LEDE 為準。 1. ath9k 驅動程式註冊點:ath9k/init.c#ath9k_init(void) [crayon-65185282a70a2946813109/] 主要有三件事情,(1) 初始化 PCI 匯流排、(2) 初始化 AHB 匯流排、(3) 初始化 quirks: [crayon-65185282a70a8210056986/] 2. 初始化 PCI 匯流排:ath9k/pci.c#ath_pci_init(void) [crayon-65185282a70aa111587006/] 這邊傳入 struct pci_driver ath_pci_driver 當參數,ath_pci_driver 定義為: [crayon-65185282a70ab963061338/] struct pci_driver 本身定義了一些 PCI driver 的 method, 同時有 struct device_driver 給 device driver-model 使用 (The struct device_driver structure, which represents one driver capable of handling certain devices […]
-
TIL: ALIGN in Linux kernel
from include/uapi/linux/kernel.h and scripts/dtc/dtc.h [crayon-65185282a7404318284868/]
-
Perf tracing wireless driver on LEDE/OpenWRT
1. Config LEDE/OpenWRT with CONFIG_PACKAGE_perf=y CONFIG_KERNEL_PERF_EVENTS=y 2. Add dynamic probe with external modules [crayon-65185282a75e4855526836/] 3. Perf Recording [crayon-65185282a75e9146682107/] 4. Perf Reporting [crayon-65185282a75eb457159390/] 5. References Linux Perf Tools Tips - oliveryang.net perf Examples - brendangreeg.com