Notes
main
main
  • Introduction
  • linuxKernel
    • tips
    • make_help
    • old linux
      • compile_linux0.11
      • TestEnvironment
      • load_setup
      • get_hard_data
    • list
    • plist
    • fifo
    • idr
    • xarray
    • rbtree
    • maple_tree
    • syscall
    • bitmap
    • page
    • page_flags
    • page_size
    • page mapcount
    • page refcount
    • folio
    • slub
      • proc_slabinfo
      • slub_theory
      • kmalloc_kfree
      • kmem_cache
      • slab_alloc
      • slab_free
      • proc_meminfo_SReclaimable_SReclaimable
    • vmalloc
    • brk
    • mmap
    • mremap
    • mprotect
    • madvise
    • read
    • write
    • shmem
    • huge_page
    • page_fault
    • rmap
    • lru
    • multi-gen-LRU
    • page_reclaim
    • page_cache
    • page_table
    • rcu
    • kvm
    • aarch64_boot
    • tracing_system
    • cache_coherence_and_memory_consistency
    • cpu_speculates
    • mmap_lock
    • per-vma_lock
    • cgroup
    • symbol
    • campact
    • page_ext
    • mempool
    • kernelstack
    • filesystem
    • io_stack
    • workingset
    • ioremap
    • sched_period
  • linuxDebug
    • openocd_openjtag
    • i2c_tools
    • objdump
    • addr2line
    • gdb_useage
    • debug_linux_kernel_via_gdb
    • debug_linux_module_via_gdb
    • early_boot
    • sequentially_execute
    • dynamic_debug
    • research_linuxKernel_by_patch
    • tracefs
    • ebpf
    • bpftrace
    • perf
    • flame_graph
    • crash
    • ASAN_HWASAN_MTE_check_mem_bug
    • page_owner
    • vmtouch
    • fio
    • benchmark
  • linuxSystem
    • common
      • system_version
      • procfs
      • proc_sys_vm
      • cmd_ps
      • makefile
      • file_descriptor
      • psi
      • ulimit
      • top
      • delay_accounting
    • ubuntu
      • custom_kernel
      • get_cmd_src
      • record_ssh_info
      • log
      • run_custom_script
      • repo
      • cockpit
      • nfs
      • tftp
      • misc
    • fedora
      • system_upgrade
      • custom_kernel
      • lvextend
      • yt-dlp
      • jellyfin
  • linuxDriver
    • i2c_peripherals_driver
    • spi_peripherals_driver
    • gpio_subsystem
    • IRQ_driver
    • blockIO_unblockIO_async
    • linux_own_driver
    • misc_device
    • input_device
    • timer
    • atomic_spinlock_semaphore_mutex
    • lcd
    • touch_screen
    • debugfs
    • v4l2
    • mmap
  • hardware
    • paging_mmu_pt
    • iommu
  • process_thread_scheduler
    • scheduler01
    • scheduler02
    • scheduler03
    • scheduler04
    • scheduler05
    • scheduler06
  • memory_management
    • mm1
    • mm2
    • mm3
    • mm4
    • mm5
  • input_output_filesystem
    • io_fs_01
    • io_fs_02
    • io_fs_03
    • io_fs_04
  • lock_and_lockup_detector
    • general_lock
    • hung_task
    • softLockup_hardLockup
    • crash_experiment
  • MIT_6.S081
    • 6.S081_Operating_System_Engineering
    • Schedule.md
    • Class
      • Overview
      • Administrivia
    • Labs
      • Tools
      • Guidance
      • startup
      • syscall
      • page_table
      • Calling_Convention
      • traps
    • xv6
      • xv6
    • References.md
  • qemu
    • qemu_buildroot
    • qemu_busybox.md
    • Serial.md
    • demo_mini2440
      • 0_compilation_error_summary
      • 1_compilation_steps
      • 2_operation_mode
      • 3_transplant_tools_libraries
      • 4_tools_use
      • reference_website
  • tools
    • getKernelSourceCodeList
    • nat
    • shell
    • translating
    • YouCompleteMe
    • cscope
    • global
    • vscode
    • vim
    • binary
    • markdown
    • draw
    • git
    • tig
    • tmux
    • mail_client
    • download_patchset_from_LKML
    • minicom
    • clash
  • other
    • interview
    • interview_c_base
    • know_dontknow
    • Stop-Ask-Questions-The-Stupid-Ways
    • How-To-Ask-Questions-The-Smart-Way
    • docker
    • buildroot
    • rv32_to_rv64
Powered by GitBook
On this page
  • 简述
  • 设置内核空间页表的过程
  • 将 用户空间虚拟地址内容 复制到 内核空间虚拟地址 的过程

Was this helpful?

  1. MIT_6.S081
  2. Labs

page_table

PrevioussyscallNextCalling_Convention

Last updated 3 years ago

Was this helpful?

简述

page table,页表

页表的功能:将虚拟地址转换成物理地址

设置内核空间页表的过程

在main()中设置内核空间页表的过程,如下:

  1. 调用kvminit()设置内核空间页表的衡等映射,比如UART0的物理地址0x10000000L对应的虚拟地址也是0x10000000L

  2. 由于XV6采用三级页表的方式进行管理,调用kvminithart() -> w_satp()将第一级页表(根页表)的起始地址存储到SATP寄存器中,同时激活分页功能(Risc-V架构),但是因为第一步将内核空间的页表设置成衡等映射,所以对内核空间来说,激活分页功能后,执行下一条指令没有影响

    注意:

    执行此指令之前,所有的地址都是物理地址

    执行完此指令后,所有的地址都是虚拟地址

  3. 调用kvminithart() -> sfence_vma()刷新TLB

将 用户空间虚拟地址内容 复制到 内核空间虚拟地址 的过程

此处以int write(int pid, const void *buf, int size)为例子,如下:

当用户空间调用write()时,通过ecall陷入内核空间,详细解释看。注意:write()实现函数由汇编语言编写而成(user/usys.S,此文件需要编译后才自动产生)

接着调用uservec() -> usertrap() -> syscall(),通过系统启用号(如:SYS_write),调用sys_write(),通过寄存器x0~x2得到由用户空间传递到内核空间的参数,调用filewrite() -> pipewrite() -> copyin(user_pagetable),然后通过用户空间页表将用户空间虚拟地址转换成对应的物理地址,最后将物理地址的内容复制到内核空间的虚拟地址

如果将用户空间页表内容 映射到 内核空间页表(不是复制),调用copyin()时,就不需要通过用户空间页表将用户空间虚拟地址转换成对应的物理地址,直接将用户空间虚拟地址的内容复制到内核空间的虚拟地址

最后,从 内核空间 返回到 用户空间,调用sys_write() -> syscall() -> usertrapret() -> userret(), 返回到ecall下一条指令继续执行

traps 文档