gpt4 book ai didi

linux - 为什么不在 ARM Linux Kernel 上为 vmalloc 填写页面错误中的 PTE 条目?

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

为什么在VMALLOC_START~VMALLOC_END发生page fault时do_translation_fault不填充Page table entry而只填充PG, PUD和PMD?

arch/arm/mm/fault.c中对应源码@do_translation_fault:

414 static int __kprobes
415 do_translation_fault(unsigned long addr, unsigned int fsr,
416 struct pt_regs *regs)
417 {
418 unsigned int index;
419 pgd_t *pgd, *pgd_k;
420 pud_t *pud, *pud_k;
421 pmd_t *pmd, *pmd_k;
422
423 if (addr < TASK_SIZE)
424 return do_page_fault(addr, fsr, regs);
425
426 if (user_mode(regs))
427 goto bad_area;
428
429 index = pgd_index(addr);
430
431 /*
432 * FIXME: CP15 C1 is write only on ARMv3 architectures.
433 */
434 pgd = cpu_get_pgd() + index;
435 pgd_k = init_mm.pgd + index;
436
437 if (pgd_none(*pgd_k))
438 goto bad_area;
439 if (!pgd_present(*pgd))
440 set_pgd(pgd, *pgd_k);
441
442 pud = pud_offset(pgd, addr);
443 pud_k = pud_offset(pgd_k, addr);
444
445 if (pud_none(*pud_k))
446 goto bad_area;
447 if (!pud_present(*pud))
448 set_pud(pud, *pud_k);
449
450 pmd = pmd_offset(pud, addr);
451 pmd_k = pmd_offset(pud_k, addr);
452
453 #ifdef CONFIG_ARM_LPAE
454 /*
455 * Only one hardware entry per PMD with LPAE.
456 */
457 index = 0;
458 #else
459 /*
460 * On ARM one Linux PGD entry contains two hardware entries (see page
461 * tables layout in pgtable.h). We normally guarantee that we always
462 * fill both L1 entries. But create_mapping() doesn't follow the rule.
463 * It can create inidividual L1 entries, so here we have to call
464 * pmd_none() check for the entry really corresponded to address, not
465 * for the first of pair.
466 */
467 index = (addr >> SECTION_SHIFT) & 1;
468 #endif
469 if (pmd_none(pmd_k[index]))
470 goto bad_area;
471
472 copy_pmd(pmd, pmd_k);
473 return 0;
474
475 bad_area:
476 do_bad_area(addr, fsr, regs);
477 return 0;
478 }

最佳答案

此范围为内核内存保留,使用 vmalloc 分配。

当 IRQ(软或硬)被禁用时,内核内存可以正常访问,并且无法处理页面错误。
vmalloc 函数负责预先创建映射,因此访问不会出错。
如果出现错误,那是因为访问的是未分配(或已释放)的内存,因此无法处理。

关于linux - 为什么不在 ARM Linux Kernel 上为 vmalloc 填写页面错误中的 PTE 条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11068478/

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