调用 get_user_pages_fast 后内核恐慌

如何解决调用 get_user_pages_fast 后内核恐慌

get_user_pages_fast 函数导致内核崩溃。

我必须使用 get_user_pages_fast 而不是 pin_user_pages,因为我需要支持最低内核 2.6。

主要目标是从内核内存中获取一个页面。

我在这里遗漏了什么?

内核恐慌:

 [15307.994946] BUG: kernel NULL pointer dereference,address: 0000000000000000
 [15307.996126] #PF: supervisor write access in kernel mode
 [15307.996970] #PF: error_code(0x0002) - not-present page
 [15307.997800] PGD 80000001158dc067 P4D 80000001158dc067 PUD 1214b5067 PMD 0 
 [15307.998891] Oops: 0002 [#1] SMP PTI
 [15307.999479] CPU: 10 PID: 10586 Comm: flint_ext Tainted: G           O      5.12.0-rc1_for_upstream_min_debug_2021_03_01_12_16 #1
 [15308.001271] Hardware name: QEMU Standard PC (Q35 + ICH9,2009),BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
 [15308.003007] RIP: 0010:internal_get_user_pages_fast+0x66c/0xad0
 [15308.003939] Code: 01 02 00 00 48 8b 53 08 48 8d 42 ff 83 e2 01 48 0f 44 c3 f0 80 08 02 48 63 45 cc 49 83 c4 08 48 81 c1 00 10 00 00 48 8b 75 90 <48> 89 1c c6 83 45 cc 01 48 39 4d c0 0f 85 3a ff ff ff 48 8b 45 98
 [15308.006762] RSP: 0018:ffff8881994e3940 EFLAGS: 00010006
 [15308.007676] RAX: 0000000000000000 RBX: ffffea0006339140 RCX: 0000000002480000
 [15308.008880] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffea0006339140
 [15308.010090] RBP: ffff8881994e3a10 R08: 0000000000000000 R09: 0000000000000001
 [15308.011302] R10: 0000000000000001 R11: ffff88810b19c5e0 R12: ffff888117cba400
 [15308.012588] R13: 000000ffffffffff R14: ffffea0000000000 R15: 800000018ce45067
 [15308.013902] FS:  00007f4cd063e740(0000) GS:ffff88856b900000(0000) knlGS:0000000000000000
 [15308.015387] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 [15308.016445] CR2: 0000000000000000 CR3: 000000014b58c005 CR4: 0000000000370ea0
 [15308.017766] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 [15308.019067] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
 [15308.020327] Call Trace:
 [15308.020857]  ioctl.isra.0.cold+0x3d/0x9a [mst_pciconf]
 [15308.021821]  ? __lock_acquire+0x56c/0x2530
 [15308.022622]  ? find_held_lock+0x2b/0x80
 [15308.023381]  ? filemap_map_pages+0x163/0x690
 [15308.024199]  ? __lock_acquire+0x56c/0x2530
 [15308.024987]  ? find_held_lock+0x2b/0x80
 [15308.025736]  ? do_sigaction+0x11e/0x270
 [15308.026481]  ? lockdep_hardirqs_on_prepare+0xd4/0x180
 [15308.027428]  ? _raw_spin_unlock_irq+0x24/0x30
 [15308.028263]  new_ioctl+0x24/0x30 [mst_pciconf]
 [15308.029107]  __x64_sys_ioctl+0x3d8/0x790
 [15308.029864]  ? __x64_sys_rt_sigaction+0x7a/0x100
 [15308.030735]  ? lockdep_hardirqs_on_prepare+0xd4/0x180
 [15308.031683]  do_syscall_64+0x2d/0x40
 [15308.032390]  entry_SYSCALL_64_after_hwframe+0x44/0xae

用户空间代码:

int allocate_kernel_memory_page(char* pin_pages,struct mtcr_page_info* page_info,int page_amount)
{
    int return_value = 0;
    int page_size = getpagesize();
    char addrstr[80];


    if(!mf || !page_info)
    {
        return_value = -1;
    }

    // Allocate the page address array.
    page_info->page_address_array =
        calloc(page_amount,sizeof(struct mtcr_page_address));
    
    // Set the requested page size.
    page_info->page_size = page_amount * page_size;

    // Allocate user buffer.
    pin_pages = memalign(page_size,page_info->page_size);

    // Save the start buffer pointer as an integer.
    sprintf(addrstr,"%p",pin_pages);
    page_info->page_pointer_start = strtoul(addrstr,NULL,0);

    // Pin the memory in the kernel space.
    return_value = ioctl(mf->fd,PCICONF_PAGE_ALLOCATION,page_info);
}

内核空间(来自 switch case 的情况):

case PAGE_ALLOCATION:
    {
        struct page_info_st page_info;
        int write_permission = 1;
        int page_counter;
        int ret;

        // Copy the page info structure from the user space.
        if (copy_from_user(&page_info,udata,sizeof(struct page_info_st))) {
            ret = -EFAULT;
            goto fin;
        }

        ret = get_user_pages_fast(page_info.page_pointer_start,page_info.page_size,write_permission,dev->pages);
  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res