From: Anup Patel <anup@brainfault.org>
To: Logan Gunthorpe <logang@deltatee.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>,
Palmer Dabbelt <palmer@sifive.com>,
"linux-kernel@vger.kernel.org List"
<linux-kernel@vger.kernel.org>,
Stephen Bates <sbates@raithlin.com>,
Atish Patra <atish.patra@wdc.com>,
Anup Patel <anup.patel@wdc.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
linux-riscv@lists.infradead.org,
Mike Rapoport <rppt@linux.ibm.com>,
Christoph Hellwig <hch@lst.de>, Zong Li <zongbox@gmail.com>
Subject: Re: [PATCH 4/7] RISC-V: Update page tables to cover the whole linear mapping
Date: Thu, 28 Mar 2019 15:33:52 +0530 [thread overview]
Message-ID: <CAAhSdy0rZCNG4582gCd2wJ9zWwRZJ8uohPLs91=Ww=+=JnG4=w@mail.gmail.com> (raw)
In-Reply-To: <20190327213643.23789-5-logang@deltatee.com>
On Thu, Mar 28, 2019 at 3:06 AM Logan Gunthorpe <logang@deltatee.com> wrote:
>
> With the new virtual address changes in an earlier patch, we want the
> page tables to cover more of the linear mapping region. Instead of
> only mapping from PAGE_OFFSET and up, we instead map starting
> from an aligned version of va_pa_offset such that all of the physical
> address space will be mapped.
>
> Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
> Cc: Palmer Dabbelt <palmer@sifive.com>
> Cc: Albert Ou <aou@eecs.berkeley.edu>
> Cc: Anup Patel <anup.patel@wdc.com>
> Cc: Atish Patra <atish.patra@wdc.com>
> Cc: Paul Walmsley <paul.walmsley@sifive.com>
> Cc: Zong Li <zongbox@gmail.com>
> Cc: Mike Rapoport <rppt@linux.ibm.com>
> ---
> arch/riscv/kernel/setup.c | 1 -
> arch/riscv/mm/init.c | 27 +++++++++++++++------------
> 2 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index ecb654f6a79e..8286df8be31a 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -59,7 +59,6 @@ EXPORT_SYMBOL(empty_zero_page);
> /* The lucky hart to first increment this variable will boot the other cores */
> atomic_t hart_lottery;
> unsigned long boot_cpu_hartid;
> -
> void __init parse_dtb(unsigned int hartid, void *dtb)
> {
> if (early_init_dt_scan(__va(dtb)))
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index b9d50031e78f..315194557c3d 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -150,8 +150,8 @@ pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
> pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
>
> #ifndef __PAGETABLE_PMD_FOLDED
> -#define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT)
> -pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss;
> +#define NUM_SWAPPER_PMDS ((uintptr_t)-VMALLOC_END >> PGDIR_SHIFT)
> +pmd_t swapper_pmd[PTRS_PER_PMD*((-VMALLOC_END)/PGDIR_SIZE)] __page_aligned_bss;
> pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
> pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
> #endif
> @@ -180,13 +180,18 @@ asmlinkage void __init setup_vm(void)
> extern char _start;
> uintptr_t i;
> uintptr_t pa = (uintptr_t) &_start;
> + uintptr_t linear_start;
> + uintptr_t off;
> pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC);
>
> va_pa_offset = PAGE_OFFSET - pa;
> pfn_base = PFN_DOWN(pa);
>
> + linear_start = ALIGN_DOWN(va_pa_offset, PGDIR_SIZE);
> + off = linear_start - va_pa_offset;
> +
> /* Sanity check alignment and size */
> - BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
> + BUG_ON(linear_start <= VMALLOC_END);
> BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0);
>
> #ifndef __PAGETABLE_PMD_FOLDED
> @@ -195,15 +200,14 @@ asmlinkage void __init setup_vm(void)
> __pgprot(_PAGE_TABLE));
> trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot);
>
> - for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
> - size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
> -
> + for (i = 0; i < (-linear_start)/PGDIR_SIZE; ++i) {
> + size_t o = (linear_start >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
> swapper_pg_dir[o] =
> pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i,
> __pgprot(_PAGE_TABLE));
> }
> for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++)
> - swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot);
> + swapper_pmd[i] = pfn_pmd(PFN_DOWN(off + i * PMD_SIZE), prot);
>
> swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] =
> pfn_pgd(PFN_DOWN((uintptr_t)fixmap_pmd),
> @@ -215,11 +219,10 @@ asmlinkage void __init setup_vm(void)
> trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
> pfn_pgd(PFN_DOWN(pa), prot);
>
> - for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
> - size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
> -
> - swapper_pg_dir[o] =
> - pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot);
> + for (i = 0; i < (-linear_start)/PGDIR_SIZE; ++i) {
> + size_t o = (linear_start >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
> + swapper_pg_dir[o] = pfn_pgd(PFN_DOWN(off + i * PGDIR_SIZE),
> + prot);
> }
>
> swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] =
> --
> 2.20.1
>
I understand that this patch is inline with your virtual memory layout cleanup
but the way we map virtual memory in swapper_pg_dir is bound to change.
We should not be mapping complete virtual memory in swapper_pd_dir()
rather we should only map based on amount of RAM available.
Refer, https://www.lkml.org/lkml/2019/3/24/3
The setup_vm() should only map vmlinux_start to vmlinux_end plus the
FDT. Complete virtual memory mapping should be done after we have
done early parsing of FDT when we know available memory banks in
setup_vm_final() (called from paging_init())
Regards,
Anup
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2019-03-28 10:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-27 21:36 [PATCH 0/7] RISC-V: Sparsmem, Memory Hotplug and pte_devmap for P2P Logan Gunthorpe
2019-03-27 21:36 ` [PATCH 1/7] RISC-V: Implement sparsemem Logan Gunthorpe
2019-03-27 21:36 ` [PATCH 2/7] RISC-V: doc: Add file describing the virtual memory map Logan Gunthorpe
2019-03-28 11:49 ` Mike Rapoport
2019-03-28 15:51 ` Logan Gunthorpe
2019-03-27 21:36 ` [PATCH 3/7] RISC-V: Rework kernel's virtual address space mapping Logan Gunthorpe
2019-03-28 5:39 ` Palmer Dabbelt
2019-03-28 6:28 ` Anup Patel
2019-03-28 15:54 ` Logan Gunthorpe
2019-03-27 21:36 ` [PATCH 4/7] RISC-V: Update page tables to cover the whole linear mapping Logan Gunthorpe
2019-03-28 10:03 ` Anup Patel [this message]
2019-03-28 18:24 ` Logan Gunthorpe
2019-03-27 21:36 ` [PATCH 5/7] RISC-V: Implement memory hotplug Logan Gunthorpe
2019-03-27 21:36 ` [PATCH 6/7] RISC-V: Implement memory hot remove Logan Gunthorpe
2019-03-27 21:36 ` [PATCH 7/7] RISC-V: Implement pte_devmap() Logan Gunthorpe
2019-04-24 23:23 ` [PATCH 0/7] RISC-V: Sparsmem, Memory Hotplug and pte_devmap for P2P Palmer Dabbelt
2019-04-26 16:37 ` Logan Gunthorpe
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='CAAhSdy0rZCNG4582gCd2wJ9zWwRZJ8uohPLs91=Ww=+=JnG4=w@mail.gmail.com' \
--to=anup@brainfault.org \
--cc=anup.patel@wdc.com \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@wdc.com \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=logang@deltatee.com \
--cc=palmer@sifive.com \
--cc=paul.walmsley@sifive.com \
--cc=rppt@linux.ibm.com \
--cc=sbates@raithlin.com \
--cc=zongbox@gmail.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).