免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2170 | 回复: 1
打印 上一主题 下一主题

[内存管理] 匿名页申请pte_mkspecial疑问? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-22 17:45 |只看该作者 |倒序浏览
进程匿名空间未分配页帧时,对匿名空间读操作会引发缺页异常,对应缺页异常处理函数为:
  1. static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
  2.                 unsigned long address, pte_t *page_table, pmd_t *pmd,
  3.                 unsigned int flags)
  4. {
  5.         struct page *page;
  6.         spinlock_t *ptl;
  7.         pte_t entry;

  8.         pte_unmap(page_table);

  9.         /* Check if we need to add a guard page to the stack */
  10.         if (check_stack_guard_page(vma, address) < 0)
  11.                 return VM_FAULT_SIGBUS;

  12.         /* Use the zero-page for reads */
  13.         if (!(flags & FAULT_FLAG_WRITE)) {
  14.                 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
  15.                                                 vma->vm_page_prot));
  16.                 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
  17.                 if (!pte_none(*page_table))
  18.                         goto unlock;
  19.                 goto setpte;
  20.         }
复制代码
正常情况应该是设置页表项为只读的,对匿名区间进行写操作时引发缺页异常;此时会作COW操作,申请一个页帧,并将页帧清0。
ULK中看到的代码会作页表项写保护:
entry = pte_wrprotect(mk_pte(virt_to_page(empty_zero_page),
                                 vma->vm_page_prot));

但是2.6.32.60代码是用pte_mkspecial:
pte_mkspecial只是把pte的第9位置1,而页表项第9位是ignore的。
Table 4-6. Format of a 32-Bit Page-Table Entry that Maps a 4-KByte Page
11:9 Ignored

但此处页表项权限是vma的权限,而没有写保护,此处怎样引发缺页异常进而作COW操作呢?

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
2 [报告]
发表于 2013-06-06 17:45 |只看该作者
回复 1# Morphad

可以看一下my_zero_pfn(address)的实现:

zero_pfn

static int __init init_zero_pfn(void)
{
    zero_pfn = page_to_pfn(ZERO_PAGE(0));
    return 0;
}

也就是pfn 0,而x86上的pfn 0主要用于存放实模式的中断向量表和BIOS的data,是不会被分配的,根本不在memblock/buddy system的管理中。访问这样一个page应该产生page fault。

至于special:

“Special” mappings do not wish to be associated with a "struct page" (either it doesn't exist, or it exists but they don't want to touch it).


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP