2016-11-16 181 views
0

我試圖創建一個將禁用數據緩存的Linux內核模塊。我正在嘗試使用arch/arm/include/asm/cacheflush.h中的v7_exit_coherency_flush(all)函數,並且此函數調用了我在arch/arm/mm/arch-v7.S中找到的v7_flush_dcache_all。模塊中的未知符號/ v7_flush_dcache_all在Linux內核模塊中未定義

我的問題是,當我試圖讓自己的模塊,我得到一個警告

WARNING: "v7_flush_dcache_all [/home/pi/Documents/ARMHammer/kern/my_kernel/cache_disable.ko] undefined! 

,當我嘗試插入模塊我得到一個錯誤

insmod: ERROR: could not insert module cache_disable.ko: Unknown symbol in module 

所以它看起來像ach-v7.S文件沒有被讀取。我試圖簡單地將它包含在我的主文件中,但是這產生了很多錯誤,可能是因爲它是一個彙編文件。

我幾乎堅持在這一點上,有沒有辦法將彙編文件包含在Makefile中,或者我沒有包含所有必需的.h文件?

爲了什麼它的價值,這是我的主文件

#include <linux/kernel.h> 
#include <linux/module.h> 
#include <linux/init.h> 
#include <linux/sched.h> /* For current */ 
#include <linux/tty.h>  /* For the tty declarations */ 
#include <linux/version.h> /* For LINUX_VERSION_CODE */ 
#include <linux/mm.h> 

#include <asm/cp15.h> 
#include <asm/cacheflush.h> 
#include <asm/glue-cache.h> 
#include <asm/shmparam.h> 
#include <asm/cachetype.h> 
#include <asm/outercache.h> 

// #include "my_cache-v7.h" 


MODULE_LICENSE("GPL"); 
MODULE_AUTHOR("Peter Jay Salzman"); 


static void print_string(char *str) 
{ 
    struct tty_struct *my_tty; 
    #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,5)) 
     my_tty = current->tty; 
    #else 
     my_tty = current->signal->tty; 
    #endif 

     if (my_tty != NULL) { 
      ((my_tty->ops)->write) (my_tty, /* The tty itself */ 
    #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9))  
          0, /* Don't take the string 
           from user space  */ 
    #endif 
          str, /* String     */ 
          strlen(str)); /* Length */ 
    #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9))  
      ((my_tty->ops)->write) (my_tty, 0, "\015\012", 2); 
    #else 
      ((my_tty->ops)->write) (my_tty, "\015\012", 2); 
    #endif 
    } 
} 

static int __init print_string_init(void) 
{ 
    v7_exit_coherency_flush(all); 

    print_string("The module has been inserted. Hello world!"); 
    return 0; 
} 

static void __exit print_string_exit(void) 
{ 
    print_string("The module has been removed. Farewell world!"); 
} 

module_init(print_string_init); 
module_exit(print_string_exit); 

和我的Makefile

obj-m += cache_disable.o 
KDIR = /home/pi/linux/ 
all: 
    make -C $(KDIR) M=$(PWD) modules 

clean: 
    make -C $(KDIR) M=$(PWD) clean 

而且,如果有人知道更簡單的方法來禁用緩存,我所有的耳朵!

+0

看起來像'v7_exit_coherency_flush'宏不適合被模塊調用。只有編譯進它的內核和驅動程序可以使用該宏。請注意,可以從模塊函數調用需要導出('EXPORT_SYMBOL')。至於包含,'.S'文件不打算包含在內。相反,您可以複製它並與您的模塊一起編譯。 – Tsyvarev

+0

這是一個內部函數,通常只能通過[proc]調用(https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/arm/mm/proc- v7.S?id = refs/tags/v4.9-rc5#n542)機制。特定的ARM版本將綁定到特定的ARM CPU類型。 Linux驅動程序/模塊是爲了在所有硬件上運行。 –

回答

1

v7_exit_coherency_flush()用於電源管理代碼,將CPU從內核中徹底清除以關閉電源 - 由於非常好的原因,無法從隨機模塊調用CPU。如果你真的想丟失數據並以奇怪的方式使機器崩潰,那麼你可能完全繞過內核函數,並使用一個簡單的內聯asm直接命中SCTLR *

我不敢想象你想達到什麼目的,但是如果你真的想在緩存關閉的情況下運行Linux(痛苦緩慢),你需要重建內核,關閉CONFIG_SMP以打開CONFIG_CPU_DCACHE_DISABLE。這是唯一可能有效的方法。

*我甚至不會解釋,這是一個可怕的想法。