Borislav Petkov
2020-May-13 11:13 UTC
[PATCH v3 24/75] x86/boot/compressed/64: Unmap GHCB page before booting the kernel
On Tue, Apr 28, 2020 at 05:16:34PM +0200, Joerg Roedel wrote:> @@ -302,9 +313,13 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code) > * - User faults > * - Reserved bits set > */ > - if (error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) { > + if (ghcb_fault || > + error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) { > /* Print some information for debugging */ > - error_putstr("Unexpected page-fault:"); > + if (ghcb_fault) > + error_putstr("Page-fault on GHCB page:"); > + else > + error_putstr("Unexpected page-fault:");You could carve out the info dumping into a separate function to unclutter this if-statement (diff ontop): diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c index d3771d455249..c1979fc0f853 100644 --- a/arch/x86/boot/compressed/ident_map_64.c +++ b/arch/x86/boot/compressed/ident_map_64.c @@ -296,6 +296,22 @@ int set_page_non_present(unsigned long address) return set_clr_page_flags(&mapping_info, address, 0, _PAGE_PRESENT); } +static void do_pf_error(const char *msg, unsigned long error_code, + unsigned long address, unsigned long ip) +{ + error_putstr(msg); + + error_putstr("\nError Code: "); + error_puthex(error_code); + error_putstr("\nCR2: 0x"); + error_puthex(address); + error_putstr("\nRIP relative to _head: 0x"); + error_puthex(ip - (unsigned long)_head); + error_putstr("\n"); + + error("Stopping.\n"); +} + void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code) { unsigned long address = native_read_cr2(); @@ -309,27 +325,15 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code) /* * Check for unexpected error codes. Unexpected are: + * - Faults on the GHCB page due to unexpected #VCs * - Faults on present pages * - User faults * - Reserved bits set */ - if (ghcb_fault || - error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) { - /* Print some information for debugging */ - if (ghcb_fault) - error_putstr("Page-fault on GHCB page:"); - else - error_putstr("Unexpected page-fault:"); - error_putstr("\nError Code: "); - error_puthex(error_code); - error_putstr("\nCR2: 0x"); - error_puthex(address); - error_putstr("\nRIP relative to _head: 0x"); - error_puthex(regs->ip - (unsigned long)_head); - error_putstr("\n"); - - error("Stopping.\n"); - } + if (ghcb_fault) + do_pf_error("Page-fault on GHCB page:", error_code, address, regs->ip); + else if (error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) + do_pf_error("Unexpected page-fault:", error_code, address, regs->ip); /* * Error code is sane - now identity map the 2M region around -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Joerg Roedel
2020-May-13 11:30 UTC
[PATCH v3 24/75] x86/boot/compressed/64: Unmap GHCB page before booting the kernel
On Wed, May 13, 2020 at 01:13:40PM +0200, Borislav Petkov wrote:> On Tue, Apr 28, 2020 at 05:16:34PM +0200, Joerg Roedel wrote: > > @@ -302,9 +313,13 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code) > > * - User faults > > * - Reserved bits set > > */ > > - if (error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) { > > + if (ghcb_fault || > > + error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) { > > /* Print some information for debugging */ > > - error_putstr("Unexpected page-fault:"); > > + if (ghcb_fault) > > + error_putstr("Page-fault on GHCB page:"); > > + else > > + error_putstr("Unexpected page-fault:"); > > You could carve out the info dumping into a separate function to > unclutter this if-statement (diff ontop):Yeah, I had this this way in v2, but changed it upon you request[1] :) Joerg [1] https://lore.kernel.org/lkml/20200402114941.GA9352 at zn.tnic/
Borislav Petkov
2020-May-13 11:46 UTC
[PATCH v3 24/75] x86/boot/compressed/64: Unmap GHCB page before booting the kernel
On Wed, May 13, 2020 at 01:30:11PM +0200, Joerg Roedel wrote:> Yeah, I had this this way in v2, but changed it upon you request[1] :)Yeah, I was wondering why this isn't a separate function - you like them so much. :-P> [1] https://lore.kernel.org/lkml/20200402114941.GA9352 at zn.tnic/But that one didn't have the ghcb_fault check. Maybe it was being added later... :) Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Possibly Parallel Threads
- [PATCH v3 24/75] x86/boot/compressed/64: Unmap GHCB page before booting the kernel
- [PATCH v3 24/75] x86/boot/compressed/64: Unmap GHCB page before booting the kernel
- [PATCH v3 24/75] x86/boot/compressed/64: Unmap GHCB page before booting the kernel
- [PATCH v3 24/75] x86/boot/compressed/64: Unmap GHCB page before booting the kernel
- [PATCH v4 14/75] x86/boot/compressed/64: Add page-fault handler