From: Pingfan Liu <kernelfans@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Pingfan Liu <kernelfans@gmail.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Ard Biesheuvel <ardb@kernel.org>,
Marc Zyngier <maz@kernel.org>,
Kristina Martsenko <kristina.martsenko@arm.com>,
James Morse <james.morse@arm.com>,
Steven Price <steven.price@arm.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Pavel Tatashin <pasha.tatashin@soleen.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Atish Patra <atish.patra@wdc.com>,
Mike Rapoport <rppt@kernel.org>,
Logan Gunthorpe <logang@deltatee.com>,
Mark Brown <broonie@kernel.org>
Subject: [PATCHv3 4/5] arm64/mm: make __create_pgd_mapping() capable to handle pgtable's paddr
Date: Mon, 31 May 2021 04:45:39 -0400 [thread overview]
Message-ID: <20210531084540.78546-5-kernelfans@gmail.com> (raw)
In-Reply-To: <20210531084540.78546-1-kernelfans@gmail.com>
This patch is the last preparation for calling __create_pgd_mapping()
from head.S.
Under mmu-offset situation, __create_pgd_mapping() handles paddr of each
pgtable level. All of pud_t */pmd_t */pte_t * points to paddr, and they
should be handled carefully to avoid the involvement of __va().
Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Kristina Martsenko <kristina.martsenko@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Steven Price <steven.price@arm.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Atish Patra <atish.patra@wdc.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Logan Gunthorpe <logang@deltatee.com>
Cc: Mark Brown <broonie@kernel.org>
To: linux-arm-kernel@lists.infradead.org
---
arch/arm64/mm/mmu.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index fe16f235d1fa..5f717552b524 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -189,6 +189,12 @@ static void init_pte(pmd_t *pmdp, unsigned long addr, unsigned long end,
pte_t *ptep;
ptep = pte_set_fixmap_offset(pmdp, addr);
+ if (likely(!(flags & BOOT_HEAD)))
+ ptep = pte_set_fixmap_offset(pmdp, addr);
+ else
+ /* for head.S, there is no __va() */
+ ptep = (pte_t *)__pmd_to_phys(*pmdp) + pte_index(addr);
+
do {
pte_t old_pte = READ_ONCE(*ptep);
@@ -204,7 +210,8 @@ static void init_pte(pmd_t *pmdp, unsigned long addr, unsigned long end,
phys += PAGE_SIZE;
} while (ptep++, addr += PAGE_SIZE, addr != end);
- pte_clear_fixmap();
+ if (likely(!(flags & BOOT_HEAD)))
+ pte_clear_fixmap();
}
static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr,
@@ -253,7 +260,17 @@ static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end,
unsigned long next;
pmd_t *pmdp;
- pmdp = pmd_set_fixmap_offset(pudp, addr);
+ if (likely(!(flags & BOOT_HEAD))) {
+ pmdp = pmd_set_fixmap_offset(pudp, addr);
+ } else {
+#if CONFIG_PGTABLE_LEVELS > 2
+ /* for head.S, there is no __va() */
+ pmdp = (pmd_t *)__pud_to_phys(*pudp) + pmd_index(addr);
+#else
+ pmdp = (pmd_t *)pudp;
+#endif
+ }
+
do {
pmd_t old_pmd = READ_ONCE(*pmdp);
@@ -280,7 +297,8 @@ static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end,
phys += next - addr;
} while (pmdp++, addr = next, addr != end);
- pmd_clear_fixmap();
+ if (likely(!(flags & BOOT_HEAD)))
+ pmd_clear_fixmap();
}
static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr,
@@ -359,7 +377,17 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end,
}
SAFE_BUG_ON(flags, p4d_bad(p4d));
- pudp = pud_set_fixmap_offset(p4dp, addr);
+ if (likely(!(flags & BOOT_HEAD))) {
+ pudp = pud_set_fixmap_offset(p4dp, addr);
+ } else {
+#if CONFIG_PGTABLE_LEVELS > 3
+ /* for head.S, there is no __va() */
+ pudp = (pud_t *)__p4d_to_phys(*p4dp) + pud_index(addr);
+#else
+ pudp = (pud_t *)p4dp;
+#endif
+ }
+
do {
pud_t old_pud = READ_ONCE(*pudp);
@@ -388,7 +416,8 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end,
phys += next - addr;
} while (pudp++, addr = next, addr != end);
- pud_clear_fixmap();
+ if (likely(!(flags & BOOT_HEAD)))
+ pud_clear_fixmap();
}
static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
--
2.29.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-05-31 8:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-31 8:45 [PATCHv3 0/5] use __create_pgd_mapping() to implement idmap and unify codes Pingfan Liu
2021-05-31 8:45 ` [PATCHv3 1/5] arm64/mm: introduce pgtable allocator for idmap_pg_dir and init_pg_dir Pingfan Liu
2021-05-31 8:45 ` [PATCHv3 2/5] arm64/mm: disable WARN_ON() and BUG_ON() in __create_pgd_mapping() if too early Pingfan Liu
2021-05-31 8:45 ` [PATCHv3 3/5] arm64/mm: unconditionally set IDMAP_PGTABLE_LEVELS to max pgtable level Pingfan Liu
2021-05-31 8:45 ` Pingfan Liu [this message]
2021-05-31 8:45 ` [PATCHv3 5/5] arm64/mm: use __create_pgd_mapping() to create pgtable for idmap_pg_dir and init_pg_dir Pingfan Liu
2021-05-31 19:50 ` [PATCHv3 0/5] use __create_pgd_mapping() to implement idmap and unify codes Ard Biesheuvel
2021-06-01 9:25 ` Pingfan Liu
2021-06-08 17:38 ` Catalin Marinas
2021-06-09 9:25 ` Pingfan Liu
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=20210531084540.78546-5-kernelfans@gmail.com \
--to=kernelfans@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=atish.patra@wdc.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=kristina.martsenko@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=logang@deltatee.com \
--cc=maz@kernel.org \
--cc=pasha.tatashin@soleen.com \
--cc=rppt@kernel.org \
--cc=steven.price@arm.com \
--cc=will@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;
as well as URLs for NNTP newsgroup(s).