From: "Huang, Kai" <kai.huang@intel.com>
To: "kirill.shutemov@linux.intel.com" <kirill.shutemov@linux.intel.com>
Cc: "ardb@kernel.org" <ardb@kernel.org>,
"luto@kernel.org" <luto@kernel.org>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"thomas.lendacky@amd.com" <thomas.lendacky@amd.com>,
"tzimmermann@suse.de" <tzimmermann@suse.de>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"seanjc@google.com" <seanjc@google.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"bhe@redhat.com" <bhe@redhat.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"hpa@zytor.com" <hpa@zytor.com>,
"peterz@infradead.org" <peterz@infradead.org>,
"bp@alien8.de" <bp@alien8.de>,
"rafael@kernel.org" <rafael@kernel.org>,
"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
"x86@kernel.org" <x86@kernel.org>
Subject: Re: [PATCH 3/3] x86/64/kexec: Rewrite init_transition_pgtable() with kernel_ident_mapping_init()
Date: Fri, 5 Jul 2024 10:35:52 +0000 [thread overview]
Message-ID: <50ceccb8039847c253b68c59af0ceaa5e04eefb4.camel@intel.com> (raw)
In-Reply-To: <vyvbvham7qcj2pnotfn4mocozx6x33zkvuks63w3ymzk4w6sjc@2gk5xbtb5xrb>
On Thu, 2024-07-04 at 16:44 +0300, kirill.shutemov@linux.intel.com wrote:
> On Wed, Jul 03, 2024 at 11:06:21AM +0000, Huang, Kai wrote:
> > > static int init_transition_pgtable(struct kimage *image, pgd_t *pgd)
> > > {
> > > - pgprot_t prot = PAGE_KERNEL_EXEC_NOENC;
> > > - unsigned long vaddr, paddr;
> > > - int result = -ENOMEM;
> > > - p4d_t *p4d;
> > > - pud_t *pud;
> > > - pmd_t *pmd;
> > > - pte_t *pte;
> > > + struct x86_mapping_info info = {
> > > + .alloc_pgt_page = alloc_transition_pgt_page,
> > > + .context = image,
> > > + .page_flag = __PAGE_KERNEL_LARGE_EXEC,
> > > + .kernpg_flag = _KERNPG_TABLE_NOENC,
> > > + .offset = __START_KERNEL_map - phys_base,
> > > + };
> > > + unsigned long mstart = PAGE_ALIGN_DOWN(__pa(relocate_kernel));
> > > + unsigned long mend = mstart + PAGE_SIZE;
> > >
> > > - vaddr = (unsigned long)relocate_kernel;
> > > - paddr = __pa(page_address(image->control_code_page)+PAGE_SIZE);
> >
> > Perhaps I am missing something, but this seems a functional change to me.
> >
> > IIUC the page after image->control_code_page is allocated when loading the
> > kexec kernel image. It is a different page from the page where the
> > relocate_kernel code resides in.
> >
> > The old code maps relocate_kernel kernel VA to the page after the
> > control_code_page. Later in machine_kexec(), the relocate_kernel code is
> > copied to that page so the mapping can work for that:
> >
> > control_page = page_address(image->control_code_page) + PAGE_SIZE;
> > __memcpy(control_page, relocate_kernel,
> > KEXEC_CONTROL_CODE_MAX_SIZE);
> >
> > The new code in this patch, however, seems just maps the relocate_kernel VA
> > to the PA of the relocate_kernel, which should be different from the old
> > mapping.
>
> Yes, original code maps at relocate_kernel() VA the page with copy of the
> relocate_kernel() in control_code_page. But it is safe to map original
> relocate_kernel() page there as well as it is not going to be overwritten
> until swap_pages(). We are not going to use original relocate_kernel()
> page after RET at the end of relocate_kernel().
I am not super familiar with this, but this doesn't seem 100% safe to me.
E.g, did you consider the kexec jump case?
The second half of control page is also used to store registers in kexec
jump. If the relocate_kernel VA isn't mapped to the control page, then IIUC
after jumping back to old kernel it seems we won't be able to read those
registers back?
>
> Does it make any sense?
>
> I will try to explain it in the commit message in the next version.
>
I think even it's safe to change to map to the relocate_kernel() page, it
should be done in a separate patch. This patch should just focus on removing
the duplicated page table setup code.
prev parent reply other threads:[~2024-07-05 10:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-01 12:43 [PATCH 0/3] x86: Reduce code duplication on page table initialization Kirill A. Shutemov
2024-07-01 12:43 ` [PATCH 1/3] x86/mm/ident_map: Fix virtual address wrap to zero Kirill A. Shutemov
2024-07-03 10:11 ` Huang, Kai
2024-07-01 12:43 ` [PATCH 2/3] x86/acpi: Replace manual page table initialization with kernel_ident_mapping_init() Kirill A. Shutemov
2024-07-03 10:23 ` Huang, Kai
2024-07-01 12:43 ` [PATCH 3/3] x86/64/kexec: Rewrite init_transition_pgtable() " Kirill A. Shutemov
2024-07-03 11:06 ` Huang, Kai
2024-07-04 13:44 ` kirill.shutemov
2024-07-05 10:35 ` Huang, Kai [this message]
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=50ceccb8039847c253b68c59af0ceaa5e04eefb4.camel@intel.com \
--to=kai.huang@intel.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=tzimmermann@suse.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