* [PATCH] LoongArch: Clear invalid tlb when set huge page PTE entry
@ 2023-09-05 4:48 Bibo Mao
2023-09-06 15:05 ` kernel test robot
0 siblings, 1 reply; 2+ messages in thread
From: Bibo Mao @ 2023-09-05 4:48 UTC (permalink / raw)
To: Huacai Chen; +Cc: WANG Xuerui, Andrew Morton, loongarch, linux-kernel
For LoongArch machines where hardware page table walk is not
support, if hugetlb pte entry is invalid, invalid tlb with normal
page will be filled and triggers page fault exception from HW.
During page fault handling, current thread maybe migrates to other
CPUs and set huge page pte entry. And if the thread migrates to
the old CPU, stale tlb with normal page exists still, there will
be confliction. So the invalid tlb need be flushed when set huge
page pte entry like set_huge_pte_at and set_pmd_at function.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/include/asm/hugetlb.h | 4 ++++
arch/loongarch/mm/pgtable.c | 8 +++++++-
arch/loongarch/mm/tlb.c | 17 +++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/include/asm/hugetlb.h b/arch/loongarch/include/asm/hugetlb.h
index aa44b3fe43dd..62cd7528a07f 100644
--- a/arch/loongarch/include/asm/hugetlb.h
+++ b/arch/loongarch/include/asm/hugetlb.h
@@ -59,6 +59,10 @@ static inline int huge_pte_none(pte_t pte)
return !val || (val == (unsigned long)invalid_pte_table);
}
+#define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT
+extern void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
+ pte_t *ptep, pte_t pte);
+
#define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS
static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
unsigned long addr,
diff --git a/arch/loongarch/mm/pgtable.c b/arch/loongarch/mm/pgtable.c
index b14343e211b6..dfae34484f43 100644
--- a/arch/loongarch/mm/pgtable.c
+++ b/arch/loongarch/mm/pgtable.c
@@ -116,8 +116,14 @@ pmd_t mk_pmd(struct page *page, pgprot_t prot)
void set_pmd_at(struct mm_struct *mm, unsigned long addr,
pmd_t *pmdp, pmd_t pmd)
{
+ /*
+ * The similar with function set_huge_pte_at
+ * Need flush invalid normal page pte if hw ptw is not supported
+ */
+ if (!cpu_has_ptw && pmd_none(*pmdp))
+ flush_tlb_mm(mm);
+
*pmdp = pmd;
- flush_tlb_all();
}
void __init pagetable_init(void)
diff --git a/arch/loongarch/mm/tlb.c b/arch/loongarch/mm/tlb.c
index eb8572e201ea..ef7a89a98982 100644
--- a/arch/loongarch/mm/tlb.c
+++ b/arch/loongarch/mm/tlb.c
@@ -201,6 +201,23 @@ void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t *ptep
local_irq_restore(flags);
}
+void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
+ pte_t *ptep, pte_t pte)
+{
+ /*
+ * If huge pte entry is none, tlb entry with normal page size is filled
+ * for machines which does not support hardware page walking.
+ *
+ * Thread maybe migrates to other CPUs after page fault happends and
+ * migrates back again after hugepage pte is set, tlbs with normal page
+ * about invalid_pte_table need be flushed
+ */
+ if (!cpu_has_ptw && huge_pte_none(*ptep))
+ flush_tlb_mm(mm);
+
+ set_pte_at(mm, addr, ptep, pte);
+}
+
static void setup_ptwalker(void)
{
unsigned long pwctl0, pwctl1;
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] LoongArch: Clear invalid tlb when set huge page PTE entry
2023-09-05 4:48 [PATCH] LoongArch: Clear invalid tlb when set huge page PTE entry Bibo Mao
@ 2023-09-06 15:05 ` kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2023-09-06 15:05 UTC (permalink / raw)
To: Bibo Mao, Huacai Chen
Cc: oe-kbuild-all, WANG Xuerui, Andrew Morton,
Linux Memory Management List, loongarch, linux-kernel
Hi Bibo,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.5 next-20230906]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bibo-Mao/LoongArch-Clear-invalid-tlb-when-set-huge-page-PTE-entry/20230906-013753
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20230905044828.1460721-1-maobibo%40loongson.cn
patch subject: [PATCH] LoongArch: Clear invalid tlb when set huge page PTE entry
config: loongarch-allnoconfig (https://download.01.org/0day-ci/archive/20230906/202309062224.jKf5JY7H-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230906/202309062224.jKf5JY7H-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202309062224.jKf5JY7H-lkp@intel.com/
All errors (new ones prefixed by >>):
>> arch/loongarch/mm/tlb.c:204:6: error: redefinition of 'set_huge_pte_at'
204 | void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
| ^~~~~~~~~~~~~~~
In file included from arch/loongarch/mm/tlb.c:9:
include/linux/hugetlb.h:1175:20: note: previous definition of 'set_huge_pte_at' with type 'void(struct mm_struct *, long unsigned int, pte_t *, pte_t)'
1175 | static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
| ^~~~~~~~~~~~~~~
arch/loongarch/mm/tlb.c: In function 'set_huge_pte_at':
>> arch/loongarch/mm/tlb.c:215:29: error: implicit declaration of function 'huge_pte_none'; did you mean 'huge_pte_lock'? [-Werror=implicit-function-declaration]
215 | if (!cpu_has_ptw && huge_pte_none(*ptep))
| ^~~~~~~~~~~~~
| huge_pte_lock
arch/loongarch/mm/tlb.c: At top level:
arch/loongarch/mm/tlb.c:281:6: warning: no previous prototype for 'setup_tlb_handler' [-Wmissing-prototypes]
281 | void setup_tlb_handler(int cpu)
| ^~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/set_huge_pte_at +204 arch/loongarch/mm/tlb.c
203
> 204 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
205 pte_t *ptep, pte_t pte)
206 {
207 /*
208 * If huge pte entry is none, tlb entry with normal page size is filled
209 * for machines which does not support hardware page walking.
210 *
211 * Thread maybe migrates to other CPUs after page fault happends and
212 * migrates back again after hugepage pte is set, tlbs with normal page
213 * about invalid_pte_table need be flushed
214 */
> 215 if (!cpu_has_ptw && huge_pte_none(*ptep))
216 flush_tlb_mm(mm);
217
218 set_pte_at(mm, addr, ptep, pte);
219 }
220
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-06 15:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-05 4:48 [PATCH] LoongArch: Clear invalid tlb when set huge page PTE entry Bibo Mao
2023-09-06 15:05 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox