From: Atish Patra <atish.patra@wdc.com>
To: linux-kernel@vger.kernel.org
Cc: Atish Patra <atish.patra@wdc.com>,
Anup Patel <anup.patel@wdc.com>, Ard Biesheuvel <ardb@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Greentime Hu <greentime.hu@sifive.com>,
Kees Cook <keescook@chromium.org>,
linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org,
Mark Rutland <mark.rutland@arm.com>,
Masahiro Yamada <masahiroy@kernel.org>,
Mike Rapoport <rppt@linux.ibm.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Will Deacon <will@kernel.org>, Zong Li <zong.li@sifive.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
linux-arm-kernel@lists.infradead.org
Subject: [RFT PATCH v3 3/9] RISC-V: Implement late mapping page table allocation functions
Date: Thu, 16 Jul 2020 16:40:58 -0700 [thread overview]
Message-ID: <20200716234104.29049-4-atish.patra@wdc.com> (raw)
In-Reply-To: <20200716234104.29049-1-atish.patra@wdc.com>
Currently, page table setup is done during setup_va_final where fixmap can
be used to create the temporary mappings. The physical frame is allocated
from memblock_alloc_* functions. However, this won't work if page table
mapping needs to be created for a different mm context (i.e. efi mm) at
a later point of time.
Use generic kernel page allocation function & macros for any mapping
after setup_vm_final.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
---
arch/riscv/mm/init.c | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 62c90161765f..9f3129c76985 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -209,6 +209,7 @@ pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
static bool mmu_enabled;
+static bool late_mapping;
#define MAX_EARLY_MAPPING_SIZE SZ_128M
@@ -233,7 +234,9 @@ void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
static pte_t *__init get_pte_virt(phys_addr_t pa)
{
- if (mmu_enabled) {
+ if (late_mapping)
+ return (pte_t *) __va(pa);
+ else if (mmu_enabled) {
clear_fixmap(FIX_PTE);
return (pte_t *)set_fixmap_offset(FIX_PTE, pa);
} else {
@@ -243,13 +246,19 @@ static pte_t *__init get_pte_virt(phys_addr_t pa)
static phys_addr_t __init alloc_pte(uintptr_t va)
{
+ unsigned long vaddr;
/*
* We only create PMD or PGD early mappings so we
* should never reach here with MMU disabled.
*/
BUG_ON(!mmu_enabled);
-
- return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE);
+ if (late_mapping) {
+ vaddr = __get_free_page(GFP_KERNEL);
+ if (!vaddr || !pgtable_pte_page_ctor(virt_to_page(vaddr)))
+ BUG();
+ return __pa(vaddr);
+ } else
+ return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE);
}
static void __init create_pte_mapping(pte_t *ptep,
@@ -278,7 +287,9 @@ pmd_t early_pmd[PTRS_PER_PMD * NUM_EARLY_PMDS] __initdata __aligned(PAGE_SIZE);
static pmd_t *__init get_pmd_virt(phys_addr_t pa)
{
- if (mmu_enabled) {
+ if (late_mapping)
+ return (pmd_t *) __va(pa);
+ else if (mmu_enabled) {
clear_fixmap(FIX_PMD);
return (pmd_t *)set_fixmap_offset(FIX_PMD, pa);
} else {
@@ -289,8 +300,13 @@ static pmd_t *__init get_pmd_virt(phys_addr_t pa)
static phys_addr_t __init alloc_pmd(uintptr_t va)
{
uintptr_t pmd_num;
+ unsigned long vaddr;
- if (mmu_enabled)
+ if (late_mapping) {
+ vaddr = __get_free_page(GFP_KERNEL);
+ BUG_ON(!vaddr);
+ return __pa(vaddr);
+ } else if (mmu_enabled)
return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE);
pmd_num = (va - PAGE_OFFSET) >> PGDIR_SHIFT;
@@ -528,6 +544,9 @@ static void __init setup_vm_final(void)
/* Move to swapper page table */
csr_write(CSR_SATP, PFN_DOWN(__pa_symbol(swapper_pg_dir)) | SATP_MODE);
local_flush_tlb_all();
+
+ /* generic page allocation function must be used to setup page table */
+ late_mapping = true;
}
#else
void *dtb_early_va __initdata;
--
2.24.0
next prev parent reply other threads:[~2020-07-16 23:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-16 23:40 [RFT PATCH v3 0/9] Add UEFI support for RISC-V Atish Patra
2020-07-16 23:40 ` [RFT PATCH v3 1/9] RISC-V: Move DT mapping outof fixmap Atish Patra
2020-07-17 6:32 ` Arnd Bergmann
2020-07-18 1:05 ` Atish Patra
2020-07-18 9:24 ` Arnd Bergmann
2020-07-21 4:18 ` Atish Patra
2020-07-21 8:57 ` Arnd Bergmann
2020-07-21 9:02 ` Ard Biesheuvel
2020-07-21 9:30 ` Anup Patel
2020-07-16 23:40 ` [RFT PATCH v3 2/9] RISC-V: Add early ioremap support Atish Patra
2020-07-16 23:40 ` Atish Patra [this message]
2020-07-16 23:40 ` [RFT PATCH v3 4/9] include: pe.h: Add RISC-V related PE definition Atish Patra
2020-07-16 23:41 ` [RFT PATCH v3 5/9] RISC-V: Add PE/COFF header for EFI stub Atish Patra
2020-07-16 23:41 ` [RFT PATCH v3 6/9] RISC-V: Add EFI stub support Atish Patra
2020-07-16 23:41 ` [RFT PATCH v3 7/9] efi: Rename arm-init to efi-init common for all arch Atish Patra
2020-07-16 23:41 ` [RFT PATCH v3 8/9] RISC-V: Add EFI runtime services Atish Patra
2020-07-16 23:41 ` [RFT PATCH v3 9/9] RISC-V: Add page table dump support for uefi Atish Patra
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=20200716234104.29049-4-atish.patra@wdc.com \
--to=atish.patra@wdc.com \
--cc=anup.patel@wdc.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=greentime.hu@sifive.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rppt@linux.ibm.com \
--cc=will@kernel.org \
--cc=xypron.glpk@gmx.de \
--cc=zong.li@sifive.com \
/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;
as well as URLs for NNTP newsgroup(s).