x86: Change 4-level page table base address to low memory
PATCH 1/3 x86: Change 4-level page table base address to low memory
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with CONFIG_LOADADDR. Change it to an address within the low memory range instead.
Fixes crashes seen when 'dhcp' on QEMU x86_64 with "-net nic -net user,tftp=.,bootfile=u-boot".
---
arch/x86/cpu/i386/cpu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/cpu/i386/cpu.c +2 -4
@@ -462,6 +462,7 @@ int cpu_has_64bit(void)has_long_mode (); } +#define PAGETABLE_BASE 0x80000#define PAGETABLE_SIZE (6 * 4096)/**
@@ -523,10 +524,7 @@ int cpu_jump_to_64bit_uboot(ulong target)uint32_t *pgtable;func_t func; -/* TODO(sjg at chromium.org): Find a better place for this */ - pgtable = (uint32_t *)0x1000000 ; -if (!pgtable) -return -ENOMEM ; + pgtable = (uint32_t *)PAGETABLE_BASE ;build_pagetable (pgtable);
Signature · 1 line
2.7.4
PATCH 2/3 x86: Don't copy the cpu_call64() function to a hardcoded address
Before jumping to 64-bit U-Boot proper, SPL copies the cpu_call64() function to a hardcoded address 0x3000000. This can have potential conflicts with application usage. Switch the destination address to be allocated from the heap to avoid such risk.
---
arch/x86/cpu/i386/call64.S | 4 ++++ arch/x86/cpu/i386/cpu.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
arch/x86/cpu/i386/call64.S +4 -0
@@ -79,6 +79,10 @@ lret_target: mov %eax, %eax /* Clear bits 63:32 */ jmp *%eax /* Jump to the 64-bit target */ +.globl call64_stub_size +call64_stub_size: + .long . - cpu_call64 + .data .align 16 .globl gdt64
arch/x86/cpu/i386/cpu.c +8 -3
@@ -523,18 +523,23 @@ int cpu_jump_to_64bit_uboot(ulong target)typedef void (*func_t )(ulong pgtable,ulong setup_base,ulong target);uint32_t *pgtable;func_t func; +char *ptr; pgtable = (uint32_t *)PAGETABLE_BASE ;build_pagetable (pgtable); -/* TODO(sjg at chromium.org): Find a better place for this */ -char *ptr = (char *)0x3000000 ; +extern long call64_stub_size; + ptr =malloc (call64_stub_size); +if (!ptr) { +printf ("Failed to allocate the cpu_call64 stub\n" ); +return -ENOMEM ; + }char *gdt = (char *)0x3100000 ;extern char gdt64[]; -memcpy (ptr, cpu_call64,0x1000 ); +memcpy (ptr, cpu_call64, call64_stub_size);memcpy (gdt, gdt64,0x100 );/*
Signature · 1 line
2.7.4
PATCH 2/3 x86: Don't copy the cpu_call64() function to a hardcoded address
Quoted 6 lines · Bin Meng
Before jumping to 64-bit U-Boot proper, SPL copies the
cpu_call64()function to a hardcoded address0x3000000. This can have potential conflicts with application usage. Switch the destination address to be allocated from the heap to avoid such risk.
Quoted 6 lines
Signed-off-by Bin Meng <[email protected]>---
arch/x86/cpu/i386/call64.S | 4 ++++ arch/x86/cpu/i386/cpu.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
PATCH 2/3 x86: Don't copy the cpu_call64() function to a hardcoded address
Quoted 8 lines · Simon Glass
Quoted 6 lines · Bin Meng
Before jumping to 64-bit U-Boot proper, SPL copies the
cpu_call64()function to a hardcoded address0x3000000. This can have potential conflicts with application usage. Switch the destination address to be allocated from the heap to avoid such risk.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Bin Meng <[email protected]>---
arch/x86/cpu/i386/call64.S | 4 ++++ arch/x86/cpu/i386/cpu.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)Reviewed-by Simon Glass <[email protected]>
applied to u-boot-x86, thanks!
PATCH 3/3 x86: Use the existing GDT in the ROM for 64-bit U-Boot proper
In reply to Bin MengIt is unnecessary to use a RAM version GDT for 64-bit U-Boot proper. In fact we can just use the ROM version directly, which not only eliminates the risk of being overwritten by application, but also removes the complexity of patching the cpu_call64().
---
arch/x86/cpu/i386/cpu.c | 14 -------------- 1 file changed, 14 deletions(-)
arch/x86/cpu/i386/cpu.c +0 -14
@@ -535,23 +535,9 @@ int cpu_jump_to_64bit_uboot(ulong target)printf ("Failed to allocate the cpu_call64 stub\n" );return -ENOMEM ; } -char *gdt = (char *)0x3100000 ; - -extern char gdt64[]; -memcpy (ptr, cpu_call64, call64_stub_size); -memcpy (gdt, gdt64,0x100 ); -/* -* TODO(sjg at chromium.org): This manually inserts the pointers into -* the code. Tidy this up to avoid this. -*/ func = (func_t )ptr; -ulong ofs = (ulong )cpu_call64 - (ulong )ptr; - *(ulong *)(ptr +7 ) = (ulong )gdt; - *(ulong *)(ptr +0xc ) = (ulong )gdt +2 ; - *(ulong *)(ptr +0x13 ) = (ulong )gdt; - *(ulong *)(ptr +0x117 -0xd4 ) -= ofs;/* * Copy U-Boot from ROM
Signature · 1 line
2.7.4
PATCH 3/3 x86: Use the existing GDT in the ROM for 64-bit U-Boot proper
Hi Bin,
Quoted 6 lines · Bin Meng
It is unnecessary to use a RAM version GDT for 64-bit U-Boot proper. In fact we can just use the ROM version directly, which not only eliminates the risk of being overwritten by application, but also removes the complexity of patching the
cpu_call64().
Quoted 6 lines
Signed-off-by Bin Meng <[email protected]>---
arch/x86/cpu/i386/cpu.c | 14 -------------- 1 file changed, 14 deletions(-)
I am not sure what issue I had with this, but I'm pleased that this works.
PATCH 3/3 x86: Use the existing GDT in the ROM for 64-bit U-Boot proper
Quoted 12 lines · Simon Glass
Hi Bin,
Quoted 8 lines · Bin Meng
It is unnecessary to use a RAM version GDT for 64-bit U-Boot proper. In fact we can just use the ROM version directly, which not only eliminates the risk of being overwritten by application, but also removes the complexity of patching the
cpu_call64().Signed-off-by Bin Meng <[email protected]>
Quoted 8 lines
Quoted 4 lines
---
arch/x86/cpu/i386/cpu.c | 14 -------------- 1 file changed, 14 deletions(-)I am not sure what issue I had with this, but I'm pleased that this works.
Reviewed-by Simon Glass <[email protected]>
applied to u-boot-x86, thanks!
PATCH 1/3 x86: Change 4-level page table base address to low memory
In reply to Bin MengQuoted 9 lines · Bin Meng
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.Fixes crashes seen when 'dhcp' on QEMU
x86_64with "-net nic -net user,tftp=.,bootfile=u-boot".Reported-by Alexander Graf <[email protected]>Signed-off-by Bin Meng <[email protected]>
Thanks for addressing this. It fixes the problem reported in
x86: #define CONFIG_LOADADDR 0x1100000
https://lists.denx.de/pipermail/u-boot/2019-January/356108.html
I have set aforementioned patch to superseded.
Tested on qemu-x86_64.
PATCH 1/3 x86: Change 4-level page table base address to low memory
In reply to Bin MengQuoted 7 lines
Am 31.01.2019 um 17:22 schrieb Bin Meng <[email protected]>:
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.
Can't you dynamically allocate the PT too?
Alex
Quoted 38 lines
Fixes crashes seen when 'dhcp' on QEMU
x86_64with "-net nic -net user,tftp=.,bootfile=u-boot".Reported-by Alexander Graf <[email protected]>Signed-off-by Bin Meng <[email protected]>---
arch/x86/cpu/i386/cpu.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)arch/x86/cpu/i386/cpu.c +2
-4@@ -462,6 +462,7 @@ int cpu_has_64bit(void)has_long_mode (); } +#define PAGETABLE_BASE 0x80000#define PAGETABLE_SIZE (6 * 4096)/** @@ -523,10 +524,7 @@ int cpu_jump_to_64bit_uboot(ulong target)uint32_t *pgtable;func_t func; -/* TODO(sjg at chromium.org): Find a better place for this */ - pgtable = (uint32_t *)0x1000000 ; -if (!pgtable) -return -ENOMEM ; + pgtable = (uint32_t *)PAGETABLE_BASE ;build_pagetable (pgtable);Signature · 1 line
2.7.4
PATCH 1/3 x86: Change 4-level page table base address to low memory
Hi Alex,
Quoted 11 lines · Alexander Graf
Quoted 8 lines
Am 31.01.2019 um 17:22 schrieb Bin Meng <[email protected]>:
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.Can't you dynamically allocate the PT too?
The dynamically allocated PT only makes sense when in SPL. It then becomes an arbitrary address again when entering in the 64-bit proper.
Regards,
Bin
PATCH 1/3 x86: Change 4-level page table base address to low memory
Quoted 16 lines
Am 01.02.2019 um 00:40 schrieb Bin Meng <[email protected]>:
Hi Alex,
Quoted 10 lines · Alexander Graf
Quoted 8 lines
Am 31.01.2019 um 17:22 schrieb Bin Meng <[email protected]>:
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.
Quoted 5 lines
Quoted 2 lines
Can't you dynamically allocate the PT too?
The dynamically allocated PT only makes sense when in SPL. It then becomes an arbitrary address again when entering in the 64-bit proper.
I'm not sure I follow? On aarch64, we allocate every level dynamically. I feel like I'm missing a piece of the puzzle here :)
Alex
Quoted 3 lines
Regards,
Bin
PATCH 1/3 x86: Change 4-level page table base address to low memory
Hi Alex,
Quoted 17 lines · Alexander Graf
Quoted 17 lines
Am 01.02.2019 um 00:40 schrieb Bin Meng <[email protected]>:
Hi Alex,
Quoted 10 lines · Alexander Graf
Quoted 8 lines
Am 31.01.2019 um 17:22 schrieb Bin Meng <[email protected]>:
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Can't you dynamically allocate the PT too?
The dynamically allocated PT only makes sense when in SPL. It then becomes an arbitrary address again when entering in the 64-bit proper.
I'm not sure I follow? On aarch64, we allocate every level dynamically. I feel like I'm missing a piece of the puzzle here :)
The current x86 implementation is the SPL allocates the page table for the 64-bit U-Boot. We can certainly change the implementation but I would leave that for future changes.
Regards,
Bin
PATCH 1/3 x86: Change 4-level page table base address to low memory
Quoted 30 lines
Am 01.02.2019 um 08:29 schrieb Bin Meng <[email protected]>:
Hi Alex,
Quoted 24 lines · Alexander Graf
Quoted 22 lines
Am 01.02.2019 um 00:40 schrieb Bin Meng <[email protected]>:
Hi Alex,
Quoted 12 lines · Alexander Graf
Quoted 8 lines
Am 31.01.2019 um 17:22 schrieb Bin Meng <[email protected]>:
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.Can't you dynamically allocate the PT too?
The dynamically allocated PT only makes sense when in SPL. It then becomes an arbitrary address again when entering in the 64-bit proper.
Quoted 6 lines
Quoted 2 lines
I'm not sure I follow? On aarch64, we allocate every level dynamically. I feel like I'm missing a piece of the puzzle here :)
The current x86 implementation is the SPL allocates the page table for the 64-bit U-Boot. We can certainly change the implementation but I would leave that for future changes.
I see. Works for me :)
Alex
Quoted 3 lines
Regards,
Bin
PATCH 1/3 x86: Change 4-level page table base address to low memory
In reply to Bin MengQuoted 8 lines · Bin Meng
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.Fixes crashes seen when 'dhcp' on QEMU
x86_64with "-net nic -net user,tftp=.,bootfile=u-boot".
Quoted 6 lines
Reported-by Alexander Graf <[email protected]>Signed-off-by Bin Meng <[email protected]>---
arch/x86/cpu/i386/cpu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
PATCH 1/3 x86: Change 4-level page table base address to low memory
Quoted 13 lines · Simon Glass
Quoted 12 lines · Bin Meng
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.Fixes crashes seen when 'dhcp' on QEMU
x86_64with "-net nic -net user,tftp=.,bootfile=u-boot".Reported-by Alexander Graf <[email protected]>Signed-off-by Bin Meng <[email protected]>---
Quoted 9 lines
Quoted 2 lines
arch/x86/cpu/i386/cpu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)Reviewed-by Simon Glass <[email protected]>_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
Hello Bin,
this patch is needed together with
test/py: use default load address for tftp
https://lists.denx.de/pipermail/u-boot/2019-January/356265.html
to get the EFI patch queue merged.
Should Tom pick the patch series?
Best regards
Heinrich
PATCH 1/3 x86: Change 4-level page table base address to low memory
Hi Heinrich,
Quoted 27 lines · Heinrich Schuchardt
Quoted 13 lines · Simon Glass
Quoted 12 lines · Bin Meng
At present the 4-level page table base address for 64-bit U-Boot proper is assigned an address that conflicts with
CONFIG_LOADADDR. Change it to an address within the low memory range instead.Fixes crashes seen when 'dhcp' on QEMU
x86_64with "-net nic -net user,tftp=.,bootfile=u-boot".Reported-by Alexander Graf <[email protected]>Signed-off-by Bin Meng <[email protected]>---
Quoted 9 lines
Quoted 2 lines
arch/x86/cpu/i386/cpu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)Reviewed-by Simon Glass <[email protected]>_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-bootHello Bin,
Quoted 9 lines
this patch is needed together with
test/py: use default load address for tftp
https://lists.denx.de/pipermail/u-boot/2019-January/356265.htmlto get the EFI patch queue merged.
Should Tom pick the patch series?
Sorry I just came back from Chinese new year holiday vacation. I will send PR to Tom ASAP.
applied to u-boot-x86, thanks!
Regards,
Bin