mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: kexec@lists.infradead.org, "Schönherr, Jan H." <jschoenh@amazon.de>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,  Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Kai Huang <kai.huang@intel.com>,
	Nikolay Borisov <nik.borisov@suse.com>,
	 linux-kernel@vger.kernel.org, Simon Horman <horms@kernel.org>,
	Dave Young <dyoung@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	jpoimboe@kernel.org,  bsz@amazon.de
Subject: Re: [EXTERNAL] [RFC PATCH v3 01/20] x86/kexec: Ensure control_code_page is mapped in kexec page tables
Date: Mon, 25 Nov 2024 13:19:41 +0000	[thread overview]
Message-ID: <7f75150e9d5d358c8fdc38b591f99a252071fba0.camel@infradead.org> (raw)
In-Reply-To: <8b7cd35ab5fec39b80eda8d5907b641af14c3272.camel@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 1950 bytes --]

On Mon, 2024-11-25 at 10:29 +0000, David Woodhouse wrote:
> On Mon, 2024-11-25 at 09:54 +0000, David Woodhouse wrote:
> > From: David Woodhouse <dwmw@amazon.co.uk>
> > 
> > The control_code_page should be explicitly mapped into the identity
> > mapped page tables for the relocate_kernel environment. This only seems
> > to have worked by luck before, because it tended to be within the same
> > 2MiB or 1GiB large page already mapped for another reason.
> > 
> > A subsequent commit will reduce the control_code_page to a single 4KiB
> > page instead of a higher-order allocation, and seems to make it much
> > *less* likely that we get lucky with its placement. This leads to a
> > fault when relocate_kernel() first tries to access the page through its
> > identity-mapped virtual address.
> 
> This one is confusing me. Jan points out that it shouldn't be needed,
> because the control page should come from kernel memory and thus should
> be mapped anyway because the loop immediately below my added code adds
> *all* of the pfn_mapped[] ranges.

I think we understand this one now; it's because of PTI. So where the
identmap code in e.g. ident_p4d_init() calls set_pte(), set_pte() is
actually trying to write *both* the kernel and userspace copies of the
page table, which it expects to be in adjacent pages. But in this case
it's just scribbling over the end of the single 4KiB page that was
allocated for it.

This should suffice to mask the problem (testing now) but obviously it
isn't a great solution:

--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -213,7 +213,7 @@ static void *alloc_pgt_page(void *data)
        struct page *page;
        void *p = NULL;
 
-       page = kimage_alloc_control_pages(image, 0);
+       page = kimage_alloc_control_pages(image, 1);
        if (page) {
                p = page_address(page);
                clear_page(p);


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]

  reply	other threads:[~2024-11-25 13:19 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-25  9:54 [RFC PATCH v3 00/20] x86/kexec: Add exception handling for relocate_kernel and further yak-shaving David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 01/20] x86/kexec: Ensure control_code_page is mapped in kexec page tables David Woodhouse
2024-11-25 10:29   ` [EXTERNAL] " David Woodhouse
2024-11-25 13:19     ` David Woodhouse [this message]
2024-11-25 17:05       ` [RFC PATCH] x86/mm: Disable PTI for kernel_ident_mapping_init() David Woodhouse
2024-11-25 18:31         ` Dave Hansen
2024-11-25 18:53           ` David Woodhouse
2024-11-25 19:13             ` Dave Hansen
2024-11-25 19:36               ` David Woodhouse
2024-11-26 11:42               ` David Woodhouse
2024-11-26 15:49                 ` Dave Hansen
2024-11-26 16:09                   ` David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 02/20] x86/kexec: Restore GDT on return from preserve_context kexec David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 03/20] x86/kexec: Clean up and document register use in relocate_kernel_64.S David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 04/20] x86/kexec: Use named labels in swap_pages " David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 05/20] x86/kexec: Only swap pages for preserve_context mode David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 06/20] x86/kexec: Allocate PGD for x86_64 transition page tables separately David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 07/20] x86/kexec: Copy control page into place in machine_kexec_prepare() David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 08/20] x86/kexec: Invoke copy of relocate_kernel() instead of the original David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 09/20] x86/kexec: Move relocate_kernel to kernel .data section David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 10/20] x86/kexec: Add data section to relocate_kernel David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 11/20] x86/kexec: Drop page_list argument from relocate_kernel() David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 12/20] x86/kexec: Eliminate writes through kernel mapping of relocate_kernel page David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 13/20] x86/kexec: Clean up register usage in relocate_kernel() David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 14/20] x86/kexec: Mark relocate_kernel page as ROX instead of RWX David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 15/20] x86/kexec: Add CONFIG_KEXEC_DEBUG option David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 16/20] x86/kexec: Debugging support: load a GDT David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 17/20] x86/kexec: Debugging support: Load an IDT and basic exception entry points David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 18/20] x86/kexec: Debugging support: Dump registers on exception David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 19/20] x86/kexec: Add 8250 serial port output David Woodhouse
2024-11-25  9:54 ` [RFC PATCH v3 20/20] [DO NOT MERGE] x86/kexec: Add int3 in kexec path for testing David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7f75150e9d5d358c8fdc38b591f99a252071fba0.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=bp@alien8.de \
    --cc=bsz@amazon.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dyoung@redhat.com \
    --cc=horms@kernel.org \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@kernel.org \
    --cc=jschoenh@amazon.de \
    --cc=kai.huang@intel.com \
    --cc=kexec@lists.infradead.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®