From: Dylan Jhong <dylan@andestech.com>
To: <paul.walmsley@sifive.com>, <palmer@dabbelt.com>,
<aou@eecs.berkeley.edu>, <ajones@ventanamicro.com>,
<alexghiti@rivosinc.com>, <anup@brainfault.org>,
<rppt@kernel.org>, <samuel@sholland.org>,
<panqinglin2020@iscas.ac.cn>, <sergey.matyukevich@syntacore.com>,
<maz@kernel.org>, <linux-riscv@lists.infradead.org>,
<conor.dooley@microchip.com>, <linux-kernel@vger.kernel.org>
Cc: <ycliang@andestech.com>, <x5710999x@gmail.com>,
<tim609@andestech.com>, Dylan Jhong <dylan@andestech.com>
Subject: [PATCH 1/1] riscv: Implement arch_sync_kernel_mappings() for "preventive" TLB flush
Date: Mon, 7 Aug 2023 16:23:05 +0800 [thread overview]
Message-ID: <20230807082305.198784-2-dylan@andestech.com> (raw)
In-Reply-To: <20230807082305.198784-1-dylan@andestech.com>
Since RISC-V is a microarchitecture that allows caching invalid entries in the TLB,
it is necessary to issue a "preventive" SFENCE.VMA to ensure that each core obtains
the correct kernel mapping.
The patch implements TLB flushing in arch_sync_kernel_mappings(), ensuring that kernel
page table mappings created via vmap/vmalloc() are updated before switching MM.
Signed-off-by: Dylan Jhong <dylan@andestech.com>
---
arch/riscv/include/asm/page.h | 2 ++
arch/riscv/mm/tlbflush.c | 12 ++++++++++++
2 files changed, 14 insertions(+)
diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
index b55ba20903ec..6c86ab69687e 100644
--- a/arch/riscv/include/asm/page.h
+++ b/arch/riscv/include/asm/page.h
@@ -21,6 +21,8 @@
#define HPAGE_MASK (~(HPAGE_SIZE - 1))
#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
+#define ARCH_PAGE_TABLE_SYNC_MASK PGTBL_PTE_MODIFIED
+
/*
* PAGE_OFFSET -- the first address of the first page of memory.
* When not using MMU this corresponds to the first free page in
diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
index 77be59aadc73..d63364948c85 100644
--- a/arch/riscv/mm/tlbflush.c
+++ b/arch/riscv/mm/tlbflush.c
@@ -149,3 +149,15 @@ void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start,
__flush_tlb_range(vma->vm_mm, start, end - start, PMD_SIZE);
}
#endif
+
+/*
+ * Since RISC-V is a microarchitecture that allows caching invalid entries in the TLB,
+ * it is necessary to issue a "preventive" SFENCE.VMA to ensure that each core obtains
+ * the correct kernel mapping. arch_sync_kernel_mappings() will ensure that kernel
+ * page table mappings created via vmap/vmalloc() are updated before switching MM.
+ */
+void arch_sync_kernel_mappings(unsigned long start, unsigned long end)
+{
+ if (start < VMALLOC_END && end > VMALLOC_START)
+ flush_tlb_all();
+}
\ No newline at end of file
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Dylan Jhong <dylan@andestech.com>
To: <paul.walmsley@sifive.com>, <palmer@dabbelt.com>,
<aou@eecs.berkeley.edu>, <ajones@ventanamicro.com>,
<alexghiti@rivosinc.com>, <anup@brainfault.org>,
<rppt@kernel.org>, <samuel@sholland.org>,
<panqinglin2020@iscas.ac.cn>, <sergey.matyukevich@syntacore.com>,
<maz@kernel.org>, <linux-riscv@lists.infradead.org>,
<conor.dooley@microchip.com>, <linux-kernel@vger.kernel.org>
Cc: <ycliang@andestech.com>, <x5710999x@gmail.com>,
<tim609@andestech.com>, Dylan Jhong <dylan@andestech.com>
Subject: [PATCH 1/1] riscv: Implement arch_sync_kernel_mappings() for "preventive" TLB flush
Date: Mon, 7 Aug 2023 16:23:05 +0800 [thread overview]
Message-ID: <20230807082305.198784-2-dylan@andestech.com> (raw)
In-Reply-To: <20230807082305.198784-1-dylan@andestech.com>
Since RISC-V is a microarchitecture that allows caching invalid entries in the TLB,
it is necessary to issue a "preventive" SFENCE.VMA to ensure that each core obtains
the correct kernel mapping.
The patch implements TLB flushing in arch_sync_kernel_mappings(), ensuring that kernel
page table mappings created via vmap/vmalloc() are updated before switching MM.
Signed-off-by: Dylan Jhong <dylan@andestech.com>
---
arch/riscv/include/asm/page.h | 2 ++
arch/riscv/mm/tlbflush.c | 12 ++++++++++++
2 files changed, 14 insertions(+)
diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
index b55ba20903ec..6c86ab69687e 100644
--- a/arch/riscv/include/asm/page.h
+++ b/arch/riscv/include/asm/page.h
@@ -21,6 +21,8 @@
#define HPAGE_MASK (~(HPAGE_SIZE - 1))
#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
+#define ARCH_PAGE_TABLE_SYNC_MASK PGTBL_PTE_MODIFIED
+
/*
* PAGE_OFFSET -- the first address of the first page of memory.
* When not using MMU this corresponds to the first free page in
diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
index 77be59aadc73..d63364948c85 100644
--- a/arch/riscv/mm/tlbflush.c
+++ b/arch/riscv/mm/tlbflush.c
@@ -149,3 +149,15 @@ void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start,
__flush_tlb_range(vma->vm_mm, start, end - start, PMD_SIZE);
}
#endif
+
+/*
+ * Since RISC-V is a microarchitecture that allows caching invalid entries in the TLB,
+ * it is necessary to issue a "preventive" SFENCE.VMA to ensure that each core obtains
+ * the correct kernel mapping. arch_sync_kernel_mappings() will ensure that kernel
+ * page table mappings created via vmap/vmalloc() are updated before switching MM.
+ */
+void arch_sync_kernel_mappings(unsigned long start, unsigned long end)
+{
+ if (start < VMALLOC_END && end > VMALLOC_START)
+ flush_tlb_all();
+}
\ No newline at end of file
--
2.34.1
next prev parent reply other threads:[~2023-08-07 8:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 8:23 [PATCH 0/1] Enhanced TLB flushing for vmap/vmalloc() Dylan Jhong
2023-08-07 8:23 ` Dylan Jhong
2023-08-07 8:23 ` Dylan Jhong [this message]
2023-08-07 8:23 ` [PATCH 1/1] riscv: Implement arch_sync_kernel_mappings() for "preventive" TLB flush Dylan Jhong
2023-08-07 9:35 ` kernel test robot
2023-08-07 9:35 ` kernel test robot
2023-08-07 12:28 ` kernel test robot
2023-08-07 12:28 ` kernel test robot
2023-08-08 10:16 ` Alexandre Ghiti
2023-08-08 10:16 ` Alexandre Ghiti
2023-08-09 11:16 ` Dylan Jhong
2023-08-09 11:16 ` Dylan Jhong
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=20230807082305.198784-2-dylan@andestech.com \
--to=dylan@andestech.com \
--cc=ajones@ventanamicro.com \
--cc=alexghiti@rivosinc.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=conor.dooley@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maz@kernel.org \
--cc=palmer@dabbelt.com \
--cc=panqinglin2020@iscas.ac.cn \
--cc=paul.walmsley@sifive.com \
--cc=rppt@kernel.org \
--cc=samuel@sholland.org \
--cc=sergey.matyukevich@syntacore.com \
--cc=tim609@andestech.com \
--cc=x5710999x@gmail.com \
--cc=ycliang@andestech.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.