From: Tom Lendacky <thomas.lendacky@amd.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
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>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Baoquan He <bhe@redhat.com>
Cc: Ard Biesheuvel <ardb@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Sean Christopherson <seanjc@google.com>,
linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
Kai Huang <kai.huang@intel.com>
Subject: Re: [PATCHv2 2/4] x86/acpi: Replace manual page table initialization with kernel_ident_mapping_init()
Date: Wed, 14 Aug 2024 10:55:29 -0500 [thread overview]
Message-ID: <5dd9f90a-604e-b52c-8679-b17d88e14ed5@amd.com> (raw)
In-Reply-To: <20240814124613.2632226-3-kirill.shutemov@linux.intel.com>
On 8/14/24 07:46, Kirill A. Shutemov wrote:
> The function init_transition_pgtable() maps the page with
> asm_acpi_mp_play_dead() into an identity mapping.
>
> Replace manual page table initialization with kernel_ident_mapping_init()
> to avoid code duplication. Use x86_mapping_info::offset to get the page
> mapped at the correct location.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Reviewed-by: Kai Huang <kai.huang@intel.com>
A bit confusing on the last change. You have to understand how
kernel_ident_mapping_init() works in regards to supplying an offset
value and how to set that offset value up properly to get the kernel VA
address into the identity map. Otherwise:
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
> arch/x86/kernel/acpi/madt_wakeup.c | 73 ++++++------------------------
> 1 file changed, 15 insertions(+), 58 deletions(-)
>
> diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c
> index d5ef6215583b..78960b338be9 100644
> --- a/arch/x86/kernel/acpi/madt_wakeup.c
> +++ b/arch/x86/kernel/acpi/madt_wakeup.c
> @@ -70,58 +70,6 @@ static void __init free_pgt_page(void *pgt, void *dummy)
> return memblock_free(pgt, PAGE_SIZE);
> }
>
> -/*
> - * Make sure asm_acpi_mp_play_dead() is present in the identity mapping at
> - * the same place as in the kernel page tables. asm_acpi_mp_play_dead() switches
> - * to the identity mapping and the function has be present at the same spot in
> - * the virtual address space before and after switching page tables.
> - */
> -static int __init init_transition_pgtable(pgd_t *pgd)
> -{
> - pgprot_t prot = PAGE_KERNEL_EXEC_NOENC;
> - unsigned long vaddr, paddr;
> - p4d_t *p4d;
> - pud_t *pud;
> - pmd_t *pmd;
> - pte_t *pte;
> -
> - vaddr = (unsigned long)asm_acpi_mp_play_dead;
> - pgd += pgd_index(vaddr);
> - if (!pgd_present(*pgd)) {
> - p4d = (p4d_t *)alloc_pgt_page(NULL);
> - if (!p4d)
> - return -ENOMEM;
> - set_pgd(pgd, __pgd(__pa(p4d) | _KERNPG_TABLE));
> - }
> - p4d = p4d_offset(pgd, vaddr);
> - if (!p4d_present(*p4d)) {
> - pud = (pud_t *)alloc_pgt_page(NULL);
> - if (!pud)
> - return -ENOMEM;
> - set_p4d(p4d, __p4d(__pa(pud) | _KERNPG_TABLE));
> - }
> - pud = pud_offset(p4d, vaddr);
> - if (!pud_present(*pud)) {
> - pmd = (pmd_t *)alloc_pgt_page(NULL);
> - if (!pmd)
> - return -ENOMEM;
> - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE));
> - }
> - pmd = pmd_offset(pud, vaddr);
> - if (!pmd_present(*pmd)) {
> - pte = (pte_t *)alloc_pgt_page(NULL);
> - if (!pte)
> - return -ENOMEM;
> - set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
> - }
> - pte = pte_offset_kernel(pmd, vaddr);
> -
> - paddr = __pa(vaddr);
> - set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, prot));
> -
> - return 0;
> -}
> -
> static int __init acpi_mp_setup_reset(u64 reset_vector)
> {
> struct x86_mapping_info info = {
> @@ -130,6 +78,7 @@ static int __init acpi_mp_setup_reset(u64 reset_vector)
> .page_flag = __PAGE_KERNEL_LARGE_EXEC,
> .kernpg_flag = _KERNPG_TABLE_NOENC,
> };
> + unsigned long mstart, mend;
> pgd_t *pgd;
>
> pgd = alloc_pgt_page(NULL);
> @@ -137,8 +86,6 @@ static int __init acpi_mp_setup_reset(u64 reset_vector)
> return -ENOMEM;
>
> for (int i = 0; i < nr_pfn_mapped; i++) {
> - unsigned long mstart, mend;
> -
> mstart = pfn_mapped[i].start << PAGE_SHIFT;
> mend = pfn_mapped[i].end << PAGE_SHIFT;
> if (kernel_ident_mapping_init(&info, pgd, mstart, mend)) {
> @@ -147,14 +94,24 @@ static int __init acpi_mp_setup_reset(u64 reset_vector)
> }
> }
>
> - if (kernel_ident_mapping_init(&info, pgd,
> - PAGE_ALIGN_DOWN(reset_vector),
> - PAGE_ALIGN(reset_vector + 1))) {
> + mstart = PAGE_ALIGN_DOWN(reset_vector);
> + mend = mstart + PAGE_SIZE;
> + if (kernel_ident_mapping_init(&info, pgd, mstart, mend)) {
> kernel_ident_mapping_free(&info, pgd);
> return -ENOMEM;
> }
>
> - if (init_transition_pgtable(pgd)) {
> + /*
> + * Make sure asm_acpi_mp_play_dead() is present in the identity mapping
> + * at the same place as in the kernel page tables.
> + * asm_acpi_mp_play_dead() switches to the identity mapping and the
> + * function has be present at the same spot in the virtual address space
> + * before and after switching page tables.
> + */
> + info.offset = __START_KERNEL_map - phys_base;
> + mstart = PAGE_ALIGN_DOWN(__pa(asm_acpi_mp_play_dead));
> + mend = mstart + PAGE_SIZE;
> + if (kernel_ident_mapping_init(&info, pgd, mstart, mend)) {
> kernel_ident_mapping_free(&info, pgd);
> return -ENOMEM;
> }
next prev parent reply other threads:[~2024-08-14 15:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 12:46 [PATCHv2 0/4] x86: Reduce code duplication on page table initialization Kirill A. Shutemov
2024-08-14 12:46 ` [PATCHv2 1/4] x86/mm/ident_map: Fix virtual address wrap to zero Kirill A. Shutemov
2024-08-14 14:22 ` Tom Lendacky
2024-08-14 19:25 ` Thomas Gleixner
2024-08-15 9:15 ` Kirill A. Shutemov
2024-08-15 10:57 ` Thomas Gleixner
2024-08-14 12:46 ` [PATCHv2 2/4] x86/acpi: Replace manual page table initialization with kernel_ident_mapping_init() Kirill A. Shutemov
2024-08-14 15:55 ` Tom Lendacky [this message]
2024-08-14 12:46 ` [PATCHv2 3/4] x86/64/kexec: Map original relocate_kernel() in init_transition_pgtable() Kirill A. Shutemov
2024-08-15 6:15 ` Baoquan He
2024-08-15 9:18 ` Kirill A. Shutemov
2024-08-14 12:46 ` [PATCHv2 4/4] x86/64/kexec: Rewrite init_transition_pgtable() with kernel_ident_mapping_init() Kirill A. Shutemov
2024-08-14 16:02 ` Tom Lendacky
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=5dd9f90a-604e-b52c-8679-b17d88e14ed5@amd.com \
--to=thomas.lendacky@amd.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=kai.huang@intel.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=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