Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8C8ACC433EF for ; Fri, 18 Mar 2022 11:03:25 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nVANs-0003Fo-Ac; Fri, 18 Mar 2022 07:03:04 -0400 Received: from mscreen.etri.re.kr ([129.254.9.16]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (Exim 4.94.2) (envelope-from ) id 1nVANo-0003FF-Q7 for kernelnewbies@kernelnewbies.org; Fri, 18 Mar 2022 07:03:01 -0400 Received: from unknown (HELO send001-relay.gov-dooray.com) (211.180.235.152) by 129.254.9.16 with ESMTP; 18 Mar 2022 20:02:53 +0900 X-Original-SENDERIP: 211.180.235.152 X-Original-MAILFROM: ckim@etri.re.kr X-Original-RCPTTO: kernelnewbies@kernelnewbies.org Received: from [10.162.225.106] (HELO smtp001-imp.gov-dooray.com) ([10.162.225.106]) by send001-relay.gov-dooray.com with SMTP id 99b104e2623466dd; Fri, 18 Mar 2022 20:02:53 +0900 DKIM-Signature: a=rsa-sha256; b=xZloSsxts9jHPa7VA0jXs1s+KOMBpHv5UsH5kAxL6KTWYQeZEdbytBy5KTjrd1MZpc/2+XNW+2 PYee9Xnp+Ta1quApyZVVHHT1TYzmKxG3QfvMToaeF6+/jxXHltD0zLk4g/wXK8A9NenFrk/f2UmC hMduyRP1Sk59gjeK8s6mptI4XdhG4Zg/RwJ/IlwSfMb1W8uWePRxfPcfSj9gMEI07NiACTyASn4D +ep3rYr53s3BrUprv/tLpf3hZqjDDSfxlPobl6D7Es0+szzZ/33/9cDh2gs06jKeiCzeVHHAGHsz UAZnMdedGOqBxdDeh8THAmucx0NW49Ck20a6dunw==; c=relaxed/relaxed; s=selector; d=dooray.com; v=1; bh=LeaYZAysl7oONKjuBg4oV5QNIo+KU78P63LQPUyPA0c=; h=From:To:Subject:Message-ID; Received: from [129.254.132.39] (HELO CHANKIMPC) ([129.254.132.39]) by smtp001-imp.gov-dooray.com with SMTP id 877790c7623466dd; Fri, 18 Mar 2022 20:02:53 +0900 From: "Chan Kim" To: "'JeongHwan Kim'" , References: <7df5449d-9667-531e-c5fc-a008fc50c613@gmail.com> <0b3501d83a89$f04b8000$d0e28000$@etri.re.kr> <6716e46d-412e-f9d6-b5d4-c704bbbb6a26@gmail.com> In-Reply-To: <6716e46d-412e-f9d6-b5d4-c704bbbb6a26@gmail.com> Subject: RE: Which Page table is appled when MMU is turned on in boot process of ARM64 Date: Fri, 18 Mar 2022 20:02:52 +0900 Message-ID: <0b9a01d83ab7$b71766e0$254634a0$@etri.re.kr> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Content-Language: ko Thread-Index: AQKu+J+2/SvMP7cgpla+EQmnmQptZAGpfai1AgTnxDeq+gWhwA== X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============2892141911641977874==" Errors-To: kernelnewbies-bounces@kernelnewbies.org This is a multipart message in MIME format. --===============2892141911641977874== Content-Type: multipart/alternative; boundary="----=_NextPart_000_0B9B_01D83B03.2701A6F0" Content-Language: ko This is a multipart message in MIME format. ------=_NextPart_000_0B9B_01D83B03.2701A6F0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi JeongHwan, The boot loader (like u-boot) loads the linux Image (in arm64, Image is = uncompressed format) on memory and make the pc jump to that address. For example, see this code from u-boot. msr spsr_el3, \tmp msr elr_el3, \ep eret The u-boot program normally runs at el3 and making all the conditions = right for starting the linux (there are some requirements), Sets elr_el3 (exception link register el3) register with the ep (entry = point) value, which physical address like 0x80080000.=20 When the cpu executes =E2=80=98eret=E2=80=99(return from exception), the = pc value becomes the value in elr_el3(for example 0x80080000) and it = goes into el2. In linux head.S, it either remains in el2 or goes down to el1 before = jumping to start_kernel(). I found the -fno-PIE is needed for ASLR (address space location = randomization from kernel 4.xx) and I don=E2=80=99t know exactly what = ASLR is. (but I know what KASLR is) Anyway, the codes are placed packed or sometimes spaced in kernel = virtual addresses by the linker. As you said they are all express in = kernel virtual address. In my recent experiment , for example _head was in 0xffffffc010080000 = but it=E2=80=99s 0x80080000 physically. And ffffffc0103a0320 is just = 0x803a0320.=20 There is this linear relationship for the kernel.(convenient). But the = codes and data before the =E2=80=9Cprimary_switched=E2=80=9D are = accessed using physical address. In assembly b (branch, it=E2=80=99s goto. No return) or bl (branch and = link, this is like function. It returns to current location using link = register) is using relative address when the distance is less then some = value. (maybe 24 bits?) so there is no problem for using b or bl in the head.S = file. But as you saw, when it call primary_switched, ( br x8 ), the = address in x8 is pure virtual address for the first time. Hope that helps. Regards, Chan Kim =20 =20 From: JeongHwan Kim =20 Sent: Friday, March 18, 2022 4:41 PM To: Chan Kim ; kernelnewbies@kernelnewbies.org Subject: Re: Which Page table is appled when MMU is turned on in boot = process of ARM64 =20 Thank you for reply. =20 I have a question about the meaning of "Until MMU is turned on, the CPU = has been=20 using physical address and pc-relative jumps." I understand the CPU runs on physical address in assembly code before = MMU is enabled. =20 But how is it possible? =20 For example, when the head.S is compiled, the PIC(position independent = code) option is disabled as like this using -fno-PIE option: =20 aarch64-linux-gnu-gcc -Wp,-MMD,arch/arm64/kernel/.head.o.d -nostdinc = -isystem /usr/lib/gcc-cross/aarch64-linux-gnu/9/include = -I./arch/arm64/include -I./arch/arm64/include/generated -I./include = -I./arch/arm64/include/uapi -I./arch/arm6 4/include/generated/uapi -I./include/uapi -I./include/generated/uapi = -include ./include/linux/compiler-version.h -include = ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian = -DKASAN_SHADOW_SCALE_SHIFT=3D -fmacro-prefix-map=3D./=3D -D__ASSEMB LY__ -fno-PIE -mabi=3Dlp64 -fno-asynchronous-unwind-tables = -fno-unwind-tables -DKASAN_SHADOW_SCALE_SHIFT=3D -Wa,-gdwarf-2 -c -o = arch/arm64/kernel/head.o arch/arm64/kernel/head.S =20 and system.map shows all the symbols of assembly code are virtual = address.=20 =20 Please let me know the method how the assembly code runs in PIC way. Only are the pc-relative jumps needed? =20 Regards, J.Hwan KIm=20 =20 On 22. 3. 18. 14:35, Chan Kim wrote: =20 Hi JeongHwan, =20 Recently I followed the kernel boot process so now I understand how it's doing. The kernel starts at HEAD and it jumps to primary_entry. (code below is 5.10.0. but in 5.4.21 it jumped to stext, just name change) Primary_entry looks like this. =20 SYM_CODE_START(primary_entry) =20 bl preserve_boot_args bl el2_setup // Drop to EL1, w0=3Dcpu_boot_mode adrp x23, __PHYS_OFFSET and x23, x23, MIN_KIMG_ALIGN - 1 // KASLR offset, = defaults to 0 bl set_cpu_boot_mode_flag bl __create_page_tables /* * The following calls CPU setup code, see = arch/arm64/mm/proc.S for * details. * On return, the CPU will be ready for the MMU to be turned = on and * the TCR will have been set. */ bl __cpu_setup // initialise processor b __primary_switch SYM_CODE_END(primary_entry) =20 The page tables for id mapping (for 0x80000000 ~ .. physical address) = and swapper_pgdir (for virtual address) are setup inside = __create_page_tables. MMU is turned on in __primary_switch. (code below for 5.10.0-rc5) You see there is bl __enable_mmu. Until MMU is turned on, the CPU has = been using physical address and pc-relative jumps.=20 At the instant MMU is turned on, the page table for the current physical address range is already setup so there is no problem using physical address.(just identical mapping)=20 The first place where kernel virtual address is used is at the end of __primary_switch. The value __primary_switched is a virtual address (starting with 0xffffffc0....) and from that point on virtual->physical address mapping is used. Old version will be the same. (I checked previously for 5.4.21) =20 =20 SYM_FUNC_START_LOCAL(__primary_switch) #ifdef CONFIG_RANDOMIZE_BASE mov x19, x0 // preserve new SCTLR_EL1 value mrs x20, sctlr_el1 // preserve old SCTLR_EL1 value #endif =20 adrp x1, init_pg_dir bl __enable_mmu #ifdef CONFIG_RELOCATABLE #ifdef CONFIG_RELR mov x24, #0 // no RELR displacement yet #endif bl __relocate_kernel #ifdef CONFIG_RANDOMIZE_BASE ldr x8, =3D__primary_switched adrp x0, __PHYS_OFFSET blr x8 =20 /* * If we return here, we have a KASLR displacement in x23 which we need * to take into account by discarding the current kernel mapping and * creating a new one. */ pre_disable_mmu_workaround msr sctlr_el1, x20 // disable the MMU isb bl __create_page_tables // recreate kernel mapping =20 tlbi vmalle1 // Remove any stale TLB entries dsb nsh =20 msr sctlr_el1, x19 // re-enable the MMU isb ic iallu // flush instructions fetched dsb nsh // via old mapping isb =20 bl __relocate_kernel #endif #endif ldr x8, =3D__primary_switched adrp x0, __PHYS_OFFSET br x8 SYM_FUNC_END(__primary_switch) =20 =20 Hope this helps. Have a nice day! =20 Chan =20 -----Original Message----- From: JeongHwan Kim = Sent: Friday, March 18, 2022 10:41 AM To: kernelnewbies@kernelnewbies.org = =20 Subject: Which Page table is appled when MMU is turned on in boot = process of ARM64 =20 Hi, everyone =20 =20 When ARM64 boots, it setup 2 page tables ("idmap_pg_dir" and "swapper_pgdir"). =20 On turning on MMU, which page table is applied? =20 I heard that "idmap_pg_dir" is applied as soon as MMU is turned on. =20 I cannot understand why "idmap_pg_dir" is applied, which is for "Lower" address. =20 As I understand, the virtual address of kernel code is in "Higher" address. =20 Can you explain why "idmap_pg_dir" is applied on MMU turning on? =20 =20 Thanks in advance =20 J.Hwan Kim =20 =20 =20 =20 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org = https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies =20 =20 =20 =20 ------=_NextPart_000_0B9B_01D83B03.2701A6F0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi JeongHwan,

The boot loader (like u-boot) loads the linux Image = (in arm64, Image is uncompressed format) on memory and make the pc jump = to that address.

For example, see this code from = u-boot.

msr spsr_el3, \tmp

=C2=A0=C2=A0=C2=A0 msr elr_el3, = \ep

=C2=A0=C2=A0=C2=A0 eret

The u-boot program normally runs at el3 and making = all the conditions right for starting the linux (there are some = requirements),

Sets elr_el3 (exception link register el3) register = with the ep (entry point) value, which physical address like 0x80080000. =

When the cpu executes =E2=80=98eret=E2=80=99(return = from exception), the pc value becomes the value in elr_el3(for example = 0x80080000) and it goes into el2.

In linux head.S, it either remains in el2 or goes = down to el1 before jumping to start_kernel().

I found the -fno-PIE is needed for ASLR (address = space location randomization from kernel 4.xx) and I don=E2=80=99t know = exactly what ASLR is. (but I know what KASLR is)

Anyway, the codes are placed packed or sometimes = spaced in kernel virtual addresses by the linker. As you said they are = all express in kernel virtual address.

In my recent experiment , for example _head was in = 0xffffffc010080000 but it=E2=80=99s 0x80080000 physically. And = ffffffc0103a0320 is just 0x803a0320.

There is this linear relationship for the = kernel.(convenient). But the codes and data before the = =E2=80=9Cprimary_switched=E2=80=9D are accessed using physical = address.

In assembly b (branch, it=E2=80=99s goto. No = return) or bl (branch and link, this is like function. It returns to = current location using link register) is using relative address when the = distance is less then some value.

(maybe 24 bits?) so there is no problem for using b = or bl in the head.S file. But as you saw, when it call primary_switched, = ( br x8 ), the address in x8 is pure virtual address for the first = time.

Hope that helps.

Regards,

Chan Kim

 

 

From:<= /b> JeongHwan = Kim <frog007.kernel.kr@gmail.com>
Sent: Friday, March = 18, 2022 4:41 PM
To: Chan Kim <ckim@etri.re.kr>; = kernelnewbies@kernelnewbies.org
Subject: Re: Which Page table = is appled when MMU is turned on in boot process of = ARM64

 

Thank you = for reply.

 

I have a = question about the meaning of "Until MMU is turned on, the CPU has = been

using physical address = and pc-relative jumps."

I understand the CPU runs on physical address in assembly =
code before MMU is enabled.
 
But =
how is it possible?
 
For =
example, when the head.S is compiled, the PIC(position independent code) =
option is disabled as like this using -fno-PIE =
option:
 
aarch64-linux-gnu-gcc =
-Wp,-MMD,arch/arm64/kernel/.head.o.d  -nostdinc -isystem =
/usr/lib/gcc-cross/aarch64-linux-gnu/9/include -I./arch/arm64/include =
-I./arch/arm64/include/generated  -I./include =
-I./arch/arm64/include/uapi -I./arch/arm6
4/include/generated/uapi -I./include/uapi =
-I./include/generated/uapi -include ./include/linux/compiler-version.h =
-include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian =
-DKASAN_SHADOW_SCALE_SHIFT=3D -fmacro-prefix-map=3D./=3D =
-D__ASSEMB
LY__ -fno-PIE -mabi=3Dlp64 =
-fno-asynchronous-unwind-tables -fno-unwind-tables =
-DKASAN_SHADOW_SCALE_SHIFT=3D -Wa,-gdwarf-2    -c -o =
arch/arm64/kernel/head.o =
arch/arm64/kernel/head.S
 
and =
system.map shows all the symbols of assembly code are virtual address. =
 
Please let me know the method how the assembly code runs in =
PIC way.
Only are the =
pc-relative jumps needed?
 
Regards,
J.Hwan KIm 
 

On 22. 3. 18. 14:35, Chan Kim = wrote:

 
Hi =
JeongHwan,
 
Recently I followed the kernel boot process so now I =
understand how it's
doing.
The =
kernel starts at HEAD and it jumps to primary_entry. (code below =
is
5.10.0.=C2=A0 but in =
5.4.21 it jumped to stext, just name =
change)
Primary_entry =
looks like this.
 
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
SYM_CODE_START(primary_entry)
 
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 bl=C2=A0 preserve_boot_args
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 bl=C2=A0 =
el2_setup=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // =
Drop to EL1, w0=3Dcpu_boot_mode
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 adrp=C2=A0=C2=A0=C2=A0 x23, =
__PHYS_OFFSET
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 and x23, x23, MIN_KIMG_ALIGN - 1=C2=A0=C2=A0=C2=A0 // KASLR =
offset, defaults to
0
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 bl=C2=A0 set_cpu_boot_mode_flag
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 bl=C2=A0 __create_page_tables
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
 =C2=A0/*
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 * The following calls CPU setup code, see =
arch/arm64/mm/proc.S
for
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 * details.
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 * On return, the CPU will be ready for the MMU to be turned =
on
and
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 * the TCR will have been =
set.
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 */
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0bl=C2=A0 =
__cpu_setup=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // =
initialise processor
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 b=C2=A0=C2=A0 __primary_switch
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
SYM_CODE_END(primary_entry)
 
The =
page tables for id mapping (for 0x80000000 ~ .. physical address) =
and
swapper_pgdir (for =
virtual address) are setup inside =
__create_page_tables.
MMU =
is turned on in __primary_switch. (code below for =
5.10.0-rc5)
You see there =
is bl __enable_mmu. Until MMU is turned on, the CPU has =
been
using physical =
address and pc-relative jumps. 
At the instant MMU is turned on, the page table for the =
current physical
address =
range is already setup so there is no problem using =
physical
address.(just =
identical mapping) 
The =
first place where kernel virtual address is used is at the end =
of
__primary_switch. The =
value __primary_switched is a virtual =
address
(starting with =
0xffffffc0....) and from that point on =
virtual->physical
address mapping is used.=C2=A0 Old version will be the =
same. (I checked
previously for 5.4.21)
 
 
  =
SYM_FUNC_START_LOCAL(__primary_switch)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #ifdef =
CONFIG_RANDOMIZE_BASE
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 mov x19, =
x0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
 // preserve new SCTLR_EL1 value
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 mrs x20, =
sctlr_el1=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // =
preserve old SCTLR_EL1
value
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
#endif
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C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A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0=C2=A0 * If we return here, we have a KASLR =
displacement in
x23 which =
we need
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0=C2=A0 * to take into account by discarding the =
current kernel
mapping =
and
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0=C2=A0 * creating a new =
one.
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0=C2=A0 */
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =
pre_disable_mmu_workaround
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 msr sctlr_el1, =
x20=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // disable the =
MMU
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 isb
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 bl=C2=A0 =
__create_page_tables=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // =
recreate kernel
mapping
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 tlbi=C2=A0=C2=A0=C2=A0 =
vmalle1=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 // Remove any stale TLB
entries
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =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=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 adrp=C2=A0=C2=A0=C2=A0 x0, =
__PHYS_OFFSET
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 br=C2=A0 x8
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
SYM_FUNC_END(__primary_switch)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
 
Hope =
this helps.
Have a nice =
day!
 
Chan
 
-----Original =
Message-----
From: =
JeongHwan Kim <frog007.kernel.kr@gmail.c=
om>
Sent: Friday, =
March 18, 2022 10:41 AM
To: kernelnewbies@kernelnewbi=
es.org
Subject: Which =
Page table is appled when MMU is turned on in boot =
process
of =
ARM64
 
Hi, =
everyone
 
 
When =
ARM64 boots, it setup 2 page tables ("idmap_pg_dir" =
and
"swapper_pgdir").
 
On =
turning on MMU, which page table is =
applied?
 
I =
heard that "idmap_pg_dir" is applied as soon as MMU is turned =
on.
 
I =
cannot understand why "idmap_pg_dir" is applied, which is for =
"Lower"
address.
 
As I =
understand, the virtual address of kernel code is in =
"Higher"
address.
 
Can =
you explain why "idmap_pg_dir" is applied on MMU turning =
on?
 
 
Thanks in advance
 
J.Hwan Kim
 
 
 
 
_______________________________________________
Kernelnewbies mailing =
list
Kernelnewbies@kernelnewbi=
es.org
h=
ttps://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
 
 
 
 
------=_NextPart_000_0B9B_01D83B03.2701A6F0-- --===============2892141911641977874== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============2892141911641977874==--