Tentative fix for dom0 boot problem
Subsystems (2)
Juergen Gross
maintainerJulien,
could you please test the attached patches?
Juergen
From 7d6734e517b65c3702a279fc2c1fff5ba7927ef9 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Wed, 22 Jun 2022 12:19:55 +0200
Subject: [PATCH 1/2] x86/xen: use clear_bss() for Xen PV guests
Instead of clearing the bss area in assembly code, use the clear_bss() function.
This requires to pass the start_info address as parameter to xen_start_kernel() in order to avoid the xen_start_info being zeroed again.
--- arch/x86/include/asm/setup.h | 3 +++ arch/x86/kernel/head64.c | 2 +- arch/x86/xen/enlighten_pv.c | 8 ++++++-- arch/x86/xen/xen-head.S | 10 +--------- 4 files changed, 11 insertions(+), 12 deletions(-)
arch/x86/include/asm/setup.h +3 -0
@@ -120,6 +120,9 @@ void *extend_brk(size_t size, size_t align); static char __brk_##name[size]extern void probe_roms (void ); + +void clear_bss (void ); +#ifdef __i386__ asmlinkage void __init i386_start_kernel(void);
arch/x86/kernel/head64.c +1 -1
@@ -426,7 +426,7 @@ void __init do_early_exception(struct pt_regs *regs, int trapnr)/* Don't add a printk in there. printk relies on the PDA which is not initialized yet. */ -static void __init clear_bss (void ) +void __init clear_bss (void ) {memset (__bss_start,0 , (unsigned long ) __bss_stop - (unsigned long ) __bss_start);
arch/x86/xen/enlighten_pv.c +6 -2
@@ -1183,15 +1183,19 @@ static void __init xen_domu_set_legacy_features(void)extern void early_xen_iret_patch (void );/* First C function to be called on Xen boot */ -asmlinkage __visible void __init xen_start_kernel(void) +asmlinkage __visible void __init xen_start_kernel(struct start_info *si) {struct physdev_set_iopl set_iopl;unsigned long initrd_start =0 ;int rc; -if (!xen_start_info) +if (!si)return ; +clear_bss (); + + xen_start_info = si; +__text_gen_insn (&early_xen_iret_patch,JMP32_INSN_OPCODE , &early_xen_iret_patch, &xen_iret,JMP32_INSN_SIZE );
arch/x86/xen/xen-head.S +1 -9
@@ -48,15 +48,6 @@ SYM_CODE_START(startup_xen) ANNOTATE_NOENDBR cld - /* Clear .bss */ - xor %eax,%eax - mov $__bss_start, %rdi - mov $__bss_stop, %rcx - sub %rdi, %rcx - shr $3, %rcx - rep stosq - - mov %rsi, xen_start_info mov initial_stack(%rip), %rsp /* Set up %gs.
@@ -71,6 +62,7 @@ SYM_CODE_START(startup_xen) cdq wrmsr + mov %rsi, %rdi call xen_start_kernel SYM_CODE_END(startup_xen) __FINIT
Signature · 1 line
2.35.3
From ff35bc33c5ee184868d41bf76dcc7322191f9fd3 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Wed, 22 Jun 2022 12:17:47 +0200
Subject: [PATCH 2/2] x86: fix setup of brk area
Commit e32683c6f7d2 ("x86/mm: Fix RESERVE_BRK() for older binutils") put the brk area into the .bss segment, causing it not to be cleared initially. As the brk area is used to allocate early page tables, these might contain garbage in not explicitly written entries.
Fix that by letting clear_bss() clear the brk area, too.
--- arch/x86/kernel/head64.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kernel/head64.c +2 -0
@@ -430,6 +430,8 @@ void __init clear_bss(void) {memset (__bss_start,0 , (unsigned long ) __bss_stop - (unsigned long ) __bss_start); +memset (__brk_base,0 , + (unsigned long ) __brk_limit - (unsigned long ) __brk_base); }static unsigned long get_cmd_line_ptr (void )
Signature · 1 line
2.35.3
Quoted 1 line · Juergen Gross
Julien,
Hi Juergen,
Quoted 1 line
could you please test the attached patches?
I am getting the following error:
(XEN) d0v0 Unhandled: vec 14, #PF[0003] (XEN) Pagetable walk from ffffffff84001000:
(XEN) L4[0x1ff] = 000000046c004067 0000000000004004 (XEN) L3[0x1fe] = 000000046c003067 0000000000004003 (XEN) L2[0x020] = 000000046c024067 0000000000004024 (XEN) L1[0x001] = 001000046c001025 0000000000004001
(XEN) domain_crash_sync called from entry.S: fault at ffff82d040325906 x86_64/entry.S#create_bounce_frame+0x15d/0x177 (XEN) Domain 0 (vcpu#0) crashed on cpu#1:
(XEN) ----[ Xen-4.17-unstable x86_64 debug=y Tainted: C ]----
(XEN) CPU: 1
(XEN) RIP: e033:[<ffffffff832a3481>]
(XEN) RFLAGS: 0000000000000206 EM: 1 CONTEXT: pv guest (d0v0)
(XEN) rax: 0000000000000000 rbx: ffffffff84000000 rcx: 000000000002b000 (XEN) rdx: ffffffff84000000 rsi: ffffffff84000000 rdi: ffffffff84001000 (XEN) rbp: 0000000000000000 rsp: ffffffff82a03e60 r8: 0000000000000000 (XEN) r9: 0000000000000000 r10: 0000000000000000 r11: 0000000000000000 (XEN) r12: 0000000000000000 r13: 0000000000000000 r14: 0000000000000000 (XEN) r15: 0000000000000000 cr0: 0000000080050033 cr4: 00000000003426e0 (XEN) cr3: 000000046c001000 cr2: ffffffff84001000 (XEN) fsb: 0000000000000000 gsb: ffffffff83271000 gss: 0000000000000000 (XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: e02b cs: e033 (XEN) Guest stack trace from rsp=ffffffff82a03e60: (XEN) 000000000002b000 0000000000000000 0000000000000003 ffffffff832a3481 (XEN) 000000010000e030 0000000000010006 ffffffff82a03ea8 000000000000e02b (XEN) 0000000000000000 ffffffff832ae884 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 ffffffff832a317f 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN) Hardware Dom0 crashed: rebooting machine in 5 seconds.
Cheers,
Signature · 1 line
Julien Grall
Juergen Gross
maintainerQuoted 9 lines · Julien Grall
Quoted 1 line · Juergen Gross
Julien,
Hi Juergen,
Quoted 1 line
could you please test the attached patches?
Quoted 8 lines
I am getting the following error:
(XEN) d0v0 Unhandled: vec 14, #PF[0003] (XEN) Pagetable walk from
ffffffff84001000:
(XEN) L4[0x1ff] =000000046c0040670000000000004004 (XEN) L3[0x1fe] =000000046c0030670000000000004003 (XEN) L2[0x020] =000000046c0240670000000000004024 (XEN) L1[0x001] =001000046c0010250000000000004001
Hmm, from this data I guess this was a write to a page table.
Quoted 5 lines
(XEN)
domain_crash_synccalled fromentry.S: fault atffff82d040325906x86_64/entry.S#create_bounce_frame+0x15d/0x177 (XEN) Domain 0 (vcpu#0) crashed on cpu#1:
(XEN) ----[ Xen-4.17-unstable x86_64 debug=y Tainted: C ]----
(XEN) CPU: 1
(XEN) RIP: e033:[<ffffffff832a3481>]
Can you please find out the associated statement?
Quoted 11 lines
(XEN) RFLAGS: 0000000000000206 EM: 1 CONTEXT: pv guest (d0v0) (XEN) rax: 0000000000000000 rbx: ffffffff84000000 rcx:
000000000002b000(XEN) rdx: ffffffff84000000 rsi: ffffffff84000000 rdi:ffffffff84001000(XEN) rbp: 0000000000000000 rsp: ffffffff82a03e60 r8: 0000000000000000 (XEN) r9: 0000000000000000 r10: 0000000000000000 r11: 0000000000000000 (XEN) r12: 0000000000000000 r13: 0000000000000000 r14: 0000000000000000 (XEN) r15: 0000000000000000 cr0: 0000000080050033 cr4:00000000003426e0(XEN) cr3: 000000046c001000 cr2:ffffffff84001000
(XEN) fsb: 0000000000000000 gsb: ffffffff83271000 gss: 0000000000000000 (XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: e02b cs: e033 (XEN) Guest stack trace from rsp=ffffffff82a03e60:
Quoted 8 lines
(XEN)
000000000002b0000000000000000000 0000000000000003ffffffff832a3481(XEN)000000010000e0300000000000010006ffffffff82a03ea8000000000000e02b(XEN) 0000000000000000ffffffff832ae8840000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000ffffffff832a317f0000000000000000
Further analysis might be easier if you can supply function + displacement for any text segment addresses on the stack.
BTW, I could boot the kernel with my patches as Dom0 without any problem. OTOH it booted even without the patches. :-)
Juergen
Hi Juergen,
Quoted 21 lines · Juergen Gross
Quoted 9 lines · Julien Grall
Quoted 1 line · Juergen Gross
Julien,
Hi Juergen,
Quoted 1 line
could you please test the attached patches?
Quoted 8 lines
I am getting the following error:
(XEN) d0v0 Unhandled: vec 14, #PF[0003] (XEN) Pagetable walk from
ffffffff84001000:
(XEN) L4[0x1ff] =000000046c0040670000000000004004 (XEN) L3[0x1fe] =000000046c0030670000000000004003 (XEN) L2[0x020] =000000046c0240670000000000004024 (XEN) L1[0x001] =001000046c0010250000000000004001Hmm, from this data I guess this was a write to a page table.
Quoted 7 lines
Quoted 5 lines
(XEN)
domain_crash_synccalled fromentry.S: fault atffff82d040325906x86_64/entry.S#create_bounce_frame+0x15d/0x177 (XEN) Domain 0 (vcpu#0) crashed on cpu#1:
(XEN) ----[ Xen-4.17-unstable x86_64 debug=y Tainted: C ]----
(XEN) CPU: 1
(XEN) RIP: e033:[<ffffffff832a3481>]Can you please find out the associated statement?
arch/x86/kernel/head64.c:433
This is the memset() for __brk_base.
Quoted 21 lines
Quoted 12 lines
(XEN) RFLAGS: 0000000000000206 EM: 1 CONTEXT: pv guest (d0v0) (XEN) rax: 0000000000000000 rbx: ffffffff84000000 rcx:
000000000002b000(XEN) rdx: ffffffff84000000 rsi: ffffffff84000000 rdi:ffffffff84001000(XEN) rbp: 0000000000000000 rsp: ffffffff82a03e60 r8: 0000000000000000 (XEN) r9: 0000000000000000 r10: 0000000000000000 r11: 0000000000000000 (XEN) r12: 0000000000000000 r13: 0000000000000000 r14: 0000000000000000 (XEN) r15: 0000000000000000 cr0: 0000000080050033 cr4:00000000003426e0(XEN) cr3: 000000046c001000 cr2:ffffffff84001000
(XEN) fsb: 0000000000000000 gsb: ffffffff83271000 gss: 0000000000000000 (XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: e02b cs: e033 (XEN) Guest stack trace from rsp=ffffffff82a03e60:Quoted 8 lines
(XEN)
000000000002b0000000000000000000 0000000000000003ffffffff832a3481(XEN)000000010000e0300000000000010006ffffffff82a03ea8000000000000e02b(XEN) 0000000000000000ffffffff832ae8840000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000ffffffff832a317f0000000000000000
Quoted 2 lines
Further analysis might be easier if you can supply function + displacement for any text segment addresses on the stack.
ffffffff832ae884: arch/x86/include/asm/text-patching.h:112ffffffff832a317f: arch/x86/kernel/head64.c:325
Quoted 3 lines
BTW, I could boot the kernel with my patches as Dom0 without any problem. OTOH it booted even without the patches. :-)
So I have tried with two different compilers (GCC 7.3.1 and GCC 10.2.1) and hit the same error. This would suggest this is related to my .config. You can find it in [1] if you want to reproduce it yourself.
Cheers,
[1] https://pastebin.com/xityGDN9
Signature · 1 line
Julien Grall
Juergen Gross
maintainerQuoted 30 lines · Julien Grall
Hi Juergen,
Quoted 27 lines · Juergen Gross
Quoted 9 lines · Julien Grall
Quoted 1 line · Juergen Gross
Julien,
Hi Juergen,
Quoted 1 line
could you please test the attached patches?
Quoted 8 lines
I am getting the following error:
(XEN) d0v0 Unhandled: vec 14, #PF[0003] (XEN) Pagetable walk from
ffffffff84001000:
(XEN) L4[0x1ff] =000000046c0040670000000000004004 (XEN) L3[0x1fe] =000000046c0030670000000000004003 (XEN) L2[0x020] =000000046c0240670000000000004024 (XEN) L1[0x001] =001000046c0010250000000000004001Hmm, from this data I guess this was a write to a page table.
Quoted 5 lines
(XEN)
domain_crash_synccalled fromentry.S: fault atffff82d040325906x86_64/entry.S#create_bounce_frame+0x15d/0x177 (XEN) Domain 0 (vcpu#0) crashed on cpu#1:
(XEN) ----[ Xen-4.17-unstable x86_64 debug=y Tainted: C ]----
(XEN) CPU: 1
(XEN) RIP: e033:[<ffffffff832a3481>]
Quoted 5 lines
Quoted 1 line
Can you please find out the associated statement?
arch/x86/kernel/head64.c:433This is the
memset()for__brk_base.
Very weird.
In the kernel's linker script we have:
__end_of_kernel_reserve = .;
. = ALIGN(PAGE_SIZE);
.brk (NOLOAD) : AT(ADDR(.brk) - LOAD_OFFSET) {
__brk_base = .;
. += 64 * 1024; /* 64k alignment slop space */
*(.bss..brk) /* areas brk users have reserved */
__brk_limit = .;
}
. = ALIGN(PAGE_SIZE); /* keep VO_INIT_SIZE page aligned */
_end = .;So the area to be zeroed should be larger than 64k.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(XEN) RFLAGS: 0000000000000206 EM: 1 CONTEXT: pv guest (d0v0) (XEN) rax: 0000000000000000 rbx: ffffffff84000000 rcx:
000000000002b000(XEN) rdx: ffffffff84000000 rsi: ffffffff84000000 rdi:ffffffff84001000
Just guessing I'd say that memset started at ffffffff84000000 and there are 2b000 bytes left to be cleared. A disassembly of clear_bss() would help here.
Anyway it seems as if the memset would run right into the initial page tables supplied by the hypervisor.
Can you please post the hypervisor's console messages regarding dom0 sizes and locations?
Could it be that the brk area is the last section relevant for loading the kernel? In contrast to your .config, I have CONFIG_AMD_MEM_ENCRYPT defined and this adds the .init.scratch section after the brk area. Maybe the hypervisor is not adjusting the page table location correctly due to the NOLOAD attribute of brk?
Juergen