gpt4 book ai didi

linux - 如何取消映射和释放 highmem 页面

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:35:35 24 4
gpt4 key购买 nike

我在模块的 init 方法中分配并映射了 highmem 页面:

highmem_page = alloc_pages( GFP_HIGHUSER, 3 );
if ( ! highmem_page ) printk(KERN_ERR "Couldn't allocate highmem page with order : 3\n" );
else {
highmem_page_address = kmap( highmem_page );
if ( ! highmem_page_address ) printk( KERN_ERR "Couldn't map highmem pages.\n");
else {
printk( KERN_ERR "Address for highuser pages is : %lx. Order: %d.\n",
highmem_page_address,
3
);
}
}

哪个运行良好并在日志中生成了输出。通过 dmesg:

[ 4065.975025] Address for highuser pages is : ffff88002c5d0000. Order: 3.

现在,在退出时,我正在做这样的事情:

kunmap(highmem_page); //will unmap only ? can it free too? highly doubtful!
__free_pages( highmem_page, 3 ); //will free the pages?

我认为 kunmap() 应该从内核的虚拟地址空间取消映射 highmem 页面。 我的理解正确吗?然后 __free_pages() 应该释放分配的页面。

然而,当我尝试这个 dmesg 时,显示了一些我无法理解的东西:

[ 4109.529834] BUG: unable to handle kernel paging request at ffffeb880002c5dc
[ 4109.529845] IP: [<ffffffff8111e999>] __free_pages+0x9/0x40
[ 4109.529856] PGD 0
[ 4109.529861] Oops: 0000 [#1] SMP
[ 4109.529866] CPU 0
[ 4109.529869] Modules linked in: prob4(O-)
...
[ 4109.529943]
[ 4109.529948] Pid: 5060, comm: rmmod Tainted: G O 3.2.6 #4 TOSHIBA T20 /T20
[ 4109.529956] RIP: 0010:[<ffffffff8111e999>] [<ffffffff8111e999>] __free_pages+0x9/0x40
[ 4109.529963] RSP: 0018:ffff88002c5b5e78 EFLAGS: 00010216
[ 4109.529967] RAX: 000001880002c5c0 RBX: ffffea0000b17400 RCX: 0000000000000024
[ 4109.529970] RDX: 0000000000000000 RSI: 0000000000000006 RDI: ffffeb880002c5c0
[ 4109.529974] RBP: ffff88002c5b5e78 R08: 0000000000000000 R09: 0000000000000005
[ 4109.529978] R10: ffffea0000b18018 R11: 0000000000000000 R12: ffffffffa024f2f8
[ 4109.529981] R13: ffff88002c5b5f18 R14: 00007fffe3342480 R15: 0000000000000001
[ 4109.529986] FS: 00007f927f6d4700(0000) GS:ffff88005f400000(0000) knlGS:0000000000000000
[ 4109.529990] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[ 4109.529993] CR2: ffffeb880002c5dc CR3: 000000002c537000 CR4: 00000000000006f0
[ 4109.529997] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 4109.530000] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[ 4109.530005] Process rmmod (pid: 5060, threadinfo ffff88002c5b4000, task ffff88005b0416e0)
[ 4109.530008] Stack:
[ 4109.530010] ffff88002c5b5ea8 ffffffff8111ea14 ffff88002c5b5e98 ffffffff00000006
[ 4109.530017] ffff88002c5b5ec8 0000000000000007 ffff88002c5b5ec8 ffffffffa024d049
[ 4109.530024] 0000000000000880 ffffffffa024f000 ffff88002c5b5f78 ffffffff810a4cde
[ 4109.530031] Call Trace:
[ 4109.530037] [<ffffffff8111ea14>] free_pages+0x44/0x50
[ 4109.530043] [<ffffffffa024d049>] my_pager_exit+0x49/0x1000 [prob4]
[ 4109.530051] [<ffffffff810a4cde>] sys_delete_module+0x19e/0x270
[ 4109.530059] [<ffffffff81645102>] system_call_fastpath+0x16/0x1b
[ 4109.530062] Code: 04 25 d8 05 01 00 8b 4d b8 48 8b 55 c0 e9 fe fe ff ff 31 d2 48 89 de e8 06 c6 ff ff e9 6d ff ff ff 90 55 48 89 e5 66 66 66 66 90 <8b> 47 1c f0 ff 4f 1c 0f 94 c0 84 c0 74 09 85 f6 74 0d e8 60 d8
[ 4109.530120] RIP [<ffffffff8111e999>] __free_pages+0x9/0x40
[ 4109.530125] RSP <ffff88002c5b5e78>
[ 4109.530127] CR2: ffffeb880002c5dc
[ 4109.530132] ---[ end trace 2dcb27dca5b2d882 ]---

现在,我该怎么办?

R# rmmod prob4
ERROR: Removing 'prob4': Device or resource busy

那么,如何从 HIGHMEM 取消映射并释放已分配的页面?

最佳答案

kmap 仅映射其结构被传递的页面。但是,程序仍应正确释放页面,因为 _free_pages() 会释放通过 alloc_pages() 分配的所有页面。尝试编写一个基本功能模块以仅分配一页(顺序 1)然后释放它。如果可行,那么在您的模块中的某处,代码正在尝试访问未映射的页面。

关于linux - 如何取消映射和释放 highmem 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19742630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com