Q&A 게시판

리눅스 커널에 대한 Q&A 게시판 입니다. (비밀글 체크는 꼭 필요한 경우에만)

head.S의 primary_entry에서 init_kernel_el 전 dcache_clean_poc 를 하는 이유에 대한 질문입니다.

작성자
이민찬
작성일
2023-09-10 22:36
조회
103
안녕하세요 문영일님.
리눅스 커널 v6.4.2의 head.S를 분석하던 중 궁금한 점이 있어 질문드립니다.

primary_entry 코드에서 init_kernel_el에 들어가기 전에 MMU와 캐시가 on 상태라면,
__idmap_text_start 부터 __idmap_text_end 영역을 POC 까지 clean 합니다.

궁금한 것은 MMU와 캐시가 on일 때, MMU를 끄기 전 캐시를 clean 하는 이유와
그 영역은 왜 __idmap_text_start 부터 __idmap_text_end 사이의 영역인가 입니다.

참고한 자료를 함께 작성하겠습니다.

1) 관련 주석은 다음과 같습니다.
/*
* If we entered with the MMU and caches on, clean the ID mapped part
* of the primary boot code to the PoC so we can safely execute it with
* the MMU off.
*/

2) https://lore.kernel.org/linux-arm-kernel/20221108182204.2447664-6-ardb@kernel.org/

3) System.map 파일 중 __idmap_text_start 부터 __idmap_text_end 까지
ffff8000099e4000 T __idmap_text_start
ffff8000099e4000 t enter_vhe
ffff8000099e4038 T cpu_resume
ffff8000099e4068 T cpu_soft_restart
ffff8000099e40a0 T primary_entry
ffff8000099e40dc T init_kernel_el
ffff8000099e40ec t init_el1
ffff8000099e4118 t init_el2
ffff8000099e42dc T secondary_holding_pen
ffff8000099e4304 t pen
ffff8000099e4318 T secondary_entry
ffff8000099e4328 t secondary_startup
ffff8000099e434c T __enable_mmu
ffff8000099e4394 T __cpu_secondary_check52bitva
ffff8000099e439c t __no_granule_support
ffff8000099e43c4 t __relocate_kernel
ffff8000099e4410 t __primary_switch
ffff8000099e4480 T idmap_cpu_replace_ttbr1
ffff8000099e44ac T idmap_kpti_install_ng_mappings
ffff8000099e46ac t __idmap_kpti_secondary
ffff8000099e46f4 T __cpu_setup
ffff8000099e47e0 T __idmap_text_end
전체 1
  • 2023-09-11 13:16
    안녕하세요? 이민찬님,

    해당 코드가 6.3-rc1에서 패치가 되어 추가되었군요.
    idmap을 만들고 MMU를 켠 경우 idmap 가상 주소에 연관된 주소 범위는 __idmap_text_start 부터 __idmap_text_end 까지입니다.
    이 주소 범위내에는 코드 및 데이터가 존재하는데 MMU가 꺼진 다른 core 또는 h/w debugger를 통해 해당 메모리를 볼 때 올바른 값이 보이지 않을 수 있습니다.
    이를 방지하기 위해 혹시라도 메모리에 저장되지 않은 데이터는 PoC까지 캐시를 모두 clean하여 메모리에 저장하게 유도하였다고 합니다.

    감사합니다.

    문영일 드림.